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

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

Issue 8417019: Simplify VideoDecodeEngine interface by making everything synchronous. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix for CaptureVideoDecoder Created 9 years, 1 month 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
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/bind.h" 5 #include "base/bind.h"
6 #include "content/renderer/media/capture_video_decoder.h" 6 #include "content/renderer/media/capture_video_decoder.h"
7 #include "content/renderer/media/video_capture_impl.h" 7 #include "content/renderer/media/video_capture_impl.h"
8 #include "content/renderer/media/video_capture_impl_manager.h" 8 #include "content/renderer/media/video_capture_impl_manager.h"
9 #include "media/base/filters.h" 9 #include "media/base/filters.h"
10 #include "media/base/limits.h" 10 #include "media/base/limits.h"
11 #include "media/base/mock_callback.h" 11 #include "media/base/mock_callback.h"
12 #include "media/base/mock_filter_host.h" 12 #include "media/base/mock_filter_host.h"
13 #include "media/base/mock_filters.h" 13 #include "media/base/mock_filters.h"
14 #include "media/base/pipeline_status.h" 14 #include "media/base/pipeline_status.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 using ::testing::_; 17 using ::testing::_;
18 using ::testing::AnyNumber; 18 using ::testing::AnyNumber;
19 using ::testing::Return; 19 using ::testing::Return;
20 using ::testing::StrictMock; 20 using ::testing::StrictMock;
21 21
22 static const media::VideoCaptureSessionId kVideoStreamId = 1; 22 static const media::VideoCaptureSessionId kVideoStreamId = 1;
23 23
24 ACTION_P(ReturnFrameFromRenderer, decoder) {
25 decoder->ProduceVideoFrame(arg0);
26 }
27
28 ACTION_P3(CreateDataBufferFromCapture, decoder, vc_impl, data_buffer_number) { 24 ACTION_P3(CreateDataBufferFromCapture, decoder, vc_impl, data_buffer_number) {
29 for (int i = 0; i < data_buffer_number; i++) { 25 for (int i = 0; i < data_buffer_number; i++) {
30 media::VideoCapture::VideoFrameBuffer* buffer; 26 media::VideoCapture::VideoFrameBuffer* buffer;
31 buffer = new media::VideoCapture::VideoFrameBuffer(); 27 buffer = new media::VideoCapture::VideoFrameBuffer();
32 buffer->width = arg1.width; 28 buffer->width = arg1.width;
33 buffer->height = arg1.height; 29 buffer->height = arg1.height;
34 int length = buffer->width * buffer->height * 3 / 2; 30 int length = buffer->width * buffer->height * 3 / 2;
35 buffer->memory_pointer = new uint8[length]; 31 buffer->memory_pointer = new uint8[length];
36 buffer->buffer_size = length; 32 buffer->buffer_size = length;
37 decoder->OnBufferReady(vc_impl, buffer); 33 decoder->OnBufferReady(vc_impl, buffer);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 media::VideoCapture::VideoCaptureCapability capability; 87 media::VideoCapture::VideoCaptureCapability capability;
92 capability.width = 176; 88 capability.width = 176;
93 capability.height = 144; 89 capability.height = 144;
94 capability.max_fps = 30; 90 capability.max_fps = 30;
95 capability.expected_capture_delay = 0; 91 capability.expected_capture_delay = 0;
96 capability.raw_type = media::VideoFrame::I420; 92 capability.raw_type = media::VideoFrame::I420;
97 capability.interlaced = false; 93 capability.interlaced = false;
98 94
99 decoder_ = new CaptureVideoDecoder(message_loop_proxy_, 95 decoder_ = new CaptureVideoDecoder(message_loop_proxy_,
100 kVideoStreamId, vc_manager_, capability); 96 kVideoStreamId, vc_manager_, capability);
101 renderer_ = new media::MockVideoRenderer();
102
103 decoder_->set_host(&host_); 97 decoder_->set_host(&host_);
104 decoder_->set_consume_video_frame_callback(
105 base::Bind(&media::MockVideoRenderer::ConsumeVideoFrame,
106 base::Unretained(renderer_.get())));
107 EXPECT_CALL(statistics_callback_object_, OnStatistics(_)) 98 EXPECT_CALL(statistics_callback_object_, OnStatistics(_))
108 .Times(AnyNumber()); 99 .Times(AnyNumber());
100
101 read_cb_ = base::Bind(&CaptureVideoDecoderTest::FrameReady,
102 base::Unretained(this));
109 } 103 }
110 104
111 virtual ~CaptureVideoDecoderTest() { 105 virtual ~CaptureVideoDecoderTest() {
112 message_loop_->RunAllPending(); 106 message_loop_->RunAllPending();
113 } 107 }
114 108
115 media::StatisticsCallback NewStatisticsCallback() { 109 media::StatisticsCallback NewStatisticsCallback() {
116 return base::Bind(&media::MockStatisticsCallback::OnStatistics, 110 return base::Bind(&media::MockStatisticsCallback::OnStatistics,
117 base::Unretained(&statistics_callback_object_)); 111 base::Unretained(&statistics_callback_object_));
118 } 112 }
119 113
114 MOCK_METHOD1(FrameReady, void(scoped_refptr<media::VideoFrame>));
115
120 // Fixture members. 116 // Fixture members.
121 scoped_refptr<CaptureVideoDecoder> decoder_; 117 scoped_refptr<CaptureVideoDecoder> decoder_;
122 scoped_refptr<MockVideoCaptureImplManager> vc_manager_; 118 scoped_refptr<MockVideoCaptureImplManager> vc_manager_;
123 scoped_refptr<media::MockVideoRenderer> renderer_;
124 media::MockStatisticsCallback statistics_callback_object_; 119 media::MockStatisticsCallback statistics_callback_object_;
125 StrictMock<media::MockFilterHost> host_; 120 StrictMock<media::MockFilterHost> host_;
126 scoped_ptr<MessageLoop> message_loop_; 121 scoped_ptr<MessageLoop> message_loop_;
127 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; 122 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
123 media::VideoDecoder::ReadCB read_cb_;
128 124
129 private: 125 private:
130 DISALLOW_COPY_AND_ASSIGN(CaptureVideoDecoderTest); 126 DISALLOW_COPY_AND_ASSIGN(CaptureVideoDecoderTest);
131 }; 127 };
132 128
133 TEST_F(CaptureVideoDecoderTest, Play) { 129 TEST_F(CaptureVideoDecoderTest, Play) {
134 int data_buffer_number = 1; 130 int data_buffer_number = 1;
135 media::VideoCapture::EventHandler* capture_client = 131 media::VideoCapture::EventHandler* capture_client =
136 static_cast<media::VideoCapture::EventHandler*>(decoder_); 132 static_cast<media::VideoCapture::EventHandler*>(decoder_);
137 scoped_ptr<MockVideoCaptureImpl> vc_impl( 133 scoped_ptr<MockVideoCaptureImpl> vc_impl(
138 new MockVideoCaptureImpl(kVideoStreamId, 134 new MockVideoCaptureImpl(kVideoStreamId,
139 message_loop_proxy_, 135 message_loop_proxy_,
140 new VideoCaptureMessageFilter())); 136 new VideoCaptureMessageFilter()));
141 137
142 EXPECT_CALL(*vc_manager_, AddDevice(_, _)) 138 EXPECT_CALL(*vc_manager_, AddDevice(_, _))
143 .WillOnce(Return(vc_impl.get())); 139 .WillOnce(Return(vc_impl.get()));
144 decoder_->Initialize(NULL, 140 decoder_->Initialize(NULL,
145 media::NewExpectedClosure(), 141 media::NewExpectedClosure(),
146 NewStatisticsCallback()); 142 NewStatisticsCallback());
147 message_loop_->RunAllPending(); 143 message_loop_->RunAllPending();
148 144
149 EXPECT_CALL(*renderer_, ConsumeVideoFrame(_)) 145 EXPECT_CALL(*this, FrameReady(_));
150 .WillRepeatedly(ReturnFrameFromRenderer(decoder_.get())); 146 decoder_->Read(read_cb_);
147
151 EXPECT_CALL(*vc_impl, StartCapture(capture_client, _)) 148 EXPECT_CALL(*vc_impl, StartCapture(capture_client, _))
152 .Times(1) 149 .Times(1)
153 .WillOnce(CreateDataBufferFromCapture(capture_client, vc_impl.get(), 150 .WillOnce(CreateDataBufferFromCapture(capture_client, vc_impl.get(),
154 data_buffer_number)); 151 data_buffer_number));
155 EXPECT_CALL(*vc_impl, FeedBuffer(_)) 152 EXPECT_CALL(*vc_impl, FeedBuffer(_))
156 .Times(data_buffer_number) 153 .Times(data_buffer_number)
157 .WillRepeatedly(DeleteDataBuffer()); 154 .WillRepeatedly(DeleteDataBuffer());
158 decoder_->Seek(base::TimeDelta(), 155 decoder_->Seek(base::TimeDelta(),
159 media::NewExpectedStatusCB(media::PIPELINE_OK)); 156 media::NewExpectedStatusCB(media::PIPELINE_OK));
160 decoder_->Play(media::NewExpectedClosure()); 157 decoder_->Play(media::NewExpectedClosure());
161 message_loop_->RunAllPending(); 158 message_loop_->RunAllPending();
162 159
163 EXPECT_CALL(*vc_impl, StopCapture(capture_client)) 160 EXPECT_CALL(*vc_impl, StopCapture(capture_client))
164 .Times(1) 161 .Times(1)
165 .WillOnce(CaptureStopped(capture_client, vc_impl.get())); 162 .WillOnce(CaptureStopped(capture_client, vc_impl.get()));
166 EXPECT_CALL(*vc_manager_, RemoveDevice(_, _)) 163 EXPECT_CALL(*vc_manager_, RemoveDevice(_, _))
167 .WillOnce(Return()); 164 .WillOnce(Return());
168 decoder_->Stop(media::NewExpectedClosure()); 165 decoder_->Stop(media::NewExpectedClosure());
169 message_loop_->RunAllPending(); 166 message_loop_->RunAllPending();
170 } 167 }
OLDNEW
« no previous file with comments | « content/renderer/media/capture_video_decoder.cc ('k') | content/renderer/media/rtc_video_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698