Skip to content

Commit

Permalink
Allocate AVPacket for v4l2_sink
Browse files Browse the repository at this point in the history
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 <#2302>
  • Loading branch information
rom1v committed Jun 14, 2021
1 parent 4af317d commit cd28945
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions app/src/v4l2_sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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:
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion app/src/v4l2_sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct sc_v4l2_sink {
bool header_written;

AVFrame *frame;
AVPacket packet;
AVPacket *packet;
};

bool
Expand Down

0 comments on commit cd28945

Please sign in to comment.