v4l2dec: CB1 driver deal with all resolution change except codec change [1/1]

PD#SWPL-189084

Problem:
driver deal with all resolution change except codec change

Solution:
when w h of caps changed, not reset decode drive

Verify:
AT301

Change-Id: Id0397762579cff85345937840c918c975593e554
Signed-off-by: hanghang.luo <hanghang.luo@amlogic.com>
diff --git a/src/gstamlv4l2videodec.c b/src/gstamlv4l2videodec.c
index 74a66e0..5814746 100644
--- a/src/gstamlv4l2videodec.c
+++ b/src/gstamlv4l2videodec.c
@@ -327,6 +327,31 @@
 }
 
 static gboolean
+gst_aml_v4l2_video_dec_update_probe_src_caps(GstAmlVideoDecoder *decoder)
+{
+    GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
+    GstCaps *caps;
+
+    GST_DEBUG_OBJECT (self, "update probe src caps");
+    gst_caps_replace (&self->probed_srccaps, NULL);
+    self->probed_srccaps = gst_aml_v4l2_object_probe_caps (self->v4l2capture,
+        gst_aml_v4l2_object_get_raw_caps ());
+    if (gst_caps_is_empty (self->probed_srccaps))
+    {
+        GST_ELEMENT_ERROR (self, RESOURCE, SETTINGS,
+            (_("Decoder on device %s has no supported output format"),
+            self->v4l2output->videodev), (NULL));
+        return FALSE;
+    }
+
+    caps = gst_caps_copy(self->probed_srccaps);
+    gst_caps_set_features_simple(caps, gst_caps_features_from_string(GST_CAPS_FEATURE_MEMORY_DMABUF));
+    gst_caps_append(self->probed_srccaps, caps);
+    GST_DEBUG_OBJECT (self, "update probe src caps: %" GST_PTR_FORMAT,self->probed_srccaps);
+    return TRUE;
+}
+
+static gboolean
 gst_aml_v4l2_video_dec_codec_chg(GstAmlVideoDecoder *decoder,
                                   GstAmlVideoCodecState *state)
 {
@@ -348,67 +373,20 @@
   return FALSE;
 }
 
-static gboolean
-gst_aml_v4l2_video_dec_res_chg(GstAmlVideoDecoder *decoder,
-                                  GstAmlVideoCodecState *state)
-{
-  GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
-  gboolean ret = FALSE;
-  gint width_new = -1,height_new = -1,width_old = -1,height_old = -1;
-  GstStructure *s_old = NULL;
-  GstStructure *s_new = NULL;
-
-  // first play, must set foramt;
-  if (!self->input_state)
-  {
-    ret = TRUE;
-    goto done;
-  }
-
-  if (self->input_state->caps)
-    s_old = gst_caps_get_structure(self->input_state->caps,0);
-  if (state->caps)
-    s_new = gst_caps_get_structure(state->caps,0);
-
-  if (s_new && gst_structure_has_field(s_new,"width") && gst_structure_has_field(s_new,"height"))
-  {
-    gst_structure_get_int(s_new,"width",&width_new);
-    gst_structure_get_int(s_new,"height",&height_new);
-  }
-  if (s_old && gst_structure_has_field(s_old,"width") && gst_structure_has_field(s_old,"height"))
-  {
-    gst_structure_get_int(s_old,"width",&width_old);
-    gst_structure_get_int(s_old,"height",&height_old);
-  }
-
-  if (width_new != width_old || height_new != height_old)
-    ret = TRUE;
-
-done:
-  GST_DEBUG_OBJECT(self, "ret is %d",ret);
-  return ret;
-}
 
 static gboolean
 gst_aml_v4l2_video_dec_set_format(GstAmlVideoDecoder *decoder,
                                   GstAmlVideoCodecState *state)
 {
+
   GstAmlV4l2Error error = GST_AML_V4L2_ERROR_INIT;
   gboolean ret = TRUE;
   GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
-  GstCaps *caps;
-
-  GST_DEBUG_OBJECT (self, "Setting format: %" GST_PTR_FORMAT, state->caps);
-  if (self->input_state)
-  {
-    if (gst_aml_v4l2_video_dec_res_chg(decoder,state) || gst_aml_v4l2_video_dec_codec_chg(decoder,state))
-      GST_DEBUG_OBJECT(self, "resolution or codec changed");
-    else
-      goto done;
-  }
-
   GstCapsFeatures *const features = gst_caps_get_features(state->caps, 0);
   GstStructure *s = gst_caps_get_structure(state->caps,0);
+
+  GST_DEBUG_OBJECT (self, "Setting format: %" GST_PTR_FORMAT, state->caps);
+
   if (s && gst_structure_has_field(s,"format"))
   {
     if (!strcmp("XVID",gst_structure_get_string(s,"format")))
@@ -424,12 +402,18 @@
 
   if (self->input_state)
   {
-    if (gst_aml_v4l2_object_caps_equal(self->v4l2output, state->caps))
-    {
-      GST_DEBUG_OBJECT (self, "Compatible caps");
-      goto done;
-    }
+      // 1、Only resolution change caused by codec changes are triggered by the gst,
+      // 2、the rest are triggered by drive.
+      if (!gst_aml_v4l2_video_dec_codec_chg(decoder,state))
+      {
+          if ((ret = gst_aml_v4l2_video_dec_update_probe_src_caps(decoder)) == FALSE)
+              GST_ERROR_OBJECT(self, "update probe caps error");
+          goto done;
+      }
+  }
 
+  if (self->input_state)
+  {
     gst_aml_v4l2_video_dec_finish (decoder);
     gst_aml_v4l2_object_stop (self->v4l2output);
 
@@ -477,7 +461,7 @@
       goto done;
   }
 
-  if (!gst_aml_v4l2_object_set_format (self->v4l2output, state->caps, &error))
+  if ((ret = gst_aml_v4l2_object_set_format (self->v4l2output, state->caps, &error)) == FALSE)
   {
       GST_ERROR_OBJECT(self, "set format error");
       goto done;
@@ -490,16 +474,12 @@
       goto done;
   }
 
-  gst_caps_replace (&self->probed_srccaps, NULL);
-  self->probed_srccaps = gst_aml_v4l2_object_probe_caps (self->v4l2capture,
-      gst_aml_v4l2_object_get_raw_caps ());
+  if ((ret = gst_aml_v4l2_video_dec_update_probe_src_caps(decoder)) == FALSE)
+  {
+      GST_ERROR_OBJECT(self, "update probe caps error");
+      goto done;
+  }
 
-  if (gst_caps_is_empty (self->probed_srccaps))
-    goto no_raw_format;
-
-  caps = gst_caps_copy(self->probed_srccaps);
-  gst_caps_set_features_simple(caps, gst_caps_features_from_string(GST_CAPS_FEATURE_MEMORY_DMABUF));
-  gst_caps_append(self->probed_srccaps, caps);
   if (ret)
     self->input_state = gst_aml_video_codec_state_ref (state);
   else
@@ -507,12 +487,6 @@
 
 done:
   return ret;
-
-no_raw_format:
-  GST_ELEMENT_ERROR (self, RESOURCE, SETTINGS,
-      (_("Decoder on device %s has no supported output format"),
-          self->v4l2output->videodev), (NULL));
-  return GST_FLOW_ERROR;
 }
 
 static gboolean
@@ -1176,6 +1150,7 @@
     else
       gst_aml_v4l2_clear_error (&error);
     gst_caps_unref (caps);
+
     gst_aml_v4l2_video_dec_set_output_status(decoder,info);
     if (!gst_aml_video_decoder_negotiate (decoder))
     {