Ejemplo n.º 1
0
Archivo: te.c Proyecto: ITikhonov/tem
static void audio_request_cb(pa_stream *s, size_t length, void *userdata) {
	int i;
	uint32_t buf[length/4];

	if(pa_stream_is_corked(s)) return;

	for(i=0;i<length/4;i++) {
		if((offset+i-1)/ticksize != (offset+i)/ticksize) {
			int ntickno=(offset+i)/ticksize;
			if(ntickno!=tickno) {
				g_mutex_lock(tickmutex);
				tickno=ntickno;
				printf("signal %u %u (%u)\n",beatno(),tickinbeat(),offset+i);
				g_cond_signal(tickcond);
				g_mutex_unlock(tickmutex);
			}
		}


		int k;
		int32_t v=0;
		for(k=0;k<stack.len;k++) {
			v=stack.action[k].f(v,stack.action+k,offset+i);
		}
		buf[i]=v;
	}
	offset+=i;
	pa_stream_write(s,buf,length,0,0,PA_SEEK_RELATIVE);
}
static PyObject* PulseAudio_resume(output_PulseAudio *self, PyObject *args)
{
    /*ensure output stream is still running*/
    /*FIXME*/

    /*uncork output stream, if corked*/
    pa_threaded_mainloop_lock(self->mainloop);

    if (pa_stream_is_corked(self->stream)) {
        pa_operation *op = pa_stream_cork(
            self->stream,
            0,
            (pa_stream_success_cb_t)success_callback,
            self->mainloop);

        while (pa_operation_get_state(op) == PA_OPERATION_RUNNING) {
            pa_threaded_mainloop_wait(self->mainloop);
        }

        pa_operation_unref(op);
    }

    pa_threaded_mainloop_unlock(self->mainloop);

    Py_INCREF(Py_None);
    return Py_None;
}
Ejemplo n.º 3
0
static void stream_latency_cb(pa_stream *s, void *userdata)
{
    audio_output_t *aout = userdata;
    aout_sys_t *sys = aout->sys;

    /* This callback is _never_ called while paused. */
    if (sys->first_pts == VLC_TS_INVALID)
        return; /* nothing to do if buffers are (still) empty */
    if (pa_stream_is_corked(s) > 0)
        stream_start(s, aout);
}
Ejemplo n.º 4
0
/**
 * Determines whether the stream is paused.  On libpulse older than
 * 0.9.11, it uses a custom pause flag.
 */
static bool
pulse_output_stream_is_paused(struct pulse_output *po)
{
	assert(po->stream != NULL);

#if !defined(PA_CHECK_VERSION) || !PA_CHECK_VERSION(0,9,11)
	return po->pause;
#else
	return pa_stream_is_corked(po->stream);
#endif
}
int pa_simple_is_corked(pa_simple *p) {
	int is_cork;
    pa_assert(p);

    pa_threaded_mainloop_lock(p->mainloop);

    is_cork = pa_stream_is_corked(p->stream);

    pa_threaded_mainloop_unlock(p->mainloop);

    return is_cork;
}
Ejemplo n.º 6
0
static int instream_pause_pa(SoundIoPrivate *si, SoundIoInStreamPrivate *is, bool pause) {
    SoundIoInStreamPulseAudio *ispa = &is->backend_data.pulseaudio;
    SoundIoPulseAudio *sipa = &si->backend_data.pulseaudio;

    pa_threaded_mainloop_lock(sipa->main_loop);

    if (pause != pa_stream_is_corked(ispa->stream)) {
        pa_operation *op = pa_stream_cork(ispa->stream, pause, NULL, NULL);
        if (!op)
            return SoundIoErrorStreaming;
        pa_operation_unref(op);
    }

    pa_threaded_mainloop_unlock(sipa->main_loop);

    return 0;
}
Ejemplo n.º 7
0
static int outstream_pause_pa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, bool pause) {
    struct SoundIoOutStreamPulseAudio *ospa = &os->backend_data.pulseaudio;
    struct SoundIoPulseAudio *sipa = &si->backend_data.pulseaudio;

    if (!pa_threaded_mainloop_in_thread(sipa->main_loop)) {
        pa_threaded_mainloop_lock(sipa->main_loop);
    }

    if (pause != pa_stream_is_corked(ospa->stream)) {
        pa_operation *op = pa_stream_cork(ospa->stream, pause, NULL, NULL);
        if (!op) {
            pa_threaded_mainloop_unlock(sipa->main_loop);
            return SoundIoErrorStreaming;
        }
        pa_operation_unref(op);
    }

    if (!pa_threaded_mainloop_in_thread(sipa->main_loop)) {
        pa_threaded_mainloop_unlock(sipa->main_loop);
    }

    return 0;
}
Ejemplo n.º 8
0
static ALuint PulseProc(ALvoid *param)
{
    ALCdevice *Device = param;
    pulse_data *data = Device->ExtraData;
    ALuint buffer_size;
    ALint update_size;
    size_t frame_size;
    ssize_t len;

    SetRTPriority();

    pa_threaded_mainloop_lock(data->loop);
    frame_size = pa_frame_size(&data->spec);
    update_size = Device->UpdateSize * frame_size;

    /* Sanitize buffer metrics, in case we actually have less than what we
     * asked for. */
    buffer_size = minu(update_size*Device->NumUpdates, data->attr.tlength);
    update_size = minu(update_size, buffer_size/2);
    do {
        len = pa_stream_writable_size(data->stream) - data->attr.tlength +
              buffer_size;
        if(len < update_size)
        {
            if(pa_stream_is_corked(data->stream) == 1)
            {
                pa_operation *o;
                o = pa_stream_cork(data->stream, 0, NULL, NULL);
                if(o) pa_operation_unref(o);
            }
            pa_threaded_mainloop_unlock(data->loop);
            Sleep(1);
            pa_threaded_mainloop_lock(data->loop);
            continue;
        }
        len -= len%update_size;

        while(len > 0)
        {
            size_t newlen = len;
            void *buf;
            pa_free_cb_t free_func = NULL;

#if PA_CHECK_VERSION(0,9,16)
            if(!pa_stream_begin_write ||
               pa_stream_begin_write(data->stream, &buf, &newlen) < 0)
#endif
            {
                buf = pa_xmalloc(newlen);
                free_func = pa_xfree;
            }
            pa_threaded_mainloop_unlock(data->loop);

            aluMixData(Device, buf, newlen/frame_size);

            pa_threaded_mainloop_lock(data->loop);
            pa_stream_write(data->stream, buf, newlen, free_func, 0, PA_SEEK_RELATIVE);
            len -= newlen;
        }
    } while(!data->killNow && Device->Connected);
    pa_threaded_mainloop_unlock(data->loop);

    return 0;
}