video-info: Validate chroma-site when parsing caps and set defaults if none is set
Previously there was no validation at all and the defaults were set if the colorimetry was not set or invalid, but there's not really any connection between colorimetry and chroma-site. More validation could make sense in the future. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8258>
This commit is contained in:
parent
bdce7166b8
commit
959ccf65ad
@ -5650,7 +5650,7 @@ performed.</doc>
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/video/video-chroma.h">chroma is vertically cosited</doc>
|
||||
</member>
|
||||
<member name="alt_line" value="8" c:identifier="GST_VIDEO_CHROMA_SITE_ALT_LINE" glib:nick="alt-line" glib:name="GST_VIDEO_CHROMA_SITE_ALT_LINE">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/video/video-chroma.h">choma samples are sited on alternate lines</doc>
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/video/video-chroma.h">chroma samples are sited on alternate lines</doc>
|
||||
</member>
|
||||
<member name="cosited" value="6" c:identifier="GST_VIDEO_CHROMA_SITE_COSITED" glib:nick="cosited" glib:name="GST_VIDEO_CHROMA_SITE_COSITED">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/video/video-chroma.h">chroma samples cosited with luma samples</doc>
|
||||
|
@ -31,7 +31,7 @@ G_BEGIN_DECLS
|
||||
* @GST_VIDEO_CHROMA_SITE_NONE: no cositing
|
||||
* @GST_VIDEO_CHROMA_SITE_H_COSITED: chroma is horizontally cosited
|
||||
* @GST_VIDEO_CHROMA_SITE_V_COSITED: chroma is vertically cosited
|
||||
* @GST_VIDEO_CHROMA_SITE_ALT_LINE: choma samples are sited on alternate lines
|
||||
* @GST_VIDEO_CHROMA_SITE_ALT_LINE: chroma samples are sited on alternate lines
|
||||
* @GST_VIDEO_CHROMA_SITE_COSITED: chroma samples cosited with luma samples
|
||||
* @GST_VIDEO_CHROMA_SITE_JPEG: jpeg style cositing, also for mpeg1 and mjpeg
|
||||
* @GST_VIDEO_CHROMA_SITE_MPEG2: mpeg2 style cositing
|
||||
|
@ -166,10 +166,8 @@ set_default_colorimetry (GstVideoInfo * info)
|
||||
|
||||
if (GST_VIDEO_FORMAT_INFO_IS_YUV (finfo)) {
|
||||
if (info->height > 576) {
|
||||
info->chroma_site = GST_VIDEO_CHROMA_SITE_H_COSITED;
|
||||
info->colorimetry = default_color[DEFAULT_YUV_HD];
|
||||
} else {
|
||||
info->chroma_site = GST_VIDEO_CHROMA_SITE_NONE;
|
||||
info->colorimetry = default_color[DEFAULT_YUV_SD];
|
||||
}
|
||||
} else if (GST_VIDEO_FORMAT_INFO_IS_GRAY (finfo)) {
|
||||
@ -182,7 +180,7 @@ set_default_colorimetry (GstVideoInfo * info)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
validate_colorimetry (GstVideoInfo * info)
|
||||
validate_colorimetry (const GstVideoInfo * info)
|
||||
{
|
||||
const GstVideoFormatInfo *finfo = info->finfo;
|
||||
|
||||
@ -205,6 +203,48 @@ validate_colorimetry (GstVideoInfo * info)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
set_default_chroma_site (GstVideoInfo * info)
|
||||
{
|
||||
const GstVideoFormatInfo *finfo = info->finfo;
|
||||
|
||||
if (GST_VIDEO_FORMAT_INFO_IS_YUV (finfo)) {
|
||||
if (info->height > 576) {
|
||||
info->chroma_site = GST_VIDEO_CHROMA_SITE_H_COSITED;
|
||||
} else {
|
||||
info->chroma_site = GST_VIDEO_CHROMA_SITE_NONE;
|
||||
}
|
||||
} else {
|
||||
info->chroma_site = GST_VIDEO_CHROMA_SITE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
validate_chroma_site (const GstVideoInfo * info)
|
||||
{
|
||||
const GstVideoFormatInfo *finfo = info->finfo;
|
||||
|
||||
if (GST_VIDEO_FORMAT_INFO_IS_YUV (finfo)) {
|
||||
// FIXME: Might also want to check here for subsampling?
|
||||
// - chroma-site only makes sense with subsampled formats?
|
||||
// - ALT_LINE only makes sense for formats with vertical subsampling, and if
|
||||
// also V_COSITED?
|
||||
if ((info->chroma_site & GST_VIDEO_CHROMA_SITE_NONE) &&
|
||||
(info->chroma_site & (GST_VIDEO_CHROMA_SITE_H_COSITED |
|
||||
GST_VIDEO_CHROMA_SITE_V_COSITED))) {
|
||||
GST_WARNING
|
||||
("No chroma siting together with horizontal or vertical cositing is invalid");
|
||||
return FALSE;
|
||||
}
|
||||
} else if (info->chroma_site != GST_VIDEO_CHROMA_SITE_UNKNOWN) {
|
||||
GST_WARNING ("chroma-site only makes sense for YUV formats, %s is none",
|
||||
finfo->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_video_info_set_format_common (GstVideoInfo * info, GstVideoFormat format,
|
||||
guint width, guint height)
|
||||
@ -503,10 +543,19 @@ gst_video_info_from_caps (GstVideoInfo * info, const GstCaps * caps)
|
||||
* PAR to be doubled/halved too many times */
|
||||
}
|
||||
|
||||
if ((s = gst_structure_get_string (structure, "chroma-site")))
|
||||
if ((s = gst_structure_get_string (structure, "chroma-site"))) {
|
||||
info->chroma_site = gst_video_chroma_site_from_string (s);
|
||||
else
|
||||
info->chroma_site = GST_VIDEO_CHROMA_SITE_UNKNOWN;
|
||||
if (!validate_chroma_site (info)) {
|
||||
GST_WARNING ("invalid chroma-site, using default");
|
||||
set_default_chroma_site (info);
|
||||
} else if (GST_VIDEO_FORMAT_INFO_IS_YUV (info->finfo)
|
||||
&& info->chroma_site == GST_VIDEO_CHROMA_SITE_UNKNOWN) {
|
||||
/* force a default chroma-site for YUV formats */
|
||||
set_default_chroma_site (info);
|
||||
}
|
||||
} else {
|
||||
set_default_chroma_site (info);
|
||||
}
|
||||
|
||||
if ((s = gst_structure_get_string (structure, "colorimetry"))) {
|
||||
if (!gst_video_colorimetry_from_string (&info->colorimetry, s)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user