Re: [FFmpeg-devel] [PATCH v4 2/2] avformat/gopher: Add support for Gopher over TLS.

2021-03-05 Thread Ivan J.
Bump for review. Test instructions:

https://ffmpeg.org/pipermail/ffmpeg-devel/2021-February/276913.html


Best regards,
Ivan
___
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] configure: Fix bashism in openal check. (was: [PATCH] Bugfix for #9135)

2021-03-05 Thread Peter White
This is a test to check if my postfix setup does what I intend.
___
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/3] avcodec/codec: remove outdated comment about AVCodec.encode2()

2021-03-05 Thread James Almer
The packet passed as argument to this function hasn't contained
a user-provided buffer since 93016f5d1d.

Signed-off-by: James Almer 
---
 libavcodec/codec.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/codec.h b/libavcodec/codec.h
index 0ccbf0eb19..3d7a1f4c26 100644
--- a/libavcodec/codec.h
+++ b/libavcodec/codec.h
@@ -273,7 +273,7 @@ typedef struct AVCodec {
  * Encode data to an AVPacket.
  *
  * @param  avctx  codec context
- * @param  avpkt  output AVPacket (may contain a user-provided 
buffer)
+ * @param  avpkt  output AVPacket
  * @param[in]  frame  AVFrame containing the raw data to be encoded
  * @param[out] got_packet_ptr encoder sets to 0 or 1 to indicate that a
  *non-empty packet was returned in avpkt.
-- 
2.30.1

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

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

[FFmpeg-devel] [PATCH 3/3] avcodec/codec: add doxy to AVCodec.decode()

2021-03-05 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/codec.h | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/libavcodec/codec.h b/libavcodec/codec.h
index bcda061da1..c019e7357c 100644
--- a/libavcodec/codec.h
+++ b/libavcodec/codec.h
@@ -281,6 +281,17 @@ typedef struct AVCodec {
  */
 int (*encode2)(struct AVCodecContext *avctx, struct AVPacket *avpkt,
const struct AVFrame *frame, int *got_packet_ptr);
+/**
+ * Decode picture or subtitle data.
+ *
+ * @param  avctx  codec context
+ * @param  outdatacodec type dependent output struct
+ * @param[out] got_packet_ptr decoder sets to 0 or 1 to indicate that a
+ *non-empty frame or subtitle was returned in
+ *outdata.
+ * @param[in]  avpkt  AVPacket containing the bitstream to be 
decoded
+ * @return amount of bytes read from the packet, negative error code on 
failure
+ */
 int (*decode)(struct AVCodecContext *, void *outdata, int *got_frame_ptr,
   struct AVPacket *avpkt);
 int (*close)(struct AVCodecContext *);
-- 
2.30.1

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

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

[FFmpeg-devel] [PATCH 2/3] avcodec/codec: use the correct name for all AVCodec.decode() parameters

2021-03-05 Thread James Almer
This field hasn't been used to return the output frame size since
avcodec_decode_audio3() was removed.

Signed-off-by: James Almer 
---
 libavcodec/codec.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/codec.h b/libavcodec/codec.h
index 3d7a1f4c26..bcda061da1 100644
--- a/libavcodec/codec.h
+++ b/libavcodec/codec.h
@@ -281,7 +281,8 @@ typedef struct AVCodec {
  */
 int (*encode2)(struct AVCodecContext *avctx, struct AVPacket *avpkt,
const struct AVFrame *frame, int *got_packet_ptr);
-int (*decode)(struct AVCodecContext *, void *outdata, int *outdata_size, 
struct AVPacket *avpkt);
+int (*decode)(struct AVCodecContext *, void *outdata, int *got_frame_ptr,
+  struct AVPacket *avpkt);
 int (*close)(struct AVCodecContext *);
 /**
  * Encode API with decoupled frame/packet dataflow. This function is called
-- 
2.30.1

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

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

Re: [FFmpeg-devel] [PATCH 4/8] avcodec: Constify some AVPackets

2021-03-05 Thread Andreas Rheinhardt
James Almer:
> On 3/4/2021 12:42 PM, Andreas Rheinhardt wrote:
>> Signed-off-by: Andreas Rheinhardt 
>> ---
>> Of all the decoders using the simple decode API (i.e. with .decode set)
>> only imm5 seems to modify its input packet (which is fine given that it
>> is not the user-supplied reference);
> 
> Having that decoder make a writable copy using a different AVPacket
> struct, so the input one can be constified, sounds like a good idea in
> order to make the AVPacket parameter in AVCodec->decode() const (If
> that's what you're trying to achieve), and would be consistent with
> AVCodec->encode2().
> 

I was actually thinking about using const and casting it away in that
one decoder, but if you don't like this, I can modify it.

> For that matter, why is got_frame called "outdata_size" in codec.h? Did
> the purpose of that parameter change at some point?
> 
> libfdk_aac's API is not
>> const-correct, so as-is it is not compatible with constifiying the
>> AVPacket
>> in the .decode function, yet this is easily fixable.
>>
___
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/f_ebur128: add all sample rates support

2021-03-05 Thread Clément Bœsch
On Thu, Mar 04, 2021 at 04:05:53PM +0100, Paul B Mahol wrote:
[...]
> +double f0 = 1681.974450955533;
> +double G = 3.999843853973347;
> +double Q = 0.7071752369554196;
> +
> +double K = tan(M_PI * f0 / (double)inlink->sample_rate);
> +double Vh = pow(10.0, G / 20.0);
> +double Vb = pow(Vh, 0.4996667741545416);

Not a fan of these constants coming out of nowhere. Please add the
following comment in the code: "Unofficial reversed parametrization of pre
and RLB from 48kHz".

And in the commit description, please include the following:

The magic constants come from the unofficial "ITU-R BS.1770-1 filter
specifications"¹ by Raiden (libebur128) which relies on "Parameter
Quantization in Direct-Form Recursive Audio Filters"² by Brian
Neunaber.

The constants seem to include a quantization bias, for example:
- Vb is supposed to be exactly √Vh in a high shelf filter
- the Pre-filter Gain should likely be 4dB
- Pre Q and RLB Q are respectively very close to √½ and ½

Those are not adjusted to prevent the values from drifting away from
the official specifications.

An alternative to this approach would be to requantize on the fly as
proposed by pbelkner³, where the 48kHz code path would use the exact
specifications constants while derivating constants for other
frequencies.

[1]: https://www.scribd.com/document/49991813/ITU-R-BS-1770-1-filters
[2]: 
https://www.scribd.com/document/6531763/Direct-Form-Filter-Parameter-Quantization
[3]: https://hydrogenaud.io/index.php?topic=86116.msg740092#msg740092

Feel free to add more information if you have any. This will likely save a
lot of time for anyone looking into understanding and improving that code
in the future.

> +
> +double a0 = 1.0 + K / Q + K * K;
> +
> +ebur128->pre_b[0] = (Vh + Vb * K / Q + K * K) / a0;
> +ebur128->pre_b[1] = 2.0 * (K * K - Vh) / a0;
> +ebur128->pre_b[2] = (Vh - Vb * K / Q + K * K) / a0;
> +ebur128->pre_a[1] = 2.0 * (K * K - 1.0) / a0;
> +ebur128->pre_a[2] = (1.0 - K / Q + K * K) / a0;
> +
> +f0 = 38.13547087602444;
> +Q = 0.5003270373238773;
> +K = tan(M_PI * f0 / (double)inlink->sample_rate);
> +
> +ebur128->rlb_b[0] = 1.0;
> +ebur128->rlb_b[1] = -2.0;
> +ebur128->rlb_b[2] = 1.0;

> +ebur128->rlb_a[1] = 2.0 * (K * K - 1.0) / (1.0 + K / Q + K * K);
> +ebur128->rlb_a[2] = (1.0 - K / Q + K * K) / (1.0 + K / Q + K * K);

You can redefine a0 like with the pre filter and use it in these 2
expressions.

[...]

Regards,

-- 
Clément B.
___
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] configure: Fix bashism in openal check. (was: [PATCH] Bugfix for #9135)

2021-03-05 Thread Peter White
On Wed, Mar 03, 2021 at 06:17:36PM +0100, Reimar Döffinger wrote:
> > 
> > I have never come around to setting up postfix for forwarding mails
> > externally on my current system. So, for now, I am using the second
> > best solution. Please see the attachment.
> 
> Maybe not worth the effort, but FYI git can communicate directly with
> a SMTP server nowadays, and msmtmp is a simpler solution if all
> you want is a simple forwarding sendmail (not normally
> needed for git anymore though).

Thank you for the information. I always meant to set up postfix properly
anyways but procrastinated it until now. Now I have finally done it.

Shall I send the patch again, opening a new thread, or will the previous
attachment suffice? So far it seems to be getting ignored, or do I
simply need to be more patient?


Peter
___
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] Custom allocation functions

2021-03-05 Thread Martijn Otto
Hello all,

I have made some changes to get custom allocation functions in ffmpeg.
This is useful to me, as the software I work with easily runs into
congestion on memory allocations in certain cases.

I hope it is useful to others as well. It would be nice if this could
be part of ffmpeg proper. If you have specific issues with my
implementation, please let me know.

With regards,
Martijn
From 802b4aecb77c8a35eb6641aa8dd6d27bbcda1fe2 Mon Sep 17 00:00:00 2001
From: Martijn Otto 
Date: Thu, 4 Mar 2021 17:30:15 +0100
Subject: [PATCH] Add custom memory allocation routines.

This feature is a useful optimization strategy. It allows the
implementation of working with a memory pool for better performance.
---
 libavformat/hlsenc.c |  1 +
 libavutil/buffer.c   | 41 +++--
 libavutil/buffer.h   | 23 +++
 3 files changed, 59 insertions(+), 6 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 7d97ce1789..c8e4281e7b 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -927,6 +927,7 @@ static int hls_mux_init(AVFormatContext *s, VariantStream *vs)
 } else {
 ret = hlsenc_io_open(s, &vs->out, vs->base_output_dirname, &options);
 }
+avio_flush(oc->pb);
 av_dict_free(&options);
 }
 if (ret < 0) {
diff --git a/libavutil/buffer.c b/libavutil/buffer.c
index 3204f11b68..bd86b38524 100644
--- a/libavutil/buffer.c
+++ b/libavutil/buffer.c
@@ -59,23 +59,52 @@ AVBufferRef *av_buffer_create(uint8_t *data, int size,
 return ref;
 }
 
+PFNBufferAlloc externalAllocFunc = NULL;
+PFNBufferDealloc externalDeallocFunc = NULL;
+
+void av_set_buffer_alloc_free_funcs( PFNBufferAlloc externalAlloc, PFNBufferDealloc externalDealloc )
+{
+externalAllocFunc = externalAlloc;
+externalDeallocFunc = externalDealloc;
+}
+
 void av_buffer_default_free(void *opaque, uint8_t *data)
 {
 av_free(data);
 }
+void av_buffer_external_free(void *opaque, uint8_t *data)
+{
+if (externalDeallocFunc != NULL)
+externalDeallocFunc(data);
+}
 
 AVBufferRef *av_buffer_alloc(int size)
 {
 AVBufferRef *ret = NULL;
 uint8_t*data = NULL;
 
-data = av_malloc(size);
-if (!data)
-return NULL;
+//Give priority to the external allocation function to give the application a chance to manage it's own buffer allocations.
+if (externalAllocFunc != NULL)
+data = externalAllocFunc(size);
 
-ret = av_buffer_create(data, size, av_buffer_default_free, NULL, 0);
-if (!ret)
-av_freep(&data);
+if (data) {
+//Create a buffer and tell it to free it's data using the external free function. We've used the external
+//allocator for allocation, so we need to use external deallocator for deallocation.
+ret = av_buffer_create(data, size, av_buffer_external_free, NULL, 0);
+if (!ret)
+av_buffer_external_free(NULL, data);
+} else {
+//The external allocation function may return NULL for other reasons than out of memory, so
+//if it did we will fall back to our own allocation function.
+data = av_malloc(size);
+if (!data)
+return NULL; //We're out of memory after all.
+
+//We've created the buffer data ourselves so we can use our own free function.
+ret = av_buffer_create(data, size, av_buffer_default_free, NULL, 0);
+if (!ret)
+av_freep(&data);
+}
 
 return ret;
 }
diff --git a/libavutil/buffer.h b/libavutil/buffer.h
index fd4e381efa..3efe585d56 100644
--- a/libavutil/buffer.h
+++ b/libavutil/buffer.h
@@ -93,6 +93,29 @@ typedef struct AVBufferRef {
 int  size;
 } AVBufferRef;
 
+#if defined(_WIN32)
+#define FFAPI __stdcall
+#else
+#define FFAPI
+#endif
+
+typedef void* (FFAPI *PFNBufferAlloc)( int size );
+typedef void (FFAPI *PFNBufferDealloc)( void* buffer );
+/**
+ * Set allocation functions that can be used to externally manage buffer allocations.
+ * During regular playback buffers are continuously being allocated and deallocated. In high performance
+ * applications this becomes a problem. When multiple files are playing at the same time on different threads
+ * these allocations interlock with eachother causing performance loss due to reduced paralellism.
+ * To remedy this these applications may set these allocation/deallocation functions which it can use to prevent
+ * this behaviour. It could for example implement a pool allocator from which it will source the buffers.
+ *
+ * @param externalAlloc   The function that will be called when a new buffer is required. This function can return
+ *NULL if it does not take care of allocating buffers of the provided size. In this case FFMPeg will
+ *fall back to it's own allocation function.
+ * @param externalDealloc The function that will be called when a buffer is to be deallocated.
+ */
+void av_set_buffer_alloc_fr

[FFmpeg-devel] [PATCH 00/48 v3] deprecate av_init_packet() and sizeof(AVPacket) as part of the ABI

2021-03-05 Thread James Almer
Changes from v2 include fixing issues reported in the previous set, handling
AVPacketList in a better way, skiping the dv patch for now as it needs a more
thorough solution, removed the ffplay patch as it was already done by Marton,
and removed the frame_thread_encoder patch as it became unnecessary after a
change by Andreas.
The decklink patch still only removes the av_init_packet() calls and doesn't
remove stack usage, as I can't test it.

James Almer (48):
  avcodec/packet: deprecate av_init_packet()
  avcodec/packet_internal: make avpriv_packet_list_* functions use an
internal struct
  avcodec/cri: use av_packet_alloc() to allocate packets
  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/mux: use av_packet_alloc() to allocate packets
  avformat/utils: 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/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/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/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

 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   |  42 ++--
 fftools/ffmpeg.c | 318 ---
 fftools/ffmpeg.h |   4 +
 fftools/ffmpeg_opt.c |   5 +-
 fftools/ffprobe.c|  34 ++--
 libavcodec/avpacket.c|  41 ++--
 libavcodec/cri.c |  16 +-
 libavcodec/libxvid.c |  13 +-
 libavcodec/mmaldec.c |  15 +-
 libavcodec/mpegvideo_enc.c   |  38 ++--
 libavcodec/packet.h  |  22 ++-
 libavcodec/packet_internal.h |  10 +-
 libavcodec/pthread_frame.c   |  20 +-
 libavcodec/tdsc.c|  14 +-
 libavcodec/tests/avpacket.c  |  19 +-
 libavcodec/tiff.c|  14 +-
 libavcodec/version.h |   5 +-
 libavcodec/webp.c|  24 ++-
 libavdevice/decklink_common.h|   2 +-
 libavdevice/decklink_dec.cpp |  21 +-
 libavdevice/dshow.c  |  10 +-
 libavdevice/dshow_capture.h  |   3 +-
 libavdevice/vfwcap.c |  13 +-
 libavdevice/xcbgrab.c|   4 -
 libavfilter/vf_mcdeint.c |  13 +-
 libavfilter/vf_uspp.c|  14 +-
 libavformat/aiffenc.c|   4 +-
 libavformat/amvenc.c |  41 ++--
 libavformat/asfdec_o.c   |  63 +++---
 libavformat/a

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

2021-03-05 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| 22 ++
 libavcodec/version.h   |  5 -
 libavformat/avformat.h |  4 
 4 files changed, 41 insertions(+), 13 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..f07ca4936c 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
  */
@@ -393,10 +395,13 @@ typedef struct AVPacket {
 #endif
 } AVPacket;
 
+#if FF_API_INIT_PACKET
+attribute_deprecated
 typedef struct AVPacketList {
 AVPacket pkt;
 struct AVPacketList *next;
 } AVPacketList;
+#endif
 
 #define AV_PKT_FLAG_KEY 0x0001 ///< The packet contains a keyframe
 #define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted
@@ -460,6 +465,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 +473,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 2b3757fa07..163dbc1cbf 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,7 +28,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR  58
-#define LIBAVCODEC_VERSION_MINOR 128
+#define LIBAVCODEC_VERSION_MINOR 129
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
@@ -159,5 +159,8 @@
 #ifndef FF_API_GET_FRAME_CLASS
 #define FF_API_GET_FRAME_CLASS (LIBAVCODEC_VERSION_MAJOR < 60)
 #endif
+#ifndef FF_API_INIT_PACKET
+#define FF_API_INIT_PACKET (LIBAVCODEC_VERSION_MAJOR < 60)
+#e

[FFmpeg-devel] [PATCH 02/48] avcodec/packet_internal: make avpriv_packet_list_* functions use an internal struct

2021-03-05 Thread James Almer
The next pointer is kept at the end for backwards compatibility until the
major bump, when it should be moved at the front.

Signed-off-by: James Almer 
---
 libavcodec/avpacket.c | 18 +-
 libavcodec/packet_internal.h  | 10 +++---
 libavdevice/decklink_common.h |  2 +-
 libavdevice/decklink_dec.cpp  |  9 +
 libavdevice/dshow.c   | 10 +-
 libavdevice/dshow_capture.h   |  3 ++-
 libavdevice/vfwcap.c  | 13 +++--
 libavformat/aiffenc.c |  4 ++--
 libavformat/flacenc.c |  2 +-
 libavformat/internal.h| 14 +++---
 libavformat/matroskadec.c |  4 ++--
 libavformat/mp3enc.c  |  2 +-
 libavformat/mux.c | 11 ++-
 libavformat/mxfenc.c  |  7 ---
 libavformat/ttaenc.c  |  2 +-
 libavformat/utils.c   | 14 +++---
 16 files changed, 67 insertions(+), 58 deletions(-)

diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index ae0cbfb9f9..8c75c75f7b 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -733,13 +733,13 @@ FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 }
 
-int avpriv_packet_list_put(AVPacketList **packet_buffer,
-   AVPacketList **plast_pktl,
+int avpriv_packet_list_put(PacketList **packet_buffer,
+   PacketList **plast_pktl,
AVPacket  *pkt,
int (*copy)(AVPacket *dst, const AVPacket *src),
int flags)
 {
-AVPacketList *pktl = av_mallocz(sizeof(AVPacketList));
+PacketList *pktl = av_mallocz(sizeof(PacketList));
 int ret;
 
 if (!pktl)
@@ -770,11 +770,11 @@ int avpriv_packet_list_put(AVPacketList **packet_buffer,
 return 0;
 }
 
-int avpriv_packet_list_get(AVPacketList **pkt_buffer,
-   AVPacketList **pkt_buffer_end,
+int avpriv_packet_list_get(PacketList **pkt_buffer,
+   PacketList **pkt_buffer_end,
AVPacket  *pkt)
 {
-AVPacketList *pktl;
+PacketList *pktl;
 if (!*pkt_buffer)
 return AVERROR(EAGAIN);
 pktl= *pkt_buffer;
@@ -786,12 +786,12 @@ int avpriv_packet_list_get(AVPacketList **pkt_buffer,
 return 0;
 }
 
-void avpriv_packet_list_free(AVPacketList **pkt_buf, AVPacketList 
**pkt_buf_end)
+void avpriv_packet_list_free(PacketList **pkt_buf, PacketList **pkt_buf_end)
 {
-AVPacketList *tmp = *pkt_buf;
+PacketList *tmp = *pkt_buf;
 
 while (tmp) {
-AVPacketList *pktl = tmp;
+PacketList *pktl = tmp;
 tmp = pktl->next;
 av_packet_unref(&pktl->pkt);
 av_freep(&pktl);
diff --git a/libavcodec/packet_internal.h b/libavcodec/packet_internal.h
index 832ddb4a61..b1d91f6347 100644
--- a/libavcodec/packet_internal.h
+++ b/libavcodec/packet_internal.h
@@ -23,6 +23,10 @@
 
 #include "packet.h"
 
+typedef struct PacketList {
+AVPacket pkt;
+struct PacketList *next;
+} PacketList;
 
 /**
  * Append an AVPacket to the list.
@@ -37,7 +41,7 @@
  * @return 0 on success, negative AVERROR value on failure. On failure,
the packet and the list are unchanged.
  */
-int avpriv_packet_list_put(AVPacketList **head, AVPacketList **tail,
+int avpriv_packet_list_put(PacketList **head, PacketList **tail,
AVPacket *pkt,
int (*copy)(AVPacket *dst, const AVPacket *src),
int flags);
@@ -54,7 +58,7 @@ int avpriv_packet_list_put(AVPacketList **head, AVPacketList 
**tail,
  * @return 0 on success, and a packet is returned. AVERROR(EAGAIN) if
  * the list was empty.
  */
-int avpriv_packet_list_get(AVPacketList **head, AVPacketList **tail,
+int avpriv_packet_list_get(PacketList **head, PacketList **tail,
AVPacket *pkt);
 
 /**
@@ -63,7 +67,7 @@ int avpriv_packet_list_get(AVPacketList **head, AVPacketList 
**tail,
  * @param head List head element
  * @param tail List tail element
  */
-void avpriv_packet_list_free(AVPacketList **head, AVPacketList **tail);
+void avpriv_packet_list_free(PacketList **head, PacketList **tail);
 
 int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, 
int error_count, int pict_type);
 
diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
index e49d9d54ad..6e032956a8 100644
--- a/libavdevice/decklink_common.h
+++ b/libavdevice/decklink_common.h
@@ -75,7 +75,7 @@ class decklink_output_callback;
 class decklink_input_callback;
 
 typedef struct AVPacketQueue {
-AVPacketList *first_pkt, *last_pkt;
+PacketList *first_pkt, *last_pkt;
 int nb_packets;
 unsigned long long size;
 int abort_request;
diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index 4f8103e614..5acb2e8fbb 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -35,6 +35,7 @@ extern "C" {
 
 extern "C" {
 #include "co

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

2021-03-05 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 3312606b75..0558d0c8dd 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;
@@ -345,13 +350,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;
@@ -415,6 +418,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.1

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

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

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

2021-03-05 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.1

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

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

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

2021-03-05 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.1

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

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

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

2021-03-05 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 d1e908fd43..17a593e379 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.1

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

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

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

2021-03-05 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/mpegvideo_enc.c | 38 --
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 34dcf8c313..355e14a71b 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);
@@ -1393,6 +1390,7 @@ static int encode_frame(AVCodecContext *c, AVFrame *frame)
 static int estimate_best_b_count(MpegEncContext *s)
 {
 const AVCodec *codec = avcodec_find_encoder(s->avctx->codec_id);
+AVPacket *pkt;
 const int scale = s->brd_scale;
 int width  = s->width  >> scale;
 int height = s->height >> scale;
@@ -1403,6 +1401,10 @@ static int estimate_best_b_count(MpegEncContext *s)
 
 av_assert0(scale >= 0 && scale <= 3);
 
+pkt = av_packet_alloc();
+if (!pkt)
+return AVERROR(ENOMEM);
+
 //emms_c();
 //s->next_picture_ptr->quality;
 p_lambda = s->last_lambda_for[AV_PICTURE_TYPE_P];
@@ -1454,8 +1456,10 @@ static int estimate_best_b_count(MpegEncContext *s)
 break;
 
 c = avcodec_alloc_context3(NULL);
-if (!c)
-return AVERROR(ENOMEM);
+if (!c) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
 
 c->width= width;
 c->height   = height;
@@ -1473,10 +1477,11 @@ static int estimate_best_b_count(MpegEncContext *s)
 if (ret < 0)
 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 +1496,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 +1506,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,10 +1522,15 @@ static int estimate_best_b_count(MpegEncContext *s)
 
 fail:
 avcodec_free_context(&c);
-if (ret < 0)
-return ret;
+av_packet_unref(pkt);
+if (ret < 0) {
+best_b_count = ret;
+break;
+}
 }
 
+av_packet_free(&pkt);
+
 return best_b_count;
 }
 
-- 
2.30.1

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

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

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

2021-03-05 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.1

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

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

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

2021-03-05 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.1

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

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

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

2021-03-05 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.1

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

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

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

2021-03-05 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.1

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

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

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

2021-03-05 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/internal.h |  5 +
 libavformat/mux.c  | 40 
 libavformat/options.c  |  6 ++
 libavformat/utils.c|  1 +
 4 files changed, 32 insertions(+), 20 deletions(-)

diff --git a/libavformat/internal.h b/libavformat/internal.h
index e913d958fc..02ff2fd77a 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -92,6 +92,11 @@ struct AVFormatInternal {
  */
 struct PacketList *parse_queue;
 struct PacketList *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 440113b149..e98b86a81e 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -1211,7 +1211,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) {
@@ -1232,6 +1232,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;
@@ -1273,14 +1274,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;
 }
@@ -1354,7 +1355,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) {
@@ -1363,18 +1364,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);
@@ -1382,17 +1382,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..8d7c4fe4cb 100644
--- a/libavformat/options.c
+++ b/libavformat/options.c
@@ -220,6 +220,12 @@ AVFormatContext *avformat_alloc_context(void)
 av_free(ic);
 return NULL;
 }
+internal->pkt = av_packet_alloc();
+if (!internal->pkt) {
+av_free(internal);
+av_free(ic);
+return NULL;
+}
 avformat_get_context_defaults(ic);
 ic->internal = internal;
 ic->internal->offset = AV_NOPTS_VALUE;
diff --git a/libavformat/utils.c b/libavformat/utils.c
index

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

2021-03-05 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 02ff2fd77a..96902b818c 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 PacketList *parse_queue;
 struct PacketList *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 192ef51f47..2b17c6174b 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);
@@ -807,9 +813,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 (;;) {
 PacketList *pktl = s->internal->raw_packet_buffer;
@@ -1409,14 +1421,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);
@@ -1428,7 +1440,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;
@@ -1438,39 +1450,39 @@ static int parse_packet(AVFormatContext *s, AVPacket 
*pkt,
 data  = len ? data + len : data;
 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->flag

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

2021-03-05 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.1

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

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

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

2021-03-05 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 16/48] avformat/avidec: use av_packet_alloc() to allocate packets

2021-03-05 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 5ea6160eef..fa0599501a 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;
@@ -1130,6 +1130,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;
 
@@ -1141,7 +1144,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);
@@ -1152,6 +1155,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);
 }
@@ -1172,8 +1176,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;
@@ -1183,11 +1187,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;
 }
@@ -1806,10 +1810,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,
@@ -1943,7 +1947,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.1

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

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

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

2021-03-05 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 9cbf3d3349..ac11dd9cb2 100644
--- a/libavformat/avienc.c
+++ b/libavformat/avienc.c
@@ -66,6 +66,7 @@ typedef struct AVIIndex {
 
 typedef struct AVIContext {
 const AVClass *class;
+AVPacket *empty_packet;
 int64_t riff_start, movi_list, odml_list;
 int64_t frames_hdr_all;
 int riff_id;
@@ -274,6 +275,10 @@ static int avi_write_header(AVFormatContext *s)
 return AVERROR(EINVAL);
 }
 
+avi->empty_packet = av_packet_alloc();
+if (!avi->empty_packet)
+return AVERROR(ENOMEM);
+
 for (n = 0; n < s->nb_streams; n++) {
 s->streams[n]->priv_data = av_mallocz(sizeof(AVIStream));
 if (!s->streams[n]->priv_data)
@@ -739,24 +744,21 @@ static int avi_write_idx1(AVFormatContext *s)
 
 static int write_skip_frames(AVFormatContext *s, int stream_index, int64_t dts)
 {
+AVIContext *avi = s->priv_data;
 AVIStream *avist= s->streams[stream_index]->priv_data;
 AVCodecParameters *par = s->streams[stream_index]->codecpar;
 
 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->empty_packet->stream_index = stream_index;
+avi_write_packet_internal(s, avi->empty_packet);
 ff_dlog(s, "dup dts:%s packet_count:%d\n", av_ts2str(dts), 
avist->packet_count);
 }
 
@@ -978,6 +980,10 @@ static int avi_write_trailer(AVFormatContext *s)
 
 static void avi_deinit(AVFormatContext *s)
 {
+AVIContext *avi = s->priv_data;
+
+av_packet_free(&avi->empty_packet);
+
 for (int i = 0; i < s->nb_streams; i++) {
 AVIStream *avist = s->streams[i]->priv_data;
 if (!avist)
-- 
2.30.1

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

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

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

2021-03-05 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.1

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

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

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

2021-03-05 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 df11b5450c..f33b7ba93a 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -1162,7 +1162,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.1

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

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

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

2021-03-05 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/flacdec.c | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index 6aca4755a1..f7b21986dc 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 = s->internal->parse_pkt;
 AVStream *st = s->streams[stream_index];
 AVCodecParserContext *parser;
 int ret;
@@ -268,7 +268,6 @@ 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);
 parser = av_parser_init(st->codecpar->codec_id);
 if (!parser){
 return AV_NOPTS_VALUE;
@@ -279,20 +278,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
-- 
2.30.1

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

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

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

2021-03-05 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 22/48] avformat/matroskadec: use av_packet_alloc() to allocate packets

2021-03-05 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 9a65774464..3ee28a447c 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -381,6 +381,8 @@ typedef struct MatroskaDemuxContext {
 /* byte position of the segment inside the stream */
 int64_t segment_start;
 
+AVPacket *pkt;
+
 /* the packet queue */
 PacketList *queue;
 PacketList *queue_end;
@@ -2943,6 +2945,10 @@ static int matroska_read_header(AVFormatContext *s)
 }
 ebml_free(ebml_syntax, &ebml);
 
+matroska->pkt = av_packet_alloc();
+if (!matroska->pkt)
+return AVERROR(ENOMEM);
+
 /* The next thing is a segment. */
 pos = avio_tell(matroska->ctx->pb);
 res = ebml_parse(matroska, matroska_segments, matroska);
@@ -3004,7 +3010,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;
@@ -3236,7 +3242,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) {
@@ -3373,7 +3379,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;
@@ -3490,7 +3496,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);
@@ -3520,7 +3526,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);
@@ -3894,6 +3900,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.1

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

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

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

2021-03-05 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 367e05b36b..68e1426d00 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);
@@ -1933,8 +1933,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
@@ -2428,9 +2426,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);
@@ -2442,7 +2440,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;
@@ -2474,8 +2472,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);
@@ -2699,6 +2697,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.1

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

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

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

2021-03-05 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/movenc.c | 101 +--
 libavformat/movenc.h |   4 +-
 libavformat/movenchint.c |  19 
 3 files changed, 77 insertions(+), 47 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index ccb9768564..7aa0a9888a 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;
@@ -3732,7 +3735,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) {
@@ -3740,11 +3743,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;
@@ -5967,20 +5970,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;
 }
@@ -6007,7 +6010,7 @@ static int mov_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 return 0;
 }
 
