Skip to content

Commit

Permalink
Merge pull request #5 from AgoraIO-Extensions/dev/android
Browse files Browse the repository at this point in the history
feat: support android
  • Loading branch information
xiayangqun authored Oct 26, 2022
2 parents ccfe0bc + a717e32 commit 4152f45
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 171 deletions.
6 changes: 6 additions & 0 deletions VideoObserverPlugin/VideoObserverPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
#include "spdlog/sinks/stdout_sinks.h"
#include "spdlog/spdlog.h"

#if defined(__ANDROID__)

#include "spdlog/sinks/android_sink.h"

#endif

#define IRIS_LOG_PLUGIN_D(...) \
SPDLOG_LOGGER_CALL(spdlog::default_logger(), spdlog::level::debug, \
__VA_ARGS__)
Expand Down
10 changes: 9 additions & 1 deletion VideoObserverPlugin/VideoObserverPlugin.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef __IRIS_PLUGIN_CPP_API_H__
#define __IRIS_PLUGIN_CPP_API_H__

#include "iris_plugin_platform.h"
#include <IAgoraMediaEngine.h>
#include <IAgoraRtcEngine.h>
Expand All @@ -8,12 +9,15 @@ class IRIS_PLUGIN_CPP_API VideoObserverPlugin
: public agora::media::IVideoFrameObserver {
public:
VideoObserverPlugin(agora::rtc::IRtcEngine *rtc_engine);

~VideoObserverPlugin();

bool onCaptureVideoFrame(VideoFrame &videoFrame) override;

bool onSecondaryCameraCaptureVideoFrame(VideoFrame &videoFrame) override;

bool onScreenCaptureVideoFrame(VideoFrame &videoFrame) override;

bool onSecondaryScreenCaptureVideoFrame(VideoFrame &videoFrame) override;

bool onMediaPlayerVideoFrame(VideoFrame &videoFrame,
Expand All @@ -39,15 +43,19 @@ class IRIS_PLUGIN_CPP_API VideoObserverPlugin
getVideoFrameProcessMode() override;

agora::media::base::VIDEO_PIXEL_FORMAT getVideoFormatPreference() override;

bool getRotationApplied() override { return true; }

bool getMirrorApplied() override {
return IVideoFrameObserver::getMirrorApplied();
}

bool EnablePlugin();

bool DisablePlugin();

private:
agora::rtc::IRtcEngine *rtc_engine_ = nullptr;
};

#endif
39 changes: 36 additions & 3 deletions VideoObserverPlugin/plugin_c_api.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "Plugin_c_api.h"
#include "plugin_c_api.h"
#include "VideoObserverPlugin.h"
#if defined(__ANDROID__)
#include <jni.h>
#endif

bool EnablePlugin(PluginSamplePtr plugin) {
if (plugin) {
return ((VideoObserverPlugin *) plugin)->EnablePlugin();
Expand All @@ -16,12 +20,41 @@ bool DisablePlugin(PluginSamplePtr plugin) {
}
}

PluginSamplePtr CreateSampePlugin(void *rtcEnginePtr) {
PluginSamplePtr CreateSamplePlugin(void *rtcEnginePtr) {
auto *plugin =
new VideoObserverPlugin((agora::rtc::IRtcEngine *) rtcEnginePtr);
return (void *) plugin;
}

void DestroySamplePlugin(PluginSamplePtr plugin) {
delete (VideoObserverPlugin *) plugin;
}
}

#if defined(__ANDROID__)
extern "C" JNIEXPORT jlong JNICALL
Java_io_agora_iris_plugin_IrisVideoPlugin_createSamplePlugin(
JNIEnv *env, jobject thiz, jlong native_handle) {
return (jlong) CreateSamplePlugin((void *) native_handle);
}

extern "C" JNIEXPORT void JNICALL
Java_io_agora_iris_plugin_IrisVideoPlugin_destroySamplePlugin(JNIEnv *env,
jobject thiz,
jlong handle) {
DestroySamplePlugin((PluginSamplePtr) handle);
}

extern "C" JNIEXPORT jboolean JNICALL
Java_io_agora_iris_plugin_IrisVideoPlugin_enablePlugin(JNIEnv *env,
jobject thiz,
jlong handle) {
EnablePlugin((PluginSamplePtr) handle);
}

extern "C" JNIEXPORT jboolean JNICALL
Java_io_agora_iris_plugin_IrisVideoPlugin_disablePlugin(JNIEnv *env,
jobject thiz,
jlong handle) {
DisablePlugin((PluginSamplePtr) handle);
}
#endif
5 changes: 4 additions & 1 deletion VideoObserverPlugin/plugin_c_api.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#ifndef __IRIS_PLUGIN_C_API_H__
#define __IRIS_PLUGIN_C_API_H__

#include "iris_plugin_platform.h"

typedef void *PluginSamplePtr;
IRIS_PLUGIN_API bool EnablePlugin(PluginSamplePtr plugin);
IRIS_PLUGIN_API bool DisablePlugin(PluginSamplePtr plugin);
IRIS_PLUGIN_API PluginSamplePtr CreateSampePlugin(void *rtcEnginePtr);
IRIS_PLUGIN_API PluginSamplePtr CreateSamplePlugin(void *rtcEnginePtr);
IRIS_PLUGIN_API void DestroySamplePlugin(PluginSamplePtr plugin);

#endif

This file was deleted.

128 changes: 0 additions & 128 deletions dcg/android/app/src/main/java/io/agora/iris/IrisVIdeoPlugin.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.agora.iris.plugin;

public class IrisVideoPlugin {
static { System.loadLibrary("VideoObserverPlugin"); }

private long handle;

public IrisVideoPlugin(long nativeHandle) {
handle = createSamplePlugin(nativeHandle);
}

public void destroy() {
destroySamplePlugin(this.handle);
this.handle = 0;
}

boolean enable() { return enablePlugin(this.handle); }

boolean disable() { return disablePlugin(this.handle); }

private native long createSamplePlugin(long nativeHandle);

private native void destroySamplePlugin(long handle);

private native boolean enablePlugin(long handle);

private native boolean disablePlugin(long handle);
}
17 changes: 11 additions & 6 deletions dcg/ci/build-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,21 @@ buildALL() {
echo "start build aar ----------"
sh ./gradlew assemble"$buildType" -P"$sdkType" -Dhttps.proxyHost=10.80.1.174 -Dhttps.proxyPort=1080
echo "start copy outputs ----------"
output_dir="$root_path/build/android/ALL_ARCHITECTURE/output/dcg/$buildType"
output_dir="$root_path/build/android/ALL_ARCHITECTURE/output/$buildType"
output_name="VideoObserverPlugin"
mkdir -p "$output_dir"
cp app/build/outputs/aar/app-"$buildTypeLower".aar "$output_dir/$output_name.aar"
cp app/build/intermediates/aar_main_jar/"$buildTypeLower"/classes.jar "$output_dir/$output_name.jar"
cp -rp app/.cxx/cmake/"$buildTypeLower"/arm64-v8a/output/dcg/include/ "$output_dir/include/"
cp -rp app/.cxx/cmake/"$buildTypeLower"/arm64-v8a/output/dcg/"$buildType"/ "$output_dir/arm64-v8a/"
cp -rp app/.cxx/cmake/"$buildTypeLower"/armeabi-v7a/output/dcg/"$buildType"/ "$output_dir/armeabi-v7a/"
cp -rp app/.cxx/cmake/"$buildTypeLower"/x86/output/dcg/"$buildType"/ "$output_dir/x86/"
cp -rp app/.cxx/cmake/"$buildTypeLower"/x86_64/output/dcg/"$buildType"/ "$output_dir/x86_64/"
mkdir -p "$output_dir/include"
cp -rp app/.cxx/cmake/"$buildTypeLower"/arm64-v8a/output/include/ "$output_dir/include/"
mkdir -p "$output_dir/arm64-v8a"
cp -rp app/.cxx/cmake/"$buildTypeLower"/arm64-v8a/output/"$buildType"/ "$output_dir/arm64-v8a/"
mkdir -p "$output_dir/armeabi-v7a"
cp -rp app/.cxx/cmake/"$buildTypeLower"/armeabi-v7a/output/"$buildType"/ "$output_dir/armeabi-v7a/"
mkdir -p "$output_dir/x86"
cp -rp app/.cxx/cmake/"$buildTypeLower"/x86/output/"$buildType"/ "$output_dir/x86/"
mkdir -p "$output_dir/x86_64"
cp -rp app/.cxx/cmake/"$buildTypeLower"/x86_64/output/"$buildType"/ "$output_dir/x86_64/"
}

if [ "$1" = "build" ]; then
Expand Down

0 comments on commit 4152f45

Please sign in to comment.