Chromium Code Reviews| 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 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1105 const base::TimeDelta packet_pts = | 1105 const base::TimeDelta packet_pts = |
| 1106 ConvertFromTimeBase(stream->time_base, packet_buffer->pkt.pts); | 1106 ConvertFromTimeBase(stream->time_base, packet_buffer->pkt.pts); |
| 1107 if (packet_pts < start_time_estimates[stream->index]) | 1107 if (packet_pts < start_time_estimates[stream->index]) |
| 1108 start_time_estimates[stream->index] = packet_pts; | 1108 start_time_estimates[stream->index] = packet_pts; |
| 1109 } | 1109 } |
| 1110 packet_buffer = packet_buffer->next; | 1110 packet_buffer = packet_buffer->next; |
| 1111 } | 1111 } |
| 1112 } | 1112 } |
| 1113 | 1113 |
| 1114 scoped_ptr<MediaTracks> media_tracks(new MediaTracks()); | 1114 scoped_ptr<MediaTracks> media_tracks(new MediaTracks()); |
| 1115 MediaTracks::TrackToDemuxStreamMap track_to_demux_stream_map; | |
| 1115 AVStream* audio_stream = NULL; | 1116 AVStream* audio_stream = NULL; |
| 1116 AudioDecoderConfig audio_config; | 1117 AudioDecoderConfig audio_config; |
| 1117 AVStream* video_stream = NULL; | 1118 AVStream* video_stream = NULL; |
| 1118 VideoDecoderConfig video_config; | 1119 VideoDecoderConfig video_config; |
| 1119 | 1120 |
| 1120 // If available, |start_time_| will be set to the lowest stream start time. | 1121 // If available, |start_time_| will be set to the lowest stream start time. |
| 1121 start_time_ = kInfiniteDuration(); | 1122 start_time_ = kInfiniteDuration(); |
| 1122 | 1123 |
| 1123 base::TimeDelta max_duration; | 1124 base::TimeDelta max_duration; |
| 1124 int detected_audio_track_count = 0; | 1125 int detected_audio_track_count = 0; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1214 if (strstr(format_context->iformat->name, "webm") || | 1215 if (strstr(format_context->iformat->name, "webm") || |
| 1215 strstr(format_context->iformat->name, "matroska")) { | 1216 strstr(format_context->iformat->name, "matroska")) { |
| 1216 // 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. |
| 1217 // 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 |
| 1218 track_id = base::UintToString(media_tracks->tracks().size() + 1); | 1219 track_id = base::UintToString(media_tracks->tracks().size() + 1); |
| 1219 track_label = streams_[i]->GetMetadata("title"); | 1220 track_label = streams_[i]->GetMetadata("title"); |
| 1220 } | 1221 } |
| 1221 | 1222 |
| 1222 // 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 |
| 1223 // 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; | |
| 1224 if (codec_type == AVMEDIA_TYPE_AUDIO) { | 1226 if (codec_type == AVMEDIA_TYPE_AUDIO) { |
| 1225 CHECK(!audio_stream); | 1227 CHECK(!audio_stream); |
| 1226 audio_stream = stream; | 1228 audio_stream = stream; |
| 1227 audio_config = streams_[i]->audio_decoder_config(); | 1229 audio_config = streams_[i]->audio_decoder_config(); |
| 1228 RecordAudioCodecStats(audio_config); | 1230 RecordAudioCodecStats(audio_config); |
| 1229 | 1231 |
| 1230 media_tracks->AddAudioTrack(audio_config, track_id, "main", track_label, | 1232 media_track = media_tracks->AddAudioTrack(audio_config, track_id, "main", |
| 1231 track_language); | 1233 track_label, track_language); |
| 1234 track_to_demux_stream_map[media_track] = streams_[i]; | |
| 1232 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { | 1235 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { |
| 1233 CHECK(!video_stream); | 1236 CHECK(!video_stream); |
| 1234 video_stream = stream; | 1237 video_stream = stream; |
| 1235 video_config = streams_[i]->video_decoder_config(); | 1238 video_config = streams_[i]->video_decoder_config(); |
| 1236 RecordVideoCodecStats(video_config, stream->codec->color_range); | 1239 RecordVideoCodecStats(video_config, stream->codec->color_range); |
| 1237 | 1240 |
| 1238 media_tracks->AddVideoTrack(video_config, track_id, "main", track_label, | 1241 media_track = media_tracks->AddVideoTrack(video_config, track_id, "main", |
| 1239 track_language); | 1242 track_label, track_language); |
| 1243 track_to_demux_stream_map[media_track] = streams_[i]; | |
| 1240 } | 1244 } |
| 1241 | 1245 |
| 1242 max_duration = std::max(max_duration, streams_[i]->duration()); | 1246 max_duration = std::max(max_duration, streams_[i]->duration()); |
| 1243 | 1247 |
| 1244 const base::TimeDelta start_time = | 1248 const base::TimeDelta start_time = |
| 1245 ExtractStartTime(stream, start_time_estimates[i]); | 1249 ExtractStartTime(stream, start_time_estimates[i]); |
| 1246 const bool has_start_time = start_time != kNoTimestamp(); | 1250 const bool has_start_time = start_time != kNoTimestamp(); |
| 1247 | 1251 |
| 1248 // 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 |
| 1249 // the fallback stream with the preferred stream below. | 1253 // the fallback stream with the preferred stream below. |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1405 "video_format", VideoPixelFormatToString(video_config.format())); | 1409 "video_format", VideoPixelFormatToString(video_config.format())); |
| 1406 metadata_event->params.SetBoolean("video_is_encrypted", | 1410 metadata_event->params.SetBoolean("video_is_encrypted", |
| 1407 video_config.is_encrypted()); | 1411 video_config.is_encrypted()); |
| 1408 } | 1412 } |
| 1409 | 1413 |
| 1410 SetTimeProperty(metadata_event.get(), "max_duration", max_duration); | 1414 SetTimeProperty(metadata_event.get(), "max_duration", max_duration); |
| 1411 SetTimeProperty(metadata_event.get(), "start_time", start_time_); | 1415 SetTimeProperty(metadata_event.get(), "start_time", start_time_); |
| 1412 metadata_event->params.SetInteger("bitrate", bitrate_); | 1416 metadata_event->params.SetInteger("bitrate", bitrate_); |
| 1413 media_log_->AddEvent(std::move(metadata_event)); | 1417 media_log_->AddEvent(std::move(metadata_event)); |
| 1414 | 1418 |
| 1419 media_tracks->set_track_to_demux_stream_map(track_to_demux_stream_map); | |
| 1415 media_tracks_updated_cb_.Run(std::move(media_tracks)); | 1420 media_tracks_updated_cb_.Run(std::move(media_tracks)); |
| 1416 | 1421 |
| 1417 status_cb.Run(PIPELINE_OK); | 1422 status_cb.Run(PIPELINE_OK); |
| 1418 } | 1423 } |
| 1419 | 1424 |
| 1420 void FFmpegDemuxer::OnSeekFrameDone(const PipelineStatusCB& cb, int result) { | 1425 void FFmpegDemuxer::OnSeekFrameDone(const PipelineStatusCB& cb, int result) { |
| 1421 DCHECK(task_runner_->BelongsToCurrentThread()); | 1426 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 1422 CHECK(pending_seek_); | 1427 CHECK(pending_seek_); |
| 1423 pending_seek_ = false; | 1428 pending_seek_ = false; |
| 1424 | 1429 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1588 } | 1593 } |
| 1589 | 1594 |
| 1590 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { | 1595 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { |
| 1591 DCHECK(task_runner_->BelongsToCurrentThread()); | 1596 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 1592 for (const auto& stream : streams_) { // |stream| is a ref to a pointer. | 1597 for (const auto& stream : streams_) { // |stream| is a ref to a pointer. |
| 1593 if (stream) | 1598 if (stream) |
| 1594 stream->SetLiveness(liveness); | 1599 stream->SetLiveness(liveness); |
| 1595 } | 1600 } |
| 1596 } | 1601 } |
| 1597 | 1602 |
| 1603 void FFmpegDemuxer::OnTrackIdsAssigned(const MediaTracks& tracks, | |
| 1604 const std::vector<unsigned>& track_ids) { | |
| 1605 DCHECK_EQ(tracks.tracks().size(), track_ids.size()); | |
|
wolenetz
2016/04/14 20:43:39
Similarly, these two DCHECK_EQs need to be CHECK_E
servolk
2016/04/15 02:23:25
Done.
| |
| 1606 const auto& track_to_demux_stream = tracks.track_to_demux_stream_map(); | |
| 1607 DCHECK_EQ(track_to_demux_stream.size(), tracks.tracks().size()); | |
| 1608 for (size_t i = 0; i < track_ids.size(); ++i) { | |
| 1609 const MediaTrack* track = tracks.tracks()[i].get(); | |
| 1610 DCHECK(track); | |
| 1611 const auto& it = track_to_demux_stream.find(track); | |
| 1612 DCHECK(it != track_to_demux_stream.end()); | |
| 1613 DVLOG(3) << "OnTrackIdsAssigned track_id=" << track_ids[i] | |
| 1614 << " DemuxerStream=" << it->second; | |
| 1615 track_id_to_demux_stream_[track_ids[i]] = it->second; | |
| 1616 } | |
| 1617 } | |
| 1618 | |
| 1619 const DemuxerStream* FFmpegDemuxer::GetDemuxerStreamByTrackId( | |
| 1620 unsigned track_id) const { | |
| 1621 const auto& it = track_id_to_demux_stream_.find(track_id); | |
| 1622 CHECK(it != track_id_to_demux_stream_.end()); | |
| 1623 return it->second; | |
| 1624 } | |
| 1625 | |
| 1598 } // namespace media | 1626 } // namespace media |
| OLD | NEW |