diff options
Diffstat (limited to 'decoder.c')
-rw-r--r-- | decoder.c | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -74,6 +74,26 @@ cDecoder::cDecoder() : rbuf(50000), ac3dtsDecoder(&rbuf) exit(-1); } + rgbFrame = avcodec_alloc_frame(); + if (!rgbFrame) { + esyslog("[dxr3-decoder] failed to alloc rgbFrame"); + exit(-1); + } + + // reserve place for raw data for our rgbFrame + uint8_t *buffer; + int numBytes; + // determine required buffer size and allocate buffer + numBytes = avpicture_get_size(PIX_FMT_RGB24, contextVideo->width, contextVideo->height); + buffer = (uint8_t *)av_malloc(numBytes * sizeof(uint8_t)); + if (!buffer) { + esyslog("[dxr3-decoder] failed to alloc rgbFrame data"); + exit(-1); + } + + // ssociate the frame with our newly allocated buffer + avpicture_fill((AVPicture *)rgbFrame, buffer, PIX_FMT_RGB24, contextVideo->width, contextVideo->height); + lastBitrate = 0xff; // init with an invalid value - see checkMpegAudioHdr; } @@ -84,6 +104,11 @@ cDecoder::~cDecoder() // close codec, if it is open avcodec_close(contextAudio); avcodec_close(contextVideo); + + if (rgbFrame) { + av_free(rgbFrame->data); + av_free(rgbFrame); + } } // ================================== @@ -102,6 +127,27 @@ void cDecoder::Init() } } +AVFrame *cDecoder::decode(AVPacket *source, uint32_t width, uint32_t height) +{ + AVFrame frame; + int gotPicture; + + avcodec_decode_video2(contextVideo, &frame, &gotPicture, source); + + if (gotPicture) { + + SwsContext *swsContext = sws_getContext(contextVideo->width, contextVideo->height, + contextVideo->pix_fmt, width, height, PIX_FMT_RGB24, SWS_BILINEAR, 0, 0, 0); + + if (swsContext) { + sws_scale(swsContext, frame.data, frame.linesize, 0, contextVideo->height, rgbFrame->data, rgbFrame->linesize); + return rgbFrame; + } + } + + return NULL; +} + void cDecoder::decode(cDxr3PesFrame *frame, iAudio *audio) { int len, out_size; |