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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "media/base/audio_decoder_config.h" | 6 #include "media/base/audio_decoder_config.h" |
7 #include "media/base/decoder_buffer.h" | 7 #include "media/base/decoder_buffer.h" |
8 #include "media/base/mock_callback.h" | 8 #include "media/base/mock_callback.h" |
9 #include "media/base/mock_demuxer_host.h" | 9 #include "media/base/mock_demuxer_host.h" |
10 #include "media/base/test_data_util.h" | 10 #include "media/base/test_data_util.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 // Default cluster to append after kDefaultFirstCluster() | 119 // Default cluster to append after kDefaultFirstCluster() |
120 // has been appended. This cluster starts with blocks that | 120 // has been appended. This cluster starts with blocks that |
121 // have timestamps consistent with the end times of the blocks | 121 // have timestamps consistent with the end times of the blocks |
122 // in kDefaultFirstCluster() so that these two clusters represent | 122 // in kDefaultFirstCluster() so that these two clusters represent |
123 // a continuous region. | 123 // a continuous region. |
124 scoped_ptr<Cluster> kDefaultSecondCluster() { | 124 scoped_ptr<Cluster> kDefaultSecondCluster() { |
125 return GenerateCluster(46, 66, 5); | 125 return GenerateCluster(46, 66, 5); |
126 } | 126 } |
127 | 127 |
128 ChunkDemuxerTest() | 128 ChunkDemuxerTest() |
129 : buffered_bytes_(0), | 129 : client_(new MockChunkDemuxerClient()), |
130 client_(new MockChunkDemuxerClient()), | |
131 demuxer_(new ChunkDemuxer(client_.get())) { | 130 demuxer_(new ChunkDemuxer(client_.get())) { |
132 } | 131 } |
133 | 132 |
134 virtual ~ChunkDemuxerTest() { | 133 virtual ~ChunkDemuxerTest() { |
135 ShutdownDemuxer(); | 134 ShutdownDemuxer(); |
136 } | 135 } |
137 | 136 |
138 void CreateInitSegment(bool has_audio, bool has_video, | 137 void CreateInitSegment(bool has_audio, bool has_video, |
139 bool video_content_encoded, | 138 bool video_content_encoded, |
140 scoped_array<uint8>* buffer, | 139 scoped_array<uint8>* buffer, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 return demuxer_->AddId(source_id, type, codecs); | 229 return demuxer_->AddId(source_id, type, codecs); |
231 } | 230 } |
232 | 231 |
233 bool AppendData(const uint8* data, size_t length) { | 232 bool AppendData(const uint8* data, size_t length) { |
234 return AppendData(kSourceId, data, length); | 233 return AppendData(kSourceId, data, length); |
235 } | 234 } |
236 | 235 |
237 bool AppendData(const std::string& source_id, | 236 bool AppendData(const std::string& source_id, |
238 const uint8* data, size_t length) { | 237 const uint8* data, size_t length) { |
239 CHECK(length); | 238 CHECK(length); |
240 EXPECT_CALL(host_, AddBufferedByteRange(_, _)).Times(AnyNumber()) | 239 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber()) |
241 .WillRepeatedly(SaveArg<1>(&buffered_bytes_)); | 240 .WillRepeatedly(SaveArg<1>(&buffered_time_)); |
242 return demuxer_->AppendData(source_id, data, length); | 241 return demuxer_->AppendData(source_id, data, length); |
243 } | 242 } |
244 | 243 |
245 bool AppendDataInPieces(const uint8* data, size_t length) { | 244 bool AppendDataInPieces(const uint8* data, size_t length) { |
246 return AppendDataInPieces(data, length, 7); | 245 return AppendDataInPieces(data, length, 7); |
247 } | 246 } |
248 | 247 |
249 bool AppendDataInPieces(const uint8* data, size_t length, size_t piece_size) { | 248 bool AppendDataInPieces(const uint8* data, size_t length, size_t piece_size) { |
250 const uint8* start = data; | 249 const uint8* start = data; |
251 const uint8* end = data + length; | 250 const uint8* end = data + length; |
252 while (start < end) { | 251 while (start < end) { |
253 int64 old_buffered_bytes = buffered_bytes_; | 252 base::TimeDelta old_buffered_time = buffered_time_; |
254 size_t append_size = std::min(piece_size, | 253 size_t append_size = std::min(piece_size, |
255 static_cast<size_t>(end - start)); | 254 static_cast<size_t>(end - start)); |
256 if (!AppendData(start, append_size)) | 255 if (!AppendData(start, append_size)) |
257 return false; | 256 return false; |
258 start += append_size; | 257 start += append_size; |
259 | 258 |
260 EXPECT_GE(buffered_bytes_, old_buffered_bytes); | 259 EXPECT_GE(buffered_time_, old_buffered_time); |
261 } | 260 } |
262 return true; | 261 return true; |
263 } | 262 } |
264 | 263 |
265 bool AppendInitSegment(bool has_audio, bool has_video, | 264 bool AppendInitSegment(bool has_audio, bool has_video, |
266 bool video_content_encoded) { | 265 bool video_content_encoded) { |
267 return AppendInitSegment(kSourceId, has_audio, has_video, | 266 return AppendInitSegment(kSourceId, has_audio, has_video, |
268 video_content_encoded); | 267 video_content_encoded); |
269 } | 268 } |
270 | 269 |
271 bool AppendInitSegment(const std::string& source_id, | 270 bool AppendInitSegment(const std::string& source_id, |
272 bool has_audio, bool has_video, | 271 bool has_audio, bool has_video, |
273 bool video_content_encoded) { | 272 bool video_content_encoded) { |
274 scoped_array<uint8> info_tracks; | 273 scoped_array<uint8> info_tracks; |
275 int info_tracks_size = 0; | 274 int info_tracks_size = 0; |
276 CreateInitSegment(has_audio, has_video, video_content_encoded, | 275 CreateInitSegment(has_audio, has_video, video_content_encoded, |
277 &info_tracks, &info_tracks_size); | 276 &info_tracks, &info_tracks_size); |
278 return AppendData(source_id, info_tracks.get(), info_tracks_size); | 277 return AppendData(source_id, info_tracks.get(), info_tracks_size); |
279 } | 278 } |
280 | 279 |
281 void InitDoneCalled(PipelineStatus expected_status, | 280 void InitDoneCalled(PipelineStatus expected_status, |
282 PipelineStatus status) { | 281 PipelineStatus status) { |
283 EXPECT_EQ(status, expected_status); | 282 EXPECT_EQ(status, expected_status); |
284 } | 283 } |
285 | 284 |
286 PipelineStatusCB CreateInitDoneCB(const base::TimeDelta& expected_duration, | 285 PipelineStatusCB CreateInitDoneCB(const base::TimeDelta& expected_duration, |
287 PipelineStatus expected_status) { | 286 PipelineStatus expected_status) { |
288 if (expected_status == PIPELINE_OK) { | 287 if (expected_status == PIPELINE_OK) |
289 if (expected_duration != kInfiniteDuration()) | |
290 EXPECT_CALL(host_, SetTotalBytes(_)); | |
291 EXPECT_CALL(host_, SetDuration(expected_duration)); | 288 EXPECT_CALL(host_, SetDuration(expected_duration)); |
292 } | |
293 return CreateInitDoneCB(expected_status); | 289 return CreateInitDoneCB(expected_status); |
294 } | 290 } |
295 | 291 |
296 PipelineStatusCB CreateInitDoneCB(PipelineStatus expected_status) { | 292 PipelineStatusCB CreateInitDoneCB(PipelineStatus expected_status) { |
297 return base::Bind(&ChunkDemuxerTest::InitDoneCalled, | 293 return base::Bind(&ChunkDemuxerTest::InitDoneCalled, |
298 base::Unretained(this), | 294 base::Unretained(this), |
299 expected_status); | 295 expected_status); |
300 } | 296 } |
301 | 297 |
302 bool InitDemuxer(bool has_audio, bool has_video, | 298 bool InitDemuxer(bool has_audio, bool has_video, |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 &video_read_done)); | 559 &video_read_done)); |
564 | 560 |
565 EXPECT_TRUE(video_read_done); | 561 EXPECT_TRUE(video_read_done); |
566 } | 562 } |
567 } | 563 } |
568 | 564 |
569 return true; | 565 return true; |
570 } | 566 } |
571 | 567 |
572 MockDemuxerHost host_; | 568 MockDemuxerHost host_; |
573 int64 buffered_bytes_; | 569 base::TimeDelta buffered_time_; |
574 | 570 |
575 scoped_ptr<MockChunkDemuxerClient> client_; | 571 scoped_ptr<MockChunkDemuxerClient> client_; |
576 scoped_refptr<ChunkDemuxer> demuxer_; | 572 scoped_refptr<ChunkDemuxer> demuxer_; |
577 | 573 |
578 private: | 574 private: |
579 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest); | 575 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest); |
580 }; | 576 }; |
581 | 577 |
582 TEST_F(ChunkDemuxerTest, TestInit) { | 578 TEST_F(ChunkDemuxerTest, TestInit) { |
583 // Test no streams, audio-only, video-only, and audio & video scenarios, | 579 // Test no streams, audio-only, video-only, and audio & video scenarios, |
(...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1690 EXPECT_CALL(*client_, DemuxerOpened(_)); | 1686 EXPECT_CALL(*client_, DemuxerOpened(_)); |
1691 demuxer_->Initialize(&host_, CreateInitDoneCB(PIPELINE_OK)); | 1687 demuxer_->Initialize(&host_, CreateInitDoneCB(PIPELINE_OK)); |
1692 ASSERT_EQ(AddId("audio", true, false), ChunkDemuxer::kOk); | 1688 ASSERT_EQ(AddId("audio", true, false), ChunkDemuxer::kOk); |
1693 ASSERT_EQ(AddId("video", false, true), ChunkDemuxer::kOk); | 1689 ASSERT_EQ(AddId("video", false, true), ChunkDemuxer::kOk); |
1694 | 1690 |
1695 CheckExpectedRanges("audio", "{ }"); | 1691 CheckExpectedRanges("audio", "{ }"); |
1696 CheckExpectedRanges("video", "{ }"); | 1692 CheckExpectedRanges("video", "{ }"); |
1697 } | 1693 } |
1698 | 1694 |
1699 } // namespace media | 1695 } // namespace media |
OLD | NEW |