240 lines
10 KiB
Diff
240 lines
10 KiB
Diff
From: uazo <uazo@users.noreply.github.com>
|
|
Date: Wed, 6 Mar 2024 12:05:52 +0000
|
|
Subject: Enable platform aac audio and h264 video
|
|
|
|
Allows the activation in android and windows of aac and
|
|
h264 decoding via the s.o. libraries, replacing ffmpeg which does
|
|
not have the necessary licences.
|
|
|
|
Context: https://github.com/uazo/cromite/pull/856
|
|
License: GPL-2.0-or-later - https://spdx.org/licenses/GPL-2.0-or-later.html
|
|
---
|
|
.../Enable-platform-aac-audio-and-h264-video.inc | 7 +++++++
|
|
media/BUILD.gn | 2 ++
|
|
.../src/org/chromium/media/AudioManagerAndroid.java | 2 ++
|
|
media/base/android/media_codec_util.cc | 4 ++++
|
|
media/base/win/mf_helpers.cc | 4 ++++
|
|
media/filters/ffmpeg_audio_decoder.cc | 10 ++++++++++
|
|
media/filters/ffmpeg_demuxer.cc | 1 +
|
|
media/filters/ffmpeg_video_decoder.cc | 11 +++++++++++
|
|
media/filters/win/media_foundation_audio_decoder.cc | 9 +++++++++
|
|
media/gpu/windows/supported_profile_helpers.cc | 13 ++++++++++++-
|
|
media/media_options.gni | 8 ++++++++
|
|
11 files changed, 70 insertions(+), 1 deletion(-)
|
|
create mode 100644 cromite_flags/media/base/media_switches_cc/Enable-platform-aac-audio-and-h264-video.inc
|
|
|
|
diff --git a/cromite_flags/media/base/media_switches_cc/Enable-platform-aac-audio-and-h264-video.inc b/cromite_flags/media/base/media_switches_cc/Enable-platform-aac-audio-and-h264-video.inc
|
|
new file mode 100644
|
|
--- /dev/null
|
|
+++ b/cromite_flags/media/base/media_switches_cc/Enable-platform-aac-audio-and-h264-video.inc
|
|
@@ -0,0 +1,7 @@
|
|
+#if BUILDFLAG(IS_LINUX)
|
|
+
|
|
+SET_CROMITE_FEATURE_ENABLED(kAcceleratedVideoDecodeLinuxGL);
|
|
+SET_CROMITE_FEATURE_ENABLED(kAcceleratedVideoEncodeLinux);
|
|
+SET_CROMITE_FEATURE_ENABLED(kVaapiIgnoreDriverChecks);
|
|
+
|
|
+#endif
|
|
diff --git a/media/BUILD.gn b/media/BUILD.gn
|
|
--- a/media/BUILD.gn
|
|
+++ b/media/BUILD.gn
|
|
@@ -26,6 +26,8 @@ buildflag_header("media_buildflags") {
|
|
header = "media_buildflags.h"
|
|
|
|
flags = [
|
|
+ "ENABLE_PLATFORM_AAC_AUDIO=$enable_platform_aac_audio",
|
|
+ "ENABLE_PLATFORM_H264_VIDEO=$enable_platform_h264_video",
|
|
"ALLOW_OOP_VIDEO_DECODER=$allow_oop_video_decoder",
|
|
"ALLOW_HOSTING_OOP_VIDEO_DECODER=$allow_hosting_oop_video_decoder",
|
|
"ALTERNATE_CDM_STORAGE_ID_KEY=\"$alternate_cdm_storage_id_key\"",
|
|
diff --git a/media/base/android/java/src/org/chromium/media/AudioManagerAndroid.java b/media/base/android/java/src/org/chromium/media/AudioManagerAndroid.java
|
|
--- a/media/base/android/java/src/org/chromium/media/AudioManagerAndroid.java
|
|
+++ b/media/base/android/java/src/org/chromium/media/AudioManagerAndroid.java
|
|
@@ -678,6 +678,8 @@ class AudioManagerAndroid {
|
|
break;
|
|
}
|
|
}
|
|
+ // only PCM_LINEAR allowed via hdmi in cromite
|
|
+ mask &= AudioEncodingFormat.PCM_LINEAR;
|
|
|
|
// Require all devices to support a format
|
|
if (first) {
|
|
diff --git a/media/base/android/media_codec_util.cc b/media/base/android/media_codec_util.cc
|
|
--- a/media/base/android/media_codec_util.cc
|
|
+++ b/media/base/android/media_codec_util.cc
|
|
@@ -16,6 +16,7 @@
|
|
#include "base/numerics/safe_conversions.h"
|
|
#include "base/strings/string_util.h"
|
|
#include "base/system/sys_info.h"
|
|
+#include "media/media_buildflags.h"
|
|
#include "media/base/android/media_codec_bridge.h"
|
|
#include "media/base/video_codecs.h"
|
|
#include "third_party/re2/src/re2/re2.h"
|
|
@@ -127,6 +128,9 @@ std::string MediaCodecUtil::CodecToAndroidMimeType(AudioCodec codec) {
|
|
// static
|
|
std::string MediaCodecUtil::CodecToAndroidMimeType(AudioCodec codec,
|
|
SampleFormat sample_format) {
|
|
+#if BUILDFLAG(ENABLE_PLATFORM_AAC_AUDIO)
|
|
+ if (codec == AudioCodec::kAAC) return kAacMimeType;
|
|
+#endif
|
|
// Passthrough is possible for some bitstream formats.
|
|
if (sample_format == kSampleFormatDts ||
|
|
sample_format == kSampleFormatDtsxP2 ||
|
|
diff --git a/media/base/win/mf_helpers.cc b/media/base/win/mf_helpers.cc
|
|
--- a/media/base/win/mf_helpers.cc
|
|
+++ b/media/base/win/mf_helpers.cc
|
|
@@ -496,7 +496,11 @@ HRESULT GetAacAudioType(const AudioDecoderConfig& decoder_config,
|
|
|
|
size_t extra_size = wave_format_size - sizeof(WAVEFORMATEX);
|
|
aac_wave_format->wfx.cbSize = static_cast<WORD>(extra_size);
|
|
+#if BUILDFLAG(ENABLE_PLATFORM_AAC_AUDIO)
|
|
+ aac_wave_format->wPayloadType = 1; // Audio Data Transport Stream (ADTS)
|
|
+#else
|
|
aac_wave_format->wPayloadType = 0; // RAW AAC
|
|
+#endif
|
|
aac_wave_format->wAudioProfileLevelIndication =
|
|
0xFE; // no audio profile specified
|
|
aac_wave_format->wStructType = 0; // audio specific config follows
|
|
diff --git a/media/filters/ffmpeg_audio_decoder.cc b/media/filters/ffmpeg_audio_decoder.cc
|
|
--- a/media/filters/ffmpeg_audio_decoder.cc
|
|
+++ b/media/filters/ffmpeg_audio_decoder.cc
|
|
@@ -127,6 +127,16 @@ void FFmpegAudioDecoder::Initialize(const AudioDecoderConfig& config,
|
|
return;
|
|
}
|
|
|
|
+#if BUILDFLAG(ENABLE_PLATFORM_AAC_AUDIO)
|
|
+ if (config.codec() == AudioCodec::kAAC) {
|
|
+ std::move(bound_init_cb)
|
|
+ .Run(DecoderStatus(DecoderStatus::Codes::kUnsupportedProfile)
|
|
+ .WithData("decoder", "FFmpegAudioDecoder")
|
|
+ .WithData("profile", config.profile()));
|
|
+ return;
|
|
+ }
|
|
+#endif
|
|
+
|
|
// TODO(dalecurtis): Remove this if ffmpeg ever gets xHE-AAC support.
|
|
if (config.profile() == AudioCodecProfile::kXHE_AAC) {
|
|
std::move(bound_init_cb)
|
|
diff --git a/media/filters/ffmpeg_demuxer.cc b/media/filters/ffmpeg_demuxer.cc
|
|
--- a/media/filters/ffmpeg_demuxer.cc
|
|
+++ b/media/filters/ffmpeg_demuxer.cc
|
|
@@ -728,6 +728,7 @@ void FFmpegDemuxerStream::InitBitstreamConverter() {
|
|
// FFmpeg doesn't understand xHE-AAC profiles yet, which can't be put in
|
|
// ADTS anyways, so skip bitstream conversion when the profile is
|
|
// unknown.
|
|
+ // Also Windows need ADTS conversion for AAC
|
|
if (audio_config_->profile() != AudioCodecProfile::kXHE_AAC) {
|
|
bitstream_converter_ =
|
|
std::make_unique<FFmpegAACBitstreamConverter>(stream_->codecpar);
|
|
diff --git a/media/filters/ffmpeg_video_decoder.cc b/media/filters/ffmpeg_video_decoder.cc
|
|
--- a/media/filters/ffmpeg_video_decoder.cc
|
|
+++ b/media/filters/ffmpeg_video_decoder.cc
|
|
@@ -18,6 +18,7 @@
|
|
#include "base/numerics/safe_conversions.h"
|
|
#include "base/task/bind_post_task.h"
|
|
#include "base/task/sequenced_task_runner.h"
|
|
+#include "media/media_buildflags.h"
|
|
#include "media/base/decoder_buffer.h"
|
|
#include "media/base/limits.h"
|
|
#include "media/base/media_log.h"
|
|
@@ -117,6 +118,16 @@ static void ReleaseVideoBufferImpl(void* opaque, uint8_t* data) {
|
|
|
|
// static
|
|
bool FFmpegVideoDecoder::IsCodecSupported(VideoCodec codec) {
|
|
+#if BUILDFLAG(ENABLE_PLATFORM_H264_VIDEO)
|
|
+ if (codec == VideoCodec::kH264) {
|
|
+ return false;
|
|
+ }
|
|
+#endif
|
|
+#if BUILDFLAG(ENABLE_PLATFORM_HEVC)
|
|
+ if (codec == VideoCodec::kHEVC) {
|
|
+ return false;
|
|
+ }
|
|
+#endif
|
|
// We only build support for H.264.
|
|
return codec == VideoCodec::kH264 && IsDecoderBuiltInVideoCodec(codec);
|
|
}
|
|
diff --git a/media/filters/win/media_foundation_audio_decoder.cc b/media/filters/win/media_foundation_audio_decoder.cc
|
|
--- a/media/filters/win/media_foundation_audio_decoder.cc
|
|
+++ b/media/filters/win/media_foundation_audio_decoder.cc
|
|
@@ -101,11 +101,15 @@ std::optional<MFT_REGISTER_TYPE_INFO> GetTypeInfo(
|
|
#endif
|
|
#if BUILDFLAG(USE_PROPRIETARY_CODECS)
|
|
case AudioCodec::kAAC:
|
|
+#if BUILDFLAG(ENABLE_PLATFORM_AAC_AUDIO)
|
|
+ return MFT_REGISTER_TYPE_INFO{MFMediaType_Audio, MFAudioFormat_AAC};
|
|
+#else
|
|
if (config.profile() == AudioCodecProfile::kXHE_AAC &&
|
|
base::win::GetVersion() >= base::win::Version::WIN11_22H2) {
|
|
return MFT_REGISTER_TYPE_INFO{MFMediaType_Audio, MFAudioFormat_AAC};
|
|
}
|
|
[[fallthrough]];
|
|
+#endif // BUILDFLAG(ENABLE_PLATFORM_AAC_AUDIO)
|
|
#endif
|
|
#if BUILDFLAG(ENABLE_PLATFORM_AC4_AUDIO)
|
|
case AudioCodec::kAC4:
|
|
@@ -323,8 +327,13 @@ void MediaFoundationAudioDecoder::Reset(base::OnceClosure reset_cb) {
|
|
}
|
|
|
|
bool MediaFoundationAudioDecoder::NeedsBitstreamConversion() const {
|
|
+#if BUILDFLAG(ENABLE_PLATFORM_AAC_AUDIO)
|
|
+ // An AAC stream needs to be converted as ADTS stream.
|
|
+ return config_.codec() == AudioCodec::kAAC;
|
|
+#else
|
|
// DTS does not require any header/bit stream conversion
|
|
return false;
|
|
+#endif
|
|
}
|
|
|
|
HRESULT MediaFoundationAudioDecoder::CreateDecoder() {
|
|
diff --git a/media/gpu/windows/supported_profile_helpers.cc b/media/gpu/windows/supported_profile_helpers.cc
|
|
--- a/media/gpu/windows/supported_profile_helpers.cc
|
|
+++ b/media/gpu/windows/supported_profile_helpers.cc
|
|
@@ -364,7 +364,11 @@ SupportedResolutionRangeMap GetSupportedD3DVideoDecoderResolutions(
|
|
//
|
|
// On Windows 7 the maximum resolution supported by media foundation is
|
|
// 1920 x 1088. We use 1088 to account for 16x16 macro-blocks.
|
|
+#if BUILDFLAG(ENABLE_PLATFORM_H264_VIDEO)
|
|
+ constexpr gfx::Size kDefaultMaxH264Resolution(4096, 2304);
|
|
+#else
|
|
constexpr gfx::Size kDefaultMaxH264Resolution(1920, 1088);
|
|
+#endif
|
|
SupportedResolutionRange h264_profile;
|
|
h264_profile.min_resolution = kMinResolution;
|
|
h264_profile.max_landscape_resolution = kDefaultMaxH264Resolution;
|
|
@@ -372,7 +376,14 @@ SupportedResolutionRangeMap GetSupportedD3DVideoDecoderResolutions(
|
|
// We don't have a way to map DXVA support to specific H.264 profiles, so just
|
|
// mark all the common ones with the same level of support.
|
|
constexpr VideoCodecProfile kSupportedH264Profiles[] = {
|
|
- H264PROFILE_BASELINE, H264PROFILE_MAIN, H264PROFILE_HIGH};
|
|
+ H264PROFILE_BASELINE, H264PROFILE_MAIN, H264PROFILE_HIGH
|
|
+#if BUILDFLAG(ENABLE_PLATFORM_H264_VIDEO)
|
|
+ // even if they are not supported, we add the items so that play
|
|
+ // is still attempted. On the contrary, non-support would appear immediately.
|
|
+ , H264PROFILE_HIGH10PROFILE, H264PROFILE_HIGH422PROFILE,
|
|
+ H264PROFILE_HIGH444PREDICTIVEPROFILE
|
|
+#endif
|
|
+ };
|
|
for (const auto profile : kSupportedH264Profiles)
|
|
supported_resolutions[profile] = h264_profile;
|
|
|
|
diff --git a/media/media_options.gni b/media/media_options.gni
|
|
--- a/media/media_options.gni
|
|
+++ b/media/media_options.gni
|
|
@@ -65,6 +65,14 @@ declare_args() {
|
|
media_use_symphonia = false
|
|
}
|
|
|
|
+ # Enables AAC audio decoder using only MediaCodecAudioDecoder in Android
|
|
+ # and MediaFoundationAudioDecoder in Windows
|
|
+ enable_platform_aac_audio = false
|
|
+
|
|
+ # Enables h264 video decoder using only MediaCodecVideoDecoder in Android
|
|
+ # and D3D11VideoDecoder in Windows
|
|
+ enable_platform_h264_video = false
|
|
+
|
|
# Enable usage of OpenH264 within the media library. Used for software based
|
|
# encoding of H264 content.
|
|
media_use_openh264 = true
|
|
--
|