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

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

Issue 1735003004: Implement reading of media track info from WebM and MP4 containers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@demuxer-tracks2
Patch Set: Mark WebMStreamParser with MEDIA_EXPORT to allow usage in unit tests Created 4 years, 9 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
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 <utility> 8 #include <utility>
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_helpers.h" 12 #include "base/callback_helpers.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
16 #include "base/metrics/sparse_histogram.h" 16 #include "base/metrics/sparse_histogram.h"
17 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
20 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "base/sys_byteorder.h" 21 #include "base/sys_byteorder.h"
22 #include "base/task_runner_util.h" 22 #include "base/task_runner_util.h"
23 #include "base/thread_task_runner_handle.h" 23 #include "base/thread_task_runner_handle.h"
24 #include "base/time/time.h" 24 #include "base/time/time.h"
25 #include "media/audio/sample_rates.h" 25 #include "media/audio/sample_rates.h"
26 #include "media/base/bind_to_current_loop.h" 26 #include "media/base/bind_to_current_loop.h"
27 #include "media/base/decrypt_config.h" 27 #include "media/base/decrypt_config.h"
28 #include "media/base/limits.h" 28 #include "media/base/limits.h"
29 #include "media/base/media_log.h" 29 #include "media/base/media_log.h"
30 #include "media/base/media_tracks.h"
30 #include "media/base/timestamp_constants.h" 31 #include "media/base/timestamp_constants.h"
31 #include "media/ffmpeg/ffmpeg_common.h" 32 #include "media/ffmpeg/ffmpeg_common.h"
32 #include "media/filters/ffmpeg_aac_bitstream_converter.h" 33 #include "media/filters/ffmpeg_aac_bitstream_converter.h"
33 #include "media/filters/ffmpeg_bitstream_converter.h" 34 #include "media/filters/ffmpeg_bitstream_converter.h"
34 #include "media/filters/ffmpeg_glue.h" 35 #include "media/filters/ffmpeg_glue.h"
35 #include "media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.h" 36 #include "media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.h"
36 #include "media/filters/webvtt_util.h" 37 #include "media/filters/webvtt_util.h"
37 #include "media/formats/webm/webm_crypto_helpers.h" 38 #include "media/formats/webm/webm_crypto_helpers.h"
38 #include "media/media_features.h" 39 #include "media/media_features.h"
39 40
(...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 if (packet_buffer->pkt.pts != static_cast<int64_t>(AV_NOPTS_VALUE)) { 1050 if (packet_buffer->pkt.pts != static_cast<int64_t>(AV_NOPTS_VALUE)) {
1050 const base::TimeDelta packet_pts = 1051 const base::TimeDelta packet_pts =
1051 ConvertFromTimeBase(stream->time_base, packet_buffer->pkt.pts); 1052 ConvertFromTimeBase(stream->time_base, packet_buffer->pkt.pts);
1052 if (packet_pts < start_time_estimates[stream->index]) 1053 if (packet_pts < start_time_estimates[stream->index])
1053 start_time_estimates[stream->index] = packet_pts; 1054 start_time_estimates[stream->index] = packet_pts;
1054 } 1055 }
1055 packet_buffer = packet_buffer->next; 1056 packet_buffer = packet_buffer->next;
1056 } 1057 }
1057 } 1058 }
1058 1059
1060 scoped_ptr<MediaTracks> media_tracks(new MediaTracks());
1059 AVStream* audio_stream = NULL; 1061 AVStream* audio_stream = NULL;
1060 AudioDecoderConfig audio_config; 1062 AudioDecoderConfig audio_config;
1061 AVStream* video_stream = NULL; 1063 AVStream* video_stream = NULL;
1062 VideoDecoderConfig video_config; 1064 VideoDecoderConfig video_config;
1063 1065
1064 // If available, |start_time_| will be set to the lowest stream start time. 1066 // If available, |start_time_| will be set to the lowest stream start time.
1065 start_time_ = kInfiniteDuration(); 1067 start_time_ = kInfiniteDuration();
1066 1068
1067 base::TimeDelta max_duration; 1069 base::TimeDelta max_duration;
1068 for (size_t i = 0; i < format_context->nb_streams; ++i) { 1070 for (size_t i = 0; i < format_context->nb_streams; ++i) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 // things like: codec, channel layout, sample/pixel format, etc... 1120 // things like: codec, channel layout, sample/pixel format, etc...
1119 scoped_ptr<FFmpegDemuxerStream> demuxer_stream = 1121 scoped_ptr<FFmpegDemuxerStream> demuxer_stream =
1120 FFmpegDemuxerStream::Create(this, stream, media_log_); 1122 FFmpegDemuxerStream::Create(this, stream, media_log_);
1121 if (demuxer_stream.get()) { 1123 if (demuxer_stream.get()) {
1122 streams_[i] = demuxer_stream.release(); 1124 streams_[i] = demuxer_stream.release();
1123 } else { 1125 } else {
1124 // This AVStream does not successfully convert. 1126 // This AVStream does not successfully convert.
1125 continue; 1127 continue;
1126 } 1128 }
1127 1129
1130 std::string track_id = base::UintToString(stream->id);
wolenetz 2016/03/05 03:26:20 nit: the id struct member is an int, not a uint
servolk 2016/03/07 23:45:01 Done.
1131 std::string track_label = streams_[i]->GetMetadata("handler_name");
1132 std::string track_language = streams_[i]->GetMetadata("language");
1133
1134 // Some metadata is named differently in FFmpeg for webm files.
1135 if (strstr(format_context->iformat->name, "webm") ||
1136 strstr(format_context->iformat->name, "matroska")) {
1137 // TODO(servolk): FFmpeg doesn't set stream->id correctly for webm files.
1138 // Need to fix that and use it as track id. crbug.com/323183
wolenetz 2016/03/05 03:26:20 nit: reactivate that closed bug or file a new one
servolk 2016/03/07 23:45:01 Done.
1139 track_id = base::UintToString(media_tracks->tracks().size() + 1);
1140 track_label = streams_[i]->GetMetadata("title");
1141 }
1142
1128 // Note when we find our audio/video stream (we only want one of each) and 1143 // Note when we find our audio/video stream (we only want one of each) and
1129 // record src= playback UMA stats for the stream's decoder config. 1144 // record src= playback UMA stats for the stream's decoder config.
1130 if (codec_type == AVMEDIA_TYPE_AUDIO) { 1145 if (codec_type == AVMEDIA_TYPE_AUDIO) {
1131 CHECK(!audio_stream); 1146 CHECK(!audio_stream);
1132 audio_stream = stream; 1147 audio_stream = stream;
1133 audio_config = streams_[i]->audio_decoder_config(); 1148 audio_config = streams_[i]->audio_decoder_config();
1134 RecordAudioCodecStats(audio_config); 1149 RecordAudioCodecStats(audio_config);
1150
1151 media_tracks->AddAudioTrack(audio_config, track_id, "main", track_label,
1152 track_language);
1135 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { 1153 } else if (codec_type == AVMEDIA_TYPE_VIDEO) {
1136 CHECK(!video_stream); 1154 CHECK(!video_stream);
1137 video_stream = stream; 1155 video_stream = stream;
1138 video_config = streams_[i]->video_decoder_config(); 1156 video_config = streams_[i]->video_decoder_config();
1139 RecordVideoCodecStats(video_config, stream->codec->color_range); 1157 RecordVideoCodecStats(video_config, stream->codec->color_range);
1158
1159 media_tracks->AddVideoTrack(video_config, track_id, "main", track_label,
1160 track_language);
1140 } 1161 }
1141 1162
1142 max_duration = std::max(max_duration, streams_[i]->duration()); 1163 max_duration = std::max(max_duration, streams_[i]->duration());
1143 1164
1144 const base::TimeDelta start_time = 1165 const base::TimeDelta start_time =
1145 ExtractStartTime(stream, start_time_estimates[i]); 1166 ExtractStartTime(stream, start_time_estimates[i]);
1146 const bool has_start_time = start_time != kNoTimestamp(); 1167 const bool has_start_time = start_time != kNoTimestamp();
1147 1168
1148 // Always prefer the video stream for seeking. If none exists, we'll swap 1169 // Always prefer the video stream for seeking. If none exists, we'll swap
1149 // the fallback stream with the preferred stream below. 1170 // the fallback stream with the preferred stream below.
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 media_log_->SetBooleanProperty("video_is_encrypted", 1321 media_log_->SetBooleanProperty("video_is_encrypted",
1301 video_config.is_encrypted()); 1322 video_config.is_encrypted());
1302 } else { 1323 } else {
1303 media_log_->SetBooleanProperty("found_video_stream", false); 1324 media_log_->SetBooleanProperty("found_video_stream", false);
1304 } 1325 }
1305 1326
1306 media_log_->SetTimeProperty("max_duration", max_duration); 1327 media_log_->SetTimeProperty("max_duration", max_duration);
1307 media_log_->SetTimeProperty("start_time", start_time_); 1328 media_log_->SetTimeProperty("start_time", start_time_);
1308 media_log_->SetIntegerProperty("bitrate", bitrate_); 1329 media_log_->SetIntegerProperty("bitrate", bitrate_);
1309 1330
1331 media_tracks_updated_cb_.Run(std::move(media_tracks));
1332
1310 status_cb.Run(PIPELINE_OK); 1333 status_cb.Run(PIPELINE_OK);
1311 } 1334 }
1312 1335
1313 void FFmpegDemuxer::OnSeekFrameDone(const PipelineStatusCB& cb, int result) { 1336 void FFmpegDemuxer::OnSeekFrameDone(const PipelineStatusCB& cb, int result) {
1314 DCHECK(task_runner_->BelongsToCurrentThread()); 1337 DCHECK(task_runner_->BelongsToCurrentThread());
1315 CHECK(pending_seek_); 1338 CHECK(pending_seek_);
1316 pending_seek_ = false; 1339 pending_seek_ = false;
1317 1340
1318 if (!blocking_thread_.IsRunning()) { 1341 if (!blocking_thread_.IsRunning()) {
1319 MEDIA_LOG(ERROR, media_log_) << GetDisplayName() << ": bad state"; 1342 MEDIA_LOG(ERROR, media_log_) << GetDisplayName() << ": bad state";
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1511 1534
1512 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { 1535 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) {
1513 DCHECK(task_runner_->BelongsToCurrentThread()); 1536 DCHECK(task_runner_->BelongsToCurrentThread());
1514 for (const auto& stream : streams_) { // |stream| is a ref to a pointer. 1537 for (const auto& stream : streams_) { // |stream| is a ref to a pointer.
1515 if (stream) 1538 if (stream)
1516 stream->SetLiveness(liveness); 1539 stream->SetLiveness(liveness);
1517 } 1540 }
1518 } 1541 }
1519 1542
1520 } // namespace media 1543 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698