{
int resFfmpeg = 0;
+ std::unique_ptr<byte[]> pDstBuf;
std::unique_ptr<byte[]> pOutBuf;
+ SwsContext* pCvtCtxt;
+ AVFrame srcFrame;
+ AVFrame dstFrame;
+
SysTryReturn(NID_MEDIA, __pCodecCtx, null, E_INVALID_STATE,
"[E_INVALID_STATE] Not Constructed");
SysTryReturn(NID_MEDIA, resFfmpeg >= 0, null, E_SYSTEM,
"[E_SYSTEM] Could not copy image data to buffer!!");
+ if (__pixelFormat == MEDIA_PIXEL_FORMAT_NONE)
+ {
+ pCvtCtxt = sws_getContext(__pCodecCtx->width, __pCodecCtx->height, __pCodecCtx->pix_fmt,
+ __pCodecCtx->width, __pCodecCtx->height, PIX_FMT_BGRA,
+ SWS_BICUBIC, NULL, NULL, NULL);
+
+ memset(&srcFrame, 0, sizeof(srcFrame));
+ memset(&dstFrame, 0, sizeof(dstFrame));
+
+ outLength = avpicture_get_size(PIX_FMT_BGRA, __pCodecCtx->width, __pCodecCtx->height);
+ SysTryReturn(NID_MEDIA, outLength >= 0, null, E_INVALID_ARG,
+ "[E_FAILURE] Not able find size of dest frame for pix (%d), size (%d x %d)",
+ PIX_FMT_BGRA, __pCodecCtx->width, __pCodecCtx->height);
+
+ pDstBuf.reset(new (std::nothrow) byte[outLength]);
+ SysTryReturn(NID_MEDIA, pOutBuf.get() != null, null, E_OUT_OF_MEMORY,
+ "[E_OUT_OF_MEMORY] Memory allocation of %d bytes for output buffer failed!", outLength);
+
+ // Fill source frame
+ avpicture_fill((AVPicture*)&srcFrame, (byte*)pOutBuf.get(), __pCodecCtx->pix_fmt, __pCodecCtx->width, __pCodecCtx->height);
+
+ // Fill dest frame
+ avpicture_fill((AVPicture*)&dstFrame, (byte*)pDstBuf.get(), PIX_FMT_BGRA, __pCodecCtx->width, __pCodecCtx->height);
+
+ // Scaling
+ sws_scale(pCvtCtxt, srcFrame.data, srcFrame.linesize, 0, __pCodecCtx->height, dstFrame.data, dstFrame.linesize);
+
+ __pixelFormat = MEDIA_PIXEL_FORMAT_BGRA8888;
+ pOutBuf.swap(pDstBuf);
+ }
+
SetLastResult(E_SUCCESS);
return pOutBuf.release();
}