quantum6 / Android-USB-OTG-Camera

Apache License 2.0
120 stars 37 forks source link

IFrameCallback中的onframe没有被触发回调 #38

Open BruceZhang2017 opened 1 month ago

BruceZhang2017 commented 1 month ago

视频能够正常预览。而且mUVCCamera.setFrameCallback(mIFrameCallback, UVCCamera.FRAME_FORMAT_MJPEG); 也设置为MJPEG了。请问楼主是什么问题呢?

quantum6 commented 3 weeks ago

感觉应该是没有设置监听器导致的

BruceZhang2017 commented 3 weeks ago

@quantum6 是直接使用你的代码的。

BruceZhang2017 commented 3 weeks ago
    mUVCCameraView = (CameraViewInterface) mTextureView;
    mUVCCameraView.setCallback(this);
    mCameraHelper = UVCCameraHelper.getInstance();
    mCameraHelper.setDefaultFrameFormat(UVCCameraHelper.FRAME_FORMAT_MJPEG);
    mCameraHelper.initUSBMonitor(this, mUVCCameraView, listener);

    mCameraHelper.setOnPreviewFrameListener(new AbstractUVCCameraHandler.OnPreViewResultListener() {
        @Override
        public void onPreviewResult(byte[] data) {
            Log.d(TAG, "onPreviewResult: "+data.length);
            processFrame(data);
        }
    });

public void handleStartPreview(final Object surface) { if (DEBUG) Log.v(TAG_THREAD, "handleStartPreview:"); if ((mUVCCamera == null) || mIsPreviewing) return; try { mUVCCamera.setPreviewSize(mWidth, mHeight, 1, 31, mPreviewMode, mBandwidthFactor); // 获取USB Camera预览数据,使用NV21颜色会失真 // 无论使用YUV还是MPEG,setFrameCallback的设置效果一致 // mUVCCamera.setFrameCallback(mIFrameCallback, UVCCamera.PIXEL_FORMAT_NV21); mUVCCamera.setFrameCallback(mIFrameCallback, UVCCamera.FRAME_FORMAT_MJPEG);

        } catch (final IllegalArgumentException e) {
            try {
                // fallback to YUV mode
                mUVCCamera.setPreviewSize(mWidth, mHeight, 1, 31, UVCCamera.DEFAULT_PREVIEW_MODE, mBandwidthFactor);
            } catch (final IllegalArgumentException e1) {
                callOnError(e1);
                return;
            }
        }
        if (surface instanceof SurfaceHolder) {
            mUVCCamera.setPreviewDisplay((SurfaceHolder) surface);
        }
        if (surface instanceof Surface) {
            mUVCCamera.setPreviewDisplay((Surface) surface);
        } else {
            mUVCCamera.setPreviewTexture((SurfaceTexture) surface);
        }
        mUVCCamera.startPreview();
        mUVCCamera.updateCameraParams();
        synchronized (mSync) {
            mIsPreviewing = true;
        }
        callOnStartPreview();
    }
BruceZhang2017 commented 3 weeks ago

@quantum6 上面的代码。还需要什么代码吗?