From 98e9e8998f8fe1f9793610b58bb4e5e8f8145526 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Fri, 14 Jun 2013 14:48:34 +0100 Subject: variable size video decoder --- rotord/libavwrapper.cpp | 70 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 58 insertions(+), 12 deletions(-) (limited to 'rotord/libavwrapper.cpp') diff --git a/rotord/libavwrapper.cpp b/rotord/libavwrapper.cpp index 5e767e0..a5f2111 100755 --- a/rotord/libavwrapper.cpp +++ b/rotord/libavwrapper.cpp @@ -215,6 +215,33 @@ bool libav::decoder::openUsingInitializedContainer(enum PixelFormat formatParam) /* duration is in microsecs */ numFrames = (int)(( container->duration / (double)AV_TIME_BASE ) * pCtx->time_base.den + 0.5); + init_buffers_and_scaler(); + + /* Give some info on stderr about the file & stream */ + //dump_format(container, 0, fname, 0); + + previousFrameIndex = -1; + return true; +} +bool libav::decoder::reinit_buffers_and_scaler(){ + mutex.lock(); + if (NULL != Sctx) { + sws_freeContext(Sctx); + Sctx = NULL; + } + if (NULL != pRaw) { + av_free(pRaw); + pRaw = NULL; + } + if (NULL != pFrameRGB) { + av_free(pFrameRGB); + pFrameRGB = NULL; + } + mutex.unlock(); + init_buffers_and_scaler(); +} + +bool libav::decoder::init_buffers_and_scaler(){ /* Get framebuffers */ if (! (pRaw = avcodec_alloc_frame()) ) throw std::runtime_error(""); @@ -230,7 +257,7 @@ bool libav::decoder::openUsingInitializedContainer(enum PixelFormat formatParam) Sctx = NULL; } else { - numBytes = avpicture_get_size( format, pCtx->width, pCtx->height ); // RGB24 format + numBytes = avpicture_get_size( format, width, height ); // RGB24 format if (! (buffer = (uint8_t*)av_malloc(numBytes + FF_INPUT_BUFFER_PADDING_SIZE)) ) // RGB24 format throw std::runtime_error(""); if (! (blank = (uint8_t*)av_mallocz(avpicture_get_size(pCtx->pix_fmt,width,height))) ) // native codec format @@ -238,7 +265,7 @@ bool libav::decoder::openUsingInitializedContainer(enum PixelFormat formatParam) /* Init buffers */ avpicture_fill( (AVPicture * ) pFrameRGB, buffer, format, - pCtx->width, pCtx->height ); + width, height ); /* Init scale & convert */ if (! (Sctx=sws_getContext( @@ -252,12 +279,18 @@ bool libav::decoder::openUsingInitializedContainer(enum PixelFormat formatParam) NULL,NULL,NULL)) ) throw std::runtime_error(""); } +} - /* Give some info on stderr about the file & stream */ - //dump_format(container, 0, fname, 0); +bool libav::decoder::fetchFrame(int w, int h,int targetFrameIndex) +{ + if (w!=width||h!=height){ + width=w; + height=h; + cerr<<"libav::decoder reiniting to "<channels << " channels, a sample rate of " << codecContext->sample_rate << "Hz and "<sample_fmt<< " (aka "<< av_get_sample_fmt_name(codecContext->sample_fmt) << ") "<sample_fmt)) cerr<<"found planar audio"<sample_fmt)==1); + + if(isPlanar) { cerr<<"found planar audio"<format //format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames, enum AVSampleFormat for audio) - int ff=frame->format; + //int ff=frame->format; //uint64_t frame->channel_layout //Channel layout of the audio data. - uint64_t fcl=frame->channel_layout; + //uint64_t fcl=frame->channel_layout; //int frame->nb_extended_buf //Number of elements in extended_buf. - int fnb=frame->nb_extended_buf; + //int fnb=frame->nb_extended_buf; //int frame->decode_error_flags //decode error flags of the frame, set to a combination of FF_DECODE_ERROR_xxx flags if the decoder produced a frame, but there were errors during the decoding. - int fde=frame->decode_error_flags; + //int fde=frame->decode_error_flags; //uint16_t s=((uint16_t*) frame->buf[j]->data)[i]; - uint16_t s=((uint16_t*) frame->buf[0]->data)[j*channels+i]; + uint16_t s; + if (isPlanar) { + s=((uint16_t*) frame->buf[j]->data)[i]; + }else { + s=((uint16_t*) frame->buf[0]->data)[j*channels+i]; + } + + //where is audio grunge coming from? signed/ unsigned? doesn't seem to be byte order.. + // add +1 to data subscript with no effect + + //which? must be determined by format or layout of the channels //ALSO some kind of HEINOUS memory leak?? buffer[((sample_end+i)*frame->channels)+j]=s; -- cgit v1.2.3