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