avsync-lib: remove no reqired mutex and avoid blocking [1/1]
PD#SWPL-53639
Problem:
For 60fps 4K content playing have frame freeze then drop occationally
it is due to display refresh thread was blocked and cannot be finished
in one VSync. optimized the possible blocking codes in that thread
to avoid schedule switch out
Solution:
*Removed no need mutex in pattern module
*Log use CLOCK_MONOTONIC instead of timeofdate to avoid possible
NTP adjustment check block.
*avsync lib time compare use CLOCK_MONOTONIC also.
*frame queue use rd/wr index to check fullbess instead of
fullness field to avoid mutex.
Verify:
NTS test case PLAY-DV-60FPS-HEAAC
Change-Id: I0703bc2f9455b3ad24d53951c9e0e025f4cc2cd8
Signed-off-by: yongchun.li <yongchun.li@amlogic.com>
diff --git a/src/queue.c b/src/queue.c
index e3318c1..3317cf0 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -17,7 +17,6 @@
int max_len;
int ri; //read index
int wi; //write index
- int total_num;
void **items;
};
@@ -45,7 +44,6 @@
q->max_len = max_len;
q->ri = q->wi = 0;
- q->total_num = 0;
return q;
}
@@ -62,16 +60,20 @@
int queue_item(void *queue, void * item)
{
struct queue *q = queue;
+ int fullness;
- if (!q || q->total_num == q->max_len)
+ if (!q)
return -1;
+ fullness = q->wi - q->ri;
+ if (fullness < 0) fullness += q->max_len;
+ if (fullness >= q->max_len - 1)
+ return -1; // not enough space
+
q->items[q->wi] = item;
if (q->wi == q->max_len - 1)
q->wi = 0;
else
q->wi++;
- q->total_num++;
-
return 0;
}
@@ -79,10 +81,15 @@
{
struct queue *q = queue;
int32_t index;
+ int fullness;
- if (!q || !q->total_num || q->total_num <= cnt)
+ if (!q)
return -1;
+ fullness = q->wi - q->ri;
+ if (fullness < 0) fullness += q->max_len;
+ if (fullness == 0 || fullness <= cnt)
+ return -1; //no enough to peek
index = q->ri;
index += cnt;
if (index >= q->max_len)
@@ -95,24 +102,30 @@
int dqueue_item(void *queue, void** p_item)
{
struct queue *q = queue;
+ int fullness;
- if (!q || !q->total_num)
+ if (!q)
return -1;
+ fullness = q->wi - q->ri;
+ if (fullness < 0) fullness += q->max_len;
+ if (fullness == 0)
+ return -1; //empty
*p_item = q->items[q->ri];
if (q->ri == q->max_len - 1)
q->ri = 0;
else
q->ri++;
- q->total_num--;
-
return 0;
}
int queue_size(void *queue)
{
struct queue *q = queue;
+ int fullness;
if (!q)
return -1;
- return q->total_num;
+ fullness = q->wi - q->ri;
+ if (fullness < 0) fullness += q->max_len;
+ return fullness;
}