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 bool low_delay, | 41 bool low_delay, |
39 const PipelineStatusCB& status_cb) OVERRIDE; | 42 const PipelineStatusCB& status_cb) OVERRIDE; |
40 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, | 43 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, |
41 const DecodeCB& decode_cb) OVERRIDE; | 44 const DecodeCB& decode_cb) OVERRIDE; |
42 virtual void Reset(const base::Closure& closure) OVERRIDE; | 45 virtual void Reset(const base::Closure& closure) OVERRIDE; |
43 virtual void Stop() OVERRIDE; | 46 virtual void Stop() OVERRIDE; |
44 virtual scoped_refptr<VideoFrame> GetDecodeOutput() OVERRIDE; | 47 virtual scoped_refptr<VideoFrame> GetDecodeOutput() OVERRIDE; |
| 48 virtual int GetMaxDecodeRequests() const OVERRIDE; |
45 | 49 |
46 // Holds the next init/decode/reset callback from firing. | 50 // Holds the next init/decode/reset callback from firing. |
47 void HoldNextInit(); | 51 void HoldNextInit(); |
48 void HoldNextDecode(); | 52 void HoldDecode(); |
49 void HoldNextReset(); | 53 void HoldNextReset(); |
50 | 54 |
51 // Satisfies the pending init/decode/reset callback, which must be ready to | 55 // Satisfies the pending init/decode/reset callback, which must be ready to |
52 // fire when these methods are called. | 56 // fire when these methods are called. |
53 void SatisfyInit(); | 57 void SatisfyInit(); |
54 void SatisfyDecode(); | 58 void SatisfyDecode(); |
55 void SatisfyReset(); | 59 void SatisfyReset(); |
56 | 60 |
| 61 // Satisfies single decode request. |
| 62 void SatisfySingleDecode(); |
| 63 |
| 64 void SimulateError(); |
| 65 |
57 int total_bytes_decoded() const { return total_bytes_decoded_; } | 66 int total_bytes_decoded() const { return total_bytes_decoded_; } |
58 | 67 |
59 private: | 68 private: |
60 enum State { | 69 enum State { |
61 UNINITIALIZED, | 70 STATE_UNINITIALIZED, |
62 NORMAL | 71 STATE_NORMAL, |
| 72 STATE_END_OF_STREAM, |
| 73 STATE_ERROR, |
63 }; | 74 }; |
64 | 75 |
65 // Callback for updating |total_bytes_decoded_|. | 76 // Callback for updating |total_bytes_decoded_|. |
66 void OnFrameDecoded(int buffer_size, | 77 void OnFrameDecoded(int buffer_size, |
67 const DecodeCB& decode_cb, | 78 const DecodeCB& decode_cb, |
68 Status status, | 79 Status status, |
69 const scoped_refptr<VideoFrame>& video_frame); | 80 const scoped_refptr<VideoFrame>& video_frame); |
70 | 81 |
| 82 // Runs |decode_cb| or puts it to |held_decode_callbacks_| depending on |
| 83 // current value of |hold_decode_|. |
| 84 void RunOrHoldDecode(const DecodeCB& decode_cb); |
| 85 |
| 86 // Runs |decode_cb| with a frame from |decoded_frames_|. |
| 87 void RunDecodeCallback(const DecodeCB& decode_cb); |
| 88 |
71 void DoReset(); | 89 void DoReset(); |
72 | 90 |
73 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 91 base::ThreadChecker thread_checker_; |
74 | 92 |
75 const int decoding_delay_; | 93 const size_t decoding_delay_; |
76 | 94 const bool supports_get_decode_output_; |
77 bool supports_get_decode_output_; | 95 const int max_parallel_decoding_requests_; |
78 | 96 |
79 State state_; | 97 State state_; |
80 | 98 |
81 CallbackHolder<PipelineStatusCB> init_cb_; | 99 CallbackHolder<PipelineStatusCB> init_cb_; |
82 CallbackHolder<DecodeCB> decode_cb_; | |
83 CallbackHolder<base::Closure> reset_cb_; | 100 CallbackHolder<base::Closure> reset_cb_; |
84 | 101 |
| 102 bool hold_decode_; |
| 103 std::list<DecodeCB> held_decode_callbacks_; |
| 104 |
85 VideoDecoderConfig current_config_; | 105 VideoDecoderConfig current_config_; |
86 | 106 |
87 std::list<scoped_refptr<VideoFrame> > decoded_frames_; | 107 std::list<scoped_refptr<VideoFrame> > decoded_frames_; |
88 | 108 |
89 int total_bytes_decoded_; | 109 int total_bytes_decoded_; |
90 | 110 |
91 // NOTE: Weak pointers must be invalidated before all other member variables. | 111 // NOTE: Weak pointers must be invalidated before all other member variables. |
92 base::WeakPtrFactory<FakeVideoDecoder> weak_factory_; | 112 base::WeakPtrFactory<FakeVideoDecoder> weak_factory_; |
93 | 113 |
94 DISALLOW_COPY_AND_ASSIGN(FakeVideoDecoder); | 114 DISALLOW_COPY_AND_ASSIGN(FakeVideoDecoder); |
95 }; | 115 }; |
96 | 116 |
97 } // namespace media | 117 } // namespace media |
98 | 118 |
99 #endif // MEDIA_FILTERS_FAKE_VIDEO_DECODER_H_ | 119 #endif // MEDIA_FILTERS_FAKE_VIDEO_DECODER_H_ |
OLD | NEW |