blob: 8292fbd1cc1ddf867408c08380857edefafc445c [file] [log] [blame]
kjellanderaf716552016-02-11 12:21:45 -08001/*
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
11package org.webrtc;
12
Magnus Jedvert5e7834e2016-02-12 17:05:29 +010013import android.content.Context;
Magnus Jedvert5199c742016-02-18 13:09:54 +010014import java.util.List;
Magnus Jedvert5e7834e2016-02-12 17:05:29 +010015
16// Base interface for all VideoCapturers to implement.
Magnus Jedvert5e7834e2016-02-12 17:05:29 +010017public interface VideoCapturer {
18 // Interface used for providing callbacks to an observer.
Sami Kalliomäki05b552f2018-07-05 17:06:51 +020019 @Deprecated
Magnus Jedvert5e7834e2016-02-12 17:05:29 +010020 public interface CapturerObserver {
21 // Notify if the camera have been started successfully or not.
22 // Called on a Java thread owned by VideoCapturer.
23 void onCapturerStarted(boolean success);
Sami Kalliomaki16032122016-07-20 16:13:08 +020024 void onCapturerStopped();
Magnus Jedvert5e7834e2016-02-12 17:05:29 +010025
26 // Delivers a captured frame. Called on a Java thread owned by VideoCapturer.
sakalbe910462017-08-11 00:26:05 -070027 void onFrameCaptured(VideoFrame frame);
kjellanderaf716552016-02-11 12:21:45 -080028 }
29
Sami Kalliomäki05b552f2018-07-05 17:06:51 +020030 /** Deprecated, implementations should be update to implement the version below. */
31 @Deprecated
32 default void initialize(SurfaceTextureHelper surfaceTextureHelper, Context applicationContext,
33 CapturerObserver capturerObserver) {
34 throw new UnsupportedOperationException("Not implemented.");
35 }
36
magjed0dc23162016-03-14 03:59:38 -070037 /**
Magnus Jedvert27dcacd2016-07-07 10:00:22 +020038 * This function is used to initialize the camera thread, the android application context, and the
39 * capture observer. It will be called only once and before any startCapture() request. The
40 * camera thread is guaranteed to be valid until dispose() is called. If the VideoCapturer wants
41 * to deliver texture frames, it should do this by rendering on the SurfaceTexture in
Magnus Jedvert26b9e122018-05-02 14:41:22 +020042 * {@code surfaceTextureHelper}, register itself as a listener, and forward the frames to
43 * CapturerObserver.onFrameCaptured(). The caller still has ownership of {@code
44 * surfaceTextureHelper} and is responsible for making sure surfaceTextureHelper.dispose() is
45 * called. This also means that the caller can reuse the SurfaceTextureHelper to initialize a new
46 * VideoCapturer once the previous VideoCapturer has been disposed.
magjed0dc23162016-03-14 03:59:38 -070047 */
Sami Kalliomäki05b552f2018-07-05 17:06:51 +020048 // Our version of clang format doesn't understand default and messes up.
49 // clang-format off
50 default void initialize(SurfaceTextureHelper surfaceTextureHelper, Context applicationContext,
51 org.webrtc.CapturerObserver capturerObserver) {
52 initialize(surfaceTextureHelper, applicationContext, (CapturerObserver) capturerObserver);
53 }
Magnus Jedvert27dcacd2016-07-07 10:00:22 +020054
55 /**
Magnus Jedvert26b9e122018-05-02 14:41:22 +020056 * Start capturing frames in a format that is as close as possible to {@code width x height} and
57 * {@code framerate}.
Magnus Jedvert27dcacd2016-07-07 10:00:22 +020058 */
59 void startCapture(int width, int height, int framerate);
Magnus Jedvert5e7834e2016-02-12 17:05:29 +010060
magjed0dc23162016-03-14 03:59:38 -070061 /**
62 * Stop capturing. This function should block until capture is actually stopped.
63 */
Magnus Jedvert5e7834e2016-02-12 17:05:29 +010064 void stopCapture() throws InterruptedException;
65
sakal79ede032016-06-14 05:33:18 -070066 void changeCaptureFormat(int width, int height, int framerate);
67
magjed0dc23162016-03-14 03:59:38 -070068 /**
69 * Perform any final cleanup here. No more capturing will be done after this call.
70 */
Magnus Jedvert5e7834e2016-02-12 17:05:29 +010071 void dispose();
arsanyb75f2542016-08-31 18:50:52 -070072
73 /**
74 * @return true if-and-only-if this is a screen capturer.
75 */
76 boolean isScreencast();
kjellanderaf716552016-02-11 12:21:45 -080077}