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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 // Ensure the codec is supported. IsValidConfig() also checks that the | 887 // Ensure the codec is supported. IsValidConfig() also checks that the |
879 // channel layout and sample format are valid. | 888 // channel layout and sample format are valid. |
880 AVStreamToAudioDecoderConfig(stream, &audio_config, false); | 889 AVStreamToAudioDecoderConfig(stream, &audio_config, false); |
881 if (!audio_config.IsValidConfig()) | 890 if (!audio_config.IsValidConfig()) |
882 continue; | 891 continue; |
883 audio_stream = stream; | 892 audio_stream = stream; |
884 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { | 893 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { |
885 if (video_stream) | 894 if (video_stream) |
886 continue; | 895 continue; |
887 | 896 |
| 897 |
| 898 #if defined(ENABLE_HEVC_DEMUXING) |
| 899 if (stream->codec->codec_id == AV_CODEC_ID_HEVC) { |
| 900 // If ffmpeg is built without HEVC parser/decoder support, it will be |
| 901 // able to demux HEVC based solely on container-provided information, |
| 902 // but unable to get some of the parameters without parsing the stream |
| 903 // (e.g. coded size needs to be read from SPS, pixel format is typically |
| 904 // deduced from decoder config in hvcC box). These are not really needed |
| 905 // when using external decoder (e.g. hardware decoder), so override them |
| 906 // here, to make sure this translates into a valid VideoDecoderConfig. |
| 907 if (stream->codec->coded_width == 0 && |
| 908 stream->codec->coded_height == 0) { |
| 909 DCHECK(stream->codec->width > 0); |
| 910 DCHECK(stream->codec->height > 0); |
| 911 stream->codec->coded_width = stream->codec->width; |
| 912 stream->codec->coded_height = stream->codec->height; |
| 913 } |
| 914 if (stream->codec->pix_fmt == AV_PIX_FMT_NONE) { |
| 915 stream->codec->pix_fmt = PIX_FMT_YUV420P; |
| 916 } |
| 917 } |
| 918 #endif |
888 // Log the codec detected, whether it is supported or not. | 919 // Log the codec detected, whether it is supported or not. |
889 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.DetectedVideoCodec", | 920 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.DetectedVideoCodec", |
890 codec_context->codec_id); | 921 codec_context->codec_id); |
891 // Ensure the codec is supported. IsValidConfig() also checks that the | 922 // Ensure the codec is supported. IsValidConfig() also checks that the |
892 // frame size and visible size are valid. | 923 // frame size and visible size are valid. |
893 AVStreamToVideoDecoderConfig(stream, &video_config, false); | 924 AVStreamToVideoDecoderConfig(stream, &video_config, false); |
894 | 925 |
895 if (!video_config.IsValidConfig()) | 926 if (!video_config.IsValidConfig()) |
896 continue; | 927 continue; |
897 video_stream = stream; | 928 video_stream = stream; |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1290 | 1321 |
1291 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { | 1322 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { |
1292 DCHECK(task_runner_->BelongsToCurrentThread()); | 1323 DCHECK(task_runner_->BelongsToCurrentThread()); |
1293 for (const auto& stream : streams_) { // |stream| is a ref to a pointer. | 1324 for (const auto& stream : streams_) { // |stream| is a ref to a pointer. |
1294 if (stream) | 1325 if (stream) |
1295 stream->SetLiveness(liveness); | 1326 stream->SetLiveness(liveness); |
1296 } | 1327 } |
1297 } | 1328 } |
1298 | 1329 |
1299 } // namespace media | 1330 } // namespace media |
OLD | NEW |