mirror of
https://github.com/mpv-player/mpv
synced 2025-02-18 13:47:04 +00:00
ao_jack: align data sizes on audio frame size
Fixes crashes when playing with certain numbers of channels. The core assumes AOs accept data aligned on channels * samplesize, and ao_jack's play() function broke that assumption: mpv: core/mplayer.c:2348: fill_audio_out_buffers: Assertion `played % unitsize == 0' failed. Fix by aligning the buffer and chunk sizes as needed.
This commit is contained in:
parent
4e6098ed49
commit
e54ab16d1a
@ -56,7 +56,6 @@ static volatile float callback_time = 0;
|
||||
#define CHUNK_SIZE (16 * 1024)
|
||||
//! number of "virtual" chunks the buffer consists of
|
||||
#define NUM_CHUNKS 8
|
||||
#define BUFFSIZE (NUM_CHUNKS * CHUNK_SIZE)
|
||||
|
||||
//! buffer for audio data
|
||||
static AVFifoBuffer *buffer;
|
||||
@ -159,7 +158,7 @@ static int outputaudio(jack_nframes_t nframes, void *arg)
|
||||
int i;
|
||||
for (i = 0; i < num_ports; i++)
|
||||
bufs[i] = jack_port_get_buffer(ports[i], nframes);
|
||||
if (paused || underrun)
|
||||
if (paused || underrun || !buffer)
|
||||
silence(bufs, nframes, num_ports);
|
||||
else if (read_buffer(bufs, nframes, num_ports) < nframes)
|
||||
underrun = 1;
|
||||
@ -239,7 +238,6 @@ static int init(struct ao *ao, char *params)
|
||||
mp_msg(MSGT_AO, MSGL_FATAL, "[JACK] cannot open server\n");
|
||||
goto err_out;
|
||||
}
|
||||
buffer = av_fifo_alloc(BUFFSIZE);
|
||||
jack_set_process_callback(client, outputaudio, ao);
|
||||
|
||||
// list matching ports if connections should be made
|
||||
@ -296,8 +294,10 @@ static int init(struct ao *ao, char *params)
|
||||
|
||||
ao->format = AF_FORMAT_FLOAT_NE;
|
||||
ao->bps = ao->channels.num * ao->samplerate * sizeof(float);
|
||||
ao->buffersize = CHUNK_SIZE * NUM_CHUNKS;
|
||||
ao->outburst = CHUNK_SIZE;
|
||||
int unitsize = ao->channels.num * sizeof(float);
|
||||
ao->outburst = CHUNK_SIZE / unitsize * unitsize;
|
||||
ao->buffersize = NUM_CHUNKS * ao->outburst;
|
||||
buffer = av_fifo_alloc(ao->buffersize);
|
||||
free(matching_ports);
|
||||
free(port_name);
|
||||
free(client_name);
|
||||
|
Loading…
Reference in New Issue
Block a user