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" |
11 #include "media/filters/mock_gpu_video_decoder_factories.h" | 11 #include "media/filters/mock_gpu_video_accelerator_factories.h" |
12 #include "media/video/mock_video_decode_accelerator.h" | 12 #include "media/video/mock_video_decode_accelerator.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 using ::testing::_; | 15 using ::testing::_; |
16 using ::testing::Invoke; | 16 using ::testing::Invoke; |
17 using ::testing::Return; | 17 using ::testing::Return; |
18 using ::testing::SaveArg; | 18 using ::testing::SaveArg; |
19 using ::testing::WithArgs; | 19 using ::testing::WithArgs; |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 | 22 |
23 // TODO(wuchengli): add MockSharedMemroy so more functions can be tested. | 23 // TODO(wuchengli): add MockSharedMemroy so more functions can be tested. |
24 class RTCVideoDecoderTest : public ::testing::Test, | 24 class RTCVideoDecoderTest : public ::testing::Test, |
25 webrtc::DecodedImageCallback { | 25 webrtc::DecodedImageCallback { |
26 public: | 26 public: |
27 RTCVideoDecoderTest() | 27 RTCVideoDecoderTest() |
28 : mock_gpu_factories_(new media::MockGpuVideoDecoderFactories), | 28 : mock_gpu_factories_(new media::MockGpuVideoAcceleratorFactories), |
29 vda_thread_("vda_thread"), | 29 vda_thread_("vda_thread"), |
30 idle_waiter_(false, false) { | 30 idle_waiter_(false, false) { |
31 memset(&codec_, 0, sizeof(codec_)); | 31 memset(&codec_, 0, sizeof(codec_)); |
32 } | 32 } |
33 | 33 |
34 virtual void SetUp() OVERRIDE { | 34 virtual void SetUp() OVERRIDE { |
35 ASSERT_TRUE(vda_thread_.Start()); | 35 ASSERT_TRUE(vda_thread_.Start()); |
36 vda_loop_proxy_ = vda_thread_.message_loop_proxy(); | 36 vda_loop_proxy_ = vda_thread_.message_loop_proxy(); |
37 mock_vda_ = new media::MockVideoDecodeAccelerator; | 37 mock_vda_ = new media::MockVideoDecodeAccelerator; |
38 EXPECT_CALL(*mock_gpu_factories_, GetMessageLoop()) | 38 EXPECT_CALL(*mock_gpu_factories_, GetMessageLoop()) |
39 .WillRepeatedly(Return(vda_loop_proxy_)); | 39 .WillRepeatedly(Return(vda_loop_proxy_)); |
40 EXPECT_CALL(*mock_gpu_factories_, CreateVideoDecodeAccelerator(_, _)) | 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 CreateVideoDecodeAccelerator(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()); | 46 EXPECT_CALL(*mock_gpu_factories_, Abort()).WillRepeatedly(Return()); |
47 EXPECT_CALL(*mock_gpu_factories_, CreateSharedMemory(_)) | 47 EXPECT_CALL(*mock_gpu_factories_, CreateSharedMemory(_)) |
48 .WillRepeatedly(Return(static_cast<base::SharedMemory*>(NULL))); | 48 .WillRepeatedly(Return(static_cast<base::SharedMemory*>(NULL))); |
49 EXPECT_CALL(*mock_vda_, Destroy()); | 49 EXPECT_CALL(*mock_vda_, Destroy()); |
50 rtc_decoder_ = | 50 rtc_decoder_ = |
51 RTCVideoDecoder::Create(webrtc::kVideoCodecVP8, mock_gpu_factories_); | 51 RTCVideoDecoder::Create(webrtc::kVideoCodecVP8, mock_gpu_factories_); |
52 } | 52 } |
53 | 53 |
54 virtual void TearDown() OVERRIDE { | 54 virtual void TearDown() OVERRIDE { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 87 |
88 void RunUntilIdle() { | 88 void RunUntilIdle() { |
89 VLOG(2) << "RunUntilIdle"; | 89 VLOG(2) << "RunUntilIdle"; |
90 vda_loop_proxy_->PostTask(FROM_HERE, | 90 vda_loop_proxy_->PostTask(FROM_HERE, |
91 base::Bind(&base::WaitableEvent::Signal, | 91 base::Bind(&base::WaitableEvent::Signal, |
92 base::Unretained(&idle_waiter_))); | 92 base::Unretained(&idle_waiter_))); |
93 idle_waiter_.Wait(); | 93 idle_waiter_.Wait(); |
94 } | 94 } |
95 | 95 |
96 protected: | 96 protected: |
97 scoped_refptr<media::MockGpuVideoDecoderFactories> mock_gpu_factories_; | 97 scoped_refptr<media::MockGpuVideoAcceleratorFactories> mock_gpu_factories_; |
98 media::MockVideoDecodeAccelerator* mock_vda_; | 98 media::MockVideoDecodeAccelerator* mock_vda_; |
99 scoped_ptr<RTCVideoDecoder> rtc_decoder_; | 99 scoped_ptr<RTCVideoDecoder> rtc_decoder_; |
100 webrtc::VideoCodec codec_; | 100 webrtc::VideoCodec codec_; |
101 base::Thread vda_thread_; | 101 base::Thread vda_thread_; |
102 | 102 |
103 private: | 103 private: |
104 scoped_refptr<base::MessageLoopProxy> vda_loop_proxy_; | 104 scoped_refptr<base::MessageLoopProxy> vda_loop_proxy_; |
105 | 105 |
106 base::Lock lock_; | 106 base::Lock lock_; |
107 base::WaitableEvent idle_waiter_; | 107 base::WaitableEvent idle_waiter_; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 0)); | 186 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 0)); |
187 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, | 187 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, |
188 RTCVideoDecoder::ID_HALF - 2)); | 188 RTCVideoDecoder::ID_HALF - 2)); |
189 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, | 189 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, |
190 RTCVideoDecoder::ID_HALF + 2)); | 190 RTCVideoDecoder::ID_HALF + 2)); |
191 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, | 191 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, |
192 RTCVideoDecoder::ID_LAST)); | 192 RTCVideoDecoder::ID_LAST)); |
193 } | 193 } |
194 | 194 |
195 } // content | 195 } // content |
OLD | NEW |