| 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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 return false; | 285 return false; |
| 286 } | 286 } |
| 287 | 287 |
| 288 if (last_block_timecode_ != -1 && timecode < last_block_timecode_) { | 288 if (last_block_timecode_ != -1 && timecode < last_block_timecode_) { |
| 289 MEDIA_LOG(log_cb_) | 289 MEDIA_LOG(log_cb_) |
| 290 << "Got a block with a timecode before the previous block."; | 290 << "Got a block with a timecode before the previous block."; |
| 291 return false; | 291 return false; |
| 292 } | 292 } |
| 293 | 293 |
| 294 Track* track = NULL; | 294 Track* track = NULL; |
| 295 bool is_text = false; | 295 StreamParserBuffer::Type buffer_type = DemuxerStream::AUDIO; |
| 296 std::string encryption_key_id; | 296 std::string encryption_key_id; |
| 297 if (track_num == audio_.track_num()) { | 297 if (track_num == audio_.track_num()) { |
| 298 track = &audio_; | 298 track = &audio_; |
| 299 encryption_key_id = audio_encryption_key_id_; | 299 encryption_key_id = audio_encryption_key_id_; |
| 300 } else if (track_num == video_.track_num()) { | 300 } else if (track_num == video_.track_num()) { |
| 301 track = &video_; | 301 track = &video_; |
| 302 encryption_key_id = video_encryption_key_id_; | 302 encryption_key_id = video_encryption_key_id_; |
| 303 buffer_type = DemuxerStream::VIDEO; |
| 303 } else if (ignored_tracks_.find(track_num) != ignored_tracks_.end()) { | 304 } else if (ignored_tracks_.find(track_num) != ignored_tracks_.end()) { |
| 304 return true; | 305 return true; |
| 305 } else if (Track* const text_track = FindTextTrack(track_num)) { | 306 } else if (Track* const text_track = FindTextTrack(track_num)) { |
| 306 if (is_simple_block) // BlockGroup is required for WebVTT cues | 307 if (is_simple_block) // BlockGroup is required for WebVTT cues |
| 307 return false; | 308 return false; |
| 308 if (block_duration < 0) // not specified | 309 if (block_duration < 0) // not specified |
| 309 return false; | 310 return false; |
| 310 track = text_track; | 311 track = text_track; |
| 311 is_text = true; | 312 buffer_type = DemuxerStream::TEXT; |
| 312 } else { | 313 } else { |
| 313 MEDIA_LOG(log_cb_) << "Unexpected track number " << track_num; | 314 MEDIA_LOG(log_cb_) << "Unexpected track number " << track_num; |
| 314 return false; | 315 return false; |
| 315 } | 316 } |
| 316 | 317 |
| 317 last_block_timecode_ = timecode; | 318 last_block_timecode_ = timecode; |
| 318 | 319 |
| 319 base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds( | 320 base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds( |
| 320 (cluster_timecode_ + timecode) * timecode_multiplier_); | 321 (cluster_timecode_ + timecode) * timecode_multiplier_); |
| 321 | 322 |
| 322 scoped_refptr<StreamParserBuffer> buffer; | 323 scoped_refptr<StreamParserBuffer> buffer; |
| 323 if (!is_text) { | 324 if (buffer_type != DemuxerStream::TEXT) { |
| 324 // The first bit of the flags is set when a SimpleBlock contains only | 325 // The first bit of the flags is set when a SimpleBlock contains only |
| 325 // keyframes. If this is a Block, then inspection of the payload is | 326 // keyframes. If this is a Block, then inspection of the payload is |
| 326 // necessary to determine whether it contains a keyframe or not. | 327 // necessary to determine whether it contains a keyframe or not. |
| 327 // http://www.matroska.org/technical/specs/index.html | 328 // http://www.matroska.org/technical/specs/index.html |
| 328 bool is_keyframe = | 329 bool is_keyframe = |
| 329 is_simple_block ? (flags & 0x80) != 0 : track->IsKeyframe(data, size); | 330 is_simple_block ? (flags & 0x80) != 0 : track->IsKeyframe(data, size); |
| 330 | 331 |
| 331 // Every encrypted Block has a signal byte and IV prepended to it. Current | 332 // Every encrypted Block has a signal byte and IV prepended to it. Current |
| 332 // encrypted WebM request for comments specification is here | 333 // encrypted WebM request for comments specification is here |
| 333 // http://wiki.webmproject.org/encryption/webm-encryption-rfc | 334 // http://wiki.webmproject.org/encryption/webm-encryption-rfc |
| 334 scoped_ptr<DecryptConfig> decrypt_config; | 335 scoped_ptr<DecryptConfig> decrypt_config; |
| 335 int data_offset = 0; | 336 int data_offset = 0; |
| 336 if (!encryption_key_id.empty() && | 337 if (!encryption_key_id.empty() && |
| 337 !WebMCreateDecryptConfig( | 338 !WebMCreateDecryptConfig( |
| 338 data, size, | 339 data, size, |
| 339 reinterpret_cast<const uint8*>(encryption_key_id.data()), | 340 reinterpret_cast<const uint8*>(encryption_key_id.data()), |
| 340 encryption_key_id.size(), | 341 encryption_key_id.size(), |
| 341 &decrypt_config, &data_offset)) { | 342 &decrypt_config, &data_offset)) { |
| 342 return false; | 343 return false; |
| 343 } | 344 } |
| 344 | 345 |
| 345 buffer = StreamParserBuffer::CopyFrom( | 346 buffer = StreamParserBuffer::CopyFrom( |
| 346 data + data_offset, size - data_offset, | 347 data + data_offset, size - data_offset, |
| 347 additional, additional_size, | 348 additional, additional_size, |
| 348 is_keyframe); | 349 is_keyframe, buffer_type); |
| 350 buffer->set_text_track_number(track_num); |
| 349 | 351 |
| 350 if (decrypt_config) | 352 if (decrypt_config) |
| 351 buffer->set_decrypt_config(decrypt_config.Pass()); | 353 buffer->set_decrypt_config(decrypt_config.Pass()); |
| 352 } else { | 354 } else { |
| 353 std::string id, settings, content; | 355 std::string id, settings, content; |
| 354 WebMWebVTTParser::Parse(data, size, &id, &settings, &content); | 356 WebMWebVTTParser::Parse(data, size, &id, &settings, &content); |
| 355 | 357 |
| 356 std::vector<uint8> side_data; | 358 std::vector<uint8> side_data; |
| 357 MakeSideData(id.begin(), id.end(), | 359 MakeSideData(id.begin(), id.end(), |
| 358 settings.begin(), settings.end(), | 360 settings.begin(), settings.end(), |
| 359 &side_data); | 361 &side_data); |
| 360 | 362 |
| 361 buffer = StreamParserBuffer::CopyFrom( | 363 buffer = StreamParserBuffer::CopyFrom( |
| 362 reinterpret_cast<const uint8*>(content.data()), | 364 reinterpret_cast<const uint8*>(content.data()), |
| 363 content.length(), | 365 content.length(), |
| 364 &side_data[0], | 366 &side_data[0], |
| 365 side_data.size(), | 367 side_data.size(), |
| 366 true); | 368 true, buffer_type); |
| 369 buffer->set_text_track_number(track_num); |
| 367 } | 370 } |
| 368 | 371 |
| 369 buffer->set_timestamp(timestamp); | 372 buffer->set_timestamp(timestamp); |
| 370 if (cluster_start_time_ == kNoTimestamp()) | 373 if (cluster_start_time_ == kNoTimestamp()) |
| 371 cluster_start_time_ = timestamp; | 374 cluster_start_time_ = timestamp; |
| 372 | 375 |
| 373 if (block_duration >= 0) { | 376 if (block_duration >= 0) { |
| 374 buffer->set_duration(base::TimeDelta::FromMicroseconds( | 377 buffer->set_duration(base::TimeDelta::FromMicroseconds( |
| 375 block_duration * timecode_multiplier_)); | 378 block_duration * timecode_multiplier_)); |
| 376 } | 379 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 WebMClusterParser::FindTextTrack(int track_num) { | 445 WebMClusterParser::FindTextTrack(int track_num) { |
| 443 const TextTrackMap::iterator it = text_track_map_.find(track_num); | 446 const TextTrackMap::iterator it = text_track_map_.find(track_num); |
| 444 | 447 |
| 445 if (it == text_track_map_.end()) | 448 if (it == text_track_map_.end()) |
| 446 return NULL; | 449 return NULL; |
| 447 | 450 |
| 448 return &it->second; | 451 return &it->second; |
| 449 } | 452 } |
| 450 | 453 |
| 451 } // namespace media | 454 } // namespace media |
| OLD | NEW |