From fba8be65b369fb391789ba31ea6120f2f04fd027 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20=C3=96man?= <andreas@lonelycoder.com>
Date: Mon, 15 Oct 2012 14:33:37 +0200
Subject: [PATCH] HTSP: Allow a subscriber to set queue depth

---
 src/htsp.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/htsp.c b/src/htsp.c
index f371183c..531e9fff 100644
--- a/src/htsp.c
+++ b/src/htsp.c
@@ -171,8 +171,12 @@ typedef struct htsp_subscription {
 
   int hs_90khz;
 
+  int hs_queue_depth;
+
 } htsp_subscription_t;
 
+#define HTSP_DEFAULT_QUEUE_DEPTH 500000
+
 /* **************************************************************************
  * Support routines
  * *************************************************************************/
@@ -1133,6 +1137,8 @@ htsp_method_subscribe(htsp_connection_t *htsp, htsmsg_t *in)
 
   hs->hs_htsp = htsp;
   hs->hs_90khz = req90khz;
+  hs->hs_queue_depth = htsmsg_get_u32_or_default(in, "queueDepth",
+						 HTSP_DEFAULT_QUEUE_DEPTH);
   htsp_init_queue(&hs->hs_q, 0);
 
   hs->hs_sid = sid;
@@ -1739,9 +1745,9 @@ htsp_stream_deliver(htsp_subscription_t *hs, th_pkt_t *pkt)
   int64_t ts;
   int qlen = hs->hs_q.hmq_payload;
 
-  if((qlen > 500000 && pkt->pkt_frametype == PKT_B_FRAME) ||
-     (qlen > 750000 && pkt->pkt_frametype == PKT_P_FRAME) || 
-     (qlen > 1500000)) {
+  if((qlen > hs->hs_queue_depth     && pkt->pkt_frametype == PKT_B_FRAME) ||
+     (qlen > hs->hs_queue_depth * 2 && pkt->pkt_frametype == PKT_P_FRAME) || 
+     (qlen > hs->hs_queue_depth * 3)) {
 
     hs->hs_dropstats[pkt->pkt_frametype]++;