From cd2894570d224d854d6e27abb401434fa6ec2840 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Mon, 14 Jun 2021 09:07:49 +0200 Subject: [PATCH] Allocate AVPacket for v4l2_sink From FFmpeg/doc/APIchanges: 2021-03-17 - f7db77bd87 - lavc 58.133.100 - codec.h Deprecated av_init_packet(). Once removed, sizeof(AVPacket) will no longer be a part of the public ABI. Refs #2302 --- app/src/v4l2_sink.c | 13 +++++++++++-- app/src/v4l2_sink.h | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/src/v4l2_sink.c b/app/src/v4l2_sink.c index d7c1a667..bd184b4d 100644 --- a/app/src/v4l2_sink.c +++ b/app/src/v4l2_sink.c @@ -86,7 +86,7 @@ encode_and_write_frame(struct sc_v4l2_sink *vs, const AVFrame *frame) { return false; } - AVPacket *packet = &vs->packet; + AVPacket *packet = vs->packet; ret = avcodec_receive_packet(vs->encoder_ctx, packet); if (ret == 0) { // A packet was received @@ -235,11 +235,17 @@ sc_v4l2_sink_open(struct sc_v4l2_sink *vs) { goto error_avcodec_close; } + vs->packet = av_packet_alloc(); + if (!vs->packet) { + LOGE("Could not allocate packet"); + goto error_av_frame_free; + } + LOGD("Starting v4l2 thread"); ok = sc_thread_create(&vs->thread, run_v4l2_sink, "v4l2", vs); if (!ok) { LOGC("Could not start v4l2 thread"); - goto error_av_frame_free; + goto error_av_packet_free; } vs->header_written = false; @@ -249,6 +255,8 @@ sc_v4l2_sink_open(struct sc_v4l2_sink *vs) { return true; +error_av_packet_free: + av_packet_free(&vs->packet); error_av_frame_free: av_frame_free(&vs->frame); error_avcodec_close: @@ -278,6 +286,7 @@ sc_v4l2_sink_close(struct sc_v4l2_sink *vs) { sc_thread_join(&vs->thread, NULL); + av_packet_free(&vs->packet); av_frame_free(&vs->frame); avcodec_close(vs->encoder_ctx); avcodec_free_context(&vs->encoder_ctx); diff --git a/app/src/v4l2_sink.h b/app/src/v4l2_sink.h index 9d2ee149..81bcdd1e 100644 --- a/app/src/v4l2_sink.h +++ b/app/src/v4l2_sink.h @@ -26,7 +26,7 @@ struct sc_v4l2_sink { bool header_written; AVFrame *frame; - AVPacket packet; + AVPacket *packet; }; bool