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 <string> | 8 #include <string> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_to_current_loop.h" |
12 #include "base/callback.h" | 13 #include "base/callback.h" |
13 #include "base/callback_helpers.h" | 14 #include "base/callback_helpers.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
15 #include "base/message_loop/message_loop_proxy.h" | 16 #include "base/message_loop/message_loop_proxy.h" |
16 #include "base/metrics/sparse_histogram.h" | 17 #include "base/metrics/sparse_histogram.h" |
17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
19 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
20 #include "base/sys_byteorder.h" | 21 #include "base/sys_byteorder.h" |
21 #include "base/task_runner_util.h" | 22 #include "base/task_runner_util.h" |
22 #include "base/time/time.h" | 23 #include "base/time/time.h" |
23 #include "media/base/audio_decoder_config.h" | 24 #include "media/base/audio_decoder_config.h" |
24 #include "media/base/bind_to_current_loop.h" | |
25 #include "media/base/decoder_buffer.h" | 25 #include "media/base/decoder_buffer.h" |
26 #include "media/base/decrypt_config.h" | 26 #include "media/base/decrypt_config.h" |
27 #include "media/base/limits.h" | 27 #include "media/base/limits.h" |
28 #include "media/base/media_log.h" | 28 #include "media/base/media_log.h" |
29 #include "media/base/video_decoder_config.h" | 29 #include "media/base/video_decoder_config.h" |
30 #include "media/ffmpeg/ffmpeg_common.h" | 30 #include "media/ffmpeg/ffmpeg_common.h" |
31 #include "media/filters/ffmpeg_aac_bitstream_converter.h" | 31 #include "media/filters/ffmpeg_aac_bitstream_converter.h" |
32 #include "media/filters/ffmpeg_bitstream_converter.h" | 32 #include "media/filters/ffmpeg_bitstream_converter.h" |
33 #include "media/filters/ffmpeg_glue.h" | 33 #include "media/filters/ffmpeg_glue.h" |
34 #include "media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.h" | 34 #include "media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.h" |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 } | 416 } |
417 | 417 |
418 DemuxerStream::Liveness FFmpegDemuxerStream::liveness() const { | 418 DemuxerStream::Liveness FFmpegDemuxerStream::liveness() const { |
419 DCHECK(task_runner_->BelongsToCurrentThread()); | 419 DCHECK(task_runner_->BelongsToCurrentThread()); |
420 return liveness_; | 420 return liveness_; |
421 } | 421 } |
422 | 422 |
423 void FFmpegDemuxerStream::Read(const ReadCB& read_cb) { | 423 void FFmpegDemuxerStream::Read(const ReadCB& read_cb) { |
424 DCHECK(task_runner_->BelongsToCurrentThread()); | 424 DCHECK(task_runner_->BelongsToCurrentThread()); |
425 CHECK(read_cb_.is_null()) << "Overlapping reads are not supported"; | 425 CHECK(read_cb_.is_null()) << "Overlapping reads are not supported"; |
426 read_cb_ = BindToCurrentLoop(read_cb); | 426 read_cb_ = base::BindToCurrentLoop(read_cb); |
427 | 427 |
428 // Don't accept any additional reads if we've been told to stop. | 428 // Don't accept any additional reads if we've been told to stop. |
429 // The |demuxer_| may have been destroyed in the pipeline thread. | 429 // The |demuxer_| may have been destroyed in the pipeline thread. |
430 // | 430 // |
431 // TODO(scherkus): it would be cleaner to reply with an error message. | 431 // TODO(scherkus): it would be cleaner to reply with an error message. |
432 if (!demuxer_) { | 432 if (!demuxer_) { |
433 base::ResetAndReturn(&read_cb_).Run( | 433 base::ResetAndReturn(&read_cb_).Run( |
434 DemuxerStream::kOk, DecoderBuffer::CreateEOSBuffer()); | 434 DemuxerStream::kOk, DecoderBuffer::CreateEOSBuffer()); |
435 return; | 435 return; |
436 } | 436 } |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 &FFmpegDemuxer::OnSeekFrameDone, weak_factory_.GetWeakPtr(), cb)); | 670 &FFmpegDemuxer::OnSeekFrameDone, weak_factory_.GetWeakPtr(), cb)); |
671 } | 671 } |
672 | 672 |
673 void FFmpegDemuxer::Initialize(DemuxerHost* host, | 673 void FFmpegDemuxer::Initialize(DemuxerHost* host, |
674 const PipelineStatusCB& status_cb, | 674 const PipelineStatusCB& status_cb, |
675 bool enable_text_tracks) { | 675 bool enable_text_tracks) { |
676 DCHECK(task_runner_->BelongsToCurrentThread()); | 676 DCHECK(task_runner_->BelongsToCurrentThread()); |
677 host_ = host; | 677 host_ = host; |
678 text_enabled_ = enable_text_tracks; | 678 text_enabled_ = enable_text_tracks; |
679 | 679 |
680 url_protocol_.reset(new BlockingUrlProtocol(data_source_, BindToCurrentLoop( | 680 url_protocol_.reset(new BlockingUrlProtocol(data_source_, |
681 base::Bind(&FFmpegDemuxer::OnDataSourceError, base::Unretained(this))))); | 681 base::BindToCurrentLoop(base::Bind(&FFmpegDemuxer::OnDataSourceError, |
| 682 base::Unretained(this))))); |
682 glue_.reset(new FFmpegGlue(url_protocol_.get())); | 683 glue_.reset(new FFmpegGlue(url_protocol_.get())); |
683 AVFormatContext* format_context = glue_->format_context(); | 684 AVFormatContext* format_context = glue_->format_context(); |
684 | 685 |
685 // Disable ID3v1 tag reading to avoid costly seeks to end of file for data we | 686 // Disable ID3v1 tag reading to avoid costly seeks to end of file for data we |
686 // don't use. FFmpeg will only read ID3v1 tags if no other metadata is | 687 // don't use. FFmpeg will only read ID3v1 tags if no other metadata is |
687 // available, so add a metadata entry to ensure some is always present. | 688 // available, so add a metadata entry to ensure some is always present. |
688 av_dict_set(&format_context->metadata, "skip_id3v1_tags", "", 0); | 689 av_dict_set(&format_context->metadata, "skip_id3v1_tags", "", 0); |
689 | 690 |
690 // Ensure ffmpeg doesn't give up too early while looking for stream params; | 691 // Ensure ffmpeg doesn't give up too early while looking for stream params; |
691 // this does not increase the amount of data downloaded. The default value | 692 // this does not increase the amount of data downloaded. The default value |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1294 | 1295 |
1295 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { | 1296 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { |
1296 DCHECK(task_runner_->BelongsToCurrentThread()); | 1297 DCHECK(task_runner_->BelongsToCurrentThread()); |
1297 for (const auto& stream : streams_) { // |stream| is a ref to a pointer. | 1298 for (const auto& stream : streams_) { // |stream| is a ref to a pointer. |
1298 if (stream) | 1299 if (stream) |
1299 stream->SetLiveness(liveness); | 1300 stream->SetLiveness(liveness); |
1300 } | 1301 } |
1301 } | 1302 } |
1302 | 1303 |
1303 } // namespace media | 1304 } // namespace media |
OLD | NEW |