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/callback.h" | 12 #include "base/callback.h" |
13 #include "base/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/metrics/sparse_histogram.h" | 17 #include "base/metrics/sparse_histogram.h" |
18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
20 #include "base/strings/stringprintf.h" | |
20 #include "base/task_runner_util.h" | 21 #include "base/task_runner_util.h" |
21 #include "base/time/time.h" | 22 #include "base/time/time.h" |
22 #include "media/base/audio_decoder_config.h" | 23 #include "media/base/audio_decoder_config.h" |
23 #include "media/base/bind_to_loop.h" | 24 #include "media/base/bind_to_loop.h" |
24 #include "media/base/decoder_buffer.h" | 25 #include "media/base/decoder_buffer.h" |
25 #include "media/base/decrypt_config.h" | 26 #include "media/base/decrypt_config.h" |
26 #include "media/base/limits.h" | 27 #include "media/base/limits.h" |
27 #include "media/base/media_log.h" | 28 #include "media/base/media_log.h" |
28 #include "media/base/media_switches.h" | 29 #include "media/base/media_switches.h" |
29 #include "media/base/video_decoder_config.h" | 30 #include "media/base/video_decoder_config.h" |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
484 status_cb.Run(DEMUXER_ERROR_COULD_NOT_PARSE); | 485 status_cb.Run(DEMUXER_ERROR_COULD_NOT_PARSE); |
485 return; | 486 return; |
486 } | 487 } |
487 | 488 |
488 // Create demuxer stream entries for each possible AVStream. Each stream | 489 // Create demuxer stream entries for each possible AVStream. Each stream |
489 // is examined to determine if it is supported or not (is the codec enabled | 490 // is examined to determine if it is supported or not (is the codec enabled |
490 // for it in this release?). Unsupported streams are skipped, allowing for | 491 // for it in this release?). Unsupported streams are skipped, allowing for |
491 // partial playback. At least one audio or video stream must be playable. | 492 // partial playback. At least one audio or video stream must be playable. |
492 AVFormatContext* format_context = glue_->format_context(); | 493 AVFormatContext* format_context = glue_->format_context(); |
493 streams_.resize(format_context->nb_streams); | 494 streams_.resize(format_context->nb_streams); |
495 | |
494 bool found_audio_stream = false; | 496 bool found_audio_stream = false; |
DaleCurtis
2013/08/05 19:58:39
You can remove the bool's now that we can just che
Ty Overby
2013/08/05 20:14:59
??? We still use found_audio_stream and found_vid
DaleCurtis
2013/08/05 20:19:22
Yeah.
| |
497 AVStream* audio_stream = nullptr; | |
DaleCurtis
2013/08/05 19:58:39
We're still not C++11 enabled, so this should be N
Ty Overby
2013/08/05 20:14:59
Done.
| |
498 AudioDecoderConfig audio_config; | |
499 | |
495 bool found_video_stream = false; | 500 bool found_video_stream = false; |
501 AVStream* video_stream = nullptr; | |
DaleCurtis
2013/08/05 19:58:39
Ditto.
Ty Overby
2013/08/05 20:14:59
Done.
| |
502 VideoDecoderConfig video_config; | |
496 | 503 |
497 base::TimeDelta max_duration; | 504 base::TimeDelta max_duration; |
498 for (size_t i = 0; i < format_context->nb_streams; ++i) { | 505 for (size_t i = 0; i < format_context->nb_streams; ++i) { |
499 AVStream* stream = format_context->streams[i]; | 506 AVStream* stream = format_context->streams[i]; |
500 AVCodecContext* codec_context = stream->codec; | 507 AVCodecContext* codec_context = stream->codec; |
501 AVMediaType codec_type = codec_context->codec_type; | 508 AVMediaType codec_type = codec_context->codec_type; |
502 | 509 |
503 if (codec_type == AVMEDIA_TYPE_AUDIO) { | 510 if (codec_type == AVMEDIA_TYPE_AUDIO) { |
504 if (found_audio_stream) | 511 if (found_audio_stream) |
505 continue; | 512 continue; |
513 audio_stream = stream; | |
514 | |
506 // Log the codec detected, whether it is supported or not. | 515 // Log the codec detected, whether it is supported or not. |
507 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.DetectedAudioCodec", | 516 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.DetectedAudioCodec", |
508 codec_context->codec_id); | 517 codec_context->codec_id); |
509 // Ensure the codec is supported. IsValidConfig() also checks that the | 518 // Ensure the codec is supported. IsValidConfig() also checks that the |
510 // channel layout and sample format are valid. | 519 // channel layout and sample format are valid. |
511 AudioDecoderConfig audio_config; | |
512 AVStreamToAudioDecoderConfig(stream, &audio_config, false); | 520 AVStreamToAudioDecoderConfig(stream, &audio_config, false); |
513 if (!audio_config.IsValidConfig()) | 521 if (!audio_config.IsValidConfig()) |
514 continue; | 522 continue; |
515 found_audio_stream = true; | 523 found_audio_stream = true; |
516 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { | 524 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { |
517 if (found_video_stream) | 525 if (found_video_stream) |
518 continue; | 526 continue; |
527 video_stream = stream; | |
528 | |
519 // Log the codec detected, whether it is supported or not. | 529 // Log the codec detected, whether it is supported or not. |
520 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.DetectedVideoCodec", | 530 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.DetectedVideoCodec", |
521 codec_context->codec_id); | 531 codec_context->codec_id); |
522 // Ensure the codec is supported. IsValidConfig() also checks that the | 532 // Ensure the codec is supported. IsValidConfig() also checks that the |
523 // frame size and visible size are valid. | 533 // frame size and visible size are valid. |
524 VideoDecoderConfig video_config; | |
525 AVStreamToVideoDecoderConfig(stream, &video_config, false); | 534 AVStreamToVideoDecoderConfig(stream, &video_config, false); |
535 | |
526 if (!video_config.IsValidConfig()) | 536 if (!video_config.IsValidConfig()) |
527 continue; | 537 continue; |
528 found_video_stream = true; | 538 found_video_stream = true; |
529 } else { | 539 } else { |
530 continue; | 540 continue; |
531 } | 541 } |
532 | 542 |
533 streams_[i] = new FFmpegDemuxerStream(this, stream); | 543 streams_[i] = new FFmpegDemuxerStream(this, stream); |
534 max_duration = std::max(max_duration, streams_[i]->duration()); | 544 max_duration = std::max(max_duration, streams_[i]->duration()); |
535 | 545 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 // initializing. | 582 // initializing. |
573 host_->SetDuration(max_duration); | 583 host_->SetDuration(max_duration); |
574 duration_known_ = (max_duration != kInfiniteDuration()); | 584 duration_known_ = (max_duration != kInfiniteDuration()); |
575 | 585 |
576 int64 filesize_in_bytes = 0; | 586 int64 filesize_in_bytes = 0; |
577 url_protocol_.GetSize(&filesize_in_bytes); | 587 url_protocol_.GetSize(&filesize_in_bytes); |
578 bitrate_ = CalculateBitrate(format_context, max_duration, filesize_in_bytes); | 588 bitrate_ = CalculateBitrate(format_context, max_duration, filesize_in_bytes); |
579 if (bitrate_ > 0) | 589 if (bitrate_ > 0) |
580 data_source_->SetBitrate(bitrate_); | 590 data_source_->SetBitrate(bitrate_); |
581 | 591 |
592 // Audio logging | |
593 if (found_audio_stream) { | |
594 AVCodecContext* audio_codec = audio_stream->codec; | |
595 media_log_->SetBooleanProperty("found_audio_stream", true); | |
DaleCurtis
2013/08/05 19:58:39
Else set to false?
Ty Overby
2013/08/05 20:14:59
Done.
Ty Overby
2013/08/05 20:14:59
Done.
| |
596 media_log_->SetStringProperty("audio_codec_name", | |
597 audio_codec->codec_name); | |
598 media_log_->SetIntegerProperty("audio_sample_rate", | |
599 audio_codec->sample_rate); | |
600 media_log_->SetIntegerProperty("audio_channels_count", | |
601 audio_codec->channels); | |
602 media_log_->SetIntegerProperty("audio_samples_per_second", | |
603 audio_config.samples_per_second()); | |
604 } | |
605 | |
606 // Video logging | |
607 if (found_video_stream) { | |
608 AVCodecContext* video_codec = video_stream->codec; | |
609 media_log_->SetBooleanProperty("found_video_stream", true); | |
DaleCurtis
2013/08/05 19:58:39
Ditto?
Ty Overby
2013/08/05 20:14:59
Done.
| |
610 std::string codec_name = avcodec_get_name(video_codec->codec_id); | |
611 media_log_->SetStringProperty("video_codec_name", codec_name); | |
612 media_log_->SetIntegerProperty("width", video_codec->width); | |
613 media_log_->SetIntegerProperty("height", video_codec->height); | |
614 media_log_->SetIntegerProperty("coded_width", | |
615 video_codec->coded_width); | |
616 media_log_->SetIntegerProperty("coded_height", | |
617 video_codec->coded_height); | |
618 media_log_->SetStringProperty( | |
619 "time_base", | |
620 base::StringPrintf("%d/%d", | |
621 video_codec->time_base.num, | |
622 video_codec->time_base.den)); | |
623 media_log_->SetStringProperty( | |
624 "video_format", VideoFrame::FormatToString(video_config.format())); | |
625 media_log_->SetBooleanProperty("video_is_encrypted", | |
626 video_config.is_encrypted()); | |
627 } | |
628 | |
629 media_log_->SetDoubleProperty("max_duration", max_duration.InSecondsF()); | |
630 media_log_->SetDoubleProperty("start_time", start_time_.InSecondsF()); | |
631 media_log_->SetStringProperty("filesize_in_bytes", | |
632 std::to_string(filesize_in_bytes)); | |
DaleCurtis
2013/08/05 19:58:39
Indent.
Ty Overby
2013/08/05 20:14:59
Done.
| |
633 media_log_->SetIntegerProperty("bitrate", bitrate_); | |
634 | |
582 status_cb.Run(PIPELINE_OK); | 635 status_cb.Run(PIPELINE_OK); |
583 } | 636 } |
584 | 637 |
585 void FFmpegDemuxer::OnSeekFrameDone(const PipelineStatusCB& cb, int result) { | 638 void FFmpegDemuxer::OnSeekFrameDone(const PipelineStatusCB& cb, int result) { |
586 DCHECK(message_loop_->BelongsToCurrentThread()); | 639 DCHECK(message_loop_->BelongsToCurrentThread()); |
587 CHECK(pending_seek_); | 640 CHECK(pending_seek_); |
588 pending_seek_ = false; | 641 pending_seek_ = false; |
589 | 642 |
590 if (!blocking_thread_.IsRunning()) { | 643 if (!blocking_thread_.IsRunning()) { |
591 cb.Run(PIPELINE_ERROR_ABORT); | 644 cb.Run(PIPELINE_ERROR_ABORT); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
777 } | 830 } |
778 for (size_t i = 0; i < buffered.size(); ++i) | 831 for (size_t i = 0; i < buffered.size(); ++i) |
779 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i)); | 832 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i)); |
780 } | 833 } |
781 | 834 |
782 void FFmpegDemuxer::OnDataSourceError() { | 835 void FFmpegDemuxer::OnDataSourceError() { |
783 host_->OnDemuxerError(PIPELINE_ERROR_READ); | 836 host_->OnDemuxerError(PIPELINE_ERROR_READ); |
784 } | 837 } |
785 | 838 |
786 } // namespace media | 839 } // namespace media |
OLD | NEW |