From b56ad59ac5ece753d435c40db5ad2228c9d67d6f Mon Sep 17 00:00:00 2001 From: Altay Date: Sun, 8 Nov 2026 14:42:14 +0300 Subject: [PATCH 1/4] fix: make the publication LGPL-complete and prove the publish path Maven Central releases cannot be replaced, so every gap must close before the first tag. - Publish the pinned FFmpeg tree, JNI wrapper and build scripts as an ffmpeg-source artifact of the publication, so LGPL source sits next to the binary, signed with it. - verify now publishes to Maven Local and asserts the POM, sources and javadoc jars, AAR and ffmpeg-source; CI runs it with a release-shaped version and a throwaway signing key. - check-aar enforces the decoder set per ABI and fails on an empty or host-specific configure line. - A VERSION file makes av_version_info report the FFmpeg tag instead of this repository's git describe. It is removed from the staged tree after the FFmpeg build, because on a case-insensitive file system it shadows the C++ header. - Negative controls run in verify and prove those checks fail. - Renovate skips the release age for submodules: git-refs has no timestamps, so updates stalled. --- .github/workflows/ci.yml | 2 +- NOTICE | 22 ++--- README.md | 13 ++- build.gradle.kts | 83 ++++++++++++++++- renovate.json | 5 + scripts/build-ffmpeg.sh | 17 ++-- scripts/check-aar.sh | 29 +++++- scripts/check-negative-controls.sh | 141 +++++++++++++++++++++++++++++ scripts/check-publication.sh | 81 +++++++++++++++++ scripts/package-ffmpeg-source.sh | 38 ++++++++ scripts/stage-ffmpeg-source.sh | 13 +++ scripts/verify-release-shape.sh | 21 +++++ 12 files changed, 439 insertions(+), 26 deletions(-) create mode 100755 scripts/check-negative-controls.sh create mode 100755 scripts/check-publication.sh create mode 100755 scripts/package-ffmpeg-source.sh create mode 100755 scripts/stage-ffmpeg-source.sh create mode 100755 scripts/verify-release-shape.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9dbe950..853daf6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,7 +47,7 @@ jobs: "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" --install "ndk;${ndk_version}" >/dev/null - name: Verify repository - run: ./gradlew verify + run: scripts/verify-release-shape.sh - name: Check Markdown links uses: putdotio/.github/.github/actions/links@e07dede03892f9b80fec82bf38afcd5f76b763b0 # v2.3.3 diff --git a/NOTICE b/NOTICE index 0d7184f..b36a8cf 100644 --- a/NOTICE +++ b/NOTICE @@ -4,21 +4,21 @@ Copyright (c) put.io This project is licensed under the Apache License, Version 2.0. See LICENSE. The AAR published by this project bundles FFmpeg libraries (libavcodec, -libavutil and libswresample) linked into libffmpegJNI. FFmpeg is licensed under -the GNU Lesser General Public License, version 2.1 or later. FFmpeg is built -without --enable-gpl, --enable-nonfree and --enable-version3. +libavutil and libswresample) linked into libffmpegJNI. FFmpeg is Copyright (c) +2000-2026 the FFmpeg developers and is licensed under the GNU Lesser General +Public License, version 2.1 or later. FFmpeg is built without --enable-gpl, +--enable-nonfree and --enable-version3. Source and build instructions for FFmpeg in a released AAR: -- FFmpeg source: the ffmpeg submodule of this repository at the release tag, - https://github.com/putdotio/media3-ffmpeg-decoder/tags -- Configure flags: libraries/decoder_ffmpeg/src/main/jni/build_ffmpeg.sh in the - media submodule, with the ffmpegDecoders list in gradle.properties. +- Every release publishes the corresponding source next to the AAR on Maven + Central, signed like the AAR. It has the classifier ffmpeg-source: + https://repo1.maven.org/maven2/io/put/media3-ffmpeg-decoder//media3-ffmpeg-decoder--ffmpeg-source.tar.xz +- That archive holds the FFmpeg source at the pinned commit, the JNI wrapper + that links it, the build scripts, and BUILD.txt with the rebuild command. - Every AAR carries META-INF/media3-ffmpeg-decoder/ffmpeg-build.txt with the - exact FFmpeg commit, build script and configure string, and the LGPL text in - META-INF/media3-ffmpeg-decoder/COPYING.LGPLv2.1. -- To rebuild it, modified or not, follow the README. The JNI wrapper is - Apache-2.0 source in the media submodule. + exact FFmpeg commit, build script and per-ABI configure lines, and the LGPL + text in META-INF/media3-ffmpeg-decoder/COPYING.LGPLv2.1. The JNI wrapper and Java classes are built from AndroidX Media3, Copyright The Android Open Source Project, licensed under the Apache License, Version 2.0. diff --git a/README.md b/README.md index 01603af..bc64d12 100644 --- a/README.md +++ b/README.md @@ -21,11 +21,18 @@ Needs Java 21, the NDK in `ndkVersion`, Linux x86_64 or macOS, and shallow submo ```bash git clone --recurse-submodules --shallow-submodules https://github.com/putdotio/media3-ffmpeg-decoder.git +cd media3-ffmpeg-decoder ./gradlew verify ./gradlew publishToMavenLocal -Pversion=1.11.1+1 ``` -`./gradlew verify` builds FFmpeg with Media3's own `build_ffmpeg.sh`, then [check-aar.sh](./scripts/check-aar.sh) fails the build on a non-LGPL FFmpeg, a 64-bit library not aligned to 16 KB, a missing ABI or a missing renderer class. +`./gradlew verify` builds FFmpeg with Media3's own `build_ffmpeg.sh`, then publishes to Maven Local and fails the build on what a release must not ship: + +- [check-aar.sh](./scripts/check-aar.sh): a non-LGPL FFmpeg, a decoder outside the allowed set, a missing per-ABI configure line, a 64-bit library not aligned to 16 KB, a missing ABI or a missing renderer class. +- [check-publication.sh](./scripts/check-publication.sh): a POM without both licenses, a missing sources or javadoc jar, or an `ffmpeg-source` archive that differs from the pinned FFmpeg. +- [check-negative-controls.sh](./scripts/check-negative-controls.sh): proves both checks fail on broken input. + +CI runs [verify-release-shape.sh](./scripts/verify-release-shape.sh), which does the same with a release version and a throwaway signing key. ## Bump Media3 @@ -60,7 +67,7 @@ git tag 'v1.11.1+1' git push origin 'v1.11.1+1' ``` -Pushing a `v*` tag publishes the AAR, sources and POM, signed, from the [release job](./.github/workflows/ci.yml). The tag must be on `main`. The version must be the current Media3 version plus `+`. Central rejects a re-upload, so never delete or re-push a tag: bump the build number instead. +Pushing a `v*` tag publishes the AAR, sources, javadoc, `ffmpeg-source` archive and POM, signed, from the [release job](./.github/workflows/ci.yml). The tag must be on `main`. The version must be the current Media3 version plus `+`. Central rejects a re-upload, so never delete or re-push a tag: bump the build number instead. The job reads `MAVEN_CENTRAL_USERNAME`, `MAVEN_CENTRAL_PASSWORD`, `SIGNING_KEY_ID`, `SIGNING_KEY` and `SIGNING_PASSWORD` from the protected `release` environment. @@ -68,4 +75,4 @@ The job reads `MAVEN_CENTRAL_USERNAME`, `MAVEN_CENTRAL_PASSWORD`, `SIGNING_KEY_I This project is [Apache-2.0](./LICENSE), the license of Media3's module. -The AAR bundles FFmpeg, which is LGPL-2.1-or-later. FFmpeg is built without `--enable-gpl`, `--enable-nonfree` and `--enable-version3`. Each AAR carries the exact FFmpeg commit, configure string and LGPL text under `META-INF/media3-ffmpeg-decoder/`, and the corresponding source is the `ffmpeg` submodule at the release tag. See [NOTICE](./NOTICE). +The AAR bundles FFmpeg, which is LGPL-2.1-or-later. FFmpeg is built without `--enable-gpl`, `--enable-nonfree` and `--enable-version3`. Each AAR carries the exact FFmpeg commit, per-ABI configure lines and LGPL text under `META-INF/media3-ffmpeg-decoder/`. The corresponding source is published next to the AAR on Maven Central as `media3-ffmpeg-decoder--ffmpeg-source.tar.xz`: the pinned FFmpeg tree, the JNI wrapper, the build scripts and a `BUILD.txt` with the rebuild command. See [NOTICE](./NOTICE). diff --git a/build.gradle.kts b/build.gradle.kts index 472b4c3..0189b51 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,6 +15,8 @@ val upstreamModule = layout.projectDirectory.dir("media/libraries/decoder_ffmpeg val stagedModule = layout.buildDirectory.dir("ffmpeg-module") val stagedCMakeLists = stagedModule.map { it.file("jni/CMakeLists.txt") } val ffmpegBuildLog = stagedModule.map { it.file("build.log") } +val stagedFfmpeg = stagedModule.map { it.dir("jni/ffmpeg") } +val ffmpegSourceArchive = layout.buildDirectory.file("ffmpeg-source/ffmpeg-source.tar.xz") group = "io.put" version = providers.gradleProperty("version").orNull?.takeUnless { it == "unspecified" } ?: "$media3Version-SNAPSHOT" @@ -97,7 +99,9 @@ val buildFfmpeg = script = layout.projectDirectory.file("scripts/build-ffmpeg.sh") inputs.property("ffmpegCommit", gitCommit("ffmpeg")) inputs.property("media3Commit", gitCommit("media")) - inputs.file(layout.projectDirectory.file("NOTICE")).withPathSensitivity(PathSensitivity.RELATIVE) + inputs + .files("NOTICE", "LICENSE", "scripts/stage-ffmpeg-source.sh") + .withPathSensitivity(PathSensitivity.RELATIVE) outputs.dir(stagedModule) arguments.add(ndkDirectoryPath) arguments.add(ffmpegMinSdk.toString()) @@ -105,6 +109,20 @@ val buildFfmpeg = arguments.addAll(ffmpegDecoders) } +val packageFfmpegSource = + tasks.register("packageFfmpegSource") { + group = "build" + description = "Packages the FFmpeg source, JNI wrapper and build scripts for LGPL distribution" + script = layout.projectDirectory.file("scripts/package-ffmpeg-source.sh") + inputs.property("ffmpegCommit", gitCommit("ffmpeg")) + inputs.property("media3Commit", gitCommit("media")) + inputs + .files("NOTICE", "LICENSE", "gradle.properties", "scripts/stage-ffmpeg-source.sh", "scripts/build-ffmpeg.sh") + .withPathSensitivity(PathSensitivity.RELATIVE) + outputs.file(ffmpegSourceArchive) + arguments.add(ffmpegSourceArchive.map { it.asFile.path }) + } + androidComponents { beforeVariants(selector().withBuildType("debug")) { it.enable = false } onVariants { variant -> @@ -119,18 +137,60 @@ tasks.matching { it.name.startsWith("configureCMake") }.configureEach { val checkAar = tasks.register("checkAar") { group = "verification" - description = "Checks the AAR for 16 KB alignment, ABIs, FFmpeg's license and the renderer class" + description = "Checks the AAR for 16 KB alignment, ABIs, decoders, FFmpeg's license and the renderer class" dependsOn("assembleRelease") + outputs.upToDateWhen { false } script = layout.projectDirectory.file("scripts/check-aar.sh") arguments.add(layout.buildDirectory.file("outputs/aar/media3-ffmpeg-decoder-release.aar").map { it.asFile.path }) arguments.add(ffmpegBuildLog.map { it.asFile.path }) arguments.add(ndkDirectoryPath) + arguments.add(stagedFfmpeg.map { it.asFile.path }) + } + +val publicationSigning = if (providers.gradleProperty("signingInMemoryKey").isPresent) "signed" else "unsigned" +val publishedVersionDirectory = + version.toString().let { publishedVersion -> + providers + .systemProperty("maven.repo.local") + .orElse(providers.systemProperty("user.home").map { "$it/.m2/repository" }) + .map { "$it/io/put/media3-ffmpeg-decoder/$publishedVersion" } + } + +val checkPublication = + tasks.register("checkPublication") { + group = "verification" + description = "Checks the publication in Maven Local for everything Maven Central and the LGPL require" + dependsOn("publishToMavenLocal") + outputs.upToDateWhen { false } + script = layout.projectDirectory.file("scripts/check-publication.sh") + arguments.add(publishedVersionDirectory) + arguments.add(version.toString()) + arguments.add(publicationSigning) + } + +val checkNegativeControls = + tasks.register("checkNegativeControls") { + group = "verification" + description = "Proves the AAR and publication checks fail on broken input" + dependsOn(checkAar, checkPublication) + outputs.upToDateWhen { false } + script = layout.projectDirectory.file("scripts/check-negative-controls.sh") + inputs + .files("scripts/check-aar.sh", "scripts/check-publication.sh") + .withPathSensitivity(PathSensitivity.RELATIVE) + arguments.add(layout.buildDirectory.file("outputs/aar/media3-ffmpeg-decoder-release.aar").map { it.asFile.path }) + arguments.add(ffmpegBuildLog.map { it.asFile.path }) + arguments.add(ndkDirectoryPath) + arguments.add(stagedFfmpeg.map { it.asFile.path }) + arguments.add(publishedVersionDirectory) + arguments.add(version.toString()) + arguments.add(publicationSigning) } tasks.register("verify") { group = "verification" - description = "Builds the AAR and enforces the release checks" - dependsOn(checkAar) + description = "Builds the AAR, publishes to Maven Local and enforces the release checks" + dependsOn(checkAar, checkPublication, checkNegativeControls) } dependencies { @@ -151,6 +211,16 @@ tasks.matching { it.name.startsWith("publish") && !it.name.endsWith("ToMavenLoca } } +publishing { + publications.withType().configureEach { + artifact(ffmpegSourceArchive) { + builtBy(packageFfmpegSource) + classifier = "ffmpeg-source" + extension = "tar.xz" + } + } +} + mavenPublishing { publishToMavenCentral(automaticRelease = true) if (providers.gradleProperty("signingInMemoryKey").isPresent) { @@ -176,6 +246,11 @@ mavenPublishing { name.set("Apache-2.0") url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") } + license { + name.set("LGPL-2.1-or-later") + url.set("https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt") + comments.set("The FFmpeg libraries statically linked into libffmpegJNI") + } } developers { diff --git a/renovate.json b/renovate.json index ea2f2e7..4a9e6a9 100644 --- a/renovate.json +++ b/renovate.json @@ -5,6 +5,11 @@ "enabled": true }, "packageRules": [ + { + "description": "git-refs returns no release timestamps, so a release age would stall every submodule update", + "matchManagers": ["git-submodules"], + "minimumReleaseAge": null + }, { "matchManagers": ["git-submodules"], "matchDepNames": ["media"], diff --git a/scripts/build-ffmpeg.sh b/scripts/build-ffmpeg.sh index 381e3d9..19dba66 100755 --- a/scripts/build-ffmpeg.sh +++ b/scripts/build-ffmpeg.sh @@ -15,28 +15,33 @@ case "$(uname -s)" in *) echo "unsupported host: $(uname -s)" >&2; exit 1 ;; esac -upstream_jni="$repo_root/media/libraries/decoder_ffmpeg/src/main/jni" build_log="$module_dir/build.log" rm -rf "$module_dir" -mkdir -p "$module_dir/jni/ffmpeg" -cp "$upstream_jni/build_ffmpeg.sh" "$upstream_jni/CMakeLists.txt" "$upstream_jni/ffmpeg_jni.cc" "$module_dir/jni/" -git -C "$repo_root/ffmpeg" archive HEAD | tar -x -C "$module_dir/jni/ffmpeg" +"$repo_root/scripts/stage-ffmpeg-source.sh" "$module_dir" if ! "$module_dir/jni/build_ffmpeg.sh" "$module_dir" "$ndk_path" "$host_platform" "$min_sdk" "${decoders[@]}" >"$build_log" 2>&1; then tail -n 80 "$build_log" >&2 exit 1 fi +rm "$module_dir/jni/ffmpeg/VERSION" ffmpeg_commit="$(git -C "$repo_root/ffmpeg" rev-parse HEAD)" media3_commit="$(git -C "$repo_root/media" rev-parse HEAD)" ffmpeg_tag="$(git -C "$repo_root" config -f .gitmodules submodule.ffmpeg.branch)" media3_tag="$(git -C "$repo_root" config -f .gitmodules submodule.media.branch)" -configuration="$(sed -n 's/^#define FFMPEG_CONFIGURATION "\(.*\)"$/\1/p' "$module_dir/jni/ffmpeg/config.h")" +strings_tools=("$ndk_path"/toolchains/llvm/prebuilt/*/bin/llvm-strings) +configurations="" +for abi in arm64-v8a armeabi-v7a x86_64 x86; do + archive_strings="$("${strings_tools[0]}" "$module_dir/jni/ffmpeg/android-libs/$abi/libavutil.a")" + configuration="$(awk -v prefix="--libdir=android-libs/$abi " 'index($0, prefix) == 1 { print; exit }' <<<"$archive_strings" | sed "s#$ndk_path#\$NDK#g")" + configurations+="${configurations:+$'\n'}Configuration $abi: $configuration" +done license_dir="$resources_dir/META-INF/media3-ffmpeg-decoder" rm -rf "$license_dir" mkdir -p "$license_dir" +cp "$repo_root/LICENSE" "$license_dir/LICENSE" cp "$repo_root/NOTICE" "$license_dir/NOTICE" cp "$repo_root/ffmpeg/COPYING.LGPLv2.1" "$license_dir/COPYING.LGPLv2.1" cat >"$license_dir/ffmpeg-build.txt" <&2 @@ -16,7 +21,7 @@ work_dir="$(mktemp -d)" trap 'rm -rf "$work_dir"' EXIT unzip -q "$aar" -d "$work_dir" -for abi in arm64-v8a armeabi-v7a x86_64 x86; do +for abi in "${abis[@]}"; do [[ -f "$work_dir/jni/$abi/libffmpegJNI.so" ]] || fail "missing libffmpegJNI.so for $abi" done @@ -41,10 +46,32 @@ fi classes_listing="$(unzip -l "$work_dir/classes.jar")" for entry in \ androidx/media3/decoder/ffmpeg/FfmpegAudioRenderer.class \ + META-INF/media3-ffmpeg-decoder/LICENSE \ META-INF/media3-ffmpeg-decoder/NOTICE \ META-INF/media3-ffmpeg-decoder/COPYING.LGPLv2.1 \ META-INF/media3-ffmpeg-decoder/ffmpeg-build.txt; do grep -q "$entry" <<<"$classes_listing" || fail "classes.jar is missing $entry" done +enabled_decoders="$(sed -n 's/^#define CONFIG_\(.*\)_DECODER 1$/\1/p' "$ffmpeg_dir/config_components.h" | tr '[:upper:]' '[:lower:]' | sort)" +[[ "$enabled_decoders" == "$allowed_decoders" ]] || + fail "enabled decoders differ from the allowed set: $(tr '\n' ' ' <<<"$enabled_decoders")" + +build_info="$(unzip -p "$work_dir/classes.jar" META-INF/media3-ffmpeg-decoder/ffmpeg-build.txt)" +ffmpeg_tag="$(sed -n 's/^FFmpeg tag: //p' <<<"$build_info")" +[[ -n "$ffmpeg_tag" ]] || fail "ffmpeg-build.txt has no FFmpeg tag" + +for abi in "${abis[@]}"; do + configuration="$(sed -n "s/^Configuration $abi: //p" <<<"$build_info")" + [[ -n "$configuration" ]] || fail "empty configuration for $abi" + [[ "$configuration" == *"--libdir=android-libs/$abi "* ]] || fail "configuration for $abi names another ABI" + [[ "$configuration" != *"$ndk_path"* ]] || fail "configuration for $abi carries the builder's NDK path" + configured_decoders="$({ grep -oE -- '--enable-decoder=[^ ]+' <<<"$configuration" || true; } | sed 's/^--enable-decoder=//' | sort)" + [[ "$configured_decoders" == "$allowed_decoders" ]] || + fail "decoders in $abi differ from the allowed set: $(tr '\n' ' ' <<<"$configured_decoders")" + + archive_strings="$("$strings_tool" "$ffmpeg_dir/android-libs/$abi/libavutil.a")" + grep -qxF -- "$ffmpeg_tag" <<<"$archive_strings" || fail "libavutil.a for $abi does not report $ffmpeg_tag" +done + echo "check-aar: ok" diff --git a/scripts/check-negative-controls.sh b/scripts/check-negative-controls.sh new file mode 100755 index 0000000..f58d749 --- /dev/null +++ b/scripts/check-negative-controls.sh @@ -0,0 +1,141 @@ +#!/usr/bin/env bash +set -euo pipefail + +scripts_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +aar="$1" +build_log="$2" +ndk_path="$3" +ffmpeg_dir="$4" +published_dir="$5" +version="$6" +signing="$7" + +work_dir="$(mktemp -d)" +trap 'rm -rf "$work_dir"' EXIT +controls=0 + +die() { + echo "check-negative-controls: $1" >&2 + exit 1 +} + +expect_failure() { + local reason="$1" + shift + local output + if output="$("$@" 2>&1)"; then + die "check passed but should have failed with: $reason" + fi + grep -qF -- "$reason" <<<"$output" || die "wanted '$reason', got: $output" + controls=$((controls + 1)) +} + +expect_aar_failure() { + local reason="$1" + local mutated_aar="$2" + local mutated_ffmpeg="$3" + expect_failure "$reason" "$scripts_dir/check-aar.sh" "$mutated_aar" "$build_log" "$ndk_path" "$mutated_ffmpeg" +} + +mutate_build_info() { + local aar_dir="$work_dir/aar" + local classes_dir="$work_dir/classes" + rm -rf "$aar_dir" "$classes_dir" "$work_dir/mutated.aar" + mkdir -p "$aar_dir" "$classes_dir" + unzip -q "$aar" -d "$aar_dir" + unzip -q "$aar_dir/classes.jar" -d "$classes_dir" + sed -i.bak "$1" "$classes_dir/META-INF/media3-ffmpeg-decoder/ffmpeg-build.txt" + rm "$classes_dir/META-INF/media3-ffmpeg-decoder/ffmpeg-build.txt.bak" "$aar_dir/classes.jar" + (cd "$classes_dir" && zip -qr "$aar_dir/classes.jar" .) + (cd "$aar_dir" && zip -qr "$work_dir/mutated.aar" .) +} + +mutate_config_components() { + local mirror="$work_dir/ffmpeg" + rm -rf "$mirror" + mkdir -p "$mirror" + ln -s "$ffmpeg_dir/android-libs" "$mirror/android-libs" + sed "$1" "$ffmpeg_dir/config_components.h" >"$mirror/config_components.h" +} + +mutate_build_info 's/^Configuration arm64-v8a: .*/Configuration arm64-v8a: /' +expect_aar_failure "empty configuration for arm64-v8a" "$work_dir/mutated.aar" "$ffmpeg_dir" + +mutate_build_info '/^Configuration x86: /s/ --enable-decoder=truehd//' +expect_aar_failure "decoders in x86 differ from the allowed set" "$work_dir/mutated.aar" "$ffmpeg_dir" + +mutate_build_info 's/^FFmpeg tag: .*/FFmpeg tag: n0.0.0/' +expect_aar_failure "libavutil.a for arm64-v8a does not report n0.0.0" "$work_dir/mutated.aar" "$ffmpeg_dir" + +mutate_config_components 's/^#define CONFIG_HEVC_DECODER 0$/#define CONFIG_HEVC_DECODER 1/' +expect_aar_failure "enabled decoders differ from the allowed set" "$aar" "$work_dir/ffmpeg" + +mutate_config_components 's/^#define CONFIG_TRUEHD_DECODER 1$/#define CONFIG_TRUEHD_DECODER 0/' +expect_aar_failure "enabled decoders differ from the allowed set" "$aar" "$work_dir/ffmpeg" + +publication="$work_dir/publication" +prefix="$publication/media3-ffmpeg-decoder-$version" + +reset_publication() { + rm -rf "$publication" + cp -R "$published_dir" "$publication" +} + +expect_publication_failure() { + expect_failure "$1" "$scripts_dir/check-publication.sh" "$publication" "$version" "$signing" +} + +mutate_ffmpeg_source() { + local expanded="$work_dir/expanded" + rm -rf "$expanded" + mkdir -p "$expanded" + tar -xJf "$prefix-ffmpeg-source.tar.xz" -C "$expanded" + (cd "$expanded/ffmpeg-source" && eval "$1") + XZ_OPT=-0 tar -cJf "$prefix-ffmpeg-source.tar.xz" -C "$expanded" ffmpeg-source +} + +for suffix in .aar .pom -sources.jar -javadoc.jar -ffmpeg-source.tar.xz; do + reset_publication + rm "$prefix$suffix" + expect_publication_failure "missing media3-ffmpeg-decoder-$version$suffix" +done + +reset_publication +sed -i.bak '/LGPL-2.1-or-later/d' "$prefix.pom" +expect_publication_failure "POM is missing license LGPL-2.1-or-later" + +reset_publication +sed -i.bak '/Apache-2.0<\/name>/d' "$prefix.pom" +expect_publication_failure "POM is missing license Apache-2.0" + +reset_publication +(cd "$work_dir" && rm -f stub.jar && echo stub >stub.txt && zip -q stub.jar stub.txt && mv stub.jar "$prefix-sources.jar") +expect_publication_failure "sources jar is missing androidx/media3/decoder/ffmpeg/FfmpegAudioRenderer.java" + +reset_publication +mutate_ffmpeg_source 'rm jni/ffmpeg/configure' +expect_publication_failure "ffmpeg-source is missing jni/ffmpeg/configure" + +reset_publication +mutate_ffmpeg_source 'rm jni/ffmpeg/COPYING.LGPLv2.1' +expect_publication_failure "ffmpeg-source is missing jni/ffmpeg/COPYING.LGPLv2.1" + +reset_publication +mutate_ffmpeg_source 'rm jni/ffmpeg_jni.cc' +expect_publication_failure "ffmpeg-source is missing jni/ffmpeg_jni.cc" + +reset_publication +mutate_ffmpeg_source 'echo n0.0.0 >jni/ffmpeg/VERSION' +expect_publication_failure "ffmpeg-source VERSION does not name" + +reset_publication +mutate_ffmpeg_source 'echo "# patched" >>jni/ffmpeg/configure' +expect_publication_failure "ffmpeg-source differs from the pinned FFmpeg commit" + +if [[ "$signing" == signed ]]; then + reset_publication + rm "$prefix-ffmpeg-source.tar.xz.asc" + expect_publication_failure "missing signature for media3-ffmpeg-decoder-$version-ffmpeg-source.tar.xz" +fi + +echo "check-negative-controls: $controls controls failed as expected" diff --git a/scripts/check-publication.sh b/scripts/check-publication.sh new file mode 100755 index 0000000..ea8018a --- /dev/null +++ b/scripts/check-publication.sh @@ -0,0 +1,81 @@ +#!/usr/bin/env bash +set -euo pipefail + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +published_dir="$1" +version="$2" +signing="$3" + +fail() { + echo "check-publication: $1" >&2 + exit 1 +} + +prefix="$published_dir/media3-ffmpeg-decoder-$version" +aar="$prefix.aar" +pom="$prefix.pom" +sources_jar="$prefix-sources.jar" +javadoc_jar="$prefix-javadoc.jar" +ffmpeg_source="$prefix-ffmpeg-source.tar.xz" +artifacts=("$aar" "$pom" "$sources_jar" "$javadoc_jar" "$ffmpeg_source") + +for artifact in "${artifacts[@]}"; do + [[ -s "$artifact" ]] || fail "missing $(basename "$artifact")" +done + +if [[ "$signing" == signed ]]; then + for artifact in "${artifacts[@]}"; do + [[ -s "$artifact.asc" ]] || fail "missing signature for $(basename "$artifact")" + done +fi + +work_dir="$(mktemp -d)" +trap 'rm -rf "$work_dir"' EXIT + +pom_text="$(<"$pom")" +for license in Apache-2.0 LGPL-2.1-or-later; do + grep -qF "$license" <<<"$pom_text" || fail "POM is missing license $license" +done +grep -qF "$version" <<<"$pom_text" || fail "POM does not declare version $version" + +aar_listing="$(unzip -l "$aar")" || fail "$(basename "$aar") is not a zip" +grep -q 'jni/arm64-v8a/libffmpegJNI.so' <<<"$aar_listing" || fail "AAR is missing libffmpegJNI.so" + +unzip -l "$javadoc_jar" >/dev/null || fail "$(basename "$javadoc_jar") is not a zip" + +sources_listing="$(unzip -l "$sources_jar")" || fail "$(basename "$sources_jar") is not a zip" +for entry in androidx/media3/decoder/ffmpeg/FfmpegAudioRenderer.java androidx/media3/decoder/ffmpeg/FfmpegLibrary.java; do + grep -q "$entry" <<<"$sources_listing" || fail "sources jar is missing $entry" +done + +mkdir "$work_dir/extracted" +tar -xJf "$ffmpeg_source" -C "$work_dir/extracted" || fail "$(basename "$ffmpeg_source") is not a tar.xz" +source_root="$work_dir/extracted/ffmpeg-source" +for entry in \ + jni/ffmpeg/configure \ + jni/ffmpeg/COPYING.LGPLv2.1 \ + jni/ffmpeg/VERSION \ + jni/build_ffmpeg.sh \ + jni/CMakeLists.txt \ + jni/ffmpeg_jni.cc \ + scripts/build-ffmpeg.sh \ + gradle.properties \ + BUILD.txt \ + LICENSE \ + NOTICE; do + [[ -s "$source_root/$entry" ]] || fail "ffmpeg-source is missing $entry" +done + +ffmpeg_tag="$(git -C "$repo_root" config -f .gitmodules submodule.ffmpeg.branch)" +[[ "$(<"$source_root/jni/ffmpeg/VERSION")" == "$ffmpeg_tag" ]] || + fail "ffmpeg-source VERSION does not name $ffmpeg_tag" + +mkdir "$work_dir/pinned" +git -C "$repo_root/ffmpeg" archive HEAD | tar -x -C "$work_dir/pinned" +rm "$source_root/jni/ffmpeg/VERSION" +diff -r "$work_dir/pinned" "$source_root/jni/ffmpeg" >"$work_dir/diff" || { + head -n 5 "$work_dir/diff" >&2 + fail "ffmpeg-source differs from the pinned FFmpeg commit" +} + +echo "check-publication: ok" diff --git a/scripts/package-ffmpeg-source.sh b/scripts/package-ffmpeg-source.sh new file mode 100755 index 0000000..0a844d2 --- /dev/null +++ b/scripts/package-ffmpeg-source.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +set -euo pipefail + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +output="$1" + +work_dir="$(mktemp -d)" +trap 'rm -rf "$work_dir"' EXIT +package_dir="$work_dir/ffmpeg-source" + +"$repo_root/scripts/stage-ffmpeg-source.sh" "$package_dir" +mkdir -p "$package_dir/scripts" +cp "$repo_root/scripts/build-ffmpeg.sh" "$repo_root/scripts/stage-ffmpeg-source.sh" "$package_dir/scripts/" +cp "$repo_root/LICENSE" "$repo_root/NOTICE" "$repo_root/gradle.properties" "$package_dir/" +cat >"$package_dir/BUILD.txt" <<'INFO' +Corresponding source for the FFmpeg libraries linked into libffmpegJNI.so. + +jni/ffmpeg FFmpeg at the pinned tag, with a VERSION file naming it +jni/build_ffmpeg.sh AndroidX Media3's FFmpeg build script +jni/CMakeLists.txt links libffmpegJNI.so from the FFmpeg libraries +jni/ffmpeg_jni.cc the JNI wrapper, Apache-2.0 +gradle.properties NDK version, minimum SDK and decoder list of this release +scripts/ how the release stages this tree and records its configuration + +Rebuild the FFmpeg static libraries for every ABI from this directory, with +host set to linux-x86_64 or darwin-x86_64 and NDK set to the NDK path: + + jni/build_ffmpeg.sh "$PWD" "$NDK" "$host" \ + "$(sed -n 's/^ffmpegMinSdk=//p' gradle.properties)" \ + $(sed -n 's/^ffmpegDecoders=//p' gradle.properties) + +The libraries land in jni/ffmpeg/android-libs/. Delete jni/ffmpeg/VERSION +before you compile jni/ffmpeg_jni.cc: on a case-insensitive file system it +shadows the C++ header. +INFO + +mkdir -p "$(dirname "$output")" +tar -cJf "$output" -C "$work_dir" ffmpeg-source diff --git a/scripts/stage-ffmpeg-source.sh b/scripts/stage-ffmpeg-source.sh new file mode 100755 index 0000000..92a60e3 --- /dev/null +++ b/scripts/stage-ffmpeg-source.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -euo pipefail + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +module_dir="$1" + +upstream_jni="$repo_root/media/libraries/decoder_ffmpeg/src/main/jni" +ffmpeg_tag="$(git -C "$repo_root" config -f .gitmodules submodule.ffmpeg.branch)" + +mkdir -p "$module_dir/jni/ffmpeg" +cp "$upstream_jni/build_ffmpeg.sh" "$upstream_jni/CMakeLists.txt" "$upstream_jni/ffmpeg_jni.cc" "$module_dir/jni/" +git -C "$repo_root/ffmpeg" archive HEAD | tar -x -C "$module_dir/jni/ffmpeg" +printf '%s\n' "$ffmpeg_tag" >"$module_dir/jni/ffmpeg/VERSION" diff --git a/scripts/verify-release-shape.sh b/scripts/verify-release-shape.sh new file mode 100755 index 0000000..0a75574 --- /dev/null +++ b/scripts/verify-release-shape.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -euo pipefail + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +media3_version="$(sed -n 's/^releaseVersion = "\(.*\)"$/\1/p' "$repo_root/media/gradle/libs.versions.toml")" +if [[ -z "$media3_version" ]]; then + echo "verify-release-shape: no releaseVersion in the media submodule" >&2 + exit 1 +fi + +GNUPGHOME="$(mktemp -d)" +export GNUPGHOME +trap 'rm -rf "$GNUPGHOME"' EXIT +gpg --batch --quiet --pinentry-mode loopback --passphrase '' \ + --quick-generate-key 'media3-ffmpeg-decoder verify ' rsa3072 sign never + +ORG_GRADLE_PROJECT_signingInMemoryKey="$(gpg --batch --armor --export-secret-keys)" +export ORG_GRADLE_PROJECT_signingInMemoryKey + +cd "$repo_root" +./gradlew verify --no-configuration-cache "-Pversion=$media3_version+1" "$@" From aba5a5562c2a0f905312ccfaad2ce57b3f61eb55 Mon Sep 17 00:00:00 2001 From: Altay Date: Sun, 8 Nov 2026 14:45:32 +0300 Subject: [PATCH 2/4] ci: retry slow Gradle distribution downloads The wrapper failed twice on a 10 second read timeout with no retry, and a release tag run would hit the same failure. --- gradle/wrapper/gradle-wrapper.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ad7845b..c032f1e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,8 +1,8 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-9.7.1-bin.zip -networkTimeout=10000 -retries=0 +networkTimeout=60000 +retries=3 retryBackOffMs=500 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME From 6b2a67db6bd51be9d1f0d806613bfaf0ff9b4981 Mon Sep 17 00:00:00 2001 From: Altay Date: Sun, 8 Nov 2026 15:28:16 +0300 Subject: [PATCH 3/4] fix: keep GPL code out of the FFmpeg build and source FFmpeg n7.1.5 builds GPL-headed aarch64 ac3dsp files without a CONFIG_GPL gate, so a configure line that says LGPL still shipped GPL object code in the arm64 library. A staged patch drops those files from the build and keeps the ac3 and eac3 decoders on the C implementation. Staging also deletes every other GPL-headed file, and a new gate scans the objects compiled into each ABI. The AAR and NOTICE now carry FFmpeg's LICENSE.md and every compiled non-LGPL notice, the POM uses one combined license entry, and BUILD.txt gives the rebuild and relink commands. --- NOTICE | 421 ++++++++++++++++++++++++++++- README.md | 20 +- build.gradle.kts | 28 +- patches/ffmpeg-lgpl-only.patch | 44 +++ scripts/apply-ffmpeg-patch.sh | 10 + scripts/build-ffmpeg.sh | 10 +- scripts/check-aar.sh | 12 + scripts/check-ffmpeg-licenses.sh | 56 ++++ scripts/check-negative-controls.sh | 136 +++++++++- scripts/check-publication.sh | 21 +- scripts/classify-license.pl | 164 +++++++++++ scripts/ffmpeg-gpl-files.sh | 10 + scripts/list-compiled-sources.pl | 41 +++ scripts/package-ffmpeg-source.sh | 68 ++++- scripts/record-objects/make | 16 ++ scripts/stage-ffmpeg-source.sh | 1 + 16 files changed, 1013 insertions(+), 45 deletions(-) create mode 100644 patches/ffmpeg-lgpl-only.patch create mode 100755 scripts/apply-ffmpeg-patch.sh create mode 100755 scripts/check-ffmpeg-licenses.sh create mode 100755 scripts/classify-license.pl create mode 100755 scripts/ffmpeg-gpl-files.sh create mode 100755 scripts/list-compiled-sources.pl create mode 100755 scripts/record-objects/make diff --git a/NOTICE b/NOTICE index b36a8cf..2f1044e 100644 --- a/NOTICE +++ b/NOTICE @@ -6,19 +6,432 @@ This project is licensed under the Apache License, Version 2.0. See LICENSE. The AAR published by this project bundles FFmpeg libraries (libavcodec, libavutil and libswresample) linked into libffmpegJNI. FFmpeg is Copyright (c) 2000-2026 the FFmpeg developers and is licensed under the GNU Lesser General -Public License, version 2.1 or later. FFmpeg is built without --enable-gpl, ---enable-nonfree and --enable-version3. +Public License, version 2.1 or later. FFmpeg's own license file ships in the +AAR as META-INF/media3-ffmpeg-decoder/FFMPEG-LICENSE.md. FFmpeg is built without +--enable-gpl, --enable-nonfree and --enable-version3. + +Changes put.io made to FFmpeg (LGPL 2.1 section 2a): + +- 2026-11-08: libavcodec/ac3dsp.c and libavcodec/aarch64/Makefile are changed by + patches/ffmpeg-lgpl-only.patch, so the ac3 and eac3 decoders use the C + implementation on arm64. Both files carry a dated notice of the change. +- 2026-11-08: libavcodec/aarch64/ac3dsp_init_aarch64.c and + libavcodec/aarch64/ac3dsp_neon.S are deleted. FFmpeg licenses them under the + GPL and builds them without --enable-gpl. +- Every other file in the FFmpeg tree whose header grants the GPL is deleted + too. None of them is compiled into this project. Source and build instructions for FFmpeg in a released AAR: - Every release publishes the corresponding source next to the AAR on Maven Central, signed like the AAR. It has the classifier ffmpeg-source: https://repo1.maven.org/maven2/io/put/media3-ffmpeg-decoder//media3-ffmpeg-decoder--ffmpeg-source.tar.xz -- That archive holds the FFmpeg source at the pinned commit, the JNI wrapper - that links it, the build scripts, and BUILD.txt with the rebuild command. +- That archive holds the FFmpeg source that was built, the patch, the JNI + wrapper that links it, the build scripts, and BUILD.txt with the commands to + rebuild FFmpeg and relink libffmpegJNI.so. - Every AAR carries META-INF/media3-ffmpeg-decoder/ffmpeg-build.txt with the exact FFmpeg commit, build script and per-ABI configure lines, and the LGPL text in META-INF/media3-ffmpeg-decoder/COPYING.LGPLv2.1. The JNI wrapper and Java classes are built from AndroidX Media3, Copyright The Android Open Source Project, licensed under the Apache License, Version 2.0. + +This software is based in part on the work of the Independent JPEG Group. + +Third-party notices from FFmpeg files compiled into libffmpegJNI, per compiled +file set on arm64-v8a, armeabi-v7a, x86_64 or x86: + +--- zlib License + +libavcodec/aarch64/fdctdsp_neon.S +libavutil/adler32.c + +Copyright (C) 2009-2011, Nokia Corporation and/or its subsidiary(-ies). + All Rights Reserved. +Author: Siarhei Siamashka +Copyright (C) 2013-2014, Linaro Limited. All Rights Reserved. +Author: Ragesh Radhakrishnan +Copyright (C) 2014-2016, 2020, D. R. Commander. All Rights Reserved. +Copyright (C) 2015-2016, 2018, Matthieu Darbois. All Rights Reserved. +Copyright (C) 2016, Siarhei Siamashka. All Rights Reserved. + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. + +Copyright (C) 1995 Mark Adler + +--- MIT License + +libavcodec/arm/jrevdct_arm.S +libavutil/avsscanf.c + + Copyright (c) 2001 Lionel Ulmer (lionel.ulmer@free.fr / bbrox@bbrox.org) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Copyright (c) 2005-2014 Rich Felker, et al. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +--- ISC License + +libavcodec/faandct.c + +Copyright (c) 2003 Michael Niedermayer +Copyright (c) 2003 Roman Shaposhnik + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +--- Independent JPEG Group license + +libavcodec/jfdctfst.c +libavcodec/jfdctint_template.c +libavcodec/jrevdct.c + +This file is part of the Independent JPEG Group's software. + +The authors make NO WARRANTY or representation, either express or implied, +with respect to this software, its quality, accuracy, merchantability, or +fitness for a particular purpose. This software is provided "AS IS", and +you, its user, assume the entire risk as to its quality and accuracy. + +This software is copyright (C) 1994-1996, Thomas G. Lane. +All Rights Reserved except as specified below. + +Permission is hereby granted to use, copy, modify, and distribute this +software (or portions thereof) for any purpose, without fee, subject to +these conditions: +(1) If any part of the source code for this software is distributed, then +this README file must be included, with this copyright and no-warranty +notice unaltered; and any additions, deletions, or changes to the original +files must be clearly indicated in accompanying documentation. +(2) If only executable code is distributed, then the accompanying +documentation must state that "this software is based in part on the work +of the Independent JPEG Group". +(3) Permission for use of this software is granted only if the user accepts +full responsibility for any undesirable consequences; the authors accept +NO LIABILITY for damages of any kind. + +These conditions apply to any software derived from or based on the IJG +code, not just to the unmodified library. If you use our work, you ought +to acknowledge us. + +Permission is NOT granted for the use of any IJG author's name or company +name in advertising or publicity relating to this software or products +derived from it. This software may be referred to only as "the Independent +JPEG Group's software". + +We specifically permit and encourage the use of this software as the basis +of commercial products, provided that all warranty or liability claims are +assumed by the product vendor. + +This software is copyright (C) 1991-1996, Thomas G. Lane. +All Rights Reserved except as specified below. + +This software is copyright (C) 1991, 1992, Thomas G. Lane. +All Rights Reserved except as specified below. + +--- Boost Software License 1.0 (on top of the LGPL grant of the file) + +libavutil/libm.h +libavutil/mathematics.c + +erf function +Algorithm taken from the Boost project, source: +http://www.boost.org/doc/libs/1_46_1/boost/math/special_functions/erf.hpp +Use, modification and distribution are subject to the +Boost Software License, Version 1.0 (see notice below). +Boost Software License - Version 1.0 - August 17th, 2003 +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + +0th order modified bessel function of the first kind. +Algorithm taken from the Boost project, source: +https://searchcode.com/codesearch/view/14918379/ +Use, modification and distribution are subject to the +Boost Software License, Version 1.0 (see notice below). +Boost Software License - Version 1.0 - August 17th, 2003 +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +--- BSD 3-clause License (on top of the LGPL grant of the file) + +libavutil/fixed_dsp.c +libavutil/fixed_dsp.h +libavutil/softfloat_tables.h +libavutil/uuid.c + +Copyright (c) 2012 + MIPS Technologies, Inc., California. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. Neither the name of the MIPS Technologies, Inc., nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. Neither the name of the MIPS Technologies, Inc., nor the names of is + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +Copyright (C) 1996, 1997 Theodore Ts'o. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, and the entire permission notice in its entirety, + including the disclaimer of warranties. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. The name of the author may not be used to endorse or promote + products derived from this software without specific prior + written permission. + +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF +WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH +DAMAGE. + +--- Attribution (on top of the LGPL grant of the file) + +libavutil/sha.c + +Copyright (C) 2007 Michael Niedermayer +Copyright (C) 2009 Konstantin Shishkov +based on public domain SHA-1 code by Steve Reid +and on BSD-licensed SHA-2 code by Aaron D. Gifford + +FFmpeg LICENSE.md, verbatim: + +# License + +Most files in FFmpeg are under the GNU Lesser General Public License version 2.1 +or later (LGPL v2.1+). Read the file `COPYING.LGPLv2.1` for details. Some other +files have MIT/X11/BSD-style licenses. In combination the LGPL v2.1+ applies to +FFmpeg. + +Some optional parts of FFmpeg are licensed under the GNU General Public License +version 2 or later (GPL v2+). See the file `COPYING.GPLv2` for details. None of +these parts are used by default, you have to explicitly pass `--enable-gpl` to +configure to activate them. In this case, FFmpeg's license changes to GPL v2+. + +Specifically, the GPL parts of FFmpeg are: + +- libpostproc +- optional x86 optimization in the files + - `libavcodec/x86/flac_dsp_gpl.asm` + - `libavcodec/x86/idct_mmx.c` + - `libavfilter/x86/vf_removegrain.asm` +- the following building and testing tools + - `compat/solaris/make_sunver.pl` + - `doc/t2h.pm` + - `doc/texi2pod.pl` + - `libswresample/tests/swresample.c` + - `tests/checkasm/*` + - `tests/tiny_ssim.c` +- the following filters in libavfilter: + - `signature_lookup.c` + - `vf_blackframe.c` + - `vf_boxblur.c` + - `vf_colormatrix.c` + - `vf_cover_rect.c` + - `vf_cropdetect.c` + - `vf_delogo.c` + - `vf_eq.c` + - `vf_find_rect.c` + - `vf_fspp.c` + - `vf_histeq.c` + - `vf_hqdn3d.c` + - `vf_kerndeint.c` + - `vf_lensfun.c` (GPL version 3 or later) + - `vf_mcdeint.c` + - `vf_mpdecimate.c` + - `vf_nnedi.c` + - `vf_owdenoise.c` + - `vf_perspective.c` + - `vf_phase.c` + - `vf_pp.c` + - `vf_pp7.c` + - `vf_pullup.c` + - `vf_repeatfields.c` + - `vf_sab.c` + - `vf_signature.c` + - `vf_smartblur.c` + - `vf_spp.c` + - `vf_stereo3d.c` + - `vf_super2xsai.c` + - `vf_tinterlace.c` + - `vf_uspp.c` + - `vf_vaguedenoiser.c` + - `vsrc_mptestsrc.c` + +Should you, for whatever reason, prefer to use version 3 of the (L)GPL, then +the configure parameter `--enable-version3` will activate this licensing option +for you. Read the file `COPYING.LGPLv3` or, if you have enabled GPL parts, +`COPYING.GPLv3` to learn the exact legal terms that apply in this case. + +There are a handful of files under other licensing terms, namely: + +* The files `libavcodec/jfdctfst.c`, `libavcodec/jfdctint_template.c` and + `libavcodec/jrevdct.c` are taken from libjpeg, see the top of the files for + licensing details. Specifically note that you must credit the IJG in the + documentation accompanying your program if you only distribute executables. + You must also indicate any changes including additions and deletions to + those three files in the documentation. +* `tests/reference.pnm` is under the expat license. + + +## External libraries + +FFmpeg can be combined with a number of external libraries, which sometimes +affect the licensing of binaries resulting from the combination. + +### Compatible libraries + +The following libraries are under GPL version 2: +- avisynth +- frei0r +- libcdio +- libdavs2 +- librubberband +- libvidstab +- libx264 +- libx265 +- libxavs +- libxavs2 +- libxvid + +When combining them with FFmpeg, FFmpeg needs to be licensed as GPL as well by +passing `--enable-gpl` to configure. + +The following libraries are under LGPL version 3: +- gmp +- libaribb24 +- liblensfun + +When combining them with FFmpeg, use the configure option `--enable-version3` to +upgrade FFmpeg to the LGPL v3. + +The VMAF, mbedTLS, RK MPI, OpenCORE and VisualOn libraries are under the Apache License +2.0. That license is incompatible with the LGPL v2.1 and the GPL v2, but not with +version 3 of those licenses. So to combine these libraries with FFmpeg, the +license version needs to be upgraded by passing `--enable-version3` to configure. + +The smbclient library is under the GPL v3, to combine it with FFmpeg, +the options `--enable-gpl` and `--enable-version3` have to be passed to +configure to upgrade FFmpeg to the GPL v3. + +### Incompatible libraries + +There are certain libraries you can combine with FFmpeg whose licenses are not +compatible with the GPL and/or the LGPL. If you wish to enable these +libraries, even in circumstances that their license may be incompatible, pass +`--enable-nonfree` to configure. This will cause the resulting binary to be +unredistributable. + +The Fraunhofer FDK AAC and OpenSSL libraries are under licenses which are +incompatible with the GPLv2 and v3. To the best of our knowledge, they are +compatible with the LGPL. diff --git a/README.md b/README.md index bc64d12..5c7d1d9 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,10 @@ cd media3-ffmpeg-decoder `./gradlew verify` builds FFmpeg with Media3's own `build_ffmpeg.sh`, then publishes to Maven Local and fails the build on what a release must not ship: -- [check-aar.sh](./scripts/check-aar.sh): a non-LGPL FFmpeg, a decoder outside the allowed set, a missing per-ABI configure line, a 64-bit library not aligned to 16 KB, a missing ABI or a missing renderer class. -- [check-publication.sh](./scripts/check-publication.sh): a POM without both licenses, a missing sources or javadoc jar, or an `ffmpeg-source` archive that differs from the pinned FFmpeg. -- [check-negative-controls.sh](./scripts/check-negative-controls.sh): proves both checks fail on broken input. +- [check-ffmpeg-licenses.sh](./scripts/check-ffmpeg-licenses.sh): any GPL source compiled into any ABI, from the objects each ABI actually built, or a compiled non-LGPL notice missing from [NOTICE](./NOTICE). Runs during `buildFfmpeg`. +- [check-aar.sh](./scripts/check-aar.sh): a non-LGPL FFmpeg, a decoder outside the allowed set, a missing per-ABI configure line, a 64-bit library not aligned to 16 KB, a missing ABI, a missing renderer class, a missing notice file, or a `RELEASE` that disagrees with the pinned tag. +- [check-publication.sh](./scripts/check-publication.sh): a POM without the single combined license entry, a missing sources or javadoc jar, an `ffmpeg-source` archive that differs from the pinned FFmpeg plus [patches/ffmpeg-lgpl-only.patch](./patches/ffmpeg-lgpl-only.patch), or a GPL file in that archive. +- [check-negative-controls.sh](./scripts/check-negative-controls.sh): proves each check fails on broken input. CI runs [verify-release-shape.sh](./scripts/verify-release-shape.sh), which does the same with a release version and a throwaway signing key. @@ -60,6 +61,8 @@ git add .gitmodules ffmpeg ./gradlew verify ``` +[check-ffmpeg-licenses.sh](./scripts/check-ffmpeg-licenses.sh) fails on a new GPL source or a new third-party notice. Remove a GPL source with [patches/ffmpeg-lgpl-only.patch](./patches/ffmpeg-lgpl-only.patch). Add a new notice to [NOTICE](./NOTICE) from `scripts/classify-license.pl --print-notices <<-ffmpeg-source.tar.xz`: the pinned FFmpeg tree, the JNI wrapper, the build scripts and a `BUILD.txt` with the rebuild command. See [NOTICE](./NOTICE). +The AAR bundles FFmpeg, which is LGPL-2.1-or-later. FFmpeg is built without `--enable-gpl`, `--enable-nonfree` and `--enable-version3`. On arm64, [patches/ffmpeg-lgpl-only.patch](./patches/ffmpeg-lgpl-only.patch) removes FFmpeg's GPL AC-3 NEON assembly, so the ac3 and eac3 decoders run the C implementation. Each AAR carries the exact FFmpeg commit, per-ABI configure lines, LGPL text, FFmpeg's `LICENSE.md` and the third-party notices under `META-INF/media3-ffmpeg-decoder/`. The corresponding source is published next to the AAR on Maven Central as `media3-ffmpeg-decoder--ffmpeg-source.tar.xz`: the FFmpeg tree that was built, the patch, the JNI wrapper, the build scripts and a `BUILD.txt` with the commands to rebuild FFmpeg and relink `libffmpegJNI.so`. See [NOTICE](./NOTICE). + +## Shipping this in an app + +An app that bundles this AAR carries FFmpeg under the LGPL. To stay compliant: + +- Keep the notices. Show the contents of `META-INF/media3-ffmpeg-decoder/` (`NOTICE`, `LICENSE`, `COPYING.LGPLv2.1`, `FFMPEG-LICENSE.md`) in your app's licenses screen or docs, or ship them next to it. +- Offer the matching source: the `ffmpeg-source` archive of the exact version you ship, from Maven Central or your own host. +- Do not strip the notices with packaging excludes. `packaging { resources { excludes } }` must not match `META-INF/media3-ffmpeg-decoder/**`, including broad patterns like `META-INF/*` or `META-INF/**`. +- Do not prevent users from replacing `libffmpegJNI.so` with one they rebuilt from that archive. `BUILD.txt` has the commands. diff --git a/build.gradle.kts b/build.gradle.kts index 0189b51..6d43a51 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -92,6 +92,20 @@ val gitCommit = { path: String -> val ndkDirectoryPath = androidComponents.sdkComponents.ndkDirectory.map { it.asFile.path } +val ffmpegLicenseInputs = + listOf( + "NOTICE", + "LICENSE", + "patches", + "scripts/stage-ffmpeg-source.sh", + "scripts/apply-ffmpeg-patch.sh", + "scripts/ffmpeg-gpl-files.sh", + "scripts/classify-license.pl", + "scripts/list-compiled-sources.pl", + "scripts/check-ffmpeg-licenses.sh", + "scripts/record-objects", + ) + val buildFfmpeg = tasks.register("buildFfmpeg") { group = "build" @@ -100,7 +114,7 @@ val buildFfmpeg = inputs.property("ffmpegCommit", gitCommit("ffmpeg")) inputs.property("media3Commit", gitCommit("media")) inputs - .files("NOTICE", "LICENSE", "scripts/stage-ffmpeg-source.sh") + .files(ffmpegLicenseInputs) .withPathSensitivity(PathSensitivity.RELATIVE) outputs.dir(stagedModule) arguments.add(ndkDirectoryPath) @@ -117,7 +131,7 @@ val packageFfmpegSource = inputs.property("ffmpegCommit", gitCommit("ffmpeg")) inputs.property("media3Commit", gitCommit("media")) inputs - .files("NOTICE", "LICENSE", "gradle.properties", "scripts/stage-ffmpeg-source.sh", "scripts/build-ffmpeg.sh") + .files(ffmpegLicenseInputs, "gradle.properties", "scripts/build-ffmpeg.sh") .withPathSensitivity(PathSensitivity.RELATIVE) outputs.file(ffmpegSourceArchive) arguments.add(ffmpegSourceArchive.map { it.asFile.path }) @@ -243,13 +257,9 @@ mavenPublishing { licenses { license { - name.set("Apache-2.0") - url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") - } - license { - name.set("LGPL-2.1-or-later") - url.set("https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt") - comments.set("The FFmpeg libraries statically linked into libffmpegJNI") + name.set("Apache-2.0 AND LGPL-2.1-or-later") + url.set("https://github.com/putdotio/media3-ffmpeg-decoder/blob/main/NOTICE") + comments.set("Apache-2.0 for the Java classes and JNI wrapper, LGPL-2.1-or-later for the FFmpeg libraries statically linked into libffmpegJNI") } } diff --git a/patches/ffmpeg-lgpl-only.patch b/patches/ffmpeg-lgpl-only.patch new file mode 100644 index 0000000..f8822f9 --- /dev/null +++ b/patches/ffmpeg-lgpl-only.patch @@ -0,0 +1,44 @@ +--- a/libavcodec/aarch64/Makefile ++++ b/libavcodec/aarch64/Makefile +@@ -1,5 +1,7 @@ ++# Modified by put.io on 2026-11-08: removed ac3dsp_init_aarch64.o and ++# ac3dsp_neon.o, whose sources are licensed under the GPL. ++ + # subsystems +-OBJS-$(CONFIG_AC3DSP) += aarch64/ac3dsp_init_aarch64.o + OBJS-$(CONFIG_FDCTDSP) += aarch64/fdctdsp_init_aarch64.o + OBJS-$(CONFIG_FMTCONVERT) += aarch64/fmtconvert_init.o + OBJS-$(CONFIG_H264CHROMA) += aarch64/h264chroma_init_aarch64.o +@@ -38,7 +40,6 @@ + + # subsystems + NEON-OBJS-$(CONFIG_AAC_DECODER) += aarch64/sbrdsp_neon.o +-NEON-OBJS-$(CONFIG_AC3DSP) += aarch64/ac3dsp_neon.o + NEON-OBJS-$(CONFIG_FDCTDSP) += aarch64/fdctdsp_neon.o + NEON-OBJS-$(CONFIG_FMTCONVERT) += aarch64/fmtconvert_neon.o + NEON-OBJS-$(CONFIG_H264CHROMA) += aarch64/h264cmc_neon.o +--- a/libavcodec/ac3dsp.c ++++ b/libavcodec/ac3dsp.c +@@ -19,6 +19,11 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++/* ++ * Modified by put.io on 2026-11-08: aarch64 uses the C implementation, because ++ * FFmpeg's aarch64 assembly for this DSP is licensed under the GPL. ++ */ ++ + #include + #include + #include +@@ -389,9 +394,7 @@ + c->downmix = NULL; + c->downmix_fixed = NULL; + +-#if ARCH_AARCH64 +- ff_ac3dsp_init_aarch64(c); +-#elif ARCH_ARM ++#if ARCH_ARM + ff_ac3dsp_init_arm(c); + #elif ARCH_X86 + ff_ac3dsp_init_x86(c); diff --git a/scripts/apply-ffmpeg-patch.sh b/scripts/apply-ffmpeg-patch.sh new file mode 100755 index 0000000..5bd55b3 --- /dev/null +++ b/scripts/apply-ffmpeg-patch.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -euo pipefail + +scripts_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +tree="$1" + +patch -d "$tree" -p1 -N -F 0 -s -i "$scripts_dir/../patches/ffmpeg-lgpl-only.patch" +"$scripts_dir/ffmpeg-gpl-files.sh" "$tree" | while IFS= read -r gpl_file; do + rm "$tree/$gpl_file" +done diff --git a/scripts/build-ffmpeg.sh b/scripts/build-ffmpeg.sh index 19dba66..0421e2c 100755 --- a/scripts/build-ffmpeg.sh +++ b/scripts/build-ffmpeg.sh @@ -20,10 +20,15 @@ build_log="$module_dir/build.log" rm -rf "$module_dir" "$repo_root/scripts/stage-ffmpeg-source.sh" "$module_dir" -if ! "$module_dir/jni/build_ffmpeg.sh" "$module_dir" "$ndk_path" "$host_platform" "$min_sdk" "${decoders[@]}" >"$build_log" 2>&1; then +objects_dir="$module_dir/compiled-objects" +export FFMPEG_OBJECTS_DIR="$objects_dir" +FFMPEG_REAL_MAKE="$(command -v make)" +export FFMPEG_REAL_MAKE +if ! PATH="$repo_root/scripts/record-objects:$PATH" "$module_dir/jni/build_ffmpeg.sh" "$module_dir" "$ndk_path" "$host_platform" "$min_sdk" "${decoders[@]}" >"$build_log" 2>&1; then tail -n 80 "$build_log" >&2 exit 1 fi +"$repo_root/scripts/check-ffmpeg-licenses.sh" "$module_dir/jni/ffmpeg" "$objects_dir" "$repo_root/NOTICE" "$ndk_path" "$module_dir/compiled-licenses.txt" rm "$module_dir/jni/ffmpeg/VERSION" ffmpeg_commit="$(git -C "$repo_root/ffmpeg" rev-parse HEAD)" @@ -44,9 +49,10 @@ mkdir -p "$license_dir" cp "$repo_root/LICENSE" "$license_dir/LICENSE" cp "$repo_root/NOTICE" "$license_dir/NOTICE" cp "$repo_root/ffmpeg/COPYING.LGPLv2.1" "$license_dir/COPYING.LGPLv2.1" +cp "$repo_root/ffmpeg/LICENSE.md" "$license_dir/FFMPEG-LICENSE.md" cat >"$license_dir/ffmpeg-build.txt" <&2 + exit 1 +} + +work_dir="$(mktemp -d)" +trap 'rm -rf "$work_dir"' EXIT + +perl -e 'local $/; my @texts = map { open my $fh, "<", $_ or die; my $t = <$fh>; $t =~ s/\s+/ /g; $t =~ s/^ | $//g; $t } @ARGV; exit(index($texts[1], $texts[0]) >= 0 ? 0 : 1)' "$ffmpeg_dir/LICENSE.md" "$notice_file" || + fail "NOTICE is missing FFmpeg's LICENSE.md" + +wrapper_grant="$("$scripts_dir/classify-license.pl" "$(dirname "$ffmpeg_dir")" <<"$report" +for abi in arm64-v8a armeabi-v7a x86_64 x86; do + [[ -d "$objects_dir/$abi" ]] || fail "no recorded objects for $abi" + listing="$work_dir/$abi.listing" + "$scripts_dir/list-compiled-sources.pl" "$ffmpeg_dir" "$objects_dir/$abi" >"$listing" 2>"$work_dir/error" || + fail "$(cat "$work_dir/error")" + + awk -F'\t' '$1 == "object" { n = split($2, parts, "/"); print parts[n] }' "$listing" | sort -u >"$work_dir/recorded" + for library in avcodec avutil swresample; do + archive="$ffmpeg_dir/android-libs/$abi/lib$library.a" + [[ -f "$archive" ]] || fail "no static library $archive" + "$llvm_ar" t "$archive" + done | grep -F .o | sort -u >"$work_dir/members" + unrecorded="$(comm -23 "$work_dir/members" "$work_dir/recorded")" + [[ -z "$unrecorded" ]] || fail "$abi archive members have no recorded object: $unrecorded" + + awk -F'\t' '$1 != "object" { print $2 }' "$listing" | + "$scripts_dir/classify-license.pl" "$ffmpeg_dir" "$notice_file" >"$work_dir/$abi.classes" + + gpl_sources="$(awk -F'\t' '$1 == "gpl" { print $3 }' "$work_dir/$abi.classes")" + [[ -z "$gpl_sources" ]] || fail "GPL source compiled into $abi: $gpl_sources" + + awk -F'\t' -v abi="$abi" '$1 != "lgpl" || $2 != "-" { print abi "\t" $1 "\t" $2 "\t" $3 }' \ + "$work_dir/$abi.classes" >>"$report" + + missing_notices="$(awk -F'\t' '$4 == "missing-notice" { print $3 }' "$work_dir/$abi.classes")" + [[ -z "$missing_notices" ]] || fail "NOTICE is missing notices for $abi: $missing_notices" +done + +echo "check-ffmpeg-licenses: ok, no GPL source in any ABI, $(wc -l <"$report" | tr -d ' ') non-LGPL entries" diff --git a/scripts/check-negative-controls.sh b/scripts/check-negative-controls.sh index f58d749..e0007dc 100755 --- a/scripts/check-negative-controls.sh +++ b/scripts/check-negative-controls.sh @@ -2,6 +2,7 @@ set -euo pipefail scripts_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +repo_root="$(dirname "$scripts_dir")" aar="$1" build_log="$2" ndk_path="$3" @@ -50,12 +51,35 @@ mutate_build_info() { (cd "$aar_dir" && zip -qr "$work_dir/mutated.aar" .) } -mutate_config_components() { +mirror_for_aar() { local mirror="$work_dir/ffmpeg" rm -rf "$mirror" mkdir -p "$mirror" ln -s "$ffmpeg_dir/android-libs" "$mirror/android-libs" - sed "$1" "$ffmpeg_dir/config_components.h" >"$mirror/config_components.h" + cp "$ffmpeg_dir/RELEASE" "$mirror/RELEASE" + cp "$ffmpeg_dir/config_components.h" "$mirror/config_components.h" +} + +mutate_config_components() { + mirror_for_aar + sed "$1" "$ffmpeg_dir/config_components.h" >"$work_dir/ffmpeg/config_components.h" +} + +mutate_release() { + mirror_for_aar + printf '%s\n' "$1" >"$work_dir/ffmpeg/RELEASE" +} + +drop_classes_entry() { + local aar_dir="$work_dir/aar" + local classes_dir="$work_dir/classes" + rm -rf "$aar_dir" "$classes_dir" "$work_dir/mutated.aar" + mkdir -p "$aar_dir" "$classes_dir" + unzip -q "$aar" -d "$aar_dir" + unzip -q "$aar_dir/classes.jar" -d "$classes_dir" + rm "$classes_dir/$1" "$aar_dir/classes.jar" + (cd "$classes_dir" && zip -qr "$aar_dir/classes.jar" .) + (cd "$aar_dir" && zip -qr "$work_dir/mutated.aar" .) } mutate_build_info 's/^Configuration arm64-v8a: .*/Configuration arm64-v8a: /' @@ -73,6 +97,84 @@ expect_aar_failure "enabled decoders differ from the allowed set" "$aar" "$work_ mutate_config_components 's/^#define CONFIG_TRUEHD_DECODER 1$/#define CONFIG_TRUEHD_DECODER 0/' expect_aar_failure "enabled decoders differ from the allowed set" "$aar" "$work_dir/ffmpeg" +mutate_release "0.0.0" +expect_aar_failure "does not match .gitmodules tag" "$aar" "$work_dir/ffmpeg" + +drop_classes_entry META-INF/media3-ffmpeg-decoder/FFMPEG-LICENSE.md +expect_aar_failure "classes.jar is missing META-INF/media3-ffmpeg-decoder/FFMPEG-LICENSE.md" "$work_dir/mutated.aar" "$ffmpeg_dir" + +module_dir="$(dirname "$(dirname "$ffmpeg_dir")")" +gate="$work_dir/gate" +gate_report="$work_dir/gate-report" + +reset_gate() { + rm -rf "$gate" + mkdir -p "$gate/jni" + cp -R "$ffmpeg_dir" "$gate/jni/ffmpeg" + cp "$module_dir/jni/ffmpeg_jni.cc" "$gate/jni/ffmpeg_jni.cc" + cp -R "$module_dir/compiled-objects" "$gate/compiled-objects" + cp "$repo_root/NOTICE" "$gate/NOTICE" +} + +expect_gate_failure() { + expect_failure "$1" "$scripts_dir/check-ffmpeg-licenses.sh" "$gate/jni/ffmpeg" "$gate/compiled-objects" "$gate/NOTICE" "$ndk_path" "$gate_report" +} + +record_compiled_object() { + local abi="$1" object="$2" + shift 2 + mkdir -p "$gate/compiled-objects/$abi/$(dirname "$object")" + printf '%s: %s\n' "$object" "$*" >"$gate/compiled-objects/$abi/${object%.o}.d" +} + +restore_pristine() { + git -C "$repo_root/ffmpeg" show "HEAD:$1" >"$gate/jni/ffmpeg/$1" +} + +gate_clean="$("$scripts_dir/check-ffmpeg-licenses.sh" "$ffmpeg_dir" "$module_dir/compiled-objects" "$repo_root/NOTICE" "$ndk_path" "$gate_report")" +grep -q "ok, no GPL source" <<<"$gate_clean" || die "gate did not pass on the real tree: $gate_clean" + +reset_gate +restore_pristine libavcodec/aarch64/ac3dsp_neon.S +record_compiled_object arm64-v8a libavcodec/aarch64/ac3dsp_neon.o libavcodec/aarch64/ac3dsp_neon.S +expect_gate_failure "GPL source compiled into arm64-v8a: libavcodec/aarch64/ac3dsp_neon.S" + +reset_gate +restore_pristine libavcodec/aarch64/ac3dsp_init_aarch64.c +record_compiled_object armeabi-v7a libavcodec/includer.o libavcodec/ac3dsp.c libavcodec/aarch64/ac3dsp_init_aarch64.c +expect_gate_failure "GPL source compiled into armeabi-v7a: libavcodec/aarch64/ac3dsp_init_aarch64.c" + +reset_gate +cat >"$gate/jni/ffmpeg/libavutil/wrapped_gpl.c" <<'SOURCE' +/* + * This file is free software; you can redistribute it under the terms + * of the GNU General + * Public License as published by the Free Software Foundation. + */ +SOURCE +record_compiled_object x86 libavutil/wrapped_gpl.o libavutil/wrapped_gpl.c +expect_gate_failure "GPL source compiled into x86: libavutil/wrapped_gpl.c" + +reset_gate +record_compiled_object x86_64 libavcodec/absent.o libavcodec/absent.c +expect_gate_failure "source libavcodec/absent.c is not in the tree" + +reset_gate +rm "$gate/compiled-objects/arm64-v8a/libavcodec/ac3dsp.d" +expect_gate_failure "arm64-v8a archive members have no recorded object" + +reset_gate +rm -rf "$gate/compiled-objects/x86" +expect_gate_failure "no recorded objects for x86" + +reset_gate +perl -0pi -e 's/The following libraries are under GPL/The following libraries are under a tampered license/' "$gate/NOTICE" +expect_gate_failure "NOTICE is missing FFmpeg's LICENSE.md" + +reset_gate +sed -i.bak '/avsscanf/d;/Rich Felker/d' "$gate/NOTICE" +expect_gate_failure "NOTICE is missing notices for arm64-v8a:" + publication="$work_dir/publication" prefix="$publication/media3-ffmpeg-decoder-$version" @@ -101,12 +203,12 @@ for suffix in .aar .pom -sources.jar -javadoc.jar -ffmpeg-source.tar.xz; do done reset_publication -sed -i.bak '/LGPL-2.1-or-later/d' "$prefix.pom" -expect_publication_failure "POM is missing license LGPL-2.1-or-later" +sed -i.bak 's##Apache-2.0#' "$prefix.pom" +expect_publication_failure "POM must declare exactly one combined license entry" reset_publication -sed -i.bak '/Apache-2.0<\/name>/d' "$prefix.pom" -expect_publication_failure "POM is missing license Apache-2.0" +sed -i.bak 's#Apache-2.0 AND LGPL-2.1-or-later#Apache-2.0#' "$prefix.pom" +expect_publication_failure "POM is missing the combined license name" reset_publication (cd "$work_dir" && rm -f stub.jar && echo stub >stub.txt && zip -q stub.jar stub.txt && mv stub.jar "$prefix-sources.jar") @@ -130,7 +232,27 @@ expect_publication_failure "ffmpeg-source VERSION does not name" reset_publication mutate_ffmpeg_source 'echo "# patched" >>jni/ffmpeg/configure' -expect_publication_failure "ffmpeg-source differs from the pinned FFmpeg commit" +expect_publication_failure "ffmpeg-source differs from the pinned FFmpeg plus the patch" + +reset_publication +mutate_ffmpeg_source 'rm jni/ffmpeg/libavcodec/ac3dsp.c' +expect_publication_failure "ffmpeg-source differs from the pinned FFmpeg plus the patch" + +reset_publication +mutate_ffmpeg_source 'rm patches/ffmpeg-lgpl-only.patch' +expect_publication_failure "ffmpeg-source is missing patches/ffmpeg-lgpl-only.patch" + +reset_publication +mutate_ffmpeg_source 'echo "# changed" >>patches/ffmpeg-lgpl-only.patch' +expect_publication_failure "ffmpeg-source patch differs from patches/ffmpeg-lgpl-only.patch" + +reset_publication +mutate_ffmpeg_source "git -C \"$repo_root/ffmpeg\" show HEAD:libavcodec/aarch64/ac3dsp_neon.S >jni/ffmpeg/libavcodec/aarch64/ac3dsp_neon.S" +expect_publication_failure "ffmpeg-source carries GPL file libavcodec/aarch64/ac3dsp_neon.S" + +reset_publication +mutate_ffmpeg_source "git -C \"$repo_root/ffmpeg\" show HEAD:libavutil/macos_kperf.c >jni/ffmpeg/libavutil/macos_kperf.c" +expect_publication_failure "ffmpeg-source carries GPL files: libavutil/macos_kperf.c" if [[ "$signing" == signed ]]; then reset_publication diff --git a/scripts/check-publication.sh b/scripts/check-publication.sh index ea8018a..fbf7f16 100755 --- a/scripts/check-publication.sh +++ b/scripts/check-publication.sh @@ -33,9 +33,8 @@ work_dir="$(mktemp -d)" trap 'rm -rf "$work_dir"' EXIT pom_text="$(<"$pom")" -for license in Apache-2.0 LGPL-2.1-or-later; do - grep -qF "$license" <<<"$pom_text" || fail "POM is missing license $license" -done +[[ "$(grep -c '' <<<"$pom_text")" -eq 1 ]] || fail "POM must declare exactly one combined license entry" +grep -qF 'Apache-2.0 AND LGPL-2.1-or-later' <<<"$pom_text" || fail "POM is missing the combined license name" grep -qF "$version" <<<"$pom_text" || fail "POM does not declare version $version" aar_listing="$(unzip -l "$aar")" || fail "$(basename "$aar") is not a zip" @@ -55,6 +54,8 @@ for entry in \ jni/ffmpeg/configure \ jni/ffmpeg/COPYING.LGPLv2.1 \ jni/ffmpeg/VERSION \ + jni/ffmpeg/LICENSE.md \ + patches/ffmpeg-lgpl-only.patch \ jni/build_ffmpeg.sh \ jni/CMakeLists.txt \ jni/ffmpeg_jni.cc \ @@ -70,12 +71,24 @@ ffmpeg_tag="$(git -C "$repo_root" config -f .gitmodules submodule.ffmpeg.branch) [[ "$(<"$source_root/jni/ffmpeg/VERSION")" == "$ffmpeg_tag" ]] || fail "ffmpeg-source VERSION does not name $ffmpeg_tag" +for gpl_source in libavcodec/aarch64/ac3dsp_init_aarch64.c libavcodec/aarch64/ac3dsp_neon.S; do + [[ ! -e "$source_root/jni/ffmpeg/$gpl_source" ]] || fail "ffmpeg-source carries GPL file $gpl_source" +done +gpl_files="$("$repo_root/scripts/ffmpeg-gpl-files.sh" "$source_root/jni/ffmpeg")" +[[ -z "$gpl_files" ]] || fail "ffmpeg-source carries GPL files: $gpl_files" + +cmp -s "$repo_root/patches/ffmpeg-lgpl-only.patch" "$source_root/patches/ffmpeg-lgpl-only.patch" || + fail "ffmpeg-source patch differs from patches/ffmpeg-lgpl-only.patch" +grep -q 'GNU General Public' "$source_root/patches/ffmpeg-lgpl-only.patch" && + fail "ffmpeg-source patch carries GPL text" + mkdir "$work_dir/pinned" git -C "$repo_root/ffmpeg" archive HEAD | tar -x -C "$work_dir/pinned" +"$repo_root/scripts/apply-ffmpeg-patch.sh" "$work_dir/pinned" rm "$source_root/jni/ffmpeg/VERSION" diff -r "$work_dir/pinned" "$source_root/jni/ffmpeg" >"$work_dir/diff" || { head -n 5 "$work_dir/diff" >&2 - fail "ffmpeg-source differs from the pinned FFmpeg commit" + fail "ffmpeg-source differs from the pinned FFmpeg plus the patch" } echo "check-publication: ok" diff --git a/scripts/classify-license.pl b/scripts/classify-license.pl new file mode 100755 index 0000000..80ce5f7 --- /dev/null +++ b/scripts/classify-license.pl @@ -0,0 +1,164 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +my $print_notices = 0; +if (@ARGV && $ARGV[0] eq '--print-notices') { + $print_notices = 1; + shift @ARGV; +} +my ($base, $notice_path) = @ARGV; +defined $base or die "usage: classify-license.pl [--print-notices] [notice file] < relative paths\n"; + +my $license_words = qr/copyright|\(c\)|permission|warranty|redistribution|licen[sc]e|as[- ]is|rights reserved|public domain|neither the name|this notice|acknowledg|based in part|conditions|independent jpeg|disclaim|liabilit|damages|restrictions/; + +sub lines_of { + my ($path) = @_; + open my $fh, '<:raw', $path or die "classify-license: cannot read $path: $!\n"; + my @lines = <$fh>; + close $fh; + s/\r?\n$// for @lines; + return \@lines; +} + +sub header_lines { + my ($lines) = @_; + my @header; + my $in_block = 0; + for my $line (@$lines) { + my $current = $line; + if ($in_block) { + $in_block = 0 if $current =~ s{\*/.*$}{}; + push @header, $current; + next; + } + next if $current =~ /^\s*$/ || $current =~ /^#!/; + if ($current =~ m{^\s*/\*(.*)$}) { + my $rest = $1; + $in_block = 1 unless $rest =~ s{\*/.*$}{}; + push @header, $rest; + next; + } + if ($current =~ m{^\s*(?://|;|@)(.*)$}) { + push @header, $1; + next; + } + if ($current =~ /^\s*#(?!\s*(?:include|if|ifdef|ifndef|define|undef|pragma|else|elif|endif|error|warning)\b)(.*)$/) { + push @header, $1; + next; + } + last; + } + return \@header; +} + +sub normalized { + my ($lines) = @_; + my $text = join ' ', map { + my $line = $_; + $line =~ s/^\s*(?:\*+|\/\/+|;+|#+|\@)\s?//; + $line; + } @$lines; + $text =~ s/\s+/ /g; + $text =~ s/^ | $//g; + return lc $text; +} + +sub comment_blocks { + my ($lines) = @_; + my $text = join "\n", @$lines; + my @blocks; + while ($text =~ m{/\*(.*?)\*/}gs) { + push @blocks, [ split /\n/, $1 ]; + } + my @run; + for my $line (@$lines, '') { + if ($line =~ m{^\s*(?://|;|@)(.*)$}) { + push @run, $1; + } elsif (@run) { + push @blocks, [@run]; + @run = (); + } + } + return \@blocks; +} + +sub notice_tags { + my ($text) = @_; + my @tags; + push @tags, 'boost' if $text =~ /permission is hereby granted, free of charge, to any person or organization/; + push @tags, 'mit' if $text =~ /permission is hereby granted, free of charge, to any person obtaining/; + push @tags, 'bsd' if $text =~ /redistribution and use in source and binary forms/; + push @tags, 'isc' if $text =~ /permission to use, copy, modify,? and\/?or distribute/; + push @tags, 'zlib' if $text =~ /this software is provided 'as-is'/; + push @tags, 'ijg' if $text =~ /independent jpeg group/; + push @tags, 'apache' if $text =~ /licensed under the apache license/; + push @tags, 'public-domain' if $text =~ /public domain/; + return @tags; +} + +sub grant_of { + my ($text) = @_; + return 'lgpl' if $text =~ /gnu (?:lesser|library) general public licen[sc]e/ || $text =~ /(?) { + chomp $relative; + next if $relative eq ''; + my $lines = lines_of("$base/$relative"); + my $blocks = comment_blocks($lines); + my $grant = grant_of(normalized(header_lines($lines))); + my %seen; + my @tags = grep { !$seen{$_}++ } map { notice_tags(normalized($_)) } @$blocks; + my $paragraphs = @tags ? notice_paragraphs($blocks) : []; + if ($print_notices) { + next unless @tags; + printf "%s (%s)\n\n", $relative, join(', ', @tags); + print join("\n", @$_), "\n\n" for @$paragraphs; + next; + } + my $status = ''; + if (defined $notice_text && @tags) { + my $complete = @$paragraphs && index($notice_text, lc $relative) >= 0; + for my $paragraph (@$paragraphs) { + $complete &&= index($notice_text, normalized($paragraph)) >= 0; + } + $status = $complete ? "\tin-notice" : "\tmissing-notice"; + } + printf "%s\t%s\t%s%s\n", $grant, @tags ? join(',', @tags) : '-', $relative, $status; +} diff --git a/scripts/ffmpeg-gpl-files.sh b/scripts/ffmpeg-gpl-files.sh new file mode 100755 index 0000000..e16f924 --- /dev/null +++ b/scripts/ffmpeg-gpl-files.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -euo pipefail + +scripts_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +tree="$1" + +(cd "$tree" && find . -type f | sed 's#^\./##') | + grep -E '\.(c|S|h|asm|inc|cpp|cc|m|mm|pl|pm|sh|py|mak)$' | + "$scripts_dir/classify-license.pl" "$tree" | + awk -F'\t' '$1 == "gpl" { print $3 }' diff --git a/scripts/list-compiled-sources.pl b/scripts/list-compiled-sources.pl new file mode 100755 index 0000000..ed54398 --- /dev/null +++ b/scripts/list-compiled-sources.pl @@ -0,0 +1,41 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use File::Find; + +my ($tree, $record_dir) = @ARGV; +defined $record_dir or die "usage: list-compiled-sources.pl \n"; + +my @depfiles; +find(sub { push @depfiles, $File::Find::name if /\.d$/ }, $record_dir); +@depfiles or die "list-compiled-sources: no depfiles in $record_dir\n"; + +my (%objects, %sources, %includes); +for my $depfile (@depfiles) { + open my $fh, '<', $depfile or die "list-compiled-sources: cannot read $depfile: $!\n"; + local $/; + my $text = <$fh>; + close $fh; + $text =~ s/\\\r?\n/ /g; + my ($rule) = $text =~ /^(.*?:(?:\s|$).*)$/m; + defined $rule or die "list-compiled-sources: no rule in $depfile\n"; + my ($object, $prereqs) = $rule =~ /^(\S+?):\s*(.*)$/; + defined $object && $object =~ /\.o$/ or die "list-compiled-sources: no object in $depfile\n"; + $object =~ s{^\./}{}; + my @prereqs = split ' ', $prereqs; + @prereqs or die "list-compiled-sources: $object has no source\n"; + my $source = shift @prereqs; + $source =~ s{^\./}{}; + -f "$tree/$source" or die "list-compiled-sources: $object source $source is not in the tree\n"; + $objects{$object} = 1; + $sources{$source} = 1; + for my $prereq (@prereqs) { + $prereq =~ s{^\./}{}; + next if $prereq =~ m{^/}; + $includes{$prereq} = 1 if -f "$tree/$prereq"; + } +} + +print "object\t$_\n" for sort keys %objects; +print "source\t$_\n" for sort keys %sources; +print "include\t$_\n" for sort grep { !$sources{$_} } keys %includes; diff --git a/scripts/package-ffmpeg-source.sh b/scripts/package-ffmpeg-source.sh index 0a844d2..2e51a77 100755 --- a/scripts/package-ffmpeg-source.sh +++ b/scripts/package-ffmpeg-source.sh @@ -9,29 +9,67 @@ trap 'rm -rf "$work_dir"' EXIT package_dir="$work_dir/ffmpeg-source" "$repo_root/scripts/stage-ffmpeg-source.sh" "$package_dir" -mkdir -p "$package_dir/scripts" -cp "$repo_root/scripts/build-ffmpeg.sh" "$repo_root/scripts/stage-ffmpeg-source.sh" "$package_dir/scripts/" +mkdir -p "$package_dir/scripts/record-objects" "$package_dir/patches" +cp "$repo_root/patches/ffmpeg-lgpl-only.patch" "$package_dir/patches/" +cp \ + "$repo_root/scripts/build-ffmpeg.sh" \ + "$repo_root/scripts/stage-ffmpeg-source.sh" \ + "$repo_root/scripts/apply-ffmpeg-patch.sh" \ + "$repo_root/scripts/ffmpeg-gpl-files.sh" \ + "$repo_root/scripts/classify-license.pl" \ + "$repo_root/scripts/list-compiled-sources.pl" \ + "$repo_root/scripts/check-ffmpeg-licenses.sh" \ + "$package_dir/scripts/" +cp "$repo_root/scripts/record-objects/make" "$package_dir/scripts/record-objects/" cp "$repo_root/LICENSE" "$repo_root/NOTICE" "$repo_root/gradle.properties" "$package_dir/" cat >"$package_dir/BUILD.txt" <<'INFO' Corresponding source for the FFmpeg libraries linked into libffmpegJNI.so. -jni/ffmpeg FFmpeg at the pinned tag, with a VERSION file naming it -jni/build_ffmpeg.sh AndroidX Media3's FFmpeg build script -jni/CMakeLists.txt links libffmpegJNI.so from the FFmpeg libraries -jni/ffmpeg_jni.cc the JNI wrapper, Apache-2.0 -gradle.properties NDK version, minimum SDK and decoder list of this release -scripts/ how the release stages this tree and records its configuration +jni/ffmpeg FFmpeg at the pinned tag, modified as below, + with a VERSION file naming the tag +patches/ffmpeg-lgpl-only.patch the change to FFmpeg, already applied in jni/ffmpeg +jni/build_ffmpeg.sh AndroidX Media3's FFmpeg build script +jni/CMakeLists.txt the release's link of libffmpegJNI.so +jni/ffmpeg_jni.cc the JNI wrapper, Apache-2.0 +gradle.properties NDK version, minimum SDK and decoder list of this release +scripts/ how the release stages this tree and records its build -Rebuild the FFmpeg static libraries for every ABI from this directory, with -host set to linux-x86_64 or darwin-x86_64 and NDK set to the NDK path: +jni/ffmpeg differs from FFmpeg's tag in two ways. The patch is applied. Every +source file whose header grants the GPL is deleted. NOTICE names the changes. - jni/build_ffmpeg.sh "$PWD" "$NDK" "$host" \ - "$(sed -n 's/^ffmpegMinSdk=//p' gradle.properties)" \ +Set these from this directory. Pick the NDK version in gradle.properties: + + NDK=/path/to/ndk + host=linux-x86_64 # or darwin-x86_64 + abi=arm64-v8a # or armeabi-v7a, x86_64, x86 + min_sdk="$(sed -n 's/^ffmpegMinSdk=//p' gradle.properties)" + +Rebuild the FFmpeg static libraries. The script builds every ABI and writes +each one to jni/ffmpeg/android-libs/: + + jni/build_ffmpeg.sh "$PWD" "$NDK" "$host" "$min_sdk" \ $(sed -n 's/^ffmpegDecoders=//p' gradle.properties) -The libraries land in jni/ffmpeg/android-libs/. Delete jni/ffmpeg/VERSION -before you compile jni/ffmpeg_jni.cc: on a case-insensitive file system it -shadows the C++ header. +Relink libffmpegJNI.so for $abi with the NDK toolchain: + + rm -f jni/ffmpeg/VERSION + case "$abi" in + arm64-v8a) target=aarch64-linux-android; extra=-Wl,-Bsymbolic ;; + armeabi-v7a) target=armv7a-linux-androideabi; extra= ;; + x86_64) target=x86_64-linux-android; extra= ;; + x86) target=i686-linux-android; extra= ;; + esac + mkdir -p "relink/$abi" + "$NDK/toolchains/llvm/prebuilt/$host/bin/$target$min_sdk-clang++" \ + -std=c++11 -O2 -fPIC -shared -fvisibility=hidden -fvisibility-inlines-hidden \ + -Ijni/ffmpeg jni/ffmpeg_jni.cc -o "relink/$abi/libffmpegJNI.so" \ + "-Ljni/ffmpeg/android-libs/$abi" -lswresample -lavcodec -lavutil -landroid -llog \ + -Wl,--no-undefined -Wl,-z,max-page-size=16384 $extra + +Delete VERSION only after the FFmpeg build: FFmpeg reads it, and on a +case-insensitive file system it shadows the C++ header. + +Replace libffmpegJNI.so for that ABI in your app to run the rebuilt code. INFO mkdir -p "$(dirname "$output")" diff --git a/scripts/record-objects/make b/scripts/record-objects/make new file mode 100755 index 0000000..e63fd1f --- /dev/null +++ b/scripts/record-objects/make @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -euo pipefail + +if [[ "${1:-}" == clean ]]; then + abi="$(sed -n 's#^LIBDIR=.*android-libs/##p' ffbuild/config.mak)" + [[ -n "$abi" ]] || { echo "record-objects: no ABI in ffbuild/config.mak" >&2; exit 1; } + record_dir="$FFMPEG_OBJECTS_DIR/$abi" + mkdir -p "$record_dir" + while IFS= read -r object; do + depfile="${object%.o}.d" + [[ -f "$depfile" ]] || { echo "record-objects: $object has no $depfile" >&2; exit 1; } + mkdir -p "$record_dir/$(dirname "$object")" + cp "$depfile" "$record_dir/$depfile" + done < <(find . -name '*.o' | sed 's#^\./##') +fi +exec "$FFMPEG_REAL_MAKE" "$@" diff --git a/scripts/stage-ffmpeg-source.sh b/scripts/stage-ffmpeg-source.sh index 92a60e3..6a8e594 100755 --- a/scripts/stage-ffmpeg-source.sh +++ b/scripts/stage-ffmpeg-source.sh @@ -10,4 +10,5 @@ ffmpeg_tag="$(git -C "$repo_root" config -f .gitmodules submodule.ffmpeg.branch) mkdir -p "$module_dir/jni/ffmpeg" cp "$upstream_jni/build_ffmpeg.sh" "$upstream_jni/CMakeLists.txt" "$upstream_jni/ffmpeg_jni.cc" "$module_dir/jni/" git -C "$repo_root/ffmpeg" archive HEAD | tar -x -C "$module_dir/jni/ffmpeg" +"$repo_root/scripts/apply-ffmpeg-patch.sh" "$module_dir/jni/ffmpeg" printf '%s\n' "$ffmpeg_tag" >"$module_dir/jni/ffmpeg/VERSION" From 143fd61bfc3de13de89679d3fcac1851689783f5 Mon Sep 17 00:00:00 2001 From: Altay Date: Sun, 8 Nov 2026 16:09:00 +0300 Subject: [PATCH 4/4] fix: treat a GPL grant as GPL when the header also mentions the LGPL The classifier returned lgpl for any header containing that word, so vf_owdenoise.c stayed in the source archive. The relink command in BUILD.txt also left a libc++_shared.so dependency the released library does not have. --- scripts/check-negative-controls.sh | 12 ++++++++++++ scripts/classify-license.pl | 1 + scripts/package-ffmpeg-source.sh | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/scripts/check-negative-controls.sh b/scripts/check-negative-controls.sh index e0007dc..1c0acee 100755 --- a/scripts/check-negative-controls.sh +++ b/scripts/check-negative-controls.sh @@ -155,6 +155,18 @@ SOURCE record_compiled_object x86 libavutil/wrapped_gpl.o libavutil/wrapped_gpl.c expect_gate_failure "GPL source compiled into x86: libavutil/wrapped_gpl.c" +reset_gate +cat >"$gate/jni/ffmpeg/libavutil/mentions_lgpl.c" <<'SOURCE' +/* + * This file is free software; you can redistribute it under the terms of + * the GNU General Public License as published by the Free Software Foundation. + */ + +// Part of this file can also be used under the LGPL. +SOURCE +record_compiled_object x86 libavutil/mentions_lgpl.o libavutil/mentions_lgpl.c +expect_gate_failure "GPL source compiled into x86: libavutil/mentions_lgpl.c" + reset_gate record_compiled_object x86_64 libavcodec/absent.o libavcodec/absent.c expect_gate_failure "source libavcodec/absent.c is not in the tree" diff --git a/scripts/classify-license.pl b/scripts/classify-license.pl index 80ce5f7..8a7170d 100755 --- a/scripts/classify-license.pl +++ b/scripts/classify-license.pl @@ -99,6 +99,7 @@ sub notice_tags { sub grant_of { my ($text) = @_; + return 'gpl' if $text =~ /terms\s+of\s+the\s+gnu\s+general\s+public\s+licen[sc]e/; return 'lgpl' if $text =~ /gnu (?:lesser|library) general public licen[sc]e/ || $text =~ /(? header.