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 15 matching lines...) Expand all Loading... |
26 #include "media/base/limits.h" | 26 #include "media/base/limits.h" |
27 #include "media/base/media_log.h" | 27 #include "media/base/media_log.h" |
28 #include "media/ffmpeg/ffmpeg_common.h" | 28 #include "media/ffmpeg/ffmpeg_common.h" |
29 #include "media/filters/ffmpeg_aac_bitstream_converter.h" | 29 #include "media/filters/ffmpeg_aac_bitstream_converter.h" |
30 #include "media/filters/ffmpeg_bitstream_converter.h" | 30 #include "media/filters/ffmpeg_bitstream_converter.h" |
31 #include "media/filters/ffmpeg_glue.h" | 31 #include "media/filters/ffmpeg_glue.h" |
32 #include "media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.h" | 32 #include "media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.h" |
33 #include "media/filters/webvtt_util.h" | 33 #include "media/filters/webvtt_util.h" |
34 #include "media/formats/webm/webm_crypto_helpers.h" | 34 #include "media/formats/webm/webm_crypto_helpers.h" |
35 | 35 |
| 36 #if defined(USE_PROPRIETARY_CODECS) && defined(ENABLE_HEVC_DEMUXING) |
| 37 #include "media/filters/ffmpeg_h265_to_annex_b_bitstream_converter.h" |
| 38 #endif |
| 39 |
36 namespace media { | 40 namespace media { |
37 | 41 |
38 static base::Time ExtractTimelineOffset(AVFormatContext* format_context) { | 42 static base::Time ExtractTimelineOffset(AVFormatContext* format_context) { |
39 if (strstr(format_context->iformat->name, "webm") || | 43 if (strstr(format_context->iformat->name, "webm") || |
40 strstr(format_context->iformat->name, "matroska")) { | 44 strstr(format_context->iformat->name, "matroska")) { |
41 const AVDictionaryEntry* entry = | 45 const AVDictionaryEntry* entry = |
42 av_dict_get(format_context->metadata, "creation_time", NULL, 0); | 46 av_dict_get(format_context->metadata, "creation_time", NULL, 0); |
43 | 47 |
44 base::Time timeline_offset; | 48 base::Time timeline_offset; |
45 if (entry != NULL && entry->value != NULL && | 49 if (entry != NULL && entry->value != NULL && |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 if (bitstream_converter_) | 544 if (bitstream_converter_) |
541 InitBitstreamConverter(); | 545 InitBitstreamConverter(); |
542 #endif // defined(USE_PROPRIETARY_CODECS) | 546 #endif // defined(USE_PROPRIETARY_CODECS) |
543 } | 547 } |
544 | 548 |
545 void FFmpegDemuxerStream::InitBitstreamConverter() { | 549 void FFmpegDemuxerStream::InitBitstreamConverter() { |
546 #if defined(USE_PROPRIETARY_CODECS) | 550 #if defined(USE_PROPRIETARY_CODECS) |
547 if (stream_->codec->codec_id == AV_CODEC_ID_H264) { | 551 if (stream_->codec->codec_id == AV_CODEC_ID_H264) { |
548 bitstream_converter_.reset( | 552 bitstream_converter_.reset( |
549 new FFmpegH264ToAnnexBBitstreamConverter(stream_->codec)); | 553 new FFmpegH264ToAnnexBBitstreamConverter(stream_->codec)); |
| 554 #if defined(ENABLE_HEVC_DEMUXING) |
| 555 } else if (stream_->codec->codec_id == AV_CODEC_ID_HEVC) { |
| 556 bitstream_converter_.reset( |
| 557 new FFmpegH265ToAnnexBBitstreamConverter(stream_->codec)); |
| 558 #endif |
550 } else if (stream_->codec->codec_id == AV_CODEC_ID_AAC) { | 559 } else if (stream_->codec->codec_id == AV_CODEC_ID_AAC) { |
551 bitstream_converter_.reset( | 560 bitstream_converter_.reset( |
552 new FFmpegAACBitstreamConverter(stream_->codec)); | 561 new FFmpegAACBitstreamConverter(stream_->codec)); |
553 } | 562 } |
554 #endif // defined(USE_PROPRIETARY_CODECS) | 563 #endif // defined(USE_PROPRIETARY_CODECS) |
555 } | 564 } |
556 | 565 |
557 bool FFmpegDemuxerStream::SupportsConfigChanges() { return false; } | 566 bool FFmpegDemuxerStream::SupportsConfigChanges() { return false; } |
558 | 567 |
559 AudioDecoderConfig FFmpegDemuxerStream::audio_decoder_config() { | 568 AudioDecoderConfig FFmpegDemuxerStream::audio_decoder_config() { |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 // Ensure the codec is supported. IsValidConfig() also checks that the | 997 // Ensure the codec is supported. IsValidConfig() also checks that the |
989 // channel layout and sample format are valid. | 998 // channel layout and sample format are valid. |
990 AVStreamToAudioDecoderConfig(stream, &audio_config); | 999 AVStreamToAudioDecoderConfig(stream, &audio_config); |
991 if (!audio_config.IsValidConfig()) | 1000 if (!audio_config.IsValidConfig()) |
992 continue; | 1001 continue; |
993 audio_stream = stream; | 1002 audio_stream = stream; |
994 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { | 1003 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { |
995 if (video_stream) | 1004 if (video_stream) |
996 continue; | 1005 continue; |
997 | 1006 |
| 1007 |
| 1008 #if defined(ENABLE_HEVC_DEMUXING) |
| 1009 if (stream->codec->codec_id == AV_CODEC_ID_HEVC) { |
| 1010 // If ffmpeg is built without HEVC parser/decoder support, it will be |
| 1011 // able to demux HEVC based solely on container-provided information, |
| 1012 // but unable to get some of the parameters without parsing the stream |
| 1013 // (e.g. coded size needs to be read from SPS, pixel format is typically |
| 1014 // deduced from decoder config in hvcC box). These are not really needed |
| 1015 // when using external decoder (e.g. hardware decoder), so override them |
| 1016 // here, to make sure this translates into a valid VideoDecoderConfig. |
| 1017 if (stream->codec->coded_width == 0 && |
| 1018 stream->codec->coded_height == 0) { |
| 1019 DCHECK(stream->codec->width > 0); |
| 1020 DCHECK(stream->codec->height > 0); |
| 1021 stream->codec->coded_width = stream->codec->width; |
| 1022 stream->codec->coded_height = stream->codec->height; |
| 1023 } |
| 1024 if (stream->codec->pix_fmt == AV_PIX_FMT_NONE) { |
| 1025 stream->codec->pix_fmt = PIX_FMT_YUV420P; |
| 1026 } |
| 1027 } |
| 1028 #endif |
998 // Log the codec detected, whether it is supported or not. | 1029 // Log the codec detected, whether it is supported or not. |
999 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.DetectedVideoCodec", | 1030 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.DetectedVideoCodec", |
1000 codec_context->codec_id); | 1031 codec_context->codec_id); |
1001 // Ensure the codec is supported. IsValidConfig() also checks that the | 1032 // Ensure the codec is supported. IsValidConfig() also checks that the |
1002 // frame size and visible size are valid. | 1033 // frame size and visible size are valid. |
1003 AVStreamToVideoDecoderConfig(stream, &video_config); | 1034 AVStreamToVideoDecoderConfig(stream, &video_config); |
1004 | 1035 |
1005 if (!video_config.IsValidConfig()) | 1036 if (!video_config.IsValidConfig()) |
1006 continue; | 1037 continue; |
1007 video_stream = stream; | 1038 video_stream = stream; |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1412 | 1443 |
1413 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { | 1444 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { |
1414 DCHECK(task_runner_->BelongsToCurrentThread()); | 1445 DCHECK(task_runner_->BelongsToCurrentThread()); |
1415 for (const auto& stream : streams_) { // |stream| is a ref to a pointer. | 1446 for (const auto& stream : streams_) { // |stream| is a ref to a pointer. |
1416 if (stream) | 1447 if (stream) |
1417 stream->SetLiveness(liveness); | 1448 stream->SetLiveness(liveness); |
1418 } | 1449 } |
1419 } | 1450 } |
1420 | 1451 |
1421 } // namespace media | 1452 } // namespace media |
OLD | NEW |