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 1187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 if (strstr(format_context->iformat->name, "webm") || | 1198 if (strstr(format_context->iformat->name, "webm") || |
1199 strstr(format_context->iformat->name, "matroska")) { | 1199 strstr(format_context->iformat->name, "matroska")) { |
1200 // TODO(servolk): FFmpeg doesn't set stream->id correctly for webm files. | 1200 // TODO(servolk): FFmpeg doesn't set stream->id correctly for webm files. |
1201 // Need to fix that and use it as track id. crbug.com/323183 | 1201 // Need to fix that and use it as track id. crbug.com/323183 |
1202 track_id = base::UintToString(media_tracks->tracks().size() + 1); | 1202 track_id = base::UintToString(media_tracks->tracks().size() + 1); |
1203 track_label = streams_[i]->GetMetadata("title"); | 1203 track_label = streams_[i]->GetMetadata("title"); |
1204 } | 1204 } |
1205 | 1205 |
1206 // Note when we find our audio/video stream (we only want one of each) and | 1206 // Note when we find our audio/video stream (we only want one of each) and |
1207 // record src= playback UMA stats for the stream's decoder config. | 1207 // record src= playback UMA stats for the stream's decoder config. |
| 1208 const MediaTrack* media_track = nullptr; |
1208 if (codec_type == AVMEDIA_TYPE_AUDIO) { | 1209 if (codec_type == AVMEDIA_TYPE_AUDIO) { |
1209 CHECK(!audio_stream); | 1210 CHECK(!audio_stream); |
1210 audio_stream = stream; | 1211 audio_stream = stream; |
1211 audio_config = streams_[i]->audio_decoder_config(); | 1212 audio_config = streams_[i]->audio_decoder_config(); |
1212 RecordAudioCodecStats(audio_config); | 1213 RecordAudioCodecStats(audio_config); |
1213 | 1214 |
1214 media_tracks->AddAudioTrack(audio_config, track_id, "main", track_label, | 1215 media_track = media_tracks->AddAudioTrack(audio_config, track_id, "main", |
1215 track_language); | 1216 track_label, track_language); |
1216 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { | 1217 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { |
1217 CHECK(!video_stream); | 1218 CHECK(!video_stream); |
1218 video_stream = stream; | 1219 video_stream = stream; |
1219 video_config = streams_[i]->video_decoder_config(); | 1220 video_config = streams_[i]->video_decoder_config(); |
1220 RecordVideoCodecStats(video_config, stream->codec->color_range); | 1221 RecordVideoCodecStats(video_config, stream->codec->color_range); |
1221 | 1222 |
1222 media_tracks->AddVideoTrack(video_config, track_id, "main", track_label, | 1223 media_track = media_tracks->AddVideoTrack(video_config, track_id, "main", |
1223 track_language); | 1224 track_label, track_language); |
1224 } | 1225 } |
| 1226 DVLOG(5) << "Associating media_track=" << media_track |
| 1227 << " with demuxer_stream=" << streams_[i]; |
| 1228 track_to_stream_map_[media_track] = streams_[i]; |
1225 | 1229 |
1226 max_duration = std::max(max_duration, streams_[i]->duration()); | 1230 max_duration = std::max(max_duration, streams_[i]->duration()); |
1227 | 1231 |
1228 const base::TimeDelta start_time = | 1232 const base::TimeDelta start_time = |
1229 ExtractStartTime(stream, start_time_estimates[i]); | 1233 ExtractStartTime(stream, start_time_estimates[i]); |
1230 const bool has_start_time = start_time != kNoTimestamp(); | 1234 const bool has_start_time = start_time != kNoTimestamp(); |
1231 | 1235 |
1232 // Always prefer the video stream for seeking. If none exists, we'll swap | 1236 // Always prefer the video stream for seeking. If none exists, we'll swap |
1233 // the fallback stream with the preferred stream below. | 1237 // the fallback stream with the preferred stream below. |
1234 if (codec_type == AVMEDIA_TYPE_VIDEO) { | 1238 if (codec_type == AVMEDIA_TYPE_VIDEO) { |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1572 } | 1576 } |
1573 | 1577 |
1574 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { | 1578 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { |
1575 DCHECK(task_runner_->BelongsToCurrentThread()); | 1579 DCHECK(task_runner_->BelongsToCurrentThread()); |
1576 for (const auto& stream : streams_) { // |stream| is a ref to a pointer. | 1580 for (const auto& stream : streams_) { // |stream| is a ref to a pointer. |
1577 if (stream) | 1581 if (stream) |
1578 stream->SetLiveness(liveness); | 1582 stream->SetLiveness(liveness); |
1579 } | 1583 } |
1580 } | 1584 } |
1581 | 1585 |
| 1586 void FFmpegDemuxer::OnTrackIdAssigned(unsigned track_id, |
| 1587 const MediaTrack* track) { |
| 1588 DVLOG(5) << "OnTrackIdAssigned track_id=" << track_id << " track=" << track; |
| 1589 if (track) { |
| 1590 DCHECK(track_id_to_track_map_.find(track_id) == |
| 1591 track_id_to_track_map_.end()); |
| 1592 track_id_to_track_map_[track_id] = track; |
| 1593 } else { |
| 1594 DCHECK(track_id_to_track_map_.find(track_id) != |
| 1595 track_id_to_track_map_.end()); |
| 1596 track_id_to_track_map_.erase(track_id); |
| 1597 } |
| 1598 } |
| 1599 |
| 1600 const DemuxerStream* FFmpegDemuxer::GetDemuxerStreamByTrackId( |
| 1601 unsigned track_id) const { |
| 1602 const auto& it1 = track_id_to_track_map_.find(track_id); |
| 1603 CHECK(it1 != track_id_to_track_map_.end()); |
| 1604 const auto& it2 = track_to_stream_map_.find(it1->second); |
| 1605 CHECK(it2 != track_to_stream_map_.end()); |
| 1606 return it2->second; |
| 1607 } |
| 1608 |
1582 } // namespace media | 1609 } // namespace media |
OLD | NEW |