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 <https://github.com/Genymobile/scrcpy/issues/2302>
This commit is contained in:
Romain Vimont 2021-06-14 09:07:49 +02:00
parent 4af317d40d
commit cd2894570d
2 changed files with 12 additions and 3 deletions

View file

@ -86,7 +86,7 @@ encode_and_write_frame(struct sc_v4l2_sink *vs, const AVFrame *frame) {
return false; return false;
} }
AVPacket *packet = &vs->packet; AVPacket *packet = vs->packet;
ret = avcodec_receive_packet(vs->encoder_ctx, packet); ret = avcodec_receive_packet(vs->encoder_ctx, packet);
if (ret == 0) { if (ret == 0) {
// A packet was received // A packet was received
@ -235,11 +235,17 @@ sc_v4l2_sink_open(struct sc_v4l2_sink *vs) {
goto error_avcodec_close; 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"); LOGD("Starting v4l2 thread");
ok = sc_thread_create(&vs->thread, run_v4l2_sink, "v4l2", vs); ok = sc_thread_create(&vs->thread, run_v4l2_sink, "v4l2", vs);
if (!ok) { if (!ok) {
LOGC("Could not start v4l2 thread"); LOGC("Could not start v4l2 thread");
goto error_av_frame_free; goto error_av_packet_free;
} }
vs->header_written = false; vs->header_written = false;
@ -249,6 +255,8 @@ sc_v4l2_sink_open(struct sc_v4l2_sink *vs) {
return true; return true;
error_av_packet_free:
av_packet_free(&vs->packet);
error_av_frame_free: error_av_frame_free:
av_frame_free(&vs->frame); av_frame_free(&vs->frame);
error_avcodec_close: error_avcodec_close:
@ -278,6 +286,7 @@ sc_v4l2_sink_close(struct sc_v4l2_sink *vs) {
sc_thread_join(&vs->thread, NULL); sc_thread_join(&vs->thread, NULL);
av_packet_free(&vs->packet);
av_frame_free(&vs->frame); av_frame_free(&vs->frame);
avcodec_close(vs->encoder_ctx); avcodec_close(vs->encoder_ctx);
avcodec_free_context(&vs->encoder_ctx); avcodec_free_context(&vs->encoder_ctx);

View file

@ -26,7 +26,7 @@ struct sc_v4l2_sink {
bool header_written; bool header_written;
AVFrame *frame; AVFrame *frame;
AVPacket packet; AVPacket *packet;
}; };
bool bool