summaryrefslogtreecommitdiff
path: root/pjmedia
diff options
context:
space:
mode:
authorNanang Izzuddin <nanang@teluu.com>2008-09-24 17:27:46 +0000
committerNanang Izzuddin <nanang@teluu.com>2008-09-24 17:27:46 +0000
commite71cbd6b9a500ecf826258a82847ddff31fb0548 (patch)
tree9e1ab527c9dd32d3cb9189ab81015f7cbb9a0a28 /pjmedia
parent02e3cd6bbb45d51d3267d66149d6576405aa683b (diff)
Ticket #638: Reenable prefetch buffering via initial prefetch setting (set 0 to disable, otherwise to enable).
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@2317 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjmedia')
-rw-r--r--pjmedia/include/pjmedia/jbuf.h14
-rw-r--r--pjmedia/src/pjmedia/jbuf.c42
-rw-r--r--pjmedia/src/pjmedia/stream.c6
3 files changed, 41 insertions, 21 deletions
diff --git a/pjmedia/include/pjmedia/jbuf.h b/pjmedia/include/pjmedia/jbuf.h
index 3d718039..db004c65 100644
--- a/pjmedia/include/pjmedia/jbuf.h
+++ b/pjmedia/include/pjmedia/jbuf.h
@@ -149,14 +149,16 @@ PJ_DECL(pj_status_t) pjmedia_jbuf_set_fixed( pjmedia_jbuf *jb,
* Set the jitter buffer to adaptive mode.
*
* @param jb The jitter buffer.
- * @param prefetch The prefetch value to be applied to the jitter
- * buffer.
+ * @param prefetch The initial prefetch value to be applied to the
+ * jitter buffer. Setting this to other than 0 will
+ * activate prefetch buffering, a jitter buffer feature
+ * that each time it gets empty, it won't return a
+ * normal frame until its size reaches the number
+ * specified here.
* @param min_prefetch The minimum delay that must be applied to each
- * incoming packets, in number of frames. The
- * default value is zero.
+ * incoming packets, in number of frames.
* @param max_prefetch The maximum allowable value for prefetch delay,
- * in number of frames. The default value is equal
- * to the size of the jitter buffer.
+ * in number of frames.
*
* @return PJ_SUCCESS on success.
*/
diff --git a/pjmedia/src/pjmedia/jbuf.c b/pjmedia/src/pjmedia/jbuf.c
index 172aa00e..a27253e4 100644
--- a/pjmedia/src/pjmedia/jbuf.c
+++ b/pjmedia/src/pjmedia/jbuf.c
@@ -32,7 +32,6 @@
#define SAFE_SHRINKING_DIFF 1
#define MIN_SHRINK_GAP_MSEC 200
-#define USE_PREFETCH_BUFFERING 0
typedef struct jb_framelist_t
{
@@ -66,6 +65,7 @@ struct pjmedia_jbuf
int jb_prefetch; // no. of frame to insert before removing some
// (at the beginning of the framelist->flist_buffer operation)
int jb_prefetch_cnt; // prefetch counter
+ int jb_def_prefetch; // Default prefetch
int jb_min_prefetch; // Minimum allowable prefetch
int jb_max_prefetch; // Maximum allowable prefetch
int jb_status; // status is 'init' until the first 'put' operation
@@ -78,6 +78,7 @@ struct pjmedia_jbuf
#define JB_STATUS_INITIALIZING 0
#define JB_STATUS_PROCESSING 1
+#define JB_STATUS_PREFETCHING 2
/* Enabling this would log the jitter buffer state about once per
* second.
@@ -343,7 +344,7 @@ PJ_DEF(pj_status_t) pjmedia_jbuf_set_fixed( pjmedia_jbuf *jb,
PJ_ASSERT_RETURN(prefetch <= jb->jb_max_count, PJ_EINVAL);
jb->jb_min_prefetch = jb->jb_max_prefetch =
- jb->jb_prefetch = prefetch;
+ jb->jb_prefetch = jb->jb_def_prefetch = prefetch;
return PJ_SUCCESS;
}
@@ -364,7 +365,7 @@ PJ_DEF(pj_status_t) pjmedia_jbuf_set_adaptive( pjmedia_jbuf *jb,
max_prefetch <= jb->jb_max_count,
PJ_EINVAL);
- jb->jb_prefetch = prefetch;
+ jb->jb_prefetch = jb->jb_def_prefetch = prefetch;
jb->jb_min_prefetch = min_prefetch;
jb->jb_max_prefetch = max_prefetch;
@@ -422,14 +423,14 @@ static void jbuf_calculate_jitter(pjmedia_jbuf *jb)
*/
if (jb->jb_stable_hist > STABLE_HISTORY_LIMIT) {
- /* Update max_hist_level. */
- jb->jb_max_hist_level = jb->jb_prefetch;
-
diff = (jb->jb_prefetch - jb->jb_max_hist_level) / 3;
if (diff < 1)
diff = 1;
+ /* Update max_hist_level. */
+ jb->jb_max_hist_level = jb->jb_prefetch;
+
jb->jb_prefetch -= diff;
if (jb->jb_prefetch < jb->jb_min_prefetch)
jb->jb_prefetch = jb->jb_min_prefetch;
@@ -541,8 +542,23 @@ PJ_DEF(void) pjmedia_jbuf_put_frame2(pjmedia_jbuf *jb,
PJ_MAX(jb->jb_max_count/4,1) );
}
- if (jb->jb_prefetch_cnt < jb->jb_prefetch)
+ if (jb->jb_prefetch_cnt < jb->jb_prefetch) {
jb->jb_prefetch_cnt += seq_diff;
+
+ TRACE__((jb->name.ptr, "PUT prefetch_cnt=%d/%d",
+ jb->jb_prefetch_cnt, jb->jb_prefetch));
+
+ if (jb->jb_status == JB_STATUS_PREFETCHING &&
+ jb->jb_prefetch_cnt >= jb->jb_prefetch)
+ {
+ int diff, cur_size;
+
+ cur_size = jb_framelist_size(&jb->jb_framelist);
+ jb->jb_status = JB_STATUS_PROCESSING;
+ }
+ }
+
+
if (discarded)
*discarded = PJ_FALSE;
@@ -582,13 +598,15 @@ PJ_DEF(void) pjmedia_jbuf_get_frame2(pjmedia_jbuf *jb,
jbuf_update(jb, JB_OP_GET);
-#if USE_PREFETCH_BUFFERING
-
if (jb_framelist_size(&jb->jb_framelist) == 0) {
jb->jb_prefetch_cnt = 0;
+ if (jb->jb_def_prefetch)
+ jb->jb_status = JB_STATUS_PREFETCHING;
}
- if ((jb->jb_prefetch_cnt < jb->jb_prefetch)) {
+ if (jb->jb_status == JB_STATUS_PREFETCHING &&
+ jb->jb_prefetch_cnt < jb->jb_prefetch)
+ {
/* Can't return frame because jitter buffer is filling up
* minimum prefetch.
*/
@@ -601,11 +619,11 @@ PJ_DEF(void) pjmedia_jbuf_get_frame2(pjmedia_jbuf *jb,
if (size)
*size = 0;
+ TRACE__((jb->name.ptr, "GET prefetch_cnt=%d/%d",
+ jb->jb_prefetch_cnt, jb->jb_prefetch));
return;
}
-#endif
-
/* Retrieve a frame from frame list */
if (jb_framelist_get(&jb->jb_framelist,frame,size,&ftype,bit_info) ==
PJ_FALSE)
diff --git a/pjmedia/src/pjmedia/stream.c b/pjmedia/src/pjmedia/stream.c
index faa55c4f..736362c4 100644
--- a/pjmedia/src/pjmedia/stream.c
+++ b/pjmedia/src/pjmedia/stream.c
@@ -1669,7 +1669,7 @@ PJ_DEF(pj_status_t) pjmedia_stream_create( pjmedia_endpt *endpt,
else
jb_max = 500 / stream->codec_param.info.frm_ptime;
- if (info->jb_min_pre >= 0)
+ if (info->jb_min_pre > 0)
jb_min_pre = info->jb_min_pre;
else
//jb_min_pre = 60 / stream->codec_param.info.frm_ptime;
@@ -1681,11 +1681,11 @@ PJ_DEF(pj_status_t) pjmedia_stream_create( pjmedia_endpt *endpt,
//jb_max_pre = 240 / stream->codec_param.info.frm_ptime;
jb_max_pre = jb_max * 4 / 5;
- if (info->jb_init >= 0)
+ if (info->jb_init > 0)
jb_init = info->jb_init;
else
//jb_init = (jb_min_pre + jb_max_pre) / 2;
- jb_init = jb_min_pre;
+ jb_init = 0;
/* Create jitter buffer */