libmix:  mix_video - Fix green artifacts in CNN videos

BZ: 9679

Flash video streamed from CNN site can have errors in the bitstream,
missing reference frames, etc, causing green artifacts in the decoded video.

This fix will skip video frames for which reference frames are not available
displaying only frames decoded correctly and increasing robustness.  Change
to mix_video to track reference IDR frames.

Consequences are that black video will be displayed until a correct video
bitstream is received from the server.

Change-Id: I4a2cd044c9e30a324c2e987d91df9f14e873f8a8
Signed-off-by: Linda Cline <linda.s.cline@intel.com>
Reviewed-on: http://android.intel.com:8080/20167
Reviewed-by: Chen, Weian <weian.chen@intel.com>
Tested-by: Sun, Hang L <hang.l.sun@intel.com>
Reviewed-by: buildbot <buildbot@intel.com>
Tested-by: buildbot <buildbot@intel.com>
diff --git a/mix_video/src/mixvideodef.h b/mix_video/src/mixvideodef.h
index 1c0aa02..464bc14 100644
--- a/mix_video/src/mixvideodef.h
+++ b/mix_video/src/mixvideodef.h
@@ -50,6 +50,7 @@
     MIX_RESULT_NOT_PERMITTED,
     MIX_RESULT_ERROR_PROCESS_STREAM,
     MIX_RESULT_MISSING_CONFIG,
+    MIX_RESULT_MISSING_IDR,
     MIX_RESULT_VIDEO_LAST
 } MIX_VIDEO_ERROR_CODE;
 
diff --git a/mix_video/src/mixvideoformat_h264.cpp b/mix_video/src/mixvideoformat_h264.cpp
old mode 100644
new mode 100755
index 158c456..a8213a7
--- a/mix_video/src/mixvideoformat_h264.cpp
+++ b/mix_video/src/mixvideoformat_h264.cpp
@@ -80,6 +80,7 @@
     enum _vbp_parser_type ptype = VBP_H264;
     vbp_data_h264 *data = NULL;
     MixIOVec *header = NULL;
+    missing_idr = true;
 
     MixVideoConfigParamsDecH264 *config_params_h264 = NULL;
     bool va_setup_flag = FALSE;
@@ -1228,6 +1229,7 @@
 
     if (data->new_sps) {
         decode_params->new_sequence = data->new_sps;
+        missing_idr = true;
 
         ret = _handle_new_sequence(data);
         if (ret != MIX_RESULT_SUCCESS) {
@@ -1258,6 +1260,17 @@
         return ret;
     }
 
+    // Check if first slice is IDR (5)
+    if (data->pic_data->slc_data->nal_unit_type == 5) {
+       missing_idr = false;
+       LOG_V("Received IDR.\n");
+    }
+    else if (missing_idr) {
+       LOG_V("Missing IDR.\n");
+       LOG_V("End\n");
+       return MIX_RESULT_MISSING_IDR;
+    }
+
     uint64 last_ts = this->current_timestamp;
     this->current_timestamp = ts;
     this->discontinuity_frame_in_progress = discontinuity;
diff --git a/mix_video/src/mixvideoformat_h264.h b/mix_video/src/mixvideoformat_h264.h
old mode 100644
new mode 100755
index b85d6df..a7d6479
--- a/mix_video/src/mixvideoformat_h264.h
+++ b/mix_video/src/mixvideoformat_h264.h
@@ -72,6 +72,7 @@
     //Can improve which frame is used for this at a later time
     MixVideoFrame  *last_decoded_frame;  //last surface decoded, to be used as reference frame when reference frames are missing
 #endif
+    bool missing_idr;
 };