Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: media/filters/ffmpeg_demuxer.cc

Issue 1812543003: Allow muting/unmuting audio through media track API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blink-sb-tracks6
Patch Set: Added VideoTrackSelectDeselect test case Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 if (strstr(format_context->iformat->name, "webm") || 1199 if (strstr(format_context->iformat->name, "webm") ||
1199 strstr(format_context->iformat->name, "matroska")) { 1200 strstr(format_context->iformat->name, "matroska")) {
1200 // TODO(servolk): FFmpeg doesn't set stream->id correctly for webm files. 1201 // 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 1202 // Need to fix that and use it as track id. crbug.com/323183
1202 track_id = base::UintToString(media_tracks->tracks().size() + 1); 1203 track_id = base::UintToString(media_tracks->tracks().size() + 1);
1203 track_label = streams_[i]->GetMetadata("title"); 1204 track_label = streams_[i]->GetMetadata("title");
1204 } 1205 }
1205 1206
1206 // Note when we find our audio/video stream (we only want one of each) and 1207 // 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. 1208 // record src= playback UMA stats for the stream's decoder config.
1209 const MediaTrack* media_track = nullptr;
1208 if (codec_type == AVMEDIA_TYPE_AUDIO) { 1210 if (codec_type == AVMEDIA_TYPE_AUDIO) {
1209 CHECK(!audio_stream); 1211 CHECK(!audio_stream);
1210 audio_stream = stream; 1212 audio_stream = stream;
1211 audio_config = streams_[i]->audio_decoder_config(); 1213 audio_config = streams_[i]->audio_decoder_config();
1212 RecordAudioCodecStats(audio_config); 1214 RecordAudioCodecStats(audio_config);
1213 1215
1214 media_tracks->AddAudioTrack(audio_config, track_id, "main", track_label, 1216 media_track = media_tracks->AddAudioTrack(audio_config, track_id, "main",
1215 track_language); 1217 track_label, track_language);
1218 track_to_demux_stream_map[media_track] = streams_[i];
1216 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { 1219 } else if (codec_type == AVMEDIA_TYPE_VIDEO) {
1217 CHECK(!video_stream); 1220 CHECK(!video_stream);
1218 video_stream = stream; 1221 video_stream = stream;
1219 video_config = streams_[i]->video_decoder_config(); 1222 video_config = streams_[i]->video_decoder_config();
1220 RecordVideoCodecStats(video_config, stream->codec->color_range); 1223 RecordVideoCodecStats(video_config, stream->codec->color_range);
1221 1224
1222 media_tracks->AddVideoTrack(video_config, track_id, "main", track_label, 1225 media_track = media_tracks->AddVideoTrack(video_config, track_id, "main",
1223 track_language); 1226 track_label, track_language);
1227 track_to_demux_stream_map[media_track] = streams_[i];
1224 } 1228 }
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.
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 "video_format", VideoPixelFormatToString(video_config.format())); 1393 "video_format", VideoPixelFormatToString(video_config.format()));
1390 metadata_event->params.SetBoolean("video_is_encrypted", 1394 metadata_event->params.SetBoolean("video_is_encrypted",
1391 video_config.is_encrypted()); 1395 video_config.is_encrypted());
1392 } 1396 }
1393 1397
1394 SetTimeProperty(metadata_event.get(), "max_duration", max_duration); 1398 SetTimeProperty(metadata_event.get(), "max_duration", max_duration);
1395 SetTimeProperty(metadata_event.get(), "start_time", start_time_); 1399 SetTimeProperty(metadata_event.get(), "start_time", start_time_);
1396 metadata_event->params.SetInteger("bitrate", bitrate_); 1400 metadata_event->params.SetInteger("bitrate", bitrate_);
1397 media_log_->AddEvent(std::move(metadata_event)); 1401 media_log_->AddEvent(std::move(metadata_event));
1398 1402
1403 media_tracks->set_track_to_demux_stream_map(track_to_demux_stream_map);
1399 media_tracks_updated_cb_.Run(std::move(media_tracks)); 1404 media_tracks_updated_cb_.Run(std::move(media_tracks));
1400 1405
1401 status_cb.Run(PIPELINE_OK); 1406 status_cb.Run(PIPELINE_OK);
1402 } 1407 }
1403 1408
1404 void FFmpegDemuxer::OnSeekFrameDone(const PipelineStatusCB& cb, int result) { 1409 void FFmpegDemuxer::OnSeekFrameDone(const PipelineStatusCB& cb, int result) {
1405 DCHECK(task_runner_->BelongsToCurrentThread()); 1410 DCHECK(task_runner_->BelongsToCurrentThread());
1406 CHECK(pending_seek_); 1411 CHECK(pending_seek_);
1407 pending_seek_ = false; 1412 pending_seek_ = false;
1408 1413
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1572 } 1577 }
1573 1578
1574 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { 1579 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) {
1575 DCHECK(task_runner_->BelongsToCurrentThread()); 1580 DCHECK(task_runner_->BelongsToCurrentThread());
1576 for (const auto& stream : streams_) { // |stream| is a ref to a pointer. 1581 for (const auto& stream : streams_) { // |stream| is a ref to a pointer.
1577 if (stream) 1582 if (stream)
1578 stream->SetLiveness(liveness); 1583 stream->SetLiveness(liveness);
1579 } 1584 }
1580 } 1585 }
1581 1586
1587 void FFmpegDemuxer::OnTrackIdsAssigned(const MediaTracks& tracks,
1588 const std::vector<unsigned>& track_ids) {
1589 DCHECK_EQ(tracks.tracks().size(), track_ids.size());
1590 const auto& track_to_demux_stream = tracks.track_to_demux_stream_map();
1591 DCHECK_EQ(track_to_demux_stream.size(), tracks.tracks().size());
1592 for (size_t i = 0; i < track_ids.size(); ++i) {
1593 const MediaTrack* track = tracks.tracks()[i].get();
1594 DCHECK(track);
1595 const auto& it = track_to_demux_stream.find(track);
1596 DCHECK(it != track_to_demux_stream.end());
1597 DVLOG(3) << "OnTrackIdsAssigned track_id=" << track_ids[i]
1598 << " DemuxerStream=" << it->second;
1599 track_id_to_demux_stream_[track_ids[i]] = it->second;
1600 }
1601 }
1602
1603 const DemuxerStream* FFmpegDemuxer::GetDemuxerStreamByTrackId(
1604 unsigned track_id) const {
1605 const auto& it = track_id_to_demux_stream_.find(track_id);
1606 CHECK(it != track_id_to_demux_stream_.end());
1607 return it->second;
1608 }
1609
1582 } // namespace media 1610 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698