add libpmp3 module which is independent

pull/166/head
xufuji456 4 years ago
parent fbfe1cea33
commit b553ef1bba
  1. 9
      app/CMakeLists.txt
  2. 2
      app/build.gradle
  3. 18
      app/src/main/java/com/frank/ffmpeg/AudioPlayer.java
  4. 2
      app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.kt
  5. 1
      libmp3/.gitignore
  6. 43
      libmp3/CMakeLists.txt
  7. 52
      libmp3/build.gradle
  8. 0
      libmp3/libs/arm64-v8a/libmp3lame.so
  9. 0
      libmp3/libs/armeabi-v7a/libmp3lame.so
  10. 21
      libmp3/proguard-rules.pro
  11. 2
      libmp3/src/main/AndroidManifest.xml
  12. 19
      libmp3/src/main/cpp/audio_lame.c
  13. 1323
      libmp3/src/main/cpp/lame.h
  14. 4
      libmp3/src/main/java/com/frank/mp3/Mp3Converter.kt
  15. 18
      libmp3/src/main/java/com/frank/mp3/Mp3Lame.kt
  16. 2
      libmp3/src/main/java/com/frank/mp3/Mp3LameBuilder.kt
  17. 31
      libmp3/src/main/java/com/frank/mp3/Mp3Lite.java
  18. 3
      libmp3/src/main/res/values/strings.xml
  19. 2
      settings.gradle

