| 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 17 matching lines...) Expand all Loading... |
| 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" |
| 35 #include "media/filters/webvtt_util.h" | 35 #include "media/filters/webvtt_util.h" |
| 36 #include "media/formats/webm/webm_crypto_helpers.h" | 36 #include "media/formats/webm/webm_crypto_helpers.h" |
| 37 | 37 |
| 38 #if defined(USE_PROPRIETARY_CODECS) && defined(ENABLE_HEVC_DEMUXING) |
| 39 #include "media/filters/ffmpeg_h265_to_annex_b_bitstream_converter.h" |
| 40 #endif |
| 41 |
| 38 namespace media { | 42 namespace media { |
| 39 | 43 |
| 40 static base::Time ExtractTimelineOffset(AVFormatContext* format_context) { | 44 static base::Time ExtractTimelineOffset(AVFormatContext* format_context) { |
| 41 if (strstr(format_context->iformat->name, "webm") || | 45 if (strstr(format_context->iformat->name, "webm") || |
| 42 strstr(format_context->iformat->name, "matroska")) { | 46 strstr(format_context->iformat->name, "matroska")) { |
| 43 const AVDictionaryEntry* entry = | 47 const AVDictionaryEntry* entry = |
| 44 av_dict_get(format_context->metadata, "creation_time", NULL, 0); | 48 av_dict_get(format_context->metadata, "creation_time", NULL, 0); |
| 45 | 49 |
| 46 base::Time timeline_offset; | 50 base::Time timeline_offset; |
| 47 if (entry != NULL && entry->value != NULL && | 51 if (entry != NULL && entry->value != NULL && |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 if (bitstream_converter_) | 457 if (bitstream_converter_) |
| 454 InitBitstreamConverter(); | 458 InitBitstreamConverter(); |
| 455 #endif // defined(USE_PROPRIETARY_CODECS) | 459 #endif // defined(USE_PROPRIETARY_CODECS) |
| 456 } | 460 } |
| 457 | 461 |
| 458 void FFmpegDemuxerStream::InitBitstreamConverter() { | 462 void FFmpegDemuxerStream::InitBitstreamConverter() { |
| 459 #if defined(USE_PROPRIETARY_CODECS) | 463 #if defined(USE_PROPRIETARY_CODECS) |
| 460 if (stream_->codec->codec_id == AV_CODEC_ID_H264) { | 464 if (stream_->codec->codec_id == AV_CODEC_ID_H264) { |
| 461 bitstream_converter_.reset( | 465 bitstream_converter_.reset( |
| 462 new FFmpegH264ToAnnexBBitstreamConverter(stream_->codec)); | 466 new FFmpegH264ToAnnexBBitstreamConverter(stream_->codec)); |
| 467 #if defined(ENABLE_HEVC_DEMUXING) |
| 468 } else if (stream_->codec->codec_id == AV_CODEC_ID_HEVC) { |
| 469 bitstream_converter_.reset( |
| 470 new FFmpegH265ToAnnexBBitstreamConverter(stream_->codec)); |
| 471 #endif |
| 463 } else if (stream_->codec->codec_id == AV_CODEC_ID_AAC) { | 472 } else if (stream_->codec->codec_id == AV_CODEC_ID_AAC) { |
| 464 bitstream_converter_.reset( | 473 bitstream_converter_.reset( |
| 465 new FFmpegAACBitstreamConverter(stream_->codec)); | 474 new FFmpegAACBitstreamConverter(stream_->codec)); |
| 466 } | 475 } |
| 467 #endif // defined(USE_PROPRIETARY_CODECS) | 476 #endif // defined(USE_PROPRIETARY_CODECS) |
| 468 } | 477 } |
| 469 | 478 |
| 470 bool FFmpegDemuxerStream::SupportsConfigChanges() { return false; } | 479 bool FFmpegDemuxerStream::SupportsConfigChanges() { return false; } |
| 471 | 480 |
| 472 AudioDecoderConfig FFmpegDemuxerStream::audio_decoder_config() { | 481 AudioDecoderConfig FFmpegDemuxerStream::audio_decoder_config() { |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 // Ensure the codec is supported. IsValidConfig() also checks that the | 890 // Ensure the codec is supported. IsValidConfig() also checks that the |
| 882 // channel layout and sample format are valid. | 891 // channel layout and sample format are valid. |
| 883 AVStreamToAudioDecoderConfig(stream, &audio_config, false); | 892 AVStreamToAudioDecoderConfig(stream, &audio_config, false); |
| 884 if (!audio_config.IsValidConfig()) | 893 if (!audio_config.IsValidConfig()) |
| 885 continue; | 894 continue; |
| 886 audio_stream = stream; | 895 audio_stream = stream; |
| 887 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { | 896 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { |
| 888 if (video_stream) | 897 if (video_stream) |
| 889 continue; | 898 continue; |
| 890 | 899 |
| 900 |
| 901 #if defined(ENABLE_HEVC_DEMUXING) |
| 902 if (stream->codec->codec_id == AV_CODEC_ID_HEVC) { |
| 903 // If ffmpeg is built without HEVC parser/decoder support, it will be |
| 904 // able to demux HEVC based solely on container-provided information, |
| 905 // but unable to get some of the parameters without parsing the stream |
| 906 // (e.g. coded size needs to be read from SPS, pixel format is typically |
| 907 // deduced from decoder config in hvcC box). These are not really needed |
| 908 // when using external decoder (e.g. hardware decoder), so override them |
| 909 // here, to make sure this translates into a valid VideoDecoderConfig. |
| 910 if (stream->codec->coded_width == 0 && |
| 911 stream->codec->coded_height == 0) { |
| 912 DCHECK(stream->codec->width > 0); |
| 913 DCHECK(stream->codec->height > 0); |
| 914 stream->codec->coded_width = stream->codec->width; |
| 915 stream->codec->coded_height = stream->codec->height; |
| 916 } |
| 917 if (stream->codec->pix_fmt == AV_PIX_FMT_NONE) { |
| 918 stream->codec->pix_fmt = PIX_FMT_YUV420P; |
| 919 } |
| 920 } |
| 921 #endif |
| 891 // Log the codec detected, whether it is supported or not. | 922 // Log the codec detected, whether it is supported or not. |
| 892 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.DetectedVideoCodec", | 923 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.DetectedVideoCodec", |
| 893 codec_context->codec_id); | 924 codec_context->codec_id); |
| 894 // Ensure the codec is supported. IsValidConfig() also checks that the | 925 // Ensure the codec is supported. IsValidConfig() also checks that the |
| 895 // frame size and visible size are valid. | 926 // frame size and visible size are valid. |
| 896 AVStreamToVideoDecoderConfig(stream, &video_config, false); | 927 AVStreamToVideoDecoderConfig(stream, &video_config, false); |
| 897 | 928 |
| 898 if (!video_config.IsValidConfig()) | 929 if (!video_config.IsValidConfig()) |
| 899 continue; | 930 continue; |
| 900 video_stream = stream; | 931 video_stream = stream; |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1293 | 1324 |
| 1294 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { | 1325 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { |
| 1295 DCHECK(task_runner_->BelongsToCurrentThread()); | 1326 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 1296 for (const auto& stream : streams_) { // |stream| is a ref to a pointer. | 1327 for (const auto& stream : streams_) { // |stream| is a ref to a pointer. |
| 1297 if (stream) | 1328 if (stream) |
| 1298 stream->SetLiveness(liveness); | 1329 stream->SetLiveness(liveness); |
| 1299 } | 1330 } |
| 1300 } | 1331 } |
| 1301 | 1332 |
| 1302 } // namespace media | 1333 } // namespace media |
| OLD | NEW |