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