From 4af317d40da70d63dee44bf645694ed5c4f05d65 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Mon, 14 Jun 2021 09:07:49 +0200 Subject: [PATCH] Allocate AVPacket for recorder 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/recorder.c | 27 ++++++++++++++++----------- app/src/recorder.h | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/src/recorder.c b/app/src/recorder.c index 91390ff1..85570324 100644 --- a/app/src/recorder.c +++ b/app/src/recorder.c @@ -35,11 +35,14 @@ record_packet_new(const AVPacket *packet) { return NULL; } - // av_packet_ref() does not initialize all fields in old FFmpeg versions - // See - av_init_packet(&rec->packet); + rec->packet = av_packet_alloc(); + if (!rec->packet) { + free(rec); + return NULL; + } - if (av_packet_ref(&rec->packet, packet)) { + if (av_packet_ref(rec->packet, packet)) { + av_packet_free(&rec->packet); free(rec); return NULL; } @@ -48,7 +51,8 @@ record_packet_new(const AVPacket *packet) { static void record_packet_delete(struct record_packet *rec) { - av_packet_unref(&rec->packet); + av_packet_unref(rec->packet); + av_packet_free(&rec->packet); free(rec); } @@ -144,8 +148,8 @@ run_recorder(void *data) { struct record_packet *last = recorder->previous; if (last) { // assign an arbitrary duration to the last packet - last->packet.duration = 100000; - bool ok = recorder_write(recorder, &last->packet); + last->packet->duration = 100000; + bool ok = recorder_write(recorder, last->packet); if (!ok) { // failing to write the last frame is not very serious, no // future frame may depend on it, so the resulting file @@ -172,13 +176,14 @@ run_recorder(void *data) { } // config packets have no PTS, we must ignore them - if (rec->packet.pts != AV_NOPTS_VALUE - && previous->packet.pts != AV_NOPTS_VALUE) { + if (rec->packet->pts != AV_NOPTS_VALUE + && previous->packet->pts != AV_NOPTS_VALUE) { // we now know the duration of the previous packet - previous->packet.duration = rec->packet.pts - previous->packet.pts; + previous->packet->duration = + rec->packet->pts - previous->packet->pts; } - bool ok = recorder_write(recorder, &previous->packet); + bool ok = recorder_write(recorder, previous->packet); record_packet_delete(previous); if (!ok) { LOGE("Could not record packet"); diff --git a/app/src/recorder.h b/app/src/recorder.h index 1b2b9284..0c376cd1 100644 --- a/app/src/recorder.h +++ b/app/src/recorder.h @@ -13,7 +13,7 @@ #include "util/thread.h" struct record_packet { - AVPacket packet; + AVPacket *packet; struct record_packet *next; };