| Index: media/base/android/media_codec_player_unittest.cc
|
| diff --git a/media/base/android/media_codec_player_unittest.cc b/media/base/android/media_codec_player_unittest.cc
|
| index 516293d71497e1dadd6a72579518048eea7dfeb2..b379aca16a01d78691d83c373ae7de130709c1c7 100644
|
| --- a/media/base/android/media_codec_player_unittest.cc
|
| +++ b/media/base/android/media_codec_player_unittest.cc
|
| @@ -62,6 +62,7 @@ class MockMediaPlayerManager : public MediaPlayerManager {
|
| MockMediaPlayerManager()
|
| : playback_completed_(false),
|
| num_seeks_completed_(0),
|
| + num_video_codec_created_(0),
|
| weak_ptr_factory_(this) {}
|
| ~MockMediaPlayerManager() override {}
|
|
|
| @@ -105,24 +106,23 @@ class MockMediaPlayerManager : public MediaPlayerManager {
|
| MediaPlayerAndroid* GetPlayer(int player_id) override { return nullptr; }
|
| bool RequestPlay(int player_id) override { return true; }
|
|
|
| - void OnMediaResourcesRequested(int player_id) {}
|
| + void OnMediaResourcesRequested(int player_id) { ++num_video_codec_created_; }
|
|
|
| // Time update callback that reports the internal progress of the stream.
|
| // Implementation dependent, used for testing only.
|
| void OnDecodersTimeUpdate(DemuxerStream::Type stream_type,
|
| base::TimeDelta now_playing,
|
| base::TimeDelta last_buffered) {
|
| - PTSTime& hit = first_frame_hit_[stream_type];
|
| - if (hit.is_null())
|
| - hit = PTSTime(now_playing, base::TimeTicks::Now());
|
| + render_stat_[stream_type].AddValue(
|
| + PTSTime(now_playing, base::TimeTicks::Now()));
|
| }
|
|
|
| // First frame information
|
| base::TimeDelta FirstFramePTS(DemuxerStream::Type stream_type) const {
|
| - return first_frame_hit_[stream_type].pts;
|
| + return render_stat_[stream_type].min().pts;
|
| }
|
| base::TimeTicks FirstFrameTime(DemuxerStream::Type stream_type) const {
|
| - return first_frame_hit_[stream_type].time;
|
| + return render_stat_[stream_type].min().time;
|
| }
|
|
|
| base::WeakPtr<MockMediaPlayerManager> GetWeakPtr() {
|
| @@ -138,9 +138,11 @@ class MockMediaPlayerManager : public MediaPlayerManager {
|
| }
|
| bool IsSeekCompleted() const { return num_seeks_completed_ > 0; }
|
| bool HasFirstFrame(DemuxerStream::Type stream_type) const {
|
| - return !first_frame_hit_[stream_type].is_null();
|
| + return render_stat_[stream_type].num_values() != 0;
|
| }
|
|
|
| + int num_video_codec_created() const { return num_video_codec_created_; }
|
| +
|
| struct MediaMetadata {
|
| base::TimeDelta duration;
|
| int width;
|
| @@ -150,20 +152,23 @@ class MockMediaPlayerManager : public MediaPlayerManager {
|
| };
|
| MediaMetadata media_metadata_;
|
|
|
| - Minimax<base::TimeDelta> pts_stat_;
|
| -
|
| - private:
|
| - bool playback_completed_;
|
| - int num_seeks_completed_;
|
| -
|
| struct PTSTime {
|
| base::TimeDelta pts;
|
| base::TimeTicks time;
|
| +
|
| PTSTime() : pts(), time() {}
|
| PTSTime(base::TimeDelta p, base::TimeTicks t) : pts(p), time(t) {}
|
| bool is_null() const { return time.is_null(); }
|
| + bool operator<(const PTSTime& rhs) const { return time < rhs.time; }
|
| };
|
| - PTSTime first_frame_hit_[DemuxerStream::NUM_TYPES];
|
| + Minimax<PTSTime> render_stat_[DemuxerStream::NUM_TYPES];
|
| +
|
| + Minimax<base::TimeDelta> pts_stat_;
|
| +
|
| + private:
|
| + bool playback_completed_;
|
| + int num_seeks_completed_;
|
| + int num_video_codec_created_;
|
|
|
| base::WeakPtrFactory<MockMediaPlayerManager> weak_ptr_factory_;
|
|
|
| @@ -382,6 +387,10 @@ void MockDemuxerAndroid::RequestDemuxerData(DemuxerStream::Type type) {
|
| if (!created)
|
| return;
|
|
|
| + // Request key frame after |kConfigChanged|
|
| + if (type == DemuxerStream::VIDEO && !chunk.demuxer_configs.empty())
|
| + video_factory_->RequestKeyFrame();
|
| +
|
| chunk.type = type;
|
|
|
| // Post to the Media thread. Use the weak pointer to prevent the data arrival
|
| @@ -845,7 +854,7 @@ TEST_F(MediaCodecPlayerTest, VideoPlayTillCompletion) {
|
| }
|
|
|
| // http://crbug.com/518900
|
| -TEST_F(MediaCodecPlayerTest, DISABLED_AudioSeekAfterStop) {
|
| +TEST_F(MediaCodecPlayerTest, AudioSeekAfterStop) {
|
| SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
|
|
|
| // Play for 300 ms, then Pause, then Seek to beginning. The playback should
|
| @@ -978,7 +987,7 @@ TEST_F(MediaCodecPlayerTest, AudioSeekThenPlayThenConfig) {
|
| }
|
|
|
| // http://crbug.com/518900
|
| -TEST_F(MediaCodecPlayerTest, DISABLED_AudioSeekWhilePlaying) {
|
| +TEST_F(MediaCodecPlayerTest, AudioSeekWhilePlaying) {
|
| SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
|
|
|
| // Play for 300 ms, then issue several Seek commands in the row.
|
| @@ -1107,7 +1116,7 @@ TEST_F(MediaCodecPlayerTest, VideoRemoveAndSetSurface) {
|
| }
|
|
|
| // http://crbug.com/518900
|
| -TEST_F(MediaCodecPlayerTest, DISABLED_VideoReleaseAndStart) {
|
| +TEST_F(MediaCodecPlayerTest, VideoReleaseAndStart) {
|
| SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
|
|
|
| base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1000);
|
| @@ -1586,4 +1595,74 @@ TEST_F(MediaCodecPlayerTest, AVPrerollVideoEndsWhilePrerolling) {
|
| EXPECT_FALSE(manager_.HasFirstFrame(DemuxerStream::VIDEO));
|
| }
|
|
|
| +TEST_F(MediaCodecPlayerTest, AVConfigChangeWhilePlaying) {
|
| + SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
|
| +
|
| + // Test that playback continues after video config change.
|
| +
|
| + // Initialize A/V playback
|
| + base::TimeDelta duration = base::TimeDelta::FromMilliseconds(800);
|
| + base::TimeDelta config_change_position =
|
| + base::TimeDelta::FromMilliseconds(400);
|
| +
|
| + base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(800);
|
| +
|
| + demuxer_->SetAudioFactory(
|
| + scoped_ptr<AudioFactory>(new AudioFactory(duration)));
|
| + demuxer_->SetVideoFactory(
|
| + scoped_ptr<VideoFactory>(new VideoFactory(duration)));
|
| +
|
| + demuxer_->video_factory()->RequestConfigChange(config_change_position);
|
| +
|
| + CreatePlayer();
|
| + SetVideoSurface();
|
| +
|
| + // Set special testing callback to receive PTS from decoders.
|
| + player_->SetDecodersTimeCallbackForTests(
|
| + base::Bind(&MockMediaPlayerManager::OnDecodersTimeUpdate,
|
| + base::Unretained(&manager_)));
|
| +
|
| + // Wait till the player is initialized on media thread.
|
| + EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized,
|
| + base::Unretained(demuxer_))));
|
| +
|
| + if (!demuxer_->IsInitialized()) {
|
| + DVLOG(0) << "AVConfigChangeWhilePlaying: demuxer is not initialized";
|
| + return;
|
| + }
|
| +
|
| + // Ask decoders to always reconfigure after the player has been initialized.
|
| + player_->SetAlwaysReconfigureForTests(DemuxerStream::VIDEO);
|
| +
|
| + // Post configuration after the player has been initialized.
|
| + demuxer_->PostInternalConfigs();
|
| +
|
| + // Start and wait for playback.
|
| + player_->Start();
|
| +
|
| + // Wait till we start to play.
|
| + EXPECT_TRUE(
|
| + WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackStarted,
|
| + base::Unretained(&manager_)),
|
| + start_timeout));
|
| +
|
| + // Wait another 100 ms to make sure we are done with initial preroll.
|
| + WaitForDelay(base::TimeDelta::FromMilliseconds(100));
|
| +
|
| + EXPECT_FALSE(player_->IsPrerollingForTests(DemuxerStream::AUDIO));
|
| + EXPECT_FALSE(player_->IsPrerollingForTests(DemuxerStream::VIDEO));
|
| +
|
| + // Wait till completion
|
| + EXPECT_TRUE(
|
| + WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackCompleted,
|
| + base::Unretained(&manager_)),
|
| + base::TimeDelta::FromMilliseconds(2000)));
|
| +
|
| + // The video codec should be recreated upon config changes.
|
| + EXPECT_EQ(2, manager_.num_video_codec_created());
|
| +
|
| + // Check that we did not miss video frames
|
| + EXPECT_EQ(41, manager_.render_stat_[DemuxerStream::VIDEO].num_values());
|
| +}
|
| +
|
| } // namespace media
|
|
|