-if ((ret = av_packet_ref(&trk->cover_image, pkt)) < 0)
+if ((ret = av_packet_ref(trk->cover_image, pkt)) < 0)
 return ret;
 
 return 0;
@@ -6093,7 +6096,7 @@ static int mov_create_chapter_track(AVFormatContext *s, 
int tracknum)
 
 MOVMuxContext *mov = s->priv_data;
 MOVTrack *track = &mov->tracks[tracknum];
-AVPacket pkt = { .stream_index = tracknum, .flags = AV_PKT_FLAG_KEY };
+AVPacket *pkt = mov->pkt;
 int i, len;
 
 track->mode = mov->mode;
@@ -6155,13 +6158,16 @@ static int mov_create_chapter_track(AVFormatContext *s, 
int tracknum)
 }
 #endif
 
+pkt->stream_index = tracknum;
+pkt->flags = AV_PKT_FLAG_KEY;
+
 for (i = 0; i < s->nb_chapters; i++) {
 AVChapter *c = s->chapters[i];
 AVDictionaryEntry *t;
 
 int64_t end = av_rescale_q(c->end, c->time_base, 
(AVRational){1,MOV_TIMESCALE});
-pkt.pts = pkt.dts = av_rescale_q(c->start, c->time_base, 
(AVRational){1,MOV_TIMESCALE});
-pkt.duration = end - pkt.dts;
+pkt->pts = pkt->dts = a

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

2021-03-05 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.1

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

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

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

2021-03-05 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.1

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

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

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

2021-03-05 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 28/48] avformat/rtpenc_mpegts: use av_packet_alloc() to allocate packets

