kjellander | af71655 | 2016-02-11 12:21:45 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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. |
| 9 | */ |
| 10 | |
| 11 | package org.webrtc; |
| 12 | |
Magnus Jedvert | 5e7834e | 2016-02-12 17:05:29 +0100 | [diff] [blame] | 13 | import android.content.Context; |
Magnus Jedvert | 5199c74 | 2016-02-18 13:09:54 +0100 | [diff] [blame] | 14 | import java.util.List; |
Magnus Jedvert | 5e7834e | 2016-02-12 17:05:29 +0100 | [diff] [blame] | 15 | |
| 16 | // Base interface for all VideoCapturers to implement. |
Magnus Jedvert | 5e7834e | 2016-02-12 17:05:29 +0100 | [diff] [blame] | 17 | public interface VideoCapturer { |
| 18 | // Interface used for providing callbacks to an observer. |
| 19 | public interface CapturerObserver { |
| 20 | // Notify if the camera have been started successfully or not. |
| 21 | // Called on a Java thread owned by VideoCapturer. |
| 22 | void onCapturerStarted(boolean success); |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 23 | void onCapturerStopped(); |
Magnus Jedvert | 5e7834e | 2016-02-12 17:05:29 +0100 | [diff] [blame] | 24 | |
| 25 | // Delivers a captured frame. Called on a Java thread owned by VideoCapturer. |
Sami Kalliomäki | 682dc61 | 2018-01-26 11:06:45 +0100 | [diff] [blame] | 26 | @Deprecated |
| 27 | default void onByteBufferFrameCaptured( |
| 28 | byte[] data, int width, int height, int rotation, long timeStamp) { |
| 29 | throw new UnsupportedOperationException("Deprecated and not implemented."); |
| 30 | } |
Magnus Jedvert | 5e7834e | 2016-02-12 17:05:29 +0100 | [diff] [blame] | 31 | |
| 32 | // Delivers a captured frame in a texture with id |oesTextureId|. Called on a Java thread |
| 33 | // owned by VideoCapturer. |
Sami Kalliomäki | 682dc61 | 2018-01-26 11:06:45 +0100 | [diff] [blame] | 34 | @Deprecated |
| 35 | default void onTextureFrameCaptured(int width, int height, int oesTextureId, |
| 36 | float[] transformMatrix, int rotation, long timestamp) { |
| 37 | throw new UnsupportedOperationException("Deprecated and not implemented."); |
| 38 | } |
sakal | be91046 | 2017-08-11 00:26:05 -0700 | [diff] [blame] | 39 | |
| 40 | // Delivers a captured frame. Called on a Java thread owned by VideoCapturer. |
| 41 | void onFrameCaptured(VideoFrame frame); |
kjellander | af71655 | 2016-02-11 12:21:45 -0800 | [diff] [blame] | 42 | } |
| 43 | |
magjed | 0dc2316 | 2016-03-14 03:59:38 -0700 | [diff] [blame] | 44 | /** |
Magnus Jedvert | 27dcacd | 2016-07-07 10:00:22 +0200 | [diff] [blame] | 45 | * This function is used to initialize the camera thread, the android application context, and the |
| 46 | * capture observer. It will be called only once and before any startCapture() request. The |
| 47 | * camera thread is guaranteed to be valid until dispose() is called. If the VideoCapturer wants |
| 48 | * to deliver texture frames, it should do this by rendering on the SurfaceTexture in |
| 49 | * |surfaceTextureHelper|, register itself as a listener, and forward the texture frames to |
| 50 | * CapturerObserver.onTextureFrameCaptured(). |
magjed | 0dc2316 | 2016-03-14 03:59:38 -0700 | [diff] [blame] | 51 | */ |
Magnus Jedvert | 27dcacd | 2016-07-07 10:00:22 +0200 | [diff] [blame] | 52 | void initialize(SurfaceTextureHelper surfaceTextureHelper, Context applicationContext, |
| 53 | CapturerObserver capturerObserver); |
| 54 | |
| 55 | /** |
| 56 | * Start capturing frames in a format that is as close as possible to |width| x |height| and |
| 57 | * |framerate|. |
| 58 | */ |
| 59 | void startCapture(int width, int height, int framerate); |
Magnus Jedvert | 5e7834e | 2016-02-12 17:05:29 +0100 | [diff] [blame] | 60 | |
magjed | 0dc2316 | 2016-03-14 03:59:38 -0700 | [diff] [blame] | 61 | /** |
| 62 | * Stop capturing. This function should block until capture is actually stopped. |
| 63 | */ |
Magnus Jedvert | 5e7834e | 2016-02-12 17:05:29 +0100 | [diff] [blame] | 64 | void stopCapture() throws InterruptedException; |
| 65 | |
sakal | 79ede03 | 2016-06-14 05:33:18 -0700 | [diff] [blame] | 66 | void changeCaptureFormat(int width, int height, int framerate); |
| 67 | |
magjed | 0dc2316 | 2016-03-14 03:59:38 -0700 | [diff] [blame] | 68 | /** |
| 69 | * Perform any final cleanup here. No more capturing will be done after this call. |
| 70 | */ |
Magnus Jedvert | 5e7834e | 2016-02-12 17:05:29 +0100 | [diff] [blame] | 71 | void dispose(); |
arsany | b75f254 | 2016-08-31 18:50:52 -0700 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * @return true if-and-only-if this is a screen capturer. |
| 75 | */ |
| 76 | boolean isScreencast(); |
kjellander | af71655 | 2016-02-11 12:21:45 -0800 | [diff] [blame] | 77 | } |