java - Video Compression using Telegram's Code Android - Output surface wait timed out | MediaCodec -
the code i'm using repo : https://github.com/drklo/telegram/
in ~/src/main/java/org/telegram/android/video/mediacontroller class encoder , decoder instantiated, i'm getting "sufrace wait timed out exception" in outputsurface class no matter video i'm choosing.
tried on devices : nexus 4 (lollipop), asus zenfone 5 (kitkat), moto g (kitkat).
is there i'm missing? have not changed code @ all.
-- code snippet mediacontroller.java --
if (!decoderdone) { int decoderstatus = decoder.dequeueoutputbuffer(info, timeout_usec); if (decoderstatus == mediacodec.info_try_again_later) { decoderoutputavailable = false; } else if (decoderstatus == mediacodec.info_output_buffers_changed) { } else if (decoderstatus == mediacodec.info_output_format_changed) { mediaformat newformat = decoder.getoutputformat(); log.e("tmessages", "newformat = " + newformat); } else if (decoderstatus < 0) { throw new runtimeexception("unexpected result decoder.dequeueoutputbuffer: " + decoderstatus); } else { boolean dorender = false; if (build.version.sdk_int >= 18) { dorender = info.size != 0; } else { dorender = info.size != 0 || info.presentationtimeus != 0; } if (endtime > 0 && info.presentationtimeus >= endtime) { inputdone = true; decoderdone = true; dorender = false; info.flags |= mediacodec.buffer_flag_end_of_stream; } if (starttime > 0 && videotime == -1) { if (info.presentationtimeus < starttime) { dorender = false; log.e("tmessages", "drop frame starttime = " + starttime + " present time = " + info.presentationtimeus); } else { videotime = info.presentationtimeus; } } decoder.releaseoutputbuffer(decoderstatus, dorender); if (dorender) { boolean errorwait = false; try { outputsurface.awaitnewimage(); } catch (exception e) { log.e("wait",""+true); errorwait = true; log.e("tmessages", e.getmessage()); } if (!errorwait) { if (build.version.sdk_int >= 18) { outputsurface.drawimage(false); inputsurface.setpresentationtime(info.presentationtimeus * 1000); inputsurface.swapbuffers(); } else { int inputbufindex = encoder.dequeueinputbuffer(timeout_usec); if (inputbufindex >= 0) { outputsurface.drawimage(true); bytebuffer rgbbuf = outputsurface.getframe(); bytebuffer yuvbuf = encoderinputbuffers[inputbufindex]; yuvbuf.clear(); convertvideoframe(rgbbuf, yuvbuf, colorformat, resultwidth, resultheight, padding, swapuv); encoder.queueinputbuffer(inputbufindex, 0, buffersize, info.presentationtimeus, 0); } else { log.e("tmessages", "input buffer not available"); } } } } if ((info.flags & mediacodec.buffer_flag_end_of_stream) != 0) { decoderoutputavailable = false; log.e("tmessages", "decoder stream end"); if (build.version.sdk_int >= 18) { encoder.signalendofinputstream(); } else { int inputbufindex = encoder.dequeueinputbuffer(timeout_usec); if (inputbufindex >= 0) { encoder.queueinputbuffer(inputbufindex, 0, 1, info.presentationtimeus, mediacodec.buffer_flag_end_of_stream); } } } } }
-- code snippet outputsurface.java --
public void awaitnewimage() { final int timeout_ms = 2500; synchronized (mframesyncobject) { while (!mframeavailable) { try { mframesyncobject.wait(timeout_ms); if (!mframeavailable) { throw new runtimeexception("surface frame wait timed out"); } } catch (interruptedexception ie) { throw new runtimeexception(ie); } } mframeavailable = false; } mtexturerender.checkglerror("before updateteximage"); msurfacetexture.updateteximage(); } public void drawimage(boolean invert) { mtexturerender.drawframe(msurfacetexture, invert); } @override public void onframeavailable(surfacetexture st) { log.d("frame ","new frame"); synchronized (mframesyncobject) { if (mframeavailable) { throw new runtimeexception("mframeavailable set, frame dropped"); } mframeavailable = true; mframesyncobject.notifyall(); } }
these code snippets might not make lot of sense , can't post complete code here because huge. can find complete code here : https://github.com/316karan/mediacodec-tele
the problem never receive frame on outputsurface , goes in infinite loop timeouts.
Comments
Post a Comment