| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <deque> | 5 #include <deque> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "content/renderer/media/rtc_video_decoder.h" |
| 10 #include "media/base/data_buffer.h" | 11 #include "media/base/data_buffer.h" |
| 11 #include "media/base/filters.h" | 12 #include "media/base/filters.h" |
| 12 #include "media/base/limits.h" | 13 #include "media/base/limits.h" |
| 13 #include "media/base/mock_callback.h" | 14 #include "media/base/mock_callback.h" |
| 14 #include "media/base/mock_filter_host.h" | 15 #include "media/base/mock_filter_host.h" |
| 15 #include "media/base/mock_filters.h" | 16 #include "media/base/mock_filters.h" |
| 16 #include "media/base/mock_task.h" | 17 #include "media/base/mock_task.h" |
| 17 #include "media/base/video_frame.h" | 18 #include "media/base/video_frame.h" |
| 18 #include "media/filters/rtc_video_decoder.h" | |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 20 |
| 21 using ::testing::_; | 21 using ::testing::_; |
| 22 using ::testing::AnyNumber; | 22 using ::testing::AnyNumber; |
| 23 using ::testing::DoAll; | 23 using ::testing::DoAll; |
| 24 using ::testing::Message; | 24 using ::testing::Message; |
| 25 using ::testing::Return; | 25 using ::testing::Return; |
| 26 using ::testing::ReturnNull; | 26 using ::testing::ReturnNull; |
| 27 using ::testing::SetArgumentPointee; | 27 using ::testing::SetArgumentPointee; |
| 28 using ::testing::StrictMock; | 28 using ::testing::StrictMock; |
| 29 using ::testing::WithArg; | 29 using ::testing::WithArg; |
| 30 using ::testing::Invoke; | 30 using ::testing::Invoke; |
| 31 | 31 |
| 32 namespace media { | |
| 33 | |
| 34 class RTCVideoDecoderTest : public testing::Test { | 32 class RTCVideoDecoderTest : public testing::Test { |
| 35 protected: | 33 protected: |
| 36 static const int kWidth; | 34 static const int kWidth; |
| 37 static const int kHeight; | 35 static const int kHeight; |
| 38 static const char* kUrl; | 36 static const char* kUrl; |
| 39 static const PipelineStatistics kStatistics; | 37 static const media::PipelineStatistics kStatistics; |
| 40 | 38 |
| 41 RTCVideoDecoderTest() { | 39 RTCVideoDecoderTest() { |
| 42 MediaFormat media_format; | 40 media::MediaFormat media_format; |
| 43 decoder_ = new RTCVideoDecoder(&message_loop_, kUrl); | 41 decoder_ = new RTCVideoDecoder(&message_loop_, kUrl); |
| 44 renderer_ = new MockVideoRenderer(); | 42 renderer_ = new media::MockVideoRenderer(); |
| 45 | 43 |
| 46 DCHECK(decoder_); | 44 DCHECK(decoder_); |
| 47 | 45 |
| 48 // Inject mocks and prepare a demuxer stream. | 46 // Inject mocks and prepare a demuxer stream. |
| 49 decoder_->set_host(&host_); | 47 decoder_->set_host(&host_); |
| 50 | 48 |
| 51 EXPECT_CALL(stats_callback_object_, OnStatistics(_)) | 49 EXPECT_CALL(stats_callback_object_, OnStatistics(_)) |
| 52 .Times(AnyNumber()); | 50 .Times(AnyNumber()); |
| 53 } | 51 } |
| 54 | 52 |
| 55 virtual ~RTCVideoDecoderTest() { | 53 virtual ~RTCVideoDecoderTest() { |
| 56 // Finish up any remaining tasks. | 54 // Finish up any remaining tasks. |
| 57 message_loop_.RunAllPending(); | 55 message_loop_.RunAllPending(); |
| 58 } | 56 } |
| 59 | 57 |
| 60 void InitializeDecoderSuccessfully() { | 58 void InitializeDecoderSuccessfully() { |
| 61 // Test successful initialization. | 59 // Test successful initialization. |
| 62 decoder_->Initialize(NULL, | 60 decoder_->Initialize(NULL, |
| 63 NewExpectedCallback(), NewStatisticsCallback()); | 61 media::NewExpectedCallback(), NewStatisticsCallback()); |
| 64 message_loop_.RunAllPending(); | 62 message_loop_.RunAllPending(); |
| 65 } | 63 } |
| 66 | 64 |
| 67 StatisticsCallback* NewStatisticsCallback() { | 65 media::StatisticsCallback* NewStatisticsCallback() { |
| 68 return NewCallback(&stats_callback_object_, | 66 return NewCallback(&stats_callback_object_, |
| 69 &MockStatisticsCallback::OnStatistics); | 67 &media::MockStatisticsCallback::OnStatistics); |
| 70 } | 68 } |
| 71 | 69 |
| 72 // Fixture members. | 70 // Fixture members. |
| 73 scoped_refptr<RTCVideoDecoder> decoder_; | 71 scoped_refptr<RTCVideoDecoder> decoder_; |
| 74 scoped_refptr<MockVideoRenderer> renderer_; | 72 scoped_refptr<media::MockVideoRenderer> renderer_; |
| 75 MockStatisticsCallback stats_callback_object_; | 73 media::MockStatisticsCallback stats_callback_object_; |
| 76 StrictMock<MockFilterHost> host_; | 74 StrictMock<media::MockFilterHost> host_; |
| 77 MessageLoop message_loop_; | 75 MessageLoop message_loop_; |
| 78 | 76 |
| 79 private: | 77 private: |
| 80 DISALLOW_COPY_AND_ASSIGN(RTCVideoDecoderTest); | 78 DISALLOW_COPY_AND_ASSIGN(RTCVideoDecoderTest); |
| 81 }; | 79 }; |
| 82 | 80 |
| 83 const int RTCVideoDecoderTest::kWidth = 176; | 81 const int RTCVideoDecoderTest::kWidth = 176; |
| 84 const int RTCVideoDecoderTest::kHeight = 144; | 82 const int RTCVideoDecoderTest::kHeight = 144; |
| 85 const char* RTCVideoDecoderTest::kUrl = "media://remote/0"; | 83 const char* RTCVideoDecoderTest::kUrl = "media://remote/0"; |
| 86 const PipelineStatistics RTCVideoDecoderTest::kStatistics; | 84 const media::PipelineStatistics RTCVideoDecoderTest::kStatistics; |
| 87 | 85 |
| 88 TEST_F(RTCVideoDecoderTest, Initialize_Successful) { | 86 TEST_F(RTCVideoDecoderTest, Initialize_Successful) { |
| 89 InitializeDecoderSuccessfully(); | 87 InitializeDecoderSuccessfully(); |
| 90 | 88 |
| 91 // Test that the output media format is an uncompressed video surface that | 89 // Test that the output media format is an uncompressed video surface that |
| 92 // matches the dimensions specified by rtc. | 90 // matches the dimensions specified by rtc. |
| 93 const MediaFormat& media_format = decoder_->media_format(); | 91 const media::MediaFormat& media_format = decoder_->media_format(); |
| 94 int width = 0; | 92 int width = 0; |
| 95 int height = 0; | 93 int height = 0; |
| 96 EXPECT_TRUE(media_format.GetAsInteger(MediaFormat::kWidth, &width)); | 94 EXPECT_TRUE(media_format.GetAsInteger(media::MediaFormat::kWidth, &width)); |
| 97 EXPECT_EQ(kWidth, width); | 95 EXPECT_EQ(kWidth, width); |
| 98 EXPECT_TRUE(media_format.GetAsInteger(MediaFormat::kHeight, &height)); | 96 EXPECT_TRUE(media_format.GetAsInteger(media::MediaFormat::kHeight, &height)); |
| 99 EXPECT_EQ(kHeight, height); | 97 EXPECT_EQ(kHeight, height); |
| 100 } | 98 } |
| 101 | 99 |
| 102 TEST_F(RTCVideoDecoderTest, DoSeek) { | 100 TEST_F(RTCVideoDecoderTest, DoSeek) { |
| 103 const base::TimeDelta kZero; | 101 const base::TimeDelta kZero; |
| 104 | 102 |
| 105 InitializeDecoderSuccessfully(); | 103 InitializeDecoderSuccessfully(); |
| 106 | 104 |
| 107 decoder_->set_consume_video_frame_callback( | 105 decoder_->set_consume_video_frame_callback( |
| 108 base::Bind(&MockVideoRenderer::ConsumeVideoFrame, | 106 base::Bind(&media::MockVideoRenderer::ConsumeVideoFrame, |
| 109 base::Unretained(renderer_.get()))); | 107 base::Unretained(renderer_.get()))); |
| 110 | 108 |
| 111 // Expect Seek and verify the results. | 109 // Expect Seek and verify the results. |
| 112 EXPECT_CALL(*renderer_.get(), ConsumeVideoFrame(_)) | 110 EXPECT_CALL(*renderer_.get(), ConsumeVideoFrame(_)) |
| 113 .Times(Limits::kMaxVideoFrames); | 111 .Times(media::Limits::kMaxVideoFrames); |
| 114 decoder_->Seek(kZero, NewExpectedStatusCB(PIPELINE_OK)); | 112 decoder_->Seek(kZero, NewExpectedStatusCB(media::PIPELINE_OK)); |
| 115 | 113 |
| 116 message_loop_.RunAllPending(); | 114 message_loop_.RunAllPending(); |
| 117 EXPECT_EQ(RTCVideoDecoder::kNormal, decoder_->state_); | 115 EXPECT_EQ(RTCVideoDecoder::kNormal, decoder_->state_); |
| 118 } | 116 } |
| 119 | 117 |
| 120 TEST_F(RTCVideoDecoderTest, DoDeliverFrame) { | 118 TEST_F(RTCVideoDecoderTest, DoDeliverFrame) { |
| 121 const base::TimeDelta kZero; | 119 const base::TimeDelta kZero; |
| 122 EXPECT_CALL(host_, GetTime()).WillRepeatedly(Return(base::TimeDelta())); | 120 EXPECT_CALL(host_, GetTime()).WillRepeatedly(Return(base::TimeDelta())); |
| 123 | 121 |
| 124 InitializeDecoderSuccessfully(); | 122 InitializeDecoderSuccessfully(); |
| 125 | 123 |
| 126 // Pass the frame back to decoder | 124 // Pass the frame back to decoder |
| 127 decoder_->set_consume_video_frame_callback( | 125 decoder_->set_consume_video_frame_callback( |
| 128 base::Bind(&RTCVideoDecoder::ProduceVideoFrame, | 126 base::Bind(&RTCVideoDecoder::ProduceVideoFrame, |
| 129 base::Unretained(decoder_.get()))); | 127 base::Unretained(decoder_.get()))); |
| 130 decoder_->Seek(kZero, NewExpectedStatusCB(PIPELINE_OK)); | 128 decoder_->Seek(kZero, NewExpectedStatusCB(media::PIPELINE_OK)); |
| 131 | 129 |
| 132 decoder_->set_consume_video_frame_callback( | 130 decoder_->set_consume_video_frame_callback( |
| 133 base::Bind(&MockVideoRenderer::ConsumeVideoFrame, | 131 base::Bind(&media::MockVideoRenderer::ConsumeVideoFrame, |
| 134 base::Unretained(renderer_.get()))); | 132 base::Unretained(renderer_.get()))); |
| 135 EXPECT_CALL(*renderer_.get(), ConsumeVideoFrame(_)) | 133 EXPECT_CALL(*renderer_.get(), ConsumeVideoFrame(_)) |
| 136 .Times(Limits::kMaxVideoFrames); | 134 .Times(media::Limits::kMaxVideoFrames); |
| 137 | 135 |
| 138 unsigned int video_frame_size = decoder_->width_*decoder_->height_*3/2; | 136 unsigned int video_frame_size = decoder_->width_*decoder_->height_*3/2; |
| 139 unsigned char* video_frame = new unsigned char[video_frame_size]; | 137 unsigned char* video_frame = new unsigned char[video_frame_size]; |
| 140 | 138 |
| 141 for (size_t i = 0; i < Limits::kMaxVideoFrames; ++i) { | 139 for (size_t i = 0; i < media::Limits::kMaxVideoFrames; ++i) { |
| 142 decoder_->DeliverFrame(video_frame, video_frame_size); | 140 decoder_->DeliverFrame(video_frame, video_frame_size); |
| 143 } | 141 } |
| 144 delete [] video_frame; | 142 delete [] video_frame; |
| 145 | 143 |
| 146 message_loop_.RunAllPending(); | 144 message_loop_.RunAllPending(); |
| 147 EXPECT_EQ(RTCVideoDecoder::kNormal, decoder_->state_); | 145 EXPECT_EQ(RTCVideoDecoder::kNormal, decoder_->state_); |
| 148 } | 146 } |
| 149 | 147 |
| 150 TEST_F(RTCVideoDecoderTest, DoFrameSizeChange) { | 148 TEST_F(RTCVideoDecoderTest, DoFrameSizeChange) { |
| 151 InitializeDecoderSuccessfully(); | 149 InitializeDecoderSuccessfully(); |
| 152 | 150 |
| 153 int new_width = kWidth * 2; | 151 int new_width = kWidth * 2; |
| 154 int new_height = kHeight * 2; | 152 int new_height = kHeight * 2; |
| 155 int new_number_of_streams = 0; | 153 int new_number_of_streams = 0; |
| 156 | 154 |
| 157 EXPECT_CALL(host_, | 155 EXPECT_CALL(host_, |
| 158 SetVideoSize(new_width, new_height)).WillRepeatedly(Return()); | 156 SetVideoSize(new_width, new_height)).WillRepeatedly(Return()); |
| 159 | 157 |
| 160 decoder_->FrameSizeChange(new_width, new_height, new_number_of_streams); | 158 decoder_->FrameSizeChange(new_width, new_height, new_number_of_streams); |
| 161 | 159 |
| 162 const MediaFormat& media_format = decoder_->media_format(); | 160 const media::MediaFormat& media_format = decoder_->media_format(); |
| 163 int width = 0; | 161 int width = 0; |
| 164 int height = 0; | 162 int height = 0; |
| 165 EXPECT_TRUE(media_format.GetAsInteger(MediaFormat::kWidth, &width)); | 163 EXPECT_TRUE(media_format.GetAsInteger(media::MediaFormat::kWidth, &width)); |
| 166 EXPECT_EQ(new_width, width); | 164 EXPECT_EQ(new_width, width); |
| 167 EXPECT_TRUE(media_format.GetAsInteger(MediaFormat::kHeight, &height)); | 165 EXPECT_TRUE(media_format.GetAsInteger(media::MediaFormat::kHeight, &height)); |
| 168 EXPECT_EQ(new_height, height); | 166 EXPECT_EQ(new_height, height); |
| 169 | 167 |
| 170 message_loop_.RunAllPending(); | 168 message_loop_.RunAllPending(); |
| 171 } | 169 } |
| 172 | |
| 173 | |
| 174 } // namespace media | |
| OLD | NEW |