Skip to content

Commit

Permalink
fix(videoframe): Added buffer alignment between lines
Browse files Browse the repository at this point in the history
Fixed warning from qTox#3527.
  • Loading branch information
Diadlo committed Jul 19, 2016
1 parent f970bb5 commit 824dd56
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions src/video/videoframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ QImage VideoFrame::toQImage(QSize size)

vpx_image *VideoFrame::toVpxImage()
{
vpx_image* img = vpx_img_alloc(nullptr, VPX_IMG_FMT_I420, width, height, 0);
vpx_image* img = vpx_img_alloc(nullptr, VPX_IMG_FMT_I420, width, height, 16);

if (!convertToYUV420())
return img;
Expand Down Expand Up @@ -130,7 +130,6 @@ bool VideoFrame::convertToRGB24(QSize size)
qWarning() << "None of the frames are valid! Did someone release us?";
return false;
}
//std::cout << "converting to RGB24" << std::endl;

if (size.isEmpty())
{
Expand All @@ -148,35 +147,37 @@ bool VideoFrame::convertToRGB24(QSize size)
av_frame_free(&frameRGB24);
}

frameRGB24=av_frame_alloc();
frameRGB24 = av_frame_alloc();
if (!frameRGB24)
{
qCritical() << "av_frame_alloc failed";
return false;
}

int imgBufferSize = av_image_get_buffer_size(AV_PIX_FMT_RGB24, size.width(), size.height(), 1);
int imgBufferSize = av_image_get_buffer_size(AV_PIX_FMT_RGB24, size.width(), size.height(), 16);
uint8_t* buf = (uint8_t*)av_malloc(imgBufferSize);
if (!buf)
{
qCritical() << "av_malloc failed";
av_frame_free(&frameRGB24);
return false;
}
frameRGB24->opaque = buf;


frameRGB24->opaque = buf;
uint8_t** data = frameRGB24->data;
int* linesize = frameRGB24->linesize;
av_image_fill_arrays(data, linesize, buf, AV_PIX_FMT_RGB24, size.width(), size.height(), 1);
av_image_fill_arrays(data, linesize, buf, AV_PIX_FMT_RGB24, size.width(), size.height(), 16);
frameRGB24->width = size.width();
frameRGB24->height = size.height();

// Bilinear is better for shrinking, bicubic better for upscaling
int resizeAlgo = size.width()<=width ? SWS_BILINEAR : SWS_BICUBIC;
int resizeAlgo = size.width() <= width ? SWS_BILINEAR : SWS_BICUBIC;

SwsContext *swsCtx = sws_getContext(width, height, (AVPixelFormat)pixFmt,
size.width(), size.height(), AV_PIX_FMT_RGB24,
resizeAlgo, nullptr, nullptr, nullptr);

sws_scale(swsCtx, (uint8_t const * const *)sourceFrame->data,
sourceFrame->linesize, 0, height,
frameRGB24->data, frameRGB24->linesize);
Expand Down Expand Up @@ -206,7 +207,6 @@ bool VideoFrame::convertToYUV420()
qCritical() << "None of the frames are valid! Did someone release us?";
return false;
}
//std::cout << "converting to YUV420" << std::endl;

frameYUV420=av_frame_alloc();
if (!frameYUV420)
Expand All @@ -215,7 +215,7 @@ bool VideoFrame::convertToYUV420()
return false;
}

int imgBufferSize = av_image_get_buffer_size(AV_PIX_FMT_RGB24, width, height, 1);
int imgBufferSize = av_image_get_buffer_size(AV_PIX_FMT_RGB24, width, height, 16);
uint8_t* buf = (uint8_t*)av_malloc(imgBufferSize);
if (!buf)
{
Expand All @@ -227,7 +227,7 @@ bool VideoFrame::convertToYUV420()

uint8_t** data = frameYUV420->data;
int* linesize = frameYUV420->linesize;
av_image_fill_arrays(data, linesize, buf, AV_PIX_FMT_YUV420P, width, height, 1);
av_image_fill_arrays(data, linesize, buf, AV_PIX_FMT_YUV420P, width, height, 16);

SwsContext *swsCtx = sws_getContext(width, height, (AVPixelFormat)pixFmt,
width, height, AV_PIX_FMT_YUV420P,
Expand Down
4 changes: 2 additions & 2 deletions src/widget/form/settings/avform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ void AVForm::onVideoModesIndexChanged(int index)
auto onGrabbed = [screenshotGrabber, devName, this] (QRect region)
{
VideoMode mode(region);
mode.width = mode.width / 2 * 2;
mode.height = mode.height / 2 * 2;
mode.width = mode.width / 16 * 16;
mode.height = mode.height / 16 * 16;

Settings::getInstance().setScreenRegion(mode.toRect());
Settings::getInstance().setScreenGrabbed(true);
Expand Down

0 comments on commit 824dd56

Please sign in to comment.