Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: content/renderer/media/rtc_video_decoder_unittest.cc

Issue 19534002: Make RendererGpuVideoDecoderFactories live on arbitrary threads. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 18 matching lines...) Expand all
29 idle_waiter_(false, false) { 29 idle_waiter_(false, false) {
30 memset(&codec_, 0, sizeof(codec_)); 30 memset(&codec_, 0, sizeof(codec_));
31 } 31 }
32 32
33 virtual void SetUp() OVERRIDE { 33 virtual void SetUp() OVERRIDE {
34 ASSERT_TRUE(vda_thread_.Start()); 34 ASSERT_TRUE(vda_thread_.Start());
35 vda_loop_proxy_ = vda_thread_.message_loop_proxy(); 35 vda_loop_proxy_ = vda_thread_.message_loop_proxy();
36 mock_vda_ = new media::MockVideoDecodeAccelerator; 36 mock_vda_ = new media::MockVideoDecodeAccelerator;
37 EXPECT_CALL(*mock_gpu_factories_, GetMessageLoop()) 37 EXPECT_CALL(*mock_gpu_factories_, GetMessageLoop())
38 .WillRepeatedly(Return(vda_loop_proxy_)); 38 .WillRepeatedly(Return(vda_loop_proxy_));
39 EXPECT_CALL(*mock_gpu_factories_, CreateVideoDecodeAccelerator(_, _))
40 .WillRepeatedly(
41 Return(static_cast<media::VideoDecodeAccelerator*>(NULL)));
39 EXPECT_CALL(*mock_gpu_factories_, 42 EXPECT_CALL(*mock_gpu_factories_,
40 CreateVideoDecodeAccelerator(media::VP8PROFILE_MAIN, _)) 43 CreateVideoDecodeAccelerator(media::VP8PROFILE_MAIN, _))
41 .WillOnce(Return(mock_vda_)); 44 .WillRepeatedly(Return(mock_vda_));
42 EXPECT_CALL(*mock_gpu_factories_, Abort()).WillRepeatedly(Return()); 45 EXPECT_CALL(*mock_gpu_factories_, Abort()).WillRepeatedly(Return());
43 EXPECT_CALL(*mock_gpu_factories_, CreateSharedMemory(_)) 46 EXPECT_CALL(*mock_gpu_factories_, CreateSharedMemory(_))
44 .WillRepeatedly(Return(static_cast<base::SharedMemory*>(NULL))); 47 .WillRepeatedly(Return(static_cast<base::SharedMemory*>(NULL)));
45 EXPECT_CALL(*mock_vda_, Destroy()); 48 EXPECT_CALL(*mock_vda_, Destroy());
46 rtc_decoder_ = RTCVideoDecoder::Create(mock_gpu_factories_); 49 rtc_decoder_ =
50 RTCVideoDecoder::Create(webrtc::kVideoCodecVP8, mock_gpu_factories_);
47 } 51 }
48 52
49 virtual void TearDown() OVERRIDE { 53 virtual void TearDown() OVERRIDE {
50 VLOG(2) << "TearDown"; 54 VLOG(2) << "TearDown";
51 if (vda_thread_.IsRunning()) { 55 if (vda_thread_.IsRunning()) {
56 if (rtc_decoder_)
57 rtc_decoder_->Release();
52 RunUntilIdle(); // Wait until all callbascks complete. 58 RunUntilIdle(); // Wait until all callbascks complete.
53 vda_loop_proxy_->DeleteSoon(FROM_HERE, rtc_decoder_.release()); 59 vda_loop_proxy_->DeleteSoon(FROM_HERE, rtc_decoder_.release());
54 // Make sure the decoder is released before stopping the thread. 60 // Make sure the decoder is released before stopping the thread.
55 RunUntilIdle(); 61 RunUntilIdle();
56 vda_thread_.Stop(); 62 vda_thread_.Stop();
57 } else { 63 } else {
58 rtc_decoder_.reset(); 64 rtc_decoder_.reset();
59 } 65 }
60 } 66 }
61 67
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 webrtc::VideoCodec codec_; 101 webrtc::VideoCodec codec_;
96 base::Thread vda_thread_; 102 base::Thread vda_thread_;
97 103
98 private: 104 private:
99 scoped_refptr<base::MessageLoopProxy> vda_loop_proxy_; 105 scoped_refptr<base::MessageLoopProxy> vda_loop_proxy_;
100 106
101 base::Lock lock_; 107 base::Lock lock_;
102 base::WaitableEvent idle_waiter_; 108 base::WaitableEvent idle_waiter_;
103 }; 109 };
104 110
111 TEST_F(RTCVideoDecoderTest, CreateReturnsNullOnUnsupportedCodec) {
112 scoped_ptr<RTCVideoDecoder> null_rtc_decoder(
113 RTCVideoDecoder::Create(webrtc::kVideoCodecI420, mock_gpu_factories_));
114 EXPECT_EQ(NULL, null_rtc_decoder.get());
115 }
116
105 TEST_F(RTCVideoDecoderTest, InitDecodeReturnsErrorOnFeedbackMode) { 117 TEST_F(RTCVideoDecoderTest, InitDecodeReturnsErrorOnFeedbackMode) {
106 codec_.codecType = webrtc::kVideoCodecVP8; 118 codec_.codecType = webrtc::kVideoCodecVP8;
107 codec_.codecSpecific.VP8.feedbackModeOn = true; 119 codec_.codecSpecific.VP8.feedbackModeOn = true;
108 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, rtc_decoder_->InitDecode(&codec_, 1)); 120 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, rtc_decoder_->InitDecode(&codec_, 1));
109 } 121 }
110 122
111 TEST_F(RTCVideoDecoderTest, DecodeReturnsErrorWithoutInitDecode) { 123 TEST_F(RTCVideoDecoderTest, DecodeReturnsErrorWithoutInitDecode) {
112 webrtc::EncodedImage input_image; 124 webrtc::EncodedImage input_image;
113 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED, 125 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED,
114 rtc_decoder_->Decode(input_image, false, NULL, NULL, 0)); 126 rtc_decoder_->Decode(input_image, false, NULL, NULL, 0));
(...skipping 18 matching lines...) Expand all
133 145
134 TEST_F(RTCVideoDecoderTest, ResetReturnsOk) { 146 TEST_F(RTCVideoDecoderTest, ResetReturnsOk) {
135 Initialize(); 147 Initialize();
136 EXPECT_CALL(*mock_vda_, Reset()) 148 EXPECT_CALL(*mock_vda_, Reset())
137 .WillOnce(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone)); 149 .WillOnce(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone));
138 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Reset()); 150 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Reset());
139 } 151 }
140 152
141 TEST_F(RTCVideoDecoderTest, ReleaseReturnsOk) { 153 TEST_F(RTCVideoDecoderTest, ReleaseReturnsOk) {
142 Initialize(); 154 Initialize();
143 EXPECT_CALL(*mock_vda_, Reset())
144 .WillOnce(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone));
145 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Release()); 155 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Release());
146 } 156 }
147 157
148 TEST_F(RTCVideoDecoderTest, VdaThreadStops) { vda_thread_.Stop(); } 158 TEST_F(RTCVideoDecoderTest, VdaThreadStops) { vda_thread_.Stop(); }
149 159
150 TEST_F(RTCVideoDecoderTest, IsBufferAfterReset) { 160 TEST_F(RTCVideoDecoderTest, IsBufferAfterReset) {
151 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_INVALID)); 161 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_INVALID));
152 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 162 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST,
153 RTCVideoDecoder::ID_INVALID)); 163 RTCVideoDecoder::ID_INVALID));
154 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_HALF - 2, 164 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_HALF - 2,
(...skipping 11 matching lines...) Expand all
166 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 0)); 176 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 0));
167 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 177 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST,
168 RTCVideoDecoder::ID_HALF - 2)); 178 RTCVideoDecoder::ID_HALF - 2));
169 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 179 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST,
170 RTCVideoDecoder::ID_HALF + 2)); 180 RTCVideoDecoder::ID_HALF + 2));
171 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 181 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST,
172 RTCVideoDecoder::ID_LAST)); 182 RTCVideoDecoder::ID_LAST));
173 } 183 }
174 184
175 } // content 185 } // content
OLDNEW
« no previous file with comments | « content/renderer/media/rtc_video_decoder_factory.cc ('k') | content/renderer/media/webmediaplayer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698