Android, use Mediacodec with libstreaming -
i've problem library
https://github.com/fyhertz/libstreaming
it allows send via wireless streaming of photocamera, use 3 methods: 2 mediacodec , 1 mediarecorder. modify it, , have use mediacodec;however first of tried code of example 2 of library, i've found same error: log tell me device can use mediacodec, set encoder , when test decoder fall , buffer filled -1.
this method in encoderdebugger class exception occurs, kind soul can me please?
private long decode(boolean withprefix) { int n =3, = 0, j = 0; long elapsed = 0, = timestamp(); int decinputindex = 0, decoutputindex = 0; bytebuffer[] decinputbuffers = mdecoder.getinputbuffers(); bytebuffer[] decoutputbuffers = mdecoder.getoutputbuffers(); bufferinfo info = new bufferinfo(); while (elapsed<3000000) { // feeds decoder nal unit if (i<nb_encoded) { decinputindex = mdecoder.dequeueinputbuffer(1000000/framerate); if (decinputindex>=0) { int l1 = decinputbuffers[decinputindex].capacity(); int l2 = mvideo[i].length; decinputbuffers[decinputindex].clear(); if ((withprefix && hasprefix(mvideo[i])) || (!withprefix && !hasprefix(mvideo[i]))) { check(l1>=l2, "the decoder input buffer not big enough (nal="+l2+", capacity="+l1+")."); decinputbuffers[decinputindex].put(mvideo[i],0,mvideo[i].length); } else if (withprefix && !hasprefix(mvideo[i])) { check(l1>=l2+4, "the decoder input buffer not big enough (nal="+(l2+4)+", capacity="+l1+")."); decinputbuffers[decinputindex].put(new byte[] {0,0,0,1}); decinputbuffers[decinputindex].put(mvideo[i],0,mvideo[i].length); } else if (!withprefix && hasprefix(mvideo[i])) { check(l1>=l2-4, "the decoder input buffer not big enough (nal="+(l2-4)+", capacity="+l1+")."); decinputbuffers[decinputindex].put(mvideo[i],4,mvideo[i].length-4); } mdecoder.queueinputbuffer(decinputindex, 0, l2, timestamp(), 0); i++; } else { if (verbose) log.d(tag,"no buffer available !7"); } } // tries decoded image decoutputindex = mdecoder.dequeueoutputbuffer(info, 1000000/framerate); if (decoutputindex == mediacodec.info_output_buffers_changed) { decoutputbuffers = mdecoder.getoutputbuffers(); } else if (decoutputindex == mediacodec.info_output_format_changed) { mdecoutputformat = mdecoder.getoutputformat(); } else if (decoutputindex>=0) { if (n>2) { // have encoded , decoded image ! int length = info.size; mdecodedvideo[j] = new byte[length]; decoutputbuffers[decoutputindex].clear(); decoutputbuffers[decoutputindex].get(mdecodedvideo[j], 0, length); // converts decoded frame nv21 converttonv21(j); if (j>=nb_decoded-1) { flushmediacodec(mdecoder); if (verbose) log.v(tag, "decoding "+n+" frames took "+elapsed/1000+" ms"); return elapsed; } j++; } mdecoder.releaseoutputbuffer(decoutputindex, false); n++; } elapsed = timestamp() - now; } throw new runtimeexception("the decoder did not decode anything."); }
here's suggestions:
(1) check settings of encoder , decoder, , make sure match. example, revolution , color format same.
(2) make sure first packet generated encoder has been sent , pushed decoder. packet defines basic settings of video stream.
(3) decoder buffers 5-10 frames. data in buffer invalid few hundred ms.
(4) while initiating decoder, set surface null. otherwise output buffer read surface , released automatically.
Comments
Post a Comment