Skip to content

Commit

Permalink
Add 16 KB page support for decoder extensions on Android 15
Browse files Browse the repository at this point in the history
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#1685
PiperOrigin-RevId: 684488244
  • Loading branch information
rohitjoins authored and OxygenCobalt committed Oct 18, 2024
1 parent b676ac3 commit 73cf33a
Show file tree
Hide file tree
Showing 14 changed files with 176 additions and 1 deletion.
1 change: 1 addition & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion constants.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions libraries/decoder_av1/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions libraries/decoder_av1/src/main/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")

12 changes: 12 additions & 0 deletions libraries/decoder_ffmpeg/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
4 changes: 4 additions & 0 deletions libraries/decoder_ffmpeg/src/main/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
8 changes: 8 additions & 0 deletions libraries/decoder_flac/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions libraries/decoder_flac/src/main/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
67 changes: 67 additions & 0 deletions libraries/decoder_iamf/build.gradle
Original file line number Diff line number Diff line change
@@ -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
}
50 changes: 50 additions & 0 deletions libraries/decoder_iamf/src/main/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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")
8 changes: 8 additions & 0 deletions libraries/decoder_opus/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions libraries/decoder_opus/src/main/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 8 additions & 0 deletions libraries/decoder_vp9/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions libraries/decoder_vp9/src/main/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 73cf33a

Please sign in to comment.