MediaCodec failing on S7
<p>I have set a series of classes to decode H264 streaming video from a server and render it on a SurfaceView. Now this code is working perfectly on every device I've tried including the emulator, but suddenly I bought myself a S7 and in this device it does not work properly anymore.</p>

<p>The weird thing is that some times it will work perfectly, then some other times it will throw this error:</p>

<pre><code>06-15 16:41:40.249 13300-24605/cm.myapp E/ACodec: [OMX.Exynos.avc.dec] ERROR(0x90000012)
06-15 16:41:40.249 13300-24605/cm.myapp E/ACodec: signalError(omxError 0x90000012, internalError -2147483648)
06-15 16:41:40.249 13300-24604/cm.myapp E/MediaCodec: Codec reported err 0x90000012, actionCode 0, while in state 6
06-15 16:41:40.249 13300-24578/cm.myapp  W/MediaStreamerThread: Failed to draw media.
</code></pre>

<p>Sometimes it will crash on the dequeueInputBuffers call:</p>

<pre><code>java.lang.IllegalStateException
                                                                                at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
                                                                                at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:2379)
</code></pre>

<p>And then again, some other times it will throw this very different error:</p>

<pre><code>06-15 16:34:57.239 13300-16625/cm.myapp W/System.err: java.lang.IllegalArgumentException: The surface has been released
06-15 16:34:57.239 13300-16625/cm.myapp W/System.err:     at android.media.MediaCodec.native_configure(Native Method)
06-15 16:34:57.239 13300-16625/cm.myapp W/System.err:     at android.media.MediaCodec.configure(MediaCodec.java:1778)
                                                                        java.lang.RuntimeException: Could not create h264 decoder
</code></pre>

<p>These errors by themselves are not very verbose and thus I cannot figure out where the problem might be.</p>

<p>Again my code works perfectly on most devices but it's failing on this one. How is this possible? Any ideas?</p>

<p>This is my decoding code:</p>

<pre><code>public class H264Decoder
{
    static private final long TIMEOUT_US = 10000L;

    private MediaCodec mDecoder;
    private Surface mSurface;

    private static final List&lt;byte[]&gt; EMPTY_ENCODE_RESULT = new ArrayList&lt;&gt;();
    public void init()
    {

                try
                {
                    mDecoder = MediaCodec.createDecoderByType( "video/avc" );

                    MediaFormat mediaFormat = MediaFormat.createVideoFormat("video/avc", 640, 480);

                    mDecoder.configure(mediaFormat, mSurface, null, 0);
                    mDecoder.start();

                }
                catch(NoClassDefFoundError ex) {
                    ex.printStackTrace();
                    throw new RuntimeException("Could not create h264 decoder", ex);
                }        
    }

    public List&lt;byte[]&gt; offer(byte[] data)
    {
        List&lt;byte[]&gt; returnValue = new ArrayList&lt;&gt;();
        returnValue.add(decode(data, true));
        return returnValue; 
    }

    public void release()
    {
        assert mSurface != null;
        assert mDecoder != null;

        mDecoder.stop();
        mDecoder.release();
        mDecoder = null;
    }

    public H264Decoder(Surface surface)
    {
        mSurface = surface;
    }

    public byte[] decode(byte[] data, boolean updateRender)
    {
        if (mSurface == null)
        {
            return null;
        }
        // INPUT -----------------------------------------------------------------------------------

        int inputBufferIndex = mDecoder.dequeueInputBuffer(TIMEOUT_US);

        if (inputBufferIndex &gt;= 0)
        {
            // Get an input buffer from the codec, fill it with data, give it back
            ByteBuffer inputBuffer = mDecoder.getInputBuffers()[inputBufferIndex];
            inputBuffer.put(data);
            mDecoder.queueInputBuffer(inputBufferIndex, 0, data.length, 0, 0 );
        }

        // OUTPUT ----------------------------------------------------------------------------------

        MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
        int outputBufferIndex = mDecoder.dequeueOutputBuffer(info, TIMEOUT_US);

        if ( outputBufferIndex &gt;= 0 )
        {
            final ByteBuffer[] outputBuffer = mDecoder.getOutputBuffers();
            mDecoder.releaseOutputBuffer(outputBufferIndex, updateRender);

        }
        else if ( outputBufferIndex == MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED )
        {
            //outputBuffers = codec.getOutputBuffers();
        }
        else if ( outputBufferIndex == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED )
        {
            MediaFormat format = mDecoder.getOutputFormat();
        }
        return null;
    }
}
</code></pre>