← Back to team overview

rohc team mailing list archive

Re: [Question #233909]: about feedback - rohc_feedback_flush()

 

Question #233909 on rohc changed:
https://answers.launchpad.net/rohc/+question/233909

Didier Barvaux posted a new comment:
Hi,

> Yes, the second one looks well since that API has more information.
> 
> I am still working on version 1.3.1 and version 1.5.1 , so could you
> please provide a method or API for that? I guess something that has
> the following flavor would work for me. Of course, I believe your
> real codes will be much more complicated with all error
> protections :-). I will put it into the rohc_comp.c file at my end.

In addition to error checking missing, your code only takes the length
of the 1st unlocked feedback... if it even exists.

The feedbacks_first_unlocked index points on the first unlocked
feedback only if there is one. Otherwise it points on the location for
next feedback to come from decompressor.

Last thing, you need to add the length of the feedback header to the
length of data stored in the feedbacks[] array. They are not stored,
they are added dynamically when piggybacking or flushing.

I coded the version below for main dev branch (ie. future 1.7.0).
It should work for 1.5.x if you replace the call to rohc_comp_debug()
by a call to rohc_debugf(). Let me know if it works for you. If so,
I'll commit it and it will be part of next 1.7.0 release.

Regards,
Didier


=== modified file 'src/comp/rohc_comp.c'
--- src/comp/rohc_comp.c	2013-08-12 17:01:11 +0000
+++ src/comp/rohc_comp.c	2013-08-15 16:18:48 +0000
@@ -2552,6 +2552,58 @@ int rohc_feedback_flush(struct rohc_comp
 }
 
 
+/**
+ * @brief How many bytes of unsent feedback data are available at compressor?
+ *
+ * @param comp  The ROHC compressor
+ * @return      The number of bytes of unsent feedback data,
+ *              0 if no unsent feedback data is available
+ *
+ * @ingroup rohc_comp
+ */
+size_t rohc_feedback_avail_bytes(const struct rohc_comp *const comp)
+{
+	size_t feedback_length;
+	size_t i;
+
+	/* check input validity */
+	if(comp == NULL)
+	{
+		goto error;
+	}
+
+	feedback_length = 0;
+	for(i = 0; i < FEEDBACK_RING_SIZE; i++)
+	{
+		/* take only defined, unlocked feedbacks into account */
+		if(comp->feedbacks[i].length > 0 && !comp->feedbacks[i].is_locked)
+		{
+			/* retrieve the length of the feedback data */
+			feedback_length += comp->feedbacks[i].length;
+
+			/* how many additional bytes are required to encode length? */
+			if(feedback_length < 8)
+			{
+				feedback_length++;
+			}
+			else
+			{
+				feedback_length += 2;
+			}
+		}
+	}
+
+	rohc_debug(comp, ROHC_TRACE_COMP, ROHC_PROFILE_GENERAL,
+	           "there are %zu byte(s) of available unsent feedback data\n",
+	           feedback_length);
+
+	return feedback_length;
+
+error:
+	return 0;
+}
+
+
 #if !defined(ENABLE_DEPRECATED_API) || ENABLE_DEPRECATED_API == 1
 
 /**

=== modified file 'src/comp/rohc_comp.h'
--- src/comp/rohc_comp.h	2013-08-12 17:01:11 +0000
+++ src/comp/rohc_comp.h	2013-08-15 16:22:23 +0000
@@ -412,6 +412,8 @@ bool ROHC_EXPORT rohc_comp_deliver_feedb
 int ROHC_EXPORT rohc_feedback_flush(struct rohc_comp *comp,
                                     unsigned char *obuf,
                                     int osize);
+size_t ROHC_EXPORT rohc_feedback_avail_bytes(const struct rohc_comp *const comp)
+	__attribute__((warn_unused_result));
 bool ROHC_EXPORT rohc_feedback_remove_locked(struct rohc_comp *const comp)
 	__attribute__((warn_unused_result));
 bool ROHC_EXPORT rohc_feedback_unlock(struct rohc_comp *const comp)

-- 
You received this question notification because you are a member of ROHC
Team, which is an answer contact for rohc.