[clutter-gst] players: listen to pixel-aspect-ratio changes



commit 721b4df25cc8df86c26cc4d3f501ee0a34c03800
Author: Lionel Landwerlin <llandwerlin gmail com>
Date:   Thu Mar 14 15:08:37 2013 +0000

    players: listen to pixel-aspect-ratio changes

 clutter-gst/clutter-gst-aspectratio.c |   43 +++++++++++++++++++++++---------
 clutter-gst/clutter-gst-aspectratio.h |   28 ++++++++++++++++++++-
 clutter-gst/clutter-gst-playback.c    |   17 ++++++++++---
 clutter-gst/clutter-gst-player.c      |   26 +++++++++++++++++--
 clutter-gst/clutter-gst-private.h     |   12 +++++++--
 5 files changed, 103 insertions(+), 23 deletions(-)
---
diff --git a/clutter-gst/clutter-gst-aspectratio.c b/clutter-gst/clutter-gst-aspectratio.c
index 3dd1e47..b9daf36 100644
--- a/clutter-gst/clutter-gst-aspectratio.c
+++ b/clutter-gst/clutter-gst-aspectratio.c
@@ -1,4 +1,30 @@
-/* clutter-gst-aspectratio.c */
+/*
+ * Clutter-GStreamer.
+ *
+ * GStreamer integration library for Clutter.
+ *
+ * clutter-gst-aspectratio.c - An actor rendering a video with respect
+ * to its aspect ratio.
+ *
+ * Authored by Lionel Landwerlin <lionel g landwerlin linux intel com>
+ *
+ * Copyright (C) 2013 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
 
 #include "clutter-gst-aspectratio.h"
 
@@ -94,8 +120,6 @@ _recompute_paint_box (ClutterGstAspectratio *self)
   actor_width = box.x2 - box.x1;
   actor_height = box.y2 - box.y1;
 
-  g_message ("alloc=(%fx%f)", actor_width, actor_height);
-
   if (actor_width <= 0 || actor_height <= 0)
     return;
 
@@ -117,10 +141,6 @@ _recompute_paint_box (ClutterGstAspectratio *self)
   priv->paint_box.y1 = (actor_height - new_height) / 2;
   priv->paint_box.x2 = priv->paint_box.x1 + new_width;
   priv->paint_box.y2 = priv->paint_box.y1 + new_height;
-
-  g_message ("output=(%fx%f) box=(%fx%f-%fx%f)", new_width, new_height,
-             priv->paint_box.x1, priv->paint_box.y1,
-             priv->paint_box.x2, priv->paint_box.y2);
 }
 
 static void
@@ -139,9 +159,9 @@ _player_size_changed (ClutterGstPlayer      *player,
 }
 
 static void
-clutter_gst_aspectratio_player_changed (ClutterGstAspectratio *self,
-                                        GParamSpec            *spec,
-                                        gpointer               user_data)
+_player_changed (ClutterGstAspectratio *self,
+                 GParamSpec            *spec,
+                 gpointer               user_data)
 {
   ClutterGstAspectratioPrivate *priv = self->priv;
   ClutterGstPlayer *player = clutter_gst_actor_get_player (CLUTTER_GST_ACTOR (self));
@@ -163,7 +183,6 @@ clutter_gst_aspectratio_player_changed (ClutterGstAspectratio *self,
   _recompute_paint_box (self);
 }
 
-
 /**/
 
 static void
@@ -230,7 +249,7 @@ clutter_gst_aspectratio_init (ClutterGstAspectratio *self)
   self->priv = ASPECTRATIO_PRIVATE (self);
 
   g_signal_connect (self, "notify::player",
-                    G_CALLBACK (clutter_gst_aspectratio_player_changed), NULL);
+                    G_CALLBACK (_player_changed), NULL);
   g_signal_connect_swapped (self, "allocation-changed",
                             G_CALLBACK (_recompute_paint_box), self);
 }
