v4l2: Move propose allocation to v4l2object

This commit is contained in:
Nicolas Dufresne 2014-03-27 13:20:53 -04:00
parent f810196b3e
commit 0488984f82
3 changed files with 64 additions and 55 deletions

View file

@ -3169,3 +3169,63 @@ pool_failed:
return FALSE;
}
}
gboolean
gst_v4l2_object_propose_allocation (GstV4l2Object * obj, GstQuery * query)
{
GstBufferPool *pool;
guint size = 0;
GstCaps *caps;
gboolean need_pool;
gst_query_parse_allocation (query, &caps, &need_pool);
if (caps == NULL)
goto no_caps;
if ((pool = obj->pool))
gst_object_ref (pool);
if (pool != NULL) {
GstCaps *pcaps;
GstStructure *config;
/* we had a pool, check caps */
config = gst_buffer_pool_get_config (pool);
gst_buffer_pool_config_get_params (config, &pcaps, &size, NULL, NULL);
GST_DEBUG_OBJECT (obj->element,
"we had a pool with caps %" GST_PTR_FORMAT, pcaps);
if (!gst_caps_is_equal (caps, pcaps)) {
gst_structure_free (config);
gst_object_unref (pool);
goto different_caps;
}
gst_structure_free (config);
}
/* we need at least 2 buffers to operate */
gst_query_add_allocation_pool (query, pool, size, 2, 0);
/* we also support various metadata */
/* FIXME should it be set per class ? */
gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
gst_query_add_allocation_meta (query, GST_VIDEO_CROP_META_API_TYPE, NULL);
if (pool)
gst_object_unref (pool);
return TRUE;
/* ERRORS */
no_caps:
{
GST_DEBUG_OBJECT (obj->element, "no caps specified");
return FALSE;
}
different_caps:
{
/* different caps, we can't use this pool */
GST_DEBUG_OBJECT (obj->element, "pool has different caps");
return FALSE;
}
}

View file

@ -268,6 +268,9 @@ gboolean gst_v4l2_object_set_crop (GstV4l2Object * obj);
gboolean gst_v4l2_object_decide_allocation (GstV4l2Object * v4l2object,
GstQuery * query);
gboolean gst_v4l2_object_propose_allocation (GstV4l2Object * obj,
GstQuery * query);
GstStructure * gst_v4l2_object_v4l2fourcc_to_structure (guint32 fourcc);

View file

@ -536,61 +536,7 @@ static gboolean
gst_v4l2sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
{
GstV4l2Sink *v4l2sink = GST_V4L2SINK (bsink);
GstV4l2Object *obj = v4l2sink->v4l2object;
GstBufferPool *pool;
guint size = 0;
GstCaps *caps;
gboolean need_pool;
gst_query_parse_allocation (query, &caps, &need_pool);
if (caps == NULL)
goto no_caps;
if ((pool = obj->pool))
gst_object_ref (pool);
if (pool != NULL) {
GstCaps *pcaps;
GstStructure *config;
/* we had a pool, check caps */
config = gst_buffer_pool_get_config (pool);
gst_buffer_pool_config_get_params (config, &pcaps, &size, NULL, NULL);
GST_DEBUG_OBJECT (v4l2sink,
"we had a pool with caps %" GST_PTR_FORMAT, pcaps);
if (!gst_caps_is_equal (caps, pcaps)) {
gst_structure_free (config);
gst_object_unref (pool);
goto different_caps;
}
gst_structure_free (config);
}
/* we need at least 2 buffers to operate */
gst_query_add_allocation_pool (query, pool, size, 2, 0);
/* we also support various metadata */
gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
gst_query_add_allocation_meta (query, GST_VIDEO_CROP_META_API_TYPE, NULL);
if (pool)
gst_object_unref (pool);
return TRUE;
/* ERRORS */
no_caps:
{
GST_DEBUG_OBJECT (v4l2sink, "no caps specified");
return FALSE;
}
different_caps:
{
/* different caps, we can't use this pool */
GST_DEBUG_OBJECT (v4l2sink, "pool has different caps");
return FALSE;
}
return gst_v4l2_object_propose_allocation (v4l2sink->v4l2object, query);
}
/* called after A/V sync to render frame */