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 |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 &video_read_done)); | 562 &video_read_done)); |
564 | 563 |
565 EXPECT_TRUE(video_read_done); | 564 EXPECT_TRUE(video_read_done); |
566 } | 565 } |
567 } | 566 } |
568 | 567 |
569 return true; | 568 return true; |
570 } | 569 } |
571 | 570 |
572 MockDemuxerHost host_; | 571 MockDemuxerHost host_; |
573 int64 buffered_bytes_; | 572 base::TimeDelta buffered_time_; |
574 | 573 |
575 scoped_ptr<MockChunkDemuxerClient> client_; | 574 scoped_ptr<MockChunkDemuxerClient> client_; |
576 scoped_refptr<ChunkDemuxer> demuxer_; | 575 scoped_refptr<ChunkDemuxer> demuxer_; |
577 | 576 |
578 private: | 577 private: |
579 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest); | 578 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest); |
580 }; | 579 }; |
581 | 580 |
582 TEST_F(ChunkDemuxerTest, TestInit) { | 581 TEST_F(ChunkDemuxerTest, TestInit) { |
583 // Test no streams, audio-only, video-only, and audio & video scenarios, | 582 // Test no streams, audio-only, video-only, and audio & video scenarios, |
(...skipping 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1685 EXPECT_CALL(*client_, DemuxerOpened(_)); | 1684 EXPECT_CALL(*client_, DemuxerOpened(_)); |
1686 demuxer_->Initialize(&host_, CreateInitDoneCB(PIPELINE_OK)); | 1685 demuxer_->Initialize(&host_, CreateInitDoneCB(PIPELINE_OK)); |
1687 ASSERT_EQ(AddId("audio", true, false), ChunkDemuxer::kOk); | 1686 ASSERT_EQ(AddId("audio", true, false), ChunkDemuxer::kOk); |
1688 ASSERT_EQ(AddId("video", false, true), ChunkDemuxer::kOk); | 1687 ASSERT_EQ(AddId("video", false, true), ChunkDemuxer::kOk); |
1689 | 1688 |
1690 CheckExpectedRanges("audio", "{ }"); | 1689 CheckExpectedRanges("audio", "{ }"); |
1691 CheckExpectedRanges("video", "{ }"); | 1690 CheckExpectedRanges("video", "{ }"); |
1692 } | 1691 } |
1693 | 1692 |
1694 } // namespace media | 1693 } // namespace media |
OLD | NEW |