OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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 #include <deque> | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/memory/singleton.h" | |
9 #include "base/string_util.h" | |
10 #include "media/base/data_buffer.h" | |
11 #include "media/base/filters.h" | |
12 #include "media/base/limits.h" | |
13 #include "media/base/mock_callback.h" | |
14 #include "media/base/mock_filter_host.h" | |
15 #include "media/base/mock_filters.h" | |
16 #include "media/base/mock_task.h" | |
17 #include "media/base/video_frame.h" | |
18 #include "media/filters/rtc_video_decoder.h" | |
19 #include "testing/gtest/include/gtest/gtest.h" | |
20 | |
21 using ::testing::_; | |
22 using ::testing::AnyNumber; | |
23 using ::testing::DoAll; | |
24 using ::testing::Message; | |
25 using ::testing::Return; | |
26 using ::testing::ReturnNull; | |
27 using ::testing::SetArgumentPointee; | |
28 using ::testing::StrictMock; | |
29 using ::testing::WithArg; | |
30 using ::testing::Invoke; | |
31 | |
32 namespace media { | |
33 | |
34 class RTCVideoDecoderTest : public testing::Test { | |
35 protected: | |
36 static const int kWidth; | |
37 static const int kHeight; | |
38 static const char* kUrl; | |
39 static const PipelineStatistics kStatistics; | |
40 | |
41 RTCVideoDecoderTest() { | |
42 MediaFormat media_format; | |
43 decoder_ = new RTCVideoDecoder(&message_loop_, kUrl); | |
44 renderer_ = new MockVideoRenderer(); | |
45 | |
46 DCHECK(decoder_); | |
47 | |
48 // Inject mocks and prepare a demuxer stream. | |
49 decoder_->set_host(&host_); | |
50 | |
51 EXPECT_CALL(stats_callback_object_, OnStatistics(_)) | |
52 .Times(AnyNumber()); | |
53 } | |
54 | |
55 virtual ~RTCVideoDecoderTest() { | |
56 // Finish up any remaining tasks. | |
57 message_loop_.RunAllPending(); | |
58 } | |
59 | |
60 void InitializeDecoderSuccessfully() { | |
61 // Test successful initialization. | |
62 decoder_->Initialize(NULL, | |
63 NewExpectedCallback(), NewStatisticsCallback()); | |
64 message_loop_.RunAllPending(); | |
65 } | |
66 | |
67 StatisticsCallback* NewStatisticsCallback() { | |
68 return NewCallback(&stats_callback_object_, | |
69 &MockStatisticsCallback::OnStatistics); | |
70 } | |
71 | |
72 // Fixture members. | |
73 scoped_refptr<RTCVideoDecoder> decoder_; | |
74 scoped_refptr<MockVideoRenderer> renderer_; | |
75 MockStatisticsCallback stats_callback_object_; | |
76 StrictMock<MockFilterHost> host_; | |
77 MessageLoop message_loop_; | |
78 | |
79 private: | |
80 DISALLOW_COPY_AND_ASSIGN(RTCVideoDecoderTest); | |
81 }; | |
82 | |
83 const int RTCVideoDecoderTest::kWidth = 176; | |
84 const int RTCVideoDecoderTest::kHeight = 144; | |
85 const char* RTCVideoDecoderTest::kUrl = "media://remote/0"; | |
86 const PipelineStatistics RTCVideoDecoderTest::kStatistics; | |
87 | |
88 TEST_F(RTCVideoDecoderTest, Initialize_Successful) { | |
89 InitializeDecoderSuccessfully(); | |
90 | |
91 // Test that the output media format is an uncompressed video surface that | |
92 // matches the dimensions specified by rtc. | |
93 const MediaFormat& media_format = decoder_->media_format(); | |
94 int width = 0; | |
95 int height = 0; | |
96 EXPECT_TRUE(media_format.GetAsInteger(MediaFormat::kWidth, &width)); | |
97 EXPECT_EQ(kWidth, width); | |
98 EXPECT_TRUE(media_format.GetAsInteger(MediaFormat::kHeight, &height)); | |
99 EXPECT_EQ(kHeight, height); | |
100 } | |
101 | |
102 TEST_F(RTCVideoDecoderTest, DoSeek) { | |
103 const base::TimeDelta kZero; | |
104 | |
105 InitializeDecoderSuccessfully(); | |
106 | |
107 decoder_->set_consume_video_frame_callback( | |
108 base::Bind(&MockVideoRenderer::ConsumeVideoFrame, | |
109 base::Unretained(renderer_.get()))); | |
110 | |
111 // Expect Seek and verify the results. | |
112 EXPECT_CALL(*renderer_.get(), ConsumeVideoFrame(_)) | |
113 .Times(Limits::kMaxVideoFrames); | |
114 decoder_->Seek(kZero, NewExpectedStatusCB(PIPELINE_OK)); | |
115 | |
116 message_loop_.RunAllPending(); | |
117 EXPECT_EQ(RTCVideoDecoder::kNormal, decoder_->state_); | |
118 } | |
119 | |
120 TEST_F(RTCVideoDecoderTest, DoDeliverFrame) { | |
121 const base::TimeDelta kZero; | |
122 EXPECT_CALL(host_, GetTime()).WillRepeatedly(Return(base::TimeDelta())); | |
123 | |
124 InitializeDecoderSuccessfully(); | |
125 | |
126 // Pass the frame back to decoder | |
127 decoder_->set_consume_video_frame_callback( | |
128 base::Bind(&RTCVideoDecoder::ProduceVideoFrame, | |
129 base::Unretained(decoder_.get()))); | |
130 decoder_->Seek(kZero, NewExpectedStatusCB(PIPELINE_OK)); | |
131 | |
132 decoder_->set_consume_video_frame_callback( | |
133 base::Bind(&MockVideoRenderer::ConsumeVideoFrame, | |
134 base::Unretained(renderer_.get()))); | |
135 EXPECT_CALL(*renderer_.get(), ConsumeVideoFrame(_)) | |
136 .Times(Limits::kMaxVideoFrames); | |
137 | |
138 unsigned int video_frame_size = decoder_->width_*decoder_->height_*3/2; | |
139 unsigned char* video_frame = new unsigned char[video_frame_size]; | |
140 | |
141 for (size_t i = 0; i < Limits::kMaxVideoFrames; ++i) { | |
142 decoder_->DeliverFrame(video_frame, video_frame_size); | |
143 } | |
144 delete [] video_frame; | |
145 | |
146 message_loop_.RunAllPending(); | |
147 EXPECT_EQ(RTCVideoDecoder::kNormal, decoder_->state_); | |
148 } | |
149 | |
150 TEST_F(RTCVideoDecoderTest, DoFrameSizeChange) { | |
151 InitializeDecoderSuccessfully(); | |
152 | |
153 int new_width = kWidth * 2; | |
154 int new_height = kHeight * 2; | |
155 int new_number_of_streams = 0; | |
156 | |
157 EXPECT_CALL(host_, | |
158 SetVideoSize(new_width, new_height)).WillRepeatedly(Return()); | |
159 | |
160 decoder_->FrameSizeChange(new_width, new_height, new_number_of_streams); | |
161 | |
162 const MediaFormat& media_format = decoder_->media_format(); | |
163 int width = 0; | |
164 int height = 0; | |
165 EXPECT_TRUE(media_format.GetAsInteger(MediaFormat::kWidth, &width)); | |
166 EXPECT_EQ(new_width, width); | |
167 EXPECT_TRUE(media_format.GetAsInteger(MediaFormat::kHeight, &height)); | |
168 EXPECT_EQ(new_height, height); | |
169 | |
170 message_loop_.RunAllPending(); | |
171 } | |
172 | |
173 | |
174 } // namespace media | |
OLD | NEW |