У меня есть этот пользовательский класс видеозахвата:
...
import org.webrtc.JavaI420Buffer;
import org.webrtc.SurfaceTextureHelper;
import org.webrtc.VideoCapturer;
import org.webrtc.VideoFrame;
import java.nio.ByteBuffer;
public class CustomCapturer implements VideoCapturer {
private SurfaceTextureHelper surTexture;
private Context appContext;
private org.webrtc.CapturerObserver capturerObs;
private Thread captureThread;
@Override
public void initialize(SurfaceTextureHelper surfaceTextureHelper, Context applicationContext, org.webrtc.CapturerObserver capturerObserver) {
surTexture = surfaceTextureHelper;
appContext = applicationContext;
capturerObs = capturerObserver;
}
public void addFrame(Bitmap frame_asbitmap) {
try {
final long captureTimeNs =
TimeUnit.MILLISECONDS.toNanos(SystemClock.elapsedRealtime());
long start = System.nanoTime();
JavaI420Buffer buffer = JavaI420Buffer.allocate(640, 480);
bitmapToI420(frame_asbitmap, buffer);
long frameTime = System.nanoTime() - start;
VideoFrame videoFrame = new VideoFrame(buffer, 0, frameTime);
capturerObs.onFrameCaptured(videoFrame);
} catch (Exception e) {
}
}
@Override
public void startCapture(int width, int height, int fps) {
captureThread = new Thread(() -> {
try {
long start = System.nanoTime();
capturerObs.onCapturerStarted(true);
} catch(InterruptedException ex) {
ex.printStackTrace();
}
});
captureThread.start();
}
@Override
public void stopCapture() {
captureThread.interrupt();
}
@Override
public void changeCaptureFormat(int width, int height, int fps) {
}
@Override
public void dispose() { }
@Override
public boolean isScreencast() {
return false;
}
}
Как использовать его в качестве источника для локальной видеодорожки? Я искал документацию по этому вопросу, но не мог найти. Я планирую подключить этот класс к локальной видеодорожке, а затем добавить к нему кадры с USB-камеры, используя метод addFrame(Bitmap frame_asbitmap)
из MainActivity
.