mirror of
https://github.com/mpv-player/mpv
synced 2025-01-30 11:42:04 +00:00
af_lavcac3enc: replace deprecated av_init_packet()
This commit is contained in:
parent
39bed5c7fc
commit
d28a792c00
@ -70,6 +70,7 @@ struct priv {
|
||||
|
||||
const struct AVCodec *lavc_acodec;
|
||||
struct AVCodecContext *lavc_actx;
|
||||
AVPacket *lavc_pkt;
|
||||
int bit_rate;
|
||||
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;
|
||||
|
||||
reset(f);
|
||||
av_packet_free(&s->lavc_pkt);
|
||||
avcodec_free_context(&s->lavc_actx);
|
||||
}
|
||||
|
||||
@ -152,13 +154,12 @@ static void process(struct mp_filter *f)
|
||||
|
||||
bool err = true;
|
||||
struct mp_aframe *out = NULL;
|
||||
AVPacket pkt = {0};
|
||||
av_init_packet(&pkt);
|
||||
AVPacket *pkt = s->lavc_pkt;
|
||||
|
||||
// Send input as long as it wants.
|
||||
while (1) {
|
||||
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)
|
||||
break;
|
||||
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);
|
||||
|
||||
int frame_size = pkt.size;
|
||||
int frame_size = pkt->size;
|
||||
int header_len = 0;
|
||||
char hdr[8];
|
||||
|
||||
if (s->opts->add_iec61937_header && pkt.size > 5) {
|
||||
int bsmod = pkt.data[5] & 0x7;
|
||||
if (s->opts->add_iec61937_header && pkt->size > 5) {
|
||||
int bsmod = pkt->data[5] & 0x7;
|
||||
int len = frame_size;
|
||||
|
||||
frame_size = AC3_FRAME_SIZE * 2 * 2;
|
||||
@ -243,10 +244,10 @@ static void process(struct mp_filter *f)
|
||||
goto error;
|
||||
char *buf = planes[0];
|
||||
memcpy(buf, hdr, header_len);
|
||||
memcpy(buf + header_len, pkt.data, pkt.size);
|
||||
memset(buf + header_len + pkt.size, 0,
|
||||
frame_size - (header_len + pkt.size));
|
||||
swap_16((uint16_t *)(buf + header_len), pkt.size / 2);
|
||||
memcpy(buf + header_len, pkt->data, pkt->size);
|
||||
memset(buf + header_len + pkt->size, 0,
|
||||
frame_size - (header_len + pkt->size));
|
||||
swap_16((uint16_t *)(buf + header_len), pkt->size / 2);
|
||||
mp_aframe_set_size(out, frame_size / sstride);
|
||||
mp_pin_in_write(f->ppins[1], MAKE_FRAME(MP_FRAME_AUDIO, out));
|
||||
out = NULL;
|
||||
@ -255,7 +256,7 @@ done:
|
||||
err = false;
|
||||
// fall through
|
||||
error:
|
||||
av_packet_unref(&pkt);
|
||||
av_packet_unref(pkt);
|
||||
talloc_free(out);
|
||||
if (err)
|
||||
mp_filter_internal_mark_failed(f);
|
||||
@ -298,6 +299,10 @@ static struct mp_filter *af_lavcac3enc_create(struct mp_filter *parent,
|
||||
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)
|
||||
goto error;
|
||||
|
||||
@ -360,6 +365,7 @@ static struct mp_filter *af_lavcac3enc_create(struct mp_filter *parent,
|
||||
return f;
|
||||
|
||||
error:
|
||||
av_packet_free(&s->lavc_pkt);
|
||||
talloc_free(f);
|
||||
return NULL;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user