Go to the documentation of this file.
25 #include <jack/jack.h>
42 #define FIFO_PACKETS_NUM 16
68 jack_nframes_t latency, cycle_delay;
77 cycle_delay = jack_frames_since_cycle_start(self->client);
81 av_gettime() / 1000000.0 - (
double) cycle_delay / self->sample_rate,
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];
108 pkt.
pts = (cycle_time - (
double) latency / (self->nports * self->sample_rate)) * 1000000.0;
134 int test, pkt_size =
self->buffer_size *
self->nports *
sizeof(
float);
156 self->client = jack_client_open(
context->url, JackNullOption, &
status);
162 sem_init(&self->packet_count, 0, 0);
164 self->sample_rate = jack_get_sample_rate(self->client);
168 self->buffer_size = jack_get_buffer_size(self->client);
171 for (
i = 0;
i <
self->nports;
i++) {
173 snprintf(str,
sizeof(str),
"input_%d",
i + 1);
174 self->ports[
i] = jack_port_register(self->client, str,
175 JACK_DEFAULT_AUDIO_TYPE,
177 if (!self->ports[
i]) {
180 jack_client_close(self->client);
191 self->timefilter =
ff_timefilter_new (1.0 / self->sample_rate, self->buffer_size, 1.5);
192 if (!self->timefilter) {
193 jack_client_close(self->client);
201 if (!self->new_pkts) {
202 jack_client_close(self->client);
206 jack_client_close(self->client);
227 jack_deactivate(self->client);
228 jack_client_close(self->client);
268 struct timespec timeout = {0, 0};
275 if (!self->activated) {
276 if (!jack_activate(self->client)) {
279 "JACK client registered and activated (rate=%dHz, buffer_size=%d frames)\n",
280 self->sample_rate, self->buffer_size);
290 if (errno == ETIMEDOUT) {
292 "Input error: timed out when waiting for JACK process callback output\n");
306 if (self->pkt_xrun) {
311 if (self->jack_xrun) {
332 #define OFFSET(x) offsetof(JackData, x)
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Opaque type representing a time filter state.
#define AV_LOG_WARNING
Something somehow does not look correct.
size_t av_fifo_can_write(const AVFifo *f)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
enum AVMediaType codec_type
General type of the encoded data.
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
static int xrun_callback(void *arg)
#define FIFO_PACKETS_NUM
Size of the internal FIFO buffers as a number of audio packets.
int nb_channels
Number of channels in this layout.
static int start_jack(AVFormatContext *context)
static const AVClass jack_indev_class
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
static av_cold int read_close(AVFormatContext *ctx)
TimeFilter * ff_timefilter_new(double time_base, double period, double bandwidth)
Create a new Delay Locked Loop time filter.
jack_nframes_t sample_rate
@ AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
#define sem_timedwait(psem, val)
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
static int process_callback(jack_nframes_t nframes, void *arg)
static void free_pkt_fifo(AVFifo **fifop)
static int audio_read_packet(AVFormatContext *context, AVPacket *pkt)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option keep it simple and lowercase description are in without and describe what they for example set the foo of the bar offset is the offset of the field in your context
AVCodecParameters * codecpar
Codec parameters associated with this stream.
#define LIBAVUTIL_VERSION_INT
static int read_header(FFV1Context *f)
Describe the class of an AVClass context structure.
static void shutdown_callback(void *arg)
const char * av_default_item_name(void *ptr)
Return the context name.
size_t av_fifo_can_read(const AVFifo *f)
static int supply_new_packets(JackData *self, AVFormatContext *context)
AVChannelLayout ch_layout
Audio only.
int sample_rate
Audio only.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static void stop_jack(JackData *self)
static int audio_read_close(AVFormatContext *context)
void ff_timefilter_reset(TimeFilter *self)
Reset the filter.
#define AV_LOG_INFO
Standard information.
void ff_timefilter_destroy(TimeFilter *self)
Free all resources associated with the filter.
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define av_malloc_array(a, b)
static const AVOption options[]
double ff_timefilter_update(TimeFilter *self, double system_time, double period)
Update the filter.
#define sem_destroy(psem)
const FFInputFormat ff_jack_demuxer
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
@ AV_OPT_TYPE_INT
Underlying C type is int.
static void test(const char *pattern, const char *host)
int64_t av_gettime(void)
Get the current time in microseconds.
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
jack_nframes_t buffer_size
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
static int audio_read_header(AVFormatContext *context)