diff --git a/clutter-gst/clutter-gst-aspectratio.h b/clutter-gst/clutter-gst-aspectratio.h
index 4f74b51..0419e96 100644
--- a/clutter-gst/clutter-gst-aspectratio.h
+++ b/clutter-gst/clutter-gst-aspectratio.h
@@ -1,4 +1,30 @@
-/* clutter-gst-aspectratio.h */
+/*
+ * Clutter-GStreamer.
+ *
+ * GStreamer integration library for Clutter.
+ *
+ * clutter-gst-aspectratio.c - An actor rendering a video with respect
+ * to its aspect ratio.
+ *
+ * Authored by Lionel Landwerlin <lionel g landwerlin linux intel com>
+ *
+ * Copyright (C) 2013 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
 
 #ifndef __CLUTTER_GST_ASPECTRATIO_H__
 #define __CLUTTER_GST_ASPECTRATIO_H__
diff --git a/clutter-gst/clutter-gst-playback.c b/clutter-gst/clutter-gst-playback.c
index e517aac..1b00615 100644
--- a/clutter-gst/clutter-gst-playback.c
+++ b/clutter-gst/clutter-gst-playback.c
@@ -1889,9 +1889,9 @@ _new_frame_from_pipeline (CoglGstVideoSink *sink, ClutterGstPlayback *self)
 {
   ClutterGstPlaybackPrivate *priv = self->priv;
 
-  clutter_gst_util_update_frame (CLUTTER_GST_PLAYER (self),
-                                 &priv->current_frame,
-                                 cogl_gst_video_sink_get_pipeline (sink));
+  clutter_gst_player_update_frame (CLUTTER_GST_PLAYER (self),
+                                   &priv->current_frame,
+                                   cogl_gst_video_sink_get_pipeline (sink));
 }
 
 static void
@@ -1900,6 +1900,14 @@ _ready_from_pipeline (CoglGstVideoSink *sink, ClutterGstPlayback *self)
   g_signal_emit_by_name (self, "ready");
 }
 
+static void
+_pixel_aspect_ratio_changed (CoglGstVideoSink   *sink,
+                             GParamSpec         *spec,
+                             ClutterGstPlayback *self)
+{
+  clutter_gst_frame_update_pixel_aspect_ratio (self->priv->current_frame, sink);
+}
+
 static GstElement *
 get_pipeline (ClutterGstPlayback *self)
 {
@@ -1930,12 +1938,13 @@ get_pipeline (ClutterGstPlayback *self)
     }
 
   video_sink = cogl_gst_video_sink_new (clutter_gst_get_cogl_context ());
-  /* gst_element_factory_make ("coglsink", "video-sink"); */
 
   g_signal_connect (video_sink, "new-frame",
                     G_CALLBACK (_new_frame_from_pipeline), self);
   g_signal_connect (video_sink, "pipeline-ready",
                     G_CALLBACK (_ready_from_pipeline), self);
+  g_signal_connect (video_sink, "notify::pixel-aspect-ratio",
+                    G_CALLBACK (_pixel_aspect_ratio_changed), self);
 
   g_object_set (G_OBJECT (pipeline),
                 "audio-sink", audio_sink,
diff --git a/clutter-gst/clutter-gst-player.c b/clutter-gst/clutter-gst-player.c
index 80e6fc3..0eaa952 100644
--- a/clutter-gst/clutter-gst-player.c
+++ b/clutter-gst/clutter-gst-player.c
@@ -363,15 +363,18 @@ clutter_gst_player_get_idle (ClutterGstPlayer *self)
 /* Internal functions */
 
 void
-clutter_gst_util_update_frame (ClutterGstPlayer *player,
-                               ClutterGstFrame **frame,
-                               CoglPipeline     *pipeline)
+clutter_gst_player_update_frame (ClutterGstPlayer *player,
+                                 ClutterGstFrame **frame,
+                                 CoglPipeline     *pipeline)
 {
   ClutterGstFrame *old_frame = *frame;
   ClutterGstFrame *new_frame = clutter_gst_frame_new (pipeline);
 
   *frame = new_frame;
 
+  new_frame->resolution.par_n = old_frame->resolution.par_n;
+  new_frame->resolution.par_d = old_frame->resolution.par_d;
+
   if (old_frame == NULL ||
       new_frame->resolution.width != old_frame->resolution.width ||
       new_frame->resolution.height != old_frame->resolution.height)
@@ -386,3 +389,20 @@ clutter_gst_util_update_frame (ClutterGstPlayer *player,
 
   g_signal_emit_by_name (player, "new-frame", new_frame);
 }
+
+void
+clutter_gst_frame_update_pixel_aspect_ratio (ClutterGstFrame  *frame,
+                                             CoglGstVideoSink *sink)
+{
+  GValue value = G_VALUE_INIT;
+
+  g_value_init (&value, GST_TYPE_FRACTION);
+  g_object_get_property (G_OBJECT (sink),
+                         "pixel-aspect-ratio",
+                         &value);
+
+  frame->resolution.par_n = gst_value_get_fraction_numerator (&value);
+  frame->resolution.par_d = gst_value_get_fraction_denominator (&value);
+
+  g_value_unset (&value);
+}
diff --git a/clutter-gst/clutter-gst-private.h b/clutter-gst/clutter-gst-private.h
index c245e0a..9fa9939 100644
--- a/clutter-gst/clutter-gst-private.h
+++ b/clutter-gst/clutter-gst-private.h
@@ -29,6 +29,8 @@
 #include <glib.h>
 #include "clutter-gst.h"
 
+#include <cogl-gst/cogl-gst.h>
+
 G_BEGIN_DECLS
 
 /* GLib has some define for that, but defining it ourselves allows to require a
@@ -55,9 +57,13 @@ ClutterGstFrame *clutter_gst_frame_new (CoglPipeline *pipeline);
 
 ClutterGstFrame *clutter_gst_create_blank_frame (const ClutterColor *color);
 
-void clutter_gst_util_update_frame (ClutterGstPlayer *player,
-                                    ClutterGstFrame **frame,
-                                    CoglPipeline     *pipeline);
+void clutter_gst_player_update_frame (ClutterGstPlayer *player,
+                                      ClutterGstFrame **frame,
+                                      CoglPipeline     *pipeline);
+
+void clutter_gst_frame_update_pixel_aspect_ratio (ClutterGstFrame  *frame,
+                                                  CoglGstVideoSink *sink);
+
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]