| 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 "media/formats/webm/webm_cluster_parser.h" |
| 6 |
| 5 #include <stddef.h> | 7 #include <stddef.h> |
| 6 #include <stdint.h> | 8 #include <stdint.h> |
| 7 | 9 |
| 8 #include <algorithm> | 10 #include <algorithm> |
| 9 #include <cstdlib> | 11 #include <cstdlib> |
| 12 #include <memory> |
| 10 #include <string> | 13 #include <string> |
| 11 #include <vector> | 14 #include <vector> |
| 12 | 15 |
| 13 #include "base/bind.h" | 16 #include "base/bind.h" |
| 14 #include "base/logging.h" | 17 #include "base/logging.h" |
| 15 #include "base/macros.h" | 18 #include "base/macros.h" |
| 16 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 17 #include "media/base/audio_decoder_config.h" | 20 #include "media/base/audio_decoder_config.h" |
| 18 #include "media/base/decrypt_config.h" | 21 #include "media/base/decrypt_config.h" |
| 19 #include "media/base/mock_media_log.h" | 22 #include "media/base/mock_media_log.h" |
| 20 #include "media/base/timestamp_constants.h" | 23 #include "media/base/timestamp_constants.h" |
| 21 #include "media/formats/webm/cluster_builder.h" | 24 #include "media/formats/webm/cluster_builder.h" |
| 22 #include "media/formats/webm/opus_packet_builder.h" | 25 #include "media/formats/webm/opus_packet_builder.h" |
| 23 #include "media/formats/webm/webm_cluster_parser.h" | |
| 24 #include "media/formats/webm/webm_constants.h" | 26 #include "media/formats/webm/webm_constants.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 29 |
| 28 using ::testing::HasSubstr; | 30 using ::testing::HasSubstr; |
| 29 using ::testing::InSequence; | 31 using ::testing::InSequence; |
| 30 using ::testing::Return; | 32 using ::testing::Return; |
| 31 using ::testing::StrictMock; | 33 using ::testing::StrictMock; |
| 32 using ::testing::Mock; | 34 using ::testing::Mock; |
| 33 using ::testing::_; | 35 using ::testing::_; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 {kVideoTrackNum, 100, 33, false, NULL, 0}, | 116 {kVideoTrackNum, 100, 33, false, NULL, 0}, |
| 115 }; | 117 }; |
| 116 | 118 |
| 117 const uint8_t kEncryptedFrame[] = { | 119 const uint8_t kEncryptedFrame[] = { |
| 118 // Block is encrypted | 120 // Block is encrypted |
| 119 0x01, | 121 0x01, |
| 120 | 122 |
| 121 // IV | 123 // IV |
| 122 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}; | 124 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}; |
| 123 | 125 |
| 124 scoped_ptr<Cluster> CreateCluster(int timecode, | 126 std::unique_ptr<Cluster> CreateCluster(int timecode, |
| 125 const BlockInfo* block_info, | 127 const BlockInfo* block_info, |
| 126 int block_count) { | 128 int block_count) { |
| 127 ClusterBuilder cb; | 129 ClusterBuilder cb; |
| 128 cb.SetClusterTimecode(0); | 130 cb.SetClusterTimecode(0); |
| 129 | 131 |
| 130 uint8_t kDefaultBlockData[] = { 0x00 }; | 132 uint8_t kDefaultBlockData[] = { 0x00 }; |
| 131 | 133 |
| 132 for (int i = 0; i < block_count; i++) { | 134 for (int i = 0; i < block_count; i++) { |
| 133 const uint8_t* data; | 135 const uint8_t* data; |
| 134 int data_length; | 136 int data_length; |
| 135 if (block_info[i].data != NULL) { | 137 if (block_info[i].data != NULL) { |
| 136 data = block_info[i].data; | 138 data = block_info[i].data; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 156 | 158 |
| 157 cb.AddBlockGroup(block_info[i].track_num, block_info[i].timestamp, | 159 cb.AddBlockGroup(block_info[i].track_num, block_info[i].timestamp, |
| 158 block_info[i].duration, 0, data, data_length); | 160 block_info[i].duration, 0, data, data_length); |
| 159 } | 161 } |
| 160 | 162 |
| 161 return cb.Finish(); | 163 return cb.Finish(); |
| 162 } | 164 } |
| 163 | 165 |
| 164 // Creates a Cluster with one encrypted Block. |bytes_to_write| is number of | 166 // Creates a Cluster with one encrypted Block. |bytes_to_write| is number of |
| 165 // bytes of the encrypted frame to write. | 167 // bytes of the encrypted frame to write. |
| 166 scoped_ptr<Cluster> CreateEncryptedCluster(int bytes_to_write) { | 168 std::unique_ptr<Cluster> CreateEncryptedCluster(int bytes_to_write) { |
| 167 CHECK_GT(bytes_to_write, 0); | 169 CHECK_GT(bytes_to_write, 0); |
| 168 CHECK_LE(bytes_to_write, static_cast<int>(sizeof(kEncryptedFrame))); | 170 CHECK_LE(bytes_to_write, static_cast<int>(sizeof(kEncryptedFrame))); |
| 169 | 171 |
| 170 ClusterBuilder cb; | 172 ClusterBuilder cb; |
| 171 cb.SetClusterTimecode(0); | 173 cb.SetClusterTimecode(0); |
| 172 cb.AddSimpleBlock(kVideoTrackNum, 0, 0, kEncryptedFrame, bytes_to_write); | 174 cb.AddSimpleBlock(kVideoTrackNum, 0, 0, kEncryptedFrame, bytes_to_write); |
| 173 return cb.Finish(); | 175 return cb.Finish(); |
| 174 } | 176 } |
| 175 | 177 |
| 176 bool VerifyBuffers(const WebMClusterParser::BufferQueue& audio_buffers, | 178 bool VerifyBuffers(const WebMClusterParser::BufferQueue& audio_buffers, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 EXPECT_EQ(block_info[i].timestamp, buffer->timestamp().InMilliseconds()); | 225 EXPECT_EQ(block_info[i].timestamp, buffer->timestamp().InMilliseconds()); |
| 224 EXPECT_EQ(std::abs(block_info[i].duration), | 226 EXPECT_EQ(std::abs(block_info[i].duration), |
| 225 buffer->duration().InMillisecondsF()); | 227 buffer->duration().InMillisecondsF()); |
| 226 EXPECT_EQ(expected_type, buffer->type()); | 228 EXPECT_EQ(expected_type, buffer->type()); |
| 227 EXPECT_EQ(block_info[i].track_num, buffer->track_id()); | 229 EXPECT_EQ(block_info[i].track_num, buffer->track_id()); |
| 228 } | 230 } |
| 229 | 231 |
| 230 return true; | 232 return true; |
| 231 } | 233 } |
| 232 | 234 |
| 233 bool VerifyBuffers(const scoped_ptr<WebMClusterParser>& parser, | 235 bool VerifyBuffers(const std::unique_ptr<WebMClusterParser>& parser, |
| 234 const BlockInfo* block_info, | 236 const BlockInfo* block_info, |
| 235 int block_count) { | 237 int block_count) { |
| 236 const WebMClusterParser::TextBufferQueueMap& text_map = | 238 const WebMClusterParser::TextBufferQueueMap& text_map = |
| 237 parser->GetTextBuffers(); | 239 parser->GetTextBuffers(); |
| 238 const WebMClusterParser::BufferQueue* text_buffers; | 240 const WebMClusterParser::BufferQueue* text_buffers; |
| 239 const WebMClusterParser::BufferQueue no_text_buffers; | 241 const WebMClusterParser::BufferQueue no_text_buffers; |
| 240 if (!text_map.empty()) | 242 if (!text_map.empty()) |
| 241 text_buffers = &(text_map.rbegin()->second); | 243 text_buffers = &(text_map.rbegin()->second); |
| 242 else | 244 else |
| 243 text_buffers = &no_text_buffers; | 245 text_buffers = &no_text_buffers; |
| 244 | 246 |
| 245 return VerifyBuffers(parser->GetAudioBuffers(), | 247 return VerifyBuffers(parser->GetAudioBuffers(), |
| 246 parser->GetVideoBuffers(), | 248 parser->GetVideoBuffers(), |
| 247 *text_buffers, | 249 *text_buffers, |
| 248 block_info, | 250 block_info, |
| 249 block_count); | 251 block_count); |
| 250 } | 252 } |
| 251 | 253 |
| 252 bool VerifyTextBuffers(const scoped_ptr<WebMClusterParser>& parser, | 254 bool VerifyTextBuffers(const std::unique_ptr<WebMClusterParser>& parser, |
| 253 const BlockInfo* block_info_ptr, | 255 const BlockInfo* block_info_ptr, |
| 254 int block_count, | 256 int block_count, |
| 255 int text_track_num, | 257 int text_track_num, |
| 256 const WebMClusterParser::BufferQueue& text_buffers) { | 258 const WebMClusterParser::BufferQueue& text_buffers) { |
| 257 const BlockInfo* const block_info_end = block_info_ptr + block_count; | 259 const BlockInfo* const block_info_end = block_info_ptr + block_count; |
| 258 | 260 |
| 259 typedef WebMClusterParser::BufferQueue::const_iterator TextBufferIter; | 261 typedef WebMClusterParser::BufferQueue::const_iterator TextBufferIter; |
| 260 TextBufferIter buffer_iter = text_buffers.begin(); | 262 TextBufferIter buffer_iter = text_buffers.begin(); |
| 261 const TextBufferIter buffer_end = text_buffers.end(); | 263 const TextBufferIter buffer_end = text_buffers.end(); |
| 262 | 264 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 WebMClusterParser* CreateParserWithKeyIdsAndAudioCodec( | 366 WebMClusterParser* CreateParserWithKeyIdsAndAudioCodec( |
| 365 const std::string& audio_encryption_key_id, | 367 const std::string& audio_encryption_key_id, |
| 366 const std::string& video_encryption_key_id, | 368 const std::string& video_encryption_key_id, |
| 367 const AudioCodec audio_codec) { | 369 const AudioCodec audio_codec) { |
| 368 return CreateParserHelper(kNoTimestamp(), kNoTimestamp(), TextTracks(), | 370 return CreateParserHelper(kNoTimestamp(), kNoTimestamp(), TextTracks(), |
| 369 std::set<int64_t>(), audio_encryption_key_id, | 371 std::set<int64_t>(), audio_encryption_key_id, |
| 370 video_encryption_key_id, audio_codec); | 372 video_encryption_key_id, audio_codec); |
| 371 } | 373 } |
| 372 | 374 |
| 373 scoped_refptr<StrictMock<MockMediaLog>> media_log_; | 375 scoped_refptr<StrictMock<MockMediaLog>> media_log_; |
| 374 scoped_ptr<WebMClusterParser> parser_; | 376 std::unique_ptr<WebMClusterParser> parser_; |
| 375 | 377 |
| 376 private: | 378 private: |
| 377 DISALLOW_COPY_AND_ASSIGN(WebMClusterParserTest); | 379 DISALLOW_COPY_AND_ASSIGN(WebMClusterParserTest); |
| 378 }; | 380 }; |
| 379 | 381 |
| 380 TEST_F(WebMClusterParserTest, HeldBackBufferHoldsBackAllTracks) { | 382 TEST_F(WebMClusterParserTest, HeldBackBufferHoldsBackAllTracks) { |
| 381 // If a buffer is missing duration and is being held back, then all other | 383 // If a buffer is missing duration and is being held back, then all other |
| 382 // tracks' buffers that have same or higher (decode) timestamp should be held | 384 // tracks' buffers that have same or higher (decode) timestamp should be held |
| 383 // back too to keep the timestamps emitted for a cluster monotonically | 385 // back too to keep the timestamps emitted for a cluster monotonically |
| 384 // non-decreasing and in same order as parsed. | 386 // non-decreasing and in same order as parsed. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 // |kExpectedBuffersOnPartialCluster| identifies the exact subset of | 434 // |kExpectedBuffersOnPartialCluster| identifies the exact subset of |
| 433 // |kBlockInfo| returned by the parser. | 435 // |kBlockInfo| returned by the parser. |
| 434 for (int i = 0; i < block_count; ++i) { | 436 for (int i = 0; i < block_count; ++i) { |
| 435 if (i > 0) | 437 if (i > 0) |
| 436 parser_->Reset(); | 438 parser_->Reset(); |
| 437 // Since we don't know exactly the offsets of each block in the full | 439 // Since we don't know exactly the offsets of each block in the full |
| 438 // cluster, build a cluster with exactly one additional block so that | 440 // cluster, build a cluster with exactly one additional block so that |
| 439 // parse of all but one byte should deterministically parse all but the | 441 // parse of all but one byte should deterministically parse all but the |
| 440 // last full block. Don't |exceed block_count| blocks though. | 442 // last full block. Don't |exceed block_count| blocks though. |
| 441 int blocks_in_cluster = std::min(i + 2, block_count); | 443 int blocks_in_cluster = std::min(i + 2, block_count); |
| 442 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, | 444 std::unique_ptr<Cluster> cluster( |
| 443 blocks_in_cluster)); | 445 CreateCluster(0, kBlockInfo, blocks_in_cluster)); |
| 444 // Parse all but the last byte unless we need to parse the full cluster. | 446 // Parse all but the last byte unless we need to parse the full cluster. |
| 445 bool parse_full_cluster = i == (block_count - 1); | 447 bool parse_full_cluster = i == (block_count - 1); |
| 446 | 448 |
| 447 if (parse_full_cluster) { | 449 if (parse_full_cluster) { |
| 448 EXPECT_MEDIA_LOG( | 450 EXPECT_MEDIA_LOG( |
| 449 WebMSimpleBlockDurationEstimated(kExpectedVideoEstimationInMs)); | 451 WebMSimpleBlockDurationEstimated(kExpectedVideoEstimationInMs)); |
| 450 } | 452 } |
| 451 | 453 |
| 452 int result = parser_->Parse(cluster->data(), parse_full_cluster ? | 454 int result = parser_->Parse(cluster->data(), parse_full_cluster ? |
| 453 cluster->size() : cluster->size() - 1); | 455 cluster->size() : cluster->size() - 1); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 464 | 466 |
| 465 EXPECT_TRUE(VerifyBuffers(parser_, kBlockInfo, | 467 EXPECT_TRUE(VerifyBuffers(parser_, kBlockInfo, |
| 466 kExpectedBuffersOnPartialCluster[i])); | 468 kExpectedBuffersOnPartialCluster[i])); |
| 467 } | 469 } |
| 468 } | 470 } |
| 469 | 471 |
| 470 TEST_F(WebMClusterParserTest, Reset) { | 472 TEST_F(WebMClusterParserTest, Reset) { |
| 471 InSequence s; | 473 InSequence s; |
| 472 | 474 |
| 473 int block_count = arraysize(kDefaultBlockInfo); | 475 int block_count = arraysize(kDefaultBlockInfo); |
| 474 scoped_ptr<Cluster> cluster(CreateCluster(0, kDefaultBlockInfo, block_count)); | 476 std::unique_ptr<Cluster> cluster( |
| 477 CreateCluster(0, kDefaultBlockInfo, block_count)); |
| 475 | 478 |
| 476 // Send slightly less than the full cluster so all but the last block is | 479 // Send slightly less than the full cluster so all but the last block is |
| 477 // parsed. | 480 // parsed. |
| 478 int result = parser_->Parse(cluster->data(), cluster->size() - 1); | 481 int result = parser_->Parse(cluster->data(), cluster->size() - 1); |
| 479 EXPECT_GT(result, 0); | 482 EXPECT_GT(result, 0); |
| 480 EXPECT_LT(result, cluster->size()); | 483 EXPECT_LT(result, cluster->size()); |
| 481 | 484 |
| 482 ASSERT_TRUE(VerifyBuffers(parser_, kDefaultBlockInfo, block_count - 1)); | 485 ASSERT_TRUE(VerifyBuffers(parser_, kDefaultBlockInfo, block_count - 1)); |
| 483 parser_->Reset(); | 486 parser_->Reset(); |
| 484 | 487 |
| 485 // Now parse a whole cluster to verify that all the blocks will get parsed. | 488 // Now parse a whole cluster to verify that all the blocks will get parsed. |
| 486 result = parser_->Parse(cluster->data(), cluster->size()); | 489 result = parser_->Parse(cluster->data(), cluster->size()); |
| 487 EXPECT_EQ(cluster->size(), result); | 490 EXPECT_EQ(cluster->size(), result); |
| 488 ASSERT_TRUE(VerifyBuffers(parser_, kDefaultBlockInfo, block_count)); | 491 ASSERT_TRUE(VerifyBuffers(parser_, kDefaultBlockInfo, block_count)); |
| 489 } | 492 } |
| 490 | 493 |
| 491 TEST_F(WebMClusterParserTest, ParseClusterWithSingleCall) { | 494 TEST_F(WebMClusterParserTest, ParseClusterWithSingleCall) { |
| 492 int block_count = arraysize(kDefaultBlockInfo); | 495 int block_count = arraysize(kDefaultBlockInfo); |
| 493 scoped_ptr<Cluster> cluster(CreateCluster(0, kDefaultBlockInfo, block_count)); | 496 std::unique_ptr<Cluster> cluster( |
| 497 CreateCluster(0, kDefaultBlockInfo, block_count)); |
| 494 | 498 |
| 495 int result = parser_->Parse(cluster->data(), cluster->size()); | 499 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 496 EXPECT_EQ(cluster->size(), result); | 500 EXPECT_EQ(cluster->size(), result); |
| 497 ASSERT_TRUE(VerifyBuffers(parser_, kDefaultBlockInfo, block_count)); | 501 ASSERT_TRUE(VerifyBuffers(parser_, kDefaultBlockInfo, block_count)); |
| 498 } | 502 } |
| 499 | 503 |
| 500 TEST_F(WebMClusterParserTest, ParseClusterWithMultipleCalls) { | 504 TEST_F(WebMClusterParserTest, ParseClusterWithMultipleCalls) { |
| 501 int block_count = arraysize(kDefaultBlockInfo); | 505 int block_count = arraysize(kDefaultBlockInfo); |
| 502 scoped_ptr<Cluster> cluster(CreateCluster(0, kDefaultBlockInfo, block_count)); | 506 std::unique_ptr<Cluster> cluster( |
| 507 CreateCluster(0, kDefaultBlockInfo, block_count)); |
| 503 | 508 |
| 504 WebMClusterParser::BufferQueue audio_buffers; | 509 WebMClusterParser::BufferQueue audio_buffers; |
| 505 WebMClusterParser::BufferQueue video_buffers; | 510 WebMClusterParser::BufferQueue video_buffers; |
| 506 const WebMClusterParser::BufferQueue no_text_buffers; | 511 const WebMClusterParser::BufferQueue no_text_buffers; |
| 507 | 512 |
| 508 const uint8_t* data = cluster->data(); | 513 const uint8_t* data = cluster->data(); |
| 509 int size = cluster->size(); | 514 int size = cluster->size(); |
| 510 int default_parse_size = 3; | 515 int default_parse_size = 3; |
| 511 int parse_size = std::min(default_parse_size, size); | 516 int parse_size = std::min(default_parse_size, size); |
| 512 | 517 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 | 573 |
| 569 TEST_F(WebMClusterParserTest, ParseSimpleBlockAndBlockGroupMixture) { | 574 TEST_F(WebMClusterParserTest, ParseSimpleBlockAndBlockGroupMixture) { |
| 570 const BlockInfo kBlockInfo[] = { | 575 const BlockInfo kBlockInfo[] = { |
| 571 {kAudioTrackNum, 0, 23, true, NULL, 0}, | 576 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
| 572 {kAudioTrackNum, 23, 23, false, NULL, 0}, | 577 {kAudioTrackNum, 23, 23, false, NULL, 0}, |
| 573 {kVideoTrackNum, 33, 34, true, NULL, 0}, | 578 {kVideoTrackNum, 33, 34, true, NULL, 0}, |
| 574 {kAudioTrackNum, 46, 23, false, NULL, 0}, | 579 {kAudioTrackNum, 46, 23, false, NULL, 0}, |
| 575 {kVideoTrackNum, 67, 33, false, NULL, 0}, | 580 {kVideoTrackNum, 67, 33, false, NULL, 0}, |
| 576 }; | 581 }; |
| 577 int block_count = arraysize(kBlockInfo); | 582 int block_count = arraysize(kBlockInfo); |
| 578 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 583 std::unique_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
| 579 | 584 |
| 580 int result = parser_->Parse(cluster->data(), cluster->size()); | 585 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 581 EXPECT_EQ(cluster->size(), result); | 586 EXPECT_EQ(cluster->size(), result); |
| 582 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | 587 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); |
| 583 } | 588 } |
| 584 | 589 |
| 585 TEST_F(WebMClusterParserTest, IgnoredTracks) { | 590 TEST_F(WebMClusterParserTest, IgnoredTracks) { |
| 586 std::set<int64_t> ignored_tracks; | 591 std::set<int64_t> ignored_tracks; |
| 587 ignored_tracks.insert(kTextTrackNum); | 592 ignored_tracks.insert(kTextTrackNum); |
| 588 | 593 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 600 | 605 |
| 601 const BlockInfo kOutputBlockInfo[] = { | 606 const BlockInfo kOutputBlockInfo[] = { |
| 602 {kAudioTrackNum, 0, 23, true, NULL, 0}, | 607 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
| 603 {kAudioTrackNum, 23, 23, true, NULL, 0}, | 608 {kAudioTrackNum, 23, 23, true, NULL, 0}, |
| 604 {kVideoTrackNum, 33, 34, true, NULL, 0}, | 609 {kVideoTrackNum, 33, 34, true, NULL, 0}, |
| 605 {kAudioTrackNum, 46, 23, true, NULL, 0}, | 610 {kAudioTrackNum, 46, 23, true, NULL, 0}, |
| 606 {kVideoTrackNum, 67, 34, true, NULL, 0}, | 611 {kVideoTrackNum, 67, 34, true, NULL, 0}, |
| 607 }; | 612 }; |
| 608 int output_block_count = arraysize(kOutputBlockInfo); | 613 int output_block_count = arraysize(kOutputBlockInfo); |
| 609 | 614 |
| 610 scoped_ptr<Cluster> cluster( | 615 std::unique_ptr<Cluster> cluster( |
| 611 CreateCluster(0, kInputBlockInfo, input_block_count)); | 616 CreateCluster(0, kInputBlockInfo, input_block_count)); |
| 612 | 617 |
| 613 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(23)); | 618 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(23)); |
| 614 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(34)); | 619 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(34)); |
| 615 int result = parser_->Parse(cluster->data(), cluster->size()); | 620 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 616 EXPECT_EQ(cluster->size(), result); | 621 EXPECT_EQ(cluster->size(), result); |
| 617 ASSERT_TRUE(VerifyBuffers(parser_, kOutputBlockInfo, output_block_count)); | 622 ASSERT_TRUE(VerifyBuffers(parser_, kOutputBlockInfo, output_block_count)); |
| 618 } | 623 } |
| 619 | 624 |
| 620 TEST_F(WebMClusterParserTest, ParseTextTracks) { | 625 TEST_F(WebMClusterParserTest, ParseTextTracks) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 631 {kAudioTrackNum, 0, 23, true, NULL, 0}, | 636 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
| 632 {kAudioTrackNum, 23, 23, true, NULL, 0}, | 637 {kAudioTrackNum, 23, 23, true, NULL, 0}, |
| 633 {kVideoTrackNum, 33, 34, true, NULL, 0}, | 638 {kVideoTrackNum, 33, 34, true, NULL, 0}, |
| 634 {kTextTrackNum, 33, 42, false, NULL, 0}, | 639 {kTextTrackNum, 33, 42, false, NULL, 0}, |
| 635 {kAudioTrackNum, 46, 23, true, NULL, 0}, | 640 {kAudioTrackNum, 46, 23, true, NULL, 0}, |
| 636 {kTextTrackNum, 55, 44, false, NULL, 0}, | 641 {kTextTrackNum, 55, 44, false, NULL, 0}, |
| 637 {kVideoTrackNum, 67, 34, true, NULL, 0}, | 642 {kVideoTrackNum, 67, 34, true, NULL, 0}, |
| 638 }; | 643 }; |
| 639 int input_block_count = arraysize(kInputBlockInfo); | 644 int input_block_count = arraysize(kInputBlockInfo); |
| 640 | 645 |
| 641 scoped_ptr<Cluster> cluster( | 646 std::unique_ptr<Cluster> cluster( |
| 642 CreateCluster(0, kInputBlockInfo, input_block_count)); | 647 CreateCluster(0, kInputBlockInfo, input_block_count)); |
| 643 | 648 |
| 644 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(23)); | 649 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(23)); |
| 645 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(34)); | 650 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(34)); |
| 646 int result = parser_->Parse(cluster->data(), cluster->size()); | 651 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 647 EXPECT_EQ(cluster->size(), result); | 652 EXPECT_EQ(cluster->size(), result); |
| 648 ASSERT_TRUE(VerifyBuffers(parser_, kInputBlockInfo, input_block_count)); | 653 ASSERT_TRUE(VerifyBuffers(parser_, kInputBlockInfo, input_block_count)); |
| 649 } | 654 } |
| 650 | 655 |
| 651 TEST_F(WebMClusterParserTest, TextTracksSimpleBlock) { | 656 TEST_F(WebMClusterParserTest, TextTracksSimpleBlock) { |
| 652 TextTracks text_tracks; | 657 TextTracks text_tracks; |
| 653 | 658 |
| 654 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), | 659 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), |
| 655 TextTrackConfig(kTextSubtitles, "", "", | 660 TextTrackConfig(kTextSubtitles, "", "", |
| 656 ""))); | 661 ""))); |
| 657 | 662 |
| 658 parser_.reset(CreateParserWithDefaultDurationsAndOptionalTextTracks( | 663 parser_.reset(CreateParserWithDefaultDurationsAndOptionalTextTracks( |
| 659 kNoTimestamp(), kNoTimestamp(), text_tracks)); | 664 kNoTimestamp(), kNoTimestamp(), text_tracks)); |
| 660 | 665 |
| 661 const BlockInfo kInputBlockInfo[] = { | 666 const BlockInfo kInputBlockInfo[] = { |
| 662 { kTextTrackNum, 33, 42, true }, | 667 { kTextTrackNum, 33, 42, true }, |
| 663 }; | 668 }; |
| 664 int input_block_count = arraysize(kInputBlockInfo); | 669 int input_block_count = arraysize(kInputBlockInfo); |
| 665 | 670 |
| 666 scoped_ptr<Cluster> cluster( | 671 std::unique_ptr<Cluster> cluster( |
| 667 CreateCluster(0, kInputBlockInfo, input_block_count)); | 672 CreateCluster(0, kInputBlockInfo, input_block_count)); |
| 668 | 673 |
| 669 int result = parser_->Parse(cluster->data(), cluster->size()); | 674 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 670 EXPECT_LT(result, 0); | 675 EXPECT_LT(result, 0); |
| 671 } | 676 } |
| 672 | 677 |
| 673 TEST_F(WebMClusterParserTest, ParseMultipleTextTracks) { | 678 TEST_F(WebMClusterParserTest, ParseMultipleTextTracks) { |
| 674 TextTracks text_tracks; | 679 TextTracks text_tracks; |
| 675 | 680 |
| 676 const int kSubtitleTextTrackNum = kTextTrackNum; | 681 const int kSubtitleTextTrackNum = kTextTrackNum; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 692 {kAudioTrackNum, 23, 23, true, NULL, 0}, | 697 {kAudioTrackNum, 23, 23, true, NULL, 0}, |
| 693 {kVideoTrackNum, 33, 34, true, NULL, 0}, | 698 {kVideoTrackNum, 33, 34, true, NULL, 0}, |
| 694 {kSubtitleTextTrackNum, 33, 42, false, NULL, 0}, | 699 {kSubtitleTextTrackNum, 33, 42, false, NULL, 0}, |
| 695 {kAudioTrackNum, 46, 23, true, NULL, 0}, | 700 {kAudioTrackNum, 46, 23, true, NULL, 0}, |
| 696 {kCaptionTextTrackNum, 55, 44, false, NULL, 0}, | 701 {kCaptionTextTrackNum, 55, 44, false, NULL, 0}, |
| 697 {kVideoTrackNum, 67, 34, true, NULL, 0}, | 702 {kVideoTrackNum, 67, 34, true, NULL, 0}, |
| 698 {kSubtitleTextTrackNum, 67, 33, false, NULL, 0}, | 703 {kSubtitleTextTrackNum, 67, 33, false, NULL, 0}, |
| 699 }; | 704 }; |
| 700 int input_block_count = arraysize(kInputBlockInfo); | 705 int input_block_count = arraysize(kInputBlockInfo); |
| 701 | 706 |
| 702 scoped_ptr<Cluster> cluster( | 707 std::unique_ptr<Cluster> cluster( |
| 703 CreateCluster(0, kInputBlockInfo, input_block_count)); | 708 CreateCluster(0, kInputBlockInfo, input_block_count)); |
| 704 | 709 |
| 705 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(23)); | 710 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(23)); |
| 706 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(34)); | 711 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(34)); |
| 707 int result = parser_->Parse(cluster->data(), cluster->size()); | 712 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 708 EXPECT_EQ(cluster->size(), result); | 713 EXPECT_EQ(cluster->size(), result); |
| 709 | 714 |
| 710 const WebMClusterParser::TextBufferQueueMap& text_map = | 715 const WebMClusterParser::TextBufferQueueMap& text_map = |
| 711 parser_->GetTextBuffers(); | 716 parser_->GetTextBuffers(); |
| 712 for (WebMClusterParser::TextBufferQueueMap::const_iterator itr = | 717 for (WebMClusterParser::TextBufferQueueMap::const_iterator itr = |
| 713 text_map.begin(); | 718 text_map.begin(); |
| 714 itr != text_map.end(); | 719 itr != text_map.end(); |
| 715 ++itr) { | 720 ++itr) { |
| 716 const TextTracks::const_iterator find_result = | 721 const TextTracks::const_iterator find_result = |
| 717 text_tracks.find(itr->first); | 722 text_tracks.find(itr->first); |
| 718 ASSERT_TRUE(find_result != text_tracks.end()); | 723 ASSERT_TRUE(find_result != text_tracks.end()); |
| 719 ASSERT_TRUE(VerifyTextBuffers(parser_, kInputBlockInfo, input_block_count, | 724 ASSERT_TRUE(VerifyTextBuffers(parser_, kInputBlockInfo, input_block_count, |
| 720 itr->first, itr->second)); | 725 itr->first, itr->second)); |
| 721 } | 726 } |
| 722 } | 727 } |
| 723 | 728 |
| 724 TEST_F(WebMClusterParserTest, ParseEncryptedBlock) { | 729 TEST_F(WebMClusterParserTest, ParseEncryptedBlock) { |
| 725 scoped_ptr<Cluster> cluster(CreateEncryptedCluster(sizeof(kEncryptedFrame))); | 730 std::unique_ptr<Cluster> cluster( |
| 731 CreateEncryptedCluster(sizeof(kEncryptedFrame))); |
| 726 | 732 |
| 727 parser_.reset(CreateParserWithKeyIdsAndAudioCodec( | 733 parser_.reset(CreateParserWithKeyIdsAndAudioCodec( |
| 728 std::string(), "video_key_id", kUnknownAudioCodec)); | 734 std::string(), "video_key_id", kUnknownAudioCodec)); |
| 729 | 735 |
| 730 // The encrypted cluster contains just one block, video. | 736 // The encrypted cluster contains just one block, video. |
| 731 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated( | 737 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated( |
| 732 WebMClusterParser::kDefaultVideoBufferDurationInMs)); | 738 WebMClusterParser::kDefaultVideoBufferDurationInMs)); |
| 733 | 739 |
| 734 int result = parser_->Parse(cluster->data(), cluster->size()); | 740 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 735 EXPECT_EQ(cluster->size(), result); | 741 EXPECT_EQ(cluster->size(), result); |
| 736 ASSERT_EQ(1UL, parser_->GetVideoBuffers().size()); | 742 ASSERT_EQ(1UL, parser_->GetVideoBuffers().size()); |
| 737 scoped_refptr<StreamParserBuffer> buffer = parser_->GetVideoBuffers()[0]; | 743 scoped_refptr<StreamParserBuffer> buffer = parser_->GetVideoBuffers()[0]; |
| 738 VerifyEncryptedBuffer(buffer); | 744 VerifyEncryptedBuffer(buffer); |
| 739 } | 745 } |
| 740 | 746 |
| 741 TEST_F(WebMClusterParserTest, ParseBadEncryptedBlock) { | 747 TEST_F(WebMClusterParserTest, ParseBadEncryptedBlock) { |
| 742 scoped_ptr<Cluster> cluster( | 748 std::unique_ptr<Cluster> cluster( |
| 743 CreateEncryptedCluster(sizeof(kEncryptedFrame) - 1)); | 749 CreateEncryptedCluster(sizeof(kEncryptedFrame) - 1)); |
| 744 | 750 |
| 745 parser_.reset(CreateParserWithKeyIdsAndAudioCodec( | 751 parser_.reset(CreateParserWithKeyIdsAndAudioCodec( |
| 746 std::string(), "video_key_id", kUnknownAudioCodec)); | 752 std::string(), "video_key_id", kUnknownAudioCodec)); |
| 747 int result = parser_->Parse(cluster->data(), cluster->size()); | 753 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 748 EXPECT_EQ(-1, result); | 754 EXPECT_EQ(-1, result); |
| 749 } | 755 } |
| 750 | 756 |
| 751 TEST_F(WebMClusterParserTest, ParseInvalidZeroSizedCluster) { | 757 TEST_F(WebMClusterParserTest, ParseInvalidZeroSizedCluster) { |
| 752 const uint8_t kBuffer[] = { | 758 const uint8_t kBuffer[] = { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 773 TextTrackConfig(kTextSubtitles, "", "", | 779 TextTrackConfig(kTextSubtitles, "", "", |
| 774 ""))); | 780 ""))); |
| 775 | 781 |
| 776 parser_.reset(CreateParserWithDefaultDurationsAndOptionalTextTracks( | 782 parser_.reset(CreateParserWithDefaultDurationsAndOptionalTextTracks( |
| 777 kNoTimestamp(), kNoTimestamp(), text_tracks)); | 783 kNoTimestamp(), kNoTimestamp(), text_tracks)); |
| 778 | 784 |
| 779 const BlockInfo kBlockInfo[] = { | 785 const BlockInfo kBlockInfo[] = { |
| 780 { kTextTrackNum, 33, -42, false }, | 786 { kTextTrackNum, 33, -42, false }, |
| 781 }; | 787 }; |
| 782 int block_count = arraysize(kBlockInfo); | 788 int block_count = arraysize(kBlockInfo); |
| 783 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 789 std::unique_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
| 784 int result = parser_->Parse(cluster->data(), cluster->size()); | 790 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 785 EXPECT_LT(result, 0); | 791 EXPECT_LT(result, 0); |
| 786 } | 792 } |
| 787 | 793 |
| 788 TEST_F(WebMClusterParserTest, ParseWithDefaultDurationsSimpleBlocks) { | 794 TEST_F(WebMClusterParserTest, ParseWithDefaultDurationsSimpleBlocks) { |
| 789 InSequence s; | 795 InSequence s; |
| 790 ResetParserToHaveDefaultDurations(); | 796 ResetParserToHaveDefaultDurations(); |
| 791 | 797 |
| 792 EXPECT_LT(kTestAudioFrameDefaultDurationInMs, 23); | 798 EXPECT_LT(kTestAudioFrameDefaultDurationInMs, 23); |
| 793 EXPECT_LT(kTestVideoFrameDefaultDurationInMs, 33); | 799 EXPECT_LT(kTestVideoFrameDefaultDurationInMs, 33); |
| 794 | 800 |
| 795 const BlockInfo kBlockInfo[] = { | 801 const BlockInfo kBlockInfo[] = { |
| 796 {kAudioTrackNum, 0, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, | 802 {kAudioTrackNum, 0, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
| 797 {kAudioTrackNum, 23, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, | 803 {kAudioTrackNum, 23, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
| 798 {kVideoTrackNum, 33, kTestVideoFrameDefaultDurationInMs, true, NULL, 0}, | 804 {kVideoTrackNum, 33, kTestVideoFrameDefaultDurationInMs, true, NULL, 0}, |
| 799 {kAudioTrackNum, 46, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, | 805 {kAudioTrackNum, 46, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
| 800 {kVideoTrackNum, 67, kTestVideoFrameDefaultDurationInMs, true, NULL, 0}, | 806 {kVideoTrackNum, 67, kTestVideoFrameDefaultDurationInMs, true, NULL, 0}, |
| 801 {kAudioTrackNum, 69, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, | 807 {kAudioTrackNum, 69, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
| 802 {kVideoTrackNum, 100, kTestVideoFrameDefaultDurationInMs, true, NULL, 0}, | 808 {kVideoTrackNum, 100, kTestVideoFrameDefaultDurationInMs, true, NULL, 0}, |
| 803 }; | 809 }; |
| 804 | 810 |
| 805 int block_count = arraysize(kBlockInfo); | 811 int block_count = arraysize(kBlockInfo); |
| 806 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 812 std::unique_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
| 807 | 813 |
| 808 // Send slightly less than the full cluster so all but the last block is | 814 // Send slightly less than the full cluster so all but the last block is |
| 809 // parsed. Though all the blocks are simple blocks, none should be held aside | 815 // parsed. Though all the blocks are simple blocks, none should be held aside |
| 810 // for duration estimation prior to end of cluster detection because all the | 816 // for duration estimation prior to end of cluster detection because all the |
| 811 // tracks have DefaultDurations. | 817 // tracks have DefaultDurations. |
| 812 int result = parser_->Parse(cluster->data(), cluster->size() - 1); | 818 int result = parser_->Parse(cluster->data(), cluster->size() - 1); |
| 813 EXPECT_GT(result, 0); | 819 EXPECT_GT(result, 0); |
| 814 EXPECT_LT(result, cluster->size()); | 820 EXPECT_LT(result, cluster->size()); |
| 815 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count - 1)); | 821 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count - 1)); |
| 816 | 822 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 838 {kAudioTrackNum, 0, 23, true, NULL, 0}, | 844 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
| 839 {kAudioTrackNum, 23, 22, true, NULL, 0}, | 845 {kAudioTrackNum, 23, 22, true, NULL, 0}, |
| 840 {kVideoTrackNum, 33, 33, true, NULL, 0}, | 846 {kVideoTrackNum, 33, 33, true, NULL, 0}, |
| 841 {kAudioTrackNum, 45, 23, true, NULL, 0}, | 847 {kAudioTrackNum, 45, 23, true, NULL, 0}, |
| 842 {kVideoTrackNum, 66, 34, true, NULL, 0}, | 848 {kVideoTrackNum, 66, 34, true, NULL, 0}, |
| 843 {kAudioTrackNum, 68, kExpectedAudioEstimationInMs, true, NULL, 0}, | 849 {kAudioTrackNum, 68, kExpectedAudioEstimationInMs, true, NULL, 0}, |
| 844 {kVideoTrackNum, 100, kExpectedVideoEstimationInMs, true, NULL, 0}, | 850 {kVideoTrackNum, 100, kExpectedVideoEstimationInMs, true, NULL, 0}, |
| 845 }; | 851 }; |
| 846 | 852 |
| 847 int block_count1 = arraysize(kBlockInfo1); | 853 int block_count1 = arraysize(kBlockInfo1); |
| 848 scoped_ptr<Cluster> cluster1(CreateCluster(0, kBlockInfo1, block_count1)); | 854 std::unique_ptr<Cluster> cluster1( |
| 855 CreateCluster(0, kBlockInfo1, block_count1)); |
| 849 | 856 |
| 850 // Send slightly less than the first full cluster so all but the last video | 857 // Send slightly less than the first full cluster so all but the last video |
| 851 // block is parsed. Verify the last fully parsed audio and video buffer are | 858 // block is parsed. Verify the last fully parsed audio and video buffer are |
| 852 // both missing from the result (parser should hold them aside for duration | 859 // both missing from the result (parser should hold them aside for duration |
| 853 // estimation prior to end of cluster detection in the absence of | 860 // estimation prior to end of cluster detection in the absence of |
| 854 // DefaultDurations.) | 861 // DefaultDurations.) |
| 855 int result = parser_->Parse(cluster1->data(), cluster1->size() - 1); | 862 int result = parser_->Parse(cluster1->data(), cluster1->size() - 1); |
| 856 EXPECT_GT(result, 0); | 863 EXPECT_GT(result, 0); |
| 857 EXPECT_LT(result, cluster1->size()); | 864 EXPECT_LT(result, cluster1->size()); |
| 858 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1 - 3)); | 865 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1 - 3)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 873 // Verify that the estimated frame duration is tracked across clusters for | 880 // Verify that the estimated frame duration is tracked across clusters for |
| 874 // each track. | 881 // each track. |
| 875 const BlockInfo kBlockInfo2[] = { | 882 const BlockInfo kBlockInfo2[] = { |
| 876 // Estimate carries over across clusters | 883 // Estimate carries over across clusters |
| 877 {kAudioTrackNum, 200, kExpectedAudioEstimationInMs, true, NULL, 0}, | 884 {kAudioTrackNum, 200, kExpectedAudioEstimationInMs, true, NULL, 0}, |
| 878 // Estimate carries over across clusters | 885 // Estimate carries over across clusters |
| 879 {kVideoTrackNum, 201, kExpectedVideoEstimationInMs, true, NULL, 0}, | 886 {kVideoTrackNum, 201, kExpectedVideoEstimationInMs, true, NULL, 0}, |
| 880 }; | 887 }; |
| 881 | 888 |
| 882 int block_count2 = arraysize(kBlockInfo2); | 889 int block_count2 = arraysize(kBlockInfo2); |
| 883 scoped_ptr<Cluster> cluster2(CreateCluster(0, kBlockInfo2, block_count2)); | 890 std::unique_ptr<Cluster> cluster2( |
| 891 CreateCluster(0, kBlockInfo2, block_count2)); |
| 884 EXPECT_MEDIA_LOG( | 892 EXPECT_MEDIA_LOG( |
| 885 WebMSimpleBlockDurationEstimated(kExpectedAudioEstimationInMs)); | 893 WebMSimpleBlockDurationEstimated(kExpectedAudioEstimationInMs)); |
| 886 EXPECT_MEDIA_LOG( | 894 EXPECT_MEDIA_LOG( |
| 887 WebMSimpleBlockDurationEstimated(kExpectedVideoEstimationInMs)); | 895 WebMSimpleBlockDurationEstimated(kExpectedVideoEstimationInMs)); |
| 888 result = parser_->Parse(cluster2->data(), cluster2->size()); | 896 result = parser_->Parse(cluster2->data(), cluster2->size()); |
| 889 EXPECT_EQ(cluster2->size(), result); | 897 EXPECT_EQ(cluster2->size(), result); |
| 890 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo2, block_count2)); | 898 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo2, block_count2)); |
| 891 } | 899 } |
| 892 | 900 |
| 893 TEST_F(WebMClusterParserTest, ParseWithoutAnyDurationsBlockGroups) { | 901 TEST_F(WebMClusterParserTest, ParseWithoutAnyDurationsBlockGroups) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 906 {kAudioTrackNum, 0, -23, false, NULL, 0}, | 914 {kAudioTrackNum, 0, -23, false, NULL, 0}, |
| 907 {kAudioTrackNum, 23, -22, false, NULL, 0}, | 915 {kAudioTrackNum, 23, -22, false, NULL, 0}, |
| 908 {kVideoTrackNum, 33, -33, false, NULL, 0}, | 916 {kVideoTrackNum, 33, -33, false, NULL, 0}, |
| 909 {kAudioTrackNum, 45, -23, false, NULL, 0}, | 917 {kAudioTrackNum, 45, -23, false, NULL, 0}, |
| 910 {kVideoTrackNum, 66, -34, false, NULL, 0}, | 918 {kVideoTrackNum, 66, -34, false, NULL, 0}, |
| 911 {kAudioTrackNum, 68, -kExpectedAudioEstimationInMs, false, NULL, 0}, | 919 {kAudioTrackNum, 68, -kExpectedAudioEstimationInMs, false, NULL, 0}, |
| 912 {kVideoTrackNum, 100, -kExpectedVideoEstimationInMs, false, NULL, 0}, | 920 {kVideoTrackNum, 100, -kExpectedVideoEstimationInMs, false, NULL, 0}, |
| 913 }; | 921 }; |
| 914 | 922 |
| 915 int block_count1 = arraysize(kBlockInfo1); | 923 int block_count1 = arraysize(kBlockInfo1); |
| 916 scoped_ptr<Cluster> cluster1(CreateCluster(0, kBlockInfo1, block_count1)); | 924 std::unique_ptr<Cluster> cluster1( |
| 925 CreateCluster(0, kBlockInfo1, block_count1)); |
| 917 | 926 |
| 918 // Send slightly less than the first full cluster so all but the last video | 927 // Send slightly less than the first full cluster so all but the last video |
| 919 // block is parsed. Verify the last fully parsed audio and video buffer are | 928 // block is parsed. Verify the last fully parsed audio and video buffer are |
| 920 // both missing from the result (parser should hold them aside for duration | 929 // both missing from the result (parser should hold them aside for duration |
| 921 // estimation prior to end of cluster detection in the absence of | 930 // estimation prior to end of cluster detection in the absence of |
| 922 // DefaultDurations.) | 931 // DefaultDurations.) |
| 923 int result = parser_->Parse(cluster1->data(), cluster1->size() - 1); | 932 int result = parser_->Parse(cluster1->data(), cluster1->size() - 1); |
| 924 EXPECT_GT(result, 0); | 933 EXPECT_GT(result, 0); |
| 925 EXPECT_LT(result, cluster1->size()); | 934 EXPECT_LT(result, cluster1->size()); |
| 926 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1 - 3)); | 935 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1 - 3)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 939 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1)); | 948 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1)); |
| 940 | 949 |
| 941 // Verify that the estimated frame duration is tracked across clusters for | 950 // Verify that the estimated frame duration is tracked across clusters for |
| 942 // each track. | 951 // each track. |
| 943 const BlockInfo kBlockInfo2[] = { | 952 const BlockInfo kBlockInfo2[] = { |
| 944 {kAudioTrackNum, 200, -kExpectedAudioEstimationInMs, false, NULL, 0}, | 953 {kAudioTrackNum, 200, -kExpectedAudioEstimationInMs, false, NULL, 0}, |
| 945 {kVideoTrackNum, 201, -kExpectedVideoEstimationInMs, false, NULL, 0}, | 954 {kVideoTrackNum, 201, -kExpectedVideoEstimationInMs, false, NULL, 0}, |
| 946 }; | 955 }; |
| 947 | 956 |
| 948 int block_count2 = arraysize(kBlockInfo2); | 957 int block_count2 = arraysize(kBlockInfo2); |
| 949 scoped_ptr<Cluster> cluster2(CreateCluster(0, kBlockInfo2, block_count2)); | 958 std::unique_ptr<Cluster> cluster2( |
| 959 CreateCluster(0, kBlockInfo2, block_count2)); |
| 950 EXPECT_MEDIA_LOG( | 960 EXPECT_MEDIA_LOG( |
| 951 WebMSimpleBlockDurationEstimated(kExpectedAudioEstimationInMs)); | 961 WebMSimpleBlockDurationEstimated(kExpectedAudioEstimationInMs)); |
| 952 EXPECT_MEDIA_LOG( | 962 EXPECT_MEDIA_LOG( |
| 953 WebMSimpleBlockDurationEstimated(kExpectedVideoEstimationInMs)); | 963 WebMSimpleBlockDurationEstimated(kExpectedVideoEstimationInMs)); |
| 954 result = parser_->Parse(cluster2->data(), cluster2->size()); | 964 result = parser_->Parse(cluster2->data(), cluster2->size()); |
| 955 EXPECT_EQ(cluster2->size(), result); | 965 EXPECT_EQ(cluster2->size(), result); |
| 956 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo2, block_count2)); | 966 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo2, block_count2)); |
| 957 } | 967 } |
| 958 | 968 |
| 959 // TODO(wolenetz): Is parser behavior correct? See http://crbug.com/363433. | 969 // TODO(wolenetz): Is parser behavior correct? See http://crbug.com/363433. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 974 {kAudioTrackNum, 69, -kTestAudioFrameDefaultDurationInMs, false, NULL, 0}, | 984 {kAudioTrackNum, 69, -kTestAudioFrameDefaultDurationInMs, false, NULL, 0}, |
| 975 {kVideoTrackNum, | 985 {kVideoTrackNum, |
| 976 100, | 986 100, |
| 977 -kTestVideoFrameDefaultDurationInMs, | 987 -kTestVideoFrameDefaultDurationInMs, |
| 978 false, | 988 false, |
| 979 NULL, | 989 NULL, |
| 980 0}, | 990 0}, |
| 981 }; | 991 }; |
| 982 | 992 |
| 983 int block_count = arraysize(kBlockInfo); | 993 int block_count = arraysize(kBlockInfo); |
| 984 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 994 std::unique_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
| 985 | 995 |
| 986 // Send slightly less than the full cluster so all but the last block is | 996 // Send slightly less than the full cluster so all but the last block is |
| 987 // parsed. None should be held aside for duration estimation prior to end of | 997 // parsed. None should be held aside for duration estimation prior to end of |
| 988 // cluster detection because all the tracks have DefaultDurations. | 998 // cluster detection because all the tracks have DefaultDurations. |
| 989 int result = parser_->Parse(cluster->data(), cluster->size() - 1); | 999 int result = parser_->Parse(cluster->data(), cluster->size() - 1); |
| 990 EXPECT_GT(result, 0); | 1000 EXPECT_GT(result, 0); |
| 991 EXPECT_LT(result, cluster->size()); | 1001 EXPECT_LT(result, cluster->size()); |
| 992 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count - 1)); | 1002 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count - 1)); |
| 993 | 1003 |
| 994 parser_->Reset(); | 1004 parser_->Reset(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1009 true | 1019 true |
| 1010 }, { | 1020 }, { |
| 1011 kVideoTrackNum, | 1021 kVideoTrackNum, |
| 1012 0, | 1022 0, |
| 1013 WebMClusterParser::kDefaultVideoBufferDurationInMs, | 1023 WebMClusterParser::kDefaultVideoBufferDurationInMs, |
| 1014 true | 1024 true |
| 1015 }, | 1025 }, |
| 1016 }; | 1026 }; |
| 1017 | 1027 |
| 1018 int block_count = arraysize(kBlockInfo); | 1028 int block_count = arraysize(kBlockInfo); |
| 1019 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 1029 std::unique_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
| 1020 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated( | 1030 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated( |
| 1021 WebMClusterParser::kDefaultAudioBufferDurationInMs)); | 1031 WebMClusterParser::kDefaultAudioBufferDurationInMs)); |
| 1022 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated( | 1032 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated( |
| 1023 WebMClusterParser::kDefaultVideoBufferDurationInMs)); | 1033 WebMClusterParser::kDefaultVideoBufferDurationInMs)); |
| 1024 int result = parser_->Parse(cluster->data(), cluster->size()); | 1034 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 1025 EXPECT_EQ(cluster->size(), result); | 1035 EXPECT_EQ(cluster->size(), result); |
| 1026 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | 1036 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); |
| 1027 } | 1037 } |
| 1028 | 1038 |
| 1029 TEST_F(WebMClusterParserTest, | 1039 TEST_F(WebMClusterParserTest, |
| 1030 ParseDegenerateClusterWithDefaultDurationsYieldsDefaultDurations) { | 1040 ParseDegenerateClusterWithDefaultDurationsYieldsDefaultDurations) { |
| 1031 ResetParserToHaveDefaultDurations(); | 1041 ResetParserToHaveDefaultDurations(); |
| 1032 | 1042 |
| 1033 const BlockInfo kBlockInfo[] = { | 1043 const BlockInfo kBlockInfo[] = { |
| 1034 { kAudioTrackNum, 0, kTestAudioFrameDefaultDurationInMs, true }, | 1044 { kAudioTrackNum, 0, kTestAudioFrameDefaultDurationInMs, true }, |
| 1035 { kVideoTrackNum, 0, kTestVideoFrameDefaultDurationInMs, true }, | 1045 { kVideoTrackNum, 0, kTestVideoFrameDefaultDurationInMs, true }, |
| 1036 }; | 1046 }; |
| 1037 | 1047 |
| 1038 int block_count = arraysize(kBlockInfo); | 1048 int block_count = arraysize(kBlockInfo); |
| 1039 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 1049 std::unique_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
| 1040 int result = parser_->Parse(cluster->data(), cluster->size()); | 1050 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 1041 EXPECT_EQ(cluster->size(), result); | 1051 EXPECT_EQ(cluster->size(), result); |
| 1042 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | 1052 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); |
| 1043 } | 1053 } |
| 1044 | 1054 |
| 1045 TEST_F(WebMClusterParserTest, ReadOpusDurationsSimpleBlockAtEndOfCluster) { | 1055 TEST_F(WebMClusterParserTest, ReadOpusDurationsSimpleBlockAtEndOfCluster) { |
| 1046 int loop_count = 0; | 1056 int loop_count = 0; |
| 1047 for (const auto* packet_ptr : BuildAllOpusPackets()) { | 1057 for (const auto* packet_ptr : BuildAllOpusPackets()) { |
| 1048 InSequence s; | 1058 InSequence s; |
| 1049 | 1059 |
| 1050 // Get a new parser each iteration to prevent exceeding the media log cap. | 1060 // Get a new parser each iteration to prevent exceeding the media log cap. |
| 1051 parser_.reset(CreateParserWithKeyIdsAndAudioCodec( | 1061 parser_.reset(CreateParserWithKeyIdsAndAudioCodec( |
| 1052 std::string(), std::string(), kCodecOpus)); | 1062 std::string(), std::string(), kCodecOpus)); |
| 1053 | 1063 |
| 1054 const BlockInfo kBlockInfo[] = {{kAudioTrackNum, | 1064 const BlockInfo kBlockInfo[] = {{kAudioTrackNum, |
| 1055 0, | 1065 0, |
| 1056 packet_ptr->duration_ms(), | 1066 packet_ptr->duration_ms(), |
| 1057 true, // Make it a SimpleBlock. | 1067 true, // Make it a SimpleBlock. |
| 1058 packet_ptr->data(), | 1068 packet_ptr->data(), |
| 1059 packet_ptr->size()}}; | 1069 packet_ptr->size()}}; |
| 1060 | 1070 |
| 1061 int block_count = arraysize(kBlockInfo); | 1071 int block_count = arraysize(kBlockInfo); |
| 1062 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 1072 std::unique_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
| 1063 int duration_ms = packet_ptr->duration_ms(); // Casts from double. | 1073 int duration_ms = packet_ptr->duration_ms(); // Casts from double. |
| 1064 if (duration_ms > 120) { | 1074 if (duration_ms > 120) { |
| 1065 EXPECT_MEDIA_LOG(OpusPacketDurationTooHigh(duration_ms)); | 1075 EXPECT_MEDIA_LOG(OpusPacketDurationTooHigh(duration_ms)); |
| 1066 } | 1076 } |
| 1067 | 1077 |
| 1068 int result = parser_->Parse(cluster->data(), cluster->size()); | 1078 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 1069 EXPECT_EQ(cluster->size(), result); | 1079 EXPECT_EQ(cluster->size(), result); |
| 1070 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | 1080 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); |
| 1071 | 1081 |
| 1072 // Fail early if any iteration fails to meet the logging expectations. | 1082 // Fail early if any iteration fails to meet the logging expectations. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1098 block_duration_ms, packet_ptr->duration_ms())); | 1108 block_duration_ms, packet_ptr->duration_ms())); |
| 1099 | 1109 |
| 1100 BlockInfo block_infos[] = {{kAudioTrackNum, | 1110 BlockInfo block_infos[] = {{kAudioTrackNum, |
| 1101 0, | 1111 0, |
| 1102 block_duration_ms, | 1112 block_duration_ms, |
| 1103 false, // Not a SimpleBlock. | 1113 false, // Not a SimpleBlock. |
| 1104 packet_ptr->data(), | 1114 packet_ptr->data(), |
| 1105 packet_ptr->size()}}; | 1115 packet_ptr->size()}}; |
| 1106 | 1116 |
| 1107 int block_count = arraysize(block_infos); | 1117 int block_count = arraysize(block_infos); |
| 1108 scoped_ptr<Cluster> cluster(CreateCluster(0, block_infos, block_count)); | 1118 std::unique_ptr<Cluster> cluster( |
| 1119 CreateCluster(0, block_infos, block_count)); |
| 1109 int result = parser_->Parse(cluster->data(), cluster->size()); | 1120 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 1110 EXPECT_EQ(cluster->size(), result); | 1121 EXPECT_EQ(cluster->size(), result); |
| 1111 | 1122 |
| 1112 // BlockInfo duration will be used to verify buffer duration, so changing | 1123 // BlockInfo duration will be used to verify buffer duration, so changing |
| 1113 // duration to be that of the Opus packet to verify it was preferred. | 1124 // duration to be that of the Opus packet to verify it was preferred. |
| 1114 block_infos[0].duration = packet_ptr->duration_ms(); | 1125 block_infos[0].duration = packet_ptr->duration_ms(); |
| 1115 | 1126 |
| 1116 ASSERT_TRUE(VerifyBuffers(parser_, block_infos, block_count)); | 1127 ASSERT_TRUE(VerifyBuffers(parser_, block_infos, block_count)); |
| 1117 | 1128 |
| 1118 // Fail early if any iteration fails to meet the logging expectations. | 1129 // Fail early if any iteration fails to meet the logging expectations. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1138 | 1149 |
| 1139 // Single Block with BlockDuration and encrypted data. | 1150 // Single Block with BlockDuration and encrypted data. |
| 1140 const BlockInfo kBlockInfo[] = {{kAudioTrackNum, | 1151 const BlockInfo kBlockInfo[] = {{kAudioTrackNum, |
| 1141 0, | 1152 0, |
| 1142 kTestAudioFrameDefaultDurationInMs, | 1153 kTestAudioFrameDefaultDurationInMs, |
| 1143 false, // Not a SimpleBlock | 1154 false, // Not a SimpleBlock |
| 1144 kEncryptedFrame, // Encrypted frame data | 1155 kEncryptedFrame, // Encrypted frame data |
| 1145 arraysize(kEncryptedFrame)}}; | 1156 arraysize(kEncryptedFrame)}}; |
| 1146 | 1157 |
| 1147 int block_count = arraysize(kBlockInfo); | 1158 int block_count = arraysize(kBlockInfo); |
| 1148 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 1159 std::unique_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
| 1149 int result = parser_->Parse(cluster->data(), cluster->size()); | 1160 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 1150 EXPECT_EQ(cluster->size(), result); | 1161 EXPECT_EQ(cluster->size(), result); |
| 1151 | 1162 |
| 1152 // Will verify that duration of buffer matches that of BlockDuration. | 1163 // Will verify that duration of buffer matches that of BlockDuration. |
| 1153 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | 1164 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); |
| 1154 } | 1165 } |
| 1155 | 1166 |
| 1156 } // namespace media | 1167 } // namespace media |
| OLD | NEW |