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 <https://github.com/Genymobile/scrcpy/issues/2302>
This commit is contained in:
@@ -35,11 +35,14 @@ record_packet_new(const AVPacket *packet) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// av_packet_ref() does not initialize all fields in old FFmpeg versions
|
rec->packet = av_packet_alloc();
|
||||||
// See <https://github.com/Genymobile/scrcpy/issues/707>
|
if (!rec->packet) {
|
||||||
av_init_packet(&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);
|
free(rec);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -48,7 +51,8 @@ record_packet_new(const AVPacket *packet) {
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
record_packet_delete(struct record_packet *rec) {
|
record_packet_delete(struct record_packet *rec) {
|
||||||
av_packet_unref(&rec->packet);
|
av_packet_unref(rec->packet);
|
||||||
|
av_packet_free(&rec->packet);
|
||||||
free(rec);
|
free(rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,8 +148,8 @@ run_recorder(void *data) {
|
|||||||
struct record_packet *last = recorder->previous;
|
struct record_packet *last = recorder->previous;
|
||||||
if (last) {
|
if (last) {
|
||||||
// assign an arbitrary duration to the last packet
|
// assign an arbitrary duration to the last packet
|
||||||
last->packet.duration = 100000;
|
last->packet->duration = 100000;
|
||||||
bool ok = recorder_write(recorder, &last->packet);
|
bool ok = recorder_write(recorder, last->packet);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
// failing to write the last frame is not very serious, no
|
// failing to write the last frame is not very serious, no
|
||||||
// future frame may depend on it, so the resulting file
|
// 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
|
// config packets have no PTS, we must ignore them
|
||||||
if (rec->packet.pts != AV_NOPTS_VALUE
|
if (rec->packet->pts != AV_NOPTS_VALUE
|
||||||
&& previous->packet.pts != AV_NOPTS_VALUE) {
|
&& previous->packet->pts != AV_NOPTS_VALUE) {
|
||||||
// we now know the duration of the previous packet
|
// 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);
|
record_packet_delete(previous);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
LOGE("Could not record packet");
|
LOGE("Could not record packet");
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
#include "util/thread.h"
|
#include "util/thread.h"
|
||||||
|
|
||||||
struct record_packet {
|
struct record_packet {
|
||||||
AVPacket packet;
|
AVPacket *packet;
|
||||||
struct record_packet *next;
|
struct record_packet *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user