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