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);
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);
191 if (!self->timefilter) {
192 jack_client_close(self->client);
201 jack_client_close(self->client);
223 jack_deactivate(self->client);
224 jack_client_close(self->client);
226 sem_destroy(&self->packet_count);
264 struct timespec timeout = {0, 0};
271 if (!self->activated) {
272 if (!jack_activate(self->client)) {
275 "JACK client registered and activated (rate=%dHz, buffer_size=%d frames)\n",
276 self->sample_rate, self->buffer_size);
285 if (sem_timedwait(&self->packet_count, &timeout)) {
286 if (errno == ETIMEDOUT) {
288 "Input error: timed out when waiting for JACK process callback output\n");
302 if (self->pkt_xrun) {
307 if (self->jack_xrun) {
328 #define OFFSET(x) offsetof(JackData, x)
350 .priv_class = &jack_indev_class,