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 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "media/base/audio_decoder_config.h" | 11 #include "media/base/audio_decoder_config.h" |
12 #include "media/base/decrypt_config.h" | 12 #include "media/base/decrypt_config.h" |
13 #include "media/formats/webm/cluster_builder.h" | 13 #include "media/formats/webm/cluster_builder.h" |
14 #include "media/formats/webm/opus_packet_builder.h" | 14 #include "media/formats/webm/opus_packet_builder.h" |
15 #include "media/formats/webm/webm_cluster_parser.h" | 15 #include "media/formats/webm/webm_cluster_parser.h" |
16 #include "media/formats/webm/webm_constants.h" | 16 #include "media/formats/webm/webm_constants.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 | 19 |
20 using ::testing::InSequence; | 20 using ::testing::InSequence; |
21 using ::testing::Return; | 21 using ::testing::Return; |
22 using ::testing::_; | 22 using ::testing::_; |
23 | 23 |
24 namespace media { | 24 namespace media { |
25 | 25 |
26 typedef WebMTracksParser::TextTracks TextTracks; | 26 typedef WebMTracksParser::TextTracks TextTracks; |
27 | 27 |
28 namespace { | |
29 | |
28 enum { | 30 enum { |
29 kTimecodeScale = 1000000, // Timecode scale for millisecond timestamps. | 31 kTimecodeScale = 1000000, // Timecode scale for millisecond timestamps. |
30 kAudioTrackNum = 1, | 32 kAudioTrackNum = 1, |
31 kVideoTrackNum = 2, | 33 kVideoTrackNum = 2, |
32 kTextTrackNum = 3, | 34 kTextTrackNum = 3, |
33 kTestAudioFrameDefaultDurationInMs = 13, | 35 kTestAudioFrameDefaultDurationInMs = 13, |
34 kTestVideoFrameDefaultDurationInMs = 17 | 36 kTestVideoFrameDefaultDurationInMs = 17 |
35 }; | 37 }; |
36 | 38 |
37 // Test duration defaults must differ from parser estimation defaults to know | 39 // Test duration defaults must differ from parser estimation defaults to know |
(...skipping 18 matching lines...) Expand all Loading... | |
56 // parser verification. | 58 // parser verification. |
57 double duration; | 59 double duration; |
58 | 60 |
59 bool use_simple_block; | 61 bool use_simple_block; |
60 | 62 |
61 // Default data will be used if no data given. | 63 // Default data will be used if no data given. |
62 const uint8_t* data; | 64 const uint8_t* data; |
63 int data_length; | 65 int data_length; |
64 }; | 66 }; |
65 | 67 |
66 static const BlockInfo kDefaultBlockInfo[] = { | 68 const BlockInfo kDefaultBlockInfo[] = { |
67 {kAudioTrackNum, 0, 23, true, NULL, 0}, | 69 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
68 {kAudioTrackNum, 23, 23, true, NULL, 0}, | 70 {kAudioTrackNum, 23, 23, true, NULL, 0}, |
69 // Assumes not using DefaultDuration | 71 // Assumes not using DefaultDuration |
70 {kVideoTrackNum, 33, 34, true, NULL, 0}, | 72 {kVideoTrackNum, 33, 34, true, NULL, 0}, |
71 {kAudioTrackNum, 46, 23, true, NULL, 0}, | 73 {kAudioTrackNum, 46, 23, true, NULL, 0}, |
72 {kVideoTrackNum, 67, 33, false, NULL, 0}, | 74 {kVideoTrackNum, 67, 33, false, NULL, 0}, |
73 {kAudioTrackNum, 69, 23, false, NULL, 0}, | 75 {kAudioTrackNum, 69, 23, false, NULL, 0}, |
74 {kVideoTrackNum, 100, 33, false, NULL, 0}, | 76 {kVideoTrackNum, 100, 33, false, NULL, 0}, |
75 }; | 77 }; |
76 | 78 |
77 static const uint8_t kEncryptedFrame[] = { | 79 const uint8_t kEncryptedFrame[] = { |
78 0x01, // Block is encrypted | 80 // Block is encrypted |
79 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 // IV | 81 0x01, |
80 }; | |
81 | 82 |
82 static scoped_ptr<Cluster> CreateCluster(int timecode, | 83 // IV |
83 const BlockInfo* block_info, | 84 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}; |
84 int block_count) { | 85 |
86 // Helper that hard-codes some non-varying constructor parameters. | |
87 WebMClusterParser* CreateParserHelper( | |
88 base::TimeDelta audio_default_duration, | |
89 base::TimeDelta video_default_duration, | |
90 const WebMTracksParser::TextTracks& text_tracks, | |
91 const std::set<int64>& ignored_tracks, | |
92 const std::string& audio_encryption_key_id, | |
93 const std::string& video_encryption_key_id, | |
94 const AudioCodec audio_codec) { | |
95 return new WebMClusterParser( | |
96 kTimecodeScale, kAudioTrackNum, audio_default_duration, kVideoTrackNum, | |
97 video_default_duration, text_tracks, ignored_tracks, | |
98 audio_encryption_key_id, video_encryption_key_id, audio_codec, | |
99 new MediaLog()); | |
100 } | |
101 | |
102 // Create a default version of the parser for test. | |
103 WebMClusterParser* CreateParser() { | |
xhwang
2015/07/21 04:28:31
Looking at the call sites below, it's a bit hard t
wolenetz
2015/07/21 18:15:56
Done (and good point!) I hadn't read that particul
| |
104 return CreateParserHelper(kNoTimestamp(), kNoTimestamp(), TextTracks(), | |
105 std::set<int64>(), std::string(), std::string(), | |
106 kUnknownAudioCodec); | |
107 } | |
108 | |
109 // Create a parser for test with custom audio and video default durations, and | |
110 // optionally custom text tracks. | |
111 WebMClusterParser* CreateParser( | |
112 base::TimeDelta audio_default_duration, | |
113 base::TimeDelta video_default_duration, | |
114 const WebMTracksParser::TextTracks& text_tracks = TextTracks()) { | |
115 return CreateParserHelper(audio_default_duration, video_default_duration, | |
116 text_tracks, std::set<int64>(), std::string(), | |
117 std::string(), kUnknownAudioCodec); | |
118 } | |
119 | |
120 // Create a parser for test with custom ignored tracks. | |
121 WebMClusterParser* CreateParser(std::set<int64>& ignored_tracks) { | |
122 return CreateParserHelper(kNoTimestamp(), kNoTimestamp(), TextTracks(), | |
123 ignored_tracks, std::string(), std::string(), | |
124 kUnknownAudioCodec); | |
125 } | |
126 | |
127 // Create a parser for test with custom encryption key ids and audio codec. | |
128 WebMClusterParser* CreateParser(const std::string& audio_encryption_key_id, | |
129 const std::string& video_encryption_key_id, | |
130 const AudioCodec audio_codec) { | |
131 return CreateParserHelper(kNoTimestamp(), kNoTimestamp(), TextTracks(), | |
132 std::set<int64>(), audio_encryption_key_id, | |
133 video_encryption_key_id, audio_codec); | |
134 } | |
135 | |
136 scoped_ptr<Cluster> CreateCluster(int timecode, | |
137 const BlockInfo* block_info, | |
138 int block_count) { | |
85 ClusterBuilder cb; | 139 ClusterBuilder cb; |
86 cb.SetClusterTimecode(0); | 140 cb.SetClusterTimecode(0); |
87 | 141 |
88 uint8_t kDefaultBlockData[] = { 0x00 }; | 142 uint8_t kDefaultBlockData[] = { 0x00 }; |
89 | 143 |
90 for (int i = 0; i < block_count; i++) { | 144 for (int i = 0; i < block_count; i++) { |
91 const uint8_t* data; | 145 const uint8_t* data; |
92 int data_length; | 146 int data_length; |
93 if (block_info[i].data != NULL) { | 147 if (block_info[i].data != NULL) { |
94 data = block_info[i].data; | 148 data = block_info[i].data; |
(...skipping 19 matching lines...) Expand all Loading... | |
114 | 168 |
115 cb.AddBlockGroup(block_info[i].track_num, block_info[i].timestamp, | 169 cb.AddBlockGroup(block_info[i].track_num, block_info[i].timestamp, |
116 block_info[i].duration, 0, data, data_length); | 170 block_info[i].duration, 0, data, data_length); |
117 } | 171 } |
118 | 172 |
119 return cb.Finish(); | 173 return cb.Finish(); |
120 } | 174 } |
121 | 175 |
122 // Creates a Cluster with one encrypted Block. |bytes_to_write| is number of | 176 // Creates a Cluster with one encrypted Block. |bytes_to_write| is number of |
123 // bytes of the encrypted frame to write. | 177 // bytes of the encrypted frame to write. |
124 static scoped_ptr<Cluster> CreateEncryptedCluster(int bytes_to_write) { | 178 scoped_ptr<Cluster> CreateEncryptedCluster(int bytes_to_write) { |
125 CHECK_GT(bytes_to_write, 0); | 179 CHECK_GT(bytes_to_write, 0); |
126 CHECK_LE(bytes_to_write, static_cast<int>(sizeof(kEncryptedFrame))); | 180 CHECK_LE(bytes_to_write, static_cast<int>(sizeof(kEncryptedFrame))); |
127 | 181 |
128 ClusterBuilder cb; | 182 ClusterBuilder cb; |
129 cb.SetClusterTimecode(0); | 183 cb.SetClusterTimecode(0); |
130 cb.AddSimpleBlock(kVideoTrackNum, 0, 0, kEncryptedFrame, bytes_to_write); | 184 cb.AddSimpleBlock(kVideoTrackNum, 0, 0, kEncryptedFrame, bytes_to_write); |
131 return cb.Finish(); | 185 return cb.Finish(); |
132 } | 186 } |
133 | 187 |
134 static bool VerifyBuffers(const WebMClusterParser::BufferQueue& audio_buffers, | 188 bool VerifyBuffers(const WebMClusterParser::BufferQueue& audio_buffers, |
135 const WebMClusterParser::BufferQueue& video_buffers, | 189 const WebMClusterParser::BufferQueue& video_buffers, |
136 const WebMClusterParser::BufferQueue& text_buffers, | 190 const WebMClusterParser::BufferQueue& text_buffers, |
137 const BlockInfo* block_info, | 191 const BlockInfo* block_info, |
138 int block_count) { | 192 int block_count) { |
139 int buffer_count = audio_buffers.size() + video_buffers.size() + | 193 int buffer_count = audio_buffers.size() + video_buffers.size() + |
140 text_buffers.size(); | 194 text_buffers.size(); |
141 if (block_count != buffer_count) { | 195 if (block_count != buffer_count) { |
142 DVLOG(1) << __FUNCTION__ << " : block_count (" << block_count | 196 DVLOG(1) << __FUNCTION__ << " : block_count (" << block_count |
143 << ") mismatches buffer_count (" << buffer_count << ")"; | 197 << ") mismatches buffer_count (" << buffer_count << ")"; |
144 return false; | 198 return false; |
145 } | 199 } |
146 | 200 |
147 size_t audio_offset = 0; | 201 size_t audio_offset = 0; |
148 size_t video_offset = 0; | 202 size_t video_offset = 0; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 EXPECT_EQ(block_info[i].timestamp, buffer->timestamp().InMilliseconds()); | 235 EXPECT_EQ(block_info[i].timestamp, buffer->timestamp().InMilliseconds()); |
182 EXPECT_EQ(std::abs(block_info[i].duration), | 236 EXPECT_EQ(std::abs(block_info[i].duration), |
183 buffer->duration().InMillisecondsF()); | 237 buffer->duration().InMillisecondsF()); |
184 EXPECT_EQ(expected_type, buffer->type()); | 238 EXPECT_EQ(expected_type, buffer->type()); |
185 EXPECT_EQ(block_info[i].track_num, buffer->track_id()); | 239 EXPECT_EQ(block_info[i].track_num, buffer->track_id()); |
186 } | 240 } |
187 | 241 |
188 return true; | 242 return true; |
189 } | 243 } |
190 | 244 |
191 static bool VerifyBuffers(const scoped_ptr<WebMClusterParser>& parser, | 245 bool VerifyBuffers(const scoped_ptr<WebMClusterParser>& parser, |
192 const BlockInfo* block_info, | 246 const BlockInfo* block_info, |
193 int block_count) { | 247 int block_count) { |
194 const WebMClusterParser::TextBufferQueueMap& text_map = | 248 const WebMClusterParser::TextBufferQueueMap& text_map = |
195 parser->GetTextBuffers(); | 249 parser->GetTextBuffers(); |
196 const WebMClusterParser::BufferQueue* text_buffers; | 250 const WebMClusterParser::BufferQueue* text_buffers; |
197 const WebMClusterParser::BufferQueue no_text_buffers; | 251 const WebMClusterParser::BufferQueue no_text_buffers; |
198 if (!text_map.empty()) | 252 if (!text_map.empty()) |
199 text_buffers = &(text_map.rbegin()->second); | 253 text_buffers = &(text_map.rbegin()->second); |
200 else | 254 else |
201 text_buffers = &no_text_buffers; | 255 text_buffers = &no_text_buffers; |
202 | 256 |
203 return VerifyBuffers(parser->GetAudioBuffers(), | 257 return VerifyBuffers(parser->GetAudioBuffers(), |
204 parser->GetVideoBuffers(), | 258 parser->GetVideoBuffers(), |
205 *text_buffers, | 259 *text_buffers, |
206 block_info, | 260 block_info, |
207 block_count); | 261 block_count); |
208 } | 262 } |
209 | 263 |
210 static bool VerifyTextBuffers( | 264 bool VerifyTextBuffers(const scoped_ptr<WebMClusterParser>& parser, |
211 const scoped_ptr<WebMClusterParser>& parser, | 265 const BlockInfo* block_info_ptr, |
212 const BlockInfo* block_info_ptr, | 266 int block_count, |
213 int block_count, | 267 int text_track_num, |
214 int text_track_num, | 268 const WebMClusterParser::BufferQueue& text_buffers) { |
215 const WebMClusterParser::BufferQueue& text_buffers) { | |
216 const BlockInfo* const block_info_end = block_info_ptr + block_count; | 269 const BlockInfo* const block_info_end = block_info_ptr + block_count; |
217 | 270 |
218 typedef WebMClusterParser::BufferQueue::const_iterator TextBufferIter; | 271 typedef WebMClusterParser::BufferQueue::const_iterator TextBufferIter; |
219 TextBufferIter buffer_iter = text_buffers.begin(); | 272 TextBufferIter buffer_iter = text_buffers.begin(); |
220 const TextBufferIter buffer_end = text_buffers.end(); | 273 const TextBufferIter buffer_end = text_buffers.end(); |
221 | 274 |
222 while (block_info_ptr != block_info_end) { | 275 while (block_info_ptr != block_info_end) { |
223 const BlockInfo& block_info = *block_info_ptr++; | 276 const BlockInfo& block_info = *block_info_ptr++; |
224 | 277 |
225 if (block_info.track_num != text_track_num) | 278 if (block_info.track_num != text_track_num) |
226 continue; | 279 continue; |
227 | 280 |
228 EXPECT_FALSE(block_info.use_simple_block); | 281 EXPECT_FALSE(block_info.use_simple_block); |
229 EXPECT_FALSE(buffer_iter == buffer_end); | 282 EXPECT_FALSE(buffer_iter == buffer_end); |
230 | 283 |
231 const scoped_refptr<StreamParserBuffer> buffer = *buffer_iter++; | 284 const scoped_refptr<StreamParserBuffer> buffer = *buffer_iter++; |
232 EXPECT_EQ(block_info.timestamp, buffer->timestamp().InMilliseconds()); | 285 EXPECT_EQ(block_info.timestamp, buffer->timestamp().InMilliseconds()); |
233 EXPECT_EQ(std::abs(block_info.duration), | 286 EXPECT_EQ(std::abs(block_info.duration), |
234 buffer->duration().InMillisecondsF()); | 287 buffer->duration().InMillisecondsF()); |
235 EXPECT_EQ(DemuxerStream::TEXT, buffer->type()); | 288 EXPECT_EQ(DemuxerStream::TEXT, buffer->type()); |
236 EXPECT_EQ(text_track_num, buffer->track_id()); | 289 EXPECT_EQ(text_track_num, buffer->track_id()); |
237 } | 290 } |
238 | 291 |
239 EXPECT_TRUE(buffer_iter == buffer_end); | 292 EXPECT_TRUE(buffer_iter == buffer_end); |
240 return true; | 293 return true; |
241 } | 294 } |
242 | 295 |
243 static void VerifyEncryptedBuffer( | 296 void VerifyEncryptedBuffer(scoped_refptr<StreamParserBuffer> buffer) { |
244 scoped_refptr<StreamParserBuffer> buffer) { | |
245 EXPECT_TRUE(buffer->decrypt_config()); | 297 EXPECT_TRUE(buffer->decrypt_config()); |
246 EXPECT_EQ(static_cast<unsigned long>(DecryptConfig::kDecryptionKeySize), | 298 EXPECT_EQ(static_cast<unsigned long>(DecryptConfig::kDecryptionKeySize), |
247 buffer->decrypt_config()->iv().length()); | 299 buffer->decrypt_config()->iv().length()); |
248 } | 300 } |
249 | 301 |
250 static void AppendToEnd(const WebMClusterParser::BufferQueue& src, | 302 void AppendToEnd(const WebMClusterParser::BufferQueue& src, |
251 WebMClusterParser::BufferQueue* dest) { | 303 WebMClusterParser::BufferQueue* dest) { |
252 for (WebMClusterParser::BufferQueue::const_iterator itr = src.begin(); | 304 for (WebMClusterParser::BufferQueue::const_iterator itr = src.begin(); |
253 itr != src.end(); ++itr) { | 305 itr != src.end(); ++itr) { |
254 dest->push_back(*itr); | 306 dest->push_back(*itr); |
255 } | 307 } |
256 } | 308 } |
257 | 309 |
310 } // namespace | |
311 | |
258 class WebMClusterParserTest : public testing::Test { | 312 class WebMClusterParserTest : public testing::Test { |
259 public: | 313 public: |
260 WebMClusterParserTest() | 314 WebMClusterParserTest() : parser_(CreateParser()) {} |
261 : parser_(new WebMClusterParser(kTimecodeScale, | |
262 kAudioTrackNum, | |
263 kNoTimestamp(), | |
264 kVideoTrackNum, | |
265 kNoTimestamp(), | |
266 TextTracks(), | |
267 std::set<int64>(), | |
268 std::string(), | |
269 std::string(), | |
270 kUnknownAudioCodec, | |
271 new MediaLog())) {} | |
272 | 315 |
273 protected: | 316 protected: |
274 void ResetParserToHaveDefaultDurations() { | 317 void ResetParserToHaveDefaultDurations() { |
275 base::TimeDelta default_audio_duration = base::TimeDelta::FromMilliseconds( | 318 base::TimeDelta default_audio_duration = base::TimeDelta::FromMilliseconds( |
276 kTestAudioFrameDefaultDurationInMs); | 319 kTestAudioFrameDefaultDurationInMs); |
277 base::TimeDelta default_video_duration = base::TimeDelta::FromMilliseconds( | 320 base::TimeDelta default_video_duration = base::TimeDelta::FromMilliseconds( |
278 kTestVideoFrameDefaultDurationInMs); | 321 kTestVideoFrameDefaultDurationInMs); |
279 ASSERT_GE(default_audio_duration, base::TimeDelta()); | 322 ASSERT_GE(default_audio_duration, base::TimeDelta()); |
280 ASSERT_GE(default_video_duration, base::TimeDelta()); | 323 ASSERT_GE(default_video_duration, base::TimeDelta()); |
281 ASSERT_NE(kNoTimestamp(), default_audio_duration); | 324 ASSERT_NE(kNoTimestamp(), default_audio_duration); |
282 ASSERT_NE(kNoTimestamp(), default_video_duration); | 325 ASSERT_NE(kNoTimestamp(), default_video_duration); |
283 | 326 |
284 parser_.reset(new WebMClusterParser( | 327 parser_.reset(CreateParser(default_audio_duration, default_video_duration)); |
285 kTimecodeScale, kAudioTrackNum, default_audio_duration, kVideoTrackNum, | |
286 default_video_duration, TextTracks(), std::set<int64>(), std::string(), | |
287 std::string(), kUnknownAudioCodec, new MediaLog())); | |
288 } | 328 } |
289 | 329 |
290 scoped_ptr<WebMClusterParser> parser_; | 330 scoped_ptr<WebMClusterParser> parser_; |
291 | 331 |
292 private: | 332 private: |
293 DISALLOW_COPY_AND_ASSIGN(WebMClusterParserTest); | 333 DISALLOW_COPY_AND_ASSIGN(WebMClusterParserTest); |
294 }; | 334 }; |
295 | 335 |
296 TEST_F(WebMClusterParserTest, HeldBackBufferHoldsBackAllTracks) { | 336 TEST_F(WebMClusterParserTest, HeldBackBufferHoldsBackAllTracks) { |
297 // If a buffer is missing duration and is being held back, then all other | 337 // If a buffer is missing duration and is being held back, then all other |
298 // tracks' buffers that have same or higher (decode) timestamp should be held | 338 // tracks' buffers that have same or higher (decode) timestamp should be held |
299 // back too to keep the timestamps emitted for a cluster monotonically | 339 // back too to keep the timestamps emitted for a cluster monotonically |
300 // non-decreasing and in same order as parsed. | 340 // non-decreasing and in same order as parsed. |
301 InSequence s; | 341 InSequence s; |
302 | 342 |
303 // Reset the parser to have 3 tracks: text, video (no default frame duration), | 343 // Reset the parser to have 3 tracks: text, video (no default frame duration), |
304 // and audio (with a default frame duration). | 344 // and audio (with a default frame duration). |
305 TextTracks text_tracks; | 345 TextTracks text_tracks; |
306 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), | 346 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), |
307 TextTrackConfig(kTextSubtitles, "", "", | 347 TextTrackConfig(kTextSubtitles, "", "", |
308 ""))); | 348 ""))); |
309 base::TimeDelta default_audio_duration = | 349 base::TimeDelta default_audio_duration = |
310 base::TimeDelta::FromMilliseconds(kTestAudioFrameDefaultDurationInMs); | 350 base::TimeDelta::FromMilliseconds(kTestAudioFrameDefaultDurationInMs); |
311 ASSERT_GE(default_audio_duration, base::TimeDelta()); | 351 ASSERT_GE(default_audio_duration, base::TimeDelta()); |
312 ASSERT_NE(kNoTimestamp(), default_audio_duration); | 352 ASSERT_NE(kNoTimestamp(), default_audio_duration); |
313 parser_.reset(new WebMClusterParser( | 353 parser_.reset( |
314 kTimecodeScale, kAudioTrackNum, default_audio_duration, kVideoTrackNum, | 354 CreateParser(default_audio_duration, kNoTimestamp(), text_tracks)); |
315 kNoTimestamp(), text_tracks, std::set<int64>(), std::string(), | |
316 std::string(), kUnknownAudioCodec, new MediaLog())); | |
317 | 355 |
318 const BlockInfo kBlockInfo[] = { | 356 const BlockInfo kBlockInfo[] = { |
319 {kVideoTrackNum, 0, 33, true, NULL, 0}, | 357 {kVideoTrackNum, 0, 33, true, NULL, 0}, |
320 {kAudioTrackNum, 0, 23, false, NULL, 0}, | 358 {kAudioTrackNum, 0, 23, false, NULL, 0}, |
321 {kTextTrackNum, 10, 42, false, NULL, 0}, | 359 {kTextTrackNum, 10, 42, false, NULL, 0}, |
322 {kAudioTrackNum, 23, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, | 360 {kAudioTrackNum, 23, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
323 {kVideoTrackNum, 33, 33, true, NULL, 0}, | 361 {kVideoTrackNum, 33, 33, true, NULL, 0}, |
324 {kAudioTrackNum, 36, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, | 362 {kAudioTrackNum, 36, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
325 {kVideoTrackNum, 66, 33, true, NULL, 0}, | 363 {kVideoTrackNum, 66, 33, true, NULL, 0}, |
326 {kAudioTrackNum, 70, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, | 364 {kAudioTrackNum, 70, kTestAudioFrameDefaultDurationInMs, true, NULL, 0}, |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
489 | 527 |
490 int result = parser_->Parse(cluster->data(), cluster->size()); | 528 int result = parser_->Parse(cluster->data(), cluster->size()); |
491 EXPECT_EQ(cluster->size(), result); | 529 EXPECT_EQ(cluster->size(), result); |
492 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | 530 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); |
493 } | 531 } |
494 | 532 |
495 TEST_F(WebMClusterParserTest, IgnoredTracks) { | 533 TEST_F(WebMClusterParserTest, IgnoredTracks) { |
496 std::set<int64> ignored_tracks; | 534 std::set<int64> ignored_tracks; |
497 ignored_tracks.insert(kTextTrackNum); | 535 ignored_tracks.insert(kTextTrackNum); |
498 | 536 |
499 parser_.reset(new WebMClusterParser( | 537 parser_.reset(CreateParser(ignored_tracks)); |
500 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, | |
501 kNoTimestamp(), TextTracks(), ignored_tracks, std::string(), | |
502 std::string(), kUnknownAudioCodec, new MediaLog())); | |
503 | 538 |
504 const BlockInfo kInputBlockInfo[] = { | 539 const BlockInfo kInputBlockInfo[] = { |
505 {kAudioTrackNum, 0, 23, true, NULL, 0}, | 540 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
506 {kAudioTrackNum, 23, 23, true, NULL, 0}, | 541 {kAudioTrackNum, 23, 23, true, NULL, 0}, |
507 {kVideoTrackNum, 33, 34, true, NULL, 0}, | 542 {kVideoTrackNum, 33, 34, true, NULL, 0}, |
508 {kTextTrackNum, 33, 99, true, NULL, 0}, | 543 {kTextTrackNum, 33, 99, true, NULL, 0}, |
509 {kAudioTrackNum, 46, 23, true, NULL, 0}, | 544 {kAudioTrackNum, 46, 23, true, NULL, 0}, |
510 {kVideoTrackNum, 67, 34, true, NULL, 0}, | 545 {kVideoTrackNum, 67, 34, true, NULL, 0}, |
511 }; | 546 }; |
512 int input_block_count = arraysize(kInputBlockInfo); | 547 int input_block_count = arraysize(kInputBlockInfo); |
(...skipping 15 matching lines...) Expand all Loading... | |
528 ASSERT_TRUE(VerifyBuffers(parser_, kOutputBlockInfo, output_block_count)); | 563 ASSERT_TRUE(VerifyBuffers(parser_, kOutputBlockInfo, output_block_count)); |
529 } | 564 } |
530 | 565 |
531 TEST_F(WebMClusterParserTest, ParseTextTracks) { | 566 TEST_F(WebMClusterParserTest, ParseTextTracks) { |
532 TextTracks text_tracks; | 567 TextTracks text_tracks; |
533 | 568 |
534 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), | 569 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), |
535 TextTrackConfig(kTextSubtitles, "", "", | 570 TextTrackConfig(kTextSubtitles, "", "", |
536 ""))); | 571 ""))); |
537 | 572 |
538 parser_.reset(new WebMClusterParser( | 573 parser_.reset(CreateParser(kNoTimestamp(), kNoTimestamp(), text_tracks)); |
539 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, | |
540 kNoTimestamp(), text_tracks, std::set<int64>(), std::string(), | |
541 std::string(), kUnknownAudioCodec, new MediaLog())); | |
542 | 574 |
543 const BlockInfo kInputBlockInfo[] = { | 575 const BlockInfo kInputBlockInfo[] = { |
544 {kAudioTrackNum, 0, 23, true, NULL, 0}, | 576 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
545 {kAudioTrackNum, 23, 23, true, NULL, 0}, | 577 {kAudioTrackNum, 23, 23, true, NULL, 0}, |
546 {kVideoTrackNum, 33, 34, true, NULL, 0}, | 578 {kVideoTrackNum, 33, 34, true, NULL, 0}, |
547 {kTextTrackNum, 33, 42, false, NULL, 0}, | 579 {kTextTrackNum, 33, 42, false, NULL, 0}, |
548 {kAudioTrackNum, 46, 23, true, NULL, 0}, | 580 {kAudioTrackNum, 46, 23, true, NULL, 0}, |
549 {kTextTrackNum, 55, 44, false, NULL, 0}, | 581 {kTextTrackNum, 55, 44, false, NULL, 0}, |
550 {kVideoTrackNum, 67, 34, true, NULL, 0}, | 582 {kVideoTrackNum, 67, 34, true, NULL, 0}, |
551 }; | 583 }; |
552 int input_block_count = arraysize(kInputBlockInfo); | 584 int input_block_count = arraysize(kInputBlockInfo); |
553 | 585 |
554 scoped_ptr<Cluster> cluster( | 586 scoped_ptr<Cluster> cluster( |
555 CreateCluster(0, kInputBlockInfo, input_block_count)); | 587 CreateCluster(0, kInputBlockInfo, input_block_count)); |
556 | 588 |
557 int result = parser_->Parse(cluster->data(), cluster->size()); | 589 int result = parser_->Parse(cluster->data(), cluster->size()); |
558 EXPECT_EQ(cluster->size(), result); | 590 EXPECT_EQ(cluster->size(), result); |
559 ASSERT_TRUE(VerifyBuffers(parser_, kInputBlockInfo, input_block_count)); | 591 ASSERT_TRUE(VerifyBuffers(parser_, kInputBlockInfo, input_block_count)); |
560 } | 592 } |
561 | 593 |
562 TEST_F(WebMClusterParserTest, TextTracksSimpleBlock) { | 594 TEST_F(WebMClusterParserTest, TextTracksSimpleBlock) { |
563 TextTracks text_tracks; | 595 TextTracks text_tracks; |
564 | 596 |
565 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), | 597 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), |
566 TextTrackConfig(kTextSubtitles, "", "", | 598 TextTrackConfig(kTextSubtitles, "", "", |
567 ""))); | 599 ""))); |
568 | 600 |
569 parser_.reset(new WebMClusterParser( | 601 parser_.reset(CreateParser(kNoTimestamp(), kNoTimestamp(), text_tracks)); |
570 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, | |
571 kNoTimestamp(), text_tracks, std::set<int64>(), std::string(), | |
572 std::string(), kUnknownAudioCodec, new MediaLog())); | |
573 | 602 |
574 const BlockInfo kInputBlockInfo[] = { | 603 const BlockInfo kInputBlockInfo[] = { |
575 { kTextTrackNum, 33, 42, true }, | 604 { kTextTrackNum, 33, 42, true }, |
576 }; | 605 }; |
577 int input_block_count = arraysize(kInputBlockInfo); | 606 int input_block_count = arraysize(kInputBlockInfo); |
578 | 607 |
579 scoped_ptr<Cluster> cluster( | 608 scoped_ptr<Cluster> cluster( |
580 CreateCluster(0, kInputBlockInfo, input_block_count)); | 609 CreateCluster(0, kInputBlockInfo, input_block_count)); |
581 | 610 |
582 int result = parser_->Parse(cluster->data(), cluster->size()); | 611 int result = parser_->Parse(cluster->data(), cluster->size()); |
583 EXPECT_LT(result, 0); | 612 EXPECT_LT(result, 0); |
584 } | 613 } |
585 | 614 |
586 TEST_F(WebMClusterParserTest, ParseMultipleTextTracks) { | 615 TEST_F(WebMClusterParserTest, ParseMultipleTextTracks) { |
587 TextTracks text_tracks; | 616 TextTracks text_tracks; |
588 | 617 |
589 const int kSubtitleTextTrackNum = kTextTrackNum; | 618 const int kSubtitleTextTrackNum = kTextTrackNum; |
590 const int kCaptionTextTrackNum = kTextTrackNum + 1; | 619 const int kCaptionTextTrackNum = kTextTrackNum + 1; |
591 | 620 |
592 text_tracks.insert(std::make_pair(TextTracks::key_type(kSubtitleTextTrackNum), | 621 text_tracks.insert(std::make_pair(TextTracks::key_type(kSubtitleTextTrackNum), |
593 TextTrackConfig(kTextSubtitles, "", "", | 622 TextTrackConfig(kTextSubtitles, "", "", |
594 ""))); | 623 ""))); |
595 | 624 |
596 text_tracks.insert(std::make_pair(TextTracks::key_type(kCaptionTextTrackNum), | 625 text_tracks.insert(std::make_pair(TextTracks::key_type(kCaptionTextTrackNum), |
597 TextTrackConfig(kTextCaptions, "", "", | 626 TextTrackConfig(kTextCaptions, "", "", |
598 ""))); | 627 ""))); |
599 | 628 |
600 parser_.reset(new WebMClusterParser( | 629 parser_.reset(CreateParser(kNoTimestamp(), kNoTimestamp(), text_tracks)); |
601 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, | |
602 kNoTimestamp(), text_tracks, std::set<int64>(), std::string(), | |
603 std::string(), kUnknownAudioCodec, new MediaLog())); | |
604 | 630 |
605 const BlockInfo kInputBlockInfo[] = { | 631 const BlockInfo kInputBlockInfo[] = { |
606 {kAudioTrackNum, 0, 23, true, NULL, 0}, | 632 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
607 {kAudioTrackNum, 23, 23, true, NULL, 0}, | 633 {kAudioTrackNum, 23, 23, true, NULL, 0}, |
608 {kVideoTrackNum, 33, 34, true, NULL, 0}, | 634 {kVideoTrackNum, 33, 34, true, NULL, 0}, |
609 {kSubtitleTextTrackNum, 33, 42, false, NULL, 0}, | 635 {kSubtitleTextTrackNum, 33, 42, false, NULL, 0}, |
610 {kAudioTrackNum, 46, 23, true, NULL, 0}, | 636 {kAudioTrackNum, 46, 23, true, NULL, 0}, |
611 {kCaptionTextTrackNum, 55, 44, false, NULL, 0}, | 637 {kCaptionTextTrackNum, 55, 44, false, NULL, 0}, |
612 {kVideoTrackNum, 67, 34, true, NULL, 0}, | 638 {kVideoTrackNum, 67, 34, true, NULL, 0}, |
613 {kSubtitleTextTrackNum, 67, 33, false, NULL, 0}, | 639 {kSubtitleTextTrackNum, 67, 33, false, NULL, 0}, |
(...skipping 16 matching lines...) Expand all Loading... | |
630 text_tracks.find(itr->first); | 656 text_tracks.find(itr->first); |
631 ASSERT_TRUE(find_result != text_tracks.end()); | 657 ASSERT_TRUE(find_result != text_tracks.end()); |
632 ASSERT_TRUE(VerifyTextBuffers(parser_, kInputBlockInfo, input_block_count, | 658 ASSERT_TRUE(VerifyTextBuffers(parser_, kInputBlockInfo, input_block_count, |
633 itr->first, itr->second)); | 659 itr->first, itr->second)); |
634 } | 660 } |
635 } | 661 } |
636 | 662 |
637 TEST_F(WebMClusterParserTest, ParseEncryptedBlock) { | 663 TEST_F(WebMClusterParserTest, ParseEncryptedBlock) { |
638 scoped_ptr<Cluster> cluster(CreateEncryptedCluster(sizeof(kEncryptedFrame))); | 664 scoped_ptr<Cluster> cluster(CreateEncryptedCluster(sizeof(kEncryptedFrame))); |
639 | 665 |
640 parser_.reset(new WebMClusterParser( | 666 parser_.reset( |
641 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, | 667 CreateParser(std::string(), "video_key_id", kUnknownAudioCodec)); |
642 kNoTimestamp(), TextTracks(), std::set<int64>(), std::string(), | |
643 "video_key_id", kUnknownAudioCodec, new MediaLog())); | |
644 int result = parser_->Parse(cluster->data(), cluster->size()); | 668 int result = parser_->Parse(cluster->data(), cluster->size()); |
645 EXPECT_EQ(cluster->size(), result); | 669 EXPECT_EQ(cluster->size(), result); |
646 ASSERT_EQ(1UL, parser_->GetVideoBuffers().size()); | 670 ASSERT_EQ(1UL, parser_->GetVideoBuffers().size()); |
647 scoped_refptr<StreamParserBuffer> buffer = parser_->GetVideoBuffers()[0]; | 671 scoped_refptr<StreamParserBuffer> buffer = parser_->GetVideoBuffers()[0]; |
648 VerifyEncryptedBuffer(buffer); | 672 VerifyEncryptedBuffer(buffer); |
649 } | 673 } |
650 | 674 |
651 TEST_F(WebMClusterParserTest, ParseBadEncryptedBlock) { | 675 TEST_F(WebMClusterParserTest, ParseBadEncryptedBlock) { |
652 scoped_ptr<Cluster> cluster( | 676 scoped_ptr<Cluster> cluster( |
653 CreateEncryptedCluster(sizeof(kEncryptedFrame) - 1)); | 677 CreateEncryptedCluster(sizeof(kEncryptedFrame) - 1)); |
654 | 678 |
655 parser_.reset(new WebMClusterParser( | 679 parser_.reset( |
656 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, | 680 CreateParser(std::string(), "video_key_id", kUnknownAudioCodec)); |
657 kNoTimestamp(), TextTracks(), std::set<int64>(), std::string(), | |
658 "video_key_id", kUnknownAudioCodec, new MediaLog())); | |
659 int result = parser_->Parse(cluster->data(), cluster->size()); | 681 int result = parser_->Parse(cluster->data(), cluster->size()); |
660 EXPECT_EQ(-1, result); | 682 EXPECT_EQ(-1, result); |
661 } | 683 } |
662 | 684 |
663 TEST_F(WebMClusterParserTest, ParseInvalidZeroSizedCluster) { | 685 TEST_F(WebMClusterParserTest, ParseInvalidZeroSizedCluster) { |
664 const uint8_t kBuffer[] = { | 686 const uint8_t kBuffer[] = { |
665 0x1F, 0x43, 0xB6, 0x75, 0x80, // CLUSTER (size = 0) | 687 0x1F, 0x43, 0xB6, 0x75, 0x80, // CLUSTER (size = 0) |
666 }; | 688 }; |
667 | 689 |
668 EXPECT_EQ(-1, parser_->Parse(kBuffer, sizeof(kBuffer))); | 690 EXPECT_EQ(-1, parser_->Parse(kBuffer, sizeof(kBuffer))); |
669 } | 691 } |
670 | 692 |
671 TEST_F(WebMClusterParserTest, ParseInvalidUnknownButActuallyZeroSizedCluster) { | 693 TEST_F(WebMClusterParserTest, ParseInvalidUnknownButActuallyZeroSizedCluster) { |
672 const uint8_t kBuffer[] = { | 694 const uint8_t kBuffer[] = { |
673 0x1F, 0x43, 0xB6, 0x75, 0xFF, // CLUSTER (size = "unknown") | 695 0x1F, 0x43, 0xB6, 0x75, 0xFF, // CLUSTER (size = "unknown") |
674 0x1F, 0x43, 0xB6, 0x75, 0x85, // CLUSTER (size = 5) | 696 0x1F, 0x43, 0xB6, 0x75, 0x85, // CLUSTER (size = 5) |
675 }; | 697 }; |
676 | 698 |
677 EXPECT_EQ(-1, parser_->Parse(kBuffer, sizeof(kBuffer))); | 699 EXPECT_EQ(-1, parser_->Parse(kBuffer, sizeof(kBuffer))); |
678 } | 700 } |
679 | 701 |
680 TEST_F(WebMClusterParserTest, ParseInvalidTextBlockGroupWithoutDuration) { | 702 TEST_F(WebMClusterParserTest, ParseInvalidTextBlockGroupWithoutDuration) { |
681 // Text track frames must have explicitly specified BlockGroup BlockDurations. | 703 // Text track frames must have explicitly specified BlockGroup BlockDurations. |
682 TextTracks text_tracks; | 704 TextTracks text_tracks; |
683 | 705 |
684 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), | 706 text_tracks.insert(std::make_pair(TextTracks::key_type(kTextTrackNum), |
685 TextTrackConfig(kTextSubtitles, "", "", | 707 TextTrackConfig(kTextSubtitles, "", "", |
686 ""))); | 708 ""))); |
687 | 709 |
688 parser_.reset(new WebMClusterParser( | 710 parser_.reset(CreateParser(kNoTimestamp(), kNoTimestamp(), text_tracks)); |
689 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, | |
690 kNoTimestamp(), text_tracks, std::set<int64>(), std::string(), | |
691 std::string(), kUnknownAudioCodec, new MediaLog())); | |
692 | 711 |
693 const BlockInfo kBlockInfo[] = { | 712 const BlockInfo kBlockInfo[] = { |
694 { kTextTrackNum, 33, -42, false }, | 713 { kTextTrackNum, 33, -42, false }, |
695 }; | 714 }; |
696 int block_count = arraysize(kBlockInfo); | 715 int block_count = arraysize(kBlockInfo); |
697 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 716 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
698 int result = parser_->Parse(cluster->data(), cluster->size()); | 717 int result = parser_->Parse(cluster->data(), cluster->size()); |
699 EXPECT_LT(result, 0); | 718 EXPECT_LT(result, 0); |
700 } | 719 } |
701 | 720 |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
929 | 948 |
930 int block_count = arraysize(kBlockInfo); | 949 int block_count = arraysize(kBlockInfo); |
931 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 950 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
932 int result = parser_->Parse(cluster->data(), cluster->size()); | 951 int result = parser_->Parse(cluster->data(), cluster->size()); |
933 EXPECT_EQ(cluster->size(), result); | 952 EXPECT_EQ(cluster->size(), result); |
934 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | 953 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); |
935 } | 954 } |
936 | 955 |
937 TEST_F(WebMClusterParserTest, ReadOpusDurationsSimpleBlockAtEndOfCluster) { | 956 TEST_F(WebMClusterParserTest, ReadOpusDurationsSimpleBlockAtEndOfCluster) { |
938 // Reset parser to expect Opus codec audio. | 957 // Reset parser to expect Opus codec audio. |
939 parser_.reset(new WebMClusterParser( | 958 parser_.reset(CreateParser(std::string(), std::string(), kCodecOpus)); |
940 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, | |
941 kNoTimestamp(), TextTracks(), std::set<int64>(), std::string(), | |
942 std::string(), kCodecOpus, new MediaLog())); | |
943 | 959 |
944 int loop_count = 0; | 960 int loop_count = 0; |
945 for (const auto* packet_ptr : BuildAllOpusPackets()) { | 961 for (const auto* packet_ptr : BuildAllOpusPackets()) { |
946 const BlockInfo kBlockInfo[] = {{kAudioTrackNum, | 962 const BlockInfo kBlockInfo[] = {{kAudioTrackNum, |
947 0, | 963 0, |
948 packet_ptr->duration_ms(), | 964 packet_ptr->duration_ms(), |
949 true, // Make it a SimpleBlock. | 965 true, // Make it a SimpleBlock. |
950 packet_ptr->data(), | 966 packet_ptr->data(), |
951 packet_ptr->size()}}; | 967 packet_ptr->size()}}; |
952 | 968 |
953 int block_count = arraysize(kBlockInfo); | 969 int block_count = arraysize(kBlockInfo); |
954 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 970 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
955 int result = parser_->Parse(cluster->data(), cluster->size()); | 971 int result = parser_->Parse(cluster->data(), cluster->size()); |
956 EXPECT_EQ(cluster->size(), result); | 972 EXPECT_EQ(cluster->size(), result); |
957 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | 973 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); |
958 loop_count++; | 974 loop_count++; |
959 } | 975 } |
960 | 976 |
961 // Test should minimally cover all the combinations of config and frame count. | 977 // Test should minimally cover all the combinations of config and frame count. |
962 ASSERT_GE(loop_count, kNumPossibleOpusConfigs * kMaxOpusPacketFrameCount); | 978 ASSERT_GE(loop_count, kNumPossibleOpusConfigs * kMaxOpusPacketFrameCount); |
963 } | 979 } |
964 | 980 |
965 TEST_F(WebMClusterParserTest, PreferOpusDurationsOverBlockDurations) { | 981 TEST_F(WebMClusterParserTest, PreferOpusDurationsOverBlockDurations) { |
966 // Reset parser to expect Opus codec audio. | 982 // Reset parser to expect Opus codec audio. |
967 parser_.reset(new WebMClusterParser( | 983 parser_.reset(CreateParser(std::string(), std::string(), kCodecOpus)); |
968 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, | |
969 kNoTimestamp(), TextTracks(), std::set<int64>(), std::string(), | |
970 std::string(), kCodecOpus, new MediaLog())); | |
971 | 984 |
972 int loop_count = 0; | 985 int loop_count = 0; |
973 for (const auto* packet_ptr : BuildAllOpusPackets()) { | 986 for (const auto* packet_ptr : BuildAllOpusPackets()) { |
974 // Setting BlockDuration != Opus duration to see which one the parser uses. | 987 // Setting BlockDuration != Opus duration to see which one the parser uses. |
975 int block_duration_ms = packet_ptr->duration_ms() + 10; | 988 int block_duration_ms = packet_ptr->duration_ms() + 10; |
976 | 989 |
977 BlockInfo block_infos[] = {{kAudioTrackNum, | 990 BlockInfo block_infos[] = {{kAudioTrackNum, |
978 0, | 991 0, |
979 block_duration_ms, | 992 block_duration_ms, |
980 false, // Not a SimpleBlock. | 993 false, // Not a SimpleBlock. |
(...skipping 18 matching lines...) Expand all Loading... | |
999 } | 1012 } |
1000 | 1013 |
1001 // Tests that BlockDuration is used to set duration on buffer rather than | 1014 // Tests that BlockDuration is used to set duration on buffer rather than |
1002 // encoded duration in Opus packet (or hard coded duration estimates). Encoded | 1015 // encoded duration in Opus packet (or hard coded duration estimates). Encoded |
1003 // Opus duration is usually preferred but cannot be known when encrypted. | 1016 // Opus duration is usually preferred but cannot be known when encrypted. |
1004 TEST_F(WebMClusterParserTest, DontReadEncodedDurationWhenEncrypted) { | 1017 TEST_F(WebMClusterParserTest, DontReadEncodedDurationWhenEncrypted) { |
1005 // Non-empty dummy value signals encryption is active for audio. | 1018 // Non-empty dummy value signals encryption is active for audio. |
1006 std::string audio_encryption_id("audio_key_id"); | 1019 std::string audio_encryption_id("audio_key_id"); |
1007 | 1020 |
1008 // Reset parser to expect Opus codec audio and use audio encryption key id. | 1021 // Reset parser to expect Opus codec audio and use audio encryption key id. |
1009 parser_.reset(new WebMClusterParser( | 1022 parser_.reset(CreateParser(audio_encryption_id, std::string(), kCodecOpus)); |
1010 kTimecodeScale, kAudioTrackNum, kNoTimestamp(), kVideoTrackNum, | |
1011 kNoTimestamp(), TextTracks(), std::set<int64>(), audio_encryption_id, | |
1012 std::string(), kCodecOpus, new MediaLog())); | |
1013 | 1023 |
1014 // Single Block with BlockDuration and encrypted data. | 1024 // Single Block with BlockDuration and encrypted data. |
1015 const BlockInfo kBlockInfo[] = {{kAudioTrackNum, | 1025 const BlockInfo kBlockInfo[] = {{kAudioTrackNum, |
1016 0, | 1026 0, |
1017 kTestAudioFrameDefaultDurationInMs, | 1027 kTestAudioFrameDefaultDurationInMs, |
1018 false, // Not a SimpleBlock | 1028 false, // Not a SimpleBlock |
1019 kEncryptedFrame, // Encrypted frame data | 1029 kEncryptedFrame, // Encrypted frame data |
1020 arraysize(kEncryptedFrame)}}; | 1030 arraysize(kEncryptedFrame)}}; |
1021 | 1031 |
1022 int block_count = arraysize(kBlockInfo); | 1032 int block_count = arraysize(kBlockInfo); |
1023 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 1033 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
1024 int result = parser_->Parse(cluster->data(), cluster->size()); | 1034 int result = parser_->Parse(cluster->data(), cluster->size()); |
1025 EXPECT_EQ(cluster->size(), result); | 1035 EXPECT_EQ(cluster->size(), result); |
1026 | 1036 |
1027 // Will verify that duration of buffer matches that of BlockDuration. | 1037 // Will verify that duration of buffer matches that of BlockDuration. |
1028 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | 1038 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); |
1029 } | 1039 } |
1030 | 1040 |
1031 } // namespace media | 1041 } // namespace media |
OLD | NEW |