Skip to content

Commit

Permalink
avcodec/nvenc: use switch for nvenc_copy_frame
Browse files Browse the repository at this point in the history
  • Loading branch information
BtbN committed Sep 7, 2016
1 parent 5875a1e commit ac2bdbb
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions libavcodec/nvenc.c
Expand Up @@ -1292,7 +1292,8 @@ static int nvenc_copy_frame(AVCodecContext *avctx, NvencSurface *inSurf,
uint8_t *buf = lockBufferParams->bufferDataPtr;
int off = inSurf->height * lockBufferParams->pitch;

if (frame->format == AV_PIX_FMT_YUV420P) {
switch (frame->format) {
case AV_PIX_FMT_YUV420P:
av_image_copy_plane(buf, lockBufferParams->pitch,
frame->data[0], frame->linesize[0],
avctx->width, avctx->height);
Expand All @@ -1308,7 +1309,8 @@ static int nvenc_copy_frame(AVCodecContext *avctx, NvencSurface *inSurf,
av_image_copy_plane(buf, lockBufferParams->pitch >> 1,
frame->data[1], frame->linesize[1],
avctx->width >> 1, avctx->height >> 1);
} else if (frame->format == AV_PIX_FMT_NV12) {
break;
case AV_PIX_FMT_NV12:
av_image_copy_plane(buf, lockBufferParams->pitch,
frame->data[0], frame->linesize[0],
avctx->width, avctx->height);
Expand All @@ -1318,7 +1320,8 @@ static int nvenc_copy_frame(AVCodecContext *avctx, NvencSurface *inSurf,
av_image_copy_plane(buf, lockBufferParams->pitch,
frame->data[1], frame->linesize[1],
avctx->width, avctx->height >> 1);
} else if (frame->format == AV_PIX_FMT_P010) {
break;
case AV_PIX_FMT_P010:
av_image_copy_plane(buf, lockBufferParams->pitch,
frame->data[0], frame->linesize[0],
avctx->width << 1, avctx->height);
Expand All @@ -1328,7 +1331,8 @@ static int nvenc_copy_frame(AVCodecContext *avctx, NvencSurface *inSurf,
av_image_copy_plane(buf, lockBufferParams->pitch,
frame->data[1], frame->linesize[1],
avctx->width << 1, avctx->height >> 1);
} else if (frame->format == AV_PIX_FMT_YUV444P) {
break;
case AV_PIX_FMT_YUV444P:
av_image_copy_plane(buf, lockBufferParams->pitch,
frame->data[0], frame->linesize[0],
avctx->width, avctx->height);
Expand All @@ -1344,7 +1348,8 @@ static int nvenc_copy_frame(AVCodecContext *avctx, NvencSurface *inSurf,
av_image_copy_plane(buf, lockBufferParams->pitch,
frame->data[2], frame->linesize[2],
avctx->width, avctx->height);
} else if (frame->format == AV_PIX_FMT_YUV444P16) {
break;
case AV_PIX_FMT_YUV444P16:
av_image_copy_plane(buf, lockBufferParams->pitch,
frame->data[0], frame->linesize[0],
avctx->width << 1, avctx->height);
Expand All @@ -1360,11 +1365,14 @@ static int nvenc_copy_frame(AVCodecContext *avctx, NvencSurface *inSurf,
av_image_copy_plane(buf, lockBufferParams->pitch,
frame->data[2], frame->linesize[2],
avctx->width << 1, avctx->height);
} else if (frame->format == AV_PIX_FMT_0RGB32 || frame->format == AV_PIX_FMT_0BGR32) {
break;
case AV_PIX_FMT_0RGB32:
case AV_PIX_FMT_0BGR32:
av_image_copy_plane(buf, lockBufferParams->pitch,
frame->data[0], frame->linesize[0],
avctx->width << 2, avctx->height);
} else {
break;
default:
av_log(avctx, AV_LOG_FATAL, "Invalid pixel format!\n");
return AVERROR(EINVAL);
}
Expand Down

0 comments on commit ac2bdbb

Please sign in to comment.