Logo Search packages:      
Sourcecode: pulseaudio version File versions

int pa_stream_begin_write ( pa_stream p,
void **  data,
size_t *  nbytes 

Prepare writing data to the server (for playback streams). This function may be used to optimize the number of memory copies when doing playback ("zero-copy"). It is recommended to call this function before each call to pa_stream_write(). Pass in the address to a pointer and an address of the number of bytes you want to write. On return the two values will contain a pointer where you can place the data to write and the maximum number of bytes you can write. On return *nbytes can be smaller or have the same value as you passed in. You need to be able to handle both cases. Accessing memory beyond the returned *nbytes value is invalid. Acessing the memory returned after the following pa_stream_write() or pa_stream_cancel_write() is invalid. On invocation only *nbytes needs to be initialized, on return both *data and *nbytes will be valid. If you place (size_t) -1 in *nbytes on invocation the memory size will be chosen automatically (which is recommended to do). After placing your data in the memory area returned call pa_stream_write() with data set to an address within this memory area and an nbytes value that is smaller or equal to what was returned by this function to actually execute the write. An invocation of pa_stream_write() should follow "quickly" on pa_stream_begin_write(). It is not recommended letting an unbounded amount of time pass after calling pa_stream_begin_write() and before calling pa_stream_write(). If you want to cancel a previously called pa_stream_begin_write() without calling pa_stream_write() use pa_stream_cancel_write(). Calling pa_stream_begin_write() twice without calling pa_stream_write() or pa_stream_cancel_write() in between will return exactly the same pointer/nbytes values.


Definition at line 1196 of file stream.c.



    pa_assert(PA_REFCNT_VALUE(s) >= 1);

    PA_CHECK_VALIDITY(s->context, !pa_detect_fork(), PA_ERR_FORKED);
    PA_CHECK_VALIDITY(s->context, s->direction == PA_STREAM_PLAYBACK || s->direction == PA_STREAM_UPLOAD, PA_ERR_BADSTATE);
    PA_CHECK_VALIDITY(s->context, data, PA_ERR_INVALID);
    PA_CHECK_VALIDITY(s->context, nbytes && *nbytes != 0, PA_ERR_INVALID);

    if (*nbytes != (size_t) -1) {
        size_t m, fs;

        m = pa_mempool_block_size_max(s->context->mempool);
        fs = pa_frame_size(&s->sample_spec);

        m = (m / fs) * fs;
        if (*nbytes > m)
            *nbytes = m;

    if (!s->write_memblock) {
        s->write_memblock = pa_memblock_new(s->context->mempool, *nbytes);
        s->write_data = pa_memblock_acquire(s->write_memblock);

    *data = s->write_data;
    *nbytes = pa_memblock_get_length(s->write_memblock);

    return 0;

Generated by  Doxygen 1.6.0   Back to index