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