libdvr: T-Shift size exceed 11G, cause the DTV black screen [1/1]

PD#SWPL-40034

Problem:
T-Shift size exceed 11G, cause the DTV black screen,
there has a deadlock bug.

Solution:
1.fixed deadlock error.we need lock record first and to
lock playback,because deal record event,we will get playback
lock.so not try get record lock when we had got playback lock.


Verify:
AM301

Signed-off-by: hualing chen <hualing.chen@amlogic.com>
Change-Id: I928f878bf2ceddb017d3411cf8555799eb737f87
diff --git a/src/dvr_wrapper.c b/src/dvr_wrapper.c
index 5bc679b..7db2a83 100644
--- a/src/dvr_wrapper.c
+++ b/src/dvr_wrapper.c
@@ -1264,11 +1264,28 @@
   DVR_RecordSegmentInfo_t seg_info_1st;
   int got_1st_seg;
   DVR_WrapperCtx_t *ctx_record;/*for timeshift*/
-
+  DVR_Bool_t is_timeshift = DVR_FALSE;
 
   DVR_RETURN_IF_FALSE(playback);
   DVR_RETURN_IF_FALSE(p_pids);
 
+  ctx_record = NULL;
+
+  /*lock the recorder to avoid changing the recording segments*/
+  ctx_record = ctx_getRecord(sn_timeshift_record);
+
+  if (ctx_record) {
+    pthread_mutex_lock(&ctx_record->lock);
+    if (!ctx_valid(ctx_record)
+      || ctx_record->sn != sn_timeshift_record) {
+      DVR_WRAPPER_DEBUG(1, "timeshift, record is not for timeshifting, FATAL error found\n");
+      pthread_mutex_unlock(&ctx_record->lock);
+      is_timeshift  = DVR_FALSE;
+    } else {
+      is_timeshift  = DVR_TRUE;
+    }
+  }
+
   ctx = ctx_getPlayback((unsigned long)playback);
   DVR_RETURN_IF_FALSE(ctx);
 
@@ -1286,23 +1303,16 @@
 
   DVR_RETURN_IF_FALSE_WITH_UNLOCK(ctx_valid(ctx), &ctx->lock);
 
-  ctx_record = NULL;
   if (ctx->playback.param_open.is_timeshift) {
     /*lock the recorder to avoid changing the recording segments*/
-    ctx_record = ctx_getRecord(sn_timeshift_record);
-
-    if (ctx_record) {
-      pthread_mutex_lock(&ctx_record->lock);
-      if (!ctx_valid(ctx_record)
-        || ctx_record->sn != sn_timeshift_record) {
-        DVR_WRAPPER_DEBUG(1, "timeshift, record is not for timeshifting, FATAL error\n");
-        pthread_mutex_unlock(&ctx_record->lock);
-      } else {
-        DVR_WRAPPER_DEBUG(1, "playback(sn:%ld) record(sn:%ld) locked ok due to timeshift\n",
-          ctx->sn, ctx_record->sn);
-      }
+    if (is_timeshift == DVR_FALSE) {
+      DVR_WRAPPER_DEBUG(1, "timeshift, record is not for timeshifting, FATAL error return\n");
+      pthread_mutex_unlock(&ctx->lock);
+      return DVR_FAILURE;
+    } else {
+      DVR_WRAPPER_DEBUG(1, "playback(sn:%ld) record(sn:%ld) locked ok due to timeshift\n",
+        ctx->sn, ctx_record->sn);
     }
-    DVR_RETURN_IF_FALSE_WITH_UNLOCK(ctx_record, &ctx->lock);
   }
 
   /*obtain all segments in a list*/