gtk: Add "video-aspect-ratio-override" property

Allow front-ends to override the pixel aspect ratio found inside the
video file itself, or most likely, missing from the video file.

This is a long-standing feature of totem.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1137>
This commit is contained in:
Bastien Nocera 2021-05-07 18:22:06 +02:00 committed by GStreamer Marge Bot
parent 522be6cf7c
commit c63365c80f
5 changed files with 82 additions and 2 deletions

View file

@ -7215,6 +7215,20 @@
"type": "GstFraction",
"writable": true
},
"video-aspect-ratio-override": {
"blurb": "The pixel aspect ratio of the video (0/1 = follow stream)",
"conditionally-available": false,
"construct": false,
"construct-only": false,
"controllable": false,
"default": "0/1",
"max": "2147483647/1",
"min": "0/2147483647",
"mutable": "null",
"readable": true,
"type": "GstFraction",
"writable": true
},
"widget": {
"blurb": "The GtkWidget to place in the widget hierarchy (must only be get from the GTK main thread)",
"conditionally-available": false,

View file

@ -37,6 +37,8 @@ GST_DEBUG_CATEGORY (gst_debug_gtk_base_sink);
#define DEFAULT_FORCE_ASPECT_RATIO TRUE
#define DEFAULT_DISPLAY_PAR_N 0
#define DEFAULT_DISPLAY_PAR_D 1
#define DEFAULT_VIDEO_PAR_N 0
#define DEFAULT_VIDEO_PAR_D 1
#define DEFAULT_IGNORE_ALPHA TRUE
static void gst_gtk_base_sink_finalize (GObject * object);
@ -68,6 +70,7 @@ enum
PROP_WIDGET,
PROP_FORCE_ASPECT_RATIO,
PROP_PIXEL_ASPECT_RATIO,
PROP_VIDEO_ASPECT_RATIO_OVERRIDE,
PROP_IGNORE_ALPHA,
};
@ -117,6 +120,21 @@ gst_gtk_base_sink_class_init (GstGtkBaseSinkClass * klass)
0, G_MAXINT, G_MAXINT, 1, DEFAULT_DISPLAY_PAR_N,
DEFAULT_DISPLAY_PAR_D, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstGtkBaseSink:video-aspect-ratio-override:
*
* The pixel aspect ratio of the video (0/1 = follow stream)
*
* Since: 1.20
*/
g_object_class_install_property (gobject_class,
PROP_VIDEO_ASPECT_RATIO_OVERRIDE,
gst_param_spec_fraction ("video-aspect-ratio-override",
"Video Pixel Aspect Ratio",
"The pixel aspect ratio of the video (0/1 = follow stream)", 0,
G_MAXINT, G_MAXINT, 1, DEFAULT_VIDEO_PAR_N, DEFAULT_VIDEO_PAR_D,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_IGNORE_ALPHA,
g_param_spec_boolean ("ignore-alpha", "Ignore Alpha",
"When enabled, alpha will be ignored and converted to black",
@ -141,6 +159,8 @@ gst_gtk_base_sink_init (GstGtkBaseSink * gtk_sink)
gtk_sink->force_aspect_ratio = DEFAULT_FORCE_ASPECT_RATIO;
gtk_sink->par_n = DEFAULT_DISPLAY_PAR_N;
gtk_sink->par_d = DEFAULT_DISPLAY_PAR_D;
gtk_sink->video_par_n = DEFAULT_VIDEO_PAR_N;
gtk_sink->video_par_d = DEFAULT_VIDEO_PAR_D;
gtk_sink->ignore_alpha = DEFAULT_IGNORE_ALPHA;
}
@ -200,6 +220,10 @@ gst_gtk_base_sink_get_widget (GstGtkBaseSink * gtk_sink)
gtk_sink->bind_pixel_aspect_ratio =
g_object_bind_property (gtk_sink, "pixel-aspect-ratio", gtk_sink->widget,
"pixel-aspect-ratio", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
gtk_sink->bind_video_aspect_ratio =
g_object_bind_property (gtk_sink, "video-aspect-ratio-override",
gtk_sink->widget, "video-aspect-ratio-override",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
gtk_sink->bind_ignore_alpha =
g_object_bind_property (gtk_sink, "ignore-alpha", gtk_sink->widget,
"ignore-alpha", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
@ -253,6 +277,10 @@ gst_gtk_base_sink_get_property (GObject * object, guint prop_id,
case PROP_PIXEL_ASPECT_RATIO:
gst_value_set_fraction (value, gtk_sink->par_n, gtk_sink->par_d);
break;
case PROP_VIDEO_ASPECT_RATIO_OVERRIDE:
gst_value_set_fraction (value, gtk_sink->video_par_n,
gtk_sink->video_par_d);
break;
case PROP_IGNORE_ALPHA:
g_value_set_boolean (value, gtk_sink->ignore_alpha);
break;
@ -276,6 +304,10 @@ gst_gtk_base_sink_set_property (GObject * object, guint prop_id,
gtk_sink->par_n = gst_value_get_fraction_numerator (value);
gtk_sink->par_d = gst_value_get_fraction_denominator (value);
break;
case PROP_VIDEO_ASPECT_RATIO_OVERRIDE:
gtk_sink->video_par_n = gst_value_get_fraction_numerator (value);
gtk_sink->video_par_d = gst_value_get_fraction_denominator (value);
break;
case PROP_IGNORE_ALPHA:
gtk_sink->ignore_alpha = g_value_get_boolean (value);
break;

View file

@ -65,6 +65,10 @@ struct _GstGtkBaseSink
gint par_d;
GBinding *bind_pixel_aspect_ratio;
gint video_par_n;
gint video_par_d;
GBinding *bind_video_aspect_ratio;
gboolean ignore_alpha;
GBinding *bind_ignore_alpha;

View file

@ -32,6 +32,8 @@ GST_DEBUG_CATEGORY (gst_debug_gtk_base_widget);
#define DEFAULT_FORCE_ASPECT_RATIO TRUE
#define DEFAULT_DISPLAY_PAR_N 0
#define DEFAULT_DISPLAY_PAR_D 1
#define DEFAULT_VIDEO_PAR_N 0
#define DEFAULT_VIDEO_PAR_D 1
#define DEFAULT_IGNORE_ALPHA TRUE
enum
@ -40,6 +42,7 @@ enum
PROP_FORCE_ASPECT_RATIO,
PROP_PIXEL_ASPECT_RATIO,
PROP_IGNORE_ALPHA,
PROP_VIDEO_ASPECT_RATIO_OVERRIDE,
};
static gboolean
@ -55,8 +58,14 @@ _calculate_par (GtkGstBaseWidget * widget, GstVideoInfo * info)
if (width == 0 || height == 0)
return FALSE;
par_n = GST_VIDEO_INFO_PAR_N (info);
par_d = GST_VIDEO_INFO_PAR_D (info);
/* get video's PAR */
if (widget->video_par_n != 0 && widget->video_par_d != 0) {
par_n = widget->video_par_n;
par_d = widget->video_par_d;
} else {
par_n = GST_VIDEO_INFO_PAR_N (info);
par_d = GST_VIDEO_INFO_PAR_D (info);
}
if (!par_n)
par_n = 1;
@ -214,6 +223,11 @@ gtk_gst_base_widget_set_property (GObject * object, guint prop_id,
gtk_widget->par_d = gst_value_get_fraction_denominator (value);
_update_par (gtk_widget);
break;
case PROP_VIDEO_ASPECT_RATIO_OVERRIDE:
gtk_widget->video_par_n = gst_value_get_fraction_numerator (value);
gtk_widget->video_par_d = gst_value_get_fraction_denominator (value);
_update_par (gtk_widget);
break;
case PROP_IGNORE_ALPHA:
gtk_widget->ignore_alpha = g_value_get_boolean (value);
break;
@ -236,6 +250,10 @@ gtk_gst_base_widget_get_property (GObject * object, guint prop_id,
case PROP_PIXEL_ASPECT_RATIO:
gst_value_set_fraction (value, gtk_widget->par_n, gtk_widget->par_d);
break;
case PROP_VIDEO_ASPECT_RATIO_OVERRIDE:
gst_value_set_fraction (value, gtk_widget->video_par_n,
gtk_widget->video_par_d);
break;
case PROP_IGNORE_ALPHA:
g_value_set_boolean (value, gtk_widget->ignore_alpha);
break;
@ -458,6 +476,15 @@ gtk_gst_base_widget_class_init (GtkGstBaseWidgetClass * klass)
DEFAULT_DISPLAY_PAR_D, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
GST_PARAM_MUTABLE_PLAYING));
g_object_class_install_property (gobject_klass,
PROP_VIDEO_ASPECT_RATIO_OVERRIDE,
gst_param_spec_fraction ("video-aspect-ratio-override",
"Video Pixel Aspect Ratio",
"The pixel aspect ratio of the video (0/1 = follow stream)", 0,
G_MAXINT, G_MAXINT, 1, DEFAULT_VIDEO_PAR_N, DEFAULT_VIDEO_PAR_D,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
GST_PARAM_MUTABLE_PLAYING));
g_object_class_install_property (gobject_klass, PROP_IGNORE_ALPHA,
g_param_spec_boolean ("ignore-alpha", "Ignore Alpha",
"When enabled, alpha will be ignored and converted to black",
@ -484,6 +511,8 @@ gtk_gst_base_widget_init (GtkGstBaseWidget * widget)
widget->force_aspect_ratio = DEFAULT_FORCE_ASPECT_RATIO;
widget->par_n = DEFAULT_DISPLAY_PAR_N;
widget->par_d = DEFAULT_DISPLAY_PAR_D;
widget->video_par_n = DEFAULT_VIDEO_PAR_N;
widget->video_par_d = DEFAULT_VIDEO_PAR_D;
widget->ignore_alpha = DEFAULT_IGNORE_ALPHA;
gst_video_info_init (&widget->v_info);

View file

@ -47,6 +47,7 @@ struct _GtkGstBaseWidget
/* properties */
gboolean force_aspect_ratio;
gint par_n, par_d;
gint video_par_n, video_par_d;
gboolean ignore_alpha;
gint display_width;