1+ /*
2+ * Copyright 2019 Alex Andres
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ #include " JNI_CustomVideoSource.h"
18+ #include " JavaUtils.h"
19+ #include " api/VideoFrame.h"
20+
21+ #include " media/video/CustomVideoSource.h"
22+
23+ #include " rtc_base/logging.h"
24+
25+ JNIEXPORT void JNICALL Java_dev_onvoid_webrtc_media_video_CustomVideoSource_initialize
26+ (JNIEnv * env, jobject caller)
27+ {
28+ std::shared_ptr<jni::SyncClock> sync_clock = std::make_shared<jni::SyncClock>();
29+ webrtc::scoped_refptr<jni::CustomVideoSource> source = webrtc::make_ref_counted<jni::CustomVideoSource>(sync_clock);
30+
31+ SetHandle (env, caller, source.release ());
32+ }
33+
34+ JNIEXPORT void JNICALL Java_dev_onvoid_webrtc_media_video_CustomVideoSource_dispose
35+ (JNIEnv * env, jobject caller)
36+ {
37+ jni::CustomVideoSource * source = GetHandle<jni::CustomVideoSource>(env, caller);
38+ CHECK_HANDLE (source);
39+
40+ webrtc::RefCountReleaseStatus status = source->Release ();
41+
42+ if (status != webrtc::RefCountReleaseStatus::kDroppedLastRef ) {
43+ RTC_LOG (LS_WARNING) << " Native object was not deleted. A reference is still around somewhere." ;
44+ }
45+
46+ SetHandle<std::nullptr_t >(env, caller, nullptr );
47+
48+ source = nullptr ;
49+ }
50+
51+ JNIEXPORT void JNICALL Java_dev_onvoid_webrtc_media_video_CustomVideoSource_pushFrame
52+ (JNIEnv * env, jobject caller, jobject javaFrame)
53+ {
54+ jni::CustomVideoSource * source = GetHandle<jni::CustomVideoSource>(env, caller);
55+ CHECK_HANDLE (source);
56+
57+ if (javaFrame != nullptr ) {
58+ auto frame = jni::JavaLocalRef<jobject>(env, javaFrame);
59+ webrtc::VideoFrame nativeFrame = jni::VideoFrame::toNative (env, frame);
60+
61+ source->PushFrame (nativeFrame);
62+ }
63+ }
0 commit comments