gboolean xmms_ringbuf_iseos (const xmms_ringbuf_t *ringbuf) { g_return_val_if_fail (ringbuf, TRUE); return !xmms_ringbuf_bytes_used (ringbuf) && ringbuf->eos; }
/** * Number of bytes free in the ringbuffer */ guint xmms_ringbuf_bytes_free (const xmms_ringbuf_t *ringbuf) { g_return_val_if_fail (ringbuf, 0); return ringbuf->buffer_size_usable - xmms_ringbuf_bytes_used (ringbuf); }
void xmms_ringbuf_wait_used (const xmms_ringbuf_t *ringbuf, guint len, GMutex *mtx) { g_return_if_fail (ringbuf); g_return_if_fail (len > 0); g_return_if_fail (len <= ringbuf->buffer_size_usable); g_return_if_fail (mtx); while ((xmms_ringbuf_bytes_used (ringbuf) < len) && !ringbuf->eos) { g_cond_wait (ringbuf->used_cond, mtx); } }
static guint read_bytes (xmms_ringbuf_t *ringbuf, guint8 *data, guint len) { guint to_read, r = 0, cnt, tmp; gboolean ok; to_read = MIN (len, xmms_ringbuf_bytes_used (ringbuf)); while (!g_queue_is_empty (ringbuf->hotspots)) { xmms_ringbuf_hotspot_t *hs = g_queue_peek_head (ringbuf->hotspots); if (hs->pos != ringbuf->rd_index) { /* make sure we don't cross a hotspot */ to_read = MIN (to_read, (hs->pos - ringbuf->rd_index + ringbuf->buffer_size) % ringbuf->buffer_size); break; } (void) g_queue_pop_head (ringbuf->hotspots); ok = hs->callback (hs->arg); if (hs->destroy) hs->destroy (hs->arg); g_free (hs); if (!ok) { return 0; } /* we loop here, to see if there are multiple hotspots in same position */ } tmp = ringbuf->rd_index; while (to_read > 0) { cnt = MIN (to_read, ringbuf->buffer_size - tmp); memcpy (data, ringbuf->buffer + tmp, cnt); tmp = (tmp + cnt) % ringbuf->buffer_size; to_read -= cnt; r += cnt; data += cnt; } return r; }
/* returns the current latency: time left in ms until the data currently read * from the latest xform in the chain will actually be played */ guint32 xmms_output_latency (xmms_output_t *output) { guint ret = 0; guint buffersize = 0; /* data already waiting in the ringbuffer */ buffersize += xmms_ringbuf_bytes_used (output->filler_buffer); /* latency of the soundcard */ buffersize += xmms_output_plugin_method_latency_get (output->plugin, output); if (output->format) { ret = xmms_sample_bytes_to_ms (output->format, buffersize); } return ret; }
gint xmms_output_bytes_available (xmms_output_t *output) { return xmms_ringbuf_bytes_used (output->filler_buffer); }