2

我的手机上插入了一个外部 UVC 摄像头,我想将流发送到 RTSP 客户端。我已成功实施libstream。但问题是,当我打开我的应用程序时,它的 SurfaceView 是由 UVC 摄像头顶部的手机摄像头本机摄像头设置的,因此当我读取服务器端发送的帧时,会收到来自前置摄像头的帧。

从我注意到libstream从本机相机传感器读取图像并将其写入处理图像分组和编码的套接字。虽然,外部 UVC 相机已经有一个应用程序可以检索和处理来自 USB 传感器的图像。我一直在尝试导入库并将外部摄像头中的代码替换到 libstream 中,但没有成功。

private void openCamera() throws RuntimeException {
    final Semaphore lock = new Semaphore(0);
    final RuntimeException[] exception = new RuntimeException[1];
    mCameraThread = new Thread(new Runnable() {
        @Override
        public void run() {
            Looper.prepare();
            mCameraLooper = Looper.myLooper();
            try {
                mCamera = Camera.open(mCameraId);
            } catch (RuntimeException e) {
                exception[0] = e;
            } finally {
                lock.release();
                Looper.loop();
            }
        }
    });
    mCameraThread.start();
    lock.acquireUninterruptibly();
    if (exception[0] != null) throw new CameraInUseException(exception[0].getMessage());
}


protected synchronized void createCamera() throws RuntimeException {
    if (mSurfaceView == null)
        throw new InvalidSurfaceException("Invalid surface !");
    if (mSurfaceView.getHolder() == null || !mSurfaceReady)
        throw new InvalidSurfaceException("Invalid surface !");

    if (mCamera == null) {
        openCamera();
        mUpdated = false;
        mUnlocked = false;
        mCamera.setErrorCallback(new Camera.ErrorCallback() {
            @Override
            public void onError(int error, Camera camera) {
                // On some phones when trying to use the camera facing front the media server will die
                // Whether or not this callback may be called really depends on the phone
                if (error == Camera.CAMERA_ERROR_SERVER_DIED) {
                    // In this case the application must release the camera and instantiate a new one
                    Log.e(TAG,"Media server died !");
                    // We don't know in what thread we are so stop needs to be synchronized
                    mCameraOpenedManually = false;
                    stop();
                } else {
                    Log.e(TAG,"Error unknown with the camera: "+error);
                }
            }
        });

        try {

            // If the phone has a flash, we turn it on/off according to mFlashEnabled
            // setRecordingHint(true) is a very nice optimization if you plane to only use the Camera for recording
            Parameters parameters = mCamera.getParameters();
            if (parameters.getFlashMode()!=null) {
                parameters.setFlashMode(mFlashEnabled?Parameters.FLASH_MODE_TORCH:Parameters.FLASH_MODE_OFF);
            }
            parameters.setRecordingHint(true);
            mCamera.setParameters(parameters);
            mCamera.setDisplayOrientation(mOrientation);

            try {
                if (mMode == MODE_MEDIACODEC_API_2) {
                    mSurfaceView.startGLThread();
                    mCamera.setPreviewTexture(mSurfaceView.getSurfaceTexture());
                } else {
                    mCamera.setPreviewDisplay(mSurfaceView.getHolder());
                }
            } catch (IOException e) {
                throw new InvalidSurfaceException("Invalid surface !");
            }

        } catch (RuntimeException e) {
            destroyCamera();
            throw e;
        }

    }
}

@SuppressLint("InlinedApi")
public VideoStream(int camera) {
    super();
    setCamera(camera);
}

上面的代码就是所谓的手机摄像头,app使用UVC摄像头库进行图像处理,设置SurfaceView图像。我想知道是否有任何解决方法可以将来自 UVC 相机而不是本机移动相机的帧发送到 RSTP 客户端?

4

0 回答 0