24 #include <pulse/rtclock.h>
25 #include <pulse/error.h>
36 #define DEFAULT_CODEC_ID AV_NE(AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE)
58 #define CHECK_SUCCESS_GOTO(rerror, expression, label) \
60 if (!(expression)) { \
61 rerror = AVERROR_EXTERNAL; \
66 #define CHECK_DEAD_GOTO(p, rerror, label) \
68 if (!(p)->context || !PA_CONTEXT_IS_GOOD(pa_context_get_state((p)->context)) || \
69 !(p)->stream || !PA_STREAM_IS_GOOD(pa_stream_get_state((p)->stream))) { \
70 rerror = AVERROR_EXTERNAL; \
78 switch (pa_context_get_state(c)) {
79 case PA_CONTEXT_READY:
80 case PA_CONTEXT_TERMINATED:
81 case PA_CONTEXT_FAILED:
82 pa_threaded_mainloop_signal(p->
mainloop, 0);
90 switch (pa_stream_get_state(s)) {
92 case PA_STREAM_FAILED:
93 case PA_STREAM_TERMINATED:
94 pa_threaded_mainloop_signal(p->
mainloop, 0);
102 pa_threaded_mainloop_signal(p->
mainloop, 0);
108 pa_threaded_mainloop_signal(p->
mainloop, 0);
116 pa_threaded_mainloop_stop(pd->
mainloop);
119 pa_stream_unref(pd->
stream);
123 pa_context_disconnect(pd->
context);
129 pa_threaded_mainloop_free(pd->
mainloop);
150 pa_buffer_attr attr = { -1 };
153 pa_channel_map_init_extend(&cmap, pd->
channels, PA_CHANNEL_MAP_WAVEEX);
164 if (s->
url[0] !=
'\0' && strcmp(s->
url,
"default"))
167 if (!(pd->
mainloop = pa_threaded_mainloop_new())) {
172 if (!(pd->
context = pa_context_new(pa_threaded_mainloop_get_api(pd->
mainloop), pd->
name))) {
184 pa_threaded_mainloop_lock(pd->
mainloop);
186 if (pa_threaded_mainloop_start(pd->
mainloop) < 0) {
188 goto unlock_and_fail;
192 pa_context_state_t
state;
194 state = pa_context_get_state(pd->
context);
196 if (state == PA_CONTEXT_READY)
199 if (!PA_CONTEXT_IS_GOOD(state)) {
201 goto unlock_and_fail;
205 pa_threaded_mainloop_wait(pd->
mainloop);
210 goto unlock_and_fail;
218 ret = pa_stream_connect_record(pd->
stream, device, &attr,
219 PA_STREAM_INTERPOLATE_TIMING
220 |PA_STREAM_ADJUST_LATENCY
221 |PA_STREAM_AUTO_TIMING_UPDATE);
225 goto unlock_and_fail;
229 pa_stream_state_t
state;
231 state = pa_stream_get_state(pd->
stream);
233 if (state == PA_STREAM_READY)
236 if (!PA_STREAM_IS_GOOD(state)) {
238 goto unlock_and_fail;
242 pa_threaded_mainloop_wait(pd->
mainloop);
245 pa_threaded_mainloop_unlock(pd->
mainloop);
265 pa_threaded_mainloop_unlock(pd->
mainloop);
281 pa_threaded_mainloop_lock(pd->
mainloop);
288 r = pa_stream_peek(pd->
stream, &read_data, &read_length);
291 if (read_length <= 0) {
292 pa_threaded_mainloop_wait(pd->
mainloop);
294 }
else if (!read_data) {
297 r = pa_stream_drop(pd->
stream);
304 goto unlock_and_fail;
308 pa_operation_unref(pa_stream_update_timing_info(pd->
stream,
NULL,
NULL));
310 if (pa_stream_get_latency(pd->
stream, &latency, &negative) >= 0) {
314 int frame_duration = read_length /
frame_size;
329 memcpy(pkt->
data, read_data, read_length);
330 pa_stream_drop(pd->
stream);
332 pa_threaded_mainloop_unlock(pd->
mainloop);
336 pa_threaded_mainloop_unlock(pd->
mainloop);
346 #define OFFSET(a) offsetof(PulseData, a)
347 #define D AV_OPT_FLAG_DECODING_PARAM
356 {
"fragment_size",
"set buffering size, affects latency and cpu usage",
OFFSET(fragment_size),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
D },
357 {
"wallclock",
"set the initial pts using the current time",
OFFSET(wallclock),
AV_OPT_TYPE_INT, {.i64 = 1}, -1, 1,
D },
378 .priv_class = &pulse_demuxer_class,
void ff_timefilter_destroy(TimeFilter *self)
Free all resources associated with the filter.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
static int read_data(void *opaque, uint8_t *buf, int buf_size)
#define CHECK_DEAD_GOTO(p, rerror, label)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
const char * av_default_item_name(void *ptr)
Return the context name.
static av_cold int pulse_close(AVFormatContext *s)
AVInputFormat ff_pulse_demuxer
static const AVClass pulse_demuxer_class
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Opaque type representing a time filter state.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
static av_cold int read_close(AVFormatContext *ctx)
#define CHECK_SUCCESS_GOTO(rerror, expression, label)
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
char * url
input or output URL.
enum AVMediaType codec_type
General type of the encoded data.
common internal API header
#define ss(width, name, subs,...)
enum AVCodecID audio_codec_id
Forced audio codec_id.
pa_sample_format_t av_cold ff_codec_id_to_pulse_format(enum AVCodecID codec_id)
static const AVOption options[]
static void stream_request_cb(pa_stream *s, size_t length, void *userdata)
static int read_header(FFV1Context *f)
int64_t av_gettime(void)
Get the current time in microseconds.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
TimeFilter * ff_timefilter_new(double time_base, double period, double bandwidth)
Create a new Delay Locked Loop time filter.
static void stream_state_cb(pa_stream *s, void *userdata)
static av_cold int pulse_read_header(AVFormatContext *s)
Describe the class of an AVClass context structure.
int ff_pulse_audio_get_devices(AVDeviceInfoList *devices, const char *server, int output)
static void context_state_cb(pa_context *c, void *userdata)
#define flags(name, subs,...)
int sample_rate
Audio only.
double ff_timefilter_update(TimeFilter *self, double system_time, double period)
Update the filter.
static void stream_latency_update_cb(pa_stream *s, void *userdata)
void * priv_data
Format private data.
static int pulse_get_device_list(AVFormatContext *h, AVDeviceInfoList *device_list)
pa_threaded_mainloop * mainloop
static int pulse_read_packet(AVFormatContext *s, AVPacket *pkt)
AVCodecParameters * codecpar
Codec parameters associated with this stream.
#define AVERROR_EXTERNAL
Generic error in an external library.
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...