tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SamplesWaitingForKey.h (1888B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef SamplesWaitingForKey_h_
      8 #define SamplesWaitingForKey_h_
      9 
     10 #include <functional>
     11 
     12 #include "MediaInfo.h"
     13 #include "mozilla/MozPromise.h"
     14 #include "mozilla/Mutex.h"
     15 #include "mozilla/RefPtr.h"
     16 
     17 namespace mozilla {
     18 
     19 typedef nsTArray<uint8_t> CencKeyId;
     20 
     21 class CDMProxy;
     22 template <typename... Es>
     23 class MediaEventProducer;
     24 class MediaRawData;
     25 
     26 // Encapsulates the task of waiting for the CDMProxy to have the necessary
     27 // keys to decrypt a given sample.
     28 class SamplesWaitingForKey {
     29 public:
     30  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SamplesWaitingForKey)
     31 
     32  typedef MozPromise<RefPtr<MediaRawData>, bool, /* IsExclusive = */ true>
     33      WaitForKeyPromise;
     34 
     35  SamplesWaitingForKey(
     36      CDMProxy* aProxy, TrackInfo::TrackType aType,
     37      const std::function<MediaEventProducer<TrackInfo::TrackType>*()>&
     38          aOnWaitingForKeyEvent);
     39 
     40  // Returns a promise that will be resolved if or when a key for decoding the
     41  // sample becomes usable.
     42  RefPtr<WaitForKeyPromise> WaitIfKeyNotUsable(MediaRawData* aSample);
     43 
     44  void NotifyUsable(const CencKeyId& aKeyId);
     45 
     46  void Flush();
     47 
     48  void BreakCycles();
     49 
     50 protected:
     51  ~SamplesWaitingForKey();
     52 
     53 private:
     54  Mutex mMutex MOZ_UNANNOTATED;
     55  RefPtr<CDMProxy> mProxy;
     56  struct SampleEntry {
     57    RefPtr<MediaRawData> mSample;
     58    MozPromiseHolder<WaitForKeyPromise> mPromise;
     59  };
     60  nsTArray<SampleEntry> mSamples;
     61  const TrackInfo::TrackType mType;
     62  const std::function<MediaEventProducer<TrackInfo::TrackType>*()>
     63      mOnWaitingForKeyEvent;
     64 };
     65 
     66 }  // namespace mozilla
     67 
     68 #endif  //  SamplesWaitingForKey_h_