Skip to content
Open
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
4 changes: 2 additions & 2 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion opus/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions opus/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 22 additions & 5 deletions opus/src/main/cpp/codec/CodecOpus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -65,7 +76,9 @@ std::vector<uint8_t> 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;
Expand All @@ -77,6 +90,10 @@ std::vector<uint8_t> 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;
}
Expand Down
3 changes: 3 additions & 0 deletions opus/src/main/cpp/codec/CodecOpus.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@
#include <cstdint>
#include <vector>
#include <opus.h>
#include <opusenc.h>

class CodecOpus {

private:
const char *TAG = "CodecOpus";
OpusEncoder* encoder;
OggOpusEnc* fileEncoder;
OpusDecoder* decoder;

int decoderNumChannels = -1;

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);
Expand Down
Binary file added opus/src/main/cpp/lib/x86_64/libopusenc.a
Binary file not shown.