[FFmpeg-devel] [PATCH] lavc/rawdec: Use 16-byte line alignment for B1W0 and B0W1 video in nut

Michael Niedermayer michael at niedermayer.cc
Fri Feb 5 02:46:15 CET 2016


On Thu, Feb 04, 2016 at 10:45:23PM +0100, Mats Peterson wrote:
> The line alignment for B1W0 and B0W1 1 bpp video in nut was
> previously 4 bytes, which generated alignment warning messages, not
> only for odd-width files. The alignment is now 16 bytes.
> 
> Also, made some simplifications, added some placeholders for the
> future PAL8 fourcc in nut, and added comments regarding the
> temporary nature of some of the code, which will be removed when
> PAL8 is fully implemented in nut (whenever that will be).
> 
> Mats
> 
> -- 
> Mats Peterson
> http://matsp888.no-ip.org/~mats/

>  rawdec.c |   78 +++++++++++++++++++++++++++++++++++++++++++++------------------
>  1 file changed, 56 insertions(+), 22 deletions(-)
> 45570d7ee012c2944315e66757cb45072d86176c  0001-lavc-rawdec-Use-16-byte-line-alignment-for-B1W0-and-.patch
> From 74681b2856afbf12a9588120c5039afdf02fa58b Mon Sep 17 00:00:00 2001
> From: Mats Peterson <matsp888 at yahoo.com>
> Date: Thu, 4 Feb 2016 22:44:33 +0100
> Subject: [PATCH] lavc/rawdec: Use 16-byte line alignment for B1W0 and B0W1 video in nut
> 
> ---
>  libavcodec/rawdec.c |   78 ++++++++++++++++++++++++++++++++++++---------------
>  1 file changed, 56 insertions(+), 22 deletions(-)
> 
> diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c
> index 93cbedf..525db4c 100644
> --- a/libavcodec/rawdec.c
> +++ b/libavcodec/rawdec.c
> @@ -41,7 +41,11 @@ typedef struct RawVideoContext {
>      AVBufferRef *palette;
>      int frame_size;  /* size of the frame in bytes */
>      int flip;
> -    int is_1_2_4_8_bpp; // 1, 2, 4 and 8 bpp in avi/mov
> +    int is_1_2_4_8_bpp; // 1, 2, 4 and 8 bpp in avi/mov, 1 and 8 bpp in nut
> +    int is_mono;
> +    int is_pal8;
> +    int is_nut_mono;
> +    int is_nut_pal8;
>      int is_yuv2;
>      int is_lt_16bpp; // 16bpp pixfmt and bits_per_coded_sample < 16
>      int tff;
> @@ -96,7 +100,7 @@ static av_cold int raw_init_decoder(AVCodecContext *avctx)
>              avpriv_set_systematic_pal2((uint32_t*)context->palette->data, avctx->pix_fmt);
>          else {
>              memset(context->palette->data, 0, AVPALETTE_SIZE);
> -            if (avctx->bits_per_coded_sample == 1)
> +            if (avctx->bits_per_coded_sample <= 1)
>                  memset(context->palette->data, 0xff, 4);
>          }
>      }
> @@ -108,11 +112,24 @@ static av_cold int raw_init_decoder(AVCodecContext *avctx)
>          avctx->codec_tag == MKTAG('W','R','A','W'))
>          context->flip = 1;
>  
> +    if (avctx->pix_fmt == AV_PIX_FMT_MONOWHITE ||
> +        avctx->pix_fmt == AV_PIX_FMT_MONOBLACK)
> +        context->is_mono = 1;
> +    else if (avctx->pix_fmt == AV_PIX_FMT_PAL8)
> +        context->is_pal8 = 1;
> +
> +    if (avctx->codec_tag == MKTAG('B','1','W','0') ||
> +        avctx->codec_tag == MKTAG('B','0','W','1'))
> +        context->is_nut_mono = 1;
> +    else if (avctx->codec_tag == MKTAG('P','A','L','8'))
> +        context->is_nut_pal8 = 1;
> +
>      if (avctx->codec_tag == AV_RL32("yuv2") &&
>          avctx->pix_fmt   == AV_PIX_FMT_YUYV422)
>          context->is_yuv2 = 1;
>  
> -    if (avctx->pix_fmt == AV_PIX_FMT_PAL8 && avctx->bits_per_coded_sample == 1)
> +    /* Temporary solution until PAL8 is implemented in nut */
> +    if (context->is_pal8 && avctx->bits_per_coded_sample == 1)
>          avctx->pix_fmt = AV_PIX_FMT_NONE;
>  
>      return 0;
> @@ -160,22 +177,34 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame,
>      const uint8_t *buf             = avpkt->data;
>      int buf_size                   = avpkt->size;
>      int linesize_align             = 4;
> -    int avpkt_stride;
> +    int stride;
>      int res, len;
>      int need_copy;
>  
>      AVFrame   *frame   = data;
>  
> +    if (avctx->width <= 0) {
> +        av_log(avctx, AV_LOG_ERROR, "width is not set\n");
> +        return AVERROR_INVALIDDATA;
> +    }
>      if (avctx->height <= 0) {
>          av_log(avctx, AV_LOG_ERROR, "height is not set\n");
>          return AVERROR_INVALIDDATA;
>      }
> -    avpkt_stride = avpkt->size / avctx->height;
>  
> -    if (avpkt_stride == 0) {
> -        av_log(avctx, AV_LOG_ERROR, "Packet too small (%d) height (%d)\n", avpkt->size, avctx->height);
> +    if (context->is_nut_mono)
> +        stride = avctx->width / 8 + (avctx->width & 7 ? 1 : 0);
> +    else if (context->is_nut_pal8)
> +        stride = avctx->width;
> +    else
> +        stride = avpkt->size / avctx->height;

stride can be 0 and cause division by 0 later

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Its not that you shouldnt use gotos but rather that you should write
readable code and code with gotos often but not always is less readable
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160205/4cafe477/attachment.sig>


More information about the ffmpeg-devel mailing list