| 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 <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 event->params.SetString(key, "kInfiniteDuration"); | 196 event->params.SetString(key, "kInfiniteDuration"); |
| 197 else if (value == kNoTimestamp) | 197 else if (value == kNoTimestamp) |
| 198 event->params.SetString(key, "kNoTimestamp"); | 198 event->params.SetString(key, "kNoTimestamp"); |
| 199 else | 199 else |
| 200 event->params.SetDouble(key, value.InSecondsF()); | 200 event->params.SetDouble(key, value.InSecondsF()); |
| 201 } | 201 } |
| 202 | 202 |
| 203 std::unique_ptr<FFmpegDemuxerStream> FFmpegDemuxerStream::Create( | 203 std::unique_ptr<FFmpegDemuxerStream> FFmpegDemuxerStream::Create( |
| 204 FFmpegDemuxer* demuxer, | 204 FFmpegDemuxer* demuxer, |
| 205 AVStream* stream, | 205 AVStream* stream, |
| 206 const scoped_refptr<MediaLog>& media_log) { | 206 MediaLog* media_log) { |
| 207 if (!demuxer || !stream) | 207 if (!demuxer || !stream) |
| 208 return nullptr; | 208 return nullptr; |
| 209 | 209 |
| 210 std::unique_ptr<FFmpegDemuxerStream> demuxer_stream; | 210 std::unique_ptr<FFmpegDemuxerStream> demuxer_stream; |
| 211 std::unique_ptr<AudioDecoderConfig> audio_config; | 211 std::unique_ptr<AudioDecoderConfig> audio_config; |
| 212 std::unique_ptr<VideoDecoderConfig> video_config; | 212 std::unique_ptr<VideoDecoderConfig> video_config; |
| 213 | 213 |
| 214 if (stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { | 214 if (stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { |
| 215 audio_config.reset(new AudioDecoderConfig()); | 215 audio_config.reset(new AudioDecoderConfig()); |
| 216 | 216 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 } | 258 } |
| 259 | 259 |
| 260 // | 260 // |
| 261 // FFmpegDemuxerStream | 261 // FFmpegDemuxerStream |
| 262 // | 262 // |
| 263 FFmpegDemuxerStream::FFmpegDemuxerStream( | 263 FFmpegDemuxerStream::FFmpegDemuxerStream( |
| 264 FFmpegDemuxer* demuxer, | 264 FFmpegDemuxer* demuxer, |
| 265 AVStream* stream, | 265 AVStream* stream, |
| 266 std::unique_ptr<AudioDecoderConfig> audio_config, | 266 std::unique_ptr<AudioDecoderConfig> audio_config, |
| 267 std::unique_ptr<VideoDecoderConfig> video_config, | 267 std::unique_ptr<VideoDecoderConfig> video_config, |
| 268 scoped_refptr<MediaLog> media_log) | 268 MediaLog* media_log) |
| 269 : demuxer_(demuxer), | 269 : demuxer_(demuxer), |
| 270 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 270 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 271 stream_(stream), | 271 stream_(stream), |
| 272 start_time_(kNoTimestamp), | 272 start_time_(kNoTimestamp), |
| 273 audio_config_(audio_config.release()), | 273 audio_config_(audio_config.release()), |
| 274 video_config_(video_config.release()), | 274 video_config_(video_config.release()), |
| 275 media_log_(std::move(media_log)), | 275 media_log_(media_log), |
| 276 type_(UNKNOWN), | 276 type_(UNKNOWN), |
| 277 liveness_(LIVENESS_UNKNOWN), | 277 liveness_(LIVENESS_UNKNOWN), |
| 278 end_of_stream_(false), | 278 end_of_stream_(false), |
| 279 last_packet_timestamp_(kNoTimestamp), | 279 last_packet_timestamp_(kNoTimestamp), |
| 280 last_packet_duration_(kNoTimestamp), | 280 last_packet_duration_(kNoTimestamp), |
| 281 video_rotation_(VIDEO_ROTATION_0), | 281 video_rotation_(VIDEO_ROTATION_0), |
| 282 is_enabled_(true), | 282 is_enabled_(true), |
| 283 waiting_for_keyframe_(false), | 283 waiting_for_keyframe_(false), |
| 284 aborted_(false), | 284 aborted_(false), |
| 285 fixup_negative_timestamps_(false) { | 285 fixup_negative_timestamps_(false) { |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 } | 828 } |
| 829 | 829 |
| 830 // | 830 // |
| 831 // FFmpegDemuxer | 831 // FFmpegDemuxer |
| 832 // | 832 // |
| 833 FFmpegDemuxer::FFmpegDemuxer( | 833 FFmpegDemuxer::FFmpegDemuxer( |
| 834 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 834 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 835 DataSource* data_source, | 835 DataSource* data_source, |
| 836 const EncryptedMediaInitDataCB& encrypted_media_init_data_cb, | 836 const EncryptedMediaInitDataCB& encrypted_media_init_data_cb, |
| 837 const MediaTracksUpdatedCB& media_tracks_updated_cb, | 837 const MediaTracksUpdatedCB& media_tracks_updated_cb, |
| 838 const scoped_refptr<MediaLog>& media_log) | 838 MediaLog* media_log) |
| 839 : host_(NULL), | 839 : host_(NULL), |
| 840 task_runner_(task_runner), | 840 task_runner_(task_runner), |
| 841 // FFmpeg has no asynchronous API, so we use base::WaitableEvents inside | 841 // FFmpeg has no asynchronous API, so we use base::WaitableEvents inside |
| 842 // the BlockingUrlProtocol to handle hops to the render thread for network | 842 // the BlockingUrlProtocol to handle hops to the render thread for network |
| 843 // reads and seeks. | 843 // reads and seeks. |
| 844 blocking_task_runner_(base::CreateSequencedTaskRunnerWithTraits( | 844 blocking_task_runner_(base::CreateSequencedTaskRunnerWithTraits( |
| 845 base::TaskTraits().MayBlock().WithBaseSyncPrimitives().WithPriority( | 845 base::TaskTraits().MayBlock().WithBaseSyncPrimitives().WithPriority( |
| 846 base::TaskPriority::USER_BLOCKING))), | 846 base::TaskPriority::USER_BLOCKING))), |
| 847 stopped_(false), | 847 stopped_(false), |
| 848 pending_read_(false), | 848 pending_read_(false), |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1366 media_track = media_tracks->AddAudioTrack(audio_config, track_id, "main", | 1366 media_track = media_tracks->AddAudioTrack(audio_config, track_id, "main", |
| 1367 track_label, track_language); | 1367 track_label, track_language); |
| 1368 media_track->set_id(base::UintToString(track_id)); | 1368 media_track->set_id(base::UintToString(track_id)); |
| 1369 DCHECK(track_id_to_demux_stream_map_.find(media_track->id()) == | 1369 DCHECK(track_id_to_demux_stream_map_.find(media_track->id()) == |
| 1370 track_id_to_demux_stream_map_.end()); | 1370 track_id_to_demux_stream_map_.end()); |
| 1371 track_id_to_demux_stream_map_[media_track->id()] = streams_[i].get(); | 1371 track_id_to_demux_stream_map_[media_track->id()] = streams_[i].get(); |
| 1372 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { | 1372 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { |
| 1373 VideoDecoderConfig video_config = streams_[i]->video_decoder_config(); | 1373 VideoDecoderConfig video_config = streams_[i]->video_decoder_config(); |
| 1374 | 1374 |
| 1375 RecordVideoCodecStats(video_config, stream->codecpar->color_range, | 1375 RecordVideoCodecStats(video_config, stream->codecpar->color_range, |
| 1376 media_log_.get()); | 1376 media_log_); |
| 1377 | 1377 |
| 1378 media_track = media_tracks->AddVideoTrack(video_config, track_id, "main", | 1378 media_track = media_tracks->AddVideoTrack(video_config, track_id, "main", |
| 1379 track_label, track_language); | 1379 track_label, track_language); |
| 1380 media_track->set_id(base::UintToString(track_id)); | 1380 media_track->set_id(base::UintToString(track_id)); |
| 1381 DCHECK(track_id_to_demux_stream_map_.find(media_track->id()) == | 1381 DCHECK(track_id_to_demux_stream_map_.find(media_track->id()) == |
| 1382 track_id_to_demux_stream_map_.end()); | 1382 track_id_to_demux_stream_map_.end()); |
| 1383 track_id_to_demux_stream_map_[media_track->id()] = streams_[i].get(); | 1383 track_id_to_demux_stream_map_[media_track->id()] = streams_[i].get(); |
| 1384 } | 1384 } |
| 1385 | 1385 |
| 1386 max_duration = std::max(max_duration, streams_[i]->duration()); | 1386 max_duration = std::max(max_duration, streams_[i]->duration()); |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1868 | 1868 |
| 1869 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { | 1869 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { |
| 1870 DCHECK(task_runner_->BelongsToCurrentThread()); | 1870 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 1871 for (const auto& stream : streams_) { | 1871 for (const auto& stream : streams_) { |
| 1872 if (stream) | 1872 if (stream) |
| 1873 stream->SetLiveness(liveness); | 1873 stream->SetLiveness(liveness); |
| 1874 } | 1874 } |
| 1875 } | 1875 } |
| 1876 | 1876 |
| 1877 } // namespace media | 1877 } // namespace media |
| OLD | NEW |