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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 cb.AddSimpleBlock(track_number, timestamp_in_ms, block_flags, | 387 cb.AddSimpleBlock(track_number, timestamp_in_ms, block_flags, |
388 &data[0], data.size()); | 388 &data[0], data.size()); |
389 } | 389 } |
390 } | 390 } |
391 AppendCluster(source_id, cb.Finish()); | 391 AppendCluster(source_id, cb.Finish()); |
392 } | 392 } |
393 | 393 |
394 void AppendData(const std::string& source_id, | 394 void AppendData(const std::string& source_id, |
395 const uint8* data, size_t length) { | 395 const uint8* data, size_t length) { |
396 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber()); | 396 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber()); |
397 demuxer_->AppendData(source_id, data, length); | 397 |
| 398 // TODO(wolenetz): Test timestamp offset updating once "sequence" append |
| 399 // mode processing is implemented. See http://crbug.com/249422. |
| 400 demuxer_->AppendData(source_id, data, length, NULL); |
398 } | 401 } |
399 | 402 |
400 void AppendDataInPieces(const uint8* data, size_t length) { | 403 void AppendDataInPieces(const uint8* data, size_t length) { |
401 AppendDataInPieces(data, length, 7); | 404 AppendDataInPieces(data, length, 7); |
402 } | 405 } |
403 | 406 |
404 void AppendDataInPieces(const uint8* data, size_t length, size_t piece_size) { | 407 void AppendDataInPieces(const uint8* data, size_t length, size_t piece_size) { |
405 const uint8* start = data; | 408 const uint8* start = data; |
406 const uint8* end = data + length; | 409 const uint8* end = data + length; |
407 while (start < end) { | 410 while (start < end) { |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1209 AppendCluster(GenerateCluster(5000, 6)); | 1212 AppendCluster(GenerateCluster(5000, 6)); |
1210 GenerateExpectedReads(5000, 6); | 1213 GenerateExpectedReads(5000, 6); |
1211 } | 1214 } |
1212 | 1215 |
1213 // Test the case where AppendData() is called before Init(). | 1216 // Test the case where AppendData() is called before Init(). |
1214 TEST_F(ChunkDemuxerTest, AppendDataBeforeInit) { | 1217 TEST_F(ChunkDemuxerTest, AppendDataBeforeInit) { |
1215 scoped_ptr<uint8[]> info_tracks; | 1218 scoped_ptr<uint8[]> info_tracks; |
1216 int info_tracks_size = 0; | 1219 int info_tracks_size = 0; |
1217 CreateInitSegment(HAS_AUDIO | HAS_VIDEO, | 1220 CreateInitSegment(HAS_AUDIO | HAS_VIDEO, |
1218 false, false, &info_tracks, &info_tracks_size); | 1221 false, false, &info_tracks, &info_tracks_size); |
1219 | 1222 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size, NULL); |
1220 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size); | |
1221 } | 1223 } |
1222 | 1224 |
1223 // Make sure Read() callbacks are dispatched with the proper data. | 1225 // Make sure Read() callbacks are dispatched with the proper data. |
1224 TEST_F(ChunkDemuxerTest, Read) { | 1226 TEST_F(ChunkDemuxerTest, Read) { |
1225 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1227 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
1226 | 1228 |
1227 AppendCluster(kDefaultFirstCluster()); | 1229 AppendCluster(kDefaultFirstCluster()); |
1228 | 1230 |
1229 bool audio_read_done = false; | 1231 bool audio_read_done = false; |
1230 bool video_read_done = false; | 1232 bool video_read_done = false; |
(...skipping 12 matching lines...) Expand all Loading... |
1243 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1245 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
1244 AppendCluster(kDefaultFirstCluster()); | 1246 AppendCluster(kDefaultFirstCluster()); |
1245 AppendCluster(GenerateCluster(10, 4)); | 1247 AppendCluster(GenerateCluster(10, 4)); |
1246 | 1248 |
1247 // Make sure that AppendCluster() does not fail with a cluster that has | 1249 // Make sure that AppendCluster() does not fail with a cluster that has |
1248 // overlaps with the previously appended cluster. | 1250 // overlaps with the previously appended cluster. |
1249 AppendCluster(GenerateCluster(5, 4)); | 1251 AppendCluster(GenerateCluster(5, 4)); |
1250 | 1252 |
1251 // Verify that AppendData() can still accept more data. | 1253 // Verify that AppendData() can still accept more data. |
1252 scoped_ptr<Cluster> cluster_c(GenerateCluster(45, 2)); | 1254 scoped_ptr<Cluster> cluster_c(GenerateCluster(45, 2)); |
1253 demuxer_->AppendData(kSourceId, cluster_c->data(), cluster_c->size()); | 1255 demuxer_->AppendData(kSourceId, cluster_c->data(), cluster_c->size(), NULL); |
1254 } | 1256 } |
1255 | 1257 |
1256 TEST_F(ChunkDemuxerTest, NonMonotonicButAboveClusterTimecode) { | 1258 TEST_F(ChunkDemuxerTest, NonMonotonicButAboveClusterTimecode) { |
1257 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1259 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
1258 AppendCluster(kDefaultFirstCluster()); | 1260 AppendCluster(kDefaultFirstCluster()); |
1259 | 1261 |
1260 ClusterBuilder cb; | 1262 ClusterBuilder cb; |
1261 | 1263 |
1262 // Test the case where block timecodes are not monotonically | 1264 // Test the case where block timecodes are not monotonically |
1263 // increasing but stay above the cluster timecode. | 1265 // increasing but stay above the cluster timecode. |
1264 cb.SetClusterTimecode(5); | 1266 cb.SetClusterTimecode(5); |
1265 AddSimpleBlock(&cb, kAudioTrackNum, 5); | 1267 AddSimpleBlock(&cb, kAudioTrackNum, 5); |
1266 AddSimpleBlock(&cb, kVideoTrackNum, 10); | 1268 AddSimpleBlock(&cb, kVideoTrackNum, 10); |
1267 AddSimpleBlock(&cb, kAudioTrackNum, 7); | 1269 AddSimpleBlock(&cb, kAudioTrackNum, 7); |
1268 AddSimpleBlock(&cb, kVideoTrackNum, 15); | 1270 AddSimpleBlock(&cb, kVideoTrackNum, 15); |
1269 | 1271 |
1270 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); | 1272 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); |
1271 AppendCluster(cb.Finish()); | 1273 AppendCluster(cb.Finish()); |
1272 | 1274 |
1273 // Verify that AppendData() ignores data after the error. | 1275 // Verify that AppendData() ignores data after the error. |
1274 scoped_ptr<Cluster> cluster_b(GenerateCluster(20, 2)); | 1276 scoped_ptr<Cluster> cluster_b(GenerateCluster(20, 2)); |
1275 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size()); | 1277 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(), NULL); |
1276 } | 1278 } |
1277 | 1279 |
1278 TEST_F(ChunkDemuxerTest, BackwardsAndBeforeClusterTimecode) { | 1280 TEST_F(ChunkDemuxerTest, BackwardsAndBeforeClusterTimecode) { |
1279 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1281 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
1280 AppendCluster(kDefaultFirstCluster()); | 1282 AppendCluster(kDefaultFirstCluster()); |
1281 | 1283 |
1282 ClusterBuilder cb; | 1284 ClusterBuilder cb; |
1283 | 1285 |
1284 // Test timecodes going backwards and including values less than the cluster | 1286 // Test timecodes going backwards and including values less than the cluster |
1285 // timecode. | 1287 // timecode. |
1286 cb.SetClusterTimecode(5); | 1288 cb.SetClusterTimecode(5); |
1287 AddSimpleBlock(&cb, kAudioTrackNum, 5); | 1289 AddSimpleBlock(&cb, kAudioTrackNum, 5); |
1288 AddSimpleBlock(&cb, kVideoTrackNum, 5); | 1290 AddSimpleBlock(&cb, kVideoTrackNum, 5); |
1289 AddSimpleBlock(&cb, kAudioTrackNum, 3); | 1291 AddSimpleBlock(&cb, kAudioTrackNum, 3); |
1290 AddSimpleBlock(&cb, kVideoTrackNum, 3); | 1292 AddSimpleBlock(&cb, kVideoTrackNum, 3); |
1291 | 1293 |
1292 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); | 1294 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); |
1293 AppendCluster(cb.Finish()); | 1295 AppendCluster(cb.Finish()); |
1294 | 1296 |
1295 // Verify that AppendData() ignores data after the error. | 1297 // Verify that AppendData() ignores data after the error. |
1296 scoped_ptr<Cluster> cluster_b(GenerateCluster(6, 2)); | 1298 scoped_ptr<Cluster> cluster_b(GenerateCluster(6, 2)); |
1297 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size()); | 1299 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(), NULL); |
1298 } | 1300 } |
1299 | 1301 |
1300 | 1302 |
1301 TEST_F(ChunkDemuxerTest, PerStreamMonotonicallyIncreasingTimestamps) { | 1303 TEST_F(ChunkDemuxerTest, PerStreamMonotonicallyIncreasingTimestamps) { |
1302 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1304 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
1303 AppendCluster(kDefaultFirstCluster()); | 1305 AppendCluster(kDefaultFirstCluster()); |
1304 | 1306 |
1305 ClusterBuilder cb; | 1307 ClusterBuilder cb; |
1306 | 1308 |
1307 // Test monotonic increasing timestamps on a per stream | 1309 // Test monotonic increasing timestamps on a per stream |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1744 | 1746 |
1745 TEST_F(ChunkDemuxerTest, ParseErrorDuringInit) { | 1747 TEST_F(ChunkDemuxerTest, ParseErrorDuringInit) { |
1746 EXPECT_CALL(*this, DemuxerOpened()); | 1748 EXPECT_CALL(*this, DemuxerOpened()); |
1747 demuxer_->Initialize( | 1749 demuxer_->Initialize( |
1748 &host_, CreateInitDoneCB( | 1750 &host_, CreateInitDoneCB( |
1749 kNoTimestamp(), DEMUXER_ERROR_COULD_NOT_OPEN), true); | 1751 kNoTimestamp(), DEMUXER_ERROR_COULD_NOT_OPEN), true); |
1750 | 1752 |
1751 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); | 1753 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); |
1752 | 1754 |
1753 uint8 tmp = 0; | 1755 uint8 tmp = 0; |
1754 demuxer_->AppendData(kSourceId, &tmp, 1); | 1756 demuxer_->AppendData(kSourceId, &tmp, 1, NULL); |
1755 } | 1757 } |
1756 | 1758 |
1757 TEST_F(ChunkDemuxerTest, AVHeadersWithAudioOnlyType) { | 1759 TEST_F(ChunkDemuxerTest, AVHeadersWithAudioOnlyType) { |
1758 EXPECT_CALL(*this, DemuxerOpened()); | 1760 EXPECT_CALL(*this, DemuxerOpened()); |
1759 demuxer_->Initialize( | 1761 demuxer_->Initialize( |
1760 &host_, CreateInitDoneCB(kNoTimestamp(), | 1762 &host_, CreateInitDoneCB(kNoTimestamp(), |
1761 DEMUXER_ERROR_COULD_NOT_OPEN), true); | 1763 DEMUXER_ERROR_COULD_NOT_OPEN), true); |
1762 | 1764 |
1763 std::vector<std::string> codecs(1); | 1765 std::vector<std::string> codecs(1); |
1764 codecs[0] = "vorbis"; | 1766 codecs[0] = "vorbis"; |
(...skipping 1377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3142 // NOTE: we start at 175 here because the buffer at 125 was returned | 3144 // NOTE: we start at 175 here because the buffer at 125 was returned |
3143 // to the pending read initiated above. | 3145 // to the pending read initiated above. |
3144 CheckExpectedBuffers(text_stream, "175 225"); | 3146 CheckExpectedBuffers(text_stream, "175 225"); |
3145 | 3147 |
3146 // Verify that audio & video streams contiue to return expected values. | 3148 // Verify that audio & video streams contiue to return expected values. |
3147 CheckExpectedBuffers(audio_stream, "160 180"); | 3149 CheckExpectedBuffers(audio_stream, "160 180"); |
3148 CheckExpectedBuffers(video_stream, "180 210"); | 3150 CheckExpectedBuffers(video_stream, "180 210"); |
3149 } | 3151 } |
3150 | 3152 |
3151 } // namespace media | 3153 } // namespace media |
OLD | NEW |