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 15 matching lines...) Expand all Loading... |
26 public: | 26 public: |
27 RTCVideoDecoderTest() | 27 RTCVideoDecoderTest() |
28 : mock_gpu_factories_(new media::MockGpuVideoAcceleratorFactories), | 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_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_, GetMessageLoop()) | 38 EXPECT_CALL(*mock_gpu_factories_, GetTaskRunner()) |
39 .WillRepeatedly(Return(vda_loop_proxy_)); | 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()); | 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 { |
55 VLOG(2) << "TearDown"; | 55 VLOG(2) << "TearDown"; |
56 if (vda_thread_.IsRunning()) { | 56 if (vda_thread_.IsRunning()) { |
57 RunUntilIdle(); // Wait until all callbascks complete. | 57 RunUntilIdle(); // Wait until all callbascks complete. |
58 vda_loop_proxy_->DeleteSoon(FROM_HERE, rtc_decoder_.release()); | 58 vda_task_runner_->DeleteSoon(FROM_HERE, rtc_decoder_.release()); |
59 // Make sure the decoder is released before stopping the thread. | 59 // Make sure the decoder is released before stopping the thread. |
60 RunUntilIdle(); | 60 RunUntilIdle(); |
61 vda_thread_.Stop(); | 61 vda_thread_.Stop(); |
62 } else { | 62 } else { |
63 rtc_decoder_.reset(); | 63 rtc_decoder_.reset(); |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 virtual int32_t Decoded(webrtc::I420VideoFrame& decoded_image) OVERRIDE { | 67 virtual int32_t Decoded(webrtc::I420VideoFrame& decoded_image) OVERRIDE { |
68 VLOG(2) << "Decoded"; | 68 VLOG(2) << "Decoded"; |
69 EXPECT_EQ(vda_loop_proxy_, base::MessageLoopProxy::current()); | 69 EXPECT_EQ(vda_task_runner_, base::MessageLoopProxy::current()); |
70 return WEBRTC_VIDEO_CODEC_OK; | 70 return WEBRTC_VIDEO_CODEC_OK; |
71 } | 71 } |
72 | 72 |
73 void Initialize() { | 73 void Initialize() { |
74 VLOG(2) << "Initialize"; | 74 VLOG(2) << "Initialize"; |
75 codec_.codecType = webrtc::kVideoCodecVP8; | 75 codec_.codecType = webrtc::kVideoCodecVP8; |
76 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->InitDecode(&codec_, 1)); | 76 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->InitDecode(&codec_, 1)); |
77 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 77 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
78 rtc_decoder_->RegisterDecodeCompleteCallback(this)); | 78 rtc_decoder_->RegisterDecodeCompleteCallback(this)); |
79 } | 79 } |
80 | 80 |
81 void NotifyResetDone() { | 81 void NotifyResetDone() { |
82 VLOG(2) << "NotifyResetDone"; | 82 VLOG(2) << "NotifyResetDone"; |
83 vda_loop_proxy_->PostTask(FROM_HERE, | 83 vda_task_runner_->PostTask( |
84 base::Bind(&RTCVideoDecoder::NotifyResetDone, | 84 FROM_HERE, |
85 base::Unretained(rtc_decoder_.get()))); | 85 base::Bind(&RTCVideoDecoder::NotifyResetDone, |
| 86 base::Unretained(rtc_decoder_.get()))); |
86 } | 87 } |
87 | 88 |
88 void RunUntilIdle() { | 89 void RunUntilIdle() { |
89 VLOG(2) << "RunUntilIdle"; | 90 VLOG(2) << "RunUntilIdle"; |
90 vda_loop_proxy_->PostTask(FROM_HERE, | 91 vda_task_runner_->PostTask(FROM_HERE, |
91 base::Bind(&base::WaitableEvent::Signal, | 92 base::Bind(&base::WaitableEvent::Signal, |
92 base::Unretained(&idle_waiter_))); | 93 base::Unretained(&idle_waiter_))); |
93 idle_waiter_.Wait(); | 94 idle_waiter_.Wait(); |
94 } | 95 } |
95 | 96 |
96 protected: | 97 protected: |
97 scoped_refptr<media::MockGpuVideoAcceleratorFactories> mock_gpu_factories_; | 98 scoped_refptr<media::MockGpuVideoAcceleratorFactories> mock_gpu_factories_; |
98 media::MockVideoDecodeAccelerator* mock_vda_; | 99 media::MockVideoDecodeAccelerator* mock_vda_; |
99 scoped_ptr<RTCVideoDecoder> rtc_decoder_; | 100 scoped_ptr<RTCVideoDecoder> rtc_decoder_; |
100 webrtc::VideoCodec codec_; | 101 webrtc::VideoCodec codec_; |
101 base::Thread vda_thread_; | 102 base::Thread vda_thread_; |
102 | 103 |
103 private: | 104 private: |
104 scoped_refptr<base::MessageLoopProxy> vda_loop_proxy_; | 105 scoped_refptr<base::SingleThreadTaskRunner> vda_task_runner_; |
105 | 106 |
106 base::Lock lock_; | 107 base::Lock lock_; |
107 base::WaitableEvent idle_waiter_; | 108 base::WaitableEvent idle_waiter_; |
108 }; | 109 }; |
109 | 110 |
110 TEST_F(RTCVideoDecoderTest, CreateReturnsNullOnUnsupportedCodec) { | 111 TEST_F(RTCVideoDecoderTest, CreateReturnsNullOnUnsupportedCodec) { |
111 scoped_ptr<RTCVideoDecoder> null_rtc_decoder( | 112 scoped_ptr<RTCVideoDecoder> null_rtc_decoder( |
112 RTCVideoDecoder::Create(webrtc::kVideoCodecI420, mock_gpu_factories_)); | 113 RTCVideoDecoder::Create(webrtc::kVideoCodecI420, mock_gpu_factories_)); |
113 EXPECT_EQ(NULL, null_rtc_decoder.get()); | 114 EXPECT_EQ(NULL, null_rtc_decoder.get()); |
114 } | 115 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 | 211 |
211 EXPECT_FALSE(rtc_decoder_->IsFirstBufferAfterReset(RTCVideoDecoder::ID_LAST, | 212 EXPECT_FALSE(rtc_decoder_->IsFirstBufferAfterReset(RTCVideoDecoder::ID_LAST, |
212 RTCVideoDecoder::ID_LAST)); | 213 RTCVideoDecoder::ID_LAST)); |
213 EXPECT_TRUE( | 214 EXPECT_TRUE( |
214 rtc_decoder_->IsFirstBufferAfterReset(0, RTCVideoDecoder::ID_LAST)); | 215 rtc_decoder_->IsFirstBufferAfterReset(0, RTCVideoDecoder::ID_LAST)); |
215 EXPECT_FALSE( | 216 EXPECT_FALSE( |
216 rtc_decoder_->IsFirstBufferAfterReset(1, RTCVideoDecoder::ID_LAST)); | 217 rtc_decoder_->IsFirstBufferAfterReset(1, RTCVideoDecoder::ID_LAST)); |
217 } | 218 } |
218 | 219 |
219 } // content | 220 } // content |
OLD | NEW |