24 #include <semaphore.h>
25 #include <jack/jack.h>
40 #define FIFO_PACKETS_NUM 16
66 jack_nframes_t latency, cycle_delay;
75 cycle_delay = jack_frames_since_cycle_start(self->client);
79 av_gettime() / 1000000.0 - (
double) cycle_delay / self->sample_rate,
91 pkt_data = (
float *) pkt.
data;
95 for (i = 0; i <
self->nports; i++) {
96 #if HAVE_JACK_PORT_GET_LATENCY_RANGE
97 jack_latency_range_t range;
98 jack_port_get_latency_range(self->ports[i], JackCaptureLatency, &range);
101 latency += jack_port_get_total_latency(self->client, self->ports[i]);
103 buffer = jack_port_get_buffer(self->ports[i], self->buffer_size);
104 for (j = 0; j <
self->buffer_size; j++)
105 pkt_data[j * self->nports + i] = buffer[j];
109 pkt.
pts = (cycle_time - (double) latency / (self->nports * self->sample_rate)) * 1000000.0;
113 sem_post(&self->packet_count);
135 int test, pkt_size =
self->buffer_size *
self->nports *
sizeof(float);
153 jack_status_t status;
157 self->client = jack_client_open(context->
filename, JackNullOption, &status);
163 sem_init(&self->packet_count, 0, 0);
165 self->sample_rate = jack_get_sample_rate(self->client);
166 self->ports =
av_malloc(self->nports *
sizeof(*self->ports));
167 self->buffer_size = jack_get_buffer_size(self->client);
170 for (i = 0; i <
self->nports; i++) {
172 snprintf(str,
sizeof(str),
"input_%d", i + 1);
173 self->ports[i] = jack_port_register(self->client, str,
174 JACK_DEFAULT_AUDIO_TYPE,
176 if (!self->ports[i]) {
179 jack_client_close(self->client);
190 self->timefilter =
ff_timefilter_new (1.0 / self->sample_rate, self->buffer_size, 1.5);
197 jack_client_close(self->client);
219 jack_deactivate(self->client);
220 jack_client_close(self->client);
222 sem_destroy(&self->packet_count);
260 struct timespec timeout = {0, 0};
267 if (!self->activated) {
268 if (!jack_activate(self->client)) {
271 "JACK client registered and activated (rate=%dHz, buffer_size=%d frames)\n",
272 self->sample_rate, self->buffer_size);
281 if (sem_timedwait(&self->packet_count, &timeout)) {
282 if (errno == ETIMEDOUT) {
284 "Input error: timed out when waiting for JACK process callback output\n");
295 if (self->pkt_xrun) {
300 if (self->jack_xrun) {
321 #define OFFSET(x) offsetof(JackData, x)
342 .priv_class = &jack_indev_class,