2 u012967581 u012967581 于 2015.05.25 14:19 提问

MediaCodec UDP实时解码?显示不了

MediaCodec配置:

MediaFormat mediaFormat = MediaFormat.createVideoFormat(
"video/avc", w, h);

        mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, biterate);
        mediaFormat.setInteger(MediaFormat.KEY_FRAME_RATE, fps);
        mediaFormat
                .setInteger(
                        MediaFormat.KEY_COLOR_FORMAT,
                        MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420SemiPlanar);


        mediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 1);


        decoder = MediaCodec.createDecoderByType("video/avc");
        if (decoder == null) {
            Log.e("DecodeActivity", "createDecoderByType fail!");
            return;
        }
        decoder.configure(mediaFormat, surface, null,0);
        decoder.start();


拿到数据解码:

    @Override
    public void run() {

        DatagramSocket dsocket = null;
        try {
            dsocket = new DatagramSocket(9898);
        } catch (SocketException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        while (isHasNext) {
            System.out.println("=======开始循环");
            DatagramPacket dp = new DatagramPacket(bytes, size - 2);

                dsocket.receive(dp);

                decoderbyty(dp);
                }


    //开始解码
    private void decoderbyty(DatagramPacket packet) {
    byte[] outData = new byte[packet.getLength()];
    System.arraycopy(packet.getData(), packet.getOffset(), outData, 0,
            packet.getLength());

    ByteBuffer[] inputBuffers = decoder.getInputBuffers();
    ByteBuffer[] outputBuffers = decoder.getOutputBuffers();
    int inputBufferIndex = decoder.dequeueInputBuffer(0);
    if (inputBufferIndex >= 0) {

        ByteBuffer inputBuffer = inputBuffers[inputBufferIndex];
        inputBuffer.clear();
        inputBuffer.put(outData);
        decoder.queueInputBuffer(inputBufferIndex, 0, outData.length, 0, 0);
        // inputBuffer.put(yuv420Byte);
        // mediaCodec.queueInputBuffer(inputBufferIndex, 0,
        // yuv420Byte.length, 0, 0);
    }

    MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
    int outputBufferIndex = decoder.dequeueOutputBuffer(bufferInfo, 0);
    while (outputBufferIndex >= 0) {
        //ByteBuffer outputBuffer = outputBuffers[outputBufferIndex];
        /*
         * byte[] outData2 = new byte[bufferInfo.size];
         * outputBuffer.get(outData2); if (dataListOut != null)
         * dataListOut.add(outData2);
         */

        decoder.releaseOutputBuffer(outputBufferIndex, true);
        outputBufferIndex = decoder.dequeueOutputBuffer(bufferInfo, 0);
    }
}

现在出现的问题就是 surface上没反应,显示不了,
后台logo
05-25 14:11:27.007: I/System.out(11782): =======开始循环

05-25 14:11:27.007: D/VSP(172): H264Dec_decode_one_slice_data, 740, Exit hardware decoder
05-25 14:11:27.007: D/VSP(172): H264Dec_decode_one_slice_data, 757, int_status: 148
05-25 14:11:27.007: D/VSP(172): H264Dec_decode_one_slice_data, 803, (mb_x< 05-25 14:11:27.007: I/SPRDAVCDecoder(172): VSP_bind_cb, ref frame: 0xb73fce00, b73fce70; iRefCount=0
05-25 14:11:27.007: D/VSP(172): H264Dec_decode_one_slice_data, 814, finished decoding one frame
05-25 14:11:27.017: I/SPRDAVCDecoder(172): VSP_unbind_cb, ref frame: 0xb73fcf78, b73fcfe8; iRefCount=1
05-25 14:11:27.017: D/VSP(172): H264DecDecode_NALU, 914, finished decoding one NALU
05-25 14:11:27.017: D/VSP(172): H264DecDecode, 402, g_nalu_ptr->len: 17948, frame_dec_finish: 1,ret: 0
05-25 14:11:27.017: D/VSP(172): H264DecDecode, 440, exit decoder, error_flag: 0
05-25 14:11:27.017: D/VSP(172): VSP_RELEASE_Dev, 257, ret: 0
05-25 14:11:27.017: I/SPRDAVCDecoder(172): onQueueFilled, 1149, decRet: 0, 11ms, dec_out.frameEffective: 1, needIVOP: 0
05-25 14:11:27.017: I/SPRDAVCDecoder(172): onQueueFilled, 1224, dec_out.pBufferHeader: b73fcfe8, dec_out.mPicId: 1275
05-25 14:11:27.027: I/SPRDAVCDecoder(172): drainOneOutputBuffer, 1312, outHeader: b73fcfe8, outHeader->pBuffer: b73fcf78, outHeader->nOffset: 0, outHeader->nFlags: 16, outHeader->nTimeStamp: 0
05-25 14:11:27.027: I/SprdSimpleOMXComponent(172): fillThisBuffer, buffer: 0xb73fd070, header: 0xb73d0840, iRefCount: 0
05-25 14:11:27.027: I/SPRDAVCDecoder(172): onQueueFilled, 1032, outHeader:0xb73d0660, inHeader: 0xb73b72e0, len: 18016, nOffset: 0, time: 0, EOS: 0
05-25 14:11:27.027: D/VSP(172): VSP_ACQUIRE_Dev, 199
05-25 14:11:27.027: D/VSP(172): H264DecDecode, 381, g_stream_offset: 4, g_slice_datalen: 18012, g_nalu_ptr->len: 18012, destuffing_num: 0
05-25 14:11:27.027: D/VSP(172): H264Dec_Read_SPS_PPS_SliceHeader, 76, the first byte: 0x41.
05-25 14:11:27.027: D/VSP(172): H264Dec_decode_one_slice_data, 717, Start hardware decoder
05-25 14:11:27.037: I/System.out(11782): =======开始循环

7个回答

u012967581
u012967581   2015.05.25 14:21

大神指导下,找了几天的资料都没找到原因。

u012967581
u012967581   2015.05.26 14:24

有没用过的,求教啊..........我找了好久也没找到原因

u012967581
u012967581   2015.05.28 09:07

有木有知道的。。。。。。。。。一帧一帧解码是不是要加pps sps

u012967581
u012967581   2015.06.01 11:34

有木有人懂的 ,, 高手。。。。在哪?

qq_31537075
qq_31537075   2016.03.15 16:54

我用的TCP,和你遇到的问题一样,解码显示不了,你如何解决的??

langudu658
langudu658   2016.04.12 15:09

求楼主分享经验!!!

skyredni
skyredni   2017.06.09 16:09

楼主解决问题了吗?我现在正在做这个,不太明白,希望楼主可以指导一下。

Csdn user default icon
上传中...
上传图片
插入图片