WebRTCDemo: couldn't run a second time. The reason is voe could register/unregister for each run, but vie would expect initialization only once per process.
This cl is to teach videocapture android how to deinitialize and allow it to be re-initializable. BUG=3284 TEST=ManualTest R=fischman@webrtc.org Review URL: https://webrtc-codereview.appspot.com/15429004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@6167 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
54231f0662
commit
7cb4752184
@ -47,6 +47,8 @@ JOWW(void, NativeWebRtcContextRegistry_register)(
|
||||
JOWW(void, NativeWebRtcContextRegistry_unRegister)(
|
||||
JNIEnv* jni,
|
||||
jclass) {
|
||||
CHECK(webrtc::VideoEngine::SetAndroidObjects(NULL) == 0,
|
||||
"Failed to unregister android objects from video engine");
|
||||
CHECK(webrtc::VoiceEngine::SetAndroidObjects(NULL, NULL, NULL) == 0,
|
||||
"Failed to unregister android objects from voice engine");
|
||||
webrtc_examples::ClearVieDeviceObjects();
|
||||
|
@ -142,6 +142,13 @@ void DeviceInfoAndroid::Initialize(JNIEnv* jni) {
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceInfoAndroid::DeInitialize() {
|
||||
if (g_camera_info) {
|
||||
delete g_camera_info;
|
||||
g_camera_info = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
VideoCaptureModule::DeviceInfo* VideoCaptureImpl::CreateDeviceInfo(
|
||||
const int32_t id) {
|
||||
return new videocapturemodule::DeviceInfoAndroid(id);
|
||||
|
@ -24,6 +24,7 @@ namespace videocapturemodule
|
||||
class DeviceInfoAndroid : public DeviceInfoImpl {
|
||||
public:
|
||||
static void Initialize(JNIEnv* env);
|
||||
static void DeInitialize();
|
||||
|
||||
DeviceInfoAndroid(int32_t id);
|
||||
virtual ~DeviceInfoAndroid();
|
||||
|
@ -39,25 +39,37 @@ void JNICALL ProvideCameraFrame(
|
||||
}
|
||||
|
||||
int32_t SetCaptureAndroidVM(JavaVM* javaVM) {
|
||||
assert(!g_jvm);
|
||||
g_jvm = javaVM;
|
||||
AttachThreadScoped ats(g_jvm);
|
||||
if (javaVM) {
|
||||
assert(!g_jvm);
|
||||
g_jvm = javaVM;
|
||||
AttachThreadScoped ats(g_jvm);
|
||||
|
||||
videocapturemodule::DeviceInfoAndroid::Initialize(ats.env());
|
||||
videocapturemodule::DeviceInfoAndroid::Initialize(ats.env());
|
||||
|
||||
jclass j_capture_class =
|
||||
ats.env()->FindClass("org/webrtc/videoengine/VideoCaptureAndroid");
|
||||
assert(j_capture_class);
|
||||
g_java_capturer_class =
|
||||
reinterpret_cast<jclass>(ats.env()->NewGlobalRef(j_capture_class));
|
||||
assert(g_java_capturer_class);
|
||||
jclass j_capture_class =
|
||||
ats.env()->FindClass("org/webrtc/videoengine/VideoCaptureAndroid");
|
||||
assert(j_capture_class);
|
||||
g_java_capturer_class =
|
||||
reinterpret_cast<jclass>(ats.env()->NewGlobalRef(j_capture_class));
|
||||
assert(g_java_capturer_class);
|
||||
|
||||
JNINativeMethod native_method = {
|
||||
"ProvideCameraFrame", "([BIJ)V",
|
||||
reinterpret_cast<void*>(&ProvideCameraFrame)
|
||||
};
|
||||
if (ats.env()->RegisterNatives(g_java_capturer_class, &native_method, 1) != 0)
|
||||
assert(false);
|
||||
JNINativeMethod native_method = {
|
||||
"ProvideCameraFrame", "([BIJ)V",
|
||||
reinterpret_cast<void*>(&ProvideCameraFrame)
|
||||
};
|
||||
if (ats.env()->RegisterNatives(g_java_capturer_class,
|
||||
&native_method, 1) != 0)
|
||||
assert(false);
|
||||
} else {
|
||||
if (g_jvm) {
|
||||
AttachThreadScoped ats(g_jvm);
|
||||
ats.env()->UnregisterNatives(g_java_capturer_class);
|
||||
ats.env()->DeleteGlobalRef(g_java_capturer_class);
|
||||
g_java_capturer_class = NULL;
|
||||
videocapturemodule::DeviceInfoAndroid::DeInitialize();
|
||||
g_jvm = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user