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 |
| 346 // TODO(wolenetz/acolwell): Validate and use a common cross-parser TrackId |
| 347 // type with remapped bytestream track numbers and allow multiple tracks as |
| 348 // applicable. See https://crbug.com/341581. |
345 buffer = StreamParserBuffer::CopyFrom( | 349 buffer = StreamParserBuffer::CopyFrom( |
346 data + data_offset, size - data_offset, | 350 data + data_offset, size - data_offset, |
347 additional, additional_size, | 351 additional, additional_size, |
348 is_keyframe); | 352 is_keyframe, buffer_type, track_num); |
349 | 353 |
350 if (decrypt_config) | 354 if (decrypt_config) |
351 buffer->set_decrypt_config(decrypt_config.Pass()); | 355 buffer->set_decrypt_config(decrypt_config.Pass()); |
352 } else { | 356 } else { |
353 std::string id, settings, content; | 357 std::string id, settings, content; |
354 WebMWebVTTParser::Parse(data, size, &id, &settings, &content); | 358 WebMWebVTTParser::Parse(data, size, &id, &settings, &content); |
355 | 359 |
356 std::vector<uint8> side_data; | 360 std::vector<uint8> side_data; |
357 MakeSideData(id.begin(), id.end(), | 361 MakeSideData(id.begin(), id.end(), |
358 settings.begin(), settings.end(), | 362 settings.begin(), settings.end(), |
359 &side_data); | 363 &side_data); |
360 | 364 |
| 365 // TODO(wolenetz/acolwell): Validate and use a common cross-parser TrackId |
| 366 // type with remapped bytestream track numbers and allow multiple tracks as |
| 367 // applicable. See https://crbug.com/341581. |
361 buffer = StreamParserBuffer::CopyFrom( | 368 buffer = StreamParserBuffer::CopyFrom( |
362 reinterpret_cast<const uint8*>(content.data()), | 369 reinterpret_cast<const uint8*>(content.data()), |
363 content.length(), | 370 content.length(), |
364 &side_data[0], | 371 &side_data[0], |
365 side_data.size(), | 372 side_data.size(), |
366 true); | 373 true, buffer_type, track_num); |
367 } | 374 } |
368 | 375 |
369 buffer->set_timestamp(timestamp); | 376 buffer->set_timestamp(timestamp); |
370 if (cluster_start_time_ == kNoTimestamp()) | 377 if (cluster_start_time_ == kNoTimestamp()) |
371 cluster_start_time_ = timestamp; | 378 cluster_start_time_ = timestamp; |
372 | 379 |
373 if (block_duration >= 0) { | 380 if (block_duration >= 0) { |
374 buffer->set_duration(base::TimeDelta::FromMicroseconds( | 381 buffer->set_duration(base::TimeDelta::FromMicroseconds( |
375 block_duration * timecode_multiplier_)); | 382 block_duration * timecode_multiplier_)); |
376 } | 383 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 WebMClusterParser::FindTextTrack(int track_num) { | 449 WebMClusterParser::FindTextTrack(int track_num) { |
443 const TextTrackMap::iterator it = text_track_map_.find(track_num); | 450 const TextTrackMap::iterator it = text_track_map_.find(track_num); |
444 | 451 |
445 if (it == text_track_map_.end()) | 452 if (it == text_track_map_.end()) |
446 return NULL; | 453 return NULL; |
447 | 454 |
448 return &it->second; | 455 return &it->second; |
449 } | 456 } |
450 | 457 |
451 } // namespace media | 458 } // namespace media |
OLD | NEW |