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.h" | 6 #include "base/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 19 matching lines...) Expand all Loading... |
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(_, _)) |
| 41 .WillRepeatedly( |
| 42 Return(static_cast<media::VideoDecodeAccelerator*>(NULL))); |
40 EXPECT_CALL(*mock_gpu_factories_, | 43 EXPECT_CALL(*mock_gpu_factories_, |
41 CreateVideoDecodeAccelerator(media::VP8PROFILE_MAIN, _)) | 44 CreateVideoDecodeAccelerator(media::VP8PROFILE_MAIN, _)) |
42 .WillOnce(Return(mock_vda_)); | 45 .WillRepeatedly(Return(mock_vda_)); |
43 EXPECT_CALL(*mock_gpu_factories_, Abort()).WillRepeatedly(Return()); | 46 EXPECT_CALL(*mock_gpu_factories_, Abort()).WillRepeatedly(Return()); |
44 EXPECT_CALL(*mock_gpu_factories_, CreateSharedMemory(_)) | 47 EXPECT_CALL(*mock_gpu_factories_, CreateSharedMemory(_)) |
45 .WillRepeatedly(Return(static_cast<base::SharedMemory*>(NULL))); | 48 .WillRepeatedly(Return(static_cast<base::SharedMemory*>(NULL))); |
46 EXPECT_CALL(*mock_vda_, Destroy()); | 49 EXPECT_CALL(*mock_vda_, Destroy()); |
47 rtc_decoder_ = RTCVideoDecoder::Create(mock_gpu_factories_); | 50 rtc_decoder_ = |
| 51 RTCVideoDecoder::Create(webrtc::kVideoCodecVP8, mock_gpu_factories_); |
48 } | 52 } |
49 | 53 |
50 virtual void TearDown() OVERRIDE { | 54 virtual void TearDown() OVERRIDE { |
51 VLOG(2) << "TearDown"; | 55 VLOG(2) << "TearDown"; |
52 if (vda_thread_.IsRunning()) { | 56 if (vda_thread_.IsRunning()) { |
| 57 if (rtc_decoder_) |
| 58 rtc_decoder_->Release(); |
53 RunUntilIdle(); // Wait until all callbascks complete. | 59 RunUntilIdle(); // Wait until all callbascks complete. |
54 vda_loop_proxy_->DeleteSoon(FROM_HERE, rtc_decoder_.release()); | 60 vda_loop_proxy_->DeleteSoon(FROM_HERE, rtc_decoder_.release()); |
55 // Make sure the decoder is released before stopping the thread. | 61 // Make sure the decoder is released before stopping the thread. |
56 RunUntilIdle(); | 62 RunUntilIdle(); |
57 vda_thread_.Stop(); | 63 vda_thread_.Stop(); |
58 } else { | 64 } else { |
59 rtc_decoder_.reset(); | 65 rtc_decoder_.reset(); |
60 } | 66 } |
61 } | 67 } |
62 | 68 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 webrtc::VideoCodec codec_; | 102 webrtc::VideoCodec codec_; |
97 base::Thread vda_thread_; | 103 base::Thread vda_thread_; |
98 | 104 |
99 private: | 105 private: |
100 scoped_refptr<base::MessageLoopProxy> vda_loop_proxy_; | 106 scoped_refptr<base::MessageLoopProxy> vda_loop_proxy_; |
101 | 107 |
102 base::Lock lock_; | 108 base::Lock lock_; |
103 base::WaitableEvent idle_waiter_; | 109 base::WaitableEvent idle_waiter_; |
104 }; | 110 }; |
105 | 111 |
| 112 TEST_F(RTCVideoDecoderTest, CreateReturnsNullOnUnsupportedCodec) { |
| 113 scoped_ptr<RTCVideoDecoder> null_rtc_decoder( |
| 114 RTCVideoDecoder::Create(webrtc::kVideoCodecI420, mock_gpu_factories_)); |
| 115 EXPECT_EQ(NULL, null_rtc_decoder.get()); |
| 116 } |
| 117 |
106 TEST_F(RTCVideoDecoderTest, InitDecodeReturnsErrorOnFeedbackMode) { | 118 TEST_F(RTCVideoDecoderTest, InitDecodeReturnsErrorOnFeedbackMode) { |
107 codec_.codecType = webrtc::kVideoCodecVP8; | 119 codec_.codecType = webrtc::kVideoCodecVP8; |
108 codec_.codecSpecific.VP8.feedbackModeOn = true; | 120 codec_.codecSpecific.VP8.feedbackModeOn = true; |
109 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, rtc_decoder_->InitDecode(&codec_, 1)); | 121 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, rtc_decoder_->InitDecode(&codec_, 1)); |
110 } | 122 } |
111 | 123 |
112 TEST_F(RTCVideoDecoderTest, DecodeReturnsErrorWithoutInitDecode) { | 124 TEST_F(RTCVideoDecoderTest, DecodeReturnsErrorWithoutInitDecode) { |
113 webrtc::EncodedImage input_image; | 125 webrtc::EncodedImage input_image; |
114 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED, | 126 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED, |
115 rtc_decoder_->Decode(input_image, false, NULL, NULL, 0)); | 127 rtc_decoder_->Decode(input_image, false, NULL, NULL, 0)); |
(...skipping 18 matching lines...) Expand all Loading... |
134 | 146 |
135 TEST_F(RTCVideoDecoderTest, ResetReturnsOk) { | 147 TEST_F(RTCVideoDecoderTest, ResetReturnsOk) { |
136 Initialize(); | 148 Initialize(); |
137 EXPECT_CALL(*mock_vda_, Reset()) | 149 EXPECT_CALL(*mock_vda_, Reset()) |
138 .WillOnce(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone)); | 150 .WillOnce(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone)); |
139 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Reset()); | 151 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Reset()); |
140 } | 152 } |
141 | 153 |
142 TEST_F(RTCVideoDecoderTest, ReleaseReturnsOk) { | 154 TEST_F(RTCVideoDecoderTest, ReleaseReturnsOk) { |
143 Initialize(); | 155 Initialize(); |
144 EXPECT_CALL(*mock_vda_, Reset()) | |
145 .WillOnce(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone)); | |
146 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Release()); | 156 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Release()); |
147 } | 157 } |
148 | 158 |
149 TEST_F(RTCVideoDecoderTest, VdaThreadStops) { vda_thread_.Stop(); } | 159 TEST_F(RTCVideoDecoderTest, VdaThreadStops) { vda_thread_.Stop(); } |
150 | 160 |
151 TEST_F(RTCVideoDecoderTest, IsBufferAfterReset) { | 161 TEST_F(RTCVideoDecoderTest, IsBufferAfterReset) { |
152 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_INVALID)); | 162 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_INVALID)); |
153 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, | 163 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, |
154 RTCVideoDecoder::ID_INVALID)); | 164 RTCVideoDecoder::ID_INVALID)); |
155 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_HALF - 2, | 165 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_HALF - 2, |
(...skipping 11 matching lines...) Expand all Loading... |
167 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 0)); | 177 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 0)); |
168 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, | 178 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, |
169 RTCVideoDecoder::ID_HALF - 2)); | 179 RTCVideoDecoder::ID_HALF - 2)); |
170 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, | 180 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, |
171 RTCVideoDecoder::ID_HALF + 2)); | 181 RTCVideoDecoder::ID_HALF + 2)); |
172 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, | 182 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, |
173 RTCVideoDecoder::ID_LAST)); | 183 RTCVideoDecoder::ID_LAST)); |
174 } | 184 } |
175 | 185 |
176 } // content | 186 } // content |
OLD | NEW |