OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_BASE_ANDROID_MEDIA_CODEC_LOOP_H_ | 5 #ifndef MEDIA_BASE_ANDROID_MEDIA_CODEC_LOOP_H_ |
6 #define MEDIA_BASE_ANDROID_MEDIA_CODEC_LOOP_H_ | 6 #define MEDIA_BASE_ANDROID_MEDIA_CODEC_LOOP_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" |
14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/single_thread_task_runner.h" |
15 #include "base/time/tick_clock.h" | 17 #include "base/time/tick_clock.h" |
16 #include "base/time/time.h" | 18 #include "base/time/time.h" |
17 #include "base/timer/timer.h" | 19 #include "base/timer/timer.h" |
18 #include "media/base/android/media_codec_bridge.h" | 20 #include "media/base/android/media_codec_bridge.h" |
19 #include "media/base/decode_status.h" | 21 #include "media/base/decode_status.h" |
20 #include "media/base/encryption_scheme.h" | 22 #include "media/base/encryption_scheme.h" |
21 #include "media/base/media_export.h" | 23 #include "media/base/media_export.h" |
22 #include "media/base/subsample_entry.h" | 24 #include "media/base/subsample_entry.h" |
23 | 25 |
24 // MediaCodecLoop is based on Android's MediaCodec API. | 26 // MediaCodecLoop is based on Android's MediaCodec API. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 // (OnKeyAdded) | 96 // (OnKeyAdded) |
95 // | | 97 // | |
96 // [Ready] | 98 // [Ready] |
97 // | 99 // |
98 // -[Any state]- | 100 // -[Any state]- |
99 // | | | 101 // | | |
100 // (Flush ok) (Flush fails) | 102 // (Flush ok) (Flush fails) |
101 // | | | 103 // | | |
102 // [Ready] [Error] | 104 // [Ready] [Error] |
103 | 105 |
104 namespace base { | |
105 class SingleThreadTaskRunner; | |
106 } | |
107 | |
108 namespace media { | 106 namespace media { |
109 | 107 |
110 class MEDIA_EXPORT MediaCodecLoop { | 108 class MEDIA_EXPORT MediaCodecLoop { |
111 public: | 109 public: |
112 // TODO(liberato): this exists in video_decoder.h and audio_decoder.h too. | 110 // TODO(liberato): this exists in video_decoder.h and audio_decoder.h too. |
113 using InitCB = base::Callback<void(bool success)>; | 111 using InitCB = base::Callback<void(bool success)>; |
114 using DecodeCB = base::Callback<void(DecodeStatus status)>; | 112 using DecodeCB = base::Callback<void(DecodeStatus status)>; |
115 | 113 |
116 // Data that the client wants to put into an input buffer. | 114 // Data that the client wants to put into an input buffer. |
117 struct InputData { | 115 struct InputData { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 // success, or false to transition to the error state. | 188 // success, or false to transition to the error state. |
191 virtual bool OnOutputFormatChanged() = 0; | 189 virtual bool OnOutputFormatChanged() = 0; |
192 | 190 |
193 // Notify the client when our state transitions to STATE_ERROR. | 191 // Notify the client when our state transitions to STATE_ERROR. |
194 virtual void OnCodecLoopError() = 0; | 192 virtual void OnCodecLoopError() = 0; |
195 | 193 |
196 protected: | 194 protected: |
197 virtual ~Client() {} | 195 virtual ~Client() {} |
198 }; | 196 }; |
199 | 197 |
200 // We will take ownership of |media_codec|. We will not destroy it until | 198 // We will take ownership of |media_codec|. We will not destroy it until we |
201 // we are destructed. |media_codec| may not be null. | 199 // are destructed. |media_codec| may not be null. |sdk_level| is temporary. |
202 // |sdk_level| is temporary. It is used only to decouple MediaCodecLoop from | 200 // It is used only to decouple MediaCodecLoop from BuildInfo, until we get |
203 // BuildInfo, until we get BuildInfo into a mockable state. | 201 // BuildInfo into a mockable state. If |timer_task_runner| is non-null, |
| 202 // timers are redirected to it. |
204 MediaCodecLoop(int sdk_level, | 203 MediaCodecLoop(int sdk_level, |
205 Client* client, | 204 Client* client, |
206 std::unique_ptr<MediaCodecBridge> media_codec, | 205 std::unique_ptr<MediaCodecBridge> media_codec, |
207 scoped_refptr<base::SingleThreadTaskRunner> = | 206 scoped_refptr<base::SingleThreadTaskRunner> timer_task_runner); |
208 scoped_refptr<base::SingleThreadTaskRunner>()); | |
209 ~MediaCodecLoop(); | 207 ~MediaCodecLoop(); |
210 | 208 |
211 // Optionally set the tick clock used for testing. It is our caller's | 209 // Optionally set the tick clock used for testing. It is our caller's |
212 // responsibility to maintain ownership of this, since | 210 // responsibility to maintain ownership of this, since |
213 // FakeSingleThreadTaskRunner maintains a raw ptr to it also. | 211 // FakeSingleThreadTaskRunner maintains a raw ptr to it also. |
214 void SetTestTickClock(base::TickClock* test_tick_clock); | 212 void SetTestTickClock(base::TickClock* test_tick_clock); |
215 | 213 |
216 // Does the MediaCodec processing cycle: enqueues an input buffer, then | 214 // Does the MediaCodec processing cycle: enqueues an input buffer, then |
217 // dequeues output buffers. This should be called by the client when more | 215 // dequeues output buffers. This should be called by the client when more |
218 // work becomes available, such as when new input data arrives. If codec | 216 // work becomes available, such as when new input data arrives. If codec |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 | 320 |
323 // NOTE: Weak pointers must be invalidated before all other member variables. | 321 // NOTE: Weak pointers must be invalidated before all other member variables. |
324 base::WeakPtrFactory<MediaCodecLoop> weak_factory_; | 322 base::WeakPtrFactory<MediaCodecLoop> weak_factory_; |
325 | 323 |
326 DISALLOW_COPY_AND_ASSIGN(MediaCodecLoop); | 324 DISALLOW_COPY_AND_ASSIGN(MediaCodecLoop); |
327 }; | 325 }; |
328 | 326 |
329 } // namespace media | 327 } // namespace media |
330 | 328 |
331 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_LOOP_H_ | 329 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_LOOP_H_ |
OLD | NEW |