[Xfce4-commits] [apps/parole] 02/02: Hacked together scaling and centering, be sure to clean up

noreply at xfce.org noreply at xfce.org
Tue Jun 17 07:12:32 CEST 2014


This is an automated email from the git hooks/post-receive script.

bluesabre pushed a commit to branch master
in repository apps/parole.

commit 76ef7e1bc5615aebf611c986ef5973aae92410de
Author: Sean Davis <smd.seandavis at gmail.com>
Date:   Tue Jun 17 01:12:26 2014 -0400

    Hacked together scaling and centering, be sure to clean up
---
 src/gst/parole-gst.c |   76 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/gst/parole-gst.h |    7 +++++
 src/parole-player.c  |   55 ++++++++++++++++++++++++++++++------
 3 files changed, 130 insertions(+), 8 deletions(-)

diff --git a/src/gst/parole-gst.c b/src/gst/parole-gst.c
index da30356..2f2300a 100644
--- a/src/gst/parole-gst.c
+++ b/src/gst/parole-gst.c
@@ -300,6 +300,82 @@ parole_gst_show (GtkWidget *widget)
         GTK_WIDGET_CLASS (parole_gst_parent_class)->show (widget);
 }
 
+void
+parole_gst_get_video_output_size_from_dimensions (ParoleGst *gst, gint w, gint h, gint *ret_w, gint *ret_h)
+{
+    *ret_w = w;
+    *ret_h = w;
+
+    if ( gst->priv->state >= GST_STATE_PAUSED )
+    {
+        gboolean has_video;
+        guint video_w, video_h;
+        guint video_par_n, video_par_d;
+        guint dar_n, dar_d;
+        guint disp_par_n, disp_par_d;
+
+        g_object_get (G_OBJECT (gst->priv->stream),
+                      "has-video", &has_video,
+                      "video-width", &video_w,
+                      "video-height", &video_h,
+                      "disp-par-n", &disp_par_n,
+                      "disp-par-d", &disp_par_d,
+                      NULL);
+
+        if ( has_video )
+        {
+            if ( video_w != 0 && video_h != 0 )
+            {
+                switch ( gst->priv->aspect_ratio )
+                {
+                    case PAROLE_ASPECT_RATIO_NONE:
+                        return;
+                    case PAROLE_ASPECT_RATIO_AUTO:
+                        *ret_w = video_w;
+                        *ret_h = video_h;
+                        return;
+                    case PAROLE_ASPECT_RATIO_SQUARE:
+                        video_par_n = 1;
+                        video_par_d = 1;
+                        break;
+                    case PAROLE_ASPECT_RATIO_16_9:
+                        video_par_n = 16 * video_h;
+                        video_par_d = 9 * video_w;
+                        break;
+                    case PAROLE_ASPECT_RATIO_4_3:
+                        video_par_n = 4 * video_h;
+                        video_par_d = 3 * video_w;
+                        break;
+                    case PAROLE_ASPECT_RATIO_DVB:
+                        video_par_n = 20 * video_h;
+                        video_par_d = 9 * video_w;
+                        break;
+                    default:
+                        return;
+                }
+
+                if ( gst_video_calculate_display_ratio (&dar_n, &dar_d,
+                                                        video_w, video_h,
+                                                        video_par_n, video_par_d,
+                                                        disp_par_n, disp_par_d) )
+                {
+                    if (video_w % dar_n == 0)
+                    {
+                        *ret_w = video_w;
+                        *ret_h = (guint) gst_util_uint64_scale (video_w, dar_d, dar_n);
+                    }
+                    else
+                    {
+                        *ret_w = (guint) gst_util_uint64_scale (video_h, dar_n, dar_d);
+                        *ret_h = video_h;
+                    }
+                    g_print ("Got best video size %dx%d fraction, %d/%d\n", *ret_w, *ret_h, disp_par_n, disp_par_d);
+                }
+            }
+        }
+    }
+}
+
 static void
 parole_gst_get_video_output_size (ParoleGst *gst, gint *ret_w, gint *ret_h)
 {
diff --git a/src/gst/parole-gst.h b/src/gst/parole-gst.h
index 75a7605..f70efe9 100644
--- a/src/gst/parole-gst.h
+++ b/src/gst/parole-gst.h
@@ -178,6 +178,13 @@ void        gst_set_current_audio_track     (ParoleGst *gst,
 void        gst_set_current_subtitle_track  (ParoleGst *gst,
                                              gint track_no);
 
+void
+parole_gst_get_video_output_size_from_dimensions (ParoleGst *gst,
+                                                  gint w,
+                                                  gint h,
+                                                  gint *ret_w,
+                                                  gint *ret_h);
+
 const ParoleStream
 *parole_gst_get_stream                      (ParoleGst *gst);
 
diff --git a/src/parole-player.c b/src/parole-player.c
index e8d201b..1e42918 100644
--- a/src/parole-player.c
+++ b/src/parole-player.c
@@ -437,6 +437,9 @@ struct ParolePlayerPrivate
     gboolean            buffering;
     gboolean            wait_for_gst_disc_info;
 
+    ClutterActor       *stage;
+    ClutterActor       *texture;
+
     /* Actions */
     GSimpleAction      *media_next_action;
     GSimpleAction      *media_playpause_action;
@@ -2921,6 +2924,11 @@ gboolean
 parole_player_configure_event_cb (GtkWidget *widget, GdkEventConfigure *ev, ParolePlayer *player)
 {
     gint old_w, old_h, new_w, new_h;
+    gfloat clutter_width, clutter_height, x, y;
+    GtkAllocation *alloc = g_new(GtkAllocation, 1);
+
+    /* Get the current window size */
+    gtk_window_get_size (GTK_WINDOW (widget), &new_w, &new_h);
 
     if ( !player->priv->full_screen )
     {
@@ -2930,9 +2938,6 @@ parole_player_configure_event_cb (GtkWidget *widget, GdkEventConfigure *ev, Paro
                       "window-height", &old_h,
                       NULL);
 
-        /* Get the current window size */
-        gtk_window_get_size (GTK_WINDOW (widget), &new_w, &new_h);
-
         /* Configure gets run twice, only change on update */
         if (old_w != new_w || old_h != new_h)
         {
@@ -2945,6 +2950,32 @@ parole_player_configure_event_cb (GtkWidget *widget, GdkEventConfigure *ev, Paro
         }
     }
 
+    gtk_widget_get_allocation(player->priv->videobox, alloc);
+    clutter_actor_set_size (player->priv->stage, alloc->width, alloc->height);
+
+    parole_gst_get_video_output_size_from_dimensions (PAROLE_GST(player->priv->gst), alloc->width, alloc->height, &new_w, &new_h);
+
+    x = 0.0;
+    y = 0.0;
+
+    if ( ((gdouble)alloc->width / (gdouble)new_w) * (gdouble)new_h <= (gdouble)alloc->height )
+    {
+        clutter_height = ((gdouble)alloc->width / (gdouble)new_w) * (gdouble)new_h;
+        clutter_width = alloc->width;
+        y = (alloc->height - clutter_height) / 2.0;
+    }
+
+    else
+    {
+        clutter_width = (((gdouble)alloc->height / (gdouble)new_h) * (gdouble)new_w);
+        clutter_height = alloc->height;
+        x = (alloc->width - clutter_width) / 2.0;
+    }
+
+    clutter_actor_set_size (player->priv->texture, clutter_width, clutter_height);
+    clutter_actor_set_x(player->priv->texture, x);
+    clutter_actor_set_y(player->priv->texture, y);
+
     return FALSE;
 }
 
@@ -3542,19 +3573,27 @@ parole_player_init (ParolePlayer *player)
     if (g_strcmp0(videosink, "cluttersink") == 0)
     {
         GtkWidget *clutterbox;
-        ClutterActor *stage, *texture;
         GstElement *video_sink;
+        ClutterColor *color = clutter_color_new(0,0,0,255);
+        GValue value = {0};
+        g_value_init(&value, G_TYPE_BOOLEAN);
+        g_value_set_boolean(&value, TRUE);
 
         clutterbox = gtk_clutter_embed_new();
         gtk_box_pack_start (GTK_BOX (player->priv->videobox),
                                      clutterbox,
                                      TRUE, TRUE, 0);
-        stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (clutterbox));
-        texture = CLUTTER_ACTOR (g_object_new (CLUTTER_TYPE_TEXTURE, "disable-slicing", TRUE, NULL));
+        player->priv->stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (clutterbox));
+        clutter_actor_set_background_color(player->priv->stage, color);
+        player->priv->texture = CLUTTER_ACTOR (g_object_new (CLUTTER_TYPE_TEXTURE, "disable-slicing", TRUE, NULL));
+        clutter_actor_set_x_align(player->priv->texture, CLUTTER_ACTOR_ALIGN_CENTER);
+        clutter_actor_set_y_align(player->priv->texture, CLUTTER_ACTOR_ALIGN_CENTER);
+        g_object_set_property (G_OBJECT(player->priv->texture), "keep-aspect-ratio", &value);
         video_sink = parole_gst_video_sink (PAROLE_GST(player->priv->gst));
-        g_object_set (video_sink, "texture", texture, NULL);
-        clutter_actor_add_child (stage, texture);
+        g_object_set (video_sink, "texture", player->priv->texture, NULL);
+        clutter_actor_add_child (player->priv->stage, player->priv->texture);
         gtk_widget_show (clutterbox);
+        g_object_set_property (G_OBJECT(player->priv->texture), "keep-aspect-ratio", &value);
     }
     else
     {

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list