Android: Use scoped java refs
We currently use raw jobject in our code mixed with sporadic ScopedLocalRefFrame. This CL moves every jobject into a scoped object, either local, global, or a parameter. Also, this CL uses the JNI generation script to generate declaration stubs for the Java->C++ functions so that it no longer becomes possible to mistype them without getting compilation errors. TBR=brandt@webrtc.org Bug: webrtc:8278,webrtc:6969 Change-Id: Ic7bac74a89c11180177d65041086d7db1cdfb516 Reviewed-on: https://webrtc-review.googlesource.com/34655 Commit-Queue: Magnus Jedvert <magjed@webrtc.org> Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> Cr-Commit-Position: refs/heads/master@{#21387}
This commit is contained in:
committed by
Commit Bot
parent
ec22e3f503
commit
84d8ae5df7
@ -11,6 +11,7 @@
|
||||
package org.webrtc;
|
||||
|
||||
/** An implementation of CapturerObserver that forwards all calls from Java to the C layer. */
|
||||
@JNINamespace("webrtc::jni")
|
||||
class AndroidVideoTrackSourceObserver implements VideoCapturer.CapturerObserver {
|
||||
// Pointer to VideoTrackSourceProxy proxying AndroidVideoTrackSource.
|
||||
private final long nativeSource;
|
||||
@ -49,12 +50,12 @@ class AndroidVideoTrackSourceObserver implements VideoCapturer.CapturerObserver
|
||||
frame.getRotation(), frame.getTimestampNs(), frame.getBuffer());
|
||||
}
|
||||
|
||||
private native void nativeCapturerStarted(long nativeSource, boolean success);
|
||||
private native void nativeCapturerStopped(long nativeSource);
|
||||
private native void nativeOnByteBufferFrameCaptured(long nativeSource, byte[] data, int length,
|
||||
int width, int height, int rotation, long timeStamp);
|
||||
private native void nativeOnTextureFrameCaptured(long nativeSource, int width, int height,
|
||||
private static native void nativeCapturerStarted(long source, boolean success);
|
||||
private static native void nativeCapturerStopped(long source);
|
||||
private static native void nativeOnByteBufferFrameCaptured(
|
||||
long source, byte[] data, int length, int width, int height, int rotation, long timeStamp);
|
||||
private static native void nativeOnTextureFrameCaptured(long source, int width, int height,
|
||||
int oesTextureId, float[] transformMatrix, int rotation, long timestamp);
|
||||
private native void nativeOnFrameCaptured(long nativeSource, int width, int height, int rotation,
|
||||
long timestampNs, VideoFrame.Buffer frame);
|
||||
private static native void nativeOnFrameCaptured(
|
||||
long source, int width, int height, int rotation, long timestampNs, VideoFrame.Buffer frame);
|
||||
}
|
||||
|
||||
@ -19,6 +19,7 @@ package org.webrtc;
|
||||
* Histogram.createCounts("WebRTC.Video.SomeMetric", 1, 10000, 50);
|
||||
* someMetricHistogram.addSample(someVariable);
|
||||
*/
|
||||
@JNINamespace("webrtc::jni")
|
||||
class Histogram {
|
||||
private final long handle;
|
||||
|
||||
|
||||
26
sdk/android/src/java/org/webrtc/JNINamespace.java
Normal file
26
sdk/android/src/java/org/webrtc/JNINamespace.java
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @JNINamespace is used by the JNI generator to create the necessary JNI
|
||||
* bindings and expose this method to native code using the specified namespace.
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface JNINamespace {
|
||||
public String value();
|
||||
}
|
||||
@ -13,11 +13,12 @@ package org.webrtc;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/** Class with static JNI helper functions that are used in many places. */
|
||||
@JNINamespace("webrtc::jni")
|
||||
class JniCommon {
|
||||
/** Functions to increment/decrement an rtc::RefCountInterface pointer. */
|
||||
static native void nativeAddRef(long nativeRefCountedPointer);
|
||||
static native void nativeReleaseRef(long nativeRefCountedPointer);
|
||||
static native void nativeAddRef(long refCountedPointer);
|
||||
static native void nativeReleaseRef(long refCountedPointer);
|
||||
|
||||
public static native ByteBuffer allocateNativeByteBuffer(int size);
|
||||
public static native void freeNativeByteBuffer(ByteBuffer buffer);
|
||||
public static native ByteBuffer nativeAllocateByteBuffer(int size);
|
||||
public static native void nativeFreeByteBuffer(ByteBuffer buffer);
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ package org.webrtc;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@JNINamespace("webrtc::jni")
|
||||
public class NV12Buffer implements VideoFrame.Buffer {
|
||||
private final int width;
|
||||
private final int height;
|
||||
|
||||
@ -12,6 +12,7 @@ package org.webrtc;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@JNINamespace("webrtc::jni")
|
||||
public class NV21Buffer implements VideoFrame.Buffer {
|
||||
private final byte[] data;
|
||||
private final int width;
|
||||
|
||||
@ -10,6 +10,12 @@
|
||||
|
||||
package org.webrtc;
|
||||
|
||||
@JNINamespace("webrtc::jni")
|
||||
class VP8Decoder extends WrappedNativeVideoDecoder {
|
||||
@Override native long createNativeDecoder();
|
||||
@Override
|
||||
long createNativeDecoder() {
|
||||
return nativeCreateDecoder();
|
||||
}
|
||||
|
||||
static native long nativeCreateDecoder();
|
||||
}
|
||||
|
||||
@ -10,8 +10,14 @@
|
||||
|
||||
package org.webrtc;
|
||||
|
||||
@JNINamespace("webrtc::jni")
|
||||
class VP8Encoder extends WrappedNativeVideoEncoder {
|
||||
@Override native long createNativeEncoder();
|
||||
@Override
|
||||
long createNativeEncoder() {
|
||||
return nativeCreateEncoder();
|
||||
}
|
||||
|
||||
static native long nativeCreateEncoder();
|
||||
|
||||
@Override
|
||||
boolean isSoftwareEncoder() {
|
||||
|
||||
@ -10,8 +10,14 @@
|
||||
|
||||
package org.webrtc;
|
||||
|
||||
@JNINamespace("webrtc::jni")
|
||||
class VP9Decoder extends WrappedNativeVideoDecoder {
|
||||
@Override native long createNativeDecoder();
|
||||
@Override
|
||||
long createNativeDecoder() {
|
||||
return nativeCreateDecoder();
|
||||
}
|
||||
|
||||
static native boolean isSupported();
|
||||
static native long nativeCreateDecoder();
|
||||
|
||||
static native boolean nativeIsSupported();
|
||||
}
|
||||
|
||||
@ -10,13 +10,19 @@
|
||||
|
||||
package org.webrtc;
|
||||
|
||||
@JNINamespace("webrtc::jni")
|
||||
class VP9Encoder extends WrappedNativeVideoEncoder {
|
||||
@Override native long createNativeEncoder();
|
||||
@Override
|
||||
long createNativeEncoder() {
|
||||
return nativeCreateEncoder();
|
||||
}
|
||||
|
||||
static native long nativeCreateEncoder();
|
||||
|
||||
@Override
|
||||
boolean isSoftwareEncoder() {
|
||||
return true;
|
||||
}
|
||||
|
||||
static native boolean isSupported();
|
||||
static native boolean nativeIsSupported();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user