mirror of
https://github.com/mpv-player/mpv
synced 2025-03-25 04:38:01 +00:00
encode: bail out on missing A or V stream
In mplayer2, it was valid to try to start encoding before all streams were initialized. mpv avoids this situation and thus allows us to properly bail out on some kinds of failures. Also, this commit fixes a missing check in ao uninit which could cause heap corruption when ao initialization did not complete.
This commit is contained in:
parent
84829a4ea1
commit
538baaef6e
@ -233,15 +233,21 @@ int encode_lavc_start(struct encode_lavc_context *ctx)
|
||||
for (i = 0; i < ctx->avc->nb_streams; ++i)
|
||||
if (ctx->avc->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
|
||||
break;
|
||||
if (i >= ctx->avc->nb_streams)
|
||||
if (i >= ctx->avc->nb_streams) {
|
||||
encode_lavc_fail(ctx,
|
||||
"encode-lavc: video stream missing, invalid codec?\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (ctx->expect_audio) {
|
||||
for (i = 0; i < ctx->avc->nb_streams; ++i)
|
||||
if (ctx->avc->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO)
|
||||
break;
|
||||
if (i >= ctx->avc->nb_streams)
|
||||
if (i >= ctx->avc->nb_streams) {
|
||||
encode_lavc_fail(ctx,
|
||||
"encode-lavc: audio stream missing, invalid codec?\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
ctx->header_written = -1;
|
||||
|
@ -293,6 +293,14 @@ static int encode(struct ao *ao, double apts, void *data);
|
||||
static void uninit(struct ao *ao, bool cut_audio)
|
||||
{
|
||||
struct priv *ac = ao->priv;
|
||||
struct encode_lavc_context *ectx = ao->encode_lavc_ctx;
|
||||
|
||||
if (!encode_lavc_start(ectx)) {
|
||||
mp_msg(MSGT_ENCODE, MSGL_WARN,
|
||||
"ao-lavc: not even ready to encode audio at end -> dropped");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ac->buffer) {
|
||||
double pts = ao->pts + ac->offset / (double) ao->samplerate;
|
||||
if (ao->buffer.len > 0) {
|
||||
@ -455,7 +463,8 @@ static int play(struct ao *ao, void *data, int len, int flags)
|
||||
len /= ac->sample_size * ao->channels;
|
||||
|
||||
if (!encode_lavc_start(ectx)) {
|
||||
mp_msg(MSGT_ENCODE, MSGL_WARN, "ao-lavc: NOTE: deferred initial audio frame (probably because video is not there yet)\n");
|
||||
mp_msg(MSGT_ENCODE, MSGL_WARN,
|
||||
"ao-lavc: not ready yet for encoding audio\n");
|
||||
return 0;
|
||||
}
|
||||
if (pts == MP_NOPTS_VALUE) {
|
||||
|
Loading…
Reference in New Issue
Block a user