diff --git a/.idea/gradle.xml b/.idea/gradle.xml index c5a320f..068bb52 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -4,9 +4,10 @@ diff --git a/.idea/misc.xml b/.idea/misc.xml index 37a7509..6199cc2 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/build.gradle b/build.gradle index 3aaad6f..4e7e314 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,14 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.61' + ext.kotlin_version = '1.6.20' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:4.2.0-beta03' + classpath 'com.android.tools.build:gradle:7.3.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4dbfc67..32f00a0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https://services.gradle.org/distributions/gradle-6.7.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip diff --git a/opus/build.gradle b/opus/build.gradle index 6ef048d..0c431b3 100644 --- a/opus/build.gradle +++ b/opus/build.gradle @@ -20,7 +20,8 @@ android { } ndk { - abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' +// abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' + abiFilters 'x86_64' } } } diff --git a/opus/src/main/cpp/CMakeLists.txt b/opus/src/main/cpp/CMakeLists.txt index 210de5b..15f63f7 100644 --- a/opus/src/main/cpp/CMakeLists.txt +++ b/opus/src/main/cpp/CMakeLists.txt @@ -26,9 +26,9 @@ include_directories(${PROJECT_SOURCE_DIR}/include) #add other prebuilt libraries add_library(opus SHARED IMPORTED) add_library(opusenc SHARED IMPORTED) - +# set_target_properties(opus PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/lib/${ANDROID_ABI}/libopus.so) -set_target_properties(opusenc PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/lib/${ANDROID_ABI}/libopusenc.so) +set_target_properties(opusenc PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/lib/${ANDROID_ABI}/libopusenc.a) # Searches for a specified prebuilt library and stores the path as a # variable. Because CMake includes system libraries in the search path by diff --git a/opus/src/main/cpp/codec/CodecOpus.cpp b/opus/src/main/cpp/codec/CodecOpus.cpp index 047c6aa..b6ab028 100644 --- a/opus/src/main/cpp/codec/CodecOpus.cpp +++ b/opus/src/main/cpp/codec/CodecOpus.cpp @@ -21,12 +21,23 @@ int CodecOpus::encoderInit(int sampleRate, int numChannels, int application) { return size; } - encoder = (OpusEncoder*) malloc((size_t) size); + int error; + + OggOpusComments *comments; + comments = ope_comments_create(); + fileEncoder = (OggOpusEnc*) malloc((size_t) size); + fileEncoder = ope_encoder_create_file("/data/data/com.theeasiestway.opus/cache/rec.opus", comments, sampleRate, numChannels, 0, &error); + if (!fileEncoder) { + LOGE(TAG, "[encoderInit] couldn't open file"); + free(fileEncoder); + return -1; + } - int ret = opus_encoder_init(encoder, sampleRate, numChannels, application); + encoder = (OpusEncoder*) malloc((size_t) size); + error = opus_encoder_init(encoder, sampleRate, numChannels, application); - if (ret) { - LOGE(TAG, "[encoderInit] couldn't init encoder ret: %d; error: %s", ret, opus_strerror(ret)); + if (error) { + LOGE(TAG, "[encoderInit] couldn't init encoder ret: %d; error: %s", error, opus_strerror(error)); free(encoder); return -1; } else LOGD(TAG, "[encoderInit] encoder successfully initialized"); @@ -65,7 +76,9 @@ std::vector CodecOpus::encode(uint8_t *bytes, int frameSize) { int maxBytesCount = sizeof(unsigned char) * 1024; unsigned char *outBuffer = (unsigned char*) malloc((size_t) maxBytesCount); - int resultLength = opus_encode(encoder, (opus_int16 *) bytes, frameSize, outBuffer, maxBytesCount); + int resultLength; + resultLength = ope_encoder_write(fileEncoder, (opus_int16 *) bytes, frameSize); + resultLength = opus_encode(encoder, (opus_int16 *) bytes, frameSize, outBuffer, maxBytesCount); if (resultLength <= 0) { LOGE(TAG, "[encode] error: %s", opus_strerror(resultLength)); return result; @@ -77,6 +90,10 @@ std::vector CodecOpus::encode(uint8_t *bytes, int frameSize) { } void CodecOpus::encoderRelease() { + ope_encoder_drain(fileEncoder); + ope_encoder_destroy(fileEncoder); + fileEncoder = nullptr; + if (encoder) opus_encoder_destroy(encoder); encoder = nullptr; } diff --git a/opus/src/main/cpp/codec/CodecOpus.h b/opus/src/main/cpp/codec/CodecOpus.h index 7c7b5b6..d56f5e3 100644 --- a/opus/src/main/cpp/codec/CodecOpus.h +++ b/opus/src/main/cpp/codec/CodecOpus.h @@ -8,12 +8,14 @@ #include #include #include +#include class CodecOpus { private: const char *TAG = "CodecOpus"; OpusEncoder* encoder; + OggOpusEnc* fileEncoder; OpusDecoder* decoder; int decoderNumChannels = -1; @@ -21,6 +23,7 @@ class CodecOpus { int checkForNull(const char *methodName, bool isEncoder); public: + int encoderCreateFile(int sampleRate, int numChannels, int application); int encoderInit(int sampleRate, int numChannels, int application); int encoderSetBitrate(int bitrate); int encoderSetComplexity(int complexity); diff --git a/opus/src/main/cpp/lib/x86_64/libopusenc.a b/opus/src/main/cpp/lib/x86_64/libopusenc.a new file mode 100644 index 0000000..2895b31 Binary files /dev/null and b/opus/src/main/cpp/lib/x86_64/libopusenc.a differ