Chromium Code Reviews| 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 | 8 |
| 8 #include "base/bind.h" | 9 #include "base/bind.h" |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "media/base/audio_decoder_config.h" | |
| 10 #include "media/base/decrypt_config.h" | 12 #include "media/base/decrypt_config.h" |
| 11 #include "media/formats/webm/cluster_builder.h" | 13 #include "media/formats/webm/cluster_builder.h" |
| 12 #include "media/formats/webm/webm_cluster_parser.h" | 14 #include "media/formats/webm/webm_cluster_parser.h" |
| 13 #include "media/formats/webm/webm_constants.h" | 15 #include "media/formats/webm/webm_constants.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 18 |
| 17 using ::testing::InSequence; | 19 using ::testing::InSequence; |
| 18 using ::testing::Return; | 20 using ::testing::Return; |
| 19 using ::testing::_; | 21 using ::testing::_; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 42 | 44 |
| 43 struct BlockInfo { | 45 struct BlockInfo { |
| 44 int track_num; | 46 int track_num; |
| 45 int timestamp; | 47 int timestamp; |
| 46 | 48 |
| 47 // Negative value is allowed only for block groups (not simple blocks) and | 49 // Negative value is allowed only for block groups (not simple blocks) and |
| 48 // directs CreateCluster() to exclude BlockDuration entry from the cluster for | 50 // directs CreateCluster() to exclude BlockDuration entry from the cluster for |
| 49 // this BlockGroup. The absolute value is used for parser verification. | 51 // this BlockGroup. The absolute value is used for parser verification. |
| 50 // For simple blocks, this value must be non-negative, and is used only for | 52 // For simple blocks, this value must be non-negative, and is used only for |
| 51 // parser verification. | 53 // parser verification. |
| 52 int duration; | 54 float duration; |
| 55 | |
| 53 bool use_simple_block; | 56 bool use_simple_block; |
| 57 | |
| 58 // Default data will be used if no data given. | |
| 59 const uint8* data; | |
| 60 int data_length; | |
| 54 }; | 61 }; |
| 55 | 62 |
| 56 static const BlockInfo kDefaultBlockInfo[] = { | 63 static const BlockInfo kDefaultBlockInfo[] = { |
| 57 { kAudioTrackNum, 0, 23, true }, | 64 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
| 58 { kAudioTrackNum, 23, 23, true }, | 65 {kAudioTrackNum, 23, 23, true, NULL, 0}, |
| 59 { kVideoTrackNum, 33, 34, true }, // Assumes not using DefaultDuration | 66 // Assumes not using DefaultDuration |
| 60 { kAudioTrackNum, 46, 23, true }, | 67 {kVideoTrackNum, 33, 34, true, NULL, 0}, |
| 61 { kVideoTrackNum, 67, 33, false }, | 68 {kAudioTrackNum, 46, 23, true, NULL, 0}, |
| 62 { kAudioTrackNum, 69, 23, false }, | 69 {kVideoTrackNum, 67, 33, false, NULL, 0}, |
| 63 { kVideoTrackNum, 100, 33, false }, | 70 {kAudioTrackNum, 69, 23, false, NULL, 0}, |
| 71 {kVideoTrackNum, 100, 33, false, NULL, 0}, | |
| 64 }; | 72 }; |
| 65 | 73 |
| 74 // Opus configuration. kCodecOpus is critical for OpusWebMClusterParserTest, | |
| 75 // other arguments are just reasonable dummy data. | |
| 76 const AudioDecoderConfig kOpusAudioConfig(kCodecOpus, | |
| 77 kSampleFormatF32, | |
| 78 CHANNEL_LAYOUT_STEREO, | |
| 79 48000, | |
| 80 NULL, | |
| 81 0, | |
| 82 false); | |
| 83 | |
| 66 static const uint8 kEncryptedFrame[] = { | 84 static const uint8 kEncryptedFrame[] = { |
| 67 0x01, // Block is encrypted | 85 0x01, // Block is encrypted |
| 68 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 // IV | 86 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 // IV |
| 69 }; | 87 }; |
| 70 | 88 |
| 71 static scoped_ptr<Cluster> CreateCluster(int timecode, | 89 static scoped_ptr<Cluster> CreateCluster(int timecode, |
| 72 const BlockInfo* block_info, | 90 const BlockInfo* block_info, |
| 73 int block_count) { | 91 int block_count) { |
| 74 ClusterBuilder cb; | 92 ClusterBuilder cb; |
| 75 cb.SetClusterTimecode(0); | 93 cb.SetClusterTimecode(0); |
| 76 | 94 |
| 95 uint8 kDefaultBlockData[] = {0x00}; | |
| 96 | |
| 77 for (int i = 0; i < block_count; i++) { | 97 for (int i = 0; i < block_count; i++) { |
| 78 uint8 data[] = { 0x00 }; | 98 const uint8* data; |
| 99 int data_length; | |
| 100 if (block_info[i].data != NULL) { | |
| 101 data = block_info[i].data; | |
| 102 data_length = block_info[i].data_length; | |
| 103 } else { | |
| 104 data = kDefaultBlockData; | |
| 105 data_length = sizeof(kDefaultBlockData); | |
| 106 } | |
| 107 | |
| 79 if (block_info[i].use_simple_block) { | 108 if (block_info[i].use_simple_block) { |
| 80 CHECK_GE(block_info[i].duration, 0); | 109 CHECK_GE(block_info[i].duration, 0); |
| 81 cb.AddSimpleBlock(block_info[i].track_num, | 110 cb.AddSimpleBlock(block_info[i].track_num, |
| 82 block_info[i].timestamp, | 111 block_info[i].timestamp, |
| 83 0, data, sizeof(data)); | 112 0, data, data_length); |
| 84 continue; | 113 continue; |
| 85 } | 114 } |
| 86 | 115 |
| 87 if (block_info[i].duration < 0) { | 116 if (block_info[i].duration < 0) { |
| 88 cb.AddBlockGroupWithoutBlockDuration(block_info[i].track_num, | 117 cb.AddBlockGroupWithoutBlockDuration(block_info[i].track_num, |
| 89 block_info[i].timestamp, | 118 block_info[i].timestamp, |
| 90 0, data, sizeof(data)); | 119 0, data,data_length); |
| 91 continue; | 120 continue; |
| 92 } | 121 } |
| 93 | 122 |
| 94 cb.AddBlockGroup(block_info[i].track_num, | 123 cb.AddBlockGroup(block_info[i].track_num, |
| 95 block_info[i].timestamp, | 124 block_info[i].timestamp, |
| 96 block_info[i].duration, | 125 block_info[i].duration, |
| 97 0, data, sizeof(data)); | 126 0, data, data_length); |
| 98 } | 127 } |
| 99 | 128 |
| 100 return cb.Finish(); | 129 return cb.Finish(); |
| 101 } | 130 } |
| 102 | 131 |
| 103 // Creates a Cluster with one encrypted Block. |bytes_to_write| is number of | 132 // Creates a Cluster with one encrypted Block. |bytes_to_write| is number of |
| 104 // bytes of the encrypted frame to write. | 133 // bytes of the encrypted frame to write. |
| 105 static scoped_ptr<Cluster> CreateEncryptedCluster(int bytes_to_write) { | 134 static scoped_ptr<Cluster> CreateEncryptedCluster(int bytes_to_write) { |
| 106 CHECK_GT(bytes_to_write, 0); | 135 CHECK_GT(bytes_to_write, 0); |
| 107 CHECK_LE(bytes_to_write, static_cast<int>(sizeof(kEncryptedFrame))); | 136 CHECK_LE(bytes_to_write, static_cast<int>(sizeof(kEncryptedFrame))); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 WebMClusterParserTest() | 270 WebMClusterParserTest() |
| 242 : parser_(new WebMClusterParser(kTimecodeScale, | 271 : parser_(new WebMClusterParser(kTimecodeScale, |
| 243 kAudioTrackNum, | 272 kAudioTrackNum, |
| 244 kNoTimestamp(), | 273 kNoTimestamp(), |
| 245 kVideoTrackNum, | 274 kVideoTrackNum, |
| 246 kNoTimestamp(), | 275 kNoTimestamp(), |
| 247 TextTracks(), | 276 TextTracks(), |
| 248 std::set<int64>(), | 277 std::set<int64>(), |
| 249 std::string(), | 278 std::string(), |
| 250 std::string(), | 279 std::string(), |
| 280 AudioDecoderConfig(), | |
| 251 LogCB())) {} | 281 LogCB())) {} |
| 252 | 282 |
| 253 protected: | 283 protected: |
| 254 void ResetParserToHaveDefaultDurations() { | 284 void ResetParserToHaveDefaultDurations() { |
| 255 base::TimeDelta default_audio_duration = base::TimeDelta::FromMilliseconds( | 285 base::TimeDelta default_audio_duration = base::TimeDelta::FromMilliseconds( |
| 256 kTestAudioFrameDefaultDurationInMs); | 286 kTestAudioFrameDefaultDurationInMs); |
| 257 base::TimeDelta default_video_duration = base::TimeDelta::FromMilliseconds( | 287 base::TimeDelta default_video_duration = base::TimeDelta::FromMilliseconds( |
| 258 kTestVideoFrameDefaultDurationInMs); | 288 kTestVideoFrameDefaultDurationInMs); |
| 259 ASSERT_GE(default_audio_duration, base::TimeDelta()); | 289 ASSERT_GE(default_audio_duration, base::TimeDelta()); |
| 260 ASSERT_GE(default_video_duration, base::TimeDelta()); | 290 ASSERT_GE(default_video_duration, base::TimeDelta()); |
| 261 ASSERT_NE(kNoTimestamp(), default_audio_duration); | 291 ASSERT_NE(kNoTimestamp(), default_audio_duration); |
| 262 ASSERT_NE(kNoTimestamp(), default_video_duration); | 292 ASSERT_NE(kNoTimestamp(), default_video_duration); |
| 263 | 293 |
| 264 parser_.reset(new WebMClusterParser(kTimecodeScale, | 294 parser_.reset(new WebMClusterParser(kTimecodeScale, |
| 265 kAudioTrackNum, | 295 kAudioTrackNum, |
| 266 default_audio_duration, | 296 default_audio_duration, |
| 267 kVideoTrackNum, | 297 kVideoTrackNum, |
| 268 default_video_duration, | 298 default_video_duration, |
| 269 TextTracks(), | 299 TextTracks(), |
| 270 std::set<int64>(), | 300 std::set<int64>(), |
| 271 std::string(), | 301 std::string(), |
| 272 std::string(), | 302 std::string(), |
| 303 AudioDecoderConfig(), | |
| 273 LogCB())); | 304 LogCB())); |
| 274 } | 305 } |
| 275 | 306 |
| 276 scoped_ptr<WebMClusterParser> parser_; | 307 scoped_ptr<WebMClusterParser> parser_; |
| 277 | 308 |
| 278 private: | 309 private: |
| 279 DISALLOW_COPY_AND_ASSIGN(WebMClusterParserTest); | 310 DISALLOW_COPY_AND_ASSIGN(WebMClusterParserTest); |
| 280 }; | 311 }; |
| 281 | 312 |
| 282 TEST_F(WebMClusterParserTest, HeldBackBufferHoldsBackAllTracks) { | 313 TEST_F(WebMClusterParserTest, HeldBackBufferHoldsBackAllTracks) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 298 ASSERT_NE(kNoTimestamp(), default_audio_duration); | 329 ASSERT_NE(kNoTimestamp(), default_audio_duration); |
| 299 parser_.reset(new WebMClusterParser(kTimecodeScale, | 330 parser_.reset(new WebMClusterParser(kTimecodeScale, |
| 300 kAudioTrackNum, | 331 kAudioTrackNum, |
| 301 default_audio_duration, | 332 default_audio_duration, |
| 302 kVideoTrackNum, | 333 kVideoTrackNum, |
| 303 kNoTimestamp(), | 334 kNoTimestamp(), |
| 304 text_tracks, | 335 text_tracks, |
| 305 std::set<int64>(), | 336 std::set<int64>(), |
| 306 std::string(), | 337 std::string(), |
| 307 std::string(), | 338 std::string(), |
| 339 AudioDecoderConfig(), | |
| 308 LogCB())); | 340 LogCB())); |
| 309 | 341 |
| 310 const BlockInfo kBlockInfo[] = { | 342 const BlockInfo kBlockInfo[] = { |
| 311 { kVideoTrackNum, 0, 33, true }, | 343 {kVideoTrackNum, 0, 33, true, NULL, 0}, |
| 312 { kAudioTrackNum, 0, 23, false }, | 344 {kAudioTrackNum, 0, 23, false, NULL, 0}, |
| 313 { kTextTrackNum, 10, 42, false }, | 345 {kTextTrackNum, 10, 42, false, NULL, 0}, |
| 314 { kAudioTrackNum, 23, kTestAudioFrameDefaultDurationInMs, true }, | 346 {kAudioTrackNum, 23, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
| 315 { kVideoTrackNum, 33, 33, true }, | 347 {kVideoTrackNum, 33, 33, true, NULL, 0}, |
| 316 { kAudioTrackNum, 36, kTestAudioFrameDefaultDurationInMs, true }, | 348 {kAudioTrackNum, 36, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
| 317 { kVideoTrackNum, 66, 33, true }, | 349 {kVideoTrackNum, 66, 33, true, NULL, 0}, |
| 318 { kAudioTrackNum, 70, kTestAudioFrameDefaultDurationInMs, true }, | 350 {kAudioTrackNum, 70, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
| 319 { kAudioTrackNum, 83, kTestAudioFrameDefaultDurationInMs, true }, | 351 {kAudioTrackNum, 83, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
| 320 }; | 352 }; |
| 321 | 353 |
| 322 const int kExpectedBuffersOnPartialCluster[] = { | 354 const int kExpectedBuffersOnPartialCluster[] = { |
| 323 0, // Video simple block without DefaultDuration should be held back | 355 0, // Video simple block without DefaultDuration should be held back |
| 324 0, // Audio buffer ready, but not emitted because its TS >= held back video | 356 0, // Audio buffer ready, but not emitted because its TS >= held back video |
| 325 0, // Text buffer ready, but not emitted because its TS >= held back video | 357 0, // Text buffer ready, but not emitted because its TS >= held back video |
| 326 0, // 2nd audio buffer ready, also not emitted for same reason as first | 358 0, // 2nd audio buffer ready, also not emitted for same reason as first |
| 327 4, // All previous buffers emitted, 2nd video held back with no duration | 359 4, // All previous buffers emitted, 2nd video held back with no duration |
| 328 4, // 2nd video still has no duration, 3rd audio ready but not emitted | 360 4, // 2nd video still has no duration, 3rd audio ready but not emitted |
| 329 6, // All previous buffers emitted, 3rd video held back with no duration | 361 6, // All previous buffers emitted, 3rd video held back with no duration |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 block_count)); | 469 block_count)); |
| 438 } | 470 } |
| 439 | 471 |
| 440 // Verify that both BlockGroups with the BlockDuration before the Block | 472 // Verify that both BlockGroups with the BlockDuration before the Block |
| 441 // and BlockGroups with the BlockDuration after the Block are supported | 473 // and BlockGroups with the BlockDuration after the Block are supported |
| 442 // correctly. | 474 // correctly. |
| 443 // Note: Raw bytes are use here because ClusterBuilder only generates | 475 // Note: Raw bytes are use here because ClusterBuilder only generates |
| 444 // one of these scenarios. | 476 // one of these scenarios. |
| 445 TEST_F(WebMClusterParserTest, ParseBlockGroup) { | 477 TEST_F(WebMClusterParserTest, ParseBlockGroup) { |
| 446 const BlockInfo kBlockInfo[] = { | 478 const BlockInfo kBlockInfo[] = { |
| 447 { kAudioTrackNum, 0, 23, false }, | 479 {kAudioTrackNum, 0, 23, false, NULL, 0}, |
| 448 { kVideoTrackNum, 33, 34, false }, | 480 {kVideoTrackNum, 33, 34, false, NULL, 0}, |
| 449 }; | 481 }; |
| 450 int block_count = arraysize(kBlockInfo); | 482 int block_count = arraysize(kBlockInfo); |
| 451 | 483 |
| 452 const uint8 kClusterData[] = { | 484 const uint8 kClusterData[] = { |
| 453 0x1F, 0x43, 0xB6, 0x75, 0x9B, // Cluster(size=27) | 485 0x1F, 0x43, 0xB6, 0x75, 0x9B, // Cluster(size=27) |
| 454 0xE7, 0x81, 0x00, // Timecode(size=1, value=0) | 486 0xE7, 0x81, 0x00, // Timecode(size=1, value=0) |
| 455 // BlockGroup with BlockDuration before Block. | 487 // BlockGroup with BlockDuration before Block. |
| 456 0xA0, 0x8A, // BlockGroup(size=10) | 488 0xA0, 0x8A, // BlockGroup(size=10) |
| 457 0x9B, 0x81, 0x17, // BlockDuration(size=1, value=23) | 489 0x9B, 0x81, 0x17, // BlockDuration(size=1, value=23) |
| 458 0xA1, 0x85, 0x81, 0x00, 0x00, 0x00, 0xaa, // Block(size=5, track=1, ts=0) | 490 0xA1, 0x85, 0x81, 0x00, 0x00, 0x00, 0xaa, // Block(size=5, track=1, ts=0) |
| 459 // BlockGroup with BlockDuration after Block. | 491 // BlockGroup with BlockDuration after Block. |
| 460 0xA0, 0x8A, // BlockGroup(size=10) | 492 0xA0, 0x8A, // BlockGroup(size=10) |
| 461 0xA1, 0x85, 0x82, 0x00, 0x21, 0x00, 0x55, // Block(size=5, track=2, ts=33) | 493 0xA1, 0x85, 0x82, 0x00, 0x21, 0x00, 0x55, // Block(size=5, track=2, ts=33) |
| 462 0x9B, 0x81, 0x22, // BlockDuration(size=1, value=34) | 494 0x9B, 0x81, 0x22, // BlockDuration(size=1, value=34) |
| 463 }; | 495 }; |
| 464 const int kClusterSize = sizeof(kClusterData); | 496 const int kClusterSize = sizeof(kClusterData); |
| 465 | 497 |
| 466 int result = parser_->Parse(kClusterData, kClusterSize); | 498 int result = parser_->Parse(kClusterData, kClusterSize); |
| 467 EXPECT_EQ(kClusterSize, result); | 499 EXPECT_EQ(kClusterSize, result); |
| 468 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | 500 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); |
| 469 } | 501 } |
| 470 | 502 |
| 471 TEST_F(WebMClusterParserTest, ParseSimpleBlockAndBlockGroupMixture) { | 503 TEST_F(WebMClusterParserTest, ParseSimpleBlockAndBlockGroupMixture) { |
| 472 const BlockInfo kBlockInfo[] = { | 504 const BlockInfo kBlockInfo[] = { |
| 473 { kAudioTrackNum, 0, 23, true }, | 505 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
| 474 { kAudioTrackNum, 23, 23, false }, | 506 {kAudioTrackNum, 23, 23, false, NULL, 0}, |
| 475 { kVideoTrackNum, 33, 34, true }, | 507 {kVideoTrackNum, 33, 34, true, NULL, 0}, |
| 476 { kAudioTrackNum, 46, 23, false }, | 508 {kAudioTrackNum, 46, 23, false, NULL, 0}, |
| 477 { kVideoTrackNum, 67, 33, false }, | 509 {kVideoTrackNum, 67, 33, false, NULL, 0}, |
| 478 }; | 510 }; |
| 479 int block_count = arraysize(kBlockInfo); | 511 int block_count = arraysize(kBlockInfo); |
| 480 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 512 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
| 481 | 513 |
| 482 int result = parser_->Parse(cluster->data(), cluster->size()); | 514 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 483 EXPECT_EQ(cluster->size(), result); | 515 EXPECT_EQ(cluster->size(), result); |
| 484 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | 516 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); |
| 485 } | 517 } |
| 486 | 518 |
| 487 TEST_F(WebMClusterParserTest, IgnoredTracks) { | 519 TEST_F(WebMClusterParserTest, IgnoredTracks) { |
| 488 std::set<int64> ignored_tracks; | 520 std::set<int64> ignored_tracks; |
| 489 ignored_tracks.insert(kTextTrackNum); | 521 ignored_tracks.insert(kTextTrackNum); |
| 490 | 522 |
| 491 parser_.reset(new WebMClusterParser(kTimecodeScale, | 523 parser_.reset(new WebMClusterParser(kTimecodeScale, |
| 492 kAudioTrackNum, | 524 kAudioTrackNum, |
| 493 kNoTimestamp(), | 525 kNoTimestamp(), |
| 494 kVideoTrackNum, | 526 kVideoTrackNum, |
| 495 kNoTimestamp(), | 527 kNoTimestamp(), |
| 496 TextTracks(), | 528 TextTracks(), |
| 497 ignored_tracks, | 529 ignored_tracks, |
| 498 std::string(), | 530 std::string(), |
| 499 std::string(), | 531 std::string(), |
| 532 AudioDecoderConfig(), | |
| 500 LogCB())); | 533 LogCB())); |
| 501 | 534 |
| 502 const BlockInfo kInputBlockInfo[] = { | 535 const BlockInfo kInputBlockInfo[] = { |
| 503 { kAudioTrackNum, 0, 23, true }, | 536 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
| 504 { kAudioTrackNum, 23, 23, true }, | 537 {kAudioTrackNum, 23, 23, true, NULL, 0}, |
| 505 { kVideoTrackNum, 33, 34, true }, | 538 {kVideoTrackNum, 33, 34, true, NULL, 0}, |
| 506 { kTextTrackNum, 33, 99, true }, | 539 {kTextTrackNum, 33, 99, true, NULL, 0}, |
| 507 { kAudioTrackNum, 46, 23, true }, | 540 {kAudioTrackNum, 46, 23, true, NULL, 0}, |
| 508 { kVideoTrackNum, 67, 34, true }, | 541 {kVideoTrackNum, 67, 34, true, NULL, 0}, |
| 509 }; | 542 }; |
| 510 int input_block_count = arraysize(kInputBlockInfo); | 543 int input_block_count = arraysize(kInputBlockInfo); |
| 511 | 544 |
| 512 const BlockInfo kOutputBlockInfo[] = { | 545 const BlockInfo kOutputBlockInfo[] = { |
| 513 { kAudioTrackNum, 0, 23, true }, | 546 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
| 514 { kAudioTrackNum, 23, 23, true }, | 547 {kAudioTrackNum, 23, 23, true, NULL, 0}, |
| 515 { kVideoTrackNum, 33, 34, true }, | 548 {kVideoTrackNum, 33, 34, true, NULL, 0}, |
| 516 { kAudioTrackNum, 46, 23, true }, | 549 {kAudioTrackNum, 46, 23, true, NULL, 0}, |
| 517 { kVideoTrackNum, 67, 34, true }, | 550 {kVideoTrackNum, 67, 34, true, NULL, 0}, |
| 518 }; | 551 }; |
| 519 int output_block_count = arraysize(kOutputBlockInfo); | 552 int output_block_count = arraysize(kOutputBlockInfo); |
| 520 | 553 |
| 521 scoped_ptr<Cluster> cluster( | 554 scoped_ptr<Cluster> cluster( |
| 522 CreateCluster(0, kInputBlockInfo, input_block_count)); | 555 CreateCluster(0, kInputBlockInfo, input_block_count)); |
| 523 | 556 |
| 524 int result = parser_->Parse(cluster->data(), cluster->size()); | 557 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 525 EXPECT_EQ(cluster->size(), result); | 558 EXPECT_EQ(cluster->size(), result); |
| 526 ASSERT_TRUE(VerifyBuffers(parser_, kOutputBlockInfo, output_block_count)); | 559 ASSERT_TRUE(VerifyBuffers(parser_, kOutputBlockInfo, output_block_count)); |
| 527 } | 560 } |
| 528 | 561 |
| 529 TEST_F(WebMClusterParserTest, ParseTextTracks) { | 562 TEST_F(WebMClusterParserTest, ParseTextTracks) { |
| 530 TextTracks text_tracks; | 563 TextTracks text_tracks; |
| 531 | 564 |
| 532 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), | 565 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), |
| 533 TextTrackConfig(kTextSubtitles, "", "", | 566 TextTrackConfig(kTextSubtitles, "", "", |
| 534 ""))); | 567 ""))); |
| 535 | 568 |
| 536 parser_.reset(new WebMClusterParser(kTimecodeScale, | 569 parser_.reset(new WebMClusterParser(kTimecodeScale, |
| 537 kAudioTrackNum, | 570 kAudioTrackNum, |
| 538 kNoTimestamp(), | 571 kNoTimestamp(), |
| 539 kVideoTrackNum, | 572 kVideoTrackNum, |
| 540 kNoTimestamp(), | 573 kNoTimestamp(), |
| 541 text_tracks, | 574 text_tracks, |
| 542 std::set<int64>(), | 575 std::set<int64>(), |
| 543 std::string(), | 576 std::string(), |
| 544 std::string(), | 577 std::string(), |
| 578 AudioDecoderConfig(), | |
| 545 LogCB())); | 579 LogCB())); |
| 546 | 580 |
| 547 const BlockInfo kInputBlockInfo[] = { | 581 const BlockInfo kInputBlockInfo[] = { |
| 548 { kAudioTrackNum, 0, 23, true }, | 582 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
| 549 { kAudioTrackNum, 23, 23, true }, | 583 {kAudioTrackNum, 23, 23, true, NULL, 0}, |
| 550 { kVideoTrackNum, 33, 34, true }, | 584 {kVideoTrackNum, 33, 34, true, NULL, 0}, |
| 551 { kTextTrackNum, 33, 42, false }, | 585 {kTextTrackNum, 33, 42, false, NULL, 0}, |
| 552 { kAudioTrackNum, 46, 23, true }, | 586 {kAudioTrackNum, 46, 23, true, NULL, 0}, |
| 553 { kTextTrackNum, 55, 44, false }, | 587 {kTextTrackNum, 55, 44, false, NULL, 0}, |
| 554 { kVideoTrackNum, 67, 34, true }, | 588 {kVideoTrackNum, 67, 34, true, NULL, 0}, |
| 555 }; | 589 }; |
| 556 int input_block_count = arraysize(kInputBlockInfo); | 590 int input_block_count = arraysize(kInputBlockInfo); |
| 557 | 591 |
| 558 scoped_ptr<Cluster> cluster( | 592 scoped_ptr<Cluster> cluster( |
| 559 CreateCluster(0, kInputBlockInfo, input_block_count)); | 593 CreateCluster(0, kInputBlockInfo, input_block_count)); |
| 560 | 594 |
| 561 int result = parser_->Parse(cluster->data(), cluster->size()); | 595 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 562 EXPECT_EQ(cluster->size(), result); | 596 EXPECT_EQ(cluster->size(), result); |
| 563 ASSERT_TRUE(VerifyBuffers(parser_, kInputBlockInfo, input_block_count)); | 597 ASSERT_TRUE(VerifyBuffers(parser_, kInputBlockInfo, input_block_count)); |
| 564 } | 598 } |
| 565 | 599 |
| 566 TEST_F(WebMClusterParserTest, TextTracksSimpleBlock) { | 600 TEST_F(WebMClusterParserTest, TextTracksSimpleBlock) { |
| 567 TextTracks text_tracks; | 601 TextTracks text_tracks; |
| 568 | 602 |
| 569 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), | 603 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), |
| 570 TextTrackConfig(kTextSubtitles, "", "", | 604 TextTrackConfig(kTextSubtitles, "", "", |
| 571 ""))); | 605 ""))); |
| 572 | 606 |
| 573 parser_.reset(new WebMClusterParser(kTimecodeScale, | 607 parser_.reset(new WebMClusterParser(kTimecodeScale, |
| 574 kAudioTrackNum, | 608 kAudioTrackNum, |
| 575 kNoTimestamp(), | 609 kNoTimestamp(), |
| 576 kVideoTrackNum, | 610 kVideoTrackNum, |
| 577 kNoTimestamp(), | 611 kNoTimestamp(), |
| 578 text_tracks, | 612 text_tracks, |
| 579 std::set<int64>(), | 613 std::set<int64>(), |
| 580 std::string(), | 614 std::string(), |
| 581 std::string(), | 615 std::string(), |
| 616 AudioDecoderConfig(), | |
| 582 LogCB())); | 617 LogCB())); |
| 583 | 618 |
| 584 const BlockInfo kInputBlockInfo[] = { | 619 const BlockInfo kInputBlockInfo[] = { |
| 585 { kTextTrackNum, 33, 42, true }, | 620 { kTextTrackNum, 33, 42, true }, |
| 586 }; | 621 }; |
| 587 int input_block_count = arraysize(kInputBlockInfo); | 622 int input_block_count = arraysize(kInputBlockInfo); |
| 588 | 623 |
| 589 scoped_ptr<Cluster> cluster( | 624 scoped_ptr<Cluster> cluster( |
| 590 CreateCluster(0, kInputBlockInfo, input_block_count)); | 625 CreateCluster(0, kInputBlockInfo, input_block_count)); |
| 591 | 626 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 609 | 644 |
| 610 parser_.reset(new WebMClusterParser(kTimecodeScale, | 645 parser_.reset(new WebMClusterParser(kTimecodeScale, |
| 611 kAudioTrackNum, | 646 kAudioTrackNum, |
| 612 kNoTimestamp(), | 647 kNoTimestamp(), |
| 613 kVideoTrackNum, | 648 kVideoTrackNum, |
| 614 kNoTimestamp(), | 649 kNoTimestamp(), |
| 615 text_tracks, | 650 text_tracks, |
| 616 std::set<int64>(), | 651 std::set<int64>(), |
| 617 std::string(), | 652 std::string(), |
| 618 std::string(), | 653 std::string(), |
| 654 AudioDecoderConfig(), | |
| 619 LogCB())); | 655 LogCB())); |
| 620 | 656 |
| 621 const BlockInfo kInputBlockInfo[] = { | 657 const BlockInfo kInputBlockInfo[] = { |
| 622 { kAudioTrackNum, 0, 23, true }, | 658 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
| 623 { kAudioTrackNum, 23, 23, true }, | 659 {kAudioTrackNum, 23, 23, true, NULL, 0}, |
| 624 { kVideoTrackNum, 33, 34, true }, | 660 {kVideoTrackNum, 33, 34, true, NULL, 0}, |
| 625 { kSubtitleTextTrackNum, 33, 42, false }, | 661 {kSubtitleTextTrackNum, 33, 42, false, NULL, 0}, |
| 626 { kAudioTrackNum, 46, 23, true }, | 662 {kAudioTrackNum, 46, 23, true, NULL, 0}, |
| 627 { kCaptionTextTrackNum, 55, 44, false }, | 663 {kCaptionTextTrackNum, 55, 44, false, NULL, 0}, |
| 628 { kVideoTrackNum, 67, 34, true }, | 664 {kVideoTrackNum, 67, 34, true, NULL, 0}, |
| 629 { kSubtitleTextTrackNum, 67, 33, false }, | 665 {kSubtitleTextTrackNum, 67, 33, false, NULL, 0}, |
| 630 }; | 666 }; |
| 631 int input_block_count = arraysize(kInputBlockInfo); | 667 int input_block_count = arraysize(kInputBlockInfo); |
| 632 | 668 |
| 633 scoped_ptr<Cluster> cluster( | 669 scoped_ptr<Cluster> cluster( |
| 634 CreateCluster(0, kInputBlockInfo, input_block_count)); | 670 CreateCluster(0, kInputBlockInfo, input_block_count)); |
| 635 | 671 |
| 636 int result = parser_->Parse(cluster->data(), cluster->size()); | 672 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 637 EXPECT_EQ(cluster->size(), result); | 673 EXPECT_EQ(cluster->size(), result); |
| 638 | 674 |
| 639 const WebMClusterParser::TextBufferQueueMap& text_map = | 675 const WebMClusterParser::TextBufferQueueMap& text_map = |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 655 | 691 |
| 656 parser_.reset(new WebMClusterParser(kTimecodeScale, | 692 parser_.reset(new WebMClusterParser(kTimecodeScale, |
| 657 kAudioTrackNum, | 693 kAudioTrackNum, |
| 658 kNoTimestamp(), | 694 kNoTimestamp(), |
| 659 kVideoTrackNum, | 695 kVideoTrackNum, |
| 660 kNoTimestamp(), | 696 kNoTimestamp(), |
| 661 TextTracks(), | 697 TextTracks(), |
| 662 std::set<int64>(), | 698 std::set<int64>(), |
| 663 std::string(), | 699 std::string(), |
| 664 "video_key_id", | 700 "video_key_id", |
| 701 AudioDecoderConfig(), | |
| 665 LogCB())); | 702 LogCB())); |
| 666 int result = parser_->Parse(cluster->data(), cluster->size()); | 703 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 667 EXPECT_EQ(cluster->size(), result); | 704 EXPECT_EQ(cluster->size(), result); |
| 668 ASSERT_EQ(1UL, parser_->GetVideoBuffers().size()); | 705 ASSERT_EQ(1UL, parser_->GetVideoBuffers().size()); |
| 669 scoped_refptr<StreamParserBuffer> buffer = parser_->GetVideoBuffers()[0]; | 706 scoped_refptr<StreamParserBuffer> buffer = parser_->GetVideoBuffers()[0]; |
| 670 VerifyEncryptedBuffer(buffer); | 707 VerifyEncryptedBuffer(buffer); |
| 671 } | 708 } |
| 672 | 709 |
| 673 TEST_F(WebMClusterParserTest, ParseBadEncryptedBlock) { | 710 TEST_F(WebMClusterParserTest, ParseBadEncryptedBlock) { |
| 674 scoped_ptr<Cluster> cluster( | 711 scoped_ptr<Cluster> cluster( |
| 675 CreateEncryptedCluster(sizeof(kEncryptedFrame) - 1)); | 712 CreateEncryptedCluster(sizeof(kEncryptedFrame) - 1)); |
| 676 | 713 |
| 677 parser_.reset(new WebMClusterParser(kTimecodeScale, | 714 parser_.reset(new WebMClusterParser(kTimecodeScale, |
| 678 kAudioTrackNum, | 715 kAudioTrackNum, |
| 679 kNoTimestamp(), | 716 kNoTimestamp(), |
| 680 kVideoTrackNum, | 717 kVideoTrackNum, |
| 681 kNoTimestamp(), | 718 kNoTimestamp(), |
| 682 TextTracks(), | 719 TextTracks(), |
| 683 std::set<int64>(), | 720 std::set<int64>(), |
| 684 std::string(), | 721 std::string(), |
| 685 "video_key_id", | 722 "video_key_id", |
| 723 AudioDecoderConfig(), | |
| 686 LogCB())); | 724 LogCB())); |
| 687 int result = parser_->Parse(cluster->data(), cluster->size()); | 725 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 688 EXPECT_EQ(-1, result); | 726 EXPECT_EQ(-1, result); |
| 689 } | 727 } |
| 690 | 728 |
| 691 TEST_F(WebMClusterParserTest, ParseInvalidZeroSizedCluster) { | 729 TEST_F(WebMClusterParserTest, ParseInvalidZeroSizedCluster) { |
| 692 const uint8 kBuffer[] = { | 730 const uint8 kBuffer[] = { |
| 693 0x1F, 0x43, 0xB6, 0x75, 0x80, // CLUSTER (size = 0) | 731 0x1F, 0x43, 0xB6, 0x75, 0x80, // CLUSTER (size = 0) |
| 694 }; | 732 }; |
| 695 | 733 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 715 | 753 |
| 716 parser_.reset(new WebMClusterParser(kTimecodeScale, | 754 parser_.reset(new WebMClusterParser(kTimecodeScale, |
| 717 kAudioTrackNum, | 755 kAudioTrackNum, |
| 718 kNoTimestamp(), | 756 kNoTimestamp(), |
| 719 kVideoTrackNum, | 757 kVideoTrackNum, |
| 720 kNoTimestamp(), | 758 kNoTimestamp(), |
| 721 text_tracks, | 759 text_tracks, |
| 722 std::set<int64>(), | 760 std::set<int64>(), |
| 723 std::string(), | 761 std::string(), |
| 724 std::string(), | 762 std::string(), |
| 763 AudioDecoderConfig(), | |
| 725 LogCB())); | 764 LogCB())); |
| 726 | 765 |
| 727 const BlockInfo kBlockInfo[] = { | 766 const BlockInfo kBlockInfo[] = { |
| 728 { kTextTrackNum, 33, -42, false }, | 767 { kTextTrackNum, 33, -42, false }, |
| 729 }; | 768 }; |
| 730 int block_count = arraysize(kBlockInfo); | 769 int block_count = arraysize(kBlockInfo); |
| 731 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 770 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
| 732 int result = parser_->Parse(cluster->data(), cluster->size()); | 771 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 733 EXPECT_LT(result, 0); | 772 EXPECT_LT(result, 0); |
| 734 } | 773 } |
| 735 | 774 |
| 736 TEST_F(WebMClusterParserTest, ParseWithDefaultDurationsSimpleBlocks) { | 775 TEST_F(WebMClusterParserTest, ParseWithDefaultDurationsSimpleBlocks) { |
| 737 InSequence s; | 776 InSequence s; |
| 738 ResetParserToHaveDefaultDurations(); | 777 ResetParserToHaveDefaultDurations(); |
| 739 | 778 |
| 740 EXPECT_LT(kTestAudioFrameDefaultDurationInMs, 23); | 779 EXPECT_LT(kTestAudioFrameDefaultDurationInMs, 23); |
| 741 EXPECT_LT(kTestVideoFrameDefaultDurationInMs, 33); | 780 EXPECT_LT(kTestVideoFrameDefaultDurationInMs, 33); |
| 742 | 781 |
| 743 const BlockInfo kBlockInfo[] = { | 782 const BlockInfo kBlockInfo[] = { |
| 744 { kAudioTrackNum, 0, kTestAudioFrameDefaultDurationInMs, true }, | 783 {kAudioTrackNum, 0, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
| 745 { kAudioTrackNum, 23, kTestAudioFrameDefaultDurationInMs, true }, | 784 {kAudioTrackNum, 23, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
| 746 { kVideoTrackNum, 33, kTestVideoFrameDefaultDurationInMs, true }, | 785 {kVideoTrackNum, 33, kTestVideoFrameDefaultDurationInMs, true, NULL, 0}, |
| 747 { kAudioTrackNum, 46, kTestAudioFrameDefaultDurationInMs, true }, | 786 {kAudioTrackNum, 46, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
| 748 { kVideoTrackNum, 67, kTestVideoFrameDefaultDurationInMs, true }, | 787 {kVideoTrackNum, 67, kTestVideoFrameDefaultDurationInMs, true, NULL, 0}, |
| 749 { kAudioTrackNum, 69, kTestAudioFrameDefaultDurationInMs, true }, | 788 {kAudioTrackNum, 69, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
| 750 { kVideoTrackNum, 100, kTestVideoFrameDefaultDurationInMs, true }, | 789 {kVideoTrackNum, 100, kTestVideoFrameDefaultDurationInMs, true, NULL, 0}, |
| 751 }; | 790 }; |
| 752 | 791 |
| 753 int block_count = arraysize(kBlockInfo); | 792 int block_count = arraysize(kBlockInfo); |
| 754 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 793 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
| 755 | 794 |
| 756 // Send slightly less than the full cluster so all but the last block is | 795 // Send slightly less than the full cluster so all but the last block is |
| 757 // parsed. Though all the blocks are simple blocks, none should be held aside | 796 // parsed. Though all the blocks are simple blocks, none should be held aside |
| 758 // for duration estimation prior to end of cluster detection because all the | 797 // for duration estimation prior to end of cluster detection because all the |
| 759 // tracks have DefaultDurations. | 798 // tracks have DefaultDurations. |
| 760 int result = parser_->Parse(cluster->data(), cluster->size() - 1); | 799 int result = parser_->Parse(cluster->data(), cluster->size() - 1); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 771 } | 810 } |
| 772 | 811 |
| 773 TEST_F(WebMClusterParserTest, ParseWithoutAnyDurationsSimpleBlocks) { | 812 TEST_F(WebMClusterParserTest, ParseWithoutAnyDurationsSimpleBlocks) { |
| 774 InSequence s; | 813 InSequence s; |
| 775 | 814 |
| 776 // Absent DefaultDuration information, SimpleBlock durations are derived from | 815 // Absent DefaultDuration information, SimpleBlock durations are derived from |
| 777 // inter-buffer track timestamp delta if within the cluster, and are estimated | 816 // inter-buffer track timestamp delta if within the cluster, and are estimated |
| 778 // as the lowest non-zero duration seen so far if the last buffer in the track | 817 // as the lowest non-zero duration seen so far if the last buffer in the track |
| 779 // in the cluster (independently for each track in the cluster). | 818 // in the cluster (independently for each track in the cluster). |
| 780 const BlockInfo kBlockInfo1[] = { | 819 const BlockInfo kBlockInfo1[] = { |
| 781 { kAudioTrackNum, 0, 23, true }, | 820 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
| 782 { kAudioTrackNum, 23, 22, true }, | 821 {kAudioTrackNum, 23, 22, true, NULL, 0}, |
| 783 { kVideoTrackNum, 33, 33, true }, | 822 {kVideoTrackNum, 33, 33, true, NULL, 0}, |
| 784 { kAudioTrackNum, 45, 23, true }, | 823 {kAudioTrackNum, 45, 23, true, NULL, 0}, |
| 785 { kVideoTrackNum, 66, 34, true }, | 824 {kVideoTrackNum, 66, 34, true, NULL, 0}, |
| 786 { kAudioTrackNum, 68, 22, true }, // Estimated from minimum audio dur | 825 // Estimated from minimum audio dur |
| 787 { kVideoTrackNum, 100, 33, true }, // Estimated from minimum video dur | 826 {kAudioTrackNum, 68, 22, true, NULL, 0}, |
| 827 // Estimated from minimum video dur | |
| 828 {kVideoTrackNum, 100, 33, true, NULL, 0}, | |
| 788 }; | 829 }; |
| 789 | 830 |
| 790 int block_count1 = arraysize(kBlockInfo1); | 831 int block_count1 = arraysize(kBlockInfo1); |
| 791 scoped_ptr<Cluster> cluster1(CreateCluster(0, kBlockInfo1, block_count1)); | 832 scoped_ptr<Cluster> cluster1(CreateCluster(0, kBlockInfo1, block_count1)); |
| 792 | 833 |
| 793 // Send slightly less than the first full cluster so all but the last video | 834 // Send slightly less than the first full cluster so all but the last video |
| 794 // block is parsed. Verify the last fully parsed audio and video buffer are | 835 // block is parsed. Verify the last fully parsed audio and video buffer are |
| 795 // both missing from the result (parser should hold them aside for duration | 836 // both missing from the result (parser should hold them aside for duration |
| 796 // estimation prior to end of cluster detection in the absence of | 837 // estimation prior to end of cluster detection in the absence of |
| 797 // DefaultDurations.) | 838 // DefaultDurations.) |
| 798 int result = parser_->Parse(cluster1->data(), cluster1->size() - 1); | 839 int result = parser_->Parse(cluster1->data(), cluster1->size() - 1); |
| 799 EXPECT_GT(result, 0); | 840 EXPECT_GT(result, 0); |
| 800 EXPECT_LT(result, cluster1->size()); | 841 EXPECT_LT(result, cluster1->size()); |
| 801 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1 - 3)); | 842 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1 - 3)); |
| 802 EXPECT_EQ(3UL, parser_->GetAudioBuffers().size()); | 843 EXPECT_EQ(3UL, parser_->GetAudioBuffers().size()); |
| 803 EXPECT_EQ(1UL, parser_->GetVideoBuffers().size()); | 844 EXPECT_EQ(1UL, parser_->GetVideoBuffers().size()); |
| 804 | 845 |
| 805 parser_->Reset(); | 846 parser_->Reset(); |
| 806 | 847 |
| 807 // Now parse the full first cluster and verify all the blocks are parsed. | 848 // Now parse the full first cluster and verify all the blocks are parsed. |
| 808 result = parser_->Parse(cluster1->data(), cluster1->size()); | 849 result = parser_->Parse(cluster1->data(), cluster1->size()); |
| 809 EXPECT_EQ(cluster1->size(), result); | 850 EXPECT_EQ(cluster1->size(), result); |
| 810 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1)); | 851 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1)); |
| 811 | 852 |
| 812 // Verify that the estimated frame duration is tracked across clusters for | 853 // Verify that the estimated frame duration is tracked across clusters for |
| 813 // each track. | 854 // each track. |
| 814 const BlockInfo kBlockInfo2[] = { | 855 const BlockInfo kBlockInfo2[] = { |
| 815 { kAudioTrackNum, 200, 22, true }, // Estimate carries over across clusters | 856 // Estimate carries over across clusters |
| 816 { kVideoTrackNum, 201, 33, true }, // Estimate carries over across clusters | 857 {kAudioTrackNum, 200, 22, true, NULL, 0}, |
| 858 // Estimate carries over across clusters | |
| 859 {kVideoTrackNum, 201, 33, true, NULL, 0}, | |
| 817 }; | 860 }; |
| 818 | 861 |
| 819 int block_count2 = arraysize(kBlockInfo2); | 862 int block_count2 = arraysize(kBlockInfo2); |
| 820 scoped_ptr<Cluster> cluster2(CreateCluster(0, kBlockInfo2, block_count2)); | 863 scoped_ptr<Cluster> cluster2(CreateCluster(0, kBlockInfo2, block_count2)); |
| 821 result = parser_->Parse(cluster2->data(), cluster2->size()); | 864 result = parser_->Parse(cluster2->data(), cluster2->size()); |
| 822 EXPECT_EQ(cluster2->size(), result); | 865 EXPECT_EQ(cluster2->size(), result); |
| 823 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo2, block_count2)); | 866 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo2, block_count2)); |
| 824 } | 867 } |
| 825 | 868 |
| 826 TEST_F(WebMClusterParserTest, ParseWithoutAnyDurationsBlockGroups) { | 869 TEST_F(WebMClusterParserTest, ParseWithoutAnyDurationsBlockGroups) { |
| 827 InSequence s; | 870 InSequence s; |
| 828 | 871 |
| 829 // Absent DefaultDuration and BlockDuration information, BlockGroup block | 872 // Absent DefaultDuration and BlockDuration information, BlockGroup block |
| 830 // durations are derived from inter-buffer track timestamp delta if within the | 873 // durations are derived from inter-buffer track timestamp delta if within the |
| 831 // cluster, and are estimated as the lowest non-zero duration seen so far if | 874 // cluster, and are estimated as the lowest non-zero duration seen so far if |
| 832 // the last buffer in the track in the cluster (independently for each track | 875 // the last buffer in the track in the cluster (independently for each track |
| 833 // in the cluster). | 876 // in the cluster). |
| 834 const BlockInfo kBlockInfo1[] = { | 877 const BlockInfo kBlockInfo1[] = { |
| 835 { kAudioTrackNum, 0, -23, false }, | 878 {kAudioTrackNum, 0, -23, false, NULL, 0}, |
| 836 { kAudioTrackNum, 23, -22, false }, | 879 {kAudioTrackNum, 23, -22, false, NULL, 0}, |
| 837 { kVideoTrackNum, 33, -33, false }, | 880 {kVideoTrackNum, 33, -33, false, NULL, 0}, |
| 838 { kAudioTrackNum, 45, -23, false }, | 881 {kAudioTrackNum, 45, -23, false, NULL, 0}, |
| 839 { kVideoTrackNum, 66, -34, false }, | 882 {kVideoTrackNum, 66, -34, false, NULL, 0}, |
| 840 { kAudioTrackNum, 68, -22, false }, // Estimated from minimum audio dur | 883 // Estimated from minimum audio dur |
| 841 { kVideoTrackNum, 100, -33, false }, // Estimated from minimum video dur | 884 {kAudioTrackNum, 68, -22, false, NULL, 0}, |
| 885 // Estimated from minimum video dur | |
| 886 {kVideoTrackNum, 100, -33, false, NULL, 0}, | |
| 842 }; | 887 }; |
| 843 | 888 |
| 844 int block_count1 = arraysize(kBlockInfo1); | 889 int block_count1 = arraysize(kBlockInfo1); |
| 845 scoped_ptr<Cluster> cluster1(CreateCluster(0, kBlockInfo1, block_count1)); | 890 scoped_ptr<Cluster> cluster1(CreateCluster(0, kBlockInfo1, block_count1)); |
| 846 | 891 |
| 847 // Send slightly less than the first full cluster so all but the last video | 892 // Send slightly less than the first full cluster so all but the last video |
| 848 // block is parsed. Verify the last fully parsed audio and video buffer are | 893 // block is parsed. Verify the last fully parsed audio and video buffer are |
| 849 // both missing from the result (parser should hold them aside for duration | 894 // both missing from the result (parser should hold them aside for duration |
| 850 // estimation prior to end of cluster detection in the absence of | 895 // estimation prior to end of cluster detection in the absence of |
| 851 // DefaultDurations.) | 896 // DefaultDurations.) |
| 852 int result = parser_->Parse(cluster1->data(), cluster1->size() - 1); | 897 int result = parser_->Parse(cluster1->data(), cluster1->size() - 1); |
| 853 EXPECT_GT(result, 0); | 898 EXPECT_GT(result, 0); |
| 854 EXPECT_LT(result, cluster1->size()); | 899 EXPECT_LT(result, cluster1->size()); |
| 855 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1 - 3)); | 900 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1 - 3)); |
| 856 EXPECT_EQ(3UL, parser_->GetAudioBuffers().size()); | 901 EXPECT_EQ(3UL, parser_->GetAudioBuffers().size()); |
| 857 EXPECT_EQ(1UL, parser_->GetVideoBuffers().size()); | 902 EXPECT_EQ(1UL, parser_->GetVideoBuffers().size()); |
| 858 | 903 |
| 859 parser_->Reset(); | 904 parser_->Reset(); |
| 860 | 905 |
| 861 // Now parse the full first cluster and verify all the blocks are parsed. | 906 // Now parse the full first cluster and verify all the blocks are parsed. |
| 862 result = parser_->Parse(cluster1->data(), cluster1->size()); | 907 result = parser_->Parse(cluster1->data(), cluster1->size()); |
| 863 EXPECT_EQ(cluster1->size(), result); | 908 EXPECT_EQ(cluster1->size(), result); |
| 864 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1)); | 909 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1)); |
| 865 | 910 |
| 866 // Verify that the estimated frame duration is tracked across clusters for | 911 // Verify that the estimated frame duration is tracked across clusters for |
| 867 // each track. | 912 // each track. |
| 868 const BlockInfo kBlockInfo2[] = { | 913 const BlockInfo kBlockInfo2[] = { |
| 869 { kAudioTrackNum, 200, -22, false }, | 914 {kAudioTrackNum, 200, -22, false, NULL, 0}, |
| 870 { kVideoTrackNum, 201, -33, false }, | 915 {kVideoTrackNum, 201, -33, false, NULL, 0}, |
| 871 }; | 916 }; |
| 872 | 917 |
| 873 int block_count2 = arraysize(kBlockInfo2); | 918 int block_count2 = arraysize(kBlockInfo2); |
| 874 scoped_ptr<Cluster> cluster2(CreateCluster(0, kBlockInfo2, block_count2)); | 919 scoped_ptr<Cluster> cluster2(CreateCluster(0, kBlockInfo2, block_count2)); |
| 875 result = parser_->Parse(cluster2->data(), cluster2->size()); | 920 result = parser_->Parse(cluster2->data(), cluster2->size()); |
| 876 EXPECT_EQ(cluster2->size(), result); | 921 EXPECT_EQ(cluster2->size(), result); |
| 877 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo2, block_count2)); | 922 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo2, block_count2)); |
| 878 } | 923 } |
| 879 | 924 |
| 880 // TODO(wolenetz): Is parser behavior correct? See http://crbug.com/363433. | 925 // TODO(wolenetz): Is parser behavior correct? See http://crbug.com/363433. |
| 881 TEST_F(WebMClusterParserTest, | 926 TEST_F(WebMClusterParserTest, |
| 882 ParseWithDefaultDurationsBlockGroupsWithoutDurations) { | 927 ParseWithDefaultDurationsBlockGroupsWithoutDurations) { |
| 883 InSequence s; | 928 InSequence s; |
| 884 ResetParserToHaveDefaultDurations(); | 929 ResetParserToHaveDefaultDurations(); |
| 885 | 930 |
| 886 EXPECT_LT(kTestAudioFrameDefaultDurationInMs, 23); | 931 EXPECT_LT(kTestAudioFrameDefaultDurationInMs, 23); |
| 887 EXPECT_LT(kTestVideoFrameDefaultDurationInMs, 33); | 932 EXPECT_LT(kTestVideoFrameDefaultDurationInMs, 33); |
| 888 | 933 |
| 889 const BlockInfo kBlockInfo[] = { | 934 const BlockInfo kBlockInfo[] = { |
| 890 { kAudioTrackNum, 0, -kTestAudioFrameDefaultDurationInMs, false }, | 935 {kAudioTrackNum, 0, -kTestAudioFrameDefaultDurationInMs, false, NULL, 0}, |
| 891 { kAudioTrackNum, 23, -kTestAudioFrameDefaultDurationInMs, false }, | 936 {kAudioTrackNum, 23, -kTestAudioFrameDefaultDurationInMs, false, NULL, 0}, |
| 892 { kVideoTrackNum, 33, -kTestVideoFrameDefaultDurationInMs, false }, | 937 {kVideoTrackNum, 33, -kTestVideoFrameDefaultDurationInMs, false, NULL, 0}, |
| 893 { kAudioTrackNum, 46, -kTestAudioFrameDefaultDurationInMs, false }, | 938 {kAudioTrackNum, 46, -kTestAudioFrameDefaultDurationInMs, false, NULL, 0}, |
| 894 { kVideoTrackNum, 67, -kTestVideoFrameDefaultDurationInMs, false }, | 939 {kVideoTrackNum, 67, -kTestVideoFrameDefaultDurationInMs, false, NULL, 0}, |
| 895 { kAudioTrackNum, 69, -kTestAudioFrameDefaultDurationInMs, false }, | 940 {kAudioTrackNum, 69, -kTestAudioFrameDefaultDurationInMs, false, NULL, 0}, |
| 896 { kVideoTrackNum, 100, -kTestVideoFrameDefaultDurationInMs, false }, | 941 {kVideoTrackNum, |
| 942 100, | |
| 943 -kTestVideoFrameDefaultDurationInMs, | |
| 944 false, | |
| 945 NULL, | |
| 946 0}, | |
| 897 }; | 947 }; |
| 898 | 948 |
| 899 int block_count = arraysize(kBlockInfo); | 949 int block_count = arraysize(kBlockInfo); |
| 900 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 950 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
| 901 | 951 |
| 902 // Send slightly less than the full cluster so all but the last block is | 952 // Send slightly less than the full cluster so all but the last block is |
| 903 // parsed. None should be held aside for duration estimation prior to end of | 953 // parsed. None should be held aside for duration estimation prior to end of |
| 904 // cluster detection because all the tracks have DefaultDurations. | 954 // cluster detection because all the tracks have DefaultDurations. |
| 905 int result = parser_->Parse(cluster->data(), cluster->size() - 1); | 955 int result = parser_->Parse(cluster->data(), cluster->size() - 1); |
| 906 EXPECT_GT(result, 0); | 956 EXPECT_GT(result, 0); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 936 int result = parser_->Parse(cluster->data(), cluster->size()); | 986 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 937 EXPECT_EQ(cluster->size(), result); | 987 EXPECT_EQ(cluster->size(), result); |
| 938 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | 988 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); |
| 939 } | 989 } |
| 940 | 990 |
| 941 TEST_F(WebMClusterParserTest, | 991 TEST_F(WebMClusterParserTest, |
| 942 ParseDegenerateClusterWithDefaultDurationsYieldsDefaultDurations) { | 992 ParseDegenerateClusterWithDefaultDurationsYieldsDefaultDurations) { |
| 943 ResetParserToHaveDefaultDurations(); | 993 ResetParserToHaveDefaultDurations(); |
| 944 | 994 |
| 945 const BlockInfo kBlockInfo[] = { | 995 const BlockInfo kBlockInfo[] = { |
| 946 { kAudioTrackNum, 0, kTestAudioFrameDefaultDurationInMs, true }, | 996 {kAudioTrackNum, 0, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
| 947 { kVideoTrackNum, 0, kTestVideoFrameDefaultDurationInMs, true }, | 997 {kVideoTrackNum, 0, kTestVideoFrameDefaultDurationInMs, true, NULL, 0}, |
| 948 }; | 998 }; |
| 949 | 999 |
| 950 int block_count = arraysize(kBlockInfo); | 1000 int block_count = arraysize(kBlockInfo); |
| 951 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 1001 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
| 952 int result = parser_->Parse(cluster->data(), cluster->size()); | 1002 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 953 EXPECT_EQ(cluster->size(), result); | 1003 EXPECT_EQ(cluster->size(), result); |
| 954 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | 1004 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); |
| 955 } | 1005 } |
| 956 | 1006 |
| 1007 using OpusTestParam = std::tr1::tuple<int, int, bool>; | |
| 1008 class OpusWebMClusterParserTest | |
|
wolenetz
2015/01/30 20:46:12
This looks like a good candidate for splitting out
chcunningham
2015/02/03 20:34:43
I split the Builder pieces into a separate file. W
| |
| 1009 : public WebMClusterParserTest, | |
| 1010 public ::testing::WithParamInterface<OpusTestParam> { | |
| 1011 protected: | |
| 1012 void SetUp() override { | |
| 1013 opus_config_ = std::tr1::get<0>(GetParam()); | |
| 1014 opus_frame_count_ = std::tr1::get<1>(GetParam()); | |
| 1015 variable_len_frames_ = std::tr1::get<2>(GetParam()); | |
| 1016 | |
| 1017 parser_.reset(new WebMClusterParser( | |
| 1018 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, | |
| 1019 kNoTimestamp(), TextTracks(), std::set<int64>(), std::string(), | |
| 1020 std::string(), kOpusAudioConfig, LogCB())); | |
| 1021 } | |
| 1022 | |
| 1023 // 5 highest bits of the Opus TOC byte. | |
| 1024 int opus_config_; | |
| 1025 | |
| 1026 // Number of frames in the opus packet. | |
| 1027 int opus_frame_count_; | |
| 1028 | |
| 1029 // Indicates compressed frames may differ in length. Only considered when | |
| 1030 // opus_frame_count_ >= 2. | |
| 1031 bool variable_len_frames_; | |
| 1032 }; | |
| 1033 | |
| 1034 std::vector<uint8> BuildOpusPacket(int config, | |
|
chcunningham
2015/01/29 22:14:20
I'm expecting this return to be RVO'd. Am I right?
wolenetz
2015/01/30 20:46:12
This is fine with me for these tests. For producti
chcunningham
2015/02/03 20:34:43
Acknowledged.
| |
| 1035 int frame_count, | |
| 1036 bool variable_len) { | |
| 1037 std::vector<uint8> opus_bytes; | |
| 1038 int frame_count_code; | |
| 1039 uint8 frame_count_byte; | |
| 1040 | |
| 1041 if (frame_count == 1) { | |
| 1042 frame_count_code = 0; | |
| 1043 } else if (frame_count == 2) { | |
| 1044 frame_count_code = variable_len ? 2 : 1; | |
| 1045 } else { | |
| 1046 frame_count_code = 3; | |
| 1047 frame_count_byte = (variable_len ? 1 << 7 : 0) | frame_count; | |
| 1048 } | |
| 1049 | |
| 1050 // All opus packets must have TOC byte. | |
| 1051 uint8 opus_toc_byte = (config << 3) | frame_count_code; | |
| 1052 opus_bytes.push_back(opus_toc_byte); | |
| 1053 | |
| 1054 // For code 3 packets, the number of frames is signalled in the "frame | |
| 1055 // count byte". | |
| 1056 if (frame_count_code == 3) { | |
| 1057 opus_bytes.push_back(frame_count_byte); | |
| 1058 } | |
| 1059 | |
| 1060 // Simulating encoded frame data. | |
| 1061 opus_bytes.push_back(static_cast<uint8>(0)); | |
| 1062 | |
| 1063 return opus_bytes; | |
| 1064 } | |
| 1065 | |
| 1066 TEST_P(OpusWebMClusterParserTest, ReadOpusDurationSimpleBlockAtEndOfCluster) { | |
| 1067 std::vector<uint8> opus_bytes = | |
| 1068 BuildOpusPacket(opus_config_, opus_frame_count_, variable_len_frames_); | |
| 1069 | |
| 1070 int expected_duration_ms = | |
| 1071 opus_frame_count_ * | |
| 1072 (parser_->kOpusFrameDurationsMu[opus_config_] / static_cast<float>(1000)); | |
| 1073 | |
| 1074 const BlockInfo kBlockInfo[] = {{kAudioTrackNum, | |
| 1075 0, | |
| 1076 expected_duration_ms, | |
| 1077 true, // Make it a SimpleBlock. | |
| 1078 &opus_bytes[0], | |
| 1079 opus_bytes.size()}}; | |
| 1080 | |
| 1081 int block_count = arraysize(kBlockInfo); | |
| 1082 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | |
| 1083 int result = parser_->Parse(cluster->data(), cluster->size()); | |
| 1084 EXPECT_EQ(cluster->size(), result); | |
| 1085 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | |
| 1086 } | |
| 1087 | |
| 1088 TEST_P(OpusWebMClusterParserTest, PreferOpusDurationsOverBlockDurations) { | |
| 1089 std::vector<uint8> opus_bytes = | |
| 1090 BuildOpusPacket(opus_config_, opus_frame_count_, variable_len_frames_); | |
| 1091 | |
| 1092 int expected_duration_ms = | |
| 1093 opus_frame_count_ * | |
| 1094 (parser_->kOpusFrameDurationsMu[opus_config_] / static_cast<float>(1000)); | |
| 1095 | |
| 1096 // Setting BlockDuration != Opus duration to see which one the parser uses. | |
| 1097 int block_duration_ms = expected_duration_ms + 10; | |
| 1098 | |
| 1099 BlockInfo block_infos[] = {{kAudioTrackNum, | |
| 1100 0, | |
| 1101 block_duration_ms, | |
| 1102 false, // Not a SimpleBlock. | |
| 1103 &opus_bytes[0], | |
| 1104 opus_bytes.size()}}; | |
| 1105 | |
| 1106 int block_count = arraysize(block_infos); | |
| 1107 scoped_ptr<Cluster> cluster(CreateCluster(0, block_infos, block_count)); | |
| 1108 int result = parser_->Parse(cluster->data(), cluster->size()); | |
| 1109 EXPECT_EQ(cluster->size(), result); | |
| 1110 | |
| 1111 // BlockInfo duration will be used to verify buffer duration, so changing | |
| 1112 // duration to be that of the Opus packet to verify it was preferred. | |
| 1113 block_infos[0].duration = expected_duration_ms; | |
| 1114 ASSERT_TRUE(VerifyBuffers(parser_, block_infos, block_count)); | |
| 1115 } | |
| 1116 | |
| 1117 // From Opus RFC. | |
|
wolenetz
2015/01/30 20:46:12
provide link please
chcunningham
2015/02/03 20:34:43
Done.
| |
| 1118 const int kNumPossibleOpusConfigs = 32; | |
|
wolenetz
2015/01/30 20:46:12
constants like these, we more often than not put i
chcunningham
2015/02/03 20:34:43
Done.
| |
| 1119 const int kMaxOpusPacketFrameCount = 48; | |
| 1120 | |
| 1121 INSTANTIATE_TEST_CASE_P( | |
|
chcunningham
2015/01/29 22:14:20
This was a fun exploration for me, but I think it
wolenetz
2015/01/30 20:46:12
yeah, overkill. Please consider categories of test
chcunningham
2015/02/03 20:34:43
Done, mostly. We chatted about not adding the nega
wolenetz
2015/02/03 22:47:01
Acknowledged.
| |
| 1122 SingleFrameOpusPackets, | |
| 1123 OpusWebMClusterParserTest, | |
| 1124 ::testing::Combine(::testing::Range(0, kNumPossibleOpusConfigs), | |
| 1125 ::testing::Values(1), | |
| 1126 ::testing::Values(false))); | |
| 1127 | |
| 1128 INSTANTIATE_TEST_CASE_P( | |
| 1129 DoubleFrameOpusPackets, | |
| 1130 OpusWebMClusterParserTest, | |
| 1131 ::testing::Combine( | |
| 1132 ::testing::Range(0, kNumPossibleOpusConfigs), | |
| 1133 ::testing::Values(2), | |
| 1134 // Lets VBR flag varry, as this affects TOC config for 2 frame packets. | |
|
wolenetz
2015/01/30 20:46:12
nit: varry spelling
chcunningham
2015/02/03 20:34:43
Done.
| |
| 1135 ::testing::Bool())); | |
| 1136 | |
| 1137 INSTANTIATE_TEST_CASE_P( | |
| 1138 MultiFrameOpusPackets, | |
| 1139 OpusWebMClusterParserTest, | |
| 1140 ::testing::Combine(::testing::Range(0, kNumPossibleOpusConfigs), | |
| 1141 ::testing::Range(3, kMaxOpusPacketFrameCount), | |
| 1142 ::testing::Values(false))); | |
| 1143 | |
| 957 } // namespace media | 1144 } // namespace media |
| OLD | NEW |