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/timer/timer.h" | 7 #include "base/timer/timer.h" |
8 #include "media/base/android/demuxer_android.h" | 8 #include "media/base/android/demuxer_android.h" |
9 #include "media/base/android/media_codec_bridge.h" | 9 #include "media/base/android/media_codec_bridge.h" |
10 #include "media/base/android/media_codec_player.h" | 10 #include "media/base/android/media_codec_player.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 return (a - b).magnitude().InMilliseconds() <= tolerance_ms; | 55 return (a - b).magnitude().InMilliseconds() <= tolerance_ms; |
56 } | 56 } |
57 | 57 |
58 // Mock of MediaPlayerManager for testing purpose. | 58 // Mock of MediaPlayerManager for testing purpose. |
59 | 59 |
60 class MockMediaPlayerManager : public MediaPlayerManager { | 60 class MockMediaPlayerManager : public MediaPlayerManager { |
61 public: | 61 public: |
62 MockMediaPlayerManager() | 62 MockMediaPlayerManager() |
63 : playback_completed_(false), | 63 : playback_completed_(false), |
64 num_seeks_completed_(0), | 64 num_seeks_completed_(0), |
| 65 num_audio_codecs_created_(0), |
| 66 num_video_codecs_created_(0), |
65 weak_ptr_factory_(this) {} | 67 weak_ptr_factory_(this) {} |
66 ~MockMediaPlayerManager() override {} | 68 ~MockMediaPlayerManager() override {} |
67 | 69 |
68 MediaResourceGetter* GetMediaResourceGetter() override { return nullptr; } | 70 MediaResourceGetter* GetMediaResourceGetter() override { return nullptr; } |
69 MediaUrlInterceptor* GetMediaUrlInterceptor() override { return nullptr; } | 71 MediaUrlInterceptor* GetMediaUrlInterceptor() override { return nullptr; } |
70 | 72 |
71 // Regular time update callback, reports current playback time to | 73 // Regular time update callback, reports current playback time to |
72 // MediaPlayerManager. | 74 // MediaPlayerManager. |
73 void OnTimeUpdate(int player_id, | 75 void OnTimeUpdate(int player_id, |
74 base::TimeDelta current_timestamp, | 76 base::TimeDelta current_timestamp, |
(...skipping 30 matching lines...) Expand all Loading... |
105 MediaPlayerAndroid* GetPlayer(int player_id) override { return nullptr; } | 107 MediaPlayerAndroid* GetPlayer(int player_id) override { return nullptr; } |
106 bool RequestPlay(int player_id) override { return true; } | 108 bool RequestPlay(int player_id) override { return true; } |
107 | 109 |
108 void OnMediaResourcesRequested(int player_id) {} | 110 void OnMediaResourcesRequested(int player_id) {} |
109 | 111 |
110 // Time update callback that reports the internal progress of the stream. | 112 // Time update callback that reports the internal progress of the stream. |
111 // Implementation dependent, used for testing only. | 113 // Implementation dependent, used for testing only. |
112 void OnDecodersTimeUpdate(DemuxerStream::Type stream_type, | 114 void OnDecodersTimeUpdate(DemuxerStream::Type stream_type, |
113 base::TimeDelta now_playing, | 115 base::TimeDelta now_playing, |
114 base::TimeDelta last_buffered) { | 116 base::TimeDelta last_buffered) { |
115 PTSTime& hit = first_frame_hit_[stream_type]; | 117 render_stat_[stream_type].AddValue( |
116 if (hit.is_null()) | 118 PTSTime(now_playing, base::TimeTicks::Now())); |
117 hit = PTSTime(now_playing, base::TimeTicks::Now()); | 119 } |
| 120 |
| 121 // Notification called on MediaCodec creation. |
| 122 // Implementation dependent, used for testing only. |
| 123 void OnMediaCodecCreated(DemuxerStream::Type stream_type) { |
| 124 if (stream_type == DemuxerStream::AUDIO) |
| 125 ++num_audio_codecs_created_; |
| 126 else if (stream_type == DemuxerStream::VIDEO) |
| 127 ++num_video_codecs_created_; |
118 } | 128 } |
119 | 129 |
120 // First frame information | 130 // First frame information |
121 base::TimeDelta FirstFramePTS(DemuxerStream::Type stream_type) const { | 131 base::TimeDelta FirstFramePTS(DemuxerStream::Type stream_type) const { |
122 return first_frame_hit_[stream_type].pts; | 132 return render_stat_[stream_type].min().pts; |
123 } | 133 } |
124 base::TimeTicks FirstFrameTime(DemuxerStream::Type stream_type) const { | 134 base::TimeTicks FirstFrameTime(DemuxerStream::Type stream_type) const { |
125 return first_frame_hit_[stream_type].time; | 135 return render_stat_[stream_type].min().time; |
126 } | 136 } |
127 | 137 |
128 base::WeakPtr<MockMediaPlayerManager> GetWeakPtr() { | 138 base::WeakPtr<MockMediaPlayerManager> GetWeakPtr() { |
129 return weak_ptr_factory_.GetWeakPtr(); | 139 return weak_ptr_factory_.GetWeakPtr(); |
130 } | 140 } |
131 | 141 |
132 // Conditions to wait for. | 142 // Conditions to wait for. |
133 bool IsMetadataChanged() const { return media_metadata_.modified; } | 143 bool IsMetadataChanged() const { return media_metadata_.modified; } |
134 bool IsPlaybackCompleted() const { return playback_completed_; } | 144 bool IsPlaybackCompleted() const { return playback_completed_; } |
135 bool IsPlaybackStarted() const { return pts_stat_.num_values() > 0; } | 145 bool IsPlaybackStarted() const { return pts_stat_.num_values() > 0; } |
136 bool IsPlaybackBeyondPosition(const base::TimeDelta& pts) const { | 146 bool IsPlaybackBeyondPosition(const base::TimeDelta& pts) const { |
137 return pts_stat_.max() > pts; | 147 return pts_stat_.max() > pts; |
138 } | 148 } |
139 bool IsSeekCompleted() const { return num_seeks_completed_ > 0; } | 149 bool IsSeekCompleted() const { return num_seeks_completed_ > 0; } |
140 bool HasFirstFrame(DemuxerStream::Type stream_type) const { | 150 bool HasFirstFrame(DemuxerStream::Type stream_type) const { |
141 return !first_frame_hit_[stream_type].is_null(); | 151 return render_stat_[stream_type].num_values() != 0; |
142 } | 152 } |
143 | 153 |
| 154 int num_audio_codecs_created() const { return num_audio_codecs_created_; } |
| 155 int num_video_codecs_created() const { return num_video_codecs_created_; } |
| 156 |
144 struct MediaMetadata { | 157 struct MediaMetadata { |
145 base::TimeDelta duration; | 158 base::TimeDelta duration; |
146 int width; | 159 int width; |
147 int height; | 160 int height; |
148 bool modified; | 161 bool modified; |
149 MediaMetadata() : width(0), height(0), modified(false) {} | 162 MediaMetadata() : width(0), height(0), modified(false) {} |
150 }; | 163 }; |
151 MediaMetadata media_metadata_; | 164 MediaMetadata media_metadata_; |
152 | 165 |
| 166 struct PTSTime { |
| 167 base::TimeDelta pts; |
| 168 base::TimeTicks time; |
| 169 |
| 170 PTSTime() : pts(), time() {} |
| 171 PTSTime(base::TimeDelta p, base::TimeTicks t) : pts(p), time(t) {} |
| 172 bool is_null() const { return time.is_null(); } |
| 173 bool operator<(const PTSTime& rhs) const { return time < rhs.time; } |
| 174 }; |
| 175 Minimax<PTSTime> render_stat_[DemuxerStream::NUM_TYPES]; |
| 176 |
153 Minimax<base::TimeDelta> pts_stat_; | 177 Minimax<base::TimeDelta> pts_stat_; |
154 | 178 |
155 private: | 179 private: |
156 bool playback_completed_; | 180 bool playback_completed_; |
157 int num_seeks_completed_; | 181 int num_seeks_completed_; |
158 | 182 int num_audio_codecs_created_; |
159 struct PTSTime { | 183 int num_video_codecs_created_; |
160 base::TimeDelta pts; | |
161 base::TimeTicks time; | |
162 PTSTime() : pts(), time() {} | |
163 PTSTime(base::TimeDelta p, base::TimeTicks t) : pts(p), time(t) {} | |
164 bool is_null() const { return time.is_null(); } | |
165 }; | |
166 PTSTime first_frame_hit_[DemuxerStream::NUM_TYPES]; | |
167 | 184 |
168 base::WeakPtrFactory<MockMediaPlayerManager> weak_ptr_factory_; | 185 base::WeakPtrFactory<MockMediaPlayerManager> weak_ptr_factory_; |
169 | 186 |
170 DISALLOW_COPY_AND_ASSIGN(MockMediaPlayerManager); | 187 DISALLOW_COPY_AND_ASSIGN(MockMediaPlayerManager); |
171 }; | 188 }; |
172 | 189 |
173 // Helper method that creates demuxer configuration. | 190 // Helper method that creates demuxer configuration. |
174 | 191 |
175 DemuxerConfigs CreateAudioVideoConfigs(const base::TimeDelta& duration, | 192 DemuxerConfigs CreateAudioVideoConfigs(const base::TimeDelta& duration, |
176 const gfx::Size& video_size) { | 193 const gfx::Size& video_size) { |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 | 392 |
376 bool created = false; | 393 bool created = false; |
377 if (type == DemuxerStream::AUDIO && audio_factory_) | 394 if (type == DemuxerStream::AUDIO && audio_factory_) |
378 created = audio_factory_->CreateChunk(&chunk, &delay); | 395 created = audio_factory_->CreateChunk(&chunk, &delay); |
379 else if (type == DemuxerStream::VIDEO && video_factory_) | 396 else if (type == DemuxerStream::VIDEO && video_factory_) |
380 created = video_factory_->CreateChunk(&chunk, &delay); | 397 created = video_factory_->CreateChunk(&chunk, &delay); |
381 | 398 |
382 if (!created) | 399 if (!created) |
383 return; | 400 return; |
384 | 401 |
| 402 // Request key frame after |kConfigChanged| |
| 403 if (type == DemuxerStream::VIDEO && !chunk.demuxer_configs.empty()) |
| 404 video_factory_->RequestKeyFrame(); |
| 405 |
385 chunk.type = type; | 406 chunk.type = type; |
386 | 407 |
387 // Post to the Media thread. Use the weak pointer to prevent the data arrival | 408 // Post to the Media thread. Use the weak pointer to prevent the data arrival |
388 // after the player has been deleted. | 409 // after the player has been deleted. |
389 GetMediaTaskRunner()->PostDelayedTask( | 410 GetMediaTaskRunner()->PostDelayedTask( |
390 FROM_HERE, base::Bind(&MockDemuxerAndroid::OnDemuxerDataAvailable, | 411 FROM_HERE, base::Bind(&MockDemuxerAndroid::OnDemuxerDataAvailable, |
391 weak_factory_.GetWeakPtr(), chunk), | 412 weak_factory_.GetWeakPtr(), chunk), |
392 delay); | 413 delay); |
393 } | 414 } |
394 | 415 |
(...skipping 1162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1557 | 1578 |
1558 // Post configuration after the player has been initialized. | 1579 // Post configuration after the player has been initialized. |
1559 demuxer_->PostInternalConfigs(); | 1580 demuxer_->PostInternalConfigs(); |
1560 | 1581 |
1561 // Issue SeekTo(). | 1582 // Issue SeekTo(). |
1562 player_->SeekTo(seek_position); | 1583 player_->SeekTo(seek_position); |
1563 | 1584 |
1564 // Start the playback. | 1585 // Start the playback. |
1565 player_->Start(); | 1586 player_->Start(); |
1566 | 1587 |
1567 // The video decoder should start prerolling | 1588 // The video decoder should start prerolling. |
1568 // Wait till preroll starts. | 1589 // Wait till preroll starts. |
1569 EXPECT_TRUE(WaitForCondition( | 1590 EXPECT_TRUE(WaitForCondition( |
1570 base::Bind(&MediaCodecPlayer::IsPrerollingForTests, | 1591 base::Bind(&MediaCodecPlayer::IsPrerollingForTests, |
1571 base::Unretained(player_), DemuxerStream::VIDEO), | 1592 base::Unretained(player_), DemuxerStream::VIDEO), |
1572 start_timeout)); | 1593 start_timeout)); |
1573 | 1594 |
1574 // Wait for playback to start. | 1595 // Wait for playback to start. |
1575 EXPECT_TRUE( | 1596 EXPECT_TRUE( |
1576 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackStarted, | 1597 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackStarted, |
1577 base::Unretained(&manager_)), | 1598 base::Unretained(&manager_)), |
1578 preroll_timeout)); | 1599 preroll_timeout)); |
1579 | 1600 |
1580 EXPECT_TRUE(manager_.HasFirstFrame(DemuxerStream::AUDIO)); | 1601 EXPECT_TRUE(manager_.HasFirstFrame(DemuxerStream::AUDIO)); |
1581 | 1602 |
1582 // Play till completion. | 1603 // Play till completion. |
1583 EXPECT_TRUE( | 1604 EXPECT_TRUE( |
1584 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackCompleted, | 1605 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackCompleted, |
1585 base::Unretained(&manager_)))); | 1606 base::Unretained(&manager_)))); |
1586 | 1607 |
1587 // There should not be any video frames. | 1608 // There should not be any video frames. |
1588 EXPECT_FALSE(manager_.HasFirstFrame(DemuxerStream::VIDEO)); | 1609 EXPECT_FALSE(manager_.HasFirstFrame(DemuxerStream::VIDEO)); |
1589 } | 1610 } |
1590 | 1611 |
| 1612 TEST_F(MediaCodecPlayerTest, VideoConfigChangeWhilePlaying) { |
| 1613 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1614 |
| 1615 // Test that video only playback continues after video config change. |
| 1616 |
| 1617 // Initialize video playback |
| 1618 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200); |
| 1619 base::TimeDelta config_change_position = |
| 1620 base::TimeDelta::FromMilliseconds(1000); |
| 1621 |
| 1622 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(2000); |
| 1623 base::TimeDelta completion_timeout = base::TimeDelta::FromMilliseconds(3000); |
| 1624 |
| 1625 demuxer_->SetVideoFactory( |
| 1626 scoped_ptr<VideoFactory>(new VideoFactory(duration))); |
| 1627 |
| 1628 demuxer_->video_factory()->RequestConfigChange(config_change_position); |
| 1629 |
| 1630 CreatePlayer(); |
| 1631 SetVideoSurface(); |
| 1632 |
| 1633 // Wait till the player is initialized on media thread. |
| 1634 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized, |
| 1635 base::Unretained(demuxer_)))); |
| 1636 |
| 1637 if (!demuxer_->IsInitialized()) { |
| 1638 DVLOG(0) << "AVConfigChangeWhilePlaying: demuxer is not initialized"; |
| 1639 return; |
| 1640 } |
| 1641 |
| 1642 // Ask decoders to always reconfigure after the player has been initialized. |
| 1643 player_->SetAlwaysReconfigureForTests(DemuxerStream::VIDEO); |
| 1644 |
| 1645 // Set a testing callback to receive PTS from decoders. |
| 1646 player_->SetDecodersTimeCallbackForTests( |
| 1647 base::Bind(&MockMediaPlayerManager::OnDecodersTimeUpdate, |
| 1648 base::Unretained(&manager_))); |
| 1649 |
| 1650 // Set a testing callback to receive MediaCodec creation events from decoders. |
| 1651 player_->SetCodecCreatedCallbackForTests( |
| 1652 base::Bind(&MockMediaPlayerManager::OnMediaCodecCreated, |
| 1653 base::Unretained(&manager_))); |
| 1654 |
| 1655 // Post configuration after the player has been initialized. |
| 1656 demuxer_->PostInternalConfigs(); |
| 1657 |
| 1658 // Start and wait for playback. |
| 1659 player_->Start(); |
| 1660 |
| 1661 // Wait till we start to play. |
| 1662 EXPECT_TRUE( |
| 1663 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackStarted, |
| 1664 base::Unretained(&manager_)), |
| 1665 start_timeout)); |
| 1666 |
| 1667 // Wait till completion |
| 1668 EXPECT_TRUE( |
| 1669 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackCompleted, |
| 1670 base::Unretained(&manager_)), |
| 1671 completion_timeout)); |
| 1672 |
| 1673 // The video codec should be recreated upon config changes. |
| 1674 EXPECT_EQ(2, manager_.num_video_codecs_created()); |
| 1675 |
| 1676 // Check that we did not miss video frames |
| 1677 int expected_video_frames = duration / kVideoFramePeriod + 1; |
| 1678 EXPECT_EQ(expected_video_frames, |
| 1679 manager_.render_stat_[DemuxerStream::VIDEO].num_values()); |
| 1680 } |
| 1681 |
| 1682 TEST_F(MediaCodecPlayerTest, AVVideoConfigChangeWhilePlaying) { |
| 1683 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1684 |
| 1685 // Test that A/V playback continues after video config change. |
| 1686 |
| 1687 // Initialize A/V playback |
| 1688 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200); |
| 1689 base::TimeDelta config_change_position = |
| 1690 base::TimeDelta::FromMilliseconds(1000); |
| 1691 |
| 1692 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(2000); |
| 1693 base::TimeDelta completion_timeout = base::TimeDelta::FromMilliseconds(3000); |
| 1694 |
| 1695 demuxer_->SetAudioFactory( |
| 1696 scoped_ptr<AudioFactory>(new AudioFactory(duration))); |
| 1697 demuxer_->SetVideoFactory( |
| 1698 scoped_ptr<VideoFactory>(new VideoFactory(duration))); |
| 1699 |
| 1700 demuxer_->video_factory()->RequestConfigChange(config_change_position); |
| 1701 |
| 1702 CreatePlayer(); |
| 1703 SetVideoSurface(); |
| 1704 |
| 1705 // Wait till the player is initialized on media thread. |
| 1706 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized, |
| 1707 base::Unretained(demuxer_)))); |
| 1708 |
| 1709 if (!demuxer_->IsInitialized()) { |
| 1710 DVLOG(0) << "AVConfigChangeWhilePlaying: demuxer is not initialized"; |
| 1711 return; |
| 1712 } |
| 1713 |
| 1714 // Ask decoders to always reconfigure after the player has been initialized. |
| 1715 player_->SetAlwaysReconfigureForTests(DemuxerStream::VIDEO); |
| 1716 |
| 1717 // Set a testing callback to receive PTS from decoders. |
| 1718 player_->SetDecodersTimeCallbackForTests( |
| 1719 base::Bind(&MockMediaPlayerManager::OnDecodersTimeUpdate, |
| 1720 base::Unretained(&manager_))); |
| 1721 |
| 1722 // Set a testing callback to receive MediaCodec creation events from decoders. |
| 1723 player_->SetCodecCreatedCallbackForTests( |
| 1724 base::Bind(&MockMediaPlayerManager::OnMediaCodecCreated, |
| 1725 base::Unretained(&manager_))); |
| 1726 |
| 1727 // Post configuration after the player has been initialized. |
| 1728 demuxer_->PostInternalConfigs(); |
| 1729 |
| 1730 // Start and wait for playback. |
| 1731 player_->Start(); |
| 1732 |
| 1733 // Wait till we start to play. |
| 1734 EXPECT_TRUE( |
| 1735 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackStarted, |
| 1736 base::Unretained(&manager_)), |
| 1737 start_timeout)); |
| 1738 |
| 1739 // Wait till completion |
| 1740 EXPECT_TRUE( |
| 1741 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackCompleted, |
| 1742 base::Unretained(&manager_)), |
| 1743 completion_timeout)); |
| 1744 |
| 1745 // The audio codec should be kept. |
| 1746 EXPECT_EQ(1, manager_.num_audio_codecs_created()); |
| 1747 |
| 1748 // The video codec should be recreated upon config changes. |
| 1749 EXPECT_EQ(2, manager_.num_video_codecs_created()); |
| 1750 |
| 1751 // Check that we did not miss video frames |
| 1752 int expected_video_frames = duration / kVideoFramePeriod + 1; |
| 1753 EXPECT_EQ(expected_video_frames, |
| 1754 manager_.render_stat_[DemuxerStream::VIDEO].num_values()); |
| 1755 |
| 1756 // Check that we did not miss audio frames. We expect two postponed frames |
| 1757 // that are not reported. |
| 1758 // For Nexus 4 KitKat the AAC decoder seems to swallow the first frame |
| 1759 // but reports the last pts twice, maybe it just shifts the reported PTS. |
| 1760 int expected_audio_frames = duration / kAudioFramePeriod + 1 - 2; |
| 1761 EXPECT_EQ(expected_audio_frames, |
| 1762 manager_.render_stat_[DemuxerStream::AUDIO].num_values()); |
| 1763 } |
| 1764 |
| 1765 TEST_F(MediaCodecPlayerTest, AVAudioConfigChangeWhilePlaying) { |
| 1766 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1767 |
| 1768 // Test that A/V playback continues after audio config change. |
| 1769 |
| 1770 // Initialize A/V playback |
| 1771 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200); |
| 1772 base::TimeDelta config_change_position = |
| 1773 base::TimeDelta::FromMilliseconds(1000); |
| 1774 |
| 1775 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(2000); |
| 1776 base::TimeDelta completion_timeout = base::TimeDelta::FromMilliseconds(3000); |
| 1777 |
| 1778 demuxer_->SetAudioFactory( |
| 1779 scoped_ptr<AudioFactory>(new AudioFactory(duration))); |
| 1780 demuxer_->SetVideoFactory( |
| 1781 scoped_ptr<VideoFactory>(new VideoFactory(duration))); |
| 1782 |
| 1783 demuxer_->audio_factory()->RequestConfigChange(config_change_position); |
| 1784 |
| 1785 CreatePlayer(); |
| 1786 SetVideoSurface(); |
| 1787 |
| 1788 // Wait till the player is initialized on media thread. |
| 1789 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized, |
| 1790 base::Unretained(demuxer_)))); |
| 1791 |
| 1792 if (!demuxer_->IsInitialized()) { |
| 1793 DVLOG(0) << "AVConfigChangeWhilePlaying: demuxer is not initialized"; |
| 1794 return; |
| 1795 } |
| 1796 |
| 1797 // Ask decoders to always reconfigure after the player has been initialized. |
| 1798 player_->SetAlwaysReconfigureForTests(DemuxerStream::AUDIO); |
| 1799 |
| 1800 // Set a testing callback to receive PTS from decoders. |
| 1801 player_->SetDecodersTimeCallbackForTests( |
| 1802 base::Bind(&MockMediaPlayerManager::OnDecodersTimeUpdate, |
| 1803 base::Unretained(&manager_))); |
| 1804 |
| 1805 // Set a testing callback to receive MediaCodec creation events from decoders. |
| 1806 player_->SetCodecCreatedCallbackForTests( |
| 1807 base::Bind(&MockMediaPlayerManager::OnMediaCodecCreated, |
| 1808 base::Unretained(&manager_))); |
| 1809 |
| 1810 // Post configuration after the player has been initialized. |
| 1811 demuxer_->PostInternalConfigs(); |
| 1812 |
| 1813 // Start and wait for playback. |
| 1814 player_->Start(); |
| 1815 |
| 1816 // Wait till we start to play. |
| 1817 EXPECT_TRUE( |
| 1818 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackStarted, |
| 1819 base::Unretained(&manager_)), |
| 1820 start_timeout)); |
| 1821 |
| 1822 // Wait till completion |
| 1823 EXPECT_TRUE( |
| 1824 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackCompleted, |
| 1825 base::Unretained(&manager_)), |
| 1826 completion_timeout)); |
| 1827 |
| 1828 // The audio codec should be recreated upon config changes. |
| 1829 EXPECT_EQ(2, manager_.num_audio_codecs_created()); |
| 1830 |
| 1831 // The video codec should be kept. |
| 1832 EXPECT_EQ(1, manager_.num_video_codecs_created()); |
| 1833 |
| 1834 // Check that we did not miss video frames. |
| 1835 int expected_video_frames = duration / kVideoFramePeriod + 1; |
| 1836 EXPECT_EQ(expected_video_frames, |
| 1837 manager_.render_stat_[DemuxerStream::VIDEO].num_values()); |
| 1838 |
| 1839 // Check that we did not miss audio frames. We expect two postponed frames |
| 1840 // that are not reported. |
| 1841 int expected_audio_frames = duration / kAudioFramePeriod + 1 - 2; |
| 1842 EXPECT_EQ(expected_audio_frames, |
| 1843 manager_.render_stat_[DemuxerStream::AUDIO].num_values()); |
| 1844 } |
| 1845 |
1591 } // namespace media | 1846 } // namespace media |
OLD | NEW |