25 #include <jack/jack.h>
41 #define FIFO_PACKETS_NUM 16
67 jack_nframes_t latency, cycle_delay;
76 cycle_delay = jack_frames_since_cycle_start(self->client);
80 av_gettime() / 1000000.0 - (
double) cycle_delay / self->sample_rate,
96 for (
i = 0;
i <
self->nports;
i++) {
97 jack_latency_range_t range;
98 jack_port_get_latency_range(self->ports[
i], JackCaptureLatency, &range);
100 buffer = jack_port_get_buffer(self->ports[
i], self->buffer_size);
101 for (j = 0; j <
self->buffer_size; j++)
102 pkt_data[j * self->nports +
i] =
buffer[j];
106 pkt.
pts = (cycle_time - (double) latency / (self->nports * self->sample_rate)) * 1000000.0;
132 int test, pkt_size =
self->buffer_size *
self->nports *
sizeof(float);
150 jack_status_t status;
154 self->client = jack_client_open(context->
url, JackNullOption, &status);
160 sem_init(&self->packet_count, 0, 0);
162 self->sample_rate = jack_get_sample_rate(self->client);
166 self->buffer_size = jack_get_buffer_size(self->client);
169 for (
i = 0;
i <
self->nports;
i++) {
172 self->ports[
i] = jack_port_register(self->client,
str,
173 JACK_DEFAULT_AUDIO_TYPE,
175 if (!self->ports[
i]) {
178 jack_client_close(self->client);
189 self->timefilter =
ff_timefilter_new (1.0 / self->sample_rate, self->buffer_size, 1.5);
190 if (!self->timefilter) {
191 jack_client_close(self->client);
199 if (!self->new_pkts) {
200 jack_client_close(self->client);
204 jack_client_close(self->client);
226 jack_deactivate(self->client);
227 jack_client_close(self->client);
267 struct timespec timeout = {0, 0};
274 if (!self->activated) {
275 if (!jack_activate(self->client)) {
278 "JACK client registered and activated (rate=%dHz, buffer_size=%d frames)\n",
279 self->sample_rate, self->buffer_size);
289 if (errno == ETIMEDOUT) {
291 "Input error: timed out when waiting for JACK process callback output\n");
305 if (self->pkt_xrun) {
310 if (self->jack_xrun) {
331 #define OFFSET(x) offsetof(JackData, x)
Libavcodec external API header.
Main libavdevice API header.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
#define flags(name, subs,...)
static int read_header(FFV1Context *f)
a very simple circular buffer FIFO implementation
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
#define LIBAVUTIL_VERSION_INT
#define FIFO_PACKETS_NUM
Size of the internal FIFO buffers as a number of audio packets.
static int audio_read_close(AVFormatContext *context)
static const AVOption options[]
AVInputFormat ff_jack_demuxer
static int audio_read_header(AVFormatContext *context)
static void free_pkt_fifo(AVFifoBuffer **fifo)
static int start_jack(AVFormatContext *context)
static const AVClass jack_indev_class
static void stop_jack(JackData *self)
static int process_callback(jack_nframes_t nframes, void *arg)
static int audio_read_packet(AVFormatContext *context, AVPacket *pkt)
static int xrun_callback(void *arg)
static void shutdown_callback(void *arg)
static int supply_new_packets(JackData *self, AVFormatContext *context)
void av_fifo_freep(AVFifoBuffer **f)
Free an AVFifoBuffer and reset pointer to NULL.
int av_fifo_size(const AVFifoBuffer *f)
Return the amount of data in bytes in the AVFifoBuffer, that is the amount of data you can read from ...
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.
int av_fifo_space(const AVFifoBuffer *f)
Return the amount of space in bytes in the AVFifoBuffer, that is the amount of data you can write int...
AVFifoBuffer * av_fifo_alloc_array(size_t nmemb, size_t size)
Initialize an AVFifoBuffer.
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.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static av_cold int read_close(AVFormatContext *ctx)
@ AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT
static void test(const char *pattern, const char *host)
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
#define sem_timedwait(psem, val)
#define sem_destroy(psem)
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
enum AVMediaType codec_type
General type of the encoded data.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int sample_rate
Audio only.
char * url
input or output URL.
void * priv_data
Format private data.
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
AVCodecParameters * codecpar
Codec parameters associated with this stream.
jack_nframes_t buffer_size
jack_nframes_t sample_rate
AVFifoBuffer * filled_pkts
Opaque type representing a time filter state.
#define av_malloc_array(a, b)
int64_t av_gettime(void)
Get the current time in microseconds.
double ff_timefilter_update(TimeFilter *self, double system_time, double period)
Update the filter.
void ff_timefilter_destroy(TimeFilter *self)
Free all resources associated with the filter.
TimeFilter * ff_timefilter_new(double time_base, double period, double bandwidth)
Create a new Delay Locked Loop time filter.
void ff_timefilter_reset(TimeFilter *self)
Reset the filter.