Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add mediainfo module to nextlib #23

Merged
merged 6 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ffmpeg/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,14 @@ function buildFfmpeg() {
--disable-postproc \
--disable-avfilter \
--disable-symver \
--enable-parsers \
--enable-demuxers \
--enable-swresample \
--enable-avformat \
--enable-libvpx \
--enable-protocol=file,http,https,mmsh,mmst,pipe,rtmp,rtmps,rtmpt,rtmpts,rtp,tls \
--extra-ldexeflags=-pie \
--disable-debug \
${EXTRA_BUILD_CONFIGURATION_FLAGS} \
${COMMON_OPTIONS}

Expand Down
4 changes: 2 additions & 2 deletions media3ext/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
android {
namespace = "io.github.anilbeesetti.nextlib.media3ext"

compileSdk = 33
compileSdk = 34

defaultConfig {

Expand Down Expand Up @@ -69,7 +69,7 @@ afterEvaluate {
publications {
create<MavenPublication>("mavenJava") {
groupId = "io.github.anilbeesetti"
artifactId = "nextlib"
artifactId = "nextlib-media3ext"
version = "1.0"

from(components["release"])
Expand Down
37 changes: 6 additions & 31 deletions media3ext/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.22.1)

# Declares and names the project.

project("ffcodecs")
project("media3ext")

set(ffmpeg_dir ${CMAKE_SOURCE_DIR}/../../../../ffmpeg/output)
set(ffmpeg_libs ${ffmpeg_dir}/lib/${ANDROID_ABI})
Expand All @@ -32,40 +32,15 @@ foreach (ffmpeg_lib_name ${ffmpeg_libs_names})
${ffmpeg_libs}/lib${ffmpeg_lib_name}.so)
endforeach ()

add_library( # Sets the name of the library.
ffcodecs

# Sets the library as a shared library.
SHARED

# Provides a relative path to your source file(s).
add_library(${CMAKE_PROJECT_NAME} SHARED
# List C/C++ source files with relative paths to this CMakeLists.txt.
ffmain.cpp
ffcommon.cpp
ffaudio.cpp
ffvideo.cpp)

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
log-lib

# Specifies the name of the NDK library that
# you want CMake to locate.
log)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
ffcodecs

# Links the target library to the log library
# included in the NDK.
${log-lib}
target_link_libraries(${CMAKE_PROJECT_NAME}
# List libraries link to the target library
log
android
${ffmpeg_libs_names})
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public final class FfmpegLibrary {
private static final String TAG = "FfmpegLibrary";

private static final LibraryLoader LOADER =
new LibraryLoader("ffcodecs") {
new LibraryLoader("media3ext") {
@Override
protected void loadLibrary(String name) {
System.loadLibrary(name);
Expand Down
1 change: 1 addition & 0 deletions mediainfo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
75 changes: 75 additions & 0 deletions mediainfo/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import com.android.build.gradle.internal.tasks.factory.dependsOn

plugins {
alias(libs.plugins.androidLibrary)
alias(libs.plugins.kotlinAndroid)
id("maven-publish")
}

android {
namespace = "io.github.anilbeesetti.nextlib.mediainfo"

compileSdk = 34

defaultConfig {

minSdk = 21
consumerProguardFiles("consumer-rules.pro")
externalNativeBuild {
cmake {
cppFlags("")
}
}

ndk {
abiFilters += listOf("x86", "x86_64", "armeabi-v7a", "arm64-v8a")
}

ndkVersion = "25.2.9519653"
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

kotlinOptions {
/// Set JVM target to 17
jvmTarget = JavaVersion.VERSION_17.toString()
}

externalNativeBuild {
cmake {
path("src/main/cpp/CMakeLists.txt")
version = "3.22.1"
}
}
}

// Gradle task to setup ffmpeg
val ffmpegSetup by tasks.registering(Exec::class) {
workingDir = file("../ffmpeg")
// export ndk path and run bash script
environment("ANDROID_NDK_HOME", android.ndkDirectory.absolutePath)
commandLine("bash", "setup.sh")
}

tasks.preBuild.dependsOn(ffmpegSetup)

dependencies {
implementation(libs.androidx.annotation)
}

afterEvaluate {
publishing {
publications {
create<MavenPublication>("mavenJava") {
groupId = "io.github.anilbeesetti"
artifactId = "nextlib-mediainfo"
version = "1.0"

from(components["release"])
}
}
}
}
Empty file added mediainfo/consumer-rules.pro
Empty file.
4 changes: 4 additions & 0 deletions mediainfo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
46 changes: 46 additions & 0 deletions mediainfo/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html.
# For more examples on how to use CMake, see https://github.com/android/ndk-samples.

# Sets the minimum CMake version required for this project.
cmake_minimum_required(VERSION 3.22.1)

project("mediainfo")

set(ffmpeg_dir ${CMAKE_SOURCE_DIR}/../../../../ffmpeg/output)
set(ffmpeg_libs ${ffmpeg_dir}/lib/${ANDROID_ABI})

include_directories(${ffmpeg_dir}/include/${ANDROID_ABI})

set(
# List variable name
ffmpeg_libs_names
# Values in the list
avcodec avformat avutil)

foreach (ffmpeg_lib_name ${ffmpeg_libs_names})
add_library(
${ffmpeg_lib_name}
SHARED
IMPORTED)
set_target_properties(
${ffmpeg_lib_name}
PROPERTIES
IMPORTED_LOCATION
${ffmpeg_libs}/lib${ffmpeg_lib_name}.so)
endforeach ()


add_library(${CMAKE_PROJECT_NAME} SHARED
# List C/C++ source files with relative paths to this CMakeLists.txt.
main.cpp
mediainfo.cpp
utils.cpp)

# Specifies libraries CMake should link to your target library. You
# can link libraries from various origins, such as libraries defined in this
# build script, prebuilt third-party libraries, or Android system libraries.
target_link_libraries(${CMAKE_PROJECT_NAME}
# List libraries link to the target library
log
${ffmpeg_libs_names})
24 changes: 24 additions & 0 deletions mediainfo/src/main/cpp/log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef NEXTPLAYER_LOG_H
#define NEXTPLAYER_LOG_H

#define LOG_TAG "NextPlayerJNI"

#ifndef NDEBUG

#include <android/log.h>

# define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)
# define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
# define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
# define LOGW(...) __android_log_print(ANDROID_LOG_WARNING, LOG_TAG, __VA_ARGS__)
# define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
#else
# define LOGV(...) (void)0
# define LOGD(...) (void)0
# define LOGI(...) (void)0
# define LOGW(...) (void)0
# define LOGE(...) (void)0
#endif


#endif //NEXTPLAYER_LOG_H
16 changes: 16 additions & 0 deletions mediainfo/src/main/cpp/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <jni.h>

#include "utils.h"

// This function is called when the native library is loaded.
jint JNI_OnLoad(JavaVM *vm, void *reserved) {
if (utils_fields_init(vm) != 0) {
return -1;
}
return JNI_VERSION_1_6;
}

// This function is called when the native library is unloaded.
void JNI_OnUnload(JavaVM *vm, void *reserved) {
utils_fields_free(vm);
}
Loading
Loading