Skip to content

Commit

Permalink
tweaks to make newest webrtc work for android
Browse files Browse the repository at this point in the history
  • Loading branch information
z-dule committed Oct 28, 2024
1 parent 2a3c630 commit eb7bd60
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 22 deletions.
4 changes: 3 additions & 1 deletion android/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ LOCAL_LDLIBS += \
-lsodium \
-llog -lz -lGLESv2 \
-latomic \
-lwebrtc
-lwebrtc \
-lc++ \
-lc++abi


ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
Expand Down
4 changes: 2 additions & 2 deletions android/jni/Application.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
APP_STL := c++_static
APP_STL := c++_shared
NDK_TOOLCHAIN_VERSION := clang
APP_PLATFORM := android-25
APP_PLATFORM := android-27

include Arch.mk
14 changes: 12 additions & 2 deletions android/jni/flow_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
//#include "webrtc/voice_engine/include/voe_base.h"
#include "rtc_base/platform_thread_types.h"
#include "modules/utility/include/jvm_android.h"
#ifdef ANDROID
#include "sdk/android/native_api/audio_device_module/audio_device_android.h"
#endif

#include <unistd.h>
#include <pthread.h>
Expand Down Expand Up @@ -425,7 +428,7 @@ static int init(JNIEnv *env, jobject jobj, jobject ctx, uint64_t avs_flags)
//info("Calling SetAndroidObjects\n");
// webrtc::VoiceEngine::SetAndroidObjects(java.vm, ctx);

//__android_log_write(ANDROID_LOG_INFO, "AVS-I", "jni: setting ctx\n");
__android_log_write(ANDROID_LOG_INFO, "AVS-I", "jni: setting ctx\n");
info("calling webrtc::JVM:Initialize: vm=%p ctx=%p\n",
java.vm, ctx);

Expand All @@ -437,7 +440,9 @@ static int init(JNIEnv *env, jobject jobj, jobject ctx, uint64_t avs_flags)


