af_lavcac3enc: replace deprecated av_init_packet()

This commit is contained in:
sfan5 2022-01-09 18:03:45 +01:00
parent 39bed5c7fc
commit d28a792c00
1 changed files with 17 additions and 11 deletions

View File

@ -70,6 +70,7 @@ struct priv {
const struct AVCodec *lavc_acodec; const struct AVCodec *lavc_acodec;
struct AVCodecContext *lavc_actx; struct AVCodecContext *lavc_actx;
AVPacket *lavc_pkt;
int bit_rate; int bit_rate;
int out_samples; // upper bound on encoded output per AC3 frame int out_samples; // upper bound on encoded output per AC3 frame
}; };
@ -134,6 +135,7 @@ static void destroy(struct mp_filter *f)
struct priv *s = f->priv; struct priv *s = f->priv;
reset(f); reset(f);
av_packet_free(&s->lavc_pkt);
avcodec_free_context(&s->lavc_actx); avcodec_free_context(&s->lavc_actx);
} }
@ -152,13 +154,12 @@ static void process(struct mp_filter *f)
bool err = true; bool err = true;
struct mp_aframe *out = NULL; struct mp_aframe *out = NULL;
AVPacket pkt = {0}; AVPacket *pkt = s->lavc_pkt;
av_init_packet(&pkt);
// Send input as long as it wants. // Send input as long as it wants.
while (1) { while (1) {
if (avcodec_is_open(s->lavc_actx)) { if (avcodec_is_open(s->lavc_actx)) {
int lavc_ret = avcodec_receive_packet(s->lavc_actx, &pkt); int lavc_ret = avcodec_receive_packet(s->lavc_actx, pkt);
if (lavc_ret >= 0) if (lavc_ret >= 0)
break; break;
if (lavc_ret < 0 && lavc_ret != AVERROR(EAGAIN)) { if (lavc_ret < 0 && lavc_ret != AVERROR(EAGAIN)) {
@ -217,12 +218,12 @@ static void process(struct mp_filter *f)
mp_aframe_copy_attributes(out, s->in_frame); mp_aframe_copy_attributes(out, s->in_frame);
int frame_size = pkt.size; int frame_size = pkt->size;
int header_len = 0; int header_len = 0;
char hdr[8]; char hdr[8];
if (s->opts->add_iec61937_header && pkt.size > 5) { if (s->opts->add_iec61937_header && pkt->size > 5) {
int bsmod = pkt.data[5] & 0x7; int bsmod = pkt->data[5] & 0x7;
int len = frame_size; int len = frame_size;
frame_size = AC3_FRAME_SIZE * 2 * 2; frame_size = AC3_FRAME_SIZE * 2 * 2;
@ -243,10 +244,10 @@ static void process(struct mp_filter *f)
goto error; goto error;
char *buf = planes[0]; char *buf = planes[0];
memcpy(buf, hdr, header_len); memcpy(buf, hdr, header_len);
memcpy(buf + header_len, pkt.data, pkt.size); memcpy(buf + header_len, pkt->data, pkt->size);
memset(buf + header_len + pkt.size, 0, memset(buf + header_len + pkt->size, 0,
frame_size - (header_len + pkt.size)); frame_size - (header_len + pkt->size));
swap_16((uint16_t *)(buf + header_len), pkt.size / 2); swap_16((uint16_t *)(buf + header_len), pkt->size / 2);
mp_aframe_set_size(out, frame_size / sstride); mp_aframe_set_size(out, frame_size / sstride);
mp_pin_in_write(f->ppins[1], MAKE_FRAME(MP_FRAME_AUDIO, out)); mp_pin_in_write(f->ppins[1], MAKE_FRAME(MP_FRAME_AUDIO, out));
out = NULL; out = NULL;
@ -255,7 +256,7 @@ done:
err = false; err = false;
// fall through // fall through
error: error:
av_packet_unref(&pkt); av_packet_unref(pkt);
talloc_free(out); talloc_free(out);
if (err) if (err)
mp_filter_internal_mark_failed(f); mp_filter_internal_mark_failed(f);
@ -298,6 +299,10 @@ static struct mp_filter *af_lavcac3enc_create(struct mp_filter *parent,
goto error; goto error;
} }
s->lavc_pkt = av_packet_alloc();
if (!s->lavc_pkt)
goto error;
if (mp_set_avopts(f->log, s->lavc_actx, s->opts->avopts) < 0) if (mp_set_avopts(f->log, s->lavc_actx, s->opts->avopts) < 0)
goto error; goto error;
@ -360,6 +365,7 @@ static struct mp_filter *af_lavcac3enc_create(struct mp_filter *parent,
return f; return f;
error: error:
av_packet_free(&s->lavc_pkt);
talloc_free(f); talloc_free(f);
return NULL; return NULL;
} }