mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-20 00:31:13 +00:00
plugins: add gst_vaapi_caps_set_width_and_height_range()
This utility function is called internally by gst_vaapi_build_caps_from_formats() and can be used outside. This function sets frame size and framerates ranges. Also gst_vaapi_build_caps_from_formats() is simplified. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-vaapi/-/merge_requests/374>
This commit is contained in:
parent
6ab488475a
commit
99ac072673
3 changed files with 40 additions and 48 deletions
|
@ -197,25 +197,6 @@ gst_vaapidecode_update_sink_caps (GstVaapiDecode * decode, GstCaps * caps)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
|
||||||
caps_set_width_and_height_range (GstCaps * caps, gint min_width,
|
|
||||||
gint min_height, gint max_width, gint max_height)
|
|
||||||
{
|
|
||||||
guint size, i;
|
|
||||||
GstStructure *structure;
|
|
||||||
|
|
||||||
/* Set the width/height info to caps */
|
|
||||||
size = gst_caps_get_size (caps);
|
|
||||||
for (i = 0; i < size; i++) {
|
|
||||||
structure = gst_caps_get_structure (caps, i);
|
|
||||||
if (!structure)
|
|
||||||
continue;
|
|
||||||
gst_structure_set (structure, "width", GST_TYPE_INT_RANGE, min_width,
|
|
||||||
max_width, "height", GST_TYPE_INT_RANGE, min_height, max_height,
|
|
||||||
"framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_vaapidecode_ensure_allowed_srcpad_caps (GstVaapiDecode * decode)
|
gst_vaapidecode_ensure_allowed_srcpad_caps (GstVaapiDecode * decode)
|
||||||
{
|
{
|
||||||
|
@ -234,7 +215,7 @@ gst_vaapidecode_ensure_allowed_srcpad_caps (GstVaapiDecode * decode)
|
||||||
if (!decode->decoder)
|
if (!decode->decoder)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
out_caps = base_caps = raw_caps = va_caps = dma_caps = gltexup_caps = NULL;
|
dma_caps = gltexup_caps = NULL;
|
||||||
|
|
||||||
formats = gst_vaapi_decoder_get_surface_attributes (decode->decoder,
|
formats = gst_vaapi_decoder_get_surface_attributes (decode->decoder,
|
||||||
&min_width, &min_height, &max_width, &max_height, &mem_types);
|
&min_width, &min_height, &max_width, &max_height, &mem_types);
|
||||||
|
@ -244,8 +225,8 @@ gst_vaapidecode_ensure_allowed_srcpad_caps (GstVaapiDecode * decode)
|
||||||
base_caps = gst_vaapi_video_format_new_template_caps_from_list (formats);
|
base_caps = gst_vaapi_video_format_new_template_caps_from_list (formats);
|
||||||
if (!base_caps)
|
if (!base_caps)
|
||||||
goto bail;
|
goto bail;
|
||||||
caps_set_width_and_height_range (base_caps, min_width, min_height, max_width,
|
gst_vaapi_caps_set_width_and_height_range (base_caps, min_width, min_height,
|
||||||
max_height);
|
max_width, max_height);
|
||||||
|
|
||||||
raw_caps = gst_vaapi_plugin_base_get_allowed_srcpad_raw_caps
|
raw_caps = gst_vaapi_plugin_base_get_allowed_srcpad_raw_caps
|
||||||
(GST_VAAPI_PLUGIN_BASE (decode),
|
(GST_VAAPI_PLUGIN_BASE (decode),
|
||||||
|
@ -253,7 +234,7 @@ gst_vaapidecode_ensure_allowed_srcpad_caps (GstVaapiDecode * decode)
|
||||||
if (!raw_caps)
|
if (!raw_caps)
|
||||||
goto bail;
|
goto bail;
|
||||||
raw_caps = gst_caps_copy (raw_caps);
|
raw_caps = gst_caps_copy (raw_caps);
|
||||||
caps_set_width_and_height_range (raw_caps, min_width, min_height,
|
gst_vaapi_caps_set_width_and_height_range (raw_caps, min_width, min_height,
|
||||||
max_width, max_height);
|
max_width, max_height);
|
||||||
|
|
||||||
va_caps = gst_caps_copy (base_caps);
|
va_caps = gst_caps_copy (base_caps);
|
||||||
|
@ -272,8 +253,8 @@ gst_vaapidecode_ensure_allowed_srcpad_caps (GstVaapiDecode * decode)
|
||||||
&& gst_vaapi_display_has_opengl (GST_VAAPI_PLUGIN_BASE_DISPLAY (decode))) {
|
&& gst_vaapi_display_has_opengl (GST_VAAPI_PLUGIN_BASE_DISPLAY (decode))) {
|
||||||
gltexup_caps = gst_caps_from_string (GST_VAAPI_MAKE_GLTEXUPLOAD_CAPS);
|
gltexup_caps = gst_caps_from_string (GST_VAAPI_MAKE_GLTEXUPLOAD_CAPS);
|
||||||
if (gltexup_caps) {
|
if (gltexup_caps) {
|
||||||
caps_set_width_and_height_range (base_caps, min_width, min_height,
|
gst_vaapi_caps_set_width_and_height_range (base_caps, min_width,
|
||||||
max_width, max_height);
|
min_height, max_width, max_height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -283,9 +264,7 @@ gst_vaapidecode_ensure_allowed_srcpad_caps (GstVaapiDecode * decode)
|
||||||
gst_caps_append (out_caps, dma_caps);
|
gst_caps_append (out_caps, dma_caps);
|
||||||
if (gltexup_caps)
|
if (gltexup_caps)
|
||||||
gst_caps_append (out_caps, gltexup_caps);
|
gst_caps_append (out_caps, gltexup_caps);
|
||||||
if (raw_caps)
|
gst_caps_append (out_caps, gst_caps_copy (raw_caps));
|
||||||
gst_caps_append (out_caps, raw_caps);
|
|
||||||
|
|
||||||
decode->allowed_srcpad_caps = out_caps;
|
decode->allowed_srcpad_caps = out_caps;
|
||||||
|
|
||||||
GST_INFO_OBJECT (decode, "allowed srcpad caps: %" GST_PTR_FORMAT,
|
GST_INFO_OBJECT (decode, "allowed srcpad caps: %" GST_PTR_FORMAT,
|
||||||
|
|
|
@ -1071,6 +1071,25 @@ gst_vaapi_encoder_get_profiles_from_caps (GstCaps * caps,
|
||||||
return profiles;
|
return profiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_vaapi_caps_set_width_and_height_range (GstCaps * caps, gint min_width,
|
||||||
|
gint min_height, gint max_width, gint max_height)
|
||||||
|
{
|
||||||
|
guint size, i;
|
||||||
|
GstStructure *structure;
|
||||||
|
|
||||||
|
/* Set the width/height info to caps */
|
||||||
|
size = gst_caps_get_size (caps);
|
||||||
|
for (i = 0; i < size; i++) {
|
||||||
|
structure = gst_caps_get_structure (caps, i);
|
||||||
|
if (!structure)
|
||||||
|
continue;
|
||||||
|
gst_structure_set (structure, "width", GST_TYPE_INT_RANGE, min_width,
|
||||||
|
max_width, "height", GST_TYPE_INT_RANGE, min_height, max_height,
|
||||||
|
"framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_vaapi_build_caps_from_formats:
|
* gst_vaapi_build_caps_from_formats:
|
||||||
* @formats: an array of supported #GstVideoFormat
|
* @formats: an array of supported #GstVideoFormat
|
||||||
|
@ -1089,42 +1108,31 @@ GstCaps *
|
||||||
gst_vaapi_build_caps_from_formats (GArray * formats, gint min_width,
|
gst_vaapi_build_caps_from_formats (GArray * formats, gint min_width,
|
||||||
gint min_height, gint max_width, gint max_height, guint mem_types)
|
gint min_height, gint max_width, gint max_height, guint mem_types)
|
||||||
{
|
{
|
||||||
GstCaps *out_caps = NULL;
|
GstCaps *out_caps, *raw_caps, *va_caps, *dma_caps;
|
||||||
GstCaps *raw_caps = NULL;
|
|
||||||
GstCaps *va_caps, *dma_caps;
|
dma_caps = NULL;
|
||||||
guint i, size;
|
|
||||||
GstStructure *structure;
|
|
||||||
|
|
||||||
raw_caps = gst_vaapi_video_format_new_template_caps_from_list (formats);
|
raw_caps = gst_vaapi_video_format_new_template_caps_from_list (formats);
|
||||||
if (!raw_caps)
|
if (!raw_caps)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
gst_vaapi_caps_set_width_and_height_range (raw_caps, min_width, min_height,
|
||||||
/* Set the width/height info to caps */
|
max_width, max_height);
|
||||||
size = gst_caps_get_size (raw_caps);
|
|
||||||
for (i = 0; i < size; i++) {
|
|
||||||
structure = gst_caps_get_structure (raw_caps, i);
|
|
||||||
if (!structure)
|
|
||||||
continue;
|
|
||||||
gst_structure_set (structure, "width", GST_TYPE_INT_RANGE, min_width,
|
|
||||||
max_width, "height", GST_TYPE_INT_RANGE, min_height, max_height, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
out_caps = gst_caps_copy (raw_caps);
|
|
||||||
|
|
||||||
va_caps = gst_caps_copy (raw_caps);
|
va_caps = gst_caps_copy (raw_caps);
|
||||||
gst_caps_set_features_simple (va_caps,
|
gst_caps_set_features_simple (va_caps,
|
||||||
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_VAAPI_SURFACE));
|
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_VAAPI_SURFACE));
|
||||||
gst_caps_append (out_caps, va_caps);
|
|
||||||
|
|
||||||
if (gst_vaapi_mem_type_supports (mem_types,
|
if (gst_vaapi_mem_type_supports (mem_types,
|
||||||
GST_VAAPI_BUFFER_MEMORY_TYPE_DMA_BUF)) {
|
GST_VAAPI_BUFFER_MEMORY_TYPE_DMA_BUF)) {
|
||||||
dma_caps = gst_caps_copy (raw_caps);
|
dma_caps = gst_caps_copy (raw_caps);
|
||||||
gst_caps_set_features_simple (dma_caps,
|
gst_caps_set_features_simple (dma_caps,
|
||||||
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_DMABUF));
|
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_DMABUF));
|
||||||
gst_caps_append (out_caps, dma_caps);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_caps_unref (raw_caps);
|
out_caps = va_caps;
|
||||||
|
if (dma_caps)
|
||||||
|
gst_caps_append (out_caps, dma_caps);
|
||||||
|
gst_caps_append (out_caps, raw_caps);
|
||||||
|
|
||||||
return out_caps;
|
return out_caps;
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,6 +161,11 @@ GArray *
|
||||||
gst_vaapi_encoder_get_profiles_from_caps (GstCaps * caps,
|
gst_vaapi_encoder_get_profiles_from_caps (GstCaps * caps,
|
||||||
GstVaapiStrToProfileFunc func);
|
GstVaapiStrToProfileFunc func);
|
||||||
|
|
||||||
|
G_GNUC_INTERNAL
|
||||||
|
void
|
||||||
|
gst_vaapi_caps_set_width_and_height_range (GstCaps * caps, gint min_width,
|
||||||
|
gint min_height, gint max_width, gint max_height);
|
||||||
|
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
GstCaps *
|
GstCaps *
|
||||||
gst_vaapi_build_caps_from_formats (GArray * formats, gint min_width,
|
gst_vaapi_build_caps_from_formats (GArray * formats, gint min_width,
|
||||||
|
|
Loading…
Reference in a new issue