INDExOS / media-for-mobile

Media for Mobile
Other
456 stars 176 forks source link

CameraCapture does not release all instances of Android's MediaCodec #24

Open bennnjamin opened 8 years ago

bennnjamin commented 8 years ago

Hi, I had an issue in my app where after stopping and starting the CameraCapture several times, it would crash. On some versions of Android, there is a hard limit to the number of instances of the hardware encoder you can instantiate using Android MediaCodec. I fixed it in CameraCapture.java, in stop(). Please see the comments I have added to the code in question.

public void stop() { super.stop(); if (previewRender != null) { /* commenting out this section works because in stop() another instance of MediaCodec is created. LinkedList videoEffects = videoEffector.getVideoEffects();

        videoEffector = androidMediaObjectFactory.createVideoEffector(); //additional instance of MediaCodec is created here when there should be none left
        videoEffector.getVideoEffects().addAll(videoEffects);
        videoEffector.enablePreview(previewRender);
       */
    }
    if (microphoneSource != null) {
        microphoneSource = null;
    }

}