Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: media/webm/webm_cluster_parser.cc

Issue 23702007: Render inband text tracks in the media pipeline (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fix compile errors 11/21 #6 Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/mp4/mp4_stream_parser_unittest.cc ('k') | media/webm/webm_cluster_parser_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/webm/webm_cluster_parser.h" 5 #include "media/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/webm/webm_constants.h" 14 #include "media/webm/webm_constants.h"
14 #include "media/webm/webm_crypto_helpers.h" 15 #include "media/webm/webm_crypto_helpers.h"
16 #include "media/webm/webm_webvtt_parser.h"
15 17
16 namespace media { 18 namespace media {
17 19
18 WebMClusterParser::TextTrackIterator::TextTrackIterator( 20 WebMClusterParser::TextTrackIterator::TextTrackIterator(
19 const TextTrackMap& text_track_map) : 21 const TextTrackMap& text_track_map) :
20 iterator_(text_track_map.begin()), 22 iterator_(text_track_map.begin()),
21 iterator_end_(text_track_map.end()) { 23 iterator_end_(text_track_map.end()) {
22 } 24 }
23 25
24 WebMClusterParser::TextTrackIterator::TextTrackIterator( 26 WebMClusterParser::TextTrackIterator::TextTrackIterator(
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 return false; 302 return false;
301 } 303 }
302 304
303 if (last_block_timecode_ != -1 && timecode < last_block_timecode_) { 305 if (last_block_timecode_ != -1 && timecode < last_block_timecode_) {
304 MEDIA_LOG(log_cb_) 306 MEDIA_LOG(log_cb_)
305 << "Got a block with a timecode before the previous block."; 307 << "Got a block with a timecode before the previous block.";
306 return false; 308 return false;
307 } 309 }
308 310
309 Track* track = NULL; 311 Track* track = NULL;
312 bool is_text = false;
310 std::string encryption_key_id; 313 std::string encryption_key_id;
311 if (track_num == audio_.track_num()) { 314 if (track_num == audio_.track_num()) {
312 track = &audio_; 315 track = &audio_;
313 encryption_key_id = audio_encryption_key_id_; 316 encryption_key_id = audio_encryption_key_id_;
314 } else if (track_num == video_.track_num()) { 317 } else if (track_num == video_.track_num()) {
315 track = &video_; 318 track = &video_;
316 encryption_key_id = video_encryption_key_id_; 319 encryption_key_id = video_encryption_key_id_;
317 } else if (ignored_tracks_.find(track_num) != ignored_tracks_.end()) { 320 } else if (ignored_tracks_.find(track_num) != ignored_tracks_.end()) {
318 return true; 321 return true;
319 } else if (Track* const text_track = FindTextTrack(track_num)) { 322 } else if (Track* const text_track = FindTextTrack(track_num)) {
320 if (is_simple_block) // BlockGroup is required for WebVTT cues 323 if (is_simple_block) // BlockGroup is required for WebVTT cues
321 return false; 324 return false;
322 if (block_duration < 0) // not specified 325 if (block_duration < 0) // not specified
323 return false; 326 return false;
324 track = text_track; 327 track = text_track;
328 is_text = true;
325 } else { 329 } else {
326 MEDIA_LOG(log_cb_) << "Unexpected track number " << track_num; 330 MEDIA_LOG(log_cb_) << "Unexpected track number " << track_num;
327 return false; 331 return false;
328 } 332 }
329 333
330 last_block_timecode_ = timecode; 334 last_block_timecode_ = timecode;
331 335
332 base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds( 336 base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds(
333 (cluster_timecode_ + timecode) * timecode_multiplier_); 337 (cluster_timecode_ + timecode) * timecode_multiplier_);
334 338
335 // The first bit of the flags is set when a SimpleBlock contains only 339 // The first bit of the flags is set when a SimpleBlock contains only
336 // keyframes. If this is a Block, then inspection of the payload is 340 // keyframes. If this is a Block, then inspection of the payload is
337 // necessary to determine whether it contains a keyframe or not. 341 // necessary to determine whether it contains a keyframe or not.
338 // http://www.matroska.org/technical/specs/index.html 342 // http://www.matroska.org/technical/specs/index.html
339 bool is_keyframe = 343 bool is_keyframe =
340 is_simple_block ? (flags & 0x80) != 0 : track->IsKeyframe(data, size); 344 is_simple_block ? (flags & 0x80) != 0 : track->IsKeyframe(data, size);
341 345
342 scoped_refptr<StreamParserBuffer> buffer = 346 scoped_refptr<StreamParserBuffer> buffer;
343 StreamParserBuffer::CopyFrom(data, size, additional, additional_size, 347 if (!is_text) {
344 is_keyframe); 348 buffer = StreamParserBuffer::CopyFrom(data, size,
349 additional, additional_size,
350 is_keyframe);
351 } else {
352 std::string id, settings, content;
353 WebMWebVTTParser::Parse(data, size,
354 &id, &settings, &content);
355
356 std::vector<uint8> side_data;
357 MakeSideData(id.begin(), id.end(),
358 settings.begin(), settings.end(),
359 &side_data);
360
361 buffer = StreamParserBuffer::CopyFrom(
362 reinterpret_cast<const uint8*>(content.data()),
363 content.length(),
364 &side_data[0],
365 side_data.size(),
366 is_keyframe);
367 }
345 368
346 // Every encrypted Block has a signal byte and IV prepended to it. Current 369 // Every encrypted Block has a signal byte and IV prepended to it. Current
347 // encrypted WebM request for comments specification is here 370 // encrypted WebM request for comments specification is here
348 // http://wiki.webmproject.org/encryption/webm-encryption-rfc 371 // http://wiki.webmproject.org/encryption/webm-encryption-rfc
349 if (!encryption_key_id.empty()) { 372 if (!encryption_key_id.empty()) {
350 scoped_ptr<DecryptConfig> config(WebMCreateDecryptConfig( 373 scoped_ptr<DecryptConfig> config(WebMCreateDecryptConfig(
351 data, size, 374 data, size,
352 reinterpret_cast<const uint8*>(encryption_key_id.data()), 375 reinterpret_cast<const uint8*>(encryption_key_id.data()),
353 encryption_key_id.size())); 376 encryption_key_id.size()));
354 if (!config) 377 if (!config)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 WebMClusterParser::FindTextTrack(int track_num) { 454 WebMClusterParser::FindTextTrack(int track_num) {
432 const TextTrackMap::iterator it = text_track_map_.find(track_num); 455 const TextTrackMap::iterator it = text_track_map_.find(track_num);
433 456
434 if (it == text_track_map_.end()) 457 if (it == text_track_map_.end())
435 return NULL; 458 return NULL;
436 459
437 return &it->second; 460 return &it->second;
438 } 461 }
439 462
440 } // namespace media 463 } // namespace media
OLDNEW
« no previous file with comments | « media/mp4/mp4_stream_parser_unittest.cc ('k') | media/webm/webm_cluster_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698