if (1) {
__android_log_write(ANDROID_LOG_INFO, "AVS-I", "jni: calling JVM::Initialize\n");
webrtc::JVM::Initialize(java.vm, ctx);
__android_log_write(ANDROID_LOG_INFO, "AVS-I", "jni: calling JVM::Initialize done\n");
std::unique_ptr<webrtc::JNIEnvironment> jenv = webrtc::JVM::GetInstance()->environment();
info("flow_manager: init: vm: %p env: %p\n",
webrtc::JVM::GetInstance()->jvm(),
Expand All @@ -446,6 +451,11 @@ static int init(JNIEnv *env, jobject jobj, jobject ctx, uint64_t avs_flags)

java.context = env->NewGlobalRef(ctx);

#ifdef ANDROID
auto adm = webrtc::CreateOpenSLESAudioDeviceModule(env, ctx);
peerflow_set_adm((void *)adm.get());
#endif

#if 0//USE_BREAKPAD
setup_breakpad(env, ctx);
#endif
Expand Down Expand Up @@ -1322,7 +1332,7 @@ static int vie_jni_get_view_size_handler(const void *view, int *w, int *h)
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved)
{
//info("JNI_OnLoad\n");
//__android_log_write(ANDROID_LOG_INFO, "AVS-I", "JNI_OnLoad\n");
__android_log_write(ANDROID_LOG_INFO, "AVS-I", "JNI_OnLoad\n");

(void)reserved;

Expand Down
1 change: 1 addition & 0 deletions include/avs_peerflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ struct avs_vidframe;

int peerflow_set_funcs(void);

void peerflow_set_adm(void *adm);
int peerflow_init(void);

typedef void (peerflow_acbr_h)(bool enabled, bool offer, void *arg);
Expand Down
9 changes: 5 additions & 4 deletions mk/dist.mk
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ AVS_ARCH_NAME := $1\n\
$(BUILD_DIST_AND)/aar/jni/$2/libavs.so
mkdir -p $(BUILD_DIST_AND)/debug/$2/
cp android/obj/local/$2/libavs.so $(BUILD_DIST_AND)/debug/$2/libavs.so
cp $(TOOLCHAIN_PATH)/sysroot/usr/lib/$3/libc++_shared.so $(BUILD_DIST_AND)/aar/jni/$2/
endef


Expand All @@ -162,19 +163,19 @@ $(BUILD_DIST_AND)/avs.aar:
$(BUILD_DIST_AND)/aar

ifneq ($(filter armv7,$(DIST_ARCH)),)
$(call build_arch,armv7,armeabi-v7a)
$(call build_arch,armv7,armeabi-v7a,arm-linux-androideabi)
endif

ifneq ($(filter arm64,$(DIST_ARCH)),)
$(call build_arch,arm64,arm64-v8a)
$(call build_arch,arm64,arm64-v8a,aarch64-linux-android)
endif

ifneq ($(filter i386,$(DIST_ARCH)),)
$(call build_arch,i386,x86)
$(call build_arch,i386,x86,i686-linux-android)
endif

ifneq ($(filter x86_64,$(DIST_ARCH)),)
$(call build_arch,x86_64,x86_64)
$(call build_arch,x86_64,x86_64,x86_64-linux-android)
endif

#ifneq ($(filter osx,$(DIST_ARCH)),)
Expand Down
4 changes: 2 additions & 2 deletions mk/target.mk
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,10 @@ SH_LFLAGS += \
-shared

SH_LIBS += \
-llog -lOpenSLES -lstdc++
-llog -lOpenSLES -lc++_static -lc++abi

LIBS += \
-lcpufeatures -lc -lm -ldl -llog -lGLESv2 -latomic -lOpenSLES -lc++
-lcpufeatures -lc -lm -ldl -llog -lGLESv2 -latomic -lOpenSLES -lc++ -lc++abi

# this one was added to get ztest to link:

Expand Down
43 changes: 32 additions & 11 deletions src/peerflow/peerflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ extern "C" {

#include "p2p/client/basic_port_allocator.h"

#ifdef ANDROID
#include <android/log.h>
#include "sdk/android/native_api/audio_device_module/audio_device_android.h"
#endif

#include "capture_source.h"
#include "cbr_detector_local.h"
#include "cbr_detector_remote.h"
Expand Down Expand Up @@ -101,6 +106,9 @@ static struct {
bool muted;
} audio;

#ifdef ANDROID
rtc::scoped_refptr<webrtc::AudioDeviceModule> androidAdm;
#endif

#if PC_STANDALONE
struct dnsc *dnsc;
Expand Down Expand Up @@ -677,25 +685,35 @@ class LogSink : public rtc::LogSink {
virtual void OnLogMessage(const std::string& msg,
rtc::LoggingSeverity severity,
const char* tag) {

enum log_level lvl = severity2level(severity);
#ifdef ANDROID
__android_log_write(ANDROID_LOG_INFO, tag, msg.c_str());
#else
loglv(lvl, "[%s] %s", tag, msg.c_str());
#endif
}

virtual void OnLogMessage(const std::string& msg,
rtc::LoggingSeverity severity) {

enum log_level lvl = severity2level(severity);
#ifdef ANDROID
__android_log_write(ANDROID_LOG_INFO, "AVS", msg.c_str());
#else
loglv(lvl, "%s", msg.c_str());
#endif
}


virtual void OnLogMessage(const std::string& msg) {
#ifdef ANDROID
__android_log_write(ANDROID_LOG_INFO, "AVS", msg.c_str());
#else
error("%s", msg.c_str());
#endif
}
};


void peerflow_start_log(void)
{
if (!g_pf.logsink) {
Expand Down Expand Up @@ -749,6 +767,13 @@ int peerflow_set_funcs(void)
return 0;
}

void peerflow_set_adm(void *adm)
{
#ifdef ANDROID
g_pf.androidAdm = (webrtc::AudioDeviceModule *)adm;
#endif
}

int peerflow_init(void)
{
webrtc::AudioDeviceModule *adm;
Expand Down Expand Up @@ -778,30 +803,26 @@ int peerflow_init(void)
#ifndef ANDROID /* webrtc logging crashes on Android due to JNI/JNA mix */
//peerflow_start_log();
#endif

//pf_platform_init();

g_pf.thread = rtc::Thread::Create();
g_pf.thread->Start();
#if 0
g_pf.thread->Invoke<void>(RTC_FROM_HERE, [] {
info("pf: starting runnable\n");
pc_platform_init();
info("pf: platform initialized\n");
});
#else
g_pf.thread->BlockingCall([] {
info("pf: starting runnable\n");
pc_platform_init();
info("pf: platform initialized\n");
});
#endif

webrtc::field_trial::InitFieldTrialsFromString(trials_str);

#ifdef ANDROID
pc_deps.adm = g_pf.androidAdm;
#else
adm = (webrtc::AudioDeviceModule *)audio_io_create_adm();
if (adm)
pc_deps.adm = adm;
#endif

pc_deps.signaling_thread = g_pf.thread.get();
pc_deps.task_queue_factory = webrtc::CreateDefaultTaskQueueFactory();
Expand Down

0 comments on commit eb7bd60

Please sign in to comment.