mirror of
https://github.com/mpv-player/mpv
synced 2025-04-04 23:40:47 +00:00
ao_lavc: slightly simplify filter use
Create a central function which pumps data through the filter. This also might fix bogus use of the filter API on flushing. (The filter is just used for convenience, but I guess the overall result is still simpler.)
This commit is contained in:
parent
4b3500dd14
commit
d3afe34c09
@ -59,7 +59,7 @@ struct priv {
|
|||||||
bool shutdown;
|
bool shutdown;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void read_frames(struct ao *ao);
|
static bool write_frame(struct ao *ao, struct mp_frame frame);
|
||||||
|
|
||||||
static bool supports_format(const AVCodec *codec, int format)
|
static bool supports_format(const AVCodec *codec, int format)
|
||||||
{
|
{
|
||||||
@ -188,9 +188,8 @@ static void uninit(struct ao *ao)
|
|||||||
|
|
||||||
outpts += encoder_get_offset(ac->enc);
|
outpts += encoder_get_offset(ac->enc);
|
||||||
|
|
||||||
if (!mp_pin_in_write(ac->fix_frame_size->pins[0], MP_EOF_FRAME))
|
if (!write_frame(ao, MP_EOF_FRAME))
|
||||||
MP_WARN(ao, "could not flush last frame\n");
|
MP_WARN(ao, "could not flush last frame\n");
|
||||||
read_frames(ao);
|
|
||||||
encoder_encode(ac->enc, NULL);
|
encoder_encode(ac->enc, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,10 +229,16 @@ static void encode(struct ao *ao, struct mp_aframe *af)
|
|||||||
av_frame_free(&frame);
|
av_frame_free(&frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void read_frames(struct ao *ao)
|
static bool write_frame(struct ao *ao, struct mp_frame frame)
|
||||||
{
|
{
|
||||||
struct priv *ac = ao->priv;
|
struct priv *ac = ao->priv;
|
||||||
|
|
||||||
|
// Can't push in frame if it doesn't want it output one.
|
||||||
|
mp_pin_out_request_data(ac->fix_frame_size->pins[1]);
|
||||||
|
|
||||||
|
if (!mp_pin_in_write(ac->fix_frame_size->pins[0], frame))
|
||||||
|
return false; // shouldn't happen™
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
struct mp_frame fr = mp_pin_out_read(ac->fix_frame_size->pins[1]);
|
struct mp_frame fr = mp_pin_out_read(ac->fix_frame_size->pins[1]);
|
||||||
if (!fr.type)
|
if (!fr.type)
|
||||||
@ -244,6 +249,8 @@ static void read_frames(struct ao *ao)
|
|||||||
encode(ao, af);
|
encode(ao, af);
|
||||||
mp_frame_unref(&fr);
|
mp_frame_unref(&fr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool audio_write(struct ao *ao, void **data, int samples)
|
static bool audio_write(struct ao *ao, void **data, int samples)
|
||||||
@ -295,14 +302,7 @@ static bool audio_write(struct ao *ao, void **data, int samples)
|
|||||||
|
|
||||||
mp_aframe_set_pts(af, outpts);
|
mp_aframe_set_pts(af, outpts);
|
||||||
|
|
||||||
// Can't push in frame if it doesn't want it output one.
|
return write_frame(ao, MAKE_FRAME(MP_FRAME_AUDIO, af));
|
||||||
mp_pin_out_request_data(ac->fix_frame_size->pins[1]);
|
|
||||||
|
|
||||||
if (!mp_pin_in_write(ac->fix_frame_size->pins[0],
|
|
||||||
MAKE_FRAME(MP_FRAME_AUDIO, af)))
|
|
||||||
return false; // shouldn't happen™
|
|
||||||
read_frames(ao);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void get_state(struct ao *ao, struct mp_pcm_state *state)
|
static void get_state(struct ao *ao, struct mp_pcm_state *state)
|
||||||
|
Loading…
Reference in New Issue
Block a user