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