java – Android camera 2 api BufferQueue has been abandoned-ThrowExceptions

Exception or error:

I am testing with new Android camera2 API and I want control each frame from camera. What I do for this is create an ImageReader and set up resolution and image format.

ImageReader imageReader = ImageReader.newInstance(1280,720,ImageFormat.YUV_420_888,1);
imageReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() {
    public void onImageAvailable(ImageReader reader) {
        Image image = reader.acquireLatestImage();
        Log.i(MainActivity.LOG_TAG,"imageReader: "+System.currentTimeMillis());

After that I create new CaptureRequest with parameter TEMPLATE_PREVIEW and add target to him imageReader. For cameraCaptureSession I create new setRepeatingRequest with this request

 try {
    final CaptureRequest.Builder builder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);


            new CameraCaptureSession.StateCallback() {
                public void onConfigured(CameraCaptureSession session) {
                    mSession = session;
                    try {
                    } catch (CameraAccessException e) {
                public void onConfigureFailed(CameraCaptureSession session) {

} catch (CameraAccessException e) {

When I opened camera and start view what I have with preview I get exception. But before exception it I got some preview image and after that I have exception

10-30 16:00:32.850    1390-1894/.camera2tutorial E/BufferQueueProducer﹕ [unnamed-1390-1] dequeueBuffer: BufferQueue has been abandoned
10-30 16:00:32.850    1390-1894/.camera2tutorial E/Legacy-CameraDevice-JNI﹕ LegacyCameraDevice_nativeProduceFrame: Error while producing frame No such device (-19).
10-30 16:00:32.850    1390-1894/.camera2tutorial W/SurfaceTextureRenderer﹕ Surface abandoned, dropping frame.
            at android.hardware.camera2.legacy.LegacyExceptionUtils.throwOnError(
            at android.hardware.camera2.legacy.LegacyCameraDevice.produceFrame(
            at android.hardware.camera2.legacy.SurfaceTextureRenderer.drawIntoSurfaces(
            at android.hardware.camera2.legacy.GLThreadManager$1.handleMessage(
            at android.os.Handler.dispatchMessage(
            at android.os.Looper.loop(

How can I fix this??

I am using a Samsung Galaxy S5 and Android API 21

How to solve:

Make sure you’re holding a reference to the ImageReader you create, probably wherever you have mSession defined.

The Surface you get from the ImageReader is roughly equivalent to a weak pointer – it won’t prevent the ImageReader from getting garbage collected. So most likely (based on your naming) the ImageReader is getting destroyed and the abandonment error then occurs.


I had the same problem when switching between activities in my app and that was after calling onSurfaceTextureDestroyed() which was only returning false, But what i did is i changed it to

public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
            Log.e(TAG, "onSurfaceTextureDestroyed");
            if(cameraDevice != null){

                cameraDevice = null;
            return false;

and that worked for me.


i found solution, this worked for me, infect error is in choosing correct size , so while using MediaRecorder.setVideoSize() use this method to choose optimal size

private static Size chooseOptimalSize(Size[] choices, int width, int height) {
        Size bigEnough = null;
        int minAreaDiff = Integer.MAX_VALUE;
        for (Size option : choices) {
            int diff = (width*height)-(option.getWidth()*option.getHeight()) ;
            if (diff >=0 && diff < minAreaDiff &&
                    option.getWidth() <= width &&
                    option.getHeight() <= height) {
                minAreaDiff = diff;
                bigEnough = option;
        if (bigEnough != null) {
            return bigEnough;
        } else {
            Arrays.sort(choices,new CompareSizeByArea());
            return choices[0];


Leave a Reply

Your email address will not be published. Required fields are marked *