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" |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 blocking_thread_("FFmpegDemuxer"), | 358 blocking_thread_("FFmpegDemuxer"), |
359 pending_read_(false), | 359 pending_read_(false), |
360 pending_seek_(false), | 360 pending_seek_(false), |
361 data_source_(data_source), | 361 data_source_(data_source), |
362 media_log_(media_log), | 362 media_log_(media_log), |
363 bitrate_(0), | 363 bitrate_(0), |
364 start_time_(kNoTimestamp()), | 364 start_time_(kNoTimestamp()), |
365 audio_disabled_(false), | 365 audio_disabled_(false), |
366 text_enabled_(false), | 366 text_enabled_(false), |
367 duration_known_(false), | 367 duration_known_(false), |
368 url_protocol_(data_source, BindToLoop(task_runner_, base::Bind( | |
369 &FFmpegDemuxer::OnDataSourceError, base::Unretained(this)))), | |
370 need_key_cb_(need_key_cb) { | 368 need_key_cb_(need_key_cb) { |
371 DCHECK(task_runner_.get()); | 369 DCHECK(task_runner_.get()); |
372 DCHECK(data_source_); | 370 DCHECK(data_source_); |
373 } | 371 } |
374 | 372 |
375 FFmpegDemuxer::~FFmpegDemuxer() {} | 373 FFmpegDemuxer::~FFmpegDemuxer() {} |
376 | 374 |
377 void FFmpegDemuxer::Stop(const base::Closure& callback) { | 375 void FFmpegDemuxer::Stop(const base::Closure& callback) { |
378 DCHECK(task_runner_->BelongsToCurrentThread()); | 376 DCHECK(task_runner_->BelongsToCurrentThread()); |
379 url_protocol_.Abort(); | 377 url_protocol_->Abort(); |
380 data_source_->Stop(BindToCurrentLoop(base::Bind( | 378 data_source_->Stop(BindToCurrentLoop(base::Bind( |
381 &FFmpegDemuxer::OnDataSourceStopped, weak_this_, | 379 &FFmpegDemuxer::OnDataSourceStopped, weak_this_, |
382 BindToCurrentLoop(callback)))); | 380 BindToCurrentLoop(callback)))); |
383 data_source_ = NULL; | 381 data_source_ = NULL; |
384 } | 382 } |
385 | 383 |
386 void FFmpegDemuxer::Seek(base::TimeDelta time, const PipelineStatusCB& cb) { | 384 void FFmpegDemuxer::Seek(base::TimeDelta time, const PipelineStatusCB& cb) { |
387 DCHECK(task_runner_->BelongsToCurrentThread()); | 385 DCHECK(task_runner_->BelongsToCurrentThread()); |
388 CHECK(!pending_seek_); | 386 CHECK(!pending_seek_); |
389 | 387 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 bool enable_text_tracks) { | 423 bool enable_text_tracks) { |
426 DCHECK(task_runner_->BelongsToCurrentThread()); | 424 DCHECK(task_runner_->BelongsToCurrentThread()); |
427 host_ = host; | 425 host_ = host; |
428 weak_this_ = weak_factory_.GetWeakPtr(); | 426 weak_this_ = weak_factory_.GetWeakPtr(); |
429 text_enabled_ = enable_text_tracks; | 427 text_enabled_ = enable_text_tracks; |
430 | 428 |
431 // TODO(scherkus): DataSource should have a host by this point, | 429 // TODO(scherkus): DataSource should have a host by this point, |
432 // see http://crbug.com/122071 | 430 // see http://crbug.com/122071 |
433 data_source_->set_host(host); | 431 data_source_->set_host(host); |
434 | 432 |
435 glue_.reset(new FFmpegGlue(&url_protocol_)); | 433 url_protocol_.reset(new BlockingUrlProtocol(data_source_, BindToCurrentLoop( |
| 434 base::Bind(&FFmpegDemuxer::OnDataSourceError, base::Unretained(this))))); |
| 435 glue_.reset(new FFmpegGlue(url_protocol_.get())); |
436 AVFormatContext* format_context = glue_->format_context(); | 436 AVFormatContext* format_context = glue_->format_context(); |
437 | 437 |
438 // Disable ID3v1 tag reading to avoid costly seeks to end of file for data we | 438 // Disable ID3v1 tag reading to avoid costly seeks to end of file for data we |
439 // don't use. FFmpeg will only read ID3v1 tags if no other metadata is | 439 // don't use. FFmpeg will only read ID3v1 tags if no other metadata is |
440 // available, so add a metadata entry to ensure some is always present. | 440 // available, so add a metadata entry to ensure some is always present. |
441 av_dict_set(&format_context->metadata, "skip_id3v1_tags", "", 0); | 441 av_dict_set(&format_context->metadata, "skip_id3v1_tags", "", 0); |
442 | 442 |
443 // Open the AVFormatContext using our glue layer. | 443 // Open the AVFormatContext using our glue layer. |
444 CHECK(blocking_thread_.Start()); | 444 CHECK(blocking_thread_.Start()); |
445 base::PostTaskAndReplyWithResult( | 445 base::PostTaskAndReplyWithResult( |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 // generation so we always get timestamps, see http://crbug.com/169570 | 655 // generation so we always get timestamps, see http://crbug.com/169570 |
656 if (strcmp(format_context->iformat->name, "avi") == 0) | 656 if (strcmp(format_context->iformat->name, "avi") == 0) |
657 format_context->flags |= AVFMT_FLAG_GENPTS; | 657 format_context->flags |= AVFMT_FLAG_GENPTS; |
658 | 658 |
659 // Good to go: set the duration and bitrate and notify we're done | 659 // Good to go: set the duration and bitrate and notify we're done |
660 // initializing. | 660 // initializing. |
661 host_->SetDuration(max_duration); | 661 host_->SetDuration(max_duration); |
662 duration_known_ = (max_duration != kInfiniteDuration()); | 662 duration_known_ = (max_duration != kInfiniteDuration()); |
663 | 663 |
664 int64 filesize_in_bytes = 0; | 664 int64 filesize_in_bytes = 0; |
665 url_protocol_.GetSize(&filesize_in_bytes); | 665 url_protocol_->GetSize(&filesize_in_bytes); |
666 bitrate_ = CalculateBitrate(format_context, max_duration, filesize_in_bytes); | 666 bitrate_ = CalculateBitrate(format_context, max_duration, filesize_in_bytes); |
667 if (bitrate_ > 0) | 667 if (bitrate_ > 0) |
668 data_source_->SetBitrate(bitrate_); | 668 data_source_->SetBitrate(bitrate_); |
669 | 669 |
670 // Audio logging | 670 // Audio logging |
671 if (audio_stream) { | 671 if (audio_stream) { |
672 AVCodecContext* audio_codec = audio_stream->codec; | 672 AVCodecContext* audio_codec = audio_stream->codec; |
673 media_log_->SetBooleanProperty("found_audio_stream", true); | 673 media_log_->SetBooleanProperty("found_audio_stream", true); |
674 | 674 |
675 SampleFormat sample_format = audio_config.sample_format(); | 675 SampleFormat sample_format = audio_config.sample_format(); |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 } | 935 } |
936 for (size_t i = 0; i < buffered.size(); ++i) | 936 for (size_t i = 0; i < buffered.size(); ++i) |
937 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i)); | 937 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i)); |
938 } | 938 } |
939 | 939 |
940 void FFmpegDemuxer::OnDataSourceError() { | 940 void FFmpegDemuxer::OnDataSourceError() { |
941 host_->OnDemuxerError(PIPELINE_ERROR_READ); | 941 host_->OnDemuxerError(PIPELINE_ERROR_READ); |
942 } | 942 } |
943 | 943 |
944 } // namespace media | 944 } // namespace media |
OLD | NEW |