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

Side by Side Diff: media/filters/ffmpeg_demuxer.cc

Issue 236023003: Add WebMediaPlayer::timelineOffset() support to WebMediaPlayerImpl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months 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 | Annotate | Revision Log
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/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"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/callback_helpers.h" 13 #include "base/callback_helpers.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop/message_loop_proxy.h" 15 #include "base/message_loop/message_loop_proxy.h"
16 #include "base/metrics/sparse_histogram.h" 16 #include "base/metrics/sparse_histogram.h"
17 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
19 #include "base/sys_byteorder.h" 20 #include "base/sys_byteorder.h"
20 #include "base/task_runner_util.h" 21 #include "base/task_runner_util.h"
21 #include "base/time/time.h" 22 #include "base/time/time.h"
22 #include "media/base/audio_decoder_config.h" 23 #include "media/base/audio_decoder_config.h"
23 #include "media/base/bind_to_current_loop.h" 24 #include "media/base/bind_to_current_loop.h"
24 #include "media/base/decoder_buffer.h" 25 #include "media/base/decoder_buffer.h"
25 #include "media/base/decrypt_config.h" 26 #include "media/base/decrypt_config.h"
26 #include "media/base/limits.h" 27 #include "media/base/limits.h"
27 #include "media/base/media_log.h" 28 #include "media/base/media_log.h"
28 #include "media/base/video_decoder_config.h" 29 #include "media/base/video_decoder_config.h"
29 #include "media/ffmpeg/ffmpeg_common.h" 30 #include "media/ffmpeg/ffmpeg_common.h"
30 #include "media/filters/ffmpeg_glue.h" 31 #include "media/filters/ffmpeg_glue.h"
31 #include "media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.h" 32 #include "media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.h"
32 #include "media/filters/webvtt_util.h" 33 #include "media/filters/webvtt_util.h"
33 #include "media/formats/webm/webm_crypto_helpers.h" 34 #include "media/formats/webm/webm_crypto_helpers.h"
34 35
35 namespace media { 36 namespace media {
36 37
38 static base::Time ExtractTimelineOffset(AVFormatContext* format_context) {
scherkus (not reviewing) 2014/04/15 00:53:40 parsing code without tests makes me nervous how a
acolwell GONE FROM CHROMIUM 2014/04/16 01:01:08 Done.
39 if (strstr(format_context->iformat->name, "webm") ||
40 strstr(format_context->iformat->name, "matroska")) {
41 const AVDictionaryEntry* entry =
42 av_dict_get(format_context->metadata, "creation_time", NULL, 0);
43
44 // Convert ffmpeg UTC representation (YYYY-MM-DD HH:MM:SS) to base::Time.
scherkus (not reviewing) 2014/04/15 00:53:40 s/ffmpeg/FFmpeg/
acolwell GONE FROM CHROMIUM 2014/04/16 01:01:08 Done.
45 std::vector<std::string> fields;
46 std::vector<std::string> date_fields;
47 std::vector<std::string> time_fields;
48 base::Time::Exploded exploded;
49 exploded.millisecond = 0;
50
51 // TODO: Update this parsing code when FFmpeg returns sub-second
scherkus (not reviewing) 2014/04/15 00:53:40 TODO(acolwell)?
acolwell GONE FROM CHROMIUM 2014/04/16 01:01:08 Done.
52 // information.
53 if (entry != NULL && entry->value != NULL &&
54 (Tokenize(entry->value, " ", &fields) == 2) &&
55 (Tokenize(fields[0], "-", &date_fields) == 3) &&
56 (Tokenize(fields[1], ":", &time_fields) == 3) &&
57 base::StringToInt(date_fields[0], &exploded.year) &&
58 base::StringToInt(date_fields[1], &exploded.month) &&
59 base::StringToInt(date_fields[2], &exploded.day_of_month) &&
60 base::StringToInt(time_fields[0], &exploded.hour) &&
61 base::StringToInt(time_fields[1], &exploded.minute) &&
62 base::StringToInt(time_fields[2], &exploded.second)) {
63 return base::Time::FromUTCExploded(exploded);
64 }
65 }
66
67 return base::Time();
68 }
69
37 // 70 //
38 // FFmpegDemuxerStream 71 // FFmpegDemuxerStream
39 // 72 //
40 FFmpegDemuxerStream::FFmpegDemuxerStream( 73 FFmpegDemuxerStream::FFmpegDemuxerStream(
41 FFmpegDemuxer* demuxer, 74 FFmpegDemuxer* demuxer,
42 AVStream* stream) 75 AVStream* stream)
43 : demuxer_(demuxer), 76 : demuxer_(demuxer),
44 task_runner_(base::MessageLoopProxy::current()), 77 task_runner_(base::MessageLoopProxy::current()),
45 stream_(stream), 78 stream_(stream),
46 type_(UNKNOWN), 79 type_(UNKNOWN),
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 } 512 }
480 } 513 }
481 return NULL; 514 return NULL;
482 } 515 }
483 516
484 base::TimeDelta FFmpegDemuxer::GetStartTime() const { 517 base::TimeDelta FFmpegDemuxer::GetStartTime() const {
485 DCHECK(task_runner_->BelongsToCurrentThread()); 518 DCHECK(task_runner_->BelongsToCurrentThread());
486 return start_time_; 519 return start_time_;
487 } 520 }
488 521
522 base::Time FFmpegDemuxer::GetWallclockTimelineOffset() const {
523 return wallclock_timeline_offset_;
524 }
525
489 void FFmpegDemuxer::AddTextStreams() { 526 void FFmpegDemuxer::AddTextStreams() {
490 DCHECK(task_runner_->BelongsToCurrentThread()); 527 DCHECK(task_runner_->BelongsToCurrentThread());
491 528
492 for (StreamVector::size_type idx = 0; idx < streams_.size(); ++idx) { 529 for (StreamVector::size_type idx = 0; idx < streams_.size(); ++idx) {
493 FFmpegDemuxerStream* stream = streams_[idx]; 530 FFmpegDemuxerStream* stream = streams_[idx];
494 if (stream == NULL || stream->type() != DemuxerStream::TEXT) 531 if (stream == NULL || stream->type() != DemuxerStream::TEXT)
495 continue; 532 continue;
496 533
497 TextKind kind = stream->GetTextKind(); 534 TextKind kind = stream->GetTextKind();
498 std::string title = stream->GetMetadata("title"); 535 std::string title = stream->GetMetadata("title");
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 // Some demuxers, like WAV, do not put timestamps on their frames. We 704 // Some demuxers, like WAV, do not put timestamps on their frames. We
668 // assume the the start time is 0. 705 // assume the the start time is 0.
669 if (start_time_ == kNoTimestamp()) 706 if (start_time_ == kNoTimestamp())
670 start_time_ = base::TimeDelta(); 707 start_time_ = base::TimeDelta();
671 708
672 // MPEG-4 B-frames cause grief for a simple container like AVI. Enable PTS 709 // 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 710 // generation so we always get timestamps, see http://crbug.com/169570
674 if (strcmp(format_context->iformat->name, "avi") == 0) 711 if (strcmp(format_context->iformat->name, "avi") == 0)
675 format_context->flags |= AVFMT_FLAG_GENPTS; 712 format_context->flags |= AVFMT_FLAG_GENPTS;
676 713
714 wallclock_timeline_offset_ = ExtractTimelineOffset(format_context);
715
677 // Good to go: set the duration and bitrate and notify we're done 716 // Good to go: set the duration and bitrate and notify we're done
678 // initializing. 717 // initializing.
679 host_->SetDuration(max_duration); 718 host_->SetDuration(max_duration);
680 duration_known_ = (max_duration != kInfiniteDuration()); 719 duration_known_ = (max_duration != kInfiniteDuration());
681 720
682 int64 filesize_in_bytes = 0; 721 int64 filesize_in_bytes = 0;
683 url_protocol_->GetSize(&filesize_in_bytes); 722 url_protocol_->GetSize(&filesize_in_bytes);
684 bitrate_ = CalculateBitrate(format_context, max_duration, filesize_in_bytes); 723 bitrate_ = CalculateBitrate(format_context, max_duration, filesize_in_bytes);
685 if (bitrate_ > 0) 724 if (bitrate_ > 0)
686 data_source_->SetBitrate(bitrate_); 725 data_source_->SetBitrate(bitrate_);
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 } 1019 }
981 for (size_t i = 0; i < buffered.size(); ++i) 1020 for (size_t i = 0; i < buffered.size(); ++i)
982 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i)); 1021 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i));
983 } 1022 }
984 1023
985 void FFmpegDemuxer::OnDataSourceError() { 1024 void FFmpegDemuxer::OnDataSourceError() {
986 host_->OnDemuxerError(PIPELINE_ERROR_READ); 1025 host_->OnDemuxerError(PIPELINE_ERROR_READ);
987 } 1026 }
988 1027
989 } // namespace media 1028 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698