2021-03-05 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.1

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

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

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

2021-03-05 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/jacosubdec.c |  2 +-
 libavformat/mpeg.c   |  4 +--
 libavformat/mpsubdec.c   |  4 +--
 libavformat/subtitles.c  | 69 +++-
 libavformat/subtitles.h  |  2 +-
 libavformat/tedcaptionsdec.c |  4 +--
 6 files changed, 45 insertions(+), 40 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..05c07cd852 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,10 +132,14 @@ AVPacket *ff_subtitles_queue_insert(FFDemuxSubtitlesQueue 
*q,
 if (!subs)
 return NULL;
 q->subs = subs;
-sub = &subs[q->nb_subs];
-if (av_new_packet(sub, len) < 0)
+sub = av_packet_alloc();
+if (!sub)
 return NULL;
-q->nb_subs++;
+if (av_new_packet(sub, len) < 0) {
+av_packet_free(&sub);
+return NULL;
+}
+subs[q->nb_subs++] = sub;
 sub->flags |= AV_PKT_FLAG_KEY;
 sub->pts = sub->dts = 0;
 memcpy(sub->data, event, len);
@@ -145,8 +149,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 +158,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 +174,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-

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

2021-03-05 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..cd69931a42 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)
+return AVERROR(ENOMEM);
 
 /* 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.1

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

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

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

2021-03-05 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.1

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

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

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

2021-03-05 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 33/48] avdevice/decklink_dec: stop using av_init_packet()

2021-03-05 Thread James Almer
Signed-off-by: James Almer 
---
 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 5acb2e8fbb..c34a69b5de 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -674,8 +674,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;
@@ -873,8 +872,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,
@@ -976,7 +974,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;
 
@@ -1035,7 +1033,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;
@@ -1059,9 +1056,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.1

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

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

[FFmpeg-devel] [PATCH 34/48] avdevice/xcbgrab: stop using av_init_packet()

2021-03-05 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 9604a5aaf2..b3c2170112 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.1

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

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

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

2021-03-05 Thread James Almer
Signed-off-by: James Almer 
---
 libavfilter/vf_mcdeint.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/libavfilter/vf_mcdeint.c b/libavfilter/vf_mcdeint.c
index bc7b3230d3..1cad45cd4e 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,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
*inpic)
 av_frame_copy_props(outpic, inpic);
 inpic->quality = mcdeint->qp * FF_QP2LAMBDA;
 
-av_init_packet(&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 +277,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.1

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

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

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

2021-03-05 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.1

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

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

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

2021-03-05 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.1

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

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

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

2021-03-05 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 c484dd3e95..bac54d5aaa 100644
--- a/tools/target_dec_fuzzer.c
+++ b/tools/target_dec_fuzzer.c
@@ -294,13 +294,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) {
@@ -311,43 +310,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))
@@ -355,7 +353,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;
   if(!decode_more) {
 ec_pixels += (ctx->width + 32LL) * (ctx->height + 32LL);
@@ -370,7 +368,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->ma

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

2021-03-05 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.1

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

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

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

2021-03-05 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.1

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

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

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

2021-03-05 Thread James Almer
Signed-off-by: James Almer 
---
This patch conflicts with one by Anton, so i'll adapt it after he pushes
his.

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

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

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

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

2021-03-05 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.1

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

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

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

2021-03-05 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.1

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

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

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

2021-03-05 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 45/48] doc/examples/vaapi_encode: use av_packet_alloc() to allocate packets

2021-03-05 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.1

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

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

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

2021-03-05 Thread James Almer
Signed-off-by: James Almer 
---
 doc/examples/vaapi_transcode.c | 42 ++
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/doc/examples/vaapi_transcode.c b/doc/examples/vaapi_transcode.c
index 279d20f636..5a1a704a8e 100644
--- a/doc/examples/vaapi_transcode.c
+++ b/doc/examples/vaapi_transcode.c
@@ -109,28 +109,25 @@ 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;
+av_packet_unref(enc_pkt);
 
 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));
@@ -216,7 +213,7 @@ static int dec_enc(AVPacket *pkt, AVCodec *enc_codec)
 initialized = 1;
 }
 
-if ((ret = encode_write(frame)) < 0)
+if ((ret = encode_write(pkt, frame)) < 0)
 fprintf(stderr, "Error during encoding and writing.\n");
 
 fail:
@@ -230,7 +227,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 +243,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,23 +278,21 @@ 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);
+av_packet_unref(dec_pkt);
+ret = dec_enc(dec_pkt, enc_codec);
 
 /* flush encoder */
