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

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

Issue 315483002: MSE: Remove Chromium-side support for LegacyFrameProcessor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 6 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
« no previous file with comments | « media/filters/chunk_demuxer.cc ('k') | media/filters/legacy_frame_processor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 10 matching lines...) Expand all
21 #include "media/formats/webm/webm_crypto_helpers.h" 21 #include "media/formats/webm/webm_crypto_helpers.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 23
24 using ::testing::AnyNumber; 24 using ::testing::AnyNumber;
25 using ::testing::Exactly; 25 using ::testing::Exactly;
26 using ::testing::InSequence; 26 using ::testing::InSequence;
27 using ::testing::NotNull; 27 using ::testing::NotNull;
28 using ::testing::Return; 28 using ::testing::Return;
29 using ::testing::SaveArg; 29 using ::testing::SaveArg;
30 using ::testing::SetArgumentPointee; 30 using ::testing::SetArgumentPointee;
31 using ::testing::Values;
32 using ::testing::_; 31 using ::testing::_;
33 32
34 namespace media { 33 namespace media {
35 34
36 const uint8 kTracksHeader[] = { 35 const uint8 kTracksHeader[] = {
37 0x16, 0x54, 0xAE, 0x6B, // Tracks ID 36 0x16, 0x54, 0xAE, 0x6B, // Tracks ID
38 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // tracks(size = 0) 37 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // tracks(size = 0)
39 }; 38 };
40 39
41 // WebM Block bytes that represent a VP8 keyframe. 40 // WebM Block bytes that represent a VP8 keyframe.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 *called = true; 126 *called = true;
128 } 127 }
129 128
130 static void OnSeekDone_OKExpected(bool* called, PipelineStatus status) { 129 static void OnSeekDone_OKExpected(bool* called, PipelineStatus status) {
131 EXPECT_EQ(status, PIPELINE_OK); 130 EXPECT_EQ(status, PIPELINE_OK);
132 *called = true; 131 *called = true;
133 } 132 }
134 133
135 static void LogFunc(const std::string& str) { DVLOG(1) << str; } 134 static void LogFunc(const std::string& str) { DVLOG(1) << str; }
136 135
137 // Test parameter determines which coded frame processor is used to process 136 class ChunkDemuxerTest : public ::testing::Test {
138 // appended data. If true, LegacyFrameProcessor is used. Otherwise, the new
139 // FrameProcessor is used.
140 class ChunkDemuxerTest : public ::testing::TestWithParam<bool> {
141 protected: 137 protected:
142 enum CodecsIndex { 138 enum CodecsIndex {
143 AUDIO, 139 AUDIO,
144 VIDEO, 140 VIDEO,
145 MAX_CODECS_INDEX 141 MAX_CODECS_INDEX
146 }; 142 };
147 143
148 // Default cluster to append first for simple tests. 144 // Default cluster to append first for simple tests.
149 scoped_ptr<Cluster> kDefaultFirstCluster() { 145 scoped_ptr<Cluster> kDefaultFirstCluster() {
150 return GenerateCluster(0, 4); 146 return GenerateCluster(0, 4);
151 } 147 }
152 148
153 // Default cluster to append after kDefaultFirstCluster() 149 // Default cluster to append after kDefaultFirstCluster()
154 // has been appended. This cluster starts with blocks that 150 // has been appended. This cluster starts with blocks that
155 // have timestamps consistent with the end times of the blocks 151 // have timestamps consistent with the end times of the blocks
156 // in kDefaultFirstCluster() so that these two clusters represent 152 // in kDefaultFirstCluster() so that these two clusters represent
157 // a continuous region. 153 // a continuous region.
158 scoped_ptr<Cluster> kDefaultSecondCluster() { 154 scoped_ptr<Cluster> kDefaultSecondCluster() {
159 return GenerateCluster(46, 66, 5); 155 return GenerateCluster(46, 66, 5);
160 } 156 }
161 157
162 ChunkDemuxerTest() 158 ChunkDemuxerTest()
163 : append_window_end_for_next_append_(kInfiniteDuration()) { 159 : append_window_end_for_next_append_(kInfiniteDuration()) {
164 use_legacy_frame_processor_ = GetParam();
165 CreateNewDemuxer(); 160 CreateNewDemuxer();
166 } 161 }
167 162
168 void CreateNewDemuxer() { 163 void CreateNewDemuxer() {
169 base::Closure open_cb = 164 base::Closure open_cb =
170 base::Bind(&ChunkDemuxerTest::DemuxerOpened, base::Unretained(this)); 165 base::Bind(&ChunkDemuxerTest::DemuxerOpened, base::Unretained(this));
171 Demuxer::NeedKeyCB need_key_cb = 166 Demuxer::NeedKeyCB need_key_cb =
172 base::Bind(&ChunkDemuxerTest::DemuxerNeedKey, base::Unretained(this)); 167 base::Bind(&ChunkDemuxerTest::DemuxerNeedKey, base::Unretained(this));
173 demuxer_.reset( 168 demuxer_.reset(
174 new ChunkDemuxer(open_cb, need_key_cb, base::Bind(&LogFunc), true)); 169 new ChunkDemuxer(open_cb, need_key_cb, base::Bind(&LogFunc), true));
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 335
341 if (has_video) { 336 if (has_video) {
342 codecs.push_back("vp8"); 337 codecs.push_back("vp8");
343 type = "video/webm"; 338 type = "video/webm";
344 } 339 }
345 340
346 if (!has_audio && !has_video) { 341 if (!has_audio && !has_video) {
347 return AddId(kSourceId, HAS_AUDIO | HAS_VIDEO); 342 return AddId(kSourceId, HAS_AUDIO | HAS_VIDEO);
348 } 343 }
349 344
350 return demuxer_->AddId(source_id, type, codecs, 345 return demuxer_->AddId(source_id, type, codecs);
351 use_legacy_frame_processor_);
352 } 346 }
353 347
354 ChunkDemuxer::Status AddIdForMp2tSource(const std::string& source_id) { 348 ChunkDemuxer::Status AddIdForMp2tSource(const std::string& source_id) {
355 std::vector<std::string> codecs; 349 std::vector<std::string> codecs;
356 std::string type = "video/mp2t"; 350 std::string type = "video/mp2t";
357 codecs.push_back("mp4a.40.2"); 351 codecs.push_back("mp4a.40.2");
358 codecs.push_back("avc1.640028"); 352 codecs.push_back("avc1.640028");
359 return demuxer_->AddId(source_id, type, codecs, 353 return demuxer_->AddId(source_id, type, codecs);
360 use_legacy_frame_processor_);
361 } 354 }
362 355
363 void AppendData(const uint8* data, size_t length) { 356 void AppendData(const uint8* data, size_t length) {
364 AppendData(kSourceId, data, length); 357 AppendData(kSourceId, data, length);
365 } 358 }
366 359
367 void AppendCluster(const std::string& source_id, 360 void AppendCluster(const std::string& source_id,
368 scoped_ptr<Cluster> cluster) { 361 scoped_ptr<Cluster> cluster) {
369 AppendData(source_id, cluster->data(), cluster->size()); 362 AppendData(source_id, cluster->data(), cluster->size());
370 } 363 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 &data[0], data.size()); 428 &data[0], data.size());
436 } 429 }
437 } 430 }
438 AppendCluster(source_id, cb.Finish()); 431 AppendCluster(source_id, cb.Finish());
439 } 432 }
440 433
441 void AppendData(const std::string& source_id, 434 void AppendData(const std::string& source_id,
442 const uint8* data, size_t length) { 435 const uint8* data, size_t length) {
443 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber()); 436 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber());
444 437
445 // TODO(wolenetz): Test timestamp offset updating once "sequence" append
446 // mode processing is implemented. See http://crbug.com/249422.
447 demuxer_->AppendData(source_id, data, length, 438 demuxer_->AppendData(source_id, data, length,
448 append_window_start_for_next_append_, 439 append_window_start_for_next_append_,
449 append_window_end_for_next_append_, 440 append_window_end_for_next_append_,
450 &timestamp_offset_map_[source_id]); 441 &timestamp_offset_map_[source_id]);
451 } 442 }
452 443
453 void AppendDataInPieces(const uint8* data, size_t length) { 444 void AppendDataInPieces(const uint8* data, size_t length) {
454 AppendDataInPieces(data, length, 7); 445 AppendDataInPieces(data, length, 7);
455 } 446 }
456 447
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 return false; 1015 return false;
1025 1016
1026 timestamp_offset_map_[id] = timestamp_offset; 1017 timestamp_offset_map_[id] = timestamp_offset;
1027 return true; 1018 return true;
1028 } 1019 }
1029 1020
1030 base::MessageLoop message_loop_; 1021 base::MessageLoop message_loop_;
1031 MockDemuxerHost host_; 1022 MockDemuxerHost host_;
1032 1023
1033 scoped_ptr<ChunkDemuxer> demuxer_; 1024 scoped_ptr<ChunkDemuxer> demuxer_;
1034 bool use_legacy_frame_processor_;
1035 1025
1036 base::TimeDelta append_window_start_for_next_append_; 1026 base::TimeDelta append_window_start_for_next_append_;
1037 base::TimeDelta append_window_end_for_next_append_; 1027 base::TimeDelta append_window_end_for_next_append_;
1038 1028
1039 // Map of source id to timestamp offset to use for the next AppendData() 1029 // Map of source id to timestamp offset to use for the next AppendData()
1040 // operation for that source id. 1030 // operation for that source id.
1041 std::map<std::string, base::TimeDelta> timestamp_offset_map_; 1031 std::map<std::string, base::TimeDelta> timestamp_offset_map_;
1042 1032
1043 private: 1033 private:
1044 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest); 1034 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest);
1045 }; 1035 };
1046 1036
1047 TEST_P(ChunkDemuxerTest, Init) { 1037 TEST_F(ChunkDemuxerTest, Init) {
1048 // Test no streams, audio-only, video-only, and audio & video scenarios. 1038 // Test no streams, audio-only, video-only, and audio & video scenarios.
1049 // Audio and video streams can be encrypted or not encrypted. 1039 // Audio and video streams can be encrypted or not encrypted.
1050 for (int i = 0; i < 16; i++) { 1040 for (int i = 0; i < 16; i++) {
1051 bool has_audio = (i & 0x1) != 0; 1041 bool has_audio = (i & 0x1) != 0;
1052 bool has_video = (i & 0x2) != 0; 1042 bool has_video = (i & 0x2) != 0;
1053 bool is_audio_encrypted = (i & 0x4) != 0; 1043 bool is_audio_encrypted = (i & 0x4) != 0;
1054 bool is_video_encrypted = (i & 0x8) != 0; 1044 bool is_video_encrypted = (i & 0x8) != 0;
1055 1045
1056 // No test on invalid combination. 1046 // No test on invalid combination.
1057 if ((!has_audio && is_audio_encrypted) || 1047 if ((!has_audio && is_audio_encrypted) ||
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 EXPECT_FALSE(video_stream); 1100 EXPECT_FALSE(video_stream);
1111 } 1101 }
1112 1102
1113 ShutdownDemuxer(); 1103 ShutdownDemuxer();
1114 demuxer_.reset(); 1104 demuxer_.reset();
1115 } 1105 }
1116 } 1106 }
1117 1107
1118 // TODO(acolwell): Fold this test into Init tests since the tests are 1108 // TODO(acolwell): Fold this test into Init tests since the tests are
1119 // almost identical. 1109 // almost identical.
1120 TEST_P(ChunkDemuxerTest, InitText) { 1110 TEST_F(ChunkDemuxerTest, InitText) {
1121 // Test with 1 video stream and 1 text streams, and 0 or 1 audio streams. 1111 // Test with 1 video stream and 1 text streams, and 0 or 1 audio streams.
1122 // No encryption cases handled here. 1112 // No encryption cases handled here.
1123 bool has_video = true; 1113 bool has_video = true;
1124 bool is_audio_encrypted = false; 1114 bool is_audio_encrypted = false;
1125 bool is_video_encrypted = false; 1115 bool is_video_encrypted = false;
1126 for (int i = 0; i < 2; i++) { 1116 for (int i = 0; i < 2; i++) {
1127 bool has_audio = (i & 0x1) != 0; 1117 bool has_audio = (i & 0x1) != 0;
1128 1118
1129 CreateNewDemuxer(); 1119 CreateNewDemuxer();
1130 1120
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1178 ->supports_partial_append_window_trimming()); 1168 ->supports_partial_append_window_trimming());
1179 } else { 1169 } else {
1180 EXPECT_FALSE(video_stream); 1170 EXPECT_FALSE(video_stream);
1181 } 1171 }
1182 1172
1183 ShutdownDemuxer(); 1173 ShutdownDemuxer();
1184 demuxer_.reset(); 1174 demuxer_.reset();
1185 } 1175 }
1186 } 1176 }
1187 1177
1188 TEST_P(ChunkDemuxerTest, SingleTextTrackIdChange) { 1178 TEST_F(ChunkDemuxerTest, SingleTextTrackIdChange) {
1189 // Test with 1 video stream, 1 audio, and 1 text stream. Send a second init 1179 // Test with 1 video stream, 1 audio, and 1 text stream. Send a second init
1190 // segment in which the text track ID changes. Verify appended buffers before 1180 // segment in which the text track ID changes. Verify appended buffers before
1191 // and after the second init segment map to the same underlying track buffers. 1181 // and after the second init segment map to the same underlying track buffers.
1192 CreateNewDemuxer(); 1182 CreateNewDemuxer();
1193 DemuxerStream* text_stream = NULL; 1183 DemuxerStream* text_stream = NULL;
1194 TextTrackConfig text_config; 1184 TextTrackConfig text_config;
1195 EXPECT_CALL(host_, AddTextStream(_, _)) 1185 EXPECT_CALL(host_, AddTextStream(_, _))
1196 .WillOnce(DoAll(SaveArg<0>(&text_stream), 1186 .WillOnce(DoAll(SaveArg<0>(&text_stream),
1197 SaveArg<1>(&text_config))); 1187 SaveArg<1>(&text_config)));
1198 ASSERT_TRUE(InitDemuxerWithEncryptionInfo( 1188 ASSERT_TRUE(InitDemuxerWithEncryptionInfo(
(...skipping 24 matching lines...) Expand all
1223 AppendSingleStreamCluster(kSourceId, kAlternateTextTrackNum, "45K"); 1213 AppendSingleStreamCluster(kSourceId, kAlternateTextTrackNum, "45K");
1224 1214
1225 CheckExpectedRanges(kSourceId, "{ [0,92) }"); 1215 CheckExpectedRanges(kSourceId, "{ [0,92) }");
1226 CheckExpectedBuffers(audio_stream, "0 23 46 69"); 1216 CheckExpectedBuffers(audio_stream, "0 23 46 69");
1227 CheckExpectedBuffers(video_stream, "0 30 60"); 1217 CheckExpectedBuffers(video_stream, "0 30 60");
1228 CheckExpectedBuffers(text_stream, "10 45"); 1218 CheckExpectedBuffers(text_stream, "10 45");
1229 1219
1230 ShutdownDemuxer(); 1220 ShutdownDemuxer();
1231 } 1221 }
1232 1222
1233 TEST_P(ChunkDemuxerTest, InitSegmentSetsNeedRandomAccessPointFlag) { 1223 TEST_F(ChunkDemuxerTest, InitSegmentSetsNeedRandomAccessPointFlag) {
1234 // Tests that non-keyframes following an init segment are allowed 1224 // Tests that non-keyframes following an init segment are allowed
1235 // and dropped, as expected if the initialization segment received 1225 // and dropped, as expected if the initialization segment received
1236 // algorithm correctly sets the needs random access point flag to true for all 1226 // algorithm correctly sets the needs random access point flag to true for all
1237 // track buffers. Note that the first initialization segment is insufficient 1227 // track buffers. Note that the first initialization segment is insufficient
1238 // to fully test this since needs random access point flag initializes to 1228 // to fully test this since needs random access point flag initializes to
1239 // true. 1229 // true.
1240 CreateNewDemuxer(); 1230 CreateNewDemuxer();
1241 DemuxerStream* text_stream = NULL; 1231 DemuxerStream* text_stream = NULL;
1242 EXPECT_CALL(host_, AddTextStream(_, _)) 1232 EXPECT_CALL(host_, AddTextStream(_, _))
1243 .WillOnce(SaveArg<0>(&text_stream)); 1233 .WillOnce(SaveArg<0>(&text_stream));
(...skipping 16 matching lines...) Expand all
1260 1250
1261 CheckExpectedBuffers(audio_stream, "23 69"); 1251 CheckExpectedBuffers(audio_stream, "23 69");
1262 CheckExpectedBuffers(video_stream, "30 90"); 1252 CheckExpectedBuffers(video_stream, "30 90");
1263 1253
1264 // WebM parser marks all text buffers as keyframes. 1254 // WebM parser marks all text buffers as keyframes.
1265 CheckExpectedBuffers(text_stream, "0 40 80 90"); 1255 CheckExpectedBuffers(text_stream, "0 40 80 90");
1266 } 1256 }
1267 1257
1268 // Make sure that the demuxer reports an error if Shutdown() 1258 // Make sure that the demuxer reports an error if Shutdown()
1269 // is called before all the initialization segments are appended. 1259 // is called before all the initialization segments are appended.
1270 TEST_P(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) { 1260 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) {
1271 EXPECT_CALL(*this, DemuxerOpened()); 1261 EXPECT_CALL(*this, DemuxerOpened());
1272 demuxer_->Initialize( 1262 demuxer_->Initialize(
1273 &host_, CreateInitDoneCB( 1263 &host_, CreateInitDoneCB(
1274 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true); 1264 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true);
1275 1265
1276 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); 1266 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk);
1277 EXPECT_EQ(AddId("video", HAS_VIDEO), ChunkDemuxer::kOk); 1267 EXPECT_EQ(AddId("video", HAS_VIDEO), ChunkDemuxer::kOk);
1278 1268
1279 AppendInitSegmentWithSourceId("audio", HAS_AUDIO); 1269 AppendInitSegmentWithSourceId("audio", HAS_AUDIO);
1280 1270
1281 ShutdownDemuxer(); 1271 ShutdownDemuxer();
1282 } 1272 }
1283 1273
1284 TEST_P(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppendedText) { 1274 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppendedText) {
1285 EXPECT_CALL(*this, DemuxerOpened()); 1275 EXPECT_CALL(*this, DemuxerOpened());
1286 demuxer_->Initialize( 1276 demuxer_->Initialize(
1287 &host_, CreateInitDoneCB( 1277 &host_, CreateInitDoneCB(
1288 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true); 1278 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true);
1289 1279
1290 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); 1280 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk);
1291 EXPECT_EQ(AddId("video_and_text", HAS_VIDEO), ChunkDemuxer::kOk); 1281 EXPECT_EQ(AddId("video_and_text", HAS_VIDEO), ChunkDemuxer::kOk);
1292 1282
1293 EXPECT_CALL(host_, AddTextStream(_, _)) 1283 EXPECT_CALL(host_, AddTextStream(_, _))
1294 .Times(Exactly(1)); 1284 .Times(Exactly(1));
1295 1285
1296 AppendInitSegmentWithSourceId("video_and_text", HAS_VIDEO | HAS_TEXT); 1286 AppendInitSegmentWithSourceId("video_and_text", HAS_VIDEO | HAS_TEXT);
1297 1287
1298 ShutdownDemuxer(); 1288 ShutdownDemuxer();
1299 } 1289 }
1300 1290
1301 // Verifies that all streams waiting for data receive an end of stream 1291 // Verifies that all streams waiting for data receive an end of stream
1302 // buffer when Shutdown() is called. 1292 // buffer when Shutdown() is called.
1303 TEST_P(ChunkDemuxerTest, Shutdown_EndOfStreamWhileWaitingForData) { 1293 TEST_F(ChunkDemuxerTest, Shutdown_EndOfStreamWhileWaitingForData) {
1304 DemuxerStream* text_stream = NULL; 1294 DemuxerStream* text_stream = NULL;
1305 EXPECT_CALL(host_, AddTextStream(_, _)) 1295 EXPECT_CALL(host_, AddTextStream(_, _))
1306 .WillOnce(SaveArg<0>(&text_stream)); 1296 .WillOnce(SaveArg<0>(&text_stream));
1307 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); 1297 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT));
1308 1298
1309 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); 1299 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO);
1310 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); 1300 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
1311 1301
1312 bool audio_read_done = false; 1302 bool audio_read_done = false;
1313 bool video_read_done = false; 1303 bool video_read_done = false;
1314 bool text_read_done = false; 1304 bool text_read_done = false;
1315 audio_stream->Read(base::Bind(&OnReadDone_EOSExpected, &audio_read_done)); 1305 audio_stream->Read(base::Bind(&OnReadDone_EOSExpected, &audio_read_done));
1316 video_stream->Read(base::Bind(&OnReadDone_EOSExpected, &video_read_done)); 1306 video_stream->Read(base::Bind(&OnReadDone_EOSExpected, &video_read_done));
1317 text_stream->Read(base::Bind(&OnReadDone_EOSExpected, &text_read_done)); 1307 text_stream->Read(base::Bind(&OnReadDone_EOSExpected, &text_read_done));
1318 message_loop_.RunUntilIdle(); 1308 message_loop_.RunUntilIdle();
1319 1309
1320 EXPECT_FALSE(audio_read_done); 1310 EXPECT_FALSE(audio_read_done);
1321 EXPECT_FALSE(video_read_done); 1311 EXPECT_FALSE(video_read_done);
1322 EXPECT_FALSE(text_read_done); 1312 EXPECT_FALSE(text_read_done);
1323 1313
1324 ShutdownDemuxer(); 1314 ShutdownDemuxer();
1325 1315
1326 EXPECT_TRUE(audio_read_done); 1316 EXPECT_TRUE(audio_read_done);
1327 EXPECT_TRUE(video_read_done); 1317 EXPECT_TRUE(video_read_done);
1328 EXPECT_TRUE(text_read_done); 1318 EXPECT_TRUE(text_read_done);
1329 } 1319 }
1330 1320
1331 // Test that Seek() completes successfully when the first cluster 1321 // Test that Seek() completes successfully when the first cluster
1332 // arrives. 1322 // arrives.
1333 TEST_P(ChunkDemuxerTest, AppendDataAfterSeek) { 1323 TEST_F(ChunkDemuxerTest, AppendDataAfterSeek) {
1334 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1324 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1335 AppendCluster(kDefaultFirstCluster()); 1325 AppendCluster(kDefaultFirstCluster());
1336 1326
1337 InSequence s; 1327 InSequence s;
1338 1328
1339 EXPECT_CALL(*this, Checkpoint(1)); 1329 EXPECT_CALL(*this, Checkpoint(1));
1340 1330
1341 Seek(base::TimeDelta::FromMilliseconds(46)); 1331 Seek(base::TimeDelta::FromMilliseconds(46));
1342 1332
1343 EXPECT_CALL(*this, Checkpoint(2)); 1333 EXPECT_CALL(*this, Checkpoint(2));
1344 1334
1345 Checkpoint(1); 1335 Checkpoint(1);
1346 1336
1347 AppendCluster(kDefaultSecondCluster()); 1337 AppendCluster(kDefaultSecondCluster());
1348 1338
1349 message_loop_.RunUntilIdle(); 1339 message_loop_.RunUntilIdle();
1350 1340
1351 Checkpoint(2); 1341 Checkpoint(2);
1352 } 1342 }
1353 1343
1354 // Test that parsing errors are handled for clusters appended after init. 1344 // Test that parsing errors are handled for clusters appended after init.
1355 TEST_P(ChunkDemuxerTest, ErrorWhileParsingClusterAfterInit) { 1345 TEST_F(ChunkDemuxerTest, ErrorWhileParsingClusterAfterInit) {
1356 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1346 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1357 AppendCluster(kDefaultFirstCluster()); 1347 AppendCluster(kDefaultFirstCluster());
1358 1348
1359 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); 1349 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE));
1360 AppendGarbage(); 1350 AppendGarbage();
1361 } 1351 }
1362 1352
1363 // Test the case where a Seek() is requested while the parser 1353 // Test the case where a Seek() is requested while the parser
1364 // is in the middle of cluster. This is to verify that the parser 1354 // is in the middle of cluster. This is to verify that the parser
1365 // does not reset itself on a seek. 1355 // does not reset itself on a seek.
1366 TEST_P(ChunkDemuxerTest, SeekWhileParsingCluster) { 1356 TEST_F(ChunkDemuxerTest, SeekWhileParsingCluster) {
1367 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1357 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1368 1358
1369 InSequence s; 1359 InSequence s;
1370 1360
1371 scoped_ptr<Cluster> cluster_a(GenerateCluster(0, 6)); 1361 scoped_ptr<Cluster> cluster_a(GenerateCluster(0, 6));
1372 1362
1373 // Split the cluster into two appends at an arbitrary point near the end. 1363 // Split the cluster into two appends at an arbitrary point near the end.
1374 int first_append_size = cluster_a->size() - 11; 1364 int first_append_size = cluster_a->size() - 11;
1375 int second_append_size = cluster_a->size() - first_append_size; 1365 int second_append_size = cluster_a->size() - first_append_size;
1376 1366
1377 // Append the first part of the cluster. 1367 // Append the first part of the cluster.
1378 AppendData(cluster_a->data(), first_append_size); 1368 AppendData(cluster_a->data(), first_append_size);
1379 1369
1380 ExpectRead(DemuxerStream::AUDIO, 0); 1370 ExpectRead(DemuxerStream::AUDIO, 0);
1381 ExpectRead(DemuxerStream::VIDEO, 0); 1371 ExpectRead(DemuxerStream::VIDEO, 0);
1382 ExpectRead(DemuxerStream::AUDIO, kAudioBlockDuration); 1372 ExpectRead(DemuxerStream::AUDIO, kAudioBlockDuration);
1383 1373
1384 Seek(base::TimeDelta::FromSeconds(5)); 1374 Seek(base::TimeDelta::FromSeconds(5));
1385 1375
1386 // Append the rest of the cluster. 1376 // Append the rest of the cluster.
1387 AppendData(cluster_a->data() + first_append_size, second_append_size); 1377 AppendData(cluster_a->data() + first_append_size, second_append_size);
1388 1378
1389 // Append the new cluster and verify that only the blocks 1379 // Append the new cluster and verify that only the blocks
1390 // in the new cluster are returned. 1380 // in the new cluster are returned.
1391 AppendCluster(GenerateCluster(5000, 6)); 1381 AppendCluster(GenerateCluster(5000, 6));
1392 GenerateExpectedReads(5000, 6); 1382 GenerateExpectedReads(5000, 6);
1393 } 1383 }
1394 1384
1395 // Test the case where AppendData() is called before Init(). 1385 // Test the case where AppendData() is called before Init().
1396 TEST_P(ChunkDemuxerTest, AppendDataBeforeInit) { 1386 TEST_F(ChunkDemuxerTest, AppendDataBeforeInit) {
1397 scoped_ptr<uint8[]> info_tracks; 1387 scoped_ptr<uint8[]> info_tracks;
1398 int info_tracks_size = 0; 1388 int info_tracks_size = 0;
1399 CreateInitSegment(HAS_AUDIO | HAS_VIDEO, 1389 CreateInitSegment(HAS_AUDIO | HAS_VIDEO,
1400 false, false, &info_tracks, &info_tracks_size); 1390 false, false, &info_tracks, &info_tracks_size);
1401 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size, 1391 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size,
1402 append_window_start_for_next_append_, 1392 append_window_start_for_next_append_,
1403 append_window_end_for_next_append_, 1393 append_window_end_for_next_append_,
1404 &timestamp_offset_map_[kSourceId]); 1394 &timestamp_offset_map_[kSourceId]);
1405 } 1395 }
1406 1396
1407 // Make sure Read() callbacks are dispatched with the proper data. 1397 // Make sure Read() callbacks are dispatched with the proper data.
1408 TEST_P(ChunkDemuxerTest, Read) { 1398 TEST_F(ChunkDemuxerTest, Read) {
1409 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1399 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1410 1400
1411 AppendCluster(kDefaultFirstCluster()); 1401 AppendCluster(kDefaultFirstCluster());
1412 1402
1413 bool audio_read_done = false; 1403 bool audio_read_done = false;
1414 bool video_read_done = false; 1404 bool video_read_done = false;
1415 ReadAudio(base::Bind(&OnReadDone, 1405 ReadAudio(base::Bind(&OnReadDone,
1416 base::TimeDelta::FromMilliseconds(0), 1406 base::TimeDelta::FromMilliseconds(0),
1417 &audio_read_done)); 1407 &audio_read_done));
1418 ReadVideo(base::Bind(&OnReadDone, 1408 ReadVideo(base::Bind(&OnReadDone,
1419 base::TimeDelta::FromMilliseconds(0), 1409 base::TimeDelta::FromMilliseconds(0),
1420 &video_read_done)); 1410 &video_read_done));
1421 1411
1422 EXPECT_TRUE(audio_read_done); 1412 EXPECT_TRUE(audio_read_done);
1423 EXPECT_TRUE(video_read_done); 1413 EXPECT_TRUE(video_read_done);
1424 } 1414 }
1425 1415
1426 TEST_P(ChunkDemuxerTest, OutOfOrderClusters) { 1416 TEST_F(ChunkDemuxerTest, OutOfOrderClusters) {
1427 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1417 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1428 AppendCluster(kDefaultFirstCluster()); 1418 AppendCluster(kDefaultFirstCluster());
1429 AppendCluster(GenerateCluster(10, 4)); 1419 AppendCluster(GenerateCluster(10, 4));
1430 1420
1431 // Make sure that AppendCluster() does not fail with a cluster that has 1421 // Make sure that AppendCluster() does not fail with a cluster that has
1432 // overlaps with the previously appended cluster. 1422 // overlaps with the previously appended cluster.
1433 AppendCluster(GenerateCluster(5, 4)); 1423 AppendCluster(GenerateCluster(5, 4));
1434 1424
1435 // Verify that AppendData() can still accept more data. 1425 // Verify that AppendData() can still accept more data.
1436 scoped_ptr<Cluster> cluster_c(GenerateCluster(45, 2)); 1426 scoped_ptr<Cluster> cluster_c(GenerateCluster(45, 2));
1437 demuxer_->AppendData(kSourceId, cluster_c->data(), cluster_c->size(), 1427 demuxer_->AppendData(kSourceId, cluster_c->data(), cluster_c->size(),
1438 append_window_start_for_next_append_, 1428 append_window_start_for_next_append_,
1439 append_window_end_for_next_append_, 1429 append_window_end_for_next_append_,
1440 &timestamp_offset_map_[kSourceId]); 1430 &timestamp_offset_map_[kSourceId]);
1441 } 1431 }
1442 1432
1443 TEST_P(ChunkDemuxerTest, NonMonotonicButAboveClusterTimecode) { 1433 TEST_F(ChunkDemuxerTest, NonMonotonicButAboveClusterTimecode) {
1444 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1434 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1445 AppendCluster(kDefaultFirstCluster()); 1435 AppendCluster(kDefaultFirstCluster());
1446 1436
1447 ClusterBuilder cb; 1437 ClusterBuilder cb;
1448 1438
1449 // Test the case where block timecodes are not monotonically 1439 // Test the case where block timecodes are not monotonically
1450 // increasing but stay above the cluster timecode. 1440 // increasing but stay above the cluster timecode.
1451 cb.SetClusterTimecode(5); 1441 cb.SetClusterTimecode(5);
1452 AddSimpleBlock(&cb, kAudioTrackNum, 5); 1442 AddSimpleBlock(&cb, kAudioTrackNum, 5);
1453 AddSimpleBlock(&cb, kVideoTrackNum, 10); 1443 AddSimpleBlock(&cb, kVideoTrackNum, 10);
1454 AddSimpleBlock(&cb, kAudioTrackNum, 7); 1444 AddSimpleBlock(&cb, kAudioTrackNum, 7);
1455 AddSimpleBlock(&cb, kVideoTrackNum, 15); 1445 AddSimpleBlock(&cb, kVideoTrackNum, 15);
1456 1446
1457 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); 1447 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE));
1458 AppendCluster(cb.Finish()); 1448 AppendCluster(cb.Finish());
1459 1449
1460 // Verify that AppendData() ignores data after the error. 1450 // Verify that AppendData() ignores data after the error.
1461 scoped_ptr<Cluster> cluster_b(GenerateCluster(20, 2)); 1451 scoped_ptr<Cluster> cluster_b(GenerateCluster(20, 2));
1462 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(), 1452 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(),
1463 append_window_start_for_next_append_, 1453 append_window_start_for_next_append_,
1464 append_window_end_for_next_append_, 1454 append_window_end_for_next_append_,
1465 &timestamp_offset_map_[kSourceId]); 1455 &timestamp_offset_map_[kSourceId]);
1466 } 1456 }
1467 1457
1468 TEST_P(ChunkDemuxerTest, BackwardsAndBeforeClusterTimecode) { 1458 TEST_F(ChunkDemuxerTest, BackwardsAndBeforeClusterTimecode) {
1469 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1459 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1470 AppendCluster(kDefaultFirstCluster()); 1460 AppendCluster(kDefaultFirstCluster());
1471 1461
1472 ClusterBuilder cb; 1462 ClusterBuilder cb;
1473 1463
1474 // Test timecodes going backwards and including values less than the cluster 1464 // Test timecodes going backwards and including values less than the cluster
1475 // timecode. 1465 // timecode.
1476 cb.SetClusterTimecode(5); 1466 cb.SetClusterTimecode(5);
1477 AddSimpleBlock(&cb, kAudioTrackNum, 5); 1467 AddSimpleBlock(&cb, kAudioTrackNum, 5);
1478 AddSimpleBlock(&cb, kVideoTrackNum, 5); 1468 AddSimpleBlock(&cb, kVideoTrackNum, 5);
1479 AddSimpleBlock(&cb, kAudioTrackNum, 3); 1469 AddSimpleBlock(&cb, kAudioTrackNum, 3);
1480 AddSimpleBlock(&cb, kVideoTrackNum, 3); 1470 AddSimpleBlock(&cb, kVideoTrackNum, 3);
1481 1471
1482 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); 1472 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE));
1483 AppendCluster(cb.Finish()); 1473 AppendCluster(cb.Finish());
1484 1474
1485 // Verify that AppendData() ignores data after the error. 1475 // Verify that AppendData() ignores data after the error.
1486 scoped_ptr<Cluster> cluster_b(GenerateCluster(6, 2)); 1476 scoped_ptr<Cluster> cluster_b(GenerateCluster(6, 2));
1487 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(), 1477 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(),
1488 append_window_start_for_next_append_, 1478 append_window_start_for_next_append_,
1489 append_window_end_for_next_append_, 1479 append_window_end_for_next_append_,
1490 &timestamp_offset_map_[kSourceId]); 1480 &timestamp_offset_map_[kSourceId]);
1491 } 1481 }
1492 1482
1493 1483
1494 TEST_P(ChunkDemuxerTest, PerStreamMonotonicallyIncreasingTimestamps) { 1484 TEST_F(ChunkDemuxerTest, PerStreamMonotonicallyIncreasingTimestamps) {
1495 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1485 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1496 AppendCluster(kDefaultFirstCluster()); 1486 AppendCluster(kDefaultFirstCluster());
1497 1487
1498 ClusterBuilder cb; 1488 ClusterBuilder cb;
1499 1489
1500 // Test monotonic increasing timestamps on a per stream 1490 // Test monotonic increasing timestamps on a per stream
1501 // basis. 1491 // basis.
1502 cb.SetClusterTimecode(5); 1492 cb.SetClusterTimecode(5);
1503 AddSimpleBlock(&cb, kAudioTrackNum, 5); 1493 AddSimpleBlock(&cb, kAudioTrackNum, 5);
1504 AddSimpleBlock(&cb, kVideoTrackNum, 5); 1494 AddSimpleBlock(&cb, kVideoTrackNum, 5);
1505 AddSimpleBlock(&cb, kAudioTrackNum, 4); 1495 AddSimpleBlock(&cb, kAudioTrackNum, 4);
1506 AddSimpleBlock(&cb, kVideoTrackNum, 7); 1496 AddSimpleBlock(&cb, kVideoTrackNum, 7);
1507 1497
1508 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); 1498 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE));
1509 AppendCluster(cb.Finish()); 1499 AppendCluster(cb.Finish());
1510 } 1500 }
1511 1501
1512 // Test the case where a cluster is passed to AppendCluster() before 1502 // Test the case where a cluster is passed to AppendCluster() before
1513 // INFO & TRACKS data. 1503 // INFO & TRACKS data.
1514 TEST_P(ChunkDemuxerTest, ClusterBeforeInitSegment) { 1504 TEST_F(ChunkDemuxerTest, ClusterBeforeInitSegment) {
1515 EXPECT_CALL(*this, DemuxerOpened()); 1505 EXPECT_CALL(*this, DemuxerOpened());
1516 demuxer_->Initialize( 1506 demuxer_->Initialize(
1517 &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN), true); 1507 &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN), true);
1518 1508
1519 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); 1509 ASSERT_EQ(AddId(), ChunkDemuxer::kOk);
1520 1510
1521 AppendCluster(GenerateCluster(0, 1)); 1511 AppendCluster(GenerateCluster(0, 1));
1522 } 1512 }
1523 1513
1524 // Test cases where we get an MarkEndOfStream() call during initialization. 1514 // Test cases where we get an MarkEndOfStream() call during initialization.
1525 TEST_P(ChunkDemuxerTest, EOSDuringInit) { 1515 TEST_F(ChunkDemuxerTest, EOSDuringInit) {
1526 EXPECT_CALL(*this, DemuxerOpened()); 1516 EXPECT_CALL(*this, DemuxerOpened());
1527 demuxer_->Initialize( 1517 demuxer_->Initialize(
1528 &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN), true); 1518 &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN), true);
1529 MarkEndOfStream(PIPELINE_OK); 1519 MarkEndOfStream(PIPELINE_OK);
1530 } 1520 }
1531 1521
1532 TEST_P(ChunkDemuxerTest, EndOfStreamWithNoAppend) { 1522 TEST_F(ChunkDemuxerTest, EndOfStreamWithNoAppend) {
1533 EXPECT_CALL(*this, DemuxerOpened()); 1523 EXPECT_CALL(*this, DemuxerOpened());
1534 demuxer_->Initialize( 1524 demuxer_->Initialize(
1535 &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN), true); 1525 &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN), true);
1536 1526
1537 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); 1527 ASSERT_EQ(AddId(), ChunkDemuxer::kOk);
1538 1528
1539 CheckExpectedRanges("{ }"); 1529 CheckExpectedRanges("{ }");
1540 MarkEndOfStream(PIPELINE_OK); 1530 MarkEndOfStream(PIPELINE_OK);
1541 ShutdownDemuxer(); 1531 ShutdownDemuxer();
1542 CheckExpectedRanges("{ }"); 1532 CheckExpectedRanges("{ }");
1543 demuxer_->RemoveId(kSourceId); 1533 demuxer_->RemoveId(kSourceId);
1544 demuxer_.reset(); 1534 demuxer_.reset();
1545 } 1535 }
1546 1536
1547 TEST_P(ChunkDemuxerTest, EndOfStreamWithNoMediaAppend) { 1537 TEST_F(ChunkDemuxerTest, EndOfStreamWithNoMediaAppend) {
1548 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1538 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1549 1539
1550 CheckExpectedRanges("{ }"); 1540 CheckExpectedRanges("{ }");
1551 MarkEndOfStream(PIPELINE_OK); 1541 MarkEndOfStream(PIPELINE_OK);
1552 CheckExpectedRanges("{ }"); 1542 CheckExpectedRanges("{ }");
1553 } 1543 }
1554 1544
1555 TEST_P(ChunkDemuxerTest, DecodeErrorEndOfStream) { 1545 TEST_F(ChunkDemuxerTest, DecodeErrorEndOfStream) {
1556 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1546 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1557 1547
1558 AppendCluster(kDefaultFirstCluster()); 1548 AppendCluster(kDefaultFirstCluster());
1559 CheckExpectedRanges(kDefaultFirstClusterRange); 1549 CheckExpectedRanges(kDefaultFirstClusterRange);
1560 1550
1561 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); 1551 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE));
1562 MarkEndOfStream(PIPELINE_ERROR_DECODE); 1552 MarkEndOfStream(PIPELINE_ERROR_DECODE);
1563 CheckExpectedRanges(kDefaultFirstClusterRange); 1553 CheckExpectedRanges(kDefaultFirstClusterRange);
1564 } 1554 }
1565 1555
1566 TEST_P(ChunkDemuxerTest, NetworkErrorEndOfStream) { 1556 TEST_F(ChunkDemuxerTest, NetworkErrorEndOfStream) {
1567 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1557 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1568 1558
1569 AppendCluster(kDefaultFirstCluster()); 1559 AppendCluster(kDefaultFirstCluster());
1570 CheckExpectedRanges(kDefaultFirstClusterRange); 1560 CheckExpectedRanges(kDefaultFirstClusterRange);
1571 1561
1572 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_NETWORK)); 1562 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_NETWORK));
1573 MarkEndOfStream(PIPELINE_ERROR_NETWORK); 1563 MarkEndOfStream(PIPELINE_ERROR_NETWORK);
1574 } 1564 }
1575 1565
1576 // Helper class to reduce duplicate code when testing end of stream 1566 // Helper class to reduce duplicate code when testing end of stream
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 1606
1617 Demuxer* demuxer_; 1607 Demuxer* demuxer_;
1618 bool audio_read_done_; 1608 bool audio_read_done_;
1619 bool video_read_done_; 1609 bool video_read_done_;
1620 1610
1621 DISALLOW_COPY_AND_ASSIGN(EndOfStreamHelper); 1611 DISALLOW_COPY_AND_ASSIGN(EndOfStreamHelper);
1622 }; 1612 };
1623 1613
1624 // Make sure that all pending reads that we don't have media data for get an 1614 // Make sure that all pending reads that we don't have media data for get an
1625 // "end of stream" buffer when MarkEndOfStream() is called. 1615 // "end of stream" buffer when MarkEndOfStream() is called.
1626 TEST_P(ChunkDemuxerTest, EndOfStreamWithPendingReads) { 1616 TEST_F(ChunkDemuxerTest, EndOfStreamWithPendingReads) {
1627 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1617 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1628 1618
1629 AppendCluster(GenerateCluster(0, 2)); 1619 AppendCluster(GenerateCluster(0, 2));
1630 1620
1631 bool audio_read_done_1 = false; 1621 bool audio_read_done_1 = false;
1632 bool video_read_done_1 = false; 1622 bool video_read_done_1 = false;
1633 EndOfStreamHelper end_of_stream_helper_1(demuxer_.get()); 1623 EndOfStreamHelper end_of_stream_helper_1(demuxer_.get());
1634 EndOfStreamHelper end_of_stream_helper_2(demuxer_.get()); 1624 EndOfStreamHelper end_of_stream_helper_2(demuxer_.get());
1635 1625
1636 ReadAudio(base::Bind(&OnReadDone, 1626 ReadAudio(base::Bind(&OnReadDone,
(...skipping 14 matching lines...) Expand all
1651 MarkEndOfStream(PIPELINE_OK); 1641 MarkEndOfStream(PIPELINE_OK);
1652 1642
1653 end_of_stream_helper_1.CheckIfReadDonesWereCalled(true); 1643 end_of_stream_helper_1.CheckIfReadDonesWereCalled(true);
1654 1644
1655 end_of_stream_helper_2.RequestReads(); 1645 end_of_stream_helper_2.RequestReads();
1656 end_of_stream_helper_2.CheckIfReadDonesWereCalled(true); 1646 end_of_stream_helper_2.CheckIfReadDonesWereCalled(true);
1657 } 1647 }
1658 1648
1659 // Make sure that all Read() calls after we get an MarkEndOfStream() 1649 // Make sure that all Read() calls after we get an MarkEndOfStream()
1660 // call return an "end of stream" buffer. 1650 // call return an "end of stream" buffer.
1661 TEST_P(ChunkDemuxerTest, ReadsAfterEndOfStream) { 1651 TEST_F(ChunkDemuxerTest, ReadsAfterEndOfStream) {
1662 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1652 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1663 1653
1664 AppendCluster(GenerateCluster(0, 2)); 1654 AppendCluster(GenerateCluster(0, 2));
1665 1655
1666 bool audio_read_done_1 = false; 1656 bool audio_read_done_1 = false;
1667 bool video_read_done_1 = false; 1657 bool video_read_done_1 = false;
1668 EndOfStreamHelper end_of_stream_helper_1(demuxer_.get()); 1658 EndOfStreamHelper end_of_stream_helper_1(demuxer_.get());
1669 EndOfStreamHelper end_of_stream_helper_2(demuxer_.get()); 1659 EndOfStreamHelper end_of_stream_helper_2(demuxer_.get());
1670 EndOfStreamHelper end_of_stream_helper_3(demuxer_.get()); 1660 EndOfStreamHelper end_of_stream_helper_3(demuxer_.get());
1671 1661
(...skipping 18 matching lines...) Expand all
1690 1680
1691 // Request a few more reads and make sure we immediately get 1681 // Request a few more reads and make sure we immediately get
1692 // end of stream buffers. 1682 // end of stream buffers.
1693 end_of_stream_helper_2.RequestReads(); 1683 end_of_stream_helper_2.RequestReads();
1694 end_of_stream_helper_2.CheckIfReadDonesWereCalled(true); 1684 end_of_stream_helper_2.CheckIfReadDonesWereCalled(true);
1695 1685
1696 end_of_stream_helper_3.RequestReads(); 1686 end_of_stream_helper_3.RequestReads();
1697 end_of_stream_helper_3.CheckIfReadDonesWereCalled(true); 1687 end_of_stream_helper_3.CheckIfReadDonesWereCalled(true);
1698 } 1688 }
1699 1689
1700 TEST_P(ChunkDemuxerTest, EndOfStreamDuringCanceledSeek) { 1690 TEST_F(ChunkDemuxerTest, EndOfStreamDuringCanceledSeek) {
1701 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1691 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1702 1692
1703 AppendCluster(0, 10); 1693 AppendCluster(0, 10);
1704 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(138))); 1694 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(138)));
1705 MarkEndOfStream(PIPELINE_OK); 1695 MarkEndOfStream(PIPELINE_OK);
1706 1696
1707 // Start the first seek. 1697 // Start the first seek.
1708 Seek(base::TimeDelta::FromMilliseconds(20)); 1698 Seek(base::TimeDelta::FromMilliseconds(20));
1709 1699
1710 // Simulate another seek being requested before the first 1700 // Simulate another seek being requested before the first
(...skipping 10 matching lines...) Expand all
1721 // Make sure audio can reach end of stream. 1711 // Make sure audio can reach end of stream.
1722 ReadUntilNotOkOrEndOfStream(DemuxerStream::AUDIO, &status, &last_timestamp); 1712 ReadUntilNotOkOrEndOfStream(DemuxerStream::AUDIO, &status, &last_timestamp);
1723 ASSERT_EQ(status, DemuxerStream::kOk); 1713 ASSERT_EQ(status, DemuxerStream::kOk);
1724 1714
1725 // Make sure video can reach end of stream. 1715 // Make sure video can reach end of stream.
1726 ReadUntilNotOkOrEndOfStream(DemuxerStream::VIDEO, &status, &last_timestamp); 1716 ReadUntilNotOkOrEndOfStream(DemuxerStream::VIDEO, &status, &last_timestamp);
1727 ASSERT_EQ(status, DemuxerStream::kOk); 1717 ASSERT_EQ(status, DemuxerStream::kOk);
1728 } 1718 }
1729 1719
1730 // Verify buffered range change behavior for audio/video/text tracks. 1720 // Verify buffered range change behavior for audio/video/text tracks.
1731 TEST_P(ChunkDemuxerTest, EndOfStreamRangeChanges) { 1721 TEST_F(ChunkDemuxerTest, EndOfStreamRangeChanges) {
1732 DemuxerStream* text_stream = NULL; 1722 DemuxerStream* text_stream = NULL;
1733 1723
1734 EXPECT_CALL(host_, AddTextStream(_, _)) 1724 EXPECT_CALL(host_, AddTextStream(_, _))
1735 .WillOnce(SaveArg<0>(&text_stream)); 1725 .WillOnce(SaveArg<0>(&text_stream));
1736 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); 1726 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT));
1737 1727
1738 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 33"); 1728 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 33");
1739 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K 23K"); 1729 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K 23K");
1740 1730
1741 // Check expected ranges and verify that an empty text track does not 1731 // Check expected ranges and verify that an empty text track does not
(...skipping 18 matching lines...) Expand all
1760 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "0K 100K"); 1750 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "0K 100K");
1761 CheckExpectedRanges(kSourceId, "{ [0,46) }"); 1751 CheckExpectedRanges(kSourceId, "{ [0,46) }");
1762 1752
1763 // Mark end of stream and verify that text track data is reflected in 1753 // Mark end of stream and verify that text track data is reflected in
1764 // the new range. 1754 // the new range.
1765 MarkEndOfStream(PIPELINE_OK); 1755 MarkEndOfStream(PIPELINE_OK);
1766 CheckExpectedRanges(kSourceId, "{ [0,200) }"); 1756 CheckExpectedRanges(kSourceId, "{ [0,200) }");
1767 } 1757 }
1768 1758
1769 // Make sure AppendData() will accept elements that span multiple calls. 1759 // Make sure AppendData() will accept elements that span multiple calls.
1770 TEST_P(ChunkDemuxerTest, AppendingInPieces) { 1760 TEST_F(ChunkDemuxerTest, AppendingInPieces) {
1771 EXPECT_CALL(*this, DemuxerOpened()); 1761 EXPECT_CALL(*this, DemuxerOpened());
1772 demuxer_->Initialize( 1762 demuxer_->Initialize(
1773 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); 1763 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true);
1774 1764
1775 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); 1765 ASSERT_EQ(AddId(), ChunkDemuxer::kOk);
1776 1766
1777 scoped_ptr<uint8[]> info_tracks; 1767 scoped_ptr<uint8[]> info_tracks;
1778 int info_tracks_size = 0; 1768 int info_tracks_size = 0;
1779 CreateInitSegment(HAS_AUDIO | HAS_VIDEO, 1769 CreateInitSegment(HAS_AUDIO | HAS_VIDEO,
1780 false, false, &info_tracks, &info_tracks_size); 1770 false, false, &info_tracks, &info_tracks_size);
(...skipping 11 matching lines...) Expand all
1792 dst += cluster_a->size(); 1782 dst += cluster_a->size();
1793 1783
1794 memcpy(dst, cluster_b->data(), cluster_b->size()); 1784 memcpy(dst, cluster_b->data(), cluster_b->size());
1795 dst += cluster_b->size(); 1785 dst += cluster_b->size();
1796 1786
1797 AppendDataInPieces(buffer.get(), buffer_size); 1787 AppendDataInPieces(buffer.get(), buffer_size);
1798 1788
1799 GenerateExpectedReads(0, 9); 1789 GenerateExpectedReads(0, 9);
1800 } 1790 }
1801 1791
1802 TEST_P(ChunkDemuxerTest, WebMFile_AudioAndVideo) { 1792 TEST_F(ChunkDemuxerTest, WebMFile_AudioAndVideo) {
1803 struct BufferTimestamps buffer_timestamps[] = { 1793 struct BufferTimestamps buffer_timestamps[] = {
1804 {0, 0}, 1794 {0, 0},
1805 {33, 3}, 1795 {33, 3},
1806 {67, 6}, 1796 {67, 6},
1807 {100, 9}, 1797 {100, 9},
1808 {133, 12}, 1798 {133, 12},
1809 {kSkip, kSkip}, 1799 {kSkip, kSkip},
1810 }; 1800 };
1811 1801
1812 // TODO(wolenetz/acolwell): Remove this SetDuration expectation and update the 1802 // TODO(wolenetz/acolwell): Remove this SetDuration expectation and update the
1813 // ParseWebMFile() call's expected duration, below, once the file is fixed to 1803 // ParseWebMFile() call's expected duration, below, once the file is fixed to
1814 // have the correct duration in the init segment. See http://crbug.com/354284. 1804 // have the correct duration in the init segment. See http://crbug.com/354284.
1815 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2746))); 1805 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2746)));
1816 1806
1817 ASSERT_TRUE(ParseWebMFile("bear-320x240.webm", buffer_timestamps, 1807 ASSERT_TRUE(ParseWebMFile("bear-320x240.webm", buffer_timestamps,
1818 base::TimeDelta::FromMilliseconds(2744))); 1808 base::TimeDelta::FromMilliseconds(2744)));
1819 } 1809 }
1820 1810
1821 TEST_P(ChunkDemuxerTest, WebMFile_LiveAudioAndVideo) { 1811 TEST_F(ChunkDemuxerTest, WebMFile_LiveAudioAndVideo) {
1822 struct BufferTimestamps buffer_timestamps[] = { 1812 struct BufferTimestamps buffer_timestamps[] = {
1823 {0, 0}, 1813 {0, 0},
1824 {33, 3}, 1814 {33, 3},
1825 {67, 6}, 1815 {67, 6},
1826 {100, 9}, 1816 {100, 9},
1827 {133, 12}, 1817 {133, 12},
1828 {kSkip, kSkip}, 1818 {kSkip, kSkip},
1829 }; 1819 };
1830 1820
1831 ASSERT_TRUE(ParseWebMFile("bear-320x240-live.webm", buffer_timestamps, 1821 ASSERT_TRUE(ParseWebMFile("bear-320x240-live.webm", buffer_timestamps,
1832 kInfiniteDuration())); 1822 kInfiniteDuration()));
1833 } 1823 }
1834 1824
1835 TEST_P(ChunkDemuxerTest, WebMFile_AudioOnly) { 1825 TEST_F(ChunkDemuxerTest, WebMFile_AudioOnly) {
1836 struct BufferTimestamps buffer_timestamps[] = { 1826 struct BufferTimestamps buffer_timestamps[] = {
1837 {kSkip, 0}, 1827 {kSkip, 0},
1838 {kSkip, 3}, 1828 {kSkip, 3},
1839 {kSkip, 6}, 1829 {kSkip, 6},
1840 {kSkip, 9}, 1830 {kSkip, 9},
1841 {kSkip, 12}, 1831 {kSkip, 12},
1842 {kSkip, kSkip}, 1832 {kSkip, kSkip},
1843 }; 1833 };
1844 1834
1845 // TODO(wolenetz/acolwell): Remove this SetDuration expectation and update the 1835 // TODO(wolenetz/acolwell): Remove this SetDuration expectation and update the
1846 // ParseWebMFile() call's expected duration, below, once the file is fixed to 1836 // ParseWebMFile() call's expected duration, below, once the file is fixed to
1847 // have the correct duration in the init segment. See http://crbug.com/354284. 1837 // have the correct duration in the init segment. See http://crbug.com/354284.
1848 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2746))); 1838 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2746)));
1849 1839
1850 ASSERT_TRUE(ParseWebMFile("bear-320x240-audio-only.webm", buffer_timestamps, 1840 ASSERT_TRUE(ParseWebMFile("bear-320x240-audio-only.webm", buffer_timestamps,
1851 base::TimeDelta::FromMilliseconds(2744), 1841 base::TimeDelta::FromMilliseconds(2744),
1852 HAS_AUDIO)); 1842 HAS_AUDIO));
1853 } 1843 }
1854 1844
1855 TEST_P(ChunkDemuxerTest, WebMFile_VideoOnly) { 1845 TEST_F(ChunkDemuxerTest, WebMFile_VideoOnly) {
1856 struct BufferTimestamps buffer_timestamps[] = { 1846 struct BufferTimestamps buffer_timestamps[] = {
1857 {0, kSkip}, 1847 {0, kSkip},
1858 {33, kSkip}, 1848 {33, kSkip},
1859 {67, kSkip}, 1849 {67, kSkip},
1860 {100, kSkip}, 1850 {100, kSkip},
1861 {133, kSkip}, 1851 {133, kSkip},
1862 {kSkip, kSkip}, 1852 {kSkip, kSkip},
1863 }; 1853 };
1864 1854
1865 // TODO(wolenetz/acolwell): Remove this SetDuration expectation and update the 1855 // TODO(wolenetz/acolwell): Remove this SetDuration expectation and update the
1866 // ParseWebMFile() call's expected duration, below, once the file is fixed to 1856 // ParseWebMFile() call's expected duration, below, once the file is fixed to
1867 // have the correct duration in the init segment. See http://crbug.com/354284. 1857 // have the correct duration in the init segment. See http://crbug.com/354284.
1868 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2736))); 1858 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2736)));
1869 1859
1870 ASSERT_TRUE(ParseWebMFile("bear-320x240-video-only.webm", buffer_timestamps, 1860 ASSERT_TRUE(ParseWebMFile("bear-320x240-video-only.webm", buffer_timestamps,
1871 base::TimeDelta::FromMilliseconds(2703), 1861 base::TimeDelta::FromMilliseconds(2703),
1872 HAS_VIDEO)); 1862 HAS_VIDEO));
1873 } 1863 }
1874 1864
1875 TEST_P(ChunkDemuxerTest, WebMFile_AltRefFrames) { 1865 TEST_F(ChunkDemuxerTest, WebMFile_AltRefFrames) {
1876 struct BufferTimestamps buffer_timestamps[] = { 1866 struct BufferTimestamps buffer_timestamps[] = {
1877 {0, 0}, 1867 {0, 0},
1878 {33, 3}, 1868 {33, 3},
1879 {33, 6}, 1869 {33, 6},
1880 {67, 9}, 1870 {67, 9},
1881 {100, 12}, 1871 {100, 12},
1882 {kSkip, kSkip}, 1872 {kSkip, kSkip},
1883 }; 1873 };
1884 1874
1885 ASSERT_TRUE(ParseWebMFile("bear-320x240-altref.webm", buffer_timestamps, 1875 ASSERT_TRUE(ParseWebMFile("bear-320x240-altref.webm", buffer_timestamps,
1886 base::TimeDelta::FromMilliseconds(2767))); 1876 base::TimeDelta::FromMilliseconds(2767)));
1887 } 1877 }
1888 1878
1889 // Verify that we output buffers before the entire cluster has been parsed. 1879 // Verify that we output buffers before the entire cluster has been parsed.
1890 TEST_P(ChunkDemuxerTest, IncrementalClusterParsing) { 1880 TEST_F(ChunkDemuxerTest, IncrementalClusterParsing) {
1891 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1881 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1892 AppendEmptyCluster(0); 1882 AppendEmptyCluster(0);
1893 1883
1894 scoped_ptr<Cluster> cluster(GenerateCluster(0, 6)); 1884 scoped_ptr<Cluster> cluster(GenerateCluster(0, 6));
1895 1885
1896 bool audio_read_done = false; 1886 bool audio_read_done = false;
1897 bool video_read_done = false; 1887 bool video_read_done = false;
1898 ReadAudio(base::Bind(&OnReadDone, 1888 ReadAudio(base::Bind(&OnReadDone,
1899 base::TimeDelta::FromMilliseconds(0), 1889 base::TimeDelta::FromMilliseconds(0),
1900 &audio_read_done)); 1890 &audio_read_done));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1933 // Append the remaining data. 1923 // Append the remaining data.
1934 ASSERT_LT(i, cluster->size()); 1924 ASSERT_LT(i, cluster->size());
1935 AppendData(cluster->data() + i, cluster->size() - i); 1925 AppendData(cluster->data() + i, cluster->size() - i);
1936 1926
1937 message_loop_.RunUntilIdle(); 1927 message_loop_.RunUntilIdle();
1938 1928
1939 EXPECT_TRUE(audio_read_done); 1929 EXPECT_TRUE(audio_read_done);
1940 EXPECT_TRUE(video_read_done); 1930 EXPECT_TRUE(video_read_done);
1941 } 1931 }
1942 1932
1943 TEST_P(ChunkDemuxerTest, ParseErrorDuringInit) { 1933 TEST_F(ChunkDemuxerTest, ParseErrorDuringInit) {
1944 EXPECT_CALL(*this, DemuxerOpened()); 1934 EXPECT_CALL(*this, DemuxerOpened());
1945 demuxer_->Initialize( 1935 demuxer_->Initialize(
1946 &host_, CreateInitDoneCB( 1936 &host_, CreateInitDoneCB(
1947 kNoTimestamp(), DEMUXER_ERROR_COULD_NOT_OPEN), true); 1937 kNoTimestamp(), DEMUXER_ERROR_COULD_NOT_OPEN), true);
1948 1938
1949 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); 1939 ASSERT_EQ(AddId(), ChunkDemuxer::kOk);
1950 1940
1951 uint8 tmp = 0; 1941 uint8 tmp = 0;
1952 demuxer_->AppendData(kSourceId, &tmp, 1, 1942 demuxer_->AppendData(kSourceId, &tmp, 1,
1953 append_window_start_for_next_append_, 1943 append_window_start_for_next_append_,
1954 append_window_end_for_next_append_, 1944 append_window_end_for_next_append_,
1955 &timestamp_offset_map_[kSourceId]); 1945 &timestamp_offset_map_[kSourceId]);
1956 } 1946 }
1957 1947
1958 TEST_P(ChunkDemuxerTest, AVHeadersWithAudioOnlyType) { 1948 TEST_F(ChunkDemuxerTest, AVHeadersWithAudioOnlyType) {
1959 EXPECT_CALL(*this, DemuxerOpened()); 1949 EXPECT_CALL(*this, DemuxerOpened());
1960 demuxer_->Initialize( 1950 demuxer_->Initialize(
1961 &host_, CreateInitDoneCB(kNoTimestamp(), 1951 &host_, CreateInitDoneCB(kNoTimestamp(),
1962 DEMUXER_ERROR_COULD_NOT_OPEN), true); 1952 DEMUXER_ERROR_COULD_NOT_OPEN), true);
1963 1953
1964 std::vector<std::string> codecs(1); 1954 std::vector<std::string> codecs(1);
1965 codecs[0] = "vorbis"; 1955 codecs[0] = "vorbis";
1966 ASSERT_EQ(demuxer_->AddId(kSourceId, "audio/webm", codecs, 1956 ASSERT_EQ(demuxer_->AddId(kSourceId, "audio/webm", codecs),
1967 use_legacy_frame_processor_),
1968 ChunkDemuxer::kOk); 1957 ChunkDemuxer::kOk);
1969 1958
1970 AppendInitSegment(HAS_AUDIO | HAS_VIDEO); 1959 AppendInitSegment(HAS_AUDIO | HAS_VIDEO);
1971 } 1960 }
1972 1961
1973 TEST_P(ChunkDemuxerTest, AVHeadersWithVideoOnlyType) { 1962 TEST_F(ChunkDemuxerTest, AVHeadersWithVideoOnlyType) {
1974 EXPECT_CALL(*this, DemuxerOpened()); 1963 EXPECT_CALL(*this, DemuxerOpened());
1975 demuxer_->Initialize( 1964 demuxer_->Initialize(
1976 &host_, CreateInitDoneCB(kNoTimestamp(), 1965 &host_, CreateInitDoneCB(kNoTimestamp(),
1977 DEMUXER_ERROR_COULD_NOT_OPEN), true); 1966 DEMUXER_ERROR_COULD_NOT_OPEN), true);
1978 1967
1979 std::vector<std::string> codecs(1); 1968 std::vector<std::string> codecs(1);
1980 codecs[0] = "vp8"; 1969 codecs[0] = "vp8";
1981 ASSERT_EQ(demuxer_->AddId(kSourceId, "video/webm", codecs, 1970 ASSERT_EQ(demuxer_->AddId(kSourceId, "video/webm", codecs),
1982 use_legacy_frame_processor_),
1983 ChunkDemuxer::kOk); 1971 ChunkDemuxer::kOk);
1984 1972
1985 AppendInitSegment(HAS_AUDIO | HAS_VIDEO); 1973 AppendInitSegment(HAS_AUDIO | HAS_VIDEO);
1986 } 1974 }
1987 1975
1988 TEST_P(ChunkDemuxerTest, MultipleHeaders) { 1976 TEST_F(ChunkDemuxerTest, MultipleHeaders) {
1989 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1977 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1990 1978
1991 AppendCluster(kDefaultFirstCluster()); 1979 AppendCluster(kDefaultFirstCluster());
1992 1980
1993 // Append another identical initialization segment. 1981 // Append another identical initialization segment.
1994 AppendInitSegment(HAS_AUDIO | HAS_VIDEO); 1982 AppendInitSegment(HAS_AUDIO | HAS_VIDEO);
1995 1983
1996 AppendCluster(kDefaultSecondCluster()); 1984 AppendCluster(kDefaultSecondCluster());
1997 1985
1998 GenerateExpectedReads(0, 9); 1986 GenerateExpectedReads(0, 9);
1999 } 1987 }
2000 1988
2001 TEST_P(ChunkDemuxerTest, AddSeparateSourcesForAudioAndVideo) { 1989 TEST_F(ChunkDemuxerTest, AddSeparateSourcesForAudioAndVideo) {
2002 std::string audio_id = "audio1"; 1990 std::string audio_id = "audio1";
2003 std::string video_id = "video1"; 1991 std::string video_id = "video1";
2004 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id)); 1992 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id));
2005 1993
2006 // Append audio and video data into separate source ids. 1994 // Append audio and video data into separate source ids.
2007 AppendCluster(audio_id, 1995 AppendCluster(audio_id,
2008 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration)); 1996 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration));
2009 GenerateAudioStreamExpectedReads(0, 4); 1997 GenerateAudioStreamExpectedReads(0, 4);
2010 AppendCluster(video_id, 1998 AppendCluster(video_id,
2011 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration)); 1999 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration));
2012 GenerateVideoStreamExpectedReads(0, 4); 2000 GenerateVideoStreamExpectedReads(0, 4);
2013 } 2001 }
2014 2002
2015 TEST_P(ChunkDemuxerTest, AddSeparateSourcesForAudioAndVideoText) { 2003 TEST_F(ChunkDemuxerTest, AddSeparateSourcesForAudioAndVideoText) {
2016 // TODO(matthewjheaney): Here and elsewhere, we need more tests 2004 // TODO(matthewjheaney): Here and elsewhere, we need more tests
2017 // for inband text tracks (http://crbug/321455). 2005 // for inband text tracks (http://crbug/321455).
2018 2006
2019 std::string audio_id = "audio1"; 2007 std::string audio_id = "audio1";
2020 std::string video_id = "video1"; 2008 std::string video_id = "video1";
2021 2009
2022 EXPECT_CALL(host_, AddTextStream(_, _)) 2010 EXPECT_CALL(host_, AddTextStream(_, _))
2023 .Times(Exactly(2)); 2011 .Times(Exactly(2));
2024 ASSERT_TRUE(InitDemuxerAudioAndVideoSourcesText(audio_id, video_id, true)); 2012 ASSERT_TRUE(InitDemuxerAudioAndVideoSourcesText(audio_id, video_id, true));
2025 2013
2026 // Append audio and video data into separate source ids. 2014 // Append audio and video data into separate source ids.
2027 AppendCluster(audio_id, 2015 AppendCluster(audio_id,
2028 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration)); 2016 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration));
2029 GenerateAudioStreamExpectedReads(0, 4); 2017 GenerateAudioStreamExpectedReads(0, 4);
2030 AppendCluster(video_id, 2018 AppendCluster(video_id,
2031 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration)); 2019 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration));
2032 GenerateVideoStreamExpectedReads(0, 4); 2020 GenerateVideoStreamExpectedReads(0, 4);
2033 } 2021 }
2034 2022
2035 TEST_P(ChunkDemuxerTest, AddIdFailures) { 2023 TEST_F(ChunkDemuxerTest, AddIdFailures) {
2036 EXPECT_CALL(*this, DemuxerOpened()); 2024 EXPECT_CALL(*this, DemuxerOpened());
2037 demuxer_->Initialize( 2025 demuxer_->Initialize(
2038 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); 2026 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true);
2039 2027
2040 std::string audio_id = "audio1"; 2028 std::string audio_id = "audio1";
2041 std::string video_id = "video1"; 2029 std::string video_id = "video1";
2042 2030
2043 ASSERT_EQ(AddId(audio_id, HAS_AUDIO), ChunkDemuxer::kOk); 2031 ASSERT_EQ(AddId(audio_id, HAS_AUDIO), ChunkDemuxer::kOk);
2044 2032
2045 // Adding an id with audio/video should fail because we already added audio. 2033 // Adding an id with audio/video should fail because we already added audio.
2046 ASSERT_EQ(AddId(), ChunkDemuxer::kReachedIdLimit); 2034 ASSERT_EQ(AddId(), ChunkDemuxer::kReachedIdLimit);
2047 2035
2048 AppendInitSegmentWithSourceId(audio_id, HAS_AUDIO); 2036 AppendInitSegmentWithSourceId(audio_id, HAS_AUDIO);
2049 2037
2050 // Adding an id after append should fail. 2038 // Adding an id after append should fail.
2051 ASSERT_EQ(AddId(video_id, HAS_VIDEO), ChunkDemuxer::kReachedIdLimit); 2039 ASSERT_EQ(AddId(video_id, HAS_VIDEO), ChunkDemuxer::kReachedIdLimit);
2052 } 2040 }
2053 2041
2054 // Test that Read() calls after a RemoveId() return "end of stream" buffers. 2042 // Test that Read() calls after a RemoveId() return "end of stream" buffers.
2055 TEST_P(ChunkDemuxerTest, RemoveId) { 2043 TEST_F(ChunkDemuxerTest, RemoveId) {
2056 std::string audio_id = "audio1"; 2044 std::string audio_id = "audio1";
2057 std::string video_id = "video1"; 2045 std::string video_id = "video1";
2058 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id)); 2046 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id));
2059 2047
2060 // Append audio and video data into separate source ids. 2048 // Append audio and video data into separate source ids.
2061 AppendCluster(audio_id, 2049 AppendCluster(audio_id,
2062 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration)); 2050 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration));
2063 AppendCluster(video_id, 2051 AppendCluster(video_id,
2064 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration)); 2052 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration));
2065 2053
2066 // Read() from audio should return normal buffers. 2054 // Read() from audio should return normal buffers.
2067 GenerateAudioStreamExpectedReads(0, 4); 2055 GenerateAudioStreamExpectedReads(0, 4);
2068 2056
2069 // Remove the audio id. 2057 // Remove the audio id.
2070 demuxer_->RemoveId(audio_id); 2058 demuxer_->RemoveId(audio_id);
2071 2059
2072 // Read() from audio should return "end of stream" buffers. 2060 // Read() from audio should return "end of stream" buffers.
2073 bool audio_read_done = false; 2061 bool audio_read_done = false;
2074 ReadAudio(base::Bind(&OnReadDone_EOSExpected, &audio_read_done)); 2062 ReadAudio(base::Bind(&OnReadDone_EOSExpected, &audio_read_done));
2075 message_loop_.RunUntilIdle(); 2063 message_loop_.RunUntilIdle();
2076 EXPECT_TRUE(audio_read_done); 2064 EXPECT_TRUE(audio_read_done);
2077 2065
2078 // Read() from video should still return normal buffers. 2066 // Read() from video should still return normal buffers.
2079 GenerateVideoStreamExpectedReads(0, 4); 2067 GenerateVideoStreamExpectedReads(0, 4);
2080 } 2068 }
2081 2069
2082 // Test that removing an ID immediately after adding it does not interfere with 2070 // Test that removing an ID immediately after adding it does not interfere with
2083 // quota for new IDs in the future. 2071 // quota for new IDs in the future.
2084 TEST_P(ChunkDemuxerTest, RemoveAndAddId) { 2072 TEST_F(ChunkDemuxerTest, RemoveAndAddId) {
2085 std::string audio_id_1 = "audio1"; 2073 std::string audio_id_1 = "audio1";
2086 ASSERT_TRUE(AddId(audio_id_1, HAS_AUDIO) == ChunkDemuxer::kOk); 2074 ASSERT_TRUE(AddId(audio_id_1, HAS_AUDIO) == ChunkDemuxer::kOk);
2087 demuxer_->RemoveId(audio_id_1); 2075 demuxer_->RemoveId(audio_id_1);
2088 2076
2089 std::string audio_id_2 = "audio2"; 2077 std::string audio_id_2 = "audio2";
2090 ASSERT_TRUE(AddId(audio_id_2, HAS_AUDIO) == ChunkDemuxer::kOk); 2078 ASSERT_TRUE(AddId(audio_id_2, HAS_AUDIO) == ChunkDemuxer::kOk);
2091 } 2079 }
2092 2080
2093 TEST_P(ChunkDemuxerTest, SeekCanceled) { 2081 TEST_F(ChunkDemuxerTest, SeekCanceled) {
2094 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2082 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2095 2083
2096 // Append cluster at the beginning of the stream. 2084 // Append cluster at the beginning of the stream.
2097 AppendCluster(GenerateCluster(0, 4)); 2085 AppendCluster(GenerateCluster(0, 4));
2098 2086
2099 // Seek to an unbuffered region. 2087 // Seek to an unbuffered region.
2100 Seek(base::TimeDelta::FromSeconds(50)); 2088 Seek(base::TimeDelta::FromSeconds(50));
2101 2089
2102 // Attempt to read in unbuffered area; should not fulfill the read. 2090 // Attempt to read in unbuffered area; should not fulfill the read.
2103 bool audio_read_done = false; 2091 bool audio_read_done = false;
2104 bool video_read_done = false; 2092 bool video_read_done = false;
2105 ReadAudio(base::Bind(&OnReadDone_AbortExpected, &audio_read_done)); 2093 ReadAudio(base::Bind(&OnReadDone_AbortExpected, &audio_read_done));
2106 ReadVideo(base::Bind(&OnReadDone_AbortExpected, &video_read_done)); 2094 ReadVideo(base::Bind(&OnReadDone_AbortExpected, &video_read_done));
2107 EXPECT_FALSE(audio_read_done); 2095 EXPECT_FALSE(audio_read_done);
2108 EXPECT_FALSE(video_read_done); 2096 EXPECT_FALSE(video_read_done);
2109 2097
2110 // Now cancel the pending seek, which should flush the reads with empty 2098 // Now cancel the pending seek, which should flush the reads with empty
2111 // buffers. 2099 // buffers.
2112 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(0); 2100 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(0);
2113 demuxer_->CancelPendingSeek(seek_time); 2101 demuxer_->CancelPendingSeek(seek_time);
2114 message_loop_.RunUntilIdle(); 2102 message_loop_.RunUntilIdle();
2115 EXPECT_TRUE(audio_read_done); 2103 EXPECT_TRUE(audio_read_done);
2116 EXPECT_TRUE(video_read_done); 2104 EXPECT_TRUE(video_read_done);
2117 2105
2118 // A seek back to the buffered region should succeed. 2106 // A seek back to the buffered region should succeed.
2119 Seek(seek_time); 2107 Seek(seek_time);
2120 GenerateExpectedReads(0, 4); 2108 GenerateExpectedReads(0, 4);
2121 } 2109 }
2122 2110
2123 TEST_P(ChunkDemuxerTest, SeekCanceledWhileWaitingForSeek) { 2111 TEST_F(ChunkDemuxerTest, SeekCanceledWhileWaitingForSeek) {
2124 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2112 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2125 2113
2126 // Append cluster at the beginning of the stream. 2114 // Append cluster at the beginning of the stream.
2127 AppendCluster(GenerateCluster(0, 4)); 2115 AppendCluster(GenerateCluster(0, 4));
2128 2116
2129 // Start waiting for a seek. 2117 // Start waiting for a seek.
2130 base::TimeDelta seek_time1 = base::TimeDelta::FromSeconds(50); 2118 base::TimeDelta seek_time1 = base::TimeDelta::FromSeconds(50);
2131 base::TimeDelta seek_time2 = base::TimeDelta::FromSeconds(0); 2119 base::TimeDelta seek_time2 = base::TimeDelta::FromSeconds(0);
2132 demuxer_->StartWaitingForSeek(seek_time1); 2120 demuxer_->StartWaitingForSeek(seek_time1);
2133 2121
2134 // Now cancel the upcoming seek to an unbuffered region. 2122 // Now cancel the upcoming seek to an unbuffered region.
2135 demuxer_->CancelPendingSeek(seek_time2); 2123 demuxer_->CancelPendingSeek(seek_time2);
2136 demuxer_->Seek(seek_time1, NewExpectedStatusCB(PIPELINE_OK)); 2124 demuxer_->Seek(seek_time1, NewExpectedStatusCB(PIPELINE_OK));
2137 2125
2138 // Read requests should be fulfilled with empty buffers. 2126 // Read requests should be fulfilled with empty buffers.
2139 bool audio_read_done = false; 2127 bool audio_read_done = false;
2140 bool video_read_done = false; 2128 bool video_read_done = false;
2141 ReadAudio(base::Bind(&OnReadDone_AbortExpected, &audio_read_done)); 2129 ReadAudio(base::Bind(&OnReadDone_AbortExpected, &audio_read_done));
2142 ReadVideo(base::Bind(&OnReadDone_AbortExpected, &video_read_done)); 2130 ReadVideo(base::Bind(&OnReadDone_AbortExpected, &video_read_done));
2143 EXPECT_TRUE(audio_read_done); 2131 EXPECT_TRUE(audio_read_done);
2144 EXPECT_TRUE(video_read_done); 2132 EXPECT_TRUE(video_read_done);
2145 2133
2146 // A seek back to the buffered region should succeed. 2134 // A seek back to the buffered region should succeed.
2147 Seek(seek_time2); 2135 Seek(seek_time2);
2148 GenerateExpectedReads(0, 4); 2136 GenerateExpectedReads(0, 4);
2149 } 2137 }
2150 2138
2151 // Test that Seek() successfully seeks to all source IDs. 2139 // Test that Seek() successfully seeks to all source IDs.
2152 TEST_P(ChunkDemuxerTest, SeekAudioAndVideoSources) { 2140 TEST_F(ChunkDemuxerTest, SeekAudioAndVideoSources) {
2153 std::string audio_id = "audio1"; 2141 std::string audio_id = "audio1";
2154 std::string video_id = "video1"; 2142 std::string video_id = "video1";
2155 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id)); 2143 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id));
2156 2144
2157 AppendCluster( 2145 AppendCluster(
2158 audio_id, 2146 audio_id,
2159 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration)); 2147 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration));
2160 AppendCluster( 2148 AppendCluster(
2161 video_id, 2149 video_id,
2162 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration)); 2150 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2199 2187
2200 // Read() should return buffers at 3. 2188 // Read() should return buffers at 3.
2201 EXPECT_TRUE(audio_read_done); 2189 EXPECT_TRUE(audio_read_done);
2202 EXPECT_TRUE(video_read_done); 2190 EXPECT_TRUE(video_read_done);
2203 } 2191 }
2204 2192
2205 // Test that Seek() completes successfully when EndOfStream 2193 // Test that Seek() completes successfully when EndOfStream
2206 // is called before data is available for that seek point. 2194 // is called before data is available for that seek point.
2207 // This scenario might be useful if seeking past the end of stream 2195 // This scenario might be useful if seeking past the end of stream
2208 // of either audio or video (or both). 2196 // of either audio or video (or both).
2209 TEST_P(ChunkDemuxerTest, EndOfStreamAfterPastEosSeek) { 2197 TEST_F(ChunkDemuxerTest, EndOfStreamAfterPastEosSeek) {
2210 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2198 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2211 2199
2212 AppendCluster(GenerateSingleStreamCluster(0, 120, kAudioTrackNum, 10)); 2200 AppendCluster(GenerateSingleStreamCluster(0, 120, kAudioTrackNum, 10));
2213 AppendCluster(GenerateSingleStreamCluster(0, 100, kVideoTrackNum, 5)); 2201 AppendCluster(GenerateSingleStreamCluster(0, 100, kVideoTrackNum, 5));
2214 2202
2215 // Seeking past the end of video. 2203 // Seeking past the end of video.
2216 // Note: audio data is available for that seek point. 2204 // Note: audio data is available for that seek point.
2217 bool seek_cb_was_called = false; 2205 bool seek_cb_was_called = false;
2218 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(110); 2206 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(110);
2219 demuxer_->StartWaitingForSeek(seek_time); 2207 demuxer_->StartWaitingForSeek(seek_time);
2220 demuxer_->Seek(seek_time, 2208 demuxer_->Seek(seek_time,
2221 base::Bind(OnSeekDone_OKExpected, &seek_cb_was_called)); 2209 base::Bind(OnSeekDone_OKExpected, &seek_cb_was_called));
2222 message_loop_.RunUntilIdle(); 2210 message_loop_.RunUntilIdle();
2223 2211
2224 EXPECT_FALSE(seek_cb_was_called); 2212 EXPECT_FALSE(seek_cb_was_called);
2225 2213
2226 EXPECT_CALL(host_, SetDuration( 2214 EXPECT_CALL(host_, SetDuration(
2227 base::TimeDelta::FromMilliseconds(120))); 2215 base::TimeDelta::FromMilliseconds(120)));
2228 MarkEndOfStream(PIPELINE_OK); 2216 MarkEndOfStream(PIPELINE_OK);
2229 message_loop_.RunUntilIdle(); 2217 message_loop_.RunUntilIdle();
2230 2218
2231 EXPECT_TRUE(seek_cb_was_called); 2219 EXPECT_TRUE(seek_cb_was_called);
2232 2220
2233 ShutdownDemuxer(); 2221 ShutdownDemuxer();
2234 } 2222 }
2235 2223
2236 // Test that EndOfStream is ignored if coming during a pending seek 2224 // Test that EndOfStream is ignored if coming during a pending seek
2237 // whose seek time is before some existing ranges. 2225 // whose seek time is before some existing ranges.
2238 TEST_P(ChunkDemuxerTest, EndOfStreamDuringPendingSeek) { 2226 TEST_F(ChunkDemuxerTest, EndOfStreamDuringPendingSeek) {
2239 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2227 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2240 2228
2241 AppendCluster(GenerateSingleStreamCluster(0, 120, kAudioTrackNum, 10)); 2229 AppendCluster(GenerateSingleStreamCluster(0, 120, kAudioTrackNum, 10));
2242 AppendCluster(GenerateSingleStreamCluster(0, 100, kVideoTrackNum, 5)); 2230 AppendCluster(GenerateSingleStreamCluster(0, 100, kVideoTrackNum, 5));
2243 AppendCluster(GenerateSingleStreamCluster(200, 300, kAudioTrackNum, 10)); 2231 AppendCluster(GenerateSingleStreamCluster(200, 300, kAudioTrackNum, 10));
2244 AppendCluster(GenerateSingleStreamCluster(200, 300, kVideoTrackNum, 5)); 2232 AppendCluster(GenerateSingleStreamCluster(200, 300, kVideoTrackNum, 5));
2245 2233
2246 bool seek_cb_was_called = false; 2234 bool seek_cb_was_called = false;
2247 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(160); 2235 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(160);
2248 demuxer_->StartWaitingForSeek(seek_time); 2236 demuxer_->StartWaitingForSeek(seek_time);
(...skipping 15 matching lines...) Expand all
2264 AppendCluster(GenerateSingleStreamCluster(140, 180, kVideoTrackNum, 5)); 2252 AppendCluster(GenerateSingleStreamCluster(140, 180, kVideoTrackNum, 5));
2265 2253
2266 message_loop_.RunUntilIdle(); 2254 message_loop_.RunUntilIdle();
2267 2255
2268 EXPECT_TRUE(seek_cb_was_called); 2256 EXPECT_TRUE(seek_cb_was_called);
2269 2257
2270 ShutdownDemuxer(); 2258 ShutdownDemuxer();
2271 } 2259 }
2272 2260
2273 // Test ranges in an audio-only stream. 2261 // Test ranges in an audio-only stream.
2274 TEST_P(ChunkDemuxerTest, GetBufferedRanges_AudioIdOnly) { 2262 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioIdOnly) {
2275 EXPECT_CALL(*this, DemuxerOpened()); 2263 EXPECT_CALL(*this, DemuxerOpened());
2276 demuxer_->Initialize( 2264 demuxer_->Initialize(
2277 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); 2265 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true);
2278 2266
2279 ASSERT_EQ(AddId(kSourceId, HAS_AUDIO), ChunkDemuxer::kOk); 2267 ASSERT_EQ(AddId(kSourceId, HAS_AUDIO), ChunkDemuxer::kOk);
2280 AppendInitSegment(HAS_AUDIO); 2268 AppendInitSegment(HAS_AUDIO);
2281 2269
2282 // Test a simple cluster. 2270 // Test a simple cluster.
2283 AppendCluster( 2271 AppendCluster(
2284 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration)); 2272 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration));
2285 2273
2286 CheckExpectedRanges("{ [0,92) }"); 2274 CheckExpectedRanges("{ [0,92) }");
2287 2275
2288 // Append a disjoint cluster to check for two separate ranges. 2276 // Append a disjoint cluster to check for two separate ranges.
2289 AppendCluster(GenerateSingleStreamCluster( 2277 AppendCluster(GenerateSingleStreamCluster(
2290 150, 219, kAudioTrackNum, kAudioBlockDuration)); 2278 150, 219, kAudioTrackNum, kAudioBlockDuration));
2291 2279
2292 CheckExpectedRanges("{ [0,92) [150,219) }"); 2280 CheckExpectedRanges("{ [0,92) [150,219) }");
2293 } 2281 }
2294 2282
2295 // Test ranges in a video-only stream. 2283 // Test ranges in a video-only stream.
2296 TEST_P(ChunkDemuxerTest, GetBufferedRanges_VideoIdOnly) { 2284 TEST_F(ChunkDemuxerTest, GetBufferedRanges_VideoIdOnly) {
2297 EXPECT_CALL(*this, DemuxerOpened()); 2285 EXPECT_CALL(*this, DemuxerOpened());
2298 demuxer_->Initialize( 2286 demuxer_->Initialize(
2299 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); 2287 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true);
2300 2288
2301 ASSERT_EQ(AddId(kSourceId, HAS_VIDEO), ChunkDemuxer::kOk); 2289 ASSERT_EQ(AddId(kSourceId, HAS_VIDEO), ChunkDemuxer::kOk);
2302 AppendInitSegment(HAS_VIDEO); 2290 AppendInitSegment(HAS_VIDEO);
2303 2291
2304 // Test a simple cluster. 2292 // Test a simple cluster.
2305 AppendCluster( 2293 AppendCluster(
2306 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration)); 2294 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration));
2307 2295
2308 CheckExpectedRanges("{ [0,132) }"); 2296 CheckExpectedRanges("{ [0,132) }");
2309 2297
2310 // Append a disjoint cluster to check for two separate ranges. 2298 // Append a disjoint cluster to check for two separate ranges.
2311 AppendCluster(GenerateSingleStreamCluster( 2299 AppendCluster(GenerateSingleStreamCluster(
2312 200, 299, kVideoTrackNum, kVideoBlockDuration)); 2300 200, 299, kVideoTrackNum, kVideoBlockDuration));
2313 2301
2314 CheckExpectedRanges("{ [0,132) [200,299) }"); 2302 CheckExpectedRanges("{ [0,132) [200,299) }");
2315 } 2303 }
2316 2304
2317 TEST_P(ChunkDemuxerTest, GetBufferedRanges_AudioVideo) { 2305 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioVideo) {
2318 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2306 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2319 2307
2320 // Audio: 0 -> 23 2308 // Audio: 0 -> 23
2321 // Video: 0 -> 33 2309 // Video: 0 -> 33
2322 // Buffered Range: 0 -> 23 2310 // Buffered Range: 0 -> 23
2323 // Audio block duration is smaller than video block duration, 2311 // Audio block duration is smaller than video block duration,
2324 // so the buffered ranges should correspond to the audio blocks. 2312 // so the buffered ranges should correspond to the audio blocks.
2325 AppendCluster(GenerateSingleStreamCluster( 2313 AppendCluster(GenerateSingleStreamCluster(
2326 0, kAudioBlockDuration, kAudioTrackNum, kAudioBlockDuration)); 2314 0, kAudioBlockDuration, kAudioTrackNum, kAudioBlockDuration));
2327 AppendCluster(GenerateSingleStreamCluster( 2315 AppendCluster(GenerateSingleStreamCluster(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2364 // Appending within buffered range should not affect buffered ranges. 2352 // Appending within buffered range should not affect buffered ranges.
2365 AppendCluster(GenerateSingleStreamCluster(930, 950, kAudioTrackNum, 20)); 2353 AppendCluster(GenerateSingleStreamCluster(930, 950, kAudioTrackNum, 20));
2366 CheckExpectedRanges("{ [0,23) [320,400) [520,570) [720,750) [920,950) }"); 2354 CheckExpectedRanges("{ [0,23) [320,400) [520,570) [720,750) [920,950) }");
2367 2355
2368 // Appending to single stream outside buffered ranges should not affect 2356 // Appending to single stream outside buffered ranges should not affect
2369 // buffered ranges. 2357 // buffered ranges.
2370 AppendCluster(GenerateSingleStreamCluster(1230, 1240, kVideoTrackNum, 10)); 2358 AppendCluster(GenerateSingleStreamCluster(1230, 1240, kVideoTrackNum, 10));
2371 CheckExpectedRanges("{ [0,23) [320,400) [520,570) [720,750) [920,950) }"); 2359 CheckExpectedRanges("{ [0,23) [320,400) [520,570) [720,750) [920,950) }");
2372 } 2360 }
2373 2361
2374 TEST_P(ChunkDemuxerTest, GetBufferedRanges_AudioVideoText) { 2362 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioVideoText) {
2375 EXPECT_CALL(host_, AddTextStream(_, _)); 2363 EXPECT_CALL(host_, AddTextStream(_, _));
2376 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); 2364 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT));
2377 2365
2378 // Append audio & video data 2366 // Append audio & video data
2379 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K 23"); 2367 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K 23");
2380 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 33"); 2368 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 33");
2381 2369
2382 // Verify that a text track with no cues does not result in an empty buffered 2370 // Verify that a text track with no cues does not result in an empty buffered
2383 // range. 2371 // range.
2384 CheckExpectedRanges("{ [0,46) }"); 2372 CheckExpectedRanges("{ [0,46) }");
2385 2373
2386 // Add some text cues. 2374 // Add some text cues.
2387 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "0K 100K"); 2375 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "0K 100K");
2388 2376
2389 // Verify that the new cues did not affect the buffered ranges. 2377 // Verify that the new cues did not affect the buffered ranges.
2390 CheckExpectedRanges("{ [0,46) }"); 2378 CheckExpectedRanges("{ [0,46) }");
2391 2379
2392 // Remove the buffered range. 2380 // Remove the buffered range.
2393 demuxer_->Remove(kSourceId, base::TimeDelta(), 2381 demuxer_->Remove(kSourceId, base::TimeDelta(),
2394 base::TimeDelta::FromMilliseconds(46)); 2382 base::TimeDelta::FromMilliseconds(46));
2395 CheckExpectedRanges("{ }"); 2383 CheckExpectedRanges("{ }");
2396 } 2384 }
2397 2385
2398 // Once MarkEndOfStream() is called, GetBufferedRanges should not cut off any 2386 // Once MarkEndOfStream() is called, GetBufferedRanges should not cut off any
2399 // over-hanging tails at the end of the ranges as this is likely due to block 2387 // over-hanging tails at the end of the ranges as this is likely due to block
2400 // duration differences. 2388 // duration differences.
2401 TEST_P(ChunkDemuxerTest, GetBufferedRanges_EndOfStream) { 2389 TEST_F(ChunkDemuxerTest, GetBufferedRanges_EndOfStream) {
2402 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2390 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2403 2391
2404 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K 23K"); 2392 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K 23K");
2405 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 33"); 2393 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 33");
2406 2394
2407 CheckExpectedRanges("{ [0,46) }"); 2395 CheckExpectedRanges("{ [0,46) }");
2408 2396
2409 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(66))); 2397 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(66)));
2410 MarkEndOfStream(PIPELINE_OK); 2398 MarkEndOfStream(PIPELINE_OK);
2411 2399
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2449 2437
2450 MarkEndOfStream(PIPELINE_OK); 2438 MarkEndOfStream(PIPELINE_OK);
2451 2439
2452 // NOTE: The last range on each stream gets extended to the highest 2440 // NOTE: The last range on each stream gets extended to the highest
2453 // end timestamp according to the spec. The last audio range gets extended 2441 // end timestamp according to the spec. The last audio range gets extended
2454 // from [200,246) to [200,398) which is why the intersection results in the 2442 // from [200,246) to [200,398) which is why the intersection results in the
2455 // middle range getting larger AND the new range appearing. 2443 // middle range getting larger AND the new range appearing.
2456 CheckExpectedRanges("{ [0,46) [200,266) [332,398) }"); 2444 CheckExpectedRanges("{ [0,46) [200,266) [332,398) }");
2457 } 2445 }
2458 2446
2459 TEST_P(ChunkDemuxerTest, DifferentStreamTimecodes) { 2447 TEST_F(ChunkDemuxerTest, DifferentStreamTimecodes) {
2460 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2448 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2461 2449
2462 // Create a cluster where the video timecode begins 25ms after the audio. 2450 // Create a cluster where the video timecode begins 25ms after the audio.
2463 AppendCluster(GenerateCluster(0, 25, 8)); 2451 AppendCluster(GenerateCluster(0, 25, 8));
2464 2452
2465 Seek(base::TimeDelta::FromSeconds(0)); 2453 Seek(base::TimeDelta::FromSeconds(0));
2466 GenerateExpectedReads(0, 25, 8); 2454 GenerateExpectedReads(0, 25, 8);
2467 2455
2468 // Seek to 5 seconds. 2456 // Seek to 5 seconds.
2469 Seek(base::TimeDelta::FromSeconds(5)); 2457 Seek(base::TimeDelta::FromSeconds(5));
2470 2458
2471 // Generate a cluster to fulfill this seek, where audio timecode begins 25ms 2459 // Generate a cluster to fulfill this seek, where audio timecode begins 25ms
2472 // after the video. 2460 // after the video.
2473 AppendCluster(GenerateCluster(5025, 5000, 8)); 2461 AppendCluster(GenerateCluster(5025, 5000, 8));
2474 GenerateExpectedReads(5025, 5000, 8); 2462 GenerateExpectedReads(5025, 5000, 8);
2475 } 2463 }
2476 2464
2477 TEST_P(ChunkDemuxerTest, DifferentStreamTimecodesSeparateSources) { 2465 TEST_F(ChunkDemuxerTest, DifferentStreamTimecodesSeparateSources) {
2478 std::string audio_id = "audio1"; 2466 std::string audio_id = "audio1";
2479 std::string video_id = "video1"; 2467 std::string video_id = "video1";
2480 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id)); 2468 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id));
2481 2469
2482 // Generate two streams where the video stream starts 5ms after the audio 2470 // Generate two streams where the video stream starts 5ms after the audio
2483 // stream and append them. 2471 // stream and append them.
2484 AppendCluster(audio_id, GenerateSingleStreamCluster( 2472 AppendCluster(audio_id, GenerateSingleStreamCluster(
2485 25, 4 * kAudioBlockDuration + 25, kAudioTrackNum, kAudioBlockDuration)); 2473 25, 4 * kAudioBlockDuration + 25, kAudioTrackNum, kAudioBlockDuration));
2486 AppendCluster(video_id, GenerateSingleStreamCluster( 2474 AppendCluster(video_id, GenerateSingleStreamCluster(
2487 30, 4 * kVideoBlockDuration + 30, kVideoTrackNum, kVideoBlockDuration)); 2475 30, 4 * kVideoBlockDuration + 30, kVideoTrackNum, kVideoBlockDuration));
2488 2476
2489 // Both streams should be able to fulfill a seek to 25. 2477 // Both streams should be able to fulfill a seek to 25.
2490 Seek(base::TimeDelta::FromMilliseconds(25)); 2478 Seek(base::TimeDelta::FromMilliseconds(25));
2491 GenerateAudioStreamExpectedReads(25, 4); 2479 GenerateAudioStreamExpectedReads(25, 4);
2492 GenerateVideoStreamExpectedReads(30, 4); 2480 GenerateVideoStreamExpectedReads(30, 4);
2493 } 2481 }
2494 2482
2495 TEST_P(ChunkDemuxerTest, DifferentStreamTimecodesOutOfRange) { 2483 TEST_F(ChunkDemuxerTest, DifferentStreamTimecodesOutOfRange) {
2496 std::string audio_id = "audio1"; 2484 std::string audio_id = "audio1";
2497 std::string video_id = "video1"; 2485 std::string video_id = "video1";
2498 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id)); 2486 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id));
2499 2487
2500 // Generate two streams where the video stream starts 10s after the audio 2488 // Generate two streams where the video stream starts 10s after the audio
2501 // stream and append them. 2489 // stream and append them.
2502 AppendCluster(audio_id, GenerateSingleStreamCluster(0, 2490 AppendCluster(audio_id, GenerateSingleStreamCluster(0,
2503 4 * kAudioBlockDuration + 0, kAudioTrackNum, kAudioBlockDuration)); 2491 4 * kAudioBlockDuration + 0, kAudioTrackNum, kAudioBlockDuration));
2504 AppendCluster(video_id, GenerateSingleStreamCluster(10000, 2492 AppendCluster(video_id, GenerateSingleStreamCluster(10000,
2505 4 * kVideoBlockDuration + 10000, kVideoTrackNum, kVideoBlockDuration)); 2493 4 * kVideoBlockDuration + 10000, kVideoTrackNum, kVideoBlockDuration));
2506 2494
2507 // Should not be able to fulfill a seek to 0. 2495 // Should not be able to fulfill a seek to 0.
2508 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(0); 2496 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(0);
2509 demuxer_->StartWaitingForSeek(seek_time); 2497 demuxer_->StartWaitingForSeek(seek_time);
2510 demuxer_->Seek(seek_time, 2498 demuxer_->Seek(seek_time,
2511 NewExpectedStatusCB(PIPELINE_ERROR_ABORT)); 2499 NewExpectedStatusCB(PIPELINE_ERROR_ABORT));
2512 ExpectRead(DemuxerStream::AUDIO, 0); 2500 ExpectRead(DemuxerStream::AUDIO, 0);
2513 ExpectEndOfStream(DemuxerStream::VIDEO); 2501 ExpectEndOfStream(DemuxerStream::VIDEO);
2514 } 2502 }
2515 2503
2516 TEST_P(ChunkDemuxerTest, ClusterWithNoBuffers) { 2504 TEST_F(ChunkDemuxerTest, ClusterWithNoBuffers) {
2517 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2505 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2518 2506
2519 // Generate and append an empty cluster beginning at 0. 2507 // Generate and append an empty cluster beginning at 0.
2520 AppendEmptyCluster(0); 2508 AppendEmptyCluster(0);
2521 2509
2522 // Sanity check that data can be appended after this cluster correctly. 2510 // Sanity check that data can be appended after this cluster correctly.
2523 AppendCluster(GenerateCluster(0, 2)); 2511 AppendCluster(GenerateCluster(0, 2));
2524 ExpectRead(DemuxerStream::AUDIO, 0); 2512 ExpectRead(DemuxerStream::AUDIO, 0);
2525 ExpectRead(DemuxerStream::VIDEO, 0); 2513 ExpectRead(DemuxerStream::VIDEO, 0);
2526 } 2514 }
2527 2515
2528 TEST_P(ChunkDemuxerTest, CodecPrefixMatching) { 2516 TEST_F(ChunkDemuxerTest, CodecPrefixMatching) {
2529 ChunkDemuxer::Status expected = ChunkDemuxer::kNotSupported; 2517 ChunkDemuxer::Status expected = ChunkDemuxer::kNotSupported;
2530 2518
2531 #if defined(USE_PROPRIETARY_CODECS) 2519 #if defined(USE_PROPRIETARY_CODECS)
2532 expected = ChunkDemuxer::kOk; 2520 expected = ChunkDemuxer::kOk;
2533 #endif 2521 #endif
2534 2522
2535 std::vector<std::string> codecs; 2523 std::vector<std::string> codecs;
2536 codecs.push_back("avc1.4D4041"); 2524 codecs.push_back("avc1.4D4041");
2537 2525
2538 EXPECT_EQ(demuxer_->AddId("source_id", "video/mp4", codecs, 2526 EXPECT_EQ(demuxer_->AddId("source_id", "video/mp4", codecs), expected);
2539 use_legacy_frame_processor_),
2540 expected);
2541 } 2527 }
2542 2528
2543 // Test codec ID's that are not compliant with RFC6381, but have been 2529 // Test codec ID's that are not compliant with RFC6381, but have been
2544 // seen in the wild. 2530 // seen in the wild.
2545 TEST_P(ChunkDemuxerTest, CodecIDsThatAreNotRFC6381Compliant) { 2531 TEST_F(ChunkDemuxerTest, CodecIDsThatAreNotRFC6381Compliant) {
2546 ChunkDemuxer::Status expected = ChunkDemuxer::kNotSupported; 2532 ChunkDemuxer::Status expected = ChunkDemuxer::kNotSupported;
2547 2533
2548 #if defined(USE_PROPRIETARY_CODECS) 2534 #if defined(USE_PROPRIETARY_CODECS)
2549 expected = ChunkDemuxer::kOk; 2535 expected = ChunkDemuxer::kOk;
2550 #endif 2536 #endif
2551 const char* codec_ids[] = { 2537 const char* codec_ids[] = {
2552 // GPAC places leading zeros on the audio object type. 2538 // GPAC places leading zeros on the audio object type.
2553 "mp4a.40.02", 2539 "mp4a.40.02",
2554 "mp4a.40.05" 2540 "mp4a.40.05"
2555 }; 2541 };
2556 2542
2557 for (size_t i = 0; i < arraysize(codec_ids); ++i) { 2543 for (size_t i = 0; i < arraysize(codec_ids); ++i) {
2558 std::vector<std::string> codecs; 2544 std::vector<std::string> codecs;
2559 codecs.push_back(codec_ids[i]); 2545 codecs.push_back(codec_ids[i]);
2560 2546
2561 ChunkDemuxer::Status result = 2547 ChunkDemuxer::Status result =
2562 demuxer_->AddId("source_id", "audio/mp4", codecs, 2548 demuxer_->AddId("source_id", "audio/mp4", codecs);
2563 use_legacy_frame_processor_);
2564 2549
2565 EXPECT_EQ(result, expected) 2550 EXPECT_EQ(result, expected)
2566 << "Fail to add codec_id '" << codec_ids[i] << "'"; 2551 << "Fail to add codec_id '" << codec_ids[i] << "'";
2567 2552
2568 if (result == ChunkDemuxer::kOk) 2553 if (result == ChunkDemuxer::kOk)
2569 demuxer_->RemoveId("source_id"); 2554 demuxer_->RemoveId("source_id");
2570 } 2555 }
2571 } 2556 }
2572 2557
2573 TEST_P(ChunkDemuxerTest, EndOfStreamStillSetAfterSeek) { 2558 TEST_F(ChunkDemuxerTest, EndOfStreamStillSetAfterSeek) {
2574 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2559 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2575 2560
2576 EXPECT_CALL(host_, SetDuration(_)) 2561 EXPECT_CALL(host_, SetDuration(_))
2577 .Times(AnyNumber()); 2562 .Times(AnyNumber());
2578 2563
2579 base::TimeDelta kLastAudioTimestamp = base::TimeDelta::FromMilliseconds(92); 2564 base::TimeDelta kLastAudioTimestamp = base::TimeDelta::FromMilliseconds(92);
2580 base::TimeDelta kLastVideoTimestamp = base::TimeDelta::FromMilliseconds(99); 2565 base::TimeDelta kLastVideoTimestamp = base::TimeDelta::FromMilliseconds(99);
2581 2566
2582 AppendCluster(kDefaultFirstCluster()); 2567 AppendCluster(kDefaultFirstCluster());
2583 AppendCluster(kDefaultSecondCluster()); 2568 AppendCluster(kDefaultSecondCluster());
(...skipping 16 matching lines...) Expand all
2600 2585
2601 ReadUntilNotOkOrEndOfStream(DemuxerStream::AUDIO, &status, &last_timestamp); 2586 ReadUntilNotOkOrEndOfStream(DemuxerStream::AUDIO, &status, &last_timestamp);
2602 EXPECT_EQ(DemuxerStream::kOk, status); 2587 EXPECT_EQ(DemuxerStream::kOk, status);
2603 EXPECT_EQ(kLastAudioTimestamp, last_timestamp); 2588 EXPECT_EQ(kLastAudioTimestamp, last_timestamp);
2604 2589
2605 ReadUntilNotOkOrEndOfStream(DemuxerStream::VIDEO, &status, &last_timestamp); 2590 ReadUntilNotOkOrEndOfStream(DemuxerStream::VIDEO, &status, &last_timestamp);
2606 EXPECT_EQ(DemuxerStream::kOk, status); 2591 EXPECT_EQ(DemuxerStream::kOk, status);
2607 EXPECT_EQ(kLastVideoTimestamp, last_timestamp); 2592 EXPECT_EQ(kLastVideoTimestamp, last_timestamp);
2608 } 2593 }
2609 2594
2610 TEST_P(ChunkDemuxerTest, GetBufferedRangesBeforeInitSegment) { 2595 TEST_F(ChunkDemuxerTest, GetBufferedRangesBeforeInitSegment) {
2611 EXPECT_CALL(*this, DemuxerOpened()); 2596 EXPECT_CALL(*this, DemuxerOpened());
2612 demuxer_->Initialize(&host_, CreateInitDoneCB(PIPELINE_OK), true); 2597 demuxer_->Initialize(&host_, CreateInitDoneCB(PIPELINE_OK), true);
2613 ASSERT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); 2598 ASSERT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk);
2614 ASSERT_EQ(AddId("video", HAS_VIDEO), ChunkDemuxer::kOk); 2599 ASSERT_EQ(AddId("video", HAS_VIDEO), ChunkDemuxer::kOk);
2615 2600
2616 CheckExpectedRanges("audio", "{ }"); 2601 CheckExpectedRanges("audio", "{ }");
2617 CheckExpectedRanges("video", "{ }"); 2602 CheckExpectedRanges("video", "{ }");
2618 } 2603 }
2619 2604
2620 // Test that Seek() completes successfully when the first cluster 2605 // Test that Seek() completes successfully when the first cluster
2621 // arrives. 2606 // arrives.
2622 TEST_P(ChunkDemuxerTest, EndOfStreamDuringSeek) { 2607 TEST_F(ChunkDemuxerTest, EndOfStreamDuringSeek) {
2623 InSequence s; 2608 InSequence s;
2624 2609
2625 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2610 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2626 2611
2627 AppendCluster(kDefaultFirstCluster()); 2612 AppendCluster(kDefaultFirstCluster());
2628 2613
2629 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(0); 2614 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(0);
2630 demuxer_->StartWaitingForSeek(seek_time); 2615 demuxer_->StartWaitingForSeek(seek_time);
2631 2616
2632 AppendCluster(kDefaultSecondCluster()); 2617 AppendCluster(kDefaultSecondCluster());
2633 EXPECT_CALL(host_, SetDuration( 2618 EXPECT_CALL(host_, SetDuration(
2634 base::TimeDelta::FromMilliseconds(kDefaultSecondClusterEndTimestamp))); 2619 base::TimeDelta::FromMilliseconds(kDefaultSecondClusterEndTimestamp)));
2635 MarkEndOfStream(PIPELINE_OK); 2620 MarkEndOfStream(PIPELINE_OK);
2636 2621
2637 demuxer_->Seek(seek_time, NewExpectedStatusCB(PIPELINE_OK)); 2622 demuxer_->Seek(seek_time, NewExpectedStatusCB(PIPELINE_OK));
2638 2623
2639 GenerateExpectedReads(0, 4); 2624 GenerateExpectedReads(0, 4);
2640 GenerateExpectedReads(46, 66, 5); 2625 GenerateExpectedReads(46, 66, 5);
2641 2626
2642 EndOfStreamHelper end_of_stream_helper(demuxer_.get()); 2627 EndOfStreamHelper end_of_stream_helper(demuxer_.get());
2643 end_of_stream_helper.RequestReads(); 2628 end_of_stream_helper.RequestReads();
2644 end_of_stream_helper.CheckIfReadDonesWereCalled(true); 2629 end_of_stream_helper.CheckIfReadDonesWereCalled(true);
2645 } 2630 }
2646 2631
2647 TEST_P(ChunkDemuxerTest, ConfigChange_Video) { 2632 TEST_F(ChunkDemuxerTest, ConfigChange_Video) {
2648 InSequence s; 2633 InSequence s;
2649 2634
2650 ASSERT_TRUE(InitDemuxerWithConfigChangeData()); 2635 ASSERT_TRUE(InitDemuxerWithConfigChangeData());
2651 2636
2652 DemuxerStream::Status status; 2637 DemuxerStream::Status status;
2653 base::TimeDelta last_timestamp; 2638 base::TimeDelta last_timestamp;
2654 2639
2655 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); 2640 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO);
2656 2641
2657 // Fetch initial video config and verify it matches what we expect. 2642 // Fetch initial video config and verify it matches what we expect.
(...skipping 26 matching lines...) Expand all
2684 ASSERT_TRUE(video_config_1.Matches(video->video_decoder_config())); 2669 ASSERT_TRUE(video_config_1.Matches(video->video_decoder_config()));
2685 2670
2686 ExpectRead(DemuxerStream::VIDEO, 801); 2671 ExpectRead(DemuxerStream::VIDEO, 801);
2687 2672
2688 // Read until the end of the stream just to make sure there aren't any other 2673 // Read until the end of the stream just to make sure there aren't any other
2689 // config changes. 2674 // config changes.
2690 ReadUntilNotOkOrEndOfStream(DemuxerStream::VIDEO, &status, &last_timestamp); 2675 ReadUntilNotOkOrEndOfStream(DemuxerStream::VIDEO, &status, &last_timestamp);
2691 ASSERT_EQ(status, DemuxerStream::kOk); 2676 ASSERT_EQ(status, DemuxerStream::kOk);
2692 } 2677 }
2693 2678
2694 TEST_P(ChunkDemuxerTest, ConfigChange_Audio) { 2679 TEST_F(ChunkDemuxerTest, ConfigChange_Audio) {
2695 InSequence s; 2680 InSequence s;
2696 2681
2697 ASSERT_TRUE(InitDemuxerWithConfigChangeData()); 2682 ASSERT_TRUE(InitDemuxerWithConfigChangeData());
2698 2683
2699 DemuxerStream::Status status; 2684 DemuxerStream::Status status;
2700 base::TimeDelta last_timestamp; 2685 base::TimeDelta last_timestamp;
2701 2686
2702 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); 2687 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO);
2703 2688
2704 // Fetch initial audio config and verify it matches what we expect. 2689 // Fetch initial audio config and verify it matches what we expect.
(...skipping 23 matching lines...) Expand all
2728 EXPECT_EQ(last_timestamp.InMilliseconds(), 782); 2713 EXPECT_EQ(last_timestamp.InMilliseconds(), 782);
2729 ASSERT_TRUE(audio_config_1.Matches(audio->audio_decoder_config())); 2714 ASSERT_TRUE(audio_config_1.Matches(audio->audio_decoder_config()));
2730 2715
2731 // Read until the end of the stream just to make sure there aren't any other 2716 // Read until the end of the stream just to make sure there aren't any other
2732 // config changes. 2717 // config changes.
2733 ReadUntilNotOkOrEndOfStream(DemuxerStream::AUDIO, &status, &last_timestamp); 2718 ReadUntilNotOkOrEndOfStream(DemuxerStream::AUDIO, &status, &last_timestamp);
2734 ASSERT_EQ(status, DemuxerStream::kOk); 2719 ASSERT_EQ(status, DemuxerStream::kOk);
2735 EXPECT_EQ(last_timestamp.InMilliseconds(), 2744); 2720 EXPECT_EQ(last_timestamp.InMilliseconds(), 2744);
2736 } 2721 }
2737 2722
2738 TEST_P(ChunkDemuxerTest, ConfigChange_Seek) { 2723 TEST_F(ChunkDemuxerTest, ConfigChange_Seek) {
2739 InSequence s; 2724 InSequence s;
2740 2725
2741 ASSERT_TRUE(InitDemuxerWithConfigChangeData()); 2726 ASSERT_TRUE(InitDemuxerWithConfigChangeData());
2742 2727
2743 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); 2728 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO);
2744 2729
2745 // Fetch initial video config and verify it matches what we expect. 2730 // Fetch initial video config and verify it matches what we expect.
2746 const VideoDecoderConfig& video_config_1 = video->video_decoder_config(); 2731 const VideoDecoderConfig& video_config_1 = video->video_decoder_config();
2747 ASSERT_TRUE(video_config_1.IsValidConfig()); 2732 ASSERT_TRUE(video_config_1.IsValidConfig());
2748 EXPECT_EQ(video_config_1.natural_size().width(), 320); 2733 EXPECT_EQ(video_config_1.natural_size().width(), 320);
(...skipping 26 matching lines...) Expand all
2775 // seek to a new location that has the same configuration as 2760 // seek to a new location that has the same configuration as
2776 // the start of the file without a Read() in the middle. 2761 // the start of the file without a Read() in the middle.
2777 Seek(base::TimeDelta::FromMilliseconds(527)); 2762 Seek(base::TimeDelta::FromMilliseconds(527));
2778 Seek(base::TimeDelta::FromMilliseconds(801)); 2763 Seek(base::TimeDelta::FromMilliseconds(801));
2779 2764
2780 // Verify that no config change is signalled. 2765 // Verify that no config change is signalled.
2781 ExpectRead(DemuxerStream::VIDEO, 801); 2766 ExpectRead(DemuxerStream::VIDEO, 801);
2782 ASSERT_TRUE(video_config_1.Matches(video->video_decoder_config())); 2767 ASSERT_TRUE(video_config_1.Matches(video->video_decoder_config()));
2783 } 2768 }
2784 2769
2785 TEST_P(ChunkDemuxerTest, TimestampPositiveOffset) { 2770 TEST_F(ChunkDemuxerTest, TimestampPositiveOffset) {
2786 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2771 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2787 2772
2788 ASSERT_TRUE(SetTimestampOffset(kSourceId, base::TimeDelta::FromSeconds(30))); 2773 ASSERT_TRUE(SetTimestampOffset(kSourceId, base::TimeDelta::FromSeconds(30)));
2789 AppendCluster(GenerateCluster(0, 2)); 2774 AppendCluster(GenerateCluster(0, 2));
2790 2775
2791 Seek(base::TimeDelta::FromMilliseconds(30000)); 2776 Seek(base::TimeDelta::FromMilliseconds(30000));
2792 2777
2793 GenerateExpectedReads(30000, 2); 2778 GenerateExpectedReads(30000, 2);
2794 } 2779 }
2795 2780
2796 TEST_P(ChunkDemuxerTest, TimestampNegativeOffset) { 2781 TEST_F(ChunkDemuxerTest, TimestampNegativeOffset) {
2797 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2782 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2798 2783
2799 ASSERT_TRUE(SetTimestampOffset(kSourceId, base::TimeDelta::FromSeconds(-1))); 2784 ASSERT_TRUE(SetTimestampOffset(kSourceId, base::TimeDelta::FromSeconds(-1)));
2800 AppendCluster(GenerateCluster(1000, 2)); 2785 AppendCluster(GenerateCluster(1000, 2));
2801 2786
2802 GenerateExpectedReads(0, 2); 2787 GenerateExpectedReads(0, 2);
2803 } 2788 }
2804 2789
2805 TEST_P(ChunkDemuxerTest, TimestampOffsetSeparateStreams) { 2790 TEST_F(ChunkDemuxerTest, TimestampOffsetSeparateStreams) {
2806 std::string audio_id = "audio1"; 2791 std::string audio_id = "audio1";
2807 std::string video_id = "video1"; 2792 std::string video_id = "video1";
2808 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id)); 2793 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id));
2809 2794
2810 ASSERT_TRUE(SetTimestampOffset( 2795 ASSERT_TRUE(SetTimestampOffset(
2811 audio_id, base::TimeDelta::FromMilliseconds(-2500))); 2796 audio_id, base::TimeDelta::FromMilliseconds(-2500)));
2812 ASSERT_TRUE(SetTimestampOffset( 2797 ASSERT_TRUE(SetTimestampOffset(
2813 video_id, base::TimeDelta::FromMilliseconds(-2500))); 2798 video_id, base::TimeDelta::FromMilliseconds(-2500)));
2814 AppendCluster(audio_id, GenerateSingleStreamCluster(2500, 2799 AppendCluster(audio_id, GenerateSingleStreamCluster(2500,
2815 2500 + kAudioBlockDuration * 4, kAudioTrackNum, kAudioBlockDuration)); 2800 2500 + kAudioBlockDuration * 4, kAudioTrackNum, kAudioBlockDuration));
2816 AppendCluster(video_id, GenerateSingleStreamCluster(2500, 2801 AppendCluster(video_id, GenerateSingleStreamCluster(2500,
2817 2500 + kVideoBlockDuration * 4, kVideoTrackNum, kVideoBlockDuration)); 2802 2500 + kVideoBlockDuration * 4, kVideoTrackNum, kVideoBlockDuration));
2818 GenerateAudioStreamExpectedReads(0, 4); 2803 GenerateAudioStreamExpectedReads(0, 4);
2819 GenerateVideoStreamExpectedReads(0, 4); 2804 GenerateVideoStreamExpectedReads(0, 4);
2820 2805
2821 Seek(base::TimeDelta::FromMilliseconds(27300)); 2806 Seek(base::TimeDelta::FromMilliseconds(27300));
2822 2807
2823 ASSERT_TRUE(SetTimestampOffset( 2808 ASSERT_TRUE(SetTimestampOffset(
2824 audio_id, base::TimeDelta::FromMilliseconds(27300))); 2809 audio_id, base::TimeDelta::FromMilliseconds(27300)));
2825 ASSERT_TRUE(SetTimestampOffset( 2810 ASSERT_TRUE(SetTimestampOffset(
2826 video_id, base::TimeDelta::FromMilliseconds(27300))); 2811 video_id, base::TimeDelta::FromMilliseconds(27300)));
2827 AppendCluster(audio_id, GenerateSingleStreamCluster( 2812 AppendCluster(audio_id, GenerateSingleStreamCluster(
2828 0, kAudioBlockDuration * 4, kAudioTrackNum, kAudioBlockDuration)); 2813 0, kAudioBlockDuration * 4, kAudioTrackNum, kAudioBlockDuration));
2829 AppendCluster(video_id, GenerateSingleStreamCluster( 2814 AppendCluster(video_id, GenerateSingleStreamCluster(
2830 0, kVideoBlockDuration * 4, kVideoTrackNum, kVideoBlockDuration)); 2815 0, kVideoBlockDuration * 4, kVideoTrackNum, kVideoBlockDuration));
2831 GenerateVideoStreamExpectedReads(27300, 4); 2816 GenerateVideoStreamExpectedReads(27300, 4);
2832 GenerateAudioStreamExpectedReads(27300, 4); 2817 GenerateAudioStreamExpectedReads(27300, 4);
2833 } 2818 }
2834 2819
2835 TEST_P(ChunkDemuxerTest, IsParsingMediaSegmentMidMediaSegment) { 2820 TEST_F(ChunkDemuxerTest, IsParsingMediaSegmentMidMediaSegment) {
2836 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2821 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2837 2822
2838 scoped_ptr<Cluster> cluster = GenerateCluster(0, 2); 2823 scoped_ptr<Cluster> cluster = GenerateCluster(0, 2);
2839 // Append only part of the cluster data. 2824 // Append only part of the cluster data.
2840 AppendData(cluster->data(), cluster->size() - 13); 2825 AppendData(cluster->data(), cluster->size() - 13);
2841 2826
2842 // Confirm we're in the middle of parsing a media segment. 2827 // Confirm we're in the middle of parsing a media segment.
2843 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId)); 2828 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId));
2844 2829
2845 demuxer_->Abort(kSourceId, 2830 demuxer_->Abort(kSourceId,
2846 append_window_start_for_next_append_, 2831 append_window_start_for_next_append_,
2847 append_window_end_for_next_append_, 2832 append_window_end_for_next_append_,
2848 &timestamp_offset_map_[kSourceId]); 2833 &timestamp_offset_map_[kSourceId]);
2849 2834
2850 // After Abort(), parsing should no longer be in the middle of a media 2835 // After Abort(), parsing should no longer be in the middle of a media
2851 // segment. 2836 // segment.
2852 ASSERT_FALSE(demuxer_->IsParsingMediaSegment(kSourceId)); 2837 ASSERT_FALSE(demuxer_->IsParsingMediaSegment(kSourceId));
2853 } 2838 }
2854 2839
2855 #if defined(USE_PROPRIETARY_CODECS) 2840 #if defined(USE_PROPRIETARY_CODECS)
2856 #if defined(ENABLE_MPEG2TS_STREAM_PARSER) 2841 #if defined(ENABLE_MPEG2TS_STREAM_PARSER)
2857 TEST_P(ChunkDemuxerTest, EmitBuffersDuringAbort) { 2842 TEST_F(ChunkDemuxerTest, EmitBuffersDuringAbort) {
2858 EXPECT_CALL(*this, DemuxerOpened()); 2843 EXPECT_CALL(*this, DemuxerOpened());
2859 demuxer_->Initialize( 2844 demuxer_->Initialize(
2860 &host_, CreateInitDoneCB(kInfiniteDuration(), PIPELINE_OK), true); 2845 &host_, CreateInitDoneCB(kInfiniteDuration(), PIPELINE_OK), true);
2861 EXPECT_EQ(ChunkDemuxer::kOk, AddIdForMp2tSource(kSourceId)); 2846 EXPECT_EQ(ChunkDemuxer::kOk, AddIdForMp2tSource(kSourceId));
2862 2847
2863 // For info: 2848 // For info:
2864 // DTS/PTS derived using dvbsnoop -s ts -if bear-1280x720.ts -tssubdecode 2849 // DTS/PTS derived using dvbsnoop -s ts -if bear-1280x720.ts -tssubdecode
2865 // Video: first PES: 2850 // Video: first PES:
2866 // PTS: 126912 (0x0001efc0) [= 90 kHz-Timestamp: 0:00:01.4101] 2851 // PTS: 126912 (0x0001efc0) [= 90 kHz-Timestamp: 0:00:01.4101]
2867 // DTS: 123909 (0x0001e405) [= 90 kHz-Timestamp: 0:00:01.3767] 2852 // DTS: 123909 (0x0001e405) [= 90 kHz-Timestamp: 0:00:01.3767]
(...skipping 24 matching lines...) Expand all
2892 demuxer_->GetBufferedRanges(kSourceId); 2877 demuxer_->GetBufferedRanges(kSourceId);
2893 2878
2894 ASSERT_EQ(range_before_abort.size(), 1u); 2879 ASSERT_EQ(range_before_abort.size(), 1u);
2895 ASSERT_EQ(range_after_abort.size(), 1u); 2880 ASSERT_EQ(range_after_abort.size(), 1u);
2896 EXPECT_EQ(range_after_abort.start(0), range_before_abort.start(0)); 2881 EXPECT_EQ(range_after_abort.start(0), range_before_abort.start(0));
2897 EXPECT_GT(range_after_abort.end(0), range_before_abort.end(0)); 2882 EXPECT_GT(range_after_abort.end(0), range_before_abort.end(0));
2898 } 2883 }
2899 #endif 2884 #endif
2900 #endif 2885 #endif
2901 2886
2902 TEST_P(ChunkDemuxerTest, WebMIsParsingMediaSegmentDetection) { 2887 TEST_F(ChunkDemuxerTest, WebMIsParsingMediaSegmentDetection) {
2903 const uint8 kBuffer[] = { 2888 const uint8 kBuffer[] = {
2904 0x1F, 0x43, 0xB6, 0x75, 0x83, // CLUSTER (size = 3) 2889 0x1F, 0x43, 0xB6, 0x75, 0x83, // CLUSTER (size = 3)
2905 0xE7, 0x81, 0x01, // Cluster TIMECODE (value = 1) 2890 0xE7, 0x81, 0x01, // Cluster TIMECODE (value = 1)
2906 2891
2907 0x1F, 0x43, 0xB6, 0x75, 0xFF, // CLUSTER (size = unknown; really 3 due to:) 2892 0x1F, 0x43, 0xB6, 0x75, 0xFF, // CLUSTER (size = unknown; really 3 due to:)
2908 0xE7, 0x81, 0x02, // Cluster TIMECODE (value = 2) 2893 0xE7, 0x81, 0x02, // Cluster TIMECODE (value = 2)
2909 /* e.g. put some blocks here... */ 2894 /* e.g. put some blocks here... */
2910 0x1A, 0x45, 0xDF, 0xA3, 0x8A, // EBMLHEADER (size = 10, not fully appended) 2895 0x1A, 0x45, 0xDF, 0xA3, 0x8A, // EBMLHEADER (size = 10, not fully appended)
2911 }; 2896 };
2912 2897
(...skipping 17 matching lines...) Expand all
2930 2915
2931 for (size_t i = 0; i < sizeof(kBuffer); i++) { 2916 for (size_t i = 0; i < sizeof(kBuffer); i++) {
2932 DVLOG(3) << "Appending and testing index " << i; 2917 DVLOG(3) << "Appending and testing index " << i;
2933 AppendData(kBuffer + i, 1); 2918 AppendData(kBuffer + i, 1);
2934 bool expected_return_value = kExpectedReturnValues[i]; 2919 bool expected_return_value = kExpectedReturnValues[i];
2935 EXPECT_EQ(expected_return_value, 2920 EXPECT_EQ(expected_return_value,
2936 demuxer_->IsParsingMediaSegment(kSourceId)); 2921 demuxer_->IsParsingMediaSegment(kSourceId));
2937 } 2922 }
2938 } 2923 }
2939 2924
2940 TEST_P(ChunkDemuxerTest, DurationChange) { 2925 TEST_F(ChunkDemuxerTest, DurationChange) {
2941 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2926 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2942 const int kStreamDuration = kDefaultDuration().InMilliseconds(); 2927 const int kStreamDuration = kDefaultDuration().InMilliseconds();
2943 2928
2944 // Add data leading up to the currently set duration. 2929 // Add data leading up to the currently set duration.
2945 AppendCluster(GenerateCluster(kStreamDuration - kAudioBlockDuration, 2930 AppendCluster(GenerateCluster(kStreamDuration - kAudioBlockDuration,
2946 kStreamDuration - kVideoBlockDuration, 2931 kStreamDuration - kVideoBlockDuration,
2947 2)); 2932 2));
2948 2933
2949 CheckExpectedRanges(kSourceId, "{ [201191,201224) }"); 2934 CheckExpectedRanges(kSourceId, "{ [201191,201224) }");
2950 2935
2951 // Add data beginning at the currently set duration and expect a new duration 2936 // Add data beginning at the currently set duration and expect a new duration
2952 // to be signaled. Note that the last video block will have a higher end 2937 // to be signaled. Note that the last video block will have a higher end
2953 // timestamp than the last audio block. 2938 // timestamp than the last audio block.
2954 if (use_legacy_frame_processor_) {
2955 const int kNewStreamDurationAudio = kStreamDuration + kAudioBlockDuration;
2956 EXPECT_CALL(host_, SetDuration(
2957 base::TimeDelta::FromMilliseconds(kNewStreamDurationAudio)));
2958 }
2959 const int kNewStreamDurationVideo = kStreamDuration + kVideoBlockDuration; 2939 const int kNewStreamDurationVideo = kStreamDuration + kVideoBlockDuration;
2960 EXPECT_CALL(host_, SetDuration( 2940 EXPECT_CALL(host_, SetDuration(
2961 base::TimeDelta::FromMilliseconds(kNewStreamDurationVideo))); 2941 base::TimeDelta::FromMilliseconds(kNewStreamDurationVideo)));
2962 AppendCluster(GenerateCluster(kDefaultDuration().InMilliseconds(), 2)); 2942 AppendCluster(GenerateCluster(kDefaultDuration().InMilliseconds(), 2));
2963 2943
2964 CheckExpectedRanges(kSourceId, "{ [201191,201247) }"); 2944 CheckExpectedRanges(kSourceId, "{ [201191,201247) }");
2965 2945
2966 // Add more data to the end of each media type. Note that the last audio block 2946 // Add more data to the end of each media type. Note that the last audio block
2967 // will have a higher end timestamp than the last video block. 2947 // will have a higher end timestamp than the last video block.
2968 const int kFinalStreamDuration = kStreamDuration + kAudioBlockDuration * 3; 2948 const int kFinalStreamDuration = kStreamDuration + kAudioBlockDuration * 3;
2969 EXPECT_CALL(host_, SetDuration( 2949 EXPECT_CALL(host_, SetDuration(
2970 base::TimeDelta::FromMilliseconds(kFinalStreamDuration))); 2950 base::TimeDelta::FromMilliseconds(kFinalStreamDuration)));
2971 AppendCluster(GenerateCluster(kStreamDuration + kAudioBlockDuration, 2951 AppendCluster(GenerateCluster(kStreamDuration + kAudioBlockDuration,
2972 kStreamDuration + kVideoBlockDuration, 2952 kStreamDuration + kVideoBlockDuration,
2973 3)); 2953 3));
2974 2954
2975 // See that the range has increased appropriately (but not to the full 2955 // See that the range has increased appropriately (but not to the full
2976 // duration of 201293, since there is not enough video appended for that). 2956 // duration of 201293, since there is not enough video appended for that).
2977 CheckExpectedRanges(kSourceId, "{ [201191,201290) }"); 2957 CheckExpectedRanges(kSourceId, "{ [201191,201290) }");
2978 } 2958 }
2979 2959
2980 TEST_P(ChunkDemuxerTest, DurationChangeTimestampOffset) { 2960 TEST_F(ChunkDemuxerTest, DurationChangeTimestampOffset) {
2981 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2961 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2982
2983 ASSERT_TRUE(SetTimestampOffset(kSourceId, kDefaultDuration())); 2962 ASSERT_TRUE(SetTimestampOffset(kSourceId, kDefaultDuration()));
2984
2985 if (use_legacy_frame_processor_) {
2986 EXPECT_CALL(host_, SetDuration(
2987 kDefaultDuration() + base::TimeDelta::FromMilliseconds(
2988 kAudioBlockDuration * 2)));
2989 }
2990 EXPECT_CALL(host_, SetDuration( 2963 EXPECT_CALL(host_, SetDuration(
2991 kDefaultDuration() + base::TimeDelta::FromMilliseconds( 2964 kDefaultDuration() + base::TimeDelta::FromMilliseconds(
2992 kVideoBlockDuration * 2))); 2965 kVideoBlockDuration * 2)));
2993 AppendCluster(GenerateCluster(0, 4)); 2966 AppendCluster(GenerateCluster(0, 4));
2994 } 2967 }
2995 2968
2996 TEST_P(ChunkDemuxerTest, EndOfStreamTruncateDuration) { 2969 TEST_F(ChunkDemuxerTest, EndOfStreamTruncateDuration) {
2997 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2970 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2998 2971
2999 AppendCluster(kDefaultFirstCluster()); 2972 AppendCluster(kDefaultFirstCluster());
3000 2973
3001 EXPECT_CALL(host_, SetDuration( 2974 EXPECT_CALL(host_, SetDuration(
3002 base::TimeDelta::FromMilliseconds(kDefaultFirstClusterEndTimestamp))); 2975 base::TimeDelta::FromMilliseconds(kDefaultFirstClusterEndTimestamp)));
3003 MarkEndOfStream(PIPELINE_OK); 2976 MarkEndOfStream(PIPELINE_OK);
3004 } 2977 }
3005 2978
3006 2979
3007 TEST_P(ChunkDemuxerTest, ZeroLengthAppend) { 2980 TEST_F(ChunkDemuxerTest, ZeroLengthAppend) {
3008 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2981 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3009 AppendData(NULL, 0); 2982 AppendData(NULL, 0);
3010 } 2983 }
3011 2984
3012 TEST_P(ChunkDemuxerTest, AppendAfterEndOfStream) { 2985 TEST_F(ChunkDemuxerTest, AppendAfterEndOfStream) {
3013 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2986 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3014 2987
3015 EXPECT_CALL(host_, SetDuration(_)) 2988 EXPECT_CALL(host_, SetDuration(_))
3016 .Times(AnyNumber()); 2989 .Times(AnyNumber());
3017 2990
3018 AppendCluster(kDefaultFirstCluster()); 2991 AppendCluster(kDefaultFirstCluster());
3019 MarkEndOfStream(PIPELINE_OK); 2992 MarkEndOfStream(PIPELINE_OK);
3020 2993
3021 demuxer_->UnmarkEndOfStream(); 2994 demuxer_->UnmarkEndOfStream();
3022 2995
3023 AppendCluster(kDefaultSecondCluster()); 2996 AppendCluster(kDefaultSecondCluster());
3024 MarkEndOfStream(PIPELINE_OK); 2997 MarkEndOfStream(PIPELINE_OK);
3025 } 2998 }
3026 2999
3027 // Test receiving a Shutdown() call before we get an Initialize() 3000 // Test receiving a Shutdown() call before we get an Initialize()
3028 // call. This can happen if video element gets destroyed before 3001 // call. This can happen if video element gets destroyed before
3029 // the pipeline has a chance to initialize the demuxer. 3002 // the pipeline has a chance to initialize the demuxer.
3030 TEST_P(ChunkDemuxerTest, Shutdown_BeforeInitialize) { 3003 TEST_F(ChunkDemuxerTest, Shutdown_BeforeInitialize) {
3031 demuxer_->Shutdown(); 3004 demuxer_->Shutdown();
3032 demuxer_->Initialize( 3005 demuxer_->Initialize(
3033 &host_, CreateInitDoneCB(DEMUXER_ERROR_COULD_NOT_OPEN), true); 3006 &host_, CreateInitDoneCB(DEMUXER_ERROR_COULD_NOT_OPEN), true);
3034 message_loop_.RunUntilIdle(); 3007 message_loop_.RunUntilIdle();
3035 } 3008 }
3036 3009
3037 // Verifies that signaling end of stream while stalled at a gap 3010 // Verifies that signaling end of stream while stalled at a gap
3038 // boundary does not trigger end of stream buffers to be returned. 3011 // boundary does not trigger end of stream buffers to be returned.
3039 TEST_P(ChunkDemuxerTest, EndOfStreamWhileWaitingForGapToBeFilled) { 3012 TEST_F(ChunkDemuxerTest, EndOfStreamWhileWaitingForGapToBeFilled) {
3040 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 3013 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3041 3014
3042 AppendCluster(0, 10); 3015 AppendCluster(0, 10);
3043 AppendCluster(300, 10); 3016 AppendCluster(300, 10);
3044 CheckExpectedRanges(kSourceId, "{ [0,132) [300,432) }"); 3017 CheckExpectedRanges(kSourceId, "{ [0,132) [300,432) }");
3045 3018
3046 GenerateExpectedReads(0, 10); 3019 GenerateExpectedReads(0, 10);
3047 3020
3048 bool audio_read_done = false; 3021 bool audio_read_done = false;
3049 bool video_read_done = false; 3022 bool video_read_done = false;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
3092 EXPECT_FALSE(audio_read_done); 3065 EXPECT_FALSE(audio_read_done);
3093 EXPECT_FALSE(video_read_done); 3066 EXPECT_FALSE(video_read_done);
3094 3067
3095 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(437))); 3068 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(437)));
3096 MarkEndOfStream(PIPELINE_OK); 3069 MarkEndOfStream(PIPELINE_OK);
3097 3070
3098 EXPECT_TRUE(audio_read_done); 3071 EXPECT_TRUE(audio_read_done);
3099 EXPECT_TRUE(video_read_done); 3072 EXPECT_TRUE(video_read_done);
3100 } 3073 }
3101 3074
3102 TEST_P(ChunkDemuxerTest, CanceledSeekDuringInitialPreroll) { 3075 TEST_F(ChunkDemuxerTest, CanceledSeekDuringInitialPreroll) {
3103 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 3076 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3104 3077
3105 // Cancel preroll. 3078 // Cancel preroll.
3106 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(200); 3079 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(200);
3107 demuxer_->CancelPendingSeek(seek_time); 3080 demuxer_->CancelPendingSeek(seek_time);
3108 3081
3109 // Initiate the seek to the new location. 3082 // Initiate the seek to the new location.
3110 Seek(seek_time); 3083 Seek(seek_time);
3111 3084
3112 // Append data to satisfy the seek. 3085 // Append data to satisfy the seek.
3113 AppendCluster(seek_time.InMilliseconds(), 10); 3086 AppendCluster(seek_time.InMilliseconds(), 10);
3114 } 3087 }
3115 3088
3116 TEST_P(ChunkDemuxerTest, GCDuringSeek) { 3089 TEST_F(ChunkDemuxerTest, GCDuringSeek) {
3117 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3090 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3118 3091
3119 demuxer_->SetMemoryLimitsForTesting(5 * kBlockSize); 3092 demuxer_->SetMemoryLimitsForTesting(5 * kBlockSize);
3120 3093
3121 base::TimeDelta seek_time1 = base::TimeDelta::FromMilliseconds(1000); 3094 base::TimeDelta seek_time1 = base::TimeDelta::FromMilliseconds(1000);
3122 base::TimeDelta seek_time2 = base::TimeDelta::FromMilliseconds(500); 3095 base::TimeDelta seek_time2 = base::TimeDelta::FromMilliseconds(500);
3123 3096
3124 // Initiate a seek to |seek_time1|. 3097 // Initiate a seek to |seek_time1|.
3125 Seek(seek_time1); 3098 Seek(seek_time1);
3126 3099
(...skipping 22 matching lines...) Expand all
3149 // Append more data and make sure that the blocks for |seek_time2| 3122 // Append more data and make sure that the blocks for |seek_time2|
3150 // don't get removed. 3123 // don't get removed.
3151 // 3124 //
3152 // NOTE: The current GC algorithm tries to preserve the GOP at the 3125 // NOTE: The current GC algorithm tries to preserve the GOP at the
3153 // current position as well as the last appended GOP. This is 3126 // current position as well as the last appended GOP. This is
3154 // why there are 2 ranges in the expectations. 3127 // why there are 2 ranges in the expectations.
3155 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 700, 5); 3128 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 700, 5);
3156 CheckExpectedRanges(kSourceId, "{ [500,592) [792,815) }"); 3129 CheckExpectedRanges(kSourceId, "{ [500,592) [792,815) }");
3157 } 3130 }
3158 3131
3159 TEST_P(ChunkDemuxerTest, AppendWindow_Video) { 3132 TEST_F(ChunkDemuxerTest, AppendWindow_Video) {
3160 ASSERT_TRUE(InitDemuxer(HAS_VIDEO)); 3133 ASSERT_TRUE(InitDemuxer(HAS_VIDEO));
3161 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); 3134 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO);
3162 3135
3163 // Set the append window to [50,280). 3136 // Set the append window to [50,280).
3164 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50); 3137 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50);
3165 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); 3138 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280);
3166 3139
3167 // Append a cluster that starts before and ends after the append window. 3140 // Append a cluster that starts before and ends after the append window.
3168 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 3141 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
3169 "0K 30 60 90 120K 150 180 210 240K 270 300 330K"); 3142 "0K 30 60 90 120K 150 180 210 240K 270 300 330K");
3170 3143
3171 // Verify that GOPs that start outside the window are not included 3144 // Verify that GOPs that start outside the window are not included
3172 // in the buffer. Also verify that buffers that start inside the 3145 // in the buffer. Also verify that buffers that start inside the
3173 // window and extend beyond the end of the window are not included. 3146 // window and extend beyond the end of the window are not included.
3174 CheckExpectedRanges(kSourceId, "{ [120,270) }"); 3147 CheckExpectedRanges(kSourceId, "{ [120,270) }");
3175 CheckExpectedBuffers(stream, "120 150 180 210 240"); 3148 CheckExpectedBuffers(stream, "120 150 180 210 240");
3176 3149
3177 // Extend the append window to [50,650). 3150 // Extend the append window to [50,650).
3178 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); 3151 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650);
3179 3152
3180 // Append more data and verify that adding buffers start at the next 3153 // Append more data and verify that adding buffers start at the next
3181 // keyframe. 3154 // keyframe.
3182 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 3155 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
3183 "360 390 420K 450 480 510 540K 570 600 630K"); 3156 "360 390 420K 450 480 510 540K 570 600 630K");
3184 CheckExpectedRanges(kSourceId, "{ [120,270) [420,630) }"); 3157 CheckExpectedRanges(kSourceId, "{ [120,270) [420,630) }");
3185 } 3158 }
3186 3159
3187 TEST_P(ChunkDemuxerTest, AppendWindow_Audio) { 3160 TEST_F(ChunkDemuxerTest, AppendWindow_Audio) {
3188 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3161 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3189 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); 3162 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO);
3190 3163
3191 // Set the append window to [50,280). 3164 // Set the append window to [50,280).
3192 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50); 3165 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50);
3193 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); 3166 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280);
3194 3167
3195 // Append a cluster that starts before and ends after the append window. 3168 // Append a cluster that starts before and ends after the append window.
3196 AppendSingleStreamCluster( 3169 AppendSingleStreamCluster(
3197 kSourceId, kAudioTrackNum, 3170 kSourceId, kAudioTrackNum,
(...skipping 14 matching lines...) Expand all
3212 // Extend the append window to [50,650). 3185 // Extend the append window to [50,650).
3213 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); 3186 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650);
3214 3187
3215 // Append more data and verify that a new range is created. 3188 // Append more data and verify that a new range is created.
3216 AppendSingleStreamCluster( 3189 AppendSingleStreamCluster(
3217 kSourceId, kAudioTrackNum, 3190 kSourceId, kAudioTrackNum,
3218 "360K 390K 420K 450K 480K 510K 540K 570K 600K 630K"); 3191 "360K 390K 420K 450K 480K 510K 540K 570K 600K 630K");
3219 CheckExpectedRanges(kSourceId, "{ [50,270) [360,630) }"); 3192 CheckExpectedRanges(kSourceId, "{ [50,270) [360,630) }");
3220 } 3193 }
3221 3194
3222 TEST_P(ChunkDemuxerTest, AppendWindow_AudioOverlapStartAndEnd) { 3195 TEST_F(ChunkDemuxerTest, AppendWindow_AudioOverlapStartAndEnd) {
3223 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3196 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3224 3197
3225 // Set the append window to [10,20). 3198 // Set the append window to [10,20).
3226 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(10); 3199 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(10);
3227 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(20); 3200 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(20);
3228 3201
3229 // Append a cluster that starts before and ends after the append window. 3202 // Append a cluster that starts before and ends after the append window.
3230 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K"); 3203 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K");
3231 3204
3232 // Verify that everything is dropped in this case. No partial append should 3205 // Verify that everything is dropped in this case. No partial append should
3233 // be generated. 3206 // be generated.
3234 CheckExpectedRanges(kSourceId, "{ }"); 3207 CheckExpectedRanges(kSourceId, "{ }");
3235 } 3208 }
3236 3209
3237 TEST_P(ChunkDemuxerTest, AppendWindow_WebMFile_AudioOnly) { 3210 TEST_F(ChunkDemuxerTest, AppendWindow_WebMFile_AudioOnly) {
3238 EXPECT_CALL(*this, DemuxerOpened()); 3211 EXPECT_CALL(*this, DemuxerOpened());
3239 demuxer_->Initialize( 3212 demuxer_->Initialize(
3240 &host_, 3213 &host_,
3241 CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), PIPELINE_OK), 3214 CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), PIPELINE_OK),
3242 true); 3215 true);
3243 ASSERT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO)); 3216 ASSERT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO));
3244 3217
3245 // Set the append window to [50,150). 3218 // Set the append window to [50,150).
3246 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50); 3219 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50);
3247 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(150); 3220 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(150);
3248 3221
3249 // Read a WebM file into memory and send the data to the demuxer. The chunk 3222 // Read a WebM file into memory and send the data to the demuxer. The chunk
3250 // size has been chosen carefully to ensure the preroll buffer used by the 3223 // size has been chosen carefully to ensure the preroll buffer used by the
3251 // partial append window trim must come from a previous Append() call. 3224 // partial append window trim must come from a previous Append() call.
3252 scoped_refptr<DecoderBuffer> buffer = 3225 scoped_refptr<DecoderBuffer> buffer =
3253 ReadTestDataFile("bear-320x240-audio-only.webm"); 3226 ReadTestDataFile("bear-320x240-audio-only.webm");
3254 AppendDataInPieces(buffer->data(), buffer->data_size(), 128); 3227 AppendDataInPieces(buffer->data(), buffer->data_size(), 128);
3255 3228
3256 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); 3229 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO);
3257 CheckExpectedBuffers(stream, "50P 50 62 86 109 122 125 128"); 3230 CheckExpectedBuffers(stream, "50P 50 62 86 109 122 125 128");
3258 } 3231 }
3259 3232
3260 TEST_P(ChunkDemuxerTest, AppendWindow_AudioConfigUpdateRemovesPreroll) { 3233 TEST_F(ChunkDemuxerTest, AppendWindow_AudioConfigUpdateRemovesPreroll) {
3261 EXPECT_CALL(*this, DemuxerOpened()); 3234 EXPECT_CALL(*this, DemuxerOpened());
3262 demuxer_->Initialize( 3235 demuxer_->Initialize(
3263 &host_, 3236 &host_,
3264 CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), PIPELINE_OK), 3237 CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), PIPELINE_OK),
3265 true); 3238 true);
3266 ASSERT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO)); 3239 ASSERT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO));
3267 3240
3268 // Set the append window such that the first file is completely before the 3241 // Set the append window such that the first file is completely before the
3269 // append window. 3242 // append window.
3270 // TODO(wolenetz/acolwell): Update this duration once the files are fixed to 3243 // TODO(wolenetz/acolwell): Update this duration once the files are fixed to
(...skipping 19 matching lines...) Expand all
3290 ASSERT_TRUE(SetTimestampOffset(kSourceId, duration_1)); 3263 ASSERT_TRUE(SetTimestampOffset(kSourceId, duration_1));
3291 AppendDataInPieces(buffer2->data(), buffer2->data_size(), 512); 3264 AppendDataInPieces(buffer2->data(), buffer2->data_size(), 512);
3292 CheckExpectedRanges(kSourceId, "{ [2746,5519) }"); 3265 CheckExpectedRanges(kSourceId, "{ [2746,5519) }");
3293 3266
3294 Seek(duration_1); 3267 Seek(duration_1);
3295 ExpectConfigChanged(DemuxerStream::AUDIO); 3268 ExpectConfigChanged(DemuxerStream::AUDIO);
3296 ASSERT_FALSE(config_1.Matches(stream->audio_decoder_config())); 3269 ASSERT_FALSE(config_1.Matches(stream->audio_decoder_config()));
3297 CheckExpectedBuffers(stream, "2746 2767 2789 2810"); 3270 CheckExpectedBuffers(stream, "2746 2767 2789 2810");
3298 } 3271 }
3299 3272
3300 TEST_P(ChunkDemuxerTest, AppendWindow_Text) { 3273 TEST_F(ChunkDemuxerTest, AppendWindow_Text) {
3301 DemuxerStream* text_stream = NULL; 3274 DemuxerStream* text_stream = NULL;
3302 EXPECT_CALL(host_, AddTextStream(_, _)) 3275 EXPECT_CALL(host_, AddTextStream(_, _))
3303 .WillOnce(SaveArg<0>(&text_stream)); 3276 .WillOnce(SaveArg<0>(&text_stream));
3304 ASSERT_TRUE(InitDemuxer(HAS_VIDEO | HAS_TEXT)); 3277 ASSERT_TRUE(InitDemuxer(HAS_VIDEO | HAS_TEXT));
3305 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); 3278 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
3306 3279
3307 // Set the append window to [20,280). 3280 // Set the append window to [20,280).
3308 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20); 3281 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20);
3309 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); 3282 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280);
3310 3283
(...skipping 18 matching lines...) Expand all
3329 "360 390 420K 450 480 510 540K 570 600 630K"); 3302 "360 390 420K 450 480 510 540K 570 600 630K");
3330 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "400K 500K 600K 700K"); 3303 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "400K 500K 600K 700K");
3331 CheckExpectedRanges(kSourceId, "{ [120,270) [420,630) }"); 3304 CheckExpectedRanges(kSourceId, "{ [120,270) [420,630) }");
3332 3305
3333 // Seek to the new range and verify that the expected buffers are returned. 3306 // Seek to the new range and verify that the expected buffers are returned.
3334 Seek(base::TimeDelta::FromMilliseconds(420)); 3307 Seek(base::TimeDelta::FromMilliseconds(420));
3335 CheckExpectedBuffers(video_stream, "420 450 480 510 540 570 600"); 3308 CheckExpectedBuffers(video_stream, "420 450 480 510 540 570 600");
3336 CheckExpectedBuffers(text_stream, "400 500"); 3309 CheckExpectedBuffers(text_stream, "400 500");
3337 } 3310 }
3338 3311
3339 TEST_P(ChunkDemuxerTest, StartWaitingForSeekAfterParseError) { 3312 TEST_F(ChunkDemuxerTest, StartWaitingForSeekAfterParseError) {
3340 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 3313 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3341 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); 3314 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE));
3342 AppendGarbage(); 3315 AppendGarbage();
3343 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(50); 3316 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(50);
3344 demuxer_->StartWaitingForSeek(seek_time); 3317 demuxer_->StartWaitingForSeek(seek_time);
3345 } 3318 }
3346 3319
3347 TEST_P(ChunkDemuxerTest, Remove_AudioVideoText) { 3320 TEST_F(ChunkDemuxerTest, Remove_AudioVideoText) {
3348 DemuxerStream* text_stream = NULL; 3321 DemuxerStream* text_stream = NULL;
3349 EXPECT_CALL(host_, AddTextStream(_, _)) 3322 EXPECT_CALL(host_, AddTextStream(_, _))
3350 .WillOnce(SaveArg<0>(&text_stream)); 3323 .WillOnce(SaveArg<0>(&text_stream));
3351 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); 3324 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT));
3352 3325
3353 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); 3326 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO);
3354 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); 3327 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
3355 3328
3356 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 3329 AppendSingleStreamCluster(kSourceId, kAudioTrackNum,
3357 "0K 20K 40K 60K 80K 100K 120K 140K"); 3330 "0K 20K 40K 60K 80K 100K 120K 140K");
(...skipping 19 matching lines...) Expand all
3377 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 3350 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
3378 "1K 31 61 91 121K 151 181"); 3351 "1K 31 61 91 121K 151 181");
3379 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "1K 101K 201K"); 3352 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "1K 101K 201K");
3380 3353
3381 Seek(base::TimeDelta()); 3354 Seek(base::TimeDelta());
3382 CheckExpectedBuffers(audio_stream, "1 21 41 61 81 101 121 141"); 3355 CheckExpectedBuffers(audio_stream, "1 21 41 61 81 101 121 141");
3383 CheckExpectedBuffers(video_stream, "1 31 61 91 121 151 181"); 3356 CheckExpectedBuffers(video_stream, "1 31 61 91 121 151 181");
3384 CheckExpectedBuffers(text_stream, "1 101 201"); 3357 CheckExpectedBuffers(text_stream, "1 101 201");
3385 } 3358 }
3386 3359
3387 TEST_P(ChunkDemuxerTest, Remove_StartAtDuration) { 3360 TEST_F(ChunkDemuxerTest, Remove_StartAtDuration) {
3388 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3361 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3389 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); 3362 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO);
3390 3363
3391 // Set the duration to something small so that the append that 3364 // Set the duration to something small so that the append that
3392 // follows updates the duration to reflect the end of the appended data. 3365 // follows updates the duration to reflect the end of the appended data.
3393 EXPECT_CALL(host_, SetDuration( 3366 EXPECT_CALL(host_, SetDuration(
3394 base::TimeDelta::FromMilliseconds(1))); 3367 base::TimeDelta::FromMilliseconds(1)));
3395 demuxer_->SetDuration(0.001); 3368 demuxer_->SetDuration(0.001);
3396 3369
3397 EXPECT_CALL(host_, SetDuration( 3370 EXPECT_CALL(host_, SetDuration(
3398 base::TimeDelta::FromMilliseconds(160))); 3371 base::TimeDelta::FromMilliseconds(160)));
3399 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 3372 AppendSingleStreamCluster(kSourceId, kAudioTrackNum,
3400 "0K 20K 40K 60K 80K 100K 120K 140K"); 3373 "0K 20K 40K 60K 80K 100K 120K 140K");
3401 3374
3402 CheckExpectedRanges(kSourceId, "{ [0,160) }"); 3375 CheckExpectedRanges(kSourceId, "{ [0,160) }");
3403 CheckExpectedBuffers(audio_stream, "0 20 40 60 80 100 120 140"); 3376 CheckExpectedBuffers(audio_stream, "0 20 40 60 80 100 120 140");
3404 3377
3405 demuxer_->Remove(kSourceId, 3378 demuxer_->Remove(kSourceId,
3406 base::TimeDelta::FromSecondsD(demuxer_->GetDuration()), 3379 base::TimeDelta::FromSecondsD(demuxer_->GetDuration()),
3407 kInfiniteDuration()); 3380 kInfiniteDuration());
3408 3381
3409 Seek(base::TimeDelta()); 3382 Seek(base::TimeDelta());
3410 CheckExpectedRanges(kSourceId, "{ [0,160) }"); 3383 CheckExpectedRanges(kSourceId, "{ [0,160) }");
3411 CheckExpectedBuffers(audio_stream, "0 20 40 60 80 100 120 140"); 3384 CheckExpectedBuffers(audio_stream, "0 20 40 60 80 100 120 140");
3412 } 3385 }
3413 3386
3414 // Verifies that a Seek() will complete without text cues for 3387 // Verifies that a Seek() will complete without text cues for
3415 // the seek point and will return cues after the seek position 3388 // the seek point and will return cues after the seek position
3416 // when they are eventually appended. 3389 // when they are eventually appended.
3417 TEST_P(ChunkDemuxerTest, SeekCompletesWithoutTextCues) { 3390 TEST_F(ChunkDemuxerTest, SeekCompletesWithoutTextCues) {
3418 DemuxerStream* text_stream = NULL; 3391 DemuxerStream* text_stream = NULL;
3419 EXPECT_CALL(host_, AddTextStream(_, _)) 3392 EXPECT_CALL(host_, AddTextStream(_, _))
3420 .WillOnce(SaveArg<0>(&text_stream)); 3393 .WillOnce(SaveArg<0>(&text_stream));
3421 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); 3394 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT));
3422 3395
3423 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); 3396 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO);
3424 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); 3397 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
3425 3398
3426 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(120); 3399 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(120);
3427 bool seek_cb_was_called = false; 3400 bool seek_cb_was_called = false;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3462 3435
3463 // NOTE: we start at 175 here because the buffer at 125 was returned 3436 // NOTE: we start at 175 here because the buffer at 125 was returned
3464 // to the pending read initiated above. 3437 // to the pending read initiated above.
3465 CheckExpectedBuffers(text_stream, "175 225"); 3438 CheckExpectedBuffers(text_stream, "175 225");
3466 3439
3467 // Verify that audio & video streams continue to return expected values. 3440 // Verify that audio & video streams continue to return expected values.
3468 CheckExpectedBuffers(audio_stream, "160 180"); 3441 CheckExpectedBuffers(audio_stream, "160 180");
3469 CheckExpectedBuffers(video_stream, "180 210"); 3442 CheckExpectedBuffers(video_stream, "180 210");
3470 } 3443 }
3471 3444
3472 TEST_P(ChunkDemuxerTest, ClusterWithUnknownSize) { 3445 TEST_F(ChunkDemuxerTest, ClusterWithUnknownSize) {
3473 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 3446 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3474 3447
3475 AppendCluster(GenerateCluster(0, 0, 4, true)); 3448 AppendCluster(GenerateCluster(0, 0, 4, true));
3476 CheckExpectedRanges(kSourceId, "{ [0,46) }"); 3449 CheckExpectedRanges(kSourceId, "{ [0,46) }");
3477 3450
3478 // A new cluster indicates end of the previous cluster with unknown size. 3451 // A new cluster indicates end of the previous cluster with unknown size.
3479 AppendCluster(GenerateCluster(46, 66, 5, true)); 3452 AppendCluster(GenerateCluster(46, 66, 5, true));
3480 CheckExpectedRanges(kSourceId, "{ [0,115) }"); 3453 CheckExpectedRanges(kSourceId, "{ [0,115) }");
3481 } 3454 }
3482 3455
3483 // Generate two sets of tests: one using FrameProcessor, and one using
3484 // LegacyFrameProcessor.
3485 INSTANTIATE_TEST_CASE_P(NewFrameProcessor, ChunkDemuxerTest, Values(false));
3486 INSTANTIATE_TEST_CASE_P(LegacyFrameProcessor, ChunkDemuxerTest, Values(true));
3487
3488 } // namespace media 3456 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/chunk_demuxer.cc ('k') | media/filters/legacy_frame_processor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698