forked from livekit/react-native-webrtc
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAbstractVideoCaptureController.java
More file actions
115 lines (93 loc) · 3.17 KB
/
AbstractVideoCaptureController.java
File metadata and controls
115 lines (93 loc) · 3.17 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
package com.oney.WebRTCModule;
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;
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) {
// XXX This can only fail if we initialize the capturer incorrectly,
// which we don't. Thus, ignore any failures here since we trust
// ourselves.
}
}
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();
}
}