ad_spdif: fix regressions

Apparently this was completely broken after commit 22b3f522. Basically,
this locked up immediately completely while decoding the first packet.
The reason was that the buffer calculations confused bytes and number of
samples. Also, EOF reporting was broken (wrong return code).

The special-casing of ad_mpg123 and ad_spdif (with DECODE_MAX_UNIT) is a
bit annoying, but will eventually be solved in a better way.
This commit is contained in:
wm4 2013-11-14 23:54:06 +01:00
parent 4ee51526ae
commit 8512a08046
2 changed files with 9 additions and 9 deletions

View File

@ -193,16 +193,16 @@ static int decode_audio(sh_audio_t *sh, struct mp_audio *buffer, int maxlen)
int sstride = 2 * sh->channels.num;
assert(sstride == buffer->sstride);
if (maxlen < spdif_ctx->iec61937_packet_size)
if (maxlen * sstride < spdif_ctx->iec61937_packet_size)
return 0;
spdif_ctx->out_buffer_len = 0;
spdif_ctx->out_buffer_size = maxlen;
spdif_ctx->out_buffer_size = maxlen * sstride;
spdif_ctx->out_buffer = buffer->planes[0];
struct demux_packet *mpkt = demux_read_packet(sh->gsh);
if (!mpkt)
return 0;
return -1;
AVPacket pkt;
mp_set_av_packet(&pkt, mpkt);
@ -212,15 +212,14 @@ static int decode_audio(sh_audio_t *sh, struct mp_audio *buffer, int maxlen)
sh->pts = mpkt->pts;
sh->pts_offset = 0;
}
int out_len = spdif_ctx->out_buffer_len;
int ret = av_write_frame(lavf_ctx, &pkt);
avio_flush(lavf_ctx->pb);
sh->pts_offset += (spdif_ctx->out_buffer_len - out_len) / sstride;
buffer->samples = spdif_ctx->out_buffer_len / sstride;
sh->pts_offset += buffer->samples;
talloc_free(mpkt);
if (ret < 0)
return -1;
buffer->samples = spdif_ctx->out_buffer_len / sstride;
return 0;
}

View File

@ -56,10 +56,11 @@ static const struct ad_functions * const ad_drivers[] = {
NULL
};
// At least ad_mpg123 needs to be able to decode this many samples at once
#define DECODE_MAX_UNIT 1152
// ad_mpg123 needs to be able to decode 1152 samples at once
// ad_spdif needs up to 8192
#define DECODE_MAX_UNIT MPMAX(8192, 1152)
// At least 8192 samples, plus hack for ad_mpg123
// At least 8192 samples, plus hack for ad_mpg123 and ad_spdif
#define DECODE_BUFFER_SAMPLES (8192 + DECODE_MAX_UNIT)
// Drop audio buffer and reinit it (after format change)