[gnome-getting-started-docs] Add a simple video player
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-getting-started-docs] Add a simple video player
- Date: Sat, 3 Nov 2012 05:21:39 +0000 (UTC)
commit b4e6cab7a6e47495b289a709f0b634ed70cf9a04
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Fri Nov 2 13:02:05 2012 -0400
Add a simple video player
.gitignore | 11 ++++
Makefile.am | 2 +-
configure.in | 9 +++-
player/Makefile.am | 6 ++
player/player.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 178 insertions(+), 2 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index cbcb5bc..7205597 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,11 @@
*~
*.mo
*.stamp
+.deps
+.libs
+*.la
+*.lo
+*.o
Makefile
Makefile.in
/INSTALL
@@ -8,10 +13,16 @@ Makefile.in
/autom4te.cache/
/config.log
/config.status
+/config.h
+/config.h.in
/configure
+/compile
+/depcomp
+/stamp-h1
/install-sh
/missing
/gnome-doc-utils.make
/getting-started/??/*.page
/getting-started/??/legal.xml
/getting-started/??/animation.xml
+/player/player
diff --git a/Makefile.am b/Makefile.am
index db09367..c4c6cd4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1 +1 @@
-SUBDIRS = getting-started
+SUBDIRS = getting-started player
diff --git a/configure.in b/configure.in
index bdc01f7..f6f7826 100644
--- a/configure.in
+++ b/configure.in
@@ -2,12 +2,19 @@ AC_INIT([gnome-getting-started-docs], [3.6.2],
[http://bugzilla.gnome.org/enter_bug.cgi?product=gnome-getting-started-docs])
AM_INIT_AUTOMAKE
AM_SILENT_RULES([yes])
+AC_PROG_CC
YELP_HELP_INIT
AM_MAINTAINER_MODE([enable])
-AC_OUTPUT([
+PKG_CHECK_MODULES(PLAYER, [clutter-gst-1.0 clutter-x11-1.0])
+AC_SUBST(CFLAGS)
+
+AM_CONFIG_HEADER(config.h)
+AC_CONFIG_FILES([
Makefile
getting-started/Makefile
+player/Makefile
])
+AC_OUTPUT
diff --git a/player/Makefile.am b/player/Makefile.am
new file mode 100644
index 0000000..4593440
--- /dev/null
+++ b/player/Makefile.am
@@ -0,0 +1,6 @@
+
+noinst_PROGRAMS = player
+
+player_SOURCES = player.c
+player_CFLAGS = $(PLAYER_CFLAGS)
+player_LDFLAGS = $(PLAYER_LIBS)
diff --git a/player/player.c b/player/player.c
new file mode 100644
index 0000000..fe1d761
--- /dev/null
+++ b/player/player.c
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2012 Red Hat
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Written by:
+ * Jasper St. Pierre <jstpierre mecheye net>
+ *
+ * Based on examples/video-player.c in clutter-gst sources
+ * Copyright 2007,2008 OpenedHand
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+
+#include <clutter/clutter.h>
+#include <clutter/x11/clutter-x11.h>
+#include <clutter-gst/clutter-gst.h>
+
+#define FADE_OUT_TIME 500
+#define BG_COLOR "#d3d8ce"
+static ClutterColor bg_color;
+
+static ClutterActor *stage;
+
+static void
+fade_out (ClutterActor *actor)
+{
+ clutter_actor_save_easing_state (actor);
+ clutter_actor_set_easing_duration (actor, FADE_OUT_TIME);
+ clutter_actor_set_opacity (actor, 0);
+ clutter_actor_restore_easing_state (actor);
+}
+
+static void
+fade_out_and_quit (void)
+{
+ fade_out (stage);
+ g_signal_connect (stage, "transitions-completed",
+ G_CALLBACK (clutter_main_quit), NULL);
+}
+
+static void
+on_video_texture_eos (ClutterMedia *media)
+{
+ fade_out_and_quit ();
+}
+
+static gboolean
+key_press_cb (ClutterActor *stage,
+ ClutterEvent *event)
+{
+ switch (clutter_event_get_key_symbol ( (event)))
+ {
+ case CLUTTER_Escape:
+ clutter_actor_destroy (stage);
+ break;
+ }
+
+ return TRUE;
+}
+
+/* XXX: not sure how to keep the frame data on screen during
+ * fade out, so just have a solid idle material for now. */
+static void
+set_idle_material (ClutterGstVideoTexture *video_texture)
+{
+ CoglColor transparent;
+ CoglHandle material;
+
+ cogl_color_init_from_4ub (&transparent, 0, 0, 0, 0);
+ material = cogl_material_new ();
+ cogl_material_set_color (material, &transparent);
+ clutter_gst_video_texture_set_idle_material (video_texture, material);
+ cogl_handle_unref (material);
+}
+
+int
+main (int argc, char *argv[])
+{
+ ClutterActor *video;
+
+ /* So we can fade out at the end. */
+ clutter_x11_set_use_argb_visual (TRUE);
+
+ if (clutter_gst_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
+ return EXIT_FAILURE;
+
+ if (argc < 2)
+ {
+ g_print ("Usage: %s [OPTIONS] <video file>\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ if (!clutter_color_from_string (&bg_color, BG_COLOR))
+ {
+ g_warning ("Invalid BG_COLOR");
+ exit (1);
+ }
+
+ stage = clutter_stage_new ();
+ clutter_stage_set_fullscreen (CLUTTER_STAGE (stage), TRUE);
+ clutter_stage_set_use_alpha (CLUTTER_STAGE (stage), TRUE);
+ clutter_actor_set_background_color (stage, &bg_color);
+ clutter_actor_set_layout_manager (stage,
+ clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_FIXED,
+ CLUTTER_BIN_ALIGNMENT_FIXED));
+
+ video = clutter_gst_video_texture_new ();
+ clutter_actor_set_x_expand (video, TRUE);
+ clutter_actor_set_y_expand (video, TRUE);
+ clutter_actor_set_x_align (video, CLUTTER_ACTOR_ALIGN_CENTER);
+ clutter_actor_set_y_align (video, CLUTTER_ACTOR_ALIGN_CENTER);
+ set_idle_material (CLUTTER_GST_VIDEO_TEXTURE (video));
+
+ g_signal_connect (video,
+ "eos",
+ G_CALLBACK (on_video_texture_eos),
+ NULL);
+
+ g_signal_connect (stage,
+ "destroy",
+ G_CALLBACK (clutter_main_quit),
+ NULL);
+
+ clutter_media_set_filename (CLUTTER_MEDIA (video), argv[1]);
+ clutter_stage_hide_cursor (CLUTTER_STAGE (stage));
+
+ clutter_actor_add_child (stage, video);
+
+ g_signal_connect (stage, "key-press-event", G_CALLBACK (key_press_cb), NULL);
+
+ clutter_media_set_playing (CLUTTER_MEDIA (video), TRUE);
+ clutter_actor_show (stage);
+ clutter_main ();
+
+ return EXIT_SUCCESS;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]