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" |
11 #include "media/base/buffers.h" | 11 #include "media/base/buffers.h" |
12 #include "media/base/decrypt_config.h" | 12 #include "media/base/decrypt_config.h" |
13 #include "media/filters/webvtt_util.h" | 13 #include "media/filters/webvtt_util.h" |
14 #include "media/formats/webm/webm_constants.h" | 14 #include "media/formats/webm/webm_constants.h" |
15 #include "media/formats/webm/webm_crypto_helpers.h" | 15 #include "media/formats/webm/webm_crypto_helpers.h" |
16 #include "media/formats/webm/webm_webvtt_parser.h" | 16 #include "media/formats/webm/webm_webvtt_parser.h" |
17 | 17 |
18 namespace media { | 18 namespace media { |
19 | 19 |
20 WebMClusterParser::WebMClusterParser( | 20 WebMClusterParser::WebMClusterParser( |
21 int64 timecode_scale, int audio_track_num, int video_track_num, | 21 int64 timecode_scale, int audio_track_num, int video_track_num, |
xhwang
2014/02/07 00:09:56
Shall we s/track_num/track_id/ in this file?
wolenetz
2014/02/07 00:29:18
Longer term, a track configuration or buffer's tra
| |
22 const WebMTracksParser::TextTracks& text_tracks, | 22 const WebMTracksParser::TextTracks& text_tracks, |
23 const std::set<int64>& ignored_tracks, | 23 const std::set<int64>& ignored_tracks, |
24 const std::string& audio_encryption_key_id, | 24 const std::string& audio_encryption_key_id, |
25 const std::string& video_encryption_key_id, | 25 const std::string& video_encryption_key_id, |
26 const LogCB& log_cb) | 26 const LogCB& log_cb) |
27 : timecode_multiplier_(timecode_scale / 1000.0), | 27 : timecode_multiplier_(timecode_scale / 1000.0), |
28 ignored_tracks_(ignored_tracks), | 28 ignored_tracks_(ignored_tracks), |
29 audio_encryption_key_id_(audio_encryption_key_id), | 29 audio_encryption_key_id_(audio_encryption_key_id), |
30 video_encryption_key_id_(video_encryption_key_id), | 30 video_encryption_key_id_(video_encryption_key_id), |
31 parser_(kWebMIdCluster, this), | 31 parser_(kWebMIdCluster, this), |
(...skipping 253 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, track_num); |
349 | 350 |
350 if (decrypt_config) | 351 if (decrypt_config) |
351 buffer->set_decrypt_config(decrypt_config.Pass()); | 352 buffer->set_decrypt_config(decrypt_config.Pass()); |
352 } else { | 353 } else { |
353 std::string id, settings, content; | 354 std::string id, settings, content; |
354 WebMWebVTTParser::Parse(data, size, &id, &settings, &content); | 355 WebMWebVTTParser::Parse(data, size, &id, &settings, &content); |
355 | 356 |
356 std::vector<uint8> side_data; | 357 std::vector<uint8> side_data; |
357 MakeSideData(id.begin(), id.end(), | 358 MakeSideData(id.begin(), id.end(), |
358 settings.begin(), settings.end(), | 359 settings.begin(), settings.end(), |
359 &side_data); | 360 &side_data); |
360 | 361 |
361 buffer = StreamParserBuffer::CopyFrom( | 362 buffer = StreamParserBuffer::CopyFrom( |
362 reinterpret_cast<const uint8*>(content.data()), | 363 reinterpret_cast<const uint8*>(content.data()), |
363 content.length(), | 364 content.length(), |
364 &side_data[0], | 365 &side_data[0], |
365 side_data.size(), | 366 side_data.size(), |
366 true); | 367 true, buffer_type, track_num); |
367 } | 368 } |
368 | 369 |
369 buffer->set_timestamp(timestamp); | 370 buffer->set_timestamp(timestamp); |
370 if (cluster_start_time_ == kNoTimestamp()) | 371 if (cluster_start_time_ == kNoTimestamp()) |
371 cluster_start_time_ = timestamp; | 372 cluster_start_time_ = timestamp; |
372 | 373 |
373 if (block_duration >= 0) { | 374 if (block_duration >= 0) { |
374 buffer->set_duration(base::TimeDelta::FromMicroseconds( | 375 buffer->set_duration(base::TimeDelta::FromMicroseconds( |
375 block_duration * timecode_multiplier_)); | 376 block_duration * timecode_multiplier_)); |
376 } | 377 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 WebMClusterParser::FindTextTrack(int track_num) { | 443 WebMClusterParser::FindTextTrack(int track_num) { |
443 const TextTrackMap::iterator it = text_track_map_.find(track_num); | 444 const TextTrackMap::iterator it = text_track_map_.find(track_num); |
444 | 445 |
445 if (it == text_track_map_.end()) | 446 if (it == text_track_map_.end()) |
446 return NULL; | 447 return NULL; |
447 | 448 |
448 return &it->second; | 449 return &it->second; |
449 } | 450 } |
450 | 451 |
451 } // namespace media | 452 } // namespace media |
OLD | NEW |