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

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: Attempt windows stream_parser_unittests compilation fix 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
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 = StreamParserBuffer::kAudio;
xhwang 2014/01/29 08:04:50 kAudio/UNKNOWN here, then set expected_type to kAu
wolenetz 2014/02/05 02:49:53 Done.
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;
103 } else if (block_info[i].track_num == kVideoTrackNum) { 104 } else if (block_info[i].track_num == kVideoTrackNum) {
104 buffers = &video_buffers; 105 buffers = &video_buffers;
105 offset = &video_offset; 106 offset = &video_offset;
107 expected_type = StreamParserBuffer::kVideo;
106 } else if (block_info[i].track_num == kTextTrackNum) { 108 } else if (block_info[i].track_num == kTextTrackNum) {
107 buffers = &text_buffers; 109 buffers = &text_buffers;
108 offset = &text_offset; 110 offset = &text_offset;
111 expected_type = StreamParserBuffer::kText;
109 } else { 112 } else {
110 LOG(ERROR) << "Unexpected track number " << block_info[i].track_num; 113 LOG(ERROR) << "Unexpected track number " << block_info[i].track_num;
111 return false; 114 return false;
112 } 115 }
113 116
114 if (*offset >= buffers->size()) 117 if (*offset >= buffers->size())
115 return false; 118 return false;
116 119
117 scoped_refptr<StreamParserBuffer> buffer = (*buffers)[(*offset)++]; 120 scoped_refptr<StreamParserBuffer> buffer = (*buffers)[(*offset)++];
118 121
119
120 EXPECT_EQ(buffer->timestamp().InMilliseconds(), block_info[i].timestamp); 122 EXPECT_EQ(buffer->timestamp().InMilliseconds(), block_info[i].timestamp);
121 123
122 if (!block_info[i].use_simple_block) 124 if (!block_info[i].use_simple_block)
123 EXPECT_NE(buffer->duration(), kNoTimestamp()); 125 EXPECT_NE(buffer->duration(), kNoTimestamp());
124 126
125 if (buffer->duration() != kNoTimestamp()) 127 if (buffer->duration() != kNoTimestamp())
126 EXPECT_EQ(buffer->duration().InMilliseconds(), block_info[i].duration); 128 EXPECT_EQ(buffer->duration().InMilliseconds(), block_info[i].duration);
129
130 EXPECT_EQ(buffer->type(), expected_type);
131 if (expected_type == StreamParserBuffer::kText)
132 EXPECT_EQ(buffer->text_track_number(), kTextTrackNum);
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 28 matching lines...) Expand all
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(buffer->timestamp().InMilliseconds(), block_info.timestamp);
174 EXPECT_EQ(buffer->duration().InMilliseconds(), block_info.duration); 180 EXPECT_EQ(buffer->duration().InMilliseconds(), block_info.duration);
181 EXPECT_EQ(buffer->type(), StreamParserBuffer::kText);
182 EXPECT_EQ(buffer->text_track_number(), text_track_num);
xhwang 2014/01/29 08:04:50 FYI, we use EXPECT_EQ(expected, variable) style, n
wolenetz 2014/02/05 02:49:53 Done, also conformed a bunch of other places in th
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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(parser_->Parse(kBuffer, sizeof(kBuffer)), -1);
537 } 545 }
538 546
539 } // namespace media 547 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698