| 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 | 9 |
| 9 #include "base/base64.h" | 10 #include "base/base64.h" |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/metrics/sparse_histogram.h" | 16 #include "base/metrics/sparse_histogram.h" |
| 16 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 MEDIA_LOG(ERROR, media_log) | 215 MEDIA_LOG(ERROR, media_log) |
| 215 << "FFmpegDemuxer: failed creating video stream"; | 216 << "FFmpegDemuxer: failed creating video stream"; |
| 216 return nullptr; | 217 return nullptr; |
| 217 } | 218 } |
| 218 | 219 |
| 219 MEDIA_LOG(INFO, media_log) << "FFmpegDemuxer: created video stream, config " | 220 MEDIA_LOG(INFO, media_log) << "FFmpegDemuxer: created video stream, config " |
| 220 << video_config->AsHumanReadableString(); | 221 << video_config->AsHumanReadableString(); |
| 221 } | 222 } |
| 222 | 223 |
| 223 return make_scoped_ptr(new FFmpegDemuxerStream( | 224 return make_scoped_ptr(new FFmpegDemuxerStream( |
| 224 demuxer, stream, audio_config.Pass(), video_config.Pass())); | 225 demuxer, stream, std::move(audio_config), std::move(video_config))); |
| 225 } | 226 } |
| 226 | 227 |
| 227 // | 228 // |
| 228 // FFmpegDemuxerStream | 229 // FFmpegDemuxerStream |
| 229 // | 230 // |
| 230 FFmpegDemuxerStream::FFmpegDemuxerStream( | 231 FFmpegDemuxerStream::FFmpegDemuxerStream( |
| 231 FFmpegDemuxer* demuxer, | 232 FFmpegDemuxer* demuxer, |
| 232 AVStream* stream, | 233 AVStream* stream, |
| 233 scoped_ptr<AudioDecoderConfig> audio_config, | 234 scoped_ptr<AudioDecoderConfig> audio_config, |
| 234 scoped_ptr<VideoDecoderConfig> video_config) | 235 scoped_ptr<VideoDecoderConfig> video_config) |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 const int discard_end_samples = | 409 const int discard_end_samples = |
| 409 base::ByteSwapToLE32(*(skip_samples_ptr + kSkipEndSamplesOffset)); | 410 base::ByteSwapToLE32(*(skip_samples_ptr + kSkipEndSamplesOffset)); |
| 410 const int samples_per_second = | 411 const int samples_per_second = |
| 411 audio_decoder_config().samples_per_second(); | 412 audio_decoder_config().samples_per_second(); |
| 412 buffer->set_discard_padding(std::make_pair( | 413 buffer->set_discard_padding(std::make_pair( |
| 413 FramesToTimeDelta(discard_front_samples, samples_per_second), | 414 FramesToTimeDelta(discard_front_samples, samples_per_second), |
| 414 FramesToTimeDelta(discard_end_samples, samples_per_second))); | 415 FramesToTimeDelta(discard_end_samples, samples_per_second))); |
| 415 } | 416 } |
| 416 | 417 |
| 417 if (decrypt_config) | 418 if (decrypt_config) |
| 418 buffer->set_decrypt_config(decrypt_config.Pass()); | 419 buffer->set_decrypt_config(std::move(decrypt_config)); |
| 419 } | 420 } |
| 420 | 421 |
| 421 if (packet->duration >= 0) { | 422 if (packet->duration >= 0) { |
| 422 buffer->set_duration( | 423 buffer->set_duration( |
| 423 ConvertStreamTimestamp(stream_->time_base, packet->duration)); | 424 ConvertStreamTimestamp(stream_->time_base, packet->duration)); |
| 424 } else { | 425 } else { |
| 425 // TODO(wolenetz): Remove when FFmpeg stops returning negative durations. | 426 // TODO(wolenetz): Remove when FFmpeg stops returning negative durations. |
| 426 // https://crbug.com/394418 | 427 // https://crbug.com/394418 |
| 427 DVLOG(1) << "FFmpeg returned a buffer with a negative duration! " | 428 DVLOG(1) << "FFmpeg returned a buffer with a negative duration! " |
| 428 << packet->duration; | 429 << packet->duration; |
| (...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1431 // | 1432 // |
| 1432 // https://code.google.com/p/chromium/issues/detail?id=169133#c10 | 1433 // https://code.google.com/p/chromium/issues/detail?id=169133#c10 |
| 1433 if (!packet->data) { | 1434 if (!packet->data) { |
| 1434 ScopedAVPacket new_packet(new AVPacket()); | 1435 ScopedAVPacket new_packet(new AVPacket()); |
| 1435 av_new_packet(new_packet.get(), 0); | 1436 av_new_packet(new_packet.get(), 0); |
| 1436 av_packet_copy_props(new_packet.get(), packet.get()); | 1437 av_packet_copy_props(new_packet.get(), packet.get()); |
| 1437 packet.swap(new_packet); | 1438 packet.swap(new_packet); |
| 1438 } | 1439 } |
| 1439 | 1440 |
| 1440 FFmpegDemuxerStream* demuxer_stream = streams_[packet->stream_index]; | 1441 FFmpegDemuxerStream* demuxer_stream = streams_[packet->stream_index]; |
| 1441 demuxer_stream->EnqueuePacket(packet.Pass()); | 1442 demuxer_stream->EnqueuePacket(std::move(packet)); |
| 1442 } | 1443 } |
| 1443 | 1444 |
| 1444 // Keep reading until we've reached capacity. | 1445 // Keep reading until we've reached capacity. |
| 1445 ReadFrameIfNeeded(); | 1446 ReadFrameIfNeeded(); |
| 1446 } | 1447 } |
| 1447 | 1448 |
| 1448 bool FFmpegDemuxer::StreamsHaveAvailableCapacity() { | 1449 bool FFmpegDemuxer::StreamsHaveAvailableCapacity() { |
| 1449 DCHECK(task_runner_->BelongsToCurrentThread()); | 1450 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 1450 StreamVector::iterator iter; | 1451 StreamVector::iterator iter; |
| 1451 for (iter = streams_.begin(); iter != streams_.end(); ++iter) { | 1452 for (iter = streams_.begin(); iter != streams_.end(); ++iter) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1523 | 1524 |
| 1524 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { | 1525 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { |
| 1525 DCHECK(task_runner_->BelongsToCurrentThread()); | 1526 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 1526 for (const auto& stream : streams_) { // |stream| is a ref to a pointer. | 1527 for (const auto& stream : streams_) { // |stream| is a ref to a pointer. |
| 1527 if (stream) | 1528 if (stream) |
| 1528 stream->SetLiveness(liveness); | 1529 stream->SetLiveness(liveness); |
| 1529 } | 1530 } |
| 1530 } | 1531 } |
| 1531 | 1532 |
| 1532 } // namespace media | 1533 } // namespace media |
| OLD | NEW |