OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/logging.h" | 6 #include "base/logging.h" |
7 #include "base/thread_task_runner_handle.h" | 7 #include "base/thread_task_runner_handle.h" |
8 #include "base/timer/timer.h" | 8 #include "base/timer/timer.h" |
9 #include "media/base/android/media_codec_audio_decoder.h" | 9 #include "media/base/android/media_codec_audio_decoder.h" |
10 #include "media/base/android/media_codec_bridge.h" | 10 #include "media/base/android/media_codec_bridge.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 void CreateAudioDecoder(); | 142 void CreateAudioDecoder(); |
143 void CreateVideoDecoder(); | 143 void CreateVideoDecoder(); |
144 void SetVideoSurface(); | 144 void SetVideoSurface(); |
145 void SetStopRequestAtTime(const base::TimeDelta& time) { | 145 void SetStopRequestAtTime(const base::TimeDelta& time) { |
146 stop_request_time_ = time; | 146 stop_request_time_ = time; |
147 } | 147 } |
148 | 148 |
149 // Decoder callbacks. | 149 // Decoder callbacks. |
150 void OnDataRequested(); | 150 void OnDataRequested(); |
151 void OnStarvation() { is_starved_ = true; } | 151 void OnStarvation() { is_starved_ = true; } |
| 152 void OnDecoderDrained() {} |
152 void OnStopDone() { is_stopped_ = true; } | 153 void OnStopDone() { is_stopped_ = true; } |
153 void OnError() { DVLOG(0) << "MediaCodecDecoderTest::" << __FUNCTION__; } | 154 void OnError() { DVLOG(0) << "MediaCodecDecoderTest::" << __FUNCTION__; } |
154 void OnUpdateCurrentTime(base::TimeDelta now_playing, | 155 void OnUpdateCurrentTime(base::TimeDelta now_playing, |
155 base::TimeDelta last_buffered) { | 156 base::TimeDelta last_buffered) { |
156 // Add the |last_buffered| value for PTS. For video it is the same as | 157 // Add the |last_buffered| value for PTS. For video it is the same as |
157 // |now_playing| and is equal to PTS, for audio |last_buffered| should | 158 // |now_playing| and is equal to PTS, for audio |last_buffered| should |
158 // exceed PTS. | 159 // exceed PTS. |
159 pts_stat_.AddValue(last_buffered); | 160 pts_stat_.AddValue(last_buffered); |
160 | 161 |
161 if (stop_request_time_ != kNoTimestamp() && | 162 if (stop_request_time_ != kNoTimestamp() && |
162 now_playing >= stop_request_time_) { | 163 now_playing >= stop_request_time_) { |
163 stop_request_time_ = kNoTimestamp(); | 164 stop_request_time_ = kNoTimestamp(); |
164 decoder_->RequestToStop(); | 165 decoder_->RequestToStop(); |
165 } | 166 } |
166 } | 167 } |
167 | 168 |
168 void OnVideoSizeChanged(const gfx::Size& video_size) {} | 169 void OnVideoSizeChanged(const gfx::Size& video_size) { |
| 170 video_size_ = video_size; |
| 171 } |
| 172 |
169 void OnVideoCodecCreated() {} | 173 void OnVideoCodecCreated() {} |
170 | 174 |
171 scoped_ptr<MediaCodecDecoder> decoder_; | 175 scoped_ptr<MediaCodecDecoder> decoder_; |
172 scoped_ptr<TestDataFactory> data_factory_; | 176 scoped_ptr<TestDataFactory> data_factory_; |
173 Minimax<base::TimeDelta> pts_stat_; | 177 Minimax<base::TimeDelta> pts_stat_; |
| 178 gfx::Size video_size_; |
174 | 179 |
175 private: | 180 private: |
176 bool is_timeout_expired() const { return is_timeout_expired_; } | 181 bool is_timeout_expired() const { return is_timeout_expired_; } |
177 void SetTimeoutExpired(bool value) { is_timeout_expired_ = value; } | 182 void SetTimeoutExpired(bool value) { is_timeout_expired_ = value; } |
178 | 183 |
179 base::MessageLoop message_loop_; | 184 base::MessageLoop message_loop_; |
180 bool is_timeout_expired_; | 185 bool is_timeout_expired_; |
181 | 186 |
182 bool is_prefetched_; | 187 bool is_prefetched_; |
183 bool is_stopped_; | 188 bool is_stopped_; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 229 |
225 DCHECK(!timer.IsRunning()); | 230 DCHECK(!timer.IsRunning()); |
226 return false; | 231 return false; |
227 } | 232 } |
228 | 233 |
229 void MediaCodecDecoderTest::CreateAudioDecoder() { | 234 void MediaCodecDecoderTest::CreateAudioDecoder() { |
230 decoder_ = scoped_ptr<MediaCodecDecoder>(new MediaCodecAudioDecoder( | 235 decoder_ = scoped_ptr<MediaCodecDecoder>(new MediaCodecAudioDecoder( |
231 task_runner_, base::Bind(&MediaCodecDecoderTest::OnDataRequested, | 236 task_runner_, base::Bind(&MediaCodecDecoderTest::OnDataRequested, |
232 base::Unretained(this)), | 237 base::Unretained(this)), |
233 base::Bind(&MediaCodecDecoderTest::OnStarvation, base::Unretained(this)), | 238 base::Bind(&MediaCodecDecoderTest::OnStarvation, base::Unretained(this)), |
| 239 base::Bind(&MediaCodecDecoderTest::OnDecoderDrained, |
| 240 base::Unretained(this)), |
234 base::Bind(&MediaCodecDecoderTest::OnStopDone, base::Unretained(this)), | 241 base::Bind(&MediaCodecDecoderTest::OnStopDone, base::Unretained(this)), |
235 base::Bind(&MediaCodecDecoderTest::OnError, base::Unretained(this)), | 242 base::Bind(&MediaCodecDecoderTest::OnError, base::Unretained(this)), |
236 base::Bind(&MediaCodecDecoderTest::OnUpdateCurrentTime, | 243 base::Bind(&MediaCodecDecoderTest::OnUpdateCurrentTime, |
237 base::Unretained(this)))); | 244 base::Unretained(this)))); |
238 | 245 |
239 data_available_cb_ = base::Bind(&MediaCodecDecoder::OnDemuxerDataAvailable, | 246 data_available_cb_ = base::Bind(&MediaCodecDecoder::OnDemuxerDataAvailable, |
240 base::Unretained(decoder_.get())); | 247 base::Unretained(decoder_.get())); |
241 } | 248 } |
242 | 249 |
243 void MediaCodecDecoderTest::CreateVideoDecoder() { | 250 void MediaCodecDecoderTest::CreateVideoDecoder() { |
244 decoder_ = scoped_ptr<MediaCodecDecoder>(new MediaCodecVideoDecoder( | 251 decoder_ = scoped_ptr<MediaCodecDecoder>(new MediaCodecVideoDecoder( |
245 task_runner_, base::Bind(&MediaCodecDecoderTest::OnDataRequested, | 252 task_runner_, base::Bind(&MediaCodecDecoderTest::OnDataRequested, |
246 base::Unretained(this)), | 253 base::Unretained(this)), |
247 base::Bind(&MediaCodecDecoderTest::OnStarvation, base::Unretained(this)), | 254 base::Bind(&MediaCodecDecoderTest::OnStarvation, base::Unretained(this)), |
| 255 base::Bind(&MediaCodecDecoderTest::OnDecoderDrained, |
| 256 base::Unretained(this)), |
248 base::Bind(&MediaCodecDecoderTest::OnStopDone, base::Unretained(this)), | 257 base::Bind(&MediaCodecDecoderTest::OnStopDone, base::Unretained(this)), |
249 base::Bind(&MediaCodecDecoderTest::OnError, base::Unretained(this)), | 258 base::Bind(&MediaCodecDecoderTest::OnError, base::Unretained(this)), |
250 base::Bind(&MediaCodecDecoderTest::OnUpdateCurrentTime, | 259 base::Bind(&MediaCodecDecoderTest::OnUpdateCurrentTime, |
251 base::Unretained(this)), | 260 base::Unretained(this)), |
252 base::Bind(&MediaCodecDecoderTest::OnVideoSizeChanged, | 261 base::Bind(&MediaCodecDecoderTest::OnVideoSizeChanged, |
253 base::Unretained(this)), | 262 base::Unretained(this)), |
254 base::Bind(&MediaCodecDecoderTest::OnVideoCodecCreated, | 263 base::Bind(&MediaCodecDecoderTest::OnVideoCodecCreated, |
255 base::Unretained(this)))); | 264 base::Unretained(this)))); |
256 | 265 |
257 data_available_cb_ = base::Bind(&MediaCodecDecoder::OnDemuxerDataAvailable, | 266 data_available_cb_ = base::Bind(&MediaCodecDecoder::OnDemuxerDataAvailable, |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 // After starvation we should be able to stop decoder. | 658 // After starvation we should be able to stop decoder. |
650 decoder_->RequestToStop(); | 659 decoder_->RequestToStop(); |
651 | 660 |
652 EXPECT_TRUE(WaitForCondition( | 661 EXPECT_TRUE(WaitForCondition( |
653 base::Bind(&MediaCodecDecoderTest::is_stopped, base::Unretained(this)))); | 662 base::Bind(&MediaCodecDecoderTest::is_stopped, base::Unretained(this)))); |
654 | 663 |
655 EXPECT_TRUE(decoder_->IsStopped()); | 664 EXPECT_TRUE(decoder_->IsStopped()); |
656 EXPECT_FALSE(decoder_->IsCompleted()); | 665 EXPECT_FALSE(decoder_->IsCompleted()); |
657 } | 666 } |
658 | 667 |
| 668 TEST_F(MediaCodecDecoderTest, VideoFirstUnitIsReconfig) { |
| 669 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 670 |
| 671 // Test that the kConfigChanged unit that comes before the first data unit |
| 672 // gets processed, i.e. is not lost. |
| 673 |
| 674 CreateVideoDecoder(); |
| 675 |
| 676 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(200); |
| 677 base::TimeDelta timeout = base::TimeDelta::FromMilliseconds(1000); |
| 678 SetDataFactory(scoped_ptr<VideoFactory>(new VideoFactory(duration))); |
| 679 |
| 680 // Ask factory to produce initial configuration unit. The configuraton will |
| 681 // be factory.GetConfigs(). |
| 682 data_factory_->RequestInitialConfigs(); |
| 683 |
| 684 // Create am alternative configuration (we just alter video size). |
| 685 DemuxerConfigs alt_configs = data_factory_->GetConfigs(); |
| 686 alt_configs.video_size = gfx::Size(100, 100); |
| 687 |
| 688 // Pass the alternative configuration to decoder. |
| 689 decoder_->SetDemuxerConfigs(alt_configs); |
| 690 |
| 691 // Prefetch. |
| 692 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched, |
| 693 base::Unretained(this), true)); |
| 694 |
| 695 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched, |
| 696 base::Unretained(this)))); |
| 697 |
| 698 // Current implementation reports the new video size after |
| 699 // SetDemuxerConfigs(), verify that it is alt size. |
| 700 EXPECT_EQ(alt_configs.video_size, video_size_); |
| 701 |
| 702 SetVideoSurface(); |
| 703 |
| 704 // Configure. |
| 705 EXPECT_EQ(MediaCodecDecoder::kConfigOk, decoder_->Configure()); |
| 706 |
| 707 // Start. |
| 708 EXPECT_TRUE(decoder_->Start(base::TimeDelta::FromMilliseconds(0))); |
| 709 |
| 710 // Wait for completion. |
| 711 EXPECT_TRUE(WaitForCondition( |
| 712 base::Bind(&MediaCodecDecoderTest::is_stopped, base::Unretained(this)), |
| 713 timeout)); |
| 714 |
| 715 EXPECT_TRUE(decoder_->IsStopped()); |
| 716 EXPECT_TRUE(decoder_->IsCompleted()); |
| 717 EXPECT_EQ(data_factory_->last_pts(), pts_stat_.max()); |
| 718 |
| 719 // Check that the reported video size is the one from the in-stream configs. |
| 720 EXPECT_EQ(data_factory_->GetConfigs().video_size, video_size_); |
| 721 } |
| 722 |
659 } // namespace media | 723 } // namespace media |
OLD | NEW |