Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Camera2Source choose with cameraId when streaming #1611

Open
Lyman92 opened this issue Oct 16, 2024 · 8 comments
Open

Camera2Source choose with cameraId when streaming #1611

Lyman92 opened this issue Oct 16, 2024 · 8 comments

Comments

@Lyman92
Copy link

Lyman92 commented Oct 16, 2024

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);
@pedroSG94
Copy link
Owner

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.

@Lyman92
Copy link
Author

Lyman92 commented Oct 17, 2024

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.

@pedroSG94
Copy link
Owner

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

@Lyman92
Copy link
Author

Lyman92 commented Oct 22, 2024

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); 

@pedroSG94
Copy link
Owner

Ok, the code seems fine now.
I think this is a bug. I will fix it and report you back

@pedroSG94
Copy link
Owner

Fixed here:
2dd78a0

@Lyman92
Copy link
Author

Lyman92 commented Oct 24, 2024

Thanks. How can I use this commit

@pedroSG94
Copy link
Owner

Try this gradle (last commit of master branch):

  implementation 'com.github.pedroSG94.RootEncoder:library:56bc7534a9'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants