OLD | NEW |
---|---|
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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 : parser_(new WebMClusterParser(kTimecodeScale, | 261 : parser_(new WebMClusterParser(kTimecodeScale, |
262 kAudioTrackNum, | 262 kAudioTrackNum, |
263 kNoTimestamp(), | 263 kNoTimestamp(), |
264 kVideoTrackNum, | 264 kVideoTrackNum, |
265 kNoTimestamp(), | 265 kNoTimestamp(), |
266 TextTracks(), | 266 TextTracks(), |
267 std::set<int64>(), | 267 std::set<int64>(), |
268 std::string(), | 268 std::string(), |
269 std::string(), | 269 std::string(), |
270 kUnknownAudioCodec, | 270 kUnknownAudioCodec, |
271 LogCB())) {} | 271 new MediaLog())) {} |
272 | 272 |
273 protected: | 273 protected: |
274 void ResetParserToHaveDefaultDurations() { | 274 void ResetParserToHaveDefaultDurations() { |
275 base::TimeDelta default_audio_duration = base::TimeDelta::FromMilliseconds( | 275 base::TimeDelta default_audio_duration = base::TimeDelta::FromMilliseconds( |
276 kTestAudioFrameDefaultDurationInMs); | 276 kTestAudioFrameDefaultDurationInMs); |
277 base::TimeDelta default_video_duration = base::TimeDelta::FromMilliseconds( | 277 base::TimeDelta default_video_duration = base::TimeDelta::FromMilliseconds( |
278 kTestVideoFrameDefaultDurationInMs); | 278 kTestVideoFrameDefaultDurationInMs); |
279 ASSERT_GE(default_audio_duration, base::TimeDelta()); | 279 ASSERT_GE(default_audio_duration, base::TimeDelta()); |
280 ASSERT_GE(default_video_duration, base::TimeDelta()); | 280 ASSERT_GE(default_video_duration, base::TimeDelta()); |
281 ASSERT_NE(kNoTimestamp(), default_audio_duration); | 281 ASSERT_NE(kNoTimestamp(), default_audio_duration); |
282 ASSERT_NE(kNoTimestamp(), default_video_duration); | 282 ASSERT_NE(kNoTimestamp(), default_video_duration); |
283 | 283 |
284 parser_.reset(new WebMClusterParser(kTimecodeScale, | 284 parser_.reset(new WebMClusterParser( |
285 kAudioTrackNum, | 285 kTimecodeScale, kAudioTrackNum, default_audio_duration, kVideoTrackNum, |
286 default_audio_duration, | 286 default_video_duration, TextTracks(), std::set<int64>(), std::string(), |
287 kVideoTrackNum, | 287 std::string(), kUnknownAudioCodec, new MediaLog())); |
xhwang
2015/07/13 22:41:17
nit: It might make sense to have a helper function
wolenetz
2015/07/13 22:59:24
sgtm. I'll put those in a separate CL though. Than
wolenetz
2015/07/21 00:57:58
I have now prepared the separate CL for review @ h
| |
288 default_video_duration, | |
289 TextTracks(), | |
290 std::set<int64>(), | |
291 std::string(), | |
292 std::string(), | |
293 kUnknownAudioCodec, | |
294 LogCB())); | |
295 } | 288 } |
296 | 289 |
297 scoped_ptr<WebMClusterParser> parser_; | 290 scoped_ptr<WebMClusterParser> parser_; |
298 | 291 |
299 private: | 292 private: |
300 DISALLOW_COPY_AND_ASSIGN(WebMClusterParserTest); | 293 DISALLOW_COPY_AND_ASSIGN(WebMClusterParserTest); |
301 }; | 294 }; |
302 | 295 |
303 TEST_F(WebMClusterParserTest, HeldBackBufferHoldsBackAllTracks) { | 296 TEST_F(WebMClusterParserTest, HeldBackBufferHoldsBackAllTracks) { |
304 // If a buffer is missing duration and is being held back, then all other | 297 // If a buffer is missing duration and is being held back, then all other |
305 // tracks' buffers that have same or higher (decode) timestamp should be held | 298 // tracks' buffers that have same or higher (decode) timestamp should be held |
306 // back too to keep the timestamps emitted for a cluster monotonically | 299 // back too to keep the timestamps emitted for a cluster monotonically |
307 // non-decreasing and in same order as parsed. | 300 // non-decreasing and in same order as parsed. |
308 InSequence s; | 301 InSequence s; |
309 | 302 |
310 // Reset the parser to have 3 tracks: text, video (no default frame duration), | 303 // Reset the parser to have 3 tracks: text, video (no default frame duration), |
311 // and audio (with a default frame duration). | 304 // and audio (with a default frame duration). |
312 TextTracks text_tracks; | 305 TextTracks text_tracks; |
313 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), | 306 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), |
314 TextTrackConfig(kTextSubtitles, "", "", | 307 TextTrackConfig(kTextSubtitles, "", "", |
315 ""))); | 308 ""))); |
316 base::TimeDelta default_audio_duration = | 309 base::TimeDelta default_audio_duration = |
317 base::TimeDelta::FromMilliseconds(kTestAudioFrameDefaultDurationInMs); | 310 base::TimeDelta::FromMilliseconds(kTestAudioFrameDefaultDurationInMs); |
318 ASSERT_GE(default_audio_duration, base::TimeDelta()); | 311 ASSERT_GE(default_audio_duration, base::TimeDelta()); |
319 ASSERT_NE(kNoTimestamp(), default_audio_duration); | 312 ASSERT_NE(kNoTimestamp(), default_audio_duration); |
320 parser_.reset(new WebMClusterParser(kTimecodeScale, | 313 parser_.reset(new WebMClusterParser( |
321 kAudioTrackNum, | 314 kTimecodeScale, kAudioTrackNum, default_audio_duration, kVideoTrackNum, |
322 default_audio_duration, | 315 kNoTimestamp(), text_tracks, std::set<int64>(), std::string(), |
323 kVideoTrackNum, | 316 std::string(), kUnknownAudioCodec, new MediaLog())); |
324 kNoTimestamp(), | |
325 text_tracks, | |
326 std::set<int64>(), | |
327 std::string(), | |
328 std::string(), | |
329 kUnknownAudioCodec, | |
330 LogCB())); | |
331 | 317 |
332 const BlockInfo kBlockInfo[] = { | 318 const BlockInfo kBlockInfo[] = { |
333 {kVideoTrackNum, 0, 33, true, NULL, 0}, | 319 {kVideoTrackNum, 0, 33, true, NULL, 0}, |
334 {kAudioTrackNum, 0, 23, false, NULL, 0}, | 320 {kAudioTrackNum, 0, 23, false, NULL, 0}, |
335 {kTextTrackNum, 10, 42, false, NULL, 0}, | 321 {kTextTrackNum, 10, 42, false, NULL, 0}, |
336 {kAudioTrackNum, 23, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, | 322 {kAudioTrackNum, 23, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
337 {kVideoTrackNum, 33, 33, true, NULL, 0}, | 323 {kVideoTrackNum, 33, 33, true, NULL, 0}, |
338 {kAudioTrackNum, 36, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, | 324 {kAudioTrackNum, 36, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
339 {kVideoTrackNum, 66, 33, true, NULL, 0}, | 325 {kVideoTrackNum, 66, 33, true, NULL, 0}, |
340 {kAudioTrackNum, 70, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, | 326 {kAudioTrackNum, 70, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
503 | 489 |
504 int result = parser_->Parse(cluster->data(), cluster->size()); | 490 int result = parser_->Parse(cluster->data(), cluster->size()); |
505 EXPECT_EQ(cluster->size(), result); | 491 EXPECT_EQ(cluster->size(), result); |
506 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | 492 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); |
507 } | 493 } |
508 | 494 |
509 TEST_F(WebMClusterParserTest, IgnoredTracks) { | 495 TEST_F(WebMClusterParserTest, IgnoredTracks) { |
510 std::set<int64> ignored_tracks; | 496 std::set<int64> ignored_tracks; |
511 ignored_tracks.insert(kTextTrackNum); | 497 ignored_tracks.insert(kTextTrackNum); |
512 | 498 |
513 parser_.reset(new WebMClusterParser(kTimecodeScale, | 499 parser_.reset(new WebMClusterParser( |
514 kAudioTrackNum, | 500 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, |
515 kNoTimestamp(), | 501 kNoTimestamp(), TextTracks(), ignored_tracks, std::string(), |
516 kVideoTrackNum, | 502 std::string(), kUnknownAudioCodec, new MediaLog())); |
517 kNoTimestamp(), | |
518 TextTracks(), | |
519 ignored_tracks, | |
520 std::string(), | |
521 std::string(), | |
522 kUnknownAudioCodec, | |
523 LogCB())); | |
524 | 503 |
525 const BlockInfo kInputBlockInfo[] = { | 504 const BlockInfo kInputBlockInfo[] = { |
526 {kAudioTrackNum, 0, 23, true, NULL, 0}, | 505 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
527 {kAudioTrackNum, 23, 23, true, NULL, 0}, | 506 {kAudioTrackNum, 23, 23, true, NULL, 0}, |
528 {kVideoTrackNum, 33, 34, true, NULL, 0}, | 507 {kVideoTrackNum, 33, 34, true, NULL, 0}, |
529 {kTextTrackNum, 33, 99, true, NULL, 0}, | 508 {kTextTrackNum, 33, 99, true, NULL, 0}, |
530 {kAudioTrackNum, 46, 23, true, NULL, 0}, | 509 {kAudioTrackNum, 46, 23, true, NULL, 0}, |
531 {kVideoTrackNum, 67, 34, true, NULL, 0}, | 510 {kVideoTrackNum, 67, 34, true, NULL, 0}, |
532 }; | 511 }; |
533 int input_block_count = arraysize(kInputBlockInfo); | 512 int input_block_count = arraysize(kInputBlockInfo); |
(...skipping 15 matching lines...) Expand all Loading... | |
549 ASSERT_TRUE(VerifyBuffers(parser_, kOutputBlockInfo, output_block_count)); | 528 ASSERT_TRUE(VerifyBuffers(parser_, kOutputBlockInfo, output_block_count)); |
550 } | 529 } |
551 | 530 |
552 TEST_F(WebMClusterParserTest, ParseTextTracks) { | 531 TEST_F(WebMClusterParserTest, ParseTextTracks) { |
553 TextTracks text_tracks; | 532 TextTracks text_tracks; |
554 | 533 |
555 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), | 534 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), |
556 TextTrackConfig(kTextSubtitles, "", "", | 535 TextTrackConfig(kTextSubtitles, "", "", |
557 ""))); | 536 ""))); |
558 | 537 |
559 parser_.reset(new WebMClusterParser(kTimecodeScale, | 538 parser_.reset(new WebMClusterParser( |
560 kAudioTrackNum, | 539 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, |
561 kNoTimestamp(), | 540 kNoTimestamp(), text_tracks, std::set<int64>(), std::string(), |
562 kVideoTrackNum, | 541 std::string(), kUnknownAudioCodec, new MediaLog())); |
563 kNoTimestamp(), | |
564 text_tracks, | |
565 std::set<int64>(), | |
566 std::string(), | |
567 std::string(), | |
568 kUnknownAudioCodec, | |
569 LogCB())); | |
570 | 542 |
571 const BlockInfo kInputBlockInfo[] = { | 543 const BlockInfo kInputBlockInfo[] = { |
572 {kAudioTrackNum, 0, 23, true, NULL, 0}, | 544 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
573 {kAudioTrackNum, 23, 23, true, NULL, 0}, | 545 {kAudioTrackNum, 23, 23, true, NULL, 0}, |
574 {kVideoTrackNum, 33, 34, true, NULL, 0}, | 546 {kVideoTrackNum, 33, 34, true, NULL, 0}, |
575 {kTextTrackNum, 33, 42, false, NULL, 0}, | 547 {kTextTrackNum, 33, 42, false, NULL, 0}, |
576 {kAudioTrackNum, 46, 23, true, NULL, 0}, | 548 {kAudioTrackNum, 46, 23, true, NULL, 0}, |
577 {kTextTrackNum, 55, 44, false, NULL, 0}, | 549 {kTextTrackNum, 55, 44, false, NULL, 0}, |
578 {kVideoTrackNum, 67, 34, true, NULL, 0}, | 550 {kVideoTrackNum, 67, 34, true, NULL, 0}, |
579 }; | 551 }; |
580 int input_block_count = arraysize(kInputBlockInfo); | 552 int input_block_count = arraysize(kInputBlockInfo); |
581 | 553 |
582 scoped_ptr<Cluster> cluster( | 554 scoped_ptr<Cluster> cluster( |
583 CreateCluster(0, kInputBlockInfo, input_block_count)); | 555 CreateCluster(0, kInputBlockInfo, input_block_count)); |
584 | 556 |
585 int result = parser_->Parse(cluster->data(), cluster->size()); | 557 int result = parser_->Parse(cluster->data(), cluster->size()); |
586 EXPECT_EQ(cluster->size(), result); | 558 EXPECT_EQ(cluster->size(), result); |
587 ASSERT_TRUE(VerifyBuffers(parser_, kInputBlockInfo, input_block_count)); | 559 ASSERT_TRUE(VerifyBuffers(parser_, kInputBlockInfo, input_block_count)); |
588 } | 560 } |
589 | 561 |
590 TEST_F(WebMClusterParserTest, TextTracksSimpleBlock) { | 562 TEST_F(WebMClusterParserTest, TextTracksSimpleBlock) { |
591 TextTracks text_tracks; | 563 TextTracks text_tracks; |
592 | 564 |
593 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), | 565 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), |
594 TextTrackConfig(kTextSubtitles, "", "", | 566 TextTrackConfig(kTextSubtitles, "", "", |
595 ""))); | 567 ""))); |
596 | 568 |
597 parser_.reset(new WebMClusterParser(kTimecodeScale, | 569 parser_.reset(new WebMClusterParser( |
598 kAudioTrackNum, | 570 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, |
599 kNoTimestamp(), | 571 kNoTimestamp(), text_tracks, std::set<int64>(), std::string(), |
600 kVideoTrackNum, | 572 std::string(), kUnknownAudioCodec, new MediaLog())); |
601 kNoTimestamp(), | |
602 text_tracks, | |
603 std::set<int64>(), | |
604 std::string(), | |
605 std::string(), | |
606 kUnknownAudioCodec, | |
607 LogCB())); | |
608 | 573 |
609 const BlockInfo kInputBlockInfo[] = { | 574 const BlockInfo kInputBlockInfo[] = { |
610 { kTextTrackNum, 33, 42, true }, | 575 { kTextTrackNum, 33, 42, true }, |
611 }; | 576 }; |
612 int input_block_count = arraysize(kInputBlockInfo); | 577 int input_block_count = arraysize(kInputBlockInfo); |
613 | 578 |
614 scoped_ptr<Cluster> cluster( | 579 scoped_ptr<Cluster> cluster( |
615 CreateCluster(0, kInputBlockInfo, input_block_count)); | 580 CreateCluster(0, kInputBlockInfo, input_block_count)); |
616 | 581 |
617 int result = parser_->Parse(cluster->data(), cluster->size()); | 582 int result = parser_->Parse(cluster->data(), cluster->size()); |
618 EXPECT_LT(result, 0); | 583 EXPECT_LT(result, 0); |
619 } | 584 } |
620 | 585 |
621 TEST_F(WebMClusterParserTest, ParseMultipleTextTracks) { | 586 TEST_F(WebMClusterParserTest, ParseMultipleTextTracks) { |
622 TextTracks text_tracks; | 587 TextTracks text_tracks; |
623 | 588 |
624 const int kSubtitleTextTrackNum = kTextTrackNum; | 589 const int kSubtitleTextTrackNum = kTextTrackNum; |
625 const int kCaptionTextTrackNum = kTextTrackNum + 1; | 590 const int kCaptionTextTrackNum = kTextTrackNum + 1; |
626 | 591 |
627 text_tracks.insert(std::make_pair(TextTracks::key_type(kSubtitleTextTrackNum), | 592 text_tracks.insert(std::make_pair(TextTracks::key_type(kSubtitleTextTrackNum), |
628 TextTrackConfig(kTextSubtitles, "", "", | 593 TextTrackConfig(kTextSubtitles, "", "", |
629 ""))); | 594 ""))); |
630 | 595 |
631 text_tracks.insert(std::make_pair(TextTracks::key_type(kCaptionTextTrackNum), | 596 text_tracks.insert(std::make_pair(TextTracks::key_type(kCaptionTextTrackNum), |
632 TextTrackConfig(kTextCaptions, "", "", | 597 TextTrackConfig(kTextCaptions, "", "", |
633 ""))); | 598 ""))); |
634 | 599 |
635 parser_.reset(new WebMClusterParser(kTimecodeScale, | 600 parser_.reset(new WebMClusterParser( |
636 kAudioTrackNum, | 601 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, |
637 kNoTimestamp(), | 602 kNoTimestamp(), text_tracks, std::set<int64>(), std::string(), |
638 kVideoTrackNum, | 603 std::string(), kUnknownAudioCodec, new MediaLog())); |
639 kNoTimestamp(), | |
640 text_tracks, | |
641 std::set<int64>(), | |
642 std::string(), | |
643 std::string(), | |
644 kUnknownAudioCodec, | |
645 LogCB())); | |
646 | 604 |
647 const BlockInfo kInputBlockInfo[] = { | 605 const BlockInfo kInputBlockInfo[] = { |
648 {kAudioTrackNum, 0, 23, true, NULL, 0}, | 606 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
649 {kAudioTrackNum, 23, 23, true, NULL, 0}, | 607 {kAudioTrackNum, 23, 23, true, NULL, 0}, |
650 {kVideoTrackNum, 33, 34, true, NULL, 0}, | 608 {kVideoTrackNum, 33, 34, true, NULL, 0}, |
651 {kSubtitleTextTrackNum, 33, 42, false, NULL, 0}, | 609 {kSubtitleTextTrackNum, 33, 42, false, NULL, 0}, |
652 {kAudioTrackNum, 46, 23, true, NULL, 0}, | 610 {kAudioTrackNum, 46, 23, true, NULL, 0}, |
653 {kCaptionTextTrackNum, 55, 44, false, NULL, 0}, | 611 {kCaptionTextTrackNum, 55, 44, false, NULL, 0}, |
654 {kVideoTrackNum, 67, 34, true, NULL, 0}, | 612 {kVideoTrackNum, 67, 34, true, NULL, 0}, |
655 {kSubtitleTextTrackNum, 67, 33, false, NULL, 0}, | 613 {kSubtitleTextTrackNum, 67, 33, false, NULL, 0}, |
(...skipping 16 matching lines...) Expand all Loading... | |
672 text_tracks.find(itr->first); | 630 text_tracks.find(itr->first); |
673 ASSERT_TRUE(find_result != text_tracks.end()); | 631 ASSERT_TRUE(find_result != text_tracks.end()); |
674 ASSERT_TRUE(VerifyTextBuffers(parser_, kInputBlockInfo, input_block_count, | 632 ASSERT_TRUE(VerifyTextBuffers(parser_, kInputBlockInfo, input_block_count, |
675 itr->first, itr->second)); | 633 itr->first, itr->second)); |
676 } | 634 } |
677 } | 635 } |
678 | 636 |
679 TEST_F(WebMClusterParserTest, ParseEncryptedBlock) { | 637 TEST_F(WebMClusterParserTest, ParseEncryptedBlock) { |
680 scoped_ptr<Cluster> cluster(CreateEncryptedCluster(sizeof(kEncryptedFrame))); | 638 scoped_ptr<Cluster> cluster(CreateEncryptedCluster(sizeof(kEncryptedFrame))); |
681 | 639 |
682 parser_.reset(new WebMClusterParser(kTimecodeScale, | 640 parser_.reset(new WebMClusterParser( |
683 kAudioTrackNum, | 641 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, |
684 kNoTimestamp(), | 642 kNoTimestamp(), TextTracks(), std::set<int64>(), std::string(), |
685 kVideoTrackNum, | 643 "video_key_id", kUnknownAudioCodec, new MediaLog())); |
686 kNoTimestamp(), | |
687 TextTracks(), | |
688 std::set<int64>(), | |
689 std::string(), | |
690 "video_key_id", | |
691 kUnknownAudioCodec, | |
692 LogCB())); | |
693 int result = parser_->Parse(cluster->data(), cluster->size()); | 644 int result = parser_->Parse(cluster->data(), cluster->size()); |
694 EXPECT_EQ(cluster->size(), result); | 645 EXPECT_EQ(cluster->size(), result); |
695 ASSERT_EQ(1UL, parser_->GetVideoBuffers().size()); | 646 ASSERT_EQ(1UL, parser_->GetVideoBuffers().size()); |
696 scoped_refptr<StreamParserBuffer> buffer = parser_->GetVideoBuffers()[0]; | 647 scoped_refptr<StreamParserBuffer> buffer = parser_->GetVideoBuffers()[0]; |
697 VerifyEncryptedBuffer(buffer); | 648 VerifyEncryptedBuffer(buffer); |
698 } | 649 } |
699 | 650 |
700 TEST_F(WebMClusterParserTest, ParseBadEncryptedBlock) { | 651 TEST_F(WebMClusterParserTest, ParseBadEncryptedBlock) { |
701 scoped_ptr<Cluster> cluster( | 652 scoped_ptr<Cluster> cluster( |
702 CreateEncryptedCluster(sizeof(kEncryptedFrame) - 1)); | 653 CreateEncryptedCluster(sizeof(kEncryptedFrame) - 1)); |
703 | 654 |
704 parser_.reset(new WebMClusterParser(kTimecodeScale, | 655 parser_.reset(new WebMClusterParser( |
705 kAudioTrackNum, | 656 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, |
706 kNoTimestamp(), | 657 kNoTimestamp(), TextTracks(), std::set<int64>(), std::string(), |
707 kVideoTrackNum, | 658 "video_key_id", kUnknownAudioCodec, new MediaLog())); |
708 kNoTimestamp(), | |
709 TextTracks(), | |
710 std::set<int64>(), | |
711 std::string(), | |
712 "video_key_id", | |
713 kUnknownAudioCodec, | |
714 LogCB())); | |
715 int result = parser_->Parse(cluster->data(), cluster->size()); | 659 int result = parser_->Parse(cluster->data(), cluster->size()); |
716 EXPECT_EQ(-1, result); | 660 EXPECT_EQ(-1, result); |
717 } | 661 } |
718 | 662 |
719 TEST_F(WebMClusterParserTest, ParseInvalidZeroSizedCluster) { | 663 TEST_F(WebMClusterParserTest, ParseInvalidZeroSizedCluster) { |
720 const uint8_t kBuffer[] = { | 664 const uint8_t kBuffer[] = { |
721 0x1F, 0x43, 0xB6, 0x75, 0x80, // CLUSTER (size = 0) | 665 0x1F, 0x43, 0xB6, 0x75, 0x80, // CLUSTER (size = 0) |
722 }; | 666 }; |
723 | 667 |
724 EXPECT_EQ(-1, parser_->Parse(kBuffer, sizeof(kBuffer))); | 668 EXPECT_EQ(-1, parser_->Parse(kBuffer, sizeof(kBuffer))); |
725 } | 669 } |
726 | 670 |
727 TEST_F(WebMClusterParserTest, ParseInvalidUnknownButActuallyZeroSizedCluster) { | 671 TEST_F(WebMClusterParserTest, ParseInvalidUnknownButActuallyZeroSizedCluster) { |
728 const uint8_t kBuffer[] = { | 672 const uint8_t kBuffer[] = { |
729 0x1F, 0x43, 0xB6, 0x75, 0xFF, // CLUSTER (size = "unknown") | 673 0x1F, 0x43, 0xB6, 0x75, 0xFF, // CLUSTER (size = "unknown") |
730 0x1F, 0x43, 0xB6, 0x75, 0x85, // CLUSTER (size = 5) | 674 0x1F, 0x43, 0xB6, 0x75, 0x85, // CLUSTER (size = 5) |
731 }; | 675 }; |
732 | 676 |
733 EXPECT_EQ(-1, parser_->Parse(kBuffer, sizeof(kBuffer))); | 677 EXPECT_EQ(-1, parser_->Parse(kBuffer, sizeof(kBuffer))); |
734 } | 678 } |
735 | 679 |
736 TEST_F(WebMClusterParserTest, ParseInvalidTextBlockGroupWithoutDuration) { | 680 TEST_F(WebMClusterParserTest, ParseInvalidTextBlockGroupWithoutDuration) { |
737 // Text track frames must have explicitly specified BlockGroup BlockDurations. | 681 // Text track frames must have explicitly specified BlockGroup BlockDurations. |
738 TextTracks text_tracks; | 682 TextTracks text_tracks; |
739 | 683 |
740 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), | 684 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), |
741 TextTrackConfig(kTextSubtitles, "", "", | 685 TextTrackConfig(kTextSubtitles, "", "", |
742 ""))); | 686 ""))); |
743 | 687 |
744 parser_.reset(new WebMClusterParser(kTimecodeScale, | 688 parser_.reset(new WebMClusterParser( |
745 kAudioTrackNum, | 689 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, |
746 kNoTimestamp(), | 690 kNoTimestamp(), text_tracks, std::set<int64>(), std::string(), |
747 kVideoTrackNum, | 691 std::string(), kUnknownAudioCodec, new MediaLog())); |
748 kNoTimestamp(), | |
749 text_tracks, | |
750 std::set<int64>(), | |
751 std::string(), | |
752 std::string(), | |
753 kUnknownAudioCodec, | |
754 LogCB())); | |
755 | 692 |
756 const BlockInfo kBlockInfo[] = { | 693 const BlockInfo kBlockInfo[] = { |
757 { kTextTrackNum, 33, -42, false }, | 694 { kTextTrackNum, 33, -42, false }, |
758 }; | 695 }; |
759 int block_count = arraysize(kBlockInfo); | 696 int block_count = arraysize(kBlockInfo); |
760 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 697 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
761 int result = parser_->Parse(cluster->data(), cluster->size()); | 698 int result = parser_->Parse(cluster->data(), cluster->size()); |
762 EXPECT_LT(result, 0); | 699 EXPECT_LT(result, 0); |
763 } | 700 } |
764 | 701 |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
995 int result = parser_->Parse(cluster->data(), cluster->size()); | 932 int result = parser_->Parse(cluster->data(), cluster->size()); |
996 EXPECT_EQ(cluster->size(), result); | 933 EXPECT_EQ(cluster->size(), result); |
997 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | 934 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); |
998 } | 935 } |
999 | 936 |
1000 TEST_F(WebMClusterParserTest, ReadOpusDurationsSimpleBlockAtEndOfCluster) { | 937 TEST_F(WebMClusterParserTest, ReadOpusDurationsSimpleBlockAtEndOfCluster) { |
1001 // Reset parser to expect Opus codec audio. | 938 // Reset parser to expect Opus codec audio. |
1002 parser_.reset(new WebMClusterParser( | 939 parser_.reset(new WebMClusterParser( |
1003 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, | 940 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, |
1004 kNoTimestamp(), TextTracks(), std::set<int64>(), std::string(), | 941 kNoTimestamp(), TextTracks(), std::set<int64>(), std::string(), |
1005 std::string(), kCodecOpus, LogCB())); | 942 std::string(), kCodecOpus, new MediaLog())); |
1006 | 943 |
1007 int loop_count = 0; | 944 int loop_count = 0; |
1008 for (const auto* packet_ptr : BuildAllOpusPackets()) { | 945 for (const auto* packet_ptr : BuildAllOpusPackets()) { |
1009 const BlockInfo kBlockInfo[] = {{kAudioTrackNum, | 946 const BlockInfo kBlockInfo[] = {{kAudioTrackNum, |
1010 0, | 947 0, |
1011 packet_ptr->duration_ms(), | 948 packet_ptr->duration_ms(), |
1012 true, // Make it a SimpleBlock. | 949 true, // Make it a SimpleBlock. |
1013 packet_ptr->data(), | 950 packet_ptr->data(), |
1014 packet_ptr->size()}}; | 951 packet_ptr->size()}}; |
1015 | 952 |
1016 int block_count = arraysize(kBlockInfo); | 953 int block_count = arraysize(kBlockInfo); |
1017 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 954 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
1018 int result = parser_->Parse(cluster->data(), cluster->size()); | 955 int result = parser_->Parse(cluster->data(), cluster->size()); |
1019 EXPECT_EQ(cluster->size(), result); | 956 EXPECT_EQ(cluster->size(), result); |
1020 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | 957 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); |
1021 loop_count++; | 958 loop_count++; |
1022 } | 959 } |
1023 | 960 |
1024 // Test should minimally cover all the combinations of config and frame count. | 961 // Test should minimally cover all the combinations of config and frame count. |
1025 ASSERT_GE(loop_count, kNumPossibleOpusConfigs * kMaxOpusPacketFrameCount); | 962 ASSERT_GE(loop_count, kNumPossibleOpusConfigs * kMaxOpusPacketFrameCount); |
1026 } | 963 } |
1027 | 964 |
1028 TEST_F(WebMClusterParserTest, PreferOpusDurationsOverBlockDurations) { | 965 TEST_F(WebMClusterParserTest, PreferOpusDurationsOverBlockDurations) { |
1029 // Reset parser to expect Opus codec audio. | 966 // Reset parser to expect Opus codec audio. |
1030 parser_.reset(new WebMClusterParser( | 967 parser_.reset(new WebMClusterParser( |
1031 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, | 968 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, |
1032 kNoTimestamp(), TextTracks(), std::set<int64>(), std::string(), | 969 kNoTimestamp(), TextTracks(), std::set<int64>(), std::string(), |
1033 std::string(), kCodecOpus, LogCB())); | 970 std::string(), kCodecOpus, new MediaLog())); |
1034 | 971 |
1035 int loop_count = 0; | 972 int loop_count = 0; |
1036 for (const auto* packet_ptr : BuildAllOpusPackets()) { | 973 for (const auto* packet_ptr : BuildAllOpusPackets()) { |
1037 // Setting BlockDuration != Opus duration to see which one the parser uses. | 974 // Setting BlockDuration != Opus duration to see which one the parser uses. |
1038 int block_duration_ms = packet_ptr->duration_ms() + 10; | 975 int block_duration_ms = packet_ptr->duration_ms() + 10; |
1039 | 976 |
1040 BlockInfo block_infos[] = {{kAudioTrackNum, | 977 BlockInfo block_infos[] = {{kAudioTrackNum, |
1041 0, | 978 0, |
1042 block_duration_ms, | 979 block_duration_ms, |
1043 false, // Not a SimpleBlock. | 980 false, // Not a SimpleBlock. |
(...skipping 21 matching lines...) Expand all Loading... | |
1065 // encoded duration in Opus packet (or hard coded duration estimates). Encoded | 1002 // encoded duration in Opus packet (or hard coded duration estimates). Encoded |
1066 // Opus duration is usually preferred but cannot be known when encrypted. | 1003 // Opus duration is usually preferred but cannot be known when encrypted. |
1067 TEST_F(WebMClusterParserTest, DontReadEncodedDurationWhenEncrypted) { | 1004 TEST_F(WebMClusterParserTest, DontReadEncodedDurationWhenEncrypted) { |
1068 // Non-empty dummy value signals encryption is active for audio. | 1005 // Non-empty dummy value signals encryption is active for audio. |
1069 std::string audio_encryption_id("audio_key_id"); | 1006 std::string audio_encryption_id("audio_key_id"); |
1070 | 1007 |
1071 // Reset parser to expect Opus codec audio and use audio encryption key id. | 1008 // Reset parser to expect Opus codec audio and use audio encryption key id. |
1072 parser_.reset(new WebMClusterParser( | 1009 parser_.reset(new WebMClusterParser( |
1073 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, | 1010 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, |
1074 kNoTimestamp(), TextTracks(), std::set<int64>(), audio_encryption_id, | 1011 kNoTimestamp(), TextTracks(), std::set<int64>(), audio_encryption_id, |
1075 std::string(), kCodecOpus, LogCB())); | 1012 std::string(), kCodecOpus, new MediaLog())); |
1076 | 1013 |
1077 // Single Block with BlockDuration and encrypted data. | 1014 // Single Block with BlockDuration and encrypted data. |
1078 const BlockInfo kBlockInfo[] = {{kAudioTrackNum, | 1015 const BlockInfo kBlockInfo[] = {{kAudioTrackNum, |
1079 0, | 1016 0, |
1080 kTestAudioFrameDefaultDurationInMs, | 1017 kTestAudioFrameDefaultDurationInMs, |
1081 false, // Not a SimpleBlock | 1018 false, // Not a SimpleBlock |
1082 kEncryptedFrame, // Encrypted frame data | 1019 kEncryptedFrame, // Encrypted frame data |
1083 arraysize(kEncryptedFrame)}}; | 1020 arraysize(kEncryptedFrame)}}; |
1084 | 1021 |
1085 int block_count = arraysize(kBlockInfo); | 1022 int block_count = arraysize(kBlockInfo); |
1086 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 1023 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
1087 int result = parser_->Parse(cluster->data(), cluster->size()); | 1024 int result = parser_->Parse(cluster->data(), cluster->size()); |
1088 EXPECT_EQ(cluster->size(), result); | 1025 EXPECT_EQ(cluster->size(), result); |
1089 | 1026 |
1090 // Will verify that duration of buffer matches that of BlockDuration. | 1027 // Will verify that duration of buffer matches that of BlockDuration. |
1091 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | 1028 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); |
1092 } | 1029 } |
1093 | 1030 |
1094 } // namespace media | 1031 } // namespace media |
OLD | NEW |