diff mbox series

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

Message ID 20210204191005.48190-29-jamrial@gmail.com
State Superseded
Headers show
Series deprecate av_init_packet() and sizeof(AVPacket) as part of the ABI
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

James Almer Feb. 4, 2021, 7:09 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/rtpenc_mpegts.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
diff mbox series

Patch

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;