| 58 | } JackData; |
| 59 | |
| 60 | static int process_callback(jack_nframes_t nframes, void *arg) |
| 61 | { |
| 62 | /* Warning: this function runs in realtime. One mustn't allocate memory here |
| 63 | * or do any other thing that could block. */ |
| 64 | |
| 65 | int i, j; |
| 66 | JackData *self = arg; |
| 67 | float * buffer; |
| 68 | jack_nframes_t latency, cycle_delay; |
| 69 | AVPacket pkt; |
| 70 | float *pkt_data; |
| 71 | double cycle_time; |
| 72 | |
| 73 | if (!self->client) |
| 74 | return 0; |
| 75 | |
| 76 | /* The approximate delay since the hardware interrupt as a number of frames */ |
| 77 | cycle_delay = jack_frames_since_cycle_start(self->client); |
| 78 | |
| 79 | /* Retrieve filtered cycle time */ |
| 80 | cycle_time = ff_timefilter_update(self->timefilter, |
| 81 | av_gettime() / 1000000.0 - (double) cycle_delay / self->sample_rate, |
| 82 | self->buffer_size); |
| 83 | |
| 84 | /* Check if an empty packet is available, and if there's enough space to send it back once filled */ |
| 85 | if (!av_fifo_can_read(self->new_pkts) || |
| 86 | !av_fifo_can_write(self->filled_pkts)) { |
| 87 | self->pkt_xrun = 1; |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | /* Retrieve empty (but allocated) packet */ |
| 92 | av_fifo_read(self->new_pkts, &pkt, 1); |
| 93 | |
| 94 | pkt_data = (float *) pkt.data; |
| 95 | latency = 0; |
| 96 | |
| 97 | /* Copy and interleave audio data from the JACK buffer into the packet */ |
| 98 | for (i = 0; i < self->nports; i++) { |
| 99 | jack_latency_range_t range; |
| 100 | jack_port_get_latency_range(self->ports[i], JackCaptureLatency, &range); |
| 101 | latency += range.max; |
| 102 | buffer = jack_port_get_buffer(self->ports[i], self->buffer_size); |
| 103 | for (j = 0; j < self->buffer_size; j++) |
| 104 | pkt_data[j * self->nports + i] = buffer[j]; |
| 105 | } |
| 106 | |
| 107 | /* Timestamp the packet with the cycle start time minus the average latency */ |
| 108 | pkt.pts = (cycle_time - (double) latency / (self->nports * self->sample_rate)) * 1000000.0; |
| 109 | |
| 110 | /* Send the now filled packet back, and increase packet counter */ |
| 111 | av_fifo_write(self->filled_pkts, &pkt, 1); |
| 112 | sem_post(&self->packet_count); |
| 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | static void shutdown_callback(void *arg) |
nothing calls this directly
no test coverage detected