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

Side by Side Diff: media/filters/fake_video_decoder.h

Issue 15085011: Add FakeVideoDecoder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_FILTERS_FAKE_VIDEO_DECODER_H_
6 #define MEDIA_FILTERS_FAKE_VIDEO_DECODER_H_
7
8 #include <list>
9
10 #include "base/bind.h"
11 #include "base/callback.h"
12 #include "base/memory/weak_ptr.h"
13 #include "media/base/decoder_buffer.h"
14 #include "media/base/demuxer_stream.h"
15 #include "media/base/media_export.h"
16 #include "media/base/pipeline_status.h"
17 #include "media/base/video_decoder.h"
18 #include "media/base/video_decoder_config.h"
19 #include "media/base/video_frame.h"
20 #include "ui/gfx/size.h"
21
22 namespace base {
23 class MessageLoopProxy;
24 }
25
26 namespace media {
27
28 class MEDIA_EXPORT FakeVideoDecoder : public VideoDecoder {
29 public:
30 // Constructs an object with a decoding delay of |decoding_delay| frames.
31 explicit FakeVideoDecoder(int decoding_delay);
32 virtual ~FakeVideoDecoder();
33
34 // VideoDecoder implementation.
35 virtual void Initialize(DemuxerStream* stream,
36 const PipelineStatusCB& status_cb,
37 const StatisticsCB& statistics_cb) OVERRIDE;
38 virtual void Read(const ReadCB& read_cb) OVERRIDE;
39 virtual void Reset(const base::Closure& closure) OVERRIDE;
40 virtual void Stop(const base::Closure& closure) OVERRIDE;
41
42 // Holds the next read/reset/stop callback from firing.
43 void HoldNextRead();
44 void HoldNextReset();
45 void HoldNextStop();
46
47 // Satisfies the pending read/reset/stop callback, which must be ready to fire
48 // when these methods are called.
49 void SatisfyRead();
50 void SatisfyReset();
51 void SatisfyStop();
52
53 private:
54 enum State {
55 UNINITIALIZED,
56 NORMAL
57 };
58
59 // A helper class that can hold a callback from being fired.
60 template <typename CB> class CallbackHolder {
scherkus (not reviewing) 2013/05/09 20:07:09 this is complex enough that I feel it should warra
xhwang 2013/05/22 04:29:42 Done.
61 public:
62 CallbackHolder() : hold_callback_(false) {}
63
64 ~CallbackHolder() {
65 // Make sure all callbacks are satisfied!
66 DCHECK(!hold_callback_);
67 DCHECK(original_cb_.is_null());
68 DCHECK(held_cb_.is_null());
69 }
70
71 // Sets the callback to be potentially held.
72 void SetCallback(const CB& cb) {
73 DCHECK(original_cb_.is_null());
74 DCHECK(held_cb_.is_null());
75 original_cb_ = cb;
76 }
77
78 bool is_null() const {
79 return original_cb_.is_null() && held_cb_.is_null();
80 }
81
82 // Holds the callback when Run() is called.
83 void HoldCallback() { hold_callback_ = true; }
84
85 // Runs or holds the callback as specified by |hold_next_callback_|.
scherkus (not reviewing) 2013/05/09 20:07:09 s/hold_next_callback_/hold_callback_/
xhwang 2013/05/22 04:29:42 Done.
86 // This method has overloaded versions to support different types of CB.
87 void Run() {
scherkus (not reviewing) 2013/05/09 20:07:09 I don't like how CH emulates the regular API but d
xhwang 2013/05/22 04:29:42 Done.
88 DCHECK(held_cb_.is_null());
89 if (hold_callback_)
90 held_cb_ = base::Bind(ResetAndReturn(&original_cb_));
scherkus (not reviewing) 2013/05/09 20:07:09 nit: base::Bind() not needed
xhwang 2013/05/22 04:29:42 Done.
91 else
92 ResetAndReturn(&original_cb_).Run();
93 }
94
95 template <typename A1, typename A2> void Run(A1 a1, A2 a2) {
96 if (hold_callback_)
97 held_cb_ =
98 base::Bind(ResetAndReturn(&original_cb_), a1, a2);
99 else
100 ResetAndReturn(&original_cb_).Run(a1, a2);
101 }
102
103 // Releases and runs the held callback.
104 void Release() {
scherkus (not reviewing) 2013/05/09 20:07:09 RunHeldCallback()?
xhwang 2013/05/22 04:29:42 Done.
105 DCHECK(hold_callback_);
106 DCHECK(!held_cb_.is_null());
107 hold_callback_ = false;
108 ResetAndReturn(&held_cb_).Run();
109 }
110
111 private:
112 bool hold_callback_;
113 CB original_cb_;
114 base::Closure held_cb_;
115 };
116
117 void ReadFromDemuxerStream();
118
119 // Callback for DemuxerStream::Read().
120 void BufferReady(DemuxerStream::Status status,
121 const scoped_refptr<DecoderBuffer>& buffer);
122
123 void DoReset();
124 void DoStop();
125
126 scoped_refptr<base::MessageLoopProxy> message_loop_;
127 base::WeakPtrFactory<FakeVideoDecoder> weak_factory_;
128 base::WeakPtr<FakeVideoDecoder> weak_this_;
129
130 const int decoding_delay_;
131
132 State state_;
133
134 StatisticsCB statistics_cb_;
135 CallbackHolder<ReadCB> read_cb_;
136 CallbackHolder<base::Closure> reset_cb_;
137 CallbackHolder<base::Closure> stop_cb_;
138
139 // Pointer to the demuxer stream that will feed us compressed buffers.
140 DemuxerStream* demuxer_stream_;
141
142 VideoDecoderConfig current_config_;
143
144 std::list<scoped_refptr<VideoFrame> > decoded_frames_;
145
146 DISALLOW_COPY_AND_ASSIGN(FakeVideoDecoder);
147 };
148
149 } // namespace media
150
151 #endif // MEDIA_FILTERS_FAKE_VIDEO_DECODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698