audio: cut audio with spdif too on playback restart

When playback is started after seeking or opening a file, we need to
make sure audio and video line up exactly. This is done by cutting or
padding the audio stream to start on the video PTS.

This does not quite work with spdif: audio is compressed data, within a
spdif frame. There is no way to cut the audio "in between" the frames.
Cutting between the frames would just produce broken spdif packets, and
who knows how receivers will react to this (play noise?). But we still
can cut it in frame boundaries.

Unfortunately, we also insert 0 data for "silence" - we probably
shouldn't do this. Chances are the receiver will switch to PCM or so.
But for now this will have to do.

Note that this could be simplified somewhat, as soon as we work with
frames. See previous commit.
This commit is contained in:
wm4 2015-03-10 15:17:57 +01:00
parent 5f8b060ec2
commit da46a13c6b
1 changed files with 3 additions and 3 deletions

View File

@ -403,8 +403,7 @@ static bool get_sync_samples(struct MPContext *mpctx, int *skip)
ao_get_format(mpctx->ao, &out_format);
double play_samplerate = out_format.rate / opts->playback_speed;
bool is_pcm = !AF_FORMAT_IS_SPECIAL(out_format.format); // no spdif
if (!opts->initial_audio_sync || !is_pcm) {
if (!opts->initial_audio_sync) {
mpctx->audio_status = STATUS_FILLING;
return true;
}
@ -438,7 +437,8 @@ static bool get_sync_samples(struct MPContext *mpctx, int *skip)
return true;
}
*skip = -ptsdiff * play_samplerate;
int align = af_format_sample_alignment(out_format.format);
*skip = (-ptsdiff * play_samplerate) / align * align;
return true;
}