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 <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1111 packet_buffer = packet_buffer->next; | 1111 packet_buffer = packet_buffer->next; |
1112 } | 1112 } |
1113 } | 1113 } |
1114 | 1114 |
1115 std::unique_ptr<MediaTracks> media_tracks(new MediaTracks()); | 1115 std::unique_ptr<MediaTracks> media_tracks(new MediaTracks()); |
1116 AVStream* audio_stream = NULL; | 1116 AVStream* audio_stream = NULL; |
1117 AudioDecoderConfig audio_config; | 1117 AudioDecoderConfig audio_config; |
1118 AVStream* video_stream = NULL; | 1118 AVStream* video_stream = NULL; |
1119 VideoDecoderConfig video_config; | 1119 VideoDecoderConfig video_config; |
1120 | 1120 |
1121 DCHECK(track_id_to_demux_stream_map_.empty()); | |
1122 | |
1121 // If available, |start_time_| will be set to the lowest stream start time. | 1123 // If available, |start_time_| will be set to the lowest stream start time. |
1122 start_time_ = kInfiniteDuration(); | 1124 start_time_ = kInfiniteDuration(); |
1123 | 1125 |
1124 base::TimeDelta max_duration; | 1126 base::TimeDelta max_duration; |
1125 int detected_audio_track_count = 0; | 1127 int detected_audio_track_count = 0; |
1126 int detected_video_track_count = 0; | 1128 int detected_video_track_count = 0; |
1127 int detected_text_track_count = 0; | 1129 int detected_text_track_count = 0; |
1128 for (size_t i = 0; i < format_context->nb_streams; ++i) { | 1130 for (size_t i = 0; i < format_context->nb_streams; ++i) { |
1129 AVStream* stream = format_context->streams[i]; | 1131 AVStream* stream = format_context->streams[i]; |
1130 const AVCodecContext* codec_context = stream->codec; | 1132 const AVCodecContext* codec_context = stream->codec; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1216 strstr(format_context->iformat->name, "matroska")) { | 1218 strstr(format_context->iformat->name, "matroska")) { |
1217 // TODO(servolk): FFmpeg doesn't set stream->id correctly for webm files. | 1219 // TODO(servolk): FFmpeg doesn't set stream->id correctly for webm files. |
1218 // Need to fix that and use it as track id. crbug.com/323183 | 1220 // Need to fix that and use it as track id. crbug.com/323183 |
1219 track_id = | 1221 track_id = |
1220 static_cast<StreamParser::TrackId>(media_tracks->tracks().size() + 1); | 1222 static_cast<StreamParser::TrackId>(media_tracks->tracks().size() + 1); |
1221 track_label = streams_[i]->GetMetadata("title"); | 1223 track_label = streams_[i]->GetMetadata("title"); |
1222 } | 1224 } |
1223 | 1225 |
1224 // Note when we find our audio/video stream (we only want one of each) and | 1226 // Note when we find our audio/video stream (we only want one of each) and |
1225 // record src= playback UMA stats for the stream's decoder config. | 1227 // record src= playback UMA stats for the stream's decoder config. |
1228 MediaTrack* media_track = nullptr; | |
1226 if (codec_type == AVMEDIA_TYPE_AUDIO) { | 1229 if (codec_type == AVMEDIA_TYPE_AUDIO) { |
1227 CHECK(!audio_stream); | 1230 CHECK(!audio_stream); |
1228 audio_stream = stream; | 1231 audio_stream = stream; |
1229 audio_config = streams_[i]->audio_decoder_config(); | 1232 audio_config = streams_[i]->audio_decoder_config(); |
1230 RecordAudioCodecStats(audio_config); | 1233 RecordAudioCodecStats(audio_config); |
1231 | 1234 |
1232 media_tracks->AddAudioTrack(audio_config, track_id, "main", track_label, | 1235 media_track = media_tracks->AddAudioTrack(audio_config, track_id, "main", |
1233 track_language); | 1236 track_label, track_language); |
1237 media_track->setId(base::UintToString(track_id)); | |
chcunningham
2016/06/09 17:57:19
So for src=, we re-use the bytstream track Id to s
servolk
2016/06/09 19:14:46
Done. Only I've added a DCHECK, don't think it des
| |
1238 track_id_to_demux_stream_map_[media_track->id()] = streams_[i]; | |
1234 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { | 1239 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { |
1235 CHECK(!video_stream); | 1240 CHECK(!video_stream); |
1236 video_stream = stream; | 1241 video_stream = stream; |
1237 video_config = streams_[i]->video_decoder_config(); | 1242 video_config = streams_[i]->video_decoder_config(); |
1238 RecordVideoCodecStats(video_config, stream->codec->color_range); | 1243 RecordVideoCodecStats(video_config, stream->codec->color_range); |
1239 | 1244 |
1240 media_tracks->AddVideoTrack(video_config, track_id, "main", track_label, | 1245 media_track = media_tracks->AddVideoTrack(video_config, track_id, "main", |
1241 track_language); | 1246 track_label, track_language); |
1247 media_track->setId(base::UintToString(track_id)); | |
1248 track_id_to_demux_stream_map_[media_track->id()] = streams_[i]; | |
1242 } | 1249 } |
1243 | 1250 |
1244 max_duration = std::max(max_duration, streams_[i]->duration()); | 1251 max_duration = std::max(max_duration, streams_[i]->duration()); |
1245 | 1252 |
1246 const base::TimeDelta start_time = | 1253 const base::TimeDelta start_time = |
1247 ExtractStartTime(stream, start_time_estimates[i]); | 1254 ExtractStartTime(stream, start_time_estimates[i]); |
1248 const bool has_start_time = start_time != kNoTimestamp(); | 1255 const bool has_start_time = start_time != kNoTimestamp(); |
1249 | 1256 |
1250 // Always prefer the video stream for seeking. If none exists, we'll swap | 1257 // Always prefer the video stream for seeking. If none exists, we'll swap |
1251 // the fallback stream with the preferred stream below. | 1258 // the fallback stream with the preferred stream below. |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1412 SetTimeProperty(metadata_event.get(), "max_duration", max_duration); | 1419 SetTimeProperty(metadata_event.get(), "max_duration", max_duration); |
1413 SetTimeProperty(metadata_event.get(), "start_time", start_time_); | 1420 SetTimeProperty(metadata_event.get(), "start_time", start_time_); |
1414 metadata_event->params.SetInteger("bitrate", bitrate_); | 1421 metadata_event->params.SetInteger("bitrate", bitrate_); |
1415 media_log_->AddEvent(std::move(metadata_event)); | 1422 media_log_->AddEvent(std::move(metadata_event)); |
1416 | 1423 |
1417 media_tracks_updated_cb_.Run(std::move(media_tracks)); | 1424 media_tracks_updated_cb_.Run(std::move(media_tracks)); |
1418 | 1425 |
1419 status_cb.Run(PIPELINE_OK); | 1426 status_cb.Run(PIPELINE_OK); |
1420 } | 1427 } |
1421 | 1428 |
1429 const DemuxerStream* FFmpegDemuxer::GetDemuxerStreamByTrackId( | |
1430 MediaTrack::TrackId track_id) const { | |
1431 auto it = track_id_to_demux_stream_map_.find(track_id); | |
1432 DCHECK(it != track_id_to_demux_stream_map_.end()); | |
1433 return it->second; | |
1434 } | |
1435 | |
1422 void FFmpegDemuxer::OnSeekFrameDone(const PipelineStatusCB& cb, int result) { | 1436 void FFmpegDemuxer::OnSeekFrameDone(const PipelineStatusCB& cb, int result) { |
1423 DCHECK(task_runner_->BelongsToCurrentThread()); | 1437 DCHECK(task_runner_->BelongsToCurrentThread()); |
1424 CHECK(pending_seek_); | 1438 CHECK(pending_seek_); |
1425 pending_seek_ = false; | 1439 pending_seek_ = false; |
1426 | 1440 |
1427 if (!blocking_thread_.IsRunning()) { | 1441 if (!blocking_thread_.IsRunning()) { |
1428 MEDIA_LOG(ERROR, media_log_) << GetDisplayName() << ": bad state"; | 1442 MEDIA_LOG(ERROR, media_log_) << GetDisplayName() << ": bad state"; |
1429 cb.Run(PIPELINE_ERROR_ABORT); | 1443 cb.Run(PIPELINE_ERROR_ABORT); |
1430 return; | 1444 return; |
1431 } | 1445 } |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1591 | 1605 |
1592 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { | 1606 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { |
1593 DCHECK(task_runner_->BelongsToCurrentThread()); | 1607 DCHECK(task_runner_->BelongsToCurrentThread()); |
1594 for (const auto& stream : streams_) { // |stream| is a ref to a pointer. | 1608 for (const auto& stream : streams_) { // |stream| is a ref to a pointer. |
1595 if (stream) | 1609 if (stream) |
1596 stream->SetLiveness(liveness); | 1610 stream->SetLiveness(liveness); |
1597 } | 1611 } |
1598 } | 1612 } |
1599 | 1613 |
1600 } // namespace media | 1614 } // namespace media |
OLD | NEW |