summaryrefslogtreecommitdiff
path: root/cogl-gst
diff options
context:
space:
mode:
authorRobert Bragg <robert@linux.intel.com>2013-04-26 00:57:06 +0100
committerLionel Landwerlin <llandwerlin@gmail.com>2013-06-21 19:06:59 +0100
commit5faed43f291f5fb64bb3ec8d6042609cf9f18cb4 (patch)
tree7b41b428f14d296ea0472cb0fe458da62cd2d52b /cogl-gst
parentee559d4e930573a50cbd704ec2a8d20316e1b2aa (diff)
downloadcogl-5faed43f291f5fb64bb3ec8d6042609cf9f18cb4.tar.gz
cogl-gst: expose aspect ratio apis
This adds several utility apis that aim to make it as easy as possible for an application to determine what size a video should be drawn at. The important detail here is that these apis take into account the pixel-aspect-ratio in addition to the video's own aspect ratio. This patch updates the cogl-basic-video-player example to use the cogl_gst_video_sink_fit_size() api to perform letterboxing. Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit d26f17c97ff6b9f6d6211e0527d5965a85305a56)
Diffstat (limited to 'cogl-gst')
-rw-r--r--cogl-gst/cogl-gst-video-sink.c57
-rw-r--r--cogl-gst/cogl-gst-video-sink.h92
2 files changed, 149 insertions, 0 deletions
diff --git a/cogl-gst/cogl-gst-video-sink.c b/cogl-gst/cogl-gst-video-sink.c
index 42d44b77..b4dada51 100644
--- a/cogl-gst/cogl-gst-video-sink.c
+++ b/cogl-gst/cogl-gst-video-sink.c
@@ -1268,3 +1268,60 @@ cogl_gst_video_sink_new (CoglContext *ctx)
return sink;
}
+
+float
+cogl_gst_video_sink_get_aspect (CoglGstVideoSink *vt)
+{
+ GstVideoInfo *info = &vt->priv->info;
+ return ((float)info->width * (float)info->par_n) /
+ ((float)info->height * (float)info->par_d);
+}
+
+float
+cogl_gst_video_sink_get_width_for_height (CoglGstVideoSink *vt,
+ float height)
+{
+ float aspect = cogl_gst_video_sink_get_aspect (vt);
+ return height * aspect;
+}
+
+float
+cogl_gst_video_sink_get_height_for_width (CoglGstVideoSink *vt,
+ float width)
+{
+ float aspect = cogl_gst_video_sink_get_aspect (vt);
+ return width / aspect;
+}
+
+void
+cogl_gst_video_sink_fit_size (CoglGstVideoSink *vt,
+ const CoglGstRectangle *available,
+ CoglGstRectangle *output)
+{
+ if (available->height == 0.0f)
+ {
+ output->x = available->x;
+ output->y = available->y;
+ output->width = output->height = 0;
+ }
+ else
+ {
+ float available_aspect = available->width / available->height;
+ float video_aspect = cogl_gst_video_sink_get_aspect (vt);
+
+ if (video_aspect > available_aspect)
+ {
+ output->width = available->width;
+ output->height = available->width / video_aspect;
+ output->x = available->x;
+ output->y = available->y + (available->height - output->height) / 2;
+ }
+ else
+ {
+ output->width = available->height * video_aspect;
+ output->height = available->height;
+ output->x = available->x + (available->width - output->width) / 2;
+ output->y = available->y;
+ }
+ }
+}
diff --git a/cogl-gst/cogl-gst-video-sink.h b/cogl-gst/cogl-gst-video-sink.h
index a9694a65..45ed8355 100644
--- a/cogl-gst/cogl-gst-video-sink.h
+++ b/cogl-gst/cogl-gst-video-sink.h
@@ -330,6 +330,98 @@ void
cogl_gst_video_sink_setup_pipeline (CoglGstVideoSink *sink,
CoglPipeline *pipeline);
+/**
+ * cogl_gst_video_sink_get_aspect:
+ * @sink: A #CoglGstVideoSink
+ *
+ * Returns a width-for-height aspect ratio that lets you calculate a
+ * suitable width for displaying your video based on a given height by
+ * multiplying your chosen height by the returned aspect ratio.
+ *
+ * This aspect ratio is calculated based on the underlying size of the
+ * video buffers and the current pixel-aspect-ratio.
+ *
+ * Return value: a width-for-height aspect ratio
+ *
+ * Since: 1.16
+ * Stability: unstable
+ */
+float
+cogl_gst_video_sink_get_aspect (CoglGstVideoSink *sink);
+
+/**
+ * cogl_gst_video_sink_get_width_for_height:
+ * @sink: A #CoglGstVideoSink
+ * @height: A specific output @height
+ *
+ * Calculates a suitable output width for a specific output @height
+ * that will maintain the video's aspect ratio.
+ *
+ * Return value: An output width for the given output @height.
+ *
+ * Since: 1.16
+ * Stability: unstable
+ */
+float
+cogl_gst_video_sink_get_width_for_height (CoglGstVideoSink *sink,
+ float height);
+
+/**
+ * cogl_gst_video_sink_get_height_for_width:
+ * @sink: A #CoglGstVideoSink
+ * @width: A specific output @width
+ *
+ * Calculates a suitable output height for a specific output @width
+ * that will maintain the video's aspect ratio.
+ *
+ * Return value: An output height for the given output @width.
+ *
+ * Since: 1.16
+ * Stability: unstable
+ */
+float
+cogl_gst_video_sink_get_height_for_width (CoglGstVideoSink *sink,
+ float width);
+
+/**
+ * CoglGstRectangle:
+ * @x: The X coordinate of the top left of the rectangle
+ * @y: The Y coordinate of the top left of the rectangle
+ * @width: The width of the rectangle
+ * @height: The height of the rectangle
+ *
+ * Describes a rectangle that can be used for video output.
+ */
+typedef struct _CoglGstRectangle
+{
+ float x;
+ float y;
+ float width;
+ float height;
+} CoglGstRectangle;
+
+/**
+ * cogl_gst_video_sink_fit_size:
+ * @sink: A #CoglGstVideoSink
+ * @available: The space available for video output
+ * @output: The return location for the calculated output position
+ *
+ * Calculates a suitable @output rectangle that can fit inside the
+ * @available space while maintaining the aspect ratio of the current
+ * video.
+ *
+ * Applications would typically use this api for "letterboxing" by
+ * using this api to position a video inside a fixed screen space and
+ * filling the remaining space with black borders.
+ *
+ * Since: 1.16
+ * Stability: unstable
+ */
+void
+cogl_gst_video_sink_fit_size (CoglGstVideoSink *sink,
+ const CoglGstRectangle *available,
+ CoglGstRectangle *output);
+
G_END_DECLS
#endif