36 #define LOC QString("AOJack: ")
54 const char **matching_ports =
nullptr;
60 Error(
LOC + tr(
"Cannot start/connect to jack server "
61 "(to check supported rate/channels)"));
67 rate = jack_get_sample_rate(
m_client);
71 Error(
LOC + tr(
"Unable to retrieve jack server sample rate"));
76 settings->AddSupportedRate(rate);
85 if (!matching_ports || !matching_ports[0])
87 Error(
LOC + tr(
"No ports available to connect to"));
94 settings->AddSupportedChannels(i+1);
95 VBAUDIO(QString(
"Adding channels: %1").arg(i+1));
100 free(
reinterpret_cast<void*
>(matching_ports));
106 free(
reinterpret_cast<void*
>(matching_ports));
121 const char **matching_ports =
nullptr;
127 Error(
LOC + tr(
"Requested more channels: (%1), than the maximum: %2")
132 VBAUDIO( QString(
"Opening JACK audio device: '%1'.")
143 Error(
LOC + tr(
"Cannot start/connect to jack server"));
149 if (!matching_ports || !matching_ports[0])
151 Error(
LOC + tr(
"No ports available to connect to"));
157 while (matching_ports[i])
162 Error(
LOC + tr(
"Not enough ports available to connect to"));
169 QString port_name = QString(
"out_%1").arg(i);
170 m_ports[i] = jack_port_register(
m_client, port_name.toLatin1().constData(),
171 JACK_DEFAULT_AUDIO_TYPE,
172 JackPortIsOutput, 0);
175 Error(
LOC + tr(
"Error while registering new jack port: %1").arg(i));
194 Error(
LOC + tr(
"Error. Unable to set process callback?!"));
196 Error(
LOC + tr(
"Error. Unable to set xrun callback?!"));
198 Error(
LOC + tr(
"Error. Unable to set graph order change callback?!"));
203 Error(
LOC + tr(
"Calling jack_activate failed"));
212 free(
reinterpret_cast<void*
>(matching_ports));
219 free(
reinterpret_cast<void*
>(matching_ports));
242 int frames_played = jack_frames_since_cycle_start (this->
m_client);
243 LOG(VB_AUDIO | VB_TIMESTAMP, LOG_INFO,
244 QString(
"Stats: frames_since_cycle_start:%1 fragment_size:%2")
264 std::array<float,JACK_CHANNELS_MAX> volumes {};
265 for (
int channel = 0; channel <
m_channels; channel++)
271 volumes[channel] = (float) (( channel_volumes[channel] *
272 channel_volumes[channel] ) /
277 volumes[channel] = 1.0 / 1.0;
283 for (
int frame = 0; frame < nframes; frame++)
285 bufs[0][frame] = aubuf[sample++] * volumes[0];
286 bufs[1][frame] = aubuf[sample++] * volumes[1];
291 for (
int frame = 0; frame < nframes; frame++)
295 bufs[0][frame] = aubuf[sample++] * volumes[0];
296 bufs[1][frame] = aubuf[sample++] * volumes[1];
297 bufs[4][frame] = aubuf[sample++] * volumes[4];
298 bufs[5][frame] = aubuf[sample++] * volumes[5];
299 bufs[2][frame] = aubuf[sample++] * volumes[2];
300 bufs[3][frame] = aubuf[sample++] * volumes[3];
305 for (
int frame = 0; frame < nframes; frame++)
310 bufs[0][frame] = aubuf[sample++] * volumes[0];
311 bufs[1][frame] = aubuf[sample++] * volumes[1];
312 bufs[4][frame] = aubuf[sample++] * volumes[4];
313 bufs[5][frame] = aubuf[sample++] * volumes[5];
314 bufs[2][frame] = aubuf[sample++] * volumes[2];
315 bufs[3][frame] = aubuf[sample++] * volumes[3];
316 bufs[6][frame] = aubuf[sample++] * volumes[6];
317 bufs[7][frame] = aubuf[sample++] * volumes[7];
322 for (
int frame = 0; frame < nframes; frame++)
326 for (
int channel = 0; channel <
m_channels; channel++)
328 bufs[channel][frame] = aubuf[sample++] * volumes[channel];
360 std::array<float*,JACK_CHANNELS_MAX> bufs {};
370 for (
int i = 0; i < t_jack_xruns; i++)
373 VBERROR(
"Discarded one audio fragment to compensate for xrun");
382 bufs[i] = (
float*)jack_port_get_buffer(
m_ports[i], nframes);
390 VBAUDIO(
"JackCallback: audio paused");
402 VBAUDIO(
"JackCallback: Play Event");
411 if (bytes_needed > bytes_read)
414 memset(
m_auBuf + bytes_read, 0, bytes_needed - bytes_read);
417 VBERROR(QString(
"Having to insert silence because GetAudioData "
418 "hasn't returned enough data. Wanted: %1 Got: %2")
419 .arg(bytes_needed).arg(bytes_read));
450 float delay = jack_get_xrun_delayed_usecs(
m_client);
454 int fragments = (int)ceilf( ((delay / 1000000.0F) *
m_sampleRate )
457 VBERROR(QString(
"Jack XRun Callback: %1 usecs delayed, xruns now %2")
479 jack_latency_range_t latency_range;
480 jack_nframes_t max_latency = 0;
484 jack_port_get_latency_range(
m_ports[i], JackPlaybackLatency, &latency_range );
485 jack_nframes_t port_latency = latency_range.max;
486 max_latency = std::max(port_latency, max_latency);
490 VBAUDIO(QString(
"JACK graph reordered. Maximum latency=%1")
504 controlLabel +=
"MixerVolume";
513 unsigned int vol = 0;
534 else if (channel == 1)
562 [[maybe_unused]]
int size)
573 QString client_name = QString(
"mythtv_%1").arg(getpid());
574 auto open_options = (jack_options_t)(JackUseExactName | JackNoStartServer);
575 jack_status_t open_status = JackFailure;
577 jack_client_t *client = jack_client_open(client_name.toLatin1().constData(),
578 open_options, &open_status);
585 const char **matching_ports =
nullptr;
586 unsigned long port_flags=JackPortIsInput;
587 const char *port_name =
nullptr;
596 port_flags |= JackPortIsPhysical;
600 matching_ports = jack_get_ports(
m_client, port_name,
nullptr, port_flags);
601 return matching_ports;
612 if (jack_connect(
m_client, jack_port_name(
m_ports[i]), matching_ports[i]))
614 Error(
LOC + tr(
"Calling jack_connect failed on port: %1\n").arg(i));
626 int err = jack_client_close(*client);
628 Error(
LOC + tr(
"Error closing Jack output device. Error: %1")