@ -32,7 +32,6 @@ add_library( # Sets the name of the library.
src/main/cpp/AVpacket_queue.c src/main/cpp/AVpacket_queue.c
src/main/cpp/media_player.c src/main/cpp/media_player.c
src/main/cpp/video_filter.c src/main/cpp/video_filter.c
src/main/cpp/audio_lame.c
src/main/cpp/fast_start.c src/main/cpp/fast_start.c
src/main/cpp/ffprobe_cmd.c src/main/cpp/ffprobe_cmd.c
) )
@ -44,13 +43,6 @@ set_target_properties( ffmpeg
PROPERTIES IMPORTED_LOCATION PROPERTIES IMPORTED_LOCATION
../../../../libs/${CMAKE_ANDROID_ARCH_ABI}/libffmpeg.so ) ../../../../libs/${CMAKE_ANDROID_ARCH_ABI}/libffmpeg.so )
add_library( mp3lame
SHARED
IMPORTED )
set_target_properties( mp3lame
PROPERTIES IMPORTED_LOCATION
../../../../libs/${CMAKE_ANDROID_ARCH_ABI}/libmp3lame.so )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
include_directories(src/main/cpp) include_directories(src/main/cpp)
@ -69,7 +61,6 @@ find_library( # Sets the name of the path variable.
target_link_libraries( # Specifies the target library. target_link_libraries( # Specifies the target library.
media-handle media-handle
mp3lame
ffmpeg ffmpeg
-landroid #native_window -landroid #native_window
-ljnigraphics #bitmap -ljnigraphics #bitmap

@ -62,4 +62,6 @@ dependencies {
implementation "androidx.core:core-ktx:$rootProject.core_ktx" implementation "androidx.core:core-ktx:$rootProject.core_ktx"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$rootProject.lifecycle_ktx" implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$rootProject.lifecycle_ktx"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//implementation "libmp3" if you need mp3-lite module
implementation project(':libmp3')
} }

@ -22,24 +22,6 @@ public class AudioPlayer {
public native void stop(); public native void stop();
public native static void lameInitDefault();
public native static void lameInit(int inSamplerate, int outChannel,
int outSamplerate, int outBitrate, float scaleInput, int mode, int vbrMode,
int quality, int vbrQuality, int abrMeanBitrate, int lowpassFreq, int highpassFreq, String id3tagTitle,
String id3tagArtist, String id3tagAlbum, String id3tagYear,
String id3tagComment);
public native static int lameEncode(short[] buffer_l, short[] buffer_r,
int samples, byte[] mp3buf);
public native static int encodeBufferInterleaved(short[] pcm, int samples,
byte[] mp3buf);
public native static int lameFlush(byte[] mp3buf);
public native static void lameClose();
/** /**
* Create an AudioTrack instance for JNI calling * Create an AudioTrack instance for JNI calling
* *

@ -16,7 +16,7 @@ import java.util.Locale
import com.frank.ffmpeg.AudioPlayer import com.frank.ffmpeg.AudioPlayer
import com.frank.ffmpeg.R import com.frank.ffmpeg.R
import com.frank.ffmpeg.handler.FFmpegHandler import com.frank.ffmpeg.handler.FFmpegHandler
import com.frank.ffmpeg.mp3.Mp3Converter import com.frank.mp3.Mp3Converter
import com.frank.ffmpeg.util.FFmpegUtil import com.frank.ffmpeg.util.FFmpegUtil
import com.frank.ffmpeg.util.FileUtil import com.frank.ffmpeg.util.FileUtil

1
libmp3/.gitignore vendored

@ -0,0 +1 @@
/build

@ -0,0 +1,43 @@
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
mp3-lite
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/audio_lame.c
)
add_library( mp3lame
SHARED
IMPORTED )
set_target_properties( mp3lame
PROPERTIES IMPORTED_LOCATION
../../../../libs/${CMAKE_ANDROID_ARCH_ABI}/libmp3lame.so )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
include_directories(src/main/cpp)
find_library( # Sets the name of the path variable.
log-lib
log )
target_link_libraries( # Specifies the target library.
mp3-lite
mp3lame
# Links the target library to the log library
# included in the NDK.
${log-lib} )

@ -0,0 +1,52 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode rootProject.ext.versionCode
versionName rootProject.ext.versionName
externalNativeBuild {
cmake {
cppFlags ""
}
}
ndk {
abiFilters "armeabi-v7a", "arm64-v8a"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
jni.srcDirs = []
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.appcompat:appcompat:$rootProject.appcompatVersion"
implementation "androidx.core:core-ktx:$rootProject.core_ktx"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$rootProject.lifecycle_ktx"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.frank.mp3" />

@ -1,7 +1,10 @@
#include "include/lame/lame.h" #include "lame.h"
#include <jni.h> #include <jni.h>
#include "ffmpeg_jni_define.h"
#define MP3_FUNC(RETURN_TYPE, FUNC_NAME, ...) \
JNIEXPORT RETURN_TYPE JNICALL Java_com_frank_mp3_Mp3Lite_ ## FUNC_NAME \
(JNIEnv *env, jclass thiz, ##__VA_ARGS__)\
lame_global_flags *glf; lame_global_flags *glf;
@ -181,12 +184,12 @@ void close_lame(lame_global_flags *glf) {
} }
AUDIO_PLAYER_FUNC(void, lameInitDefault) { MP3_FUNC(void, lameInitDefault) {
glf = initializeDefault(env); glf = initializeDefault(env);
} }
AUDIO_PLAYER_FUNC(void, lameInit, MP3_FUNC(void, lameInit,
jint inSampleRate, jint outChannel, jint outSampleRate, jint outBitrate, jint inSampleRate, jint outChannel, jint outSampleRate, jint outBitrate,
jfloat scaleInput, jint mode, jint vbrMode, jint quality, jint vbrQuality, jfloat scaleInput, jint mode, jint vbrMode, jint quality, jint vbrQuality,
jint abrMeanBitrate, jint lowPassFreq, jint highPassFreq, jstring id3tagTitle, jint abrMeanBitrate, jint lowPassFreq, jint highPassFreq, jstring id3tagTitle,
@ -201,21 +204,21 @@ AUDIO_PLAYER_FUNC(void, lameInit,
id3tagComment); id3tagComment);
} }
AUDIO_PLAYER_FUNC(jint, lameEncode, MP3_FUNC(jint, lameEncode,
jshortArray buffer_l, jshortArray buffer_r, jint samples, jbyteArray mp3buf) { jshortArray buffer_l, jshortArray buffer_r, jint samples, jbyteArray mp3buf) {
return encode(env, glf, buffer_l, buffer_r, samples, mp3buf); return encode(env, glf, buffer_l, buffer_r, samples, mp3buf);
} }
AUDIO_PLAYER_FUNC(jint, encodeBufferInterleaved, MP3_FUNC(jint, encodeBufferInterleaved,
jshortArray pcm, jint samples, jbyteArray mp3buf) { jshortArray pcm, jint samples, jbyteArray mp3buf) {
return encodeBufferInterleaved(env, glf, pcm, samples, mp3buf); return encodeBufferInterleaved(env, glf, pcm, samples, mp3buf);
} }
AUDIO_PLAYER_FUNC(jint, lameFlush, MP3_FUNC(jint, lameFlush,
jbyteArray mp3buf) { jbyteArray mp3buf) {
return flush(env, glf, mp3buf); return flush(env, glf, mp3buf);
} }
AUDIO_PLAYER_FUNC(void, lameClose) { MP3_FUNC(void, lameClose) {
close_lame(glf); close_lame(glf);
} }

File diff suppressed because it is too large Load Diff

@ -1,4 +1,4 @@
package com.frank.ffmpeg.mp3 package com.frank.mp3
import android.annotation.TargetApi import android.annotation.TargetApi
import android.media.MediaCodec import android.media.MediaCodec
@ -17,7 +17,7 @@ import java.nio.ByteOrder
import java.util.concurrent.LinkedBlockingDeque import java.util.concurrent.LinkedBlockingDeque
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
class Mp3Converter { open class Mp3Converter {
private var mMediaCodec: MediaCodec? = null private var mMediaCodec: MediaCodec? = null
private var mediaExtractor: MediaExtractor? = null private var mediaExtractor: MediaExtractor? = null

@ -1,19 +1,13 @@
package com.frank.ffmpeg.mp3 package com.frank.mp3
import com.frank.ffmpeg.AudioPlayer
class Mp3Lame { class Mp3Lame {
constructor() {
AudioPlayer.lameInitDefault()
}
internal constructor(builder: Mp3LameBuilder) { internal constructor(builder: Mp3LameBuilder) {
initialize(builder) initialize(builder)
} }
private fun initialize(builder: Mp3LameBuilder) { private fun initialize(builder: Mp3LameBuilder) {
AudioPlayer.lameInit(builder.inSampleRate, builder.outChannel, builder.outSampleRate, Mp3Lite.lameInit(builder.inSampleRate, builder.outChannel, builder.outSampleRate,
builder.outBitrate, builder.scaleInput, getIntForMode(builder.mode), getIntForVbrMode(builder.vbrMode), builder.quality, builder.vbrQuality, builder.abrMeanBitrate, builder.outBitrate, builder.scaleInput, getIntForMode(builder.mode), getIntForVbrMode(builder.vbrMode), builder.quality, builder.vbrQuality, builder.abrMeanBitrate,
builder.lowPassFreq, builder.highPassFreq, builder.id3tagTitle, builder.id3tagArtist, builder.lowPassFreq, builder.highPassFreq, builder.id3tagTitle, builder.id3tagArtist,
builder.id3tagAlbum, builder.id3tagYear, builder.id3tagComment) builder.id3tagAlbum, builder.id3tagYear, builder.id3tagComment)
@ -22,20 +16,20 @@ class Mp3Lame {
fun encode(buffer_l: ShortArray, buffer_r: ShortArray, fun encode(buffer_l: ShortArray, buffer_r: ShortArray,
samples: Int, mp3buf: ByteArray): Int { samples: Int, mp3buf: ByteArray): Int {
return AudioPlayer.lameEncode(buffer_l, buffer_r, samples, mp3buf) return Mp3Lite.lameEncode(buffer_l, buffer_r, samples, mp3buf)
} }
internal fun encodeBufferInterLeaved(pcm: ShortArray, samples: Int, internal fun encodeBufferInterLeaved(pcm: ShortArray, samples: Int,
mp3buf: ByteArray): Int { mp3buf: ByteArray): Int {
return AudioPlayer.encodeBufferInterleaved(pcm, samples, mp3buf) return Mp3Lite.encodeBufferInterleaved(pcm, samples, mp3buf)
} }
fun flush(mp3buf: ByteArray): Int { fun flush(mp3buf: ByteArray): Int {
return AudioPlayer.lameFlush(mp3buf) return Mp3Lite.lameFlush(mp3buf)
} }
fun close() { fun close() {
AudioPlayer.lameClose() Mp3Lite.lameClose()
} }
private fun getIntForMode(mode: Mp3LameBuilder.Mode): Int { private fun getIntForMode(mode: Mp3LameBuilder.Mode): Int {

@ -1,4 +1,4 @@
package com.frank.ffmpeg.mp3 package com.frank.mp3
class Mp3LameBuilder internal constructor() { class Mp3LameBuilder internal constructor() {

@ -0,0 +1,31 @@
package com.frank.mp3;
/**
* Mp3Lite: use AudioTrack and OpenSL ES to play audio
* Created by frank on 2018/2/1.
*/
public class Mp3Lite {
static {
System.loadLibrary("mp3-lite");
}
public native static void lameInitDefault();
public native static void lameInit(int inSamplerate, int outChannel,
int outSamplerate, int outBitrate, float scaleInput, int mode, int vbrMode,
int quality, int vbrQuality, int abrMeanBitrate, int lowpassFreq, int highpassFreq, String id3tagTitle,
String id3tagArtist, String id3tagAlbum, String id3tagYear,
String id3tagComment);
public native static int lameEncode(short[] buffer_l, short[] buffer_r,
int samples, byte[] mp3buf);
public native static int encodeBufferInterleaved(short[] pcm, int samples,
byte[] mp3buf);
public native static int lameFlush(byte[] mp3buf);
public native static void lameClose();
}

@ -0,0 +1,3 @@
<resources>
<string name="app_name">LibMp3</string>
</resources>

@ -1 +1 @@
include ':app', ':Live', ':OnLive' include ':app', ':Live', ':OnLive', ':libmp3'

Loading…
Cancel
Save