/src/mozilla-central/dom/media/mediasource/SourceBufferTask.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
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 MOZILLA_SOURCEBUFFERTASK_H_ |
8 | | #define MOZILLA_SOURCEBUFFERTASK_H_ |
9 | | |
10 | | #include "mozilla/MozPromise.h" |
11 | | #include "mozilla/Pair.h" |
12 | | #include "SourceBufferAttributes.h" |
13 | | #include "TimeUnits.h" |
14 | | #include "MediaResult.h" |
15 | | |
16 | | namespace mozilla { |
17 | | |
18 | | class SourceBufferTask { |
19 | | public: |
20 | | NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SourceBufferTask); |
21 | | enum class Type { |
22 | | AppendBuffer, |
23 | | Abort, |
24 | | Reset, |
25 | | RangeRemoval, |
26 | | EvictData, |
27 | | Detach, |
28 | | ChangeType |
29 | | }; |
30 | | |
31 | | typedef Pair<bool, SourceBufferAttributes> AppendBufferResult; |
32 | | typedef MozPromise<AppendBufferResult, MediaResult, /* IsExclusive = */ true> AppendPromise; |
33 | | typedef MozPromise<bool, nsresult, /* IsExclusive = */ true> RangeRemovalPromise; |
34 | | |
35 | | virtual Type GetType() const = 0; |
36 | | virtual const char* GetTypeName() const = 0; |
37 | | |
38 | | template<typename ReturnType> |
39 | | ReturnType* As() |
40 | 0 | { |
41 | 0 | MOZ_ASSERT(this->GetType() == ReturnType::sType); |
42 | 0 | return static_cast<ReturnType*>(this); |
43 | 0 | } Unexecuted instantiation: mozilla::AppendBufferTask* mozilla::SourceBufferTask::As<mozilla::AppendBufferTask>() Unexecuted instantiation: mozilla::RangeRemovalTask* mozilla::SourceBufferTask::As<mozilla::RangeRemovalTask>() Unexecuted instantiation: mozilla::EvictDataTask* mozilla::SourceBufferTask::As<mozilla::EvictDataTask>() Unexecuted instantiation: mozilla::ChangeTypeTask* mozilla::SourceBufferTask::As<mozilla::ChangeTypeTask>() |
44 | | |
45 | | protected: |
46 | 0 | virtual ~SourceBufferTask() {} |
47 | | }; |
48 | | |
49 | | class AppendBufferTask : public SourceBufferTask { |
50 | | public: |
51 | | AppendBufferTask(already_AddRefed<MediaByteBuffer> aData, |
52 | | const SourceBufferAttributes& aAttributes) |
53 | | : mBuffer(aData) |
54 | | , mAttributes(aAttributes) |
55 | 0 | {} |
56 | | |
57 | | static const Type sType = Type::AppendBuffer; |
58 | 0 | Type GetType() const override { return Type::AppendBuffer; } |
59 | 0 | const char* GetTypeName() const override { return "AppendBuffer"; } |
60 | | |
61 | | RefPtr<MediaByteBuffer> mBuffer; |
62 | | SourceBufferAttributes mAttributes; |
63 | | MozPromiseHolder<AppendPromise> mPromise; |
64 | | }; |
65 | | |
66 | | class AbortTask : public SourceBufferTask { |
67 | | public: |
68 | | static const Type sType = Type::Abort; |
69 | 0 | Type GetType() const override { return Type::Abort; } |
70 | 0 | const char* GetTypeName() const override { return "Abort"; } |
71 | | }; |
72 | | |
73 | | class ResetTask : public SourceBufferTask { |
74 | | public: |
75 | | static const Type sType = Type::Reset; |
76 | 0 | Type GetType() const override { return Type::Reset; } |
77 | 0 | const char* GetTypeName() const override { return "Reset"; } |
78 | | }; |
79 | | |
80 | | class RangeRemovalTask : public SourceBufferTask { |
81 | | public: |
82 | | explicit RangeRemovalTask(const media::TimeInterval& aRange) |
83 | | : mRange(aRange) |
84 | 0 | {} |
85 | | |
86 | | static const Type sType = Type::RangeRemoval; |
87 | 0 | Type GetType() const override { return Type::RangeRemoval; } |
88 | 0 | const char* GetTypeName() const override { return "RangeRemoval"; } |
89 | | |
90 | | media::TimeInterval mRange; |
91 | | MozPromiseHolder<RangeRemovalPromise> mPromise; |
92 | | }; |
93 | | |
94 | | class EvictDataTask : public SourceBufferTask { |
95 | | public: |
96 | | EvictDataTask(const media::TimeUnit& aPlaybackTime, int64_t aSizetoEvict) |
97 | | : mPlaybackTime(aPlaybackTime) |
98 | | , mSizeToEvict(aSizetoEvict) |
99 | 0 | {} |
100 | | |
101 | | static const Type sType = Type::EvictData; |
102 | 0 | Type GetType() const override { return Type::EvictData; } |
103 | 0 | const char* GetTypeName() const override { return "EvictData"; } |
104 | | |
105 | | media::TimeUnit mPlaybackTime; |
106 | | int64_t mSizeToEvict; |
107 | | }; |
108 | | |
109 | | class DetachTask : public SourceBufferTask { |
110 | | public: |
111 | | static const Type sType = Type::Detach; |
112 | 0 | Type GetType() const override { return Type::Detach; } |
113 | 0 | const char* GetTypeName() const override { return "Detach"; } |
114 | | }; |
115 | | |
116 | | class ChangeTypeTask : public SourceBufferTask { |
117 | | public: |
118 | | explicit ChangeTypeTask(const MediaContainerType& aType) |
119 | | : mType(aType) |
120 | 0 | { |
121 | 0 | } |
122 | | |
123 | | static const Type sType = Type::ChangeType; |
124 | 0 | Type GetType() const override { return Type::ChangeType; } |
125 | 0 | const char* GetTypeName() const override { return "ChangeType"; } |
126 | | |
127 | | const MediaContainerType mType; |
128 | | }; |
129 | | |
130 | | } // end mozilla namespace |
131 | | |
132 | | #endif |