Annotate libjingle_peerconnection_java with @Nullable.
Bug: webrtc:8881 Change-Id: Ida2ef6c003567d19529c21629c916ed40e8de3a6 Reviewed-on: https://webrtc-review.googlesource.com/63380 Commit-Queue: Sami Kalliomäki <sakal@webrtc.org> Reviewed-by: Paulina Hensman <phensman@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22563}
This commit is contained in:

committed by
Commit Bot

parent
12d6a49e97
commit
e7592d8d5f
@ -844,9 +844,16 @@ rtc_android_library("libjingle_peerconnection_java") {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
javac_args = [
|
||||||
|
"-Xep:ParameterNotNullable:ERROR",
|
||||||
|
"-Xep:FieldMissingNullable:ERROR",
|
||||||
|
"-Xep:ReturnMissingNullable:ERROR",
|
||||||
|
]
|
||||||
|
|
||||||
deps = [
|
deps = [
|
||||||
"../../modules/audio_device:audio_device_java",
|
"../../modules/audio_device:audio_device_java",
|
||||||
"../../rtc_base:base_java",
|
"../../rtc_base:base_java",
|
||||||
|
"//third_party/jsr-305:jsr_305_javalib",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ package org.webrtc;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.media.MediaRecorder;
|
import android.media.MediaRecorder;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class Camera1Capturer extends CameraCapturer {
|
public class Camera1Capturer extends CameraCapturer {
|
||||||
private final boolean captureToTexture;
|
private final boolean captureToTexture;
|
||||||
@ -26,8 +27,8 @@ public class Camera1Capturer extends CameraCapturer {
|
|||||||
@Override
|
@Override
|
||||||
protected void createCameraSession(CameraSession.CreateSessionCallback createSessionCallback,
|
protected void createCameraSession(CameraSession.CreateSessionCallback createSessionCallback,
|
||||||
CameraSession.Events events, Context applicationContext,
|
CameraSession.Events events, Context applicationContext,
|
||||||
SurfaceTextureHelper surfaceTextureHelper, MediaRecorder mediaRecorder, String cameraName,
|
SurfaceTextureHelper surfaceTextureHelper, @Nullable MediaRecorder mediaRecorder,
|
||||||
int width, int height, int framerate) {
|
String cameraName, int width, int height, int framerate) {
|
||||||
Camera1Session.create(createSessionCallback, events,
|
Camera1Session.create(createSessionCallback, events,
|
||||||
captureToTexture || (mediaRecorder != null), applicationContext, surfaceTextureHelper,
|
captureToTexture || (mediaRecorder != null), applicationContext, surfaceTextureHelper,
|
||||||
mediaRecorder, Camera1Enumerator.getCameraIndex(cameraName), width, height, framerate);
|
mediaRecorder, Camera1Enumerator.getCameraIndex(cameraName), width, height, framerate);
|
||||||
|
@ -13,6 +13,7 @@ package org.webrtc;
|
|||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import org.webrtc.CameraEnumerationAndroid.CaptureFormat;
|
import org.webrtc.CameraEnumerationAndroid.CaptureFormat;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@ -73,7 +74,7 @@ public class Camera1Enumerator implements CameraEnumerator {
|
|||||||
return new Camera1Capturer(deviceName, eventsHandler, captureToTexture);
|
return new Camera1Capturer(deviceName, eventsHandler, captureToTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static android.hardware.Camera.CameraInfo getCameraInfo(int index) {
|
private static @Nullable android.hardware.Camera.CameraInfo getCameraInfo(int index) {
|
||||||
android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
|
android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
|
||||||
try {
|
try {
|
||||||
android.hardware.Camera.getCameraInfo(index, info);
|
android.hardware.Camera.getCameraInfo(index, info);
|
||||||
@ -171,7 +172,7 @@ public class Camera1Enumerator implements CameraEnumerator {
|
|||||||
|
|
||||||
// Returns the name of the camera with camera index. Returns null if the
|
// Returns the name of the camera with camera index. Returns null if the
|
||||||
// camera can not be used.
|
// camera can not be used.
|
||||||
static String getDeviceName(int index) {
|
static @Nullable String getDeviceName(int index) {
|
||||||
android.hardware.Camera.CameraInfo info = getCameraInfo(index);
|
android.hardware.Camera.CameraInfo info = getCameraInfo(index);
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -14,11 +14,12 @@ import android.annotation.TargetApi;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.hardware.camera2.CameraManager;
|
import android.hardware.camera2.CameraManager;
|
||||||
import android.media.MediaRecorder;
|
import android.media.MediaRecorder;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@TargetApi(21)
|
@TargetApi(21)
|
||||||
public class Camera2Capturer extends CameraCapturer {
|
public class Camera2Capturer extends CameraCapturer {
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private final CameraManager cameraManager;
|
@Nullable private final CameraManager cameraManager;
|
||||||
|
|
||||||
public Camera2Capturer(Context context, String cameraName, CameraEventsHandler eventsHandler) {
|
public Camera2Capturer(Context context, String cameraName, CameraEventsHandler eventsHandler) {
|
||||||
super(cameraName, eventsHandler, new Camera2Enumerator(context));
|
super(cameraName, eventsHandler, new Camera2Enumerator(context));
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
|
|
||||||
package org.webrtc;
|
package org.webrtc;
|
||||||
|
|
||||||
import org.webrtc.CameraEnumerationAndroid.CaptureFormat;
|
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
@ -24,11 +22,12 @@ import android.os.Build;
|
|||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.util.AndroidException;
|
import android.util.AndroidException;
|
||||||
import android.util.Range;
|
import android.util.Range;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import org.webrtc.CameraEnumerationAndroid.CaptureFormat;
|
||||||
|
|
||||||
@TargetApi(21)
|
@TargetApi(21)
|
||||||
public class Camera2Enumerator implements CameraEnumerator {
|
public class Camera2Enumerator implements CameraEnumerator {
|
||||||
@ -41,7 +40,7 @@ public class Camera2Enumerator implements CameraEnumerator {
|
|||||||
new HashMap<String, List<CaptureFormat>>();
|
new HashMap<String, List<CaptureFormat>>();
|
||||||
|
|
||||||
final Context context;
|
final Context context;
|
||||||
final CameraManager cameraManager;
|
@Nullable final CameraManager cameraManager;
|
||||||
|
|
||||||
public Camera2Enumerator(Context context) {
|
public Camera2Enumerator(Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
@ -90,7 +89,7 @@ public class Camera2Enumerator implements CameraEnumerator {
|
|||||||
return new Camera2Capturer(context, deviceName, eventsHandler);
|
return new Camera2Capturer(context, deviceName, eventsHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CameraCharacteristics getCameraCharacteristics(String deviceName) {
|
private @Nullable CameraCharacteristics getCameraCharacteristics(String deviceName) {
|
||||||
try {
|
try {
|
||||||
return cameraManager.getCameraCharacteristics(deviceName);
|
return cameraManager.getCameraCharacteristics(deviceName);
|
||||||
// On Android OS pre 4.4.2, a class will not load because of VerifyError if it contains a
|
// On Android OS pre 4.4.2, a class will not load because of VerifyError if it contains a
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
package org.webrtc;
|
package org.webrtc;
|
||||||
|
|
||||||
import android.media.MediaRecorder;
|
import android.media.MediaRecorder;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base interface for camera1 and camera2 implementations. Extends VideoCapturer with a
|
* Base interface for camera1 and camera2 implementations. Extends VideoCapturer with a
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
package org.webrtc;
|
package org.webrtc;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class DefaultVideoDecoderFactory implements VideoDecoderFactory {
|
public class DefaultVideoDecoderFactory implements VideoDecoderFactory {
|
||||||
private final HardwareVideoDecoderFactory hardwareVideoDecoderFactory;
|
private final HardwareVideoDecoderFactory hardwareVideoDecoderFactory;
|
||||||
private final SoftwareVideoDecoderFactory softwareVideoDecoderFactory;
|
private final SoftwareVideoDecoderFactory softwareVideoDecoderFactory;
|
||||||
@ -21,7 +23,7 @@ public class DefaultVideoDecoderFactory implements VideoDecoderFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VideoDecoder createDecoder(String codecType) {
|
public @Nullable VideoDecoder createDecoder(String codecType) {
|
||||||
VideoDecoder decoder = hardwareVideoDecoderFactory.createDecoder(codecType);
|
VideoDecoder decoder = hardwareVideoDecoderFactory.createDecoder(codecType);
|
||||||
if (decoder != null) {
|
if (decoder != null) {
|
||||||
return decoder;
|
return decoder;
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
package org.webrtc;
|
package org.webrtc;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -31,6 +32,7 @@ public class DefaultVideoEncoderFactory implements VideoEncoderFactory {
|
|||||||
softwareVideoEncoderFactory = new SoftwareVideoEncoderFactory();
|
softwareVideoEncoderFactory = new SoftwareVideoEncoderFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public VideoEncoder createEncoder(VideoCodecInfo info) {
|
public VideoEncoder createEncoder(VideoCodecInfo info) {
|
||||||
final VideoEncoder videoEncoder = hardwareVideoEncoderFactory.createEncoder(info);
|
final VideoEncoder videoEncoder = hardwareVideoEncoderFactory.createEncoder(info);
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
package org.webrtc;
|
package org.webrtc;
|
||||||
|
|
||||||
import android.graphics.SurfaceTexture;
|
import android.graphics.SurfaceTexture;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
import javax.microedition.khronos.egl.EGL10;
|
import javax.microedition.khronos.egl.EGL10;
|
||||||
|
|
||||||
@ -84,7 +85,7 @@ public interface EglBase {
|
|||||||
* If |sharedContext| is null, a root context is created. This function will try to create an EGL
|
* If |sharedContext| is null, a root context is created. This function will try to create an EGL
|
||||||
* 1.4 context if possible, and an EGL 1.0 context otherwise.
|
* 1.4 context if possible, and an EGL 1.0 context otherwise.
|
||||||
*/
|
*/
|
||||||
public static EglBase create(Context sharedContext, int[] configAttributes) {
|
public static EglBase create(@Nullable Context sharedContext, int[] configAttributes) {
|
||||||
return (EglBase14.isEGL14Supported()
|
return (EglBase14.isEGL14Supported()
|
||||||
&& (sharedContext == null || sharedContext instanceof EglBase14.Context))
|
&& (sharedContext == null || sharedContext instanceof EglBase14.Context))
|
||||||
? new EglBase14((EglBase14.Context) sharedContext, configAttributes)
|
? new EglBase14((EglBase14.Context) sharedContext, configAttributes)
|
||||||
|
@ -24,6 +24,7 @@ import java.util.Iterator;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements org.webrtc.VideoRenderer.Callbacks by displaying the video stream on an EGL Surface.
|
* Implements org.webrtc.VideoRenderer.Callbacks by displaying the video stream on an EGL Surface.
|
||||||
@ -84,7 +85,7 @@ public class EglRenderer implements VideoRenderer.Callbacks, VideoSink {
|
|||||||
// |renderThreadHandler| is a handler for communicating with |renderThread|, and is synchronized
|
// |renderThreadHandler| is a handler for communicating with |renderThread|, and is synchronized
|
||||||
// on |handlerLock|.
|
// on |handlerLock|.
|
||||||
private final Object handlerLock = new Object();
|
private final Object handlerLock = new Object();
|
||||||
private Handler renderThreadHandler;
|
@Nullable private Handler renderThreadHandler;
|
||||||
|
|
||||||
private final ArrayList<FrameListenerAndParams> frameListeners = new ArrayList<>();
|
private final ArrayList<FrameListenerAndParams> frameListeners = new ArrayList<>();
|
||||||
|
|
||||||
@ -98,14 +99,14 @@ public class EglRenderer implements VideoRenderer.Callbacks, VideoSink {
|
|||||||
|
|
||||||
// EGL and GL resources for drawing YUV/OES textures. After initilization, these are only accessed
|
// EGL and GL resources for drawing YUV/OES textures. After initilization, these are only accessed
|
||||||
// from the render thread.
|
// from the render thread.
|
||||||
private EglBase eglBase;
|
@Nullable private EglBase eglBase;
|
||||||
private final VideoFrameDrawer frameDrawer = new VideoFrameDrawer();
|
private final VideoFrameDrawer frameDrawer = new VideoFrameDrawer();
|
||||||
private RendererCommon.GlDrawer drawer;
|
@Nullable private RendererCommon.GlDrawer drawer;
|
||||||
private final Matrix drawMatrix = new Matrix();
|
private final Matrix drawMatrix = new Matrix();
|
||||||
|
|
||||||
// Pending frame to render. Serves as a queue with size 1. Synchronized on |frameLock|.
|
// Pending frame to render. Serves as a queue with size 1. Synchronized on |frameLock|.
|
||||||
private final Object frameLock = new Object();
|
private final Object frameLock = new Object();
|
||||||
private VideoFrame pendingFrame;
|
@Nullable private VideoFrame pendingFrame;
|
||||||
|
|
||||||
// These variables are synchronized on |layoutLock|.
|
// These variables are synchronized on |layoutLock|.
|
||||||
private final Object layoutLock = new Object();
|
private final Object layoutLock = new Object();
|
||||||
@ -130,7 +131,7 @@ public class EglRenderer implements VideoRenderer.Callbacks, VideoSink {
|
|||||||
private long renderSwapBufferTimeNs;
|
private long renderSwapBufferTimeNs;
|
||||||
|
|
||||||
// Used for bitmap capturing.
|
// Used for bitmap capturing.
|
||||||
private GlTextureFrameBuffer bitmapTextureFramebuffer;
|
@Nullable private GlTextureFrameBuffer bitmapTextureFramebuffer;
|
||||||
|
|
||||||
private final Runnable logStatisticsRunnable = new Runnable() {
|
private final Runnable logStatisticsRunnable = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@ -162,7 +163,7 @@ public class EglRenderer implements VideoRenderer.Callbacks, VideoSink {
|
|||||||
* |drawer|. It is allowed to call init() to reinitialize the renderer after a previous
|
* |drawer|. It is allowed to call init() to reinitialize the renderer after a previous
|
||||||
* init()/release() cycle.
|
* init()/release() cycle.
|
||||||
*/
|
*/
|
||||||
public void init(final EglBase.Context sharedContext, final int[] configAttributes,
|
public void init(@Nullable final EglBase.Context sharedContext, final int[] configAttributes,
|
||||||
RendererCommon.GlDrawer drawer) {
|
RendererCommon.GlDrawer drawer) {
|
||||||
synchronized (handlerLock) {
|
synchronized (handlerLock) {
|
||||||
if (renderThreadHandler != null) {
|
if (renderThreadHandler != null) {
|
||||||
@ -385,7 +386,7 @@ public class EglRenderer implements VideoRenderer.Callbacks, VideoSink {
|
|||||||
* FPS reduction.
|
* FPS reduction.
|
||||||
*/
|
*/
|
||||||
public void addFrameListener(final FrameListener listener, final float scale,
|
public void addFrameListener(final FrameListener listener, final float scale,
|
||||||
final RendererCommon.GlDrawer drawerParam, final boolean applyFpsReduction) {
|
@Nullable final RendererCommon.GlDrawer drawerParam, final boolean applyFpsReduction) {
|
||||||
postToRenderThread(() -> {
|
postToRenderThread(() -> {
|
||||||
final RendererCommon.GlDrawer listenerDrawer = drawerParam == null ? drawer : drawerParam;
|
final RendererCommon.GlDrawer listenerDrawer = drawerParam == null ? drawer : drawerParam;
|
||||||
frameListeners.add(
|
frameListeners.add(
|
||||||
|
@ -19,6 +19,7 @@ import android.media.MediaCodecInfo;
|
|||||||
import android.media.MediaCodecInfo.CodecCapabilities;
|
import android.media.MediaCodecInfo.CodecCapabilities;
|
||||||
import android.media.MediaCodecList;
|
import android.media.MediaCodecList;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/** Factory for Android hardware VideoDecoders. */
|
/** Factory for Android hardware VideoDecoders. */
|
||||||
@SuppressWarnings("deprecation") // API level 16 requires use of deprecated methods.
|
@SuppressWarnings("deprecation") // API level 16 requires use of deprecated methods.
|
||||||
@ -47,6 +48,7 @@ public class HardwareVideoDecoderFactory implements VideoDecoderFactory {
|
|||||||
this.fallbackToSoftware = fallbackToSoftware;
|
this.fallbackToSoftware = fallbackToSoftware;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public VideoDecoder createDecoder(String codecType) {
|
public VideoDecoder createDecoder(String codecType) {
|
||||||
VideoCodecType type = VideoCodecType.valueOf(codecType);
|
VideoCodecType type = VideoCodecType.valueOf(codecType);
|
||||||
@ -70,7 +72,7 @@ public class HardwareVideoDecoderFactory implements VideoDecoderFactory {
|
|||||||
sharedContext);
|
sharedContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MediaCodecInfo findCodecForType(VideoCodecType type) {
|
private @Nullable MediaCodecInfo findCodecForType(VideoCodecType type) {
|
||||||
// HW decoding is not supported on builds before KITKAT.
|
// HW decoding is not supported on builds before KITKAT.
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -22,6 +22,7 @@ import java.util.Arrays;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/** Factory for android hardware video encoders. */
|
/** Factory for android hardware video encoders. */
|
||||||
@SuppressWarnings("deprecation") // API 16 requires the use of deprecated methods.
|
@SuppressWarnings("deprecation") // API 16 requires the use of deprecated methods.
|
||||||
@ -40,7 +41,7 @@ public class HardwareVideoEncoderFactory implements VideoEncoderFactory {
|
|||||||
private static final List<String> H264_HW_EXCEPTION_MODELS =
|
private static final List<String> H264_HW_EXCEPTION_MODELS =
|
||||||
Arrays.asList("SAMSUNG-SGH-I337", "Nexus 7", "Nexus 4");
|
Arrays.asList("SAMSUNG-SGH-I337", "Nexus 7", "Nexus 4");
|
||||||
|
|
||||||
private final EglBase14.Context sharedContext;
|
@Nullable private final EglBase14.Context sharedContext;
|
||||||
private final boolean enableIntelVp8Encoder;
|
private final boolean enableIntelVp8Encoder;
|
||||||
private final boolean enableH264HighProfile;
|
private final boolean enableH264HighProfile;
|
||||||
private final boolean fallbackToSoftware;
|
private final boolean fallbackToSoftware;
|
||||||
@ -70,6 +71,7 @@ public class HardwareVideoEncoderFactory implements VideoEncoderFactory {
|
|||||||
this(null, enableIntelVp8Encoder, enableH264HighProfile);
|
this(null, enableIntelVp8Encoder, enableH264HighProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public VideoEncoder createEncoder(VideoCodecInfo input) {
|
public VideoEncoder createEncoder(VideoCodecInfo input) {
|
||||||
VideoCodecType type = VideoCodecType.valueOf(input.name);
|
VideoCodecType type = VideoCodecType.valueOf(input.name);
|
||||||
@ -141,7 +143,7 @@ public class HardwareVideoEncoderFactory implements VideoEncoderFactory {
|
|||||||
return supportedCodecInfos.toArray(new VideoCodecInfo[supportedCodecInfos.size()]);
|
return supportedCodecInfos.toArray(new VideoCodecInfo[supportedCodecInfos.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MediaCodecInfo findCodecForType(VideoCodecType type) {
|
private @Nullable MediaCodecInfo findCodecForType(VideoCodecType type) {
|
||||||
for (int i = 0; i < MediaCodecList.getCodecCount(); ++i) {
|
for (int i = 0; i < MediaCodecList.getCodecCount(); ++i) {
|
||||||
MediaCodecInfo info = null;
|
MediaCodecInfo info = null;
|
||||||
try {
|
try {
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
package org.webrtc;
|
package org.webrtc;
|
||||||
|
|
||||||
|
import android.graphics.SurfaceTexture;
|
||||||
import android.media.MediaCodec;
|
import android.media.MediaCodec;
|
||||||
import android.media.MediaCodecInfo;
|
import android.media.MediaCodecInfo;
|
||||||
import android.media.MediaCodecInfo.CodecCapabilities;
|
import android.media.MediaCodecInfo.CodecCapabilities;
|
||||||
@ -28,6 +29,7 @@ import java.util.Queue;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
// Java-side of peerconnection.cc:MediaCodecVideoDecoder.
|
// Java-side of peerconnection.cc:MediaCodecVideoDecoder.
|
||||||
// This class is an implementation detail of the Java PeerConnection API.
|
// This class is an implementation detail of the Java PeerConnection API.
|
||||||
@ -69,14 +71,14 @@ public class MediaCodecVideoDecoder {
|
|||||||
private static final int MAX_QUEUED_OUTPUTBUFFERS = 3;
|
private static final int MAX_QUEUED_OUTPUTBUFFERS = 3;
|
||||||
// Active running decoder instance. Set in initDecode() (called from native code)
|
// Active running decoder instance. Set in initDecode() (called from native code)
|
||||||
// and reset to null in release() call.
|
// and reset to null in release() call.
|
||||||
private static MediaCodecVideoDecoder runningInstance = null;
|
@Nullable private static MediaCodecVideoDecoder runningInstance = null;
|
||||||
private static MediaCodecVideoDecoderErrorCallback errorCallback = null;
|
@Nullable private static MediaCodecVideoDecoderErrorCallback errorCallback = null;
|
||||||
private static int codecErrors = 0;
|
private static int codecErrors = 0;
|
||||||
// List of disabled codec types - can be set from application.
|
// List of disabled codec types - can be set from application.
|
||||||
private static Set<String> hwDecoderDisabledTypes = new HashSet<String>();
|
private static Set<String> hwDecoderDisabledTypes = new HashSet<String>();
|
||||||
|
|
||||||
private Thread mediaCodecThread;
|
@Nullable private Thread mediaCodecThread;
|
||||||
private MediaCodec mediaCodec;
|
@Nullable private MediaCodec mediaCodec;
|
||||||
private ByteBuffer[] inputBuffers;
|
private ByteBuffer[] inputBuffers;
|
||||||
private ByteBuffer[] outputBuffers;
|
private ByteBuffer[] outputBuffers;
|
||||||
private static final String VP8_MIME_TYPE = "video/x-vnd.on2.vp8";
|
private static final String VP8_MIME_TYPE = "video/x-vnd.on2.vp8";
|
||||||
@ -139,9 +141,9 @@ public class MediaCodecVideoDecoder {
|
|||||||
private boolean useSurface;
|
private boolean useSurface;
|
||||||
|
|
||||||
// The below variables are only used when decoding to a Surface.
|
// The below variables are only used when decoding to a Surface.
|
||||||
private TextureListener textureListener;
|
@Nullable private TextureListener textureListener;
|
||||||
private int droppedFrames;
|
private int droppedFrames;
|
||||||
private Surface surface = null;
|
@Nullable private Surface surface = null;
|
||||||
private final Queue<DecodedOutputBuffer> dequeuedSurfaceOutputBuffers =
|
private final Queue<DecodedOutputBuffer> dequeuedSurfaceOutputBuffers =
|
||||||
new ArrayDeque<DecodedOutputBuffer>();
|
new ArrayDeque<DecodedOutputBuffer>();
|
||||||
|
|
||||||
@ -242,7 +244,8 @@ public class MediaCodecVideoDecoder {
|
|||||||
public final int colorFormat; // Color format supported by codec.
|
public final int colorFormat; // Color format supported by codec.
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DecoderProperties findDecoder(String mime, String[] supportedCodecPrefixes) {
|
private static @Nullable DecoderProperties findDecoder(
|
||||||
|
String mime, String[] supportedCodecPrefixes) {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||||
return null; // MediaCodec.setParameters is missing.
|
return null; // MediaCodec.setParameters is missing.
|
||||||
}
|
}
|
||||||
@ -319,8 +322,8 @@ public class MediaCodecVideoDecoder {
|
|||||||
|
|
||||||
// Pass null in |surfaceTextureHelper| to configure the codec for ByteBuffer output.
|
// Pass null in |surfaceTextureHelper| to configure the codec for ByteBuffer output.
|
||||||
@CalledByNativeUnchecked
|
@CalledByNativeUnchecked
|
||||||
private boolean initDecode(
|
private boolean initDecode(VideoCodecType type, int width, int height,
|
||||||
VideoCodecType type, int width, int height, SurfaceTextureHelper surfaceTextureHelper) {
|
@Nullable SurfaceTextureHelper surfaceTextureHelper) {
|
||||||
if (mediaCodecThread != null) {
|
if (mediaCodecThread != null) {
|
||||||
throw new RuntimeException("initDecode: Forgot to release()?");
|
throw new RuntimeException("initDecode: Forgot to release()?");
|
||||||
}
|
}
|
||||||
@ -356,7 +359,7 @@ public class MediaCodecVideoDecoder {
|
|||||||
stride = width;
|
stride = width;
|
||||||
sliceHeight = height;
|
sliceHeight = height;
|
||||||
|
|
||||||
if (useSurface) {
|
if (useSurface && surfaceTextureHelper != null) {
|
||||||
textureListener = new TextureListener(surfaceTextureHelper);
|
textureListener = new TextureListener(surfaceTextureHelper);
|
||||||
surface = new Surface(surfaceTextureHelper.getSurfaceTexture());
|
surface = new Surface(surfaceTextureHelper.getSurfaceTexture());
|
||||||
}
|
}
|
||||||
@ -638,8 +641,8 @@ public class MediaCodecVideoDecoder {
|
|||||||
private final Object newFrameLock = new Object();
|
private final Object newFrameLock = new Object();
|
||||||
// |bufferToRender| is non-null when waiting for transition between addBufferToRender() to
|
// |bufferToRender| is non-null when waiting for transition between addBufferToRender() to
|
||||||
// onTextureFrameAvailable().
|
// onTextureFrameAvailable().
|
||||||
private DecodedOutputBuffer bufferToRender;
|
@Nullable private DecodedOutputBuffer bufferToRender;
|
||||||
private DecodedTextureBuffer renderedBuffer;
|
@Nullable private DecodedTextureBuffer renderedBuffer;
|
||||||
|
|
||||||
public TextureListener(SurfaceTextureHelper surfaceTextureHelper) {
|
public TextureListener(SurfaceTextureHelper surfaceTextureHelper) {
|
||||||
this.surfaceTextureHelper = surfaceTextureHelper;
|
this.surfaceTextureHelper = surfaceTextureHelper;
|
||||||
@ -681,6 +684,7 @@ public class MediaCodecVideoDecoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Dequeues and returns a DecodedTextureBuffer if available, or null otherwise.
|
// Dequeues and returns a DecodedTextureBuffer if available, or null otherwise.
|
||||||
|
@Nullable
|
||||||
@SuppressWarnings("WaitNotInLoop")
|
@SuppressWarnings("WaitNotInLoop")
|
||||||
public DecodedTextureBuffer dequeueTextureBuffer(int timeoutMs) {
|
public DecodedTextureBuffer dequeueTextureBuffer(int timeoutMs) {
|
||||||
synchronized (newFrameLock) {
|
synchronized (newFrameLock) {
|
||||||
@ -717,7 +721,7 @@ public class MediaCodecVideoDecoder {
|
|||||||
// unsupported format, or if |mediaCodec| is not in the Executing state. Throws CodecException
|
// unsupported format, or if |mediaCodec| is not in the Executing state. Throws CodecException
|
||||||
// upon codec error.
|
// upon codec error.
|
||||||
@CalledByNativeUnchecked
|
@CalledByNativeUnchecked
|
||||||
private DecodedOutputBuffer dequeueOutputBuffer(int dequeueTimeoutMs) {
|
private @Nullable DecodedOutputBuffer dequeueOutputBuffer(int dequeueTimeoutMs) {
|
||||||
checkOnMediaCodecThread();
|
checkOnMediaCodecThread();
|
||||||
if (decodeStartTimeMs.isEmpty()) {
|
if (decodeStartTimeMs.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
@ -801,7 +805,7 @@ public class MediaCodecVideoDecoder {
|
|||||||
// upon codec error. If |dequeueTimeoutMs| > 0, the oldest decoded frame will be dropped if
|
// upon codec error. If |dequeueTimeoutMs| > 0, the oldest decoded frame will be dropped if
|
||||||
// a frame can't be returned.
|
// a frame can't be returned.
|
||||||
@CalledByNativeUnchecked
|
@CalledByNativeUnchecked
|
||||||
private DecodedTextureBuffer dequeueTextureBuffer(int dequeueTimeoutMs) {
|
private @Nullable DecodedTextureBuffer dequeueTextureBuffer(int dequeueTimeoutMs) {
|
||||||
checkOnMediaCodecThread();
|
checkOnMediaCodecThread();
|
||||||
if (!useSurface) {
|
if (!useSurface) {
|
||||||
throw new IllegalStateException("dequeueTexture() called for byte buffer decoding.");
|
throw new IllegalStateException("dequeueTexture() called for byte buffer decoding.");
|
||||||
|
@ -29,6 +29,7 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import org.webrtc.EglBase14;
|
import org.webrtc.EglBase14;
|
||||||
import org.webrtc.VideoFrame;
|
import org.webrtc.VideoFrame;
|
||||||
|
|
||||||
@ -73,21 +74,21 @@ public class MediaCodecVideoEncoder {
|
|||||||
|
|
||||||
// Active running encoder instance. Set in initEncode() (called from native code)
|
// Active running encoder instance. Set in initEncode() (called from native code)
|
||||||
// and reset to null in release() call.
|
// and reset to null in release() call.
|
||||||
private static MediaCodecVideoEncoder runningInstance = null;
|
@Nullable private static MediaCodecVideoEncoder runningInstance = null;
|
||||||
private static MediaCodecVideoEncoderErrorCallback errorCallback = null;
|
@Nullable private static MediaCodecVideoEncoderErrorCallback errorCallback = null;
|
||||||
private static int codecErrors = 0;
|
private static int codecErrors = 0;
|
||||||
// List of disabled codec types - can be set from application.
|
// List of disabled codec types - can be set from application.
|
||||||
private static Set<String> hwEncoderDisabledTypes = new HashSet<String>();
|
private static Set<String> hwEncoderDisabledTypes = new HashSet<String>();
|
||||||
|
|
||||||
private Thread mediaCodecThread;
|
@Nullable private Thread mediaCodecThread;
|
||||||
private MediaCodec mediaCodec;
|
@Nullable private MediaCodec mediaCodec;
|
||||||
private ByteBuffer[] outputBuffers;
|
private ByteBuffer[] outputBuffers;
|
||||||
private EglBase14 eglBase;
|
@Nullable private EglBase14 eglBase;
|
||||||
private int profile;
|
private int profile;
|
||||||
private int width;
|
private int width;
|
||||||
private int height;
|
private int height;
|
||||||
private Surface inputSurface;
|
@Nullable private Surface inputSurface;
|
||||||
private GlRectDrawer drawer;
|
@Nullable private GlRectDrawer drawer;
|
||||||
|
|
||||||
private static final String VP8_MIME_TYPE = "video/x-vnd.on2.vp8";
|
private static final String VP8_MIME_TYPE = "video/x-vnd.on2.vp8";
|
||||||
private static final String VP9_MIME_TYPE = "video/x-vnd.on2.vp9";
|
private static final String VP9_MIME_TYPE = "video/x-vnd.on2.vp9";
|
||||||
@ -231,7 +232,7 @@ public class MediaCodecVideoEncoder {
|
|||||||
private long lastKeyFrameMs;
|
private long lastKeyFrameMs;
|
||||||
|
|
||||||
// SPS and PPS NALs (Config frame) for H.264.
|
// SPS and PPS NALs (Config frame) for H.264.
|
||||||
private ByteBuffer configData = null;
|
@Nullable private ByteBuffer configData = null;
|
||||||
|
|
||||||
// MediaCodec error handler - invoked when critical error happens which may prevent
|
// MediaCodec error handler - invoked when critical error happens which may prevent
|
||||||
// further use of media codec API. Now it means that one of media codec instances
|
// further use of media codec API. Now it means that one of media codec instances
|
||||||
@ -269,7 +270,7 @@ public class MediaCodecVideoEncoder {
|
|||||||
&& (findHwEncoder(VP8_MIME_TYPE, vp8HwList(), supportedColorList) != null);
|
&& (findHwEncoder(VP8_MIME_TYPE, vp8HwList(), supportedColorList) != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EncoderProperties vp8HwEncoderProperties() {
|
public static @Nullable EncoderProperties vp8HwEncoderProperties() {
|
||||||
if (hwEncoderDisabledTypes.contains(VP8_MIME_TYPE)) {
|
if (hwEncoderDisabledTypes.contains(VP8_MIME_TYPE)) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
@ -322,7 +323,7 @@ public class MediaCodecVideoEncoder {
|
|||||||
public final BitrateAdjustmentType bitrateAdjustmentType; // Bitrate adjustment type
|
public final BitrateAdjustmentType bitrateAdjustmentType; // Bitrate adjustment type
|
||||||
}
|
}
|
||||||
|
|
||||||
private static EncoderProperties findHwEncoder(
|
private static @Nullable EncoderProperties findHwEncoder(
|
||||||
String mime, MediaCodecProperties[] supportedHwCodecProperties, int[] colorList) {
|
String mime, MediaCodecProperties[] supportedHwCodecProperties, int[] colorList) {
|
||||||
// MediaCodec.setParameters is missing for JB and below, so bitrate
|
// MediaCodec.setParameters is missing for JB and below, so bitrate
|
||||||
// can not be adjusted dynamically.
|
// can not be adjusted dynamically.
|
||||||
@ -433,7 +434,7 @@ public class MediaCodecVideoEncoder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static MediaCodec createByCodecName(String codecName) {
|
static @Nullable MediaCodec createByCodecName(String codecName) {
|
||||||
try {
|
try {
|
||||||
// In the L-SDK this call can throw IOException so in order to work in
|
// In the L-SDK this call can throw IOException so in order to work in
|
||||||
// both cases catch an exception.
|
// both cases catch an exception.
|
||||||
@ -445,7 +446,7 @@ public class MediaCodecVideoEncoder {
|
|||||||
|
|
||||||
@CalledByNativeUnchecked
|
@CalledByNativeUnchecked
|
||||||
boolean initEncode(VideoCodecType type, int profile, int width, int height, int kbps, int fps,
|
boolean initEncode(VideoCodecType type, int profile, int width, int height, int kbps, int fps,
|
||||||
EglBase14.Context sharedContext) {
|
@Nullable EglBase14.Context sharedContext) {
|
||||||
final boolean useSurface = sharedContext != null;
|
final boolean useSurface = sharedContext != null;
|
||||||
Logging.d(TAG,
|
Logging.d(TAG,
|
||||||
"Java initEncode: " + type + ". Profile: " + profile + " : " + width + " x " + height
|
"Java initEncode: " + type + ". Profile: " + profile + " : " + width + " x " + height
|
||||||
@ -857,6 +858,7 @@ public class MediaCodecVideoEncoder {
|
|||||||
|
|
||||||
// Dequeue and return an output buffer, or null if no output is ready. Return
|
// Dequeue and return an output buffer, or null if no output is ready. Return
|
||||||
// a fake OutputBufferInfo with index -1 if the codec is no longer operable.
|
// a fake OutputBufferInfo with index -1 if the codec is no longer operable.
|
||||||
|
@Nullable
|
||||||
@CalledByNativeUnchecked
|
@CalledByNativeUnchecked
|
||||||
OutputBufferInfo dequeueOutputBuffer() {
|
OutputBufferInfo dequeueOutputBuffer() {
|
||||||
checkOnMediaCodecThread();
|
checkOnMediaCodecThread();
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
package org.webrtc;
|
package org.webrtc;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -44,7 +45,7 @@ public class MediaConstraints {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(@Nullable Object other) {
|
||||||
if (this == other) {
|
if (this == other) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
package org.webrtc;
|
package org.webrtc;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/** Java wrapper for a C++ MediaStreamTrackInterface. */
|
/** Java wrapper for a C++ MediaStreamTrackInterface. */
|
||||||
@JNINamespace("webrtc::jni")
|
@JNINamespace("webrtc::jni")
|
||||||
public class MediaStreamTrack {
|
public class MediaStreamTrack {
|
||||||
@ -55,7 +57,7 @@ public class MediaStreamTrack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Factory method to create an AudioTrack or VideoTrack subclass. */
|
/** Factory method to create an AudioTrack or VideoTrack subclass. */
|
||||||
static MediaStreamTrack createMediaStreamTrack(long nativeTrack) {
|
static @Nullable MediaStreamTrack createMediaStreamTrack(long nativeTrack) {
|
||||||
if (nativeTrack == 0) {
|
if (nativeTrack == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import static org.webrtc.NetworkMonitorAutoDetect.INVALID_NET_ID;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.webrtc.NetworkMonitorAutoDetect.ConnectionType;
|
import org.webrtc.NetworkMonitorAutoDetect.ConnectionType;
|
||||||
@ -50,7 +51,7 @@ public class NetworkMonitor {
|
|||||||
|
|
||||||
private final Object autoDetectLock = new Object();
|
private final Object autoDetectLock = new Object();
|
||||||
// Object that detects the connection type changes and brings up mobile networks.
|
// Object that detects the connection type changes and brings up mobile networks.
|
||||||
private NetworkMonitorAutoDetect autoDetect;
|
@Nullable private NetworkMonitorAutoDetect autoDetect;
|
||||||
// Also guarded by autoDetectLock.
|
// Also guarded by autoDetectLock.
|
||||||
private int numObservers;
|
private int numObservers;
|
||||||
|
|
||||||
@ -107,7 +108,7 @@ public class NetworkMonitor {
|
|||||||
* CHANGE_NETWORK_STATE permission.
|
* CHANGE_NETWORK_STATE permission.
|
||||||
*/
|
*/
|
||||||
@CalledByNative
|
@CalledByNative
|
||||||
private void startMonitoring(Context applicationContext, long nativeObserver) {
|
private void startMonitoring(@Nullable Context applicationContext, long nativeObserver) {
|
||||||
Logging.d(TAG, "Start monitoring with native observer " + nativeObserver);
|
Logging.d(TAG, "Start monitoring with native observer " + nativeObserver);
|
||||||
|
|
||||||
startMonitoring(
|
startMonitoring(
|
||||||
@ -291,6 +292,7 @@ public class NetworkMonitor {
|
|||||||
long nativePtr, NetworkInformation[] networkInfos);
|
long nativePtr, NetworkInformation[] networkInfos);
|
||||||
|
|
||||||
// For testing only.
|
// For testing only.
|
||||||
|
@Nullable
|
||||||
NetworkMonitorAutoDetect getNetworkMonitorAutoDetect() {
|
NetworkMonitorAutoDetect getNetworkMonitorAutoDetect() {
|
||||||
synchronized (autoDetectLock) {
|
synchronized (autoDetectLock) {
|
||||||
return autoDetect;
|
return autoDetect;
|
||||||
|
@ -35,6 +35,7 @@ import java.net.SocketException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Borrowed from Chromium's
|
* Borrowed from Chromium's
|
||||||
@ -188,7 +189,7 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
|
|||||||
* Note: In some rare Android systems connectivityManager is null. We handle that
|
* Note: In some rare Android systems connectivityManager is null. We handle that
|
||||||
* gracefully below.
|
* gracefully below.
|
||||||
*/
|
*/
|
||||||
private final ConnectivityManager connectivityManager;
|
@Nullable private final ConnectivityManager connectivityManager;
|
||||||
|
|
||||||
ConnectivityManagerDelegate(Context context) {
|
ConnectivityManagerDelegate(Context context) {
|
||||||
connectivityManager =
|
connectivityManager =
|
||||||
@ -227,7 +228,7 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
|
|||||||
/**
|
/**
|
||||||
* Returns connection type and status information gleaned from networkInfo.
|
* Returns connection type and status information gleaned from networkInfo.
|
||||||
*/
|
*/
|
||||||
NetworkState getNetworkState(NetworkInfo networkInfo) {
|
NetworkState getNetworkState(@Nullable NetworkInfo networkInfo) {
|
||||||
if (networkInfo == null || !networkInfo.isConnected()) {
|
if (networkInfo == null || !networkInfo.isConnected()) {
|
||||||
return new NetworkState(false, -1, -1);
|
return new NetworkState(false, -1, -1);
|
||||||
}
|
}
|
||||||
@ -246,6 +247,7 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
|
|||||||
return connectivityManager.getAllNetworks();
|
return connectivityManager.getAllNetworks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
List<NetworkInformation> getActiveNetworkList() {
|
List<NetworkInformation> getActiveNetworkList() {
|
||||||
if (!supportNetworkCallback()) {
|
if (!supportNetworkCallback()) {
|
||||||
return null;
|
return null;
|
||||||
@ -304,7 +306,7 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
private NetworkInformation networkToInfo(Network network) {
|
private @Nullable NetworkInformation networkToInfo(Network network) {
|
||||||
if (connectivityManager == null) {
|
if (connectivityManager == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -408,7 +410,7 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
|
|||||||
|
|
||||||
/** Queries the WifiManager for SSID of the current Wifi connection. */
|
/** Queries the WifiManager for SSID of the current Wifi connection. */
|
||||||
static class WifiManagerDelegate {
|
static class WifiManagerDelegate {
|
||||||
private final Context context;
|
@Nullable private final Context context;
|
||||||
WifiManagerDelegate(Context context) {
|
WifiManagerDelegate(Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
@ -444,7 +446,7 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
|
|||||||
private final Observer observer;
|
private final Observer observer;
|
||||||
// Network information about a WifiP2p (aka WiFi-Direct) network, or null if no such network is
|
// Network information about a WifiP2p (aka WiFi-Direct) network, or null if no such network is
|
||||||
// connected.
|
// connected.
|
||||||
private NetworkInformation wifiP2pNetworkInfo = null;
|
@Nullable private NetworkInformation wifiP2pNetworkInfo = null;
|
||||||
|
|
||||||
WifiDirectManagerDelegate(Observer observer, Context context) {
|
WifiDirectManagerDelegate(Observer observer, Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
@ -482,7 +484,7 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Handle a change notification about the wifi p2p group. */
|
/** Handle a change notification about the wifi p2p group. */
|
||||||
private void onWifiP2pGroupChange(WifiP2pGroup wifiP2pGroup) {
|
private void onWifiP2pGroupChange(@Nullable WifiP2pGroup wifiP2pGroup) {
|
||||||
if (wifiP2pGroup == null || wifiP2pGroup.getInterface() == null) {
|
if (wifiP2pGroup == null || wifiP2pGroup.getInterface() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -528,9 +530,9 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
|
|||||||
private final Context context;
|
private final Context context;
|
||||||
// Used to request mobile network. It does not do anything except for keeping
|
// Used to request mobile network. It does not do anything except for keeping
|
||||||
// the callback for releasing the request.
|
// the callback for releasing the request.
|
||||||
private final NetworkCallback mobileNetworkCallback;
|
@Nullable private final NetworkCallback mobileNetworkCallback;
|
||||||
// Used to receive updates on all networks.
|
// Used to receive updates on all networks.
|
||||||
private final NetworkCallback allNetworkCallback;
|
@Nullable private final NetworkCallback allNetworkCallback;
|
||||||
// connectivityManagerDelegate and wifiManagerDelegate are only non-final for testing.
|
// connectivityManagerDelegate and wifiManagerDelegate are only non-final for testing.
|
||||||
private ConnectivityManagerDelegate connectivityManagerDelegate;
|
private ConnectivityManagerDelegate connectivityManagerDelegate;
|
||||||
private WifiManagerDelegate wifiManagerDelegate;
|
private WifiManagerDelegate wifiManagerDelegate;
|
||||||
@ -617,6 +619,7 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
|
|||||||
return isRegistered;
|
return isRegistered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
List<NetworkInformation> getActiveNetworkList() {
|
List<NetworkInformation> getActiveNetworkList() {
|
||||||
List<NetworkInformation> connectivityManagerList =
|
List<NetworkInformation> connectivityManagerList =
|
||||||
connectivityManagerDelegate.getActiveNetworkList();
|
connectivityManagerDelegate.getActiveNetworkList();
|
||||||
|
@ -13,6 +13,7 @@ package org.webrtc;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Java-land version of the PeerConnection APIs; wraps the C++ API
|
* Java-land version of the PeerConnection APIs; wraps the C++ API
|
||||||
@ -202,7 +203,7 @@ public class PeerConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
private final List<String> urls;
|
@Nullable private final List<String> urls;
|
||||||
private String username = "";
|
private String username = "";
|
||||||
private String password = "";
|
private String password = "";
|
||||||
private TlsCertPolicy tlsCertPolicy = TlsCertPolicy.TLS_CERT_POLICY_SECURE;
|
private TlsCertPolicy tlsCertPolicy = TlsCertPolicy.TLS_CERT_POLICY_SECURE;
|
||||||
@ -253,16 +254,19 @@ public class PeerConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@CalledByNative("IceServer")
|
@CalledByNative("IceServer")
|
||||||
List<String> getUrls() {
|
List<String> getUrls() {
|
||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@CalledByNative("IceServer")
|
@CalledByNative("IceServer")
|
||||||
String getUsername() {
|
String getUsername() {
|
||||||
return username;
|
return username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@CalledByNative("IceServer")
|
@CalledByNative("IceServer")
|
||||||
String getPassword() {
|
String getPassword() {
|
||||||
return password;
|
return password;
|
||||||
@ -273,6 +277,7 @@ public class PeerConnection {
|
|||||||
return tlsCertPolicy;
|
return tlsCertPolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@CalledByNative("IceServer")
|
@CalledByNative("IceServer")
|
||||||
String getHostname() {
|
String getHostname() {
|
||||||
return hostname;
|
return hostname;
|
||||||
@ -406,19 +411,19 @@ public class PeerConnection {
|
|||||||
// 3) iceCheckMinInterval defines the minimal interval (equivalently the
|
// 3) iceCheckMinInterval defines the minimal interval (equivalently the
|
||||||
// maximum rate) that overrides the above two intervals when either of them
|
// maximum rate) that overrides the above two intervals when either of them
|
||||||
// is less.
|
// is less.
|
||||||
public Integer iceCheckIntervalStrongConnectivityMs;
|
@Nullable public Integer iceCheckIntervalStrongConnectivityMs;
|
||||||
public Integer iceCheckIntervalWeakConnectivityMs;
|
@Nullable public Integer iceCheckIntervalWeakConnectivityMs;
|
||||||
public Integer iceCheckMinInterval;
|
@Nullable public Integer iceCheckMinInterval;
|
||||||
// The time period in milliseconds for which a candidate pair must wait for response to
|
// The time period in milliseconds for which a candidate pair must wait for response to
|
||||||
// connectivitiy checks before it becomes unwritable.
|
// connectivitiy checks before it becomes unwritable.
|
||||||
public Integer iceUnwritableTimeMs;
|
@Nullable public Integer iceUnwritableTimeMs;
|
||||||
// The minimum number of connectivity checks that a candidate pair must sent without receiving
|
// The minimum number of connectivity checks that a candidate pair must sent without receiving
|
||||||
// response before it becomes unwritable.
|
// response before it becomes unwritable.
|
||||||
public Integer iceUnwritableMinChecks;
|
@Nullable public Integer iceUnwritableMinChecks;
|
||||||
// The interval in milliseconds at which STUN candidates will resend STUN binding requests
|
// The interval in milliseconds at which STUN candidates will resend STUN binding requests
|
||||||
// to keep NAT bindings open.
|
// to keep NAT bindings open.
|
||||||
// The default value in the implementation is used if this field is null.
|
// The default value in the implementation is used if this field is null.
|
||||||
public Integer stunCandidateKeepaliveIntervalMs;
|
@Nullable public Integer stunCandidateKeepaliveIntervalMs;
|
||||||
public boolean disableIPv6OnWifi;
|
public boolean disableIPv6OnWifi;
|
||||||
// By default, PeerConnection will use a limited number of IPv6 network
|
// By default, PeerConnection will use a limited number of IPv6 network
|
||||||
// interfaces, in order to avoid too many ICE candidate pairs being created
|
// interfaces, in order to avoid too many ICE candidate pairs being created
|
||||||
@ -426,7 +431,7 @@ public class PeerConnection {
|
|||||||
//
|
//
|
||||||
// Can be set to Integer.MAX_VALUE to effectively disable the limit.
|
// Can be set to Integer.MAX_VALUE to effectively disable the limit.
|
||||||
public int maxIPv6Networks;
|
public int maxIPv6Networks;
|
||||||
public IntervalRange iceRegatherIntervalRange;
|
@Nullable public IntervalRange iceRegatherIntervalRange;
|
||||||
|
|
||||||
// These values will be overridden by MediaStream constraints if deprecated constraints-based
|
// These values will be overridden by MediaStream constraints if deprecated constraints-based
|
||||||
// create peerconnection interface is used.
|
// create peerconnection interface is used.
|
||||||
@ -435,16 +440,16 @@ public class PeerConnection {
|
|||||||
public boolean enableCpuOveruseDetection;
|
public boolean enableCpuOveruseDetection;
|
||||||
public boolean enableRtpDataChannel;
|
public boolean enableRtpDataChannel;
|
||||||
public boolean suspendBelowMinBitrate;
|
public boolean suspendBelowMinBitrate;
|
||||||
public Integer screencastMinBitrate;
|
@Nullable public Integer screencastMinBitrate;
|
||||||
public Boolean combinedAudioVideoBwe;
|
@Nullable public Boolean combinedAudioVideoBwe;
|
||||||
public Boolean enableDtlsSrtp;
|
@Nullable public Boolean enableDtlsSrtp;
|
||||||
// Use "Unknown" to represent no preference of adapter types, not the
|
// Use "Unknown" to represent no preference of adapter types, not the
|
||||||
// preference of adapters of unknown types.
|
// preference of adapters of unknown types.
|
||||||
public AdapterType networkPreference;
|
public AdapterType networkPreference;
|
||||||
public SdpSemantics sdpSemantics;
|
public SdpSemantics sdpSemantics;
|
||||||
|
|
||||||
// This is an optional wrapper for the C++ webrtc::TurnCustomizer.
|
// This is an optional wrapper for the C++ webrtc::TurnCustomizer.
|
||||||
public TurnCustomizer turnCustomizer;
|
@Nullable public TurnCustomizer turnCustomizer;
|
||||||
|
|
||||||
// TODO(deadbeef): Instead of duplicating the defaults here, we should do
|
// TODO(deadbeef): Instead of duplicating the defaults here, we should do
|
||||||
// something to pick up the defaults from C++. The Objective-C equivalent
|
// something to pick up the defaults from C++. The Objective-C equivalent
|
||||||
@ -561,31 +566,37 @@ public class PeerConnection {
|
|||||||
return presumeWritableWhenFullyRelayed;
|
return presumeWritableWhenFullyRelayed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@CalledByNative("RTCConfiguration")
|
@CalledByNative("RTCConfiguration")
|
||||||
Integer getIceCheckIntervalStrongConnectivity() {
|
Integer getIceCheckIntervalStrongConnectivity() {
|
||||||
return iceCheckIntervalStrongConnectivityMs;
|
return iceCheckIntervalStrongConnectivityMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@CalledByNative("RTCConfiguration")
|
@CalledByNative("RTCConfiguration")
|
||||||
Integer getIceCheckIntervalWeakConnectivity() {
|
Integer getIceCheckIntervalWeakConnectivity() {
|
||||||
return iceCheckIntervalWeakConnectivityMs;
|
return iceCheckIntervalWeakConnectivityMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@CalledByNative("RTCConfiguration")
|
@CalledByNative("RTCConfiguration")
|
||||||
Integer getIceCheckMinInterval() {
|
Integer getIceCheckMinInterval() {
|
||||||
return iceCheckMinInterval;
|
return iceCheckMinInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@CalledByNative("RTCConfiguration")
|
@CalledByNative("RTCConfiguration")
|
||||||
Integer getIceUnwritableTimeout() {
|
Integer getIceUnwritableTimeout() {
|
||||||
return iceUnwritableTimeMs;
|
return iceUnwritableTimeMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@CalledByNative("RTCConfiguration")
|
@CalledByNative("RTCConfiguration")
|
||||||
Integer getIceUnwritableMinChecks() {
|
Integer getIceUnwritableMinChecks() {
|
||||||
return iceUnwritableMinChecks;
|
return iceUnwritableMinChecks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@CalledByNative("RTCConfiguration")
|
@CalledByNative("RTCConfiguration")
|
||||||
Integer getStunCandidateKeepaliveInterval() {
|
Integer getStunCandidateKeepaliveInterval() {
|
||||||
return stunCandidateKeepaliveIntervalMs;
|
return stunCandidateKeepaliveIntervalMs;
|
||||||
@ -601,11 +612,13 @@ public class PeerConnection {
|
|||||||
return maxIPv6Networks;
|
return maxIPv6Networks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@CalledByNative("RTCConfiguration")
|
@CalledByNative("RTCConfiguration")
|
||||||
IntervalRange getIceRegatherIntervalRange() {
|
IntervalRange getIceRegatherIntervalRange() {
|
||||||
return iceRegatherIntervalRange;
|
return iceRegatherIntervalRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@CalledByNative("RTCConfiguration")
|
@CalledByNative("RTCConfiguration")
|
||||||
TurnCustomizer getTurnCustomizer() {
|
TurnCustomizer getTurnCustomizer() {
|
||||||
return turnCustomizer;
|
return turnCustomizer;
|
||||||
@ -636,16 +649,19 @@ public class PeerConnection {
|
|||||||
return suspendBelowMinBitrate;
|
return suspendBelowMinBitrate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@CalledByNative("RTCConfiguration")
|
@CalledByNative("RTCConfiguration")
|
||||||
Integer getScreencastMinBitrate() {
|
Integer getScreencastMinBitrate() {
|
||||||
return screencastMinBitrate;
|
return screencastMinBitrate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@CalledByNative("RTCConfiguration")
|
@CalledByNative("RTCConfiguration")
|
||||||
Boolean getCombinedAudioVideoBwe() {
|
Boolean getCombinedAudioVideoBwe() {
|
||||||
return combinedAudioVideoBwe;
|
return combinedAudioVideoBwe;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@CalledByNative("RTCConfiguration")
|
@CalledByNative("RTCConfiguration")
|
||||||
Boolean getEnableDtlsSrtp() {
|
Boolean getEnableDtlsSrtp() {
|
||||||
return enableDtlsSrtp;
|
return enableDtlsSrtp;
|
||||||
@ -923,7 +939,7 @@ public class PeerConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public RtpTransceiver addTransceiver(
|
public RtpTransceiver addTransceiver(
|
||||||
MediaStreamTrack track, RtpTransceiver.RtpTransceiverInit init) {
|
MediaStreamTrack track, @Nullable RtpTransceiver.RtpTransceiverInit init) {
|
||||||
if (track == null) {
|
if (track == null) {
|
||||||
throw new NullPointerException("No MediaStreamTrack specified for addTransceiver.");
|
throw new NullPointerException("No MediaStreamTrack specified for addTransceiver.");
|
||||||
}
|
}
|
||||||
@ -943,7 +959,7 @@ public class PeerConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public RtpTransceiver addTransceiver(
|
public RtpTransceiver addTransceiver(
|
||||||
MediaStreamTrack.MediaType mediaType, RtpTransceiver.RtpTransceiverInit init) {
|
MediaStreamTrack.MediaType mediaType, @Nullable RtpTransceiver.RtpTransceiverInit init) {
|
||||||
if (mediaType == null) {
|
if (mediaType == null) {
|
||||||
throw new NullPointerException("No MediaType specified for addTransceiver.");
|
throw new NullPointerException("No MediaType specified for addTransceiver.");
|
||||||
}
|
}
|
||||||
@ -960,7 +976,7 @@ public class PeerConnection {
|
|||||||
|
|
||||||
// Older, non-standard implementation of getStats.
|
// Older, non-standard implementation of getStats.
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean getStats(StatsObserver observer, MediaStreamTrack track) {
|
public boolean getStats(StatsObserver observer, @Nullable MediaStreamTrack track) {
|
||||||
return nativeOldGetStats(observer, (track == null) ? 0 : track.nativeTrack);
|
return nativeOldGetStats(observer, (track == null) ? 0 : track.nativeTrack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ package org.webrtc;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Java wrapper for a C++ PeerConnectionFactoryInterface. Main entry point to
|
* Java wrapper for a C++ PeerConnectionFactoryInterface. Main entry point to
|
||||||
@ -27,9 +28,9 @@ public class PeerConnectionFactory {
|
|||||||
|
|
||||||
private final long nativeFactory;
|
private final long nativeFactory;
|
||||||
private static volatile boolean internalTracerInitialized = false;
|
private static volatile boolean internalTracerInitialized = false;
|
||||||
private static Thread networkThread;
|
@Nullable private static Thread networkThread;
|
||||||
private static Thread workerThread;
|
@Nullable private static Thread workerThread;
|
||||||
private static Thread signalingThread;
|
@Nullable private static Thread signalingThread;
|
||||||
private EglBase localEglbase;
|
private EglBase localEglbase;
|
||||||
private EglBase remoteEglbase;
|
private EglBase remoteEglbase;
|
||||||
|
|
||||||
@ -124,11 +125,11 @@ public class PeerConnectionFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
private Options options;
|
private @Nullable Options options;
|
||||||
private VideoEncoderFactory encoderFactory;
|
private @Nullable VideoEncoderFactory encoderFactory;
|
||||||
private VideoDecoderFactory decoderFactory;
|
private @Nullable VideoDecoderFactory decoderFactory;
|
||||||
private AudioProcessingFactory audioProcessingFactory;
|
private @Nullable AudioProcessingFactory audioProcessingFactory;
|
||||||
private FecControllerFactoryFactoryInterface fecControllerFactoryFactory;
|
private @Nullable FecControllerFactoryFactoryInterface fecControllerFactoryFactory;
|
||||||
|
|
||||||
private Builder() {}
|
private Builder() {}
|
||||||
|
|
||||||
@ -262,9 +263,10 @@ public class PeerConnectionFactory {
|
|||||||
null /* fecControllerFactoryFactory */);
|
null /* fecControllerFactoryFactory */);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PeerConnectionFactory(Options options, VideoEncoderFactory encoderFactory,
|
private PeerConnectionFactory(Options options, @Nullable VideoEncoderFactory encoderFactory,
|
||||||
VideoDecoderFactory decoderFactory, AudioProcessingFactory audioProcessingFactory,
|
@Nullable VideoDecoderFactory decoderFactory,
|
||||||
FecControllerFactoryFactoryInterface fecControllerFactoryFactory) {
|
@Nullable AudioProcessingFactory audioProcessingFactory,
|
||||||
|
@Nullable FecControllerFactoryFactoryInterface fecControllerFactoryFactory) {
|
||||||
checkInitializeHasBeenCalled();
|
checkInitializeHasBeenCalled();
|
||||||
nativeFactory = nativeCreatePeerConnectionFactory(ContextUtils.getApplicationContext(), options,
|
nativeFactory = nativeCreatePeerConnectionFactory(ContextUtils.getApplicationContext(), options,
|
||||||
encoderFactory, decoderFactory,
|
encoderFactory, decoderFactory,
|
||||||
@ -279,6 +281,7 @@ public class PeerConnectionFactory {
|
|||||||
* Deprecated. PeerConnection constraints are deprecated. Supply values in rtcConfig struct
|
* Deprecated. PeerConnection constraints are deprecated. Supply values in rtcConfig struct
|
||||||
* instead and use the method without constraints in the signature.
|
* instead and use the method without constraints in the signature.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public PeerConnection createPeerConnection(PeerConnection.RTCConfiguration rtcConfig,
|
public PeerConnection createPeerConnection(PeerConnection.RTCConfiguration rtcConfig,
|
||||||
MediaConstraints constraints, PeerConnection.Observer observer) {
|
MediaConstraints constraints, PeerConnection.Observer observer) {
|
||||||
@ -298,6 +301,7 @@ public class PeerConnectionFactory {
|
|||||||
* Deprecated. PeerConnection constraints are deprecated. Supply values in rtcConfig struct
|
* Deprecated. PeerConnection constraints are deprecated. Supply values in rtcConfig struct
|
||||||
* instead and use the method without constraints in the signature.
|
* instead and use the method without constraints in the signature.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public PeerConnection createPeerConnection(List<PeerConnection.IceServer> iceServers,
|
public PeerConnection createPeerConnection(List<PeerConnection.IceServer> iceServers,
|
||||||
MediaConstraints constraints, PeerConnection.Observer observer) {
|
MediaConstraints constraints, PeerConnection.Observer observer) {
|
||||||
@ -305,12 +309,14 @@ public class PeerConnectionFactory {
|
|||||||
return createPeerConnection(rtcConfig, constraints, observer);
|
return createPeerConnection(rtcConfig, constraints, observer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public PeerConnection createPeerConnection(
|
public PeerConnection createPeerConnection(
|
||||||
List<PeerConnection.IceServer> iceServers, PeerConnection.Observer observer) {
|
List<PeerConnection.IceServer> iceServers, PeerConnection.Observer observer) {
|
||||||
PeerConnection.RTCConfiguration rtcConfig = new PeerConnection.RTCConfiguration(iceServers);
|
PeerConnection.RTCConfiguration rtcConfig = new PeerConnection.RTCConfiguration(iceServers);
|
||||||
return createPeerConnection(rtcConfig, observer);
|
return createPeerConnection(rtcConfig, observer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public PeerConnection createPeerConnection(
|
public PeerConnection createPeerConnection(
|
||||||
PeerConnection.RTCConfiguration rtcConfig, PeerConnection.Observer observer) {
|
PeerConnection.RTCConfiguration rtcConfig, PeerConnection.Observer observer) {
|
||||||
return createPeerConnection(rtcConfig, null /* constraints */, observer);
|
return createPeerConnection(rtcConfig, null /* constraints */, observer);
|
||||||
@ -411,7 +417,7 @@ public class PeerConnectionFactory {
|
|||||||
return nativeFactory;
|
return nativeFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void printStackTrace(Thread thread, String threadName) {
|
private static void printStackTrace(@Nullable Thread thread, String threadName) {
|
||||||
if (thread != null) {
|
if (thread != null) {
|
||||||
StackTraceElement[] stackTraces = thread.getStackTrace();
|
StackTraceElement[] stackTraces = thread.getStackTrace();
|
||||||
if (stackTraces.length > 0) {
|
if (stackTraces.length > 0) {
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
package org.webrtc;
|
package org.webrtc;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import org.webrtc.MediaStreamTrack;
|
import org.webrtc.MediaStreamTrack;
|
||||||
@ -31,7 +32,7 @@ public class RtpParameters {
|
|||||||
// If non-null, this represents the Transport Independent Application
|
// If non-null, this represents the Transport Independent Application
|
||||||
// Specific maximum bandwidth defined in RFC3890. If null, there is no
|
// Specific maximum bandwidth defined in RFC3890. If null, there is no
|
||||||
// maximum bitrate.
|
// maximum bitrate.
|
||||||
public Integer maxBitrateBps;
|
@Nullable public Integer maxBitrateBps;
|
||||||
// SSRC to be used by this encoding.
|
// SSRC to be used by this encoding.
|
||||||
// Can't be changed between getParameters/setParameters.
|
// Can't be changed between getParameters/setParameters.
|
||||||
public Long ssrc;
|
public Long ssrc;
|
||||||
@ -48,6 +49,7 @@ public class RtpParameters {
|
|||||||
return active;
|
return active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@CalledByNative("Encoding")
|
@CalledByNative("Encoding")
|
||||||
Integer getMaxBitrateBps() {
|
Integer getMaxBitrateBps() {
|
||||||
return maxBitrateBps;
|
return maxBitrateBps;
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
package org.webrtc;
|
package org.webrtc;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import org.webrtc.MediaStreamTrack;
|
import org.webrtc.MediaStreamTrack;
|
||||||
|
|
||||||
/** Java wrapper for a C++ RtpReceiverInterface. */
|
/** Java wrapper for a C++ RtpReceiverInterface. */
|
||||||
@ -25,7 +26,7 @@ public class RtpReceiver {
|
|||||||
final long nativeRtpReceiver;
|
final long nativeRtpReceiver;
|
||||||
private long nativeObserver;
|
private long nativeObserver;
|
||||||
|
|
||||||
private MediaStreamTrack cachedTrack;
|
@Nullable private MediaStreamTrack cachedTrack;
|
||||||
|
|
||||||
@CalledByNative
|
@CalledByNative
|
||||||
public RtpReceiver(long nativeRtpReceiver) {
|
public RtpReceiver(long nativeRtpReceiver) {
|
||||||
@ -34,11 +35,12 @@ public class RtpReceiver {
|
|||||||
cachedTrack = MediaStreamTrack.createMediaStreamTrack(nativeTrack);
|
cachedTrack = MediaStreamTrack.createMediaStreamTrack(nativeTrack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public MediaStreamTrack track() {
|
public MediaStreamTrack track() {
|
||||||
return cachedTrack;
|
return cachedTrack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setParameters(RtpParameters parameters) {
|
public boolean setParameters(@Nullable RtpParameters parameters) {
|
||||||
return parameters == null ? false : nativeSetParameters(nativeRtpReceiver, parameters);
|
return parameters == null ? false : nativeSetParameters(nativeRtpReceiver, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,15 +10,17 @@
|
|||||||
|
|
||||||
package org.webrtc;
|
package org.webrtc;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/** Java wrapper for a C++ RtpSenderInterface. */
|
/** Java wrapper for a C++ RtpSenderInterface. */
|
||||||
@JNINamespace("webrtc::jni")
|
@JNINamespace("webrtc::jni")
|
||||||
public class RtpSender {
|
public class RtpSender {
|
||||||
final long nativeRtpSender;
|
final long nativeRtpSender;
|
||||||
|
|
||||||
private MediaStreamTrack cachedTrack;
|
@Nullable private MediaStreamTrack cachedTrack;
|
||||||
private boolean ownsTrack = true;
|
private boolean ownsTrack = true;
|
||||||
|
|
||||||
private final DtmfSender dtmfSender;
|
private final @Nullable DtmfSender dtmfSender;
|
||||||
|
|
||||||
@CalledByNative
|
@CalledByNative
|
||||||
public RtpSender(long nativeRtpSender) {
|
public RtpSender(long nativeRtpSender) {
|
||||||
@ -44,7 +46,7 @@ public class RtpSender {
|
|||||||
* or a MediaStream.
|
* or a MediaStream.
|
||||||
* @return true on success and false on failure.
|
* @return true on success and false on failure.
|
||||||
*/
|
*/
|
||||||
public boolean setTrack(MediaStreamTrack track, boolean takeOwnership) {
|
public boolean setTrack(@Nullable MediaStreamTrack track, boolean takeOwnership) {
|
||||||
if (!nativeSetTrack(nativeRtpSender, (track == null) ? 0 : track.nativeTrack)) {
|
if (!nativeSetTrack(nativeRtpSender, (track == null) ? 0 : track.nativeTrack)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -56,6 +58,7 @@ public class RtpSender {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public MediaStreamTrack track() {
|
public MediaStreamTrack track() {
|
||||||
return cachedTrack;
|
return cachedTrack;
|
||||||
}
|
}
|
||||||
@ -72,6 +75,7 @@ public class RtpSender {
|
|||||||
return nativeGetId(nativeRtpSender);
|
return nativeGetId(nativeRtpSender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public DtmfSender dtmf() {
|
public DtmfSender dtmf() {
|
||||||
return dtmfSender;
|
return dtmfSender;
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import android.hardware.display.VirtualDisplay;
|
|||||||
import android.media.projection.MediaProjection;
|
import android.media.projection.MediaProjection;
|
||||||
import android.media.projection.MediaProjectionManager;
|
import android.media.projection.MediaProjectionManager;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An implementation of VideoCapturer to capture the screen content as a video stream.
|
* An implementation of VideoCapturer to capture the screen content as a video stream.
|
||||||
@ -44,13 +45,13 @@ public class ScreenCapturerAndroid
|
|||||||
|
|
||||||
private int width;
|
private int width;
|
||||||
private int height;
|
private int height;
|
||||||
private VirtualDisplay virtualDisplay;
|
@Nullable private VirtualDisplay virtualDisplay;
|
||||||
private SurfaceTextureHelper surfaceTextureHelper;
|
@Nullable private SurfaceTextureHelper surfaceTextureHelper;
|
||||||
private CapturerObserver capturerObserver;
|
@Nullable private CapturerObserver capturerObserver;
|
||||||
private long numCapturedFrames = 0;
|
private long numCapturedFrames = 0;
|
||||||
private MediaProjection mediaProjection;
|
@Nullable private MediaProjection mediaProjection;
|
||||||
private boolean isDisposed = false;
|
private boolean isDisposed = false;
|
||||||
private MediaProjectionManager mediaProjectionManager;
|
@Nullable private MediaProjectionManager mediaProjectionManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new Screen Capturer.
|
* Constructs a new Screen Capturer.
|
||||||
|
@ -10,7 +10,10 @@
|
|||||||
|
|
||||||
package org.webrtc;
|
package org.webrtc;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class SoftwareVideoDecoderFactory implements VideoDecoderFactory {
|
public class SoftwareVideoDecoderFactory implements VideoDecoderFactory {
|
||||||
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public VideoDecoder createDecoder(String codecType) {
|
public VideoDecoder createDecoder(String codecType) {
|
||||||
if (codecType.equalsIgnoreCase("VP8")) {
|
if (codecType.equalsIgnoreCase("VP8")) {
|
||||||
|
@ -10,11 +10,13 @@
|
|||||||
|
|
||||||
package org.webrtc;
|
package org.webrtc;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SoftwareVideoEncoderFactory implements VideoEncoderFactory {
|
public class SoftwareVideoEncoderFactory implements VideoEncoderFactory {
|
||||||
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public VideoEncoder createEncoder(VideoCodecInfo info) {
|
public VideoEncoder createEncoder(VideoCodecInfo info) {
|
||||||
if (info.name.equalsIgnoreCase("VP8")) {
|
if (info.name.equalsIgnoreCase("VP8")) {
|
||||||
|
@ -20,6 +20,7 @@ import android.os.Handler;
|
|||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import org.webrtc.EglBase;
|
import org.webrtc.EglBase;
|
||||||
import org.webrtc.VideoFrame.TextureBuffer;
|
import org.webrtc.VideoFrame.TextureBuffer;
|
||||||
|
|
||||||
@ -62,6 +63,7 @@ public class SurfaceTextureHelper {
|
|||||||
// Therefore, in order to control the callback thread on API lvl < 21, the SurfaceTextureHelper
|
// Therefore, in order to control the callback thread on API lvl < 21, the SurfaceTextureHelper
|
||||||
// is constructed on the |handler| thread.
|
// is constructed on the |handler| thread.
|
||||||
return ThreadUtils.invokeAtFrontUninterruptibly(handler, new Callable<SurfaceTextureHelper>() {
|
return ThreadUtils.invokeAtFrontUninterruptibly(handler, new Callable<SurfaceTextureHelper>() {
|
||||||
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public SurfaceTextureHelper call() {
|
public SurfaceTextureHelper call() {
|
||||||
try {
|
try {
|
||||||
@ -81,14 +83,14 @@ public class SurfaceTextureHelper {
|
|||||||
private YuvConverter yuvConverter;
|
private YuvConverter yuvConverter;
|
||||||
|
|
||||||
// These variables are only accessed from the |handler| thread.
|
// These variables are only accessed from the |handler| thread.
|
||||||
private OnTextureFrameAvailableListener listener;
|
@Nullable private OnTextureFrameAvailableListener listener;
|
||||||
// The possible states of this class.
|
// The possible states of this class.
|
||||||
private boolean hasPendingTexture = false;
|
private boolean hasPendingTexture = false;
|
||||||
private volatile boolean isTextureInUse = false;
|
private volatile boolean isTextureInUse = false;
|
||||||
private boolean isQuitting = false;
|
private boolean isQuitting = false;
|
||||||
// |pendingListener| is set in setListener() and the runnable is posted to the handler thread.
|
// |pendingListener| is set in setListener() and the runnable is posted to the handler thread.
|
||||||
// setListener() is not allowed to be called again before stopListening(), so this is thread safe.
|
// setListener() is not allowed to be called again before stopListening(), so this is thread safe.
|
||||||
private OnTextureFrameAvailableListener pendingListener;
|
@Nullable private OnTextureFrameAvailableListener pendingListener;
|
||||||
final Runnable setListenerRunnable = new Runnable() {
|
final Runnable setListenerRunnable = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
package org.webrtc;
|
package org.webrtc;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -50,7 +51,7 @@ public class VideoCodecInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
return false;
|
return false;
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
|
@ -10,11 +10,13 @@
|
|||||||
|
|
||||||
package org.webrtc;
|
package org.webrtc;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/** Factory for creating VideoDecoders. */
|
/** Factory for creating VideoDecoders. */
|
||||||
public interface VideoDecoderFactory {
|
public interface VideoDecoderFactory {
|
||||||
/**
|
/**
|
||||||
* Creates a VideoDecoder for the given codec. Supports the same codecs supported by
|
* Creates a VideoDecoder for the given codec. Supports the same codecs supported by
|
||||||
* VideoEncoderFactory.
|
* VideoEncoderFactory.
|
||||||
*/
|
*/
|
||||||
@CalledByNative VideoDecoder createDecoder(String codecType);
|
@Nullable @CalledByNative VideoDecoder createDecoder(String codecType);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
package org.webrtc;
|
package org.webrtc;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import org.webrtc.EncodedImage;
|
import org.webrtc.EncodedImage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,8 +94,8 @@ public interface VideoEncoder {
|
|||||||
/** Settings for WebRTC quality based scaling. */
|
/** Settings for WebRTC quality based scaling. */
|
||||||
public class ScalingSettings {
|
public class ScalingSettings {
|
||||||
public final boolean on;
|
public final boolean on;
|
||||||
public final Integer low;
|
@Nullable public final Integer low;
|
||||||
public final Integer high;
|
@Nullable public final Integer high;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Settings to disable quality based scaling.
|
* Settings to disable quality based scaling.
|
||||||
|
@ -10,10 +10,12 @@
|
|||||||
|
|
||||||
package org.webrtc;
|
package org.webrtc;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/** Factory for creating VideoEncoders. */
|
/** Factory for creating VideoEncoders. */
|
||||||
public interface VideoEncoderFactory {
|
public interface VideoEncoderFactory {
|
||||||
/** Creates an encoder for the given video codec. */
|
/** Creates an encoder for the given video codec. */
|
||||||
@CalledByNative VideoEncoder createEncoder(VideoCodecInfo info);
|
@Nullable @CalledByNative VideoEncoder createEncoder(VideoCodecInfo info);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enumerates the list of supported video codecs. This method will only be called once and the
|
* Enumerates the list of supported video codecs. This method will only be called once and the
|
||||||
|
@ -14,6 +14,7 @@ import android.graphics.Matrix;
|
|||||||
import android.opengl.GLES11Ext;
|
import android.opengl.GLES11Ext;
|
||||||
import android.opengl.GLES20;
|
import android.opengl.GLES20;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Java version of webrtc::VideoFrame and webrtc::VideoFrameBuffer. A difference from the C++
|
* Java version of webrtc::VideoFrame and webrtc::VideoFrameBuffer. A difference from the C++
|
||||||
|
@ -13,6 +13,7 @@ package org.webrtc;
|
|||||||
import android.graphics.Matrix;
|
import android.graphics.Matrix;
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
import android.opengl.GLES20;
|
import android.opengl.GLES20;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -55,14 +56,15 @@ public class VideoFrameDrawer {
|
|||||||
// Intermediate copy buffer for uploading yuv frames that are not packed, i.e. stride > width.
|
// Intermediate copy buffer for uploading yuv frames that are not packed, i.e. stride > width.
|
||||||
// TODO(magjed): Investigate when GL_UNPACK_ROW_LENGTH is available, or make a custom shader
|
// TODO(magjed): Investigate when GL_UNPACK_ROW_LENGTH is available, or make a custom shader
|
||||||
// that handles stride and compare performance with intermediate copy.
|
// that handles stride and compare performance with intermediate copy.
|
||||||
private ByteBuffer copyBuffer;
|
@Nullable private ByteBuffer copyBuffer;
|
||||||
private int[] yuvTextures;
|
@Nullable private int[] yuvTextures;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upload |planes| into OpenGL textures, taking stride into consideration.
|
* Upload |planes| into OpenGL textures, taking stride into consideration.
|
||||||
*
|
*
|
||||||
* @return Array of three texture indices corresponding to Y-, U-, and V-plane respectively.
|
* @return Array of three texture indices corresponding to Y-, U-, and V-plane respectively.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public int[] uploadYuvData(int width, int height, int[] strides, ByteBuffer[] planes) {
|
public int[] uploadYuvData(int width, int height, int[] strides, ByteBuffer[] planes) {
|
||||||
final int[] planeWidths = new int[] {width, width / 2, width / 2};
|
final int[] planeWidths = new int[] {width, width / 2, width / 2};
|
||||||
final int[] planeHeights = new int[] {height, height / 2, height / 2};
|
final int[] planeHeights = new int[] {height, height / 2, height / 2};
|
||||||
@ -105,12 +107,14 @@ public class VideoFrameDrawer {
|
|||||||
return yuvTextures;
|
return yuvTextures;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public int[] uploadFromBuffer(VideoFrame.I420Buffer buffer) {
|
public int[] uploadFromBuffer(VideoFrame.I420Buffer buffer) {
|
||||||
int[] strides = {buffer.getStrideY(), buffer.getStrideU(), buffer.getStrideV()};
|
int[] strides = {buffer.getStrideY(), buffer.getStrideU(), buffer.getStrideV()};
|
||||||
ByteBuffer[] planes = {buffer.getDataY(), buffer.getDataU(), buffer.getDataV()};
|
ByteBuffer[] planes = {buffer.getDataY(), buffer.getDataU(), buffer.getDataV()};
|
||||||
return uploadYuvData(buffer.getWidth(), buffer.getHeight(), strides, planes);
|
return uploadYuvData(buffer.getWidth(), buffer.getHeight(), strides, planes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public int[] getYuvTextures() {
|
public int[] getYuvTextures() {
|
||||||
return yuvTextures;
|
return yuvTextures;
|
||||||
}
|
}
|
||||||
@ -144,7 +148,7 @@ public class VideoFrameDrawer {
|
|||||||
// |renderWidth| and |renderHeight| to avoid allocations since this function is called for every
|
// |renderWidth| and |renderHeight| to avoid allocations since this function is called for every
|
||||||
// frame.
|
// frame.
|
||||||
private void calculateTransformedRenderSize(
|
private void calculateTransformedRenderSize(
|
||||||
int frameWidth, int frameHeight, Matrix renderMatrix) {
|
int frameWidth, int frameHeight, @Nullable Matrix renderMatrix) {
|
||||||
if (renderMatrix == null) {
|
if (renderMatrix == null) {
|
||||||
renderWidth = frameWidth;
|
renderWidth = frameWidth;
|
||||||
renderHeight = frameHeight;
|
renderHeight = frameHeight;
|
||||||
@ -167,7 +171,7 @@ public class VideoFrameDrawer {
|
|||||||
private final YuvUploader yuvUploader = new YuvUploader();
|
private final YuvUploader yuvUploader = new YuvUploader();
|
||||||
// This variable will only be used for checking reference equality and is used for caching I420
|
// This variable will only be used for checking reference equality and is used for caching I420
|
||||||
// textures.
|
// textures.
|
||||||
private VideoFrame lastI420Frame;
|
@Nullable private VideoFrame lastI420Frame;
|
||||||
private final Matrix renderMatrix = new Matrix();
|
private final Matrix renderMatrix = new Matrix();
|
||||||
|
|
||||||
public void drawFrame(VideoFrame frame, RendererCommon.GlDrawer drawer) {
|
public void drawFrame(VideoFrame frame, RendererCommon.GlDrawer drawer) {
|
||||||
@ -181,7 +185,7 @@ public class VideoFrameDrawer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void drawFrame(VideoFrame frame, RendererCommon.GlDrawer drawer,
|
public void drawFrame(VideoFrame frame, RendererCommon.GlDrawer drawer,
|
||||||
Matrix additionalRenderMatrix, int viewportX, int viewportY, int viewportWidth,
|
@Nullable Matrix additionalRenderMatrix, int viewportX, int viewportY, int viewportWidth,
|
||||||
int viewportHeight) {
|
int viewportHeight) {
|
||||||
final int width = frame.getRotatedWidth();
|
final int width = frame.getRotatedWidth();
|
||||||
final int height = frame.getRotatedHeight();
|
final int height = frame.getRotatedHeight();
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
package org.webrtc;
|
package org.webrtc;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import org.webrtc.VideoFrame;
|
import org.webrtc.VideoFrame;
|
||||||
|
|
||||||
@ -28,14 +29,14 @@ public class VideoRenderer {
|
|||||||
public static class I420Frame {
|
public static class I420Frame {
|
||||||
public final int width;
|
public final int width;
|
||||||
public final int height;
|
public final int height;
|
||||||
public final int[] yuvStrides;
|
@Nullable public final int[] yuvStrides;
|
||||||
public ByteBuffer[] yuvPlanes;
|
@Nullable public ByteBuffer[] yuvPlanes;
|
||||||
public final boolean yuvFrame;
|
public final boolean yuvFrame;
|
||||||
// Matrix that transforms standard coordinates to their proper sampling locations in
|
// Matrix that transforms standard coordinates to their proper sampling locations in
|
||||||
// the texture. This transform compensates for any properties of the video source that
|
// the texture. This transform compensates for any properties of the video source that
|
||||||
// cause it to appear different from a normalized texture. This matrix does not take
|
// cause it to appear different from a normalized texture. This matrix does not take
|
||||||
// |rotationDegree| into account.
|
// |rotationDegree| into account.
|
||||||
public final float[] samplingMatrix;
|
@Nullable public final float[] samplingMatrix;
|
||||||
public int textureId;
|
public int textureId;
|
||||||
// Frame pointer in C++.
|
// Frame pointer in C++.
|
||||||
private long nativeFramePointer;
|
private long nativeFramePointer;
|
||||||
@ -46,7 +47,7 @@ public class VideoRenderer {
|
|||||||
|
|
||||||
// If this I420Frame was constructed from VideoFrame.Buffer, this points to
|
// If this I420Frame was constructed from VideoFrame.Buffer, this points to
|
||||||
// the backing buffer.
|
// the backing buffer.
|
||||||
private final VideoFrame.Buffer backingBuffer;
|
@Nullable private final VideoFrame.Buffer backingBuffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a frame of the given dimensions with the specified planar data.
|
* Construct a frame of the given dimensions with the specified planar data.
|
||||||
|
@ -14,6 +14,7 @@ import android.content.Context;
|
|||||||
import android.media.MediaRecorder;
|
import android.media.MediaRecorder;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -152,8 +153,8 @@ class Camera1Session implements CameraSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Camera1Session(Events events, boolean captureToTexture, Context applicationContext,
|
private Camera1Session(Events events, boolean captureToTexture, Context applicationContext,
|
||||||
SurfaceTextureHelper surfaceTextureHelper, MediaRecorder mediaRecorder, int cameraId,
|
SurfaceTextureHelper surfaceTextureHelper, @Nullable MediaRecorder mediaRecorder,
|
||||||
android.hardware.Camera camera, android.hardware.Camera.CameraInfo info,
|
int cameraId, android.hardware.Camera camera, android.hardware.Camera.CameraInfo info,
|
||||||
CaptureFormat captureFormat, long constructionTimeNs) {
|
CaptureFormat captureFormat, long constructionTimeNs) {
|
||||||
Logging.d(TAG, "Create new camera1 session on camera " + cameraId);
|
Logging.d(TAG, "Create new camera1 session on camera " + cameraId);
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ import android.hardware.camera2.CaptureFailure;
|
|||||||
import android.hardware.camera2.CaptureRequest;
|
import android.hardware.camera2.CaptureRequest;
|
||||||
import android.media.MediaRecorder;
|
import android.media.MediaRecorder;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import android.util.Range;
|
import android.util.Range;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
@ -51,7 +52,7 @@ class Camera2Session implements CameraSession {
|
|||||||
private final Context applicationContext;
|
private final Context applicationContext;
|
||||||
private final CameraManager cameraManager;
|
private final CameraManager cameraManager;
|
||||||
private final SurfaceTextureHelper surfaceTextureHelper;
|
private final SurfaceTextureHelper surfaceTextureHelper;
|
||||||
private final Surface mediaRecorderSurface;
|
@Nullable private final Surface mediaRecorderSurface;
|
||||||
private final String cameraId;
|
private final String cameraId;
|
||||||
private final int width;
|
private final int width;
|
||||||
private final int height;
|
private final int height;
|
||||||
@ -65,11 +66,11 @@ class Camera2Session implements CameraSession {
|
|||||||
private CaptureFormat captureFormat;
|
private CaptureFormat captureFormat;
|
||||||
|
|
||||||
// Initialized when camera opens
|
// Initialized when camera opens
|
||||||
private CameraDevice cameraDevice;
|
@Nullable private CameraDevice cameraDevice;
|
||||||
private Surface surface;
|
@Nullable private Surface surface;
|
||||||
|
|
||||||
// Initialized when capture session is created
|
// Initialized when capture session is created
|
||||||
private CameraCaptureSession captureSession;
|
@Nullable private CameraCaptureSession captureSession;
|
||||||
|
|
||||||
// State
|
// State
|
||||||
private SessionState state = SessionState.RUNNING;
|
private SessionState state = SessionState.RUNNING;
|
||||||
@ -304,7 +305,8 @@ class Camera2Session implements CameraSession {
|
|||||||
|
|
||||||
private Camera2Session(CreateSessionCallback callback, Events events, Context applicationContext,
|
private Camera2Session(CreateSessionCallback callback, Events events, Context applicationContext,
|
||||||
CameraManager cameraManager, SurfaceTextureHelper surfaceTextureHelper,
|
CameraManager cameraManager, SurfaceTextureHelper surfaceTextureHelper,
|
||||||
MediaRecorder mediaRecorder, String cameraId, int width, int height, int framerate) {
|
@Nullable MediaRecorder mediaRecorder, String cameraId, int width, int height,
|
||||||
|
int framerate) {
|
||||||
Logging.d(TAG, "Create new camera2 session on camera " + cameraId);
|
Logging.d(TAG, "Create new camera2 session on camera " + cameraId);
|
||||||
|
|
||||||
constructionTimeNs = System.nanoTime();
|
constructionTimeNs = System.nanoTime();
|
||||||
|
@ -14,6 +14,7 @@ import android.content.Context;
|
|||||||
import android.media.MediaRecorder;
|
import android.media.MediaRecorder;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@ -37,9 +38,10 @@ abstract class CameraCapturer implements CameraVideoCapturer {
|
|||||||
private final static int OPEN_CAMERA_TIMEOUT = 10000;
|
private final static int OPEN_CAMERA_TIMEOUT = 10000;
|
||||||
|
|
||||||
private final CameraEnumerator cameraEnumerator;
|
private final CameraEnumerator cameraEnumerator;
|
||||||
private final CameraEventsHandler eventsHandler;
|
@Nullable private final CameraEventsHandler eventsHandler;
|
||||||
private final Handler uiThreadHandler;
|
private final Handler uiThreadHandler;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private final CameraSession.CreateSessionCallback createSessionCallback =
|
private final CameraSession.CreateSessionCallback createSessionCallback =
|
||||||
new CameraSession.CreateSessionCallback() {
|
new CameraSession.CreateSessionCallback() {
|
||||||
@Override
|
@Override
|
||||||
@ -125,6 +127,7 @@ abstract class CameraCapturer implements CameraVideoCapturer {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private final CameraSession.Events cameraSessionEventsHandler = new CameraSession.Events() {
|
private final CameraSession.Events cameraSessionEventsHandler = new CameraSession.Events() {
|
||||||
@Override
|
@Override
|
||||||
public void onCameraOpening() {
|
public void onCameraOpening() {
|
||||||
@ -203,31 +206,31 @@ abstract class CameraCapturer implements CameraVideoCapturer {
|
|||||||
|
|
||||||
// Initialized on initialize
|
// Initialized on initialize
|
||||||
// -------------------------
|
// -------------------------
|
||||||
private Handler cameraThreadHandler;
|
@Nullable private Handler cameraThreadHandler;
|
||||||
private Context applicationContext;
|
private Context applicationContext;
|
||||||
private CapturerObserver capturerObserver;
|
private CapturerObserver capturerObserver;
|
||||||
private SurfaceTextureHelper surfaceHelper;
|
@Nullable private SurfaceTextureHelper surfaceHelper;
|
||||||
|
|
||||||
private final Object stateLock = new Object();
|
private final Object stateLock = new Object();
|
||||||
private boolean sessionOpening; /* guarded by stateLock */
|
private boolean sessionOpening; /* guarded by stateLock */
|
||||||
private CameraSession currentSession; /* guarded by stateLock */
|
@Nullable private CameraSession currentSession; /* guarded by stateLock */
|
||||||
private String cameraName; /* guarded by stateLock */
|
private String cameraName; /* guarded by stateLock */
|
||||||
private int width; /* guarded by stateLock */
|
private int width; /* guarded by stateLock */
|
||||||
private int height; /* guarded by stateLock */
|
private int height; /* guarded by stateLock */
|
||||||
private int framerate; /* guarded by stateLock */
|
private int framerate; /* guarded by stateLock */
|
||||||
private int openAttemptsRemaining; /* guarded by stateLock */
|
private int openAttemptsRemaining; /* guarded by stateLock */
|
||||||
private SwitchState switchState = SwitchState.IDLE; /* guarded by stateLock */
|
private SwitchState switchState = SwitchState.IDLE; /* guarded by stateLock */
|
||||||
private CameraSwitchHandler switchEventsHandler; /* guarded by stateLock */
|
@Nullable private CameraSwitchHandler switchEventsHandler; /* guarded by stateLock */
|
||||||
// Valid from onDone call until stopCapture, otherwise null.
|
// Valid from onDone call until stopCapture, otherwise null.
|
||||||
private CameraStatistics cameraStatistics; /* guarded by stateLock */
|
@Nullable private CameraStatistics cameraStatistics; /* guarded by stateLock */
|
||||||
private boolean firstFrameObserved; /* guarded by stateLock */
|
private boolean firstFrameObserved; /* guarded by stateLock */
|
||||||
|
|
||||||
// Variables used on camera thread - do not require stateLock synchronization.
|
// Variables used on camera thread - do not require stateLock synchronization.
|
||||||
private MediaRecorderState mediaRecorderState = MediaRecorderState.IDLE;
|
private MediaRecorderState mediaRecorderState = MediaRecorderState.IDLE;
|
||||||
private MediaRecorderHandler mediaRecorderEventsHandler;
|
@Nullable private MediaRecorderHandler mediaRecorderEventsHandler;
|
||||||
|
|
||||||
public CameraCapturer(
|
public CameraCapturer(String cameraName, @Nullable CameraEventsHandler eventsHandler,
|
||||||
String cameraName, CameraEventsHandler eventsHandler, CameraEnumerator cameraEnumerator) {
|
CameraEnumerator cameraEnumerator) {
|
||||||
if (eventsHandler == null) {
|
if (eventsHandler == null) {
|
||||||
eventsHandler = new CameraEventsHandler() {
|
eventsHandler = new CameraEventsHandler() {
|
||||||
@Override
|
@Override
|
||||||
@ -262,8 +265,8 @@ abstract class CameraCapturer implements CameraVideoCapturer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(SurfaceTextureHelper surfaceTextureHelper, Context applicationContext,
|
public void initialize(@Nullable SurfaceTextureHelper surfaceTextureHelper,
|
||||||
CapturerObserver capturerObserver) {
|
Context applicationContext, CapturerObserver capturerObserver) {
|
||||||
this.applicationContext = applicationContext;
|
this.applicationContext = applicationContext;
|
||||||
this.capturerObserver = capturerObserver;
|
this.capturerObserver = capturerObserver;
|
||||||
this.surfaceHelper = surfaceTextureHelper;
|
this.surfaceHelper = surfaceTextureHelper;
|
||||||
@ -412,14 +415,15 @@ abstract class CameraCapturer implements CameraVideoCapturer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reportCameraSwitchError(String error, CameraSwitchHandler switchEventsHandler) {
|
private void reportCameraSwitchError(
|
||||||
|
String error, @Nullable CameraSwitchHandler switchEventsHandler) {
|
||||||
Logging.e(TAG, error);
|
Logging.e(TAG, error);
|
||||||
if (switchEventsHandler != null) {
|
if (switchEventsHandler != null) {
|
||||||
switchEventsHandler.onCameraSwitchError(error);
|
switchEventsHandler.onCameraSwitchError(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void switchCameraInternal(final CameraSwitchHandler switchEventsHandler) {
|
private void switchCameraInternal(@Nullable final CameraSwitchHandler switchEventsHandler) {
|
||||||
Logging.d(TAG, "switchCamera internal");
|
Logging.d(TAG, "switchCamera internal");
|
||||||
|
|
||||||
final String[] deviceNames = cameraEnumerator.getDeviceNames();
|
final String[] deviceNames = cameraEnumerator.getDeviceNames();
|
||||||
@ -476,7 +480,7 @@ abstract class CameraCapturer implements CameraVideoCapturer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void reportUpdateMediaRecorderError(
|
private void reportUpdateMediaRecorderError(
|
||||||
String error, MediaRecorderHandler mediaRecoderEventsHandler) {
|
String error, @Nullable MediaRecorderHandler mediaRecoderEventsHandler) {
|
||||||
checkIsOnCameraThread();
|
checkIsOnCameraThread();
|
||||||
Logging.e(TAG, error);
|
Logging.e(TAG, error);
|
||||||
if (mediaRecoderEventsHandler != null) {
|
if (mediaRecoderEventsHandler != null) {
|
||||||
@ -485,7 +489,7 @@ abstract class CameraCapturer implements CameraVideoCapturer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateMediaRecorderInternal(
|
private void updateMediaRecorderInternal(
|
||||||
MediaRecorder mediaRecorder, MediaRecorderHandler mediaRecoderEventsHandler) {
|
@Nullable MediaRecorder mediaRecorder, MediaRecorderHandler mediaRecoderEventsHandler) {
|
||||||
checkIsOnCameraThread();
|
checkIsOnCameraThread();
|
||||||
boolean addMediaRecorder = (mediaRecorder != null);
|
boolean addMediaRecorder = (mediaRecorder != null);
|
||||||
Logging.d(TAG,
|
Logging.d(TAG,
|
||||||
|
@ -13,6 +13,7 @@ package org.webrtc;
|
|||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.SurfaceTexture;
|
import android.graphics.SurfaceTexture;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
import android.view.SurfaceHolder;
|
import android.view.SurfaceHolder;
|
||||||
import javax.microedition.khronos.egl.EGL10;
|
import javax.microedition.khronos.egl.EGL10;
|
||||||
@ -31,7 +32,7 @@ class EglBase10 implements EglBase {
|
|||||||
|
|
||||||
private final EGL10 egl;
|
private final EGL10 egl;
|
||||||
private EGLContext eglContext;
|
private EGLContext eglContext;
|
||||||
private EGLConfig eglConfig;
|
@Nullable private EGLConfig eglConfig;
|
||||||
private EGLDisplay eglDisplay;
|
private EGLDisplay eglDisplay;
|
||||||
private EGLSurface eglSurface = EGL10.EGL_NO_SURFACE;
|
private EGLSurface eglSurface = EGL10.EGL_NO_SURFACE;
|
||||||
|
|
||||||
@ -102,11 +103,13 @@ class EglBase10 implements EglBase {
|
|||||||
@Override
|
@Override
|
||||||
public void setKeepScreenOn(boolean b) {}
|
public void setKeepScreenOn(boolean b) {}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Canvas lockCanvas() {
|
public Canvas lockCanvas() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Canvas lockCanvas(Rect rect) {
|
public Canvas lockCanvas(Rect rect) {
|
||||||
return null;
|
return null;
|
||||||
@ -115,6 +118,7 @@ class EglBase10 implements EglBase {
|
|||||||
@Override
|
@Override
|
||||||
public void unlockCanvasAndPost(Canvas canvas) {}
|
public void unlockCanvasAndPost(Canvas canvas) {}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Rect getSurfaceFrame() {
|
public Rect getSurfaceFrame() {
|
||||||
return null;
|
return null;
|
||||||
@ -301,7 +305,7 @@ class EglBase10 implements EglBase {
|
|||||||
|
|
||||||
// Return an EGLConfig, or die trying.
|
// Return an EGLConfig, or die trying.
|
||||||
private EGLContext createEglContext(
|
private EGLContext createEglContext(
|
||||||
Context sharedContext, EGLDisplay eglDisplay, EGLConfig eglConfig) {
|
@Nullable Context sharedContext, EGLDisplay eglDisplay, EGLConfig eglConfig) {
|
||||||
if (sharedContext != null && sharedContext.eglContext == EGL10.EGL_NO_CONTEXT) {
|
if (sharedContext != null && sharedContext.eglContext == EGL10.EGL_NO_CONTEXT) {
|
||||||
throw new RuntimeException("Invalid sharedContext");
|
throw new RuntimeException("Invalid sharedContext");
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import android.opengl.EGLDisplay;
|
|||||||
import android.opengl.EGLExt;
|
import android.opengl.EGLExt;
|
||||||
import android.opengl.EGLSurface;
|
import android.opengl.EGLSurface;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
import org.webrtc.EglBase;
|
import org.webrtc.EglBase;
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ class EglBase14 implements EglBase {
|
|||||||
private static final int EGLExt_SDK_VERSION = android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
|
private static final int EGLExt_SDK_VERSION = android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
|
||||||
private static final int CURRENT_SDK_VERSION = android.os.Build.VERSION.SDK_INT;
|
private static final int CURRENT_SDK_VERSION = android.os.Build.VERSION.SDK_INT;
|
||||||
private EGLContext eglContext;
|
private EGLContext eglContext;
|
||||||
private EGLConfig eglConfig;
|
@Nullable private EGLConfig eglConfig;
|
||||||
private EGLDisplay eglDisplay;
|
private EGLDisplay eglDisplay;
|
||||||
private EGLSurface eglSurface = EGL14.EGL_NO_SURFACE;
|
private EGLSurface eglSurface = EGL14.EGL_NO_SURFACE;
|
||||||
|
|
||||||
@ -262,7 +263,7 @@ class EglBase14 implements EglBase {
|
|||||||
|
|
||||||
// Return an EGLConfig, or die trying.
|
// Return an EGLConfig, or die trying.
|
||||||
private static EGLContext createEglContext(
|
private static EGLContext createEglContext(
|
||||||
EglBase14.Context sharedContext, EGLDisplay eglDisplay, EGLConfig eglConfig) {
|
@Nullable EglBase14.Context sharedContext, EGLDisplay eglDisplay, EGLConfig eglConfig) {
|
||||||
if (sharedContext != null && sharedContext.egl14Context == EGL14.EGL_NO_CONTEXT) {
|
if (sharedContext != null && sharedContext.egl14Context == EGL14.EGL_NO_CONTEXT) {
|
||||||
throw new RuntimeException("Invalid sharedContext");
|
throw new RuntimeException("Invalid sharedContext");
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import android.media.MediaCodec;
|
|||||||
import android.media.MediaCodecInfo.CodecCapabilities;
|
import android.media.MediaCodecInfo.CodecCapabilities;
|
||||||
import android.media.MediaFormat;
|
import android.media.MediaFormat;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@ -71,7 +72,7 @@ class HardwareVideoDecoder
|
|||||||
// Output thread runs a loop which polls MediaCodec for decoded output buffers. It reformats
|
// Output thread runs a loop which polls MediaCodec for decoded output buffers. It reformats
|
||||||
// those buffers into VideoFrames and delivers them to the callback. Variable is set on decoder
|
// those buffers into VideoFrames and delivers them to the callback. Variable is set on decoder
|
||||||
// thread and is immutable while the codec is running.
|
// thread and is immutable while the codec is running.
|
||||||
private Thread outputThread;
|
@Nullable private Thread outputThread;
|
||||||
|
|
||||||
// Checker that ensures work is run on the output thread.
|
// Checker that ensures work is run on the output thread.
|
||||||
private ThreadChecker outputThreadChecker;
|
private ThreadChecker outputThreadChecker;
|
||||||
@ -81,7 +82,7 @@ class HardwareVideoDecoder
|
|||||||
private ThreadChecker decoderThreadChecker;
|
private ThreadChecker decoderThreadChecker;
|
||||||
|
|
||||||
private volatile boolean running = false;
|
private volatile boolean running = false;
|
||||||
private volatile Exception shutdownException = null;
|
@Nullable private volatile Exception shutdownException = null;
|
||||||
|
|
||||||
// Dimensions (width, height, stride, and sliceHeight) may be accessed by either the decode thread
|
// Dimensions (width, height, stride, and sliceHeight) may be accessed by either the decode thread
|
||||||
// or the output thread. Accesses should be protected with this lock.
|
// or the output thread. Accesses should be protected with this lock.
|
||||||
@ -101,8 +102,8 @@ class HardwareVideoDecoder
|
|||||||
|
|
||||||
private final EglBase.Context sharedContext;
|
private final EglBase.Context sharedContext;
|
||||||
// Valid and immutable while the decoder is running.
|
// Valid and immutable while the decoder is running.
|
||||||
private SurfaceTextureHelper surfaceTextureHelper;
|
@Nullable private SurfaceTextureHelper surfaceTextureHelper;
|
||||||
private Surface surface = null;
|
@Nullable private Surface surface = null;
|
||||||
|
|
||||||
private static class DecodedTextureMetadata {
|
private static class DecodedTextureMetadata {
|
||||||
final int width;
|
final int width;
|
||||||
@ -123,14 +124,14 @@ class HardwareVideoDecoder
|
|||||||
|
|
||||||
// Metadata for the last frame rendered to the texture.
|
// Metadata for the last frame rendered to the texture.
|
||||||
private final Object renderedTextureMetadataLock = new Object();
|
private final Object renderedTextureMetadataLock = new Object();
|
||||||
private DecodedTextureMetadata renderedTextureMetadata;
|
@Nullable private DecodedTextureMetadata renderedTextureMetadata;
|
||||||
|
|
||||||
// Decoding proceeds asynchronously. This callback returns decoded frames to the caller. Valid
|
// Decoding proceeds asynchronously. This callback returns decoded frames to the caller. Valid
|
||||||
// and immutable while the decoder is running.
|
// and immutable while the decoder is running.
|
||||||
private Callback callback;
|
@Nullable private Callback callback;
|
||||||
|
|
||||||
// Valid and immutable while the decoder is running.
|
// Valid and immutable while the decoder is running.
|
||||||
private MediaCodec codec = null;
|
@Nullable private MediaCodec codec = null;
|
||||||
|
|
||||||
HardwareVideoDecoder(
|
HardwareVideoDecoder(
|
||||||
String codecName, VideoCodecType codecType, int colorFormat, EglBase.Context sharedContext) {
|
String codecName, VideoCodecType codecType, int colorFormat, EglBase.Context sharedContext) {
|
||||||
|
@ -17,6 +17,7 @@ import android.media.MediaCodecInfo;
|
|||||||
import android.media.MediaFormat;
|
import android.media.MediaFormat;
|
||||||
import android.opengl.GLES20;
|
import android.opengl.GLES20;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@ -81,16 +82,16 @@ class HardwareVideoEncoder implements VideoEncoder {
|
|||||||
private boolean automaticResizeOn;
|
private boolean automaticResizeOn;
|
||||||
|
|
||||||
// --- Valid and immutable while an encoding session is running.
|
// --- Valid and immutable while an encoding session is running.
|
||||||
private MediaCodec codec;
|
@Nullable private MediaCodec codec;
|
||||||
// Thread that delivers encoded frames to the user callback.
|
// Thread that delivers encoded frames to the user callback.
|
||||||
private Thread outputThread;
|
@Nullable private Thread outputThread;
|
||||||
|
|
||||||
// EGL base wrapping the shared texture context. Holds hooks to both the shared context and the
|
// EGL base wrapping the shared texture context. Holds hooks to both the shared context and the
|
||||||
// input surface. Making this base current allows textures from the context to be drawn onto the
|
// input surface. Making this base current allows textures from the context to be drawn onto the
|
||||||
// surface.
|
// surface.
|
||||||
private EglBase14 textureEglBase;
|
@Nullable private EglBase14 textureEglBase;
|
||||||
// Input surface for the codec. The encoder will draw input textures onto this surface.
|
// Input surface for the codec. The encoder will draw input textures onto this surface.
|
||||||
private Surface textureInputSurface;
|
@Nullable private Surface textureInputSurface;
|
||||||
|
|
||||||
private int width;
|
private int width;
|
||||||
private int height;
|
private int height;
|
||||||
@ -102,7 +103,7 @@ class HardwareVideoEncoder implements VideoEncoder {
|
|||||||
|
|
||||||
// --- Only accessed on the output thread.
|
// --- Only accessed on the output thread.
|
||||||
// Contents of the last observed config frame output by the MediaCodec. Used by H.264.
|
// Contents of the last observed config frame output by the MediaCodec. Used by H.264.
|
||||||
private ByteBuffer configBuffer = null;
|
@Nullable private ByteBuffer configBuffer = null;
|
||||||
private int adjustedBitrate;
|
private int adjustedBitrate;
|
||||||
|
|
||||||
// Whether the encoder is running. Volatile so that the output thread can watch this value and
|
// Whether the encoder is running. Volatile so that the output thread can watch this value and
|
||||||
@ -110,7 +111,7 @@ class HardwareVideoEncoder implements VideoEncoder {
|
|||||||
private volatile boolean running = false;
|
private volatile boolean running = false;
|
||||||
// Any exception thrown during shutdown. The output thread releases the MediaCodec and uses this
|
// Any exception thrown during shutdown. The output thread releases the MediaCodec and uses this
|
||||||
// value to send exceptions thrown during release back to the encoder thread.
|
// value to send exceptions thrown during release back to the encoder thread.
|
||||||
private volatile Exception shutdownException = null;
|
@Nullable private volatile Exception shutdownException = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new HardwareVideoEncoder with the given codecName, codecType, colorFormat, key frame
|
* Creates a new HardwareVideoEncoder with the given codecName, codecType, colorFormat, key frame
|
||||||
|
@ -14,6 +14,7 @@ import android.annotation.TargetApi;
|
|||||||
import android.media.MediaCodec;
|
import android.media.MediaCodec;
|
||||||
import android.media.MediaCodecInfo;
|
import android.media.MediaCodecInfo;
|
||||||
import android.media.MediaCodecInfo.CodecCapabilities;
|
import android.media.MediaCodecInfo.CodecCapabilities;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/** Container class for static constants and helpers used with MediaCodec. */
|
/** Container class for static constants and helpers used with MediaCodec. */
|
||||||
@TargetApi(18)
|
@TargetApi(18)
|
||||||
@ -54,7 +55,8 @@ class MediaCodecUtils {
|
|||||||
// Color formats supported by texture mode encoding - in order of preference.
|
// Color formats supported by texture mode encoding - in order of preference.
|
||||||
static final int[] TEXTURE_COLOR_FORMATS = {MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface};
|
static final int[] TEXTURE_COLOR_FORMATS = {MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface};
|
||||||
|
|
||||||
static Integer selectColorFormat(int[] supportedColorFormats, CodecCapabilities capabilities) {
|
static @Nullable Integer selectColorFormat(
|
||||||
|
int[] supportedColorFormats, CodecCapabilities capabilities) {
|
||||||
for (int supportedColorFormat : supportedColorFormats) {
|
for (int supportedColorFormat : supportedColorFormats) {
|
||||||
for (int codecColorFormat : capabilities.colorFormats) {
|
for (int codecColorFormat : capabilities.colorFormats) {
|
||||||
if (codecColorFormat == supportedColorFormat) {
|
if (codecColorFormat == supportedColorFormat) {
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
package org.webrtc;
|
package org.webrtc;
|
||||||
|
|
||||||
// Explicit imports necessary for JNI generation.
|
// Explicit imports necessary for JNI generation.
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import org.webrtc.VideoEncoder;
|
import org.webrtc.VideoEncoder;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
@ -23,11 +24,13 @@ class VideoEncoderWrapper {
|
|||||||
return scalingSettings.on;
|
return scalingSettings.on;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@CalledByNative
|
@CalledByNative
|
||||||
static Integer getScalingSettingsLow(VideoEncoder.ScalingSettings scalingSettings) {
|
static Integer getScalingSettingsLow(VideoEncoder.ScalingSettings scalingSettings) {
|
||||||
return scalingSettings.low;
|
return scalingSettings.low;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@CalledByNative
|
@CalledByNative
|
||||||
static Integer getScalingSettingsHigh(VideoEncoder.ScalingSettings scalingSettings) {
|
static Integer getScalingSettingsHigh(VideoEncoder.ScalingSettings scalingSettings) {
|
||||||
return scalingSettings.high;
|
return scalingSettings.high;
|
||||||
|
@ -19,6 +19,7 @@ import android.media.audiofx.NoiseSuppressor;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import org.webrtc.Logging;
|
import org.webrtc.Logging;
|
||||||
|
|
||||||
// This class wraps control of three different platform effects. Supported
|
// This class wraps control of three different platform effects. Supported
|
||||||
@ -40,12 +41,12 @@ class WebRtcAudioEffects {
|
|||||||
// Contains the available effect descriptors returned from the
|
// Contains the available effect descriptors returned from the
|
||||||
// AudioEffect.getEffects() call. This result is cached to avoid doing the
|
// AudioEffect.getEffects() call. This result is cached to avoid doing the
|
||||||
// slow OS call multiple times.
|
// slow OS call multiple times.
|
||||||
private static Descriptor[] cachedEffects = null;
|
private static @Nullable Descriptor[] cachedEffects = null;
|
||||||
|
|
||||||
// Contains the audio effect objects. Created in enable() and destroyed
|
// Contains the audio effect objects. Created in enable() and destroyed
|
||||||
// in release().
|
// in release().
|
||||||
private AcousticEchoCanceler aec = null;
|
private @Nullable AcousticEchoCanceler aec = null;
|
||||||
private NoiseSuppressor ns = null;
|
private @Nullable NoiseSuppressor ns = null;
|
||||||
|
|
||||||
// Affects the final state given to the setEnabled() method on each effect.
|
// Affects the final state given to the setEnabled() method on each effect.
|
||||||
// The default state is set to "disabled" but each effect can also be enabled
|
// The default state is set to "disabled" but each effect can also be enabled
|
||||||
@ -293,7 +294,7 @@ class WebRtcAudioEffects {
|
|||||||
|
|
||||||
// Returns the cached copy of the audio effects array, if available, or
|
// Returns the cached copy of the audio effects array, if available, or
|
||||||
// queries the operating system for the list of effects.
|
// queries the operating system for the list of effects.
|
||||||
private static Descriptor[] getAvailableEffects() {
|
private static @Nullable Descriptor[] getAvailableEffects() {
|
||||||
if (cachedEffects != null) {
|
if (cachedEffects != null) {
|
||||||
return cachedEffects;
|
return cachedEffects;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ import android.media.AudioTrack;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import org.webrtc.Logging;
|
import org.webrtc.Logging;
|
||||||
import org.webrtc.CalledByNative;
|
import org.webrtc.CalledByNative;
|
||||||
|
|
||||||
@ -100,7 +101,7 @@ class WebRtcAudioManager {
|
|||||||
private static final int TIMER_PERIOD_IN_SECONDS = 30;
|
private static final int TIMER_PERIOD_IN_SECONDS = 30;
|
||||||
|
|
||||||
private final AudioManager audioManager;
|
private final AudioManager audioManager;
|
||||||
private Timer timer;
|
private @Nullable Timer timer;
|
||||||
|
|
||||||
public VolumeLogger(AudioManager audioManager) {
|
public VolumeLogger(AudioManager audioManager) {
|
||||||
this.audioManager = audioManager;
|
this.audioManager = audioManager;
|
||||||
|
@ -19,12 +19,13 @@ import java.lang.System;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import org.webrtc.CalledByNative;
|
||||||
import org.webrtc.Logging;
|
import org.webrtc.Logging;
|
||||||
|
import org.webrtc.NativeClassQualifiedName;
|
||||||
import org.webrtc.ThreadUtils;
|
import org.webrtc.ThreadUtils;
|
||||||
import org.webrtc.audio.AudioDeviceModule.AudioRecordErrorCallback;
|
import org.webrtc.audio.AudioDeviceModule.AudioRecordErrorCallback;
|
||||||
import org.webrtc.audio.AudioDeviceModule.AudioRecordStartErrorCode;
|
import org.webrtc.audio.AudioDeviceModule.AudioRecordStartErrorCode;
|
||||||
import org.webrtc.CalledByNative;
|
|
||||||
import org.webrtc.NativeClassQualifiedName;
|
|
||||||
import org.webrtc.audio.AudioDeviceModule.SamplesReadyCallback;
|
import org.webrtc.audio.AudioDeviceModule.SamplesReadyCallback;
|
||||||
|
|
||||||
class WebRtcAudioRecord {
|
class WebRtcAudioRecord {
|
||||||
@ -56,24 +57,24 @@ class WebRtcAudioRecord {
|
|||||||
|
|
||||||
private final long nativeAudioRecord;
|
private final long nativeAudioRecord;
|
||||||
|
|
||||||
private WebRtcAudioEffects effects = null;
|
private @Nullable WebRtcAudioEffects effects = null;
|
||||||
|
|
||||||
private ByteBuffer byteBuffer;
|
private @Nullable ByteBuffer byteBuffer;
|
||||||
|
|
||||||
private AudioRecord audioRecord = null;
|
private @Nullable AudioRecord audioRecord = null;
|
||||||
private AudioRecordThread audioThread = null;
|
private @Nullable AudioRecordThread audioThread = null;
|
||||||
|
|
||||||
private static volatile boolean microphoneMute = false;
|
private static volatile boolean microphoneMute = false;
|
||||||
private byte[] emptyBytes;
|
private byte[] emptyBytes;
|
||||||
|
|
||||||
private static AudioRecordErrorCallback errorCallback = null;
|
private static @Nullable AudioRecordErrorCallback errorCallback = null;
|
||||||
|
|
||||||
public static void setErrorCallback(AudioRecordErrorCallback errorCallback) {
|
public static void setErrorCallback(AudioRecordErrorCallback errorCallback) {
|
||||||
Logging.d(TAG, "Set error callback");
|
Logging.d(TAG, "Set error callback");
|
||||||
WebRtcAudioRecord.errorCallback = errorCallback;
|
WebRtcAudioRecord.errorCallback = errorCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SamplesReadyCallback audioSamplesReadyCallback = null;
|
private static @Nullable SamplesReadyCallback audioSamplesReadyCallback = null;
|
||||||
|
|
||||||
public static void setOnAudioSamplesReady(SamplesReadyCallback callback) {
|
public static void setOnAudioSamplesReady(SamplesReadyCallback callback) {
|
||||||
audioSamplesReadyCallback = callback;
|
audioSamplesReadyCallback = callback;
|
||||||
|
@ -20,6 +20,7 @@ import android.media.AudioTrack;
|
|||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import java.lang.Thread;
|
import java.lang.Thread;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import org.webrtc.ContextUtils;
|
import org.webrtc.ContextUtils;
|
||||||
import org.webrtc.Logging;
|
import org.webrtc.Logging;
|
||||||
import org.webrtc.ThreadUtils;
|
import org.webrtc.ThreadUtils;
|
||||||
@ -82,15 +83,15 @@ class WebRtcAudioTrack {
|
|||||||
|
|
||||||
private ByteBuffer byteBuffer;
|
private ByteBuffer byteBuffer;
|
||||||
|
|
||||||
private AudioTrack audioTrack = null;
|
private @Nullable AudioTrack audioTrack = null;
|
||||||
private AudioTrackThread audioThread = null;
|
private @Nullable AudioTrackThread audioThread = null;
|
||||||
|
|
||||||
// Samples to be played are replaced by zeros if |speakerMute| is set to true.
|
// Samples to be played are replaced by zeros if |speakerMute| is set to true.
|
||||||
// Can be used to ensure that the speaker is fully muted.
|
// Can be used to ensure that the speaker is fully muted.
|
||||||
private static volatile boolean speakerMute = false;
|
private static volatile boolean speakerMute = false;
|
||||||
private byte[] emptyBytes;
|
private byte[] emptyBytes;
|
||||||
|
|
||||||
private static AudioTrackErrorCallback errorCallback = null;
|
private static @Nullable AudioTrackErrorCallback errorCallback = null;
|
||||||
|
|
||||||
public static void setErrorCallback(AudioTrackErrorCallback errorCallback) {
|
public static void setErrorCallback(AudioTrackErrorCallback errorCallback) {
|
||||||
Logging.d(TAG, "Set extended error callback");
|
Logging.d(TAG, "Set extended error callback");
|
||||||
|
Reference in New Issue
Block a user