[aravis] gv_stream: fix missing blocks count. Count late blocks.



commit 63147a639adf9b4914c16db57640920e5b7989ca
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Tue May 11 17:15:29 2010 +0200

    gv_stream: fix missing blocks count. Count late blocks.

 src/arvgvstream.c |   52 +++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 35 insertions(+), 17 deletions(-)
---
diff --git a/src/arvgvstream.c b/src/arvgvstream.c
index e6e1c97..6993c08 100644
--- a/src/arvgvstream.c
+++ b/src/arvgvstream.c
@@ -56,10 +56,11 @@ typedef struct {
 	guint n_failures;
 	guint n_underruns;
 	guint n_aborteds;
-	guint n_resent_blocks;
-
 	guint n_size_mismatch_errors;
+
+	guint n_resent_blocks;
 	guint n_missing_blocks;
+	guint n_late_blocks;
 
 	ArvStatistic *statistic;
 
@@ -125,7 +126,9 @@ _update_socket (ArvGvStreamThreadData *thread_data, ArvBuffer *buffer)
 typedef struct {
 	ArvGvspPacket *packet;
 	ArvBuffer *buffer;
+	size_t read_data_size;
 	gint32 n_missing_blocks;
+	gint32 n_late_blocks;
 	gint32 last_block_size;
 	gint32 last_block_id;
 	gint64 last_time_us;
@@ -142,16 +145,25 @@ _close_buffer (ArvGvStreamThreadData *thread_data, ArvGvStreamThreadState *state
 	if (state->buffer == NULL)
 		return;
 
-	if (state->buffer->status == ARV_BUFFER_STATUS_FILLING ||
-	    state->n_missing_blocks != 0)
-		state->buffer->status = ARV_BUFFER_STATUS_MISSING_BLOCKS;
+	if (state->buffer->status == ARV_BUFFER_STATUS_FILLING) {
+	       if (state->read_data_size == state->buffer->size &&
+		   state->n_missing_blocks == 0)
+		       state->buffer->status = ARV_BUFFER_STATUS_SUCCESS;
+	       else
+		       state->buffer->status = ARV_BUFFER_STATUS_MISSING_BLOCKS;
+	}
+
 	if (state->buffer->status == ARV_BUFFER_STATUS_SUCCESS)
 		thread_data->n_completed_buffers++;
 	else
 		thread_data->n_failures++;
+
 	if (state->buffer->status == ARV_BUFFER_STATUS_ABORTED)
 		thread_data->n_aborteds++;
 
+	if (state->buffer->status == ARV_BUFFER_STATUS_SIZE_MISMATCH)
+		thread_data->n_size_mismatch_errors++;
+
 	if (thread_data->callback != NULL)
 		thread_data->callback (thread_data->user_data,
 				       ARV_STREAM_CALLBACK_TYPE_BUFFER_DONE,
@@ -178,10 +190,8 @@ _close_buffer (ArvGvStreamThreadData *thread_data, ArvGvStreamThreadState *state
 static void
 _process_data_leader (ArvGvStreamThreadData *thread_data, ArvGvStreamThreadState *state)
 {
-	if (state->buffer != NULL) {
-		state->buffer->status = ARV_BUFFER_STATUS_ABORTED;
+	if (state->buffer != NULL)
 		_close_buffer (thread_data, state);
-	}
 
 	state->buffer = g_async_queue_try_pop (thread_data->input_queue);
 	if (state->buffer == NULL) {
@@ -202,6 +212,7 @@ _process_data_leader (ArvGvStreamThreadData *thread_data, ArvGvStreamThreadState
 								     thread_data->timestamp_tick_frequency);
 
 	state->buffer->status = ARV_BUFFER_STATUS_FILLING;
+	state->read_data_size = 0;
 	state->n_missing_blocks = 0;
 	state->last_block_size = 0;
 	state->last_block_id = 0;
@@ -219,8 +230,10 @@ _process_data_block (ArvGvStreamThreadData *thread_data, ArvGvStreamThreadState
 	    state->buffer->status != ARV_BUFFER_STATUS_FILLING)
 		return;
 
-	if (state->buffer->frame_id != arv_gvsp_packet_get_frame_id (state->packet))
+	if (state->buffer->frame_id != arv_gvsp_packet_get_frame_id (state->packet)) {
+		thread_data->n_late_blocks ++;
 		return;
+	}
 
 	block_id = arv_gvsp_packet_get_block_id (state->packet);
 	if (block_id <= state->last_block_id) {
@@ -231,9 +244,14 @@ _process_data_block (ArvGvStreamThreadData *thread_data, ArvGvStreamThreadState
 		block_offset = state->last_block_size * (block_id - 1);
 		block_end = block_size + block_offset;
 
-		if (block_end  <= state->buffer->size)
-			memcpy (state->buffer->data + block_offset, &state->packet->data, block_size);
+		if (block_end  > state->buffer->size) {
+			arv_gvsp_packet_debug (state->packet, read_count);
+			state->buffer->status = ARV_BUFFER_STATUS_SIZE_MISMATCH;
+			return;
+		}
+		memcpy (state->buffer->data + block_offset, &state->packet->data, block_size);
 
+		state->read_data_size += block_size;
 		state->n_missing_blocks--;
 		thread_data->n_resent_blocks++;
 		return;
@@ -242,7 +260,7 @@ _process_data_block (ArvGvStreamThreadData *thread_data, ArvGvStreamThreadState
 	if (block_id != (state->last_block_id + 1)) {
 		gint32 n_misses;
 
-		n_misses = block_id - state->last_block_id;
+		n_misses = block_id - state->last_block_id - 1;
 
 		arv_gvsp_packet_debug (state->packet, read_count);
 		arv_debug ("stream-thread", "[GvStream::thread] Missing block (expected %d - %d) frame %d",
@@ -262,16 +280,13 @@ _process_data_block (ArvGvStreamThreadData *thread_data, ArvGvStreamThreadState
 	if (block_end  > state->buffer->size) {
 		arv_gvsp_packet_debug (state->packet, read_count);
 		state->buffer->status = ARV_BUFFER_STATUS_SIZE_MISMATCH;
-		thread_data->n_size_mismatch_errors++;
 		return;
 	}
 	memcpy (state->buffer->data + block_offset, &state->packet->data, block_size);
 
+	state->read_data_size += block_size;
 	state->last_block_size = block_size;
 	state->last_block_id =  block_id;
-
-	if (block_end  == state->buffer->size)
-		state->buffer->status = ARV_BUFFER_STATUS_SUCCESS;
 }
 
 static void
@@ -280,7 +295,7 @@ _process_data_trailer (ArvGvStreamThreadData *thread_data, ArvGvStreamThreadStat
 	if (state->buffer == NULL)
 		return;
 
-	if (state->n_missing_blocks != 0)
+	if (state->read_data_size < state->buffer->size)
 		return;
 
 	_close_buffer (thread_data, state);
@@ -427,6 +442,7 @@ arv_gv_stream_new (GInetAddress *device_address, guint16 port,
 	thread_data->n_size_mismatch_errors = 0;
 	thread_data->n_missing_blocks = 0;
 	thread_data->n_resent_blocks = 0;
+	thread_data->n_late_blocks = 0;
 	thread_data->n_aborteds = 0;
 
 	thread_data->statistic = arv_statistic_new (2, 5000, 200, 0);
@@ -493,6 +509,8 @@ arv_gv_stream_finalize (GObject *object)
 			   "[GvStream::finalize] n_missing_blocks       = %d", thread_data->n_missing_blocks);
 		arv_debug ("stream",
 			   "[GvStream::finalize] n_resent_blocks        = %d", thread_data->n_resent_blocks);
+		arv_debug ("stream",
+			   "[GvStream::finalize] n_late_blocks          = %d", thread_data->n_late_blocks);
 
 		thread_data->cancel = TRUE;
 		g_thread_join (gv_stream->thread);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]