mirror of
https://github.com/mpv-player/mpv
synced 2025-01-30 11:42:04 +00:00
audio: respect --end/--length with spdif passthrough
In theory, we can't really do this, because we don't know when a spdif frame ends. Spdif transports compressed audio through audio setups that were originally designed for PCM only (which includes the audio filter chain, the AO API, most audio output APIs, etc.), and to reach this goal, spdif pretends to be PCM. Compressed data frames are padded with zeros, until a certain data rate is reached, which corresponds to a pseudo-PCM format with 2 bytes per sample and 2 channels at 48000 Hz. Of course an actual spdif frame is significantly larger than a frame of the PCM format it pretends to be, so cutting audio data on frame boundaries (as according to the pseudo-PCM format) merely yields an incomplete and broken frame, not audio that plays for the desired duration. However, sending an incomplete frame might still be much better than the current behavior, which simply ignores --end/--length (but still lets the video end at the exact end time). Should this result in trouble with real spdif receivers, this commit probably has to be reverted.
This commit is contained in:
parent
f90e7ef7ea
commit
e901bb7c99
@ -367,6 +367,7 @@ int fill_audio_out_buffers(struct MPContext *mpctx, double endpts)
|
||||
bool signal_eof = false;
|
||||
bool partial_fill = false;
|
||||
struct dec_audio *d_audio = mpctx->d_audio;
|
||||
// Can't adjust the start of audio with spdif pass-through.
|
||||
bool modifiable_audio_format = !(ao->format & AF_FORMAT_SPECIAL_MASK);
|
||||
|
||||
assert(d_audio);
|
||||
@ -406,7 +407,7 @@ int fill_audio_out_buffers(struct MPContext *mpctx, double endpts)
|
||||
audio_eof = true;
|
||||
}
|
||||
|
||||
if (endpts != MP_NOPTS_VALUE && modifiable_audio_format) {
|
||||
if (endpts != MP_NOPTS_VALUE) {
|
||||
double samples = (endpts - written_audio_pts(mpctx) + mpctx->audio_delay)
|
||||
* ao->samplerate / opts->playback_speed;
|
||||
if (playsize > samples) {
|
||||
|
Loading…
Reference in New Issue
Block a user