Android: Generate Java -> C++ JNI code for VideoEncoder
This is the first CL that tries generating Java -> C++ JNI code. Bug: webrtc:8278 Change-Id: I1ff0df10db0f80a3c84a61a4e82be8f713690a69 Reviewed-on: https://webrtc-review.googlesource.com/20873 Commit-Queue: Magnus Jedvert <magjed@webrtc.org> Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20592}
This commit is contained in:
committed by
Commit Bot
parent
3f2634eadc
commit
18ce0f006d
@ -488,6 +488,7 @@ rtc_android_library("libjingle_peerconnection_java") {
|
|||||||
"src/java/org/webrtc/Histogram.java",
|
"src/java/org/webrtc/Histogram.java",
|
||||||
"src/java/org/webrtc/JniCommon.java",
|
"src/java/org/webrtc/JniCommon.java",
|
||||||
"src/java/org/webrtc/MediaCodecUtils.java",
|
"src/java/org/webrtc/MediaCodecUtils.java",
|
||||||
|
"src/java/org/webrtc/NativeClassQualifiedName.java",
|
||||||
"src/java/org/webrtc/NativeLibrary.java",
|
"src/java/org/webrtc/NativeLibrary.java",
|
||||||
"src/java/org/webrtc/NV12Buffer.java",
|
"src/java/org/webrtc/NV12Buffer.java",
|
||||||
"src/java/org/webrtc/NV21Buffer.java",
|
"src/java/org/webrtc/NV21Buffer.java",
|
||||||
|
|||||||
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.webrtc;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NativeClassQualifiedName is used by the JNI generator to create the necessary JNI
|
||||||
|
* bindings to call into the specified native class name.
|
||||||
|
*/
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface NativeClassQualifiedName {
|
||||||
|
/*
|
||||||
|
* Tells which native class the method is going to be bound to.
|
||||||
|
* The first parameter of the annotated method must be an int nativePtr pointing to
|
||||||
|
* an instance of this class.
|
||||||
|
*/
|
||||||
|
public String value();
|
||||||
|
}
|
||||||
@ -69,12 +69,13 @@ class VideoEncoderWrapper {
|
|||||||
@CalledByNative
|
@CalledByNative
|
||||||
static VideoEncoder.Callback createEncoderCallback(final long nativeEncoder) {
|
static VideoEncoder.Callback createEncoderCallback(final long nativeEncoder) {
|
||||||
return (EncodedImage frame, VideoEncoder.CodecSpecificInfo info)
|
return (EncodedImage frame, VideoEncoder.CodecSpecificInfo info)
|
||||||
-> onEncodedFrame(nativeEncoder, frame.buffer, frame.encodedWidth,
|
-> nativeOnEncodedFrame(nativeEncoder, frame.buffer, frame.encodedWidth,
|
||||||
frame.encodedHeight, frame.captureTimeNs, frame.frameType.getNative(),
|
frame.encodedHeight, frame.captureTimeNs, frame.frameType.getNative(),
|
||||||
frame.rotation, frame.completeFrame, frame.qp);
|
frame.rotation, frame.completeFrame, frame.qp);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static native void onEncodedFrame(long nativeEncoder, ByteBuffer buffer, int encodedWidth,
|
@NativeClassQualifiedName("webrtc::jni::VideoEncoderWrapper")
|
||||||
int encodedHeight, long captureTimeNs, int frameType, int rotation, boolean completeFrame,
|
private static native void nativeOnEncodedFrame(long nativeEncoder, ByteBuffer buffer,
|
||||||
Integer qp);
|
int encodedWidth, int encodedHeight, long captureTimeNs, int frameType, int rotation,
|
||||||
|
boolean completeFrame, Integer qp);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,9 +19,12 @@
|
|||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
|
||||||
#define CHECK_CLAZZ(env, jcaller, clazz, ...) RTC_DCHECK(clazz);
|
#define CHECK_CLAZZ(env, jcaller, clazz, ...) RTC_DCHECK(clazz);
|
||||||
|
#define CHECK_NATIVE_PTR(env, jcaller, native_ptr, method_name, ...) \
|
||||||
|
RTC_DCHECK(native_ptr) << method_name;
|
||||||
|
|
||||||
#define BASE_EXPORT
|
#define BASE_EXPORT
|
||||||
#define JNI_REGISTRATION_EXPORT __attribute__((visibility("default")))
|
#define JNI_REGISTRATION_EXPORT __attribute__((visibility("default")))
|
||||||
|
#define JNI_GENERATOR_EXPORT extern "C" JNIEXPORT JNICALL
|
||||||
|
|
||||||
namespace jni_generator {
|
namespace jni_generator {
|
||||||
inline void CheckException(JNIEnv* env) {
|
inline void CheckException(JNIEnv* env) {
|
||||||
@ -70,6 +73,8 @@ class JavaRef {
|
|||||||
// using DeleteLocalRef though.
|
// using DeleteLocalRef though.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using ScopedJavaLocalRef = JavaRef<T>;
|
using ScopedJavaLocalRef = JavaRef<T>;
|
||||||
|
template <typename T>
|
||||||
|
using JavaParamRef = JavaRef<T>;
|
||||||
|
|
||||||
// This function will initialize |atomic_class_id| to contain a global ref to
|
// This function will initialize |atomic_class_id| to contain a global ref to
|
||||||
// the given class, and will return that ref on subsequent calls. The caller is
|
// the given class, and will return that ref on subsequent calls. The caller is
|
||||||
|
|||||||
@ -192,6 +192,7 @@ const char* VideoEncoderWrapper::ImplementationName() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void VideoEncoderWrapper::OnEncodedFrame(JNIEnv* jni,
|
void VideoEncoderWrapper::OnEncodedFrame(JNIEnv* jni,
|
||||||
|
jobject j_caller,
|
||||||
jobject j_buffer,
|
jobject j_buffer,
|
||||||
jint encoded_width,
|
jint encoded_width,
|
||||||
jint encoded_height,
|
jint encoded_height,
|
||||||
@ -402,25 +403,5 @@ std::string VideoEncoderWrapper::GetImplementationName(JNIEnv* jni) const {
|
|||||||
return JavaToStdString(jni, jname);
|
return JavaToStdString(jni, jname);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNI_FUNCTION_DECLARATION(void,
|
|
||||||
VideoEncoderWrapper_onEncodedFrame,
|
|
||||||
JNIEnv* jni,
|
|
||||||
jclass,
|
|
||||||
jlong j_native_encoder,
|
|
||||||
jobject buffer,
|
|
||||||
jint encoded_width,
|
|
||||||
jint encoded_height,
|
|
||||||
jlong capture_time_ns,
|
|
||||||
jint frame_type,
|
|
||||||
jint rotation,
|
|
||||||
jboolean complete_frame,
|
|
||||||
jobject qp) {
|
|
||||||
VideoEncoderWrapper* native_encoder =
|
|
||||||
reinterpret_cast<VideoEncoderWrapper*>(j_native_encoder);
|
|
||||||
native_encoder->OnEncodedFrame(jni, buffer, encoded_width, encoded_height,
|
|
||||||
capture_time_ns, frame_type, rotation,
|
|
||||||
complete_frame, qp);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace jni
|
} // namespace jni
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|||||||
@ -55,6 +55,7 @@ class VideoEncoderWrapper : public VideoEncoder {
|
|||||||
|
|
||||||
// Should only be called by JNI.
|
// Should only be called by JNI.
|
||||||
void OnEncodedFrame(JNIEnv* jni,
|
void OnEncodedFrame(JNIEnv* jni,
|
||||||
|
jobject j_caller,
|
||||||
jobject j_buffer,
|
jobject j_buffer,
|
||||||
jint encoded_width,
|
jint encoded_width,
|
||||||
jint encoded_height,
|
jint encoded_height,
|
||||||
|
|||||||
Reference in New Issue
Block a user