Line data Source code
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 "MediaInfo.h"
11 : #include "mozilla/MozPromise.h"
12 : #include "mozilla/Mutex.h"
13 : #include "mozilla/RefPtr.h"
14 :
15 : namespace mozilla {
16 :
17 : typedef nsTArray<uint8_t> CencKeyId;
18 :
19 : class CDMProxy;
20 : template <typename... Es> class MediaEventProducer;
21 : class MediaRawData;
22 :
23 : // Encapsulates the task of waiting for the CDMProxy to have the necessary
24 : // keys to decrypt a given sample.
25 : class SamplesWaitingForKey
26 : {
27 : public:
28 0 : NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SamplesWaitingForKey)
29 :
30 : typedef MozPromise<RefPtr<MediaRawData>, bool, /* IsExclusive = */ true>
31 : WaitForKeyPromise;
32 :
33 : SamplesWaitingForKey(
34 : CDMProxy* aProxy,
35 : TrackInfo::TrackType aType,
36 : MediaEventProducer<TrackInfo::TrackType>* aOnWaitingForKey);
37 :
38 : // Returns a promise that will be resolved if or when a key for decoding the
39 : // sample becomes usable.
40 : RefPtr<WaitForKeyPromise> WaitIfKeyNotUsable(MediaRawData* aSample);
41 :
42 : void NotifyUsable(const CencKeyId& aKeyId);
43 :
44 : void Flush();
45 :
46 : protected:
47 : ~SamplesWaitingForKey();
48 :
49 : private:
50 : Mutex mMutex;
51 : RefPtr<CDMProxy> mProxy;
52 0 : struct SampleEntry
53 : {
54 : RefPtr<MediaRawData> mSample;
55 : MozPromiseHolder<WaitForKeyPromise> mPromise;
56 : };
57 : nsTArray<SampleEntry> mSamples;
58 : const TrackInfo::TrackType mType;
59 : MediaEventProducer<TrackInfo::TrackType>* const mOnWaitingForKeyEvent;
60 : };
61 :
62 : } // namespace mozilla
63 :
64 : #endif // SamplesWaitingForKey_h_
|