Android:MediaCodec:dequeueBuffer失败:BAD_VALUE(-22)

时间:2018-07-19 15:46:24

标签: android mediacodec

我正在尝试解码通过TCP发送的数据。

我成功地填写了解码器。 但是,当我尝试获取输出以将其呈现在surfaceView上时。我收到此错误:

dequeueBuffer failed: BAD_VALUE(-22)

此外,outputBufferIdde始终等于-1(稍后重试)

这是我的代码:

try {
    serverSocket = new ServerSocket(2968);
    Log.d(TAG,"server accept");
    Socket client = serverSocket.accept();
    InputStream inputStream = client.getInputStream();

    inputBuffersde = decodec.getInputBuffers();
    Log.d(TAG, "encodeDecode 1");
    DecoderRunnable decoderRunnable=new DecoderRunnable(decodec,infode);
    new Thread(decoderRunnable).start();


    while (true) {
        dataSizes=new byte[4];
        inputStream.read(dataSizes,0,4);
        dataSize=ByteBuffer.wrap(dataSizes).getInt();
        Log.d(TAG,"size: "+dataSize);
        totalLen=0;
        data= new byte[dataSize];

        for(;totalLen<dataSize;) {
            len=inputStream.read(data, totalLen, dataSize-totalLen);
            totalLen+=len;
            Log.d(TAG,"totalLen: "+totalLen+" ,len: "+len);
        }

        int inputBufferIdde = decodec.dequeueInputBuffer(5000);
        Log.d(TAG,"inputBufferIdde: "+inputBufferIdde);
        if (inputBufferIdde >= 0) {
            Log.d(TAG,"inputBufferIdde: "+inputBufferIdde);
            inputBuffersde[inputBufferIdde].clear();
            inputBuffersde[inputBufferIdde].rewind();
            inputBuffersde[inputBufferIdde].put(data);
            decodec.queueInputBuffer(inputBufferIdde, 0, inputBuffersde[inputBufferIdde].position(), System.nanoTime(), 0);
        }
    }
} catch(IOException e){
    e.printStackTrace();
}

DecoderRunnable看起来像这样:

public DecoderRunnable(MediaCodec decodec, MediaCodec.BufferInfo infode) {
    this.decodec = decodec;
    this.infode = infode;
}

@Override
public void run() {
    while(true){
        int outputBufferIdde = decodec.dequeueOutputBuffer(infode, 5000);
        Log.d(TAG, "outputBufferIdde : " + outputBufferIdde);
        if (outputBufferIdde >= 0) {
            Log.d(TAG, "encodeDecode 7");

            decodec.releaseOutputBuffer(outputBufferIdde, true);
        }
    }
}

有人可以帮我吗?

0 个答案:

没有答案