Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: media/formats/webm/webm_cluster_parser_unittest.cc

Issue 149153002: MSE: Add StreamParser buffer remuxing utility and tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments from PS4 Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/formats/webm/webm_cluster_parser.cc ('k') | media/media.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 EXPECT_EQ(block_info[i].track_num, buffer->track_id());
127 } 133 }
128 134
129 return true; 135 return true;
130 } 136 }
131 137
132 static bool VerifyBuffers(const scoped_ptr<WebMClusterParser>& parser, 138 static bool VerifyBuffers(const scoped_ptr<WebMClusterParser>& parser,
133 const BlockInfo* block_info, 139 const BlockInfo* block_info,
134 int block_count) { 140 int block_count) {
135 const WebMClusterParser::TextBufferQueueMap& text_map = 141 const WebMClusterParser::TextBufferQueueMap& text_map =
136 parser->GetTextBuffers(); 142 parser->GetTextBuffers();
(...skipping 26 matching lines...) Expand all
163 while (block_info_ptr != block_info_end) { 169 while (block_info_ptr != block_info_end) {
164 const BlockInfo& block_info = *block_info_ptr++; 170 const BlockInfo& block_info = *block_info_ptr++;
165 171
166 if (block_info.track_num != text_track_num) 172 if (block_info.track_num != text_track_num)
167 continue; 173 continue;
168 174
169 EXPECT_FALSE(block_info.use_simple_block); 175 EXPECT_FALSE(block_info.use_simple_block);
170 EXPECT_FALSE(buffer_iter == buffer_end); 176 EXPECT_FALSE(buffer_iter == buffer_end);
171 177
172 const scoped_refptr<StreamParserBuffer> buffer = *buffer_iter++; 178 const scoped_refptr<StreamParserBuffer> buffer = *buffer_iter++;
173 EXPECT_EQ(buffer->timestamp().InMilliseconds(), block_info.timestamp); 179 EXPECT_EQ(block_info.timestamp, buffer->timestamp().InMilliseconds());
174 EXPECT_EQ(buffer->duration().InMilliseconds(), block_info.duration); 180 EXPECT_EQ(block_info.duration, buffer->duration().InMilliseconds());
181 EXPECT_EQ(DemuxerStream::TEXT, buffer->type());
182 EXPECT_EQ(text_track_num, buffer->track_id());
175 } 183 }
176 184
177 EXPECT_TRUE(buffer_iter == buffer_end); 185 EXPECT_TRUE(buffer_iter == buffer_end);
178 return true; 186 return true;
179 } 187 }
180 188
181 static void VerifyEncryptedBuffer( 189 static void VerifyEncryptedBuffer(
182 scoped_refptr<StreamParserBuffer> buffer) { 190 scoped_refptr<StreamParserBuffer> buffer) {
183 EXPECT_TRUE(buffer->decrypt_config()); 191 EXPECT_TRUE(buffer->decrypt_config());
184 EXPECT_EQ(static_cast<unsigned long>(DecryptConfig::kDecryptionKeySize), 192 EXPECT_EQ(static_cast<unsigned long>(DecryptConfig::kDecryptionKeySize),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 // parsed. 227 // parsed.
220 int result = parser_->Parse(cluster->data(), cluster->size() - 1); 228 int result = parser_->Parse(cluster->data(), cluster->size() - 1);
221 EXPECT_GT(result, 0); 229 EXPECT_GT(result, 0);
222 EXPECT_LT(result, cluster->size()); 230 EXPECT_LT(result, cluster->size());
223 231
224 ASSERT_TRUE(VerifyBuffers(parser_, kDefaultBlockInfo, block_count - 1)); 232 ASSERT_TRUE(VerifyBuffers(parser_, kDefaultBlockInfo, block_count - 1));
225 parser_->Reset(); 233 parser_->Reset();
226 234
227 // Now parse a whole cluster to verify that all the blocks will get parsed. 235 // Now parse a whole cluster to verify that all the blocks will get parsed.
228 result = parser_->Parse(cluster->data(), cluster->size()); 236 result = parser_->Parse(cluster->data(), cluster->size());
229 EXPECT_EQ(result, cluster->size()); 237 EXPECT_EQ(cluster->size(), result);
230 ASSERT_TRUE(VerifyBuffers(parser_, kDefaultBlockInfo, block_count)); 238 ASSERT_TRUE(VerifyBuffers(parser_, kDefaultBlockInfo, block_count));
231 } 239 }
232 240
233 TEST_F(WebMClusterParserTest, ParseClusterWithSingleCall) { 241 TEST_F(WebMClusterParserTest, ParseClusterWithSingleCall) {
234 int block_count = arraysize(kDefaultBlockInfo); 242 int block_count = arraysize(kDefaultBlockInfo);
235 scoped_ptr<Cluster> cluster(CreateCluster(0, kDefaultBlockInfo, block_count)); 243 scoped_ptr<Cluster> cluster(CreateCluster(0, kDefaultBlockInfo, block_count));
236 244
237 int result = parser_->Parse(cluster->data(), cluster->size()); 245 int result = parser_->Parse(cluster->data(), cluster->size());
238 EXPECT_EQ(cluster->size(), result); 246 EXPECT_EQ(cluster->size(), result);
239 ASSERT_TRUE(VerifyBuffers(parser_, kDefaultBlockInfo, block_count)); 247 ASSERT_TRUE(VerifyBuffers(parser_, kDefaultBlockInfo, block_count));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 0x9B, 0x81, 0x17, // BlockDuration(size=1, value=23) 305 0x9B, 0x81, 0x17, // BlockDuration(size=1, value=23)
298 0xA1, 0x85, 0x81, 0x00, 0x00, 0x00, 0xaa, // Block(size=5, track=1, ts=0) 306 0xA1, 0x85, 0x81, 0x00, 0x00, 0x00, 0xaa, // Block(size=5, track=1, ts=0)
299 // BlockGroup with BlockDuration after Block. 307 // BlockGroup with BlockDuration after Block.
300 0xA0, 0x8A, // BlockGroup(size=10) 308 0xA0, 0x8A, // BlockGroup(size=10)
301 0xA1, 0x85, 0x82, 0x00, 0x21, 0x00, 0x55, // Block(size=5, track=2, ts=33) 309 0xA1, 0x85, 0x82, 0x00, 0x21, 0x00, 0x55, // Block(size=5, track=2, ts=33)
302 0x9B, 0x81, 0x22, // BlockDuration(size=1, value=34) 310 0x9B, 0x81, 0x22, // BlockDuration(size=1, value=34)
303 }; 311 };
304 const int kClusterSize = sizeof(kClusterData); 312 const int kClusterSize = sizeof(kClusterData);
305 313
306 int result = parser_->Parse(kClusterData, kClusterSize); 314 int result = parser_->Parse(kClusterData, kClusterSize);
307 EXPECT_EQ(result, kClusterSize); 315 EXPECT_EQ(kClusterSize, result);
308 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); 316 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count));
309 } 317 }
310 318
311 TEST_F(WebMClusterParserTest, ParseSimpleBlockAndBlockGroupMixture) { 319 TEST_F(WebMClusterParserTest, ParseSimpleBlockAndBlockGroupMixture) {
312 const BlockInfo kBlockInfo[] = { 320 const BlockInfo kBlockInfo[] = {
313 { kAudioTrackNum, 0, 23, true }, 321 { kAudioTrackNum, 0, 23, true },
314 { kAudioTrackNum, 23, 23, false }, 322 { kAudioTrackNum, 23, 23, false },
315 { kVideoTrackNum, 33, 34, true }, 323 { kVideoTrackNum, 33, 34, true },
316 { kAudioTrackNum, 46, 23, false }, 324 { kAudioTrackNum, 46, 23, false },
317 { kVideoTrackNum, 67, 33, false }, 325 { kVideoTrackNum, 67, 33, false },
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 LogCB())); 525 LogCB()));
518 int result = parser_->Parse(cluster->data(), cluster->size()); 526 int result = parser_->Parse(cluster->data(), cluster->size());
519 EXPECT_EQ(-1, result); 527 EXPECT_EQ(-1, result);
520 } 528 }
521 529
522 TEST_F(WebMClusterParserTest, ParseInvalidZeroSizedCluster) { 530 TEST_F(WebMClusterParserTest, ParseInvalidZeroSizedCluster) {
523 const uint8 kBuffer[] = { 531 const uint8 kBuffer[] = {
524 0x1F, 0x43, 0xB6, 0x75, 0x80, // CLUSTER (size = 0) 532 0x1F, 0x43, 0xB6, 0x75, 0x80, // CLUSTER (size = 0)
525 }; 533 };
526 534
527 EXPECT_EQ(parser_->Parse(kBuffer, sizeof(kBuffer)), -1); 535 EXPECT_EQ(-1, parser_->Parse(kBuffer, sizeof(kBuffer)));
528 } 536 }
529 537
530 TEST_F(WebMClusterParserTest, ParseInvalidUnknownButActuallyZeroSizedCluster) { 538 TEST_F(WebMClusterParserTest, ParseInvalidUnknownButActuallyZeroSizedCluster) {
531 const uint8 kBuffer[] = { 539 const uint8 kBuffer[] = {
532 0x1F, 0x43, 0xB6, 0x75, 0xFF, // CLUSTER (size = "unknown") 540 0x1F, 0x43, 0xB6, 0x75, 0xFF, // CLUSTER (size = "unknown")
533 0x1F, 0x43, 0xB6, 0x75, 0x85, // CLUSTER (size = 5) 541 0x1F, 0x43, 0xB6, 0x75, 0x85, // CLUSTER (size = 5)
534 }; 542 };
535 543
536 EXPECT_EQ(parser_->Parse(kBuffer, sizeof(kBuffer)), -1); 544 EXPECT_EQ(-1, parser_->Parse(kBuffer, sizeof(kBuffer)));
537 } 545 }
538 546
539 } // namespace media 547 } // namespace media
OLDNEW
« no previous file with comments | « media/formats/webm/webm_cluster_parser.cc ('k') | media/media.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698