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

Side by Side Diff: content/renderer/media/rtc_video_decoder_unittest.cc

Issue 10248002: Report VideoDecoder status through ReadCB instead of through FilterHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename VideoDecoder::Status to VideoDecoder::DecoderStatus since Status has been polluted by Xlib.h. Created 8 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
« no previous file with comments | « content/renderer/media/rtc_video_decoder.cc ('k') | media/base/filters.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "content/renderer/media/rtc_video_decoder.h" 5 #include "content/renderer/media/rtc_video_decoder.h"
6 6
7 #include <deque> 7 #include <deque>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "media/base/data_buffer.h" 13 #include "media/base/data_buffer.h"
14 #include "media/base/filters.h" 14 #include "media/base/filters.h"
15 #include "media/base/limits.h" 15 #include "media/base/limits.h"
16 #include "media/base/mock_callback.h" 16 #include "media/base/mock_callback.h"
17 #include "media/base/mock_filter_host.h"
18 #include "media/base/mock_filters.h" 17 #include "media/base/mock_filters.h"
19 #include "media/base/video_frame.h" 18 #include "media/base/video_frame.h"
20 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
21 #include "third_party/libjingle/source/talk/session/phone/videoframe.h" 20 #include "third_party/libjingle/source/talk/session/phone/videoframe.h"
22 21
23 using ::testing::_; 22 using ::testing::_;
24 using ::testing::AnyNumber; 23 using ::testing::AnyNumber;
25 using ::testing::DoAll; 24 using ::testing::DoAll;
26 using ::testing::Message; 25 using ::testing::Message;
27 using ::testing::Return; 26 using ::testing::Return;
28 using ::testing::ReturnNull; 27 using ::testing::ReturnNull;
29 using ::testing::SetArgumentPointee; 28 using ::testing::SetArgumentPointee;
30 using ::testing::StrictMock; 29 using ::testing::StrictMock;
31 using ::testing::WithArg; 30 using ::testing::WithArg;
32 using ::testing::Invoke; 31 using ::testing::Invoke;
33 using media::MockStatisticsCB; 32 using media::MockStatisticsCB;
34 using media::MockVideoRenderer; 33 using media::MockVideoRenderer;
35 using media::MockFilterHost;
36 using media::NewExpectedClosure; 34 using media::NewExpectedClosure;
37 using media::NewExpectedStatusCB; 35 using media::NewExpectedStatusCB;
38 using media::PipelineStatistics; 36 using media::PipelineStatistics;
39 using media::PIPELINE_OK; 37 using media::PIPELINE_OK;
40 using media::StatisticsCB; 38 using media::StatisticsCB;
41 39
42 namespace { 40 namespace {
43 41
44 class NullVideoFrame : public cricket::VideoFrame { 42 class NullVideoFrame : public cricket::VideoFrame {
45 public: 43 public:
46 NullVideoFrame() {}; 44 NullVideoFrame() {}
47 virtual ~NullVideoFrame() {}; 45 virtual ~NullVideoFrame() {}
48 46
49 virtual bool Reset(uint32 fourcc, int w, int h, int dw, int dh, 47 virtual bool Reset(uint32 fourcc, int w, int h, int dw, int dh,
50 uint8 *sample, size_t sample_size, 48 uint8 *sample, size_t sample_size,
51 size_t pixel_width, size_t pixel_height, 49 size_t pixel_width, size_t pixel_height,
52 int64 elapsed_time, int64 time_stamp, int rotation) 50 int64 elapsed_time, int64 time_stamp, int rotation)
53 OVERRIDE { 51 OVERRIDE {
54 return true; 52 return true;
55 } 53 }
56 54
57 virtual size_t GetWidth() const OVERRIDE { return 0; } 55 virtual size_t GetWidth() const OVERRIDE { return 0; }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 static const PipelineStatistics kStatistics; 126 static const PipelineStatistics kStatistics;
129 127
130 RTCVideoDecoderTest() { 128 RTCVideoDecoderTest() {
131 decoder_ = new RTCVideoDecoder(&message_loop_, kUrl); 129 decoder_ = new RTCVideoDecoder(&message_loop_, kUrl);
132 renderer_ = new MockVideoRenderer(); 130 renderer_ = new MockVideoRenderer();
133 read_cb_ = base::Bind(&RTCVideoDecoderTest::FrameReady, 131 read_cb_ = base::Bind(&RTCVideoDecoderTest::FrameReady,
134 base::Unretained(this)); 132 base::Unretained(this));
135 133
136 DCHECK(decoder_); 134 DCHECK(decoder_);
137 135
138 // Inject mocks and prepare a demuxer stream.
139 decoder_->set_host(&host_);
140
141 EXPECT_CALL(stats_callback_object_, OnStatistics(_)) 136 EXPECT_CALL(stats_callback_object_, OnStatistics(_))
142 .Times(AnyNumber()); 137 .Times(AnyNumber());
143 } 138 }
144 139
145 virtual ~RTCVideoDecoderTest() { 140 virtual ~RTCVideoDecoderTest() {
146 // Finish up any remaining tasks. 141 // Finish up any remaining tasks.
147 message_loop_.RunAllPending(); 142 message_loop_.RunAllPending();
148 } 143 }
149 144
150 void InitializeDecoderSuccessfully() { 145 void InitializeDecoderSuccessfully() {
151 // Test successful initialization. 146 // Test successful initialization.
152 decoder_->Initialize( 147 decoder_->Initialize(
153 NULL, NewExpectedStatusCB(PIPELINE_OK), NewStatisticsCB()); 148 NULL, NewExpectedStatusCB(PIPELINE_OK), NewStatisticsCB());
154 message_loop_.RunAllPending(); 149 message_loop_.RunAllPending();
155 } 150 }
156 151
157 StatisticsCB NewStatisticsCB() { 152 StatisticsCB NewStatisticsCB() {
158 return base::Bind(&MockStatisticsCB::OnStatistics, 153 return base::Bind(&MockStatisticsCB::OnStatistics,
159 base::Unretained(&stats_callback_object_)); 154 base::Unretained(&stats_callback_object_));
160 } 155 }
161 156
162 MOCK_METHOD1(FrameReady, void(scoped_refptr<media::VideoFrame>)); 157 MOCK_METHOD2(FrameReady, void(media::VideoDecoder::DecoderStatus status,
158 scoped_refptr<media::VideoFrame>));
163 159
164 // Fixture members. 160 // Fixture members.
165 scoped_refptr<RTCVideoDecoder> decoder_; 161 scoped_refptr<RTCVideoDecoder> decoder_;
166 scoped_refptr<MockVideoRenderer> renderer_; 162 scoped_refptr<MockVideoRenderer> renderer_;
167 MockStatisticsCB stats_callback_object_; 163 MockStatisticsCB stats_callback_object_;
168 StrictMock<MockFilterHost> host_;
169 MessageLoop message_loop_; 164 MessageLoop message_loop_;
170 media::VideoDecoder::ReadCB read_cb_; 165 media::VideoDecoder::ReadCB read_cb_;
171 166
172 private: 167 private:
173 DISALLOW_COPY_AND_ASSIGN(RTCVideoDecoderTest); 168 DISALLOW_COPY_AND_ASSIGN(RTCVideoDecoderTest);
174 }; 169 };
175 170
176 const int RTCVideoDecoderTest::kWidth = 640; 171 const int RTCVideoDecoderTest::kWidth = 640;
177 const int RTCVideoDecoderTest::kHeight = 480; 172 const int RTCVideoDecoderTest::kHeight = 480;
178 const char* RTCVideoDecoderTest::kUrl = "media://remote/0"; 173 const char* RTCVideoDecoderTest::kUrl = "media://remote/0";
(...skipping 18 matching lines...) Expand all
197 192
198 message_loop_.RunAllPending(); 193 message_loop_.RunAllPending();
199 EXPECT_EQ(RTCVideoDecoder::kNormal, decoder_->state_); 194 EXPECT_EQ(RTCVideoDecoder::kNormal, decoder_->state_);
200 } 195 }
201 196
202 TEST_F(RTCVideoDecoderTest, DoFlush) { 197 TEST_F(RTCVideoDecoderTest, DoFlush) {
203 const base::TimeDelta kZero; 198 const base::TimeDelta kZero;
204 199
205 InitializeDecoderSuccessfully(); 200 InitializeDecoderSuccessfully();
206 201
207 EXPECT_CALL(*this, FrameReady(_)); 202 EXPECT_CALL(*this, FrameReady(media::VideoDecoder::kOk, _));
208 decoder_->Read(read_cb_); 203 decoder_->Read(read_cb_);
209 decoder_->Pause(media::NewExpectedClosure()); 204 decoder_->Pause(media::NewExpectedClosure());
210 decoder_->Flush(media::NewExpectedClosure()); 205 decoder_->Flush(media::NewExpectedClosure());
211 206
212 message_loop_.RunAllPending(); 207 message_loop_.RunAllPending();
213 EXPECT_EQ(RTCVideoDecoder::kPaused, decoder_->state_); 208 EXPECT_EQ(RTCVideoDecoder::kPaused, decoder_->state_);
214 } 209 }
215 210
216 TEST_F(RTCVideoDecoderTest, DoRenderFrame) { 211 TEST_F(RTCVideoDecoderTest, DoRenderFrame) {
217 const base::TimeDelta kZero; 212 const base::TimeDelta kZero;
218 EXPECT_CALL(host_, GetTime()).WillRepeatedly(Return(base::TimeDelta()));
219 213
220 InitializeDecoderSuccessfully(); 214 InitializeDecoderSuccessfully();
221 215
222 NullVideoFrame video_frame; 216 NullVideoFrame video_frame;
223 217
224 for (size_t i = 0; i < media::limits::kMaxVideoFrames; ++i) { 218 for (size_t i = 0; i < media::limits::kMaxVideoFrames; ++i) {
225 decoder_->RenderFrame(&video_frame); 219 decoder_->RenderFrame(&video_frame);
226 } 220 }
227 221
228 message_loop_.RunAllPending(); 222 message_loop_.RunAllPending();
229 EXPECT_EQ(RTCVideoDecoder::kNormal, decoder_->state_); 223 EXPECT_EQ(RTCVideoDecoder::kNormal, decoder_->state_);
230 } 224 }
231 225
232 TEST_F(RTCVideoDecoderTest, DoSetSize) { 226 TEST_F(RTCVideoDecoderTest, DoSetSize) {
233 InitializeDecoderSuccessfully(); 227 InitializeDecoderSuccessfully();
234 228
235 int new_width = kWidth * 2; 229 int new_width = kWidth * 2;
236 int new_height = kHeight * 2; 230 int new_height = kHeight * 2;
237 gfx::Size new_natural_size(new_width, new_height); 231 gfx::Size new_natural_size(new_width, new_height);
238 int new_reserved = 0; 232 int new_reserved = 0;
239 233
240 EXPECT_CALL(host_,
241 SetNaturalVideoSize(new_natural_size)).WillRepeatedly(Return());
242
243 decoder_->SetSize(new_width, new_height, new_reserved); 234 decoder_->SetSize(new_width, new_height, new_reserved);
244 235
245 EXPECT_EQ(new_width, decoder_->natural_size().width()); 236 EXPECT_EQ(new_width, decoder_->natural_size().width());
246 EXPECT_EQ(new_height, decoder_->natural_size().height()); 237 EXPECT_EQ(new_height, decoder_->natural_size().height());
247 238
248 message_loop_.RunAllPending(); 239 message_loop_.RunAllPending();
249 } 240 }
OLDNEW
« no previous file with comments | « content/renderer/media/rtc_video_decoder.cc ('k') | media/base/filters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698