Allocate AVPacket for local stream packet

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:
Romain Vimont 2021-06-14 09:07:49 +02:00
parent e8b053ad2f
commit 318b6a572e

View file

@ -220,16 +220,21 @@ run_stream(void *data) {
// It's more complicated, but this allows to reduce the latency by 1 frame! // It's more complicated, but this allows to reduce the latency by 1 frame!
stream->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; stream->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES;
AVPacket *packet = av_packet_alloc();
if (!packet) {
LOGE("Could not allocate packet");
goto finally_close_parser;
}
for (;;) { for (;;) {
AVPacket packet; bool ok = stream_recv_packet(stream, packet);
bool ok = stream_recv_packet(stream, &packet);
if (!ok) { if (!ok) {
// end of stream // end of stream
break; break;
} }
ok = stream_push_packet(stream, &packet); ok = stream_push_packet(stream, packet);
av_packet_unref(&packet); av_packet_unref(packet);
if (!ok) { if (!ok) {
// cannot process packet (error already logged) // cannot process packet (error already logged)
break; break;
@ -243,6 +248,8 @@ run_stream(void *data) {
av_packet_free(&stream->pending); av_packet_free(&stream->pending);
} }
av_packet_free(&packet);
finally_close_parser:
av_parser_close(stream->parser); av_parser_close(stream->parser);
finally_close_sinks: finally_close_sinks:
stream_close_sinks(stream); stream_close_sinks(stream);