| OLD | NEW |
| 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" |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 read_cb_ = base::Bind(&RTCVideoDecoderTest::FrameReady, | 188 read_cb_ = base::Bind(&RTCVideoDecoderTest::FrameReady, |
| 189 base::Unretained(this)); | 189 base::Unretained(this)); |
| 190 | 190 |
| 191 DCHECK(decoder_); | 191 DCHECK(decoder_); |
| 192 | 192 |
| 193 EXPECT_CALL(statistics_cb_, OnStatistics(_)) | 193 EXPECT_CALL(statistics_cb_, OnStatistics(_)) |
| 194 .Times(AnyNumber()); | 194 .Times(AnyNumber()); |
| 195 } | 195 } |
| 196 | 196 |
| 197 virtual void TearDown() OVERRIDE { | 197 virtual void TearDown() OVERRIDE { |
| 198 EXPECT_CALL(*video_track_, RemoveRenderer(decoder_.get())); | 198 if (decoder_->state_ == RTCVideoDecoder::kStopped) |
| 199 decoder_->Stop(media::NewExpectedClosure()); | 199 return; |
| 200 | 200 Stop(); |
| 201 message_loop_.RunAllPending(); | |
| 202 EXPECT_EQ(RTCVideoDecoder::kStopped, decoder_->state_); | |
| 203 } | 201 } |
| 204 | 202 |
| 205 void InitializeDecoderSuccessfully() { | 203 void InitializeDecoderSuccessfully() { |
| 206 EXPECT_CALL(*video_track_, AddRenderer(decoder_.get())); | 204 EXPECT_CALL(*video_track_, AddRenderer(decoder_.get())); |
| 207 // Test successful initialization. | 205 // Test successful initialization. |
| 208 decoder_->Initialize( | 206 decoder_->Initialize( |
| 209 NULL, NewExpectedStatusCB(PIPELINE_OK), NewStatisticsCB()); | 207 NULL, NewExpectedStatusCB(PIPELINE_OK), NewStatisticsCB()); |
| 210 message_loop_.RunAllPending(); | 208 message_loop_.RunAllPending(); |
| 211 } | 209 } |
| 212 | 210 |
| 211 void Stop() { |
| 212 EXPECT_CALL(*video_track_, RemoveRenderer(decoder_.get())); |
| 213 decoder_->Stop(media::NewExpectedClosure()); |
| 214 |
| 215 message_loop_.RunAllPending(); |
| 216 EXPECT_EQ(RTCVideoDecoder::kStopped, decoder_->state_); |
| 217 } |
| 218 |
| 213 StatisticsCB NewStatisticsCB() { | 219 StatisticsCB NewStatisticsCB() { |
| 214 return base::Bind(&MockStatisticsCB::OnStatistics, | 220 return base::Bind(&MockStatisticsCB::OnStatistics, |
| 215 base::Unretained(&statistics_cb_)); | 221 base::Unretained(&statistics_cb_)); |
| 216 } | 222 } |
| 217 | 223 |
| 218 void RenderFrame() { | 224 void RenderFrame() { |
| 219 NullVideoFrame video_frame; | 225 NullVideoFrame video_frame; |
| 220 decoder_->RenderFrame(&video_frame); | 226 decoder_->RenderFrame(&video_frame); |
| 221 } | 227 } |
| 222 | 228 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 RenderFrame(); | 306 RenderFrame(); |
| 301 message_loop_.RunAllPending(); | 307 message_loop_.RunAllPending(); |
| 302 } | 308 } |
| 303 | 309 |
| 304 TEST_F(RTCVideoDecoderTest, ReadAndShutdown) { | 310 TEST_F(RTCVideoDecoderTest, ReadAndShutdown) { |
| 305 // Test all the Read requests can be fullfilled (which is needed in order to | 311 // Test all the Read requests can be fullfilled (which is needed in order to |
| 306 // teardown the pipeline) even when there's no input frame. | 312 // teardown the pipeline) even when there's no input frame. |
| 307 InitializeDecoderSuccessfully(); | 313 InitializeDecoderSuccessfully(); |
| 308 | 314 |
| 309 EXPECT_CALL(*this, FrameReady(media::VideoDecoder::kOk, | 315 EXPECT_CALL(*this, FrameReady(media::VideoDecoder::kOk, |
| 310 scoped_refptr<media::VideoFrame>())).Times(2); | 316 scoped_refptr<media::VideoFrame>())); |
| 311 decoder_->Read(read_cb_); | 317 decoder_->Read(read_cb_); |
| 312 EXPECT_FALSE(decoder_->shutting_down_); | 318 Stop(); |
| 313 decoder_->PrepareForShutdownHack(); | 319 |
| 314 EXPECT_TRUE(decoder_->shutting_down_); | 320 // Any read after stopping should be immediately satisfied. |
| 321 EXPECT_CALL(*this, FrameReady(media::VideoDecoder::kOk, |
| 322 scoped_refptr<media::VideoFrame>())); |
| 315 decoder_->Read(read_cb_); | 323 decoder_->Read(read_cb_); |
| 316 | |
| 317 message_loop_.RunAllPending(); | 324 message_loop_.RunAllPending(); |
| 318 } | 325 } |
| OLD | NEW |