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 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "media/base/decrypt_config.h" | 9 #include "media/base/decrypt_config.h" |
10 #include "media/formats/webm/cluster_builder.h" | 10 #include "media/formats/webm/cluster_builder.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 const WebMClusterParser::BufferQueue& video_buffers, | 89 const WebMClusterParser::BufferQueue& video_buffers, |
90 const WebMClusterParser::BufferQueue& text_buffers, | 90 const WebMClusterParser::BufferQueue& text_buffers, |
91 const BlockInfo* block_info, | 91 const BlockInfo* block_info, |
92 int block_count) { | 92 int block_count) { |
93 size_t audio_offset = 0; | 93 size_t audio_offset = 0; |
94 size_t video_offset = 0; | 94 size_t video_offset = 0; |
95 size_t text_offset = 0; | 95 size_t text_offset = 0; |
96 for (int i = 0; i < block_count; i++) { | 96 for (int i = 0; i < block_count; i++) { |
97 const WebMClusterParser::BufferQueue* buffers = NULL; | 97 const WebMClusterParser::BufferQueue* buffers = NULL; |
98 size_t* offset; | 98 size_t* offset; |
99 StreamParserBuffer::Type expected_type = DemuxerStream::UNKNOWN; | |
99 | 100 |
100 if (block_info[i].track_num == kAudioTrackNum) { | 101 if (block_info[i].track_num == kAudioTrackNum) { |
101 buffers = &audio_buffers; | 102 buffers = &audio_buffers; |
102 offset = &audio_offset; | 103 offset = &audio_offset; |
104 expected_type = DemuxerStream::AUDIO; | |
103 } else if (block_info[i].track_num == kVideoTrackNum) { | 105 } else if (block_info[i].track_num == kVideoTrackNum) { |
104 buffers = &video_buffers; | 106 buffers = &video_buffers; |
105 offset = &video_offset; | 107 offset = &video_offset; |
108 expected_type = DemuxerStream::VIDEO; | |
106 } else if (block_info[i].track_num == kTextTrackNum) { | 109 } else if (block_info[i].track_num == kTextTrackNum) { |
107 buffers = &text_buffers; | 110 buffers = &text_buffers; |
108 offset = &text_offset; | 111 offset = &text_offset; |
112 expected_type = DemuxerStream::TEXT; | |
109 } else { | 113 } else { |
110 LOG(ERROR) << "Unexpected track number " << block_info[i].track_num; | 114 LOG(ERROR) << "Unexpected track number " << block_info[i].track_num; |
111 return false; | 115 return false; |
112 } | 116 } |
113 | 117 |
114 if (*offset >= buffers->size()) | 118 if (*offset >= buffers->size()) |
115 return false; | 119 return false; |
116 | 120 |
117 scoped_refptr<StreamParserBuffer> buffer = (*buffers)[(*offset)++]; | 121 scoped_refptr<StreamParserBuffer> buffer = (*buffers)[(*offset)++]; |
118 | 122 |
119 | 123 EXPECT_EQ(block_info[i].timestamp, buffer->timestamp().InMilliseconds()); |
120 EXPECT_EQ(buffer->timestamp().InMilliseconds(), block_info[i].timestamp); | |
121 | 124 |
122 if (!block_info[i].use_simple_block) | 125 if (!block_info[i].use_simple_block) |
123 EXPECT_NE(buffer->duration(), kNoTimestamp()); | 126 EXPECT_NE(kNoTimestamp(), buffer->duration()); |
124 | 127 |
125 if (buffer->duration() != kNoTimestamp()) | 128 if (buffer->duration() != kNoTimestamp()) |
126 EXPECT_EQ(buffer->duration().InMilliseconds(), block_info[i].duration); | 129 EXPECT_EQ(block_info[i].duration, buffer->duration().InMilliseconds()); |
130 | |
131 EXPECT_EQ(expected_type, buffer->type()); | |
132 if (expected_type == DemuxerStream::TEXT) | |
133 EXPECT_EQ(kTextTrackNum, buffer->text_track_number()); | |
127 } | 134 } |
128 | 135 |
129 return true; | 136 return true; |
130 } | 137 } |
131 | 138 |
132 static bool VerifyBuffers(const scoped_ptr<WebMClusterParser>& parser, | 139 static bool VerifyBuffers(const scoped_ptr<WebMClusterParser>& parser, |
133 const BlockInfo* block_info, | 140 const BlockInfo* block_info, |
134 int block_count) { | 141 int block_count) { |
135 const WebMClusterParser::TextBufferQueueMap& text_map = | 142 const WebMClusterParser::TextBufferQueueMap& text_map = |
136 parser->GetTextBuffers(); | 143 parser->GetTextBuffers(); |
(...skipping 26 matching lines...) Expand all Loading... | |
163 while (block_info_ptr != block_info_end) { | 170 while (block_info_ptr != block_info_end) { |
164 const BlockInfo& block_info = *block_info_ptr++; | 171 const BlockInfo& block_info = *block_info_ptr++; |
165 | 172 |
166 if (block_info.track_num != text_track_num) | 173 if (block_info.track_num != text_track_num) |
167 continue; | 174 continue; |
168 | 175 |
169 EXPECT_FALSE(block_info.use_simple_block); | 176 EXPECT_FALSE(block_info.use_simple_block); |
170 EXPECT_FALSE(buffer_iter == buffer_end); | 177 EXPECT_FALSE(buffer_iter == buffer_end); |
171 | 178 |
172 const scoped_refptr<StreamParserBuffer> buffer = *buffer_iter++; | 179 const scoped_refptr<StreamParserBuffer> buffer = *buffer_iter++; |
173 EXPECT_EQ(buffer->timestamp().InMilliseconds(), block_info.timestamp); | 180 EXPECT_EQ(block_info.timestamp, buffer->timestamp().InMilliseconds()); |
174 EXPECT_EQ(buffer->duration().InMilliseconds(), block_info.duration); | 181 EXPECT_EQ(block_info.duration, buffer->duration().InMilliseconds()); |
182 EXPECT_EQ(DemuxerStream::TEXT, buffer->type()); | |
183 EXPECT_EQ(text_track_num, buffer->text_track_number()); | |
175 } | 184 } |
176 | 185 |
177 EXPECT_TRUE(buffer_iter == buffer_end); | 186 EXPECT_TRUE(buffer_iter == buffer_end); |
178 return true; | 187 return true; |
179 } | 188 } |
180 | 189 |
181 static void VerifyEncryptedBuffer( | 190 static void VerifyEncryptedBuffer( |
182 scoped_refptr<StreamParserBuffer> buffer) { | 191 scoped_refptr<StreamParserBuffer> buffer) { |
183 EXPECT_TRUE(buffer->decrypt_config()); | 192 EXPECT_TRUE(buffer->decrypt_config()); |
184 EXPECT_EQ(static_cast<unsigned long>(DecryptConfig::kDecryptionKeySize), | 193 EXPECT_EQ(static_cast<unsigned long>(DecryptConfig::kDecryptionKeySize), |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 // parsed. | 228 // parsed. |
220 int result = parser_->Parse(cluster->data(), cluster->size() - 1); | 229 int result = parser_->Parse(cluster->data(), cluster->size() - 1); |
221 EXPECT_GT(result, 0); | 230 EXPECT_GT(result, 0); |
222 EXPECT_LT(result, cluster->size()); | 231 EXPECT_LT(result, cluster->size()); |
223 | 232 |
224 ASSERT_TRUE(VerifyBuffers(parser_, kDefaultBlockInfo, block_count - 1)); | 233 ASSERT_TRUE(VerifyBuffers(parser_, kDefaultBlockInfo, block_count - 1)); |
225 parser_->Reset(); | 234 parser_->Reset(); |
226 | 235 |
227 // Now parse a whole cluster to verify that all the blocks will get parsed. | 236 // Now parse a whole cluster to verify that all the blocks will get parsed. |
228 result = parser_->Parse(cluster->data(), cluster->size()); | 237 result = parser_->Parse(cluster->data(), cluster->size()); |
229 EXPECT_EQ(result, cluster->size()); | 238 EXPECT_EQ(cluster->size(), result); |
230 ASSERT_TRUE(VerifyBuffers(parser_, kDefaultBlockInfo, block_count)); | 239 ASSERT_TRUE(VerifyBuffers(parser_, kDefaultBlockInfo, block_count)); |
231 } | 240 } |
232 | 241 |
233 TEST_F(WebMClusterParserTest, ParseClusterWithSingleCall) { | 242 TEST_F(WebMClusterParserTest, ParseClusterWithSingleCall) { |
234 int block_count = arraysize(kDefaultBlockInfo); | 243 int block_count = arraysize(kDefaultBlockInfo); |
235 scoped_ptr<Cluster> cluster(CreateCluster(0, kDefaultBlockInfo, block_count)); | 244 scoped_ptr<Cluster> cluster(CreateCluster(0, kDefaultBlockInfo, block_count)); |
236 | 245 |
237 int result = parser_->Parse(cluster->data(), cluster->size()); | 246 int result = parser_->Parse(cluster->data(), cluster->size()); |
238 EXPECT_EQ(cluster->size(), result); | 247 EXPECT_EQ(result, cluster->size()); |
xhwang
2014/02/06 00:36:32
why reverse this order?
wolenetz
2014/02/06 23:56:03
My mistake. Fixed.
| |
239 ASSERT_TRUE(VerifyBuffers(parser_, kDefaultBlockInfo, block_count)); | 248 ASSERT_TRUE(VerifyBuffers(parser_, kDefaultBlockInfo, block_count)); |
240 } | 249 } |
241 | 250 |
242 TEST_F(WebMClusterParserTest, ParseClusterWithMultipleCalls) { | 251 TEST_F(WebMClusterParserTest, ParseClusterWithMultipleCalls) { |
243 int block_count = arraysize(kDefaultBlockInfo); | 252 int block_count = arraysize(kDefaultBlockInfo); |
244 scoped_ptr<Cluster> cluster(CreateCluster(0, kDefaultBlockInfo, block_count)); | 253 scoped_ptr<Cluster> cluster(CreateCluster(0, kDefaultBlockInfo, block_count)); |
245 | 254 |
246 WebMClusterParser::BufferQueue audio_buffers; | 255 WebMClusterParser::BufferQueue audio_buffers; |
247 WebMClusterParser::BufferQueue video_buffers; | 256 WebMClusterParser::BufferQueue video_buffers; |
248 const WebMClusterParser::BufferQueue no_text_buffers; | 257 const WebMClusterParser::BufferQueue no_text_buffers; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 0x9B, 0x81, 0x17, // BlockDuration(size=1, value=23) | 306 0x9B, 0x81, 0x17, // BlockDuration(size=1, value=23) |
298 0xA1, 0x85, 0x81, 0x00, 0x00, 0x00, 0xaa, // Block(size=5, track=1, ts=0) | 307 0xA1, 0x85, 0x81, 0x00, 0x00, 0x00, 0xaa, // Block(size=5, track=1, ts=0) |
299 // BlockGroup with BlockDuration after Block. | 308 // BlockGroup with BlockDuration after Block. |
300 0xA0, 0x8A, // BlockGroup(size=10) | 309 0xA0, 0x8A, // BlockGroup(size=10) |
301 0xA1, 0x85, 0x82, 0x00, 0x21, 0x00, 0x55, // Block(size=5, track=2, ts=33) | 310 0xA1, 0x85, 0x82, 0x00, 0x21, 0x00, 0x55, // Block(size=5, track=2, ts=33) |
302 0x9B, 0x81, 0x22, // BlockDuration(size=1, value=34) | 311 0x9B, 0x81, 0x22, // BlockDuration(size=1, value=34) |
303 }; | 312 }; |
304 const int kClusterSize = sizeof(kClusterData); | 313 const int kClusterSize = sizeof(kClusterData); |
305 | 314 |
306 int result = parser_->Parse(kClusterData, kClusterSize); | 315 int result = parser_->Parse(kClusterData, kClusterSize); |
307 EXPECT_EQ(result, kClusterSize); | 316 EXPECT_EQ(kClusterSize, result); |
308 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | 317 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); |
309 } | 318 } |
310 | 319 |
311 TEST_F(WebMClusterParserTest, ParseSimpleBlockAndBlockGroupMixture) { | 320 TEST_F(WebMClusterParserTest, ParseSimpleBlockAndBlockGroupMixture) { |
312 const BlockInfo kBlockInfo[] = { | 321 const BlockInfo kBlockInfo[] = { |
313 { kAudioTrackNum, 0, 23, true }, | 322 { kAudioTrackNum, 0, 23, true }, |
314 { kAudioTrackNum, 23, 23, false }, | 323 { kAudioTrackNum, 23, 23, false }, |
315 { kVideoTrackNum, 33, 34, true }, | 324 { kVideoTrackNum, 33, 34, true }, |
316 { kAudioTrackNum, 46, 23, false }, | 325 { kAudioTrackNum, 46, 23, false }, |
317 { kVideoTrackNum, 67, 33, false }, | 326 { kVideoTrackNum, 67, 33, false }, |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
517 LogCB())); | 526 LogCB())); |
518 int result = parser_->Parse(cluster->data(), cluster->size()); | 527 int result = parser_->Parse(cluster->data(), cluster->size()); |
519 EXPECT_EQ(-1, result); | 528 EXPECT_EQ(-1, result); |
520 } | 529 } |
521 | 530 |
522 TEST_F(WebMClusterParserTest, ParseInvalidZeroSizedCluster) { | 531 TEST_F(WebMClusterParserTest, ParseInvalidZeroSizedCluster) { |
523 const uint8 kBuffer[] = { | 532 const uint8 kBuffer[] = { |
524 0x1F, 0x43, 0xB6, 0x75, 0x80, // CLUSTER (size = 0) | 533 0x1F, 0x43, 0xB6, 0x75, 0x80, // CLUSTER (size = 0) |
525 }; | 534 }; |
526 | 535 |
527 EXPECT_EQ(parser_->Parse(kBuffer, sizeof(kBuffer)), -1); | 536 EXPECT_EQ(-1, parser_->Parse(kBuffer, sizeof(kBuffer))); |
528 } | 537 } |
529 | 538 |
530 TEST_F(WebMClusterParserTest, ParseInvalidUnknownButActuallyZeroSizedCluster) { | 539 TEST_F(WebMClusterParserTest, ParseInvalidUnknownButActuallyZeroSizedCluster) { |
531 const uint8 kBuffer[] = { | 540 const uint8 kBuffer[] = { |
532 0x1F, 0x43, 0xB6, 0x75, 0xFF, // CLUSTER (size = "unknown") | 541 0x1F, 0x43, 0xB6, 0x75, 0xFF, // CLUSTER (size = "unknown") |
533 0x1F, 0x43, 0xB6, 0x75, 0x85, // CLUSTER (size = 5) | 542 0x1F, 0x43, 0xB6, 0x75, 0x85, // CLUSTER (size = 5) |
534 }; | 543 }; |
535 | 544 |
536 EXPECT_EQ(parser_->Parse(kBuffer, sizeof(kBuffer)), -1); | 545 EXPECT_EQ(-1, parser_->Parse(kBuffer, sizeof(kBuffer))); |
537 } | 546 } |
538 | 547 |
539 } // namespace media | 548 } // namespace media |
OLD | NEW |