From 73cf33afbc7d404016bf33de1f4c46aff945dce5 Mon Sep 17 00:00:00 2001 From: rohks Date: Thu, 10 Oct 2024 10:15:38 -0700 Subject: [PATCH] Add 16 KB page support for decoder extensions on Android 15 We need to rebuild any native components of the app to prevent crashes on devices with 16 KB page support. Tested on a device that supports 16 KB pages and runs Android 15, as well as on older Android devices. Issue: androidx/media#1685 PiperOrigin-RevId: 684488244 --- RELEASENOTES.md | 1 + constants.gradle | 1 - libraries/decoder_av1/build.gradle | 8 +++ .../decoder_av1/src/main/jni/CMakeLists.txt | 4 ++ libraries/decoder_ffmpeg/build.gradle | 12 ++++ .../src/main/jni/CMakeLists.txt | 4 ++ libraries/decoder_flac/build.gradle | 8 +++ .../decoder_flac/src/main/jni/Android.mk | 2 + libraries/decoder_iamf/build.gradle | 67 +++++++++++++++++++ .../decoder_iamf/src/main/jni/CMakeLists.txt | 50 ++++++++++++++ libraries/decoder_opus/build.gradle | 8 +++ .../decoder_opus/src/main/jni/Android.mk | 2 + libraries/decoder_vp9/build.gradle | 8 +++ libraries/decoder_vp9/src/main/jni/Android.mk | 2 + 14 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 libraries/decoder_iamf/build.gradle create mode 100644 libraries/decoder_iamf/src/main/jni/CMakeLists.txt diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 4e1520899c3..d3bd056860e 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -66,6 +66,7 @@ * Smooth Streaming Extension: * RTSP Extension: * Decoder Extensions (FFmpeg, VP9, AV1, MIDI, etc.): +* MIDI extension: * Leanback extension: * Cast Extension: * Fix bug that converted the album title of the `MediaQueueItem` to the diff --git a/constants.gradle b/constants.gradle index f882ce2a877..b89c67ec813 100644 --- a/constants.gradle +++ b/constants.gradle @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. project.ext { -<<<<<<< HEAD releaseVersion = '1.4.1' releaseVersionCode = 1_004_001_3_00 minSdkVersion = 21 diff --git a/libraries/decoder_av1/build.gradle b/libraries/decoder_av1/build.gradle index 6f66ad58801..b793cb2d8e7 100644 --- a/libraries/decoder_av1/build.gradle +++ b/libraries/decoder_av1/build.gradle @@ -27,6 +27,14 @@ android { } } } + + // TODO(Internal: b/372449691): Remove packagingOptions once AGP is updated + // to version 8.5.1 or higher. + packagingOptions { + jniLibs { + useLegacyPackaging true + } + } } // Configure the native build only if libgav1 is present to avoid gradle sync diff --git a/libraries/decoder_av1/src/main/jni/CMakeLists.txt b/libraries/decoder_av1/src/main/jni/CMakeLists.txt index 0202f0af570..4a39b6cd38a 100644 --- a/libraries/decoder_av1/src/main/jni/CMakeLists.txt +++ b/libraries/decoder_av1/src/main/jni/CMakeLists.txt @@ -61,3 +61,7 @@ target_link_libraries(gav1JNI PRIVATE libgav1_static PRIVATE ${android_log_lib}) +# Enable 16 KB ELF alignment. +target_link_options(gav1JNI + PRIVATE "-Wl,-z,max-page-size=16384") + diff --git a/libraries/decoder_ffmpeg/build.gradle b/libraries/decoder_ffmpeg/build.gradle index 524b63e9c5c..055c613cc02 100644 --- a/libraries/decoder_ffmpeg/build.gradle +++ b/libraries/decoder_ffmpeg/build.gradle @@ -19,6 +19,18 @@ android.externalNativeBuild.cmake.path = 'src/main/jni/CMakeLists.txt' // Should match cmake_minimum_required. android.externalNativeBuild.cmake.version = '3.21.0+' +android { + namespace 'androidx.media3.decoder.ffmpeg' + + // TODO(Internal: b/372449691): Remove packagingOptions once AGP is updated + // to version 8.5.1 or higher. + packagingOptions { + jniLibs { + useLegacyPackaging true + } + } +} + task assembleFfmpeg(type: Exec) { def host = "" if (Os.isFamily(Os.FAMILY_MAC)) { diff --git a/libraries/decoder_ffmpeg/src/main/jni/CMakeLists.txt b/libraries/decoder_ffmpeg/src/main/jni/CMakeLists.txt index fe74c78048d..819cb5baa41 100644 --- a/libraries/decoder_ffmpeg/src/main/jni/CMakeLists.txt +++ b/libraries/decoder_ffmpeg/src/main/jni/CMakeLists.txt @@ -56,3 +56,7 @@ target_link_libraries(ffmpegJNI if(ANDROID_ABI STREQUAL "arm64-v8a") target_link_options(ffmpegJNI PRIVATE "-Wl,-Bsymbolic") endif() + +# Enable 16 KB ELF alignment. +target_link_options(ffmpegJNI + PRIVATE "-Wl,-z,max-page-size=16384") diff --git a/libraries/decoder_flac/build.gradle b/libraries/decoder_flac/build.gradle index 0da6fa2e525..a7fa55ee409 100644 --- a/libraries/decoder_flac/build.gradle +++ b/libraries/decoder_flac/build.gradle @@ -23,6 +23,14 @@ android { } androidTest.assets.srcDir '../test_data/src/test/assets' } + + // TODO(Internal: b/372449691): Remove packagingOptions once AGP is updated + // to version 8.5.1 or higher. + packagingOptions { + jniLibs { + useLegacyPackaging true + } + } } dependencies { diff --git a/libraries/decoder_flac/src/main/jni/Android.mk b/libraries/decoder_flac/src/main/jni/Android.mk index 69520a16e58..b19d169111c 100644 --- a/libraries/decoder_flac/src/main/jni/Android.mk +++ b/libraries/decoder_flac/src/main/jni/Android.mk @@ -35,4 +35,6 @@ LOCAL_CFLAGS += -D_REENTRANT -DPIC -DU_COMMON_IMPLEMENTATION -fPIC -DHAVE_SYS_PA LOCAL_CFLAGS += -O3 -funroll-loops -finline-functions -DFLAC__NO_ASM '-DFLAC__HAS_OGG=0' LOCAL_LDLIBS := -llog -lz -lm +# Enable 16 KB ELF alignment. +LOCAL_LDFLAGS += "-Wl,-z,max-page-size=16384" include $(BUILD_SHARED_LIBRARY) diff --git a/libraries/decoder_iamf/build.gradle b/libraries/decoder_iamf/build.gradle new file mode 100644 index 00000000000..17970629bc7 --- /dev/null +++ b/libraries/decoder_iamf/build.gradle @@ -0,0 +1,67 @@ +// Copyright 2024 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +apply from: "$gradle.ext.androidxMediaSettingsDir/common_library_config.gradle" + +android { + namespace 'androidx.media3.decoder.iamf' + + sourceSets { + androidTest.assets.srcDir '../test_data/src/test/assets' + } + + defaultConfig { + externalNativeBuild { + cmake { + targets "iamfJNI" + } + } + } + + // TODO(Internal: b/372449691): Remove packagingOptions once AGP is updated + // to version 8.5.1 or higher. + packagingOptions { + jniLibs { + useLegacyPackaging true + } + } +} + +// Configure the native build only if libiamf is present to avoid gradle sync +// failures if libiamf hasn't been built according to the README instructions. +if (project.file('src/main/jni/libiamf').exists()) { + android.externalNativeBuild.cmake { + path = 'src/main/jni/CMakeLists.txt' + version = '3.21.0+' + if (project.hasProperty('externalNativeBuildDir')) { + if (!new File(externalNativeBuildDir).isAbsolute()) { + ext.externalNativeBuildDir = + new File(rootDir, it.externalNativeBuildDir) + } + buildStagingDirectory = "${externalNativeBuildDir}/${project.name}" + } + } +} + +dependencies { + implementation project(modulePrefix + 'lib-decoder') + // TODO(b/203752526): Remove this dependency. + implementation project(modulePrefix + 'lib-exoplayer') + implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion + compileOnly 'org.jetbrains.kotlin:kotlin-annotations-jvm:' + kotlinAnnotationsVersion + testImplementation project(modulePrefix + 'test-utils') + testImplementation 'org.robolectric:robolectric:' + robolectricVersion + androidTestImplementation project(modulePrefix + 'test-utils') + androidTestImplementation 'androidx.test:runner:' + androidxTestRunnerVersion + androidTestImplementation 'androidx.test.ext:junit:' + androidxTestJUnitVersion +} diff --git a/libraries/decoder_iamf/src/main/jni/CMakeLists.txt b/libraries/decoder_iamf/src/main/jni/CMakeLists.txt new file mode 100644 index 00000000000..32a65ed1ac3 --- /dev/null +++ b/libraries/decoder_iamf/src/main/jni/CMakeLists.txt @@ -0,0 +1,50 @@ +# +# Copyright 2024 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +cmake_minimum_required(VERSION 3.21.0 FATAL_ERROR) + +# Enable C++11 features. +set(CMAKE_CXX_STANDARD 11) + +# Define project name for your JNI module +project(libiamfJNI C CXX) + +set(libiamf_jni_root "${CMAKE_CURRENT_SOURCE_DIR}") + +# Build libiamf. +add_subdirectory("${libiamf_jni_root}/libiamf/code" + EXCLUDE_FROM_ALL) + +# Add the include directory from libiamf. +include_directories ("${libiamf_jni_root}/libiamf/code/include") + +# Build libiamfJNI. +add_library(iamfJNI + SHARED + iamf_jni.cc) + +# Locate NDK log library. +find_library(android_log_lib log) + +# Link libgav1JNI against used libraries. +target_link_libraries(iamfJNI + PRIVATE android + PRIVATE iamf + PRIVATE ${android_log_lib}) + +# Enable 16 KB ELF alignment. +target_link_options(iamfJNI + PRIVATE "-Wl,-z,max-page-size=16384") diff --git a/libraries/decoder_opus/build.gradle b/libraries/decoder_opus/build.gradle index af01cad0137..763eba00b13 100644 --- a/libraries/decoder_opus/build.gradle +++ b/libraries/decoder_opus/build.gradle @@ -23,6 +23,14 @@ android { } androidTest.assets.srcDir '../test_data/src/test/assets' } + + // TODO(Internal: b/372449691): Remove packagingOptions once AGP is updated + // to version 8.5.1 or higher. + packagingOptions { + jniLibs { + useLegacyPackaging true + } + } } dependencies { diff --git a/libraries/decoder_opus/src/main/jni/Android.mk b/libraries/decoder_opus/src/main/jni/Android.mk index 0b06d9ecd81..676774ed49f 100644 --- a/libraries/decoder_opus/src/main/jni/Android.mk +++ b/libraries/decoder_opus/src/main/jni/Android.mk @@ -30,4 +30,6 @@ LOCAL_CPP_EXTENSION := .cc LOCAL_SRC_FILES := opus_jni.cc LOCAL_LDLIBS := -llog -lz -lm LOCAL_STATIC_LIBRARIES := libopus +# Enable 16 KB ELF alignment. +LOCAL_LDFLAGS += "-Wl,-z,max-page-size=16384" include $(BUILD_SHARED_LIBRARY) diff --git a/libraries/decoder_vp9/build.gradle b/libraries/decoder_vp9/build.gradle index d7a29e54277..81dd71500bc 100644 --- a/libraries/decoder_vp9/build.gradle +++ b/libraries/decoder_vp9/build.gradle @@ -23,6 +23,14 @@ android { } androidTest.assets.srcDir '../test_data/src/test/assets' } + + // TODO(Internal: b/372449691): Remove packagingOptions once AGP is updated + // to version 8.5.1 or higher. + packagingOptions { + jniLibs { + useLegacyPackaging true + } + } } dependencies { diff --git a/libraries/decoder_vp9/src/main/jni/Android.mk b/libraries/decoder_vp9/src/main/jni/Android.mk index cb7571a1b0f..0794feb7308 100644 --- a/libraries/decoder_vp9/src/main/jni/Android.mk +++ b/libraries/decoder_vp9/src/main/jni/Android.mk @@ -32,6 +32,8 @@ LOCAL_SRC_FILES := vpx_jni.cc LOCAL_LDLIBS := -llog -lz -lm -landroid LOCAL_SHARED_LIBRARIES := libvpx LOCAL_STATIC_LIBRARIES := cpufeatures +# Enable 16 KB ELF alignment. +LOCAL_LDFLAGS += "-Wl,-z,max-page-size=16384" include $(BUILD_SHARED_LIBRARY) $(call import-module,android/cpufeatures)