OLD | NEW |
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/filters/ffmpeg_demuxer.h" | 5 #include "media/filters/ffmpeg_demuxer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "media/base/media_log.h" | 27 #include "media/base/media_log.h" |
28 #include "media/base/video_decoder_config.h" | 28 #include "media/base/video_decoder_config.h" |
29 #include "media/ffmpeg/ffmpeg_common.h" | 29 #include "media/ffmpeg/ffmpeg_common.h" |
30 #include "media/filters/ffmpeg_glue.h" | 30 #include "media/filters/ffmpeg_glue.h" |
31 #include "media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.h" | 31 #include "media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.h" |
32 #include "media/filters/webvtt_util.h" | 32 #include "media/filters/webvtt_util.h" |
33 #include "media/formats/webm/webm_crypto_helpers.h" | 33 #include "media/formats/webm/webm_crypto_helpers.h" |
34 | 34 |
35 namespace media { | 35 namespace media { |
36 | 36 |
| 37 static base::Time ExtractTimelineOffset(AVFormatContext* format_context) { |
| 38 if (strstr(format_context->iformat->name, "webm") || |
| 39 strstr(format_context->iformat->name, "matroska")) { |
| 40 const AVDictionaryEntry* entry = |
| 41 av_dict_get(format_context->metadata, "creation_time", NULL, 0); |
| 42 |
| 43 base::Time timeline_offset; |
| 44 if (entry != NULL && entry->value != NULL && |
| 45 FFmpegUTCDateToTime(entry->value, &timeline_offset)) { |
| 46 return timeline_offset; |
| 47 } |
| 48 } |
| 49 |
| 50 return base::Time(); |
| 51 } |
| 52 |
37 // | 53 // |
38 // FFmpegDemuxerStream | 54 // FFmpegDemuxerStream |
39 // | 55 // |
40 FFmpegDemuxerStream::FFmpegDemuxerStream( | 56 FFmpegDemuxerStream::FFmpegDemuxerStream( |
41 FFmpegDemuxer* demuxer, | 57 FFmpegDemuxer* demuxer, |
42 AVStream* stream) | 58 AVStream* stream) |
43 : demuxer_(demuxer), | 59 : demuxer_(demuxer), |
44 task_runner_(base::MessageLoopProxy::current()), | 60 task_runner_(base::MessageLoopProxy::current()), |
45 stream_(stream), | 61 stream_(stream), |
46 type_(UNKNOWN), | 62 type_(UNKNOWN), |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 } | 495 } |
480 } | 496 } |
481 return NULL; | 497 return NULL; |
482 } | 498 } |
483 | 499 |
484 base::TimeDelta FFmpegDemuxer::GetStartTime() const { | 500 base::TimeDelta FFmpegDemuxer::GetStartTime() const { |
485 DCHECK(task_runner_->BelongsToCurrentThread()); | 501 DCHECK(task_runner_->BelongsToCurrentThread()); |
486 return start_time_; | 502 return start_time_; |
487 } | 503 } |
488 | 504 |
| 505 base::Time FFmpegDemuxer::GetTimelineOffset() const { |
| 506 return timeline_offset_; |
| 507 } |
| 508 |
489 void FFmpegDemuxer::AddTextStreams() { | 509 void FFmpegDemuxer::AddTextStreams() { |
490 DCHECK(task_runner_->BelongsToCurrentThread()); | 510 DCHECK(task_runner_->BelongsToCurrentThread()); |
491 | 511 |
492 for (StreamVector::size_type idx = 0; idx < streams_.size(); ++idx) { | 512 for (StreamVector::size_type idx = 0; idx < streams_.size(); ++idx) { |
493 FFmpegDemuxerStream* stream = streams_[idx]; | 513 FFmpegDemuxerStream* stream = streams_[idx]; |
494 if (stream == NULL || stream->type() != DemuxerStream::TEXT) | 514 if (stream == NULL || stream->type() != DemuxerStream::TEXT) |
495 continue; | 515 continue; |
496 | 516 |
497 TextKind kind = stream->GetTextKind(); | 517 TextKind kind = stream->GetTextKind(); |
498 std::string title = stream->GetMetadata("title"); | 518 std::string title = stream->GetMetadata("title"); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 // Some demuxers, like WAV, do not put timestamps on their frames. We | 687 // Some demuxers, like WAV, do not put timestamps on their frames. We |
668 // assume the the start time is 0. | 688 // assume the the start time is 0. |
669 if (start_time_ == kNoTimestamp()) | 689 if (start_time_ == kNoTimestamp()) |
670 start_time_ = base::TimeDelta(); | 690 start_time_ = base::TimeDelta(); |
671 | 691 |
672 // MPEG-4 B-frames cause grief for a simple container like AVI. Enable PTS | 692 // MPEG-4 B-frames cause grief for a simple container like AVI. Enable PTS |
673 // generation so we always get timestamps, see http://crbug.com/169570 | 693 // generation so we always get timestamps, see http://crbug.com/169570 |
674 if (strcmp(format_context->iformat->name, "avi") == 0) | 694 if (strcmp(format_context->iformat->name, "avi") == 0) |
675 format_context->flags |= AVFMT_FLAG_GENPTS; | 695 format_context->flags |= AVFMT_FLAG_GENPTS; |
676 | 696 |
| 697 timeline_offset_ = ExtractTimelineOffset(format_context); |
| 698 |
677 // Good to go: set the duration and bitrate and notify we're done | 699 // Good to go: set the duration and bitrate and notify we're done |
678 // initializing. | 700 // initializing. |
679 host_->SetDuration(max_duration); | 701 host_->SetDuration(max_duration); |
680 duration_known_ = (max_duration != kInfiniteDuration()); | 702 duration_known_ = (max_duration != kInfiniteDuration()); |
681 | 703 |
682 int64 filesize_in_bytes = 0; | 704 int64 filesize_in_bytes = 0; |
683 url_protocol_->GetSize(&filesize_in_bytes); | 705 url_protocol_->GetSize(&filesize_in_bytes); |
684 bitrate_ = CalculateBitrate(format_context, max_duration, filesize_in_bytes); | 706 bitrate_ = CalculateBitrate(format_context, max_duration, filesize_in_bytes); |
685 if (bitrate_ > 0) | 707 if (bitrate_ > 0) |
686 data_source_->SetBitrate(bitrate_); | 708 data_source_->SetBitrate(bitrate_); |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 } | 1002 } |
981 for (size_t i = 0; i < buffered.size(); ++i) | 1003 for (size_t i = 0; i < buffered.size(); ++i) |
982 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i)); | 1004 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i)); |
983 } | 1005 } |
984 | 1006 |
985 void FFmpegDemuxer::OnDataSourceError() { | 1007 void FFmpegDemuxer::OnDataSourceError() { |
986 host_->OnDemuxerError(PIPELINE_ERROR_READ); | 1008 host_->OnDemuxerError(PIPELINE_ERROR_READ); |
987 } | 1009 } |
988 | 1010 |
989 } // namespace media | 1011 } // namespace media |
OLD | NEW |