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 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1215 if (strstr(format_context->iformat->name, "webm") || | 1215 if (strstr(format_context->iformat->name, "webm") || |
1216 strstr(format_context->iformat->name, "matroska")) { | 1216 strstr(format_context->iformat->name, "matroska")) { |
1217 // TODO(servolk): FFmpeg doesn't set stream->id correctly for webm files. | 1217 // 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 | 1218 // Need to fix that and use it as track id. crbug.com/323183 |
1219 track_id = base::UintToString(media_tracks->tracks().size() + 1); | 1219 track_id = base::UintToString(media_tracks->tracks().size() + 1); |
1220 track_label = streams_[i]->GetMetadata("title"); | 1220 track_label = streams_[i]->GetMetadata("title"); |
1221 } | 1221 } |
1222 | 1222 |
1223 // Note when we find our audio/video stream (we only want one of each) and | 1223 // Note when we find our audio/video stream (we only want one of each) and |
1224 // record src= playback UMA stats for the stream's decoder config. | 1224 // record src= playback UMA stats for the stream's decoder config. |
1225 const MediaTrack* media_track = nullptr; | |
1225 if (codec_type == AVMEDIA_TYPE_AUDIO) { | 1226 if (codec_type == AVMEDIA_TYPE_AUDIO) { |
1226 CHECK(!audio_stream); | 1227 CHECK(!audio_stream); |
1227 audio_stream = stream; | 1228 audio_stream = stream; |
1228 audio_config = streams_[i]->audio_decoder_config(); | 1229 audio_config = streams_[i]->audio_decoder_config(); |
1229 RecordAudioCodecStats(audio_config); | 1230 RecordAudioCodecStats(audio_config); |
1230 | 1231 |
1231 media_tracks->AddAudioTrack(audio_config, track_id, "main", track_label, | 1232 media_track = media_tracks->AddAudioTrack(audio_config, track_id, "main", |
1232 track_language); | 1233 track_label, track_language); |
1234 media_tracks->SetDemuxerStreamForMediaTrack(media_track, streams_[i]); | |
1233 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { | 1235 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { |
1234 CHECK(!video_stream); | 1236 CHECK(!video_stream); |
1235 video_stream = stream; | 1237 video_stream = stream; |
1236 video_config = streams_[i]->video_decoder_config(); | 1238 video_config = streams_[i]->video_decoder_config(); |
1237 RecordVideoCodecStats(video_config, stream->codec->color_range); | 1239 RecordVideoCodecStats(video_config, stream->codec->color_range); |
1238 | 1240 |
1239 media_tracks->AddVideoTrack(video_config, track_id, "main", track_label, | 1241 media_track = media_tracks->AddVideoTrack(video_config, track_id, "main", |
1240 track_language); | 1242 track_label, track_language); |
1243 media_tracks->SetDemuxerStreamForMediaTrack(media_track, streams_[i]); | |
1241 } | 1244 } |
1242 | 1245 |
1243 max_duration = std::max(max_duration, streams_[i]->duration()); | 1246 max_duration = std::max(max_duration, streams_[i]->duration()); |
1244 | 1247 |
1245 const base::TimeDelta start_time = | 1248 const base::TimeDelta start_time = |
1246 ExtractStartTime(stream, start_time_estimates[i]); | 1249 ExtractStartTime(stream, start_time_estimates[i]); |
1247 const bool has_start_time = start_time != kNoTimestamp(); | 1250 const bool has_start_time = start_time != kNoTimestamp(); |
1248 | 1251 |
1249 // Always prefer the video stream for seeking. If none exists, we'll swap | 1252 // Always prefer the video stream for seeking. If none exists, we'll swap |
1250 // the fallback stream with the preferred stream below. | 1253 // the fallback stream with the preferred stream below. |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1589 } | 1592 } |
1590 | 1593 |
1591 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { | 1594 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { |
1592 DCHECK(task_runner_->BelongsToCurrentThread()); | 1595 DCHECK(task_runner_->BelongsToCurrentThread()); |
1593 for (const auto& stream : streams_) { // |stream| is a ref to a pointer. | 1596 for (const auto& stream : streams_) { // |stream| is a ref to a pointer. |
1594 if (stream) | 1597 if (stream) |
1595 stream->SetLiveness(liveness); | 1598 stream->SetLiveness(liveness); |
1596 } | 1599 } |
1597 } | 1600 } |
1598 | 1601 |
1602 void FFmpegDemuxer::OnTrackIdsAssigned(const MediaTracks& tracks, | |
1603 const std::vector<unsigned>& track_ids) { | |
1604 DCHECK(track_id_to_demux_stream_.empty()); | |
chcunningham
2016/06/02 21:24:45
Same question about DCHECK vs CHECK for these two
servolk
2016/06/02 23:53:11
It's the same here. In release build we could bypa
| |
1605 track_id_to_demux_stream_ = tracks.OnTrackIdsAssigned(track_ids); | |
1606 } | |
1607 | |
1608 const DemuxerStream* FFmpegDemuxer::GetDemuxerStreamByTrackId( | |
1609 unsigned track_id) const { | |
1610 const auto& it = track_id_to_demux_stream_.find(track_id); | |
1611 CHECK(it != track_id_to_demux_stream_.end()); | |
1612 return it->second; | |
1613 } | |
1614 | |
1599 } // namespace media | 1615 } // namespace media |
OLD | NEW |