libdvr: guarded_segment_size needs to be backward compatible [1/1]

PD#SWPL-100948

Problem:
S905C3 pvr record failed on Android T.
Irdeto MW didn't rely on dvr_wrapper but called dvr_record API directly.
The problem is that recently introduced segment guarding mechanism passes a
guarded_segment_size from dvr_wrapper to dvr_record when a record is opened.
As a result, in Irdeto's situation, guarded_segment_size is uninitialized.
A too small guarded_segment_size 0 can lead to recording failure.

Solution:
Handle guarded_segment_size value 0 situation. Treat it as an indicator
to disable segment guarding mechanism. With the guarding function off,
recording can work normally as before.

Verify:
Locally tested OK in RDK AH212 environment.

Signed-off-by: Wentao.MA <wentao.ma@amlogic.com>
Change-Id: I382d90091f105af8c1058d890044f2f3beb35d97
diff --git a/src/dvr_record.c b/src/dvr_record.c
index 5d4eada..faa2050 100644
--- a/src/dvr_record.c
+++ b/src/dvr_record.c
@@ -304,7 +304,8 @@
     gettimeofday(&t2, NULL);
 
     guarded_size_exceeded = DVR_FALSE;
-    if (p_ctx->segment_info.size+len >= p_ctx->guarded_segment_size) {
+    if ( p_ctx->guarded_segment_size > 0 &&
+        p_ctx->segment_info.size+len >= p_ctx->guarded_segment_size) {
       guarded_size_exceeded = DVR_TRUE;
     }
     /* Got data from device, record it */
@@ -588,6 +589,11 @@
   p_ctx->state = DVR_RECORD_STATE_OPENED;
   p_ctx->force_sysclock = params->force_sysclock;
   p_ctx->guarded_segment_size = params->guarded_segment_size;
+  if (p_ctx->guarded_segment_size <= 0) {
+    DVR_WARN("Odd guarded_segment_size value %lld is given. Change it to"
+        " 0 to disable segment guarding mechanism.", p_ctx->guarded_segment_size);
+    p_ctx->guarded_segment_size = 0;
+  }
   p_ctx->discard_coming_data = DVR_FALSE;
   DVR_INFO("%s, block_size:%d is_new:%d", __func__, p_ctx->block_size, p_ctx->is_new_dmx);
   *p_handle = p_ctx;