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