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

Side by Side Diff: media/video/ffmpeg_video_decode_engine_unittest.cc

Issue 7932005: Reland r101418: Fix aspect ratio and clarify video frame dimensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 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 | « media/video/ffmpeg_video_decode_engine.cc ('k') | media/video/video_decode_engine.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) 2011 The Chromium Authors. All rights reserved. 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 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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "media/base/data_buffer.h" 7 #include "media/base/data_buffer.h"
8 #include "media/base/mock_task.h" 8 #include "media/base/mock_task.h"
9 #include "media/base/pipeline.h" 9 #include "media/base/pipeline.h"
10 #include "media/base/test_data_util.h" 10 #include "media/base/test_data_util.h"
11 #include "media/filters/ffmpeg_glue.h" 11 #include "media/filters/ffmpeg_glue.h"
12 #include "media/video/ffmpeg_video_decode_engine.h" 12 #include "media/video/ffmpeg_video_decode_engine.h"
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 using ::testing::_; 16 using ::testing::_;
17 using ::testing::DoAll; 17 using ::testing::DoAll;
18 using ::testing::Return; 18 using ::testing::Return;
19 using ::testing::ReturnNull; 19 using ::testing::ReturnNull;
20 using ::testing::SaveArg; 20 using ::testing::SaveArg;
21 using ::testing::SetArgumentPointee; 21 using ::testing::SetArgumentPointee;
22 using ::testing::StrictMock; 22 using ::testing::StrictMock;
23 23
24 namespace media { 24 namespace media {
25 25
26 static const size_t kWidth = 320; 26 static const gfx::Size kCodedSize(320, 240);
27 static const size_t kHeight = 240; 27 static const gfx::Rect kVisibleRect(320, 240);
28 static const size_t kSurfaceWidth = 522; 28 static const gfx::Size kNaturalSize(522, 288);
29 static const size_t kSurfaceHeight = 288;
30 static const AVRational kFrameRate = { 100, 1 }; 29 static const AVRational kFrameRate = { 100, 1 };
31 30
32 ACTION_P2(DemuxComplete, engine, buffer) { 31 ACTION_P2(DemuxComplete, engine, buffer) {
33 engine->ConsumeVideoSample(buffer); 32 engine->ConsumeVideoSample(buffer);
34 } 33 }
35 34
36 class FFmpegVideoDecodeEngineTest 35 class FFmpegVideoDecodeEngineTest
37 : public testing::Test, 36 : public testing::Test,
38 public VideoDecodeEngine::EventHandler { 37 public VideoDecodeEngine::EventHandler {
39 public: 38 public:
40 FFmpegVideoDecodeEngineTest() 39 FFmpegVideoDecodeEngineTest()
41 : config_(kCodecVP8, kWidth, kHeight, kSurfaceWidth, kSurfaceHeight, 40 : config_(kCodecVP8, kCodedSize, kVisibleRect, kNaturalSize,
42 kFrameRate.num, kFrameRate.den, NULL, 0) { 41 kFrameRate.num, kFrameRate.den, NULL, 0) {
43 CHECK(FFmpegGlue::GetInstance()); 42 CHECK(FFmpegGlue::GetInstance());
44 43
45 // Setup FFmpeg structures. 44 // Setup FFmpeg structures.
46 frame_buffer_.reset(new uint8[kWidth * kHeight]); 45 frame_buffer_.reset(new uint8[kCodedSize.GetArea()]);
47 46
48 test_engine_.reset(new FFmpegVideoDecodeEngine()); 47 test_engine_.reset(new FFmpegVideoDecodeEngine());
49 48
50 ReadTestDataFile("vp8-I-frame-320x240", &i_frame_buffer_); 49 ReadTestDataFile("vp8-I-frame-320x240", &i_frame_buffer_);
51 ReadTestDataFile("vp8-corrupt-I-frame", &corrupt_i_frame_buffer_); 50 ReadTestDataFile("vp8-corrupt-I-frame", &corrupt_i_frame_buffer_);
52 51
53 end_of_stream_buffer_ = new DataBuffer(0); 52 end_of_stream_buffer_ = new DataBuffer(0);
54 } 53 }
55 54
56 ~FFmpegVideoDecodeEngineTest() { 55 ~FFmpegVideoDecodeEngineTest() {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 .WillOnce(DemuxComplete(test_engine_.get(), buffer)) 97 .WillOnce(DemuxComplete(test_engine_.get(), buffer))
99 .WillRepeatedly(DemuxComplete(test_engine_.get(), 98 .WillRepeatedly(DemuxComplete(test_engine_.get(),
100 end_of_stream_buffer_)); 99 end_of_stream_buffer_));
101 100
102 EXPECT_CALL(*this, ConsumeVideoFrame(_, _)) 101 EXPECT_CALL(*this, ConsumeVideoFrame(_, _))
103 .WillOnce(SaveArg<0>(&video_frame_a)) 102 .WillOnce(SaveArg<0>(&video_frame_a))
104 .WillOnce(SaveArg<0>(&video_frame_b)); 103 .WillOnce(SaveArg<0>(&video_frame_b));
105 CallProduceVideoFrame(); 104 CallProduceVideoFrame();
106 CallProduceVideoFrame(); 105 CallProduceVideoFrame();
107 106
108 EXPECT_EQ(kSurfaceWidth, video_frame_a->width()); 107 size_t expected_width = static_cast<size_t>(kVisibleRect.width());
109 EXPECT_EQ(kSurfaceHeight, video_frame_a->height()); 108 size_t expected_height = static_cast<size_t>(kVisibleRect.height());
110 EXPECT_EQ(kSurfaceWidth, video_frame_b->width()); 109
111 EXPECT_EQ(kSurfaceHeight, video_frame_b->height()); 110 EXPECT_EQ(expected_width, video_frame_a->width());
111 EXPECT_EQ(expected_height, video_frame_a->height());
112 EXPECT_EQ(expected_width, video_frame_b->width());
113 EXPECT_EQ(expected_height, video_frame_b->height());
112 } 114 }
113 115
114 // VideoDecodeEngine::EventHandler implementation. 116 // VideoDecodeEngine::EventHandler implementation.
115 MOCK_METHOD2(ConsumeVideoFrame, 117 MOCK_METHOD2(ConsumeVideoFrame,
116 void(scoped_refptr<VideoFrame> video_frame, 118 void(scoped_refptr<VideoFrame> video_frame,
117 const PipelineStatistics& statistics)); 119 const PipelineStatistics& statistics));
118 MOCK_METHOD1(ProduceVideoSample, 120 MOCK_METHOD1(ProduceVideoSample,
119 void(scoped_refptr<Buffer> buffer)); 121 void(scoped_refptr<Buffer> buffer));
120 MOCK_METHOD1(OnInitializeComplete, 122 MOCK_METHOD1(OnInitializeComplete,
121 void(const VideoCodecInfo& info)); 123 void(const VideoCodecInfo& info));
122 MOCK_METHOD0(OnUninitializeComplete, void()); 124 MOCK_METHOD0(OnUninitializeComplete, void());
123 MOCK_METHOD0(OnFlushComplete, void()); 125 MOCK_METHOD0(OnFlushComplete, void());
124 MOCK_METHOD0(OnSeekComplete, void()); 126 MOCK_METHOD0(OnSeekComplete, void());
125 MOCK_METHOD0(OnError, void()); 127 MOCK_METHOD0(OnError, void());
126 128
127 void CallProduceVideoFrame() { 129 void CallProduceVideoFrame() {
128 test_engine_->ProduceVideoFrame(VideoFrame::CreateFrame(VideoFrame::YV12, 130 test_engine_->ProduceVideoFrame(VideoFrame::CreateFrame(
129 kWidth, 131 VideoFrame::YV12, kVisibleRect.width(), kVisibleRect.height(),
130 kHeight, 132 kNoTimestamp, kNoTimestamp));
131 kNoTimestamp,
132 kNoTimestamp));
133 } 133 }
134 134
135 protected: 135 protected:
136 VideoDecoderConfig config_; 136 VideoDecoderConfig config_;
137 scoped_ptr<FFmpegVideoDecodeEngine> test_engine_; 137 scoped_ptr<FFmpegVideoDecodeEngine> test_engine_;
138 scoped_array<uint8_t> frame_buffer_; 138 scoped_array<uint8_t> frame_buffer_;
139 scoped_refptr<Buffer> i_frame_buffer_; 139 scoped_refptr<Buffer> i_frame_buffer_;
140 scoped_refptr<Buffer> corrupt_i_frame_buffer_; 140 scoped_refptr<Buffer> corrupt_i_frame_buffer_;
141 scoped_refptr<Buffer> end_of_stream_buffer_; 141 scoped_refptr<Buffer> end_of_stream_buffer_;
142 142
143 private: 143 private:
144 DISALLOW_COPY_AND_ASSIGN(FFmpegVideoDecodeEngineTest); 144 DISALLOW_COPY_AND_ASSIGN(FFmpegVideoDecodeEngineTest);
145 }; 145 };
146 146
147 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_Normal) { 147 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_Normal) {
148 Initialize(); 148 Initialize();
149 } 149 }
150 150
151 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_FindDecoderFails) { 151 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_FindDecoderFails) {
152 VideoDecoderConfig config(kUnknown, kWidth, kHeight, kSurfaceWidth, 152 VideoDecoderConfig config(kUnknown, kCodedSize, kVisibleRect, kNaturalSize,
153 kSurfaceHeight, kFrameRate.num, kFrameRate.den, 153 kFrameRate.num, kFrameRate.den, NULL, 0);
154 NULL, 0);
155 // Test avcodec_find_decoder() returning NULL. 154 // Test avcodec_find_decoder() returning NULL.
156 VideoCodecInfo info; 155 VideoCodecInfo info;
157 EXPECT_CALL(*this, OnInitializeComplete(_)) 156 EXPECT_CALL(*this, OnInitializeComplete(_))
158 .WillOnce(SaveArg<0>(&info)); 157 .WillOnce(SaveArg<0>(&info));
159 test_engine_->Initialize(MessageLoop::current(), this, NULL, config); 158 test_engine_->Initialize(MessageLoop::current(), this, NULL, config);
160 EXPECT_FALSE(info.success); 159 EXPECT_FALSE(info.success);
161 } 160 }
162 161
163 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_OpenDecoderFails) { 162 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_OpenDecoderFails) {
164 // Specify Theora w/o extra data so that avcodec_open() fails. 163 // Specify Theora w/o extra data so that avcodec_open() fails.
165 VideoDecoderConfig config(kCodecTheora, kWidth, kHeight, kSurfaceWidth, 164 VideoDecoderConfig config(kCodecTheora, kCodedSize, kVisibleRect,
166 kSurfaceHeight, kFrameRate.num, kFrameRate.den, 165 kNaturalSize, kFrameRate.num, kFrameRate.den,
167 NULL, 0); 166 NULL, 0);
168 VideoCodecInfo info; 167 VideoCodecInfo info;
169 EXPECT_CALL(*this, OnInitializeComplete(_)) 168 EXPECT_CALL(*this, OnInitializeComplete(_))
170 .WillOnce(SaveArg<0>(&info)); 169 .WillOnce(SaveArg<0>(&info));
171 test_engine_->Initialize(MessageLoop::current(), this, NULL, config); 170 test_engine_->Initialize(MessageLoop::current(), this, NULL, config);
172 EXPECT_FALSE(info.success); 171 EXPECT_FALSE(info.success);
173 } 172 }
174 173
175 TEST_F(FFmpegVideoDecodeEngineTest, DecodeFrame_Normal) { 174 TEST_F(FFmpegVideoDecodeEngineTest, DecodeFrame_Normal) {
176 Initialize(); 175 Initialize();
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 // DecodeIFrameThenTestFile("vp8-I-frame-320x480"); 274 // DecodeIFrameThenTestFile("vp8-I-frame-320x480");
276 //} 275 //}
277 276
278 // Decode |i_frame_buffer_| and then a frame with a smaller height and verify 277 // Decode |i_frame_buffer_| and then a frame with a smaller height and verify
279 // the output size didn't change. 278 // the output size didn't change.
280 TEST_F(FFmpegVideoDecodeEngineTest, DecodeFrame_SmallerHeight) { 279 TEST_F(FFmpegVideoDecodeEngineTest, DecodeFrame_SmallerHeight) {
281 DecodeIFrameThenTestFile("vp8-I-frame-320x120"); 280 DecodeIFrameThenTestFile("vp8-I-frame-320x120");
282 } 281 }
283 282
284 } // namespace media 283 } // namespace media
OLDNEW
« no previous file with comments | « media/video/ffmpeg_video_decode_engine.cc ('k') | media/video/video_decode_engine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698