Skip to content

Commit

Permalink
impl pa_stream_begin_write and pa_stream_cancel_write
Browse files Browse the repository at this point in the history
  • Loading branch information
i-rinat committed Dec 19, 2015
1 parent 08a3b4a commit 1a39501
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.
44 changes: 42 additions & 2 deletions src/apulse-stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,39 @@ do_connect_pcm(pa_stream *s, snd_pcm_stream_t stream_direction)
return -1;
}

APULSE_EXPORT
int
pa_stream_begin_write(pa_stream *p, void **data, size_t *nbytes)
{
trace_info("F %s p=%p\n", __func__, p);

free(p->write_buffer);

if (*nbytes == (size_t)-1)
*nbytes = 8192;

p->write_buffer = malloc(*nbytes);

if (!p->write_buffer)
return -1;

*data = p->write_buffer;

return 0;
}

APULSE_EXPORT
int
pa_stream_cancel_write(pa_stream *p)
{
trace_info("F %s p=%p\n", __func__, p);

free(p->write_buffer);
p->write_buffer = NULL;

return 0;
}

APULSE_EXPORT
int
pa_stream_connect_playback(pa_stream *s, const char *dev, const pa_buffer_attr *attr,
Expand Down Expand Up @@ -549,6 +582,7 @@ pa_stream_unref(pa_stream *s)
g_hash_table_remove(s->c->streams_ht, GINT_TO_POINTER(s->idx));
ringbuffer_free(s->rb);
free(s->peek_buffer);
free(s->write_buffer);
free(s->name);
free(s);
}
Expand Down Expand Up @@ -608,8 +642,14 @@ pa_stream_write(pa_stream *s, const void *data, size_t nbytes, pa_free_cb_t free
size_t written = ringbuffer_write(s->rb, data, nbytes);
s->timing_info.since_underrun += written;
s->timing_info.write_index += written;
if (free_cb)
free_cb((void *)data);

if (data == s->write_buffer) {
free(s->write_buffer);
s->write_buffer = NULL;
} else {
if (free_cb)
free_cb((void *)data);
}

return 0;
}
Expand Down
1 change: 1 addition & 0 deletions src/apulse.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ struct pa_stream {
ringbuffer_t *rb;
void *peek_buffer;
size_t peek_buffer_data_len;
void *write_buffer;
volatile int paused;
};

Expand Down
14 changes: 0 additions & 14 deletions src/notimplemented.c
Original file line number Diff line number Diff line change
Expand Up @@ -787,20 +787,6 @@ pa_context* pa_stream_get_context(pa_stream *p)
return NULL;
}

APULSE_EXPORT
int pa_stream_begin_write(pa_stream *p, void **data, size_t *nbytes)
{
trace_info("Z %s\n", __func__);
return 0;
}

APULSE_EXPORT
int pa_stream_cancel_write(pa_stream *p)
{
trace_info("Z %s\n", __func__);
return 0;
}

APULSE_EXPORT
void pa_stream_set_overflow_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata)
{
Expand Down

0 comments on commit 1a39501

Please sign in to comment.