[FFmpeg-devel] 答复: [PATCH] RTP: get the buffer information of the RTP extension header.

2022-10-21 Thread Wujian(Chin)
Do experts have any good ideas on this fuction?

-邮件原件-
发件人: Wujian(Chin) 
发送时间: 2022年9月26日 14:48
收件人: ffmpeg-devel@ffmpeg.org
抄送: yangzhiyong (F) 
主题: Re: [FFmpeg-devel] [PATCH] RTP: get the buffer information of the RTP 
extension header.

Andreas:
>Wujian(Chin):
>> Signed-off-by: wujian_nanjing 
>> ---
>>  libavcodec/avpacket.c | 44 
>>  libavcodec/packet.h   | 17 +
>>  libavformat/demux.c   |  7 +++
>>  libavformat/rtpdec.c  | 37 -
>>  4 files changed, 96 insertions(+), 9 deletions(-)
>> 
>> diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index 
>> bcbc416..45c131a 100644
>> --- a/libavcodec/avpacket.c
>> +++ b/libavcodec/avpacket.c
>> @@ -46,6 +46,8 @@ void av_init_packet(AVPacket *pkt)
>>  pkt->opaque   = NULL;
>>  pkt->opaque_ref   = NULL;
>>  pkt->time_base= av_make_q(0, 1);
>> +pkt->ext  = NULL;
>> +pkt->extlen   = 0;
>>  }
>>  #endif
>>  
>> @@ -109,6 +111,46 @@ int av_new_packet(AVPacket *pkt, int size)
>>  return 0;
>>  }
>>  
>> +static void av_packet_free_ext(AVPacket *pkt) {
>> +if (!pkt)
>> +return;
>> +
>> +if (pkt->ext) {
> >+av_free(pkt->ext);
> >+pkt->ext = NULL;
> >+}
>> +
>> +pkt->extlen = 0;
>> +}
> >+
> >+int av_set_packet_ext(AVPacket *pkt, uint8_t *buf, int len) {
> >+if (!buf || (len <= 0))
> >+return 0;
> >+
>> +if (pkt->ext == buf) {
>> +pkt->extlen = len;
>> +return 0;
>> +}
>> +
>> +pkt->ext = av_malloc(len);
>> +pkt->extlen = len;
>> +(void)memcpy(pkt->ext, buf, len);
>> +
>> +return 0;
>> +}
>> +
>> +static int av_copy_packet_ext(AVPacket *pkt, const AVPacket *src) {
>> +pkt->ext = NULL;
>> +pkt->extlen = 0;
>> +
>> +av_set_packet_ext(pkt, src->ext, src->extlen);
>> +
>> +return 0;
>> +}
>> +
>>  void av_shrink_packet(AVPacket *pkt, int size)  {
>>  if (pkt->size <= size)
>> @@ -422,6 +464,7 @@ int av_packet_copy_props(AVPacket *dst, const 
>> AVPacket *src)  void av_packet_unref(AVPacket *pkt)  {
>>  av_packet_free_side_data(pkt);
>> +av_packet_free_ext(pkt);
>>  av_buffer_unref(>opaque_ref);
>>  av_buffer_unref(>buf);
>>  get_packet_defaults(pkt);
>> @@ -456,6 +499,7 @@ int av_packet_ref(AVPacket *dst, const AVPacket *src)
>>  }
>>  
>>  dst->size = src->size;
>> +av_copy_packet_ext(dst, src);
>>  
>>  return 0;
>>  fail:
>> diff --git a/libavcodec/packet.h b/libavcodec/packet.h index 
>> 404d520..137d1fa 100644
>> --- a/libavcodec/packet.h
>> +++ b/libavcodec/packet.h
>> @@ -374,6 +374,13 @@ typedef struct AVPacket {
>>  uint8_t *data;
>>  int   size;
>>  int   stream_index;
>> +
>> +/**
>> + * Extension header data and size
>> + */
>> +uint8_t *ext;
>> +uint32_t extlen;
>> +
>>  /**
>>   * A combination of AV_PKT_FLAG values
>>   */
>> @@ -523,6 +530,16 @@ void av_init_packet(AVPacket *pkt);  int 
>> av_new_packet(AVPacket *pkt, int size);
>>  
>>  /**
>> + * Allocate the ext data from buf with len lenght.
>> + * Make sure pkt->ext is null, otherwise cause memory leak.
>> + *
>> + * @param pkt packet
>> + * @param buf buffer with ext data
>> + * @param len buffer size
>> + */
>> +int av_set_packet_ext(AVPacket *pkt, uint8_t *buf, int len);
>> +
>> +/**
>>   * Reduce packet size, correctly zeroing padding
>>   *
>>   * @param pkt packet
>> diff --git a/libavformat/demux.c b/libavformat/demux.c index
>> 1620716..2a8b201 100644
>> --- a/libavformat/demux.c
>> +++ b/libavformat/demux.c
>> @@ -1175,6 +1175,13 @@ static int parse_packet(AVFormatContext *s, AVPacket 
>> *pkt,
>>  pkt->side_data_elems= 0;
>>  }
>>  
>> +if (pkt->extlen > 0) {
>> +out_pkt->extlen = pkt->extlen;
>> +out_pkt->ext = pkt->ext;
>> +pkt->extlen = 0;
>> +pkt->ext = NULL;
>> +}
>> +
>>  /* set the duration */
>>  out_pkt->duration = (sti->parser->flags & 
>> PARSER_FLAG_COMPLETE_FRAMES) ? pkt->duration : 0;
>>  if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { diff 
>> --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c index
>> fa7544c..2a539e0 100644
>> --- a/libavformat/rtpdec.c
>> +++ b/libavformat/rtpdec.c
>> @@ -699,13 +699,14 @@ static int
>> rtp_parse_packet_internal(RTPDemuxContext *s, AVPacket *pkt,  {
>>  unsigned int ssrc;
>>  int payload_type, seq, flags = 0;
>> -int ext, csrc;
>> +int has_ext, csrc, extlen;
>> +uint8_t *extbuf;
>>  AVStream *st;
>>  uint32_t timestamp;
>>  int rv = 0;
>>  
>>  csrc = buf[0] & 0x0f;
>> -ext  = buf[0] & 0x10;
>> +has_ext  = buf[0] & 0x10;
>>  payload_type = buf[1] & 0x7f;
>>  if (buf[1] & 0x80)
>>  flags |= RTP_FLAG_MARKER;
>> @@ -744,18 +745,25 @@ static int 

Re: [FFmpeg-devel] [PATCH v2 02/24] avcodec/eamad: Don't use IDCTDSP-API unnecessarily

2022-10-21 Thread Peter Ross
On Fri, Oct 21, 2022 at 10:12:38PM +0200, Andreas Rheinhardt wrote:
> The eamad decoder uses a custom IDCT and actually does not
> use the IDCTDSP API at all. Somehow it was nevertheless
> used to simply apply the identity permutation on ff_zigzag_direct.
> This commit stops doing so.

i think this dates back to when libavcodec only had one big dsp module.
this patch set looks good.

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 1/2] avcodec/cbs: Remove CBS_CONTENT_TYPE_POD

2022-10-21 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> It is equivalent to CBS_CONTENT_TYPE_INTERNAL_REFS
> with nb_offsets equal to zero.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/cbs.c  | 18 --
>  libavcodec/cbs_internal.h | 21 -
>  2 files changed, 16 insertions(+), 23 deletions(-)
> 
> diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
> index 8d6e3c3442..504197e06d 100644
> --- a/libavcodec/cbs.c
> +++ b/libavcodec/cbs.c
> @@ -839,12 +839,10 @@ void ff_cbs_delete_unit(CodedBitstreamFragment *frag,
>  static void cbs_default_free_unit_content(void *opaque, uint8_t *data)
>  {
>  const CodedBitstreamUnitTypeDescriptor *desc = opaque;
> -if (desc->content_type == CBS_CONTENT_TYPE_INTERNAL_REFS) {
> -int i;
> -for (i = 0; i < desc->type.ref.nb_offsets; i++) {
> -void **ptr = (void**)(data + desc->type.ref.offsets[i]);
> -av_buffer_unref((AVBufferRef**)(ptr + 1));
> -}
> +
> +for (int i = 0; i < desc->type.ref.nb_offsets; i++) {
> +void **ptr = (void**)(data + desc->type.ref.offsets[i]);
> +av_buffer_unref((AVBufferRef**)(ptr + 1));
>  }
>  av_free(data);
>  }
> @@ -981,14 +979,6 @@ static int cbs_clone_unit_content(CodedBitstreamContext 
> *ctx,
>  return AVERROR(ENOSYS);
>  
>  switch (desc->content_type) {
> -case CBS_CONTENT_TYPE_POD:
> -ref = av_buffer_alloc(desc->content_size);
> -if (!ref)
> -return AVERROR(ENOMEM);
> -memcpy(ref->data, unit->content, desc->content_size);
> -err = 0;
> -break;
> -
>  case CBS_CONTENT_TYPE_INTERNAL_REFS:
>  err = cbs_clone_internal_refs_unit_content(, unit, desc);
>  break;
> diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
> index 5ccba3c901..045df91744 100644
> --- a/libavcodec/cbs_internal.h
> +++ b/libavcodec/cbs_internal.h
> @@ -31,9 +31,7 @@
>  
>  
>  enum CBSContentType {
> -// Unit content is a simple structure.
> -CBS_CONTENT_TYPE_POD,
> -// Unit content contains some references to other structures, but all
> +// Unit content may contain some references to other structures, but all
>  // managed via buffer reference counting.  The descriptor defines the
>  // structure offsets of every buffer reference.
>  CBS_CONTENT_TYPE_INTERNAL_REFS,
> @@ -78,9 +76,12 @@ typedef const struct CodedBitstreamUnitTypeDescriptor {
>  size_t content_size;
>  
>  union {
> +// This union's state is determined by content_type:
> +// ref for CBS_CONTENT_TYPE_INTERNAL_REFS,
> +// complex for CBS_CONTENT_TYPE_COMPLEX.
>  struct {
> -// Number of entries in the ref_offsets array.  Only nonzero
> -// if the content_type is CBS_CONTENT_TYPE_INTERNAL_REFS.
> +// Number of entries in the ref_offsets array.
> +// May be zero, then the structure is POD-like.
>  int nb_offsets;
>  // The structure must contain two adjacent elements:
>  //   type*field;
> @@ -191,18 +192,20 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, 
> PutBitContext *pbc,
>  #define MIN_INT_BITS(length) (-(INT64_C(1) << ((length) - 1)))
>  
>  #define TYPE_LIST(...) { __VA_ARGS__ }
> -#define CBS_UNIT_TYPE_POD(type, structure) { \
> +#define CBS_UNIT_TYPE_POD(type_, structure) { \
>  .nb_unit_types  = 1, \
> -.unit_type.list = { type }, \
> -.content_type   = CBS_CONTENT_TYPE_POD, \
> +.unit_type.list = { type_ }, \
> +.content_type   = CBS_CONTENT_TYPE_INTERNAL_REFS, \
>  .content_size   = sizeof(structure), \
> +.type.ref   = { .nb_offsets = 0 }, \
>  }
>  #define CBS_UNIT_RANGE_POD(range_start, range_end, structure) { \
>  .nb_unit_types = CBS_UNIT_TYPE_RANGE, \
>  .unit_type.range.start = range_start, \
>  .unit_type.range.end   = range_end, \
> -.content_type  = CBS_CONTENT_TYPE_POD, \
> +.content_type  = CBS_CONTENT_TYPE_INTERNAL_REFS, \
>  .content_size  = sizeof(structure), \
> +.type.ref  = { .nb_offsets = 0 }, \
>  }
>  
>  #define CBS_UNIT_TYPES_INTERNAL_REF(types, structure, ref_field) { \

Will apply this patchset tonight unless there are objections.

- Andreas

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 24/24] avcodec/mpegvideo: Don't use ScanTable where unnecessary

2022-10-21 Thread Andreas Rheinhardt
For the intra_[hv]_scantables, only ScanTable.permutated
is used, so one only needs to keep that.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/ituh263dec.c|  4 ++--
 libavcodec/mpeg4videodec.c | 28 ++--
 libavcodec/mpeg4videoenc.c |  4 ++--
 libavcodec/mpegvideo.c |  6 --
 libavcodec/mpegvideo.h |  4 ++--
 libavcodec/msmpeg4.c   |  6 --
 libavcodec/msmpeg4dec.c|  4 ++--
 libavcodec/wmv2.c  |  8 
 8 files changed, 38 insertions(+), 26 deletions(-)

diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index 200de8527e..2164cd7346 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -544,9 +544,9 @@ static int h263_decode_block(MpegEncContext * s, int16_t * 
block,
 i = 0;
 if (s->ac_pred) {
 if (s->h263_aic_dir)
-scan_table = s->intra_v_scantable.permutated; /* left */
+scan_table = s->permutated_intra_v_scantable; /* left */
 else
-scan_table = s->intra_h_scantable.permutated; /* top */
+scan_table = s->permutated_intra_h_scantable; /* top */
 }
 } else if (s->mb_intra) {
 /* DC coef */
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index c4f268c534..4ab558b46f 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -1327,9 +1327,9 @@ static inline int mpeg4_decode_block(Mpeg4DecContext 
*ctx, int16_t *block,
 }
 if (s->ac_pred) {
 if (dc_pred_dir == 0)
-scan_table = s->intra_v_scantable.permutated;  /* left */
+scan_table = s->permutated_intra_v_scantable;  /* left */
 else
-scan_table = s->intra_h_scantable.permutated;  /* top */
+scan_table = s->permutated_intra_h_scantable;  /* top */
 } else {
 scan_table = s->intra_scantable.permutated;
 }
@@ -3258,13 +3258,17 @@ static int decode_vop_header(Mpeg4DecContext *ctx, 
GetBitContext *gb,
 if (s->alternate_scan) {
 ff_init_scantable(s->idsp.idct_permutation, >inter_scantable,   
ff_alternate_vertical_scan);
 ff_init_scantable(s->idsp.idct_permutation, >intra_scantable,   
ff_alternate_vertical_scan);
-ff_init_scantable(s->idsp.idct_permutation, >intra_h_scantable, 
ff_alternate_vertical_scan);
-ff_init_scantable(s->idsp.idct_permutation, >intra_v_scantable, 
ff_alternate_vertical_scan);
+ff_permute_scantable(s->permutated_intra_h_scantable, 
ff_alternate_vertical_scan,
+ s->idsp.idct_permutation);
+ff_permute_scantable(s->permutated_intra_v_scantable, 
ff_alternate_vertical_scan,
+ s->idsp.idct_permutation);
 } else {
 ff_init_scantable(s->idsp.idct_permutation, >inter_scantable,   
ff_zigzag_direct);
 ff_init_scantable(s->idsp.idct_permutation, >intra_scantable,   
ff_zigzag_direct);
-ff_init_scantable(s->idsp.idct_permutation, >intra_h_scantable, 
ff_alternate_horizontal_scan);
-ff_init_scantable(s->idsp.idct_permutation, >intra_v_scantable, 
ff_alternate_vertical_scan);
+ff_permute_scantable(s->permutated_intra_h_scantable, 
ff_alternate_horizontal_scan,
+ s->idsp.idct_permutation);
+ff_permute_scantable(s->permutated_intra_v_scantable, 
ff_alternate_vertical_scan,
+ s->idsp.idct_permutation);
 }
 
 /* Skip at this point when only parsing since the remaining
@@ -3432,13 +3436,17 @@ static int decode_studio_vop_header(Mpeg4DecContext 
*ctx, GetBitContext *gb)
 if (s->alternate_scan) {
 ff_init_scantable(s->idsp.idct_permutation, >inter_scantable,   
ff_alternate_vertical_scan);
 ff_init_scantable(s->idsp.idct_permutation, >intra_scantable,   
ff_alternate_vertical_scan);
-ff_init_scantable(s->idsp.idct_permutation, >intra_h_scantable, 
ff_alternate_vertical_scan);
-ff_init_scantable(s->idsp.idct_permutation, >intra_v_scantable, 
ff_alternate_vertical_scan);
+ff_permute_scantable(s->permutated_intra_h_scantable, 
ff_alternate_vertical_scan,
+ s->idsp.idct_permutation);
+ff_permute_scantable(s->permutated_intra_v_scantable, 
ff_alternate_vertical_scan,
+ s->idsp.idct_permutation);
 } else {
 ff_init_scantable(s->idsp.idct_permutation, >inter_scantable,   
ff_zigzag_direct);
 ff_init_scantable(s->idsp.idct_permutation, >intra_scantable,   
ff_zigzag_direct);
-ff_init_scantable(s->idsp.idct_permutation, >intra_h_scantable, 
ff_alternate_horizontal_scan);
-ff_init_scantable(s->idsp.idct_permutation, >intra_v_scantable, 
ff_alternate_vertical_scan);
+ff_permute_scantable(s->permutated_intra_h_scantable, 
ff_alternate_horizontal_scan,
+ s->idsp.idct_permutation);
+

[FFmpeg-devel] [PATCH v2 23/24] avcodec/mpegvideo: Move ASM-offset warning to its proper place

2022-10-21 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.h | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 60d2ec751e..6adf724dac 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -77,13 +77,14 @@ typedef struct MpegEncContext {
 
 /* scantables */
 ScanTable inter_scantable; ///< if inter == intra then intra should be 
used to reduce the cache usage
-ScanTable intra_scantable;
-ScanTable intra_h_scantable;
-ScanTable intra_v_scantable;
 
 /* WARNING: changes above this line require updates to hardcoded
  *  offsets used in ASM. */
 
+ScanTable intra_scantable;
+ScanTable intra_h_scantable;
+ScanTable intra_v_scantable;
+
 struct AVCodecContext *avctx;
 /* The following pointer is intended for codecs sharing code
  * between decoder and encoder and in need of a common context to do so. */
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 22/24] avcodec/eatgq: Move transient GetByteContext from context to stack

2022-10-21 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/eatgq.c | 39 ---
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/libavcodec/eatgq.c b/libavcodec/eatgq.c
index 627615b4e8..89e9f20880 100644
--- a/libavcodec/eatgq.c
+++ b/libavcodec/eatgq.c
@@ -45,7 +45,6 @@ typedef struct TgqContext {
 int width, height;
 int qtable[64];
 DECLARE_ALIGNED(16, int16_t, block)[6][64];
-GetByteContext gb;
 } TgqContext;
 
 static av_cold int tgq_decode_init(AVCodecContext *avctx)
@@ -147,34 +146,35 @@ static void tgq_idct_put_mb_dconly(TgqContext *s, AVFrame 
*frame,
 }
 }
 
-static int tgq_decode_mb(TgqContext *s, AVFrame *frame, int mb_y, int mb_x)
+static int tgq_decode_mb(TgqContext *s, GetByteContext *gbyte,
+ AVFrame *frame, int mb_y, int mb_x)
 {
 int mode;
 int i;
 int8_t dc[6];
 
-mode = bytestream2_get_byte(>gb);
+mode = bytestream2_get_byte(gbyte);
 if (mode > 12) {
 GetBitContext gb;
-int ret = init_get_bits8(, s->gb.buffer, 
FFMIN(bytestream2_get_bytes_left(>gb), mode));
+int ret = init_get_bits8(, gbyte->buffer, 
FFMIN(bytestream2_get_bytes_left(gbyte), mode));
 if (ret < 0)
 return ret;
 
 for (i = 0; i < 6; i++)
 tgq_decode_block(s, s->block[i], );
 tgq_idct_put_mb(s, s->block, frame, mb_x, mb_y);
-bytestream2_skip(>gb, mode);
+bytestream2_skip(gbyte, mode);
 } else {
 if (mode == 3) {
-memset(dc, bytestream2_get_byte(>gb), 4);
-dc[4] = bytestream2_get_byte(>gb);
-dc[5] = bytestream2_get_byte(>gb);
+memset(dc, bytestream2_get_byte(gbyte), 4);
+dc[4] = bytestream2_get_byte(gbyte);
+dc[5] = bytestream2_get_byte(gbyte);
 } else if (mode == 6) {
-bytestream2_get_buffer(>gb, dc, 6);
+bytestream2_get_buffer(gbyte, dc, 6);
 } else if (mode == 12) {
 for (i = 0; i < 6; i++) {
-dc[i] = bytestream2_get_byte(>gb);
-bytestream2_skip(>gb, 1);
+dc[i] = bytestream2_get_byte(gbyte);
+bytestream2_skip(gbyte, 1);
 }
 } else {
 av_log(s->avctx, AV_LOG_ERROR, "unsupported mb mode %i\n", mode);
@@ -202,6 +202,7 @@ static int tgq_decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
 const uint8_t *buf = avpkt->data;
 int buf_size   = avpkt->size;
 TgqContext *s  = avctx->priv_data;
+GetByteContext gbyte;
 int x, y, ret;
 int big_endian;
 
@@ -210,21 +211,21 @@ static int tgq_decode_frame(AVCodecContext *avctx, 
AVFrame *frame,
 return AVERROR_INVALIDDATA;
 }
 big_endian = AV_RL32([4]) > 0x000F;
-bytestream2_init(>gb, buf + 8, buf_size - 8);
+bytestream2_init(, buf + 8, buf_size - 8);
 if (big_endian) {
-s->width  = bytestream2_get_be16u(>gb);
-s->height = bytestream2_get_be16u(>gb);
+s->width  = bytestream2_get_be16u();
+s->height = bytestream2_get_be16u();
 } else {
-s->width  = bytestream2_get_le16u(>gb);
-s->height = bytestream2_get_le16u(>gb);
+s->width  = bytestream2_get_le16u();
+s->height = bytestream2_get_le16u();
 }
 
 ret = ff_set_dimensions(s->avctx, s->width, s->height);
 if (ret < 0)
 return ret;
 
-tgq_calculate_qtable(s, bytestream2_get_byteu(>gb));
-bytestream2_skip(>gb, 3);
+tgq_calculate_qtable(s, bytestream2_get_byteu());
+bytestream2_skipu(, 3);
 
 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
 return ret;
@@ -233,7 +234,7 @@ static int tgq_decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
 
 for (y = 0; y < FFALIGN(avctx->height, 16) >> 4; y++)
 for (x = 0; x < FFALIGN(avctx->width, 16) >> 4; x++)
-if (tgq_decode_mb(s, frame, y, x) < 0)
+if (tgq_decode_mb(s, , frame, y, x) < 0)
 return AVERROR_INVALIDDATA;
 
 *got_frame = 1;
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 21/24] avcodec/idctdsp: Move ScanTable to mpegvideo

2022-10-21 Thread Andreas Rheinhardt
Only used there.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/idctdsp.c   | 21 -
 libavcodec/idctdsp.h   | 11 ---
 libavcodec/mpegvideo.c | 21 +
 libavcodec/mpegvideo.h | 11 +++
 4 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/libavcodec/idctdsp.c b/libavcodec/idctdsp.c
index 50156930ed..7216afb094 100644
--- a/libavcodec/idctdsp.c
+++ b/libavcodec/idctdsp.c
@@ -36,27 +36,6 @@ av_cold void ff_permute_scantable(uint8_t dst[64], const 
uint8_t src[64],
 }
 }
 
-av_cold void ff_init_scantable(const uint8_t *permutation, ScanTable *st,
-   const uint8_t *src_scantable)
-{
-int i, end;
-
-st->scantable = src_scantable;
-
-for (i = 0; i < 64; i++) {
-int j = src_scantable[i];
-st->permutated[i] = permutation[j];
-}
-
-end = -1;
-for (i = 0; i < 64; i++) {
-int j = st->permutated[i];
-if (j > end)
-end = j;
-st->raster_end[i] = end;
-}
-}
-
 av_cold void ff_init_scantable_permutation(uint8_t *idct_permutation,
enum idct_permutation_type 
perm_type)
 {
diff --git a/libavcodec/idctdsp.h b/libavcodec/idctdsp.h
index b286bc231c..7224463349 100644
--- a/libavcodec/idctdsp.h
+++ b/libavcodec/idctdsp.h
@@ -25,15 +25,6 @@
 
 #include "avcodec.h"
 
-/**
- * Scantable.
- */
-typedef struct ScanTable {
-const uint8_t *scantable;
-uint8_t permutated[64];
-uint8_t raster_end[64];
-} ScanTable;
-
 enum idct_permutation_type {
 FF_IDCT_PERM_NONE,
 FF_IDCT_PERM_LIBMPEG2,
@@ -45,8 +36,6 @@ enum idct_permutation_type {
 
 void ff_permute_scantable(uint8_t dst[64], const uint8_t src[64],
   const uint8_t permutation[64]);
-void ff_init_scantable(const uint8_t *permutation, ScanTable *st,
-   const uint8_t *src_scantable);
 void ff_init_scantable_permutation(uint8_t *idct_permutation,
enum idct_permutation_type perm_type);
 int ff_init_scantable_permutation_x86(uint8_t *idct_permutation,
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index fbe9884b4c..4326f7f9a5 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -320,6 +320,27 @@ static av_cold int dct_init(MpegEncContext *s)
 return 0;
 }
 
+av_cold void ff_init_scantable(const uint8_t *permutation, ScanTable *st,
+   const uint8_t *src_scantable)
+{
+int end;
+
+st->scantable = src_scantable;
+
+for (int i = 0; i < 64; i++) {
+int j = src_scantable[i];
+st->permutated[i] = permutation[j];
+}
+
+end = -1;
+for (int i = 0; i < 64; i++) {
+int j = st->permutated[i];
+if (j > end)
+end = j;
+st->raster_end[i] = end;
+}
+}
+
 av_cold void ff_mpv_idct_init(MpegEncContext *s)
 {
 if (s->codec_id == AV_CODEC_ID_MPEG4)
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 237adf2388..60d2ec751e 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -55,6 +55,15 @@
 
 #define MAX_B_FRAMES 16
 
+/**
+ * Scantable.
+ */
+typedef struct ScanTable {
+const uint8_t *scantable;
+uint8_t permutated[64];
+uint8_t raster_end[64];
+} ScanTable;
+
 /**
  * MpegEncContext.
  */
@@ -576,6 +585,8 @@ int ff_update_duplicate_context(MpegEncContext *dst, const 
MpegEncContext *src);
 void ff_set_qscale(MpegEncContext * s, int qscale);
 
 void ff_mpv_idct_init(MpegEncContext *s);
+void ff_init_scantable(const uint8_t *permutation, ScanTable *st,
+   const uint8_t *src_scantable);
 void ff_init_block_index(MpegEncContext *s);
 
 void ff_mpv_motion(MpegEncContext *s,
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 20/24] avcodec/wmv2dec: Remove unnecessary ScanTables

2022-10-21 Thread Andreas Rheinhardt
Only ScanTable.scantable is used for the abt_scantables.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/wmv2dec.c | 9 +
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c
index f638b31cec..a70913134c 100644
--- a/libavcodec/wmv2dec.c
+++ b/libavcodec/wmv2dec.c
@@ -52,7 +52,6 @@ typedef struct WMV2DecContext {
 int per_mb_rl_bit;
 int skip_type;
 
-ScanTable abt_scantable[2];
 DECLARE_ALIGNED(32, int16_t, abt_block2)[6][64];
 } WMV2DecContext;
 
@@ -425,9 +424,7 @@ static inline int wmv2_decode_inter_block(WMV2DecContext 
*w, int16_t *block,
 w->abt_type_table[n] = w->abt_type;
 
 if (w->abt_type) {
-//const uint8_t *scantable = w->abt_scantable[w->abt_type - 
1].permutated;
-const uint8_t *scantable = w->abt_scantable[w->abt_type - 1].scantable;
-//const uint8_t *scantable = w->abt_type - 1 ? 
w->abt_scantable[1].permutated : w->abt_scantable[0].scantable;
+const uint8_t *scantable = w->abt_type == 1 ? ff_wmv2_scantableA : 
ff_wmv2_scantableB;
 
 sub_cbp = sub_cbp_table[decode012(>gb)];
 
@@ -577,10 +574,6 @@ static av_cold int wmv2_decode_init(AVCodecContext *avctx)
 return ret;
 
 ff_wmv2_common_init(s);
-ff_init_scantable(s->idsp.idct_permutation, >abt_scantable[0],
-  ff_wmv2_scantableA);
-ff_init_scantable(s->idsp.idct_permutation, >abt_scantable[1],
-  ff_wmv2_scantableB);
 
 return ff_intrax8_common_init(avctx, >x8,
   w->s.block, w->s.block_last_index,
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 19/24] avcodec/speedhqdec: Only keep what is used from ScanTable

2022-10-21 Thread Andreas Rheinhardt
Namely ScanTable.permutated.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/speedhqdec.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavcodec/speedhqdec.c b/libavcodec/speedhqdec.c
index acca437bd5..5378b987dc 100644
--- a/libavcodec/speedhqdec.c
+++ b/libavcodec/speedhqdec.c
@@ -53,7 +53,7 @@
 typedef struct SHQContext {
 BlockDSPContext bdsp;
 IDCTDSPContext idsp;
-ScanTable intra_scantable;
+uint8_t permutated_intra_scantable[64];
 int quant_matrix[64];
 enum { SHQ_SUBSAMPLING_420, SHQ_SUBSAMPLING_422, SHQ_SUBSAMPLING_444 }
 subsampling;
@@ -137,7 +137,7 @@ static inline int decode_alpha_block(const SHQContext *s, 
GetBitContext *gb, uin
 static inline int decode_dct_block(const SHQContext *s, GetBitContext *gb, int 
last_dc[4], int component, uint8_t *dest, int linesize)
 {
 const int *quant_matrix = s->quant_matrix;
-const uint8_t *scantable = s->intra_scantable.permutated;
+const uint8_t *scantable = s->permutated_intra_scantable;
 LOCAL_ALIGNED_32(int16_t, block, [64]);
 int dc_offset;
 
@@ -581,7 +581,8 @@ static av_cold int speedhq_decode_init(AVCodecContext 
*avctx)
 
 ff_blockdsp_init(>bdsp);
 ff_idctdsp_init(>idsp, avctx);
-ff_init_scantable(s->idsp.idct_permutation, >intra_scantable, 
ff_zigzag_direct);
+ff_permute_scantable(s->permutated_intra_scantable, ff_zigzag_direct,
+ s->idsp.idct_permutation);
 
 switch (avctx->codec_tag) {
 case MKTAG('S', 'H', 'Q', '0'):
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 18/24] avcodec/mjpegenc_common: Only pass what is used from ScanTable

2022-10-21 Thread Andreas Rheinhardt
Namely ScanTable.permutated.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mjpegenc.c|  2 +-
 libavcodec/mjpegenc_common.c | 10 +-
 libavcodec/mjpegenc_common.h |  4 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index e56a466b36..eafe7130e2 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -81,7 +81,7 @@ static av_cold void init_uni_ac_vlc(const uint8_t 
huff_size_ac[256],
 static void mjpeg_encode_picture_header(MpegEncContext *s)
 {
 ff_mjpeg_encode_picture_header(s->avctx, >pb, s->picture->f, 
s->mjpeg_ctx,
-   >intra_scantable, 0,
+   s->intra_scantable.permutated, 0,
s->intra_matrix, s->chroma_intra_matrix,
s->slice_context_count > 1);
 
diff --git a/libavcodec/mjpegenc_common.c b/libavcodec/mjpegenc_common.c
index c37c964931..6dfc4469a5 100644
--- a/libavcodec/mjpegenc_common.c
+++ b/libavcodec/mjpegenc_common.c
@@ -58,7 +58,7 @@ static int put_huffman_table(PutBitContext *p, int 
table_class, int table_id,
 
 static void jpeg_table_header(AVCodecContext *avctx, PutBitContext *p,
   MJpegContext *m,
-  ScanTable *intra_scantable,
+  const uint8_t intra_matrix_permutation[64],
   uint16_t luma_intra_matrix[64],
   uint16_t chroma_intra_matrix[64],
   int hsample[3], int use_slices, int 
matrices_differ)
@@ -76,7 +76,7 @@ static void jpeg_table_header(AVCodecContext *avctx, 
PutBitContext *p,
 put_bits(p, 4, 0); /* 8 bit precision */
 put_bits(p, 4, 0); /* table 0 */
 for (int i = 0; i < 64; i++) {
-uint8_t j = intra_scantable->permutated[i];
+uint8_t j = intra_matrix_permutation[i];
 put_bits(p, 8, luma_intra_matrix[j]);
 }
 
@@ -84,7 +84,7 @@ static void jpeg_table_header(AVCodecContext *avctx, 
PutBitContext *p,
 put_bits(p, 4, 0); /* 8 bit precision */
 put_bits(p, 4, 1); /* table 1 */
 for(i=0;i<64;i++) {
-j = intra_scantable->permutated[i];
+j = intra_matrix_permutation[i];
 put_bits(p, 8, chroma_intra_matrix[j]);
 }
 }
@@ -275,7 +275,7 @@ void ff_mjpeg_init_hvsample(AVCodecContext *avctx, int 
hsample[4], int vsample[4
 
 void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb,
 const AVFrame *frame, struct MJpegContext 
*m,
-ScanTable *intra_scantable, int pred,
+const uint8_t 
intra_matrix_permutation[64], int pred,
 uint16_t luma_intra_matrix[64],
 uint16_t chroma_intra_matrix[64],
 int use_slices)
@@ -298,7 +298,7 @@ void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, 
PutBitContext *pb,
 chroma_matrix = !lossless && !!memcmp(luma_intra_matrix,
   chroma_intra_matrix,
   sizeof(luma_intra_matrix[0]) * 64);
-jpeg_table_header(avctx, pb, m, intra_scantable,
+jpeg_table_header(avctx, pb, m, intra_matrix_permutation,
   luma_intra_matrix, chroma_intra_matrix, hsample,
   use_slices, chroma_matrix);
 
diff --git a/libavcodec/mjpegenc_common.h b/libavcodec/mjpegenc_common.h
index 5b13faae23..e9f0ea44a0 100644
--- a/libavcodec/mjpegenc_common.h
+++ b/libavcodec/mjpegenc_common.h
@@ -24,7 +24,6 @@
 #include 
 
 #include "avcodec.h"
-#include "idctdsp.h"
 #include "put_bits.h"
 
 struct MJpegContext;
@@ -33,7 +32,8 @@ int ff_mjpeg_add_icc_profile_size(AVCodecContext *avctx, 
const AVFrame *frame,
   size_t *max_pkt_size);
 void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb,
 const AVFrame *frame, struct MJpegContext 
*m,
-ScanTable *intra_scantable, int pred,
+const uint8_t intra_matrix_permutation[64],
+int pred,
 uint16_t luma_intra_matrix[64],
 uint16_t chroma_intra_matrix[64],
 int use_slices);
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 17/24] avcodec/mjpegdec: Only keep what is used from ScanTable

2022-10-21 Thread Andreas Rheinhardt
Namely ScanTable.permutated.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mjpegdec.c | 16 
 libavcodec/mjpegdec.h |  2 +-
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 3374ae71bd..9b7465abe7 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -115,8 +115,8 @@ static void init_idct(AVCodecContext *avctx)
 MJpegDecodeContext *s = avctx->priv_data;
 
 ff_idctdsp_init(>idsp, avctx);
-ff_init_scantable(s->idsp.idct_permutation, >scantable,
-  ff_zigzag_direct);
+ff_permute_scantable(s->permutated_scantable, ff_zigzag_direct,
+ s->idsp.idct_permutation);
 }
 
 av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx)
@@ -846,7 +846,7 @@ static int decode_block(MJpegDecodeContext *s, int16_t 
*block, int component,
 av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i);
 return AVERROR_INVALIDDATA;
 }
-j= s->scantable.permutated[i];
+j= s->permutated_scantable[i];
 block[j] = level * quant_matrix[i];
 }
 } while (i < 63);
@@ -909,14 +909,14 @@ static int decode_block_progressive(MJpegDecodeContext 
*s, int16_t *block,
 
 if (i >= se) {
 if (i == se) {
-j = s->scantable.permutated[se];
+j = s->permutated_scantable[se];
 block[j] = level * (quant_matrix[se] << Al);
 break;
 }
 av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i);
 return AVERROR_INVALIDDATA;
 }
-j = s->scantable.permutated[i];
+j = s->permutated_scantable[i];
 block[j] = level * (quant_matrix[i] << Al);
 } else {
 if (run == 0xF) {// ZRL - skip 15 coefficients
@@ -964,7 +964,7 @@ for (; ; i++) { 
\
 }   \
 break;  \
 }   \
-j = s->scantable.permutated[i]; \
+j = s->permutated_scantable[i]; \
 if (block[j])   \
 REFINE_BIT(j)   \
 else if (run-- == 0)\
@@ -994,7 +994,7 @@ static int decode_block_refinement(MJpegDecodeContext *s, 
int16_t *block,
 val = SHOW_UBITS(re, >gb, 1);
 LAST_SKIP_BITS(re, >gb, 1);
 ZERO_RUN;
-j = s->scantable.permutated[i];
+j = s->permutated_scantable[i];
 val--;
 block[j] = ((quant_matrix[i] << Al) ^ val) - val;
 if (i == se) {
@@ -1026,7 +1026,7 @@ static int decode_block_refinement(MJpegDecodeContext *s, 
int16_t *block,
 }
 
 for (; i <= last; i++) {
-j = s->scantable.permutated[i];
+j = s->permutated_scantable[i];
 if (block[j])
 REFINE_BIT(j)
 }
diff --git a/libavcodec/mjpegdec.h b/libavcodec/mjpegdec.h
index 648dd714e1..2cb218902c 100644
--- a/libavcodec/mjpegdec.h
+++ b/libavcodec/mjpegdec.h
@@ -118,7 +118,7 @@ typedef struct MJpegDecodeContext {
 uint64_t coefs_finished[MAX_COMPONENTS]; ///< bitmask of which coefs have 
been completely decoded (progressive mode)
 int palette_index;
 int force_pal8;
-ScanTable scantable;
+uint8_t permutated_scantable[64];
 BlockDSPContext bdsp;
 HpelDSPContext hdsp;
 IDCTDSPContext idsp;
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 16/24] avcodec/mimic: Only keep what is used from ScanTable

2022-10-21 Thread Andreas Rheinhardt
Namely ScanTable.permutated.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mimic.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/mimic.c b/libavcodec/mimic.c
index 74eaa7d043..891471b30e 100644
--- a/libavcodec/mimic.c
+++ b/libavcodec/mimic.c
@@ -56,7 +56,7 @@ typedef struct MimicContext {
 DECLARE_ALIGNED(32, int16_t, dct_block)[64];
 
 GetBitContext   gb;
-ScanTable   scantable;
+uint8_t permutated_scantable[64];
 BlockDSPContext bdsp;
 BswapDSPContext bbdsp;
 HpelDSPContext  hdsp;
@@ -137,7 +137,7 @@ static av_cold int mimic_decode_init(AVCodecContext *avctx)
 ff_bswapdsp_init(>bbdsp);
 ff_hpeldsp_init(>hdsp, avctx->flags);
 ff_idctdsp_init(>idsp, avctx);
-ff_init_scantable(ctx->idsp.idct_permutation, >scantable, col_zag);
+ff_permute_scantable(ctx->permutated_scantable, col_zag, 
ctx->idsp.idct_permutation);
 
 for (i = 0; i < FF_ARRAY_ELEMS(ctx->frames); i++) {
 ctx->frames[i].f = av_frame_alloc();
@@ -250,7 +250,7 @@ static int vlc_decode_block(MimicContext *ctx, int 
num_coeffs, int qscale)
 else /* TODO Use >> 10 instead of / 1001 */
 coeff = (coeff * qscale) / 1001;
 
-block[ctx->scantable.permutated[pos]] = coeff;
+block[ctx->permutated_scantable[pos]] = coeff;
 }
 
 return 0;
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 15/24] avcodec/mdec: Only keep what is used from ScanTable

2022-10-21 Thread Andreas Rheinhardt
Namely ScanTable.permutated.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mdec.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/mdec.c b/libavcodec/mdec.c
index f27cf84122..a1f85aa0cf 100644
--- a/libavcodec/mdec.c
+++ b/libavcodec/mdec.c
@@ -44,7 +44,7 @@ typedef struct MDECContext {
 BswapDSPContext bbdsp;
 IDCTDSPContext idsp;
 GetBitContext gb;
-ScanTable scantable;
+uint8_t permutated_scantable[64];
 int version;
 int qscale;
 int last_dc[3];
@@ -64,7 +64,7 @@ static inline int mdec_decode_block_intra(MDECContext *a, 
int16_t *block, int n)
 int level, diff, i, j, run;
 int component;
 RLTable *rl = _rl_mpeg1;
-uint8_t * const scantable = a->scantable.permutated;
+const uint8_t *const scantable = a->permutated_scantable;
 const uint16_t *quant_matrix = a->quant_matrix;
 const int qscale = a->qscale;
 
@@ -223,8 +223,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
 ff_bswapdsp_init(>bbdsp);
 ff_idctdsp_init(>idsp, avctx);
 ff_mpeg12_init_vlcs();
-ff_init_scantable(a->idsp.idct_permutation, >scantable,
-  ff_zigzag_direct);
+ff_permute_scantable(a->permutated_scantable, ff_zigzag_direct,
+ a->idsp.idct_permutation);
 
 avctx->pix_fmt  = AV_PIX_FMT_YUVJ420P;
 avctx->color_range = AVCOL_RANGE_JPEG;
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 14/24] avcodec/intrax8: Only keep what is used from ScanTable

2022-10-21 Thread Andreas Rheinhardt
Namely ScanTable.permutated.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/intrax8.c | 15 ---
 libavcodec/intrax8.h |  3 +--
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/libavcodec/intrax8.c b/libavcodec/intrax8.c
index f88baf8daf..d6668338fb 100644
--- a/libavcodec/intrax8.c
+++ b/libavcodec/intrax8.c
@@ -25,6 +25,7 @@
 #include "libavutil/thread.h"
 #include "avcodec.h"
 #include "get_bits.h"
+#include "idctdsp.h"
 #include "msmpeg4data.h"
 #include "intrax8huf.h"
 #include "intrax8.h"
@@ -576,7 +577,7 @@ static int x8_decode_intra_mb(IntraX8Context *const w, 
const int chroma)
 x8_select_ac_table(w, ac_mode);
 /* scantable_selector[12] = { 0, 2, 0, 1, 1, 1, 0, 2, 2, 0, 1, 2 }; <-
  * -> 10'01' 00'10' 10'00' 01'01' 01'00' 10'00 => 0x928548 */
-scantable = w->scantable[(0x928548 >> (2 * w->orient)) & 3].permutated;
+scantable = w->permutated_scantable[(0x928548 >> (2 * w->orient)) & 3];
 pos   = 0;
 do {
 n++;
@@ -714,12 +715,12 @@ av_cold int ff_intrax8_common_init(AVCodecContext *avctx,
 ff_init_scantable_permutation(w->idct_permutation,
   w->wdsp.idct_perm);
 
-ff_init_scantable(w->idct_permutation, >scantable[0],
-  ff_wmv1_scantable[0]);
-ff_init_scantable(w->idct_permutation, >scantable[1],
-  ff_wmv1_scantable[2]);
-ff_init_scantable(w->idct_permutation, >scantable[2],
-  ff_wmv1_scantable[3]);
+ff_permute_scantable(w->permutated_scantable[0], ff_wmv1_scantable[0],
+ w->idct_permutation);
+ff_permute_scantable(w->permutated_scantable[1], ff_wmv1_scantable[2],
+ w->idct_permutation);
+ff_permute_scantable(w->permutated_scantable[2], ff_wmv1_scantable[3],
+ w->idct_permutation);
 
 ff_intrax8dsp_init(>dsp);
 ff_blockdsp_init(>bdsp);
diff --git a/libavcodec/intrax8.h b/libavcodec/intrax8.h
index 9ef2fc3dd3..8e22361f1f 100644
--- a/libavcodec/intrax8.h
+++ b/libavcodec/intrax8.h
@@ -21,7 +21,6 @@
 
 #include "blockdsp.h"
 #include "get_bits.h"
-#include "idctdsp.h"
 #include "intrax8dsp.h"
 #include "wmv2dsp.h"
 #include "mpegpicture.h"
@@ -35,7 +34,7 @@ typedef struct IntraX8Context {
 
 // set by ff_intrax8_common_init
 uint8_t *prediction_table; // 2 * (mb_w * 2)
-ScanTable scantable[3];
+uint8_t permutated_scantable[3][64];
 WMV2DSPContext wdsp;
 uint8_t idct_permutation[64];
 AVCodecContext *avctx;
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 13/24] avcodec/g2meet: Pre-permute quantization tables

2022-10-21 Thread Andreas Rheinhardt
Allows to avoid a permutation lateron.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/g2meet.c | 27 ++-
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/libavcodec/g2meet.c b/libavcodec/g2meet.c
index 1973ed0741..761fd22fc3 100644
--- a/libavcodec/g2meet.c
+++ b/libavcodec/g2meet.c
@@ -59,22 +59,23 @@ enum Compression {
 COMPR_KEMPF_J_B,
 };
 
+/* These tables are already permuted according to ff_zigzag_direct */
 static const uint8_t luma_quant[64] = {
- 8,  6,  5,  8, 12, 20, 26, 31,
- 6,  6,  7, 10, 13, 29, 30, 28,
- 7,  7,  8, 12, 20, 29, 35, 28,
- 7,  9, 11, 15, 26, 44, 40, 31,
- 9, 11, 19, 28, 34, 55, 52, 39,
-12, 18, 28, 32, 41, 52, 57, 46,
-25, 32, 39, 44, 52, 61, 60, 51,
-36, 46, 48, 49, 56, 50, 52, 50
+ 8,  6,  6,  7,  6,  5,  8,  7,
+ 7,  7,  9,  9,  8, 10, 12, 20,
+13, 12, 11, 11, 12, 25, 18, 19,
+15, 20, 29, 26, 31, 30, 29, 26,
+28, 28, 32, 36, 46, 39, 32, 34,
+44, 35, 28, 28, 40, 55, 41, 44,
+48, 49, 52, 52, 52, 31, 39, 57,
+61, 56, 50, 60, 46, 51, 52, 50,
 };
 
 static const uint8_t chroma_quant[64] = {
- 9,  9, 12, 24, 50, 50, 50, 50,
- 9, 11, 13, 33, 50, 50, 50, 50,
-12, 13, 28, 50, 50, 50, 50, 50,
-24, 33, 50, 50, 50, 50, 50, 50,
+ 9,  9,  9, 12, 11, 12, 24, 13,
+13, 24, 50, 33, 28, 33, 50, 50,
+50, 50, 50, 50, 50, 50, 50, 50,
+50, 50, 50, 50, 50, 50, 50, 50,
 50, 50, 50, 50, 50, 50, 50, 50,
 50, 50, 50, 50, 50, 50, 50, 50,
 50, 50, 50, 50, 50, 50, 50, 50,
@@ -250,7 +251,7 @@ static int jpg_decode_block(JPGContext *c, GetBitContext 
*gb,
 int nbits = val;
 
 val = get_xbits(gb, nbits);
-val*= qmat[ff_zigzag_direct[pos]];
+val*= qmat[pos];
 block[c->permutated_scantable[pos]] = val;
 }
 }
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 12/24] avcodec/g2meet: Only keep what is used from ScanTable

2022-10-21 Thread Andreas Rheinhardt
Namely ScanTable.permutated.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/g2meet.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/g2meet.c b/libavcodec/g2meet.c
index 4367af3dc0..1973ed0741 100644
--- a/libavcodec/g2meet.c
+++ b/libavcodec/g2meet.c
@@ -120,7 +120,7 @@ typedef struct ePICContext {
 typedef struct JPGContext {
 BlockDSPContext bdsp;
 IDCTDSPContext idsp;
-ScanTable  scantable;
+uint8_tpermutated_scantable[64];
 
 VLCdc_vlc[2], ac_vlc[2];
 intprev_dc[3];
@@ -182,8 +182,8 @@ static av_cold int jpg_init(AVCodecContext *avctx, 
JPGContext *c)
 
 ff_blockdsp_init(>bdsp);
 ff_idctdsp_init(>idsp, avctx);
-ff_init_scantable(c->idsp.idct_permutation, >scantable,
-  ff_zigzag_direct);
+ff_permute_scantable(c->permutated_scantable, ff_zigzag_direct,
+ c->idsp.idct_permutation);
 
 return 0;
 }
@@ -251,7 +251,7 @@ static int jpg_decode_block(JPGContext *c, GetBitContext 
*gb,
 
 val = get_xbits(gb, nbits);
 val*= qmat[ff_zigzag_direct[pos]];
-block[c->scantable.permutated[pos]] = val;
+block[c->permutated_scantable[pos]] = val;
 }
 }
 return 0;
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 11/24] avcodec/cavs: Only keep what is needed from IDCTDSP-API

2022-10-21 Thread Andreas Rheinhardt
Namely ScanTable.permutated. The rest of the IDCTDSP-API
is unused as cavs has its own idct.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/cavs.c| 7 +++
 libavcodec/cavs.h| 9 ++---
 libavcodec/cavsdec.c | 2 +-
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/libavcodec/cavs.c b/libavcodec/cavs.c
index 6d54e8eae5..fdd577f7fb 100644
--- a/libavcodec/cavs.c
+++ b/libavcodec/cavs.c
@@ -792,15 +792,14 @@ int ff_cavs_init_top_lines(AVSContext *h)
 av_cold int ff_cavs_init(AVCodecContext *avctx)
 {
 AVSContext *h = avctx->priv_data;
+uint8_t permutation[64];
 
 ff_blockdsp_init(>bdsp);
 ff_h264chroma_init(>h264chroma, 8);
-ff_idctdsp_init(>idsp, avctx);
 ff_videodsp_init(>vdsp, 8);
 ff_cavsdsp_init(>cdsp);
-ff_init_scantable_permutation(h->idsp.idct_permutation,
-  h->cdsp.idct_perm);
-ff_init_scantable(h->idsp.idct_permutation, >scantable, 
ff_zigzag_direct);
+ff_init_scantable_permutation(permutation, h->cdsp.idct_perm);
+ff_permute_scantable(h->permutated_scantable, ff_zigzag_direct, 
permutation);
 
 h->avctx   = avctx;
 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
diff --git a/libavcodec/cavs.h b/libavcodec/cavs.h
index cbc163fb4d..244c322b35 100644
--- a/libavcodec/cavs.h
+++ b/libavcodec/cavs.h
@@ -22,12 +22,16 @@
 #ifndef AVCODEC_CAVS_H
 #define AVCODEC_CAVS_H
 
+#include 
+#include 
+
+#include "libavutil/frame.h"
 #include "libavutil/mem_internal.h"
 
+#include "avcodec.h"
 #include "cavsdsp.h"
 #include "blockdsp.h"
 #include "h264chroma.h"
-#include "idctdsp.h"
 #include "get_bits.h"
 #include "videodsp.h"
 
@@ -166,7 +170,6 @@ typedef struct AVSContext {
 AVCodecContext *avctx;
 BlockDSPContext bdsp;
 H264ChromaContext h264chroma;
-IDCTDSPContext idsp;
 VideoDSPContext vdsp;
 CAVSDSPContext  cdsp;
 GetBitContext gb;
@@ -220,7 +223,7 @@ typedef struct AVSContext {
 int qp_fixed;
 int pic_qp_fixed;
 int cbp;
-ScanTable scantable;
+uint8_t permutated_scantable[64];
 
 /** intra prediction is done with un-deblocked samples
  they are saved here before deblocking the MB  */
diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c
index 3e8be65968..b1fa9a981d 100644
--- a/libavcodec/cavsdec.c
+++ b/libavcodec/cavsdec.c
@@ -521,7 +521,7 @@ static inline int dequant(AVSContext *h, int16_t 
*level_buf, uint8_t *run_buf,
 {
 int round = 1 << (shift - 1);
 int pos = -1;
-const uint8_t *scantab = h->scantable.permutated;
+const uint8_t *scantab = h->permutated_scantable;
 
 /* inverse scan and dequantization */
 while (--coeff_num >= 0) {
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 10/24] avcodec/dnxhddec: Only keep what is used from ScanTable

2022-10-21 Thread Andreas Rheinhardt
Namely ScanTable.permutated.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/dnxhddec.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/dnxhddec.c b/libavcodec/dnxhddec.c
index a44f95f044..7cc4f94c7f 100644
--- a/libavcodec/dnxhddec.c
+++ b/libavcodec/dnxhddec.c
@@ -65,7 +65,7 @@ typedef struct DNXHDContext {
 int cur_field;  ///< current interlaced field
 VLC ac_vlc, dc_vlc, run_vlc;
 IDCTDSPContext idsp;
-ScanTable scantable;
+uint8_t permutated_scantable[64];
 const CIDEntry *cid_table;
 int bit_depth; // 8, 10, 12 or 0 if not initialized at all.
 int is_444;
@@ -275,8 +275,8 @@ static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame 
*frame,
 if (ctx->bit_depth != old_bit_depth) {
 ff_blockdsp_init(>bdsp);
 ff_idctdsp_init(>idsp, ctx->avctx);
-ff_init_scantable(ctx->idsp.idct_permutation, >scantable,
-  ff_zigzag_direct);
+ff_permute_scantable(ctx->permutated_scantable, ff_zigzag_direct,
+ ctx->idsp.idct_permutation);
 }
 
 // make sure profile size constraints are respected
@@ -436,7 +436,7 @@ static av_always_inline int dnxhd_decode_dct_block(const 
DNXHDContext *ctx,
 break;
 }
 
-j = ctx->scantable.permutated[i];
+j  = ctx->permutated_scantable[i];
 level *= scale[i];
 level += scale[i] >> 1;
 if (level_bias < 32 || weight_matrix[i] != level_bias)
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 09/24] avcodec/asvdec: Only keep what is used from ScanTable

2022-10-21 Thread Andreas Rheinhardt
Namely ScanTable.permutated.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/asvdec.c | 27 ++-
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/libavcodec/asvdec.c b/libavcodec/asvdec.c
index be89544732..699aab9f8f 100644
--- a/libavcodec/asvdec.c
+++ b/libavcodec/asvdec.c
@@ -58,7 +58,7 @@ typedef struct ASVDecContext {
 
 BlockDSPContext bdsp;
 IDCTDSPContext idsp;
-ScanTable scantable;
+uint8_t permutated_scantable[64];
 DECLARE_ALIGNED(32, int16_t, block)[6][64];
 uint16_t intra_matrix[64];
 uint8_t *bitstream_buffer;
@@ -141,13 +141,13 @@ static inline int asv1_decode_block(ASVDecContext *a, 
int16_t block[64])
 }
 
 if (ccp & 8)
-block[a->scantable.permutated[4 * i + 0]] = 
(asv1_get_level(>gb) * a->intra_matrix[4 * i + 0]) >> 4;
+block[a->permutated_scantable[4 * i + 0]] = 
(asv1_get_level(>gb) * a->intra_matrix[4 * i + 0]) >> 4;
 if (ccp & 4)
-block[a->scantable.permutated[4 * i + 1]] = 
(asv1_get_level(>gb) * a->intra_matrix[4 * i + 1]) >> 4;
+block[a->permutated_scantable[4 * i + 1]] = 
(asv1_get_level(>gb) * a->intra_matrix[4 * i + 1]) >> 4;
 if (ccp & 2)
-block[a->scantable.permutated[4 * i + 2]] = 
(asv1_get_level(>gb) * a->intra_matrix[4 * i + 2]) >> 4;
+block[a->permutated_scantable[4 * i + 2]] = 
(asv1_get_level(>gb) * a->intra_matrix[4 * i + 2]) >> 4;
 if (ccp & 1)
-block[a->scantable.permutated[4 * i + 3]] = 
(asv1_get_level(>gb) * a->intra_matrix[4 * i + 3]) >> 4;
+block[a->permutated_scantable[4 * i + 3]] = 
(asv1_get_level(>gb) * a->intra_matrix[4 * i + 3]) >> 4;
 }
 }
 
@@ -165,11 +165,11 @@ static inline int asv2_decode_block(ASVDecContext *a, 
int16_t block[64])
 ccp = asv2_get_vlc2(>gb, dc_ccp_vlc.table, DC_CCP_VLC_BITS);
 if (ccp) {
 if (ccp & 4)
-block[a->scantable.permutated[1]] = (asv2_get_level(>gb) * 
a->intra_matrix[1]) >> 4;
+block[a->permutated_scantable[1]] = (asv2_get_level(>gb) * 
a->intra_matrix[1]) >> 4;
 if (ccp & 2)
-block[a->scantable.permutated[2]] = (asv2_get_level(>gb) * 
a->intra_matrix[2]) >> 4;
+block[a->permutated_scantable[2]] = (asv2_get_level(>gb) * 
a->intra_matrix[2]) >> 4;
 if (ccp & 1)
-block[a->scantable.permutated[3]] = (asv2_get_level(>gb) * 
a->intra_matrix[3]) >> 4;
+block[a->permutated_scantable[3]] = (asv2_get_level(>gb) * 
a->intra_matrix[3]) >> 4;
 }
 
 for (i = 1; i < count + 1; i++) {
@@ -177,13 +177,13 @@ static inline int asv2_decode_block(ASVDecContext *a, 
int16_t block[64])
 
 if (ccp) {
 if (ccp & 8)
-block[a->scantable.permutated[4 * i + 0]] = 
(asv2_get_level(>gb) * a->intra_matrix[4 * i + 0]) >> 4;
+block[a->permutated_scantable[4 * i + 0]] = 
(asv2_get_level(>gb) * a->intra_matrix[4 * i + 0]) >> 4;
 if (ccp & 4)
-block[a->scantable.permutated[4 * i + 1]] = 
(asv2_get_level(>gb) * a->intra_matrix[4 * i + 1]) >> 4;
+block[a->permutated_scantable[4 * i + 1]] = 
(asv2_get_level(>gb) * a->intra_matrix[4 * i + 1]) >> 4;
 if (ccp & 2)
-block[a->scantable.permutated[4 * i + 2]] = 
(asv2_get_level(>gb) * a->intra_matrix[4 * i + 2]) >> 4;
+block[a->permutated_scantable[4 * i + 2]] = 
(asv2_get_level(>gb) * a->intra_matrix[4 * i + 2]) >> 4;
 if (ccp & 1)
-block[a->scantable.permutated[4 * i + 3]] = 
(asv2_get_level(>gb) * a->intra_matrix[4 * i + 3]) >> 4;
+block[a->permutated_scantable[4 * i + 3]] = 
(asv2_get_level(>gb) * a->intra_matrix[4 * i + 3]) >> 4;
 }
 }
 
@@ -311,7 +311,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
 ff_asv_common_init(avctx);
 ff_blockdsp_init(>bdsp);
 ff_idctdsp_init(>idsp, avctx);
-ff_init_scantable(a->idsp.idct_permutation, >scantable, ff_asv_scantab);
+ff_permute_scantable(a->permutated_scantable, ff_asv_scantab,
+ a->idsp.idct_permutation);
 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
 
 if (avctx->extradata_size < 1 || (inv_qscale = avctx->extradata[0]) == 0) {
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 08/24] avcodec/agm: Only keep what is used from ScanTable

2022-10-21 Thread Andreas Rheinhardt
Namely ScanTable.permutated.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/agm.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/libavcodec/agm.c b/libavcodec/agm.c
index 017aa0e1fa..374e4f4ef2 100644
--- a/libavcodec/agm.c
+++ b/libavcodec/agm.c
@@ -88,7 +88,7 @@ typedef struct AGMContext {
 int luma_quant_matrix[64];
 int chroma_quant_matrix[64];
 
-ScanTable scantable;
+uint8_t permutated_scantable[64];
 DECLARE_ALIGNED(32, int16_t, block)[64];
 
 int16_t *wblocks;
@@ -195,7 +195,7 @@ static int read_code(GetBitContext *gb, int *oskip, int 
*level, int *map, int mo
 static int decode_intra_blocks(AGMContext *s, GetBitContext *gb,
const int *quant_matrix, int *skip, int 
*dc_level)
 {
-const uint8_t *scantable = s->scantable.permutated;
+const uint8_t *scantable = s->permutated_scantable;
 int level, ret, map = 0;
 
 memset(s->wblocks, 0, s->wblocks_size);
@@ -237,7 +237,7 @@ static int decode_inter_blocks(AGMContext *s, GetBitContext 
*gb,
const int *quant_matrix, int *skip,
int *map)
 {
-const uint8_t *scantable = s->scantable.permutated;
+const uint8_t *scantable = s->permutated_scantable;
 int level, ret;
 
 memset(s->wblocks, 0, s->wblocks_size);
@@ -272,7 +272,7 @@ static int decode_inter_blocks(AGMContext *s, GetBitContext 
*gb,
 static int decode_intra_block(AGMContext *s, GetBitContext *gb,
   const int *quant_matrix, int *skip, int 
*dc_level)
 {
-const uint8_t *scantable = s->scantable.permutated;
+const uint8_t *scantable = s->permutated_scantable;
 const int offset = s->plus ? 0 : 1024;
 int16_t *block = s->block;
 int level, ret, map = 0;
@@ -362,7 +362,7 @@ static int decode_inter_block(AGMContext *s, GetBitContext 
*gb,
   const int *quant_matrix, int *skip,
   int *map)
 {
-const uint8_t *scantable = s->scantable.permutated;
+const uint8_t *scantable = s->permutated_scantable;
 int16_t *block = s->block;
 int level, ret;
 
@@ -1249,7 +1249,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
 avctx->idct_algo = FF_IDCT_SIMPLE;
 ff_idctdsp_init(>idsp, avctx);
-ff_init_scantable(s->idsp.idct_permutation, >scantable, 
ff_zigzag_direct);
+ff_permute_scantable(s->permutated_scantable, ff_zigzag_direct,
+ s->idsp.idct_permutation);
 
 s->prev_frame = av_frame_alloc();
 if (!s->prev_frame)
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 07/24] avcodec/idctdsp: Add function to apply permutation to array

2022-10-21 Thread Andreas Rheinhardt
It is the part of ff_init_scantable() that is used
by all users of said function.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/idctdsp.c | 9 +
 libavcodec/idctdsp.h | 2 ++
 2 files changed, 11 insertions(+)

diff --git a/libavcodec/idctdsp.c b/libavcodec/idctdsp.c
index 4ee9c3aa74..50156930ed 100644
--- a/libavcodec/idctdsp.c
+++ b/libavcodec/idctdsp.c
@@ -27,6 +27,15 @@
 #include "simple_idct.h"
 #include "xvididct.h"
 
+av_cold void ff_permute_scantable(uint8_t dst[64], const uint8_t src[64],
+  const uint8_t permutation[64])
+{
+for (int i = 0; i < 64; i++) {
+int j = src[i];
+dst[i] = permutation[j];
+}
+}
+
 av_cold void ff_init_scantable(const uint8_t *permutation, ScanTable *st,
const uint8_t *src_scantable)
 {
diff --git a/libavcodec/idctdsp.h b/libavcodec/idctdsp.h
index 2bd9820f72..b286bc231c 100644
--- a/libavcodec/idctdsp.h
+++ b/libavcodec/idctdsp.h
@@ -43,6 +43,8 @@ enum idct_permutation_type {
 FF_IDCT_PERM_SSE2,
 };
 
+void ff_permute_scantable(uint8_t dst[64], const uint8_t src[64],
+  const uint8_t permutation[64]);
 void ff_init_scantable(const uint8_t *permutation, ScanTable *st,
const uint8_t *src_scantable);
 void ff_init_scantable_permutation(uint8_t *idct_permutation,
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 06/24] avcodec/imm4: Remove useless ScanTable

2022-10-21 Thread Andreas Rheinhardt
Also rename the scantable variable to idct_permutation
to better reflect what it actually is.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/imm4.c | 24 +---
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/libavcodec/imm4.c b/libavcodec/imm4.c
index e2aa20813a..ccec5dff43 100644
--- a/libavcodec/imm4.c
+++ b/libavcodec/imm4.c
@@ -51,9 +51,8 @@ typedef struct IMM4Context {
 unsigned lo;
 unsigned hi;
 
-ScanTable intra_scantable;
-DECLARE_ALIGNED(32, int16_t, block)[6][64];
 IDCTDSPContext idsp;
+DECLARE_ALIGNED(32, int16_t, block)[6][64];
 } IMM4Context;
 
 static const uint8_t intra_cb[] = {
@@ -129,7 +128,7 @@ static int decode_block(AVCodecContext *avctx, 
GetBitContext *gb,
 int block, int factor, int flag, int offset, int flag2)
 {
 IMM4Context *s = avctx->priv_data;
-const uint8_t *scantable = s->intra_scantable.permutated;
+const uint8_t *idct_permutation = s->idsp.idct_permutation;
 int i, last, len, factor2;
 
 for (i = !flag; i < 64; i++) {
@@ -152,17 +151,17 @@ static int decode_block(AVCodecContext *avctx, 
GetBitContext *gb,
 i += len;
 if (i >= 64)
 break;
-s->block[block][scantable[i]] = offset * (factor2 < 0 ? -1 : 1) + 
factor * factor2;
+s->block[block][idct_permutation[i]] = offset * (factor2 < 0 ? -1 : 1) 
+ factor * factor2;
 if (last)
 break;
 }
 
 if (s->hi == 2 && flag2 && block < 4) {
 if (flag)
-s->block[block][scantable[0]]  *= 2;
-s->block[block][scantable[1]]  *= 2;
-s->block[block][scantable[8]]  *= 2;
-s->block[block][scantable[16]] *= 2;
+s->block[block][idct_permutation[0]]  *= 2;
+s->block[block][idct_permutation[1]]  *= 2;
+s->block[block][idct_permutation[8]]  *= 2;
+s->block[block][idct_permutation[16]] *= 2;
 }
 
 return 0;
@@ -172,7 +171,7 @@ static int decode_blocks(AVCodecContext *avctx, 
GetBitContext *gb,
  unsigned cbp, int flag, int offset, unsigned flag2)
 {
 IMM4Context *s = avctx->priv_data;
-const uint8_t *scantable = s->intra_scantable.permutated;
+const uint8_t *idct_permutation = s->idsp.idct_permutation;
 int ret, i;
 
 memset(s->block, 0, sizeof(s->block));
@@ -185,7 +184,7 @@ static int decode_blocks(AVCodecContext *avctx, 
GetBitContext *gb,
 x = 128;
 x *= 8;
 
-s->block[i][scantable[0]] = x;
+s->block[i][idct_permutation[0]] = x;
 }
 
 if (cbp & (1 << (5 - i))) {
@@ -495,14 +494,9 @@ static av_cold int decode_init(AVCodecContext *avctx)
 {
 static AVOnce init_static_once = AV_ONCE_INIT;
 IMM4Context *s = avctx->priv_data;
-uint8_t table[64];
-
-for (int i = 0; i < 64; i++)
-table[i] = i;
 
 ff_bswapdsp_init(>bdsp);
 ff_idctdsp_init(>idsp, avctx);
-ff_init_scantable(s->idsp.idct_permutation, >intra_scantable, table);
 
 s->prev_frame = av_frame_alloc();
 if (!s->prev_frame)
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 05/24] avcodec/aic: Remove useless ScanTable

2022-10-21 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/aic.c | 11 +++
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/libavcodec/aic.c b/libavcodec/aic.c
index 49d08f0556..7ba1c02fdd 100644
--- a/libavcodec/aic.c
+++ b/libavcodec/aic.c
@@ -143,7 +143,6 @@ typedef struct AICContext {
 AVCodecContext *avctx;
 AVFrame*frame;
 IDCTDSPContext idsp;
-ScanTable  scantable;
 
 intnum_x_slices;
 intslice_width;
@@ -348,10 +347,10 @@ static int aic_decode_slice(AICContext *ctx, int mb_x, 
int mb_y,
 for (mb = 0; mb < slice_width; mb++) {
 for (blk = 0; blk < 4; blk++) {
 if (!ctx->interlaced)
-recombine_block(ctx->block, ctx->scantable.permutated,
+recombine_block(ctx->block, ctx->idsp.idct_permutation,
 _y, _y);
 else
-recombine_block_il(ctx->block, ctx->scantable.permutated,
+recombine_block_il(ctx->block, ctx->idsp.idct_permutation,
_y, _y, blk);
 unquant_block(ctx->block, ctx->quant, ctx->quant_matrix);
 ctx->idsp.idct(ctx->block);
@@ -368,7 +367,7 @@ static int aic_decode_slice(AICContext *ctx, int mb_x, int 
mb_y,
 Y += 16;
 
 for (blk = 0; blk < 2; blk++) {
-recombine_block(ctx->block, ctx->scantable.permutated,
+recombine_block(ctx->block, ctx->idsp.idct_permutation,
 _c, _c);
 unquant_block(ctx->block, ctx->quant, ctx->quant_matrix);
 ctx->idsp.idct(ctx->block);
@@ -444,7 +443,6 @@ static av_cold int aic_decode_init(AVCodecContext *avctx)
 {
 AICContext *ctx = avctx->priv_data;
 int i;
-uint8_t scan[64];
 
 ctx->avctx = avctx;
 
@@ -452,9 +450,6 @@ static av_cold int aic_decode_init(AVCodecContext *avctx)
 
 ff_idctdsp_init(>idsp, avctx);
 
-for (i = 0; i < 64; i++)
-scan[i] = i;
-ff_init_scantable(ctx->idsp.idct_permutation, >scantable, scan);
 for (i = 0; i < 64; i++)
 ctx->quant_matrix[ctx->idsp.idct_permutation[i]] = aic_quant_matrix[i];
 
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 04/24] avcodec/eatqi: Don't use IDCTDSP-API unnecessarily

2022-10-21 Thread Andreas Rheinhardt
The eatqi decoder uses a custom IDCT and actually does not
use the IDCTDSP API at all. Somehow it was nevertheless
used to simply apply the identity permutation on ff_zigzag_direct.
This commit stops doing so.

Signed-off-by: Andreas Rheinhardt 
---
 configure  | 2 +-
 libavcodec/eatqi.c | 8 +---
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/configure b/configure
index 84d7be8bfe..baaf61271f 100755
--- a/configure
+++ b/configure
@@ -2822,7 +2822,7 @@ eac3_decoder_select="ac3_decoder"
 eac3_encoder_select="ac3_encoder"
 eamad_decoder_select="aandcttables blockdsp bswapdsp"
 eatgq_decoder_select="aandcttables"
-eatqi_decoder_select="aandcttables blockdsp bswapdsp idctdsp"
+eatqi_decoder_select="aandcttables blockdsp bswapdsp"
 exr_decoder_deps="zlib"
 exr_encoder_deps="zlib"
 ffv1_decoder_select="rangecoder"
diff --git a/libavcodec/eatqi.c b/libavcodec/eatqi.c
index 324e6f1ced..e4f12b3db2 100644
--- a/libavcodec/eatqi.c
+++ b/libavcodec/eatqi.c
@@ -36,7 +36,6 @@
 #include "get_bits.h"
 #include "aandcttab.h"
 #include "eaidct.h"
-#include "idctdsp.h"
 #include "mpeg12data.h"
 #include "mpeg12dec.h"
 
@@ -45,8 +44,6 @@ typedef struct TqiContext {
 GetBitContext gb;
 BlockDSPContext bdsp;
 BswapDSPContext bsdsp;
-IDCTDSPContext idsp;
-ScanTable intra_scantable;
 
 void *bitstream_buf;
 unsigned int bitstream_buf_size;
@@ -64,9 +61,6 @@ static av_cold int tqi_decode_init(AVCodecContext *avctx)
 
 ff_blockdsp_init(>bdsp);
 ff_bswapdsp_init(>bsdsp);
-ff_idctdsp_init(>idsp, avctx);
-ff_init_scantable_permutation(t->idsp.idct_permutation, FF_IDCT_PERM_NONE);
-ff_init_scantable(t->idsp.idct_permutation, >intra_scantable, 
ff_zigzag_direct);
 
 avctx->framerate = (AVRational){ 15, 1 };
 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
@@ -82,7 +76,7 @@ static int tqi_decode_mb(TqiContext *t, int16_t (*block)[64])
 for (n = 0; n < 6; n++) {
 int ret = ff_mpeg1_decode_block_intra(>gb,
   t->intra_matrix,
-  t->intra_scantable.permutated,
+  ff_zigzag_direct,
   t->last_dc, block[n], n, 1);
 if (ret < 0) {
 av_log(t->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n",
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 03/24] avcodec/eatgq: Don't use IDCTDSP-API unnecessarily

2022-10-21 Thread Andreas Rheinhardt
The eatgq decoder uses a custom IDCT and actually does not
use the IDCTDSP API at all. Somehow it was nevertheless
used to simply apply the identity permutation on ff_zigzag_direct.
This commit stops doing so. It also renames perm to scantable,
because it is only the scantable as given by the spec without
any further permutation performed by us.

Signed-off-by: Andreas Rheinhardt 
---
 configure  |  2 +-
 libavcodec/eatgq.c | 21 -
 2 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/configure b/configure
index 16b2084945..84d7be8bfe 100755
--- a/configure
+++ b/configure
@@ -2821,7 +2821,7 @@ dxv_decoder_select="lzf texturedsp"
 eac3_decoder_select="ac3_decoder"
 eac3_encoder_select="ac3_encoder"
 eamad_decoder_select="aandcttables blockdsp bswapdsp"
-eatgq_decoder_select="aandcttables idctdsp"
+eatgq_decoder_select="aandcttables"
 eatqi_decoder_select="aandcttables blockdsp bswapdsp idctdsp"
 exr_decoder_deps="zlib"
 exr_encoder_deps="zlib"
diff --git a/libavcodec/eatgq.c b/libavcodec/eatgq.c
index a6c3e72f85..627615b4e8 100644
--- a/libavcodec/eatgq.c
+++ b/libavcodec/eatgq.c
@@ -39,12 +39,10 @@
 #include "decode.h"
 #include "eaidct.h"
 #include "get_bits.h"
-#include "idctdsp.h"
 
 typedef struct TgqContext {
 AVCodecContext *avctx;
 int width, height;
-ScanTable scantable;
 int qtable[64];
 DECLARE_ALIGNED(16, int16_t, block)[6][64];
 GetByteContext gb;
@@ -53,10 +51,7 @@ typedef struct TgqContext {
 static av_cold int tgq_decode_init(AVCodecContext *avctx)
 {
 TgqContext *s = avctx->priv_data;
-uint8_t idct_permutation[64];
 s->avctx = avctx;
-ff_init_scantable_permutation(idct_permutation, FF_IDCT_PERM_NONE);
-ff_init_scantable(idct_permutation, >scantable, ff_zigzag_direct);
 avctx->framerate = (AVRational){ 15, 1 };
 avctx->pix_fmt   = AV_PIX_FMT_YUV420P;
 return 0;
@@ -64,15 +59,15 @@ static av_cold int tgq_decode_init(AVCodecContext *avctx)
 
 static void tgq_decode_block(TgqContext *s, int16_t block[64], GetBitContext 
*gb)
 {
-uint8_t *perm = s->scantable.permutated;
+const uint8_t *scantable = ff_zigzag_direct;
 int i, j, value;
 block[0] = get_sbits(gb, 8) * s->qtable[0];
 for (i = 1; i < 64;) {
 switch (show_bits(gb, 3)) {
 case 4:
-block[perm[i++]] = 0;
+block[scantable[i++]] = 0;
 case 0:
-block[perm[i++]] = 0;
+block[scantable[i++]] = 0;
 skip_bits(gb, 3);
 break;
 case 5:
@@ -80,16 +75,16 @@ static void tgq_decode_block(TgqContext *s, int16_t 
block[64], GetBitContext *gb
 skip_bits(gb, 2);
 value = get_bits(gb, 6);
 for (j = 0; j < value; j++)
-block[perm[i++]] = 0;
+block[scantable[i++]] = 0;
 break;
 case 6:
 skip_bits(gb, 3);
-block[perm[i]] = -s->qtable[perm[i]];
+block[scantable[i]] = -s->qtable[scantable[i]];
 i++;
 break;
 case 2:
 skip_bits(gb, 3);
-block[perm[i]] = s->qtable[perm[i]];
+block[scantable[i]] = s->qtable[scantable[i]];
 i++;
 break;
 case 7: // 111b
@@ -97,9 +92,9 @@ static void tgq_decode_block(TgqContext *s, int16_t 
block[64], GetBitContext *gb
 skip_bits(gb, 2);
 if (show_bits(gb, 6) == 0x3F) {
 skip_bits(gb, 6);
-block[perm[i]] = get_sbits(gb, 8) * s->qtable[perm[i]];
+block[scantable[i]] = get_sbits(gb, 8) * 
s->qtable[scantable[i]];
 } else {
-block[perm[i]] = get_sbits(gb, 6) * s->qtable[perm[i]];
+block[scantable[i]] = get_sbits(gb, 6) * 
s->qtable[scantable[i]];
 }
 i++;
 break;
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 02/24] avcodec/eamad: Don't use IDCTDSP-API unnecessarily

2022-10-21 Thread Andreas Rheinhardt
The eamad decoder uses a custom IDCT and actually does not
use the IDCTDSP API at all. Somehow it was nevertheless
used to simply apply the identity permutation on ff_zigzag_direct.
This commit stops doing so.

Signed-off-by: Andreas Rheinhardt 
---
 configure  | 2 +-
 libavcodec/eamad.c | 8 +---
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/configure b/configure
index bb61e9a0b8..16b2084945 100755
--- a/configure
+++ b/configure
@@ -2820,7 +2820,7 @@ dxa_decoder_deps="zlib"
 dxv_decoder_select="lzf texturedsp"
 eac3_decoder_select="ac3_decoder"
 eac3_encoder_select="ac3_encoder"
-eamad_decoder_select="aandcttables blockdsp bswapdsp idctdsp"
+eamad_decoder_select="aandcttables blockdsp bswapdsp"
 eatgq_decoder_select="aandcttables idctdsp"
 eatqi_decoder_select="aandcttables blockdsp bswapdsp idctdsp"
 exr_decoder_deps="zlib"
diff --git a/libavcodec/eamad.c b/libavcodec/eamad.c
index 2a5aac912d..de8f488f65 100644
--- a/libavcodec/eamad.c
+++ b/libavcodec/eamad.c
@@ -39,7 +39,6 @@
 #include "get_bits.h"
 #include "aandcttab.h"
 #include "eaidct.h"
-#include "idctdsp.h"
 #include "mpeg12data.h"
 #include "mpeg12vlc.h"
 
@@ -52,13 +51,11 @@ typedef struct MadContext {
 AVCodecContext *avctx;
 BlockDSPContext bdsp;
 BswapDSPContext bbdsp;
-IDCTDSPContext idsp;
 AVFrame *last_frame;
 GetBitContext gb;
 void *bitstream_buf;
 unsigned int bitstream_buf_size;
 DECLARE_ALIGNED(32, int16_t, block)[64];
-ScanTable scantable;
 uint16_t quant_matrix[64];
 int mb_x;
 int mb_y;
@@ -71,9 +68,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
 ff_blockdsp_init(>bdsp);
 ff_bswapdsp_init(>bbdsp);
-ff_idctdsp_init(>idsp, avctx);
-ff_init_scantable_permutation(s->idsp.idct_permutation, FF_IDCT_PERM_NONE);
-ff_init_scantable(s->idsp.idct_permutation, >scantable, 
ff_zigzag_direct);
 ff_mpeg12_init_vlcs();
 
 s->last_frame = av_frame_alloc();
@@ -135,7 +129,7 @@ static inline int decode_block_intra(MadContext *s, int16_t 
* block)
 {
 int level, i, j, run;
 RLTable *rl = _rl_mpeg1;
-const uint8_t *scantable = s->scantable.permutated;
+const uint8_t *scantable = ff_zigzag_direct;
 int16_t *quant_matrix = s->quant_matrix;
 
 block[0] = (128 + get_sbits(>gb, 8)) * quant_matrix[0];
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 01/24] configure: Add idctdsp dependency to codecs that need it

2022-10-21 Thread Andreas Rheinhardt
Currently masked by faan.

Signed-off-by: Andreas Rheinhardt 
---
 configure | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 431fa5bf7a..bb61e9a0b8 100755
--- a/configure
+++ b/configure
@@ -2773,6 +2773,7 @@ ac3_fixed_encoder_select="ac3dsp audiodsp mdct me_cmp"
 acelp_kelvin_decoder_select="audiodsp"
 adpcm_g722_decoder_select="g722dsp"
 adpcm_g722_encoder_select="g722dsp"
+agm_decoder_select="idctdsp"
 aic_decoder_select="golomb idctdsp"
 alac_encoder_select="lpc"
 als_decoder_select="bswapdsp mpeg4audio"
@@ -2820,7 +2821,7 @@ dxv_decoder_select="lzf texturedsp"
 eac3_decoder_select="ac3_decoder"
 eac3_encoder_select="ac3_encoder"
 eamad_decoder_select="aandcttables blockdsp bswapdsp idctdsp"
-eatgq_decoder_select="aandcttables"
+eatgq_decoder_select="aandcttables idctdsp"
 eatqi_decoder_select="aandcttables blockdsp bswapdsp idctdsp"
 exr_decoder_deps="zlib"
 exr_encoder_deps="zlib"
@@ -2859,7 +2860,7 @@ huffyuv_encoder_select="bswapdsp huffman huffyuvencdsp 
llvidencdsp"
 hymt_decoder_select="huffyuv_decoder"
 iac_decoder_select="imc_decoder"
 imc_decoder_select="bswapdsp fft mdct sinewin"
-imm4_decoder_select="bswapdsp"
+imm4_decoder_select="bswapdsp idctdsp"
 imm5_decoder_select="h264_decoder hevc_decoder"
 indeo3_decoder_select="hpeldsp"
 indeo4_decoder_select="ividsp"
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 7/7] avutil/integer: Use '|' instead of '+' where it is more natural

2022-10-21 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavutil/integer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavutil/integer.c b/libavutil/integer.c
index a692c3783c..d0a0f62c9a 100644
--- a/libavutil/integer.c
+++ b/libavutil/integer.c
@@ -104,7 +104,7 @@ AVInteger av_shr_i(AVInteger a, int s){
 unsigned int index= i + (s>>4);
 unsigned int v=0;
 if (index + 1 < AV_INTEGER_SIZE) v  = a.v[index + 1] * (1U << 16);
-if(index  > (s&15);
 }
 return out;
@@ -161,6 +161,6 @@ int64_t av_i2int(AVInteger a){
 uint64_t out = 0;
 
 for (int i = 3; i >= 0; i--)
-out = (out<<16) + a.v[i];
+out = (out << 16) | a.v[i];
 return out;
 }
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 6/7] avutil/integer: Fix undefined left shifts of negative numbers

2022-10-21 Thread Andreas Rheinhardt
Affected the integers FATE-test.

Signed-off-by: Andreas Rheinhardt 
---
 libavutil/integer.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/libavutil/integer.c b/libavutil/integer.c
index b709c6d487..a692c3783c 100644
--- a/libavutil/integer.c
+++ b/libavutil/integer.c
@@ -103,7 +103,7 @@ AVInteger av_shr_i(AVInteger a, int s){
 for(i=0; i>4);
 unsigned int v=0;
-if(index+1> (s&15);
 }
@@ -158,11 +158,9 @@ AVInteger av_int2i(int64_t a){
 }
 
 int64_t av_i2int(AVInteger a){
-int i;
-int64_t out=(int8_t)a.v[AV_INTEGER_SIZE-1];
+uint64_t out = 0;
 
-for(i= AV_INTEGER_SIZE-2; i>=0; i--){
+for (int i = 3; i >= 0; i--)
 out = (out<<16) + a.v[i];
-}
 return out;
 }
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 5/7] avutil/aes: Don't use out-of-bounds index

2022-10-21 Thread Andreas Rheinhardt
Up until now, av_aes_init() uses a->round_key[0].u8 + t
as dst of memcpy where it is intended for t to be greater
than 16 (u8 is an uint8_t[16]); given that round_key itself
is an array, it is actually intended for dst to be
in a latter round_key member. To do this properly,
just cast a->round_key to unsigned char*.

This fixes the srtp, aes, aes_ctr, mov-3elist-encrypted,
mov-frag-encrypted and mov-tenc-only-encrypted
FATE-tests with (Clang-)UBSan.

Signed-off-by: Andreas Rheinhardt 
---
 libavutil/aes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavutil/aes.c b/libavutil/aes.c
index 8b78daa782..2f08fb4164 100644
--- a/libavutil/aes.c
+++ b/libavutil/aes.c
@@ -253,7 +253,7 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, 
int decrypt)
 tk[j][i] ^= sbox[tk[j - 1][i]];
 }
 
-memcpy(a->round_key[0].u8 + t, tk, KC * 4);
+memcpy((unsigned char*)a->round_key + t, tk, KC * 4);
 }
 
 if (decrypt) {
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 4/7] avutil/aes: Don't use misaligned pointers

2022-10-21 Thread Andreas Rheinhardt
The AES code uses av_aes_block, a union consisting of
uint64_t[2], uint32_t[4], uint8_t[4][4] and uint8_t[16].
subshift() performs byte-wise manipulations of two av_aes_blocks,
but when encrypting, it does so with a shift of two bytes;
more precisely, it uses
"av_aes_block *s1 = (av_aes_block *) (s0[0].u8 - s)"
and lateron uses the uint8_t[16] member to access s0.
Yet av_aes_block requires to be suitably aligned for
the uint64_t[2] member, which s0[0].u8 - 2 is certainly
not. This is in violation of 6.3.2.3 (7) of C11. UBSan
reports this in the aes_ctr, mov-3elist-encrypted,
mov-frag-encrypted, mov-tenc-only-encrypted and srtp
tests.
Furthermore, there is another issue here: The pointer points
outside of s0; this works, because all the accesses lateron
use an index >= 3. (Clang-)UBSan reports this as
"runtime error: index -2 out of bounds for type 'uint8_t[16]'".

This commit fixes both of these issues: The latter issue
is fixed by applying an offset of "+ 3" during the cast
and subtracting this from the indices used lateron.
The former issue is solved by not casting to av_aes_block*
at all; instead simply cast to unsigned char*.

Signed-off-by: Andreas Rheinhardt 
---
 libavutil/aes.c | 22 --
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/libavutil/aes.c b/libavutil/aes.c
index 029d738f87..8b78daa782 100644
--- a/libavutil/aes.c
+++ b/libavutil/aes.c
@@ -80,25 +80,27 @@ static inline void addkey_d(uint8_t *dst, const 
av_aes_block *src,
 
 static void subshift(av_aes_block s0[2], int s, const uint8_t *box)
 {
-av_aes_block *s1 = (av_aes_block *) (s0[0].u8 - s);
-av_aes_block *s3 = (av_aes_block *) (s0[0].u8 + s);
+unsigned char *s1_dst = (unsigned char*)s0[0].u8 + 3 - s;
+const unsigned char *s1_src = s1_dst + sizeof(*s0);
+unsigned char *s3_dst = (unsigned char*)s0[0].u8 + s + 1;
+const unsigned char *s3_src = s3_dst + sizeof(*s0);
 
 s0[0].u8[ 0] = box[s0[1].u8[ 0]];
 s0[0].u8[ 4] = box[s0[1].u8[ 4]];
 s0[0].u8[ 8] = box[s0[1].u8[ 8]];
 s0[0].u8[12] = box[s0[1].u8[12]];
-s1[0].u8[ 3] = box[s1[1].u8[ 7]];
-s1[0].u8[ 7] = box[s1[1].u8[11]];
-s1[0].u8[11] = box[s1[1].u8[15]];
-s1[0].u8[15] = box[s1[1].u8[ 3]];
+s1_dst[ 0] = box[s1_src[ 4]];
+s1_dst[ 4] = box[s1_src[ 8]];
+s1_dst[ 8] = box[s1_src[12]];
+s1_dst[12] = box[s1_src[ 0]];
 s0[0].u8[ 2] = box[s0[1].u8[10]];
 s0[0].u8[10] = box[s0[1].u8[ 2]];
 s0[0].u8[ 6] = box[s0[1].u8[14]];
 s0[0].u8[14] = box[s0[1].u8[ 6]];
-s3[0].u8[ 1] = box[s3[1].u8[13]];
-s3[0].u8[13] = box[s3[1].u8[ 9]];
-s3[0].u8[ 9] = box[s3[1].u8[ 5]];
-s3[0].u8[ 5] = box[s3[1].u8[ 1]];
+s3_dst[ 0] = box[s3_src[12]];
+s3_dst[12] = box[s3_src[ 8]];
+s3_dst[ 8] = box[s3_src[ 4]];
+s3_dst[ 4] = box[s3_src[ 0]];
 }
 
 static inline int mix_core(uint32_t multbl[][256], int a, int b, int c, int d)
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 3/7] avcodec/snowenc: Fix invalid left shift of negative numbers

2022-10-21 Thread Andreas Rheinhardt
Affected the vsynth(1|2|_lena)-snow(|-hpel) tests.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/snowenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c
index ea0d4fc27f..ada24f7895 100644
--- a/libavcodec/snowenc.c
+++ b/libavcodec/snowenc.c
@@ -935,7 +935,7 @@ static av_always_inline int check_block_inter(SnowContext 
*s, int mb_x, int mb_y
 av_assert2(mb_x < b_stride);
 
 index = (p0 + 31 * p1) & (ME_CACHE_SIZE-1);
-value = s->me_cache_generation + (p0 >> 10) + (p1 << 6) + (block->ref << 
12);
+value = s->me_cache_generation + (p0 >> 10) + p1 * (1 << 6) + (block->ref 
<< 12);
 if (s->me_cache[index] == value)
 return 0;
 s->me_cache[index] = value;
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 24/24] avcodec/mpegvideo: Don't use ScanTable where unnecessary

2022-10-21 Thread Andreas Rheinhardt
Michael Niedermayer:
> On Thu, Oct 20, 2022 at 07:24:36PM +0200, Andreas Rheinhardt wrote:
>> For the intra_[hv]_scantables, only ScanTable.permutated
>> is used, so one only needs to keep that.
> [...]
>> diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
>> index 8e6e35b927..bf499a2206 100644
>> --- a/libavcodec/mpeg4videoenc.c
>> +++ b/libavcodec/mpeg4videoenc.c
>> @@ -175,7 +175,7 @@ static inline int decide_ac_pred(MpegEncContext *s, 
>> int16_t block[6][64],
>>  ac_val1[i + 8] = level;
>>  }
>>  }
>> -st[n] = s->intra_h_scantable.permutated;
>> +st[n] = s->intra_h_scantable;
>>  } else {
>>  const int xy = s->mb_x - 1 + s->mb_y * s->mb_stride;
>>  /* left prediction */
>> @@ -197,7 +197,7 @@ static inline int decide_ac_pred(MpegEncContext *s, 
>> int16_t block[6][64],
>>  ac_val1[i + 8] = block[n][s->idsp.idct_permutation[i]];
>>  }
>>  }
>> -st[n] = s->intra_v_scantable.permutated;
>> +st[n] = s->intra_v_scantable;
> 
> Iam thinking that replacing 
> s->intra_v_scantable.permutated
> by
> intra_v_scantable
> is semantically feeling inferrior to calling it
> permutated_intra_v_scantable
> or something like that
> 
> The same probably applies to te other patches too
> iam not happy about the long name but having consistent
> naming between scantables (as in the spec) and scantables permutated
> for idct optimizations could improve readability of the code
> 

Ok, will send a v2 with this changed.

- Andreas

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/7] avcodec/motion_est_template: Avoid using last + 1 element of array

2022-10-21 Thread Andreas Rheinhardt
For an int array[8][2] using [8][0] (which is an int*
pointing to the element beyond the last element of array)
triggers a "runtime error: index 8 out of bounds for type 'int[8][2]'"
from (Clang-)UBSan in the fate-vsynth(1|2|_lena)-snow tests.

I don't know whether this is really undefined behaviour or does not
actually fall under the "pointer arithmetic with the element beyond
the last element of the array is allowed as long as it is not
accessed" exception". All I know is that the code itself does not
read from beyond the last element of the array.

Nevertheless rewrite the code to a form that UBSan does not complain
about.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/motion_est_template.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/motion_est_template.c b/libavcodec/motion_est_template.c
index f3e94b7ebb..1888697db7 100644
--- a/libavcodec/motion_est_template.c
+++ b/libavcodec/motion_est_template.c
@@ -281,7 +281,7 @@ static int qpel_motion_search(MpegEncContext * s,
 for(i=0; i<8; i++){
 if(score < best[i]){
 memmove([i+1], [i], sizeof(int)*(7-i));
-memmove(_pos[i+1][0], _pos[i][0], 
sizeof(int)*2*(7-i));
+memmove(_pos[i + 1], _pos[i], 
sizeof(*best_pos) * (7 - i));
 best[i]= score;
 best_pos[i][0]= nx + 4*mx;
 best_pos[i][1]= ny + 4*my;
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/7] avcodec/snow_dwt: Fix left shifts of negative numbers

2022-10-21 Thread Andreas Rheinhardt
Affected the vsynth(1|2|_lena)-snow(|-hpel) tests.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/snow_dwt.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/snow_dwt.c b/libavcodec/snow_dwt.c
index 18b315ef66..965f409002 100644
--- a/libavcodec/snow_dwt.c
+++ b/libavcodec/snow_dwt.c
@@ -778,10 +778,10 @@ static inline int w_c(struct MpegEncContext *v, const 
uint8_t *pix1, const uint8
 
 for (i = 0; i < h; i++) {
 for (j = 0; j < w; j += 4) {
-tmp[32 * i + j + 0] = (pix1[j + 0] - pix2[j + 0]) << 4;
-tmp[32 * i + j + 1] = (pix1[j + 1] - pix2[j + 1]) << 4;
-tmp[32 * i + j + 2] = (pix1[j + 2] - pix2[j + 2]) << 4;
-tmp[32 * i + j + 3] = (pix1[j + 3] - pix2[j + 3]) << 4;
+tmp[32 * i + j + 0] = (pix1[j + 0] - pix2[j + 0]) * (1 << 4);
+tmp[32 * i + j + 1] = (pix1[j + 1] - pix2[j + 1]) * (1 << 4);
+tmp[32 * i + j + 2] = (pix1[j + 2] - pix2[j + 2]) * (1 << 4);
+tmp[32 * i + j + 3] = (pix1[j + 3] - pix2[j + 3]) * (1 << 4);
 }
 pix1 += line_size;
 pix2 += line_size;
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 2/2] ffmpeg: fix implementation of updated input start time

2022-10-21 Thread Gyan Doshi
The current adjustment of input start times just adjusts the tsoffset.
And it does so, by resetting the tsoffset to nullify the new start time.
This leads to breakage of -copyts, ignoring of input_ts_offset, breaking
of -isync as well as breaking wrap correction.

Fixed by taking cognizance of these parameters, and by correcting start times
just before sync offsets are applied.
---
 fftools/ffmpeg.c   |  2 +-
 fftools/ffmpeg.h   |  5 -
 fftools/ffmpeg_demux.c |  4 ++--
 fftools/ffmpeg_opt.c   | 33 +++--
 4 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 0fe582be3b..c564b2649e 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1815,7 +1815,7 @@ static void do_streamcopy(InputStream *ist, OutputStream 
*ost, const AVPacket *p
 start_time = 0;
 if (copy_ts) {
 start_time += f->start_time != AV_NOPTS_VALUE ? f->start_time : 0;
-start_time += start_at_zero ? 0 : f->ctx->start_time;
+start_time += start_at_zero ? 0 : f->start_time_effective;
 }
 if (ist->pts >= f->recording_time + start_time) {
 close_output_stream(ost);
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 5966cac60e..2d97ccaa15 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -447,7 +447,10 @@ typedef struct InputFile {
 AVRational time_base; /* time base of the duration */
 int64_t input_ts_offset;
 int input_sync_ref;
-
+/**
+ * Effective format start time based on enabled streams.
+ */
+int64_t start_time_effective;
 int64_t ts_offset;
 /**
  * Extra timestamp offset added by discontinuity handling.
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 6e89f5999a..220fda56da 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -120,7 +120,7 @@ static int seek_to_start(InputFile *ifile)
 static void ts_fixup(InputFile *ifile, AVPacket *pkt, int *repeat_pict)
 {
 InputStream *ist = input_streams[ifile->ist_index + pkt->stream_index];
-const int64_t start_time = ifile->ctx->start_time;
+const int64_t start_time = ifile->start_time_effective;
 int64_t duration;
 
 if (debug_ts) {
@@ -367,7 +367,7 @@ int ifile_get_packet(InputFile *f, AVPacket **pkt)
 if (f->readrate || f->rate_emu) {
 int i;
 int64_t file_start = copy_ts * (
-  (f->ctx->start_time != AV_NOPTS_VALUE ? 
f->ctx->start_time * !start_at_zero : 0) +
+  (f->start_time_effective != AV_NOPTS_VALUE ? 
f->start_time_effective * !start_at_zero : 0) +
   (f->start_time != AV_NOPTS_VALUE ? f->start_time 
: 0)
  );
 float scale = f->rate_emu ? 1.0 : f->readrate;
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 28b7d4dc27..a6fa9b7801 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -216,13 +216,15 @@ int parse_and_set_vsync(const char *arg, int *vsync_var, 
int file_idx, int st_id
 return 0;
 }
 
+/* Correct input file start times based on enabled streams */
 static void correct_input_start_times(void)
 {
-// Correct starttime based on the enabled streams
 for (int i = 0; i < nb_input_files; i++) {
 InputFile   *ifile = input_files[i];
 AVFormatContext*is = ifile->ctx;
-int64_t new_start_time = INT64_MAX;
+int64_t new_start_time = INT64_MAX, diff, abs_start_seek;
+
+ifile->start_time_effective = is->start_time;
 
 if (is->start_time == AV_NOPTS_VALUE ||
 !(is->iformat->flags & AVFMT_TS_DISCONT))
@@ -234,9 +236,20 @@ static void correct_input_start_times(void)
 continue;
 new_start_time = FFMIN(new_start_time, 
av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q));
 }
-if (new_start_time > is->start_time) {
-av_log(is, AV_LOG_VERBOSE, "Correcting start time by %"PRId64"\n", 
new_start_time - is->start_time);
-ifile->ts_offset = -new_start_time;
+
+diff = new_start_time - is->start_time;
+if (diff) {
+av_log(NULL, AV_LOG_VERBOSE, "Correcting start time of Input #%d 
by %"PRId64" us.\n", i, diff);
+ifile->start_time_effective = new_start_time;
+if (copy_ts && start_at_zero)
+ifile->ts_offset = -new_start_time;
+else if (!copy_ts) {
+abs_start_seek = is->start_time + (ifile->start_time != 
AV_NOPTS_VALUE) ? ifile->start_time : 0;
+ifile->ts_offset = abs_start_seek > new_start_time ? 
-abs_start_seek : -new_start_time;
+} else if (copy_ts)
+ifile->ts_offset = 0;
+
+ifile->ts_offset += ifile->input_ts_offset;
 }
 }
 }
@@ -269,9 +282,9 @@ static int apply_sync_offsets(void)
 if (self->ctx->start_time_realtime != AV_NOPTS_VALUE && 

[FFmpeg-devel] [PATCH v2 1/2] ffmpeg: shift start time correction to ffmpeg_opt

2022-10-21 Thread Gyan Doshi
In preparation for applying start time correction that accounts for all
factors such as copyts, input_ts_offset ..etc
---
 fftools/ffmpeg.c | 22 --
 fftools/ffmpeg_opt.c | 27 +++
 2 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index e57486fd4a..0fe582be3b 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3194,28 +3194,6 @@ static int transcode_init(void)
 input_streams[j + ifile->ist_index]->start = 
av_gettime_relative();
 }
 
-// Correct starttime based on the enabled streams
-for (i = 0; i < nb_input_files; i++) {
-InputFile   *ifile = input_files[i];
-AVFormatContext*is = ifile->ctx;
-int64_t new_start_time = INT64_MAX;
-
-if (is->start_time == AV_NOPTS_VALUE ||
-!(is->iformat->flags & AVFMT_TS_DISCONT))
-continue;
-
-for (int j = 0; j < is->nb_streams; j++) {
-AVStream *st = is->streams[j];
-if(st->discard == AVDISCARD_ALL || st->start_time == 
AV_NOPTS_VALUE)
-continue;
-new_start_time = FFMIN(new_start_time, 
av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q));
-}
-if (new_start_time > is->start_time) {
-av_log(is, AV_LOG_VERBOSE, "Correcting start time by %"PRId64"\n", 
new_start_time - is->start_time);
-ifile->ts_offset = -new_start_time;
-}
-}
-
 /* init input streams */
 for (i = 0; i < nb_input_streams; i++)
 if ((ret = init_input_stream(i, error, sizeof(error))) < 0)
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 9245e02813..28b7d4dc27 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -216,6 +216,31 @@ int parse_and_set_vsync(const char *arg, int *vsync_var, 
int file_idx, int st_id
 return 0;
 }
 
+static void correct_input_start_times(void)
+{
+// Correct starttime based on the enabled streams
+for (int i = 0; i < nb_input_files; i++) {
+InputFile   *ifile = input_files[i];
+AVFormatContext*is = ifile->ctx;
+int64_t new_start_time = INT64_MAX;
+
+if (is->start_time == AV_NOPTS_VALUE ||
+!(is->iformat->flags & AVFMT_TS_DISCONT))
+continue;
+
+for (int j = 0; j < is->nb_streams; j++) {
+AVStream *st = is->streams[j];
+if(st->discard == AVDISCARD_ALL || st->start_time == 
AV_NOPTS_VALUE)
+continue;
+new_start_time = FFMIN(new_start_time, 
av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q));
+}
+if (new_start_time > is->start_time) {
+av_log(is, AV_LOG_VERBOSE, "Correcting start time by %"PRId64"\n", 
new_start_time - is->start_time);
+ifile->ts_offset = -new_start_time;
+}
+}
+}
+
 static int apply_sync_offsets(void)
 {
 for (int i = 0; i < nb_input_files; i++) {
@@ -1909,6 +1934,8 @@ int ffmpeg_parse_options(int argc, char **argv)
 goto fail;
 }
 
+correct_input_start_times();
+
 check_filter_outputs();
 
 fail:
-- 
2.36.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avformat/yuv4mpegdec: increase header limit

2022-10-21 Thread Paul B Mahol
On 10/20/22, Chema Gonzalez  wrote:
> From: Chema Gonzalez 
>
> Allows demuxing UHD F10: fps yuvj420p files
>
> ffmpeg (at HEAD as of now) is creating this:
>
> ```
> $ ffmpeg -y -i source.265 /tmp/foo.y4m >& /dev/null
> ...
> $ xxd /tmp/raw.y4m |less
> : 5955 5634 4d50 4547 3220 5731 3932 3020  YUV4MPEG2 W1920
> 0010: 4831 3038 3020 4631 3030 3030 3030 3030  H1080 F1
> 0020: 303a     2049 7020 4130  0: Ip A0
> 0030: 3a30 2043 3432 306d 7065 6732 2058 5953  :0 C420mpeg2 XYS
> 0040: 4353 533d 3432 304d 5045 4732 2058 434f  CSS=420MPEG2 XCO
> 0050: 4c4f 5252 414e 4745 3d4c 494d 4954 4544  LORRANGE=LIMITED
> 0060: 0a46 5241 4d45 0a82 8282 8282 8282 8282  .FRAME..
> ...
> ```
>
> Which cannot be parsed by the same ffmpeg decoder:
> ```
> $ ffmpeg -i /tmp/foo.y4m /tmp/bar.y4m
> ...
> [yuv4mpegpipe @ 0x2b69a40] Header too large.
> /tmp/foo.y4m: Invalid argument
> ```
>
> This is kicking the ball (per 0b1ff3265e9bdad3b4b6b97ced2f126cb3599568),
> but seems to work.
> ---
>  libavformat/yuv4mpegdec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavformat/yuv4mpegdec.c b/libavformat/yuv4mpegdec.c
> index b24275acc1..c0972af7de 100644
> --- a/libavformat/yuv4mpegdec.c
> +++ b/libavformat/yuv4mpegdec.c
> @@ -27,7 +27,7 @@
>  #include "yuv4mpeg.h"
>
>  /* Header size increased to allow room for optional flags */
> -#define MAX_YUV4_HEADER 96
> +#define MAX_YUV4_HEADER 128
>  #define MAX_FRAME_HEADER 80
>
>  static int yuv4_read_header(AVFormatContext *s)
> --
> 2.37.3
>



will apply soon.

> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] RFC: v210enc optimisations and initial AVX-512

2022-10-21 Thread Henrik Gramner
On Fri, Oct 21, 2022 at 5:41 AM Kieran Kunhya  wrote:
>
> Hi,
>
> Please see attached an attempt to optimise the 8-bit input to v210enc to
> reduce the number of shuffles.
> This comes at the cost of having to extract the middle element and perform
> a DWORD shift on it and then reinserting it.
> I have added a few comments but any other ideas are welcome.

Random untested idea:

A: db 32,  0, 48, -1,  1, 33,  2, -1, 49,  3, 34, -1,  4, 50,  5, -1
   db 35,  6, 51, -1,  7, 36,  8, -1, 52,  9, 37, -1, 10, 53, 11, -1
   db 38, 12, 54, -1, 13, 39, 14, -1, 55, 15, 40, -1, 16, 56, 17, -1
   db 41, 18, 57, -1, 19, 42, 20, -1, 58, 21, 43, -1, 22, 59, 23, -1
B: db  1,  0, 16,  0
C: dd 0x0003fc00

[...]

mova  m2, [A]
vpbroadcastd  m3, [B]
vpbroadcastd  m6, [C]

[...]

.loop:
movu ym1, [yq]
vinserti32x4  m1, [uq], 2
vinserti32x4  m1, [vq], 3
CLIPUBm1, m4, m5
vpermbm1, m2, m1
pmaddubsw m0, m1, m3
pslld m1, 2
vpternlogdm0, m1, m6, 0xca
movu  [dstq], m0

I guess it could also be scaled to ymm if you're a big Skylake fan :P
(in which case you'd probably want to reorder the shuffle indices so
that chroma comes first, i.e. movq [u] + movhps [v] + vinserti32x4
[y])
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] avfilter/vf_threshold: fix handling of zero threshold

2022-10-21 Thread Paul B Mahol
Patch attached.
From 1b4cc348d05677aa844a8c553d9242812dc6890d Mon Sep 17 00:00:00 2001
From: Paul B Mahol 
Date: Thu, 20 Oct 2022 19:38:55 +0200
Subject: [PATCH] avfilter/vf_threshold: fix handling of zero threshold

Signed-off-by: Paul B Mahol 
---
 libavfilter/vf_threshold_init.h  |  4 ++--
 libavfilter/x86/vf_threshold.asm | 23 ---
 2 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/libavfilter/vf_threshold_init.h b/libavfilter/vf_threshold_init.h
index 7d160ddbb9..64a0a861ba 100644
--- a/libavfilter/vf_threshold_init.h
+++ b/libavfilter/vf_threshold_init.h
@@ -38,7 +38,7 @@ static void threshold8(const uint8_t *in, const uint8_t *threshold,
 {
 for (int y = 0; y < h; y++) {
 for (int x = 0; x < w; x++)
-out[x] = in[x] < threshold[x] ? min[x] : max[x];
+out[x] = in[x] <= threshold[x] ? min[x] : max[x];
 
 in+= ilinesize;
 threshold += tlinesize;
@@ -64,7 +64,7 @@ static void threshold16(const uint8_t *iin, const uint8_t *tthreshold,
 
 for (int y = 0; y < h; y++) {
 for (int x = 0; x < w; x++)
-out[x] = in[x] < threshold[x] ? min[x] : max[x];
+out[x] = in[x] <= threshold[x] ? min[x] : max[x];
 
 in+= ilinesize / 2;
 threshold += tlinesize / 2;
diff --git a/libavfilter/x86/vf_threshold.asm b/libavfilter/x86/vf_threshold.asm
index 098069b083..8977a586c0 100644
--- a/libavfilter/x86/vf_threshold.asm
+++ b/libavfilter/x86/vf_threshold.asm
@@ -22,15 +22,10 @@
 
 %include "libavutil/x86/x86util.asm"
 
-SECTION_RODATA
-
-pb_128: times 16 db 128
-pb_128_0 : times 8 db 0, 128
-
 SECTION .text
 
-;%1 depth (8 or 16) ; %2 b or w ; %3 constant
-%macro THRESHOLD 3
+;%1 depth (8 or 16) ; %2 b or w
+%macro THRESHOLD 2
 %if ARCH_X86_64
 cglobal threshold%1, 10, 13, 5, in, threshold, min, max, out, ilinesize, tlinesize, flinesize, slinesize, olinesize, w, h, x
 mov wd, dword wm
@@ -45,7 +40,6 @@ cglobal threshold%1, 5, 7, 5, in, threshold, min, max, out, w, x
 %define olinesizeq  r9mp
 %define hd  r11mp
 %endif
-VBROADCASTI128  m4, [%3]
 %if %1 == 16
 add wq, wq ; w *= 2 (16 bits instead of 8)
 %endif
@@ -63,9 +57,8 @@ cglobal threshold%1, 5, 7, 5, in, threshold, min, max, out, w, x
 movum0, [thresholdq + xq]
 movum2, [minq + xq]
 movum3, [maxq + xq]
-pxorm0, m4
-pxorm1, m4
-pcmpgt%2m0, m1
+pminu%2 m0, m1
+pcmpeq%2m0, m1
 PBLENDVBm3, m2, m0
 movu   [outq + xq], m3
 add xq, mmsize
@@ -82,11 +75,11 @@ RET
 %endmacro
 
 INIT_XMM sse4
-THRESHOLD 8, b, pb_128
-THRESHOLD 16, w, pb_128_0
+THRESHOLD 8, b
+THRESHOLD 16, w
 
 %if HAVE_AVX2_EXTERNAL
 INIT_YMM avx2
-THRESHOLD 8, b, pb_128
-THRESHOLD 16, w, pb_128_0
+THRESHOLD 8, b
+THRESHOLD 16, w
 %endif
-- 
2.37.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] avutil/integer: ignore the upper bits of AVInteger in av_i2int()

2022-10-21 Thread James Almer
The function is meant to return the least significant 64 bits after all.
Should fix undefined behavior (left shift of negative values) as reported by 
ubsan.

Signed-off-by: James Almer 
---
 libavutil/integer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavutil/integer.c b/libavutil/integer.c
index b709c6d487..4ba33bcbc5 100644
--- a/libavutil/integer.c
+++ b/libavutil/integer.c
@@ -159,9 +159,9 @@ AVInteger av_int2i(int64_t a){
 
 int64_t av_i2int(AVInteger a){
 int i;
-int64_t out=(int8_t)a.v[AV_INTEGER_SIZE-1];
+int64_t out = a.v[AV_INTEGER_SIZE - 5];
 
-for(i= AV_INTEGER_SIZE-2; i>=0; i--){
+for (i = AV_INTEGER_SIZE - 6; i >= 0; i--) {
 out = (out<<16) + a.v[i];
 }
 return out;
-- 
2.37.3

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/2] avcodec/ac3_parser: improve false positive detection when parsing sync frames

2022-10-21 Thread James Almer
A two byte sync word is not enough to ensure we got a real syncframe, nor are
all the range checks we do in the first seven bytes. Do therefore an integrity
check for the sync frame in order to prevent the parser from filling avctx with
bogus information.

Signed-off-by: James Almer 
---
 libavcodec/aac_ac3_parser.c | 38 +
 libavcodec/aac_ac3_parser.h |  2 ++
 libavcodec/ac3_parser.c |  1 +
 3 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/libavcodec/aac_ac3_parser.c b/libavcodec/aac_ac3_parser.c
index b14b1e31f9..1279db6e05 100644
--- a/libavcodec/aac_ac3_parser.c
+++ b/libavcodec/aac_ac3_parser.c
@@ -24,8 +24,11 @@
 
 #include "libavutil/channel_layout.h"
 #include "libavutil/common.h"
+#include "libavutil/intreadwrite.h"
 #include "parser.h"
 #include "aac_ac3_parser.h"
+#include "ac3_parser.h"
+#include "ac3_parser_internal.h"
 
 int ff_aac_ac3_parse(AVCodecParserContext *s1,
  AVCodecContext *avctx,
@@ -79,10 +82,6 @@ get_next:
 *poutbuf = buf;
 *poutbuf_size = buf_size;
 
-/* update codec info */
-if(s->codec_id)
-avctx->codec_id = s->codec_id;
-
 if (got_frame) {
 /* Due to backwards compatible HE-AAC the sample rate, channel count,
and total number of samples found in an AAC ADTS header are not
@@ -90,6 +89,34 @@ get_next:
duration in seconds is still correct (as is the number of bits in
the frame). */
 if (avctx->codec_id != AV_CODEC_ID_AAC) {
+int offset = ff_ac3_find_syncword(buf, buf_size);
+
+if (offset < 0)
+return i;
+
+buf += offset;
+buf_size -= offset;
+while (buf_size > 0) {
+uint16_t frame_size;
+uint8_t bsid;
+int ret = av_ac3_parse_header(buf, buf_size, , 
_size);
+
+if (ret < 0 || frame_size > buf_size)
+return i;
+
+/* Check for false positives since the syncword is not enough,
+   and only for the last syncframe in the buffer, as that was
+   used to fill AACAC3ParseContext. See section 6.1.2 of A/52. 
*/
+if (buf_size > frame_size) {
+buf += frame_size;
+buf_size -= frame_size;
+continue;
+}
+if (av_crc(s->crc_ctx, 0, buf + 2, frame_size - 4) != 
AV_RL16(buf + frame_size - 2))
+return i;
+break;
+}
+
 avctx->sample_rate = s->sample_rate;
 if (!CONFIG_EAC3_DECODER || avctx->codec_id != AV_CODEC_ID_EAC3) {
 av_channel_layout_uninit(>ch_layout);
@@ -110,6 +137,9 @@ FF_ENABLE_DEPRECATION_WARNINGS
 avctx->audio_service_type = s->service_type;
 }
 
+if(s->codec_id)
+avctx->codec_id = s->codec_id;
+
 /* Calculate the average bit rate */
 s->frame_number++;
 if (!CONFIG_EAC3_DECODER || avctx->codec_id != AV_CODEC_ID_EAC3) {
diff --git a/libavcodec/aac_ac3_parser.h b/libavcodec/aac_ac3_parser.h
index 8b93cbf84f..9d56606f2e 100644
--- a/libavcodec/aac_ac3_parser.h
+++ b/libavcodec/aac_ac3_parser.h
@@ -24,6 +24,7 @@
 #define AVCODEC_AAC_AC3_PARSER_H
 
 #include 
+#include "libavutil/crc.h"
 #include "avcodec.h"
 #include "parser.h"
 
@@ -44,6 +45,7 @@ typedef struct AACAC3ParseContext {
 int (*sync)(uint64_t state, struct AACAC3ParseContext *hdr_info,
 int *need_next_header, int *new_frame_start);
 
+const AVCRC *crc_ctx;
 int channels;
 int sample_rate;
 int bit_rate;
diff --git a/libavcodec/ac3_parser.c b/libavcodec/ac3_parser.c
index 425e1b4742..ecbc63ce9a 100644
--- a/libavcodec/ac3_parser.c
+++ b/libavcodec/ac3_parser.c
@@ -260,6 +260,7 @@ static av_cold int ac3_parse_init(AVCodecParserContext *s1)
 {
 AACAC3ParseContext *s = s1->priv_data;
 s->header_size = AC3_HEADER_SIZE;
+s->crc_ctx = av_crc_get_table(AV_CRC_16_ANSI);
 s->sync = ac3_sync;
 return 0;
 }
-- 
2.37.3

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/2] avcodec/ac3dec: split off code discarding garbage at the beginning of a packet

2022-10-21 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/ac3_parser.c  | 19 +++
 libavcodec/ac3_parser_internal.h |  2 ++
 libavcodec/ac3dec.c  | 15 ++-
 3 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/libavcodec/ac3_parser.c b/libavcodec/ac3_parser.c
index 4f154bb7c4..425e1b4742 100644
--- a/libavcodec/ac3_parser.c
+++ b/libavcodec/ac3_parser.c
@@ -53,6 +53,25 @@ static const uint8_t center_levels[4] = { 4, 5, 6, 5 };
  */
 static const uint8_t surround_levels[4] = { 4, 6, 7, 6 };
 
+int ff_ac3_find_syncword(const uint8_t *buf, int buf_size)
+{
+int i;
+
+for (i = 1; i < buf_size; i += 2) {
+if (buf[i] == 0x77 || buf[i] == 0x0B) {
+if ((buf[i] ^ buf[i-1]) == (0x77 ^ 0x0B)) {
+i--;
+break;
+} else if ((buf[i] ^ buf[i+1]) == (0x77 ^ 0x0B)) {
+break;
+}
+}
+}
+if (i >= buf_size)
+return AVERROR_INVALIDDATA;
+
+return i;
+}
 
 int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
 {
diff --git a/libavcodec/ac3_parser_internal.h b/libavcodec/ac3_parser_internal.h
index bd4e1bbffb..2ac0e67ec2 100644
--- a/libavcodec/ac3_parser_internal.h
+++ b/libavcodec/ac3_parser_internal.h
@@ -79,4 +79,6 @@ int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo 
*hdr);
 int avpriv_ac3_parse_header(AC3HeaderInfo **hdr, const uint8_t *buf,
 size_t size);
 
+int ff_ac3_find_syncword(const uint8_t *buf, int buf_size);
+
 #endif /* AVCODEC_AC3_PARSER_INTERNAL_H */
diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index 340f6e1e37..8e40587ff1 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -1508,19 +1508,8 @@ static int ac3_decode_frame(AVCodecContext *avctx, 
AVFrame *frame,
 s->superframe_size = 0;
 
 buf_size = full_buf_size;
-for (i = 1; i < buf_size; i += 2) {
-if (buf[i] == 0x77 || buf[i] == 0x0B) {
-if ((buf[i] ^ buf[i-1]) == (0x77 ^ 0x0B)) {
-i--;
-break;
-} else if ((buf[i] ^ buf[i+1]) == (0x77 ^ 0x0B)) {
-break;
-}
-}
-}
-if (i >= buf_size)
-return AVERROR_INVALIDDATA;
-if (i > 10)
+i = ff_ac3_find_syncword(buf, buf_size);
+if (i < 0 || i > 10)
 return i;
 buf += i;
 buf_size -= i;
-- 
2.37.3

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] tools: add an AV_CODEC_CAP_ENCODER_RECON_FRAME test tool

2022-10-21 Thread James Almer

On 10/21/2022 5:30 AM, Anton Khirnov wrote:

+static int frame_hash(FrameChecksum **pc, size_t *nb_c, int64_t ts,
+  const AVFrame *frame)
+{
+FrameChecksum *c;
+int shift_h, shift_v;
+
+c = av_realloc_array(*pc, *nb_c + 1, sizeof(*c));


Use av_fast_realloc(), or the size_t replacement if it's pushed before 
this. Or maybe port this to AVFifo with auto grow. Either case will 
reduce the amount of reallocations considerably.



+if (!c)
+return AVERROR(ENOMEM);
+*pc = c;
+(*nb_c)++;
+
+c += *nb_c - 1;
+memset(c, 0, sizeof(*c));
+
+av_pix_fmt_get_chroma_sub_sample(frame->format, _h, _v);
+
+c->ts = ts;
+for (int p = 0; frame->data[p]; p++) {
+const uint8_t *data = frame->data[p];
+int linesize = av_image_get_linesize(frame->format, frame->width, p);
+uint32_t checksum = 0;
+
+for (int j = 0; j < frame->height >> shift_v; j++) {


Isn't the shift meant for the chroma planes only?


+checksum = av_adler32_update(checksum, data, linesize);
+data += frame->linesize[p];
+}
+
+c->checksum[p] = checksum;
+}
+
+return 0;
+}

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v5] avformat/hls: Add option to retry failed segments for hls

2022-10-21 Thread Steven Liu
gnattu  于2022年10月20日周四 20:12写道:
>
> Current HLS implementation simply skip a failed segment to catch up
> the stream, but this is not optimal for some use cases like livestream
> recording.
> Add an option to retry a failed segment to ensure the output file is
> a complete stream.
>
> Signed-off-by: gnattu 
> ---
> v5 changed coding style as requested
> v4 added documentation for the new seg_max_try option
>
>  doc/demuxers.texi |  4 
>  libavformat/hls.c | 15 ++-
>  2 files changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/doc/demuxers.texi b/doc/demuxers.texi
> index 2b6dd86c2a..3e09a0f14e 100644
> --- a/doc/demuxers.texi
> +++ b/doc/demuxers.texi
> @@ -401,6 +401,10 @@ Use HTTP partial requests for downloading HTTP segments.
>
>  @item seg_format_options
>  Set options for the demuxer of media segments using a list of key=value 
> pairs separated by @code{:}.
> +
> +@item seg_max_retry
> +Maximum number of times to reload a segment on error, useful when segment 
> skip on network error is not desired.
> +Default value is 0.
>  @end table
>
>  @section image2
> diff --git a/libavformat/hls.c b/libavformat/hls.c
> index e622425e80..2a5ffb927f 100644
> --- a/libavformat/hls.c
> +++ b/libavformat/hls.c
> @@ -225,6 +225,7 @@ typedef struct HLSContext {
>  int http_persistent;
>  int http_multiple;
>  int http_seekable;
> +int seg_max_retry;
>  AVIOContext *playlist_pb;
>  HLSCryptoContext  crypto_ctx;
>  } HLSContext;
> @@ -1472,6 +1473,7 @@ static int read_data(void *opaque, uint8_t *buf, int 
> buf_size)
>  int ret;
>  int just_opened = 0;
>  int reload_count = 0;
> +int segment_retries = 0;
>  struct segment *seg;
>
>  restart:
> @@ -1563,9 +1565,18 @@ reload:
>  av_log(v->parent, AV_LOG_WARNING, "Failed to open segment 
> %"PRId64" of playlist %d\n",
> v->cur_seq_no,
> v->index);
> -v->cur_seq_no += 1;
> +if (segment_retries >= c->seg_max_retry) {
> +av_log(v->parent, AV_LOG_WARNING, "Segment %"PRId64" of 
> playlist %d failed too many times, skipping\n",
> +   v->cur_seq_no,
> +   v->index);
> +v->cur_seq_no++;
> +segment_retries = 0;
> +} else {
> +segment_retries++;
> +}
>  goto reload;
>  }
> +segment_retries = 0;
>  just_opened = 1;
>  }
>
> @@ -2549,6 +2560,8 @@ static const AVOption hls_options[] = {
>  OFFSET(http_seekable), AV_OPT_TYPE_BOOL, { .i64 = -1}, -1, 1, FLAGS},
>  {"seg_format_options", "Set options for segment demuxer",
>  OFFSET(seg_format_opts), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, 
> FLAGS},
> +{"seg_max_retry", "Maximum number of times to reload a segment on 
> error.",
> + OFFSET(seg_max_retry), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS},
>  {NULL}
>  };
>
> --
> 2.37.0 (Apple Git-136)
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

LGTM

Thanks
Steven
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] tools: add an AV_CODEC_CAP_ENCODER_RECON_FRAME test tool

2022-10-21 Thread Anton Khirnov
---
 Makefile |   2 +
 tools/Makefile   |   3 +-
 tools/enc_recon_frame_test.c | 391 +++
 3 files changed, 395 insertions(+), 1 deletion(-)
 create mode 100644 tools/enc_recon_frame_test.c

diff --git a/Makefile b/Makefile
index 1fb742f390..bf1b69f96b 100644
--- a/Makefile
+++ b/Makefile
@@ -67,6 +67,8 @@ tools/target_io_dem_fuzzer$(EXESUF): 
tools/target_io_dem_fuzzer.o $(FF_DEP_LIBS)
 
 tools/enum_options$(EXESUF): ELIBS = $(FF_EXTRALIBS)
 tools/enum_options$(EXESUF): $(FF_DEP_LIBS)
+tools/enc_recon_frame_test$(EXESUF): $(FF_DEP_LIBS)
+tools/enc_recon_frame_test$(EXESUF): ELIBS = $(FF_EXTRALIBS)
 tools/scale_slice_test$(EXESUF): $(FF_DEP_LIBS)
 tools/scale_slice_test$(EXESUF): ELIBS = $(FF_EXTRALIBS)
 tools/sofa2wavs$(EXESUF): ELIBS = $(FF_EXTRALIBS)
diff --git a/tools/Makefile b/tools/Makefile
index 4afa23342d..dee6a41668 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -1,4 +1,4 @@
-TOOLS = enum_options qt-faststart scale_slice_test trasher uncoded_frame
+TOOLS = enc_recon_frame_test enum_options qt-faststart scale_slice_test 
trasher uncoded_frame
 TOOLS-$(CONFIG_LIBMYSOFA) += sofa2wavs
 TOOLS-$(CONFIG_ZLIB) += cws2fws
 
@@ -17,6 +17,7 @@ tools/target_dem_fuzzer.o: tools/target_dem_fuzzer.c
 tools/target_io_dem_fuzzer.o: tools/target_dem_fuzzer.c
$(COMPILE_C) -DIO_FLAT=0
 
+tools/enc_recon_frame_test$(EXESUF): tools/decode_simple.o
 tools/venc_data_dump$(EXESUF): tools/decode_simple.o
 tools/scale_slice_test$(EXESUF): tools/decode_simple.o
 
diff --git a/tools/enc_recon_frame_test.c b/tools/enc_recon_frame_test.c
new file mode 100644
index 00..8450bad4d1
--- /dev/null
+++ b/tools/enc_recon_frame_test.c
@@ -0,0 +1,391 @@
+/*
+ * copyright (c) 2022 Anton Khirnov 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/* A test for AV_CODEC_FLAG_RECON_FRAME
+ * TODO: dump reconstructed frames to disk */
+
+#include 
+#include 
+#include 
+
+#include "decode_simple.h"
+
+#include "libavutil/adler32.h"
+#include "libavutil/common.h"
+#include "libavutil/error.h"
+#include "libavutil/frame.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
+
+#include "libavformat/avformat.h"
+
+#include "libavcodec/avcodec.h"
+#include "libavcodec/codec.h"
+
+#include "libswscale/swscale.h"
+
+typedef struct FrameChecksum {
+int64_t  ts;
+uint32_t checksum[4];
+} FrameChecksum;
+
+typedef struct PrivData {
+AVCodecContext *enc;
+AVCodecContext *dec;
+
+int64_t pts_in;
+
+AVPacket *pkt;
+AVFrame  *frame, *frame_recon;
+
+struct SwsContext *scaler;
+
+FrameChecksum *checksums_decoded;
+size_t  nb_checksums_decoded;
+FrameChecksum *checksums_recon;
+size_t  nb_checksums_recon;
+} PrivData;
+
+static int frame_hash(FrameChecksum **pc, size_t *nb_c, int64_t ts,
+  const AVFrame *frame)
+{
+FrameChecksum *c;
+int shift_h, shift_v;
+
+c = av_realloc_array(*pc, *nb_c + 1, sizeof(*c));
+if (!c)
+return AVERROR(ENOMEM);
+*pc = c;
+(*nb_c)++;
+
+c += *nb_c - 1;
+memset(c, 0, sizeof(*c));
+
+av_pix_fmt_get_chroma_sub_sample(frame->format, _h, _v);
+
+c->ts = ts;
+for (int p = 0; frame->data[p]; p++) {
+const uint8_t *data = frame->data[p];
+int linesize = av_image_get_linesize(frame->format, frame->width, p);
+uint32_t checksum = 0;
+
+for (int j = 0; j < frame->height >> shift_v; j++) {
+checksum = av_adler32_update(checksum, data, linesize);
+data += frame->linesize[p];
+}
+
+c->checksum[p] = checksum;
+}
+
+return 0;
+}
+
+static int recon_frame_process(PrivData *pd, const AVPacket *pkt)
+{
+AVFrame *f = pd->frame_recon;
+int ret;
+
+ret = avcodec_receive_frame(pd->enc, f);
+if (ret < 0) {
+fprintf(stderr, "Error retrieving a reconstructed frame\n");
+return ret;
+}
+
+// the encoder's internal format (in which the reconsturcted frames are
+// exported) may be different from the user-facing pixel format
+if (f->format != pd->enc->pix_fmt) {
+if (!pd->scaler) {
+pd->scaler = sws_getContext(f->width, f->height, f->format,
+

Re: [FFmpeg-devel] [PATCH 1/4] lavu/thread: add an internal function for setting thread name

2022-10-21 Thread Anton Khirnov
Will push the set soonish if nobody has more comments.

-- 
Anton Khirnov
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v5 0/6] Implement SEI parsing for QSV decoders

2022-10-21 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of
> Andreas Rheinhardt
> Sent: Thursday, July 21, 2022 11:56 PM
> To: Xiang, Haihao ; ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH v5 0/6] Implement SEI parsing for
> QSV decoders
> 
> Xiang, Haihao:
> > On Fri, 2022-07-01 at 20:48 +, ffmpegagent wrote:
> >> Missing SEI information has always been a major drawback when
> using the QSV
> >> decoders. I used to think that there's no chance to get at the
> data without
> >> explicit implementation from the MSDK side (or doing something
> weird like
> >> parsing in parallel). It turned out that there's a hardly known
> api method
> >> that provides access to all SEI (h264/hevc) or user data
> (mpeg2video).
> >>
> >> This allows to get things like closed captions, frame packing,
> display
> >> orientation, HDR data (mastering display, content light level,
> etc.) without
> >> having to rely on those data being provided by the MSDK as
> extended buffers.
> >>
> >> The commit "Implement SEI parsing for QSV decoders" includes some
> hard-coded
> >> workarounds for MSDK bugs which I reported:
> >>
> > https://github.com/Intel-Media-
> SDK/MediaSDK/issues/2597#issuecomment-1072795311
> >>
> >> But that doesn't help. Those bugs exist and I'm sharing my
> workarounds,
> >> which are empirically determined by testing a range of files. If
> someone is
> >> interested, I can provide private access to a repository where we
> have been
> >> testing this. Alternatively, I could also leave those workarounds
> out, and
> >> just skip those SEI types.
> >>
> >> In a previous version of this patchset, there was a concern that
> payload
> >> data might need to be re-ordered. Meanwhile I have researched this
> carefully
> >> and the conclusion is that this is not required.
> >>
> >> My detailed analysis can be found here:
> >> https://gist.github.com/softworkz/36c49586a8610813a32270ee3947a932
> >>
> >> v4
> >>
> >>  * add new dependencies in makefile Now, build still works when
> someone uses
> >>configure --disable-decoder=h264 --disable-decoder=hevc
> >>--disable-decoder=mpegvideo --disable-decoder=mpeg1video
> >>--disable-decoder=mpeg2video --enable-libmfx
> >>
> >> v3
> >>
> >>  * frame.h: clarify doc text for av_frame_copy_side_data()
> >>
> >> v2
> >>
> >>  * qsvdec: make error handling consistent and clear
> >>  * qsvdec: remove AV_CODEC_ID_MPEG1VIDEO constants
> >>  * hevcdec: rename function to ff_hevc_set_side_data(), add doc
> text
> >>
> >> v3
> >>
> >>  * qsvdec: fix c/p error
> >>
> >> softworkz (6):
> >>   avutil/frame: Add av_frame_copy_side_data() and
> >> av_frame_remove_all_side_data()
> >>   avcodec/vpp_qsv: Copy side data from input to output frame
> >>   avcodec/mpeg12dec: make mpeg_decode_user_data() accessible
> >>   avcodec/hevcdec: make set_side_data() accessible
> >>   avcodec/h264dec: make h264_export_frame_props() accessible
> >>   avcodec/qsvdec: Implement SEI parsing for QSV decoders
> >>
> >>  doc/APIchanges   |   4 +
> >>  libavcodec/Makefile  |   6 +-
> >>  libavcodec/h264_slice.c  |  98 ---
> >>  libavcodec/h264dec.h |   2 +
> >>  libavcodec/hevcdec.c | 117 +-
> >>  libavcodec/hevcdec.h |   9 ++
> >>  libavcodec/hevcdsp.c |   4 +
> >>  libavcodec/mpeg12.h  |  28 +
> >>  libavcodec/mpeg12dec.c   |  40 +-
> >>  libavcodec/qsvdec.c  | 234
> +++
> >>  libavfilter/qsvvpp.c |   6 +
> >>  libavfilter/vf_overlay_qsv.c |  19 ++-
> >>  libavutil/frame.c|  67 ++
> >>  libavutil/frame.h|  32 +
> >>  libavutil/version.h  |   2 +-
> >>  15 files changed, 494 insertions(+), 174 deletions(-)
> >>
> >>
> >> base-commit: 6a82412bf33108111eb3f63076fd5a51349ae114
> >> Published-As:
> >> https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-
> 31%2Fsoftworkz%2Fsubmit_qsv_sei-v5
> >> Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-
> ffstaging-
> >> 31/softworkz/submit_qsv_sei-v5
> >> Pull-Request: https://github.com/ffstaging/FFmpeg/pull/31
> >>
> >> Range-diff vs v4:
> >>
> >>  1:  7656477360 = 1:  7656477360 avutil/frame: Add
> av_frame_copy_side_data()
> >> and av_frame_remove_all_side_data()
> >>  2:  06976606c5 = 2:  06976606c5 avcodec/vpp_qsv: Copy side data
> from input to
> >> output frame
> >>  3:  320a8a535c = 3:  320a8a535c avcodec/mpeg12dec: make
> >> mpeg_decode_user_data() accessible
> >>  4:  e58ad6564f = 4:  e58ad6564f avcodec/hevcdec: make
> set_side_data()
> >> accessible
> >>  5:  a57bfaebb9 = 5:  4c0b6eb4cb avcodec/h264dec: make
> >> h264_export_frame_props() accessible
> >>  6:  3f2588563e ! 6:  19bc00be4d avcodec/qsvdec: Implement SEI
> parsing for QSV
> >> decoders
> >>  @@ Commit message
> >>
> >>   Signed-off-by: softworkz 
> >>
> >>  + ## libavcodec/Makefile ##
> >>  +@@ libavcodec/Makefile: 

Re: [FFmpeg-devel] [PATCH v3 0/4] Add derive-device function which searches for existing devices in both directions

2022-10-21 Thread Soft Works



> -Original Message-
> From: ffmpegagent 
> Sent: Friday, July 22, 2022 1:40 AM
> To: ffmpeg-devel@ffmpeg.org
> Cc: Mark Thompson ; Soft Works ;
> softworkz 
> Subject: [PATCH v3 0/4] Add derive-device function which searches for
> existing devices in both directions
> 
> This is an updated version of: [PATCH v4 1/1] avutils/hwcontext: When
> deriving a hwdevice, search for existing device in both directions
> 
> There has been an objection that the earlier patchset would change
> API
> behavior, and that this change should be limited to ffmpeg cli.
> 
> To achieve this, the API behavior is left unchanged now and a new
> function
> av_hwdevice_ctx_get_or_create_derived() is added and used by the
> hwupload
> and hwmap filters.
> 
> v2: Implemented concept for "weak references" to avoid circular
> reference
> lockup.
> 
> v3: rebased due to conflicts
> 
> softworkz (4):
>   avutil/buffer: add av_ref_from_buffer() function
>   avutils/hwcontext: add derive-device function which searches for
> existing devices in both directions
>   lavu: bump minor version and add doc/APIchanges entry for
> av_hwdevice_ctx_get_or_create_derived()
>   avfilter/hwmap,hwupload: use new
> av_hwdevice_ctx_get_or_create_derived
> method

Hi,

@Mark Thompson - would you mind to take a look at this?

You were the only one who was objecting and I had reworked 
this in the sense of our discussion (hopefully).

Thanks,
softworkz


___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] Ping on help output, logging and VAAPI overlay

2022-10-21 Thread Soft Works
This is a friendly ping on these recent submissions:


Print filter input/output formats in help output
https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=7737


Fixes and Enhancements for VAAPI Overlay
https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=7722


Add option to log timing
https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=7290

Thanks,
softworkz
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".