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" |
| 14 #include "media/formats/webm/opus_packet_builder.h" | |
| 12 #include "media/formats/webm/webm_cluster_parser.h" | 15 #include "media/formats/webm/webm_cluster_parser.h" |
| 13 #include "media/formats/webm/webm_constants.h" | 16 #include "media/formats/webm/webm_constants.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 19 |
| 17 using ::testing::InSequence; | 20 using ::testing::InSequence; |
| 18 using ::testing::Return; | 21 using ::testing::Return; |
| 19 using ::testing::_; | 22 using ::testing::_; |
| 20 | 23 |
| 21 namespace media { | 24 namespace media { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 42 | 45 |
| 43 struct BlockInfo { | 46 struct BlockInfo { |
| 44 int track_num; | 47 int track_num; |
| 45 int timestamp; | 48 int timestamp; |
| 46 | 49 |
| 47 // Negative value is allowed only for block groups (not simple blocks) and | 50 // Negative value is allowed only for block groups (not simple blocks) and |
| 48 // directs CreateCluster() to exclude BlockDuration entry from the cluster for | 51 // directs CreateCluster() to exclude BlockDuration entry from the cluster for |
| 49 // this BlockGroup. The absolute value is used for parser verification. | 52 // 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 | 53 // For simple blocks, this value must be non-negative, and is used only for |
| 51 // parser verification. | 54 // parser verification. |
| 52 int duration; | 55 float duration; |
| 56 | |
| 53 bool use_simple_block; | 57 bool use_simple_block; |
| 58 | |
| 59 // Default data will be used if no data given. | |
| 60 const uint8* data; | |
| 61 int data_length; | |
| 54 }; | 62 }; |
| 55 | 63 |
| 56 static const BlockInfo kDefaultBlockInfo[] = { | 64 static const BlockInfo kDefaultBlockInfo[] = { |
| 57 { kAudioTrackNum, 0, 23, true }, | 65 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
| 58 { kAudioTrackNum, 23, 23, true }, | 66 {kAudioTrackNum, 23, 23, true, NULL, 0}, |
| 59 { kVideoTrackNum, 33, 34, true }, // Assumes not using DefaultDuration | 67 // Assumes not using DefaultDuration |
| 60 { kAudioTrackNum, 46, 23, true }, | 68 {kVideoTrackNum, 33, 34, true, NULL, 0}, |
| 61 { kVideoTrackNum, 67, 33, false }, | 69 {kAudioTrackNum, 46, 23, true, NULL, 0}, |
| 62 { kAudioTrackNum, 69, 23, false }, | 70 {kVideoTrackNum, 67, 33, false, NULL, 0}, |
| 63 { kVideoTrackNum, 100, 33, false }, | 71 {kAudioTrackNum, 69, 23, false, NULL, 0}, |
| 72 {kVideoTrackNum, 100, 33, false, NULL, 0}, | |
| 64 }; | 73 }; |
| 65 | 74 |
| 66 static const uint8 kEncryptedFrame[] = { | 75 static const uint8 kEncryptedFrame[] = { |
| 67 0x01, // Block is encrypted | 76 0x01, // Block is encrypted |
| 68 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 // IV | 77 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 // IV |
| 69 }; | 78 }; |
| 70 | 79 |
| 71 static scoped_ptr<Cluster> CreateCluster(int timecode, | 80 static scoped_ptr<Cluster> CreateCluster(int timecode, |
| 72 const BlockInfo* block_info, | 81 const BlockInfo* block_info, |
| 73 int block_count) { | 82 int block_count) { |
| 74 ClusterBuilder cb; | 83 ClusterBuilder cb; |
| 75 cb.SetClusterTimecode(0); | 84 cb.SetClusterTimecode(0); |
| 76 | 85 |
| 86 uint8 kDefaultBlockData[] = {0x00}; | |
|
wolenetz
2015/02/03 22:47:02
nit: space after { and before }
chcunningham
2015/02/05 02:48:22
Done.
| |
| 87 | |
| 77 for (int i = 0; i < block_count; i++) { | 88 for (int i = 0; i < block_count; i++) { |
| 78 uint8 data[] = { 0x00 }; | 89 const uint8* data; |
| 90 int data_length; | |
| 91 if (block_info[i].data != NULL) { | |
| 92 data = block_info[i].data; | |
| 93 data_length = block_info[i].data_length; | |
| 94 } else { | |
| 95 data = kDefaultBlockData; | |
| 96 data_length = sizeof(kDefaultBlockData); | |
| 97 } | |
| 98 | |
| 79 if (block_info[i].use_simple_block) { | 99 if (block_info[i].use_simple_block) { |
| 80 CHECK_GE(block_info[i].duration, 0); | 100 CHECK_GE(block_info[i].duration, 0); |
| 81 cb.AddSimpleBlock(block_info[i].track_num, | 101 cb.AddSimpleBlock(block_info[i].track_num, block_info[i].timestamp, 0, |
| 82 block_info[i].timestamp, | 102 data, data_length); |
| 83 0, data, sizeof(data)); | |
| 84 continue; | 103 continue; |
| 85 } | 104 } |
| 86 | 105 |
| 87 if (block_info[i].duration < 0) { | 106 if (block_info[i].duration < 0) { |
| 88 cb.AddBlockGroupWithoutBlockDuration(block_info[i].track_num, | 107 cb.AddBlockGroupWithoutBlockDuration(block_info[i].track_num, |
| 89 block_info[i].timestamp, | 108 block_info[i].timestamp, 0, data, |
| 90 0, data, sizeof(data)); | 109 data_length); |
| 91 continue; | 110 continue; |
| 92 } | 111 } |
| 93 | 112 |
| 94 cb.AddBlockGroup(block_info[i].track_num, | 113 cb.AddBlockGroup(block_info[i].track_num, block_info[i].timestamp, |
| 95 block_info[i].timestamp, | 114 block_info[i].duration, 0, data, data_length); |
| 96 block_info[i].duration, | |
| 97 0, data, sizeof(data)); | |
| 98 } | 115 } |
| 99 | 116 |
| 100 return cb.Finish(); | 117 return cb.Finish(); |
| 101 } | 118 } |
| 102 | 119 |
| 103 // Creates a Cluster with one encrypted Block. |bytes_to_write| is number of | 120 // Creates a Cluster with one encrypted Block. |bytes_to_write| is number of |
| 104 // bytes of the encrypted frame to write. | 121 // bytes of the encrypted frame to write. |
| 105 static scoped_ptr<Cluster> CreateEncryptedCluster(int bytes_to_write) { | 122 static scoped_ptr<Cluster> CreateEncryptedCluster(int bytes_to_write) { |
| 106 CHECK_GT(bytes_to_write, 0); | 123 CHECK_GT(bytes_to_write, 0); |
| 107 CHECK_LE(bytes_to_write, static_cast<int>(sizeof(kEncryptedFrame))); | 124 CHECK_LE(bytes_to_write, static_cast<int>(sizeof(kEncryptedFrame))); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 DVLOG(1) << __FUNCTION__ << " : Too few buffers (" << buffers->size() | 171 DVLOG(1) << __FUNCTION__ << " : Too few buffers (" << buffers->size() |
| 155 << ") for track_num (" << block_info[i].track_num | 172 << ") for track_num (" << block_info[i].track_num |
| 156 << "), expected at least " << *offset + 1 << " buffers"; | 173 << "), expected at least " << *offset + 1 << " buffers"; |
| 157 return false; | 174 return false; |
| 158 } | 175 } |
| 159 | 176 |
| 160 scoped_refptr<StreamParserBuffer> buffer = (*buffers)[(*offset)++]; | 177 scoped_refptr<StreamParserBuffer> buffer = (*buffers)[(*offset)++]; |
| 161 | 178 |
| 162 EXPECT_EQ(block_info[i].timestamp, buffer->timestamp().InMilliseconds()); | 179 EXPECT_EQ(block_info[i].timestamp, buffer->timestamp().InMilliseconds()); |
| 163 EXPECT_EQ(std::abs(block_info[i].duration), | 180 EXPECT_EQ(std::abs(block_info[i].duration), |
| 164 buffer->duration().InMilliseconds()); | 181 buffer->duration().InMillisecondsF()); |
| 165 EXPECT_EQ(expected_type, buffer->type()); | 182 EXPECT_EQ(expected_type, buffer->type()); |
| 166 EXPECT_EQ(block_info[i].track_num, buffer->track_id()); | 183 EXPECT_EQ(block_info[i].track_num, buffer->track_id()); |
| 167 } | 184 } |
| 168 | 185 |
| 169 return true; | 186 return true; |
| 170 } | 187 } |
| 171 | 188 |
| 172 static bool VerifyBuffers(const scoped_ptr<WebMClusterParser>& parser, | 189 static bool VerifyBuffers(const scoped_ptr<WebMClusterParser>& parser, |
| 173 const BlockInfo* block_info, | 190 const BlockInfo* block_info, |
| 174 int block_count) { | 191 int block_count) { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 205 | 222 |
| 206 if (block_info.track_num != text_track_num) | 223 if (block_info.track_num != text_track_num) |
| 207 continue; | 224 continue; |
| 208 | 225 |
| 209 EXPECT_FALSE(block_info.use_simple_block); | 226 EXPECT_FALSE(block_info.use_simple_block); |
| 210 EXPECT_FALSE(buffer_iter == buffer_end); | 227 EXPECT_FALSE(buffer_iter == buffer_end); |
| 211 | 228 |
| 212 const scoped_refptr<StreamParserBuffer> buffer = *buffer_iter++; | 229 const scoped_refptr<StreamParserBuffer> buffer = *buffer_iter++; |
| 213 EXPECT_EQ(block_info.timestamp, buffer->timestamp().InMilliseconds()); | 230 EXPECT_EQ(block_info.timestamp, buffer->timestamp().InMilliseconds()); |
| 214 EXPECT_EQ(std::abs(block_info.duration), | 231 EXPECT_EQ(std::abs(block_info.duration), |
| 215 buffer->duration().InMilliseconds()); | 232 buffer->duration().InMillisecondsF()); |
| 216 EXPECT_EQ(DemuxerStream::TEXT, buffer->type()); | 233 EXPECT_EQ(DemuxerStream::TEXT, buffer->type()); |
| 217 EXPECT_EQ(text_track_num, buffer->track_id()); | 234 EXPECT_EQ(text_track_num, buffer->track_id()); |
| 218 } | 235 } |
| 219 | 236 |
| 220 EXPECT_TRUE(buffer_iter == buffer_end); | 237 EXPECT_TRUE(buffer_iter == buffer_end); |
| 221 return true; | 238 return true; |
| 222 } | 239 } |
| 223 | 240 |
| 224 static void VerifyEncryptedBuffer( | 241 static void VerifyEncryptedBuffer( |
| 225 scoped_refptr<StreamParserBuffer> buffer) { | 242 scoped_refptr<StreamParserBuffer> buffer) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 241 WebMClusterParserTest() | 258 WebMClusterParserTest() |
| 242 : parser_(new WebMClusterParser(kTimecodeScale, | 259 : parser_(new WebMClusterParser(kTimecodeScale, |
| 243 kAudioTrackNum, | 260 kAudioTrackNum, |
| 244 kNoTimestamp(), | 261 kNoTimestamp(), |
| 245 kVideoTrackNum, | 262 kVideoTrackNum, |
| 246 kNoTimestamp(), | 263 kNoTimestamp(), |
| 247 TextTracks(), | 264 TextTracks(), |
| 248 std::set<int64>(), | 265 std::set<int64>(), |
| 249 std::string(), | 266 std::string(), |
| 250 std::string(), | 267 std::string(), |
| 268 kUnknownAudioCodec, | |
| 251 LogCB())) {} | 269 LogCB())) {} |
| 252 | 270 |
| 253 protected: | 271 protected: |
| 254 void ResetParserToHaveDefaultDurations() { | 272 void ResetParserToHaveDefaultDurations() { |
| 255 base::TimeDelta default_audio_duration = base::TimeDelta::FromMilliseconds( | 273 base::TimeDelta default_audio_duration = base::TimeDelta::FromMilliseconds( |
| 256 kTestAudioFrameDefaultDurationInMs); | 274 kTestAudioFrameDefaultDurationInMs); |
| 257 base::TimeDelta default_video_duration = base::TimeDelta::FromMilliseconds( | 275 base::TimeDelta default_video_duration = base::TimeDelta::FromMilliseconds( |
| 258 kTestVideoFrameDefaultDurationInMs); | 276 kTestVideoFrameDefaultDurationInMs); |
| 259 ASSERT_GE(default_audio_duration, base::TimeDelta()); | 277 ASSERT_GE(default_audio_duration, base::TimeDelta()); |
| 260 ASSERT_GE(default_video_duration, base::TimeDelta()); | 278 ASSERT_GE(default_video_duration, base::TimeDelta()); |
| 261 ASSERT_NE(kNoTimestamp(), default_audio_duration); | 279 ASSERT_NE(kNoTimestamp(), default_audio_duration); |
| 262 ASSERT_NE(kNoTimestamp(), default_video_duration); | 280 ASSERT_NE(kNoTimestamp(), default_video_duration); |
| 263 | 281 |
| 264 parser_.reset(new WebMClusterParser(kTimecodeScale, | 282 parser_.reset(new WebMClusterParser(kTimecodeScale, |
| 265 kAudioTrackNum, | 283 kAudioTrackNum, |
| 266 default_audio_duration, | 284 default_audio_duration, |
| 267 kVideoTrackNum, | 285 kVideoTrackNum, |
| 268 default_video_duration, | 286 default_video_duration, |
| 269 TextTracks(), | 287 TextTracks(), |
| 270 std::set<int64>(), | 288 std::set<int64>(), |
| 271 std::string(), | 289 std::string(), |
| 272 std::string(), | 290 std::string(), |
| 291 kUnknownAudioCodec, | |
| 273 LogCB())); | 292 LogCB())); |
| 274 } | 293 } |
| 275 | 294 |
| 276 scoped_ptr<WebMClusterParser> parser_; | 295 scoped_ptr<WebMClusterParser> parser_; |
| 277 | 296 |
| 278 private: | 297 private: |
| 279 DISALLOW_COPY_AND_ASSIGN(WebMClusterParserTest); | 298 DISALLOW_COPY_AND_ASSIGN(WebMClusterParserTest); |
| 280 }; | 299 }; |
| 281 | 300 |
| 282 TEST_F(WebMClusterParserTest, HeldBackBufferHoldsBackAllTracks) { | 301 TEST_F(WebMClusterParserTest, HeldBackBufferHoldsBackAllTracks) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 298 ASSERT_NE(kNoTimestamp(), default_audio_duration); | 317 ASSERT_NE(kNoTimestamp(), default_audio_duration); |
| 299 parser_.reset(new WebMClusterParser(kTimecodeScale, | 318 parser_.reset(new WebMClusterParser(kTimecodeScale, |
| 300 kAudioTrackNum, | 319 kAudioTrackNum, |
| 301 default_audio_duration, | 320 default_audio_duration, |
| 302 kVideoTrackNum, | 321 kVideoTrackNum, |
| 303 kNoTimestamp(), | 322 kNoTimestamp(), |
| 304 text_tracks, | 323 text_tracks, |
| 305 std::set<int64>(), | 324 std::set<int64>(), |
| 306 std::string(), | 325 std::string(), |
| 307 std::string(), | 326 std::string(), |
| 327 kUnknownAudioCodec, | |
| 308 LogCB())); | 328 LogCB())); |
| 309 | 329 |
| 310 const BlockInfo kBlockInfo[] = { | 330 const BlockInfo kBlockInfo[] = { |
| 311 { kVideoTrackNum, 0, 33, true }, | 331 {kVideoTrackNum, 0, 33, true, NULL, 0}, |
| 312 { kAudioTrackNum, 0, 23, false }, | 332 {kAudioTrackNum, 0, 23, false, NULL, 0}, |
| 313 { kTextTrackNum, 10, 42, false }, | 333 {kTextTrackNum, 10, 42, false, NULL, 0}, |
| 314 { kAudioTrackNum, 23, kTestAudioFrameDefaultDurationInMs, true }, | 334 {kAudioTrackNum, 23, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
| 315 { kVideoTrackNum, 33, 33, true }, | 335 {kVideoTrackNum, 33, 33, true, NULL, 0}, |
| 316 { kAudioTrackNum, 36, kTestAudioFrameDefaultDurationInMs, true }, | 336 {kAudioTrackNum, 36, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
| 317 { kVideoTrackNum, 66, 33, true }, | 337 {kVideoTrackNum, 66, 33, true, NULL, 0}, |
| 318 { kAudioTrackNum, 70, kTestAudioFrameDefaultDurationInMs, true }, | 338 {kAudioTrackNum, 70, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
| 319 { kAudioTrackNum, 83, kTestAudioFrameDefaultDurationInMs, true }, | 339 {kAudioTrackNum, 83, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
| 320 }; | 340 }; |
| 321 | 341 |
| 322 const int kExpectedBuffersOnPartialCluster[] = { | 342 const int kExpectedBuffersOnPartialCluster[] = { |
| 323 0, // Video simple block without DefaultDuration should be held back | 343 0, // Video simple block without DefaultDuration should be held back |
| 324 0, // Audio buffer ready, but not emitted because its TS >= held back video | 344 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 | 345 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 | 346 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 | 347 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 | 348 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 | 349 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)); | 457 block_count)); |
| 438 } | 458 } |
| 439 | 459 |
| 440 // Verify that both BlockGroups with the BlockDuration before the Block | 460 // Verify that both BlockGroups with the BlockDuration before the Block |
| 441 // and BlockGroups with the BlockDuration after the Block are supported | 461 // and BlockGroups with the BlockDuration after the Block are supported |
| 442 // correctly. | 462 // correctly. |
| 443 // Note: Raw bytes are use here because ClusterBuilder only generates | 463 // Note: Raw bytes are use here because ClusterBuilder only generates |
| 444 // one of these scenarios. | 464 // one of these scenarios. |
| 445 TEST_F(WebMClusterParserTest, ParseBlockGroup) { | 465 TEST_F(WebMClusterParserTest, ParseBlockGroup) { |
| 446 const BlockInfo kBlockInfo[] = { | 466 const BlockInfo kBlockInfo[] = { |
| 447 { kAudioTrackNum, 0, 23, false }, | 467 {kAudioTrackNum, 0, 23, false, NULL, 0}, |
| 448 { kVideoTrackNum, 33, 34, false }, | 468 {kVideoTrackNum, 33, 34, false, NULL, 0}, |
| 449 }; | 469 }; |
| 450 int block_count = arraysize(kBlockInfo); | 470 int block_count = arraysize(kBlockInfo); |
| 451 | 471 |
| 452 const uint8 kClusterData[] = { | 472 const uint8 kClusterData[] = { |
| 453 0x1F, 0x43, 0xB6, 0x75, 0x9B, // Cluster(size=27) | 473 0x1F, 0x43, 0xB6, 0x75, 0x9B, // Cluster(size=27) |
| 454 0xE7, 0x81, 0x00, // Timecode(size=1, value=0) | 474 0xE7, 0x81, 0x00, // Timecode(size=1, value=0) |
| 455 // BlockGroup with BlockDuration before Block. | 475 // BlockGroup with BlockDuration before Block. |
| 456 0xA0, 0x8A, // BlockGroup(size=10) | 476 0xA0, 0x8A, // BlockGroup(size=10) |
| 457 0x9B, 0x81, 0x17, // BlockDuration(size=1, value=23) | 477 0x9B, 0x81, 0x17, // BlockDuration(size=1, value=23) |
| 458 0xA1, 0x85, 0x81, 0x00, 0x00, 0x00, 0xaa, // Block(size=5, track=1, ts=0) | 478 0xA1, 0x85, 0x81, 0x00, 0x00, 0x00, 0xaa, // Block(size=5, track=1, ts=0) |
| 459 // BlockGroup with BlockDuration after Block. | 479 // BlockGroup with BlockDuration after Block. |
| 460 0xA0, 0x8A, // BlockGroup(size=10) | 480 0xA0, 0x8A, // BlockGroup(size=10) |
| 461 0xA1, 0x85, 0x82, 0x00, 0x21, 0x00, 0x55, // Block(size=5, track=2, ts=33) | 481 0xA1, 0x85, 0x82, 0x00, 0x21, 0x00, 0x55, // Block(size=5, track=2, ts=33) |
| 462 0x9B, 0x81, 0x22, // BlockDuration(size=1, value=34) | 482 0x9B, 0x81, 0x22, // BlockDuration(size=1, value=34) |
| 463 }; | 483 }; |
| 464 const int kClusterSize = sizeof(kClusterData); | 484 const int kClusterSize = sizeof(kClusterData); |
| 465 | 485 |
| 466 int result = parser_->Parse(kClusterData, kClusterSize); | 486 int result = parser_->Parse(kClusterData, kClusterSize); |
| 467 EXPECT_EQ(kClusterSize, result); | 487 EXPECT_EQ(kClusterSize, result); |
| 468 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | 488 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); |
| 469 } | 489 } |
| 470 | 490 |
| 471 TEST_F(WebMClusterParserTest, ParseSimpleBlockAndBlockGroupMixture) { | 491 TEST_F(WebMClusterParserTest, ParseSimpleBlockAndBlockGroupMixture) { |
| 472 const BlockInfo kBlockInfo[] = { | 492 const BlockInfo kBlockInfo[] = { |
| 473 { kAudioTrackNum, 0, 23, true }, | 493 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
| 474 { kAudioTrackNum, 23, 23, false }, | 494 {kAudioTrackNum, 23, 23, false, NULL, 0}, |
| 475 { kVideoTrackNum, 33, 34, true }, | 495 {kVideoTrackNum, 33, 34, true, NULL, 0}, |
| 476 { kAudioTrackNum, 46, 23, false }, | 496 {kAudioTrackNum, 46, 23, false, NULL, 0}, |
| 477 { kVideoTrackNum, 67, 33, false }, | 497 {kVideoTrackNum, 67, 33, false, NULL, 0}, |
| 478 }; | 498 }; |
| 479 int block_count = arraysize(kBlockInfo); | 499 int block_count = arraysize(kBlockInfo); |
| 480 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 500 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
| 481 | 501 |
| 482 int result = parser_->Parse(cluster->data(), cluster->size()); | 502 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 483 EXPECT_EQ(cluster->size(), result); | 503 EXPECT_EQ(cluster->size(), result); |
| 484 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | 504 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); |
| 485 } | 505 } |
| 486 | 506 |
| 487 TEST_F(WebMClusterParserTest, IgnoredTracks) { | 507 TEST_F(WebMClusterParserTest, IgnoredTracks) { |
| 488 std::set<int64> ignored_tracks; | 508 std::set<int64> ignored_tracks; |
| 489 ignored_tracks.insert(kTextTrackNum); | 509 ignored_tracks.insert(kTextTrackNum); |
| 490 | 510 |
| 491 parser_.reset(new WebMClusterParser(kTimecodeScale, | 511 parser_.reset(new WebMClusterParser(kTimecodeScale, |
| 492 kAudioTrackNum, | 512 kAudioTrackNum, |
| 493 kNoTimestamp(), | 513 kNoTimestamp(), |
| 494 kVideoTrackNum, | 514 kVideoTrackNum, |
| 495 kNoTimestamp(), | 515 kNoTimestamp(), |
| 496 TextTracks(), | 516 TextTracks(), |
| 497 ignored_tracks, | 517 ignored_tracks, |
| 498 std::string(), | 518 std::string(), |
| 499 std::string(), | 519 std::string(), |
| 520 kUnknownAudioCodec, | |
| 500 LogCB())); | 521 LogCB())); |
| 501 | 522 |
| 502 const BlockInfo kInputBlockInfo[] = { | 523 const BlockInfo kInputBlockInfo[] = { |
| 503 { kAudioTrackNum, 0, 23, true }, | 524 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
| 504 { kAudioTrackNum, 23, 23, true }, | 525 {kAudioTrackNum, 23, 23, true, NULL, 0}, |
| 505 { kVideoTrackNum, 33, 34, true }, | 526 {kVideoTrackNum, 33, 34, true, NULL, 0}, |
| 506 { kTextTrackNum, 33, 99, true }, | 527 {kTextTrackNum, 33, 99, true, NULL, 0}, |
| 507 { kAudioTrackNum, 46, 23, true }, | 528 {kAudioTrackNum, 46, 23, true, NULL, 0}, |
| 508 { kVideoTrackNum, 67, 34, true }, | 529 {kVideoTrackNum, 67, 34, true, NULL, 0}, |
| 509 }; | 530 }; |
| 510 int input_block_count = arraysize(kInputBlockInfo); | 531 int input_block_count = arraysize(kInputBlockInfo); |
| 511 | 532 |
| 512 const BlockInfo kOutputBlockInfo[] = { | 533 const BlockInfo kOutputBlockInfo[] = { |
| 513 { kAudioTrackNum, 0, 23, true }, | 534 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
| 514 { kAudioTrackNum, 23, 23, true }, | 535 {kAudioTrackNum, 23, 23, true, NULL, 0}, |
| 515 { kVideoTrackNum, 33, 34, true }, | 536 {kVideoTrackNum, 33, 34, true, NULL, 0}, |
| 516 { kAudioTrackNum, 46, 23, true }, | 537 {kAudioTrackNum, 46, 23, true, NULL, 0}, |
| 517 { kVideoTrackNum, 67, 34, true }, | 538 {kVideoTrackNum, 67, 34, true, NULL, 0}, |
| 518 }; | 539 }; |
| 519 int output_block_count = arraysize(kOutputBlockInfo); | 540 int output_block_count = arraysize(kOutputBlockInfo); |
| 520 | 541 |
| 521 scoped_ptr<Cluster> cluster( | 542 scoped_ptr<Cluster> cluster( |
| 522 CreateCluster(0, kInputBlockInfo, input_block_count)); | 543 CreateCluster(0, kInputBlockInfo, input_block_count)); |
| 523 | 544 |
| 524 int result = parser_->Parse(cluster->data(), cluster->size()); | 545 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 525 EXPECT_EQ(cluster->size(), result); | 546 EXPECT_EQ(cluster->size(), result); |
| 526 ASSERT_TRUE(VerifyBuffers(parser_, kOutputBlockInfo, output_block_count)); | 547 ASSERT_TRUE(VerifyBuffers(parser_, kOutputBlockInfo, output_block_count)); |
| 527 } | 548 } |
| 528 | 549 |
| 529 TEST_F(WebMClusterParserTest, ParseTextTracks) { | 550 TEST_F(WebMClusterParserTest, ParseTextTracks) { |
| 530 TextTracks text_tracks; | 551 TextTracks text_tracks; |
| 531 | 552 |
| 532 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), | 553 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), |
| 533 TextTrackConfig(kTextSubtitles, "", "", | 554 TextTrackConfig(kTextSubtitles, "", "", |
| 534 ""))); | 555 ""))); |
| 535 | 556 |
| 536 parser_.reset(new WebMClusterParser(kTimecodeScale, | 557 parser_.reset(new WebMClusterParser(kTimecodeScale, |
| 537 kAudioTrackNum, | 558 kAudioTrackNum, |
| 538 kNoTimestamp(), | 559 kNoTimestamp(), |
| 539 kVideoTrackNum, | 560 kVideoTrackNum, |
| 540 kNoTimestamp(), | 561 kNoTimestamp(), |
| 541 text_tracks, | 562 text_tracks, |
| 542 std::set<int64>(), | 563 std::set<int64>(), |
| 543 std::string(), | 564 std::string(), |
| 544 std::string(), | 565 std::string(), |
| 566 kUnknownAudioCodec, | |
| 545 LogCB())); | 567 LogCB())); |
| 546 | 568 |
| 547 const BlockInfo kInputBlockInfo[] = { | 569 const BlockInfo kInputBlockInfo[] = { |
| 548 { kAudioTrackNum, 0, 23, true }, | 570 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
| 549 { kAudioTrackNum, 23, 23, true }, | 571 {kAudioTrackNum, 23, 23, true, NULL, 0}, |
| 550 { kVideoTrackNum, 33, 34, true }, | 572 {kVideoTrackNum, 33, 34, true, NULL, 0}, |
| 551 { kTextTrackNum, 33, 42, false }, | 573 {kTextTrackNum, 33, 42, false, NULL, 0}, |
| 552 { kAudioTrackNum, 46, 23, true }, | 574 {kAudioTrackNum, 46, 23, true, NULL, 0}, |
| 553 { kTextTrackNum, 55, 44, false }, | 575 {kTextTrackNum, 55, 44, false, NULL, 0}, |
| 554 { kVideoTrackNum, 67, 34, true }, | 576 {kVideoTrackNum, 67, 34, true, NULL, 0}, |
| 555 }; | 577 }; |
| 556 int input_block_count = arraysize(kInputBlockInfo); | 578 int input_block_count = arraysize(kInputBlockInfo); |
| 557 | 579 |
| 558 scoped_ptr<Cluster> cluster( | 580 scoped_ptr<Cluster> cluster( |
| 559 CreateCluster(0, kInputBlockInfo, input_block_count)); | 581 CreateCluster(0, kInputBlockInfo, input_block_count)); |
| 560 | 582 |
| 561 int result = parser_->Parse(cluster->data(), cluster->size()); | 583 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 562 EXPECT_EQ(cluster->size(), result); | 584 EXPECT_EQ(cluster->size(), result); |
| 563 ASSERT_TRUE(VerifyBuffers(parser_, kInputBlockInfo, input_block_count)); | 585 ASSERT_TRUE(VerifyBuffers(parser_, kInputBlockInfo, input_block_count)); |
| 564 } | 586 } |
| 565 | 587 |
| 566 TEST_F(WebMClusterParserTest, TextTracksSimpleBlock) { | 588 TEST_F(WebMClusterParserTest, TextTracksSimpleBlock) { |
| 567 TextTracks text_tracks; | 589 TextTracks text_tracks; |
| 568 | 590 |
| 569 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), | 591 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), |
| 570 TextTrackConfig(kTextSubtitles, "", "", | 592 TextTrackConfig(kTextSubtitles, "", "", |
| 571 ""))); | 593 ""))); |
| 572 | 594 |
| 573 parser_.reset(new WebMClusterParser(kTimecodeScale, | 595 parser_.reset(new WebMClusterParser(kTimecodeScale, |
| 574 kAudioTrackNum, | 596 kAudioTrackNum, |
| 575 kNoTimestamp(), | 597 kNoTimestamp(), |
| 576 kVideoTrackNum, | 598 kVideoTrackNum, |
| 577 kNoTimestamp(), | 599 kNoTimestamp(), |
| 578 text_tracks, | 600 text_tracks, |
| 579 std::set<int64>(), | 601 std::set<int64>(), |
| 580 std::string(), | 602 std::string(), |
| 581 std::string(), | 603 std::string(), |
| 604 kUnknownAudioCodec, | |
| 582 LogCB())); | 605 LogCB())); |
| 583 | 606 |
| 584 const BlockInfo kInputBlockInfo[] = { | 607 const BlockInfo kInputBlockInfo[] = { |
| 585 { kTextTrackNum, 33, 42, true }, | 608 { kTextTrackNum, 33, 42, true }, |
| 586 }; | 609 }; |
| 587 int input_block_count = arraysize(kInputBlockInfo); | 610 int input_block_count = arraysize(kInputBlockInfo); |
| 588 | 611 |
| 589 scoped_ptr<Cluster> cluster( | 612 scoped_ptr<Cluster> cluster( |
| 590 CreateCluster(0, kInputBlockInfo, input_block_count)); | 613 CreateCluster(0, kInputBlockInfo, input_block_count)); |
| 591 | 614 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 609 | 632 |
| 610 parser_.reset(new WebMClusterParser(kTimecodeScale, | 633 parser_.reset(new WebMClusterParser(kTimecodeScale, |
| 611 kAudioTrackNum, | 634 kAudioTrackNum, |
| 612 kNoTimestamp(), | 635 kNoTimestamp(), |
| 613 kVideoTrackNum, | 636 kVideoTrackNum, |
| 614 kNoTimestamp(), | 637 kNoTimestamp(), |
| 615 text_tracks, | 638 text_tracks, |
| 616 std::set<int64>(), | 639 std::set<int64>(), |
| 617 std::string(), | 640 std::string(), |
| 618 std::string(), | 641 std::string(), |
| 642 kUnknownAudioCodec, | |
| 619 LogCB())); | 643 LogCB())); |
| 620 | 644 |
| 621 const BlockInfo kInputBlockInfo[] = { | 645 const BlockInfo kInputBlockInfo[] = { |
| 622 { kAudioTrackNum, 0, 23, true }, | 646 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
| 623 { kAudioTrackNum, 23, 23, true }, | 647 {kAudioTrackNum, 23, 23, true, NULL, 0}, |
| 624 { kVideoTrackNum, 33, 34, true }, | 648 {kVideoTrackNum, 33, 34, true, NULL, 0}, |
| 625 { kSubtitleTextTrackNum, 33, 42, false }, | 649 {kSubtitleTextTrackNum, 33, 42, false, NULL, 0}, |
| 626 { kAudioTrackNum, 46, 23, true }, | 650 {kAudioTrackNum, 46, 23, true, NULL, 0}, |
| 627 { kCaptionTextTrackNum, 55, 44, false }, | 651 {kCaptionTextTrackNum, 55, 44, false, NULL, 0}, |
| 628 { kVideoTrackNum, 67, 34, true }, | 652 {kVideoTrackNum, 67, 34, true, NULL, 0}, |
| 629 { kSubtitleTextTrackNum, 67, 33, false }, | 653 {kSubtitleTextTrackNum, 67, 33, false, NULL, 0}, |
| 630 }; | 654 }; |
| 631 int input_block_count = arraysize(kInputBlockInfo); | 655 int input_block_count = arraysize(kInputBlockInfo); |
| 632 | 656 |
| 633 scoped_ptr<Cluster> cluster( | 657 scoped_ptr<Cluster> cluster( |
| 634 CreateCluster(0, kInputBlockInfo, input_block_count)); | 658 CreateCluster(0, kInputBlockInfo, input_block_count)); |
| 635 | 659 |
| 636 int result = parser_->Parse(cluster->data(), cluster->size()); | 660 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 637 EXPECT_EQ(cluster->size(), result); | 661 EXPECT_EQ(cluster->size(), result); |
| 638 | 662 |
| 639 const WebMClusterParser::TextBufferQueueMap& text_map = | 663 const WebMClusterParser::TextBufferQueueMap& text_map = |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 655 | 679 |
| 656 parser_.reset(new WebMClusterParser(kTimecodeScale, | 680 parser_.reset(new WebMClusterParser(kTimecodeScale, |
| 657 kAudioTrackNum, | 681 kAudioTrackNum, |
| 658 kNoTimestamp(), | 682 kNoTimestamp(), |
| 659 kVideoTrackNum, | 683 kVideoTrackNum, |
| 660 kNoTimestamp(), | 684 kNoTimestamp(), |
| 661 TextTracks(), | 685 TextTracks(), |
| 662 std::set<int64>(), | 686 std::set<int64>(), |
| 663 std::string(), | 687 std::string(), |
| 664 "video_key_id", | 688 "video_key_id", |
| 689 kUnknownAudioCodec, | |
| 665 LogCB())); | 690 LogCB())); |
| 666 int result = parser_->Parse(cluster->data(), cluster->size()); | 691 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 667 EXPECT_EQ(cluster->size(), result); | 692 EXPECT_EQ(cluster->size(), result); |
| 668 ASSERT_EQ(1UL, parser_->GetVideoBuffers().size()); | 693 ASSERT_EQ(1UL, parser_->GetVideoBuffers().size()); |
| 669 scoped_refptr<StreamParserBuffer> buffer = parser_->GetVideoBuffers()[0]; | 694 scoped_refptr<StreamParserBuffer> buffer = parser_->GetVideoBuffers()[0]; |
| 670 VerifyEncryptedBuffer(buffer); | 695 VerifyEncryptedBuffer(buffer); |
| 671 } | 696 } |
| 672 | 697 |
| 673 TEST_F(WebMClusterParserTest, ParseBadEncryptedBlock) { | 698 TEST_F(WebMClusterParserTest, ParseBadEncryptedBlock) { |
| 674 scoped_ptr<Cluster> cluster( | 699 scoped_ptr<Cluster> cluster( |
| 675 CreateEncryptedCluster(sizeof(kEncryptedFrame) - 1)); | 700 CreateEncryptedCluster(sizeof(kEncryptedFrame) - 1)); |
| 676 | 701 |
| 677 parser_.reset(new WebMClusterParser(kTimecodeScale, | 702 parser_.reset(new WebMClusterParser(kTimecodeScale, |
| 678 kAudioTrackNum, | 703 kAudioTrackNum, |
| 679 kNoTimestamp(), | 704 kNoTimestamp(), |
| 680 kVideoTrackNum, | 705 kVideoTrackNum, |
| 681 kNoTimestamp(), | 706 kNoTimestamp(), |
| 682 TextTracks(), | 707 TextTracks(), |
| 683 std::set<int64>(), | 708 std::set<int64>(), |
| 684 std::string(), | 709 std::string(), |
| 685 "video_key_id", | 710 "video_key_id", |
| 711 kUnknownAudioCodec, | |
| 686 LogCB())); | 712 LogCB())); |
| 687 int result = parser_->Parse(cluster->data(), cluster->size()); | 713 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 688 EXPECT_EQ(-1, result); | 714 EXPECT_EQ(-1, result); |
| 689 } | 715 } |
| 690 | 716 |
| 691 TEST_F(WebMClusterParserTest, ParseInvalidZeroSizedCluster) { | 717 TEST_F(WebMClusterParserTest, ParseInvalidZeroSizedCluster) { |
| 692 const uint8 kBuffer[] = { | 718 const uint8 kBuffer[] = { |
| 693 0x1F, 0x43, 0xB6, 0x75, 0x80, // CLUSTER (size = 0) | 719 0x1F, 0x43, 0xB6, 0x75, 0x80, // CLUSTER (size = 0) |
| 694 }; | 720 }; |
| 695 | 721 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 715 | 741 |
| 716 parser_.reset(new WebMClusterParser(kTimecodeScale, | 742 parser_.reset(new WebMClusterParser(kTimecodeScale, |
| 717 kAudioTrackNum, | 743 kAudioTrackNum, |
| 718 kNoTimestamp(), | 744 kNoTimestamp(), |
| 719 kVideoTrackNum, | 745 kVideoTrackNum, |
| 720 kNoTimestamp(), | 746 kNoTimestamp(), |
| 721 text_tracks, | 747 text_tracks, |
| 722 std::set<int64>(), | 748 std::set<int64>(), |
| 723 std::string(), | 749 std::string(), |
| 724 std::string(), | 750 std::string(), |
| 751 kUnknownAudioCodec, | |
| 725 LogCB())); | 752 LogCB())); |
| 726 | 753 |
| 727 const BlockInfo kBlockInfo[] = { | 754 const BlockInfo kBlockInfo[] = { |
| 728 { kTextTrackNum, 33, -42, false }, | 755 { kTextTrackNum, 33, -42, false }, |
| 729 }; | 756 }; |
| 730 int block_count = arraysize(kBlockInfo); | 757 int block_count = arraysize(kBlockInfo); |
| 731 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 758 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
| 732 int result = parser_->Parse(cluster->data(), cluster->size()); | 759 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 733 EXPECT_LT(result, 0); | 760 EXPECT_LT(result, 0); |
| 734 } | 761 } |
| 735 | 762 |
| 736 TEST_F(WebMClusterParserTest, ParseWithDefaultDurationsSimpleBlocks) { | 763 TEST_F(WebMClusterParserTest, ParseWithDefaultDurationsSimpleBlocks) { |
| 737 InSequence s; | 764 InSequence s; |
| 738 ResetParserToHaveDefaultDurations(); | 765 ResetParserToHaveDefaultDurations(); |
| 739 | 766 |
| 740 EXPECT_LT(kTestAudioFrameDefaultDurationInMs, 23); | 767 EXPECT_LT(kTestAudioFrameDefaultDurationInMs, 23); |
| 741 EXPECT_LT(kTestVideoFrameDefaultDurationInMs, 33); | 768 EXPECT_LT(kTestVideoFrameDefaultDurationInMs, 33); |
| 742 | 769 |
| 743 const BlockInfo kBlockInfo[] = { | 770 const BlockInfo kBlockInfo[] = { |
| 744 { kAudioTrackNum, 0, kTestAudioFrameDefaultDurationInMs, true }, | 771 {kAudioTrackNum, 0, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
| 745 { kAudioTrackNum, 23, kTestAudioFrameDefaultDurationInMs, true }, | 772 {kAudioTrackNum, 23, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
| 746 { kVideoTrackNum, 33, kTestVideoFrameDefaultDurationInMs, true }, | 773 {kVideoTrackNum, 33, kTestVideoFrameDefaultDurationInMs, true, NULL, 0}, |
| 747 { kAudioTrackNum, 46, kTestAudioFrameDefaultDurationInMs, true }, | 774 {kAudioTrackNum, 46, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
| 748 { kVideoTrackNum, 67, kTestVideoFrameDefaultDurationInMs, true }, | 775 {kVideoTrackNum, 67, kTestVideoFrameDefaultDurationInMs, true, NULL, 0}, |
| 749 { kAudioTrackNum, 69, kTestAudioFrameDefaultDurationInMs, true }, | 776 {kAudioTrackNum, 69, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
| 750 { kVideoTrackNum, 100, kTestVideoFrameDefaultDurationInMs, true }, | 777 {kVideoTrackNum, 100, kTestVideoFrameDefaultDurationInMs, true, NULL, 0}, |
| 751 }; | 778 }; |
| 752 | 779 |
| 753 int block_count = arraysize(kBlockInfo); | 780 int block_count = arraysize(kBlockInfo); |
| 754 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 781 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
| 755 | 782 |
| 756 // Send slightly less than the full cluster so all but the last block is | 783 // 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 | 784 // 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 | 785 // for duration estimation prior to end of cluster detection because all the |
| 759 // tracks have DefaultDurations. | 786 // tracks have DefaultDurations. |
| 760 int result = parser_->Parse(cluster->data(), cluster->size() - 1); | 787 int result = parser_->Parse(cluster->data(), cluster->size() - 1); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 771 } | 798 } |
| 772 | 799 |
| 773 TEST_F(WebMClusterParserTest, ParseWithoutAnyDurationsSimpleBlocks) { | 800 TEST_F(WebMClusterParserTest, ParseWithoutAnyDurationsSimpleBlocks) { |
| 774 InSequence s; | 801 InSequence s; |
| 775 | 802 |
| 776 // Absent DefaultDuration information, SimpleBlock durations are derived from | 803 // Absent DefaultDuration information, SimpleBlock durations are derived from |
| 777 // inter-buffer track timestamp delta if within the cluster, and are estimated | 804 // 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 | 805 // 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). | 806 // in the cluster (independently for each track in the cluster). |
| 780 const BlockInfo kBlockInfo1[] = { | 807 const BlockInfo kBlockInfo1[] = { |
| 781 { kAudioTrackNum, 0, 23, true }, | 808 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
| 782 { kAudioTrackNum, 23, 22, true }, | 809 {kAudioTrackNum, 23, 22, true, NULL, 0}, |
| 783 { kVideoTrackNum, 33, 33, true }, | 810 {kVideoTrackNum, 33, 33, true, NULL, 0}, |
| 784 { kAudioTrackNum, 45, 23, true }, | 811 {kAudioTrackNum, 45, 23, true, NULL, 0}, |
| 785 { kVideoTrackNum, 66, 34, true }, | 812 {kVideoTrackNum, 66, 34, true, NULL, 0}, |
| 786 { kAudioTrackNum, 68, 22, true }, // Estimated from minimum audio dur | 813 // Estimated from minimum audio dur |
| 787 { kVideoTrackNum, 100, 33, true }, // Estimated from minimum video dur | 814 {kAudioTrackNum, 68, 22, true, NULL, 0}, |
| 815 // Estimated from minimum video dur | |
| 816 {kVideoTrackNum, 100, 33, true, NULL, 0}, | |
| 788 }; | 817 }; |
| 789 | 818 |
| 790 int block_count1 = arraysize(kBlockInfo1); | 819 int block_count1 = arraysize(kBlockInfo1); |
| 791 scoped_ptr<Cluster> cluster1(CreateCluster(0, kBlockInfo1, block_count1)); | 820 scoped_ptr<Cluster> cluster1(CreateCluster(0, kBlockInfo1, block_count1)); |
| 792 | 821 |
| 793 // Send slightly less than the first full cluster so all but the last video | 822 // 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 | 823 // 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 | 824 // both missing from the result (parser should hold them aside for duration |
| 796 // estimation prior to end of cluster detection in the absence of | 825 // estimation prior to end of cluster detection in the absence of |
| 797 // DefaultDurations.) | 826 // DefaultDurations.) |
| 798 int result = parser_->Parse(cluster1->data(), cluster1->size() - 1); | 827 int result = parser_->Parse(cluster1->data(), cluster1->size() - 1); |
| 799 EXPECT_GT(result, 0); | 828 EXPECT_GT(result, 0); |
| 800 EXPECT_LT(result, cluster1->size()); | 829 EXPECT_LT(result, cluster1->size()); |
| 801 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1 - 3)); | 830 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1 - 3)); |
| 802 EXPECT_EQ(3UL, parser_->GetAudioBuffers().size()); | 831 EXPECT_EQ(3UL, parser_->GetAudioBuffers().size()); |
| 803 EXPECT_EQ(1UL, parser_->GetVideoBuffers().size()); | 832 EXPECT_EQ(1UL, parser_->GetVideoBuffers().size()); |
| 804 | 833 |
| 805 parser_->Reset(); | 834 parser_->Reset(); |
| 806 | 835 |
| 807 // Now parse the full first cluster and verify all the blocks are parsed. | 836 // Now parse the full first cluster and verify all the blocks are parsed. |
| 808 result = parser_->Parse(cluster1->data(), cluster1->size()); | 837 result = parser_->Parse(cluster1->data(), cluster1->size()); |
| 809 EXPECT_EQ(cluster1->size(), result); | 838 EXPECT_EQ(cluster1->size(), result); |
| 810 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1)); | 839 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1)); |
| 811 | 840 |
| 812 // Verify that the estimated frame duration is tracked across clusters for | 841 // Verify that the estimated frame duration is tracked across clusters for |
| 813 // each track. | 842 // each track. |
| 814 const BlockInfo kBlockInfo2[] = { | 843 const BlockInfo kBlockInfo2[] = { |
| 815 { kAudioTrackNum, 200, 22, true }, // Estimate carries over across clusters | 844 // Estimate carries over across clusters |
| 816 { kVideoTrackNum, 201, 33, true }, // Estimate carries over across clusters | 845 {kAudioTrackNum, 200, 22, true, NULL, 0}, |
| 846 // Estimate carries over across clusters | |
| 847 {kVideoTrackNum, 201, 33, true, NULL, 0}, | |
| 817 }; | 848 }; |
| 818 | 849 |
| 819 int block_count2 = arraysize(kBlockInfo2); | 850 int block_count2 = arraysize(kBlockInfo2); |
| 820 scoped_ptr<Cluster> cluster2(CreateCluster(0, kBlockInfo2, block_count2)); | 851 scoped_ptr<Cluster> cluster2(CreateCluster(0, kBlockInfo2, block_count2)); |
| 821 result = parser_->Parse(cluster2->data(), cluster2->size()); | 852 result = parser_->Parse(cluster2->data(), cluster2->size()); |
| 822 EXPECT_EQ(cluster2->size(), result); | 853 EXPECT_EQ(cluster2->size(), result); |
| 823 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo2, block_count2)); | 854 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo2, block_count2)); |
| 824 } | 855 } |
| 825 | 856 |
| 826 TEST_F(WebMClusterParserTest, ParseWithoutAnyDurationsBlockGroups) { | 857 TEST_F(WebMClusterParserTest, ParseWithoutAnyDurationsBlockGroups) { |
| 827 InSequence s; | 858 InSequence s; |
| 828 | 859 |
| 829 // Absent DefaultDuration and BlockDuration information, BlockGroup block | 860 // Absent DefaultDuration and BlockDuration information, BlockGroup block |
| 830 // durations are derived from inter-buffer track timestamp delta if within the | 861 // 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 | 862 // 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 | 863 // the last buffer in the track in the cluster (independently for each track |
| 833 // in the cluster). | 864 // in the cluster). |
| 834 const BlockInfo kBlockInfo1[] = { | 865 const BlockInfo kBlockInfo1[] = { |
| 835 { kAudioTrackNum, 0, -23, false }, | 866 {kAudioTrackNum, 0, -23, false, NULL, 0}, |
| 836 { kAudioTrackNum, 23, -22, false }, | 867 {kAudioTrackNum, 23, -22, false, NULL, 0}, |
| 837 { kVideoTrackNum, 33, -33, false }, | 868 {kVideoTrackNum, 33, -33, false, NULL, 0}, |
| 838 { kAudioTrackNum, 45, -23, false }, | 869 {kAudioTrackNum, 45, -23, false, NULL, 0}, |
| 839 { kVideoTrackNum, 66, -34, false }, | 870 {kVideoTrackNum, 66, -34, false, NULL, 0}, |
| 840 { kAudioTrackNum, 68, -22, false }, // Estimated from minimum audio dur | 871 // Estimated from minimum audio dur |
| 841 { kVideoTrackNum, 100, -33, false }, // Estimated from minimum video dur | 872 {kAudioTrackNum, 68, -22, false, NULL, 0}, |
| 873 // Estimated from minimum video dur | |
| 874 {kVideoTrackNum, 100, -33, false, NULL, 0}, | |
| 842 }; | 875 }; |
| 843 | 876 |
| 844 int block_count1 = arraysize(kBlockInfo1); | 877 int block_count1 = arraysize(kBlockInfo1); |
| 845 scoped_ptr<Cluster> cluster1(CreateCluster(0, kBlockInfo1, block_count1)); | 878 scoped_ptr<Cluster> cluster1(CreateCluster(0, kBlockInfo1, block_count1)); |
| 846 | 879 |
| 847 // Send slightly less than the first full cluster so all but the last video | 880 // 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 | 881 // 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 | 882 // both missing from the result (parser should hold them aside for duration |
| 850 // estimation prior to end of cluster detection in the absence of | 883 // estimation prior to end of cluster detection in the absence of |
| 851 // DefaultDurations.) | 884 // DefaultDurations.) |
| 852 int result = parser_->Parse(cluster1->data(), cluster1->size() - 1); | 885 int result = parser_->Parse(cluster1->data(), cluster1->size() - 1); |
| 853 EXPECT_GT(result, 0); | 886 EXPECT_GT(result, 0); |
| 854 EXPECT_LT(result, cluster1->size()); | 887 EXPECT_LT(result, cluster1->size()); |
| 855 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1 - 3)); | 888 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1 - 3)); |
| 856 EXPECT_EQ(3UL, parser_->GetAudioBuffers().size()); | 889 EXPECT_EQ(3UL, parser_->GetAudioBuffers().size()); |
| 857 EXPECT_EQ(1UL, parser_->GetVideoBuffers().size()); | 890 EXPECT_EQ(1UL, parser_->GetVideoBuffers().size()); |
| 858 | 891 |
| 859 parser_->Reset(); | 892 parser_->Reset(); |
| 860 | 893 |
| 861 // Now parse the full first cluster and verify all the blocks are parsed. | 894 // Now parse the full first cluster and verify all the blocks are parsed. |
| 862 result = parser_->Parse(cluster1->data(), cluster1->size()); | 895 result = parser_->Parse(cluster1->data(), cluster1->size()); |
| 863 EXPECT_EQ(cluster1->size(), result); | 896 EXPECT_EQ(cluster1->size(), result); |
| 864 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1)); | 897 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1)); |
| 865 | 898 |
| 866 // Verify that the estimated frame duration is tracked across clusters for | 899 // Verify that the estimated frame duration is tracked across clusters for |
| 867 // each track. | 900 // each track. |
| 868 const BlockInfo kBlockInfo2[] = { | 901 const BlockInfo kBlockInfo2[] = { |
| 869 { kAudioTrackNum, 200, -22, false }, | 902 {kAudioTrackNum, 200, -22, false, NULL, 0}, |
| 870 { kVideoTrackNum, 201, -33, false }, | 903 {kVideoTrackNum, 201, -33, false, NULL, 0}, |
| 871 }; | 904 }; |
| 872 | 905 |
| 873 int block_count2 = arraysize(kBlockInfo2); | 906 int block_count2 = arraysize(kBlockInfo2); |
| 874 scoped_ptr<Cluster> cluster2(CreateCluster(0, kBlockInfo2, block_count2)); | 907 scoped_ptr<Cluster> cluster2(CreateCluster(0, kBlockInfo2, block_count2)); |
| 875 result = parser_->Parse(cluster2->data(), cluster2->size()); | 908 result = parser_->Parse(cluster2->data(), cluster2->size()); |
| 876 EXPECT_EQ(cluster2->size(), result); | 909 EXPECT_EQ(cluster2->size(), result); |
| 877 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo2, block_count2)); | 910 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo2, block_count2)); |
| 878 } | 911 } |
| 879 | 912 |
| 880 // TODO(wolenetz): Is parser behavior correct? See http://crbug.com/363433. | 913 // TODO(wolenetz): Is parser behavior correct? See http://crbug.com/363433. |
| 881 TEST_F(WebMClusterParserTest, | 914 TEST_F(WebMClusterParserTest, |
| 882 ParseWithDefaultDurationsBlockGroupsWithoutDurations) { | 915 ParseWithDefaultDurationsBlockGroupsWithoutDurations) { |
| 883 InSequence s; | 916 InSequence s; |
| 884 ResetParserToHaveDefaultDurations(); | 917 ResetParserToHaveDefaultDurations(); |
| 885 | 918 |
| 886 EXPECT_LT(kTestAudioFrameDefaultDurationInMs, 23); | 919 EXPECT_LT(kTestAudioFrameDefaultDurationInMs, 23); |
| 887 EXPECT_LT(kTestVideoFrameDefaultDurationInMs, 33); | 920 EXPECT_LT(kTestVideoFrameDefaultDurationInMs, 33); |
| 888 | 921 |
| 889 const BlockInfo kBlockInfo[] = { | 922 const BlockInfo kBlockInfo[] = { |
| 890 { kAudioTrackNum, 0, -kTestAudioFrameDefaultDurationInMs, false }, | 923 {kAudioTrackNum, 0, -kTestAudioFrameDefaultDurationInMs, false, NULL, 0}, |
| 891 { kAudioTrackNum, 23, -kTestAudioFrameDefaultDurationInMs, false }, | 924 {kAudioTrackNum, 23, -kTestAudioFrameDefaultDurationInMs, false, NULL, 0}, |
| 892 { kVideoTrackNum, 33, -kTestVideoFrameDefaultDurationInMs, false }, | 925 {kVideoTrackNum, 33, -kTestVideoFrameDefaultDurationInMs, false, NULL, 0}, |
| 893 { kAudioTrackNum, 46, -kTestAudioFrameDefaultDurationInMs, false }, | 926 {kAudioTrackNum, 46, -kTestAudioFrameDefaultDurationInMs, false, NULL, 0}, |
| 894 { kVideoTrackNum, 67, -kTestVideoFrameDefaultDurationInMs, false }, | 927 {kVideoTrackNum, 67, -kTestVideoFrameDefaultDurationInMs, false, NULL, 0}, |
| 895 { kAudioTrackNum, 69, -kTestAudioFrameDefaultDurationInMs, false }, | 928 {kAudioTrackNum, 69, -kTestAudioFrameDefaultDurationInMs, false, NULL, 0}, |
| 896 { kVideoTrackNum, 100, -kTestVideoFrameDefaultDurationInMs, false }, | 929 {kVideoTrackNum, |
| 930 100, | |
| 931 -kTestVideoFrameDefaultDurationInMs, | |
| 932 false, | |
| 933 NULL, | |
| 934 0}, | |
| 897 }; | 935 }; |
| 898 | 936 |
| 899 int block_count = arraysize(kBlockInfo); | 937 int block_count = arraysize(kBlockInfo); |
| 900 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 938 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
| 901 | 939 |
| 902 // Send slightly less than the full cluster so all but the last block is | 940 // 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 | 941 // parsed. None should be held aside for duration estimation prior to end of |
| 904 // cluster detection because all the tracks have DefaultDurations. | 942 // cluster detection because all the tracks have DefaultDurations. |
| 905 int result = parser_->Parse(cluster->data(), cluster->size() - 1); | 943 int result = parser_->Parse(cluster->data(), cluster->size() - 1); |
| 906 EXPECT_GT(result, 0); | 944 EXPECT_GT(result, 0); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 931 }, | 969 }, |
| 932 }; | 970 }; |
| 933 | 971 |
| 934 int block_count = arraysize(kBlockInfo); | 972 int block_count = arraysize(kBlockInfo); |
| 935 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 973 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
| 936 int result = parser_->Parse(cluster->data(), cluster->size()); | 974 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 937 EXPECT_EQ(cluster->size(), result); | 975 EXPECT_EQ(cluster->size(), result); |
| 938 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | 976 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); |
| 939 } | 977 } |
| 940 | 978 |
| 941 TEST_F(WebMClusterParserTest, | 979 TEST_F(WebMClusterParserTest, ReadOpusDurationsSimpleBlockAtEndOfCluster) { |
| 942 ParseDegenerateClusterWithDefaultDurationsYieldsDefaultDurations) { | 980 // Reset parser to expect Opus codec audio. |
|
wolenetz
2015/02/03 22:47:02
Hmm. Do we no longer have DefaultDuration tested?
chcunningham
2015/02/05 02:48:22
Done with tweaks. As you know, the preference of d
| |
| 943 ResetParserToHaveDefaultDurations(); | 981 parser_.reset(new WebMClusterParser( |
| 982 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, | |
| 983 kNoTimestamp(), TextTracks(), std::set<int64>(), std::string(), | |
| 984 std::string(), kCodecOpus, LogCB())); | |
| 944 | 985 |
| 945 const BlockInfo kBlockInfo[] = { | 986 for (const auto& packet_ptr : BuildAllOpusPackets()) { |
| 946 { kAudioTrackNum, 0, kTestAudioFrameDefaultDurationInMs, true }, | 987 const BlockInfo kBlockInfo[] = {{kAudioTrackNum, |
| 947 { kVideoTrackNum, 0, kTestVideoFrameDefaultDurationInMs, true }, | 988 0, |
| 948 }; | 989 packet_ptr->duration_ms, |
| 990 true, // Make it a SimpleBlock. | |
| 991 &(packet_ptr->data[0]), | |
| 992 packet_ptr->data.size()}}; | |
| 949 | 993 |
| 950 int block_count = arraysize(kBlockInfo); | 994 int block_count = arraysize(kBlockInfo); |
|
wolenetz
2015/02/03 22:47:02
isn't this 1 always?
chcunningham
2015/02/05 02:48:22
Yeah, the whole file is silly this way. Would you
wolenetz
2015/02/05 23:04:59
tott aside, let's keep consistent. Maybe a helper
| |
| 951 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 995 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
| 952 int result = parser_->Parse(cluster->data(), cluster->size()); | 996 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 953 EXPECT_EQ(cluster->size(), result); | 997 EXPECT_EQ(cluster->size(), result); |
| 954 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | 998 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); |
| 999 } | |
| 1000 } | |
| 1001 | |
| 1002 TEST_F(WebMClusterParserTest, PreferOpusDurationsOverBlockDurations) { | |
| 1003 // Reset parser to expect Opus codec audio. | |
| 1004 parser_.reset(new WebMClusterParser( | |
| 1005 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, | |
| 1006 kNoTimestamp(), TextTracks(), std::set<int64>(), std::string(), | |
| 1007 std::string(), kCodecOpus, LogCB())); | |
| 1008 | |
| 1009 for (const auto& packet_ptr : BuildAllOpusPackets()) { | |
| 1010 // Setting BlockDuration != Opus duration to see which one the parser uses. | |
| 1011 int block_duration_ms = packet_ptr->duration_ms + 10; | |
| 1012 | |
| 1013 BlockInfo block_infos[] = {{kAudioTrackNum, | |
| 1014 0, | |
| 1015 block_duration_ms, | |
| 1016 false, // Not a SimpleBlock. | |
| 1017 &(packet_ptr->data[0]), | |
| 1018 packet_ptr->data.size()}}; | |
| 1019 | |
| 1020 int block_count = arraysize(block_infos); | |
|
wolenetz
2015/02/03 22:47:02
isn't this 1 always?
chcunningham
2015/02/05 02:48:22
See other reply
wolenetz
2015/02/05 23:04:59
Acknowledged.
| |
| 1021 scoped_ptr<Cluster> cluster(CreateCluster(0, block_infos, block_count)); | |
| 1022 int result = parser_->Parse(cluster->data(), cluster->size()); | |
| 1023 EXPECT_EQ(cluster->size(), result); | |
| 1024 | |
| 1025 // BlockInfo duration will be used to verify buffer duration, so changing | |
| 1026 // duration to be that of the Opus packet to verify it was preferred. | |
| 1027 block_infos[0].duration = packet_ptr->duration_ms; | |
|
wolenetz
2015/02/03 22:47:02
nit: I assume that the next line would fail withou
chcunningham
2015/02/05 02:48:22
I think this test is quite strong. I can't think o
wolenetz
2015/02/05 23:04:59
The test is strong. I think changing the EXPECT_EQ
| |
| 1028 ASSERT_TRUE(VerifyBuffers(parser_, block_infos, block_count)); | |
| 1029 } | |
| 955 } | 1030 } |
| 956 | 1031 |
| 957 } // namespace media | 1032 } // namespace media |
| OLD | NEW |