24 #include <semaphore.h>
25 #include <jack/jack.h>
38 #define FIFO_PACKETS_NUM 16
64 jack_nframes_t latency, cycle_delay;
73 cycle_delay = jack_frames_since_cycle_start(self->client);
77 av_gettime() / 1000000.0 - (
double) cycle_delay / self->sample_rate,
89 pkt_data = (
float *) pkt.
data;
93 for (i = 0; i <
self->nports; i++) {
94 latency += jack_port_get_total_latency(self->client, self->ports[i]);
95 buffer = jack_port_get_buffer(self->ports[i], self->buffer_size);
96 for (j = 0; j <
self->buffer_size; j++)
97 pkt_data[j * self->nports + i] = buffer[j];
101 pkt.
pts = (cycle_time - (double) latency / (self->nports * self->sample_rate)) * 1000000.0;
105 sem_post(&self->packet_count);
127 int test, pkt_size =
self->buffer_size *
self->nports *
sizeof(float);
145 jack_status_t status;
150 self->client = jack_client_open(context->
filename, JackNullOption, &status);
156 sem_init(&self->packet_count, 0, 0);
158 self->sample_rate = jack_get_sample_rate(self->client);
159 self->ports =
av_malloc(self->nports *
sizeof(*self->ports));
160 self->buffer_size = jack_get_buffer_size(self->client);
163 for (i = 0; i <
self->nports; i++) {
165 snprintf(str,
sizeof(str),
"input_%d", i + 1);
166 self->ports[i] = jack_port_register(self->client, str,
167 JACK_DEFAULT_AUDIO_TYPE,
169 if (!self->ports[i]) {
172 jack_client_close(self->client);
183 period = (double) self->buffer_size / self->sample_rate;
184 o = 2 *
M_PI * 1.5 * period;
185 self->timefilter =
ff_timefilter_new (1.0 / self->sample_rate, sqrt(2 * o), o * o);
192 jack_client_close(self->client);
214 jack_deactivate(self->client);
215 jack_client_close(self->client);
217 sem_destroy(&self->packet_count);
255 struct timespec timeout = {0, 0};
262 if (!self->activated) {
263 if (!jack_activate(self->client)) {
266 "JACK client registered and activated (rate=%dHz, buffer_size=%d frames)\n",
267 self->sample_rate, self->buffer_size);
276 if (sem_timedwait(&self->packet_count, &timeout)) {
277 if (errno == ETIMEDOUT) {
279 "Input error: timed out when waiting for JACK process callback output\n");
290 if (self->pkt_xrun) {
295 if (self->jack_xrun) {
316 #define OFFSET(x) offsetof(JackData, x)
337 .priv_class = &jack_indev_class,
static int supply_new_packets(JackData *self, AVFormatContext *context)
int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void(*func)(void *, void *, int))
Feed data from an AVFifoBuffer to a user-supplied callback.
static const AVClass jack_indev_class
int av_fifo_size(AVFifoBuffer *f)
Return the amount of data in bytes in the AVFifoBuffer, that is the amount of data you can read from ...
void ff_timefilter_destroy(TimeFilter *self)
Free all resources associated with the filter.
static void shutdown_callback(void *arg)
void ff_timefilter_reset(TimeFilter *self)
Reset the filter.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
static int audio_read_header(AVFormatContext *context, AVFormatParameters *params)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int(*func)(void *, void *, int))
Feed data from a user-supplied callback to an AVFifoBuffer.
AVFifoBuffer * filled_pkts
static int read_header(FFV1Context *f)
void av_free_packet(AVPacket *pkt)
Free a packet.
static av_cold int read_close(AVFormatContext *ctx)
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
static int start_jack(AVFormatContext *context)
static int audio_read_packet(AVFormatContext *context, AVPacket *pkt)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_log(void *avcl, int level, const char *fmt,...)
AVStream * avformat_new_stream(AVFormatContext *s, AVCodec *c)
Add a new stream to a media file.
static int audio_read_close(AVFormatContext *context)
AVCodecContext * codec
codec context
#define FIFO_PACKETS_NUM
Size of the internal FIFO buffers as a number of audio packets.
static void stop_jack(JackData *self)
char filename[1024]
input or output filename
int av_fifo_space(AVFifoBuffer *f)
Return the amount of space in bytes in the AVFifoBuffer, that is the amount of data you can write int...
static int xrun_callback(void *arg)
static const AVOption options[]
AVInputFormat ff_jack_demuxer
void av_fifo_free(AVFifoBuffer *f)
Free an AVFifoBuffer.
enum AVMediaType codec_type
int sample_rate
samples per second
jack_nframes_t sample_rate
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
a very simple circular buffer FIFO implementation
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Describe the class of an AVClass context structure.
TimeFilter * ff_timefilter_new(double clock_period, double feedback2_factor, double feedback3_factor)
Create a new Delay Locked Loop time filter.
static void free_pkt_fifo(AVFifoBuffer *fifo)
double ff_timefilter_update(TimeFilter *self, double system_time, double period)
Update the filter.
int channels
number of audio channels
void * priv_data
Format private data.
jack_nframes_t buffer_size
static int process_callback(jack_nframes_t nframes, void *arg)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t av_gettime(void)
Get the current time in microseconds.