androidvideo-streamingwebrtcrtcpeerconnectionusb-camera

Verifying that an org.WebRTC VideoFrame or NV21Buffer contain a valid (not corrupted) picture


I call the following method to stream frames from a USB Camera to org.WebRTC's Video Capture Observer. It works fine, except for some corrupted frames (green, or distorted grey frames) that appear every couple of seconds in the remote peer's video display. I want to verify that the nv21Buffer or the videoFrame are good pictures before sending them further to the observer.

    public void addFrame(ByteBuffer frame) {
        try {
            byte[] imageArray = new byte[frame.remaining()];
            frame.get(imageArray);
            NV21Buffer nv21Buffer = new NV21Buffer(imageArray, 640, 480, () -> JniCommon.nativeFreeByteBuffer(frame));
            VideoFrame videoFrame = new VideoFrame(nv21Buffer, 0, System.nanoTime());

            // before sending the videoFrame further, I need to validate if it is a good picture / frame
            capturerObs.onFrameCaptured(videoFrame);

        } catch (
                Exception e) {
            Log.d("addFrame", e.getMessage());
        }
    }

Is there any built in tools / methods to verify the goodness of the frames before sending them further?


Solution

  • Nv21 is raw pixels. In memory it is just an array of bytes. There are no checksums, or other structure that can be wrong. If it is the correct number of bytes it is “good”

    Your only option is to do some form of image processing and compare it to other frames, or develop a heuristic/algorithm to detect these. But there is not one built in.