[FFmpeg-devel] [PATCH 10/50] avcodec/webp: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/webp.c | 24 +++-
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/libavcodec/webp.c b/libavcodec/webp.c
index 6de6a5c036..5a7aebc587 100644
--- a/libavcodec/webp.c
+++ b/libavcodec/webp.c
@@ -189,6 +189,7 @@ typedef struct WebPContext {
 VP8Context v;   /* VP8 Context used for lossy decoding 
*/
 GetBitContext gb;   /* bitstream reader for main image 
chunk */
 AVFrame *alpha_frame;   /* AVFrame for alpha data decompressed 
from VP8L */
+AVPacket *pkt;  /* AVPacket to be passed to the 
underlying VP8 decoder */
 AVCodecContext *avctx;  /* parent AVCodecContext */
 int initialized;/* set once the VP8 context is 
initialized */
 int has_alpha;  /* has a separate alpha chunk */
@@ -1290,7 +1291,6 @@ static int vp8_lossy_decode_frame(AVCodecContext *avctx, 
AVFrame *p,
   unsigned int data_size)
 {
 WebPContext *s = avctx->priv_data;
-AVPacket pkt;
 int ret;
 
 if (!s->initialized) {
@@ -1306,11 +1306,11 @@ static int vp8_lossy_decode_frame(AVCodecContext 
*avctx, AVFrame *p,
 return AVERROR_PATCHWELCOME;
 }
 
-av_init_packet(&pkt);
-pkt.data = data_start;
-pkt.size = data_size;
+av_packet_unref(s->pkt);
+s->pkt->data = data_start;
+s->pkt->size = data_size;
 
-ret = ff_vp8_decode_frame(avctx, p, got_frame, &pkt);
+ret = ff_vp8_decode_frame(avctx, p, got_frame, s->pkt);
 if (ret < 0)
 return ret;
 
@@ -1527,10 +1527,23 @@ exif_end:
 return avpkt->size;
 }
 
+static av_cold int webp_decode_init(AVCodecContext *avctx)
+{
+WebPContext *s = avctx->priv_data;
+
+s->pkt = av_packet_alloc();
+if (!s->pkt)
+return AVERROR(ENOMEM);
+
+return 0;
+}
+
 static av_cold int webp_decode_close(AVCodecContext *avctx)
 {
 WebPContext *s = avctx->priv_data;
 
+av_packet_free(&s->pkt);
+
 if (s->initialized)
 return ff_vp8_decode_free(avctx);
 
@@ -1543,6 +1556,7 @@ AVCodec ff_webp_decoder = {
 .type   = AVMEDIA_TYPE_VIDEO,
 .id = AV_CODEC_ID_WEBP,
 .priv_data_size = sizeof(WebPContext),
+.init   = webp_decode_init,
 .decode = webp_decode_frame,
 .close  = webp_decode_close,
 .capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
-- 
2.30.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".

[FFmpeg-devel] [PATCH 05/50] avcodec/libxvid: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/libxvid.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/libavcodec/libxvid.c b/libavcodec/libxvid.c
index 857077dc3b..d880558893 100644
--- a/libavcodec/libxvid.c
+++ b/libavcodec/libxvid.c
@@ -685,10 +685,12 @@ FF_ENABLE_DEPRECATION_WARNINGS
 /* Encode a dummy frame to get the extradata immediately */
 if (x->quicktime_format) {
 AVFrame *picture;
-AVPacket packet = {0};
+AVPacket *packet;
 int size, got_packet, ret;
 
-av_init_packet(&packet);
+packet = av_packet_alloc();
+if (!packet)
+return AVERROR(ENOMEM);
 
 picture = av_frame_alloc();
 if (!picture)
@@ -696,6 +698,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
 
 xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
 if( xerr ) {
+av_packet_free(&packet);
 av_frame_free(&picture);
 av_log(avctx, AV_LOG_ERROR, "Xvid: Could not create encoder 
reference\n");
 return AVERROR_EXTERNAL;
@@ -704,6 +707,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
 size = ((avctx->width + 1) & ~1) * ((avctx->height + 1) & ~1);
 picture->data[0] = av_malloc(size + size / 2);
 if (!picture->data[0]) {
+av_packet_free(&packet);
 av_frame_free(&picture);
 return AVERROR(ENOMEM);
 }
@@ -711,9 +715,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
 picture->data[2] = picture->data[1] + size / 4;
 memset(picture->data[0], 0, size);
 memset(picture->data[1], 128, size / 2);
-ret = xvid_encode_frame(avctx, &packet, picture, &got_packet);
-if (!ret && got_packet)
-av_packet_unref(&packet);
+ret = xvid_encode_frame(avctx, packet, picture, &got_packet);
+av_packet_free(&packet);
 av_free(picture->data[0]);
 av_frame_free(&picture);
 xvid_encore(x->encoder_handle, XVID_ENC_DESTROY, NULL, NULL);
-- 
2.30.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".

[FFmpeg-devel] [PATCH 08/50] avcodec/tdsc: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/tdsc.c | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/libavcodec/tdsc.c b/libavcodec/tdsc.c
index 7c888b6ec8..9e7381c2bb 100644
--- a/libavcodec/tdsc.c
+++ b/libavcodec/tdsc.c
@@ -53,6 +53,7 @@ typedef struct TDSCContext {
 GetByteContext gbc;
 
 AVFrame *refframe;  // full decoded frame (without cursor)
+AVPacket *jpkt; // encoded JPEG tile
 AVFrame *jpgframe;  // decoded JPEG tile
 uint8_t *tilebuffer;// buffer containing tile data
 
@@ -80,6 +81,7 @@ static av_cold int tdsc_close(AVCodecContext *avctx)
 
 av_frame_free(&ctx->refframe);
 av_frame_free(&ctx->jpgframe);
+av_packet_free(&ctx->jpkt);
 av_freep(&ctx->deflatebuffer);
 av_freep(&ctx->tilebuffer);
 av_freep(&ctx->cursor);
@@ -111,7 +113,8 @@ static av_cold int tdsc_init(AVCodecContext *avctx)
 /* Allocate reference and JPEG frame */
 ctx->refframe = av_frame_alloc();
 ctx->jpgframe = av_frame_alloc();
-if (!ctx->refframe || !ctx->jpgframe)
+ctx->jpkt = av_packet_alloc();
+if (!ctx->refframe || !ctx->jpgframe || !ctx->jpkt)
 return AVERROR(ENOMEM);
 
 /* Prepare everything needed for JPEG decoding */
@@ -342,15 +345,14 @@ static int tdsc_decode_jpeg_tile(AVCodecContext *avctx, 
int tile_size,
  int x, int y, int w, int h)
 {
 TDSCContext *ctx = avctx->priv_data;
-AVPacket jpkt;
 int ret;
 
 /* Prepare a packet and send to the MJPEG decoder */
-av_init_packet(&jpkt);
-jpkt.data = ctx->tilebuffer;
-jpkt.size = tile_size;
+av_packet_unref(ctx->jpkt);
+ctx->jpkt->data = ctx->tilebuffer;
+ctx->jpkt->size = tile_size;
 
-ret = avcodec_send_packet(ctx->jpeg_avctx, &jpkt);
+ret = avcodec_send_packet(ctx->jpeg_avctx, ctx->jpkt);
 if (ret < 0) {
 av_log(avctx, AV_LOG_ERROR, "Error submitting a packet for 
decoding\n");
 return ret;
-- 
2.30.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".

[FFmpeg-devel] [PATCH 01/50] avcodec/packet: deprecate av_init_packet()

2021-02-04 Thread James Almer
Once removed, sizeof(AVPacket) will stop being a part of the public ABI.

Signed-off-by: James Almer 
---
 libavcodec/avpacket.c  | 23 +++
 libavcodec/packet.h| 23 +++
 libavcodec/version.h   |  3 +++
 libavformat/avformat.h |  4 
 4 files changed, 41 insertions(+), 12 deletions(-)

diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index e4ba403cf6..ae0cbfb9f9 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -32,6 +32,7 @@
 #include "packet.h"
 #include "packet_internal.h"
 
+#if FF_API_INIT_PACKET
 void av_init_packet(AVPacket *pkt)
 {
 pkt->pts  = AV_NOPTS_VALUE;
@@ -49,6 +50,16 @@ FF_ENABLE_DEPRECATION_WARNINGS
 pkt->side_data= NULL;
 pkt->side_data_elems  = 0;
 }
+#endif
+
+static void get_packet_defaults(AVPacket *pkt)
+{
+memset(pkt, 0, sizeof(*pkt));
+
+pkt->pts = AV_NOPTS_VALUE;
+pkt->dts = AV_NOPTS_VALUE;
+pkt->pos = -1;
+}
 
 AVPacket *av_packet_alloc(void)
 {
@@ -56,7 +67,7 @@ AVPacket *av_packet_alloc(void)
 if (!pkt)
 return pkt;
 
-av_init_packet(pkt);
+get_packet_defaults(pkt);
 
 return pkt;
 }
@@ -92,7 +103,7 @@ int av_new_packet(AVPacket *pkt, int size)
 if (ret < 0)
 return ret;
 
-av_init_packet(pkt);
+get_packet_defaults(pkt);
 pkt->buf  = buf;
 pkt->data = buf->data;
 pkt->size = size;
@@ -607,9 +618,7 @@ void av_packet_unref(AVPacket *pkt)
 {
 av_packet_free_side_data(pkt);
 av_buffer_unref(&pkt->buf);
-av_init_packet(pkt);
-pkt->data = NULL;
-pkt->size = 0;
+get_packet_defaults(pkt);
 }
 
 int av_packet_ref(AVPacket *dst, const AVPacket *src)
@@ -664,9 +673,7 @@ AVPacket *av_packet_clone(const AVPacket *src)
 void av_packet_move_ref(AVPacket *dst, AVPacket *src)
 {
 *dst = *src;
-av_init_packet(src);
-src->data = NULL;
-src->size = 0;
+get_packet_defaults(src);
 }
 
 int av_packet_make_refcounted(AVPacket *pkt)
diff --git a/libavcodec/packet.h b/libavcodec/packet.h
index b9d4c9c2c8..c442b6a6eb 100644
--- a/libavcodec/packet.h
+++ b/libavcodec/packet.h
@@ -319,10 +319,6 @@ typedef struct AVPacketSideData {
  * packets, with no compressed data, containing only side data
  * (e.g. to update some stream parameters at the end of encoding).
  *
- * AVPacket is one of the few structs in FFmpeg, whose size is a part of public
- * ABI. Thus it may be allocated on stack and no new fields can be added to it
- * without libavcodec and libavformat major bump.
- *
  * The semantics of data ownership depends on the buf field.
  * If it is set, the packet data is dynamically allocated and is
  * valid indefinitely until a call to av_packet_unref() reduces the
@@ -334,6 +330,12 @@ typedef struct AVPacketSideData {
  * The side data is always allocated with av_malloc(), copied by
  * av_packet_ref() and freed by av_packet_unref().
  *
+ * sizeof(AVPacket) being a part of the public ABI is deprecated. once
+ * av_init_packet() is removed, new packets will only be able to be allocated
+ * with av_packet_alloc(), and new fields may be added to the end of the struct
+ * with a minor bump.
+ *
+ * @see av_packet_alloc
  * @see av_packet_ref
  * @see av_packet_unref
  */
@@ -394,7 +396,11 @@ typedef struct AVPacket {
 } AVPacket;
 
 typedef struct AVPacketList {
+#if FF_API_INIT_PACKET
 AVPacket pkt;
+#else
+AVPacket *pkt;
+#endif
 struct AVPacketList *next;
 } AVPacketList;
 
@@ -460,6 +466,7 @@ AVPacket *av_packet_clone(const AVPacket *src);
  */
 void av_packet_free(AVPacket **pkt);
 
+#if FF_API_INIT_PACKET
 /**
  * Initialize optional fields of a packet with default values.
  *
@@ -467,8 +474,16 @@ void av_packet_free(AVPacket **pkt);
  * initialized separately.
  *
  * @param pkt packet
+ *
+ * @see av_packet_alloc
+ * @see av_packet_unref
+ *
+ * @deprecated This function is deprecated. Once it's removed,
+   sizeof(AVPacket) will not be a part of the ABI anymore.
  */
+attribute_deprecated
 void av_init_packet(AVPacket *pkt);
+#endif
 
 /**
  * Allocate the payload of a packet and initialize its fields with
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 3cac8c5f30..247568ec7f 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -153,5 +153,8 @@
 #ifndef FF_API_DEBUG_MV
 #define FF_API_DEBUG_MV  (LIBAVCODEC_VERSION_MAJOR < 60)
 #endif
+#ifndef FF_API_INIT_PACKET
+#define FF_API_INIT_PACKET (LIBAVCODEC_VERSION_MAJOR < 60)
+#endif
 
 #endif /* AVCODEC_VERSION_H */
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 523cf34d55..d2d31e1deb 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -950,7 +950,11 @@ typedef struct AVStream {
  * decoding: set by libavformat, must not be modified by the caller.
  * encoding: unused
  */
+#if FF_API_INIT_PACKET
 AVPacket attached_pic;
+#else
+AVPacket *attached_pic;
+#en

[FFmpeg-devel] [PATCH 07/50] avcodec/pthread_frame: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/pthread_frame.c | 20 +---
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index 4429a4d59c..7bcb9a7bcc 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -81,7 +81,7 @@ typedef struct PerThreadContext {
 
 AVCodecContext *avctx;  ///< Context used to decode packets passed 
to this thread.
 
-AVPacket   avpkt;   ///< Input packet (for decoding) or output 
(for encoding).
+AVPacket   *avpkt;  ///< Input packet (for decoding) or output 
(for encoding).
 
 AVFrame *frame; ///< Output frame (for decoding) or input 
(for encoding).
 int got_frame;  ///< The output of got_picture_ptr from 
the last avcodec_decode_video() call.
@@ -208,7 +208,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
 
 av_frame_unref(p->frame);
 p->got_frame = 0;
-p->result = codec->decode(avctx, p->frame, &p->got_frame, &p->avpkt);
+p->result = codec->decode(avctx, p->frame, &p->got_frame, p->avpkt);
 
 if ((p->result < 0 || !p->got_frame) && p->frame->buf[0]) {
 if (avctx->codec->caps_internal & FF_CODEC_CAP_ALLOCATE_PROGRESS)
@@ -438,8 +438,8 @@ static int submit_packet(PerThreadContext *p, 
AVCodecContext *user_avctx,
 }
 }
 
-av_packet_unref(&p->avpkt);
-ret = av_packet_ref(&p->avpkt, avpkt);
+av_packet_unref(p->avpkt);
+ret = av_packet_ref(p->avpkt, avpkt);
 if (ret < 0) {
 pthread_mutex_unlock(&p->mutex);
 av_log(p->avctx, AV_LOG_ERROR, "av_packet_ref() failed in 
submit_packet()\n");
@@ -550,7 +550,7 @@ int ff_thread_decode_frame(AVCodecContext *avctx,
 
 av_frame_move_ref(picture, p->frame);
 *got_picture_ptr = p->got_frame;
-picture->pkt_dts = p->avpkt.dts;
+picture->pkt_dts = p->avpkt->dts;
 err = p->result;
 
 /*
@@ -725,7 +725,7 @@ void ff_frame_thread_free(AVCodecContext *avctx, int 
thread_count)
 pthread_cond_destroy(&p->input_cond);
 pthread_cond_destroy(&p->progress_cond);
 pthread_cond_destroy(&p->output_cond);
-av_packet_unref(&p->avpkt);
+av_packet_free(&p->avpkt);
 
 #if FF_API_THREAD_SAFE_CALLBACKS
 for (int j = 0; j < p->released_buffers_allocated; j++)
@@ -822,6 +822,12 @@ int ff_frame_thread_init(AVCodecContext *avctx)
 err = AVERROR(ENOMEM);
 goto error;
 }
+p->avpkt = av_packet_alloc();
+if (!p->avpkt) {
+av_freep(©);
+err = AVERROR(ENOMEM);
+goto error;
+}
 
 p->parent = fctx;
 p->avctx  = copy;
@@ -841,7 +847,7 @@ int ff_frame_thread_init(AVCodecContext *avctx)
 }
 *copy->internal = *src->internal;
 copy->internal->thread_ctx = p;
-copy->internal->last_pkt_props = &p->avpkt;
+copy->internal->last_pkt_props = p->avpkt;
 
 copy->delay = avctx->delay;
 
-- 
2.30.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".

[FFmpeg-devel] [PATCH 06/50] avcodec/mpegvideo_enc: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/mpegvideo_enc.c | 23 +--
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 34dcf8c313..411cadeae7 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1366,23 +1366,20 @@ static int skip_check(MpegEncContext *s, Picture *p, 
Picture *ref)
 return 0;
 }
 
-static int encode_frame(AVCodecContext *c, AVFrame *frame)
+static int encode_frame(AVCodecContext *c, AVFrame *frame, AVPacket *pkt)
 {
-AVPacket pkt = { 0 };
 int ret;
 int size = 0;
 
-av_init_packet(&pkt);
-
 ret = avcodec_send_frame(c, frame);
 if (ret < 0)
 return ret;
 
 do {
-ret = avcodec_receive_packet(c, &pkt);
+ret = avcodec_receive_packet(c, pkt);
 if (ret >= 0) {
-size += pkt.size;
-av_packet_unref(&pkt);
+size += pkt->size;
+av_packet_unref(pkt);
 } else if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
 return ret;
 } while (ret >= 0);
@@ -1448,6 +1445,7 @@ static int estimate_best_b_count(MpegEncContext *s)
 
 for (j = 0; j < s->max_b_frames + 1; j++) {
 AVCodecContext *c;
+AVPacket *pkt;
 int64_t rd = 0;
 
 if (!s->input_picture[j])
@@ -1473,10 +1471,14 @@ static int estimate_best_b_count(MpegEncContext *s)
 if (ret < 0)
 goto fail;
 
+pkt = av_packet_alloc();
+if (!pkt)
+goto fail;
+
 s->tmp_frames[0]->pict_type = AV_PICTURE_TYPE_I;
 s->tmp_frames[0]->quality   = 1 * FF_QP2LAMBDA;
 
-out_size = encode_frame(c, s->tmp_frames[0]);
+out_size = encode_frame(c, s->tmp_frames[0], pkt);
 if (out_size < 0) {
 ret = out_size;
 goto fail;
@@ -1491,7 +1493,7 @@ static int estimate_best_b_count(MpegEncContext *s)
  AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_B;
 s->tmp_frames[i + 1]->quality   = is_p ? p_lambda : b_lambda;
 
-out_size = encode_frame(c, s->tmp_frames[i + 1]);
+out_size = encode_frame(c, s->tmp_frames[i + 1], pkt);
 if (out_size < 0) {
 ret = out_size;
 goto fail;
@@ -1501,7 +1503,7 @@ static int estimate_best_b_count(MpegEncContext *s)
 }
 
 /* get the delayed frames */
-out_size = encode_frame(c, NULL);
+out_size = encode_frame(c, NULL, pkt);
 if (out_size < 0) {
 ret = out_size;
 goto fail;
@@ -1517,6 +1519,7 @@ static int estimate_best_b_count(MpegEncContext *s)
 
 fail:
 avcodec_free_context(&c);
+av_packet_free(&pkt);
 if (ret < 0)
 return ret;
 }
-- 
2.30.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 4/8] avformat/mxfdec: Fix file position addition

2021-02-04 Thread James Almer

On 2/4/2021 3:43 PM, Tomas Härdin wrote:

mån 2021-02-01 klockan 23:31 +0100 skrev Michael Niedermayer:

Not sure this is the best solution, maybe a more general solution
limiting the avio_tell() output to less than 63bit would be a better
option


Probably, since this is likely to happen in more places


Fixes: signed integer overflow: 9223372036854775805 + 4 cannot be represented 
in type 'long'
Fixes: 
29927/clusterfuzz-testcase-minimized-ffmpeg_dem_MXF_fuzzer-5579985228267520

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
  libavformat/mxfdec.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index afff20402d..97a1b749fe 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -2861,7 +2861,7 @@ static int mxf_read_local_tags(MXFContext *mxf, KLVPacket 
*klv, MXFMetadataReadF
  return AVERROR(ENOMEM);
  if (ctx_size)
  mxf_metadataset_init(ctx, type);
-while (avio_tell(pb) + 4 < klv_end && !avio_feof(pb)) {
+while (avio_tell(pb) + (uint64_t)4 < klv_end && !avio_feof(pb)) {


Why not cast avio_tell() instead?


Or use 4ULL



/Tomas

___
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".

[FFmpeg-devel] [PATCH] Add support for the new key & value API in libaom.

2021-02-04 Thread Bohan Li
This key & value API can greatly help with users who wants to try
libaom-av1 specific options that are not supported by ffmpeg options.

As was previously discussed in this thread:
https://lists.ffmpeg.org/pipermail/ffmpeg-devel/2020-October/271658.

The commit that added the API to libaom:
https://aomedia.googlesource.com/aom/+/c1d42fe6615c96fc929257

The libaom issue tracker:
https://bugs.chromium.org/p/aomedia/issues/detail?id=2875

Signed-off-by: Bohan Li 
---
 doc/encoders.texi  | 11 +++
 libavcodec/libaomenc.c | 30 ++
 2 files changed, 41 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index c2ba7d3e6f..9fab512892 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1684,6 +1684,17 @@ Enable interintra compound. Default is true.
 @item enable-smooth-interintra (@emph{boolean}) (Requires libaom >= v2.0.0)
 Enable smooth interintra mode. Default is true.
 
+@item libaom-params
+Set libaom options using a list of @var{key}=@var{value} pairs separated
+by ":". For a list of supported options, see @command{aomenc --help} under the
+section "AV1 Specific Options".
+
+For example to specify libaom encoding options with @option{-libaom-params}:
+
+@example
+ffmpeg -i input -c:v libaom-av1 -b:v 500K -libaom-params 
tune=psnr:enable-tpl-model=1 output.mp4
+@end example
+
 @end table
 
 @section libsvtav1
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 342d0883e4..c7a87e01cd 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -124,6 +124,7 @@ typedef struct AOMEncoderContext {
 int enable_diff_wtd_comp;
 int enable_dist_wtd_comp;
 int enable_dual_filter;
+AVDictionary *extra_params;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -318,6 +319,25 @@ static av_cold int codecctl_int(AVCodecContext *avctx,
 return 0;
 }
 
+static av_cold int codec_set_option(AVCodecContext *avctx,
+const char* key,
+const char* value)
+{
+AOMContext *ctx = avctx->priv_data;
+int width = -30;
+int res;
+
+av_log(avctx, AV_LOG_DEBUG, "  %*s: %s\n", width, key, value);
+
+res = aom_codec_set_option(&ctx->encoder, key, value);
+if (res != AOM_CODEC_OK) {
+log_encoder_error(avctx, key);
+return AVERROR(EINVAL);
+}
+
+return 0;
+}
+
 static av_cold int aom_free(AVCodecContext *avctx)
 {
 AOMContext *ctx = avctx->priv_data;
@@ -874,6 +894,15 @@ static av_cold int aom_init(AVCodecContext *avctx,
 codecctl_int(avctx, AV1E_SET_ENABLE_INTRABC, ctx->enable_intrabc);
 #endif
 
+#if AOM_ENCODER_ABI_VERSION >= 23
+{
+  AVDictionaryEntry *en = NULL;
+  while ((en = av_dict_get(ctx->extra_params, "", en, 
AV_DICT_IGNORE_SUFFIX))) {
+codec_set_option(avctx, en->key, en->value);
+  }
+}
+#endif
+
 // provide dummy value to initialize wrapper, values will be updated each 
_encode()
 aom_img_wrap(&ctx->rawimg, img_fmt, avctx->width, avctx->height, 1,
  (unsigned char*)1);
@@ -1299,6 +1328,7 @@ static const AVOption options[] = {
 { "enable-masked-comp",   "Enable masked compound",
OFFSET(enable_masked_comp),   AV_OPT_TYPE_BOOL, {.i64 = 
-1}, -1, 1, VE},
 { "enable-interintra-comp",   "Enable interintra compound",
OFFSET(enable_interintra_comp),   AV_OPT_TYPE_BOOL, {.i64 = 
-1}, -1, 1, VE},
 { "enable-smooth-interintra", "Enable smooth interintra mode", 
OFFSET(enable_smooth_interintra), AV_OPT_TYPE_BOOL, {.i64 = 
-1}, -1, 1, VE},
+{ "libaom-params","Extra parameters for libaom",   
OFFSET(extra_params), AV_OPT_TYPE_DICT, { 0 },  
  0, 0, VE },
 { NULL },
 };
 
-- 
2.30.0.365.g02bc693789-goog

___
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/6] avcodec/vp9dsp_template: Fix integer overflows in itxfm_wrapper

2021-02-04 Thread Michael Niedermayer
On Mon, Nov 23, 2020 at 01:42:59AM +0100, Michael Niedermayer wrote:
> Fixes: signed integer overflow: 2147483641 + 32 cannot be represented in type 
> 'int'
> Fixes: 
> 27452/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VP9_fuzzer-5078752576667648
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/vp9dsp_template.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

will apply remaining patches of this set

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

Its not that you shouldnt use gotos but rather that you should write
readable code and code with gotos often but not always is less readable


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] [FFmpeg-cvslog] avformat/cdxl: rework probe and fix sample rate and frame rate

2021-02-04 Thread Michael Niedermayer
On Wed, Feb 03, 2021 at 11:58:25PM +, Paul B Mahol wrote:
> ffmpeg | branch: master | Paul B Mahol  | Wed Feb  3 
> 23:06:51 2021 +0100| [a8b3a51790bf5bcc498844e1cd6f0097ecb455c1] | committer: 
> Paul B Mahol
> 
> avformat/cdxl: rework probe and fix sample rate and frame rate
> 
> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a8b3a51790bf5bcc498844e1cd6f0097ecb455c1
> ---
> 
>  libavformat/cdxl.c   | 78 
> +++-
>  tests/ref/fate/cdxl-bitline-ham6 |  2 +-
>  tests/ref/fate/cdxl-demux| 22 ++--
>  tests/ref/fate/cdxl-ham6 |  2 +-
>  tests/ref/fate/cdxl-ham8 |  2 +-
>  tests/ref/fate/cdxl-pal8 |  2 +-
>  tests/ref/fate/cdxl-pal8-small   |  2 +-
>  7 files changed, 53 insertions(+), 57 deletions(-)


tickets/1937/Fruit.CDXL  was 29.97 fps and 5sec duration before and 
is 25fps and 6sec duration now

Audio is 5sec either way so the 6sec video duration feels wrong

also detection only works with a score of 1 that is likely not reliable

https://trac.ffmpeg.org/attachment/ticket/1937/Fruit.CDXL

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

Complexity theory is the science of finding the exact solution to an
approximation. Benchmarking OTOH is finding an approximation of the exact


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] [FFmpeg-cvslog] avformat/cdxl: rework probe and fix sample rate and frame rate

2021-02-04 Thread Paul B Mahol
That file is simply broken.

On Thu, Feb 4, 2021 at 10:38 PM Michael Niedermayer 
wrote:

> On Wed, Feb 03, 2021 at 11:58:25PM +, Paul B Mahol wrote:
> > ffmpeg | branch: master | Paul B Mahol  | Wed Feb  3
> 23:06:51 2021 +0100| [a8b3a51790bf5bcc498844e1cd6f0097ecb455c1] |
> committer: Paul B Mahol
> >
> > avformat/cdxl: rework probe and fix sample rate and frame rate
> >
> > >
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a8b3a51790bf5bcc498844e1cd6f0097ecb455c1
> > ---
> >
> >  libavformat/cdxl.c   | 78
> +++-
> >  tests/ref/fate/cdxl-bitline-ham6 |  2 +-
> >  tests/ref/fate/cdxl-demux| 22 ++--
> >  tests/ref/fate/cdxl-ham6 |  2 +-
> >  tests/ref/fate/cdxl-ham8 |  2 +-
> >  tests/ref/fate/cdxl-pal8 |  2 +-
> >  tests/ref/fate/cdxl-pal8-small   |  2 +-
> >  7 files changed, 53 insertions(+), 57 deletions(-)
>
>
> tickets/1937/Fruit.CDXL  was 29.97 fps and 5sec duration before and
> is 25fps and 6sec duration now
>
> Audio is 5sec either way so the 6sec video duration feels wrong
>
> also detection only works with a score of 1 that is likely not reliable
>
> https://trac.ffmpeg.org/attachment/ticket/1937/Fruit.CDXL
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Complexity theory is the science of finding the exact solution to an
> approximation. Benchmarking OTOH is finding an approximation of the exact
> ___
> 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 8/8] avformat/nutdec: Check timebase count against main header length

2021-02-04 Thread Michael Niedermayer
On Sat, Dec 19, 2020 at 12:22:08AM +0100, Michael Niedermayer wrote:
> Fixes: Timeout (long -> 3ms)
> Fixes: 
> 28514/clusterfuzz-testcase-minimized-ffmpeg_dem_NUT_fuzzer-6078669009321984
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/nutdec.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)

will apply

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

In a rich man's house there is no place to spit but his face.
-- Diogenes of Sinope


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] Add support for the new key & value API in libaom.

2021-02-04 Thread Bohan Li
Thanks for the review! Indeed the buf string does not play any role here. I
have removed it in the new patch.

Bohan

On Thu, Feb 4, 2021 at 1:02 PM Bohan Li  wrote:

> This key & value API can greatly help with users who wants to try
> libaom-av1 specific options that are not supported by ffmpeg options.
>
> As was previously discussed in this thread:
> https://lists.ffmpeg.org/pipermail/ffmpeg-devel/2020-October/271658.
>
> The commit that added the API to libaom:
> https://aomedia.googlesource.com/aom/+/c1d42fe6615c96fc929257
>
> The libaom issue tracker:
> https://bugs.chromium.org/p/aomedia/issues/detail?id=2875
>
> Signed-off-by: Bohan Li 
> ---
>  doc/encoders.texi  | 11 +++
>  libavcodec/libaomenc.c | 30 ++
>  2 files changed, 41 insertions(+)
>
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index c2ba7d3e6f..9fab512892 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -1684,6 +1684,17 @@ Enable interintra compound. Default is true.
>  @item enable-smooth-interintra (@emph{boolean}) (Requires libaom >=
> v2.0.0)
>  Enable smooth interintra mode. Default is true.
>
> +@item libaom-params
> +Set libaom options using a list of @var{key}=@var{value} pairs separated
> +by ":". For a list of supported options, see @command{aomenc --help}
> under the
> +section "AV1 Specific Options".
> +
> +For example to specify libaom encoding options with
> @option{-libaom-params}:
> +
> +@example
> +ffmpeg -i input -c:v libaom-av1 -b:v 500K -libaom-params
> tune=psnr:enable-tpl-model=1 output.mp4
> +@end example
> +
>  @end table
>
>  @section libsvtav1
> diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
> index 342d0883e4..c7a87e01cd 100644
> --- a/libavcodec/libaomenc.c
> +++ b/libavcodec/libaomenc.c
> @@ -124,6 +124,7 @@ typedef struct AOMEncoderContext {
>  int enable_diff_wtd_comp;
>  int enable_dist_wtd_comp;
>  int enable_dual_filter;
> +AVDictionary *extra_params;
>  } AOMContext;
>
>  static const char *const ctlidstr[] = {
> @@ -318,6 +319,25 @@ static av_cold int codecctl_int(AVCodecContext *avctx,
>  return 0;
>  }
>
> +static av_cold int codec_set_option(AVCodecContext *avctx,
> +const char* key,
> +const char* value)
> +{
> +AOMContext *ctx = avctx->priv_data;
> +int width = -30;
> +int res;
> +
> +av_log(avctx, AV_LOG_DEBUG, "  %*s: %s\n", width, key, value);
> +
> +res = aom_codec_set_option(&ctx->encoder, key, value);
> +if (res != AOM_CODEC_OK) {
> +log_encoder_error(avctx, key);
> +return AVERROR(EINVAL);
> +}
> +
> +return 0;
> +}
> +
>  static av_cold int aom_free(AVCodecContext *avctx)
>  {
>  AOMContext *ctx = avctx->priv_data;
> @@ -874,6 +894,15 @@ static av_cold int aom_init(AVCodecContext *avctx,
>  codecctl_int(avctx, AV1E_SET_ENABLE_INTRABC, ctx->enable_intrabc);
>  #endif
>
> +#if AOM_ENCODER_ABI_VERSION >= 23
> +{
> +  AVDictionaryEntry *en = NULL;
> +  while ((en = av_dict_get(ctx->extra_params, "", en,
> AV_DICT_IGNORE_SUFFIX))) {
> +codec_set_option(avctx, en->key, en->value);
> +  }
> +}
> +#endif
> +
>  // provide dummy value to initialize wrapper, values will be updated
> each _encode()
>  aom_img_wrap(&ctx->rawimg, img_fmt, avctx->width, avctx->height, 1,
>   (unsigned char*)1);
> @@ -1299,6 +1328,7 @@ static const AVOption options[] = {
>  { "enable-masked-comp",   "Enable masked compound",
>   OFFSET(enable_masked_comp),   AV_OPT_TYPE_BOOL,
> {.i64 = -1}, -1, 1, VE},
>  { "enable-interintra-comp",   "Enable interintra compound",
>   OFFSET(enable_interintra_comp),   AV_OPT_TYPE_BOOL,
> {.i64 = -1}, -1, 1, VE},
>  { "enable-smooth-interintra", "Enable smooth interintra mode",
>  OFFSET(enable_smooth_interintra), AV_OPT_TYPE_BOOL,
> {.i64 = -1}, -1, 1, VE},
> +{ "libaom-params","Extra parameters for libaom",
>  OFFSET(extra_params), AV_OPT_TYPE_DICT, {
> 0 },0, 0, VE },
>  { NULL },
>  };
>
> --
> 2.30.0.365.g02bc693789-goog
>
>
___
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] libavcodec/gifenc: Only write palette entries that actually used

2021-02-04 Thread Andreas Rheinhardt
Derek Buitenhuis:
> On 04/02/2021 17:26, Paul B Mahol wrote:
>> How would that work?
>> I'm not against if that does not break existing usage.
> 
> Somethng like '-no_global_paltte 1' to not use a global
> palette, and write a palette each frame. Default would be
> off, so curent behavior is maintained.
> 
> - Derek

Could AV_CODEC_FLAG_GLOBAL_HEADER be used for this?

- 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".

Re: [FFmpeg-devel] [PATCH v3] ffmpeg: add -fpsmax to clamp output framerate

2021-02-04 Thread Gyan Doshi

Will push in 12h if no further changes.

On 03-02-2021 07:42 pm, Gyan Doshi wrote:

Useful when encoding in batch or with aberrant inputs.
---
  doc/ffmpeg.texi  |  7 +++
  fftools/ffmpeg.c |  7 ++-
  fftools/ffmpeg.h |  3 +++
  fftools/ffmpeg_opt.c | 23 ---
  4 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 8eb012b7c0..b0d1cf0710 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -759,6 +759,13 @@ If in doubt use @option{-framerate} instead of the input 
option @option{-r}.
  As an output option, duplicate or drop input frames to achieve constant output
  frame rate @var{fps}.
  
+@item -fpsmax[:@var{stream_specifier}] @var{fps} (@emph{output,per-stream})

+Set maximum frame rate (Hz value, fraction or abbreviation).
+
+Clamps output frame rate when output framerate is auto-set and is higher than 
this value.
+Useful in batch processing or when input framerate is wrongly detected as very 
high.
+It cannot be set together with @code{-r}. It is ignored during streamcopy.
+
  @item -s[:@var{stream_specifier}] @var{size} (@emph{input/output,per-stream})
  Set frame size.
  
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c

index d7c833be63..add5a3e505 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3376,7 +3376,7 @@ static int init_output_stream_encode(OutputStream *ost, 
AVFrame *frame)
  ost->frame_rate = ist->framerate;
  if (ist && !ost->frame_rate.num)
  ost->frame_rate = ist->st->r_frame_rate;
-if (ist && !ost->frame_rate.num) {
+if (ist && !ost->frame_rate.num && !ost->max_frame_rate.num) {
  ost->frame_rate = (AVRational){25, 1};
  av_log(NULL, AV_LOG_WARNING,
 "No information "
@@ -3386,6 +3386,11 @@ static int init_output_stream_encode(OutputStream *ost, 
AVFrame *frame)
 ost->file_index, ost->index);
  }
  
+if (ost->max_frame_rate.num &&

+(av_q2d(ost->frame_rate) > av_q2d(ost->max_frame_rate) ||
+!ost->frame_rate.den))
+ost->frame_rate = ost->max_frame_rate;
+
  if (ost->enc->supported_framerates && !ost->force_fps) {
  int idx = av_find_nearest_q_idx(ost->frame_rate, 
ost->enc->supported_framerates);
  ost->frame_rate = ost->enc->supported_framerates[idx];
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 5aeceae6b7..423da071dc 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -108,6 +108,8 @@ typedef struct OptionsContext {
  intnb_audio_sample_rate;
  SpecifierOpt *frame_rates;
  intnb_frame_rates;
+SpecifierOpt *max_frame_rates;
+intnb_max_frame_rates;
  SpecifierOpt *frame_sizes;
  intnb_frame_sizes;
  SpecifierOpt *frame_pix_fmts;
@@ -479,6 +481,7 @@ typedef struct OutputStream {
  
  /* video only */

  AVRational frame_rate;
+AVRational max_frame_rate;
  int is_cfr;
  int force_fps;
  int top_field_first;
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index bf2eb26246..805754953e 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -55,6 +55,7 @@ static const char *const opt_name_codec_names[]   = {"c", 
"codec", "
  static const char *const opt_name_audio_channels[]= {"ac", NULL};
  static const char *const opt_name_audio_sample_rate[] = {"ar", NULL};
  static const char *const opt_name_frame_rates[]   = {"r", NULL};
+static const char *const opt_name_max_frame_rates[]   = {"fpsmax", 
NULL};
  static const char *const opt_name_frame_sizes[]   = {"s", NULL};
  static const char *const opt_name_frame_pix_fmts[]= {"pix_fmt", 
NULL};
  static const char *const opt_name_ts_scale[]  = {"itsscale", 
NULL};
@@ -1688,7 +1689,7 @@ static OutputStream *new_video_stream(OptionsContext *o, 
AVFormatContext *oc, in
  AVStream *st;
  OutputStream *ost;
  AVCodecContext *video_enc;
-char *frame_rate = NULL, *frame_aspect_ratio = NULL;
+char *frame_rate = NULL, *max_frame_rate = NULL, *frame_aspect_ratio = 
NULL;
  
  ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO, source_index);

  st  = ost->st;
@@ -1699,8 +1700,21 @@ static OutputStream *new_video_stream(OptionsContext *o, 
AVFormatContext *oc, in
  av_log(NULL, AV_LOG_FATAL, "Invalid framerate value: %s\n", 
frame_rate);
  exit_program(1);
  }
-if (frame_rate && video_sync_method == VSYNC_PASSTHROUGH)
-av_log(NULL, AV_LOG_ERROR, "Using -vsync 0 and -r can produce invalid 
output files\n");
+
+MATCH_PER_STREAM_OPT(max_frame_rates, str, max_frame_rate, oc, st);
+if (max_frame_rate && av_parse_video_rate(&ost->max_frame_rate, 
max_frame_rate) < 0) {
+av_log(NULL, AV_LOG_FATAL, "Invalid maximum framerate value: %s\n", 
max_frame_rate);
+exit_program(1);
+}
+

Re: [FFmpeg-devel] [PATCH 2/6] ffbuild/common: Make deletion of templates possible

2021-02-04 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> If a target to be built includes a template file, the target's .d file
> includes the template file as a prerequisite; if the code were changed so
> that the template file no longer exists, one would get an error from
> make that it has no rule for the template file target. Therefore add a
> dummy rule for template files to make deleting them possible.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  ffbuild/common.mak | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/ffbuild/common.mak b/ffbuild/common.mak
> index 13e13553b8..e070b6b5e2 100644
> --- a/ffbuild/common.mak
> +++ b/ffbuild/common.mak
> @@ -107,7 +107,7 @@ COMPILE_MSA = $(call COMPILE,CC,MSAFLAGS)
>  %.c %.h %.pc %.ver %.version: TAG = GEN
>  
>  # Dummy rule to stop make trying to rebuild removed or renamed headers
> -%.h:
> +%.h %_template.c:
>   @:
>  
>  # Disable suffix rules.  Most of the builtin rules are suffix rules,
> 

Will apply this patchset tomorrow unless there are objections. Patch one
and three will be merged as Lynne suggested.

- 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] avcodec/mpegvideo_motion: Improve check to remove dead code

2021-02-04 Thread Andreas Rheinhardt
Several compile-time checks can be improved because mcsel is not used
for MPEG-1/2 (it is only used for MPEG-4) and because MPEG-1/2 is the
only user of ff_mpv_motion that uses MV_TYPE_16X8 and MV_TYPE_DMV.

Signed-off-by: Andreas Rheinhardt 
---
Fixed a precedence issue in the first hunk below.

 libavcodec/mpegvideo_motion.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/libavcodec/mpegvideo_motion.c b/libavcodec/mpegvideo_motion.c
index 58cdecf83b..79785df8f8 100644
--- a/libavcodec/mpegvideo_motion.c
+++ b/libavcodec/mpegvideo_motion.c
@@ -306,9 +306,9 @@ void mpeg_motion_internal(MpegEncContext *s,
 
 if ((unsigned)src_x >= FFMAX(s->h_edge_pos - (motion_x & 1) - 15   , 0) ||
 (unsigned)src_y >= FFMAX(   v_edge_pos - (motion_y & 1) - h + 1, 0)) {
-if (is_mpeg12 ||
-s->codec_id == AV_CODEC_ID_MPEG2VIDEO ||
-s->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
+if (is_mpeg12 || (CONFIG_SMALL &&
+  (s->codec_id == AV_CODEC_ID_MPEG2VIDEO ||
+   s->codec_id == AV_CODEC_ID_MPEG1VIDEO))) {
 av_log(s->avctx, AV_LOG_DEBUG,
"MPEG motion vector out of boundary (%d %d)\n", src_x,
src_y);
@@ -853,7 +853,7 @@ static av_always_inline void 
mpv_motion_internal(MpegEncContext *s,
 
 switch (s->mv_type) {
 case MV_TYPE_16X16:
-if (s->mcsel) {
+if (!is_mpeg12 && s->mcsel) {
 if (s->real_sprite_warping_points == 1) {
 gmc1_motion(s, dest_y, dest_cb, dest_cr,
 ref_picture);
@@ -915,6 +915,7 @@ static av_always_inline void 
mpv_motion_internal(MpegEncContext *s,
 }
 break;
 case MV_TYPE_16X8:
+if (CONFIG_SMALL || is_mpeg12) {
 for (i = 0; i < 2; i++) {
 uint8_t **ref2picture;
 
@@ -936,7 +937,9 @@ static av_always_inline void 
mpv_motion_internal(MpegEncContext *s,
 dest_cr += (16 >> s->chroma_y_shift) * s->uvlinesize;
 }
 break;
+}
 case MV_TYPE_DMV:
+if (CONFIG_SMALL || is_mpeg12) {
 if (s->picture_structure == PICT_FRAME) {
 for (i = 0; i < 2; i++) {
 int j;
@@ -969,6 +972,7 @@ static av_always_inline void 
mpv_motion_internal(MpegEncContext *s,
 }
 }
 break;
+}
 default: av_assert2(0);
 }
 }
-- 
2.27.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 1/4] Remove unnecessary mem.h inclusions

2021-02-04 Thread Anton Khirnov
Quoting Andreas Rheinhardt (2021-02-04 01:05:05)
> Thanks for the report. I have only checked for whether the relevant
> translation unit uses any of the alloc/free functions (because
> DECLARE_ALIGNED is already provided by mem_internal.h), but I have not
> taken into account stuff that is included by the headers included by
> mem.h. In this case, one needs string.h (which is included in
> libavutil/common.h which in turn is included in avutil.h which is
> included in mem.h). Will look over everything again.
> 
> - Andreas
> 
> PS: It actually seems that the only thing provided by avutil.h that
> mem.h uses is size_t. Do we allow to remove included headers from
> installed headers at major version bumps?

I would say yes, IIRC it has happened before.
Certainly nobody should depend on our headers to provide any random
system headers.

-- 
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".

[FFmpeg-devel] Re: [PATCH] fix for https://trac.ffmpeg.org/ticket/9057

2021-02-04 Thread Anton Khirnov
Quoting Carl Eugen Hoyos (2021-02-03 23:05:08)
> Am Do., 21. Jan. 2021 um 17:59 Uhr schrieb :
> >
> > From: KM 
> >
> > ---
> >  libavcodec/aacdec_template.c | 11 +++
> >  1 file changed, 7 insertions(+), 4 deletions(-)
> >
> > diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
> > index fbe3074..3c2dbe3 100644
> > --- a/libavcodec/aacdec_template.c
> > +++ b/libavcodec/aacdec_template.c
> > @@ -639,11 +639,14 @@ static int set_default_channel_config(AACContext *ac, 
> > AVCodecContext *avctx,
> >   * As actual intended 7.1(wide) streams are very rare, default to 
> > assuming a
> >   * 7.1 layout was intended.
> >   */
> > -if (channel_config == 7 && avctx->strict_std_compliance < 
> > FF_COMPLIANCE_STRICT && (!ac || !ac->warned_71_wide++)) {
> > -av_log(avctx, AV_LOG_INFO, "Assuming an incorrectly encoded 7.1 
> > channel layout"
> > -   " instead of a spec-compliant 7.1(wide) layout, use -strict 
> > %d to decode"
> > -   " according to the specification instead.\n", 
> > FF_COMPLIANCE_STRICT);
> > +if (channel_config == 7 && avctx->strict_std_compliance < 
> > FF_COMPLIANCE_STRICT) {
> >  layout_map[2][2] = AAC_CHANNEL_SIDE;
> > +
> > +if (!ac || !ac->warned_71_wide++) {
> > +av_log(avctx, AV_LOG_INFO, "Assuming an incorrectly encoded 
> > 7.1 channel layout"
> > +   " instead of a spec-compliant 7.1(wide) layout, use 
> > -strict %d to decode"
> > +   " according to the specification instead.\n", 
> > FF_COMPLIANCE_STRICT);
> 
> I will push this if there are no objections.

At the very least it needs a better commit message that explains what is
done rather than "fix bug"

-- 
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 3/3] avcodec/hapdec: Check that compressed_offset is non negative

2021-02-04 Thread Anton Khirnov
Quoting Michael Niedermayer (2021-01-30 20:28:26)
> Fixes: out of array access
> Fixes: 
> 29345/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HAP_fuzzer-5401813482340352
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/hapdec.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/libavcodec/hapdec.c b/libavcodec/hapdec.c
> index ab364aa790..260fda2968 100644
> --- a/libavcodec/hapdec.c
> +++ b/libavcodec/hapdec.c
> @@ -86,6 +86,8 @@ static int hap_parse_decode_instructions(HapContext *ctx, 
> int size)
>  return ret;
>  for (i = 0; i < section_size / 4; i++) {
>  ctx->chunks[i].compressed_offset = 
> bytestream2_get_le32(gbc);
> +if (ctx->chunks[i].compressed_offset < 0)

Would it not be better to change compressed_offset to uint32 or size_t?

-- 
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".

[FFmpeg-devel] Re: [PATCH 1/3] avcodec/mjpegdec: Cleanup ff_smvjpeg_decoder()

2021-02-04 Thread Anton Khirnov
Quoting Michael Niedermayer (2020-12-20 22:15:22)
> Fixes: memleaks
> Fixes: 
> 28533/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SMVJPEG_fuzzer-6242529653686272
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/mjpegdec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
> index 11fb809c10..901ee228ab 100644
> --- a/libavcodec/mjpegdec.c
> +++ b/libavcodec/mjpegdec.c
> @@ -3031,7 +3031,7 @@ AVCodec ff_smvjpeg_decoder = {
>  .receive_frame  = ff_mjpeg_receive_frame,
>  .flush  = decode_flush,
>  .capabilities   = AV_CODEC_CAP_DR1,
> -.caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | 
> FF_CODEC_CAP_EXPORTS_CROPPING |
> +.caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | 
> FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_EXPORTS_CROPPING |

Please put it on the second line.

Looks good otherwise.

-- 
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".

[FFmpeg-devel] [PATCH v2 0/4] avcodec/aarch64/hevcdsp

2021-02-04 Thread Josh Dekker
Hi,

Rebases the unpushed part of my patches on top of Reimar's set.  Also
implements Martin's suggestions except 'unrolling the loop' for SAO band
function, will update the band function when I fix non 8x8 cases.

-- 
Josh


___
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 3/4] avcodec/aarch64/hevcdsp: add idct_dc NEON

2021-02-04 Thread Josh Dekker
Signed-off-by: Josh Dekker 
---
 libavcodec/aarch64/hevcdsp_idct_neon.S| 54 +++
 libavcodec/aarch64/hevcdsp_init_aarch64.c | 16 +++
 2 files changed, 70 insertions(+)

diff --git a/libavcodec/aarch64/hevcdsp_idct_neon.S 
b/libavcodec/aarch64/hevcdsp_idct_neon.S
index 329038a958..d3902a9e0f 100644
--- a/libavcodec/aarch64/hevcdsp_idct_neon.S
+++ b/libavcodec/aarch64/hevcdsp_idct_neon.S
@@ -5,6 +5,7 @@
  *
  * Ported from arm/hevcdsp_idct_neon.S by
  * Copyright (c) 2020 Reimar Döffinger
+ * Copyright (c) 2020 Josh Dekker
  *
  * This file is part of FFmpeg.
  *
@@ -568,3 +569,56 @@ tr_16x4 secondpass_10, 20 - 10, 512, 1
 
 idct_16x16 8
 idct_16x16 10
+
+// void ff_hevc_idct_NxN_dc_DEPTH_neon(int16_t *coeffs)
+.macro idct_dc size bitdepth
+function ff_hevc_idct_\size\()x\size\()_dc_\bitdepth\()_neon, export=1
+ldrsh   w1, [x0]
+mov w2,  #(1 << (13 - \bitdepth))
+add w1,  w1, #1
+asr w1,  w1, #1
+add w1,  w1, w2
+asr w1,  w1, #(14 - \bitdepth)
+dup  v0.8h,  w1
+dup  v1.8h,  w1
+.if \size > 4
+dup  v2.8h,  w1
+dup  v3.8h,  w1
+.if \size > 16 /* dc 32x32 */
+mov x2,  #4
+1:
+subsx2,  x2, #1
+.endif
+addx12,  x0,  #64
+movx13,  #128
+.if \size > 8 /* dc 16x16 */
+st1   {v0.8h-v3.8h}, [ x0], x13
+st1   {v0.8h-v3.8h}, [x12], x13
+st1   {v0.8h-v3.8h}, [ x0], x13
+st1   {v0.8h-v3.8h}, [x12], x13
+st1   {v0.8h-v3.8h}, [ x0], x13
+st1   {v0.8h-v3.8h}, [x12], x13
+.endif /* dc 8x8 */
+st1   {v0.8h-v3.8h}, [ x0], x13
+st1   {v0.8h-v3.8h}, [x12], x13
+.if \size > 16 /* dc 32x32 */
+bne 1b
+.endif
+.else /* dc 4x4 */
+st1   {v0.8h-v1.8h}, [x0]
+.endif
+ret
+endfunc
+.endm
+
+idct_dc 4 8
+idct_dc 4 10
+
+idct_dc 8 8
+idct_dc 8 10
+
+idct_dc 16 8
+idct_dc 16 10
+
+idct_dc 32 8
+idct_dc 32 10
diff --git a/libavcodec/aarch64/hevcdsp_init_aarch64.c 
b/libavcodec/aarch64/hevcdsp_init_aarch64.c
index 4c29daa6d5..fe111bd1ac 100644
--- a/libavcodec/aarch64/hevcdsp_init_aarch64.c
+++ b/libavcodec/aarch64/hevcdsp_init_aarch64.c
@@ -45,6 +45,14 @@ void ff_hevc_idct_8x8_8_neon(int16_t *coeffs, int col_limit);
 void ff_hevc_idct_8x8_10_neon(int16_t *coeffs, int col_limit);
 void ff_hevc_idct_16x16_8_neon(int16_t *coeffs, int col_limit);
 void ff_hevc_idct_16x16_10_neon(int16_t *coeffs, int col_limit);
+void ff_hevc_idct_4x4_dc_8_neon(int16_t *coeffs);
+void ff_hevc_idct_8x8_dc_8_neon(int16_t *coeffs);
+void ff_hevc_idct_16x16_dc_8_neon(int16_t *coeffs);
+void ff_hevc_idct_32x32_dc_8_neon(int16_t *coeffs);
+void ff_hevc_idct_4x4_dc_10_neon(int16_t *coeffs);
+void ff_hevc_idct_8x8_dc_10_neon(int16_t *coeffs);
+void ff_hevc_idct_16x16_dc_10_neon(int16_t *coeffs);
+void ff_hevc_idct_32x32_dc_10_neon(int16_t *coeffs);
 
 av_cold void ff_hevc_dsp_init_aarch64(HEVCDSPContext *c, const int bit_depth)
 {
@@ -57,6 +65,10 @@ av_cold void ff_hevc_dsp_init_aarch64(HEVCDSPContext *c, 
const int bit_depth)
 c->add_residual[3] = ff_hevc_add_residual_32x32_8_neon;
 c->idct[1] = ff_hevc_idct_8x8_8_neon;
 c->idct[2] = ff_hevc_idct_16x16_8_neon;
+c->idct_dc[0]  = ff_hevc_idct_4x4_dc_8_neon;
+c->idct_dc[1]  = ff_hevc_idct_8x8_dc_8_neon;
+c->idct_dc[2]  = ff_hevc_idct_16x16_dc_8_neon;
+c->idct_dc[3]  = ff_hevc_idct_32x32_dc_8_neon;
 }
 if (bit_depth == 10) {
 c->add_residual[0] = ff_hevc_add_residual_4x4_10_neon;
@@ -65,5 +77,9 @@ av_cold void ff_hevc_dsp_init_aarch64(HEVCDSPContext *c, 
const int bit_depth)
 c->add_residual[3] = ff_hevc_add_residual_32x32_10_neon;
 c->idct[1] = ff_hevc_idct_8x8_10_neon;
 c->idct[2] = ff_hevc_idct_16x16_10_neon;
+c->idct_dc[0]  = ff_hevc_idct_4x4_dc_10_neon;
+c->idct_dc[1]  = ff_hevc_idct_8x8_dc_10_neon;
+c->idct_dc[2]  = ff_hevc_idct_16x16_dc_10_neon;
+c->idct_dc[3]  = ff_hevc_idct_32x32_dc_10_neon;
 }
 }
-- 
2.24.3 (Apple Git-128)

___
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/4] avcodec/aarch64/hevcdsp: port add_residual functions

2021-02-04 Thread Josh Dekker
From: Reimar Döffinger 

Speedup is fairly small, around 1.5%, but these are fairly simple.

Signed-off-by: Josh Dekker 
---
 libavcodec/aarch64/hevcdsp_idct_neon.S| 190 ++
 libavcodec/aarch64/hevcdsp_init_aarch64.c |  24 +++
 2 files changed, 214 insertions(+)

diff --git a/libavcodec/aarch64/hevcdsp_idct_neon.S 
b/libavcodec/aarch64/hevcdsp_idct_neon.S
index c70d6a906d..329038a958 100644
--- a/libavcodec/aarch64/hevcdsp_idct_neon.S
+++ b/libavcodec/aarch64/hevcdsp_idct_neon.S
@@ -36,6 +36,196 @@ const trans, align=4
 .short 31, 22, 13, 4
 endconst
 
+.macro clip10 in1, in2, c1, c2
+smax\in1, \in1, \c1
+smax\in2, \in2, \c1
+smin\in1, \in1, \c2
+smin\in2, \in2, \c2
+.endm
+
+function ff_hevc_add_residual_4x4_8_neon, export=1
+ld1 {v0.8h-v1.8h}, [x1]
+ld1 {v2.s}[0], [x0], x2
+ld1 {v2.s}[1], [x0], x2
+ld1 {v2.s}[2], [x0], x2
+ld1 {v2.s}[3], [x0], x2
+sub x0, x0, x2, lsl #2
+uxtlv6.8h,  v2.8B
+uxtl2   v7.8h,  v2.16B
+sqadd   v0.8h,  v0.8h, v6.8h
+sqadd   v1.8h,  v1.8h, v7.8h
+sqxtun  v0.8B,  v0.8h
+sqxtun2 v0.16B, v1.8h
+st1 {v0.s}[0], [x0], x2
+st1 {v0.s}[1], [x0], x2
+st1 {v0.s}[2], [x0], x2
+st1 {v0.s}[3], [x0], x2
+ret
+endfunc
+
+function ff_hevc_add_residual_4x4_10_neon, export=1
+mov x12, x0
+ld1 {v0.8h-v1.8h}, [x1]
+ld1 {v2.d}[0], [x12], x2
+ld1 {v2.d}[1], [x12], x2
+ld1 {v3.d}[0], [x12], x2
+sqadd   v0.8h, v0.8h, v2.8h
+ld1 {V3.d}[1], [x12], x2
+moviv4.8h, #0
+sqadd   v1.8h, v1.8h, v3.8h
+mvniv5.8h, #0xFC, LSL #8 // movi #0x3FF
+clip10  v0.8h, v1.8h, v4.8h, v5.8h
+st1 {v0.d}[0], [x0], x2
+st1 {v0.d}[1], [x0], x2
+st1 {v1.d}[0], [x0], x2
+st1 {v1.d}[1], [x0], x2
+ret
+endfunc
+
+function ff_hevc_add_residual_8x8_8_neon, export=1
+add x12, x0, x2
+add x2,  x2, x2
+mov x3,   #8
+1:  subsx3,   x3, #2
+ld1 {v2.d}[0],   [x0]
+ld1 {v2.d}[1],   [x12]
+uxtlv3.8h,   v2.8B
+ld1 {v0.8h-v1.8h}, [x1], #32
+uxtl2   v2.8h,   v2.16B
+sqadd   v0.8h,   v0.8h,   v3.8h
+sqadd   v1.8h,   v1.8h,   v2.8h
+sqxtun  v0.8B,   v0.8h
+sqxtun2 v0.16B,  v1.8h
+st1 {v0.d}[0],   [x0], x2
+st1 {v0.d}[1],   [x12], x2
+bne 1b
+ret
+endfunc
+
+function ff_hevc_add_residual_8x8_10_neon, export=1
+add x12, x0, x2
+add x2,  x2, x2
+mov x3,  #8
+moviv4.8h, #0
+mvniv5.8h, #0xFC, LSL #8 // movi #0x3FF
+1:  subsx3,  x3, #2
+ld1 {v0.8h-v1.8h}, [x1], #32
+ld1 {v2.8h},[x0]
+sqadd   v0.8h, v0.8h, v2.8h
+ld1 {v3.8h},[x12]
+sqadd   v1.8h, v1.8h, v3.8h
+clip10  v0.8h, v1.8h, v4.8h, v5.8h
+st1 {v0.8h}, [x0], x2
+st1 {v1.8h}, [x12], x2
+bne 1b
+ret
+endfunc
+
+function ff_hevc_add_residual_16x16_8_neon, export=1
+mov x3,  #16
+add x12, x0, x2
+add x2,  x2, x2
+1:  subsx3,  x3, #2
+ld1 {v16.16B}, [x0]
+ld1 {v0.8h-v3.8h}, [x1], #64
+ld1 {v19.16B},[x12]
+uxtlv17.8h, v16.8B
+uxtl2   v18.8h, v16.16B
+uxtlv20.8h, v19.8B
+uxtl2   v21.8h, v19.16B
+sqadd   v0.8h,  v0.8h, v17.8h
+sqadd   v1.8h,  v1.8h, v18.8h
+sqadd   v2.8h,  v2.8h, v20.8h
+sqadd   v3.8h,  v3.8h, v21.8h
+sqxtun  v0.8B,  v0.8h
+sqxtun2 v0.16B, v1.8h
+sqxtun  v1.8B,  v2.8h
+sqxtun2 v1.16B, v3.8h
+st1 {v0.16B}, [x0], x2
+st1 {v1.16B}, [x12], x2
+bne 1b
+ret
+endfunc
+
+function ff_hevc_add_residual_16x16_10_neon, export=1
+mov x3,  #16
+moviv20.8h, #0
+mvniv21.8h, #0xFC, LSL #8 // movi #0x3FF
+add x12, x0, x2
+add 

[FFmpeg-devel] [PATCH v2 1/4] avcodec/aarch64/hevcdsp: port SIMD idct functions

2021-02-04 Thread Josh Dekker
From: Reimar Döffinger 

Makes SIMD-optimized 8x8 and 16x16 idcts for 8 and 10 bit depth
available on aarch64.
For a UHD HDR (10 bit) sample video these were consuming the most time
and this optimization reduced overall decode time from 19.4s to 16.4s,
approximately 15% speedup.
Test sample was the first 300 frames of "LG 4K HDR Demo - New York.ts",
running on Apple M1.

Signed-off-by: Josh Dekker 
---
 libavcodec/aarch64/Makefile   |   2 +
 libavcodec/aarch64/hevcdsp_idct_neon.S| 380 ++
 libavcodec/aarch64/hevcdsp_init_aarch64.c |  45 +++
 libavcodec/hevcdsp.c  |   2 +
 libavcodec/hevcdsp.h  |   1 +
 5 files changed, 430 insertions(+)
 create mode 100644 libavcodec/aarch64/hevcdsp_idct_neon.S
 create mode 100644 libavcodec/aarch64/hevcdsp_init_aarch64.c

diff --git a/libavcodec/aarch64/Makefile b/libavcodec/aarch64/Makefile
index f6434e40da..2ea1d74a38 100644
--- a/libavcodec/aarch64/Makefile
+++ b/libavcodec/aarch64/Makefile
@@ -61,3 +61,5 @@ NEON-OBJS-$(CONFIG_VP9_DECODER) += 
aarch64/vp9itxfm_16bpp_neon.o   \
aarch64/vp9lpf_neon.o   
\
aarch64/vp9mc_16bpp_neon.o  
\
aarch64/vp9mc_neon.o
+NEON-OBJS-$(CONFIG_HEVC_DECODER)+= aarch64/hevcdsp_idct_neon.o 
\
+   aarch64/hevcdsp_init_aarch64.o
diff --git a/libavcodec/aarch64/hevcdsp_idct_neon.S 
b/libavcodec/aarch64/hevcdsp_idct_neon.S
new file mode 100644
index 00..c70d6a906d
--- /dev/null
+++ b/libavcodec/aarch64/hevcdsp_idct_neon.S
@@ -0,0 +1,380 @@
+/*
+ * ARM NEON optimised IDCT functions for HEVC decoding
+ * Copyright (c) 2014 Seppo Tomperi 
+ * Copyright (c) 2017 Alexandra Hájková
+ *
+ * Ported from arm/hevcdsp_idct_neon.S by
+ * Copyright (c) 2020 Reimar Döffinger
+ *
+ * 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
+ */
+
+#include "libavutil/aarch64/asm.S"
+
+const trans, align=4
+.short 64, 83, 64, 36
+.short 89, 75, 50, 18
+.short 90, 87, 80, 70
+.short 57, 43, 25, 9
+.short 90, 90, 88, 85
+.short 82, 78, 73, 67
+.short 61, 54, 46, 38
+.short 31, 22, 13, 4
+endconst
+
+.macro sum_sub out, in, c, op, p
+  .ifc \op, +
+smlal\p \out, \in, \c
+  .else
+smlsl\p \out, \in, \c
+  .endif
+.endm
+
+.macro fixsqrshrn d, dt, n, m
+  .ifc \dt, .8h
+sqrshrn2\d\dt, \n\().4s, \m
+  .else
+sqrshrn \n\().4h, \n\().4s, \m
+mov \d\().d[0], \n\().d[0]
+  .endif
+.endm
+
+// uses and clobbers v28-v31 as temp registers
+.macro tr_4x4_8 in0, in1, in2, in3, out0, out1, out2, out3, p1, p2
+ sshll\p1   v28.4s, \in0, #6
+ movv29.16b, v28.16b
+ smull\p1   v30.4s, \in1, v0.h[1]
+ smull\p1   v31.4s, \in1, v0.h[3]
+ smlal\p2   v28.4s, \in2, v0.h[0] //e0
+ smlsl\p2   v29.4s, \in2, v0.h[0] //e1
+ smlal\p2   v30.4s, \in3, v0.h[3] //o0
+ smlsl\p2   v31.4s, \in3, v0.h[1] //o1
+
+ add\out0, v28.4s, v30.4s
+ add\out1, v29.4s, v31.4s
+ sub\out2, v29.4s, v31.4s
+ sub\out3, v28.4s, v30.4s
+.endm
+
+.macro transpose8_4x4 r0, r1, r2, r3
+trn1v2.8h, \r0\().8h, \r1\().8h
+trn2v3.8h, \r0\().8h, \r1\().8h
+trn1v4.8h, \r2\().8h, \r3\().8h
+trn2v5.8h, \r2\().8h, \r3\().8h
+trn1\r0\().4s, v2.4s, v4.4s
+trn2\r2\().4s, v2.4s, v4.4s
+trn1\r1\().4s, v3.4s, v5.4s
+trn2\r3\().4s, v3.4s, v5.4s
+.endm
+
+.macro transpose_8x8 r0, r1, r2, r3, r4, r5, r6, r7
+transpose8_4x4  \r0, \r1, \r2, \r3
+transpose8_4x4  \r4, \r5, \r6, \r7
+.endm
+
+.macro tr_8x4 shift, in0,in0t, in1,in1t, in2,in2t, in3,in3t, in4,in4t, 
in5,in5t, in6,in6t, in7,in7t, p1, p2
+tr_4x4_8\in0\in0t, \in2\in2t, \in4\in4t, \in6\in6t, v24.4s, 
v25.4s, v26.4s, v27.4s, \p1, \p2
+
+smull\p1v30.4s, \in1\in1t, v

[FFmpeg-devel] [PATCH v2 4/4] avcodec/aarch64/hevcdsp: add sao_band NEON

2021-02-04 Thread Josh Dekker
Only works for 8x8.

Signed-off-by: Josh Dekker 
---
 libavcodec/aarch64/Makefile   |  3 +-
 libavcodec/aarch64/hevcdsp_init_aarch64.c |  7 ++
 libavcodec/aarch64/hevcdsp_sao_neon.S | 87 +++
 3 files changed, 96 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/aarch64/hevcdsp_sao_neon.S

diff --git a/libavcodec/aarch64/Makefile b/libavcodec/aarch64/Makefile
index 2ea1d74a38..954461f81d 100644
--- a/libavcodec/aarch64/Makefile
+++ b/libavcodec/aarch64/Makefile
@@ -62,4 +62,5 @@ NEON-OBJS-$(CONFIG_VP9_DECODER) += 
aarch64/vp9itxfm_16bpp_neon.o   \
aarch64/vp9mc_16bpp_neon.o  
\
aarch64/vp9mc_neon.o
 NEON-OBJS-$(CONFIG_HEVC_DECODER)+= aarch64/hevcdsp_idct_neon.o 
\
-   aarch64/hevcdsp_init_aarch64.o
+   aarch64/hevcdsp_init_aarch64.o  
\
+   aarch64/hevcdsp_sao_neon.o
diff --git a/libavcodec/aarch64/hevcdsp_init_aarch64.c 
b/libavcodec/aarch64/hevcdsp_init_aarch64.c
index fe111bd1ac..c785e46f79 100644
--- a/libavcodec/aarch64/hevcdsp_init_aarch64.c
+++ b/libavcodec/aarch64/hevcdsp_init_aarch64.c
@@ -53,6 +53,12 @@ void ff_hevc_idct_4x4_dc_10_neon(int16_t *coeffs);
 void ff_hevc_idct_8x8_dc_10_neon(int16_t *coeffs);
 void ff_hevc_idct_16x16_dc_10_neon(int16_t *coeffs);
 void ff_hevc_idct_32x32_dc_10_neon(int16_t *coeffs);
+void ff_hevc_sao_band_filter_8x8_8_neon(uint8_t *_dst, uint8_t *_src,
+  ptrdiff_t stride_dst, ptrdiff_t stride_src,
+  int16_t *sao_offset_val, int sao_left_class,
+  int width, int height);
+
+
 
 av_cold void ff_hevc_dsp_init_aarch64(HEVCDSPContext *c, const int bit_depth)
 {
@@ -69,6 +75,7 @@ av_cold void ff_hevc_dsp_init_aarch64(HEVCDSPContext *c, 
const int bit_depth)
 c->idct_dc[1]  = ff_hevc_idct_8x8_dc_8_neon;
 c->idct_dc[2]  = ff_hevc_idct_16x16_dc_8_neon;
 c->idct_dc[3]  = ff_hevc_idct_32x32_dc_8_neon;
+c->sao_band_filter[0]  = ff_hevc_sao_band_filter_8x8_8_neon;
 }
 if (bit_depth == 10) {
 c->add_residual[0] = ff_hevc_add_residual_4x4_10_neon;
diff --git a/libavcodec/aarch64/hevcdsp_sao_neon.S 
b/libavcodec/aarch64/hevcdsp_sao_neon.S
new file mode 100644
index 00..f142c1e8c2
--- /dev/null
+++ b/libavcodec/aarch64/hevcdsp_sao_neon.S
@@ -0,0 +1,87 @@
+/* -*-arm64-*-
+ * vim: syntax=arm64asm
+ *
+ * AArch64 NEON optimised SAO functions for HEVC decoding
+ *
+ * Copyright (c) 2020 Josh Dekker 
+ *
+ * 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
+ */
+
+#include "libavutil/aarch64/asm.S"
+
+// void sao_band_filter(uint8_t *_dst, uint8_t *_src,
+//  ptrdiff_t stride_dst, ptrdiff_t stride_src,
+//  int16_t *sao_offset_val, int sao_left_class,
+//  int width, int height)
+function ff_hevc_sao_band_filter_8x8_8_neon, export=1
+sub sp, sp, #64
+stp xzr, xzr, [sp]
+stp xzr, xzr, [sp, #16]
+stp xzr, xzr, [sp, #32]
+stp xzr, xzr, [sp, #48]
+mov w8, #4
+0:
+ldrsh x9, [x4, x8, lsl #1] // x9 = sao_offset_val[k+1]
+subs w8, w8, #1
+add w10, w8, w5 // x10 = k + sao_left_class
+and w10, w10, #0x1F
+strh w9, [sp, x10, lsl #1]
+bne 0b
+ld1 {v16.16b-v19.16b}, [sp], #64
+movi v20.8h, #1
+1:  // beginning of line
+mov w8, w6
+2:
+// Simple layout for accessing 16bit values
+// with 8bit LUT.
+//
+//   00  01  02  03  04  05  06  07
+// +--->
+// |xDE#xAD|xCA#xFE|xBE#xEF|xFE#xED|
+// +--->
+//i-0 i-1 i-2 i-3
+// dst[x] = av_clip_pixel(src[x] + offset_table[src[x] >> shift]);
+ld1 {v2.8b}, [x1]
+// load src[x]
+uxtl v0.8h, v2.8b
+// >> shift
+ushr v2.8h, v0.8h, #3 // BIT_DEPTH - 3
+// x2 (access lower short)
+shl v1.8h, v2.8h, #1 // low (x2, accessing short)
+// +1 access upper short
+add v3.8h, v1.8h, v20.8h
+// shi

Re: [FFmpeg-devel] [PATCH 1/4] Remove unnecessary mem.h inclusions

2021-02-04 Thread Andreas Rheinhardt
Anton Khirnov:
> Quoting Andreas Rheinhardt (2021-02-04 01:05:05)
>> Thanks for the report. I have only checked for whether the relevant
>> translation unit uses any of the alloc/free functions (because
>> DECLARE_ALIGNED is already provided by mem_internal.h), but I have not
>> taken into account stuff that is included by the headers included by
>> mem.h. In this case, one needs string.h (which is included in
>> libavutil/common.h which in turn is included in avutil.h which is
>> included in mem.h). Will look over everything again.
>>
>> - Andreas
>>
>> PS: It actually seems that the only thing provided by avutil.h that
>> mem.h uses is size_t. Do we allow to remove included headers from
>> installed headers at major version bumps?
> 
> I would say yes, IIRC it has happened before.
> Certainly nobody should depend on our headers to provide any random
> system headers.
> 
Removing avutil.h affects not only system headers, but which of our
headers are included as it includes
#include "common.h"
#include "error.h"
#include "rational.h"
#include "version.h"
#include "macros.h"
#include "mathematics.h"
#include "log.h"
#include "pixfmt.h"
(And removing avutil.h will also remove avutil.h, of course.)

Other installed headers include too much, too: audio_fifo.h includes
avutil.h and fifo.h, but needs only attributes.h; eval.h unnecessarily
includes avutil.h; display.h includes common.h without needing it.
fifo.h includes avutil.h and attributes.h, but needs only stddef.h.
Several other headers include version.h despite the relevant FF_API
check for which it has been included no longer existing. (If we don't
remove version.h, sooner or later all headers will contain it.)

And while I played around a bit with this night, I found something odd:
libavutil/error.h is broken: It relies on MKTAG without providing the
header for it. MKTAG is in common.h which also includes mem.h which uses
an AVERROR code in an inline function. So the simple solution of
including common.h at the beginning of error.h doesn't work, as
AVERROR(EINVAL) will still be undefined in said function. I see two
other solutions: Move MKTAG (and probably a bit other stuff) to a new
header and include that in error.h; include common.h, but not at the
beginning of error.h, but only after the definition of AVERROR. Given
that I dislike monster headers like common.h, I prefer the first approach.
(I already mentioned this on IRC, but those who only follow the ML
should be informed, too.)

- 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".

Re: [FFmpeg-devel] [PATCH] avfilter/af_amix: add sum option

2021-02-04 Thread Paul B Mahol
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".

Re: [FFmpeg-devel] [PATCH] avformat: add binka demuxer

2021-02-04 Thread Paul B Mahol
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".

Re: [FFmpeg-devel] REQUEST: remove photocd_pipe demuxer as there is no parser

2021-02-04 Thread Jean-Baptiste Kempf
On Wed, 3 Feb 2021, at 11:38, Paul B Mahol wrote:
> I hereby request also to remove commit rights from Carl Eugen Hoyos for
> committing hacky and broken code.

This is not the right tone for this mailing list.

-- 
Jean-Baptiste Kempf -  President
+33 672 704 734
___
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] REQUEST: remove photocd_pipe demuxer as there is no parser

2021-02-04 Thread Paul B Mahol
On Thu, Feb 4, 2021 at 3:25 PM Jean-Baptiste Kempf  wrote:

> On Wed, 3 Feb 2021, at 11:38, Paul B Mahol wrote:
> > I hereby request also to remove commit rights from Carl Eugen Hoyos for
> > committing hacky and broken code.
>
> This is not the right tone for this mailing list.
>

I said nothing incorrect.


>
> --
> Jean-Baptiste Kempf -  President
> +33 672 704 734
> ___
> 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 1/4] Remove unnecessary mem.h inclusions

2021-02-04 Thread Anton Khirnov
Quoting Andreas Rheinhardt (2021-02-04 12:06:15)
> Anton Khirnov:
> > Quoting Andreas Rheinhardt (2021-02-04 01:05:05)
> >> Thanks for the report. I have only checked for whether the relevant
> >> translation unit uses any of the alloc/free functions (because
> >> DECLARE_ALIGNED is already provided by mem_internal.h), but I have not
> >> taken into account stuff that is included by the headers included by
> >> mem.h. In this case, one needs string.h (which is included in
> >> libavutil/common.h which in turn is included in avutil.h which is
> >> included in mem.h). Will look over everything again.
> >>
> >> - Andreas
> >>
> >> PS: It actually seems that the only thing provided by avutil.h that
> >> mem.h uses is size_t. Do we allow to remove included headers from
> >> installed headers at major version bumps?
> > 
> > I would say yes, IIRC it has happened before.
> > Certainly nobody should depend on our headers to provide any random
> > system headers.
> > 
> Removing avutil.h affects not only system headers, but which of our
> headers are included as it includes
> #include "common.h"
> #include "error.h"
> #include "rational.h"
> #include "version.h"
> #include "macros.h"
> #include "mathematics.h"
> #include "log.h"
> #include "pixfmt.h"
> (And removing avutil.h will also remove avutil.h, of course.)
> 
> Other installed headers include too much, too: audio_fifo.h includes
> avutil.h and fifo.h, but needs only attributes.h; eval.h unnecessarily
> includes avutil.h; display.h includes common.h without needing it.
> fifo.h includes avutil.h and attributes.h, but needs only stddef.h.
> Several other headers include version.h despite the relevant FF_API
> check for which it has been included no longer existing. (If we don't
> remove version.h, sooner or later all headers will contain it.)

I don't think we have an official project policy on this, but I would
be in favor of something like:

All installed headers are only guaranteed to provide those
identifiers that are explicitly declared in them. Users must not
rely on an installed header #include'ing any other specific headers,
as those can change at any time.

+exceptions for av*.h, but ideally I'd remove those too in the long
run - people should just include what they need and avoid monsterheaders

> 
> And while I played around a bit with this night, I found something odd:
> libavutil/error.h is broken: It relies on MKTAG without providing the
> header for it. MKTAG is in common.h which also includes mem.h which uses
> an AVERROR code in an inline function. So the simple solution of
> including common.h at the beginning of error.h doesn't work, as
> AVERROR(EINVAL) will still be undefined in said function. I see two
> other solutions: Move MKTAG (and probably a bit other stuff) to a new
> header and include that in error.h; include common.h, but not at the
> beginning of error.h, but only after the definition of AVERROR. Given
> that I dislike monster headers like common.h, I prefer the first approach.
> (I already mentioned this on IRC, but those who only follow the ML
> should be informed, too.)

I am in favor of moving MKTAG if you can think of a good place for it.
(also it should be properly namespaced, but not necessarily now)

-- 
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] REQUEST: remove photocd_pipe demuxer as there is no parser

2021-02-04 Thread James Almer

On 2/3/2021 7:38 AM, Paul B Mahol wrote:

This is only some of problems and some of formats I spotted.


There was no parser for webp either until i wrote one a few months ago, 
and lavf had no trouble reading webp images from for example the file 
protocol. It simply didn't work with non seekable input.

___
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] REQUEST: remove photocd_pipe demuxer as there is no parser

2021-02-04 Thread Jean-Baptiste Kempf
On Thu, 4 Feb 2021, at 15:31, Paul B Mahol wrote:
> On Thu, Feb 4, 2021 at 3:25 PM Jean-Baptiste Kempf  wrote:
> 
> > On Wed, 3 Feb 2021, at 11:38, Paul B Mahol wrote:
> > > I hereby request also to remove commit rights from Carl Eugen Hoyos for
> > > committing hacky and broken code.
> >
> > This is not the right tone for this mailing list.
> 
> I said nothing incorrect.

Hacky and Broken code is a subjective metric.

The only code that is not broken is the one that is not written.

Please tone it down.

-- 
Jean-Baptiste Kempf -  President
+33 672 704 734
___
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/4] Remove unnecessary mem.h inclusions

2021-02-04 Thread Nicolas George
Anton Khirnov (12021-02-04):
> I don't think we have an official project policy on this, but I would
> be in favor of something like:
> 
> All installed headers are only guaranteed to provide those
> identifiers that are explicitly declared in them. Users must not
> rely on an installed header #include'ing any other specific headers,
> as those can change at any time.

That would probably be ok, but I would suggest to add:

... explicitly declared or used in them.

If a function argument is size_t or int64_t, then we can expect size_t
or int64_t to be defined.

Regards,

-- 
  Nicolas George
___
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/4] avcodec/mpegvideo_motion: Improve check to remove dead code

2021-02-04 Thread Andreas Rheinhardt
Several compile-time checks can be improved because mcsel is not used
for MPEG-1/2 (it is only used for MPEG-4) and because MPEG-1/2 is the
only user of ff_mpv_motion that uses MV_TYPE_16X8 and MV_TYPE_DMV.

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

diff --git a/libavcodec/mpegvideo_motion.c b/libavcodec/mpegvideo_motion.c
index 58cdecf83b..d065542967 100644
--- a/libavcodec/mpegvideo_motion.c
+++ b/libavcodec/mpegvideo_motion.c
@@ -306,9 +306,9 @@ void mpeg_motion_internal(MpegEncContext *s,
 
 if ((unsigned)src_x >= FFMAX(s->h_edge_pos - (motion_x & 1) - 15   , 0) ||
 (unsigned)src_y >= FFMAX(   v_edge_pos - (motion_y & 1) - h + 1, 0)) {
-if (is_mpeg12 ||
-s->codec_id == AV_CODEC_ID_MPEG2VIDEO ||
-s->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
+if (is_mpeg12 || (CONFIG_SMALL &&
+  s->codec_id == AV_CODEC_ID_MPEG2VIDEO ||
+  s->codec_id == AV_CODEC_ID_MPEG1VIDEO)) {
 av_log(s->avctx, AV_LOG_DEBUG,
"MPEG motion vector out of boundary (%d %d)\n", src_x,
src_y);
@@ -853,7 +853,7 @@ static av_always_inline void 
mpv_motion_internal(MpegEncContext *s,
 
 switch (s->mv_type) {
 case MV_TYPE_16X16:
-if (s->mcsel) {
+if (!is_mpeg12 && s->mcsel) {
 if (s->real_sprite_warping_points == 1) {
 gmc1_motion(s, dest_y, dest_cb, dest_cr,
 ref_picture);
@@ -915,6 +915,7 @@ static av_always_inline void 
mpv_motion_internal(MpegEncContext *s,
 }
 break;
 case MV_TYPE_16X8:
+if (CONFIG_SMALL || is_mpeg12) {
 for (i = 0; i < 2; i++) {
 uint8_t **ref2picture;
 
@@ -936,7 +937,9 @@ static av_always_inline void 
mpv_motion_internal(MpegEncContext *s,
 dest_cr += (16 >> s->chroma_y_shift) * s->uvlinesize;
 }
 break;
+}
 case MV_TYPE_DMV:
+if (CONFIG_SMALL || is_mpeg12) {
 if (s->picture_structure == PICT_FRAME) {
 for (i = 0; i < 2; i++) {
 int j;
@@ -969,6 +972,7 @@ static av_always_inline void 
mpv_motion_internal(MpegEncContext *s,
 }
 }
 break;
+}
 default: av_assert2(0);
 }
 }
-- 
2.27.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".

[FFmpeg-devel] [PATCH 2/4] avcodec/mpegvideo_motion: Reindentation

2021-02-04 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo_motion.c | 115 +-
 1 file changed, 57 insertions(+), 58 deletions(-)

diff --git a/libavcodec/mpegvideo_motion.c b/libavcodec/mpegvideo_motion.c
index d065542967..aed11dccd7 100644
--- a/libavcodec/mpegvideo_motion.c
+++ b/libavcodec/mpegvideo_motion.c
@@ -213,16 +213,16 @@ static inline int hpel_motion(MpegEncContext *s,
 dxy |= (motion_y & 1) << 1;
 src += src_y * s->linesize + src_x;
 
-if ((unsigned)src_x >= FFMAX(s->h_edge_pos - (motion_x & 1) - 7, 0) ||
-(unsigned)src_y >= FFMAX(s->v_edge_pos - (motion_y & 1) - 7, 0)) {
-s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, src,
- s->linesize, s->linesize,
- 9, 9,
- src_x, src_y,
- s->h_edge_pos, s->v_edge_pos);
-src = s->sc.edge_emu_buffer;
-emu = 1;
-}
+if ((unsigned)src_x >= FFMAX(s->h_edge_pos - (motion_x & 1) - 7, 0) ||
+(unsigned)src_y >= FFMAX(s->v_edge_pos - (motion_y & 1) - 7, 0)) {
+s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, src,
+ s->linesize, s->linesize,
+ 9, 9,
+ src_x, src_y,
+ s->h_edge_pos, s->v_edge_pos);
+src = s->sc.edge_emu_buffer;
+emu = 1;
+}
 pix_op[dxy](dest, src, s->linesize, 8);
 return emu;
 }
@@ -916,62 +916,61 @@ static av_always_inline void 
mpv_motion_internal(MpegEncContext *s,
 break;
 case MV_TYPE_16X8:
 if (CONFIG_SMALL || is_mpeg12) {
-for (i = 0; i < 2; i++) {
-uint8_t **ref2picture;
+for (i = 0; i < 2; i++) {
+uint8_t **ref2picture;
+
+if ((s->picture_structure == s->field_select[dir][i] + 1 ||
+ s->pict_type == AV_PICTURE_TYPE_B || s->first_field) &&
+ref_picture[0]) {
+ref2picture = ref_picture;
+} else {
+ref2picture = s->current_picture_ptr->f->data;
+}
 
-if ((s->picture_structure == s->field_select[dir][i] + 1
-|| s->pict_type == AV_PICTURE_TYPE_B || s->first_field) && 
ref_picture[0]) {
-ref2picture = ref_picture;
-} else {
-ref2picture = s->current_picture_ptr->f->data;
+mpeg_motion(s, dest_y, dest_cb, dest_cr,
+s->field_select[dir][i],
+ref2picture, pix_op,
+s->mv[dir][i][0], s->mv[dir][i][1],
+8, 1, (mb_y & ~1) + i);
+
+dest_y  += 16 * s->linesize;
+dest_cb += (16 >> s->chroma_y_shift) * s->uvlinesize;
+dest_cr += (16 >> s->chroma_y_shift) * s->uvlinesize;
 }
-
-mpeg_motion(s, dest_y, dest_cb, dest_cr,
-s->field_select[dir][i],
-ref2picture, pix_op,
-s->mv[dir][i][0], s->mv[dir][i][1],
-8, 1, (mb_y & ~1) + i);
-
-dest_y  += 16 * s->linesize;
-dest_cb += (16 >> s->chroma_y_shift) * s->uvlinesize;
-dest_cr += (16 >> s->chroma_y_shift) * s->uvlinesize;
-}
-break;
+break;
 }
 case MV_TYPE_DMV:
 if (CONFIG_SMALL || is_mpeg12) {
-if (s->picture_structure == PICT_FRAME) {
-for (i = 0; i < 2; i++) {
-int j;
-for (j = 0; j < 2; j++)
-mpeg_motion_field(s, dest_y, dest_cb, dest_cr,
-  j, j ^ i, ref_picture, pix_op,
-  s->mv[dir][2 * i + j][0],
-  s->mv[dir][2 * i + j][1], 8, mb_y);
-pix_op = s->hdsp.avg_pixels_tab;
-}
-} else {
-if (!ref_picture[0]) {
-ref_picture = s->current_picture_ptr->f->data;
-}
-for (i = 0; i < 2; i++) {
-mpeg_motion(s, dest_y, dest_cb, dest_cr,
-s->picture_structure != i + 1,
-ref_picture, pix_op,
-s->mv[dir][2 * i][0], s->mv[dir][2 * i][1],
-16, 0, mb_y >> 1);
-
-// after put we make avg of the same block
-pix_op = s->hdsp.avg_pixels_tab;
-
-/* opposite parity is always in the same frame if this is
- * second field */
-if (!s->first_field) {
+if (s->picture_structure == PICT_FRAME) {
+for (i = 0; i < 2; i++) {
+for (int j = 0; j < 2; j++)
+

[FFmpeg-devel] [PATCH 3/4] avcodec/mpegvideo_motion: Remove unnecessary headers

2021-02-04 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo_motion.c | 5 -
 1 file changed, 5 deletions(-)

diff --git a/libavcodec/mpegvideo_motion.c b/libavcodec/mpegvideo_motion.c
index aed11dccd7..3f2de29c4e 100644
--- a/libavcodec/mpegvideo_motion.c
+++ b/libavcodec/mpegvideo_motion.c
@@ -21,8 +21,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include 
-
 #include "libavutil/avassert.h"
 #include "libavutil/internal.h"
 #include "libavutil/mem_internal.h"
@@ -31,11 +29,8 @@
 #include "h261.h"
 #include "mpegutils.h"
 #include "mpegvideo.h"
-#include "mjpegenc.h"
-#include "msmpeg4.h"
 #include "qpeldsp.h"
 #include "wmv2.h"
-#include 
 
 static void gmc1_motion(MpegEncContext *s,
 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
-- 
2.27.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".

[FFmpeg-devel] [PATCH 4/4] avutil/common: Move everything inside inclusion guards

2021-02-04 Thread Andreas Rheinhardt
libavutil/common.h is a public header that provides generic math
functions whereas libavutil/intmath.h is a private header that contains
plattform-specific optimized versions of said math functions. common.h
includes intmath.h (when building the FFmpeg libraries) so that the
optimized versions are used for them.

This interdependency sometimes causes trouble: intmath.h once contained
an inlined ff_sqrt function that relied upon av_log2_16bit. In case there
was no optimized logarithm available on this plattform, intmath.h needed
to include common.h to get the generic implementation and this has been
done after the optimized versions (if any) have been provided so that
common.h used the optimized versions; it also needed to be done before
ff_sqrt. Yet when intmath.h was included from common.h and if an ordinary
inclusion guard was used by common.h, the #include "common.h" in intmath.h
was a no-op and therefore av_log2_16bit was still unknown at the end of
intmath.h (and also in ff_sqrt) if no optimized version was available.

Before a955b5965825631986ba854d007d4e934e466c7d this was solved by
duplicating the #ifndef av_log2_16bit check after the inclusion of
common.h in intmath.h; said commit instead moved these checks to the
end of common.h, outside the inclusion guards and made common.h include
itself to get these unguarded defines. This is still the current
state of affairs.

Yet this is unnecessary since 9734b8ba56d05e970c353dfd5baafa43fdb08024
as said commit removed ff_sqrt as well as the #include "common.h" from
intmath.h. Therefore this commit moves everything inside the inclusion
guards and makes common.h not include itself.

Signed-off-by: Andreas Rheinhardt 
---
 libavutil/common.h | 140 +
 1 file changed, 66 insertions(+), 74 deletions(-)

diff --git a/libavutil/common.h b/libavutil/common.h
index a60a558b1d..fde90182ee 100644
--- a/libavutil/common.h
+++ b/libavutil/common.h
@@ -114,8 +114,72 @@
 #   include "intmath.h"
 #endif
 
-/* Pull in unguarded fallback defines at the end of this file. */
-#include "common.h"
+#ifndef av_ceil_log2
+#   define av_ceil_log2 av_ceil_log2_c
+#endif
+#ifndef av_clip
+#   define av_clip  av_clip_c
+#endif
+#ifndef av_clip64
+#   define av_clip64av_clip64_c
+#endif
+#ifndef av_clip_uint8
+#   define av_clip_uint8av_clip_uint8_c
+#endif
+#ifndef av_clip_int8
+#   define av_clip_int8 av_clip_int8_c
+#endif
+#ifndef av_clip_uint16
+#   define av_clip_uint16   av_clip_uint16_c
+#endif
+#ifndef av_clip_int16
+#   define av_clip_int16av_clip_int16_c
+#endif
+#ifndef av_clipl_int32
+#   define av_clipl_int32   av_clipl_int32_c
+#endif
+#ifndef av_clip_intp2
+#   define av_clip_intp2av_clip_intp2_c
+#endif
+#ifndef av_clip_uintp2
+#   define av_clip_uintp2   av_clip_uintp2_c
+#endif
+#ifndef av_mod_uintp2
+#   define av_mod_uintp2av_mod_uintp2_c
+#endif
+#ifndef av_sat_add32
+#   define av_sat_add32 av_sat_add32_c
+#endif
+#ifndef av_sat_dadd32
+#   define av_sat_dadd32av_sat_dadd32_c
+#endif
+#ifndef av_sat_sub32
+#   define av_sat_sub32 av_sat_sub32_c
+#endif
+#ifndef av_sat_dsub32
+#   define av_sat_dsub32av_sat_dsub32_c
+#endif
+#ifndef av_sat_add64
+#   define av_sat_add64 av_sat_add64_c
+#endif
+#ifndef av_sat_sub64
+#   define av_sat_sub64 av_sat_sub64_c
+#endif
+#ifndef av_clipf
+#   define av_clipf av_clipf_c
+#endif
+#ifndef av_clipd
+#   define av_clipd av_clipd_c
+#endif
+#ifndef av_popcount
+#   define av_popcount  av_popcount_c
+#endif
+#ifndef av_popcount64
+#   define av_popcount64av_popcount64_c
+#endif
+#ifndef av_parity
+#   define av_parityav_parity_c
+#endif
 
 #ifndef av_log2
 av_const int av_log2(unsigned v);
@@ -541,75 +605,3 @@ static av_always_inline av_const int av_parity_c(uint32_t 
v)
 #endif /* HAVE_AV_CONFIG_H */
 
 #endif /* AVUTIL_COMMON_H */
-
-/*
- * The following definitions are outside the multiple inclusion guard
- * to ensure they are immediately available in intmath.h.
- */
-
-#ifndef av_ceil_log2
-#   define av_ceil_log2 av_ceil_log2_c
-#endif
-#ifndef av_clip
-#   define av_clip  av_clip_c
-#endif
-#ifndef av_clip64
-#   define av_clip64av_clip64_c
-#endif
-#ifndef av_clip_uint8
-#   define av_clip_uint8av_clip_uint8_c
-#endif
-#ifndef av_clip_int8
-#   define av_clip_int8 av_clip_int8_c
-#endif
-#ifndef av_clip_uint16
-#   define av_clip_uint16   av_clip_uint16_c
-#endif
-#ifndef av_clip_int16
-#   define av_clip_int16av_clip_int16_c
-#endif
-#ifndef av_clipl_int32
-#   define av_clipl_int32   av_clipl_int32_c
-#endif
-#ifndef av_clip_intp2
-#   define av_clip_intp2av_clip_intp2_c
-#endif
-#ifndef av_clip_uintp2
-#   define av_clip_uintp2   av_clip_uintp2_c
-#endif
-#ifndef av_mod_uintp2
-#   define av_mod_uintp2av_mod_uintp2_c
-#endif
-#ifndef av_sat_add32
-#   define av_sat_add32 av_sat_add32_c
-#endif
-#ifndef av_sat_dadd32
-#   define av_sat_dad

Re: [FFmpeg-devel] [PATCH 1/4] Remove unnecessary mem.h inclusions

2021-02-04 Thread Anton Khirnov
Quoting Nicolas George (2021-02-04 15:48:03)
> Anton Khirnov (12021-02-04):
> > I don't think we have an official project policy on this, but I would
> > be in favor of something like:
> > 
> > All installed headers are only guaranteed to provide those
> > identifiers that are explicitly declared in them. Users must not
> > rely on an installed header #include'ing any other specific headers,
> > as those can change at any time.
> 
> That would probably be ok, but I would suggest to add:
> 
> ... explicitly declared or used in them.
> 
> If a function argument is size_t or int64_t, then we can expect size_t
> or int64_t to be defined.

That leads to undesirable situations, such as:
- header avfoo.h declares 'int64_t av_foo(void);'
- people start using av_foo() in their code, but do not include
   because avfoo.h includes it for them
- at some later point av_foo() is deprecated and removed
- everyone depends on avfoo.h to provide int64_t, even though avfoo.h
  does not use it anymore

-- 
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 2/2] avcodec/rscc: Check inflated_buf size whan it is used

2021-02-04 Thread Michael Niedermayer
On Sun, Nov 22, 2020 at 04:37:33PM +0100, Michael Niedermayer wrote:
> Fixes: out of array access
> Fixes: 
> 27434/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_RSCC_fuzzer-5196757675540480
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> ---
>  libavcodec/rscc.c | 4 
>  1 file changed, 4 insertions(+)

will apply

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

Awnsering whenever a program halts or runs forever is
On a turing machine, in general impossible (turings halting problem).
On any real computer, always possible as a real computer has a finite number
of states N, and will either halt in less than N cycles or never halt.


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 2/3] avcodec/mxpegdec: fix SOF counting

2021-02-04 Thread Michael Niedermayer
On Thu, Dec 03, 2020 at 10:11:38AM +0100, Michael Niedermayer wrote:
> Fixes: Timeout (>10sec -> 15ms)
> Fixes: 
> 27652/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MXPEG_fuzzer-5125920868007936
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/mxpegdec.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

will apply the remainder of this patchset

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

The smallest minority on earth is the individual. Those who deny 
individual rights cannot claim to be defenders of minorities. - Ayn Rand


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".

[FFmpeg-devel] [PATCH] avfilter: add colorize filter

2021-02-04 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/filters.texi  |  27 
 libavfilter/Makefile  |   1 +
 libavfilter/allfilters.c  |   1 +
 libavfilter/vf_colorize.c | 306 ++
 4 files changed, 335 insertions(+)
 create mode 100644 libavfilter/vf_colorize.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 52bced3143..c4aa31a91c 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -8163,6 +8163,33 @@ 
colorchannelmixer=.393:.769:.189:0:.349:.686:.168:0:.272:.534:.131
 
 This filter supports the all above options as @ref{commands}.
 
+@section colorize
+Overlay a solid color on the video stream.
+
+The filter accepts the following options:
+
+@table @option
+@item hue
+Set the color hue. Allowed range is from 0 to 360.
+Default value is 0.
+
+@item saturation
+Set the color saturation. Allowed range is from 0 to 1.
+Default value is 0.5.
+
+@item lightness
+Set the color lightness. Allowed range is from 0 to 1.
+Default value is 0.5.
+
+@item mix
+Set the mix of source lightness. By default is set to 1.0.
+Allowed range is from 0.0 to 1.0.
+@end table
+
+@subsection Commands
+
+This filter supports the all above options as @ref{commands}.
+
 @section colorkey
 RGB colorspace color keying.
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 68ff8e26d2..e26f181d21 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -198,6 +198,7 @@ OBJS-$(CONFIG_COLORBALANCE_FILTER)   += 
vf_colorbalance.o
 OBJS-$(CONFIG_COLORCHANNELMIXER_FILTER)  += vf_colorchannelmixer.o
 OBJS-$(CONFIG_COLORCONTRAST_FILTER)  += vf_colorcontrast.o
 OBJS-$(CONFIG_COLORCORRECT_FILTER)   += vf_colorcorrect.o
+OBJS-$(CONFIG_COLORIZE_FILTER)   += vf_colorize.o
 OBJS-$(CONFIG_COLORKEY_FILTER)   += vf_colorkey.o
 OBJS-$(CONFIG_COLORKEY_OPENCL_FILTER)+= vf_colorkey_opencl.o opencl.o \
 opencl/colorkey.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 3b4620a5d7..53d7063d54 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -188,6 +188,7 @@ extern AVFilter ff_vf_colorbalance;
 extern AVFilter ff_vf_colorchannelmixer;
 extern AVFilter ff_vf_colorcontrast;
 extern AVFilter ff_vf_colorcorrect;
+extern AVFilter ff_vf_colorize;
 extern AVFilter ff_vf_colorkey;
 extern AVFilter ff_vf_colorkey_opencl;
 extern AVFilter ff_vf_colorhold;
diff --git a/libavfilter/vf_colorize.c b/libavfilter/vf_colorize.c
new file mode 100644
index 00..e9d348201d
--- /dev/null
+++ b/libavfilter/vf_colorize.c
@@ -0,0 +1,306 @@
+/*
+ * 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
+ */
+
+#include "libavutil/opt.h"
+#include "libavutil/imgutils.h"
+#include "avfilter.h"
+#include "formats.h"
+#include "internal.h"
+#include "video.h"
+
+typedef struct ColorizeContext {
+const AVClass *class;
+
+float hue;
+float saturation;
+float lightness;
+float mix;
+
+int depth;
+int c[3];
+int planewidth[4];
+int planeheight[4];
+
+int (*do_plane_slice[2])(AVFilterContext *s, void *arg,
+ int jobnr, int nb_jobs);
+} ColorizeContext;
+
+static inline float lerpf(float v0, float v1, float f)
+{
+return v0 + (v1 - v0) * f;
+}
+
+static int colorizey_slice8(AVFilterContext *ctx, void *arg, int jobnr, int 
nb_jobs)
+{
+ColorizeContext *s = ctx->priv;
+AVFrame *frame = arg;
+const int width = s->planewidth[0];
+const int height = s->planeheight[0];
+const int slice_start = (height * jobnr) / nb_jobs;
+const int slice_end = (height * (jobnr + 1)) / nb_jobs;
+const int ylinesize = frame->linesize[0];
+uint8_t *yptr = frame->data[0] + slice_start * ylinesize;
+const int yv = s->c[0];
+const float mix = s->mix;
+
+for (int y = slice_start; y < slice_end; y++) {
+for (int x = 0; x < width; x++)
+yptr[x] = lerpf(yv, yptr[x], mix);
+
+yptr += ylinesize;
+}
+
+return 0;
+}
+
+static int colorizey_slice16(AVFilterContext *ctx, void *arg, int jobnr, int 
nb_jobs)
+{
+ColorizeContext *s = ctx->priv;
+AVFrame *frame = arg;
+const int width = s->planewidth[0];
+const int height = s->planeheight[0];
+const in

[FFmpeg-devel] [PATCH] libavcodec/gifenc: Only write palette entries that actually used

2021-02-04 Thread Derek Buitenhuis
GIF palette entries are not compressed, and writing 256 entries,
which can be up to every frame, uses a significant amount of
space, especially in extreme cases, where palettes can be very
small.

Example, first six seconds of Tears of Steel, palette generated
with libimagequant, 320x240 resolution, and with transparency
optimization + per frame palette:

* Before patch: 186765 bytes
* After patch: 77901 bytes

Signed-off-by: Derek Buitenhuis 
---
 libavcodec/gif.c | 81 +---
 1 file changed, 69 insertions(+), 12 deletions(-)

diff --git a/libavcodec/gif.c b/libavcodec/gif.c
index de41992851..c52db57edd 100644
--- a/libavcodec/gif.c
+++ b/libavcodec/gif.c
@@ -52,6 +52,7 @@ typedef struct GIFContext {
 int flags;
 int image;
 uint32_t palette[AVPALETTE_COUNT];  ///< local reference palette for !pal8
+size_t palette_count;
 int palette_loaded;
 int transparent_index;
 uint8_t *tmpl;  ///< temporary line buffer
@@ -62,6 +63,27 @@ enum {
 GF_TRANSDIFF  = 1<<1,
 };
 
+static void shrink_palette(const uint32_t *src, uint32_t *dst, size_t 
*palette_count)
+{
+size_t colors_seen = 0;
+
+for (size_t i = 0; i < AVPALETTE_COUNT; i++) {
+int seen = 0;
+for (size_t c = 0; c < colors_seen; c++) {
+if (src[i] == dst[c]) {
+seen = 1;
+break;
+}
+}
+if (!seen) {
+dst[colors_seen] = src[i];
+colors_seen++;
+}
+}
+
+*palette_count = colors_seen;
+}
+
 static int is_image_translucent(AVCodecContext *avctx,
 const uint8_t *buf, const int linesize)
 {
@@ -83,7 +105,7 @@ static int is_image_translucent(AVCodecContext *avctx,
 return 0;
 }
 
-static int get_palette_transparency_index(const uint32_t *palette)
+static int get_palette_transparency_index(const uint32_t *palette, int 
palette_count)
 {
 int transparent_color_index = -1;
 unsigned i, smallest_alpha = 0xff;
@@ -91,7 +113,7 @@ static int get_palette_transparency_index(const uint32_t 
*palette)
 if (!palette)
 return -1;
 
-for (i = 0; i < AVPALETTE_COUNT; i++) {
+for (i = 0; i < palette_count; i++) {
 const uint32_t v = palette[i];
 if (v >> 24 < smallest_alpha) {
 smallest_alpha = v >> 24;
@@ -266,6 +288,10 @@ static int gif_image_write_image(AVCodecContext *avctx,
 int x_start = 0, y_start = 0, trans = s->transparent_index;
 int bcid = -1, honor_transparency = (s->flags & GF_TRANSDIFF) && 
s->last_frame && !palette;
 const uint8_t *ptr;
+uint32_t shrunk_palette[AVPALETTE_COUNT] = { 0 };
+size_t shrunk_palette_count;
+
+memset(shrunk_palette, 0xff, AVPALETTE_SIZE);
 
 if (!s->image && is_image_translucent(avctx, buf, linesize)) {
 gif_crop_translucent(avctx, buf, linesize, &width, &height, &x_start, 
&y_start);
@@ -277,10 +303,21 @@ static int gif_image_write_image(AVCodecContext *avctx,
 }
 
 if (s->image || !avctx->frame_number) { /* GIF header */
-const uint32_t *global_palette = palette ? palette : s->palette;
+uint32_t *global_palette;
+uint32_t shrunk_global_palette[AVPALETTE_COUNT];
+size_t global_palette_count;
+unsigned pow2_global_palette_count;
 const AVRational sar = avctx->sample_aspect_ratio;
 int64_t aspect = 0;
 
+if (palette) {
+shrink_palette(palette, shrunk_global_palette, 
&global_palette_count);
+global_palette = shrunk_global_palette;
+} else {
+global_palette = s->palette;
+global_palette_count = s->palette_count;
+}
+
 if (sar.num > 0 && sar.den > 0) {
 aspect = sar.num * 64LL / sar.den - 15;
 if (aspect < 0 || aspect > 255)
@@ -291,17 +328,22 @@ static int gif_image_write_image(AVCodecContext *avctx,
 bytestream_put_le16(bytestream, avctx->width);
 bytestream_put_le16(bytestream, avctx->height);
 
-bcid = get_palette_transparency_index(global_palette);
+bcid = get_palette_transparency_index(global_palette, 
global_palette_count);
 
-bytestream_put_byte(bytestream, 0xf7); /* flags: global clut, 256 
entries */
+pow2_global_palette_count = av_log2(global_palette_count - 1);
+
+bytestream_put_byte(bytestream, 0xf0 | pow2_global_palette_count); /* 
flags: global clut, 256 entries */
 bytestream_put_byte(bytestream, bcid < 0 ? DEFAULT_TRANSPARENCY_INDEX 
: bcid); /* background color index */
 bytestream_put_byte(bytestream, aspect);
-for (int i = 0; i < 256; i++) {
+for (int i = 0; i < 1 << (pow2_global_palette_count + 1); i++) {
 const uint32_t v = global_palette[i] & 0xff;
 bytestream_put_be24(bytestream, v);
 }
 }
 
+if (palette)
+shrink_palette(palette, shrunk_palette, &shrunk_palette

Re: [FFmpeg-devel] [PATCH] libavcodec/gifenc: Only write palette entries that actually used

2021-02-04 Thread Paul B Mahol
On Thu, Feb 4, 2021 at 5:57 PM Derek Buitenhuis 
wrote:

> GIF palette entries are not compressed, and writing 256 entries,
> which can be up to every frame, uses a significant amount of
> space, especially in extreme cases, where palettes can be very
> small.
>
> Example, first six seconds of Tears of Steel, palette generated
> with libimagequant, 320x240 resolution, and with transparency
> optimization + per frame palette:
>
> * Before patch: 186765 bytes
> * After patch: 77901 bytes
>
> Signed-off-by: Derek Buitenhuis 
> ---
>  libavcodec/gif.c | 81 +---
>  1 file changed, 69 insertions(+), 12 deletions(-)
>
> diff --git a/libavcodec/gif.c b/libavcodec/gif.c
> index de41992851..c52db57edd 100644
> --- a/libavcodec/gif.c
> +++ b/libavcodec/gif.c
> @@ -52,6 +52,7 @@ typedef struct GIFContext {
>  int flags;
>  int image;
>  uint32_t palette[AVPALETTE_COUNT];  ///< local reference palette for
> !pal8
> +size_t palette_count;
>  int palette_loaded;
>  int transparent_index;
>  uint8_t *tmpl;  ///< temporary line buffer
> @@ -62,6 +63,27 @@ enum {
>  GF_TRANSDIFF  = 1<<1,
>  };
>
> +static void shrink_palette(const uint32_t *src, uint32_t *dst, size_t
> *palette_count)
> +{
> +size_t colors_seen = 0;
> +
> +for (size_t i = 0; i < AVPALETTE_COUNT; i++) {
> +int seen = 0;
> +for (size_t c = 0; c < colors_seen; c++) {
> +if (src[i] == dst[c]) {
> +seen = 1;
> +break;
> +}
> +}
> +if (!seen) {
> +dst[colors_seen] = src[i];
> +colors_seen++;
> +}
> +}
> +
> +*palette_count = colors_seen;
> +}
> +
>  static int is_image_translucent(AVCodecContext *avctx,
>  const uint8_t *buf, const int linesize)
>  {
> @@ -83,7 +105,7 @@ static int is_image_translucent(AVCodecContext *avctx,
>  return 0;
>  }
>
> -static int get_palette_transparency_index(const uint32_t *palette)
> +static int get_palette_transparency_index(const uint32_t *palette, int
> palette_count)
>  {
>  int transparent_color_index = -1;
>  unsigned i, smallest_alpha = 0xff;
> @@ -91,7 +113,7 @@ static int get_palette_transparency_index(const
> uint32_t *palette)
>  if (!palette)
>  return -1;
>
> -for (i = 0; i < AVPALETTE_COUNT; i++) {
> +for (i = 0; i < palette_count; i++) {
>  const uint32_t v = palette[i];
>  if (v >> 24 < smallest_alpha) {
>  smallest_alpha = v >> 24;
> @@ -266,6 +288,10 @@ static int gif_image_write_image(AVCodecContext
> *avctx,
>  int x_start = 0, y_start = 0, trans = s->transparent_index;
>  int bcid = -1, honor_transparency = (s->flags & GF_TRANSDIFF) &&
> s->last_frame && !palette;
>  const uint8_t *ptr;
> +uint32_t shrunk_palette[AVPALETTE_COUNT] = { 0 };
> +size_t shrunk_palette_count;
> +
> +memset(shrunk_palette, 0xff, AVPALETTE_SIZE);
>

You first init array to 0 and than use memset?


>
>  if (!s->image && is_image_translucent(avctx, buf, linesize)) {
>  gif_crop_translucent(avctx, buf, linesize, &width, &height,
> &x_start, &y_start);
> @@ -277,10 +303,21 @@ static int gif_image_write_image(AVCodecContext
> *avctx,
>  }
>
>  if (s->image || !avctx->frame_number) { /* GIF header */
> -const uint32_t *global_palette = palette ? palette : s->palette;
> +uint32_t *global_palette;
> +uint32_t shrunk_global_palette[AVPALETTE_COUNT];
> +size_t global_palette_count;
> +unsigned pow2_global_palette_count;
>  const AVRational sar = avctx->sample_aspect_ratio;
>  int64_t aspect = 0;
>
> +if (palette) {
> +shrink_palette(palette, shrunk_global_palette,
> &global_palette_count);
> +global_palette = shrunk_global_palette;
> +} else {
> +global_palette = s->palette;
> +global_palette_count = s->palette_count;
> +}
> +
>  if (sar.num > 0 && sar.den > 0) {
>  aspect = sar.num * 64LL / sar.den - 15;
>  if (aspect < 0 || aspect > 255)
> @@ -291,17 +328,22 @@ static int gif_image_write_image(AVCodecContext
> *avctx,
>  bytestream_put_le16(bytestream, avctx->width);
>  bytestream_put_le16(bytestream, avctx->height);
>
> -bcid = get_palette_transparency_index(global_palette);
> +bcid = get_palette_transparency_index(global_palette,
> global_palette_count);
>
> -bytestream_put_byte(bytestream, 0xf7); /* flags: global clut, 256
> entries */
> +pow2_global_palette_count = av_log2(global_palette_count - 1);
> +
> +bytestream_put_byte(bytestream, 0xf0 |
> pow2_global_palette_count); /* flags: global clut, 256 entries */
>  bytestream_put_byte(bytestream, bcid < 0 ?
> DEFAULT_TRANSPARENCY_INDEX : bcid); /* background color index */
>  bytestream_put_byt

Re: [FFmpeg-devel] [PATCH] libavcodec/gifenc: Only write palette entries that actually used

2021-02-04 Thread Derek Buitenhuis
On 04/02/2021 17:09, Derek Buitenhuis wrote:
> Accidentally left it in, removed it now.
> 
> Further, I forgot to add re-mapping of the frame values
> for the case where the user-provided palette is not
> front-loaded (e.g. it has gaps), so I'll send a v2.

Another case to consider is that we should not shrink the
global palette at all because later frames may reference
indicies not used in the first frame.

That however, loses us compression efficiency for cases
where it doesn't, or where each frame has a its own
palette anyway.

How do we feel about adding an AVOption to force the
use or not-use of a global palette?

- Derek
___
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] libavcodec/gifenc: Only write palette entries that actually used

2021-02-04 Thread Derek Buitenhuis
On 04/02/2021 17:07, Paul B Mahol wrote:
> You first init array to 0 and than use memset?

Accidentally left it in, removed it now.

Further, I forgot to add re-mapping of the frame values
for the case where the user-provided palette is not
front-loaded (e.g. it has gaps), so I'll send a v2.

- Derek
___
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] libavcodec/gifenc: Only write palette entries that actually used

2021-02-04 Thread Paul B Mahol
On Thu, Feb 4, 2021 at 6:15 PM Derek Buitenhuis 
wrote:

> On 04/02/2021 17:09, Derek Buitenhuis wrote:
> > Accidentally left it in, removed it now.
> >
> > Further, I forgot to add re-mapping of the frame values
> > for the case where the user-provided palette is not
> > front-loaded (e.g. it has gaps), so I'll send a v2.
>
> Another case to consider is that we should not shrink the
> global palette at all because later frames may reference
> indicies not used in the first frame.
>
> That however, loses us compression efficiency for cases
> where it doesn't, or where each frame has a its own
> palette anyway.
>
> How do we feel about adding an AVOption to force the
> use or not-use of a global palette?
>

How would that work?
I'm not against if that does not break existing usage.


>
> - Derek
> ___
> 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 v7 1/3] avformat/mxfdec: set toolkit version metadata

2021-02-04 Thread Tomas Härdin
tis 2021-02-02 klockan 20:47 +0800 skrev lance.lmw...@gmail.com:
> From: Limin Wang 
> 
> Please check the string of toolkit version with below command:
> ./ffmpeg -i ../fate-suite/mxf/Sony-1.mxf -c:v copy -c:a copy out.mxf
> ./ffmpeg -i out.mxf
> 
> toolkit_version : 58.65.101.0.0
> 
> Reviewed-by: Tomas Härdin 
> Signed-off-by: Limin Wang 
> ---
>  libavformat/mxfdec.c| 24 
>  tests/ref/fate/mxf-probe-applehdr10 |  1 +
>  tests/ref/fate/mxf-probe-dnxhd  |  1 +
>  3 files changed, 26 insertions(+)
> 
> diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
> index 93fa7a9..18db056 100644
> --- a/libavformat/mxfdec.c
> +++ b/libavformat/mxfdec.c
> @@ -1978,6 +1978,15 @@ static int mxf_umid_to_str(UID ul, UID uid, char **str)
>  return 0;
>  }
>  
> +static int mxf_version_to_str(uint16_t major, uint16_t minor, uint16_t 
> tertiary,
> +  uint16_t patch, uint16_t release, char **str)
> +{
> +*str = av_asprintf("%d.%d.%d.%d.%d", major, minor, tertiary, patch, 
> release);
> +if (!*str)
> +return AVERROR(ENOMEM);
> +return 0;
> +}
> +
>  static int mxf_add_umid_metadata(AVDictionary **pm, const char *key, 
> MXFPackage* package)
>  {
>  char *str;
> @@ -2739,6 +2748,17 @@ static int64_t mxf_timestamp_to_int64(uint64_t 
> timestamp)
>  av_dict_set(&s->metadata, name, str, AV_DICT_DONT_STRDUP_VAL); \
>  } while (0)
>  
> +#define SET_VERSION_METADATA(pb, name, major, minor, tertiary, patch, 
> release, str) do { \
> +major = avio_rb16(pb); \
> +minor = avio_rb16(pb); \
> +tertiary = avio_rb16(pb); \
> +patch = avio_rb16(pb); \
> +release = avio_rb16(pb); \
> +if ((ret = mxf_version_to_str(major, minor, tertiary, patch, release, 
> &str)) < 0) \
> +return ret; \
> +av_dict_set(&s->metadata, name, str, AV_DICT_DONT_STRDUP_VAL); \
> +} while (0)

Looks OK

/Tomas

___
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 v7 2/3] avformat/mxf: add platform local tag

2021-02-04 Thread Tomas Härdin
tis 2021-02-02 klockan 20:47 +0800 skrev lance.lmw...@gmail.com:
> From: Limin Wang 
> 
> Please check the string of platform with below command:
> ./ffmpeg -i ../fate-suite/mxf/Sony-1.mxf -c:v copy -c:a copy out.mxf
> ./ffmpeg -i out.mxf
> 
> application_platform: Lavf (linux)
> 
> Reviewed-by: Tomas Härdin 
> Signed-off-by: Limin Wang 
> ---
>  configure   | 1 +
>  libavformat/mxfenc.c| 4 
>  tests/ref/fate/copy-trac4914| 2 +-
>  tests/ref/fate/mxf-d10-user-comments| 2 +-
>  tests/ref/fate/mxf-opatom-user-comments | 2 +-
>  tests/ref/fate/mxf-reel_name| 2 +-
>  tests/ref/fate/mxf-user-comments| 2 +-
>  tests/ref/fate/time_base| 2 +-
>  tests/ref/lavf/mxf  | 6 +++---
>  tests/ref/lavf/mxf_d10  | 2 +-
>  tests/ref/lavf/mxf_dv25 | 2 +-
>  tests/ref/lavf/mxf_dvcpro50 | 2 +-
>  tests/ref/lavf/mxf_opatom   | 2 +-
>  tests/ref/lavf/mxf_opatom_audio | 2 +-
>  14 files changed, 19 insertions(+), 14 deletions(-)
> 
> diff --git a/configure b/configure
> index df298b4..a092a6b 100755
> --- a/configure
> +++ b/configure
> @@ -7579,6 +7579,7 @@ cat > $TMPH <  #define FFMPEG_DATADIR "$(eval c_escape $datadir)"
>  #define AVCONV_DATADIR "$(eval c_escape $datadir)"
>  #define CC_IDENT "$(c_escape ${cc_ident:-Unknown compiler})"
> +#define OS_NAME $target_os
>  #define av_restrict $restrict_keyword
>  #define EXTERN_PREFIX "${extern_prefix}"
>  #define EXTERN_ASM ${extern_prefix}
> diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
> index b0cfa87..39ab443 100644
> --- a/libavformat/mxfenc.c
> +++ b/libavformat/mxfenc.c
> @@ -752,12 +752,14 @@ static void store_version(AVFormatContext *s){
>  avio_wb16(pb, 0); // release
>  }
>  
> +#define PLATFROM_IDENT "Lavf " AV_STRINGIFY((OS_NAME))
>  static void mxf_write_identification(AVFormatContext *s)
>  {
>  MXFContext *mxf = s->priv_data;
>  AVIOContext *pb = s->pb;
>  const char *company = "FFmpeg";
>  const char *product = s->oformat != &ff_mxf_opatom_muxer ? "OP1a Muxer" 
> : "OPAtom Muxer";
> +const char *platform = s->flags & AVFMT_FLAG_BITEXACT ? "Lavf" : 
> PLATFROM_IDENT;
>  const char *version;
>  int length;
>  
> @@ -768,6 +770,7 @@ static void mxf_write_identification(AVFormatContext *s)
>  "0.0.0" : AV_STRINGIFY(LIBAVFORMAT_VERSION);
>  length = 100 +mxf_utf16_local_tag_length(company) +
>mxf_utf16_local_tag_length(product) +
> +  mxf_utf16_local_tag_length(platform) +
>mxf_utf16_local_tag_length(version);
>  klv_encode_ber_length(pb, length);
>  
> @@ -786,6 +789,7 @@ static void mxf_write_identification(AVFormatContext *s)
>  store_version(s);
>  
>  mxf_write_local_tag_utf16(s, 0x3C04, version); // Version String
> +mxf_write_local_tag_utf16(s, 0x3C08, platform); // Platform

I was going to say this is missing ToolkitVersion, but I see
store_version() writes that. So this looks OK.

/Tomas

___
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 v7 3/3] avformat/mxfenc: prefer to use the configured metadata

2021-02-04 Thread Tomas Härdin
tis 2021-02-02 klockan 20:47 +0800 skrev lance.lmw...@gmail.com:
> From: Limin Wang 
> 
> The metadata company_name, product_name, product_version from input
> file will be deleted to avoid overwriting information
> Please to test with below commands:
> ./ffmpeg -i ../fate-suite/mxf/Sony-1.mxf -c:v copy -c:a copy out.mxf
> and
> ./ffmpeg -i ../fate-suite/mxf/Sony-1.mxf -c:v copy -c:a copy \
> -metadata company_name="xxx" \
> -metadata product_name="xxx" \
> -metadata product_version="xxx" \
> out.mxf
> 
> Reviewed-by: Tomas Härdin 
> Signed-off-by: Limin Wang 
> ---
>  fftools/ffmpeg_opt.c |  3 +++
>  libavformat/mxfenc.c | 10 +++---
>  2 files changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
> index bf2eb26..07308cc 100644
> --- a/fftools/ffmpeg_opt.c
> +++ b/fftools/ffmpeg_opt.c
> @@ -2641,6 +2641,9 @@ loop_end:
>  if(o->recording_time != INT64_MAX)
>  av_dict_set(&oc->metadata, "duration", NULL, 0);
>  av_dict_set(&oc->metadata, "creation_time", NULL, 0);
> +av_dict_set(&oc->metadata, "company_name", NULL, 0);
> +av_dict_set(&oc->metadata, "product_name", NULL, 0);
> +av_dict_set(&oc->metadata, "product_version", NULL, 0);
>  }
>  if (!o->metadata_streams_manual)
>  for (i = of->ost_index; i < nb_output_streams; i++) {
> diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
> index 39ab443..0b39917 100644
> --- a/libavformat/mxfenc.c
> +++ b/libavformat/mxfenc.c
> @@ -757,8 +757,12 @@ static void mxf_write_identification(AVFormatContext *s)
>  {
>  MXFContext *mxf = s->priv_data;
>  AVIOContext *pb = s->pb;
> -const char *company = "FFmpeg";
> -const char *product = s->oformat != &ff_mxf_opatom_muxer ? "OP1a Muxer" 
> : "OPAtom Muxer";
> +AVDictionaryEntry *com_entry = av_dict_get(s->metadata, "company_name", 
> NULL, 0);
> +AVDictionaryEntry *product_entry = av_dict_get(s->metadata, 
> "product_name", NULL, 0);
> +AVDictionaryEntry *version_entry = av_dict_get(s->metadata, 
> "product_version", NULL, 0);
> +const char *company = com_entry ? com_entry->value : "FFmpeg";
> +const char *product = product_entry ? product_entry->value : s->oformat 
> != &ff_mxf_opatom_muxer ? "OP1a Muxer" : "OPAtom Muxer";
> +const char *product_version = version_entry ? version_entry->value : 
> AV_STRINGIFY(LIBAVFORMAT_VERSION);
>  const char *platform = s->flags & AVFMT_FLAG_BITEXACT ? "Lavf" : 
> PLATFROM_IDENT;
>  const char *version;
>  int length;
> @@ -767,7 +771,7 @@ static void mxf_write_identification(AVFormatContext *s)
>  PRINT_KEY(s, "identification key", pb->buf_ptr - 16);
>  
>  version = s->flags & AVFMT_FLAG_BITEXACT ?
> -"0.0.0" : AV_STRINGIFY(LIBAVFORMAT_VERSION);
> +"0.0.0" : product_version;

Looks OK

/Tomas

___
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] libavcodec/gifenc: Only write palette entries that actually used

2021-02-04 Thread Derek Buitenhuis
On 04/02/2021 17:26, Paul B Mahol wrote:
> How would that work?
> I'm not against if that does not break existing usage.

Somethng like '-no_global_paltte 1' to not use a global
palette, and write a palette each frame. Default would be
off, so curent behavior is maintained.

- Derek
___
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 4/8] avformat/mxfdec: Fix file position addition

2021-02-04 Thread Tomas Härdin
mån 2021-02-01 klockan 23:31 +0100 skrev Michael Niedermayer:
> Not sure this is the best solution, maybe a more general solution
> limiting the avio_tell() output to less than 63bit would be a better
> option

Probably, since this is likely to happen in more places

> Fixes: signed integer overflow: 9223372036854775805 + 4 cannot be represented 
> in type 'long'
> Fixes: 
> 29927/clusterfuzz-testcase-minimized-ffmpeg_dem_MXF_fuzzer-5579985228267520
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/mxfdec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
> index afff20402d..97a1b749fe 100644
> --- a/libavformat/mxfdec.c
> +++ b/libavformat/mxfdec.c
> @@ -2861,7 +2861,7 @@ static int mxf_read_local_tags(MXFContext *mxf, 
> KLVPacket *klv, MXFMetadataReadF
>  return AVERROR(ENOMEM);
>  if (ctx_size)
>  mxf_metadataset_init(ctx, type);
> -while (avio_tell(pb) + 4 < klv_end && !avio_feof(pb)) {
> +while (avio_tell(pb) + (uint64_t)4 < klv_end && !avio_feof(pb)) {

Why not cast avio_tell() instead?

/Tomas

___
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 00/50 v2] deprecate av_init_packet() and sizeof(AVPacket) as part of the ABI

2021-02-04 Thread James Almer
As the subject says, this puts AVPacket in line with AVFrame, allowing
easier extensibility of the struct, and preventing some corner cases when
packets are used uninitialized on stack. Compared to V1, i included the entire
set here, plus a few changes to ffplay and avformat/utils.

This removes all av_init_packet() instances in the tree, and all uses of
AVPacket on stack i could find. It's not exhaustive, as i probably missed a
few, but they can be removed any time between the deprecation of public
sizeof(AVPacket) and it's removal 2+ years from now.
Then there's the few cases where an AVPacket is part of another public struct,
as is the case of AVPacketList, or attached_pic in AVSteam. The latter i could
adapt right now, but it would mean a lot of preprocessor checks littering the
codebase until removed, so i refrained from doing so.

FATE passes, but a few of these patches are untested as FATE doesn't cover
some of these modules.

James Almer (50):
  avcodec/packet: deprecate av_init_packet()
  avcodec/cri: use av_packet_alloc() to allocate packets
  avcodec/frame_thread_encoder: remove av_init_packet() call
  avcodec/mmal: use av_packet_alloc() to allocate packets
  avcodec/libxvid: use av_packet_alloc() to allocate packets
  avcodec/mpegvideo_enc: use av_packet_alloc() to allocate packets
  avcodec/pthread_frame: use av_packet_alloc() to allocate packets
  avcodec/tdsc: use av_packet_alloc() to allocate packets
  avcodec/tiff: use av_packet_alloc() to allocate AVPackets
  avcodec/webp: use av_packet_alloc() to allocate packets
  avcodec/tests/avpacket: use av_packet_alloc() to allocate packets
  avformat/amvenc: use av_packet_alloc() to allocate packets
  avformat/asfdec_o: use av_packet_alloc() to allocate packets
  avformat/avidec: use av_packet_alloc() to allocate packets
  avformat/avienc: use av_packet_alloc() to allocate packets
  avformat/dv: use av_packet_alloc() to allocate packets
  avformat/flac_picture: replace call to av_init_packet()
  avformat/id3v2: replace call to av_init_packet()
  avformat/flacdec: use av_packet_alloc() to allocate packets
  avformat/hls: use av_packet_alloc() to allocate packets
  avformat/matroskadec: use av_packet_alloc() to allocate packets
  avformat/matroskaenc: use av_packet_alloc() to allocate packets
  avformat/mux: use av_packet_alloc() to allocate packets
  avformat/movenc: use av_packet_alloc() to allocate packets
  avformat/mpegts: use av_packet_alloc() to allocate packets
  avformat/mpegtsenc: use av_packet_alloc() to allocate packets
  avformat/rtpdec: use av_packet_alloc() to allocate packets
  avformat/rtpenc_mpegts: use av_packet_alloc() to allocate packets
  avformat/utils: use av_packet_alloc() to allocate packets
  avformat/subtitles: use av_packet_alloc() to allocate packets
  avformat/wc3movie: use av_packet_alloc() to allocate packets
  avformat/tests/fifo_muxer: use av_packet_alloc() to allocate packets
  avformat/tests/movenc: use av_packet_alloc() to allocate packets
  avdevice/decklink_dec: stop using av_init_packet()
  avdevice/xcbgrab: stop using av_init_packet()
  avfilter/vf_mcdeint: use av_packet_alloc() to allocate packets
  avfilter/vf_uspp: use av_packet_alloc() to allocate packets
  tools/pktdumper: use av_packet_alloc() to allocate packets
  tools/target_dec_fuzzer: use av_packet_alloc() to allocate packets
  tools/target_dem_fuzzer: use av_packet_alloc() to allocate packets
  tools/target_bsf_fuzzer: use av_packet_alloc() to allocate packets
  tests/api/api-flac-test: use av_packet_alloc() to allocate packets
  doc/examples/demuxing_decoding: use av_packet_alloc() to allocate
packets
  doc/examples/transcode_aac: use av_packet_alloc() to allocate packets
  doc/examples/transcoding: use av_packet_alloc() to allocate packets
  doc/examples/vaapi_encode: use av_packet_alloc() to allocate packets
  doc/examples/vaapi_transcode: use av_packet_alloc() to allocate
packets
  fftools/ffprobe: use av_packet_alloc() to allocate packets
  fftools/ffmpeg: use av_packet_alloc() to allocate packets
  fftools/ffplay: use av_packet_alloc() to allocate packets

 doc/examples/demuxing_decoding.c  |  25 +--
 doc/examples/transcode_aac.c  |  46 +++--
 doc/examples/transcoding.c|  48 +++--
 doc/examples/vaapi_encode.c   |  16 +-
 doc/examples/vaapi_transcode.c|  45 +++--
 fftools/ffmpeg.c  | 318 --
 fftools/ffmpeg.h  |   4 +
 fftools/ffmpeg_opt.c  |   5 +-
 fftools/ffplay.c  | 204 +++
 fftools/ffprobe.c |  34 ++--
 libavcodec/avpacket.c |  23 ++-
 libavcodec/cri.c  |  16 +-
 libavcodec/frame_thread_encoder.c |   3 +-
 libavcodec/libxvid.c  |  13 +-
 libavcodec/mmaldec.c  |  15 +-
 libavcodec/mpegvideo_enc.c|  23 ++-
 libavcodec/packet.h   |  23 ++-
 libavcodec/pthread_frame.c|  20 +-
 libavcodec/tdsc.c |  14 +

[FFmpeg-devel] [PATCH 02/50] avcodec/cri: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/cri.c | 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/libavcodec/cri.c b/libavcodec/cri.c
index efbccf4fee..8aadab7703 100644
--- a/libavcodec/cri.c
+++ b/libavcodec/cri.c
@@ -37,6 +37,7 @@
 
 typedef struct CRIContext {
 AVCodecContext *jpeg_avctx;   // wrapper context for MJPEG
+AVPacket *jpkt;   // encoded JPEG tile
 AVFrame *jpgframe;// decoded JPEG tile
 
 GetByteContext gb;
@@ -56,6 +57,10 @@ static av_cold int cri_decode_init(AVCodecContext *avctx)
 if (!s->jpgframe)
 return AVERROR(ENOMEM);
 
+s->jpkt = av_packet_alloc();
+if (!s->jpkt)
+return AVERROR(ENOMEM);
+
 codec = avcodec_find_decoder(AV_CODEC_ID_MJPEG);
 if (!codec)
 return AVERROR_BUG;
@@ -342,13 +347,11 @@ skip:
 unsigned offset = 0;
 
 for (int tile = 0; tile < 4; tile++) {
-AVPacket jpkt;
-
-av_init_packet(&jpkt);
-jpkt.data = (uint8_t *)s->data + offset;
-jpkt.size = s->tile_size[tile];
+av_packet_unref(s->jpkt);
+s->jpkt->data = (uint8_t *)s->data + offset;
+s->jpkt->size = s->tile_size[tile];
 
-ret = avcodec_send_packet(s->jpeg_avctx, &jpkt);
+ret = avcodec_send_packet(s->jpeg_avctx, s->jpkt);
 if (ret < 0) {
 av_log(avctx, AV_LOG_ERROR, "Error submitting a packet for 
decoding\n");
 return ret;
@@ -412,6 +415,7 @@ static av_cold int cri_decode_close(AVCodecContext *avctx)
 CRIContext *s = avctx->priv_data;
 
 av_frame_free(&s->jpgframe);
+av_packet_free(&s->jpkt);
 avcodec_free_context(&s->jpeg_avctx);
 
 return 0;
-- 
2.30.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".

[FFmpeg-devel] [PATCH 03/50] avcodec/frame_thread_encoder: remove av_init_packet() call

2021-02-04 Thread James Almer
The packet was allocated with av_packet_alloc(), so it's redundant.

Signed-off-by: James Almer 
---
 libavcodec/frame_thread_encoder.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavcodec/frame_thread_encoder.c 
b/libavcodec/frame_thread_encoder.c
index 83229f620a..9ae9d72934 100644
--- a/libavcodec/frame_thread_encoder.c
+++ b/libavcodec/frame_thread_encoder.c
@@ -72,7 +72,6 @@ static void * attribute_align_arg worker(void *v){
 
 if(!pkt) pkt = av_packet_alloc();
 if(!pkt) continue;
-av_init_packet(pkt);
 
 pthread_mutex_lock(&c->task_fifo_mutex);
 while (av_fifo_size(c->task_fifo) <= 0 || atomic_load(&c->exit)) {
@@ -107,7 +106,7 @@ static void * attribute_align_arg worker(void *v){
 pthread_mutex_unlock(&c->finished_task_mutex);
 }
 end:
-av_free(pkt);
+av_packet_free(&pkt);
 pthread_mutex_lock(&c->buffer_mutex);
 avcodec_close(avctx);
 pthread_mutex_unlock(&c->buffer_mutex);
-- 
2.30.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".

[FFmpeg-devel] [PATCH 04/50] avcodec/mmal: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/mmaldec.c | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/libavcodec/mmaldec.c b/libavcodec/mmaldec.c
index cb15ac072a..ed51d74de5 100644
--- a/libavcodec/mmaldec.c
+++ b/libavcodec/mmaldec.c
@@ -776,12 +776,17 @@ static int ffmmal_decode(AVCodecContext *avctx, void 
*data, int *got_frame,
 int ret = 0;
 
 if (avctx->extradata_size && !ctx->extradata_sent) {
-AVPacket pkt = {0};
-av_init_packet(&pkt);
-pkt.data = avctx->extradata;
-pkt.size = avctx->extradata_size;
+AVPacket *pkt;
+
+pkt = av_packet_alloc();
+if (!pkt)
+return AVERROR(ENOMEM);
+pkt->data = avctx->extradata;
+pkt->size = avctx->extradata_size;
 ctx->extradata_sent = 1;
-if ((ret = ffmmal_add_packet(avctx, &pkt, 1)) < 0)
+ret = ffmmal_add_packet(avctx, pkt, 1);
+av_packet_free(&pkt);
+if (ret < 0)
 return ret;
 }
 
-- 
2.30.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".

[FFmpeg-devel] [PATCH 11/50] avcodec/tests/avpacket: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/tests/avpacket.c | 19 ---
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/libavcodec/tests/avpacket.c b/libavcodec/tests/avpacket.c
index 90b72341f4..7a70ade4c3 100644
--- a/libavcodec/tests/avpacket.c
+++ b/libavcodec/tests/avpacket.c
@@ -63,9 +63,6 @@ static int initializations(AVPacket* avpkt)
 const static uint8_t* data = "selftest for av_packet_clone(...)";
 int ret = 0;
 
-/* initialize avpkt */
-av_init_packet(avpkt);
-
 /* set values for avpkt */
 avpkt->pts = 17;
 avpkt->dts = 2;
@@ -82,16 +79,24 @@ static int initializations(AVPacket* avpkt)
 
 int main(void)
 {
-AVPacket avpkt;
+AVPacket *avpkt = NULL;
 AVPacket *avpkt_clone = NULL;
 int ret = 0;
 
-if(initializations(&avpkt) < 0){
+/* test av_packet_alloc */
+avpkt = av_packet_alloc();
+if(!avpkt) {
+av_log(NULL, AV_LOG_ERROR, "av_packet_alloc failed to allcoate 
AVPacket\n");
+return 1;
+}
+
+if (initializations(avpkt) < 0) {
 printf("failed to initialize variables\n");
+av_packet_free(&avpkt);
 return 1;
 }
 /* test av_packet_clone*/
-avpkt_clone = av_packet_clone(&avpkt);
+avpkt_clone = av_packet_clone(avpkt);
 
 if(!avpkt_clone) {
 av_log(NULL, AV_LOG_ERROR,"av_packet_clone failed to clone 
AVPacket\n");
@@ -121,7 +126,7 @@ int main(void)
 }
 /*clean up*/
 av_packet_free(&avpkt_clone);
-av_packet_unref(&avpkt);
+av_packet_free(&avpkt);
 
 
 return ret;
-- 
2.30.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".

[FFmpeg-devel] [PATCH 09/50] avcodec/tiff: use av_packet_alloc() to allocate AVPackets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/tiff.c | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index f68f9818ad..c92c4170ab 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -58,6 +58,7 @@ typedef struct TiffContext {
 
 /* JPEG decoding for DNG */
 AVCodecContext *avctx_mjpeg; // wrapper context for MJPEG
+AVPacket *jpkt;  // encoded JPEG tile
 AVFrame *jpgframe;   // decoded JPEG tile
 
 int get_subimage;
@@ -877,7 +878,6 @@ static int dng_decode_jpeg(AVCodecContext *avctx, AVFrame 
*frame,
int tile_byte_count, int dst_x, int dst_y, int w, 
int h)
 {
 TiffContext *s = avctx->priv_data;
-AVPacket jpkt;
 uint8_t *dst_data, *src_data;
 uint32_t dst_offset; /* offset from dst buffer in pixels */
 int is_single_comp, is_u16, pixel_size;
@@ -887,9 +887,9 @@ static int dng_decode_jpeg(AVCodecContext *avctx, AVFrame 
*frame,
 return AVERROR_INVALIDDATA;
 
 /* Prepare a packet and send to the MJPEG decoder */
-av_init_packet(&jpkt);
-jpkt.data = (uint8_t*)s->gb.buffer;
-jpkt.size = tile_byte_count;
+av_packet_unref(s->jpkt);
+s->jpkt->data = (uint8_t*)s->gb.buffer;
+s->jpkt->size = tile_byte_count;
 
 if (s->is_bayer) {
 MJpegDecodeContext *mjpegdecctx = s->avctx_mjpeg->priv_data;
@@ -898,7 +898,7 @@ static int dng_decode_jpeg(AVCodecContext *avctx, AVFrame 
*frame,
 mjpegdecctx->bayer = 1;
 }
 
-ret = avcodec_send_packet(s->avctx_mjpeg, &jpkt);
+ret = avcodec_send_packet(s->avctx_mjpeg, s->jpkt);
 if (ret < 0) {
 av_log(avctx, AV_LOG_ERROR, "Error submitting a packet for 
decoding\n");
 return ret;
@@ -2157,7 +2157,8 @@ static av_cold int tiff_init(AVCodecContext *avctx)
 
 /* Allocate JPEG frame */
 s->jpgframe = av_frame_alloc();
-if (!s->jpgframe)
+s->jpkt = av_packet_alloc();
+if (!s->jpgframe || !s->jpkt)
 return AVERROR(ENOMEM);
 
 /* Prepare everything needed for JPEG decoding */
@@ -2193,6 +2194,7 @@ static av_cold int tiff_end(AVCodecContext *avctx)
 av_freep(&s->fax_buffer);
 s->fax_buffer_size = 0;
 av_frame_free(&s->jpgframe);
+av_packet_free(&s->jpkt);
 avcodec_free_context(&s->avctx_mjpeg);
 return 0;
 }
-- 
2.30.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".

[FFmpeg-devel] [PATCH 12/50] avformat/amvenc: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/amvenc.c | 41 +
 1 file changed, 25 insertions(+), 16 deletions(-)

diff --git a/libavformat/amvenc.c b/libavformat/amvenc.c
index 4d4ec7a2b1..5d13b618f4 100644
--- a/libavformat/amvenc.c
+++ b/libavformat/amvenc.c
@@ -62,8 +62,8 @@ typedef struct AMVContext
 
 int32_t aframe_size;  /* Expected audio frame size.  */
 int32_t ablock_align; /* Expected audio block align. */
-AVPacket apad;/* Dummy audio packet for padding. */
-AVPacket vpad;/* Most recent video frame, for padding. */
+AVPacket *apad;   /* Dummy audio packet for padding. */
+AVPacket *vpad;   /* Most recent video frame, for padding. */
 
 /*
  * Cumulative PTS values for each stream, used for the final
@@ -183,16 +183,25 @@ static av_cold int amv_init(AVFormatContext *s)
 }
 
 /* Allocate and fill dummy packet so we can pad the audio. */
-if ((ret = av_new_packet(&amv->apad, amv->ablock_align)) < 0)
+amv->apad = av_packet_alloc();
+if (!amv->apad)
+return AVERROR(ENOMEM);
+if ((ret = av_new_packet(amv->apad, amv->ablock_align)) < 0) {
+av_packet_free(&amv->apad);
 return ret;
+}
 
-amv->apad.stream_index = AMV_STREAM_AUDIO;
-memset(amv->apad.data, 0, amv->ablock_align);
-AV_WL32(amv->apad.data + 4, amv->aframe_size);
+amv->apad->stream_index = AMV_STREAM_AUDIO;
+memset(amv->apad->data, 0, amv->ablock_align);
+AV_WL32(amv->apad->data + 4, amv->aframe_size);
 
-av_init_packet(&amv->vpad);
-amv->vpad.stream_index = AMV_STREAM_VIDEO;
-amv->vpad.duration = 1;
+amv->vpad = av_packet_alloc();
+if (!amv->vpad) {
+av_packet_free(&amv->apad);
+return AVERROR(ENOMEM);
+}
+amv->vpad->stream_index = AMV_STREAM_VIDEO;
+amv->vpad->duration = 1;
 return 0;
 }
 
@@ -200,8 +209,8 @@ static void amv_deinit(AVFormatContext *s)
 {
 AMVContext *amv = s->priv_data;
 
-av_packet_unref(&amv->apad);
-av_packet_unref(&amv->vpad);
+av_packet_free(&amv->apad);
+av_packet_free(&amv->vpad);
 }
 
 static void amv_write_vlist(AVFormatContext *s, AVCodecParameters *par)
@@ -325,9 +334,9 @@ static int amv_pad(AVFormatContext *s, AVPacket *pkt)
 
 stream_index = (stream_index + 1) % s->nb_streams;
 if (stream_index == AMV_STREAM_VIDEO)
-return amv_write_packet_internal(s, &amv->vpad);
+return amv_write_packet_internal(s, amv->vpad);
 else if (stream_index == AMV_STREAM_AUDIO)
-return amv_write_packet_internal(s, &amv->apad);
+return amv_write_packet_internal(s, amv->apad);
 else
 av_assert0(0);
 
@@ -348,8 +357,8 @@ static int amv_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 
 if (pkt->stream_index == AMV_STREAM_VIDEO) {
 /* Save the last packet for padding. */
-av_packet_unref(&amv->vpad);
-if ((ret = av_packet_ref(&amv->vpad, pkt)) < 0)
+av_packet_unref(amv->vpad);
+if ((ret = av_packet_ref(amv->vpad, pkt)) < 0)
 return ret;
 }
 
@@ -366,7 +375,7 @@ static int amv_write_trailer(AVFormatContext *s)
 
 /* Pad-out one last audio frame if needed. */
 if (amv->last_stream == AMV_STREAM_VIDEO) {
-if ((ret = amv_write_packet_internal(s, &amv->apad)) < 0)
+if ((ret = amv_write_packet_internal(s, amv->apad)) < 0)
 return ret;
 }
 
-- 
2.30.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".

[FFmpeg-devel] [PATCH 13/50] avformat/asfdec_o: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/asfdec_o.c | 63 --
 1 file changed, 36 insertions(+), 27 deletions(-)

diff --git a/libavformat/asfdec_o.c b/libavformat/asfdec_o.c
index c1d90360b4..34ae541934 100644
--- a/libavformat/asfdec_o.c
+++ b/libavformat/asfdec_o.c
@@ -63,7 +63,7 @@ typedef struct GUIDParseTable {
 } GUIDParseTable;
 
 typedef struct ASFPacket {
-AVPacket avpkt;
+AVPacket *avpkt;
 int64_t dts;
 uint32_t frame_num; // ASF payloads with the same number are parts of the 
same frame
 int flags;
@@ -781,8 +781,10 @@ static int asf_read_stream_properties(AVFormatContext *s, 
const GUIDParseTable *
 asf_st->index= st->index;
 asf_st->indexed  = 0;
 st->id   = flags & ASF_STREAM_NUM;
-av_init_packet(&asf_st->pkt.avpkt);
 asf_st->pkt.data_size= 0;
+asf_st->pkt.avpkt = av_packet_alloc();
+if (!asf_st->pkt.avpkt)
+return AVERROR(ENOMEM);
 avio_skip(pb, 4); // skip reserved field
 
 switch (type) {
@@ -1140,7 +1142,7 @@ static void reset_packet(ASFPacket *asf_pkt)
 asf_pkt->duration  = 0;
 asf_pkt->flags = 0;
 asf_pkt->dts   = 0;
-av_packet_unref(&asf_pkt->avpkt);
+av_packet_unref(asf_pkt->avpkt);
 }
 
 static int asf_read_replicated_data(AVFormatContext *s, ASFPacket *asf_pkt)
@@ -1153,7 +1155,7 @@ static int asf_read_replicated_data(AVFormatContext *s, 
ASFPacket *asf_pkt)
 data_size = avio_rl32(pb); // read media object size
 if (data_size <= 0)
 return AVERROR_INVALIDDATA;
-if ((ret = av_new_packet(&asf_pkt->avpkt, data_size)) < 0)
+if ((ret = av_new_packet(asf_pkt->avpkt, data_size)) < 0)
 return ret;
 asf_pkt->data_size = asf_pkt->size_left = data_size;
 } else
@@ -1194,7 +1196,7 @@ static int asf_read_multiple_payload(AVFormatContext *s, 
AVPacket *pkt,
pay_len, asf->packet_size, avio_tell(pb));
 return AVERROR_INVALIDDATA;
 }
-p = asf_pkt->avpkt.data + asf_pkt->data_size - asf_pkt->size_left;
+p = asf_pkt->avpkt->data + asf_pkt->data_size - asf_pkt->size_left;
 if (pay_len > asf_pkt->size_left) {
 av_log(s, AV_LOG_ERROR,
"Error: invalid buffer size, pay_len %d, data size left 
%d.\n",
@@ -1229,7 +1231,7 @@ static int asf_read_single_payload(AVFormatContext *s, 
ASFPacket *asf_pkt)
 data_size = avio_rl32(pb); // read media object size
 if (data_size <= 0)
 return AVERROR_EOF;
-if ((ret = av_new_packet(&asf_pkt->avpkt, data_size)) < 0)
+if ((ret = av_new_packet(asf_pkt->avpkt, data_size)) < 0)
 return ret;
 asf_pkt->data_size = asf_pkt->size_left = data_size;
 } else
@@ -1250,7 +1252,7 @@ static int asf_read_single_payload(AVFormatContext *s, 
ASFPacket *asf_pkt)
avio_tell(pb));
 return AVERROR_INVALIDDATA;
 }
-p = asf_pkt->avpkt.data + asf_pkt->data_size - asf_pkt->size_left;
+p = asf_pkt->avpkt->data + asf_pkt->data_size - asf_pkt->size_left;
 if (size > asf_pkt->size_left || asf_pkt->size_left <= 0)
 return AVERROR_INVALIDDATA;
 if (asf_pkt->size_left > size)
@@ -1387,16 +1389,18 @@ static int asf_deinterleave(AVFormatContext *s, 
ASFPacket *asf_pkt, int st_num)
 {
 ASFContext *asf= s->priv_data;
 ASFStream *asf_st  = asf->asf_st[st_num];
-unsigned char *p   = asf_pkt->avpkt.data;
+unsigned char *p   = asf_pkt->avpkt->data;
 uint16_t pkt_len   = asf->asf_st[st_num]->virtual_pkt_len;
 uint16_t chunk_len = asf->asf_st[st_num]->virtual_chunk_len;
 int nchunks= pkt_len / chunk_len;
-AVPacket pkt;
+uint8_t *data;
 int pos = 0, j, l, ret;
 
 
-if ((ret = av_new_packet(&pkt, asf_pkt->data_size)) < 0)
-return ret;
+data = av_malloc(asf_pkt->data_size + AV_INPUT_BUFFER_PADDING_SIZE);
+if (!data)
+return AVERROR(ENOMEM);
+memset(data + asf_pkt->data_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
 
 while (asf_pkt->data_size >= asf_st->span * pkt_len + pos) {
 if (pos >= asf_pkt->data_size) {
@@ -1409,20 +1413,22 @@ static int asf_deinterleave(AVFormatContext *s, 
ASFPacket *asf_pkt, int st_num)
 for (j = 0; j < asf_st->span; j++) {
 if ((pos + chunk_len) >= asf_pkt->data_size)
 break;
-memcpy(pkt.data + pos,
+memcpy(data + pos,
p + (j * nchunks + l) * chunk_len,
chunk_len);
 pos += chunk_len;
 }
 }
 p += asf_st->span * pkt_len;
-if (p > asf_pkt->avpkt.data + asf_pkt->data_size)
+if (p > asf_pkt->avpkt->data + asf_pkt->data_size)
 break;
 }
-av_packet_unref(&asf_pkt->avpkt);
-asf_pkt->avpkt = pkt;
+av_packet_unref(asf_pkt->avpkt);
+

[FFmpeg-devel] [PATCH 14/50] avformat/avidec: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/avidec.c | 24 ++--
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index 79000f3e81..0dd447aa7f 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -59,7 +59,7 @@ typedef struct AVIStream {
  * the MS dshow demuxer */
 
 AVFormatContext *sub_ctx;
-AVPacket sub_pkt;
+AVPacket *sub_pkt;
 AVBufferRef *sub_buffer;
 
 int64_t seek_pos;
@@ -1124,6 +1124,9 @@ static int read_gab2_sub(AVFormatContext *s, AVStream 
*st, AVPacket *pkt)
 if (strcmp(sub_demuxer->name, "srt") && strcmp(sub_demuxer->name, 
"ass"))
 goto error;
 
+if (!(ast->sub_pkt = av_packet_alloc()))
+goto error;
+
 if (!(ast->sub_ctx = avformat_alloc_context()))
 goto error;
 
@@ -1135,7 +1138,7 @@ static int read_gab2_sub(AVFormatContext *s, AVStream 
*st, AVPacket *pkt)
 if (!avformat_open_input(&ast->sub_ctx, "", sub_demuxer, NULL)) {
 if (ast->sub_ctx->nb_streams != 1)
 goto error;
-ff_read_packet(ast->sub_ctx, &ast->sub_pkt);
+ff_read_packet(ast->sub_ctx, ast->sub_pkt);
 avcodec_parameters_copy(st->codecpar, 
ast->sub_ctx->streams[0]->codecpar);
 time_base = ast->sub_ctx->streams[0]->time_base;
 avpriv_set_pts_info(st, 64, time_base.num, time_base.den);
@@ -1146,6 +1149,7 @@ static int read_gab2_sub(AVFormatContext *s, AVStream 
*st, AVPacket *pkt)
 return 1;
 
 error:
+av_packet_free(&ast->sub_pkt);
 av_freep(&ast->sub_ctx);
 avio_context_free(&pb);
 }
@@ -1166,8 +1170,8 @@ static AVStream *get_subtitle_pkt(AVFormatContext *s, 
AVStream *next_st,
 for (i = 0; i < s->nb_streams; i++) {
 st  = s->streams[i];
 ast = st->priv_data;
-if (st->discard < AVDISCARD_ALL && ast && ast->sub_pkt.data) {
-ts = av_rescale_q(ast->sub_pkt.dts, st->time_base, AV_TIME_BASE_Q);
+if (st->discard < AVDISCARD_ALL && ast && ast->sub_pkt && 
ast->sub_pkt->data) {
+ts = av_rescale_q(ast->sub_pkt->dts, st->time_base, 
AV_TIME_BASE_Q);
 if (ts <= next_ts && ts < ts_min) {
 ts_min = ts;
 sub_st = st;
@@ -1177,11 +1181,11 @@ static AVStream *get_subtitle_pkt(AVFormatContext *s, 
AVStream *next_st,
 
 if (sub_st) {
 ast   = sub_st->priv_data;
-*pkt  = ast->sub_pkt;
+av_packet_move_ref(pkt, ast->sub_pkt);
 pkt->stream_index = sub_st->index;
 
-if (ff_read_packet(ast->sub_ctx, &ast->sub_pkt) < 0)
-ast->sub_pkt.data = NULL;
+if (ff_read_packet(ast->sub_ctx, ast->sub_pkt) < 0)
+ast->sub_pkt->data = NULL;
 }
 return sub_st;
 }
@@ -1800,10 +1804,10 @@ static void seek_subtitle(AVStream *st, AVStream *st2, 
int64_t timestamp)
 {
 AVIStream *ast2 = st2->priv_data;
 int64_t ts2 = av_rescale_q(timestamp, st->time_base, st2->time_base);
-av_packet_unref(&ast2->sub_pkt);
+av_packet_unref(ast2->sub_pkt);
 if (avformat_seek_file(ast2->sub_ctx, 0, INT64_MIN, ts2, ts2, 0) >= 0 ||
 avformat_seek_file(ast2->sub_ctx, 0, ts2, ts2, INT64_MAX, 0) >= 0)
-ff_read_packet(ast2->sub_ctx, &ast2->sub_pkt);
+ff_read_packet(ast2->sub_ctx, ast2->sub_pkt);
 }
 
 static int avi_read_seek(AVFormatContext *s, int stream_index,
@@ -1937,7 +1941,7 @@ static int avi_read_close(AVFormatContext *s)
 avformat_close_input(&ast->sub_ctx);
 }
 av_buffer_unref(&ast->sub_buffer);
-av_packet_unref(&ast->sub_pkt);
+av_packet_free(&ast->sub_pkt);
 }
 }
 
-- 
2.30.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".

[FFmpeg-devel] [PATCH 15/50] avformat/avienc: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/avienc.c | 18 --
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/libavformat/avienc.c b/libavformat/avienc.c
index 1b2cb529b9..58bd081fcb 100644
--- a/libavformat/avienc.c
+++ b/libavformat/avienc.c
@@ -85,6 +85,8 @@ typedef struct AVIStream {
 
 int64_t last_dts;
 
+AVPacket *empty_packet;
+
 AVIIndex indexes;
 
 int64_t strh_flags_offset;
@@ -275,9 +277,17 @@ static int avi_write_header(AVFormatContext *s)
 }
 
 for (n = 0; n < s->nb_streams; n++) {
+AVIStream *avist;
+
 s->streams[n]->priv_data = av_mallocz(sizeof(AVIStream));
 if (!s->streams[n]->priv_data)
 return AVERROR(ENOMEM);
+
+avist = s->streams[n]->priv_data;
+avist->empty_packet = av_packet_alloc();
+if (!avist->empty_packet)
+return AVERROR(ENOMEM);
+avist->empty_packet->stream_index = n;
 }
 
 /* header list */
@@ -745,18 +755,13 @@ static int write_skip_frames(AVFormatContext *s, int 
stream_index, int64_t dts)
 ff_dlog(s, "dts:%s packet_count:%d stream_index:%d\n", av_ts2str(dts), 
avist->packet_count, stream_index);
 while (par->block_align == 0 && dts != AV_NOPTS_VALUE &&
dts > avist->packet_count && par->codec_id != AV_CODEC_ID_XSUB && 
avist->packet_count) {
-AVPacket empty_packet;
 
 if (dts - avist->packet_count > 6) {
 av_log(s, AV_LOG_ERROR, "Too large number of skipped frames 
%"PRId64" > 6\n", dts - avist->packet_count);
 return AVERROR(EINVAL);
 }
 
-av_init_packet(&empty_packet);
-empty_packet.size = 0;
-empty_packet.data = NULL;
-empty_packet.stream_index = stream_index;
-avi_write_packet_internal(s, &empty_packet);
+avi_write_packet_internal(s, avist->empty_packet);
 ff_dlog(s, "dup dts:%s packet_count:%d\n", av_ts2str(dts), 
avist->packet_count);
 }
 
@@ -985,6 +990,7 @@ static void avi_deinit(AVFormatContext *s)
 for (int j = 0; j < avist->indexes.ents_allocated / 
AVI_INDEX_CLUSTER_SIZE; j++)
 av_freep(&avist->indexes.cluster[j]);
 av_freep(&avist->indexes.cluster);
+av_packet_free(&avist->empty_packet);
 avist->indexes.ents_allocated = avist->indexes.entry = 0;
 }
 }
-- 
2.30.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".

[FFmpeg-devel] [PATCH 16/50] avformat/dv: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
This one must be committed after the upcoming major bump, as it changes
the return value of an avpriv function.

 libavdevice/iec61883.c |  2 +-
 libavformat/dv.c   | 56 --
 2 files changed, 38 insertions(+), 20 deletions(-)

diff --git a/libavdevice/iec61883.c b/libavdevice/iec61883.c
index cafafb2672..4582ada151 100644
--- a/libavdevice/iec61883.c
+++ b/libavdevice/iec61883.c
@@ -191,7 +191,7 @@ static int iec61883_parse_queue_dv(struct iec61883_data 
*dv, AVPacket *pkt)
 int size;
 
 size = avpriv_dv_get_packet(dv->dv_demux, pkt);
-if (size > 0)
+if (size)
 return size;
 
 packet = dv->queue_first;
diff --git a/libavformat/dv.c b/libavformat/dv.c
index 26a78139f5..f5c0c44afc 100644
--- a/libavformat/dv.c
+++ b/libavformat/dv.c
@@ -45,7 +45,7 @@ struct DVDemuxContext {
 AVFormatContext*  fctx;
 AVStream* vst;
 AVStream* ast[4];
-AVPacket  audio_pkt[4];
+AVPacket  *audio_pkt[4];
 uint8_t   audio_buf[4][8192];
 int   ach;
 int   frames;
@@ -261,11 +261,10 @@ static int dv_extract_audio_info(DVDemuxContext *c, const 
uint8_t *frame)
 c->ast[i]->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
 c->ast[i]->codecpar->codec_id   = AV_CODEC_ID_PCM_S16LE;
 
-av_init_packet(&c->audio_pkt[i]);
-c->audio_pkt[i].size = 0;
-c->audio_pkt[i].data = c->audio_buf[i];
-c->audio_pkt[i].stream_index = c->ast[i]->index;
-c->audio_pkt[i].flags   |= AV_PKT_FLAG_KEY;
+c->audio_pkt[i]->size = 0;
+c->audio_pkt[i]->data = c->audio_buf[i];
+c->audio_pkt[i]->stream_index = c->ast[i]->index;
+c->audio_pkt[i]->flags   |= AV_PKT_FLAG_KEY;
 }
 c->ast[i]->codecpar->sample_rate= dv_audio_frequency[freq];
 c->ast[i]->codecpar->channels   = 2;
@@ -332,6 +331,12 @@ static int dv_init_demux(AVFormatContext *s, 
DVDemuxContext *c)
 c->vst->codecpar->bit_rate   = 2500;
 c->vst->start_time= 0;
 
+for (int i = 0; i < 4; i++) {
+c->audio_pkt[i] = av_packet_alloc();
+if (!c->audio_pkt[i])
+return AVERROR(ENOMEM);
+}
+
 return 0;
 }
 
@@ -353,13 +358,15 @@ DVDemuxContext *avpriv_dv_init_demux(AVFormatContext *s)
 
 int avpriv_dv_get_packet(DVDemuxContext *c, AVPacket *pkt)
 {
-int size = -1;
+int size = 0;
 int i;
 
 for (i = 0; i < c->ach; i++) {
-if (c->ast[i] && c->audio_pkt[i].size) {
-*pkt = c->audio_pkt[i];
-c->audio_pkt[i].size = 0;
+if (c->ast[i] && c->audio_pkt[i]->size) {
+int ret = av_packet_ref(pkt, c->audio_pkt[i]);
+if (ret < 0)
+return ret;
+c->audio_pkt[i]->size = 0;
 size = pkt->size;
 break;
 }
@@ -384,9 +391,9 @@ int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket 
*pkt,
 /* FIXME: in case of no audio/bad audio we have to do something */
 size = dv_extract_audio_info(c, buf);
 for (i = 0; i < c->ach; i++) {
-c->audio_pkt[i].pos  = pos;
-c->audio_pkt[i].size = size;
-c->audio_pkt[i].pts  = (c->sys->height == 720) ? (c->frames & ~1) : 
c->frames;
+c->audio_pkt[i]->pos  = pos;
+c->audio_pkt[i]->size = size;
+c->audio_pkt[i]->pts  = (c->sys->height == 720) ? (c->frames & ~1) : 
c->frames;
 ppcm[i] = c->audio_buf[i];
 }
 if (c->ach)
@@ -396,15 +403,14 @@ int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket 
*pkt,
  * channels 0,1 and odd 2,3. */
 if (c->sys->height == 720) {
 if (buf[1] & 0x0C) {
-c->audio_pkt[2].size = c->audio_pkt[3].size = 0;
+c->audio_pkt[2]->size = c->audio_pkt[3]->size = 0;
 } else {
-c->audio_pkt[0].size = c->audio_pkt[1].size = 0;
+c->audio_pkt[0]->size = c->audio_pkt[1]->size = 0;
 }
 }
 
 /* Now it's time to return video packet */
 size = dv_extract_video_info(c, buf);
-av_init_packet(pkt);
 pkt->data = buf;
 pkt->pos  = pos;
 pkt->size = size;
@@ -439,8 +445,8 @@ static int64_t dv_frame_offset(AVFormatContext *s, 
DVDemuxContext *c,
 void ff_dv_offset_reset(DVDemuxContext *c, int64_t frame_offset)
 {
 c->frames = frame_offset;
-c->audio_pkt[0].size = c->audio_pkt[1].size = 0;
-c->audio_pkt[2].size = c->audio_pkt[3].size = 0;
+c->audio_pkt[0]->size = c->audio_pkt[1]->size = 0;
+c->audio_pkt[2]->size = c->audio_pkt[3]->size = 0;
 }
 
 /
@@ -539,7 +545,7 @@ static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
 
 size = avpriv_dv_get_packet(&c->dv_demux, pkt);
 
-if (size < 0) {
+if (

[FFmpeg-devel] [PATCH 17/50] avformat/flac_picture: replace call to av_init_packet()

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/flac_picture.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/flac_picture.c b/libavformat/flac_picture.c
index 53e24b28b7..f15cfa877a 100644
--- a/libavformat/flac_picture.c
+++ b/libavformat/flac_picture.c
@@ -165,7 +165,7 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, 
int buf_size, int tr
 RETURN_ERROR(AVERROR(ENOMEM));
 }
 
-av_init_packet(&st->attached_pic);
+av_packet_unref(&st->attached_pic);
 st->attached_pic.buf  = data;
 st->attached_pic.data = data->data;
 st->attached_pic.size = len;
-- 
2.30.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".

[FFmpeg-devel] [PATCH 18/50] avformat/id3v2: replace call to av_init_packet()

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/id3v2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index 97f6cc8a68..3800f21ef9 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -1159,7 +1159,7 @@ int ff_id3v2_parse_apic(AVFormatContext *s, 
ID3v2ExtraMeta *extra_meta)
 
 av_dict_set(&st->metadata, "comment", apic->type, 0);
 
-av_init_packet(&st->attached_pic);
+av_packet_unref(&st->attached_pic);
 st->attached_pic.buf  = apic->buf;
 st->attached_pic.data = apic->buf->data;
 st->attached_pic.size = apic->buf->size - 
AV_INPUT_BUFFER_PADDING_SIZE;
-- 
2.30.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".

[FFmpeg-devel] [PATCH 19/50] avformat/flacdec: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/flacdec.c | 20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index 6aca4755a1..7852a79d39 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -259,7 +259,7 @@ static int flac_probe(const AVProbeData *p)
 static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int 
stream_index,
  int64_t *ppos, int64_t pos_limit)
 {
-AVPacket pkt;
+AVPacket *pkt;
 AVStream *st = s->streams[stream_index];
 AVCodecParserContext *parser;
 int ret;
@@ -268,9 +268,12 @@ static av_unused int64_t 
flac_read_timestamp(AVFormatContext *s, int stream_inde
 if (avio_seek(s->pb, *ppos, SEEK_SET) < 0)
 return AV_NOPTS_VALUE;
 
-av_init_packet(&pkt);
+pkt = av_packet_alloc();
+if (!pkt)
+return AV_NOPTS_VALUE;
 parser = av_parser_init(st->codecpar->codec_id);
 if (!parser){
+av_packet_free(&pkt);
 return AV_NOPTS_VALUE;
 }
 parser->flags |= PARSER_FLAG_USE_CODEC_TS;
@@ -279,20 +282,20 @@ static av_unused int64_t 
flac_read_timestamp(AVFormatContext *s, int stream_inde
 uint8_t *data;
 int size;
 
-ret = ff_raw_read_partial_packet(s, &pkt);
+ret = ff_raw_read_partial_packet(s, pkt);
 if (ret < 0){
 if (ret == AVERROR(EAGAIN))
 continue;
 else {
-av_packet_unref(&pkt);
-av_assert1(!pkt.size);
+av_packet_unref(pkt);
+av_assert1(!pkt->size);
 }
 }
 av_parser_parse2(parser, st->internal->avctx,
- &data, &size, pkt.data, pkt.size,
- pkt.pts, pkt.dts, *ppos);
+ &data, &size, pkt->data, pkt->size,
+ pkt->pts, pkt->dts, *ppos);
 
-av_packet_unref(&pkt);
+av_packet_unref(pkt);
 if (size) {
 if (parser->pts != AV_NOPTS_VALUE){
 // seeking may not have started from beginning of a frame
@@ -304,6 +307,7 @@ static av_unused int64_t 
flac_read_timestamp(AVFormatContext *s, int stream_inde
 } else if (ret < 0)
 break;
 }
+av_packet_free(&pkt);
 av_parser_close(parser);
 return pts;
 }
-- 
2.30.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".

[FFmpeg-devel] [PATCH 20/50] avformat/hls: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/hls.c | 73 +--
 1 file changed, 39 insertions(+), 34 deletions(-)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index af2468ad9b..dfc91fd5cb 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -101,7 +101,7 @@ struct playlist {
 AVFormatContext *parent;
 int index;
 AVFormatContext *ctx;
-AVPacket pkt;
+AVPacket *pkt;
 int has_noheader_flag;
 
 /* main demuxer streams associated with this playlist
@@ -256,7 +256,7 @@ static void free_playlist_list(HLSContext *c)
 av_dict_free(&pls->id3_initial);
 ff_id3v2_free_extra_meta(&pls->id3_deferred_extra);
 av_freep(&pls->init_sec_buf);
-av_packet_unref(&pls->pkt);
+av_packet_free(&pls->pkt);
 av_freep(&pls->pb.buffer);
 ff_format_io_close(c->ctx, &pls->input);
 pls->input_read_done = 0;
@@ -299,12 +299,17 @@ static struct playlist *new_playlist(HLSContext *c, const 
char *url,
 struct playlist *pls = av_mallocz(sizeof(struct playlist));
 if (!pls)
 return NULL;
+pls->pkt = av_packet_alloc();
+if (!pls->pkt) {
+av_free(pls);
+return NULL;
+}
 ff_make_absolute_url(pls->url, sizeof(pls->url), base, url);
 if (!pls->url[0]) {
+av_packet_free(&pls->pkt);
 av_free(pls);
 return NULL;
 }
-av_init_packet(&pls->pkt);
 pls->seek_timestamp = AV_NOPTS_VALUE;
 
 pls->is_id3_timestamped = -1;
@@ -2102,26 +2107,26 @@ static int recheck_discard_flags(AVFormatContext *s, 
int first)
 static void fill_timing_for_id3_timestamped_stream(struct playlist *pls)
 {
 if (pls->id3_offset >= 0) {
-pls->pkt.dts = pls->id3_mpegts_timestamp +
+pls->pkt->dts = pls->id3_mpegts_timestamp +
  av_rescale_q(pls->id3_offset,
-  
pls->ctx->streams[pls->pkt.stream_index]->time_base,
+  
pls->ctx->streams[pls->pkt->stream_index]->time_base,
   MPEG_TIME_BASE_Q);
-if (pls->pkt.duration)
-pls->id3_offset += pls->pkt.duration;
+if (pls->pkt->duration)
+pls->id3_offset += pls->pkt->duration;
 else
 pls->id3_offset = -1;
 } else {
 /* there have been packets with unknown duration
  * since the last id3 tag, should not normally happen */
-pls->pkt.dts = AV_NOPTS_VALUE;
+pls->pkt->dts = AV_NOPTS_VALUE;
 }
 
-if (pls->pkt.duration)
-pls->pkt.duration = av_rescale_q(pls->pkt.duration,
- 
pls->ctx->streams[pls->pkt.stream_index]->time_base,
+if (pls->pkt->duration)
+pls->pkt->duration = av_rescale_q(pls->pkt->duration,
+ 
pls->ctx->streams[pls->pkt->stream_index]->time_base,
  MPEG_TIME_BASE_Q);
 
-pls->pkt.pts = AV_NOPTS_VALUE;
+pls->pkt->pts = AV_NOPTS_VALUE;
 }
 
 static AVRational get_timebase(struct playlist *pls)
@@ -2129,7 +2134,7 @@ static AVRational get_timebase(struct playlist *pls)
 if (pls->is_id3_timestamped)
 return MPEG_TIME_BASE_Q;
 
-return pls->ctx->streams[pls->pkt.stream_index]->time_base;
+return pls->ctx->streams[pls->pkt->stream_index]->time_base;
 }
 
 static int compare_ts_with_wrapdetect(int64_t ts_a, struct playlist *pls_a,
@@ -2153,25 +2158,25 @@ static int hls_read_packet(AVFormatContext *s, AVPacket 
*pkt)
 struct playlist *pls = c->playlists[i];
 /* Make sure we've got one buffered packet from each open playlist
  * stream */
-if (pls->needed && !pls->pkt.data) {
+if (pls->needed && !pls->pkt->data) {
 while (1) {
 int64_t ts_diff;
 AVRational tb;
-ret = av_read_frame(pls->ctx, &pls->pkt);
+ret = av_read_frame(pls->ctx, pls->pkt);
 if (ret < 0) {
 if (!avio_feof(&pls->pb) && ret != AVERROR_EOF)
 return ret;
 break;
 } else {
 /* stream_index check prevents matching picture 
attachments etc. */
-if (pls->is_id3_timestamped && pls->pkt.stream_index == 0) 
{
+if (pls->is_id3_timestamped && pls->pkt->stream_index == 
0) {
 /* audio elementary streams are id3 timestamped */
 fill_timing_for_id3_timestamped_stream(pls);
 }
 
 if (c->first_timestamp == AV_NOPTS_VALUE &&
-pls->pkt.dts   != AV_NOPTS_VALUE)
-c->first_timestamp = av_rescale_q(pls->pkt.dts,
+pls->pkt->dts   != AV_NOPTS_VALUE)
+c->first_timestamp 

[FFmpeg-devel] [PATCH 25/50] avformat/mpegts: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/mpegts.c | 36 
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index e283ec09d7..6e0d9d7496 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -981,7 +981,7 @@ static void reset_pes_packet_state(PESContext *pes)
 
 static void new_data_packet(const uint8_t *buffer, int len, AVPacket *pkt)
 {
-av_init_packet(pkt);
+av_packet_unref(pkt);
 pkt->data = (uint8_t *)buffer;
 pkt->size = len;
 }
@@ -990,7 +990,7 @@ static int new_pes_packet(PESContext *pes, AVPacket *pkt)
 {
 uint8_t *sd;
 
-av_init_packet(pkt);
+av_packet_unref(pkt);
 
 pkt->buf  = pes->buffer;
 pkt->data = pes->buffer->data;
@@ -3298,33 +3298,37 @@ static int64_t mpegts_get_dts(AVFormatContext *s, int 
stream_index,
   int64_t *ppos, int64_t pos_limit)
 {
 MpegTSContext *ts = s->priv_data;
+AVPacket *pkt;
 int64_t pos;
 int pos47 = ts->pos47_full % ts->raw_packet_size;
 pos = ((*ppos  + ts->raw_packet_size - 1 - pos47) / ts->raw_packet_size) * 
ts->raw_packet_size + pos47;
 ff_read_frame_flush(s);
 if (avio_seek(s->pb, pos, SEEK_SET) < 0)
 return AV_NOPTS_VALUE;
+pkt = av_packet_alloc();
+if (!pkt)
+return AV_NOPTS_VALUE;
 while(pos < pos_limit) {
-int ret;
-AVPacket pkt;
-av_init_packet(&pkt);
-ret = av_read_frame(s, &pkt);
-if (ret < 0)
+int ret = av_read_frame(s, pkt);
+if (ret < 0) {
+av_packet_free(&pkt);
 return AV_NOPTS_VALUE;
-if (pkt.dts != AV_NOPTS_VALUE && pkt.pos >= 0) {
-ff_reduce_index(s, pkt.stream_index);
-av_add_index_entry(s->streams[pkt.stream_index], pkt.pos, pkt.dts, 
0, 0, AVINDEX_KEYFRAME /* FIXME keyframe? */);
-if (pkt.stream_index == stream_index && pkt.pos >= *ppos) {
-int64_t dts = pkt.dts;
-*ppos = pkt.pos;
-av_packet_unref(&pkt);
+}
+if (pkt->dts != AV_NOPTS_VALUE && pkt->pos >= 0) {
+ff_reduce_index(s, pkt->stream_index);
+av_add_index_entry(s->streams[pkt->stream_index], pkt->pos, 
pkt->dts, 0, 0, AVINDEX_KEYFRAME /* FIXME keyframe? */);
+if (pkt->stream_index == stream_index && pkt->pos >= *ppos) {
+int64_t dts = pkt->dts;
+*ppos = pkt->pos;
+av_packet_free(&pkt);
 return dts;
 }
 }
-pos = pkt.pos;
-av_packet_unref(&pkt);
+pos = pkt->pos;
+av_packet_unref(pkt);
 }
 
+av_packet_free(&pkt);
 return AV_NOPTS_VALUE;
 }
 
-- 
2.30.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".

[FFmpeg-devel] [PATCH 21/50] avformat/matroskadec: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/matroskadec.c | 17 -
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 374831baa3..9fad78c78b 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -365,6 +365,8 @@ typedef struct MatroskaDemuxContext {
 /* byte position of the segment inside the stream */
 int64_t segment_start;
 
+AVPacket *pkt;
+
 /* the packet queue */
 AVPacketList *queue;
 AVPacketList *queue_end;
@@ -2885,6 +2887,10 @@ static int matroska_read_header(AVFormatContext *s)
 }
 ebml_free(ebml_syntax, &ebml);
 
+matroska->pkt = av_packet_alloc();
+if (!matroska->pkt)
+goto fail;
+
 /* The next thing is a segment. */
 pos = avio_tell(matroska->ctx->pb);
 res = ebml_parse(matroska, matroska_segments, matroska);
@@ -2947,7 +2953,7 @@ static int matroska_read_header(AVFormatContext *s)
 st->disposition |= AV_DISPOSITION_ATTACHED_PIC;
 st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
 
-av_init_packet(pkt);
+av_packet_unref(pkt);
 pkt->buf  = attachments[j].bin.buf;
 attachments[j].bin.buf = NULL;
 pkt->data = attachments[j].bin.data;
@@ -3180,7 +3186,7 @@ static int matroska_parse_rm_audio(MatroskaDemuxContext 
*matroska,
 
 while (track->audio.pkt_cnt) {
 int ret;
-AVPacket pktl, *pkt = &pktl;
+AVPacket *pkt = matroska->pkt;
 
 ret = av_new_packet(pkt, a);
 if (ret < 0) {
@@ -3317,7 +3323,7 @@ static int matroska_parse_webvtt(MatroskaDemuxContext 
*matroska,
  uint64_t duration,
  int64_t pos)
 {
-AVPacket pktl, *pkt = &pktl;
+AVPacket *pkt = matroska->pkt;
 uint8_t *id, *settings, *text, *buf;
 int id_len, settings_len, text_len;
 uint8_t *p, *q;
@@ -3434,7 +3440,7 @@ static int matroska_parse_frame(MatroskaDemuxContext 
*matroska,
 {
 uint8_t *pkt_data = data;
 int res = 0;
-AVPacket pktl, *pkt = &pktl;
+AVPacket *pkt = matroska->pkt;
 
 if (st->codecpar->codec_id == AV_CODEC_ID_WAVPACK) {
 res = matroska_parse_wavpack(track, &pkt_data, &pkt_size);
@@ -3464,7 +3470,7 @@ static int matroska_parse_frame(MatroskaDemuxContext 
*matroska,
 if (!pkt_size && !additional_size)
 goto no_output;
 
-av_init_packet(pkt);
+av_packet_unref(pkt);
 if (!buf)
 pkt->buf = av_buffer_create(pkt_data, pkt_size + 
AV_INPUT_BUFFER_PADDING_SIZE,
 NULL, NULL, 0);
@@ -3838,6 +3844,7 @@ static int matroska_read_close(AVFormatContext *s)
 int n;
 
 matroska_clear_queue(matroska);
+av_packet_free(&matroska->pkt);
 
 for (n = 0; n < matroska->tracks.nb_elem; n++)
 if (tracks[n].type == MATROSKA_TRACK_TYPE_AUDIO)
-- 
2.30.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".

[FFmpeg-devel] [PATCH 26/50] avformat/mpegtsenc: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/mpegtsenc.c | 19 +--
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 45f8d5f373..baf303dc60 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -77,6 +77,7 @@ typedef struct MpegTSWrite {
 MpegTSSection pat; /* MPEG-2 PAT table */
 MpegTSSection sdt; /* MPEG-2 SDT table context */
 MpegTSService **services;
+AVPacket *pkt;
 int64_t sdt_period; /* SDT period in PCR time base */
 int64_t pat_period; /* PAT/PMT period in PCR time base */
 int nb_services;
@@ -1022,6 +1023,10 @@ static int mpegts_init(AVFormatContext *s)
 ts->sdt.write_packet = section_write_packet;
 ts->sdt.opaque   = s;
 
+ts->pkt = av_packet_alloc();
+if (!ts->pkt)
+return AVERROR(ENOMEM);
+
 /* assign pids to each stream */
 for (i = 0; i < s->nb_streams; i++) {
 AVStream *st = s->streams[i];
@@ -1745,23 +1750,23 @@ static int mpegts_write_packet_internal(AVFormatContext 
*s, AVPacket *pkt)
 }
 if ((AV_RB16(pkt->data) & 0xfff0) != 0xfff0) {
 int ret;
-AVPacket pkt2;
+AVPacket *pkt2 = ts->pkt;
 
 if (!ts_st->amux) {
 av_log(s, AV_LOG_ERROR, "AAC bitstream not in ADTS format "
 "and extradata missing\n");
 } else {
-av_init_packet(&pkt2);
-pkt2.data = pkt->data;
-pkt2.size = pkt->size;
+av_packet_unref(pkt2);
+pkt2->data = pkt->data;
+pkt2->size = pkt->size;
 av_assert0(pkt->dts != AV_NOPTS_VALUE);
-pkt2.dts = av_rescale_q(pkt->dts, st->time_base, 
ts_st->amux->streams[0]->time_base);
+pkt2->dts = av_rescale_q(pkt->dts, st->time_base, 
ts_st->amux->streams[0]->time_base);
 
 ret = avio_open_dyn_buf(&ts_st->amux->pb);
 if (ret < 0)
 return ret;
 
-ret = av_write_frame(ts_st->amux, &pkt2);
+ret = av_write_frame(ts_st->amux, pkt2);
 if (ret < 0) {
 ffio_free_dyn_buf(&ts_st->amux->pb);
 return ret;
@@ -2020,6 +2025,8 @@ static void mpegts_deinit(AVFormatContext *s)
 MpegTSService *service;
 int i;
 
+av_packet_free(&ts->pkt);
+
 for (i = 0; i < s->nb_streams; i++) {
 AVStream *st = s->streams[i];
 MpegTSWriteStream *ts_st = st->priv_data;
-- 
2.30.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".

[FFmpeg-devel] [PATCH 24/50] avformat/movenc: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/movenc.c | 116 ---
 libavformat/movenc.h |   4 +-
 libavformat/movenchint.c |  19 ---
 3 files changed, 85 insertions(+), 54 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 372c04295d..0af4f9ae21 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -365,7 +365,7 @@ static int mov_write_ac3_tag(AVFormatContext *s, 
AVIOContext *pb, MOVTrack *trac
 }
 
 struct eac3_info {
-AVPacket pkt;
+AVPacket *pkt;
 uint8_t ec3_done;
 uint8_t num_blocks;
 
@@ -407,6 +407,9 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, 
MOVTrack *track)
 return AVERROR(ENOMEM);
 info = track->eac3_priv;
 
+if (!info->pkt && !(info->pkt = av_packet_alloc()))
+return AVERROR(ENOMEM);
+
 if (avpriv_ac3_parse_header(&hdr, pkt->data, pkt->size) < 0) {
 /* drop the packets until we see a good one */
 if (!track->entry) {
@@ -511,20 +514,20 @@ concatenate:
 }
 
 if (!info->num_blocks) {
-ret = av_packet_ref(&info->pkt, pkt);
+ret = av_packet_ref(info->pkt, pkt);
 if (!ret)
 info->num_blocks = num_blocks;
 goto end;
 } else {
-if ((ret = av_grow_packet(&info->pkt, pkt->size)) < 0)
+if ((ret = av_grow_packet(info->pkt, pkt->size)) < 0)
 goto end;
-memcpy(info->pkt.data + info->pkt.size - pkt->size, pkt->data, 
pkt->size);
+memcpy(info->pkt->data + info->pkt->size - pkt->size, pkt->data, 
pkt->size);
 info->num_blocks += num_blocks;
-info->pkt.duration += pkt->duration;
+info->pkt->duration += pkt->duration;
 if (info->num_blocks != 6)
 goto end;
 av_packet_unref(pkt);
-av_packet_move_ref(pkt, &info->pkt);
+av_packet_move_ref(pkt, info->pkt);
 info->num_blocks = 0;
 }
 ret = pkt->size;
@@ -3734,7 +3737,7 @@ static int mov_write_covr(AVIOContext *pb, 
AVFormatContext *s)
 for (i = 0; i < s->nb_streams; i++) {
 MOVTrack *trk = &mov->tracks[i];
 
-if (!is_cover_image(trk->st) || trk->cover_image.size <= 0)
+if (!is_cover_image(trk->st) || trk->cover_image->size <= 0)
 continue;
 
 if (!pos) {
@@ -3742,11 +3745,11 @@ static int mov_write_covr(AVIOContext *pb, 
AVFormatContext *s)
 avio_wb32(pb, 0);
 ffio_wfourcc(pb, "covr");
 }
-avio_wb32(pb, 16 + trk->cover_image.size);
+avio_wb32(pb, 16 + trk->cover_image->size);
 ffio_wfourcc(pb, "data");
 avio_wb32(pb, trk->tag);
 avio_wb32(pb , 0);
-avio_write(pb, trk->cover_image.data, trk->cover_image.size);
+avio_write(pb, trk->cover_image->data, trk->cover_image->size);
 }
 
 return pos ? update_size(pb, pos) : 0;
@@ -5303,16 +5306,17 @@ static int mov_flush_fragment(AVFormatContext *s, int 
force)
 for (i = 0; i < s->nb_streams; i++) {
 MOVTrack *track = &mov->tracks[i];
 if (!track->end_reliable) {
-AVPacket pkt;
-if (!ff_interleaved_peek(s, i, &pkt, 1)) {
+AVPacket *pkt = mov->pkt;
+if (!ff_interleaved_peek(s, i, pkt, 1)) {
 if (track->dts_shift != AV_NOPTS_VALUE)
-pkt.dts += track->dts_shift;
-track->track_duration = pkt.dts - track->start_dts;
-if (pkt.pts != AV_NOPTS_VALUE)
-track->end_pts = pkt.pts;
+pkt->dts += track->dts_shift;
+track->track_duration = pkt->dts - track->start_dts;
+if (pkt->pts != AV_NOPTS_VALUE)
+track->end_pts = pkt->pts;
 else
-track->end_pts = pkt.dts;
+track->end_pts = pkt->dts;
 }
+av_packet_unref(pkt);
 }
 }
 
@@ -5965,20 +5969,20 @@ static int mov_write_single_packet(AVFormatContext *s, 
AVPacket *pkt)
 static int mov_write_subtitle_end_packet(AVFormatContext *s,
  int stream_index,
  int64_t dts) {
-AVPacket end;
+MOVMuxContext *mov = s->priv_data;
+AVPacket *end = mov->pkt;
 uint8_t data[2] = {0};
 int ret;
 
-av_init_packet(&end);
-end.size = sizeof(data);
-end.data = data;
-end.pts = dts;
-end.dts = dts;
-end.duration = 0;
-end.stream_index = stream_index;
+end->size = sizeof(data);
+end->data = data;
+end->pts = dts;
+end->dts = dts;
+end->duration = 0;
+end->stream_index = stream_index;
 
-ret = mov_write_single_packet(s, &end);
-av_packet_unref(&end);
+ret = mov_write_single_packet(s, end);
+av_packet_unref(end);
 
 return ret;
 }
@@ -6005,7 +6009,7 @@ static int mov_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 return 0;
 }
 
-if

[FFmpeg-devel] [PATCH 22/50] avformat/matroskaenc: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/matroskaenc.c | 21 +++--
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 233c472b8f..012442f7f2 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -137,7 +137,7 @@ typedef struct MatroskaMuxContext {
 mkv_cuescues;
 int64_t cues_pos;
 
-AVPacketcur_audio_pkt;
+AVPacket   *cur_audio_pkt;
 
 unsignednb_attachments;
 int have_video;
@@ -451,7 +451,7 @@ static void mkv_deinit(AVFormatContext *s)
 {
 MatroskaMuxContext *mkv = s->priv_data;
 
-av_packet_unref(&mkv->cur_audio_pkt);
+av_packet_free(&mkv->cur_audio_pkt);
 
 ffio_free_dyn_buf(&mkv->cluster_bc);
 ffio_free_dyn_buf(&mkv->info.bc);
@@ -1919,8 +1919,6 @@ static int mkv_write_header(AVFormatContext *s)
 mkv->reserve_cues_space = -1;
 }
 
-av_init_packet(&mkv->cur_audio_pkt);
-mkv->cur_audio_pkt.size = 0;
 mkv->cluster_pos = -1;
 
 // start a new cluster every 5 MB or 5 sec, or 32k / 1 sec for streaming or
@@ -2414,9 +2412,9 @@ static int mkv_write_packet(AVFormatContext *s, const 
AVPacket *pkt)
   keyframe && (mkv->have_video ? codec_type == 
AVMEDIA_TYPE_VIDEO : 1) ? AVIO_DATA_MARKER_SYNC_POINT : 
AVIO_DATA_MARKER_BOUNDARY_POINT);
 
 // check if we have an audio packet cached
-if (mkv->cur_audio_pkt.size > 0) {
-ret = mkv_write_packet_internal(s, &mkv->cur_audio_pkt);
-av_packet_unref(&mkv->cur_audio_pkt);
+if (mkv->cur_audio_pkt->size > 0) {
+ret = mkv_write_packet_internal(s, mkv->cur_audio_pkt);
+av_packet_unref(mkv->cur_audio_pkt);
 if (ret < 0) {
 av_log(s, AV_LOG_ERROR,
"Could not write cached audio packet ret:%d\n", ret);
@@ -2428,7 +2426,7 @@ static int mkv_write_packet(AVFormatContext *s, const 
AVPacket *pkt)
 // keyframe's timecode is contained in the same cluster for WebM
 if (codec_type == AVMEDIA_TYPE_AUDIO) {
 if (pkt->size > 0)
-ret = av_packet_ref(&mkv->cur_audio_pkt, pkt);
+ret = av_packet_ref(mkv->cur_audio_pkt, pkt);
 } else
 ret = mkv_write_packet_internal(s, pkt);
 return ret;
@@ -2460,8 +2458,8 @@ static int mkv_write_trailer(AVFormatContext *s)
 int ret, ret2 = 0;
 
 // check if we have an audio packet cached
-if (mkv->cur_audio_pkt.size > 0) {
-ret = mkv_write_packet_internal(s, &mkv->cur_audio_pkt);
+if (mkv->cur_audio_pkt->size > 0) {
+ret = mkv_write_packet_internal(s, mkv->cur_audio_pkt);
 if (ret < 0) {
 av_log(s, AV_LOG_ERROR,
"Could not write cached audio packet ret:%d\n", ret);
@@ -2685,6 +2683,9 @@ static int mkv_init(struct AVFormatContext *s)
 } else
 mkv->mode = MODE_MATROSKAv2;
 
+mkv->cur_audio_pkt = av_packet_alloc();
+if (!mkv->cur_audio_pkt)
+return AVERROR(ENOMEM);
 mkv->tracks = av_mallocz_array(s->nb_streams, sizeof(*mkv->tracks));
 if (!mkv->tracks)
 return AVERROR(ENOMEM);
-- 
2.30.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".

[FFmpeg-devel] [PATCH 23/50] avformat/mux: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/internal.h |  5 +
 libavformat/mux.c  | 44 ++
 libavformat/options.c  |  6 ++
 libavformat/utils.c|  1 +
 4 files changed, 35 insertions(+), 21 deletions(-)

diff --git a/libavformat/internal.h b/libavformat/internal.h
index d0db331b96..69a7caff93 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -92,6 +92,11 @@ struct AVFormatInternal {
  */
 struct AVPacketList *parse_queue;
 struct AVPacketList *parse_queue_end;
+
+/**
+ * Used to hold temporary packets.
+ */
+AVPacket *pkt;
 /**
  * Remaining size available for raw_packet_buffer, in bytes.
  */
diff --git a/libavformat/mux.c b/libavformat/mux.c
index 84c56ac6ba..3600e74a50 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -1052,7 +1052,9 @@ int ff_interleaved_peek(AVFormatContext *s, int stream,
 AVPacketList *pktl = s->internal->packet_buffer;
 while (pktl) {
 if (pktl->pkt.stream_index == stream) {
-*pkt = pktl->pkt;
+int ret = av_packet_ref(pkt, &pktl->pkt);
+if (ret < 0)
+return ret;
 if (add_offset) {
 AVStream *st = s->streams[pkt->stream_index];
 int64_t offset = st->internal->mux_ts_offset;
@@ -1208,7 +1210,7 @@ static int write_packets_common(AVFormatContext *s, 
AVPacket *pkt, int interleav
 
 int av_write_frame(AVFormatContext *s, AVPacket *in)
 {
-AVPacket local_pkt, *pkt = &local_pkt;
+AVPacket *pkt = s->internal->pkt;
 int ret;
 
 if (!in) {
@@ -1229,6 +1231,7 @@ int av_write_frame(AVFormatContext *s, AVPacket *in)
  * The following avoids copying in's data unnecessarily.
  * Copying side data is unavoidable as a bitstream filter
  * may change it, e.g. free it on errors. */
+av_packet_unref(pkt);
 pkt->buf  = NULL;
 pkt->data = in->data;
 pkt->size = in->size;
@@ -1270,14 +1273,14 @@ int av_interleaved_write_frame(AVFormatContext *s, 
AVPacket *pkt)
 int av_write_trailer(AVFormatContext *s)
 {
 int i, ret1, ret = 0;
-AVPacket pkt = {0};
-av_init_packet(&pkt);
+AVPacket *pkt = s->internal->pkt;
 
+av_packet_unref(pkt);
 for (i = 0; i < s->nb_streams; i++) {
 if (s->streams[i]->internal->bsfc) {
-ret1 = write_packets_from_bsfs(s, s->streams[i], &pkt, 
1/*interleaved*/);
+ret1 = write_packets_from_bsfs(s, s->streams[i], pkt, 
1/*interleaved*/);
 if (ret1 < 0)
-av_packet_unref(&pkt);
+av_packet_unref(pkt);
 if (ret >= 0)
 ret = ret1;
 }
@@ -1351,7 +1354,7 @@ static void uncoded_frame_free(void *unused, uint8_t 
*data)
 static int write_uncoded_frame_internal(AVFormatContext *s, int stream_index,
 AVFrame *frame, int interleaved)
 {
-AVPacket pkt, *pktp;
+AVPacket *pkt = s->internal->pkt;
 
 av_assert0(s->oformat);
 if (!s->oformat->write_uncoded_frame) {
@@ -1360,18 +1363,17 @@ static int write_uncoded_frame_internal(AVFormatContext 
*s, int stream_index,
 }
 
 if (!frame) {
-pktp = NULL;
+pkt = NULL;
 } else {
 size_t   bufsize = sizeof(frame) + AV_INPUT_BUFFER_PADDING_SIZE;
 AVFrame **framep = av_mallocz(bufsize);
 
 if (!framep)
 goto fail;
-pktp = &pkt;
-av_init_packet(&pkt);
-pkt.buf = av_buffer_create((void *)framep, bufsize,
+av_packet_unref(pkt);
+pkt->buf = av_buffer_create((void *)framep, bufsize,
uncoded_frame_free, NULL, 0);
-if (!pkt.buf) {
+if (!pkt->buf) {
 av_free(framep);
 fail:
 av_frame_free(&frame);
@@ -1379,17 +1381,17 @@ static int write_uncoded_frame_internal(AVFormatContext 
*s, int stream_index,
 }
 *framep = frame;
 
-pkt.data = (void *)framep;
-pkt.size = sizeof(frame);
-pkt.pts  =
-pkt.dts  = frame->pts;
-pkt.duration = frame->pkt_duration;
-pkt.stream_index = stream_index;
-pkt.flags |= AV_PKT_FLAG_UNCODED_FRAME;
+pkt->data = (void *)framep;
+pkt->size = sizeof(frame);
+pkt->pts  =
+pkt->dts  = frame->pts;
+pkt->duration = frame->pkt_duration;
+pkt->stream_index = stream_index;
+pkt->flags |= AV_PKT_FLAG_UNCODED_FRAME;
 }
 
-return interleaved ? av_interleaved_write_frame(s, pktp) :
- av_write_frame(s, pktp);
+return interleaved ? av_interleaved_write_frame(s, pkt) :
+ av_write_frame(s, pkt);
 }
 
 int av_write_uncoded_frame(AVFormatContext *s, int stream_index,
diff --git a/libavformat/options.c b/libavformat/options.c
index 59e0389815..8d7c4fe

[FFmpeg-devel] [PATCH 28/50] avformat/rtpenc_mpegts: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/rtpenc_mpegts.c | 23 +++
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/libavformat/rtpenc_mpegts.c b/libavformat/rtpenc_mpegts.c
index 7d7377db7a..50cebf68a3 100644
--- a/libavformat/rtpenc_mpegts.c
+++ b/libavformat/rtpenc_mpegts.c
@@ -26,6 +26,7 @@
 struct MuxChain {
 AVFormatContext *mpegts_ctx;
 AVFormatContext *rtp_ctx;
+AVPacket *pkt;
 };
 
 static int rtp_mpegts_write_close(AVFormatContext *s)
@@ -41,6 +42,9 @@ static int rtp_mpegts_write_close(AVFormatContext *s)
 av_write_trailer(chain->rtp_ctx);
 avformat_free_context(chain->rtp_ctx);
 }
+
+av_packet_free(&chain->pkt);
+
 return 0;
 }
 
@@ -58,6 +62,9 @@ static int rtp_mpegts_write_header(AVFormatContext *s)
 mpegts_ctx = avformat_alloc_context();
 if (!mpegts_ctx)
 return AVERROR(ENOMEM);
+chain->pkt = av_packet_alloc();
+if (!chain->pkt)
+goto fail;
 mpegts_ctx->oformat   = mpegts_format;
 mpegts_ctx->max_delay = s->max_delay;
 av_dict_copy(&mpegts_ctx->metadata, s->metadata, 0);
@@ -116,7 +123,7 @@ static int rtp_mpegts_write_packet(AVFormatContext *s, 
AVPacket *pkt)
 struct MuxChain *chain = s->priv_data;
 int ret = 0, size;
 uint8_t *buf;
-AVPacket local_pkt;
+AVPacket *local_pkt = chain->pkt;
 
 if (!chain->mpegts_ctx->pb) {
 if ((ret = avio_open_dyn_buf(&chain->mpegts_ctx->pb)) < 0)
@@ -130,19 +137,19 @@ static int rtp_mpegts_write_packet(AVFormatContext *s, 
AVPacket *pkt)
 av_free(buf);
 return 0;
 }
-av_init_packet(&local_pkt);
-local_pkt.data = buf;
-local_pkt.size = size;
-local_pkt.stream_index = 0;
+av_packet_unref(local_pkt);
+local_pkt->data = buf;
+local_pkt->size = size;
+local_pkt->stream_index = 0;
 if (pkt->pts != AV_NOPTS_VALUE)
-local_pkt.pts = av_rescale_q(pkt->pts,
+local_pkt->pts = av_rescale_q(pkt->pts,
  s->streams[pkt->stream_index]->time_base,
  chain->rtp_ctx->streams[0]->time_base);
 if (pkt->dts != AV_NOPTS_VALUE)
-local_pkt.dts = av_rescale_q(pkt->dts,
+local_pkt->dts = av_rescale_q(pkt->dts,
  s->streams[pkt->stream_index]->time_base,
  chain->rtp_ctx->streams[0]->time_base);
-ret = av_write_frame(chain->rtp_ctx, &local_pkt);
+ret = av_write_frame(chain->rtp_ctx, local_pkt);
 av_free(buf);
 
 return ret;
-- 
2.30.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".

[FFmpeg-devel] [PATCH 29/50] avformat/utils: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/internal.h |   1 +
 libavformat/options.c  |   5 ++-
 libavformat/utils.c| 100 +++--
 3 files changed, 62 insertions(+), 44 deletions(-)

diff --git a/libavformat/internal.h b/libavformat/internal.h
index 69a7caff93..bf0cb798d3 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -90,6 +90,7 @@ struct AVFormatInternal {
 /**
  * Packets split by the parser get queued here.
  */
+AVPacket *parse_pkt;
 struct AVPacketList *parse_queue;
 struct AVPacketList *parse_queue_end;
 
diff --git a/libavformat/options.c b/libavformat/options.c
index 8d7c4fe4cb..07403b533e 100644
--- a/libavformat/options.c
+++ b/libavformat/options.c
@@ -221,7 +221,10 @@ AVFormatContext *avformat_alloc_context(void)
 return NULL;
 }
 internal->pkt = av_packet_alloc();
-if (!internal->pkt) {
+internal->parse_pkt = av_packet_alloc();
+if (!internal->pkt || !internal->parse_pkt) {
+av_packet_free(&internal->pkt);
+av_packet_free(&internal->parse_pkt);
 av_free(internal);
 av_free(ic);
 return NULL;
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 2587bedc05..43c0be97e2 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -309,9 +309,15 @@ static int append_packet_chunked(AVIOContext *s, AVPacket 
*pkt, int size)
 
 int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
 {
+#if FF_API_INIT_PACKET
+FF_DISABLE_DEPRECATION_WARNINGS
 av_init_packet(pkt);
 pkt->data = NULL;
 pkt->size = 0;
+FF_ENABLE_DEPRECATION_WARNINGS
+#else
+av_packet_unref(pkt);
+#endif
 pkt->pos  = avio_tell(s);
 
 return append_packet_chunked(s, pkt, size);
@@ -799,9 +805,15 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
 int ret, i, err;
 AVStream *st;
 
+#if FF_API_INIT_PACKET
+FF_DISABLE_DEPRECATION_WARNINGS
 pkt->data = NULL;
 pkt->size = 0;
 av_init_packet(pkt);
+FF_ENABLE_DEPRECATION_WARNINGS
+#else
+av_packet_unref(pkt);
+#endif
 
 for (;;) {
 AVPacketList *pktl = s->internal->raw_packet_buffer;
@@ -1401,14 +1413,14 @@ FF_ENABLE_DEPRECATION_WARNINGS
 static int parse_packet(AVFormatContext *s, AVPacket *pkt,
 int stream_index, int flush)
 {
-AVPacket out_pkt;
+AVPacket *out_pkt = s->internal->parse_pkt;
 AVStream *st = s->streams[stream_index];
 uint8_t *data = pkt->data;
 int size  = pkt->size;
 int ret = 0, got_output = flush;
 
 if (size || flush) {
-av_init_packet(&out_pkt);
+av_packet_unref(out_pkt);
 } else if (st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) {
 // preserve 0-size sync packets
 compute_pkt_fields(s, st, st->parser, pkt, AV_NOPTS_VALUE, 
AV_NOPTS_VALUE);
@@ -1420,7 +1432,7 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt,
 int64_t next_dts = pkt->dts;
 
 len = av_parser_parse2(st->parser, st->internal->avctx,
-   &out_pkt.data, &out_pkt.size, data, size,
+   &out_pkt->data, &out_pkt->size, data, size,
pkt->pts, pkt->dts, pkt->pos);
 
 pkt->pts = pkt->dts = AV_NOPTS_VALUE;
@@ -1429,39 +1441,39 @@ static int parse_packet(AVFormatContext *s, AVPacket 
*pkt,
 data += len;
 size -= len;
 
-got_output = !!out_pkt.size;
+got_output = !!out_pkt->size;
 
-if (!out_pkt.size)
+if (!out_pkt->size)
 continue;
 
-if (pkt->buf && out_pkt.data == pkt->data) {
-/* reference pkt->buf only when out_pkt.data is guaranteed to point
+if (pkt->buf && out_pkt->data == pkt->data) {
+/* reference pkt->buf only when out_pkt->data is guaranteed to 
point
  * to data in it and not in the parser's internal buffer. */
 /* XXX: Ensure this is the case with all parsers when 
st->parser->flags
  * is PARSER_FLAG_COMPLETE_FRAMES and check for that instead? */
-out_pkt.buf = av_buffer_ref(pkt->buf);
-if (!out_pkt.buf) {
+out_pkt->buf = av_buffer_ref(pkt->buf);
+if (!out_pkt->buf) {
 ret = AVERROR(ENOMEM);
 goto fail;
 }
 } else {
-ret = av_packet_make_refcounted(&out_pkt);
+ret = av_packet_make_refcounted(out_pkt);
 if (ret < 0)
 goto fail;
 }
 
 if (pkt->side_data) {
-out_pkt.side_data   = pkt->side_data;
-out_pkt.side_data_elems = pkt->side_data_elems;
+out_pkt->side_data   = pkt->side_data;
+out_pkt->side_data_elems = pkt->side_data_elems;
 pkt->side_data  = NULL;
 pkt->side_data_elems= 0;
 }
 
 /* set the duration */
-out_pkt.duration = (st->parser->flags & PARSER_FLA

[FFmpeg-devel] [PATCH 27/50] avformat/rtpdec: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/rtpdec.c|  2 +-
 libavformat/rtpdec_qt.c | 63 -
 2 files changed, 38 insertions(+), 27 deletions(-)

diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c
index d592e34893..fd4601e654 100644
--- a/libavformat/rtpdec.c
+++ b/libavformat/rtpdec.c
@@ -964,7 +964,7 @@ int ff_parse_fmtp(AVFormatContext *s,
 int ff_rtp_finalize_packet(AVPacket *pkt, AVIOContext **dyn_buf, int 
stream_idx)
 {
 int ret;
-av_init_packet(pkt);
+av_packet_unref(pkt);
 
 pkt->size = avio_close_dyn_buf(*dyn_buf, &pkt->data);
 pkt->stream_index = stream_idx;
diff --git a/libavformat/rtpdec_qt.c b/libavformat/rtpdec_qt.c
index 93bf31746b..de6b12fb04 100644
--- a/libavformat/rtpdec_qt.c
+++ b/libavformat/rtpdec_qt.c
@@ -34,11 +34,21 @@
 #include "libavcodec/get_bits.h"
 
 struct PayloadContext {
-AVPacket pkt;
+AVPacket *pkt;
 int bytes_per_frame, remaining;
 uint32_t timestamp;
 };
 
+static av_cold int qt_rtp_init(AVFormatContext *ctx, int st_index,
+   PayloadContext *qt)
+{
+qt->pkt = av_packet_alloc();
+if (!qt->pkt)
+return AVERROR(ENOMEM);
+
+return 0;
+}
+
 static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt,
AVStream *st, AVPacket *pkt,
uint32_t *timestamp, const uint8_t *buf,
@@ -51,18 +61,18 @@ static int qt_rtp_parse_packet(AVFormatContext *s, 
PayloadContext *qt,
 keyframe, ret;
 
 if (qt->remaining) {
-int num = qt->pkt.size / qt->bytes_per_frame;
+int num = qt->pkt->size / qt->bytes_per_frame;
 
 if ((ret = av_new_packet(pkt, qt->bytes_per_frame)) < 0)
 return ret;
 pkt->stream_index = st->index;
-pkt->flags= qt->pkt.flags;
+pkt->flags= qt->pkt->flags;
 memcpy(pkt->data,
-   &qt->pkt.data[(num - qt->remaining) * qt->bytes_per_frame],
+   &qt->pkt->data[(num - qt->remaining) * qt->bytes_per_frame],
qt->bytes_per_frame);
 if (--qt->remaining == 0) {
-av_freep(&qt->pkt.data);
-qt->pkt.size = 0;
+av_freep(&qt->pkt->data);
+qt->pkt->size = 0;
 }
 return qt->remaining > 0;
 }
@@ -171,31 +181,31 @@ static int qt_rtp_parse_packet(AVFormatContext *s, 
PayloadContext *qt,
 
 switch (packing_scheme) {
 case 3: /* one data packet spread over 1 or multiple RTP packets */
-if (qt->pkt.size > 0 && qt->timestamp == *timestamp) {
+if (qt->pkt->size > 0 && qt->timestamp == *timestamp) {
 int err;
-if ((err = av_reallocp(&qt->pkt.data, qt->pkt.size + alen +
+if ((err = av_reallocp(&qt->pkt->data, qt->pkt->size + alen +
AV_INPUT_BUFFER_PADDING_SIZE)) < 0) {
-qt->pkt.size = 0;
+qt->pkt->size = 0;
 return err;
 }
 } else {
-av_freep(&qt->pkt.data);
-av_init_packet(&qt->pkt);
-qt->pkt.data = av_realloc(NULL, alen + 
AV_INPUT_BUFFER_PADDING_SIZE);
-if (!qt->pkt.data)
+av_freep(&qt->pkt->data);
+av_packet_unref(qt->pkt);
+qt->pkt->data = av_realloc(NULL, alen + 
AV_INPUT_BUFFER_PADDING_SIZE);
+if (!qt->pkt->data)
 return AVERROR(ENOMEM);
-qt->pkt.size = 0;
+qt->pkt->size = 0;
 qt->timestamp = *timestamp;
 }
-memcpy(qt->pkt.data + qt->pkt.size, buf + avio_tell(&pb), alen);
-qt->pkt.size += alen;
+memcpy(qt->pkt->data + qt->pkt->size, buf + avio_tell(&pb), alen);
+qt->pkt->size += alen;
 if (has_marker_bit) {
-int ret = av_packet_from_data(pkt, qt->pkt.data, qt->pkt.size);
+int ret = av_packet_from_data(pkt, qt->pkt->data, qt->pkt->size);
 if (ret < 0)
 return ret;
 
-qt->pkt.size = 0;
-qt->pkt.data = NULL;
+qt->pkt->size = 0;
+qt->pkt->data = NULL;
 pkt->flags= keyframe ? AV_PKT_FLAG_KEY : 0;
 pkt->stream_index = st->index;
 memset(pkt->data + pkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
@@ -214,17 +224,17 @@ static int qt_rtp_parse_packet(AVFormatContext *s, 
PayloadContext *qt,
 pkt->flags = keyframe ? AV_PKT_FLAG_KEY : 0;
 pkt->stream_index = st->index;
 if (qt->remaining > 0) {
-av_freep(&qt->pkt.data);
-qt->pkt.data = av_realloc(NULL, qt->remaining * 
qt->bytes_per_frame);
-if (!qt->pkt.data) {
+av_freep(&qt->pkt->data);
+qt->pkt->data = av_realloc(NULL, qt->remaining * 
qt->bytes_per_frame);
+if (!qt->pkt->data) {
 av_packet_unref(pkt);
 return AVERROR(EN

[FFmpeg-devel] [PATCH 30/50] avformat/subtitles: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/jacosubdec.c |  2 +-
 libavformat/mpeg.c   |  4 +--
 libavformat/mpsubdec.c   |  4 +--
 libavformat/subtitles.c  | 64 +++-
 libavformat/subtitles.h  |  2 +-
 libavformat/tedcaptionsdec.c |  4 +--
 6 files changed, 42 insertions(+), 38 deletions(-)

diff --git a/libavformat/jacosubdec.c b/libavformat/jacosubdec.c
index 14221b166c..b44e3b7783 100644
--- a/libavformat/jacosubdec.c
+++ b/libavformat/jacosubdec.c
@@ -250,7 +250,7 @@ static int jacosub_read_header(AVFormatContext *s)
 /* SHIFT and TIMERES affect the whole script so packet timing can only be
  * done in a second pass */
 for (i = 0; i < jacosub->q.nb_subs; i++) {
-AVPacket *sub = &jacosub->q.subs[i];
+AVPacket *sub = jacosub->q.subs[i];
 read_ts(jacosub, sub->data, &sub->pts, &sub->duration);
 }
 ff_subtitles_queue_finalize(s, &jacosub->q);
diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
index 20d1e10168..79610ec600 100644
--- a/libavformat/mpeg.c
+++ b/libavformat/mpeg.c
@@ -934,7 +934,7 @@ static int vobsub_read_packet(AVFormatContext *s, AVPacket 
*pkt)
 if (tmpq->current_sub_idx >= tmpq->nb_subs)
 continue;
 
-ts = tmpq->subs[tmpq->current_sub_idx].pts;
+ts = tmpq->subs[tmpq->current_sub_idx]->pts;
 if (ts < min_ts) {
 min_ts = ts;
 sid = i;
@@ -950,7 +950,7 @@ static int vobsub_read_packet(AVFormatContext *s, AVPacket 
*pkt)
 /* compute maximum packet size using the next packet position. This is
  * useful when the len in the header is non-sense */
 if (q->current_sub_idx < q->nb_subs) {
-psize = q->subs[q->current_sub_idx].pos - pkt->pos;
+psize = q->subs[q->current_sub_idx]->pos - pkt->pos;
 } else {
 int64_t fsize = avio_size(pb);
 psize = fsize < 0 ? 0x : fsize - pkt->pos;
diff --git a/libavformat/mpsubdec.c b/libavformat/mpsubdec.c
index 2e6dc883eb..c113be5eba 100644
--- a/libavformat/mpsubdec.c
+++ b/libavformat/mpsubdec.c
@@ -147,8 +147,8 @@ static int mpsub_read_header(AVFormatContext *s)
 if (common_factor > 1) {
 common_factor = av_gcd(pts_info.num, common_factor);
 for (i = 0; i < mpsub->q.nb_subs; i++) {
-mpsub->q.subs[i].pts  /= common_factor;
-mpsub->q.subs[i].duration /= common_factor;
+mpsub->q.subs[i]->pts  /= common_factor;
+mpsub->q.subs[i]->duration /= common_factor;
 }
 pts_info.num /= common_factor;
 }
diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c
index ad7f68938e..ec10b99822 100644
--- a/libavformat/subtitles.c
+++ b/libavformat/subtitles.c
@@ -111,13 +111,13 @@ int ff_text_peek_r8(FFTextReader *r)
 AVPacket *ff_subtitles_queue_insert(FFDemuxSubtitlesQueue *q,
 const uint8_t *event, size_t len, int 
merge)
 {
-AVPacket *subs, *sub;
+AVPacket **subs, *sub;
 
 if (merge && q->nb_subs > 0) {
 /* merge with previous event */
 
 int old_len;
-sub = &q->subs[q->nb_subs - 1];
+sub = q->subs[q->nb_subs - 1];
 old_len = sub->size;
 if (av_grow_packet(sub, len) < 0)
 return NULL;
@@ -132,7 +132,10 @@ AVPacket *ff_subtitles_queue_insert(FFDemuxSubtitlesQueue 
*q,
 if (!subs)
 return NULL;
 q->subs = subs;
-sub = &subs[q->nb_subs];
+subs[q->nb_subs] = av_packet_alloc();
+if (!subs[q->nb_subs])
+return NULL;
+sub = subs[q->nb_subs];
 if (av_new_packet(sub, len) < 0)
 return NULL;
 q->nb_subs++;
@@ -145,8 +148,8 @@ AVPacket *ff_subtitles_queue_insert(FFDemuxSubtitlesQueue 
*q,
 
 static int cmp_pkt_sub_ts_pos(const void *a, const void *b)
 {
-const AVPacket *s1 = a;
-const AVPacket *s2 = b;
+const AVPacket *s1 = *(const AVPacket **)a;
+const AVPacket *s2 = *(const AVPacket **)b;
 if (s1->pts == s2->pts)
 return FFDIFFSIGN(s1->pos, s2->pos);
 return FFDIFFSIGN(s1->pts , s2->pts);
@@ -154,8 +157,8 @@ static int cmp_pkt_sub_ts_pos(const void *a, const void *b)
 
 static int cmp_pkt_sub_pos_ts(const void *a, const void *b)
 {
-const AVPacket *s1 = a;
-const AVPacket *s2 = b;
+const AVPacket *s1 = *(const AVPacket **)a;
+const AVPacket *s2 = *(const AVPacket **)b;
 if (s1->pos == s2->pos) {
 if (s1->pts == s2->pts)
 return 0;
@@ -170,18 +173,18 @@ static void drop_dups(void *log_ctx, 
FFDemuxSubtitlesQueue *q)
 
 for (i = 1; i < q->nb_subs; i++) {
 const int last_id = i - 1 - drop;
-const AVPacket *last = &q->subs[last_id];
+const AVPacket *last = q->subs[last_id];
 
-if (q->subs[i].pts== last->pts &&
-q->subs[i].duration   == last->duration &&
-q->subs[i].stream_index == last->stream_index &&
-!strcmp(q->sub

[FFmpeg-devel] [PATCH 31/50] avformat/wc3movie: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/wc3movie.c | 21 ++---
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/libavformat/wc3movie.c b/libavformat/wc3movie.c
index 76e945d261..1fe582945a 100644
--- a/libavformat/wc3movie.c
+++ b/libavformat/wc3movie.c
@@ -69,7 +69,7 @@ typedef struct Wc3DemuxContext {
 int video_stream_index;
 int audio_stream_index;
 
-AVPacket vpkt;
+AVPacket *vpkt;
 
 } Wc3DemuxContext;
 
@@ -77,8 +77,7 @@ static int wc3_read_close(AVFormatContext *s)
 {
 Wc3DemuxContext *wc3 = s->priv_data;
 
-if (wc3->vpkt.size > 0)
-av_packet_unref(&wc3->vpkt);
+av_packet_free(&wc3->vpkt);
 
 return 0;
 }
@@ -110,8 +109,9 @@ static int wc3_read_header(AVFormatContext *s)
 wc3->height = WC3_DEFAULT_HEIGHT;
 wc3->pts = 0;
 wc3->video_stream_index = wc3->audio_stream_index = 0;
-av_init_packet(&wc3->vpkt);
-wc3->vpkt.data = NULL; wc3->vpkt.size = 0;
+wc3->vpkt = av_packet_alloc();
+if (!wc3->vpkt)
+goto fail;
 
 /* skip the first 3 32-bit numbers */
 avio_skip(pb, 12);
@@ -162,7 +162,7 @@ static int wc3_read_header(AVFormatContext *s)
 case PALT_TAG:
 /* one of several palettes */
 avio_seek(pb, -8, SEEK_CUR);
-av_append_packet(pb, &wc3->vpkt, 8 + PALETTE_SIZE);
+av_append_packet(pb, wc3->vpkt, 8 + PALETTE_SIZE);
 break;
 
 default:
@@ -248,18 +248,17 @@ static int wc3_read_packet(AVFormatContext *s,
 case SHOT_TAG:
 /* load up new palette */
 avio_seek(pb, -8, SEEK_CUR);
-av_append_packet(pb, &wc3->vpkt, 8 + 4);
+av_append_packet(pb, wc3->vpkt, 8 + 4);
 break;
 
 case VGA__TAG:
 /* send out video chunk */
 avio_seek(pb, -8, SEEK_CUR);
-ret= av_append_packet(pb, &wc3->vpkt, 8 + size);
+ret= av_append_packet(pb, wc3->vpkt, 8 + size);
 // ignore error if we have some data
-if (wc3->vpkt.size > 0)
+if (wc3->vpkt->size > 0)
 ret = 0;
-*pkt = wc3->vpkt;
-wc3->vpkt.data = NULL; wc3->vpkt.size = 0;
+av_packet_move_ref(pkt, wc3->vpkt);
 pkt->stream_index = wc3->video_stream_index;
 pkt->pts = wc3->pts;
 packet_read = 1;
-- 
2.30.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".

[FFmpeg-devel] [PATCH 32/50] avformat/tests/fifo_muxer: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/tests/fifo_muxer.c | 28 ++--
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/libavformat/tests/fifo_muxer.c b/libavformat/tests/fifo_muxer.c
index 5127a8aadb..3458c3eefd 100644
--- a/libavformat/tests/fifo_muxer.c
+++ b/libavformat/tests/fifo_muxer.c
@@ -81,9 +81,11 @@ static int fifo_basic_test(AVFormatContext *oc, AVDictionary 
**opts,
  const FailingMuxerPacketData *pkt_data)
 {
 int ret = 0, i;
-AVPacket pkt;
+AVPacket *pkt;
 
-av_init_packet(&pkt);
+pkt = av_packet_alloc();
+if (!pkt)
+return AVERROR(ENOMEM);
 
 
 ret = avformat_write_header(oc, opts);
@@ -94,20 +96,22 @@ static int fifo_basic_test(AVFormatContext *oc, 
AVDictionary **opts,
 }
 
 for (i = 0; i < 15; i++ ) {
-ret = prepare_packet(&pkt, pkt_data, i);
+ret = prepare_packet(pkt, pkt_data, i);
 if (ret < 0) {
 fprintf(stderr, "Failed to prepare test packet: %s\n",
 av_err2str(ret));
 goto write_trailer_and_fail;
 }
-ret = av_write_frame(oc, &pkt);
-av_packet_unref(&pkt);
+ret = av_write_frame(oc, pkt);
+av_packet_unref(pkt);
 if (ret < 0) {
 fprintf(stderr, "Unexpected write_frame error: %s\n",
 av_err2str(ret));
+av_packet_free(&pkt);
 goto write_trailer_and_fail;
 }
 }
+av_packet_free(&pkt);
 
 ret = av_write_frame(oc, NULL);
 if (ret < 0) {
@@ -135,9 +139,11 @@ static int fifo_overflow_drop_test(AVFormatContext *oc, 
AVDictionary **opts,
 {
 int ret = 0, i;
 int64_t write_pkt_start, write_pkt_end, duration;
-AVPacket pkt;
+AVPacket *pkt;
 
-av_init_packet(&pkt);
+pkt = av_packet_alloc();
+if (!pkt)
+return AVERROR(ENOMEM);
 
 ret = avformat_write_header(oc, opts);
 if (ret) {
@@ -148,18 +154,20 @@ static int fifo_overflow_drop_test(AVFormatContext *oc, 
AVDictionary **opts,
 
 write_pkt_start = av_gettime_relative();
 for (i = 0; i < 6; i++ ) {
-ret = prepare_packet(&pkt, data, i);
+ret = prepare_packet(pkt, data, i);
 if (ret < 0) {
 fprintf(stderr, "Failed to prepare test packet: %s\n",
 av_err2str(ret));
 goto fail;
 }
-ret = av_write_frame(oc, &pkt);
-av_packet_unref(&pkt);
+ret = av_write_frame(oc, pkt);
+av_packet_unref(pkt);
 if (ret < 0) {
 break;
 }
 }
+av_packet_free(&pkt);
+
 write_pkt_end = av_gettime_relative();
 duration = write_pkt_end - write_pkt_start;
 if (duration > (SLEEPTIME_50_MS*6)/2) {
-- 
2.30.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".

[FFmpeg-devel] [PATCH 33/50] avformat/tests/movenc: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/tests/movenc.c | 81 --
 1 file changed, 42 insertions(+), 39 deletions(-)

diff --git a/libavformat/tests/movenc.c b/libavformat/tests/movenc.c
index 1d15d97ad9..04155dde76 100644
--- a/libavformat/tests/movenc.c
+++ b/libavformat/tests/movenc.c
@@ -56,6 +56,7 @@ int out_size;
 struct AVMD5* md5;
 uint8_t hash[HASH_SIZE];
 
+AVPacket *pkt;
 AVStream *video_st, *audio_st;
 int64_t audio_dts, video_dts;
 
@@ -248,68 +249,67 @@ static void mux_frames(int n, int c)
 {
 int end_frames = frames + n;
 while (1) {
-AVPacket pkt;
 uint8_t pktdata[8] = { 0 };
-av_init_packet(&pkt);
+av_packet_unref(pkt);
 
 if (av_compare_ts(audio_dts, audio_st->time_base, video_dts, 
video_st->time_base) < 0) {
-pkt.dts = pkt.pts = audio_dts;
-pkt.stream_index = 1;
-pkt.duration = audio_duration;
+pkt->dts = pkt->pts = audio_dts;
+pkt->stream_index = 1;
+pkt->duration = audio_duration;
 audio_dts += audio_duration;
 } else {
 if (frames == end_frames)
 break;
-pkt.dts = video_dts;
-pkt.stream_index = 0;
-pkt.duration = duration;
+pkt->dts = video_dts;
+pkt->stream_index = 0;
+pkt->duration = duration;
 if ((frames % gop_size) == 0) {
-pkt.flags |= AV_PKT_FLAG_KEY;
+pkt->flags |= AV_PKT_FLAG_KEY;
 last_picture = AV_PICTURE_TYPE_I;
-pkt.pts = pkt.dts + duration;
-video_dts = pkt.pts;
+pkt->pts = pkt->dts + duration;
+video_dts = pkt->pts;
 } else {
 if (last_picture == AV_PICTURE_TYPE_P) {
 last_picture = AV_PICTURE_TYPE_B;
-pkt.pts = pkt.dts;
+pkt->pts = pkt->dts;
 video_dts = next_p_pts;
 } else {
 last_picture = AV_PICTURE_TYPE_P;
 if (((frames + 1) % gop_size) == 0) {
-pkt.pts = pkt.dts + duration;
-video_dts = pkt.pts;
+pkt->pts = pkt->dts + duration;
+video_dts = pkt->pts;
 } else {
-next_p_pts = pkt.pts = pkt.dts + 2 * duration;
+next_p_pts = pkt->pts = pkt->dts + 2 * duration;
 video_dts += duration;
 }
 }
 }
 if (!bframes)
-pkt.pts = pkt.dts;
+pkt->pts = pkt->dts;
 if (fake_pkt_duration)
-pkt.duration = fake_pkt_duration;
+pkt->duration = fake_pkt_duration;
 frames++;
 }
 
 if (clear_duration)
-pkt.duration = 0;
-AV_WB32(pktdata + 4, pkt.pts);
-pkt.data = pktdata;
-pkt.size = 8;
+pkt->duration = 0;
+AV_WB32(pktdata + 4, pkt->pts);
+pkt->data = pktdata;
+pkt->size = 8;
 if (skip_write)
 continue;
-if (skip_write_audio && pkt.stream_index == 1)
+if (skip_write_audio && pkt->stream_index == 1)
 continue;
 
 if (c) {
-pkt.pts += (1LL<<32);
-pkt.dts += (1LL<<32);
+pkt->pts += (1LL<<32);
+pkt->dts += (1LL<<32);
 }
 
 if (do_interleave)
-av_interleaved_write_frame(ctx, &pkt);
+av_interleaved_write_frame(ctx, pkt);
 else
-av_write_frame(ctx, &pkt);
+av_write_frame(ctx, pkt);
 }
 }
 
@@ -327,19 +327,16 @@ static void skip_gops(int n)
 
 static void signal_init_ts(void)
 {
-AVPacket pkt;
-av_init_packet(&pkt);
-pkt.size = 0;
-pkt.data = NULL;
-
-pkt.stream_index = 0;
-pkt.dts = video_dts;
-pkt.pts = 0;
-av_write_frame(ctx, &pkt);
-
-pkt.stream_index = 1;
-pkt.dts = pkt.pts = audio_dts;
-av_write_frame(ctx, &pkt);
+av_packet_unref(pkt);
+
+pkt->stream_index = 0;
+pkt->dts = video_dts;
+pkt->pts = 0;
+av_write_frame(ctx, pkt);
+
+pkt->stream_index = 1;
+pkt->dts = pkt->pts = audio_dts;
+av_write_frame(ctx, pkt);
 }
 
 static void finish(void)
@@ -382,6 +379,11 @@ int main(int argc, char **argv)
 md5 = av_md5_alloc();
 if (!md5)
 return 1;
+pkt = av_packet_alloc();
+if (!pkt) {
+av_free(md5);
+return 1;
+}
 
 // Write a fragmented file with an initial moov that actually contains some
 // samples. One moov+mdat with 1 second of data and one moof+mdat with 1
@@ -786,6 +788,7 @@ int main(int argc, char **argv)
 close_out();
 
 av_free(md5);
+av_packet_free(&pkt);
 
 return check_faults > 0 ? 1 : 0;
 }
-- 
2.30

[FFmpeg-devel] [PATCH 34/50] avdevice/decklink_dec: stop using av_init_packet()

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
I only removed the calls to av_init_packet() here because i can't test this
code at all, so i'll leave it to the maintainer.

 libavdevice/decklink_dec.cpp | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index 4f8103e614..23f8946d37 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -673,8 +673,7 @@ static void handle_klv(AVFormatContext *avctx, decklink_ctx 
*ctx, IDeckLinkVideo
 klv.insert(klv.end(), packet.data.begin(), packet.data.end());
 }
 
-AVPacket klv_packet;
-av_init_packet(&klv_packet);
+AVPacket klv_packet = { 0 };
 klv_packet.pts = pts;
 klv_packet.dts = pts;
 klv_packet.flags |= AV_PKT_FLAG_KEY;
@@ -872,8 +871,7 @@ HRESULT decklink_input_callback::VideoInputFrameArrived(
 
 // Handle Video Frame
 if (videoFrame) {
-AVPacket pkt;
-av_init_packet(&pkt);
+AVPacket pkt = { 0 };
 if (ctx->frameCount % 25 == 0) {
 unsigned long long qsize = avpacket_queue_size(&ctx->queue);
 av_log(avctx, AV_LOG_DEBUG,
@@ -975,7 +973,7 @@ HRESULT decklink_input_callback::VideoInputFrameArrived(
 
 if (!no_video) {
 IDeckLinkVideoFrameAncillary *vanc;
-AVPacket txt_pkt;
+AVPacket txt_pkt = { 0 };
 uint8_t txt_buf0[3531]; // 35 * 46 bytes decoded teletext lines + 
1 byte data_identifier + 1920 bytes OP47 decode buffer
 uint8_t *txt_buf = txt_buf0;
 
@@ -1034,7 +1032,6 @@ HRESULT decklink_input_callback::VideoInputFrameArrived(
 txt_buf[1] = 0x2c; // data_unit_length
 txt_buf += 46;
 }
-av_init_packet(&txt_pkt);
 txt_pkt.pts = pkt.pts;
 txt_pkt.dts = pkt.dts;
 txt_pkt.stream_index = ctx->teletext_st->index;
@@ -1058,9 +1055,8 @@ HRESULT decklink_input_callback::VideoInputFrameArrived(
 
 // Handle Audio Frame
 if (audioFrame) {
-AVPacket pkt;
+AVPacket pkt = { 0 };
 BMDTimeValue audio_pts;
-av_init_packet(&pkt);
 
 //hack among hacks
 pkt.size = audioFrame->GetSampleFrameCount() * 
ctx->audio_st->codecpar->channels * (ctx->audio_depth / 8);
-- 
2.30.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".

[FFmpeg-devel] [PATCH 35/50] avdevice/xcbgrab: stop using av_init_packet()

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavdevice/xcbgrab.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/libavdevice/xcbgrab.c b/libavdevice/xcbgrab.c
index 95bdc8ab9d..908e189b35 100644
--- a/libavdevice/xcbgrab.c
+++ b/libavdevice/xcbgrab.c
@@ -184,8 +184,6 @@ static int xcbgrab_frame(AVFormatContext *s, AVPacket *pkt)
 data   = xcb_get_image_data(img);
 length = xcb_get_image_data_length(img);
 
-av_init_packet(pkt);
-
 pkt->buf = av_buffer_create(data, length, xcbgrab_image_reply_free, img, 
0);
 if (!pkt->buf) {
 free(img);
@@ -301,8 +299,6 @@ static int xcbgrab_frame_shm(AVFormatContext *s, AVPacket 
*pkt)
 
 free(img);
 
-av_init_packet(pkt);
-
 pkt->buf = buf;
 pkt->data = buf->data;
 pkt->size = c->frame_size;
-- 
2.30.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".

[FFmpeg-devel] [PATCH 36/50] avfilter/vf_mcdeint: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavfilter/vf_mcdeint.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vf_mcdeint.c b/libavfilter/vf_mcdeint.c
index bc7b3230d3..26baf94adb 100644
--- a/libavfilter/vf_mcdeint.c
+++ b/libavfilter/vf_mcdeint.c
@@ -74,6 +74,7 @@ typedef struct MCDeintContext {
 int mode;   ///< MCDeintMode
 int parity; ///< MCDeintParity
 int qp;
+AVPacket *pkt;
 AVCodecContext *enc_ctx;
 } MCDeintContext;
 
@@ -112,6 +113,9 @@ static int config_props(AVFilterLink *inlink)
 return AVERROR(EINVAL);
 }
 
+mcdeint->pkt = av_packet_alloc();
+if (!mcdeint->pkt)
+return AVERROR(ENOMEM);
 mcdeint->enc_ctx = avcodec_alloc_context3(enc);
 if (!mcdeint->enc_ctx)
 return AVERROR(ENOMEM);
@@ -154,6 +158,7 @@ static av_cold void uninit(AVFilterContext *ctx)
 {
 MCDeintContext *mcdeint = ctx->priv;
 
+av_packet_free(&mcdeint->pkt);
 avcodec_free_context(&mcdeint->enc_ctx);
 }
 
@@ -173,7 +178,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
*inpic)
 MCDeintContext *mcdeint = inlink->dst->priv;
 AVFilterLink *outlink = inlink->dst->outputs[0];
 AVFrame *outpic, *frame_dec;
-AVPacket pkt = {0};
+AVPacket *pkt = mcdeint->pkt;
 int x, y, i, ret, got_frame = 0;
 
 outpic = ff_get_video_buffer(outlink, outlink->w, outlink->h);
@@ -184,9 +189,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
*inpic)
 av_frame_copy_props(outpic, inpic);
 inpic->quality = mcdeint->qp * FF_QP2LAMBDA;
 
-av_init_packet(&pkt);
+av_packet_unref(pkt);
 
-ret = avcodec_encode_video2(mcdeint->enc_ctx, &pkt, inpic, &got_frame);
+ret = avcodec_encode_video2(mcdeint->enc_ctx, pkt, inpic, &got_frame);
 if (ret < 0)
 goto end;
 
@@ -274,7 +279,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
*inpic)
 mcdeint->parity ^= 1;
 
 end:
-av_packet_unref(&pkt);
+av_packet_unref(pkt);
 av_frame_free(&inpic);
 if (ret < 0) {
 av_frame_free(&outpic);
-- 
2.30.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".

[FFmpeg-devel] [PATCH 37/50] avfilter/vf_uspp: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 libavfilter/vf_uspp.c | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/libavfilter/vf_uspp.c b/libavfilter/vf_uspp.c
index 8b39f53c3d..8c75207593 100644
--- a/libavfilter/vf_uspp.c
+++ b/libavfilter/vf_uspp.c
@@ -51,6 +51,7 @@ typedef struct USPPContext {
 int outbuf_size;
 uint8_t *outbuf;
 AVCodecContext *avctx_enc[BLOCK*BLOCK];
+AVPacket *pkt;
 AVFrame *frame;
 AVFrame *frame_dec;
 int8_t *non_b_qp_table;
@@ -240,19 +241,19 @@ static void filter(USPPContext *p, uint8_t *dst[3], 
uint8_t *src[3],
 const int y1c = y1 >> p->vsub;
 const int BLOCKc = BLOCK >> p->hsub;
 int offset;
-AVPacket pkt = {0};
+AVPacket *pkt = p->pkt;
 int got_pkt_ptr;
 
-av_init_packet(&pkt);
-pkt.data = p->outbuf;
-pkt.size = p->outbuf_size;
+av_packet_unref(pkt);
+pkt->data = p->outbuf;
+pkt->size = p->outbuf_size;
 
 p->frame->data[0] = p->src[0] + x1   + y1   * p->frame->linesize[0];
 p->frame->data[1] = p->src[1] + x1c  + y1c  * p->frame->linesize[1];
 p->frame->data[2] = p->src[2] + x1c  + y1c  * p->frame->linesize[2];
 p->frame->format  = p->avctx_enc[i]->pix_fmt;
 
-ret = avcodec_encode_video2(p->avctx_enc[i], &pkt, p->frame, 
&got_pkt_ptr);
+ret = avcodec_encode_video2(p->avctx_enc[i], pkt, p->frame, 
&got_pkt_ptr);
 if (ret < 0) {
 av_log(p->avctx_enc[i], AV_LOG_ERROR, "Encoding failed\n");
 continue;
@@ -373,6 +374,8 @@ static int config_input(AVFilterLink *inlink)
 uspp->outbuf_size = (width + BLOCK) * (height + BLOCK) * 10;
 if (!(uspp->frame = av_frame_alloc()))
 return AVERROR(ENOMEM);
+if (!(uspp->pkt = av_packet_alloc()))
+return AVERROR(ENOMEM);
 if (!(uspp->outbuf = av_malloc(uspp->outbuf_size)))
 return AVERROR(ENOMEM);
 
@@ -465,6 +468,7 @@ static av_cold void uninit(AVFilterContext *ctx)
 
 av_freep(&uspp->non_b_qp_table);
 av_freep(&uspp->outbuf);
+av_packet_free(&uspp->pkt);
 av_frame_free(&uspp->frame);
 }
 
-- 
2.30.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".

[FFmpeg-devel] [PATCH 38/50] tools/pktdumper: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 tools/pktdumper.c | 23 ++-
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/tools/pktdumper.c b/tools/pktdumper.c
index 16a965b756..c51f5c8922 100644
--- a/tools/pktdumper.c
+++ b/tools/pktdumper.c
@@ -54,7 +54,7 @@ int main(int argc, char **argv)
 char fntemplate[FILENAME_BUF_SIZE];
 char pktfilename[FILENAME_BUF_SIZE];
 AVFormatContext *fctx = NULL;
-AVPacket pkt;
+AVPacket *pkt;
 int64_t pktnum  = 0;
 int64_t maxpkts = 0;
 int donotquit   = 0;
@@ -101,30 +101,35 @@ int main(int argc, char **argv)
 return 1;
 }
 
-av_init_packet(&pkt);
+pkt = av_packet_alloc();
+if (!pkt) {
+fprintf(stderr, "av_packet_alloc: error %d\n", AVERROR(ENOMEM));
+return 1;
+}
 
-while ((err = av_read_frame(fctx, &pkt)) >= 0) {
+while ((err = av_read_frame(fctx, pkt)) >= 0) {
 int fd;
 snprintf(pktfilename, sizeof(pktfilename), fntemplate, pktnum,
- pkt.stream_index, pkt.pts, pkt.size,
- (pkt.flags & AV_PKT_FLAG_KEY) ? 'K' : '_');
-printf(PKTFILESUFF "\n", pktnum, pkt.stream_index, pkt.pts, pkt.size,
-   (pkt.flags & AV_PKT_FLAG_KEY) ? 'K' : '_');
+ pkt->stream_index, pkt->pts, pkt->size,
+ (pkt->flags & AV_PKT_FLAG_KEY) ? 'K' : '_');
+printf(PKTFILESUFF "\n", pktnum, pkt->stream_index, pkt->pts, 
pkt->size,
+   (pkt->flags & AV_PKT_FLAG_KEY) ? 'K' : '_');
 if (!nowrite) {
 fd  = open(pktfilename, O_WRONLY | O_CREAT, 0644);
-err = write(fd, pkt.data, pkt.size);
+err = write(fd, pkt->data, pkt->size);
 if (err < 0) {
 fprintf(stderr, "write: error %d\n", err);
 return 1;
 }
 close(fd);
 }
-av_packet_unref(&pkt);
+av_packet_unref(pkt);
 pktnum++;
 if (maxpkts && (pktnum >= maxpkts))
 break;
 }
 
+av_packet_free(&pkt);
 avformat_close_input(&fctx);
 
 while (donotquit)
-- 
2.30.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".

[FFmpeg-devel] [PATCH 39/50] tools/target_dec_fuzzer: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 tools/target_dec_fuzzer.c | 73 +++
 1 file changed, 36 insertions(+), 37 deletions(-)

diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c
index affa6e3b51..84e59000b8 100644
--- a/tools/target_dec_fuzzer.c
+++ b/tools/target_dec_fuzzer.c
@@ -286,13 +286,12 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 
 int got_frame;
 AVFrame *frame = av_frame_alloc();
-if (!frame)
+AVPacket *avpkt = av_packet_alloc();
+AVPacket *parsepkt = av_packet_alloc();
+if (!frame || !avpkt || !parsepkt)
 error("Failed memory allocation");
 
 // Read very simple container
-AVPacket avpkt, parsepkt;
-av_init_packet(&avpkt);
-av_init_packet(&parsepkt);
 while (data < end && it < maxiteration) {
 // Search for the TAG
 while (data + sizeof(fuzz_tag) < end) {
@@ -303,43 +302,42 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 if (data + sizeof(fuzz_tag) > end)
 data = end;
 
-res = av_new_packet(&parsepkt, data - last);
+res = av_new_packet(parsepkt, data - last);
 if (res < 0)
 error("Failed memory allocation");
-memcpy(parsepkt.data, last, data - last);
-parsepkt.flags = (keyframes & 1) * AV_PKT_FLAG_DISCARD + (!!(keyframes 
& 2)) * AV_PKT_FLAG_KEY;
+memcpy(parsepkt->data, last, data - last);
+parsepkt->flags = (keyframes & 1) * AV_PKT_FLAG_DISCARD + 
(!!(keyframes & 2)) * AV_PKT_FLAG_KEY;
 keyframes = (keyframes >> 2) + (keyframes<<62);
 data += sizeof(fuzz_tag);
 last = data;
 
-while (parsepkt.size > 0) {
+while (parsepkt->size > 0) {
 int decode_more;
 
 if (parser) {
-av_init_packet(&avpkt);
-int ret = av_parser_parse2(parser, parser_avctx, &avpkt.data, 
&avpkt.size,
-   parsepkt.data, parsepkt.size,
-   parsepkt.pts, parsepkt.dts, 
parsepkt.pos);
-if (avpkt.data == parsepkt.data) {
-avpkt.buf = av_buffer_ref(parsepkt.buf);
-if (!avpkt.buf)
+int ret = av_parser_parse2(parser, parser_avctx, &avpkt->data, 
&avpkt->size,
+   parsepkt->data, parsepkt->size,
+   parsepkt->pts, parsepkt->dts, 
parsepkt->pos);
+if (avpkt->data == parsepkt->data) {
+avpkt->buf = av_buffer_ref(parsepkt->buf);
+if (!avpkt->buf)
 error("Failed memory allocation");
 } else {
-if (av_packet_make_refcounted(&avpkt) < 0)
+if (av_packet_make_refcounted(avpkt) < 0)
 error("Failed memory allocation");
 }
-parsepkt.data += ret;
-parsepkt.size -= ret;
-parsepkt.pos  += ret;
-avpkt.pts = parser->pts;
-avpkt.dts = parser->dts;
-avpkt.pos = parser->pos;
+parsepkt->data += ret;
+parsepkt->size -= ret;
+parsepkt->pos  += ret;
+avpkt->pts = parser->pts;
+avpkt->dts = parser->dts;
+avpkt->pos = parser->pos;
 if ( parser->key_frame == 1 ||
 (parser->key_frame == -1 && parser->pict_type == 
AV_PICTURE_TYPE_I))
-avpkt.flags |= AV_PKT_FLAG_KEY;
-avpkt.flags |= parsepkt.flags & AV_PKT_FLAG_DISCARD;
+avpkt->flags |= AV_PKT_FLAG_KEY;
+avpkt->flags |= parsepkt->flags & AV_PKT_FLAG_DISCARD;
 } else {
-av_packet_move_ref(&avpkt, &parsepkt);
+av_packet_move_ref(avpkt, parsepkt);
 }
 
   if (!(flushpattern & 7))
@@ -347,7 +345,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
   flushpattern = (flushpattern >> 3) + (flushpattern << 61);
 
   if (ctx->codec_type != AVMEDIA_TYPE_SUBTITLE) {
-  int ret = avcodec_send_packet(ctx, &avpkt);
+  int ret = avcodec_send_packet(ctx, avpkt);
   decode_more = ret >= 0;
   } else
   decode_more = 1;
@@ -355,7 +353,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
   // Iterate through all data
   while (decode_more && it++ < maxiteration) {
 av_frame_unref(frame);
-int ret = decode_handler(ctx, frame, &got_frame, &avpkt);
+int ret = decode_handler(ctx, frame, &got_frame, avpkt);
 
 ec_pixels += (ctx->width + 32LL) * (ctx->height + 32LL);
 if (it > 20 || ec_pixels > 4 * ctx->max_pixels)
@@ -365,30 +363,30 @@ int LLVMFuzzerTestOneInput(con

[FFmpeg-devel] [PATCH 40/50] tools/target_dem_fuzzer: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 tools/target_dem_fuzzer.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/tools/target_dem_fuzzer.c b/tools/target_dem_fuzzer.c
index 8ff98af945..af1840b359 100644
--- a/tools/target_dem_fuzzer.c
+++ b/tools/target_dem_fuzzer.c
@@ -96,7 +96,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
 const uint64_t fuzz_tag = FUZZ_TAG;
 uint32_t it = 0;
 AVFormatContext *avfmt = avformat_alloc_context();
-AVPacket pkt;
+AVPacket *pkt;
 char filename[1025] = {0};
 AVIOContext *fuzzed_pb = NULL;
 uint8_t *io_buffer;
@@ -165,6 +165,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 if (!io_buffer_size || size / io_buffer_size > maxblocks)
 io_buffer_size = size;
 
+pkt = av_packet_alloc();
+if (!pkt)
+error("Failed to allocate pkt");
+
 io_buffer = av_malloc(io_buffer_size);
 if (!io_buffer)
 error("Failed to allocate io_buffer");
@@ -190,17 +194,16 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 
 ret = avformat_find_stream_info(avfmt, NULL);
 
-av_init_packet(&pkt);
-
 //TODO, test seeking
 
 for(it = 0; it < maxiteration; it++) {
-ret = av_read_frame(avfmt, &pkt);
+ret = av_read_frame(avfmt, pkt);
 if (ret < 0)
 break;
-av_packet_unref(&pkt);
+av_packet_unref(pkt);
 }
 
+av_packet_free(&pkt);
 av_freep(&fuzzed_pb->buffer);
 avio_context_free(&fuzzed_pb);
 avformat_close_input(&avfmt);
-- 
2.30.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".

[FFmpeg-devel] [PATCH 41/50] tools/target_bsf_fuzzer: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 tools/target_bsf_fuzzer.c | 33 ++---
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/tools/target_bsf_fuzzer.c b/tools/target_bsf_fuzzer.c
index 8781a93ac3..bab809162a 100644
--- a/tools/target_bsf_fuzzer.c
+++ b/tools/target_bsf_fuzzer.c
@@ -42,7 +42,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
 const uint8_t *last = data;
 const uint8_t *end = data + size;
 AVBSFContext *bsf = NULL;
-AVPacket in, out;
+AVPacket *in, *out;
 uint64_t keyframes = 0;
 uint64_t flushpattern = -1;
 int res;
@@ -119,10 +119,11 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 return 0; // Failure of av_bsf_init() does not imply that a issue was 
found
 }
 
-av_init_packet(&in);
-av_init_packet(&out);
-out.data = NULL;
-out.size = 0;
+in = av_packet_alloc();
+out = av_packet_alloc();
+if (!in || !out)
+error("Failed memory allocation");
+
 while (data < end) {
 // Search for the TAG
 while (data + sizeof(fuzz_tag) < end) {
@@ -133,11 +134,11 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 if (data + sizeof(fuzz_tag) > end)
 data = end;
 
-res = av_new_packet(&in, data - last);
+res = av_new_packet(in, data - last);
 if (res < 0)
 error("Failed memory allocation");
-memcpy(in.data, last, data - last);
-in.flags = (keyframes & 1) * AV_PKT_FLAG_DISCARD + (!!(keyframes & 2)) 
* AV_PKT_FLAG_KEY;
+memcpy(in->data, last, data - last);
+in->flags = (keyframes & 1) * AV_PKT_FLAG_DISCARD + (!!(keyframes & 
2)) * AV_PKT_FLAG_KEY;
 keyframes = (keyframes >> 2) + (keyframes<<62);
 data += sizeof(fuzz_tag);
 last = data;
@@ -146,26 +147,28 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 av_bsf_flush(bsf);
 flushpattern = (flushpattern >> 3) + (flushpattern << 61);
 
-while (in.size) {
-res = av_bsf_send_packet(bsf, &in);
+while (in->size) {
+res = av_bsf_send_packet(bsf, in);
 if (res < 0 && res != AVERROR(EAGAIN))
 break;
-res = av_bsf_receive_packet(bsf, &out);
+res = av_bsf_receive_packet(bsf, out);
 if (res < 0)
 break;
-av_packet_unref(&out);
+av_packet_unref(out);
 }
-av_packet_unref(&in);
+av_packet_unref(in);
 }
 
 res = av_bsf_send_packet(bsf, NULL);
 while (!res) {
-res = av_bsf_receive_packet(bsf, &out);
+res = av_bsf_receive_packet(bsf, out);
 if (res < 0)
 break;
-av_packet_unref(&out);
+av_packet_unref(out);
 }
 
+av_packet_free(&in);
+av_packet_free(&out);
 av_bsf_free(&bsf);
 return 0;
 }
-- 
2.30.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".

[FFmpeg-devel] [PATCH 42/50] tests/api/api-flac-test: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 tests/api/api-flac-test.c | 21 -
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/tests/api/api-flac-test.c b/tests/api/api-flac-test.c
index 3fea3258f3..4ce62ed8ba 100644
--- a/tests/api/api-flac-test.c
+++ b/tests/api/api-flac-test.c
@@ -108,7 +108,7 @@ static int init_decoder(AVCodec *dec, AVCodecContext 
**dec_ctx,
 static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx,
 AVCodecContext *dec_ctx)
 {
-AVPacket enc_pkt;
+AVPacket *enc_pkt;
 AVFrame *in_frame, *out_frame;
 uint8_t *raw_in = NULL, *raw_out = NULL;
 int in_offset = 0, out_offset = 0;
@@ -117,6 +117,12 @@ static int run_test(AVCodec *enc, AVCodec *dec, 
AVCodecContext *enc_ctx,
 int i = 0;
 int in_frame_bytes, out_frame_bytes;
 
+enc_pkt = av_packet_alloc();
+if (!enc_pkt) {
+av_log(NULL, AV_LOG_ERROR, "Can't allocate output packet\n");
+return AVERROR(ENOMEM);
+}
+
 in_frame = av_frame_alloc();
 if (!in_frame) {
 av_log(NULL, AV_LOG_ERROR, "Can't allocate input frame\n");
@@ -150,10 +156,6 @@ static int run_test(AVCodec *enc, AVCodec *dec, 
AVCodecContext *enc_ctx,
 }
 
 for (i = 0; i < NUMBER_OF_AUDIO_FRAMES; i++) {
-av_init_packet(&enc_pkt);
-enc_pkt.data = NULL;
-enc_pkt.size = 0;
-
 generate_raw_frame((uint16_t*)(in_frame->data[0]), i, 
enc_ctx->sample_rate,
enc_ctx->channels, enc_ctx->frame_size);
 in_frame_bytes = in_frame->nb_samples * in_frame->channels * 
sizeof(uint16_t);
@@ -163,7 +165,7 @@ static int run_test(AVCodec *enc, AVCodec *dec, 
AVCodecContext *enc_ctx,
 }
 memcpy(raw_in + in_offset, in_frame->data[0], in_frame_bytes);
 in_offset += in_frame_bytes;
-result = avcodec_encode_audio2(enc_ctx, &enc_pkt, in_frame, 
&got_output);
+result = avcodec_encode_audio2(enc_ctx, enc_pkt, in_frame, 
&got_output);
 if (result < 0) {
 av_log(NULL, AV_LOG_ERROR, "Error encoding audio frame\n");
 return result;
@@ -171,14 +173,14 @@ static int run_test(AVCodec *enc, AVCodec *dec, 
AVCodecContext *enc_ctx,
 
 /* if we get an encoded packet, feed it straight to the decoder */
 if (got_output) {
-result = avcodec_decode_audio4(dec_ctx, out_frame, &got_output, 
&enc_pkt);
+result = avcodec_decode_audio4(dec_ctx, out_frame, &got_output, 
enc_pkt);
 if (result < 0) {
 av_log(NULL, AV_LOG_ERROR, "Error decoding audio packet\n");
 return result;
 }
 
 if (got_output) {
-if (result != enc_pkt.size) {
+if (result != enc_pkt->size) {
 av_log(NULL, AV_LOG_INFO, "Decoder consumed only part of a 
packet, it is allowed to do so -- need to update this test\n");
 return AVERROR_UNKNOWN;
 }
@@ -206,7 +208,7 @@ static int run_test(AVCodec *enc, AVCodec *dec, 
AVCodecContext *enc_ctx,
 out_offset += out_frame_bytes;
 }
 }
-av_packet_unref(&enc_pkt);
+av_packet_unref(enc_pkt);
 }
 
 if (memcmp(raw_in, raw_out, out_frame_bytes * NUMBER_OF_AUDIO_FRAMES) != 
0) {
@@ -218,6 +220,7 @@ static int run_test(AVCodec *enc, AVCodec *dec, 
AVCodecContext *enc_ctx,
 
 av_freep(&raw_in);
 av_freep(&raw_out);
+av_packet_free(&enc_pkt);
 av_frame_free(&in_frame);
 av_frame_free(&out_frame);
 return 0;
-- 
2.30.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".

[FFmpeg-devel] [PATCH 43/50] doc/examples/demuxing_decoding: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 doc/examples/demuxing_decoding.c | 25 ++---
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/doc/examples/demuxing_decoding.c b/doc/examples/demuxing_decoding.c
index 803e35d25c..db5e0cb951 100644
--- a/doc/examples/demuxing_decoding.c
+++ b/doc/examples/demuxing_decoding.c
@@ -51,7 +51,7 @@ static int video_dst_bufsize;
 
 static int video_stream_idx = -1, audio_stream_idx = -1;
 static AVFrame *frame = NULL;
-static AVPacket pkt;
+static AVPacket *pkt = NULL;
 static int video_frame_count = 0;
 static int audio_frame_count = 0;
 
@@ -303,10 +303,12 @@ int main (int argc, char **argv)
 goto end;
 }
 
-/* initialize packet, set data to NULL, let the demuxer fill it */
-av_init_packet(&pkt);
-pkt.data = NULL;
-pkt.size = 0;
+pkt = av_packet_alloc();
+if (!pkt) {
+fprintf(stderr, "Could not allocate packet\n");
+ret = AVERROR(ENOMEM);
+goto end;
+}
 
 if (video_stream)
 printf("Demuxing video from file '%s' into '%s'\n", src_filename, 
video_dst_filename);
@@ -314,14 +316,14 @@ int main (int argc, char **argv)
 printf("Demuxing audio from file '%s' into '%s'\n", src_filename, 
audio_dst_filename);
 
 /* read frames from the file */
-while (av_read_frame(fmt_ctx, &pkt) >= 0) {
+while (av_read_frame(fmt_ctx, pkt) >= 0) {
 // check if the packet belongs to a stream we are interested in, 
otherwise
 // skip it
-if (pkt.stream_index == video_stream_idx)
-ret = decode_packet(video_dec_ctx, &pkt);
-else if (pkt.stream_index == audio_stream_idx)
-ret = decode_packet(audio_dec_ctx, &pkt);
-av_packet_unref(&pkt);
+if (pkt->stream_index == video_stream_idx)
+ret = decode_packet(video_dec_ctx, pkt);
+else if (pkt->stream_index == audio_stream_idx)
+ret = decode_packet(audio_dec_ctx, pkt);
+av_packet_unref(pkt);
 if (ret < 0)
 break;
 }
@@ -372,6 +374,7 @@ end:
 fclose(video_dst_file);
 if (audio_dst_file)
 fclose(audio_dst_file);
+av_packet_free(&pkt);
 av_frame_free(&frame);
 av_free(video_dst_data[0]);
 
-- 
2.30.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".

[FFmpeg-devel] [PATCH 44/50] doc/examples/transcode_aac: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 doc/examples/transcode_aac.c | 46 +---
 1 file changed, 27 insertions(+), 19 deletions(-)

diff --git a/doc/examples/transcode_aac.c b/doc/examples/transcode_aac.c
index e0c76f5b35..73786ab59b 100644
--- a/doc/examples/transcode_aac.c
+++ b/doc/examples/transcode_aac.c
@@ -245,14 +245,16 @@ cleanup:
 
 /**
  * Initialize one data packet for reading or writing.
- * @param packet Packet to be initialized
+ * @param[out] packet Packet to be initialized
+ * @return Error code (0 if successful)
  */
-static void init_packet(AVPacket *packet)
+static int init_packet(AVPacket **packet)
 {
-av_init_packet(packet);
-/* Set the packet data and size so that it is recognized as being empty. */
-packet->data = NULL;
-packet->size = 0;
+if (!(*packet = av_packet_alloc())) {
+fprintf(stderr, "Could not allocate packet\n");
+return AVERROR(ENOMEM);
+}
+return 0;
 }
 
 /**
@@ -371,28 +373,31 @@ static int decode_audio_frame(AVFrame *frame,
   int *data_present, int *finished)
 {
 /* Packet used for temporary storage. */
-AVPacket input_packet;
+AVPacket *input_packet;
 int error;
-init_packet(&input_packet);
+
+error = init_packet(&input_packet);
+if (error < 0)
+return error;
 
 /* Read one audio frame from the input file into a temporary packet. */
-if ((error = av_read_frame(input_format_context, &input_packet)) < 0) {
+if ((error = av_read_frame(input_format_context, input_packet)) < 0) {
 /* If we are at the end of the file, flush the decoder below. */
 if (error == AVERROR_EOF)
 *finished = 1;
 else {
 fprintf(stderr, "Could not read frame (error '%s')\n",
 av_err2str(error));
-return error;
+goto cleanup;
 }
 }
 
 /* Send the audio frame stored in the temporary packet to the decoder.
  * The input audio stream decoder is used to do this. */
-if ((error = avcodec_send_packet(input_codec_context, &input_packet)) < 0) 
{
+if ((error = avcodec_send_packet(input_codec_context, input_packet)) < 0) {
 fprintf(stderr, "Could not send packet for decoding (error '%s')\n",
 av_err2str(error));
-return error;
+goto cleanup;
 }
 
 /* Receive one frame from the decoder. */
@@ -418,7 +423,7 @@ static int decode_audio_frame(AVFrame *frame,
 }
 
 cleanup:
-av_packet_unref(&input_packet);
+av_packet_free(&input_packet);
 return error;
 }
 
@@ -661,9 +666,12 @@ static int encode_audio_frame(AVFrame *frame,
   int *data_present)
 {
 /* Packet used for temporary storage. */
-AVPacket output_packet;
+AVPacket *output_packet;
 int error;
-init_packet(&output_packet);
+
+error = init_packet(&output_packet);
+if (error < 0)
+return error;
 
 /* Set a timestamp based on the sample rate for the container. */
 if (frame) {
@@ -681,11 +689,11 @@ static int encode_audio_frame(AVFrame *frame,
 } else if (error < 0) {
 fprintf(stderr, "Could not send packet for encoding (error '%s')\n",
 av_err2str(error));
-return error;
+goto cleanup;
 }
 
 /* Receive one encoded frame from the encoder. */
-error = avcodec_receive_packet(output_codec_context, &output_packet);
+error = avcodec_receive_packet(output_codec_context, output_packet);
 /* If the encoder asks for more data to be able to provide an
  * encoded frame, return indicating that no data is present. */
 if (error == AVERROR(EAGAIN)) {
@@ -706,14 +714,14 @@ static int encode_audio_frame(AVFrame *frame,
 
 /* Write one audio frame from the temporary packet to the output file. */
 if (*data_present &&
-(error = av_write_frame(output_format_context, &output_packet)) < 0) {
+(error = av_write_frame(output_format_context, output_packet)) < 0) {
 fprintf(stderr, "Could not write frame (error '%s')\n",
 av_err2str(error));
 goto cleanup;
 }
 
 cleanup:
-av_packet_unref(&output_packet);
+av_packet_free(&output_packet);
 return error;
 }
 
-- 
2.30.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".

[FFmpeg-devel] [PATCH 45/50] doc/examples/transcoding: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 doc/examples/transcoding.c | 48 ++
 1 file changed, 28 insertions(+), 20 deletions(-)

diff --git a/doc/examples/transcoding.c b/doc/examples/transcoding.c
index 5aff08c135..6ca3089330 100644
--- a/doc/examples/transcoding.c
+++ b/doc/examples/transcoding.c
@@ -42,6 +42,7 @@ typedef struct FilteringContext {
 AVFilterContext *buffersrc_ctx;
 AVFilterGraph *filter_graph;
 
+AVPacket *enc_pkt;
 AVFrame *filtered_frame;
 } FilteringContext;
 static FilteringContext *filter_ctx;
@@ -407,6 +408,10 @@ static int init_filters(void)
 if (ret)
 return ret;
 
+filter_ctx[i].enc_pkt = av_packet_alloc();
+if (!filter_ctx[i].enc_pkt)
+return AVERROR(ENOMEM);
+
 filter_ctx[i].filtered_frame = av_frame_alloc();
 if (!filter_ctx[i].filtered_frame)
 return AVERROR(ENOMEM);
@@ -414,17 +419,17 @@ static int init_filters(void)
 return 0;
 }
 
-static int encode_write_frame(AVFrame *filt_frame, unsigned int stream_index)
+static int encode_write_frame(unsigned int stream_index, int flush)
 {
 StreamContext *stream = &stream_ctx[stream_index];
+FilteringContext *filter = &filter_ctx[stream_index];
+AVFrame *filt_frame = flush ? NULL : filter->filtered_frame;
+AVPacket *enc_pkt = filter->enc_pkt;
 int ret;
-AVPacket enc_pkt;
 
 av_log(NULL, AV_LOG_INFO, "Encoding frame\n");
 /* encode filtered frame */
-enc_pkt.data = NULL;
-enc_pkt.size = 0;
-av_init_packet(&enc_pkt);
+av_packet_unref(enc_pkt);
 
 ret = avcodec_send_frame(stream->enc_ctx, filt_frame);
 
@@ -432,20 +437,20 @@ static int encode_write_frame(AVFrame *filt_frame, 
unsigned int stream_index)
 return ret;
 
 while (ret >= 0) {
-ret = avcodec_receive_packet(stream->enc_ctx, &enc_pkt);
+ret = avcodec_receive_packet(stream->enc_ctx, enc_pkt);
 
 if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
 return 0;
 
 /* prepare packet for muxing */
-enc_pkt.stream_index = stream_index;
-av_packet_rescale_ts(&enc_pkt,
+enc_pkt->stream_index = stream_index;
+av_packet_rescale_ts(enc_pkt,
  stream->enc_ctx->time_base,
  ofmt_ctx->streams[stream_index]->time_base);
 
 av_log(NULL, AV_LOG_DEBUG, "Muxing frame\n");
 /* mux encoded frame */
-ret = av_interleaved_write_frame(ofmt_ctx, &enc_pkt);
+ret = av_interleaved_write_frame(ofmt_ctx, enc_pkt);
 }
 
 return ret;
@@ -481,7 +486,7 @@ static int filter_encode_write_frame(AVFrame *frame, 
unsigned int stream_index)
 }
 
 filter->filtered_frame->pict_type = AV_PICTURE_TYPE_NONE;
-ret = encode_write_frame(filter->filtered_frame, stream_index);
+ret = encode_write_frame(stream_index, 0);
 av_frame_unref(filter->filtered_frame);
 if (ret < 0)
 break;
@@ -497,13 +502,13 @@ static int flush_encoder(unsigned int stream_index)
 return 0;
 
 av_log(NULL, AV_LOG_INFO, "Flushing stream #%u encoder\n", stream_index);
-return encode_write_frame(NULL, stream_index);
+return encode_write_frame(stream_index, 1);
 }
 
 int main(int argc, char **argv)
 {
 int ret;
-AVPacket packet = { .data = NULL, .size = 0 };
+AVPacket *packet = NULL;
 unsigned int stream_index;
 unsigned int i;
 
@@ -518,12 +523,14 @@ int main(int argc, char **argv)
 goto end;
 if ((ret = init_filters()) < 0)
 goto end;
+if (!(packet = av_packet_alloc()))
+goto end;
 
 /* read all packets */
 while (1) {
-if ((ret = av_read_frame(ifmt_ctx, &packet)) < 0)
+if ((ret = av_read_frame(ifmt_ctx, packet)) < 0)
 break;
-stream_index = packet.stream_index;
+stream_index = packet->stream_index;
 av_log(NULL, AV_LOG_DEBUG, "Demuxer gave frame of stream_index %u\n",
 stream_index);
 
@@ -532,10 +539,10 @@ int main(int argc, char **argv)
 
 av_log(NULL, AV_LOG_DEBUG, "Going to reencode&filter the frame\n");
 
-av_packet_rescale_ts(&packet,
+av_packet_rescale_ts(packet,
  ifmt_ctx->streams[stream_index]->time_base,
  stream->dec_ctx->time_base);
-ret = avcodec_send_packet(stream->dec_ctx, &packet);
+ret = avcodec_send_packet(stream->dec_ctx, packet);
 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Decoding failed\n");
 break;
@@ -555,15 +562,15 @@ int main(int argc, char **argv)
 }
 } else {
 /* remux this frame without reencoding */
-av_packet_rescale_ts(&packet,
+av_packet_rescale_ts(packet,
  ifmt_ctx->streams[stream_index]->time_base,
   

[FFmpeg-devel] [PATCH 46/50] doc/examples/vaapi_encode: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 doc/examples/vaapi_encode.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/doc/examples/vaapi_encode.c b/doc/examples/vaapi_encode.c
index 707939db37..66cb949cdc 100644
--- a/doc/examples/vaapi_encode.c
+++ b/doc/examples/vaapi_encode.c
@@ -74,27 +74,27 @@ static int set_hwframe_ctx(AVCodecContext *ctx, AVBufferRef 
*hw_device_ctx)
 static int encode_write(AVCodecContext *avctx, AVFrame *frame, FILE *fout)
 {
 int ret = 0;
-AVPacket enc_pkt;
+AVPacket *enc_pkt;
 
-av_init_packet(&enc_pkt);
-enc_pkt.data = NULL;
-enc_pkt.size = 0;
+if (!(enc_pkt = av_packet_alloc()))
+return AVERROR(ENOMEM);
 
 if ((ret = avcodec_send_frame(avctx, frame)) < 0) {
 fprintf(stderr, "Error code: %s\n", av_err2str(ret));
 goto end;
 }
 while (1) {
-ret = avcodec_receive_packet(avctx, &enc_pkt);
+ret = avcodec_receive_packet(avctx, enc_pkt);
 if (ret)
 break;
 
-enc_pkt.stream_index = 0;
-ret = fwrite(enc_pkt.data, enc_pkt.size, 1, fout);
-av_packet_unref(&enc_pkt);
+enc_pkt->stream_index = 0;
+ret = fwrite(enc_pkt.data, enc_pkt->size, 1, fout);
+av_packet_unref(enc_pkt);
 }
 
 end:
+av_packet_free(&enc_pkt);
 ret = ((ret == AVERROR(EAGAIN)) ? 0 : -1);
 return ret;
 }
-- 
2.30.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".

[FFmpeg-devel] [PATCH 47/50] doc/examples/vaapi_transcode: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 doc/examples/vaapi_transcode.c | 45 --
 1 file changed, 26 insertions(+), 19 deletions(-)

diff --git a/doc/examples/vaapi_transcode.c b/doc/examples/vaapi_transcode.c
index 279d20f636..5fc09dd1d3 100644
--- a/doc/examples/vaapi_transcode.c
+++ b/doc/examples/vaapi_transcode.c
@@ -109,28 +109,23 @@ static int open_input_file(const char *filename)
 return ret;
 }
 
-static int encode_write(AVFrame *frame)
+static int encode_write(AVPacket *enc_pkt, AVFrame *frame)
 {
 int ret = 0;
-AVPacket enc_pkt;
-
-av_init_packet(&enc_pkt);
-enc_pkt.data = NULL;
-enc_pkt.size = 0;
 
 if ((ret = avcodec_send_frame(encoder_ctx, frame)) < 0) {
 fprintf(stderr, "Error during encoding. Error code: %s\n", 
av_err2str(ret));
 goto end;
 }
 while (1) {
-ret = avcodec_receive_packet(encoder_ctx, &enc_pkt);
+ret = avcodec_receive_packet(encoder_ctx, enc_pkt);
 if (ret)
 break;
 
-enc_pkt.stream_index = 0;
-av_packet_rescale_ts(&enc_pkt, 
ifmt_ctx->streams[video_stream]->time_base,
+enc_pkt->stream_index = 0;
+av_packet_rescale_ts(enc_pkt, 
ifmt_ctx->streams[video_stream]->time_base,
  ofmt_ctx->streams[0]->time_base);
-ret = av_interleaved_write_frame(ofmt_ctx, &enc_pkt);
+ret = av_interleaved_write_frame(ofmt_ctx, enc_pkt);
 if (ret < 0) {
 fprintf(stderr, "Error during writing data to output file. "
 "Error code: %s\n", av_err2str(ret));
@@ -148,6 +143,7 @@ end:
 static int dec_enc(AVPacket *pkt, AVCodec *enc_codec)
 {
 AVFrame *frame;
+AVPacket *enc_pkt;
 int ret = 0;
 
 ret = avcodec_send_packet(decoder_ctx, pkt);
@@ -159,10 +155,15 @@ static int dec_enc(AVPacket *pkt, AVCodec *enc_codec)
 while (ret >= 0) {
 if (!(frame = av_frame_alloc()))
 return AVERROR(ENOMEM);
+if (!(enc_pkt = av_packet_alloc())) {
+av_frame_free(&frame);
+return AVERROR(ENOMEM);
+}
 
 ret = avcodec_receive_frame(decoder_ctx, frame);
 if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
 av_frame_free(&frame);
+av_packet_free(&enc_pkt);
 return 0;
 } else if (ret < 0) {
 fprintf(stderr, "Error while decoding. Error code: %s\n", 
av_err2str(ret));
@@ -216,11 +217,12 @@ static int dec_enc(AVPacket *pkt, AVCodec *enc_codec)
 initialized = 1;
 }
 
-if ((ret = encode_write(frame)) < 0)
+if ((ret = encode_write(enc_pkt, frame)) < 0)
 fprintf(stderr, "Error during encoding and writing.\n");
 
 fail:
 av_frame_free(&frame);
+av_packet_free(&enc_pkt);
 if (ret < 0)
 return ret;
 }
@@ -230,7 +232,7 @@ fail:
 int main(int argc, char **argv)
 {
 int ret = 0;
-AVPacket dec_pkt;
+AVPacket *dec_pkt;
 AVCodec *enc_codec;
 
 if (argc != 4) {
@@ -246,6 +248,12 @@ int main(int argc, char **argv)
 return -1;
 }
 
+dec_pkt = av_packet_alloc();
+if (!dec_pkt) {
+fprintf(stderr, "Failed to allocate decode packet\n");
+goto end;
+}
+
 if ((ret = open_input_file(argv[1])) < 0)
 goto end;
 
@@ -275,20 +283,18 @@ int main(int argc, char **argv)
 
 /* read all packets and only transcoding video */
 while (ret >= 0) {
-if ((ret = av_read_frame(ifmt_ctx, &dec_pkt)) < 0)
+if ((ret = av_read_frame(ifmt_ctx, dec_pkt)) < 0)
 break;
 
-if (video_stream == dec_pkt.stream_index)
-ret = dec_enc(&dec_pkt, enc_codec);
+if (video_stream == dec_pkt->stream_index)
+ret = dec_enc(dec_pkt, enc_codec);
 
-av_packet_unref(&dec_pkt);
+av_packet_unref(dec_pkt);
 }
 
 /* flush decoder */
-dec_pkt.data = NULL;
-dec_pkt.size = 0;
-ret = dec_enc(&dec_pkt, enc_codec);
 av_packet_unref(&dec_pkt);
+ret = dec_enc(dec_pkt, enc_codec);
 
 /* flush encoder */
 ret = encode_write(NULL);
@@ -302,5 +308,6 @@ end:
 avcodec_free_context(&decoder_ctx);
 avcodec_free_context(&encoder_ctx);
 av_buffer_unref(&hw_device_ctx);
+av_packet_free(&dec_pkt);
 return ret;
 }
-- 
2.30.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".

[FFmpeg-devel] [PATCH 48/50] fftools/ffprobe: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 fftools/ffprobe.c | 34 +++---
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 3453aa09ff..68fecd61e5 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -2465,14 +2465,12 @@ static int read_interval_packets(WriterContext *w, 
InputFile *ifile,
  const ReadInterval *interval, int64_t *cur_ts)
 {
 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
-AVPacket pkt;
+AVPacket *pkt = NULL;
 AVFrame *frame = NULL;
 int ret = 0, i = 0, frame_count = 0;
 int64_t start = -INT64_MAX, end = interval->end;
 int has_start = 0, has_end = interval->has_end && !interval->end_is_offset;
 
-av_init_packet(&pkt);
-
 av_log(NULL, AV_LOG_VERBOSE, "Processing read interval ");
 log_read_interval(interval, NULL, AV_LOG_VERBOSE);
 
@@ -2505,18 +2503,23 @@ static int read_interval_packets(WriterContext *w, 
InputFile *ifile,
 ret = AVERROR(ENOMEM);
 goto end;
 }
-while (!av_read_frame(fmt_ctx, &pkt)) {
+pkt = av_packet_alloc();
+if (!pkt) {
+ret = AVERROR(ENOMEM);
+goto end;
+}
+while (!av_read_frame(fmt_ctx, pkt)) {
 if (fmt_ctx->nb_streams > nb_streams) {
 REALLOCZ_ARRAY_STREAM(nb_streams_frames,  nb_streams, 
fmt_ctx->nb_streams);
 REALLOCZ_ARRAY_STREAM(nb_streams_packets, nb_streams, 
fmt_ctx->nb_streams);
 REALLOCZ_ARRAY_STREAM(selected_streams,   nb_streams, 
fmt_ctx->nb_streams);
 nb_streams = fmt_ctx->nb_streams;
 }
-if (selected_streams[pkt.stream_index]) {
-AVRational tb = ifile->streams[pkt.stream_index].st->time_base;
+if (selected_streams[pkt->stream_index]) {
+AVRational tb = ifile->streams[pkt->stream_index].st->time_base;
 
-if (pkt.pts != AV_NOPTS_VALUE)
-*cur_ts = av_rescale_q(pkt.pts, tb, AV_TIME_BASE_Q);
+if (pkt->pts != AV_NOPTS_VALUE)
+*cur_ts = av_rescale_q(pkt->pts, tb, AV_TIME_BASE_Q);
 
 if (!has_start && *cur_ts != AV_NOPTS_VALUE) {
 start = *cur_ts;
@@ -2538,26 +2541,27 @@ static int read_interval_packets(WriterContext *w, 
InputFile *ifile,
 frame_count++;
 if (do_read_packets) {
 if (do_show_packets)
-show_packet(w, ifile, &pkt, i++);
-nb_streams_packets[pkt.stream_index]++;
+show_packet(w, ifile, pkt, i++);
+nb_streams_packets[pkt->stream_index]++;
 }
 if (do_read_frames) {
 int packet_new = 1;
-while (process_frame(w, ifile, frame, &pkt, &packet_new) > 0);
+while (process_frame(w, ifile, frame, pkt, &packet_new) > 0);
 }
 }
-av_packet_unref(&pkt);
+av_packet_unref(pkt);
 }
-av_packet_unref(&pkt);
+av_packet_unref(pkt);
 //Flush remaining frames that are cached in the decoder
 for (i = 0; i < fmt_ctx->nb_streams; i++) {
-pkt.stream_index = i;
+pkt->stream_index = i;
 if (do_read_frames)
-while (process_frame(w, ifile, frame, &pkt, &(int){1}) > 0);
+while (process_frame(w, ifile, frame, pkt, &(int){1}) > 0);
 }
 
 end:
 av_frame_free(&frame);
+av_packet_free(&pkt);
 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Could not read packets in interval ");
 log_read_interval(interval, NULL, AV_LOG_ERROR);
-- 
2.30.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".

[FFmpeg-devel] [PATCH 49/50] fftools/ffmpeg: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 fftools/ffmpeg.c | 318 +++
 fftools/ffmpeg.h |   4 +
 fftools/ffmpeg_opt.c |   5 +-
 3 files changed, 177 insertions(+), 150 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index d7c833be63..2667f226b4 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -592,6 +592,7 @@ static void ffmpeg_cleanup(int ret)
 
 av_frame_free(&ost->filtered_frame);
 av_frame_free(&ost->last_frame);
+av_packet_free(&ost->pkt);
 av_dict_free(&ost->encoder_opts);
 
 av_freep(&ost->forced_keyframes);
@@ -610,9 +611,9 @@ static void ffmpeg_cleanup(int ret)
 
 if (ost->muxing_queue) {
 while (av_fifo_size(ost->muxing_queue)) {
-AVPacket pkt;
+AVPacket *pkt;
 av_fifo_generic_read(ost->muxing_queue, &pkt, sizeof(pkt), 
NULL);
-av_packet_unref(&pkt);
+av_packet_free(&pkt);
 }
 av_fifo_freep(&ost->muxing_queue);
 }
@@ -624,6 +625,7 @@ static void ffmpeg_cleanup(int ret)
 #endif
 for (i = 0; i < nb_input_files; i++) {
 avformat_close_input(&input_files[i]->ctx);
+av_packet_free(&input_files[i]->pkt);
 av_freep(&input_files[i]);
 }
 for (i = 0; i < nb_input_streams; i++) {
@@ -631,6 +633,7 @@ static void ffmpeg_cleanup(int ret)
 
 av_frame_free(&ist->decoded_frame);
 av_frame_free(&ist->filter_frame);
+av_packet_free(&ist->pkt);
 av_dict_free(&ist->decoder_opts);
 avsubtitle_free(&ist->prev_sub.subtitle);
 av_frame_free(&ist->sub2video.frame);
@@ -746,7 +749,7 @@ static void write_packet(OutputFile *of, AVPacket *pkt, 
OutputStream *ost, int u
 }
 
 if (!of->header_written) {
-AVPacket tmp_pkt = {0};
+AVPacket *tmp_pkt;
 /* the muxer is not initialized yet, buffer the packet */
 if (!av_fifo_space(ost->muxing_queue)) {
 unsigned int are_we_over_size =
@@ -769,8 +772,11 @@ static void write_packet(OutputFile *of, AVPacket *pkt, 
OutputStream *ost, int u
 ret = av_packet_make_refcounted(pkt);
 if (ret < 0)
 exit_program(1);
-av_packet_move_ref(&tmp_pkt, pkt);
-ost->muxing_queue_data_size += tmp_pkt.size;
+tmp_pkt = av_packet_alloc();
+if (!tmp_pkt)
+exit_program(1);
+av_packet_move_ref(tmp_pkt, pkt);
+ost->muxing_queue_data_size += tmp_pkt->size;
 av_fifo_generic_write(ost->muxing_queue, &tmp_pkt, sizeof(tmp_pkt), 
NULL);
 return;
 }
@@ -999,13 +1005,9 @@ static void do_audio_out(OutputFile *of, OutputStream 
*ost,
  AVFrame *frame)
 {
 AVCodecContext *enc = ost->enc_ctx;
-AVPacket pkt;
+AVPacket *pkt = ost->pkt;
 int ret;
 
-av_init_packet(&pkt);
-pkt.data = NULL;
-pkt.size = 0;
-
 adjust_frame_pts_to_encoder_tb(of, ost, frame);
 
 if (!check_recording_time(ost))
@@ -1017,7 +1019,6 @@ static void do_audio_out(OutputFile *of, OutputStream 
*ost,
 ost->samples_encoded += frame->nb_samples;
 ost->frames_encoded++;
 
-av_assert0(pkt.size || !pkt.data);
 update_benchmark(NULL);
 if (debug_ts) {
 av_log(NULL, AV_LOG_INFO, "encoder <- type:audio "
@@ -1031,7 +1032,8 @@ static void do_audio_out(OutputFile *of, OutputStream 
*ost,
 goto error;
 
 while (1) {
-ret = avcodec_receive_packet(enc, &pkt);
+av_packet_unref(pkt);
+ret = avcodec_receive_packet(enc, pkt);
 if (ret == AVERROR(EAGAIN))
 break;
 if (ret < 0)
@@ -1039,16 +1041,16 @@ static void do_audio_out(OutputFile *of, OutputStream 
*ost,
 
 update_benchmark("encode_audio %d.%d", ost->file_index, ost->index);
 
-av_packet_rescale_ts(&pkt, enc->time_base, ost->mux_timebase);
+av_packet_rescale_ts(pkt, enc->time_base, ost->mux_timebase);
 
 if (debug_ts) {
 av_log(NULL, AV_LOG_INFO, "encoder -> type:audio "
"pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n",
-   av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, &enc->time_base),
-   av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, 
&enc->time_base));
+   av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, 
&enc->time_base),
+   av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, 
&enc->time_base));
 }
 
-output_packet(of, &pkt, ost, 0);
+output_packet(of, pkt, ost, 0);
 }
 
 return;
@@ -1064,7 +1066,7 @@ static void do_subtitle_out(OutputFile *of,
 int subtitle_out_max_size = 1024 * 1024;
 int subtitle_out_size, nb, i;
 AVCodecContext *enc;
-AVPacket pkt;
+AVPacket *pkt = ost->pkt;
 int64_t pts;
 
 if (sub->pts == AV_NOPTS_VALUE) {
@@ -1122,21 +1124,21 @@ static void do_subtitle_out(OutputFile *of,
 exit_program

[FFmpeg-devel] [PATCH 50/50] fftools/ffplay: use av_packet_alloc() to allocate packets

2021-02-04 Thread James Almer
Signed-off-by: James Almer 
---
 fftools/ffplay.c | 204 +--
 1 file changed, 127 insertions(+), 77 deletions(-)

diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index 9ff0425163..d48edc0797 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -36,6 +36,7 @@
 #include "libavutil/pixdesc.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/dict.h"
+#include "libavutil/fifo.h"
 #include "libavutil/parseutils.h"
 #include "libavutil/samplefmt.h"
 #include "libavutil/avassert.h"
@@ -111,13 +112,12 @@ const int program_birth_year = 2003;
 static unsigned sws_flags = SWS_BICUBIC;
 
 typedef struct MyAVPacketList {
-AVPacket pkt;
-struct MyAVPacketList *next;
+AVPacket *pkt;
 int serial;
 } MyAVPacketList;
 
 typedef struct PacketQueue {
-MyAVPacketList *first_pkt, *last_pkt;
+AVFifoBuffer *pkt_list;
 int nb_packets;
 int size;
 int64_t duration;
@@ -187,7 +187,8 @@ enum {
 };
 
 typedef struct Decoder {
-AVPacket pkt;
+AVPacket *pkt;
+AVPacket *tmp_pkt;
 PacketQueue *queue;
 AVCodecContext *avctx;
 int pkt_serial;
@@ -361,7 +362,7 @@ static int filter_nbthreads = 0;
 static int is_full_screen;
 static int64_t audio_callback_time;
 
-static AVPacket flush_pkt;
+static uint8_t flush_pkt;
 
 #define FF_QUIT_EVENT(SDL_USEREVENT + 2)
 
@@ -427,28 +428,25 @@ int64_t get_valid_channel_layout(int64_t channel_layout, 
int channels)
 
 static int packet_queue_put_private(PacketQueue *q, AVPacket *pkt)
 {
-MyAVPacketList *pkt1;
+MyAVPacketList pkt1;
 
 if (q->abort_request)
return -1;
 
-pkt1 = av_malloc(sizeof(MyAVPacketList));
-if (!pkt1)
-return -1;
-pkt1->pkt = *pkt;
-pkt1->next = NULL;
-if (pkt == &flush_pkt)
+if (av_fifo_space(q->pkt_list) < sizeof(pkt1)) {
+if (av_fifo_grow(q->pkt_list, sizeof(pkt1)) < 0)
+return -1;
+}
+
+if (pkt->data == &flush_pkt)
 q->serial++;
-pkt1->serial = q->serial;
+pkt1.pkt = pkt;
+pkt1.serial = q->serial;
 
-if (!q->last_pkt)
-q->first_pkt = pkt1;
-else
-q->last_pkt->next = pkt1;
-q->last_pkt = pkt1;
+av_fifo_generic_write(q->pkt_list, &pkt1, sizeof(pkt1), NULL);
 q->nb_packets++;
-q->size += pkt1->pkt.size + sizeof(*pkt1);
-q->duration += pkt1->pkt.duration;
+q->size += pkt1.pkt->size + sizeof(pkt1);
+q->duration += pkt1.pkt->duration;
 /* XXX: should duplicate packet data in DV case */
 SDL_CondSignal(q->cond);
 return 0;
@@ -456,32 +454,66 @@ static int packet_queue_put_private(PacketQueue *q, 
AVPacket *pkt)
 
 static int packet_queue_put(PacketQueue *q, AVPacket *pkt)
 {
+AVPacket *pkt1;
 int ret;
 
+pkt1 = av_packet_clone(pkt);
+if (!pkt1)
+   return -1;
 SDL_LockMutex(q->mutex);
-ret = packet_queue_put_private(q, pkt);
+ret = packet_queue_put_private(q, pkt1);
 SDL_UnlockMutex(q->mutex);
-
-if (pkt != &flush_pkt && ret < 0)
+if (ret < 0) {
+av_packet_free(&pkt1);
 av_packet_unref(pkt);
+}
+
+return ret;
+}
+
+static int packet_queue_put_flushpacket(PacketQueue *q)
+{
+AVPacket *pkt;
+int ret;
+
+pkt = av_packet_alloc();
+if (!pkt)
+   return -1;
+pkt->data = &flush_pkt;
+SDL_LockMutex(q->mutex);
+ret = packet_queue_put_private(q, pkt);
+SDL_UnlockMutex(q->mutex);
+if (ret < 0)
+av_packet_free(&pkt);
 
 return ret;
 }
 
 static int packet_queue_put_nullpacket(PacketQueue *q, int stream_index)
 {
-AVPacket pkt1, *pkt = &pkt1;
-av_init_packet(pkt);
-pkt->data = NULL;
-pkt->size = 0;
+AVPacket *pkt;
+int ret;
+
+pkt = av_packet_alloc();
+if (!pkt)
+   return -1;
 pkt->stream_index = stream_index;
-return packet_queue_put(q, pkt);
+SDL_LockMutex(q->mutex);
+ret = packet_queue_put_private(q, pkt);
+SDL_UnlockMutex(q->mutex);
+if (ret < 0)
+av_packet_free(&pkt);
+
+return ret;
 }
 
 /* packet queue handling */
 static int packet_queue_init(PacketQueue *q)
 {
 memset(q, 0, sizeof(PacketQueue));
+q->pkt_list = av_fifo_alloc(sizeof(MyAVPacketList));
+if (!q->pkt_list)
+return AVERROR(ENOMEM);
 q->mutex = SDL_CreateMutex();
 if (!q->mutex) {
 av_log(NULL, AV_LOG_FATAL, "SDL_CreateMutex(): %s\n", SDL_GetError());
@@ -498,16 +530,13 @@ static int packet_queue_init(PacketQueue *q)
 
 static void packet_queue_flush(PacketQueue *q)
 {
-MyAVPacketList *pkt, *pkt1;
+MyAVPacketList pkt1;
 
 SDL_LockMutex(q->mutex);
-for (pkt = q->first_pkt; pkt; pkt = pkt1) {
-pkt1 = pkt->next;
-av_packet_unref(&pkt->pkt);
-av_freep(&pkt);
+while (av_fifo_size(q->pkt_list) >= sizeof(pkt1)) {
+av_fifo_generic_read(q->pkt_list, &pkt1, sizeof(pkt1), NULL);
+av_packet_free(&pkt1.pkt);
 }
-q->last_pkt = NULL;
-q->first_pkt = NULL;
 q->nb_packets = 0