diff --git a/src/video/corevideosource.cpp b/src/video/corevideosource.cpp index 0e76df947..cac6ce382 100644 --- a/src/video/corevideosource.cpp +++ b/src/video/corevideosource.cpp @@ -17,11 +17,11 @@ along with qTox. If not, see . */ - extern "C" { #include #include } + #include "corevideosource.h" #include "videoframe.h" @@ -39,15 +39,13 @@ void CoreVideoSource::pushFrame(const vpx_image_t* vpxframe) QMutexLocker locker(&biglock); std::shared_ptr vframe; - AVFrame* avframe; - uint8_t* buf; - int width = vpxframe->d_w, height = vpxframe->d_h; - int dstStride, srcStride, minStride; + int width = vpxframe->d_w; + int height = vpxframe->d_h; if (subscribers <= 0) return; - avframe = av_frame_alloc(); + AVFrame* avframe = av_frame_alloc(); if (!avframe) return; avframe->width = width; @@ -55,29 +53,35 @@ void CoreVideoSource::pushFrame(const vpx_image_t* vpxframe) avframe->format = AV_PIX_FMT_YUV420P; int imgBufferSize = av_image_get_buffer_size(AV_PIX_FMT_YUV420P, width, height, 1); - buf = (uint8_t*)av_malloc(imgBufferSize); + uint8_t* buf = (uint8_t*)av_malloc(imgBufferSize); if (!buf) { av_frame_free(&avframe); return; } - avframe->opaque = buf; uint8_t** data = avframe->data; int* linesize = avframe->linesize; av_image_fill_arrays(data, linesize, buf, AV_PIX_FMT_YUV420P, width, height, 1); - dstStride=avframe->linesize[0], srcStride=vpxframe->stride[0], minStride=std::min(dstStride, srcStride); - for (int i=0; idata[0]+dstStride*i, vpxframe->planes[0]+srcStride*i, minStride); - dstStride=avframe->linesize[1], srcStride=vpxframe->stride[1], minStride=std::min(dstStride, srcStride); - for (int i=0; idata[1]+dstStride*i, vpxframe->planes[1]+srcStride*i, minStride); - dstStride=avframe->linesize[2], srcStride=vpxframe->stride[2], minStride=std::min(dstStride, srcStride); - for (int i=0; idata[2]+dstStride*i, vpxframe->planes[2]+srcStride*i, minStride); + for (int i = 0; i < 3; i++) + { + int dstStride = avframe->linesize[i]; + int srcStride = vpxframe->stride[i]; + int minStride = std::min(dstStride, srcStride); + int size = (i == 0) ? height : height / 2; + + for (int j = 0; j < size; j++) + { + uint8_t *dst = avframe->data[i] + dstStride * j; + uint8_t *src = vpxframe->planes[i] + srcStride * j; + memcpy(dst, src, minStride); + } + } vframe = std::make_shared(avframe); + + av_free(buf); emit frameAvailable(vframe); }