本文整理汇总了C++中pa_stream_set_state_callback函数的典型用法代码示例。如果您正苦于以下问题:C++ pa_stream_set_state_callback函数的具体用法?C++ pa_stream_set_state_callback怎么用?C++ pa_stream_set_state_callback使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pa_stream_set_state_callback函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pa_stream_new
static pa_stream *connect_playback_stream(ALCdevice *device,
pa_stream_flags_t flags, pa_buffer_attr *attr, pa_sample_spec *spec,
pa_channel_map *chanmap)
{
pulse_data *data = device->ExtraData;
pa_stream_state_t state;
pa_stream *stream;
stream = pa_stream_new(data->context, "Playback Stream", spec, chanmap);
if(!stream)
{
ERR("pa_stream_new() failed: %s\n",
pa_strerror(pa_context_errno(data->context)));
return NULL;
}
pa_stream_set_state_callback(stream, stream_state_callback, data->loop);
AL_PRINT("Attempting flags 0x%x\n", flags);
if (attr)
{
AL_PRINT("maxlength: %d tlegth: %d prebuf: %d minreq: %d fragsize: %d\n",
attr->maxlength, attr->tlength, attr->prebuf, attr->minreq, attr->fragsize);
}
if(pa_stream_connect_playback(stream, data->device_name, attr, flags, NULL, NULL) < 0)
{
ERR("Stream did not connect: %s\n",
pa_strerror(pa_context_errno(data->context)));
pa_stream_unref(stream);
return NULL;
}
while((state=pa_stream_get_state(stream)) != PA_STREAM_READY)
{
if(!PA_STREAM_IS_GOOD(state))
{
ERR("Stream did not get ready: %s\n",
pa_strerror(pa_context_errno(data->context)));
pa_stream_unref(stream);
return NULL;
}
pa_threaded_mainloop_wait(data->loop);
}
pa_stream_set_state_callback(stream, NULL, NULL);
return stream;
}
示例2: pulse_output_setup_stream
/**
* Create, set up and connect a context.
*
* Caller must lock the main loop.
*
* @return true on success, false on error
*/
static bool
pulse_output_setup_stream(struct pulse_output *po, const pa_sample_spec *ss,
GError **error_r)
{
assert(po != NULL);
assert(po->context != NULL);
po->stream = pa_stream_new(po->context, po->name, ss, NULL);
if (po->stream == NULL) {
g_set_error(error_r, pulse_output_quark(), 0,
"pa_stream_new() has failed: %s",
pa_strerror(pa_context_errno(po->context)));
return false;
}
#if PA_CHECK_VERSION(0,9,8)
pa_stream_set_suspended_callback(po->stream,
pulse_output_stream_suspended_cb, po);
#endif
pa_stream_set_state_callback(po->stream,
pulse_output_stream_state_cb, po);
pa_stream_set_write_callback(po->stream,
pulse_output_stream_write_cb, po);
return true;
}
示例3: pa_mainloop_new
int PulseAudioDriver::thread_body()
{
m_main_loop = pa_mainloop_new();
pa_mainloop_api* api = pa_mainloop_get_api(m_main_loop);
pa_io_event* ioev = api->io_new(api, m_pipe[0], PA_IO_EVENT_INPUT,
pipe_callback, this);
m_ctx = pa_context_new(api, "Hydrogen");
pa_context_set_state_callback(m_ctx, ctx_state_callback, this);
pa_context_connect(m_ctx, 0, pa_context_flags_t(0), 0);
int retval;
pa_mainloop_run(m_main_loop, &retval);
if (m_stream)
{
pa_stream_set_state_callback(m_stream, 0, 0);
pa_stream_set_write_callback(m_stream, 0, 0);
pa_stream_unref(m_stream);
m_stream = 0;
}
api->io_free(ioev);
pa_context_unref(m_ctx);
pa_mainloop_free(m_main_loop);
return retval;
}
示例4: pa_stream_set_state_callback
void QPulseAudioInput::close()
{
if (!m_opened)
return;
m_timer->stop();
QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
if (m_stream) {
pulseEngine->lock();
pa_stream_set_state_callback(m_stream, 0, 0);
pa_stream_set_read_callback(m_stream, 0, 0);
pa_stream_set_underflow_callback(m_stream, 0, 0);
pa_stream_set_overflow_callback(m_stream, 0, 0);
pa_stream_disconnect(m_stream);
pa_stream_unref(m_stream);
m_stream = 0;
pulseEngine->unlock();
}
disconnect(pulseEngine, &QPulseAudioEngine::contextFailed, this, &QPulseAudioInput::onPulseContextFailed);
if (!m_pullMode && m_audioSource) {
delete m_audioSource;
m_audioSource = 0;
}
m_opened = false;
}
示例5: pa_context_get_state
void PulseAudioDriver::ctx_state_callback(pa_context* ctx, void* udata)
{
PulseAudioDriver* self = (PulseAudioDriver*)udata;
pa_context_state s = pa_context_get_state(ctx);
if (s == PA_CONTEXT_READY)
{
pa_sample_spec spec;
spec.format = PA_SAMPLE_S16LE;
spec.rate = self->m_sample_rate;
spec.channels = 2;
self->m_stream = pa_stream_new(ctx, "Hydrogen", &spec, 0);
pa_stream_set_state_callback(self->m_stream, stream_state_callback, self);
pa_stream_set_write_callback(self->m_stream, stream_write_callback, self);
pa_buffer_attr bufattr;
bufattr.fragsize = (uint32_t)-1;
bufattr.maxlength = self->m_buffer_size * 4;
bufattr.minreq = 0;
bufattr.prebuf = (uint32_t)-1;
bufattr.tlength = self->m_buffer_size * 4;
pa_stream_connect_playback(self->m_stream, 0, &bufattr, pa_stream_flags_t(0), 0, 0);
}
else if (s == PA_CONTEXT_FAILED)
pa_mainloop_quit(self->m_main_loop, 1);
}
示例6: context_state_callback
/**
* Pulseaudio context state callback
*/
static void
context_state_callback (pa_context * c,
void *userdata)
{
GNUNET_assert (c);
switch (pa_context_get_state (c))
{
case PA_CONTEXT_CONNECTING:
case PA_CONTEXT_AUTHORIZING:
case PA_CONTEXT_SETTING_NAME:
break;
case PA_CONTEXT_READY:
{
int r;
pa_buffer_attr na;
GNUNET_assert (!stream_in);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Connection established.\n"));
if (! (stream_in =
pa_stream_new (c, "GNUNET_VoIP recorder", &sample_spec, NULL)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("pa_stream_new() failed: %s\n"),
pa_strerror (pa_context_errno (c)));
goto fail;
}
pa_stream_set_state_callback (stream_in, &stream_state_callback, NULL);
pa_stream_set_read_callback (stream_in, &stream_read_callback, NULL);
memset (&na, 0, sizeof (na));
na.maxlength = UINT32_MAX;
na.fragsize = pcm_length;
if ((r = pa_stream_connect_record (stream_in, NULL, &na,
PA_STREAM_ADJUST_LATENCY)) < 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("pa_stream_connect_record() failed: %s\n"),
pa_strerror (pa_context_errno (c)));
goto fail;
}
break;
}
case PA_CONTEXT_TERMINATED:
quit (0);
break;
case PA_CONTEXT_FAILED:
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Connection failure: %s\n"),
pa_strerror (pa_context_errno (c)));
goto fail;
}
return;
fail:
quit (1);
}
示例7: pa_threaded_mainloop_lock
static pa_stream *qpa_simple_new (
paaudio *g,
const char *name,
pa_stream_direction_t dir,
const char *dev,
const pa_sample_spec *ss,
const pa_channel_map *map,
const pa_buffer_attr *attr,
int *rerror)
{
int r;
pa_stream *stream;
pa_threaded_mainloop_lock (g->mainloop);
stream = pa_stream_new (g->context, name, ss, map);
if (!stream) {
goto fail;
}
pa_stream_set_state_callback (stream, stream_state_cb, g);
pa_stream_set_read_callback (stream, stream_request_cb, g);
pa_stream_set_write_callback (stream, stream_request_cb, g);
if (dir == PA_STREAM_PLAYBACK) {
r = pa_stream_connect_playback (stream, dev, attr,
PA_STREAM_INTERPOLATE_TIMING
#ifdef PA_STREAM_ADJUST_LATENCY
|PA_STREAM_ADJUST_LATENCY
#endif
|PA_STREAM_AUTO_TIMING_UPDATE, NULL, NULL);
} else {
r = pa_stream_connect_record (stream, dev, attr,
PA_STREAM_INTERPOLATE_TIMING
#ifdef PA_STREAM_ADJUST_LATENCY
|PA_STREAM_ADJUST_LATENCY
#endif
|PA_STREAM_AUTO_TIMING_UPDATE);
}
if (r < 0) {
goto fail;
}
pa_threaded_mainloop_unlock (g->mainloop);
return stream;
fail:
pa_threaded_mainloop_unlock (g->mainloop);
if (stream) {
pa_stream_unref (stream);
}
*rerror = pa_context_errno (g->context);
return NULL;
}
示例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_stream_new
static pa_stream *connect_playback_stream(ALCdevice *device,
pa_stream_flags_t flags, pa_buffer_attr *attr, pa_sample_spec *spec,
pa_channel_map *chanmap)
{
pulse_data *data = device->ExtraData;
pa_stream_state_t state;
pa_stream *stream;
stream = pa_stream_new(data->context, "Playback Stream", spec, chanmap);
if(!stream)
{
ERR("pa_stream_new() failed: %s\n",
pa_strerror(pa_context_errno(data->context)));
return NULL;
}
pa_stream_set_state_callback(stream, stream_state_callback, data->loop);
if(pa_stream_connect_playback(stream, data->device_name, attr, flags, NULL, NULL) < 0)
{
ERR("Stream did not connect: %s\n",
pa_strerror(pa_context_errno(data->context)));
pa_stream_unref(stream);
return NULL;
}
while((state=pa_stream_get_state(stream)) != PA_STREAM_READY)
{
if(!PA_STREAM_IS_GOOD(state))
{
ERR("Stream did not get ready: %s\n",
pa_strerror(pa_context_errno(data->context)));
pa_stream_unref(stream);
return NULL;
}
pa_threaded_mainloop_wait(data->loop);
}
pa_stream_set_state_callback(stream, NULL, NULL);
return stream;
}
示例10: pa_stream_set_state_callback
JNIEXPORT void JNICALL
Java_org_jitsi_impl_neomedia_pulseaudio_PA_stream_1set_1state_1callback
(JNIEnv *env, jclass clazz, jlong s, jobject cb)
{
jweak weakCb = cb ? (*env)->NewWeakGlobalRef(env, cb) : NULL;
pa_stream_set_state_callback(
(pa_stream *) (intptr_t) s,
weakCb ? PulseAudio_streamStateCallback : NULL,
(void *) weakCb);
}
示例11: qDebug
void QPulseAudioThread::reconnect(SourceContainer::const_iterator pos = s_sourceList.end())
{
if (s_sourceList.empty())
return;
if (pos != s_sourceList.end()) {
s_sourcePosition = pos;
qDebug() << "reconnecting with" << *pos;
} else
s_sourcePosition = scanForPlaybackMonitor();
if (s_sourcePosition == s_sourceList.end()) {
s_sourcePosition = s_sourceList.begin();
}
if (stream && (pa_stream_get_state(stream) == PA_STREAM_READY)) {
//qDebug() << "disconnect";
pa_stream_disconnect ( stream );
// pa_stream_unref(stream);
//qDebug() << "* return *";
}
if ( ! ( stream = pa_stream_new ( context, stream_name, &sample_spec, channel_map_set ? &channel_map : NULL ) ) ) {
fprintf ( stderr, "pa_stream_new() failed: %s\n", pa_strerror ( pa_context_errno ( context ) ) );
return;
}
pa_stream_set_state_callback
( stream, stream_state_callback, &s_sourceList );
pa_stream_set_read_callback ( stream, stream_read_callback, &s_sourceList );
pa_stream_set_moved_callback(stream, stream_moved_callback, &s_sourceList );
switch (pa_stream_get_state(stream)) {
case PA_STREAM_UNCONNECTED:// The stream is not yet connected to any sink or source.
qDebug() << "unconnected: connecting...";
connectHelper(s_sourcePosition);
break;
case PA_STREAM_CREATING ://The stream is being created.
break;
case PA_STREAM_READY :// The stream is established, you may pass audio data to it now.
qDebug() << "stream is still ready, waiting for callback...";
break;
case PA_STREAM_FAILED :// An error occured that made the stream invalid.
qDebug() << "stream is now invalid. great.";
break;
case PA_STREAM_TERMINATED:// The stream has been terminated cleanly.
qDebug() << "terminated...";
break;
}
}
示例12: context_state_callback
/*
* Context state callbacks
*
* A 'context' represents the connection handle between a PulseAudio
* client and its server. It multiplexes everything in that connection
* including data streams , bi-directional commands, and events.
*/
static void context_state_callback(pa_context *context, void *userdata) {
struct context *ctx = userdata;
struct audio_file *file;
pa_stream *stream;
int ret;
assert(ctx);
assert((file = ctx->file));
switch (pa_context_get_state(context)) {
case PA_CONTEXT_AUTHORIZING:
case PA_CONTEXT_CONNECTING:
case PA_CONTEXT_SETTING_NAME:
break;
case PA_CONTEXT_READY:
out("Connection established with PulseAudio sound server");
for (int i = 0; i < 256; i++) {
stream = pa_stream_new(context, "playback stream", &file->spec, NULL);
if (!stream)
goto fail;
pa_stream_set_state_callback(stream, stream_state_callback, userdata);
pa_stream_set_write_callback(stream, stream_write_callback, userdata);
/* Connect this stream with a sink chosen by PulseAudio */
ret = pa_stream_connect_playback(stream, NULL, NULL, 0, NULL, NULL);
if (ret < 0) {
error("pa_stream_connect_playback() failed: %s",
pa_strerror(pa_context_errno(context)));
goto fail;
}
}
break;
case PA_CONTEXT_TERMINATED:
exit(EXIT_SUCCESS);
break;
case PA_CONTEXT_FAILED:
default:
error("PulseAudio context connection failure: %s",
pa_strerror(pa_context_errno(context)));
goto fail;
}
return;
fail:
quit(ctx, EXIT_FAILURE);
}
开发者ID:a-darwish,项目名称:malicious-pulseaudio-clients,代码行数:60,代码来源:kill_server_quickly_open_write_streams.c
示例13: pa_stream_new_with_proplist
static pa_stream *connect_record_stream(const char *device_name,
pa_threaded_mainloop *loop, pa_context *context,
pa_stream_flags_t flags, pa_buffer_attr *attr, pa_sample_spec *spec,
pa_channel_map *chanmap)
{
pa_stream_state_t state;
pa_stream *stream;
stream = pa_stream_new_with_proplist(context, "Capture Stream", spec, chanmap, prop_filter);
if(!stream)
{
ERR("pa_stream_new_with_proplist() failed: %s\n", pa_strerror(pa_context_errno(context)));
return NULL;
}
pa_stream_set_state_callback(stream, stream_state_callback, loop);
if(pa_stream_connect_record(stream, device_name, attr, flags) < 0)
{
ERR("Stream did not connect: %s\n", pa_strerror(pa_context_errno(context)));
pa_stream_unref(stream);
return NULL;
}
while((state=pa_stream_get_state(stream)) != PA_STREAM_READY)
{
if(!PA_STREAM_IS_GOOD(state))
{
ERR("Stream did not get ready: %s\n", pa_strerror(pa_context_errno(context)));
pa_stream_unref(stream);
return NULL;
}
pa_threaded_mainloop_wait(loop);
}
pa_stream_set_state_callback(stream, NULL, NULL);
return stream;
}
示例14: instream_open_pa
static int instream_open_pa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) {
struct SoundIoInStreamPulseAudio *ispa = &is->backend_data.pulseaudio;
struct SoundIoInStream *instream = &is->pub;
if ((unsigned)instream->layout.channel_count > PA_CHANNELS_MAX)
return SoundIoErrorIncompatibleBackend;
if (!instream->name)
instream->name = "SoundIoInStream";
struct SoundIoPulseAudio *sipa = &si->backend_data.pulseaudio;
SOUNDIO_ATOMIC_STORE(ispa->stream_ready, false);
pa_threaded_mainloop_lock(sipa->main_loop);
pa_sample_spec sample_spec;
sample_spec.format = to_pulseaudio_format(instream->format);
sample_spec.rate = instream->sample_rate;
sample_spec.channels = instream->layout.channel_count;
pa_channel_map channel_map = to_pulseaudio_channel_map(&instream->layout);
ispa->stream = pa_stream_new(sipa->pulse_context, instream->name, &sample_spec, &channel_map);
if (!ispa->stream) {
pa_threaded_mainloop_unlock(sipa->main_loop);
instream_destroy_pa(si, is);
return SoundIoErrorNoMem;
}
pa_stream *stream = ispa->stream;
pa_stream_set_state_callback(stream, recording_stream_state_callback, is);
pa_stream_set_read_callback(stream, recording_stream_read_callback, is);
ispa->buffer_attr.maxlength = UINT32_MAX;
ispa->buffer_attr.tlength = UINT32_MAX;
ispa->buffer_attr.prebuf = 0;
ispa->buffer_attr.minreq = UINT32_MAX;
ispa->buffer_attr.fragsize = UINT32_MAX;
if (instream->software_latency > 0.0) {
int bytes_per_second = instream->bytes_per_frame * instream->sample_rate;
int buffer_length = instream->bytes_per_frame *
ceil_dbl_to_int(instream->software_latency * bytes_per_second / (double)instream->bytes_per_frame);
ispa->buffer_attr.fragsize = buffer_length;
}
pa_threaded_mainloop_unlock(sipa->main_loop);
return 0;
}
示例15: context_state_callback
/* This is called whenever the context status changes */
static void context_state_callback(pa_context *c, void *userdata) {
fail_unless(c != NULL);
switch (pa_context_get_state(c)) {
case PA_CONTEXT_CONNECTING:
case PA_CONTEXT_AUTHORIZING:
case PA_CONTEXT_SETTING_NAME:
break;
case PA_CONTEXT_READY: {
int i;
fprintf(stderr, "Connection established.\n");
for (i = 0; i < NSTREAMS; i++) {
char name[64];
pa_format_info *formats[1];
formats[0] = pa_format_info_new();
formats[0]->encoding = PA_ENCODING_PCM;
pa_format_info_set_sample_format(formats[0], PA_SAMPLE_FLOAT32);
pa_format_info_set_rate(formats[0], SAMPLE_HZ);
pa_format_info_set_channels(formats[0], 1);
fprintf(stderr, "Creating stream %i\n", i);
snprintf(name, sizeof(name), "stream #%i", i);
streams[i] = pa_stream_new_extended(c, name, formats, 1, NULL);
fail_unless(streams[i] != NULL);
pa_stream_set_state_callback(streams[i], stream_state_callback, (void*) (long) i);
pa_stream_connect_playback(streams[i], NULL, &buffer_attr, PA_STREAM_START_CORKED, NULL, i == 0 ? NULL : streams[0]);
pa_format_info_free(formats[0]);
}
break;
}
case PA_CONTEXT_TERMINATED:
mainloop_api->quit(mainloop_api, 0);
break;
case PA_CONTEXT_FAILED:
default:
fprintf(stderr, "Context error: %s\n", pa_strerror(pa_context_errno(c)));
fail();
}
}