[FFmpeg-devel] [PATCH v6 1/2] libavcodec/jpeg2000dec.c: Add functions and modify structs for PPT marker support

Michael Niedermayer michael at niedermayer.cc
Mon Mar 30 04:01:05 EEST 2020


On Sat, Mar 28, 2020 at 09:16:40PM +0530, gautamramk at gmail.com wrote:
> From: Gautam Ramakrishnan <gautamramk at gmail.com>
> 
> This patch adds support for the PPT marker. It breaks down the
> jpeg2000_decode_packet() function to decode headers and data
> separately.
> ---
>  libavcodec/jpeg2000dec.c | 202 +++++++++++++++++++++++++++++++++------
>  1 file changed, 172 insertions(+), 30 deletions(-)
> 

[...]

> @@ -927,30 +965,38 @@ static int getlblockinc(Jpeg2000DecoderContext *s)
>      return res;
>  }
>  
> -static int jpeg2000_decode_packet(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile, int *tp_index,
> -                                  Jpeg2000CodingStyle *codsty,
> -                                  Jpeg2000ResLevel *rlevel, int precno,
> -                                  int layno, uint8_t *expn, int numgbits)
> +static int jpeg2000_decode_packet_header(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
> +                                         int *tp_index,
> +                                         Jpeg2000CodingStyle *codsty,
> +                                         Jpeg2000ResLevel *rlevel, int precno,
> +                                         int layno, uint8_t *expn, int numgbits,
> +                                         int *process_data)
>  {
>      int bandno, cblkno, ret, nb_code_blocks;
> -    int cwsno;
>  
> -    if (layno < rlevel->band[0].prec[precno].decoded_layers)
> +    if (layno < rlevel->band[0].prec[precno].decoded_layers) {
> +        *process_data = 0;
>          return 0;
> +    }
>      rlevel->band[0].prec[precno].decoded_layers = layno + 1;
>  
> -    if (bytestream2_get_bytes_left(&s->g) == 0 && s->bit_index == 8) {
> -        if (*tp_index < FF_ARRAY_ELEMS(tile->tile_part) - 1) {
> -            s->g = tile->tile_part[++(*tp_index)].tpg;
> +    if (tile->has_ppt) {
> +        s->g = tile->packed_headers_stream;
> +    } else {
> +            s->g = tile->tile_part[*tp_index].tpg;
> +            if (bytestream2_get_bytes_left(&s->g) == 0 && s->bit_index == 8) {
> +                if (*tp_index < FF_ARRAY_ELEMS(tile->tile_part) - 1) {
> +                    s->g = tile->tile_part[++(*tp_index)].tpg;
> +            }
>          }
> +        if (bytestream2_peek_be32(&s->g) == JPEG2000_SOP_FIXED_BYTES)
> +            bytestream2_skip(&s->g, JPEG2000_SOP_BYTE_LENGTH);
>      }
>  
> -    if (bytestream2_peek_be32(&s->g) == JPEG2000_SOP_FIXED_BYTES)
> -        bytestream2_skip(&s->g, JPEG2000_SOP_BYTE_LENGTH);
> -
>      if (!(ret = get_bits(s, 1))) {
>          jpeg2000_flush(s);
> -        return 0;
> +        *process_data = 0;
> +        goto end;
>      } else if (ret < 0)
>          return ret;
>  
> @@ -1055,6 +1101,34 @@ static int jpeg2000_decode_packet(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
>          else
>              av_log(s->avctx, AV_LOG_ERROR, "EPH marker not found. instead %X\n", bytestream2_peek_be32(&s->g));
>      }
> +end:
> +    if (tile->has_ppt)
> +        tile->packed_headers_stream = s->g;
> +    else
> +        tile->tile_part[*tp_index].tpg = s->g;
> +    return 0;
> +}
> +
> +static int jpeg2000_decode_packet_data(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
> +                                       int *tp_index,
> +                                       Jpeg2000CodingStyle *codsty,
> +                                       Jpeg2000ResLevel *rlevel, int precno,
> +                                       int layno, uint8_t *expn, int numgbits)
> +{
> +    int bandno, cblkno, nb_code_blocks;
> +    int cwsno;
> +
> +    s->g = tile->tile_part[*tp_index].tpg;
> +    if (tile->has_ppt) {
> +        if (bytestream2_get_bytes_left(&s->g) == 0 && s->bit_index == 8) {
> +            if (*tp_index < FF_ARRAY_ELEMS(tile->tile_part) - 1) {
> +                s->g = tile->tile_part[++(*tp_index)].tpg;
> +            }
> +        }
> +        if (bytestream2_peek_be32(&s->g) == JPEG2000_SOP_FIXED_BYTES)
> +            bytestream2_skip(&s->g, JPEG2000_SOP_BYTE_LENGTH);
> +    }
> +
>  
>      for (bandno = 0; bandno < rlevel->nbands; bandno++) {
>          Jpeg2000Band *band = rlevel->band + bandno;
> @@ -1097,6 +1171,7 @@ static int jpeg2000_decode_packet(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
>              av_freep(&cblk->lengthinc);
>          }
>      }
> +    tile->tile_part[*tp_index].tpg = s->g;
>      return 0;
>  }

I think this function spliting should be in a seperate patch from adding 
ppt support.
It would make the changes more readable in the git log

thanks

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I have never wished to cater to the crowd; for what I know they do not
approve, and what they approve I do not know. -- Epicurus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20200330/b3499d95/attachment.sig>


More information about the ffmpeg-devel mailing list