-ret = encode_write(NULL);
+ret = encode_write(dec_pkt, NULL);
 
 /* write the trailer for output stream */
 av_write_trailer(ofmt_ctx);
@@ -302,5 +303,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.1

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

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

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

2021-03-05 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 740e759958..a6735f70c6 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -2463,14 +2463,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);
 
@@ -2503,18 +2501,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;
@@ -2536,26 +2539,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.1

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

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

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

2021-03-05 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 2abbc0ff29..46bb014de8 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

Re: [FFmpeg-devel] [PATCH v7 0/5] Initial implementation of TTML encoding/muxing

2021-03-05 Thread Jan Ekström
On Thu, Mar 4, 2021 at 7:48 PM Jan Ekström  wrote:
>
> I've intentionally kept this initial version simple (no styling etc) to focus
> on the basics. As this goes through review, additional features can be added
> (I had initial PoC for styling implemented some time around previous VDD), and
> there is another patch set in my queue which would then add support for muxing
> TTML into MP4.
>
> Changes from the sixth version:
>   - Split the lavc and lavf bits.
>
> Jan

As there were no further comments, applied the set as:

0f6bf94eb71c2d5e996c89c290f1a53660c46c2e
c8c6c9f5d96789001ea628f44cc5602bdc41d5f3
a0eec776b6212b0126f04bbac6bd6af0f6530b76
18713d22a2001321f9917fa4c7735f62563ec0a1
64af14555be2c9e522109e55160e0cb3f65c4690

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

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

