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

Side by Side Diff: media/formats/webm/webm_cluster_parser_unittest.cc

Issue 1310423003: Revert of MSE: Verify MediaLog events created by existing WebM unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include <cstdlib> 6 #include <cstdlib>
7 #include <string>
8 #include <vector> 7 #include <vector>
9 8
10 #include "base/bind.h" 9 #include "base/bind.h"
11 #include "base/logging.h" 10 #include "base/logging.h"
12 #include "base/strings/string_number_conversions.h"
13 #include "media/base/audio_decoder_config.h" 11 #include "media/base/audio_decoder_config.h"
14 #include "media/base/decrypt_config.h" 12 #include "media/base/decrypt_config.h"
15 #include "media/base/mock_media_log.h"
16 #include "media/formats/webm/cluster_builder.h" 13 #include "media/formats/webm/cluster_builder.h"
17 #include "media/formats/webm/opus_packet_builder.h" 14 #include "media/formats/webm/opus_packet_builder.h"
18 #include "media/formats/webm/webm_cluster_parser.h" 15 #include "media/formats/webm/webm_cluster_parser.h"
19 #include "media/formats/webm/webm_constants.h" 16 #include "media/formats/webm/webm_constants.h"
20 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
22 19
23 using ::testing::HasSubstr;
24 using ::testing::InSequence; 20 using ::testing::InSequence;
25 using ::testing::Return; 21 using ::testing::Return;
26 using ::testing::StrictMock;
27 using ::testing::_; 22 using ::testing::_;
28 23
29 namespace media { 24 namespace media {
30 25
31 typedef WebMTracksParser::TextTracks TextTracks; 26 typedef WebMTracksParser::TextTracks TextTracks;
32 27
33 // Matchers for verifying common media log entry strings.
34 MATCHER_P(OpusPacketDurationTooHigh, actual_duration_ms, "") {
35 return CONTAINS_STRING(
36 arg, "Warning, demuxed Opus packet with encoded duration: " +
37 base::IntToString(actual_duration_ms) +
38 "ms. Should be no greater than 120ms.");
39 }
40
41 MATCHER_P(WebMSimpleBlockDurationEstimated, estimated_duration_ms, "") {
42 return CONTAINS_STRING(arg, "Estimating WebM block duration to be " +
43 base::IntToString(estimated_duration_ms) +
44 "ms for the last (Simple)Block in the "
45 "Cluster for this Track. Use BlockGroups "
46 "with BlockDurations at the end of each "
47 "Track in a Cluster to avoid estimation.");
48 }
49
50 MATCHER_P2(WebMBlockDurationMismatchesOpusDuration,
51 block_duration_ms,
52 opus_duration_ms,
53 "") {
54 return CONTAINS_STRING(
55 arg, "BlockDuration (" + base::IntToString(block_duration_ms) +
56 "ms) differs significantly from encoded duration (" +
57 base::IntToString(opus_duration_ms) + "ms).");
58 }
59
60 namespace { 28 namespace {
61 29
62 // Timecode scale for millisecond timestamps. 30 enum {
63 const int kTimecodeScale = 1000000; 31 kTimecodeScale = 1000000, // Timecode scale for millisecond timestamps.
64 32 kAudioTrackNum = 1,
65 const int kAudioTrackNum = 1; 33 kVideoTrackNum = 2,
66 const int kVideoTrackNum = 2; 34 kTextTrackNum = 3,
67 const int kTextTrackNum = 3; 35 kTestAudioFrameDefaultDurationInMs = 13,
68 const int kTestAudioFrameDefaultDurationInMs = 13; 36 kTestVideoFrameDefaultDurationInMs = 17
69 const int kTestVideoFrameDefaultDurationInMs = 17; 37 };
70 38
71 // Test duration defaults must differ from parser estimation defaults to know 39 // Test duration defaults must differ from parser estimation defaults to know
72 // which durations parser used when emitting buffers. 40 // which durations parser used when emitting buffers.
73 static_assert( 41 static_assert(
74 static_cast<int>(kTestAudioFrameDefaultDurationInMs) != 42 static_cast<int>(kTestAudioFrameDefaultDurationInMs) !=
75 static_cast<int>(WebMClusterParser::kDefaultAudioBufferDurationInMs), 43 static_cast<int>(WebMClusterParser::kDefaultAudioBufferDurationInMs),
76 "test default is the same as estimation fallback audio duration"); 44 "test default is the same as estimation fallback audio duration");
77 static_assert( 45 static_assert(
78 static_cast<int>(kTestVideoFrameDefaultDurationInMs) != 46 static_cast<int>(kTestVideoFrameDefaultDurationInMs) !=
79 static_cast<int>(WebMClusterParser::kDefaultVideoBufferDurationInMs), 47 static_cast<int>(WebMClusterParser::kDefaultVideoBufferDurationInMs),
(...skipping 28 matching lines...) Expand all
108 {kVideoTrackNum, 100, 33, false, NULL, 0}, 76 {kVideoTrackNum, 100, 33, false, NULL, 0},
109 }; 77 };
110 78
111 const uint8_t kEncryptedFrame[] = { 79 const uint8_t kEncryptedFrame[] = {
112 // Block is encrypted 80 // Block is encrypted
113 0x01, 81 0x01,
114 82
115 // IV 83 // IV
116 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}; 84 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
117 85
86 // Helper that hard-codes some non-varying constructor parameters.
87 WebMClusterParser* CreateParserHelper(
88 base::TimeDelta audio_default_duration,
89 base::TimeDelta video_default_duration,
90 const WebMTracksParser::TextTracks& text_tracks,
91 const std::set<int64>& ignored_tracks,
92 const std::string& audio_encryption_key_id,
93 const std::string& video_encryption_key_id,
94 const AudioCodec audio_codec) {
95 return new WebMClusterParser(
96 kTimecodeScale, kAudioTrackNum, audio_default_duration, kVideoTrackNum,
97 video_default_duration, text_tracks, ignored_tracks,
98 audio_encryption_key_id, video_encryption_key_id, audio_codec,
99 new MediaLog());
100 }
101
102 // Create a default version of the parser for test.
103 WebMClusterParser* CreateDefaultParser() {
104 return CreateParserHelper(kNoTimestamp(), kNoTimestamp(), TextTracks(),
105 std::set<int64>(), std::string(), std::string(),
106 kUnknownAudioCodec);
107 }
108
109 // Create a parser for test with custom audio and video default durations, and
110 // optionally custom text tracks.
111 WebMClusterParser* CreateParserWithDefaultDurationsAndOptionalTextTracks(
112 base::TimeDelta audio_default_duration,
113 base::TimeDelta video_default_duration,
114 const WebMTracksParser::TextTracks& text_tracks = TextTracks()) {
115 return CreateParserHelper(audio_default_duration, video_default_duration,
116 text_tracks, std::set<int64>(), std::string(),
117 std::string(), kUnknownAudioCodec);
118 }
119
120 // Create a parser for test with custom ignored tracks.
121 WebMClusterParser* CreateParserWithIgnoredTracks(
122 std::set<int64>& ignored_tracks) {
123 return CreateParserHelper(kNoTimestamp(), kNoTimestamp(), TextTracks(),
124 ignored_tracks, std::string(), std::string(),
125 kUnknownAudioCodec);
126 }
127
128 // Create a parser for test with custom encryption key ids and audio codec.
129 WebMClusterParser* CreateParserWithKeyIdsAndAudioCodec(
130 const std::string& audio_encryption_key_id,
131 const std::string& video_encryption_key_id,
132 const AudioCodec audio_codec) {
133 return CreateParserHelper(kNoTimestamp(), kNoTimestamp(), TextTracks(),
134 std::set<int64>(), audio_encryption_key_id,
135 video_encryption_key_id, audio_codec);
136 }
137
118 scoped_ptr<Cluster> CreateCluster(int timecode, 138 scoped_ptr<Cluster> CreateCluster(int timecode,
119 const BlockInfo* block_info, 139 const BlockInfo* block_info,
120 int block_count) { 140 int block_count) {
121 ClusterBuilder cb; 141 ClusterBuilder cb;
122 cb.SetClusterTimecode(0); 142 cb.SetClusterTimecode(0);
123 143
124 uint8_t kDefaultBlockData[] = { 0x00 }; 144 uint8_t kDefaultBlockData[] = { 0x00 };
125 145
126 for (int i = 0; i < block_count; i++) { 146 for (int i = 0; i < block_count; i++) {
127 const uint8_t* data; 147 const uint8_t* data;
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 for (WebMClusterParser::BufferQueue::const_iterator itr = src.begin(); 306 for (WebMClusterParser::BufferQueue::const_iterator itr = src.begin();
287 itr != src.end(); ++itr) { 307 itr != src.end(); ++itr) {
288 dest->push_back(*itr); 308 dest->push_back(*itr);
289 } 309 }
290 } 310 }
291 311
292 } // namespace 312 } // namespace
293 313
294 class WebMClusterParserTest : public testing::Test { 314 class WebMClusterParserTest : public testing::Test {
295 public: 315 public:
296 WebMClusterParserTest() 316 WebMClusterParserTest() : parser_(CreateDefaultParser()) {}
297 : media_log_(new StrictMock<MockMediaLog>()),
298 parser_(CreateDefaultParser()) {}
299 317
300 protected: 318 protected:
301 void ResetParserToHaveDefaultDurations() { 319 void ResetParserToHaveDefaultDurations() {
302 base::TimeDelta default_audio_duration = base::TimeDelta::FromMilliseconds( 320 base::TimeDelta default_audio_duration = base::TimeDelta::FromMilliseconds(
303 kTestAudioFrameDefaultDurationInMs); 321 kTestAudioFrameDefaultDurationInMs);
304 base::TimeDelta default_video_duration = base::TimeDelta::FromMilliseconds( 322 base::TimeDelta default_video_duration = base::TimeDelta::FromMilliseconds(
305 kTestVideoFrameDefaultDurationInMs); 323 kTestVideoFrameDefaultDurationInMs);
306 ASSERT_GE(default_audio_duration, base::TimeDelta()); 324 ASSERT_GE(default_audio_duration, base::TimeDelta());
307 ASSERT_GE(default_video_duration, base::TimeDelta()); 325 ASSERT_GE(default_video_duration, base::TimeDelta());
308 ASSERT_NE(kNoTimestamp(), default_audio_duration); 326 ASSERT_NE(kNoTimestamp(), default_audio_duration);
309 ASSERT_NE(kNoTimestamp(), default_video_duration); 327 ASSERT_NE(kNoTimestamp(), default_video_duration);
310 328
311 parser_.reset(CreateParserWithDefaultDurationsAndOptionalTextTracks( 329 parser_.reset(CreateParserWithDefaultDurationsAndOptionalTextTracks(
312 default_audio_duration, default_video_duration)); 330 default_audio_duration, default_video_duration));
313 } 331 }
314 332
315 // Helper that hard-codes some non-varying constructor parameters.
316 WebMClusterParser* CreateParserHelper(
317 base::TimeDelta audio_default_duration,
318 base::TimeDelta video_default_duration,
319 const WebMTracksParser::TextTracks& text_tracks,
320 const std::set<int64>& ignored_tracks,
321 const std::string& audio_encryption_key_id,
322 const std::string& video_encryption_key_id,
323 const AudioCodec audio_codec) {
324 return new WebMClusterParser(
325 kTimecodeScale, kAudioTrackNum, audio_default_duration, kVideoTrackNum,
326 video_default_duration, text_tracks, ignored_tracks,
327 audio_encryption_key_id, video_encryption_key_id, audio_codec,
328 media_log_);
329 }
330
331 // Create a default version of the parser for test.
332 WebMClusterParser* CreateDefaultParser() {
333 return CreateParserHelper(kNoTimestamp(), kNoTimestamp(), TextTracks(),
334 std::set<int64>(), std::string(), std::string(),
335 kUnknownAudioCodec);
336 }
337
338 // Create a parser for test with custom audio and video default durations, and
339 // optionally custom text tracks.
340 WebMClusterParser* CreateParserWithDefaultDurationsAndOptionalTextTracks(
341 base::TimeDelta audio_default_duration,
342 base::TimeDelta video_default_duration,
343 const WebMTracksParser::TextTracks& text_tracks = TextTracks()) {
344 return CreateParserHelper(audio_default_duration, video_default_duration,
345 text_tracks, std::set<int64>(), std::string(),
346 std::string(), kUnknownAudioCodec);
347 }
348
349 // Create a parser for test with custom ignored tracks.
350 WebMClusterParser* CreateParserWithIgnoredTracks(
351 std::set<int64>& ignored_tracks) {
352 return CreateParserHelper(kNoTimestamp(), kNoTimestamp(), TextTracks(),
353 ignored_tracks, std::string(), std::string(),
354 kUnknownAudioCodec);
355 }
356
357 // Create a parser for test with custom encryption key ids and audio codec.
358 WebMClusterParser* CreateParserWithKeyIdsAndAudioCodec(
359 const std::string& audio_encryption_key_id,
360 const std::string& video_encryption_key_id,
361 const AudioCodec audio_codec) {
362 return CreateParserHelper(kNoTimestamp(), kNoTimestamp(), TextTracks(),
363 std::set<int64>(), audio_encryption_key_id,
364 video_encryption_key_id, audio_codec);
365 }
366
367 scoped_refptr<StrictMock<MockMediaLog>> media_log_;
368 scoped_ptr<WebMClusterParser> parser_; 333 scoped_ptr<WebMClusterParser> parser_;
369 334
370 private: 335 private:
371 DISALLOW_COPY_AND_ASSIGN(WebMClusterParserTest); 336 DISALLOW_COPY_AND_ASSIGN(WebMClusterParserTest);
372 }; 337 };
373 338
374 TEST_F(WebMClusterParserTest, HeldBackBufferHoldsBackAllTracks) { 339 TEST_F(WebMClusterParserTest, HeldBackBufferHoldsBackAllTracks) {
375 // If a buffer is missing duration and is being held back, then all other 340 // If a buffer is missing duration and is being held back, then all other
376 // tracks' buffers that have same or higher (decode) timestamp should be held 341 // tracks' buffers that have same or higher (decode) timestamp should be held
377 // back too to keep the timestamps emitted for a cluster monotonically 342 // back too to keep the timestamps emitted for a cluster monotonically
378 // non-decreasing and in same order as parsed. 343 // non-decreasing and in same order as parsed.
379 InSequence s; 344 InSequence s;
380 345
381 // Reset the parser to have 3 tracks: text, video (no default frame duration), 346 // Reset the parser to have 3 tracks: text, video (no default frame duration),
382 // and audio (with a default frame duration). 347 // and audio (with a default frame duration).
383 TextTracks text_tracks; 348 TextTracks text_tracks;
384 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), 349 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum),
385 TextTrackConfig(kTextSubtitles, "", "", 350 TextTrackConfig(kTextSubtitles, "", "",
386 ""))); 351 "")));
387 base::TimeDelta default_audio_duration = 352 base::TimeDelta default_audio_duration =
388 base::TimeDelta::FromMilliseconds(kTestAudioFrameDefaultDurationInMs); 353 base::TimeDelta::FromMilliseconds(kTestAudioFrameDefaultDurationInMs);
389 ASSERT_GE(default_audio_duration, base::TimeDelta()); 354 ASSERT_GE(default_audio_duration, base::TimeDelta());
390 ASSERT_NE(kNoTimestamp(), default_audio_duration); 355 ASSERT_NE(kNoTimestamp(), default_audio_duration);
391 parser_.reset(CreateParserWithDefaultDurationsAndOptionalTextTracks( 356 parser_.reset(CreateParserWithDefaultDurationsAndOptionalTextTracks(
392 default_audio_duration, kNoTimestamp(), text_tracks)); 357 default_audio_duration, kNoTimestamp(), text_tracks));
393 358
394 const int kExpectedVideoEstimationInMs = 33;
395
396 const BlockInfo kBlockInfo[] = { 359 const BlockInfo kBlockInfo[] = {
397 {kVideoTrackNum, 0, 33, true, NULL, 0}, 360 {kVideoTrackNum, 0, 33, true, NULL, 0},
398 {kAudioTrackNum, 0, 23, false, NULL, 0}, 361 {kAudioTrackNum, 0, 23, false, NULL, 0},
399 {kTextTrackNum, 10, 42, false, NULL, 0}, 362 {kTextTrackNum, 10, 42, false, NULL, 0},
400 {kAudioTrackNum, 23, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, 363 {kAudioTrackNum, 23, kTestAudioFrameDefaultDurationInMs, true, NULL, 0},
401 {kVideoTrackNum, 33, 33, true, NULL, 0}, 364 {kVideoTrackNum, 33, 33, true, NULL, 0},
402 {kAudioTrackNum, 36, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, 365 {kAudioTrackNum, 36, kTestAudioFrameDefaultDurationInMs, true, NULL, 0},
403 {kVideoTrackNum, 66, kExpectedVideoEstimationInMs, true, NULL, 0}, 366 {kVideoTrackNum, 66, 33, true, NULL, 0},
404 {kAudioTrackNum, 70, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, 367 {kAudioTrackNum, 70, kTestAudioFrameDefaultDurationInMs, true, NULL, 0},
405 {kAudioTrackNum, 83, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, 368 {kAudioTrackNum, 83, kTestAudioFrameDefaultDurationInMs, true, NULL, 0},
406 }; 369 };
407 370
408 const int kExpectedBuffersOnPartialCluster[] = { 371 const int kExpectedBuffersOnPartialCluster[] = {
409 0, // Video simple block without DefaultDuration should be held back 372 0, // Video simple block without DefaultDuration should be held back
410 0, // Audio buffer ready, but not emitted because its TS >= held back video 373 0, // Audio buffer ready, but not emitted because its TS >= held back video
411 0, // Text buffer ready, but not emitted because its TS >= held back video 374 0, // Text buffer ready, but not emitted because its TS >= held back video
412 0, // 2nd audio buffer ready, also not emitted for same reason as first 375 0, // 2nd audio buffer ready, also not emitted for same reason as first
413 4, // All previous buffers emitted, 2nd video held back with no duration 376 4, // All previous buffers emitted, 2nd video held back with no duration
(...skipping 16 matching lines...) Expand all
430 parser_->Reset(); 393 parser_->Reset();
431 // Since we don't know exactly the offsets of each block in the full 394 // Since we don't know exactly the offsets of each block in the full
432 // cluster, build a cluster with exactly one additional block so that 395 // cluster, build a cluster with exactly one additional block so that
433 // parse of all but one byte should deterministically parse all but the 396 // parse of all but one byte should deterministically parse all but the
434 // last full block. Don't |exceed block_count| blocks though. 397 // last full block. Don't |exceed block_count| blocks though.
435 int blocks_in_cluster = std::min(i + 2, block_count); 398 int blocks_in_cluster = std::min(i + 2, block_count);
436 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, 399 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo,
437 blocks_in_cluster)); 400 blocks_in_cluster));
438 // Parse all but the last byte unless we need to parse the full cluster. 401 // Parse all but the last byte unless we need to parse the full cluster.
439 bool parse_full_cluster = i == (block_count - 1); 402 bool parse_full_cluster = i == (block_count - 1);
440
441 if (parse_full_cluster) {
442 EXPECT_MEDIA_LOG(
443 WebMSimpleBlockDurationEstimated(kExpectedVideoEstimationInMs));
444 }
445
446 int result = parser_->Parse(cluster->data(), parse_full_cluster ? 403 int result = parser_->Parse(cluster->data(), parse_full_cluster ?
447 cluster->size() : cluster->size() - 1); 404 cluster->size() : cluster->size() - 1);
448 if (parse_full_cluster) { 405 if (parse_full_cluster) {
449 DVLOG(1) << "Verifying parse result of full cluster of " 406 DVLOG(1) << "Verifying parse result of full cluster of "
450 << blocks_in_cluster << " blocks"; 407 << blocks_in_cluster << " blocks";
451 EXPECT_EQ(cluster->size(), result); 408 EXPECT_EQ(cluster->size(), result);
452 } else { 409 } else {
453 DVLOG(1) << "Verifying parse result of cluster of " 410 DVLOG(1) << "Verifying parse result of cluster of "
454 << blocks_in_cluster << " blocks with last block incomplete"; 411 << blocks_in_cluster << " blocks with last block incomplete";
455 EXPECT_GT(cluster->size(), result); 412 EXPECT_GT(cluster->size(), result);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 {kAudioTrackNum, 23, 23, true, NULL, 0}, 554 {kAudioTrackNum, 23, 23, true, NULL, 0},
598 {kVideoTrackNum, 33, 34, true, NULL, 0}, 555 {kVideoTrackNum, 33, 34, true, NULL, 0},
599 {kAudioTrackNum, 46, 23, true, NULL, 0}, 556 {kAudioTrackNum, 46, 23, true, NULL, 0},
600 {kVideoTrackNum, 67, 34, true, NULL, 0}, 557 {kVideoTrackNum, 67, 34, true, NULL, 0},
601 }; 558 };
602 int output_block_count = arraysize(kOutputBlockInfo); 559 int output_block_count = arraysize(kOutputBlockInfo);
603 560
604 scoped_ptr<Cluster> cluster( 561 scoped_ptr<Cluster> cluster(
605 CreateCluster(0, kInputBlockInfo, input_block_count)); 562 CreateCluster(0, kInputBlockInfo, input_block_count));
606 563
607 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(23));
608 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(34));
609 int result = parser_->Parse(cluster->data(), cluster->size()); 564 int result = parser_->Parse(cluster->data(), cluster->size());
610 EXPECT_EQ(cluster->size(), result); 565 EXPECT_EQ(cluster->size(), result);
611 ASSERT_TRUE(VerifyBuffers(parser_, kOutputBlockInfo, output_block_count)); 566 ASSERT_TRUE(VerifyBuffers(parser_, kOutputBlockInfo, output_block_count));
612 } 567 }
613 568
614 TEST_F(WebMClusterParserTest, ParseTextTracks) { 569 TEST_F(WebMClusterParserTest, ParseTextTracks) {
615 TextTracks text_tracks; 570 TextTracks text_tracks;
616 571
617 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), 572 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum),
618 TextTrackConfig(kTextSubtitles, "", "", 573 TextTrackConfig(kTextSubtitles, "", "",
619 ""))); 574 "")));
620 575
621 parser_.reset(CreateParserWithDefaultDurationsAndOptionalTextTracks( 576 parser_.reset(CreateParserWithDefaultDurationsAndOptionalTextTracks(
622 kNoTimestamp(), kNoTimestamp(), text_tracks)); 577 kNoTimestamp(), kNoTimestamp(), text_tracks));
623 578
624 const BlockInfo kInputBlockInfo[] = { 579 const BlockInfo kInputBlockInfo[] = {
625 {kAudioTrackNum, 0, 23, true, NULL, 0}, 580 {kAudioTrackNum, 0, 23, true, NULL, 0},
626 {kAudioTrackNum, 23, 23, true, NULL, 0}, 581 {kAudioTrackNum, 23, 23, true, NULL, 0},
627 {kVideoTrackNum, 33, 34, true, NULL, 0}, 582 {kVideoTrackNum, 33, 34, true, NULL, 0},
628 {kTextTrackNum, 33, 42, false, NULL, 0}, 583 {kTextTrackNum, 33, 42, false, NULL, 0},
629 {kAudioTrackNum, 46, 23, true, NULL, 0}, 584 {kAudioTrackNum, 46, 23, true, NULL, 0},
630 {kTextTrackNum, 55, 44, false, NULL, 0}, 585 {kTextTrackNum, 55, 44, false, NULL, 0},
631 {kVideoTrackNum, 67, 34, true, NULL, 0}, 586 {kVideoTrackNum, 67, 34, true, NULL, 0},
632 }; 587 };
633 int input_block_count = arraysize(kInputBlockInfo); 588 int input_block_count = arraysize(kInputBlockInfo);
634 589
635 scoped_ptr<Cluster> cluster( 590 scoped_ptr<Cluster> cluster(
636 CreateCluster(0, kInputBlockInfo, input_block_count)); 591 CreateCluster(0, kInputBlockInfo, input_block_count));
637 592
638 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(23));
639 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(34));
640 int result = parser_->Parse(cluster->data(), cluster->size()); 593 int result = parser_->Parse(cluster->data(), cluster->size());
641 EXPECT_EQ(cluster->size(), result); 594 EXPECT_EQ(cluster->size(), result);
642 ASSERT_TRUE(VerifyBuffers(parser_, kInputBlockInfo, input_block_count)); 595 ASSERT_TRUE(VerifyBuffers(parser_, kInputBlockInfo, input_block_count));
643 } 596 }
644 597
645 TEST_F(WebMClusterParserTest, TextTracksSimpleBlock) { 598 TEST_F(WebMClusterParserTest, TextTracksSimpleBlock) {
646 TextTracks text_tracks; 599 TextTracks text_tracks;
647 600
648 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), 601 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum),
649 TextTrackConfig(kTextSubtitles, "", "", 602 TextTrackConfig(kTextSubtitles, "", "",
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 {kAudioTrackNum, 46, 23, true, NULL, 0}, 642 {kAudioTrackNum, 46, 23, true, NULL, 0},
690 {kCaptionTextTrackNum, 55, 44, false, NULL, 0}, 643 {kCaptionTextTrackNum, 55, 44, false, NULL, 0},
691 {kVideoTrackNum, 67, 34, true, NULL, 0}, 644 {kVideoTrackNum, 67, 34, true, NULL, 0},
692 {kSubtitleTextTrackNum, 67, 33, false, NULL, 0}, 645 {kSubtitleTextTrackNum, 67, 33, false, NULL, 0},
693 }; 646 };
694 int input_block_count = arraysize(kInputBlockInfo); 647 int input_block_count = arraysize(kInputBlockInfo);
695 648
696 scoped_ptr<Cluster> cluster( 649 scoped_ptr<Cluster> cluster(
697 CreateCluster(0, kInputBlockInfo, input_block_count)); 650 CreateCluster(0, kInputBlockInfo, input_block_count));
698 651
699 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(23));
700 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(34));
701 int result = parser_->Parse(cluster->data(), cluster->size()); 652 int result = parser_->Parse(cluster->data(), cluster->size());
702 EXPECT_EQ(cluster->size(), result); 653 EXPECT_EQ(cluster->size(), result);
703 654
704 const WebMClusterParser::TextBufferQueueMap& text_map = 655 const WebMClusterParser::TextBufferQueueMap& text_map =
705 parser_->GetTextBuffers(); 656 parser_->GetTextBuffers();
706 for (WebMClusterParser::TextBufferQueueMap::const_iterator itr = 657 for (WebMClusterParser::TextBufferQueueMap::const_iterator itr =
707 text_map.begin(); 658 text_map.begin();
708 itr != text_map.end(); 659 itr != text_map.end();
709 ++itr) { 660 ++itr) {
710 const TextTracks::const_iterator find_result = 661 const TextTracks::const_iterator find_result =
711 text_tracks.find(itr->first); 662 text_tracks.find(itr->first);
712 ASSERT_TRUE(find_result != text_tracks.end()); 663 ASSERT_TRUE(find_result != text_tracks.end());
713 ASSERT_TRUE(VerifyTextBuffers(parser_, kInputBlockInfo, input_block_count, 664 ASSERT_TRUE(VerifyTextBuffers(parser_, kInputBlockInfo, input_block_count,
714 itr->first, itr->second)); 665 itr->first, itr->second));
715 } 666 }
716 } 667 }
717 668
718 TEST_F(WebMClusterParserTest, ParseEncryptedBlock) { 669 TEST_F(WebMClusterParserTest, ParseEncryptedBlock) {
719 scoped_ptr<Cluster> cluster(CreateEncryptedCluster(sizeof(kEncryptedFrame))); 670 scoped_ptr<Cluster> cluster(CreateEncryptedCluster(sizeof(kEncryptedFrame)));
720 671
721 parser_.reset(CreateParserWithKeyIdsAndAudioCodec( 672 parser_.reset(CreateParserWithKeyIdsAndAudioCodec(
722 std::string(), "video_key_id", kUnknownAudioCodec)); 673 std::string(), "video_key_id", kUnknownAudioCodec));
723
724 // The encrypted cluster contains just one block, video.
725 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(
726 WebMClusterParser::kDefaultVideoBufferDurationInMs));
727
728 int result = parser_->Parse(cluster->data(), cluster->size()); 674 int result = parser_->Parse(cluster->data(), cluster->size());
729 EXPECT_EQ(cluster->size(), result); 675 EXPECT_EQ(cluster->size(), result);
730 ASSERT_EQ(1UL, parser_->GetVideoBuffers().size()); 676 ASSERT_EQ(1UL, parser_->GetVideoBuffers().size());
731 scoped_refptr<StreamParserBuffer> buffer = parser_->GetVideoBuffers()[0]; 677 scoped_refptr<StreamParserBuffer> buffer = parser_->GetVideoBuffers()[0];
732 VerifyEncryptedBuffer(buffer); 678 VerifyEncryptedBuffer(buffer);
733 } 679 }
734 680
735 TEST_F(WebMClusterParserTest, ParseBadEncryptedBlock) { 681 TEST_F(WebMClusterParserTest, ParseBadEncryptedBlock) {
736 scoped_ptr<Cluster> cluster( 682 scoped_ptr<Cluster> cluster(
737 CreateEncryptedCluster(sizeof(kEncryptedFrame) - 1)); 683 CreateEncryptedCluster(sizeof(kEncryptedFrame) - 1));
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 764
819 TEST_F(WebMClusterParserTest, ParseWithoutAnyDurationsSimpleBlocks) { 765 TEST_F(WebMClusterParserTest, ParseWithoutAnyDurationsSimpleBlocks) {
820 InSequence s; 766 InSequence s;
821 767
822 // Absent DefaultDuration information, SimpleBlock durations are derived from 768 // Absent DefaultDuration information, SimpleBlock durations are derived from
823 // inter-buffer track timestamp delta if within the cluster. Duration for the 769 // inter-buffer track timestamp delta if within the cluster. Duration for the
824 // last block in a cluster is estimated independently for each track in the 770 // last block in a cluster is estimated independently for each track in the
825 // cluster. For video tracks we use the maximum seen so far. For audio we use 771 // cluster. For video tracks we use the maximum seen so far. For audio we use
826 // the the minimum. 772 // the the minimum.
827 // TODO(chcunningham): Move audio over to use the maximum. 773 // TODO(chcunningham): Move audio over to use the maximum.
828
829 const int kExpectedAudioEstimationInMs = 22;
830 const int kExpectedVideoEstimationInMs = 34;
831 const BlockInfo kBlockInfo1[] = { 774 const BlockInfo kBlockInfo1[] = {
832 {kAudioTrackNum, 0, 23, true, NULL, 0}, 775 {kAudioTrackNum, 0, 23, true, NULL, 0},
833 {kAudioTrackNum, 23, 22, true, NULL, 0}, 776 {kAudioTrackNum, 23, 22, true, NULL, 0},
834 {kVideoTrackNum, 33, 33, true, NULL, 0}, 777 {kVideoTrackNum, 33, 33, true, NULL, 0},
835 {kAudioTrackNum, 45, 23, true, NULL, 0}, 778 {kAudioTrackNum, 45, 23, true, NULL, 0},
836 {kVideoTrackNum, 66, 34, true, NULL, 0}, 779 {kVideoTrackNum, 66, 34, true, NULL, 0},
837 {kAudioTrackNum, 68, kExpectedAudioEstimationInMs, true, NULL, 0}, 780 // Estimated from minimum audio dur
838 {kVideoTrackNum, 100, kExpectedVideoEstimationInMs, true, NULL, 0}, 781 {kAudioTrackNum, 68, 22, true, NULL, 0},
782 // Estimated from maximum video dur
783 {kVideoTrackNum, 100, 34, true, NULL, 0},
839 }; 784 };
840 785
841 int block_count1 = arraysize(kBlockInfo1); 786 int block_count1 = arraysize(kBlockInfo1);
842 scoped_ptr<Cluster> cluster1(CreateCluster(0, kBlockInfo1, block_count1)); 787 scoped_ptr<Cluster> cluster1(CreateCluster(0, kBlockInfo1, block_count1));
843 788
844 // Send slightly less than the first full cluster so all but the last video 789 // Send slightly less than the first full cluster so all but the last video
845 // block is parsed. Verify the last fully parsed audio and video buffer are 790 // block is parsed. Verify the last fully parsed audio and video buffer are
846 // both missing from the result (parser should hold them aside for duration 791 // both missing from the result (parser should hold them aside for duration
847 // estimation prior to end of cluster detection in the absence of 792 // estimation prior to end of cluster detection in the absence of
848 // DefaultDurations.) 793 // DefaultDurations.)
849 int result = parser_->Parse(cluster1->data(), cluster1->size() - 1); 794 int result = parser_->Parse(cluster1->data(), cluster1->size() - 1);
850 EXPECT_GT(result, 0); 795 EXPECT_GT(result, 0);
851 EXPECT_LT(result, cluster1->size()); 796 EXPECT_LT(result, cluster1->size());
852 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1 - 3)); 797 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1 - 3));
853 EXPECT_EQ(3UL, parser_->GetAudioBuffers().size()); 798 EXPECT_EQ(3UL, parser_->GetAudioBuffers().size());
854 EXPECT_EQ(1UL, parser_->GetVideoBuffers().size()); 799 EXPECT_EQ(1UL, parser_->GetVideoBuffers().size());
855 800
856 parser_->Reset(); 801 parser_->Reset();
857 802
858 // Now parse the full first cluster and verify all the blocks are parsed. 803 // Now parse the full first cluster and verify all the blocks are parsed.
859 EXPECT_MEDIA_LOG(
860 WebMSimpleBlockDurationEstimated(kExpectedAudioEstimationInMs));
861 EXPECT_MEDIA_LOG(
862 WebMSimpleBlockDurationEstimated(kExpectedVideoEstimationInMs));
863 result = parser_->Parse(cluster1->data(), cluster1->size()); 804 result = parser_->Parse(cluster1->data(), cluster1->size());
864 EXPECT_EQ(cluster1->size(), result); 805 EXPECT_EQ(cluster1->size(), result);
865 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1)); 806 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1));
866 807
867 // Verify that the estimated frame duration is tracked across clusters for 808 // Verify that the estimated frame duration is tracked across clusters for
868 // each track. 809 // each track.
869 const BlockInfo kBlockInfo2[] = { 810 const BlockInfo kBlockInfo2[] = {
870 // Estimate carries over across clusters 811 // Estimate carries over across clusters
871 {kAudioTrackNum, 200, kExpectedAudioEstimationInMs, true, NULL, 0}, 812 {kAudioTrackNum, 200, 22, true, NULL, 0},
872 // Estimate carries over across clusters 813 // Estimate carries over across clusters
873 {kVideoTrackNum, 201, kExpectedVideoEstimationInMs, true, NULL, 0}, 814 {kVideoTrackNum, 201, 34, true, NULL, 0},
874 }; 815 };
875 816
876 int block_count2 = arraysize(kBlockInfo2); 817 int block_count2 = arraysize(kBlockInfo2);
877 scoped_ptr<Cluster> cluster2(CreateCluster(0, kBlockInfo2, block_count2)); 818 scoped_ptr<Cluster> cluster2(CreateCluster(0, kBlockInfo2, block_count2));
878 EXPECT_MEDIA_LOG(
879 WebMSimpleBlockDurationEstimated(kExpectedAudioEstimationInMs));
880 EXPECT_MEDIA_LOG(
881 WebMSimpleBlockDurationEstimated(kExpectedVideoEstimationInMs));
882 result = parser_->Parse(cluster2->data(), cluster2->size()); 819 result = parser_->Parse(cluster2->data(), cluster2->size());
883 EXPECT_EQ(cluster2->size(), result); 820 EXPECT_EQ(cluster2->size(), result);
884 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo2, block_count2)); 821 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo2, block_count2));
885 } 822 }
886 823
887 TEST_F(WebMClusterParserTest, ParseWithoutAnyDurationsBlockGroups) { 824 TEST_F(WebMClusterParserTest, ParseWithoutAnyDurationsBlockGroups) {
888 InSequence s; 825 InSequence s;
889 826
890 // Absent DefaultDuration and BlockDuration information, BlockGroup block 827 // Absent DefaultDuration and BlockDuration information, BlockGroup block
891 // durations are derived from inter-buffer track timestamp delta if within the 828 // durations are derived from inter-buffer track timestamp delta if within the
892 // cluster. Duration for the last block in a cluster is estimated 829 // cluster. Duration for the last block in a cluster is estimated
893 // independently for each track in the cluster. For video tracks we use the 830 // independently for each track in the cluster. For video tracks we use the
894 // maximum seen so far. For audio we use the the minimum. 831 // maximum seen so far. For audio we use the the minimum.
895 // TODO(chcunningham): Move audio over to use the maximum. 832 // TODO(chcunningham): Move audio over to use the maximum.
896
897 const int kExpectedAudioEstimationInMs = 22;
898 const int kExpectedVideoEstimationInMs = 34;
899 const BlockInfo kBlockInfo1[] = { 833 const BlockInfo kBlockInfo1[] = {
900 {kAudioTrackNum, 0, -23, false, NULL, 0}, 834 {kAudioTrackNum, 0, -23, false, NULL, 0},
901 {kAudioTrackNum, 23, -22, false, NULL, 0}, 835 {kAudioTrackNum, 23, -22, false, NULL, 0},
902 {kVideoTrackNum, 33, -33, false, NULL, 0}, 836 {kVideoTrackNum, 33, -33, false, NULL, 0},
903 {kAudioTrackNum, 45, -23, false, NULL, 0}, 837 {kAudioTrackNum, 45, -23, false, NULL, 0},
904 {kVideoTrackNum, 66, -34, false, NULL, 0}, 838 {kVideoTrackNum, 66, -34, false, NULL, 0},
905 {kAudioTrackNum, 68, -kExpectedAudioEstimationInMs, false, NULL, 0}, 839 // Estimated from minimum audio dur
906 {kVideoTrackNum, 100, -kExpectedVideoEstimationInMs, false, NULL, 0}, 840 {kAudioTrackNum, 68, -22, false, NULL, 0},
841 // Estimated from maximum video dur
842 {kVideoTrackNum, 100, -34, false, NULL, 0},
907 }; 843 };
908 844
909 int block_count1 = arraysize(kBlockInfo1); 845 int block_count1 = arraysize(kBlockInfo1);
910 scoped_ptr<Cluster> cluster1(CreateCluster(0, kBlockInfo1, block_count1)); 846 scoped_ptr<Cluster> cluster1(CreateCluster(0, kBlockInfo1, block_count1));
911 847
912 // Send slightly less than the first full cluster so all but the last video 848 // Send slightly less than the first full cluster so all but the last video
913 // block is parsed. Verify the last fully parsed audio and video buffer are 849 // block is parsed. Verify the last fully parsed audio and video buffer are
914 // both missing from the result (parser should hold them aside for duration 850 // both missing from the result (parser should hold them aside for duration
915 // estimation prior to end of cluster detection in the absence of 851 // estimation prior to end of cluster detection in the absence of
916 // DefaultDurations.) 852 // DefaultDurations.)
917 int result = parser_->Parse(cluster1->data(), cluster1->size() - 1); 853 int result = parser_->Parse(cluster1->data(), cluster1->size() - 1);
918 EXPECT_GT(result, 0); 854 EXPECT_GT(result, 0);
919 EXPECT_LT(result, cluster1->size()); 855 EXPECT_LT(result, cluster1->size());
920 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1 - 3)); 856 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1 - 3));
921 EXPECT_EQ(3UL, parser_->GetAudioBuffers().size()); 857 EXPECT_EQ(3UL, parser_->GetAudioBuffers().size());
922 EXPECT_EQ(1UL, parser_->GetVideoBuffers().size()); 858 EXPECT_EQ(1UL, parser_->GetVideoBuffers().size());
923 859
924 parser_->Reset(); 860 parser_->Reset();
925 861
926 // Now parse the full first cluster and verify all the blocks are parsed. 862 // Now parse the full first cluster and verify all the blocks are parsed.
927 EXPECT_MEDIA_LOG(
928 WebMSimpleBlockDurationEstimated(kExpectedAudioEstimationInMs));
929 EXPECT_MEDIA_LOG(
930 WebMSimpleBlockDurationEstimated(kExpectedVideoEstimationInMs));
931 result = parser_->Parse(cluster1->data(), cluster1->size()); 863 result = parser_->Parse(cluster1->data(), cluster1->size());
932 EXPECT_EQ(cluster1->size(), result); 864 EXPECT_EQ(cluster1->size(), result);
933 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1)); 865 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1));
934 866
935 // Verify that the estimated frame duration is tracked across clusters for 867 // Verify that the estimated frame duration is tracked across clusters for
936 // each track. 868 // each track.
937 const BlockInfo kBlockInfo2[] = { 869 const BlockInfo kBlockInfo2[] = {
938 {kAudioTrackNum, 200, -kExpectedAudioEstimationInMs, false, NULL, 0}, 870 {kAudioTrackNum, 200, -22, false, NULL, 0},
939 {kVideoTrackNum, 201, -kExpectedVideoEstimationInMs, false, NULL, 0}, 871 {kVideoTrackNum, 201, -34, false, NULL, 0},
940 }; 872 };
941 873
942 int block_count2 = arraysize(kBlockInfo2); 874 int block_count2 = arraysize(kBlockInfo2);
943 scoped_ptr<Cluster> cluster2(CreateCluster(0, kBlockInfo2, block_count2)); 875 scoped_ptr<Cluster> cluster2(CreateCluster(0, kBlockInfo2, block_count2));
944 EXPECT_MEDIA_LOG(
945 WebMSimpleBlockDurationEstimated(kExpectedAudioEstimationInMs));
946 EXPECT_MEDIA_LOG(
947 WebMSimpleBlockDurationEstimated(kExpectedVideoEstimationInMs));
948 result = parser_->Parse(cluster2->data(), cluster2->size()); 876 result = parser_->Parse(cluster2->data(), cluster2->size());
949 EXPECT_EQ(cluster2->size(), result); 877 EXPECT_EQ(cluster2->size(), result);
950 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo2, block_count2)); 878 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo2, block_count2));
951 } 879 }
952 880
953 // TODO(wolenetz): Is parser behavior correct? See http://crbug.com/363433. 881 // TODO(wolenetz): Is parser behavior correct? See http://crbug.com/363433.
954 TEST_F(WebMClusterParserTest, 882 TEST_F(WebMClusterParserTest,
955 ParseWithDefaultDurationsBlockGroupsWithoutDurations) { 883 ParseWithDefaultDurationsBlockGroupsWithoutDurations) {
956 InSequence s; 884 InSequence s;
957 ResetParserToHaveDefaultDurations(); 885 ResetParserToHaveDefaultDurations();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 }, { 932 }, {
1005 kVideoTrackNum, 933 kVideoTrackNum,
1006 0, 934 0,
1007 WebMClusterParser::kDefaultVideoBufferDurationInMs, 935 WebMClusterParser::kDefaultVideoBufferDurationInMs,
1008 true 936 true
1009 }, 937 },
1010 }; 938 };
1011 939
1012 int block_count = arraysize(kBlockInfo); 940 int block_count = arraysize(kBlockInfo);
1013 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); 941 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count));
1014 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(
1015 WebMClusterParser::kDefaultAudioBufferDurationInMs));
1016 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(
1017 WebMClusterParser::kDefaultVideoBufferDurationInMs));
1018 int result = parser_->Parse(cluster->data(), cluster->size()); 942 int result = parser_->Parse(cluster->data(), cluster->size());
1019 EXPECT_EQ(cluster->size(), result); 943 EXPECT_EQ(cluster->size(), result);
1020 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); 944 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count));
1021 } 945 }
1022 946
1023 TEST_F(WebMClusterParserTest, 947 TEST_F(WebMClusterParserTest,
1024 ParseDegenerateClusterWithDefaultDurationsYieldsDefaultDurations) { 948 ParseDegenerateClusterWithDefaultDurationsYieldsDefaultDurations) {
1025 ResetParserToHaveDefaultDurations(); 949 ResetParserToHaveDefaultDurations();
1026 950
1027 const BlockInfo kBlockInfo[] = { 951 const BlockInfo kBlockInfo[] = {
1028 { kAudioTrackNum, 0, kTestAudioFrameDefaultDurationInMs, true }, 952 { kAudioTrackNum, 0, kTestAudioFrameDefaultDurationInMs, true },
1029 { kVideoTrackNum, 0, kTestVideoFrameDefaultDurationInMs, true }, 953 { kVideoTrackNum, 0, kTestVideoFrameDefaultDurationInMs, true },
1030 }; 954 };
1031 955
1032 int block_count = arraysize(kBlockInfo); 956 int block_count = arraysize(kBlockInfo);
1033 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); 957 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count));
1034 int result = parser_->Parse(cluster->data(), cluster->size()); 958 int result = parser_->Parse(cluster->data(), cluster->size());
1035 EXPECT_EQ(cluster->size(), result); 959 EXPECT_EQ(cluster->size(), result);
1036 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); 960 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count));
1037 } 961 }
1038 962
1039 TEST_F(WebMClusterParserTest, ReadOpusDurationsSimpleBlockAtEndOfCluster) { 963 TEST_F(WebMClusterParserTest, ReadOpusDurationsSimpleBlockAtEndOfCluster) {
1040 InSequence s; 964 // Reset parser to expect Opus codec audio.
965 parser_.reset(CreateParserWithKeyIdsAndAudioCodec(std::string(),
966 std::string(), kCodecOpus));
1041 967
1042 int loop_count = 0; 968 int loop_count = 0;
1043 for (const auto* packet_ptr : BuildAllOpusPackets()) { 969 for (const auto* packet_ptr : BuildAllOpusPackets()) {
1044 // Get a new parser each iteration to prevent exceeding the media log cap.
1045 parser_.reset(CreateParserWithKeyIdsAndAudioCodec(
1046 std::string(), std::string(), kCodecOpus));
1047
1048 const BlockInfo kBlockInfo[] = {{kAudioTrackNum, 970 const BlockInfo kBlockInfo[] = {{kAudioTrackNum,
1049 0, 971 0,
1050 packet_ptr->duration_ms(), 972 packet_ptr->duration_ms(),
1051 true, // Make it a SimpleBlock. 973 true, // Make it a SimpleBlock.
1052 packet_ptr->data(), 974 packet_ptr->data(),
1053 packet_ptr->size()}}; 975 packet_ptr->size()}};
1054 976
1055 int block_count = arraysize(kBlockInfo); 977 int block_count = arraysize(kBlockInfo);
1056 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); 978 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count));
1057 int duration_ms = packet_ptr->duration_ms(); // Casts from double.
1058 if (duration_ms > 120) {
1059 EXPECT_MEDIA_LOG(OpusPacketDurationTooHigh(duration_ms));
1060 }
1061
1062 int result = parser_->Parse(cluster->data(), cluster->size()); 979 int result = parser_->Parse(cluster->data(), cluster->size());
1063 EXPECT_EQ(cluster->size(), result); 980 EXPECT_EQ(cluster->size(), result);
1064 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); 981 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count));
1065 loop_count++; 982 loop_count++;
1066 } 983 }
1067 984
1068 // Test should minimally cover all the combinations of config and frame count. 985 // Test should minimally cover all the combinations of config and frame count.
1069 ASSERT_GE(loop_count, kNumPossibleOpusConfigs * kMaxOpusPacketFrameCount); 986 ASSERT_GE(loop_count, kNumPossibleOpusConfigs * kMaxOpusPacketFrameCount);
1070 } 987 }
1071 988
1072 TEST_F(WebMClusterParserTest, PreferOpusDurationsOverBlockDurations) { 989 TEST_F(WebMClusterParserTest, PreferOpusDurationsOverBlockDurations) {
1073 InSequence s; 990 // Reset parser to expect Opus codec audio.
991 parser_.reset(CreateParserWithKeyIdsAndAudioCodec(std::string(),
992 std::string(), kCodecOpus));
1074 993
1075 int loop_count = 0; 994 int loop_count = 0;
1076 for (const auto* packet_ptr : BuildAllOpusPackets()) { 995 for (const auto* packet_ptr : BuildAllOpusPackets()) {
1077 // Get a new parser each iteration to prevent exceeding the media log cap.
1078 parser_.reset(CreateParserWithKeyIdsAndAudioCodec(
1079 std::string(), std::string(), kCodecOpus));
1080
1081 // Setting BlockDuration != Opus duration to see which one the parser uses. 996 // Setting BlockDuration != Opus duration to see which one the parser uses.
1082 int block_duration_ms = packet_ptr->duration_ms() + 10; 997 int block_duration_ms = packet_ptr->duration_ms() + 10;
1083 if (packet_ptr->duration_ms() > 120) {
1084 EXPECT_MEDIA_LOG(OpusPacketDurationTooHigh(packet_ptr->duration_ms()));
1085 }
1086
1087 EXPECT_MEDIA_LOG(WebMBlockDurationMismatchesOpusDuration(
1088 block_duration_ms, packet_ptr->duration_ms()));
1089 998
1090 BlockInfo block_infos[] = {{kAudioTrackNum, 999 BlockInfo block_infos[] = {{kAudioTrackNum,
1091 0, 1000 0,
1092 block_duration_ms, 1001 block_duration_ms,
1093 false, // Not a SimpleBlock. 1002 false, // Not a SimpleBlock.
1094 packet_ptr->data(), 1003 packet_ptr->data(),
1095 packet_ptr->size()}}; 1004 packet_ptr->size()}};
1096 1005
1097 int block_count = arraysize(block_infos); 1006 int block_count = arraysize(block_infos);
1098 scoped_ptr<Cluster> cluster(CreateCluster(0, block_infos, block_count)); 1007 scoped_ptr<Cluster> cluster(CreateCluster(0, block_infos, block_count));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 int block_count = arraysize(kBlockInfo); 1042 int block_count = arraysize(kBlockInfo);
1134 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); 1043 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count));
1135 int result = parser_->Parse(cluster->data(), cluster->size()); 1044 int result = parser_->Parse(cluster->data(), cluster->size());
1136 EXPECT_EQ(cluster->size(), result); 1045 EXPECT_EQ(cluster->size(), result);
1137 1046
1138 // Will verify that duration of buffer matches that of BlockDuration. 1047 // Will verify that duration of buffer matches that of BlockDuration.
1139 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); 1048 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count));
1140 } 1049 }
1141 1050
1142 } // namespace media 1051 } // namespace media
OLDNEW
« no previous file with comments | « media/formats/webm/webm_cluster_parser.cc ('k') | media/formats/webm/webm_content_encodings_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698