Skip to content

Commit

Permalink
Merge branch 'release/2023.12.1' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
melpon committed Sep 10, 2023
2 parents b742d73 + eba4be9 commit 8e0721c
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@

## develop

## 2023.12.1 (2023-09-10)

- [FIX] V4L2VideoCapturer でデバイス名の指定が無視されていたのを修正
- @melpon
- [FIX] Android で動かすために必要な libwebrtc の初期化処理を追加
- @melpon

## 2023.12.0 (2023-09-08)

- [CHANGE] MacCapturer の解放前に明示的に Stop() 関数を呼ぶ必要があるようになる
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SORA_CPP_SDK_VERSION=2023.12.0
SORA_CPP_SDK_VERSION=2023.12.1
WEBRTC_BUILD_VERSION=m116.5845.6.1
BOOST_VERSION=1.82.0
CMAKE_VERSION=3.26.4
Expand Down
3 changes: 2 additions & 1 deletion include/sora/android/android_capturer.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class AndroidCapturer : public webrtc::jni::AndroidVideoTrackSource {
int height,
int target_fps);
static void stopCapture(JNIEnv* env, jobject capturer);
static void dispose(JNIEnv* env, jobject capturer);
static void dispose(JNIEnv* env, jobject capturer, jobject helper);

bool Init(JNIEnv* env,
jobject context,
Expand All @@ -69,6 +69,7 @@ class AndroidCapturer : public webrtc::jni::AndroidVideoTrackSource {
std::unique_ptr<webrtc::ScopedJavaGlobalRef<jobject>>
native_capturer_observer_;
std::unique_ptr<webrtc::ScopedJavaGlobalRef<jobject>> video_capturer_;
std::unique_ptr<webrtc::ScopedJavaGlobalRef<jobject>> helper_;
};

} // namespace sora
Expand Down
15 changes: 11 additions & 4 deletions src/android/android_capturer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ void AndroidCapturer::Stop() {
if (video_capturer_ != nullptr) {
RTC_LOG(LS_INFO) << "AndroidCapturer::stopCapture";
stopCapture(env_, video_capturer_->obj());
dispose(env_, video_capturer_->obj());
dispose(env_, video_capturer_->obj(), helper_->obj());
video_capturer_.reset();
native_capturer_observer_.reset();
helper_.reset();
}
}

Expand Down Expand Up @@ -200,11 +201,16 @@ void AndroidCapturer::stopCapture(JNIEnv* env, jobject capturer) {
jmethodID stopid = env->GetMethodID(capcls.obj(), "stopCapture", "()V");
env->CallVoidMethod(capturer, stopid);
}
void AndroidCapturer::dispose(JNIEnv* env, jobject capturer) {
void AndroidCapturer::dispose(JNIEnv* env, jobject capturer, jobject helper) {
// videoCapturer.dispose();
// surfaceTextureHelper.dispose();
webrtc::ScopedJavaLocalRef<jclass> capcls(env, env->GetObjectClass(capturer));
jmethodID disposeid = env->GetMethodID(capcls.obj(), "dispose", "()V");
env->CallVoidMethod(capturer, disposeid);
jmethodID capdisposeid = env->GetMethodID(capcls.obj(), "dispose", "()V");
env->CallVoidMethod(capturer, capdisposeid);

webrtc::ScopedJavaLocalRef<jclass> helpcls(env, env->GetObjectClass(helper));
jmethodID helpdisposeid = env->GetMethodID(helpcls.obj(), "dispose", "()V");
env->CallVoidMethod(helper, helpdisposeid);
}

bool AndroidCapturer::Init(JNIEnv* env,
Expand Down Expand Up @@ -294,6 +300,7 @@ bool AndroidCapturer::Init(JNIEnv* env,
video_capturer_.reset(
new webrtc::ScopedJavaGlobalRef<jobject>(env, capturer));
native_capturer_observer_ = std::move(native_capturer_observer);
helper_.reset(new webrtc::ScopedJavaGlobalRef<jobject>(env, helper));

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/audio_device_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ rtc::scoped_refptr<webrtc::AudioDeviceModule> CreateAudioDeviceModule(
return webrtc::CreateWindowsCoreAudioAudioDeviceModule(
config.task_queue_factory);
#elif defined(SORA_CPP_SDK_ANDROID)
return webrtc::CreateJavaAudioDeviceModule(
return webrtc::CreateOpenSLESAudioDeviceModule(
(JNIEnv*)config.jni_env, (jobject)config.application_context);
#else
return webrtc::AudioDeviceModule::Create(config.audio_layer,
Expand Down
1 change: 1 addition & 0 deletions src/camera_device_capturer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ CreateCameraDeviceCapturer(const CameraDeviceCapturerConfig& config) {
#elif defined(__linux__)
sora::V4L2VideoCapturerConfig v4l2_config;
v4l2_config.on_frame = config.on_frame;
v4l2_config.video_device = config.device_name;
v4l2_config.width = config.width;
v4l2_config.height = config.height;
v4l2_config.framerate = config.fps;
Expand Down
11 changes: 10 additions & 1 deletion src/java_context.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
#include "sora/java_context.h"

#ifdef SORA_CPP_SDK_ANDROID
#include <modules/utility/include/jvm_android.h>
#include <sdk/android/native_api/jni/jvm.h>
#include <sdk/android/src/jni/jvm.h>
#endif

namespace sora {

void* GetJNIEnv() {
#ifdef SORA_CPP_SDK_ANDROID
// webrtc::JVM::Initialize を呼んでおかないと
// libwebrtc の内部関数で落ちることがあるので設定しておく
static bool jvm_initialized = false;
if (!jvm_initialized) {
webrtc::JVM::Initialize(webrtc::jni::GetJVM());
jvm_initialized = true;
}
return webrtc::AttachCurrentThreadIfNeeded();
#else
return nullptr;
#endif
}

}
} // namespace sora

0 comments on commit 8e0721c

Please sign in to comment.