Camera2Source choose with cameraId when streaming
Closed this issue · 8 comments
Hello.
Android TV app
There are two cameras (the facing is both Back)
How can i switch camera with cameraId.
Camera2Source camera2Source = new Camera2Source(mContext);
String currentCameraId = camera2Source.getCurrentCameraId();
if (!currentCameraId.equals(cameraId)) {
camera2Source.switchCamera(); // not work, because both Facing.Back.
camera2Source.openCameraId(cameraId); // Camera2ApiManager need be prepared, Camera2ApiManager not enabled
}
...
genericStream.changeVideoSource(camera2Source);
Hello,
First of all send the video source to genericStream (it is necessary to have the camera2source ready) also remember start preview or stream.
After that, try using openCameraId method.
public boolean prepareCameraStream(String cameraId) {
this.cameraId = cameraId;
camera2Source = new Camera2Source(appContext);
try {
prepared = rtspStream.prepareVideo(capSizeCamera.getWidth(), capSizeCamera.getHeight(), vBitrate, 15, 2, rotation) && rtspStream.prepareAudio(sampleRate, isStereo, aBitrate, true, true);
rtspStream.getGlInterface().setCameraOrientation(0);
rtspStream.changeVideoSource(camera2Source);
rtspStream.changeAudioSource(new MicrophoneSource());
return true;
} catch (IllegalArgumentException err) {
LogUtils.e(TAG, "prepareStream changeVideoSource");
err.printStackTrace();
stopStream();
stopSelf();
return false;
}
}
public void startStream(String endpoint) {
if (!rtspStream.isStreaming()) {
rtspStream.startStream(endpoint);
if (!TextUtils.isEmpty(cameraId) && camera2Source != null) {
camera2Source.openCameraId(cameraId);
}
}
}
if (screenService != null && screenService.prepareCameraStream(SharePrefManager.getInstance().getTwoTeacherViceCamera())) {
screenService.startStream(url);
}
call openCameraId after rtspStream.startStream(endpoint);
still got Camera2ApiManager need be prepared, Camera2ApiManager not enabled.
No, that code is incorrect.
Camera2Source should be set as param to rtspStream when you do new RtspStream
In prepareVideo you should select a resolution that you want no the width or height from Camera2Source
I put camera2Source as params of new RtspStream. it still freezed after calling .openCameraId(cameraId);
capsize is 640*480 . It can work well without openCameraId()
camera2Source = new Camera2Source(getBaseContext());
genericStream = new RtspStream(getBaseContext(), this, camera2Source, new MicrophoneSource());
genericStream.getStreamClient().setReTries(10);
genericStream.getStreamClient().setLogs(true);
genericStream.getGlInterface().setForceRender(true, 15);
genericStream.setAudioCodec(AudioCodec.AAC);
genericStream.setTimestampMode(TimestampMode.BUFFER, TimestampMode.BUFFER);
genericStream.setFpsListener(fps -> LogUtils.e(TAG, "FPS: " + fps));
prepared = genericStream.prepareVideo(640, 480, vBitrate, 15, 2, rotation) &&
genericStream.prepareAudio(sampleRate, isStereo, aBitrate, true, true);
genericStream.getGlInterface().setCameraOrientation(0);
...
genericStream.startStream(endpoint);
// still log Camera2ApiManager need be prepared, Camera2ApiManager not enabled
camera2Source.openCameraId(cameraId);
Ok, the code seems fine now.
I think this is a bug. I will fix it and report you back
Thanks. How can I use this commit
Try this gradle (last commit of master branch):
implementation 'com.github.pedroSG94.RootEncoder:library:56bc7534a9'