queue2: cleanups

Add a macro to get the max size of the queue in bytes, which depends on the
max_level.bytes and the ring_buffer_max_size.
Some cleanups.
This commit is contained in:
Wim Taymans 2010-06-16 17:03:49 +02:00
parent ecd8d3be3a
commit abc9ab1747

View file

@ -99,6 +99,8 @@ enum
#define QUEUE_IS_USING_RING_BUFFER(queue) ((queue)->use_ring_buffer) /* for consistency with the above macro */ #define QUEUE_IS_USING_RING_BUFFER(queue) ((queue)->use_ring_buffer) /* for consistency with the above macro */
#define QUEUE_IS_USING_QUEUE(queue) (!QUEUE_IS_USING_TEMP_FILE(queue) && !QUEUE_IS_USING_RING_BUFFER (queue)) #define QUEUE_IS_USING_QUEUE(queue) (!QUEUE_IS_USING_TEMP_FILE(queue) && !QUEUE_IS_USING_RING_BUFFER (queue))
#define QUEUE_MAX_BYTES(queue) MIN((queue)->max_level.bytes, (queue)->ring_buffer_max_size)
/* default property values */ /* default property values */
#define DEFAULT_MAX_SIZE_BUFFERS 100 /* 100 buffers */ #define DEFAULT_MAX_SIZE_BUFFERS 100 /* 100 buffers */
#define DEFAULT_MAX_SIZE_BYTES (2 * 1024 * 1024) /* 2 MB */ #define DEFAULT_MAX_SIZE_BYTES (2 * 1024 * 1024) /* 2 MB */
@ -1089,8 +1091,7 @@ gst_queue2_have_data (GstQueue2 * queue, guint64 offset, guint length)
update_cur_pos (queue, queue->current, offset + length); update_cur_pos (queue, queue->current, offset + length);
GST_INFO_OBJECT (queue, "cur_level.bytes %u (max %u)", GST_INFO_OBJECT (queue, "cur_level.bytes %u (max %u)",
queue->cur_level.bytes, MIN (queue->max_level.bytes, queue->cur_level.bytes, QUEUE_MAX_BYTES (queue));
queue->ring_buffer_max_size));
/* we have a range for offset */ /* we have a range for offset */
GST_DEBUG_OBJECT (queue, GST_DEBUG_OBJECT (queue,
@ -1183,6 +1184,7 @@ gst_queue2_create_read (GstQueue2 * queue, guint64 offset, guint length,
guint64 file_offset; guint64 file_offset;
guint block_length, remaining, read_length; guint block_length, remaining, read_length;
gint64 read_return; gint64 read_return;
guint64 rb_size;
/* allocate the output buffer of the requested size */ /* allocate the output buffer of the requested size */
buf = gst_buffer_new_and_alloc (length); buf = gst_buffer_new_and_alloc (length);
@ -1191,6 +1193,8 @@ gst_queue2_create_read (GstQueue2 * queue, guint64 offset, guint length,
GST_DEBUG_OBJECT (queue, "Reading %u bytes from %" G_GUINT64_FORMAT, length, GST_DEBUG_OBJECT (queue, "Reading %u bytes from %" G_GUINT64_FORMAT, length,
offset); offset);
rb_size = queue->ring_buffer_max_size;
remaining = length; remaining = length;
while (remaining > 0) { while (remaining > 0) {
/* configure how much/whether to read */ /* configure how much/whether to read */
@ -1211,13 +1215,13 @@ gst_queue2_create_read (GstQueue2 * queue, guint64 offset, guint length,
", level %" G_GUINT64_FORMAT, ", level %" G_GUINT64_FORMAT,
queue->current->reading_pos, queue->current->writing_pos, level); queue->current->reading_pos, queue->current->writing_pos, level);
if (level >= queue->ring_buffer_max_size) { if (level >= rb_size) {
/* we don't have the data but if we have a ring buffer that is full, we /* we don't have the data but if we have a ring buffer that is full, we
* need to read */ * need to read */
GST_DEBUG_OBJECT (queue, GST_DEBUG_OBJECT (queue,
"ring buffer full, reading ring-buffer-max-size %d bytes", "ring buffer full, reading ring-buffer-max-size %d bytes",
queue->ring_buffer_max_size); rb_size);
read_length = queue->ring_buffer_max_size; read_length = rb_size;
} }
} }
if (read_length == 0) { if (read_length == 0) {
@ -1233,9 +1237,9 @@ gst_queue2_create_read (GstQueue2 * queue, guint64 offset, guint length,
if (QUEUE_IS_USING_RING_BUFFER (queue)) { if (QUEUE_IS_USING_RING_BUFFER (queue)) {
file_offset = file_offset =
(queue->current->rb_offset + (offset - (queue->current->rb_offset + (offset -
queue->current->offset)) % queue->ring_buffer_max_size; queue->current->offset)) % rb_size;
if (file_offset + read_length > queue->ring_buffer_max_size) { if (file_offset + read_length > rb_size) {
block_length = queue->ring_buffer_max_size - file_offset; block_length = rb_size - file_offset;
} else { } else {
block_length = read_length; block_length = read_length;
} }
@ -1254,7 +1258,7 @@ gst_queue2_create_read (GstQueue2 * queue, guint64 offset, guint length,
file_offset += read_return; file_offset += read_return;
if (QUEUE_IS_USING_RING_BUFFER (queue)) if (QUEUE_IS_USING_RING_BUFFER (queue))
file_offset %= queue->ring_buffer_max_size; file_offset %= rb_size;
data += read_return; data += read_return;
read_length -= read_return; read_length -= read_return;
@ -1522,13 +1526,14 @@ gst_queue2_write_buffer_to_ring_buffer (GstQueue2 * queue, GstBuffer * buffer)
{ {
GstBuffer *buf, *rem; GstBuffer *buf, *rem;
guint buf_size, rem_size; guint buf_size, rem_size;
const guint rb_size = queue->ring_buffer_max_size; guint rb_size;
guint8 *data; guint8 *data;
guint64 writing_pos, new_writing_pos; guint64 writing_pos, new_writing_pos;
gint64 space, rb_space; gint64 space, rb_space;
GstQueue2Range *range, *prev; GstQueue2Range *range, *prev;
writing_pos = queue->current->rb_writing_pos; writing_pos = queue->current->rb_writing_pos;
rb_size = queue->ring_buffer_max_size;
rem = buffer; rem = buffer;
@ -1544,9 +1549,7 @@ gst_queue2_write_buffer_to_ring_buffer (GstQueue2 * queue, GstBuffer * buffer)
do { do {
/* calculate the space in the ring buffer not used by data from the /* calculate the space in the ring buffer not used by data from the
* current range */ * current range */
space = space = QUEUE_MAX_BYTES (queue) - queue->cur_level.bytes;
MIN (queue->max_level.bytes,
queue->ring_buffer_max_size) - queue->cur_level.bytes;
space = MIN (space, rb_space); space = MIN (space, rb_space);
rem_size = GST_BUFFER_SIZE (rem); rem_size = GST_BUFFER_SIZE (rem);
@ -1700,8 +1703,7 @@ gst_queue2_write_buffer_to_ring_buffer (GstQueue2 * queue, GstBuffer * buffer)
update_cur_level (queue, queue->current); update_cur_level (queue, queue->current);
GST_INFO_OBJECT (queue, "cur_level.bytes %u (max %u)", GST_INFO_OBJECT (queue, "cur_level.bytes %u (max %u)",
queue->cur_level.bytes, MIN (queue->max_level.bytes, queue->cur_level.bytes, QUEUE_MAX_BYTES (queue));
queue->ring_buffer_max_size));
GST_QUEUE2_SIGNAL_ADD (queue); GST_QUEUE2_SIGNAL_ADD (queue);