[FFmpeg-devel] [PATCH 1/2] avcodec/mmaldec: Stop needlessly wrapping extradata in AVPacket

2021-03-05 Thread Andreas Rheinhardt
Up until now the function to add packets to the waiting buffers list
uses an AVPacket as parameter; therefore extradata that is also sent
once gets wrapped in an AVPacket. Yet this is unnecessary as the
function does not really need a complete AVPacket, but mostly the data.
Therefore this commit modifies the function to accept a pointer for the
data and int for the size as well as the AVPacket* parameter, which is
NULL for extradata.

Furthermore, this commit adds const to the pointed to types if the data
doesn't change. The MMAL_BUFFER_HEADER_T struct unfortunately uses
uint8_t* for data that is not modified, necessitating a cast.

Signed-off-by: Andreas Rheinhardt 
---
These two commits are completely untested; I just hope they compile.
Could please someone test them? Thanks in advance.
This commit provides an alternative way to avoid AVPackets on the stack
and av_init_packet; furthermore, this commit also aims to make this
decoder compatible with receiving a const AVPacket*.

 libavcodec/mmaldec.c | 45 
 1 file changed, 20 insertions(+), 25 deletions(-)

diff --git a/libavcodec/mmaldec.c b/libavcodec/mmaldec.c
index cb15ac072a..7486f3c526 100644
--- a/libavcodec/mmaldec.c
+++ b/libavcodec/mmaldec.c
@@ -46,7 +46,7 @@
 
 typedef struct FFBufferEntry {
 AVBufferRef *ref;
-void *data;
+const void *data;
 size_t length;
 int64_t pts, dts;
 int flags;
@@ -476,27 +476,22 @@ fail:
 // (due to us not reading/returning enough output buffers) and won't accept
 // new input. (This wouldn't be an issue if MMAL input buffers always were
 // complete frames - then the input buffer just would have to be big enough.)
-// If is_extradata is set, send it as MMAL_BUFFER_HEADER_FLAG_CONFIG.
-static int ffmmal_add_packet(AVCodecContext *avctx, AVPacket *avpkt,
- int is_extradata)
+// Extradata (avpkt == NULL) is sent as MMAL_BUFFER_HEADER_FLAG_CONFIG.
+static int ffmmal_add_packet(AVCodecContext *avctx, const AVPacket *avpkt,
+ const uint8_t *data, int size)
 {
 MMALDecodeContext *ctx = avctx->priv_data;
 AVBufferRef *buf = NULL;
-int size = 0;
-uint8_t *data = (uint8_t *)"";
-uint8_t *start;
+const uint8_t *start;
 int ret = 0;
 
-if (avpkt->size) {
-if (avpkt->buf) {
+if (size) {
+if (avpkt) {
 buf = av_buffer_ref(avpkt->buf);
-size = avpkt->size;
-data = avpkt->data;
 } else {
-buf = av_buffer_alloc(avpkt->size);
+buf = av_buffer_alloc(size);
 if (buf) {
-memcpy(buf->data, avpkt->data, avpkt->size);
-size = buf->size;
+memcpy(buf->data, data, size);
 data = buf->data;
 }
 }
@@ -504,9 +499,10 @@ static int ffmmal_add_packet(AVCodecContext *avctx, 
AVPacket *avpkt,
 ret = AVERROR(ENOMEM);
 goto done;
 }
-if (!is_extradata)
+if (avpkt)
 ctx->packets_sent++;
 } else {
+data = "";
 if (ctx->eos_sent)
 goto done;
 if (!ctx->packets_sent) {
@@ -529,7 +525,7 @@ static int ffmmal_add_packet(AVCodecContext *avctx, 
AVPacket *avpkt,
 buffer->data = data;
 buffer->length = FFMIN(size, ctx->decoder->input[0]->buffer_size);
 
-if (is_extradata)
+if (!avpkt)
 buffer->flags |= MMAL_BUFFER_HEADER_FLAG_CONFIG;
 
 if (data == start)
@@ -538,8 +534,10 @@ static int ffmmal_add_packet(AVCodecContext *avctx, 
AVPacket *avpkt,
 data += buffer->length;
 size -= buffer->length;
 
-buffer->pts = avpkt->pts == AV_NOPTS_VALUE ? MMAL_TIME_UNKNOWN : 
avpkt->pts;
-buffer->dts = avpkt->dts == AV_NOPTS_VALUE ? MMAL_TIME_UNKNOWN : 
avpkt->dts;
+buffer->pts = !avpkt || avpkt->pts == AV_NOPTS_VALUE ?
+  MMAL_TIME_UNKNOWN : avpkt->pts;
+buffer->dts = !avpkt || avpkt->dts == AV_NOPTS_VALUE ?
+  MMAL_TIME_UNKNOWN : avpkt->dts;
 
 if (!size) {
 buffer->flags |= MMAL_BUFFER_HEADER_FLAG_FRAME_END;
@@ -594,7 +592,7 @@ static int ffmmal_fill_input_port(AVCodecContext *avctx)
 mbuffer->pts = buffer->pts;
 mbuffer->dts = buffer->dts;
 mbuffer->flags = buffer->flags;
-mbuffer->data = buffer->data;
+mbuffer->data = (uint8_t*)buffer->data;
 mbuffer->length = buffer->length;
 mbuffer->user_data = buffer;
 mbuffer->alloc_size = ctx->decoder->input[0]->buffer_size;
@@ -776,16 +774,13 @@ 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;
 ctx->extradata_sent = 1;
-   

[FFmpeg-devel] [PATCH 2/2] avcodec/mmaldec: Return early upon failure

2021-03-05 Thread Andreas Rheinhardt
This avoids freeing a NULL AVBufferRef*.

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

diff --git a/libavcodec/mmaldec.c b/libavcodec/mmaldec.c
index 7486f3c526..0ea07ea787 100644
--- a/libavcodec/mmaldec.c
+++ b/libavcodec/mmaldec.c
@@ -495,21 +495,20 @@ static int ffmmal_add_packet(AVCodecContext *avctx, const 
AVPacket *avpkt,
 data = buf->data;
 }
 }
-if (!buf) {
-ret = AVERROR(ENOMEM);
-goto done;
-}
+if (!buf)
+return AVERROR(ENOMEM);
+
 if (avpkt)
 ctx->packets_sent++;
 } else {
 data = "";
 if (ctx->eos_sent)
-goto done;
+return 0;
 if (!ctx->packets_sent) {
 // Short-cut the flush logic to avoid upsetting MMAL.
 ctx->eos_sent = 1;
 ctx->eos_received = 1;
-goto done;
+return 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 48/48] fftools/ffmpeg: use av_packet_alloc() to allocate packets

2021-03-05 Thread Jack Waller
On Sat, Mar 6, 2021 at 12:44 AM James Almer  wrote:

> 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 2abbc0ff29..46bb014de8 100644
> --- a/fftools/ffmpeg.c
> +++ b/fftools/ffmpeg.c
>
> @@ -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);
>

Should you modify av_fifo_generic_read() for its second arguments( &pkt) as
well?
___
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".