changeset 125:a910b49dfbee

work in progress improvement: - fix bugs around cond_timedwait - try to avoid sticking in PMT analysis
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Tue, 21 Feb 2012 15:46:04 +0900
parents f2ae5ddeed7e
children bb93a7c0ff5d
files recpt1/recpt1.c recpt1/tssplitter_lite.c
diffstat 2 files changed, 30 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/recpt1/recpt1.c	Thu Feb 16 13:11:38 2012 +0900
+++ b/recpt1/recpt1.c	Tue Feb 21 15:46:04 2012 +0900
@@ -209,18 +209,24 @@
 {
     struct timeval now;
     struct timespec spec;
-
-    gettimeofday(&now, NULL);
-    spec.tv_sec = now.tv_sec + 1;
-    spec.tv_nsec = now.tv_usec * 1000;
+    int retry_count = 0;
 
     pthread_mutex_lock(&p_queue->mutex);
     /* entered critical section */
 
     /* wait while queue is full */
     while(p_queue->num_avail == 0) {
+
+        gettimeofday(&now, NULL);
+        spec.tv_sec = now.tv_sec + 1;
+        spec.tv_nsec = now.tv_usec * 1000;
+
         pthread_cond_timedwait(&p_queue->cond_avail,
                                &p_queue->mutex, &spec);
+        retry_count++;
+        if(retry_count > 60) {
+            f_exit = TRUE;
+        }
         if(f_exit) {
             pthread_mutex_unlock(&p_queue->mutex);
             return;
@@ -249,18 +255,24 @@
     struct timeval now;
     struct timespec spec;
     BUFSZ *buffer;
-
-    gettimeofday(&now, NULL);
-    spec.tv_sec = now.tv_sec + 1;
-    spec.tv_nsec = now.tv_usec * 1000;
+    int retry_count = 0;
 
     pthread_mutex_lock(&p_queue->mutex);
     /* entered the critical section*/
 
     /* wait while queue is empty */
     while(p_queue->num_used == 0) {
+
+        gettimeofday(&now, NULL);
+        spec.tv_sec = now.tv_sec + 1;
+        spec.tv_nsec = now.tv_usec * 1000;
+
         pthread_cond_timedwait(&p_queue->cond_used,
                                &p_queue->mutex, &spec);
+        retry_count++;
+        if(retry_count > 60) {
+            f_exit = TRUE;
+        }
         if(f_exit) {
             pthread_mutex_unlock(&p_queue->mutex);
             return NULL;
--- a/recpt1/tssplitter_lite.c	Thu Feb 16 13:11:38 2012 +0900
+++ b/recpt1/tssplitter_lite.c	Tue Feb 21 15:46:04 2012 +0900
@@ -227,7 +227,7 @@
 		// PAT
 		if(0x0000 == pid) {
 			result = AnalyzePat(sp, sbuf->data + index);
-			if(TSS_SUCCESS != result) {
+			if(result != TSS_SUCCESS) {
 				/* 下位の関数内部でmalloc error発生 */
 				return result;
 			}
@@ -238,7 +238,10 @@
 		 * 残すべきPCR/AUDIO/VIDEO PIDを取得する */
 		if(sp->pmt_pids[pid] == 1) {
 			/* この中にはPMT毎に一度しか入らないようにしておく */
-			AnalyzePmt(sp, sbuf->data + index);
+			result = AnalyzePmt(sp, sbuf->data + index);
+			if(result != TSS_SUCCESS) {
+				return result;
+			}
 			sp->pmt_pids[pid]++;
 			sp->pmt_counter += 1;
 		}
@@ -587,6 +590,7 @@
 	unsigned char N;
 	int pcr;
 	int epid;
+	int retry_count = 0;
 
 	Nall = ((buf[6] & 0x0F) << 4) + buf[7];
 	if(Nall > LENGTH_PACKET)
@@ -627,6 +631,10 @@
 			sp->pids[epid] = 1;
 		}
 		N += 4 + (((buf[N + 3]) & 0x0F) << 4) + buf[N + 4] + 1;
+		retry_count++;
+		if(retry_count > Nall) {
+			return TSS_ERROR;
+		}
 	}
 
 	return TSS_SUCCESS;