本文整理汇总了C++中pa_sample_spec_valid函数的典型用法代码示例。如果您正苦于以下问题:C++ pa_sample_spec_valid函数的具体用法?C++ pa_sample_spec_valid怎么用?C++ pa_sample_spec_valid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pa_sample_spec_valid函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pa_assert
static pa_sample_spec *parse_sdp_sample_spec(pa_sample_spec *ss, char *c) {
unsigned rate, channels;
pa_assert(ss);
pa_assert(c);
if (pa_startswith(c, "L16/")) {
ss->format = PA_SAMPLE_S16BE;
c += 4;
} else if (pa_startswith(c, "L8/")) {
ss->format = PA_SAMPLE_U8;
c += 3;
} else if (pa_startswith(c, "PCMA/")) {
ss->format = PA_SAMPLE_ALAW;
c += 5;
} else if (pa_startswith(c, "PCMU/")) {
ss->format = PA_SAMPLE_ULAW;
c += 5;
} else
return NULL;
if (sscanf(c, "%u/%u", &rate, &channels) == 2) {
ss->rate = (uint32_t) rate;
ss->channels = (uint8_t) channels;
} else if (sscanf(c, "%u", &rate) == 2) {
ss->rate = (uint32_t) rate;
ss->channels = 1;
} else
return NULL;
if (!pa_sample_spec_valid(ss))
return NULL;
return ss;
}
示例2: pa_assert
char *pa_sample_spec_to_mime_type(const pa_sample_spec *ss, const pa_channel_map *cm) {
pa_assert(pa_channel_map_compatible(cm, ss));
pa_assert(pa_sample_spec_valid(ss));
if (!pa_sample_spec_is_mime(ss, cm))
return NULL;
switch (ss->format) {
case PA_SAMPLE_S16BE:
case PA_SAMPLE_S24BE:
case PA_SAMPLE_U8:
/* Stupid UPnP implementations (PS3...) choke on spaces in
* the mime type, that's why we write only ';' here,
* instead of '; '. */
return pa_sprintf_malloc("audio/%s;rate=%u;channels=%u",
ss->format == PA_SAMPLE_S16BE ? "L16" :
(ss->format == PA_SAMPLE_S24BE ? "L24" : "L8"),
ss->rate, ss->channels);
case PA_SAMPLE_ULAW:
return pa_xstrdup("audio/basic");
default:
pa_assert_not_reached();
}
}
示例3: pulse_start_recording
/**
* Start recording
*
* We request the default format used by pulse here because the data will be
* converted and possibly re-sampled by obs anyway.
*
* For now we request a buffer length of 25ms although pulse seems to ignore
* this setting for monitor streams. For "real" input streams this should work
* fine though.
*/
static int_fast32_t pulse_start_recording(struct pulse_data *data)
{
if (pulse_get_server_info(pulse_server_info, (void *) data) < 0) {
blog(LOG_ERROR, "Unable to get server info !");
return -1;
}
if (pulse_get_source_info(pulse_source_info, data->device,
(void *) data) < 0) {
blog(LOG_ERROR, "Unable to get source info !");
return -1;
}
pa_sample_spec spec;
spec.format = data->format;
spec.rate = data->samples_per_sec;
spec.channels = data->channels;
if (!pa_sample_spec_valid(&spec)) {
blog(LOG_ERROR, "Sample spec is not valid");
return -1;
}
data->speakers = pulse_channels_to_obs_speakers(spec.channels);
data->bytes_per_frame = pa_frame_size(&spec);
data->stream = pulse_stream_new(obs_source_get_name(data->source),
&spec, NULL);
if (!data->stream) {
blog(LOG_ERROR, "Unable to create stream");
return -1;
}
pulse_lock();
pa_stream_set_read_callback(data->stream, pulse_stream_read,
(void *) data);
pulse_unlock();
pa_buffer_attr attr;
attr.fragsize = pa_usec_to_bytes(25000, &spec);
attr.maxlength = (uint32_t) -1;
attr.minreq = (uint32_t) -1;
attr.prebuf = (uint32_t) -1;
attr.tlength = (uint32_t) -1;
pa_stream_flags_t flags = PA_STREAM_ADJUST_LATENCY;
pulse_lock();
int_fast32_t ret = pa_stream_connect_record(data->stream, data->device,
&attr, flags);
pulse_unlock();
if (ret < 0) {
pulse_stop_recording(data);
blog(LOG_ERROR, "Unable to connect to stream");
return -1;
}
blog(LOG_INFO, "Started recording from '%s'", data->device);
return 0;
}
示例4: pa_scache_add_item
int pa_scache_add_item(
pa_core *c,
const char *name,
const pa_sample_spec *ss,
const pa_channel_map *map,
const pa_memchunk *chunk,
pa_proplist *p,
uint32_t *idx) {
pa_scache_entry *e;
char st[PA_SAMPLE_SPEC_SNPRINT_MAX];
pa_channel_map tmap;
pa_assert(c);
pa_assert(name);
pa_assert(!ss || pa_sample_spec_valid(ss));
pa_assert(!map || (pa_channel_map_valid(map) && ss && pa_channel_map_compatible(map, ss)));
if (ss && !map) {
pa_channel_map_init_extend(&tmap, ss->channels, PA_CHANNEL_MAP_DEFAULT);
map = &tmap;
}
if (chunk && chunk->length > PA_SCACHE_ENTRY_SIZE_MAX)
return -1;
if (!(e = scache_add_item(c, name)))
return -1;
pa_sample_spec_init(&e->sample_spec);
pa_channel_map_init(&e->channel_map);
pa_cvolume_init(&e->volume);
e->volume_is_set = FALSE;
if (ss) {
e->sample_spec = *ss;
pa_cvolume_reset(&e->volume, ss->channels);
}
if (map)
e->channel_map = *map;
if (chunk) {
e->memchunk = *chunk;
pa_memblock_ref(e->memchunk.memblock);
}
if (p)
pa_proplist_update(e->proplist, PA_UPDATE_REPLACE, p);
if (idx)
*idx = e->index;
pa_log_debug("Created sample \"%s\" (#%d), %lu bytes with sample spec %s",
name, e->index, (unsigned long) e->memchunk.length,
pa_sample_spec_snprint(st, sizeof(st), &e->sample_spec));
return 0;
}
示例5: pa_silence_memchunk_get
pa_memchunk* pa_silence_memchunk_get(pa_silence_cache *cache, pa_mempool *pool, pa_memchunk* ret, const pa_sample_spec *spec, size_t length) {
pa_memblock *b;
size_t l;
pa_assert(cache);
pa_assert(pa_sample_spec_valid(spec));
if (!(b = cache->blocks[spec->format]))
switch (spec->format) {
case PA_SAMPLE_U8:
cache->blocks[PA_SAMPLE_U8] = b = silence_memblock_new(pool, 0x80);
break;
case PA_SAMPLE_S16LE:
case PA_SAMPLE_S16BE:
case PA_SAMPLE_S32LE:
case PA_SAMPLE_S32BE:
case PA_SAMPLE_S24LE:
case PA_SAMPLE_S24BE:
case PA_SAMPLE_S24_32LE:
case PA_SAMPLE_S24_32BE:
case PA_SAMPLE_FLOAT32LE:
case PA_SAMPLE_FLOAT32BE:
cache->blocks[PA_SAMPLE_S16LE] = b = silence_memblock_new(pool, 0);
cache->blocks[PA_SAMPLE_S16BE] = pa_memblock_ref(b);
cache->blocks[PA_SAMPLE_S32LE] = pa_memblock_ref(b);
cache->blocks[PA_SAMPLE_S32BE] = pa_memblock_ref(b);
cache->blocks[PA_SAMPLE_S24LE] = pa_memblock_ref(b);
cache->blocks[PA_SAMPLE_S24BE] = pa_memblock_ref(b);
cache->blocks[PA_SAMPLE_S24_32LE] = pa_memblock_ref(b);
cache->blocks[PA_SAMPLE_S24_32BE] = pa_memblock_ref(b);
cache->blocks[PA_SAMPLE_FLOAT32LE] = pa_memblock_ref(b);
cache->blocks[PA_SAMPLE_FLOAT32BE] = pa_memblock_ref(b);
break;
case PA_SAMPLE_ALAW:
cache->blocks[PA_SAMPLE_ALAW] = b = silence_memblock_new(pool, 0xd5);
break;
case PA_SAMPLE_ULAW:
cache->blocks[PA_SAMPLE_ULAW] = b = silence_memblock_new(pool, 0xff);
break;
default:
pa_assert_not_reached();
}
pa_assert(b);
ret->memblock = pa_memblock_ref(b);
l = pa_memblock_get_length(b);
if (length > l || length == 0)
length = l;
ret->length = pa_frame_align(length, spec);
ret->index = 0;
return ret;
}
示例6: pulse_start_recording
/*
* start recording
*/
static int_fast32_t pulse_start_recording(struct pulse_data *data)
{
if (pulse_get_server_info(pulse_server_info, (void *) data) < 0) {
blog(LOG_ERROR, "pulse-input: Unable to get server info !");
return -1;
}
pa_sample_spec spec;
spec.format = data->format;
spec.rate = data->samples_per_sec;
spec.channels = data->channels;
if (!pa_sample_spec_valid(&spec)) {
blog(LOG_ERROR, "pulse-input: Sample spec is not valid");
return -1;
}
data->bytes_per_frame = pa_frame_size(&spec);
blog(LOG_DEBUG, "pulse-input: %u bytes per frame",
(unsigned int) data->bytes_per_frame);
data->stream = pulse_stream_new(obs_source_getname(data->source),
&spec, NULL);
if (!data->stream) {
blog(LOG_ERROR, "pulse-input: Unable to create stream");
return -1;
}
pulse_lock();
pa_stream_set_read_callback(data->stream, pulse_stream_read,
(void *) data);
pulse_unlock();
pa_buffer_attr attr;
attr.fragsize = get_buffer_size(data, 250);
attr.maxlength = (uint32_t) -1;
attr.minreq = (uint32_t) -1;
attr.prebuf = (uint32_t) -1;
attr.tlength = (uint32_t) -1;
pa_stream_flags_t flags =
PA_STREAM_INTERPOLATE_TIMING
| PA_STREAM_AUTO_TIMING_UPDATE
| PA_STREAM_ADJUST_LATENCY;
pulse_lock();
int_fast32_t ret = pa_stream_connect_record(data->stream, data->device,
&attr, flags);
pulse_unlock();
if (ret < 0) {
blog(LOG_ERROR, "pulse-input: Unable to connect to stream");
return -1;
}
blog(LOG_DEBUG, "pulse-input: Recording started");
return 0;
}
示例7: pa_channel_map_compatible
int pa_channel_map_compatible(const pa_channel_map *map, const pa_sample_spec *ss) {
pa_assert(map);
pa_assert(ss);
pa_return_val_if_fail(pa_channel_map_valid(map), 0);
pa_return_val_if_fail(pa_sample_spec_valid(ss), 0);
return map->channels == ss->channels;
}
示例8: eventd_sound_pulseaudio_play_data
void
eventd_sound_pulseaudio_play_data(EventdSoundPulseaudioContext *context, gpointer data, gsize length, gint format, guint32 rate, guint8 channels)
{
pa_sample_spec sample_spec;
pa_stream *stream;
EventdSoundPulseaudioEventData *event_data;
if ( data == NULL )
return;
if ( ( context == NULL ) || ( pa_context_get_state(context->context) != PA_CONTEXT_READY ) )
{
g_free(data);
return;
}
switch ( format )
{
case SF_FORMAT_PCM_16:
case SF_FORMAT_PCM_U8:
case SF_FORMAT_PCM_S8:
sample_spec.format = PA_SAMPLE_S16NE;
break;
case SF_FORMAT_PCM_24:
sample_spec.format = PA_SAMPLE_S24NE;
break;
case SF_FORMAT_PCM_32:
sample_spec.format = PA_SAMPLE_S32NE;
break;
case SF_FORMAT_FLOAT:
case SF_FORMAT_DOUBLE:
sample_spec.format = PA_SAMPLE_FLOAT32NE;
break;
default:
g_warning("Unsupported format");
return;
}
sample_spec.rate = rate;
sample_spec.channels = channels;
if ( ! pa_sample_spec_valid(&sample_spec) )
{
g_warning("Invalid spec");
return;
}
stream = pa_stream_new(context->context, "sndfile plugin playback", &sample_spec, NULL);
event_data = g_new0(EventdSoundPulseaudioEventData, 1);
event_data->data = data;
event_data->length = length;
pa_stream_set_state_callback(stream, _eventd_sound_pulseaudio_stream_state_callback, event_data);
pa_stream_connect_playback(stream, NULL, NULL, 0, NULL, NULL);
}
示例9: pa_cvolume_compatible
int pa_cvolume_compatible(const pa_cvolume *v, const pa_sample_spec *ss) {
pa_assert(v);
pa_assert(ss);
pa_return_val_if_fail(pa_cvolume_valid(v), 0);
pa_return_val_if_fail(pa_sample_spec_valid(ss), 0);
return v->channels == ss->channels;
}
示例10: pa_sample_spec_snprint
/** Pretty print a sample type specification to a string */
char* pa_sample_spec_snprint(char *s, size_t l, const pa_sample_spec *spec) {
if ( s == NULL || l == 0 || spec == NULL )
return NULL;
if ( pa_sample_spec_valid(spec) ) {
snprintf(s, l, "%s %uch %uHz", pa_sample_format_to_string(spec->format), spec->channels, spec->rate);
} else {
snprintf(s, l, "Invalid");
}
return s;
}
示例11: pulse_connect_stream
/*
* Create a new pulse audio stream and connect to it
*
* Return a negative value on error
*/
static int pulse_connect_stream(struct pulse_data *data)
{
pa_sample_spec spec;
spec.format = data->format;
spec.rate = data->samples_per_sec;
spec.channels = get_audio_channels(data->speakers);
if (!pa_sample_spec_valid(&spec)) {
blog(LOG_ERROR, "pulse-input: Sample spec is not valid");
return -1;
}
data->bytes_per_frame = pa_frame_size(&spec);
blog(LOG_DEBUG, "pulse-input: %u bytes per frame",
(unsigned int) data->bytes_per_frame);
pa_buffer_attr attr;
attr.fragsize = get_buffer_size(data, 250);
attr.maxlength = (uint32_t) -1;
attr.minreq = (uint32_t) -1;
attr.prebuf = (uint32_t) -1;
attr.tlength = (uint32_t) -1;
data->stream = pa_stream_new_with_proplist(data->context,
obs_source_getname(data->source), &spec, NULL, data->props);
if (!data->stream) {
blog(LOG_ERROR, "pulse-input: Unable to create stream");
return -1;
}
pa_stream_flags_t flags =
PA_STREAM_INTERPOLATE_TIMING
| PA_STREAM_AUTO_TIMING_UPDATE
| PA_STREAM_ADJUST_LATENCY;
if (pa_stream_connect_record(data->stream, NULL, &attr, flags) < 0) {
blog(LOG_ERROR, "pulse-input: Unable to connect to stream");
return -1;
}
for (;;) {
pulse_iterate(data);
pa_stream_state_t state = pa_stream_get_state(data->stream);
if (state == PA_STREAM_READY) {
blog(LOG_DEBUG, "pulse-input: Stream ready");
break;
}
if (!PA_STREAM_IS_GOOD(state)) {
blog(LOG_ERROR, "pulse-input: Stream connect failed");
return -1;
}
}
return 0;
}
示例12: pa_sndfile_read_sample_spec
int pa_sndfile_read_sample_spec(SNDFILE *sf, pa_sample_spec *ss) {
SF_INFO sfi;
int sf_errno;
pa_assert(sf);
pa_assert(ss);
pa_zero(sfi);
if ((sf_errno = sf_command(sf, SFC_GET_CURRENT_SF_INFO, &sfi, sizeof(sfi)))) {
pa_log_error("sndfile: %s", sf_error_number(sf_errno));
return -1;
}
switch (sfi.format & SF_FORMAT_SUBMASK) {
case SF_FORMAT_PCM_16:
case SF_FORMAT_PCM_U8:
case SF_FORMAT_PCM_S8:
ss->format = PA_SAMPLE_S16NE;
break;
case SF_FORMAT_PCM_24:
ss->format = PA_SAMPLE_S24NE;
break;
case SF_FORMAT_PCM_32:
ss->format = PA_SAMPLE_S32NE;
break;
case SF_FORMAT_ULAW:
ss->format = PA_SAMPLE_ULAW;
break;
case SF_FORMAT_ALAW:
ss->format = PA_SAMPLE_ALAW;
break;
case SF_FORMAT_FLOAT:
case SF_FORMAT_DOUBLE:
default:
ss->format = PA_SAMPLE_FLOAT32NE;
break;
}
ss->rate = (uint32_t) sfi.samplerate;
ss->channels = (uint8_t) sfi.channels;
if (!pa_sample_spec_valid(ss))
return -1;
return 0;
}
示例13: pa_context_get_tile_size
size_t pa_context_get_tile_size(pa_context *c, const pa_sample_spec *ss) {
size_t fs, mbs;
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) >= 1);
PA_CHECK_VALIDITY_RETURN_ANY(c, !pa_detect_fork(), PA_ERR_FORKED, (size_t) -1);
PA_CHECK_VALIDITY_RETURN_ANY(c, !ss || pa_sample_spec_valid(ss), PA_ERR_INVALID, (size_t) -1);
fs = ss ? pa_frame_size(ss) : 1;
mbs = PA_ROUND_DOWN(pa_mempool_block_size_max(c->mempool), fs);
return PA_MAX(mbs, fs);
}
示例14: pa_sample_spec_snprint
APULSE_EXPORT
char *
pa_sample_spec_snprint(char *s, size_t l, const pa_sample_spec *spec)
{
trace_info_f("F %s s=%p, l=%u, spec=%p\n", __func__, s, (unsigned)l, spec);
if (spec && pa_sample_spec_valid(spec)) {
snprintf(s, l, "%s %uch %uHz", pa_sample_format_to_string(spec->format), spec->channels,
spec->rate);
} else {
snprintf(s, l, "invalid");
}
return s;
}
示例15: pa_init
/**
* Pulsaudio init
*/
static void
pa_init ()
{
int r;
int i;
if (!pa_sample_spec_valid (&sample_spec))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Wrong Spec\n"));
}
/* set up main record loop */
if (!(m = pa_mainloop_new ()))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("pa_mainloop_new() failed.\n"));
}
mainloop_api = pa_mainloop_get_api (m);
/* listen to signals */
r = pa_signal_init (mainloop_api);
GNUNET_assert (r == 0);
pa_signal_new (SIGINT, &exit_signal_callback, NULL);
pa_signal_new (SIGTERM, &exit_signal_callback, NULL);
/* connect to the main pulseaudio context */
if (!(context = pa_context_new (mainloop_api, "GNUNET VoIP")))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("pa_context_new() failed.\n"));
}
pa_context_set_state_callback (context, &context_state_callback, NULL);
if (pa_context_connect (context, NULL, 0, NULL) < 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("pa_context_connect() failed: %s\n"),
pa_strerror (pa_context_errno (context)));
}
if (pa_mainloop_run (m, &i) < 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("pa_mainloop_run() failed.\n"));
}
}