OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <deque> | 9 #include <deque> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
18 #include "media/base/decrypt_config.h" | 18 #include "media/base/decrypt_config.h" |
19 #include "media/base/media_log.h" | 19 #include "media/base/media_log.h" |
| 20 #include "media/base/media_tracks.h" |
20 #include "media/base/mock_demuxer_host.h" | 21 #include "media/base/mock_demuxer_host.h" |
21 #include "media/base/test_helpers.h" | 22 #include "media/base/test_helpers.h" |
22 #include "media/base/timestamp_constants.h" | 23 #include "media/base/timestamp_constants.h" |
23 #include "media/ffmpeg/ffmpeg_common.h" | 24 #include "media/ffmpeg/ffmpeg_common.h" |
24 #include "media/filters/ffmpeg_demuxer.h" | 25 #include "media/filters/ffmpeg_demuxer.h" |
25 #include "media/filters/file_data_source.h" | 26 #include "media/filters/file_data_source.h" |
26 #include "media/formats/mp4/avc.h" | 27 #include "media/formats/mp4/avc.h" |
27 #include "media/media_features.h" | 28 #include "media/media_features.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
29 | 30 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 void CreateDemuxer(const std::string& name) { | 85 void CreateDemuxer(const std::string& name) { |
85 CHECK(!demuxer_); | 86 CHECK(!demuxer_); |
86 | 87 |
87 EXPECT_CALL(host_, OnBufferedTimeRangesChanged(_)).Times(AnyNumber()); | 88 EXPECT_CALL(host_, OnBufferedTimeRangesChanged(_)).Times(AnyNumber()); |
88 | 89 |
89 CreateDataSource(name); | 90 CreateDataSource(name); |
90 | 91 |
91 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb = base::Bind( | 92 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb = base::Bind( |
92 &FFmpegDemuxerTest::OnEncryptedMediaInitData, base::Unretained(this)); | 93 &FFmpegDemuxerTest::OnEncryptedMediaInitData, base::Unretained(this)); |
93 | 94 |
| 95 Demuxer::MediaTracksUpdatedCB tracks_updated_cb = base::Bind( |
| 96 &FFmpegDemuxerTest::OnMediaTracksUpdated, base::Unretained(this)); |
| 97 |
94 demuxer_.reset(new FFmpegDemuxer( | 98 demuxer_.reset(new FFmpegDemuxer( |
95 message_loop_.task_runner(), data_source_.get(), | 99 message_loop_.task_runner(), data_source_.get(), |
96 encrypted_media_init_data_cb, new MediaLog())); | 100 encrypted_media_init_data_cb, tracks_updated_cb, new MediaLog())); |
97 } | 101 } |
98 | 102 |
99 MOCK_METHOD1(CheckPoint, void(int v)); | 103 MOCK_METHOD1(CheckPoint, void(int v)); |
100 | 104 |
101 void InitializeDemuxerInternal(bool enable_text, | 105 void InitializeDemuxerInternal(bool enable_text, |
102 media::PipelineStatus expected_pipeline_status, | 106 media::PipelineStatus expected_pipeline_status, |
103 base::Time timeline_offset) { | 107 base::Time timeline_offset) { |
104 if (expected_pipeline_status == PIPELINE_OK) | 108 if (expected_pipeline_status == PIPELINE_OK) |
105 EXPECT_CALL(host_, SetDuration(_)); | 109 EXPECT_CALL(host_, SetDuration(_)); |
106 WaitableMessageLoopEvent event; | 110 WaitableMessageLoopEvent event; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 return base::Bind(&FFmpegDemuxerTest::OnReadDone, | 201 return base::Bind(&FFmpegDemuxerTest::OnReadDone, |
198 base::Unretained(this), | 202 base::Unretained(this), |
199 location, | 203 location, |
200 read_expectation); | 204 read_expectation); |
201 } | 205 } |
202 | 206 |
203 MOCK_METHOD2(OnEncryptedMediaInitData, | 207 MOCK_METHOD2(OnEncryptedMediaInitData, |
204 void(EmeInitDataType init_data_type, | 208 void(EmeInitDataType init_data_type, |
205 const std::vector<uint8_t>& init_data)); | 209 const std::vector<uint8_t>& init_data)); |
206 | 210 |
| 211 void OnMediaTracksUpdated(scoped_ptr<MediaTracks> tracks) { |
| 212 CHECK(tracks.get()); |
| 213 media_tracks_ = std::move(tracks); |
| 214 } |
| 215 |
207 // Accessor to demuxer internals. | 216 // Accessor to demuxer internals. |
208 void set_duration_known(bool duration_known) { | 217 void set_duration_known(bool duration_known) { |
209 demuxer_->duration_known_ = duration_known; | 218 demuxer_->duration_known_ = duration_known; |
210 } | 219 } |
211 | 220 |
212 bool IsStreamStopped(DemuxerStream::Type type) { | 221 bool IsStreamStopped(DemuxerStream::Type type) { |
213 DemuxerStream* stream = demuxer_->GetStream(type); | 222 DemuxerStream* stream = demuxer_->GetStream(type); |
214 CHECK(stream); | 223 CHECK(stream); |
215 return !static_cast<FFmpegDemuxerStream*>(stream)->demuxer_; | 224 return !static_cast<FFmpegDemuxerStream*>(stream)->demuxer_; |
216 } | 225 } |
217 | 226 |
218 // Fixture members. | 227 // Fixture members. |
219 scoped_ptr<FileDataSource> data_source_; | 228 scoped_ptr<FileDataSource> data_source_; |
220 scoped_ptr<FFmpegDemuxer> demuxer_; | 229 scoped_ptr<FFmpegDemuxer> demuxer_; |
221 StrictMock<MockDemuxerHost> host_; | 230 StrictMock<MockDemuxerHost> host_; |
| 231 scoped_ptr<MediaTracks> media_tracks_; |
222 base::MessageLoop message_loop_; | 232 base::MessageLoop message_loop_; |
223 | 233 |
224 AVFormatContext* format_context() { | 234 AVFormatContext* format_context() { |
225 return demuxer_->glue_->format_context(); | 235 return demuxer_->glue_->format_context(); |
226 } | 236 } |
227 | 237 |
228 int preferred_seeking_stream_index() const { | 238 int preferred_seeking_stream_index() const { |
229 return demuxer_->preferred_stream_for_seeking_.first; | 239 return demuxer_->preferred_stream_for_seeking_.first; |
230 } | 240 } |
231 | 241 |
(...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 audio->Read(NewReadCB(FROM_HERE, 870, 0, true)); | 1187 audio->Read(NewReadCB(FROM_HERE, 870, 0, true)); |
1178 message_loop_.Run(); | 1188 message_loop_.Run(); |
1179 | 1189 |
1180 audio->Read(NewReadCB(FROM_HERE, 872, 34830, true)); | 1190 audio->Read(NewReadCB(FROM_HERE, 872, 34830, true)); |
1181 message_loop_.Run(); | 1191 message_loop_.Run(); |
1182 #else | 1192 #else |
1183 InitializeDemuxerAndExpectPipelineStatus(DEMUXER_ERROR_NO_SUPPORTED_STREAMS); | 1193 InitializeDemuxerAndExpectPipelineStatus(DEMUXER_ERROR_NO_SUPPORTED_STREAMS); |
1184 #endif | 1194 #endif |
1185 } | 1195 } |
1186 | 1196 |
| 1197 TEST_F(FFmpegDemuxerTest, Read_Media_Track_Info) { |
| 1198 CreateDemuxer("bear.mp4"); |
| 1199 InitializeDemuxer(); |
| 1200 |
| 1201 EXPECT_EQ(media_tracks_->tracks().size(), 2u); |
| 1202 |
| 1203 const MediaTrack& audio_track = *(media_tracks_->tracks()[0]); |
| 1204 EXPECT_EQ(audio_track.type(), MediaTrack::Audio); |
| 1205 EXPECT_EQ(audio_track.id(), "1"); |
| 1206 EXPECT_EQ(audio_track.kind(), "main"); |
| 1207 EXPECT_EQ(audio_track.label(), "GPAC ISO Audio Handler"); |
| 1208 EXPECT_EQ(audio_track.language(), "und"); |
| 1209 |
| 1210 const MediaTrack& video_track = *(media_tracks_->tracks()[1]); |
| 1211 EXPECT_EQ(video_track.type(), MediaTrack::Video); |
| 1212 EXPECT_EQ(video_track.id(), "2"); |
| 1213 EXPECT_EQ(video_track.kind(), "main"); |
| 1214 EXPECT_EQ(video_track.label(), "GPAC ISO Video Handler"); |
| 1215 EXPECT_EQ(video_track.language(), "und"); |
| 1216 } |
| 1217 |
1187 #endif // defined(USE_PROPRIETARY_CODECS) | 1218 #endif // defined(USE_PROPRIETARY_CODECS) |
1188 | 1219 |
1189 } // namespace media | 1220 } // namespace media |
OLD | NEW |