Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(530)

Side by Side Diff: media/base/android/media_codec_loop.h

Issue 2132653002: MediaCodecLoop unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added some tests Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/time/tick_clock.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 #include "base/timer/timer.h" 17 #include "base/timer/timer.h"
17 #include "media/base/android/media_codec_bridge.h" 18 #include "media/base/android/media_codec_bridge.h"
18 #include "media/base/audio_decoder.h" 19 #include "media/base/audio_decoder.h"
19 #include "media/base/audio_decoder_config.h" 20 #include "media/base/audio_decoder_config.h"
20 #include "media/base/media_export.h" 21 #include "media/base/media_export.h"
21 22
22 // MediaCodecLoop is based on Android's MediaCodec API. 23 // MediaCodecLoop is based on Android's MediaCodec API.
23 // The MediaCodec API is required to play encrypted (as in EME) content on 24 // The MediaCodec API is required to play encrypted (as in EME) content on
24 // Android. It is also a way to employ hardware-accelerated decoding. 25 // Android. It is also a way to employ hardware-accelerated decoding.
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 186
186 // Notify the client when our state transitions to STATE_ERROR. 187 // Notify the client when our state transitions to STATE_ERROR.
187 virtual void OnCodecLoopError() = 0; 188 virtual void OnCodecLoopError() = 0;
188 189
189 protected: 190 protected:
190 virtual ~Client() {} 191 virtual ~Client() {}
191 }; 192 };
192 193
193 // We will take ownership of |media_codec|. We will not destroy it until 194 // We will take ownership of |media_codec|. We will not destroy it until
194 // we are destructed. |media_codec| may not be null. 195 // we are destructed. |media_codec| may not be null.
195 MediaCodecLoop(Client* client, std::unique_ptr<MediaCodecBridge> media_codec); 196 MediaCodecLoop(Client* client,
197 std::unique_ptr<MediaCodecBridge> media_codec,
198 scoped_refptr<base::SingleThreadTaskRunner> =
199 scoped_refptr<base::SingleThreadTaskRunner>());
196 ~MediaCodecLoop(); 200 ~MediaCodecLoop();
197 201
202 // Optionally set the tick clock used for testing. It is our caller's
203 // responsibility to maintain ownership of this, since
204 // FakeSingleThreadTaskRunner maintains a raw ptr to it also.
205 void SetTestTickClock(base::TickClock* test_tick_clock);
206
198 // Does the MediaCodec processing cycle: enqueues an input buffer, then 207 // Does the MediaCodec processing cycle: enqueues an input buffer, then
199 // dequeues output buffers. This should be called by the client when more 208 // dequeues output buffers. This should be called by the client when more
200 // work becomes available, such as when new input data arrives. If codec 209 // work becomes available, such as when new input data arrives. If codec
201 // output buffers are freed after OnDecodedFrame returns, then this should 210 // output buffers are freed after OnDecodedFrame returns, then this should
202 // also be called. 211 // also be called.
203 void DoPendingWork(); 212 void DoPendingWork();
204 213
205 // Try to flush this media codec. Returns true on success, false on failure. 214 // Try to flush this media codec. Returns true on success, false on failure.
206 // Failures can result in a state change to the Error state. If this returns 215 // Failures can result in a state change to the Error state. If this returns
207 // false but the state is still READY, then the codec may continue to be used. 216 // false but the state is still READY, then the codec may continue to be used.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 // Start the timer immediately if |start| is true or stop it based on elapsed 268 // Start the timer immediately if |start| is true or stop it based on elapsed
260 // idle time if |start| is false. 269 // idle time if |start| is false.
261 void ManageTimer(bool start); 270 void ManageTimer(bool start);
262 271
263 // Helper method to change the state. 272 // Helper method to change the state.
264 void SetState(State new_state); 273 void SetState(State new_state);
265 274
266 // A helper function for logging. 275 // A helper function for logging.
267 static const char* AsString(State state); 276 static const char* AsString(State state);
268 277
269 // Used to post tasks. This class is single threaded and every method should
270 // run on this task runner.
271 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
272
273 State state_; 278 State state_;
274 279
275 // The client that we notify about MediaCodec events. 280 // The client that we notify about MediaCodec events.
276 Client* client_; 281 Client* client_;
277 282
278 // The MediaCodec instance that we're using. 283 // The MediaCodec instance that we're using.
279 std::unique_ptr<MediaCodecBridge> media_codec_; 284 std::unique_ptr<MediaCodecBridge> media_codec_;
280 285
281 // Repeating timer that kicks MediaCodec operation. 286 // Repeating timer that kicks MediaCodec operation.
282 base::RepeatingTimer io_timer_; 287 base::RepeatingTimer io_timer_;
283 288
284 // Time at which we last did useful work on |io_timer_|. 289 // Time at which we last did useful work on |io_timer_|.
285 base::TimeTicks idle_time_begin_; 290 base::TimeTicks idle_time_begin_;
286 291
287 // Index of the dequeued and filled buffer that we keep trying to enqueue. 292 // Index of the dequeued and filled buffer that we keep trying to enqueue.
288 // Such buffer appears in MEDIA_CODEC_NO_KEY processing. The -1 value means 293 // Such buffer appears in MEDIA_CODEC_NO_KEY processing. The -1 value means
289 // there is no such buffer. 294 // there is no such buffer.
290 int pending_input_buf_index_; 295 int pending_input_buf_index_;
291 296
292 // When processing a pending input buffer, this is the data that was returned 297 // When processing a pending input buffer, this is the data that was returned
293 // to us by the client. |memory| has been cleared, since the codec has it. 298 // to us by the client. |memory| has been cleared, since the codec has it.
294 InputData pending_input_buf_data_; 299 InputData pending_input_buf_data_;
295 300
296 // When an EOS is queued, we defer its completion callback until the EOS 301 // When an EOS is queued, we defer its completion callback until the EOS
297 // arrives at the output queue. This is valid when we're in STATE_DRAINING. 302 // arrives at the output queue. This is valid when we're in STATE_DRAINING.
298 DecodeCB pending_eos_completion_cb_; 303 DecodeCB pending_eos_completion_cb_;
299 304
305 // Optional clock for use during testing. It may be null. We do not maintain
306 // ownership of it.
307 base::TickClock* test_tick_clock_ = nullptr;
308
300 // NOTE: Weak pointers must be invalidated before all other member variables. 309 // NOTE: Weak pointers must be invalidated before all other member variables.
301 base::WeakPtrFactory<MediaCodecLoop> weak_factory_; 310 base::WeakPtrFactory<MediaCodecLoop> weak_factory_;
302 311
303 DISALLOW_COPY_AND_ASSIGN(MediaCodecLoop); 312 DISALLOW_COPY_AND_ASSIGN(MediaCodecLoop);
304 }; 313 };
305 314
306 } // namespace media 315 } // namespace media
307 316
308 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_LOOP_H_ 317 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_LOOP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698