1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-06 15:11:58 +00:00

af_lavcac3enc: use common code for AVFrame setup

This commit is contained in:
wm4 2016-07-24 19:06:00 +02:00
parent d60db967bd
commit 3623cec7d2
3 changed files with 22 additions and 16 deletions

View File

@ -394,12 +394,9 @@ fail:
return NULL;
}
// Returns NULL on failure. The input is always unreffed.
struct AVFrame *mp_audio_to_avframe_and_unref(struct mp_audio *frame)
int mp_audio_to_avframe(struct mp_audio *frame, struct AVFrame *avframe)
{
struct AVFrame *avframe = av_frame_alloc();
if (!avframe)
goto fail;
av_frame_unref(avframe);
avframe->nb_samples = frame->samples;
avframe->format = af_to_avformat(frame->format);
@ -457,6 +454,23 @@ struct AVFrame *mp_audio_to_avframe_and_unref(struct mp_audio *frame)
avframe = tmp;
}
return 0;
fail:
av_frame_unref(avframe);
return -1;
}
// Returns NULL on failure. The input is always unreffed.
struct AVFrame *mp_audio_to_avframe_and_unref(struct mp_audio *frame)
{
struct AVFrame *avframe = av_frame_alloc();
if (!avframe)
goto fail;
if (mp_audio_to_avframe(frame, avframe) < 0)
goto fail;
talloc_free(frame);
return avframe;

View File

@ -81,6 +81,7 @@ int mp_audio_make_writeable(struct mp_audio *data);
struct AVFrame;
struct mp_audio *mp_audio_from_avframe(struct AVFrame *avframe);
struct AVFrame *mp_audio_to_avframe_and_unref(struct mp_audio *frame);
int mp_audio_to_avframe(struct mp_audio *frame, struct AVFrame *avframe);
struct mp_audio_pool;
struct mp_audio_pool *mp_audio_pool_create(void *ta_parent);

View File

@ -249,17 +249,8 @@ static int read_input_frame(struct af_instance *af, AVFrame *frame)
if (!fill_buffer(af))
return 0; // need more input
frame->nb_samples = s->in_samples;
frame->format = s->lavc_actx->sample_fmt;
frame->channel_layout = s->lavc_actx->channel_layout;
#if LIBAVUTIL_VERSION_MICRO >= 100
frame->channels = s->lavc_actx->channels;
#endif
assert(s->input->num_planes <= AV_NUM_DATA_POINTERS);
frame->extended_data = frame->data;
for (int n = 0; n < s->input->num_planes; n++)
frame->data[n] = s->input->planes[n];
frame->linesize[0] = s->input->samples * s->input->sstride;
if (mp_audio_to_avframe(s->input, frame) < 0)
return -1;
return 1;
}