henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 4 | * 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 11 | package org.webrtc; |
| 12 | |
Magnus Jedvert | 1a759c6 | 2018-04-24 15:11:02 +0200 | [diff] [blame] | 13 | import javax.annotation.Nullable; |
| 14 | |
fischman@webrtc.org | 4e65e07 | 2013-10-03 18:23:13 +0000 | [diff] [blame] | 15 | /** |
Magnus Jedvert | 7640fcf | 2016-09-21 16:20:03 +0200 | [diff] [blame] | 16 | * Java wrapper of native AndroidVideoTrackSource. |
fischman@webrtc.org | 4e65e07 | 2013-10-03 18:23:13 +0000 | [diff] [blame] | 17 | */ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 18 | public class VideoSource extends MediaSource { |
Magnus Jedvert | 26b9e12 | 2018-05-02 14:41:22 +0200 | [diff] [blame] | 19 | private final NativeCapturerObserver capturerObserver; |
Magnus Jedvert | 1a759c6 | 2018-04-24 15:11:02 +0200 | [diff] [blame] | 20 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 21 | public VideoSource(long nativeSource) { |
| 22 | super(nativeSource); |
Sami Kalliomäki | ff1de0a | 2018-05-16 12:49:47 +0200 | [diff] [blame] | 23 | this.capturerObserver = new NativeCapturerObserver(nativeGetInternalSource(nativeSource)); |
Magnus Jedvert | 1a759c6 | 2018-04-24 15:11:02 +0200 | [diff] [blame] | 24 | } |
| 25 | |
Magnus Jedvert | 7640fcf | 2016-09-21 16:20:03 +0200 | [diff] [blame] | 26 | /** |
| 27 | * Calling this function will cause frames to be scaled down to the requested resolution. Also, |
| 28 | * frames will be cropped to match the requested aspect ratio, and frames will be dropped to match |
| 29 | * the requested fps. The requested aspect ratio is orientation agnostic and will be adjusted to |
| 30 | * maintain the input orientation, so it doesn't matter if e.g. 1280x720 or 720x1280 is requested. |
| 31 | */ |
| 32 | public void adaptOutputFormat(int width, int height, int fps) { |
Magnus Jedvert | 06aa209 | 2018-10-26 14:00:18 +0200 | [diff] [blame^] | 33 | final int maxSide = Math.max(width, height); |
| 34 | final int minSide = Math.min(width, height); |
| 35 | adaptOutputFormat(maxSide, minSide, minSide, maxSide, fps); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Same as above, but allows setting two different target resolutions depending on incoming |
| 40 | * frame orientation. This gives more fine-grained control and can e.g. be used to force landscape |
| 41 | * video to be cropped to portrait video. |
| 42 | */ |
| 43 | public void adaptOutputFormat( |
| 44 | int landscapeWidth, int landscapeHeight, int portraitWidth, int portraitHeight, int fps) { |
| 45 | nativeAdaptOutputFormat(getNativeVideoTrackSource(), landscapeWidth, landscapeHeight, |
| 46 | portraitWidth, portraitHeight, fps); |
Magnus Jedvert | 7640fcf | 2016-09-21 16:20:03 +0200 | [diff] [blame] | 47 | } |
| 48 | |
Sami Kalliomäki | 05b552f | 2018-07-05 17:06:51 +0200 | [diff] [blame] | 49 | public CapturerObserver getCapturerObserver() { |
Magnus Jedvert | 1a759c6 | 2018-04-24 15:11:02 +0200 | [diff] [blame] | 50 | return capturerObserver; |
| 51 | } |
| 52 | |
Sami Kalliomäki | ee05e90 | 2018-09-28 14:38:21 +0200 | [diff] [blame] | 53 | /** Returns a pointer to webrtc::VideoTrackSourceInterface. */ |
| 54 | long getNativeVideoTrackSource() { |
| 55 | return getNativeMediaSource(); |
| 56 | } |
| 57 | |
Sami Kalliomäki | ff1de0a | 2018-05-16 12:49:47 +0200 | [diff] [blame] | 58 | // Returns source->internal() from webrtc::VideoTrackSourceProxy. |
| 59 | private static native long nativeGetInternalSource(long source); |
Magnus Jedvert | 06aa209 | 2018-10-26 14:00:18 +0200 | [diff] [blame^] | 60 | private static native void nativeAdaptOutputFormat(long source, int landscapeWidth, |
| 61 | int landscapeHeight, int portraitWidth, int portraitHeight, int fps); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 62 | } |