Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
style(corevideosource): Small style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Diadlo committed Jun 25, 2016
1 parent 9cfd678 commit ef641ce
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions src/video/corevideosource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
along with qTox. If not, see <http://www.gnu.org/licenses/>.
*/


extern "C" {
#include <libavcodec/avcodec.h>
#include <libavutil/imgutils.h>
}

#include "corevideosource.h"
#include "videoframe.h"

Expand All @@ -39,45 +39,49 @@ void CoreVideoSource::pushFrame(const vpx_image_t* vpxframe)
QMutexLocker locker(&biglock);

std::shared_ptr<VideoFrame> 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;
avframe->height = height;
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; i<height; i++)
memcpy(avframe->data[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; i<height/2; i++)
memcpy(avframe->data[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; i<height/2; i++)
memcpy(avframe->data[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<VideoFrame>(avframe);

av_free(buf);
emit frameAvailable(vframe);
}

Expand Down

0 comments on commit ef641ce

Please sign in to comment.