| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
| 7 #include "base/synchronization/waitable_event.h" | 7 #include "base/synchronization/waitable_event.h" |
| 8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
| 9 #include "content/renderer/media/rtc_video_decoder.h" | 9 #include "content/renderer/media/rtc_video_decoder.h" |
| 10 #include "media/base/gmock_callback_support.h" | 10 #include "media/base/gmock_callback_support.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 vda_task_runner_ = vda_thread_.message_loop_proxy(); | 36 vda_task_runner_ = vda_thread_.message_loop_proxy(); |
| 37 mock_vda_ = new media::MockVideoDecodeAccelerator; | 37 mock_vda_ = new media::MockVideoDecodeAccelerator; |
| 38 EXPECT_CALL(*mock_gpu_factories_, GetTaskRunner()) | 38 EXPECT_CALL(*mock_gpu_factories_, GetTaskRunner()) |
| 39 .WillRepeatedly(Return(vda_task_runner_)); | 39 .WillRepeatedly(Return(vda_task_runner_)); |
| 40 EXPECT_CALL(*mock_gpu_factories_, DoCreateVideoDecodeAccelerator(_, _)) | 40 EXPECT_CALL(*mock_gpu_factories_, DoCreateVideoDecodeAccelerator(_, _)) |
| 41 .WillRepeatedly( | 41 .WillRepeatedly( |
| 42 Return(static_cast<media::VideoDecodeAccelerator*>(NULL))); | 42 Return(static_cast<media::VideoDecodeAccelerator*>(NULL))); |
| 43 EXPECT_CALL(*mock_gpu_factories_, | 43 EXPECT_CALL(*mock_gpu_factories_, |
| 44 DoCreateVideoDecodeAccelerator(media::VP8PROFILE_MAIN, _)) | 44 DoCreateVideoDecodeAccelerator(media::VP8PROFILE_MAIN, _)) |
| 45 .WillRepeatedly(Return(mock_vda_)); | 45 .WillRepeatedly(Return(mock_vda_)); |
| 46 EXPECT_CALL(*mock_gpu_factories_, Abort()).WillRepeatedly(Return()); | |
| 47 EXPECT_CALL(*mock_gpu_factories_, CreateSharedMemory(_)) | 46 EXPECT_CALL(*mock_gpu_factories_, CreateSharedMemory(_)) |
| 48 .WillRepeatedly(Return(static_cast<base::SharedMemory*>(NULL))); | 47 .WillRepeatedly(Return(static_cast<base::SharedMemory*>(NULL))); |
| 49 EXPECT_CALL(*mock_vda_, Destroy()); | 48 EXPECT_CALL(*mock_vda_, Destroy()); |
| 50 rtc_decoder_ = | 49 rtc_decoder_ = |
| 51 RTCVideoDecoder::Create(webrtc::kVideoCodecVP8, mock_gpu_factories_); | 50 RTCVideoDecoder::Create(webrtc::kVideoCodecVP8, mock_gpu_factories_); |
| 52 } | 51 } |
| 53 | 52 |
| 54 virtual void TearDown() OVERRIDE { | 53 virtual void TearDown() OVERRIDE { |
| 55 VLOG(2) << "TearDown"; | 54 VLOG(2) << "TearDown"; |
| 56 if (vda_thread_.IsRunning()) { | 55 EXPECT_TRUE(vda_thread_.IsRunning()); |
| 57 RunUntilIdle(); // Wait until all callbascks complete. | 56 RunUntilIdle(); // Wait until all callbascks complete. |
| 58 vda_task_runner_->DeleteSoon(FROM_HERE, rtc_decoder_.release()); | 57 vda_task_runner_->DeleteSoon(FROM_HERE, rtc_decoder_.release()); |
| 59 // Make sure the decoder is released before stopping the thread. | 58 // Make sure the decoder is released before stopping the thread. |
| 60 RunUntilIdle(); | 59 RunUntilIdle(); |
| 61 vda_thread_.Stop(); | 60 vda_thread_.Stop(); |
| 62 } else { | |
| 63 rtc_decoder_.reset(); | |
| 64 } | |
| 65 } | 61 } |
| 66 | 62 |
| 67 virtual int32_t Decoded(webrtc::I420VideoFrame& decoded_image) OVERRIDE { | 63 virtual int32_t Decoded(webrtc::I420VideoFrame& decoded_image) OVERRIDE { |
| 68 VLOG(2) << "Decoded"; | 64 VLOG(2) << "Decoded"; |
| 69 EXPECT_EQ(vda_task_runner_, base::MessageLoopProxy::current()); | 65 EXPECT_EQ(vda_task_runner_, base::MessageLoopProxy::current()); |
| 70 return WEBRTC_VIDEO_CODEC_OK; | 66 return WEBRTC_VIDEO_CODEC_OK; |
| 71 } | 67 } |
| 72 | 68 |
| 73 void Initialize() { | 69 void Initialize() { |
| 74 VLOG(2) << "Initialize"; | 70 VLOG(2) << "Initialize"; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 | 155 |
| 160 TEST_F(RTCVideoDecoderTest, InitDecodeAfterRelease) { | 156 TEST_F(RTCVideoDecoderTest, InitDecodeAfterRelease) { |
| 161 EXPECT_CALL(*mock_vda_, Reset()) | 157 EXPECT_CALL(*mock_vda_, Reset()) |
| 162 .WillRepeatedly(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone)); | 158 .WillRepeatedly(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone)); |
| 163 Initialize(); | 159 Initialize(); |
| 164 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Release()); | 160 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Release()); |
| 165 Initialize(); | 161 Initialize(); |
| 166 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Release()); | 162 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Release()); |
| 167 } | 163 } |
| 168 | 164 |
| 169 TEST_F(RTCVideoDecoderTest, VdaThreadStops) { vda_thread_.Stop(); } | |
| 170 | |
| 171 TEST_F(RTCVideoDecoderTest, IsBufferAfterReset) { | 165 TEST_F(RTCVideoDecoderTest, IsBufferAfterReset) { |
| 172 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_INVALID)); | 166 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_INVALID)); |
| 173 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, | 167 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, |
| 174 RTCVideoDecoder::ID_INVALID)); | 168 RTCVideoDecoder::ID_INVALID)); |
| 175 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_HALF - 2, | 169 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_HALF - 2, |
| 176 RTCVideoDecoder::ID_HALF + 2)); | 170 RTCVideoDecoder::ID_HALF + 2)); |
| 177 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_HALF + 2, | 171 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_HALF + 2, |
| 178 RTCVideoDecoder::ID_HALF - 2)); | 172 RTCVideoDecoder::ID_HALF - 2)); |
| 179 | 173 |
| 180 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(0, 0)); | 174 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(0, 0)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 211 | 205 |
| 212 EXPECT_FALSE(rtc_decoder_->IsFirstBufferAfterReset(RTCVideoDecoder::ID_LAST, | 206 EXPECT_FALSE(rtc_decoder_->IsFirstBufferAfterReset(RTCVideoDecoder::ID_LAST, |
| 213 RTCVideoDecoder::ID_LAST)); | 207 RTCVideoDecoder::ID_LAST)); |
| 214 EXPECT_TRUE( | 208 EXPECT_TRUE( |
| 215 rtc_decoder_->IsFirstBufferAfterReset(0, RTCVideoDecoder::ID_LAST)); | 209 rtc_decoder_->IsFirstBufferAfterReset(0, RTCVideoDecoder::ID_LAST)); |
| 216 EXPECT_FALSE( | 210 EXPECT_FALSE( |
| 217 rtc_decoder_->IsFirstBufferAfterReset(1, RTCVideoDecoder::ID_LAST)); | 211 rtc_decoder_->IsFirstBufferAfterReset(1, RTCVideoDecoder::ID_LAST)); |
| 218 } | 212 } |
| 219 | 213 |
| 220 } // content | 214 } // content |
| OLD | NEW |