Repository navigation
Expand file tree
/
Copy pathAbstractVideoCaptureController.java
More file actions
124 lines (101 loc) · 3.65 KB
/
Copy pathAbstractVideoCaptureController.java
File metadata and controls
124 lines (101 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package com.oney.WebRTCModule;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.core.util.Consumer;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
import org.webrtc.VideoCapturer;
public abstract class AbstractVideoCaptureController {
protected int targetWidth;
protected int targetHeight;
protected int targetFps;
protected int actualWidth;
protected int actualHeight;
protected int actualFps;
/**
* {@link VideoCapturer} which this controller manages.
*/
protected VideoCapturer videoCapturer;
protected CapturerEventsListener capturerEventsListener;
private String TAG = "AbsVidCaptControl";
public AbstractVideoCaptureController(int width, int height, int fps) {
this.targetWidth = width;
this.targetHeight = height;
this.targetFps = fps;
this.actualWidth = width;
this.actualHeight = height;
this.actualFps = fps;
}
public void initializeVideoCapturer() {
videoCapturer = createVideoCapturer();
}
@Nullable
public abstract String getDeviceId();
public void dispose() {
if (videoCapturer != null) {
videoCapturer.dispose();
videoCapturer = null;
}
}
public int getHeight() {
return actualHeight;
}
public int getWidth() {
return actualWidth;
}
public int getFrameRate() {
return actualFps;
}
public WritableMap getSettings() {
WritableMap settings = Arguments.createMap();
settings.putString("deviceId", getDeviceId());
settings.putString("groupId", "");
settings.putInt("height", getHeight());
settings.putInt("width", getWidth());
settings.putInt("frameRate", getFrameRate());
return settings;
}
public VideoCapturer getVideoCapturer() {
return videoCapturer;
}
public void startCapture() {
try {
videoCapturer.startCapture(targetWidth, targetHeight, targetFps);
} catch (RuntimeException e) {
// CameraCapturer throws only if it was not initialized, which we always do first. Other
// capturers may throw at runtime (for example screen capture). Log it: an error here
// never reaches CameraEventsHandler, so nothing else would report it.
Log.e(TAG, "[startCapture] failed", e);
}
}
public boolean stopCapture() {
try {
if (videoCapturer != null) {
videoCapturer.stopCapture();
}
return true;
} catch (InterruptedException e) {
return false;
}
}
public void applyConstraints(ReadableMap constraints, @Nullable Consumer<Exception> onFinishedCallback) {
if (onFinishedCallback != null) {
onFinishedCallback.accept(
new UnsupportedOperationException("This video track does not support applyConstraints."));
}
}
public void setCapturerEventsListener(CapturerEventsListener listener) {
this.capturerEventsListener = listener;
}
protected abstract VideoCapturer createVideoCapturer();
public interface CapturerEventsListener {
/** Called when the capturer is ended and in an irrecoverable state. */
public void onCapturerEnded();
/**
* Called when the capturer stops sending frames for a reason outside the app
* (muted = true), and when frames come back (muted = false). The track stays live.
*/
default void onCapturerMuteChanged(boolean muted) {}
}
}