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 "media/formats/webm/webm_cluster_parser.h" | 5 #include "media/formats/webm/webm_cluster_parser.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/sys_byteorder.h" | 10 #include "base/sys_byteorder.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 enum { | 25 enum { |
26 // Limits the number of MEDIA_LOG() calls in the path of reading encoded | 26 // Limits the number of MEDIA_LOG() calls in the path of reading encoded |
27 // duration to avoid spamming for corrupted data. | 27 // duration to avoid spamming for corrupted data. |
28 kMaxDurationErrorLogs = 10, | 28 kMaxDurationErrorLogs = 10, |
29 // Limits the number of MEDIA_LOG() calls warning the user that buffer | 29 // Limits the number of MEDIA_LOG() calls warning the user that buffer |
30 // durations have been estimated. | 30 // durations have been estimated. |
31 kMaxDurationEstimateLogs = 10, | 31 kMaxDurationEstimateLogs = 10, |
32 }; | 32 }; |
33 | 33 |
34 WebMClusterParser::WebMClusterParser( | 34 WebMClusterParser::WebMClusterParser( |
35 int64 timecode_scale, | 35 int64_t timecode_scale, |
36 int audio_track_num, | 36 int audio_track_num, |
37 base::TimeDelta audio_default_duration, | 37 base::TimeDelta audio_default_duration, |
38 int video_track_num, | 38 int video_track_num, |
39 base::TimeDelta video_default_duration, | 39 base::TimeDelta video_default_duration, |
40 const WebMTracksParser::TextTracks& text_tracks, | 40 const WebMTracksParser::TextTracks& text_tracks, |
41 const std::set<int64>& ignored_tracks, | 41 const std::set<int64_t>& ignored_tracks, |
42 const std::string& audio_encryption_key_id, | 42 const std::string& audio_encryption_key_id, |
43 const std::string& video_encryption_key_id, | 43 const std::string& video_encryption_key_id, |
44 const AudioCodec audio_codec, | 44 const AudioCodec audio_codec, |
45 const scoped_refptr<MediaLog>& media_log) | 45 const scoped_refptr<MediaLog>& media_log) |
46 : timecode_multiplier_(timecode_scale / 1000.0), | 46 : timecode_multiplier_(timecode_scale / 1000.0), |
47 ignored_tracks_(ignored_tracks), | 47 ignored_tracks_(ignored_tracks), |
48 audio_encryption_key_id_(audio_encryption_key_id), | 48 audio_encryption_key_id_(audio_encryption_key_id), |
49 video_encryption_key_id_(video_encryption_key_id), | 49 video_encryption_key_id_(video_encryption_key_id), |
50 audio_codec_(audio_codec), | 50 audio_codec_(audio_codec), |
51 parser_(kWebMIdCluster, this), | 51 parser_(kWebMIdCluster, this), |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 block_data_size_ = -1; | 286 block_data_size_ = -1; |
287 block_duration_ = -1; | 287 block_duration_ = -1; |
288 block_add_id_ = -1; | 288 block_add_id_ = -1; |
289 block_additional_data_.reset(); | 289 block_additional_data_.reset(); |
290 block_additional_data_size_ = 0; | 290 block_additional_data_size_ = 0; |
291 discard_padding_ = -1; | 291 discard_padding_ = -1; |
292 discard_padding_set_ = false; | 292 discard_padding_set_ = false; |
293 return result; | 293 return result; |
294 } | 294 } |
295 | 295 |
296 bool WebMClusterParser::OnUInt(int id, int64 val) { | 296 bool WebMClusterParser::OnUInt(int id, int64_t val) { |
297 int64* dst; | 297 int64_t* dst; |
298 switch (id) { | 298 switch (id) { |
299 case kWebMIdTimecode: | 299 case kWebMIdTimecode: |
300 dst = &cluster_timecode_; | 300 dst = &cluster_timecode_; |
301 break; | 301 break; |
302 case kWebMIdBlockDuration: | 302 case kWebMIdBlockDuration: |
303 dst = &block_duration_; | 303 dst = &block_duration_; |
304 break; | 304 break; |
305 case kWebMIdBlockAddID: | 305 case kWebMIdBlockAddID: |
306 dst = &block_add_id_; | 306 dst = &block_add_id_; |
307 break; | 307 break; |
308 default: | 308 default: |
309 return true; | 309 return true; |
310 } | 310 } |
311 if (*dst != -1) | 311 if (*dst != -1) |
312 return false; | 312 return false; |
313 *dst = val; | 313 *dst = val; |
314 return true; | 314 return true; |
315 } | 315 } |
316 | 316 |
317 bool WebMClusterParser::ParseBlock(bool is_simple_block, | 317 bool WebMClusterParser::ParseBlock(bool is_simple_block, |
318 const uint8_t* buf, | 318 const uint8_t* buf, |
319 int size, | 319 int size, |
320 const uint8_t* additional, | 320 const uint8_t* additional, |
321 int additional_size, | 321 int additional_size, |
322 int duration, | 322 int duration, |
323 int64 discard_padding) { | 323 int64_t discard_padding) { |
324 if (size < 4) | 324 if (size < 4) |
325 return false; | 325 return false; |
326 | 326 |
327 // Return an error if the trackNum > 127. We just aren't | 327 // Return an error if the trackNum > 127. We just aren't |
328 // going to support large track numbers right now. | 328 // going to support large track numbers right now. |
329 if (!(buf[0] & 0x80)) { | 329 if (!(buf[0] & 0x80)) { |
330 MEDIA_LOG(ERROR, media_log_) << "TrackNumber over 127 not supported"; | 330 MEDIA_LOG(ERROR, media_log_) << "TrackNumber over 127 not supported"; |
331 return false; | 331 return false; |
332 } | 332 } |
333 | 333 |
(...skipping 30 matching lines...) Expand all Loading... |
364 << "More than 1 Block in a BlockGroup is not " | 364 << "More than 1 Block in a BlockGroup is not " |
365 "supported."; | 365 "supported."; |
366 return false; | 366 return false; |
367 } | 367 } |
368 block_data_.reset(new uint8_t[size]); | 368 block_data_.reset(new uint8_t[size]); |
369 memcpy(block_data_.get(), data, size); | 369 memcpy(block_data_.get(), data, size); |
370 block_data_size_ = size; | 370 block_data_size_ = size; |
371 return true; | 371 return true; |
372 | 372 |
373 case kWebMIdBlockAdditional: { | 373 case kWebMIdBlockAdditional: { |
374 uint64 block_add_id = base::HostToNet64(block_add_id_); | 374 uint64_t block_add_id = base::HostToNet64(block_add_id_); |
375 if (block_additional_data_) { | 375 if (block_additional_data_) { |
376 // TODO(vigneshv): Technically, more than 1 BlockAdditional is allowed | 376 // TODO(vigneshv): Technically, more than 1 BlockAdditional is allowed |
377 // as per matroska spec. But for now we don't have a use case to | 377 // as per matroska spec. But for now we don't have a use case to |
378 // support parsing of such files. Take a look at this again when such a | 378 // support parsing of such files. Take a look at this again when such a |
379 // case arises. | 379 // case arises. |
380 MEDIA_LOG(ERROR, media_log_) << "More than 1 BlockAdditional in a " | 380 MEDIA_LOG(ERROR, media_log_) << "More than 1 BlockAdditional in a " |
381 "BlockGroup is not supported."; | 381 "BlockGroup is not supported."; |
382 return false; | 382 return false; |
383 } | 383 } |
384 // First 8 bytes of side_data in DecoderBuffer is the BlockAddID | 384 // First 8 bytes of side_data in DecoderBuffer is the BlockAddID |
385 // element's value in Big Endian format. This is done to mimic ffmpeg | 385 // element's value in Big Endian format. This is done to mimic ffmpeg |
386 // demuxer's behavior. | 386 // demuxer's behavior. |
387 block_additional_data_size_ = size + sizeof(block_add_id); | 387 block_additional_data_size_ = size + sizeof(block_add_id); |
388 block_additional_data_.reset(new uint8_t[block_additional_data_size_]); | 388 block_additional_data_.reset(new uint8_t[block_additional_data_size_]); |
389 memcpy(block_additional_data_.get(), &block_add_id, | 389 memcpy(block_additional_data_.get(), &block_add_id, |
390 sizeof(block_add_id)); | 390 sizeof(block_add_id)); |
391 memcpy(block_additional_data_.get() + 8, data, size); | 391 memcpy(block_additional_data_.get() + 8, data, size); |
392 return true; | 392 return true; |
393 } | 393 } |
394 case kWebMIdDiscardPadding: { | 394 case kWebMIdDiscardPadding: { |
395 if (discard_padding_set_ || size <= 0 || size > 8) | 395 if (discard_padding_set_ || size <= 0 || size > 8) |
396 return false; | 396 return false; |
397 discard_padding_set_ = true; | 397 discard_padding_set_ = true; |
398 | 398 |
399 // Read in the big-endian integer. | 399 // Read in the big-endian integer. |
400 discard_padding_ = static_cast<int8>(data[0]); | 400 discard_padding_ = static_cast<int8_t>(data[0]); |
401 for (int i = 1; i < size; ++i) | 401 for (int i = 1; i < size; ++i) |
402 discard_padding_ = (discard_padding_ << 8) | data[i]; | 402 discard_padding_ = (discard_padding_ << 8) | data[i]; |
403 | 403 |
404 return true; | 404 return true; |
405 } | 405 } |
406 default: | 406 default: |
407 return true; | 407 return true; |
408 } | 408 } |
409 } | 409 } |
410 | 410 |
411 bool WebMClusterParser::OnBlock(bool is_simple_block, | 411 bool WebMClusterParser::OnBlock(bool is_simple_block, |
412 int track_num, | 412 int track_num, |
413 int timecode, | 413 int timecode, |
414 int block_duration, | 414 int block_duration, |
415 int flags, | 415 int flags, |
416 const uint8_t* data, | 416 const uint8_t* data, |
417 int size, | 417 int size, |
418 const uint8_t* additional, | 418 const uint8_t* additional, |
419 int additional_size, | 419 int additional_size, |
420 int64 discard_padding) { | 420 int64_t discard_padding) { |
421 DCHECK_GE(size, 0); | 421 DCHECK_GE(size, 0); |
422 if (cluster_timecode_ == -1) { | 422 if (cluster_timecode_ == -1) { |
423 MEDIA_LOG(ERROR, media_log_) << "Got a block before cluster timecode."; | 423 MEDIA_LOG(ERROR, media_log_) << "Got a block before cluster timecode."; |
424 return false; | 424 return false; |
425 } | 425 } |
426 | 426 |
427 // TODO(acolwell): Should relative negative timecode offsets be rejected? Or | 427 // TODO(acolwell): Should relative negative timecode offsets be rejected? Or |
428 // only when the absolute timecode is negative? See http://crbug.com/271794 | 428 // only when the absolute timecode is negative? See http://crbug.com/271794 |
429 if (timecode < 0) { | 429 if (timecode < 0) { |
430 MEDIA_LOG(ERROR, media_log_) << "Got a block with negative timecode offset " | 430 MEDIA_LOG(ERROR, media_log_) << "Got a block with negative timecode offset " |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 WebMClusterParser::FindTextTrack(int track_num) { | 873 WebMClusterParser::FindTextTrack(int track_num) { |
874 const TextTrackMap::iterator it = text_track_map_.find(track_num); | 874 const TextTrackMap::iterator it = text_track_map_.find(track_num); |
875 | 875 |
876 if (it == text_track_map_.end()) | 876 if (it == text_track_map_.end()) |
877 return NULL; | 877 return NULL; |
878 | 878 |
879 return &it->second; | 879 return &it->second; |
880 } | 880 } |
881 | 881 |
882 } // namespace media | 882 } // namespace media |
OLD | NEW |