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 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "media/base/limits.h" | 24 #include "media/base/limits.h" |
25 #include "media/base/media_log.h" | 25 #include "media/base/media_log.h" |
26 #include "media/ffmpeg/ffmpeg_common.h" | 26 #include "media/ffmpeg/ffmpeg_common.h" |
27 #include "media/filters/ffmpeg_aac_bitstream_converter.h" | 27 #include "media/filters/ffmpeg_aac_bitstream_converter.h" |
28 #include "media/filters/ffmpeg_bitstream_converter.h" | 28 #include "media/filters/ffmpeg_bitstream_converter.h" |
29 #include "media/filters/ffmpeg_glue.h" | 29 #include "media/filters/ffmpeg_glue.h" |
30 #include "media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.h" | 30 #include "media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.h" |
31 #include "media/filters/webvtt_util.h" | 31 #include "media/filters/webvtt_util.h" |
32 #include "media/formats/webm/webm_crypto_helpers.h" | 32 #include "media/formats/webm/webm_crypto_helpers.h" |
33 | 33 |
| 34 #if defined(USE_PROPRIETARY_CODECS) && defined(ENABLE_HEVC_DEMUXING) |
| 35 #include "media/filters/ffmpeg_h265_to_annex_b_bitstream_converter.h" |
| 36 #endif |
| 37 |
34 namespace media { | 38 namespace media { |
35 | 39 |
36 static base::Time ExtractTimelineOffset(AVFormatContext* format_context) { | 40 static base::Time ExtractTimelineOffset(AVFormatContext* format_context) { |
37 if (strstr(format_context->iformat->name, "webm") || | 41 if (strstr(format_context->iformat->name, "webm") || |
38 strstr(format_context->iformat->name, "matroska")) { | 42 strstr(format_context->iformat->name, "matroska")) { |
39 const AVDictionaryEntry* entry = | 43 const AVDictionaryEntry* entry = |
40 av_dict_get(format_context->metadata, "creation_time", NULL, 0); | 44 av_dict_get(format_context->metadata, "creation_time", NULL, 0); |
41 | 45 |
42 base::Time timeline_offset; | 46 base::Time timeline_offset; |
43 if (entry != NULL && entry->value != NULL && | 47 if (entry != NULL && entry->value != NULL && |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 if (bitstream_converter_) | 453 if (bitstream_converter_) |
450 InitBitstreamConverter(); | 454 InitBitstreamConverter(); |
451 #endif // defined(USE_PROPRIETARY_CODECS) | 455 #endif // defined(USE_PROPRIETARY_CODECS) |
452 } | 456 } |
453 | 457 |
454 void FFmpegDemuxerStream::InitBitstreamConverter() { | 458 void FFmpegDemuxerStream::InitBitstreamConverter() { |
455 #if defined(USE_PROPRIETARY_CODECS) | 459 #if defined(USE_PROPRIETARY_CODECS) |
456 if (stream_->codec->codec_id == AV_CODEC_ID_H264) { | 460 if (stream_->codec->codec_id == AV_CODEC_ID_H264) { |
457 bitstream_converter_.reset( | 461 bitstream_converter_.reset( |
458 new FFmpegH264ToAnnexBBitstreamConverter(stream_->codec)); | 462 new FFmpegH264ToAnnexBBitstreamConverter(stream_->codec)); |
| 463 #if defined(ENABLE_HEVC_DEMUXING) |
| 464 } else if (stream_->codec->codec_id == AV_CODEC_ID_HEVC) { |
| 465 bitstream_converter_.reset( |
| 466 new FFmpegH265ToAnnexBBitstreamConverter(stream_->codec)); |
| 467 #endif |
459 } else if (stream_->codec->codec_id == AV_CODEC_ID_AAC) { | 468 } else if (stream_->codec->codec_id == AV_CODEC_ID_AAC) { |
460 bitstream_converter_.reset( | 469 bitstream_converter_.reset( |
461 new FFmpegAACBitstreamConverter(stream_->codec)); | 470 new FFmpegAACBitstreamConverter(stream_->codec)); |
462 } | 471 } |
463 #endif // defined(USE_PROPRIETARY_CODECS) | 472 #endif // defined(USE_PROPRIETARY_CODECS) |
464 } | 473 } |
465 | 474 |
466 bool FFmpegDemuxerStream::SupportsConfigChanges() { return false; } | 475 bool FFmpegDemuxerStream::SupportsConfigChanges() { return false; } |
467 | 476 |
468 AudioDecoderConfig FFmpegDemuxerStream::audio_decoder_config() { | 477 AudioDecoderConfig FFmpegDemuxerStream::audio_decoder_config() { |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 // Ensure the codec is supported. IsValidConfig() also checks that the | 896 // Ensure the codec is supported. IsValidConfig() also checks that the |
888 // channel layout and sample format are valid. | 897 // channel layout and sample format are valid. |
889 AVStreamToAudioDecoderConfig(stream, &audio_config, false); | 898 AVStreamToAudioDecoderConfig(stream, &audio_config, false); |
890 if (!audio_config.IsValidConfig()) | 899 if (!audio_config.IsValidConfig()) |
891 continue; | 900 continue; |
892 audio_stream = stream; | 901 audio_stream = stream; |
893 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { | 902 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { |
894 if (video_stream) | 903 if (video_stream) |
895 continue; | 904 continue; |
896 | 905 |
| 906 |
| 907 #if defined(ENABLE_HEVC_DEMUXING) |
| 908 if (stream->codec->codec_id == AV_CODEC_ID_HEVC) { |
| 909 // If ffmpeg is built without HEVC parser/decoder support, it will be |
| 910 // able to demux HEVC based solely on container-provided information, |
| 911 // but unable to get some of the parameters without parsing the stream |
| 912 // (e.g. coded size needs to be read from SPS, pixel format is typically |
| 913 // deduced from decoder config in hvcC box). These are not really needed |
| 914 // when using external decoder (e.g. hardware decoder), so override them |
| 915 // here, to make sure this translates into a valid VideoDecoderConfig. |
| 916 if (stream->codec->coded_width == 0 && |
| 917 stream->codec->coded_height == 0) { |
| 918 DCHECK(stream->codec->width > 0); |
| 919 DCHECK(stream->codec->height > 0); |
| 920 stream->codec->coded_width = stream->codec->width; |
| 921 stream->codec->coded_height = stream->codec->height; |
| 922 } |
| 923 if (stream->codec->pix_fmt == AV_PIX_FMT_NONE) { |
| 924 stream->codec->pix_fmt = PIX_FMT_YUV420P; |
| 925 } |
| 926 } |
| 927 #endif |
897 // Log the codec detected, whether it is supported or not. | 928 // Log the codec detected, whether it is supported or not. |
898 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.DetectedVideoCodec", | 929 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.DetectedVideoCodec", |
899 codec_context->codec_id); | 930 codec_context->codec_id); |
900 // Ensure the codec is supported. IsValidConfig() also checks that the | 931 // Ensure the codec is supported. IsValidConfig() also checks that the |
901 // frame size and visible size are valid. | 932 // frame size and visible size are valid. |
902 AVStreamToVideoDecoderConfig(stream, &video_config, false); | 933 AVStreamToVideoDecoderConfig(stream, &video_config, false); |
903 | 934 |
904 if (!video_config.IsValidConfig()) | 935 if (!video_config.IsValidConfig()) |
905 continue; | 936 continue; |
906 video_stream = stream; | 937 video_stream = stream; |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1303 | 1334 |
1304 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { | 1335 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { |
1305 DCHECK(task_runner_->BelongsToCurrentThread()); | 1336 DCHECK(task_runner_->BelongsToCurrentThread()); |
1306 for (const auto& stream : streams_) { // |stream| is a ref to a pointer. | 1337 for (const auto& stream : streams_) { // |stream| is a ref to a pointer. |
1307 if (stream) | 1338 if (stream) |
1308 stream->SetLiveness(liveness); | 1339 stream->SetLiveness(liveness); |
1309 } | 1340 } |
1310 } | 1341 } |
1311 | 1342 |
1312 } // namespace media | 1343 } // namespace media |
OLD | NEW |