| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_FILTERS_FAKE_VIDEO_DECODER_H_ | 5 #ifndef MEDIA_FILTERS_FAKE_VIDEO_DECODER_H_ |
| 6 #define MEDIA_FILTERS_FAKE_VIDEO_DECODER_H_ | 6 #define MEDIA_FILTERS_FAKE_VIDEO_DECODER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/threading/thread_checker.h" |
| 14 #include "media/base/callback_holder.h" | 15 #include "media/base/callback_holder.h" |
| 15 #include "media/base/decoder_buffer.h" | 16 #include "media/base/decoder_buffer.h" |
| 16 #include "media/base/pipeline_status.h" | 17 #include "media/base/pipeline_status.h" |
| 17 #include "media/base/video_decoder.h" | 18 #include "media/base/video_decoder.h" |
| 18 #include "media/base/video_decoder_config.h" | 19 #include "media/base/video_decoder_config.h" |
| 19 #include "media/base/video_frame.h" | 20 #include "media/base/video_frame.h" |
| 20 #include "ui/gfx/size.h" | 21 #include "ui/gfx/size.h" |
| 21 | 22 |
| 22 using base::ResetAndReturn; | 23 using base::ResetAndReturn; |
| 23 | 24 |
| 24 namespace base { | 25 namespace base { |
| 25 class SingleThreadTaskRunner; | 26 class SingleThreadTaskRunner; |
| 26 } | 27 } |
| 27 | 28 |
| 28 namespace media { | 29 namespace media { |
| 29 | 30 |
| 30 class FakeVideoDecoder : public VideoDecoder { | 31 class FakeVideoDecoder : public VideoDecoder { |
| 31 public: | 32 public: |
| 32 // Constructs an object with a decoding delay of |decoding_delay| frames. | 33 // Constructs an object with a decoding delay of |decoding_delay| frames. |
| 33 FakeVideoDecoder(int decoding_delay, bool supports_get_decode_output); | 34 FakeVideoDecoder(int decoding_delay, |
| 35 bool supports_get_decode_output, |
| 36 int max_parallel_decoding_requests); |
| 34 virtual ~FakeVideoDecoder(); | 37 virtual ~FakeVideoDecoder(); |
| 35 | 38 |
| 36 // VideoDecoder implementation. | 39 // VideoDecoder implementation. |
| 37 virtual void Initialize(const VideoDecoderConfig& config, | 40 virtual void Initialize(const VideoDecoderConfig& config, |
| 38 const PipelineStatusCB& status_cb) OVERRIDE; | 41 const PipelineStatusCB& status_cb) OVERRIDE; |
| 39 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, | 42 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, |
| 40 const DecodeCB& decode_cb) OVERRIDE; | 43 const DecodeCB& decode_cb) OVERRIDE; |
| 41 virtual void Reset(const base::Closure& closure) OVERRIDE; | 44 virtual void Reset(const base::Closure& closure) OVERRIDE; |
| 42 virtual void Stop() OVERRIDE; | 45 virtual void Stop() OVERRIDE; |
| 43 virtual scoped_refptr<VideoFrame> GetDecodeOutput() OVERRIDE; | 46 virtual scoped_refptr<VideoFrame> GetDecodeOutput() OVERRIDE; |
| 47 virtual int GetMaxDecodeRequests() const OVERRIDE; |
| 44 | 48 |
| 45 // Holds the next init/decode/reset callback from firing. | 49 // Holds the next init/decode/reset callback from firing. |
| 46 void HoldNextInit(); | 50 void HoldNextInit(); |
| 47 void HoldNextDecode(); | 51 void HoldDecode(); |
| 48 void HoldNextReset(); | 52 void HoldNextReset(); |
| 49 | 53 |
| 50 // Satisfies the pending init/decode/reset callback, which must be ready to | 54 // Satisfies the pending init/decode/reset callback, which must be ready to |
| 51 // fire when these methods are called. | 55 // fire when these methods are called. |
| 52 void SatisfyInit(); | 56 void SatisfyInit(); |
| 53 void SatisfyDecode(); | 57 void SatisfyDecode(); |
| 54 void SatisfyReset(); | 58 void SatisfyReset(); |
| 55 | 59 |
| 60 // Satisfies single decode request. |
| 61 void SatisfySingleDecode(); |
| 62 |
| 63 void SimulateError(); |
| 64 |
| 56 int total_bytes_decoded() const { return total_bytes_decoded_; } | 65 int total_bytes_decoded() const { return total_bytes_decoded_; } |
| 57 | 66 |
| 58 private: | 67 private: |
| 59 enum State { | 68 enum State { |
| 60 UNINITIALIZED, | 69 UNINITIALIZED, |
| 61 NORMAL | 70 NORMAL, |
| 71 END_OF_STREAM, |
| 72 ERROR, |
| 62 }; | 73 }; |
| 63 | 74 |
| 64 // Callback for updating |total_bytes_decoded_|. | 75 // Callback for updating |total_bytes_decoded_|. |
| 65 void OnFrameDecoded(int buffer_size, | 76 void OnFrameDecoded(int buffer_size, |
| 66 const DecodeCB& decode_cb, | 77 const DecodeCB& decode_cb, |
| 67 Status status, | 78 Status status, |
| 68 const scoped_refptr<VideoFrame>& video_frame); | 79 const scoped_refptr<VideoFrame>& video_frame); |
| 69 | 80 |
| 81 // Runs |decode_cb| or puts it to |held_decode_callbacks_| depending on |
| 82 // current value of |hold_decode_|. |
| 83 void RunOrHoldDecode(const DecodeCB& decode_cb); |
| 84 |
| 85 // Runs |decode_cb| with a frame from |decoded_frames_|. |
| 86 void RunDecodeCallback(const DecodeCB& decode_cb); |
| 87 |
| 70 void DoReset(); | 88 void DoReset(); |
| 71 | 89 |
| 72 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 90 base::ThreadChecker thread_checker_; |
| 73 | 91 |
| 74 const int decoding_delay_; | 92 const size_t decoding_delay_; |
| 75 | 93 const bool supports_get_decode_output_; |
| 76 bool supports_get_decode_output_; | 94 const int max_parallel_decoding_requests_; |
| 77 | 95 |
| 78 State state_; | 96 State state_; |
| 79 | 97 |
| 80 CallbackHolder<PipelineStatusCB> init_cb_; | 98 CallbackHolder<PipelineStatusCB> init_cb_; |
| 81 CallbackHolder<DecodeCB> decode_cb_; | |
| 82 CallbackHolder<base::Closure> reset_cb_; | 99 CallbackHolder<base::Closure> reset_cb_; |
| 83 | 100 |
| 101 bool hold_decode_; |
| 102 std::list<DecodeCB> held_decode_callbacks_; |
| 103 |
| 84 VideoDecoderConfig current_config_; | 104 VideoDecoderConfig current_config_; |
| 85 | 105 |
| 86 std::list<scoped_refptr<VideoFrame> > decoded_frames_; | 106 std::list<scoped_refptr<VideoFrame> > decoded_frames_; |
| 87 | 107 |
| 88 int total_bytes_decoded_; | 108 int total_bytes_decoded_; |
| 89 | 109 |
| 90 // NOTE: Weak pointers must be invalidated before all other member variables. | 110 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 91 base::WeakPtrFactory<FakeVideoDecoder> weak_factory_; | 111 base::WeakPtrFactory<FakeVideoDecoder> weak_factory_; |
| 92 | 112 |
| 93 DISALLOW_COPY_AND_ASSIGN(FakeVideoDecoder); | 113 DISALLOW_COPY_AND_ASSIGN(FakeVideoDecoder); |
| 94 }; | 114 }; |
| 95 | 115 |
| 96 } // namespace media | 116 } // namespace media |
| 97 | 117 |
| 98 #endif // MEDIA_FILTERS_FAKE_VIDEO_DECODER_H_ | 118 #endif // MEDIA_FILTERS_FAKE_VIDEO_DECODER_H_ |
| OLD | NEW |