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

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

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