libs: video: split allocation query caos and pad caps
authorVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Thu, 31 Mar 2016 13:31:31 +0000 (15:31 +0200)
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Tue, 5 Apr 2016 09:32:50 +0000 (11:32 +0200)
Since the allocation query caps contains memory size and the pad's caps
contains the display size, a video encoder or decoder might need to allocate
a different frame size than the size negotiated in the caps.

This patch splits this logic distinction for videodecoder and videoencoder.

The user if needs a different allocation caps, should set the allocation_caps
in the GstVideoCodecState before calling negotiate() vmethod. Otherwise the
allocation_caps will be the same as the caps set in the src pad.

https://bugzilla.gnome.org/show_bug.cgi?id=764421

gst-libs/gst/video/gstvideodecoder.c
gst-libs/gst/video/gstvideoencoder.c
gst-libs/gst/video/gstvideoutils.c
gst-libs/gst/video/gstvideoutils.h

index d13484a..6e0d86f 100644 (file)
@@ -3797,6 +3797,8 @@ gst_video_decoder_negotiate_default (GstVideoDecoder * decoder)
 
   if (state->caps == NULL)
     state->caps = gst_video_info_to_caps (&state->info);
+  if (state->allocation_caps == NULL)
+    state->allocation_caps = gst_caps_ref (state->caps);
 
   GST_DEBUG_OBJECT (decoder, "setting caps %" GST_PTR_FORMAT, state->caps);
 
@@ -3845,7 +3847,7 @@ gst_video_decoder_negotiate_default (GstVideoDecoder * decoder)
     goto done;
   decoder->priv->output_state_changed = FALSE;
   /* Negotiate pool */
-  ret = gst_video_decoder_negotiate_pool (decoder, state->caps);
+  ret = gst_video_decoder_negotiate_pool (decoder, state->allocation_caps);
 
 done:
   return ret;
index a13d4ed..ca13c8b 100644 (file)
@@ -1630,6 +1630,9 @@ gst_video_encoder_negotiate_default (GstVideoEncoder * encoder)
     encoder->priv->output_state_changed = FALSE;
   }
 
+  if (state->allocation_caps == NULL)
+    state->allocation_caps = gst_caps_ref (state->caps);
+
   /* Push all pending pre-caps events of the oldest frame before
    * setting caps */
   frame = encoder->priv->frames ? encoder->priv->frames->data : NULL;
@@ -1668,7 +1671,7 @@ gst_video_encoder_negotiate_default (GstVideoEncoder * encoder)
   if (!ret)
     goto done;
 
-  query = gst_query_new_allocation (state->caps, TRUE);
+  query = gst_query_new_allocation (state->allocation_caps, TRUE);
   if (!gst_pad_peer_query (encoder->srcpad, query)) {
     GST_DEBUG_OBJECT (encoder, "didn't get downstream ALLOCATION hints");
   }
index b3decaf..8a3a230 100644 (file)
@@ -162,6 +162,8 @@ _gst_video_codec_state_free (GstVideoCodecState * state)
 
   if (state->caps)
     gst_caps_unref (state->caps);
+  if (state->allocation_caps)
+    gst_caps_unref (state->allocation_caps);
   if (state->codec_data)
     gst_buffer_unref (state->codec_data);
   g_slice_free (GstVideoCodecState, state);
index deea0ee..f7aed89 100644 (file)
@@ -41,9 +41,11 @@ typedef struct _GstVideoCodecFrame GstVideoCodecFrame;
 /**
  * GstVideoCodecState:
  * @info: The #GstVideoInfo describing the stream
- * @caps: The #GstCaps
+ * @caps: The #GstCaps used in the caps negotiation of the pad.
  * @codec_data: a #GstBuffer corresponding to the
  *     'codec_data' field of a stream, or NULL.
+ * @allocation_caps: The #GstCaps for allocation query and pool
+ *     negotiation. Since: 1.10
  *
  * Structure representing the state of an incoming or outgoing video
  * stream for encoders and decoders.
@@ -67,8 +69,10 @@ struct _GstVideoCodecState
 
   GstBuffer *codec_data;
 
+  GstCaps *allocation_caps;
+
   /*< private >*/
-  void         *padding[GST_PADDING_LARGE];
+  void         *padding[GST_PADDING_LARGE - 1];
 };
 
 /**