blob: a326a2c884fcbd0bcc405275de466cb01f9e8fac [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2013 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
henrike@webrtc.org28e20752013-07-10 00:45:36 +000011package org.webrtc;
12
Magnus Jedvert1a759c62018-04-24 15:11:02 +020013import javax.annotation.Nullable;
14
fischman@webrtc.org4e65e072013-10-03 18:23:13 +000015/**
Magnus Jedvert7640fcf2016-09-21 16:20:03 +020016 * Java wrapper of native AndroidVideoTrackSource.
fischman@webrtc.org4e65e072013-10-03 18:23:13 +000017 */
Magnus Jedvert84d8ae52017-12-20 15:12:10 +010018@JNINamespace("webrtc::jni")
henrike@webrtc.org28e20752013-07-10 00:45:36 +000019public class VideoSource extends MediaSource {
Magnus Jedvert26b9e122018-05-02 14:41:22 +020020 private final NativeCapturerObserver capturerObserver;
Magnus Jedvert1a759c62018-04-24 15:11:02 +020021
henrike@webrtc.org28e20752013-07-10 00:45:36 +000022 public VideoSource(long nativeSource) {
23 super(nativeSource);
Sami Kalliomäkiff1de0a2018-05-16 12:49:47 +020024 this.capturerObserver = new NativeCapturerObserver(nativeGetInternalSource(nativeSource));
Magnus Jedvert1a759c62018-04-24 15:11:02 +020025 }
26
27 // TODO(bugs.webrtc.org/9181): Remove.
28 VideoSource(long nativeSource, SurfaceTextureHelper surfaceTextureHelper) {
29 super(nativeSource);
Sami Kalliomäkiff1de0a2018-05-16 12:49:47 +020030 this.capturerObserver =
31 new NativeCapturerObserver(nativeGetInternalSource(nativeSource), surfaceTextureHelper);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032 }
Magnus Jedvert7640fcf2016-09-21 16:20:03 +020033
34 /**
35 * Calling this function will cause frames to be scaled down to the requested resolution. Also,
36 * frames will be cropped to match the requested aspect ratio, and frames will be dropped to match
37 * the requested fps. The requested aspect ratio is orientation agnostic and will be adjusted to
38 * maintain the input orientation, so it doesn't matter if e.g. 1280x720 or 720x1280 is requested.
39 */
40 public void adaptOutputFormat(int width, int height, int fps) {
41 nativeAdaptOutputFormat(nativeSource, width, height, fps);
42 }
43
Magnus Jedvert1a759c62018-04-24 15:11:02 +020044 public VideoCapturer.CapturerObserver getCapturerObserver() {
45 return capturerObserver;
46 }
47
Magnus Jedvert26b9e122018-05-02 14:41:22 +020048 @Override
49 public void dispose() {
50 capturerObserver.dispose();
51 super.dispose();
52 }
53
Sami Kalliomäkiff1de0a2018-05-16 12:49:47 +020054 // Returns source->internal() from webrtc::VideoTrackSourceProxy.
55 private static native long nativeGetInternalSource(long source);
Magnus Jedvert84d8ae52017-12-20 15:12:10 +010056 private static native void nativeAdaptOutputFormat(long source, int width, int height, int fps);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057}