Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(412)

Side by Side Diff: media/filters/chunk_demuxer_unittest.cc

Issue 191513002: Extract coded frame processing from SourceState into LegacyFrameProcessor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and address PS2 comments and nits Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 147
148 // Default cluster to append after kDefaultFirstCluster() 148 // Default cluster to append after kDefaultFirstCluster()
149 // has been appended. This cluster starts with blocks that 149 // has been appended. This cluster starts with blocks that
150 // have timestamps consistent with the end times of the blocks 150 // have timestamps consistent with the end times of the blocks
151 // in kDefaultFirstCluster() so that these two clusters represent 151 // in kDefaultFirstCluster() so that these two clusters represent
152 // a continuous region. 152 // a continuous region.
153 scoped_ptr<Cluster> kDefaultSecondCluster() { 153 scoped_ptr<Cluster> kDefaultSecondCluster() {
154 return GenerateCluster(46, 66, 5); 154 return GenerateCluster(46, 66, 5);
155 } 155 }
156 156
157 ChunkDemuxerTest() { 157 ChunkDemuxerTest()
158 : append_window_end_for_next_append_(kInfiniteDuration()) {
158 CreateNewDemuxer(); 159 CreateNewDemuxer();
159 } 160 }
160 161
161 void CreateNewDemuxer() { 162 void CreateNewDemuxer() {
162 base::Closure open_cb = 163 base::Closure open_cb =
163 base::Bind(&ChunkDemuxerTest::DemuxerOpened, base::Unretained(this)); 164 base::Bind(&ChunkDemuxerTest::DemuxerOpened, base::Unretained(this));
164 Demuxer::NeedKeyCB need_key_cb = 165 Demuxer::NeedKeyCB need_key_cb =
165 base::Bind(&ChunkDemuxerTest::DemuxerNeedKey, base::Unretained(this)); 166 base::Bind(&ChunkDemuxerTest::DemuxerNeedKey, base::Unretained(this));
166 demuxer_.reset(new ChunkDemuxer(open_cb, need_key_cb, 167 demuxer_.reset(new ChunkDemuxer(open_cb, need_key_cb,
167 base::Bind(&LogFunc))); 168 base::Bind(&LogFunc)));
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 } 391 }
391 AppendCluster(source_id, cb.Finish()); 392 AppendCluster(source_id, cb.Finish());
392 } 393 }
393 394
394 void AppendData(const std::string& source_id, 395 void AppendData(const std::string& source_id,
395 const uint8* data, size_t length) { 396 const uint8* data, size_t length) {
396 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber()); 397 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber());
397 398
398 // TODO(wolenetz): Test timestamp offset updating once "sequence" append 399 // TODO(wolenetz): Test timestamp offset updating once "sequence" append
399 // mode processing is implemented. See http://crbug.com/249422. 400 // mode processing is implemented. See http://crbug.com/249422.
400 demuxer_->AppendData(source_id, data, length, NULL); 401 demuxer_->AppendData(source_id, data, length,
402 append_window_start_for_next_append_,
403 append_window_end_for_next_append_,
404 &timestamp_offset_for_next_append_);
401 } 405 }
402 406
403 void AppendDataInPieces(const uint8* data, size_t length) { 407 void AppendDataInPieces(const uint8* data, size_t length) {
404 AppendDataInPieces(data, length, 7); 408 AppendDataInPieces(data, length, 7);
405 } 409 }
406 410
407 void AppendDataInPieces(const uint8* data, size_t length, size_t piece_size) { 411 void AppendDataInPieces(const uint8* data, size_t length, size_t piece_size) {
408 const uint8* start = data; 412 const uint8* start = data;
409 const uint8* end = data + length; 413 const uint8* end = data + length;
410 while (start < end) { 414 while (start < end) {
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 void MarkEndOfStream(PipelineStatus status) { 944 void MarkEndOfStream(PipelineStatus status) {
941 demuxer_->MarkEndOfStream(status); 945 demuxer_->MarkEndOfStream(status);
942 message_loop_.RunUntilIdle(); 946 message_loop_.RunUntilIdle();
943 } 947 }
944 948
945 base::MessageLoop message_loop_; 949 base::MessageLoop message_loop_;
946 MockDemuxerHost host_; 950 MockDemuxerHost host_;
947 951
948 scoped_ptr<ChunkDemuxer> demuxer_; 952 scoped_ptr<ChunkDemuxer> demuxer_;
949 953
954 base::TimeDelta append_window_start_for_next_append_;
955 base::TimeDelta append_window_end_for_next_append_;
956 base::TimeDelta timestamp_offset_for_next_append_;
957
950 private: 958 private:
951 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest); 959 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest);
952 }; 960 };
953 961
954 TEST_F(ChunkDemuxerTest, Init) { 962 TEST_F(ChunkDemuxerTest, Init) {
955 // Test no streams, audio-only, video-only, and audio & video scenarios. 963 // Test no streams, audio-only, video-only, and audio & video scenarios.
956 // Audio and video streams can be encrypted or not encrypted. 964 // Audio and video streams can be encrypted or not encrypted.
957 for (int i = 0; i < 16; i++) { 965 for (int i = 0; i < 16; i++) {
958 bool has_audio = (i & 0x1) != 0; 966 bool has_audio = (i & 0x1) != 0;
959 bool has_video = (i & 0x2) != 0; 967 bool has_video = (i & 0x2) != 0;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 AppendCluster(GenerateCluster(5000, 6)); 1220 AppendCluster(GenerateCluster(5000, 6));
1213 GenerateExpectedReads(5000, 6); 1221 GenerateExpectedReads(5000, 6);
1214 } 1222 }
1215 1223
1216 // Test the case where AppendData() is called before Init(). 1224 // Test the case where AppendData() is called before Init().
1217 TEST_F(ChunkDemuxerTest, AppendDataBeforeInit) { 1225 TEST_F(ChunkDemuxerTest, AppendDataBeforeInit) {
1218 scoped_ptr<uint8[]> info_tracks; 1226 scoped_ptr<uint8[]> info_tracks;
1219 int info_tracks_size = 0; 1227 int info_tracks_size = 0;
1220 CreateInitSegment(HAS_AUDIO | HAS_VIDEO, 1228 CreateInitSegment(HAS_AUDIO | HAS_VIDEO,
1221 false, false, &info_tracks, &info_tracks_size); 1229 false, false, &info_tracks, &info_tracks_size);
1222 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size, NULL); 1230 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size,
1231 append_window_start_for_next_append_,
1232 append_window_end_for_next_append_,
1233 &timestamp_offset_for_next_append_);
1223 } 1234 }
1224 1235
1225 // Make sure Read() callbacks are dispatched with the proper data. 1236 // Make sure Read() callbacks are dispatched with the proper data.
1226 TEST_F(ChunkDemuxerTest, Read) { 1237 TEST_F(ChunkDemuxerTest, Read) {
1227 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1238 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1228 1239
1229 AppendCluster(kDefaultFirstCluster()); 1240 AppendCluster(kDefaultFirstCluster());
1230 1241
1231 bool audio_read_done = false; 1242 bool audio_read_done = false;
1232 bool video_read_done = false; 1243 bool video_read_done = false;
(...skipping 12 matching lines...) Expand all
1245 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1256 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1246 AppendCluster(kDefaultFirstCluster()); 1257 AppendCluster(kDefaultFirstCluster());
1247 AppendCluster(GenerateCluster(10, 4)); 1258 AppendCluster(GenerateCluster(10, 4));
1248 1259
1249 // Make sure that AppendCluster() does not fail with a cluster that has 1260 // Make sure that AppendCluster() does not fail with a cluster that has
1250 // overlaps with the previously appended cluster. 1261 // overlaps with the previously appended cluster.
1251 AppendCluster(GenerateCluster(5, 4)); 1262 AppendCluster(GenerateCluster(5, 4));
1252 1263
1253 // Verify that AppendData() can still accept more data. 1264 // Verify that AppendData() can still accept more data.
1254 scoped_ptr<Cluster> cluster_c(GenerateCluster(45, 2)); 1265 scoped_ptr<Cluster> cluster_c(GenerateCluster(45, 2));
1255 demuxer_->AppendData(kSourceId, cluster_c->data(), cluster_c->size(), NULL); 1266 demuxer_->AppendData(kSourceId, cluster_c->data(), cluster_c->size(),
1267 append_window_start_for_next_append_,
1268 append_window_end_for_next_append_,
1269 &timestamp_offset_for_next_append_);
1256 } 1270 }
1257 1271
1258 TEST_F(ChunkDemuxerTest, NonMonotonicButAboveClusterTimecode) { 1272 TEST_F(ChunkDemuxerTest, NonMonotonicButAboveClusterTimecode) {
1259 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1273 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1260 AppendCluster(kDefaultFirstCluster()); 1274 AppendCluster(kDefaultFirstCluster());
1261 1275
1262 ClusterBuilder cb; 1276 ClusterBuilder cb;
1263 1277
1264 // Test the case where block timecodes are not monotonically 1278 // Test the case where block timecodes are not monotonically
1265 // increasing but stay above the cluster timecode. 1279 // increasing but stay above the cluster timecode.
1266 cb.SetClusterTimecode(5); 1280 cb.SetClusterTimecode(5);
1267 AddSimpleBlock(&cb, kAudioTrackNum, 5); 1281 AddSimpleBlock(&cb, kAudioTrackNum, 5);
1268 AddSimpleBlock(&cb, kVideoTrackNum, 10); 1282 AddSimpleBlock(&cb, kVideoTrackNum, 10);
1269 AddSimpleBlock(&cb, kAudioTrackNum, 7); 1283 AddSimpleBlock(&cb, kAudioTrackNum, 7);
1270 AddSimpleBlock(&cb, kVideoTrackNum, 15); 1284 AddSimpleBlock(&cb, kVideoTrackNum, 15);
1271 1285
1272 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); 1286 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE));
1273 AppendCluster(cb.Finish()); 1287 AppendCluster(cb.Finish());
1274 1288
1275 // Verify that AppendData() ignores data after the error. 1289 // Verify that AppendData() ignores data after the error.
1276 scoped_ptr<Cluster> cluster_b(GenerateCluster(20, 2)); 1290 scoped_ptr<Cluster> cluster_b(GenerateCluster(20, 2));
1277 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(), NULL); 1291 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(),
1292 append_window_start_for_next_append_,
1293 append_window_end_for_next_append_,
1294 &timestamp_offset_for_next_append_);
1278 } 1295 }
1279 1296
1280 TEST_F(ChunkDemuxerTest, BackwardsAndBeforeClusterTimecode) { 1297 TEST_F(ChunkDemuxerTest, BackwardsAndBeforeClusterTimecode) {
1281 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1298 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1282 AppendCluster(kDefaultFirstCluster()); 1299 AppendCluster(kDefaultFirstCluster());
1283 1300
1284 ClusterBuilder cb; 1301 ClusterBuilder cb;
1285 1302
1286 // Test timecodes going backwards and including values less than the cluster 1303 // Test timecodes going backwards and including values less than the cluster
1287 // timecode. 1304 // timecode.
1288 cb.SetClusterTimecode(5); 1305 cb.SetClusterTimecode(5);
1289 AddSimpleBlock(&cb, kAudioTrackNum, 5); 1306 AddSimpleBlock(&cb, kAudioTrackNum, 5);
1290 AddSimpleBlock(&cb, kVideoTrackNum, 5); 1307 AddSimpleBlock(&cb, kVideoTrackNum, 5);
1291 AddSimpleBlock(&cb, kAudioTrackNum, 3); 1308 AddSimpleBlock(&cb, kAudioTrackNum, 3);
1292 AddSimpleBlock(&cb, kVideoTrackNum, 3); 1309 AddSimpleBlock(&cb, kVideoTrackNum, 3);
1293 1310
1294 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); 1311 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE));
1295 AppendCluster(cb.Finish()); 1312 AppendCluster(cb.Finish());
1296 1313
1297 // Verify that AppendData() ignores data after the error. 1314 // Verify that AppendData() ignores data after the error.
1298 scoped_ptr<Cluster> cluster_b(GenerateCluster(6, 2)); 1315 scoped_ptr<Cluster> cluster_b(GenerateCluster(6, 2));
1299 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(), NULL); 1316 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(),
1317 append_window_start_for_next_append_,
1318 append_window_end_for_next_append_,
1319 &timestamp_offset_for_next_append_);
1300 } 1320 }
1301 1321
1302 1322
1303 TEST_F(ChunkDemuxerTest, PerStreamMonotonicallyIncreasingTimestamps) { 1323 TEST_F(ChunkDemuxerTest, PerStreamMonotonicallyIncreasingTimestamps) {
1304 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1324 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1305 AppendCluster(kDefaultFirstCluster()); 1325 AppendCluster(kDefaultFirstCluster());
1306 1326
1307 ClusterBuilder cb; 1327 ClusterBuilder cb;
1308 1328
1309 // Test monotonic increasing timestamps on a per stream 1329 // Test monotonic increasing timestamps on a per stream
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 1766
1747 TEST_F(ChunkDemuxerTest, ParseErrorDuringInit) { 1767 TEST_F(ChunkDemuxerTest, ParseErrorDuringInit) {
1748 EXPECT_CALL(*this, DemuxerOpened()); 1768 EXPECT_CALL(*this, DemuxerOpened());
1749 demuxer_->Initialize( 1769 demuxer_->Initialize(
1750 &host_, CreateInitDoneCB( 1770 &host_, CreateInitDoneCB(
1751 kNoTimestamp(), DEMUXER_ERROR_COULD_NOT_OPEN), true); 1771 kNoTimestamp(), DEMUXER_ERROR_COULD_NOT_OPEN), true);
1752 1772
1753 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); 1773 ASSERT_EQ(AddId(), ChunkDemuxer::kOk);
1754 1774
1755 uint8 tmp = 0; 1775 uint8 tmp = 0;
1756 demuxer_->AppendData(kSourceId, &tmp, 1, NULL); 1776 demuxer_->AppendData(kSourceId, &tmp, 1,
1777 append_window_start_for_next_append_,
1778 append_window_end_for_next_append_,
1779 &timestamp_offset_for_next_append_);
1757 } 1780 }
1758 1781
1759 TEST_F(ChunkDemuxerTest, AVHeadersWithAudioOnlyType) { 1782 TEST_F(ChunkDemuxerTest, AVHeadersWithAudioOnlyType) {
1760 EXPECT_CALL(*this, DemuxerOpened()); 1783 EXPECT_CALL(*this, DemuxerOpened());
1761 demuxer_->Initialize( 1784 demuxer_->Initialize(
1762 &host_, CreateInitDoneCB(kNoTimestamp(), 1785 &host_, CreateInitDoneCB(kNoTimestamp(),
1763 DEMUXER_ERROR_COULD_NOT_OPEN), true); 1786 DEMUXER_ERROR_COULD_NOT_OPEN), true);
1764 1787
1765 std::vector<std::string> codecs(1); 1788 std::vector<std::string> codecs(1);
1766 codecs[0] = "vorbis"; 1789 codecs[0] = "vorbis";
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
2577 Seek(base::TimeDelta::FromMilliseconds(801)); 2600 Seek(base::TimeDelta::FromMilliseconds(801));
2578 2601
2579 // Verify that no config change is signalled. 2602 // Verify that no config change is signalled.
2580 ExpectRead(DemuxerStream::VIDEO, 801); 2603 ExpectRead(DemuxerStream::VIDEO, 801);
2581 ASSERT_TRUE(video_config_1.Matches(video->video_decoder_config())); 2604 ASSERT_TRUE(video_config_1.Matches(video->video_decoder_config()));
2582 } 2605 }
2583 2606
2584 TEST_F(ChunkDemuxerTest, TimestampPositiveOffset) { 2607 TEST_F(ChunkDemuxerTest, TimestampPositiveOffset) {
2585 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2608 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2586 2609
2587 ASSERT_TRUE(demuxer_->SetTimestampOffset( 2610 ASSERT_FALSE(demuxer_->IsParsingMediaSegment(kSourceId));
acolwell GONE FROM CHROMIUM 2014/03/11 20:00:37 nit: Create a SetTimestampOffset() method in the t
wolenetz 2014/03/12 00:46:14 Done in prereq CL I split off from this one.
2588 kSourceId, base::TimeDelta::FromSeconds(30))); 2611 timestamp_offset_for_next_append_ = base::TimeDelta::FromSeconds(30);
2589 AppendCluster(GenerateCluster(0, 2)); 2612 AppendCluster(GenerateCluster(0, 2));
2590 2613
2591 Seek(base::TimeDelta::FromMilliseconds(30000)); 2614 Seek(base::TimeDelta::FromMilliseconds(30000));
2592 2615
2593 GenerateExpectedReads(30000, 2); 2616 GenerateExpectedReads(30000, 2);
2594 } 2617 }
2595 2618
2596 TEST_F(ChunkDemuxerTest, TimestampNegativeOffset) { 2619 TEST_F(ChunkDemuxerTest, TimestampNegativeOffset) {
2597 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2620 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2598 2621
2599 ASSERT_TRUE(demuxer_->SetTimestampOffset( 2622 ASSERT_FALSE(demuxer_->IsParsingMediaSegment(kSourceId));
2600 kSourceId, base::TimeDelta::FromSeconds(-1))); 2623 timestamp_offset_for_next_append_ = base::TimeDelta::FromSeconds(-1);
2601 AppendCluster(GenerateCluster(1000, 2)); 2624 AppendCluster(GenerateCluster(1000, 2));
2602 2625
2603 GenerateExpectedReads(0, 2); 2626 GenerateExpectedReads(0, 2);
2604 } 2627 }
2605 2628
2606 TEST_F(ChunkDemuxerTest, TimestampOffsetSeparateStreams) { 2629 TEST_F(ChunkDemuxerTest, TimestampOffsetSeparateStreams) {
2607 std::string audio_id = "audio1"; 2630 std::string audio_id = "audio1";
2608 std::string video_id = "video1"; 2631 std::string video_id = "video1";
2609 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id)); 2632 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id));
2610 2633
2611 ASSERT_TRUE(demuxer_->SetTimestampOffset( 2634 ASSERT_FALSE(demuxer_->IsParsingMediaSegment(audio_id));
2612 audio_id, base::TimeDelta::FromMilliseconds(-2500))); 2635 ASSERT_FALSE(demuxer_->IsParsingMediaSegment(video_id));
2613 ASSERT_TRUE(demuxer_->SetTimestampOffset( 2636
2614 video_id, base::TimeDelta::FromMilliseconds(-2500))); 2637 timestamp_offset_for_next_append_ = base::TimeDelta::FromMilliseconds(-2500);
2615 AppendCluster(audio_id, GenerateSingleStreamCluster(2500, 2638 AppendCluster(audio_id, GenerateSingleStreamCluster(2500,
2616 2500 + kAudioBlockDuration * 4, kAudioTrackNum, kAudioBlockDuration)); 2639 2500 + kAudioBlockDuration * 4, kAudioTrackNum, kAudioBlockDuration));
2640
2641 timestamp_offset_for_next_append_ = base::TimeDelta::FromMilliseconds(-2500);
2617 AppendCluster(video_id, GenerateSingleStreamCluster(2500, 2642 AppendCluster(video_id, GenerateSingleStreamCluster(2500,
2618 2500 + kVideoBlockDuration * 4, kVideoTrackNum, kVideoBlockDuration)); 2643 2500 + kVideoBlockDuration * 4, kVideoTrackNum, kVideoBlockDuration));
2619 GenerateAudioStreamExpectedReads(0, 4); 2644 GenerateAudioStreamExpectedReads(0, 4);
2620 GenerateVideoStreamExpectedReads(0, 4); 2645 GenerateVideoStreamExpectedReads(0, 4);
2621 2646
2622 Seek(base::TimeDelta::FromMilliseconds(27300)); 2647 Seek(base::TimeDelta::FromMilliseconds(27300));
2623 2648
2624 ASSERT_TRUE(demuxer_->SetTimestampOffset( 2649 ASSERT_FALSE(demuxer_->IsParsingMediaSegment(audio_id));
2625 audio_id, base::TimeDelta::FromMilliseconds(27300))); 2650 ASSERT_FALSE(demuxer_->IsParsingMediaSegment(video_id));
2626 ASSERT_TRUE(demuxer_->SetTimestampOffset( 2651
2627 video_id, base::TimeDelta::FromMilliseconds(27300))); 2652 timestamp_offset_for_next_append_ = base::TimeDelta::FromMilliseconds(27300);
2628 AppendCluster(audio_id, GenerateSingleStreamCluster( 2653 AppendCluster(audio_id, GenerateSingleStreamCluster(
2629 0, kAudioBlockDuration * 4, kAudioTrackNum, kAudioBlockDuration)); 2654 0, kAudioBlockDuration * 4, kAudioTrackNum, kAudioBlockDuration));
2655
2656 timestamp_offset_for_next_append_ = base::TimeDelta::FromMilliseconds(27300);
2630 AppendCluster(video_id, GenerateSingleStreamCluster( 2657 AppendCluster(video_id, GenerateSingleStreamCluster(
2631 0, kVideoBlockDuration * 4, kVideoTrackNum, kVideoBlockDuration)); 2658 0, kVideoBlockDuration * 4, kVideoTrackNum, kVideoBlockDuration));
2632 GenerateVideoStreamExpectedReads(27300, 4); 2659 GenerateVideoStreamExpectedReads(27300, 4);
2633 GenerateAudioStreamExpectedReads(27300, 4); 2660 GenerateAudioStreamExpectedReads(27300, 4);
2634 } 2661 }
2635 2662
2636 TEST_F(ChunkDemuxerTest, TimestampOffsetMidMediaSegment) { 2663 TEST_F(ChunkDemuxerTest, IsParsingMediaSegmentMidMediaSegment) {
2637 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2664 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2638 2665
2639 scoped_ptr<Cluster> cluster = GenerateCluster(0, 2); 2666 scoped_ptr<Cluster> cluster = GenerateCluster(0, 2);
2640 // Append only part of the cluster data. 2667 // Append only part of the cluster data.
2641 AppendData(cluster->data(), cluster->size() - 13); 2668 AppendData(cluster->data(), cluster->size() - 13);
2642 2669
2643 // Setting a timestamp should fail because we're in the middle of a cluster. 2670 // Confirm we're in the middle of parsing a media segment.
2644 ASSERT_FALSE(demuxer_->SetTimestampOffset( 2671 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId));
2645 kSourceId, base::TimeDelta::FromSeconds(25)));
2646 2672
2647 demuxer_->Abort(kSourceId); 2673 demuxer_->Abort(kSourceId);
2648 // After Abort(), setting a timestamp should succeed since we're no longer 2674 // After Abort(), parsing should no longer be in the middle of a media
2649 // in the middle of a cluster 2675 // segment.
2650 ASSERT_TRUE(demuxer_->SetTimestampOffset( 2676 ASSERT_FALSE(demuxer_->IsParsingMediaSegment(kSourceId));
2651 kSourceId, base::TimeDelta::FromSeconds(25)));
2652 } 2677 }
2653 2678
2654 TEST_F(ChunkDemuxerTest, WebMParsingMediaSegmentDetection) { 2679 TEST_F(ChunkDemuxerTest, WebMIsParsingMediaSegmentDetection) {
2655 // TODO(wolenetz): Also test 'unknown' sized clusters. 2680 // TODO(wolenetz): Also test 'unknown' sized clusters.
2656 // See http://crbug.com/335676. 2681 // See http://crbug.com/335676.
2657 const uint8 kBuffer[] = { 2682 const uint8 kBuffer[] = {
2658 0x1F, 0x43, 0xB6, 0x75, 0x83, // CLUSTER (size = 3) 2683 0x1F, 0x43, 0xB6, 0x75, 0x83, // CLUSTER (size = 3)
2659 0xE7, 0x81, 0x01, // Cluster TIMECODE (value = 1) 2684 0xE7, 0x81, 0x01, // Cluster TIMECODE (value = 1)
2660 }; 2685 };
2661 2686
2662 // Setting timestamp offset or append mode is allowed only while not 2687 // This array indicates expected return value of IsParsingMediaSegment()
2663 // parsing a media segment. This array indicates whether or not these 2688 // following each incrementally appended byte in |kBuffer|.
2664 // operations are allowed following each incrementally appended byte in
2665 // |kBuffer|.
2666 const bool kExpectedReturnValues[] = { 2689 const bool kExpectedReturnValues[] = {
2667 true, true, true, true, false, 2690 false, false, false, false, true,
2668 false, false, true, 2691 true, true, false,
2669 }; 2692 };
2670 2693
2671 COMPILE_ASSERT(arraysize(kBuffer) == arraysize(kExpectedReturnValues), 2694 COMPILE_ASSERT(arraysize(kBuffer) == arraysize(kExpectedReturnValues),
2672 test_arrays_out_of_sync); 2695 test_arrays_out_of_sync);
2673 COMPILE_ASSERT(arraysize(kBuffer) == sizeof(kBuffer), not_one_byte_per_index); 2696 COMPILE_ASSERT(arraysize(kBuffer) == sizeof(kBuffer), not_one_byte_per_index);
2674 2697
2675 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2698 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2676 2699
2677 for (size_t i = 0; i < sizeof(kBuffer); i++) { 2700 for (size_t i = 0; i < sizeof(kBuffer); i++) {
2678 DVLOG(3) << "Appending and testing index " << i; 2701 DVLOG(3) << "Appending and testing index " << i;
2679 AppendData(kBuffer + i, 1); 2702 AppendData(kBuffer + i, 1);
2680 bool expected_return_value = kExpectedReturnValues[i]; 2703 bool expected_return_value = kExpectedReturnValues[i];
2681 EXPECT_EQ(expected_return_value, demuxer_->SetTimestampOffset( 2704 EXPECT_EQ(expected_return_value,
2682 kSourceId, base::TimeDelta::FromSeconds(25))); 2705 demuxer_->IsParsingMediaSegment(kSourceId));
2683 EXPECT_EQ(expected_return_value, demuxer_->SetSequenceMode(
2684 kSourceId, true));
2685 EXPECT_EQ(expected_return_value, demuxer_->SetSequenceMode(
2686 kSourceId, false));
2687 } 2706 }
2688 } 2707 }
2689 2708
2690 TEST_F(ChunkDemuxerTest, SetSequenceModeMidMediaSegment) {
2691 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2692
2693 scoped_ptr<Cluster> cluster = GenerateCluster(0, 2);
2694 // Append only part of the cluster data.
2695 AppendData(cluster->data(), cluster->size() - 13);
2696
2697 // Setting append mode should fail because we're in the middle of a cluster.
2698 ASSERT_FALSE(demuxer_->SetSequenceMode(kSourceId, true));
2699 ASSERT_FALSE(demuxer_->SetSequenceMode(kSourceId, false));
2700
2701 demuxer_->Abort(kSourceId);
2702 // After Abort(), setting append mode should succeed since we're no longer
2703 // in the middle of a cluster.
2704 ASSERT_TRUE(demuxer_->SetSequenceMode(kSourceId, true));
2705 ASSERT_TRUE(demuxer_->SetSequenceMode(kSourceId, false));
2706 }
2707
2708 TEST_F(ChunkDemuxerTest, DurationChange) { 2709 TEST_F(ChunkDemuxerTest, DurationChange) {
2709 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2710 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2710 const int kStreamDuration = kDefaultDuration().InMilliseconds(); 2711 const int kStreamDuration = kDefaultDuration().InMilliseconds();
2711 2712
2712 // Add data leading up to the currently set duration. 2713 // Add data leading up to the currently set duration.
2713 AppendCluster(GenerateCluster(kStreamDuration - kAudioBlockDuration, 2714 AppendCluster(GenerateCluster(kStreamDuration - kAudioBlockDuration,
2714 kStreamDuration - kVideoBlockDuration, 2715 kStreamDuration - kVideoBlockDuration,
2715 2)); 2716 2));
2716 2717
2717 CheckExpectedRanges(kSourceId, "{ [201191,201224) }"); 2718 CheckExpectedRanges(kSourceId, "{ [201191,201224) }");
(...skipping 12 matching lines...) Expand all
2730 kStreamDuration + kVideoBlockDuration, 2731 kStreamDuration + kVideoBlockDuration,
2731 2)); 2732 2));
2732 2733
2733 // See that the range has increased appropriately. 2734 // See that the range has increased appropriately.
2734 CheckExpectedRanges(kSourceId, "{ [201191,201270) }"); 2735 CheckExpectedRanges(kSourceId, "{ [201191,201270) }");
2735 } 2736 }
2736 2737
2737 TEST_F(ChunkDemuxerTest, DurationChangeTimestampOffset) { 2738 TEST_F(ChunkDemuxerTest, DurationChangeTimestampOffset) {
2738 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2739 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2739 2740
2740 ASSERT_TRUE(demuxer_->SetTimestampOffset(kSourceId, kDefaultDuration())); 2741 ASSERT_FALSE(demuxer_->IsParsingMediaSegment(kSourceId));
2742 timestamp_offset_for_next_append_ = kDefaultDuration();
2741 2743
2742 EXPECT_CALL(host_, SetDuration( 2744 EXPECT_CALL(host_, SetDuration(
2743 kDefaultDuration() + base::TimeDelta::FromMilliseconds( 2745 kDefaultDuration() + base::TimeDelta::FromMilliseconds(
2744 kAudioBlockDuration * 2))); 2746 kAudioBlockDuration * 2)));
2745 AppendCluster(GenerateCluster(0, 4)); 2747 AppendCluster(GenerateCluster(0, 4));
2746 } 2748 }
2747 2749
2748 TEST_F(ChunkDemuxerTest, EndOfStreamTruncateDuration) { 2750 TEST_F(ChunkDemuxerTest, EndOfStreamTruncateDuration) {
2749 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2751 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2750 2752
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
2937 2939
2938 demuxer_->Remove(kSourceId, base::TimeDelta::FromMilliseconds(0), 2940 demuxer_->Remove(kSourceId, base::TimeDelta::FromMilliseconds(0),
2939 base::TimeDelta::FromMilliseconds(1)); 2941 base::TimeDelta::FromMilliseconds(1));
2940 } 2942 }
2941 2943
2942 TEST_F(ChunkDemuxerTest, AppendWindow_Video) { 2944 TEST_F(ChunkDemuxerTest, AppendWindow_Video) {
2943 ASSERT_TRUE(InitDemuxer(HAS_VIDEO)); 2945 ASSERT_TRUE(InitDemuxer(HAS_VIDEO));
2944 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); 2946 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO);
2945 2947
2946 // Set the append window to [20,280). 2948 // Set the append window to [20,280).
2947 demuxer_->SetAppendWindowStart(kSourceId, 2949 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20);
2948 base::TimeDelta::FromMilliseconds(20)); 2950 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280);
2949 demuxer_->SetAppendWindowEnd(kSourceId,
2950 base::TimeDelta::FromMilliseconds(280));
2951 2951
2952 // Append a cluster that starts before and ends after the append window. 2952 // Append a cluster that starts before and ends after the append window.
2953 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 2953 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
2954 "0K 30 60 90 120K 150 180 210 240K 270 300 330K"); 2954 "0K 30 60 90 120K 150 180 210 240K 270 300 330K");
2955 2955
2956 // Verify that GOPs that start outside the window are not included 2956 // Verify that GOPs that start outside the window are not included
2957 // in the buffer. Also verify that buffers that start inside the 2957 // in the buffer. Also verify that buffers that start inside the
2958 // window and extend beyond the end of the window are included. 2958 // window and extend beyond the end of the window are included.
2959 CheckExpectedRanges(kSourceId, "{ [120,300) }"); 2959 CheckExpectedRanges(kSourceId, "{ [120,300) }");
2960 CheckExpectedBuffers(stream, "120 150 180 210 240 270"); 2960 CheckExpectedBuffers(stream, "120 150 180 210 240 270");
2961 2961
2962 // Extend the append window to [20,650). 2962 // Extend the append window to [20,650).
2963 demuxer_->SetAppendWindowEnd(kSourceId, 2963 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650);
2964 base::TimeDelta::FromMilliseconds(650));
2965 2964
2966 // Append more data and verify that adding buffers start at the next 2965 // Append more data and verify that adding buffers start at the next
2967 // keyframe. 2966 // keyframe.
2968 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 2967 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
2969 "360 390 420K 450 480 510 540K 570 600 630K"); 2968 "360 390 420K 450 480 510 540K 570 600 630K");
2970 CheckExpectedRanges(kSourceId, "{ [120,300) [420,660) }"); 2969 CheckExpectedRanges(kSourceId, "{ [120,300) [420,660) }");
2971 } 2970 }
2972 2971
2973 TEST_F(ChunkDemuxerTest, AppendWindow_Audio) { 2972 TEST_F(ChunkDemuxerTest, AppendWindow_Audio) {
2974 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 2973 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
2975 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); 2974 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO);
2976 2975
2977 // Set the append window to [20,280). 2976 // Set the append window to [20,280).
2978 demuxer_->SetAppendWindowStart(kSourceId, 2977 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20);
2979 base::TimeDelta::FromMilliseconds(20)); 2978 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280);
2980 demuxer_->SetAppendWindowEnd(kSourceId,
2981 base::TimeDelta::FromMilliseconds(280));
2982 2979
2983 // Append a cluster that starts before and ends after the append window. 2980 // Append a cluster that starts before and ends after the append window.
2984 AppendSingleStreamCluster( 2981 AppendSingleStreamCluster(
2985 kSourceId, kAudioTrackNum, 2982 kSourceId, kAudioTrackNum,
2986 "0K 30K 60K 90K 120K 150K 180K 210K 240K 270K 300K 330K"); 2983 "0K 30K 60K 90K 120K 150K 180K 210K 240K 270K 300K 330K");
2987 2984
2988 // Verify that frames that start outside the window are not included 2985 // Verify that frames that start outside the window are not included
2989 // in the buffer. Also verify that buffers that start inside the 2986 // in the buffer. Also verify that buffers that start inside the
2990 // window and extend beyond the end of the window are included. 2987 // window and extend beyond the end of the window are included.
2991 CheckExpectedRanges(kSourceId, "{ [30,300) }"); 2988 CheckExpectedRanges(kSourceId, "{ [30,300) }");
2992 CheckExpectedBuffers(stream, "30 60 90 120 150 180 210 240 270"); 2989 CheckExpectedBuffers(stream, "30 60 90 120 150 180 210 240 270");
2993 2990
2994 // Extend the append window to [20,650). 2991 // Extend the append window to [20,650).
2995 demuxer_->SetAppendWindowEnd(kSourceId, 2992 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650);
2996 base::TimeDelta::FromMilliseconds(650));
2997 2993
2998 // Append more data and verify that a new range is created. 2994 // Append more data and verify that a new range is created.
2999 AppendSingleStreamCluster( 2995 AppendSingleStreamCluster(
3000 kSourceId, kAudioTrackNum, 2996 kSourceId, kAudioTrackNum,
3001 "360K 390K 420K 450K 480K 510K 540K 570K 600K 630K"); 2997 "360K 390K 420K 450K 480K 510K 540K 570K 600K 630K");
3002 CheckExpectedRanges(kSourceId, "{ [30,300) [360,660) }"); 2998 CheckExpectedRanges(kSourceId, "{ [30,300) [360,660) }");
3003 } 2999 }
3004 3000
3005 TEST_F(ChunkDemuxerTest, AppendWindow_Text) { 3001 TEST_F(ChunkDemuxerTest, AppendWindow_Text) {
3006 DemuxerStream* text_stream = NULL; 3002 DemuxerStream* text_stream = NULL;
3007 EXPECT_CALL(host_, AddTextStream(_, _)) 3003 EXPECT_CALL(host_, AddTextStream(_, _))
3008 .WillOnce(SaveArg<0>(&text_stream)); 3004 .WillOnce(SaveArg<0>(&text_stream));
3009 ASSERT_TRUE(InitDemuxer(HAS_VIDEO | HAS_TEXT)); 3005 ASSERT_TRUE(InitDemuxer(HAS_VIDEO | HAS_TEXT));
3010 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); 3006 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
3011 3007
3012 // Set the append window to [20,280). 3008 // Set the append window to [20,280).
3013 demuxer_->SetAppendWindowStart(kSourceId, 3009 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20);
3014 base::TimeDelta::FromMilliseconds(20)); 3010 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280);
3015 demuxer_->SetAppendWindowEnd(kSourceId,
3016 base::TimeDelta::FromMilliseconds(280));
3017 3011
3018 // Append a cluster that starts before and ends after the append 3012 // Append a cluster that starts before and ends after the append
3019 // window. 3013 // window.
3020 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 3014 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
3021 "0K 30 60 90 120K 150 180 210 240K 270 300 330K"); 3015 "0K 30 60 90 120K 150 180 210 240K 270 300 330K");
3022 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "0K 100K 200K 300K"); 3016 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "0K 100K 200K 300K");
3023 3017
3024 // Verify that text cues that start outside the window are not included 3018 // Verify that text cues that start outside the window are not included
3025 // in the buffer. Also verify that cues that extend beyond the 3019 // in the buffer. Also verify that cues that extend beyond the
3026 // window are included. 3020 // window are included.
3027 CheckExpectedRanges(kSourceId, "{ [120,300) }"); 3021 CheckExpectedRanges(kSourceId, "{ [120,300) }");
3028 CheckExpectedBuffers(video_stream, "120 150 180 210 240 270"); 3022 CheckExpectedBuffers(video_stream, "120 150 180 210 240 270");
3029 CheckExpectedBuffers(text_stream, "100 200"); 3023 CheckExpectedBuffers(text_stream, "100 200");
3030 3024
3031 // Extend the append window to [20,650). 3025 // Extend the append window to [20,650).
3032 demuxer_->SetAppendWindowEnd(kSourceId, 3026 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650);
3033 base::TimeDelta::FromMilliseconds(650));
3034 3027
3035 // Append more data and verify that a new range is created. 3028 // Append more data and verify that a new range is created.
3036 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 3029 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
3037 "360 390 420K 450 480 510 540K 570 600 630K"); 3030 "360 390 420K 450 480 510 540K 570 600 630K");
3038 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "400K 500K 600K 700K"); 3031 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "400K 500K 600K 700K");
3039 CheckExpectedRanges(kSourceId, "{ [120,300) [420,660) }"); 3032 CheckExpectedRanges(kSourceId, "{ [120,300) [420,660) }");
3040 3033
3041 // Seek to the new range and verify that the expected buffers are returned. 3034 // Seek to the new range and verify that the expected buffers are returned.
3042 Seek(base::TimeDelta::FromMilliseconds(420)); 3035 Seek(base::TimeDelta::FromMilliseconds(420));
3043 CheckExpectedBuffers(video_stream, "420 450 480 510 540 570 600 630"); 3036 CheckExpectedBuffers(video_stream, "420 450 480 510 540 570 600 630");
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
3144 // NOTE: we start at 175 here because the buffer at 125 was returned 3137 // NOTE: we start at 175 here because the buffer at 125 was returned
3145 // to the pending read initiated above. 3138 // to the pending read initiated above.
3146 CheckExpectedBuffers(text_stream, "175 225"); 3139 CheckExpectedBuffers(text_stream, "175 225");
3147 3140
3148 // Verify that audio & video streams contiue to return expected values. 3141 // Verify that audio & video streams contiue to return expected values.
3149 CheckExpectedBuffers(audio_stream, "160 180"); 3142 CheckExpectedBuffers(audio_stream, "160 180");
3150 CheckExpectedBuffers(video_stream, "180 210"); 3143 CheckExpectedBuffers(video_stream, "180 210");
3151 } 3144 }
3152 3145
3153 } // namespace media 3146 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698