[perl-GStreamer-Interfaces] Add a GstXOverlay example



commit 1c75f86ccb55ee575ecc3e67e6362947db4df15b
Author: Emmanuel Rodriguez <emmanuel.rodriguez gmail com>
Date:   Sun Jul 12 21:26:54 2009 +0200

    Add a GstXOverlay example
    
    Signed-off-by: Torsten Schönfeld <kaffeetisch gmx de>

 MANIFEST                     |    1 +
 examples/gst-video-sample.pl |  107 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 108 insertions(+), 0 deletions(-)
---
diff --git a/MANIFEST b/MANIFEST
index b88b87d..594d9ae 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,5 +1,6 @@
 ChangeLog.pre-git
 copyright.pod
+examples/gst-video-sample.pl
 gstinterfacesperl.h
 Interfaces.pm
 LICENSE
diff --git a/examples/gst-video-sample.pl b/examples/gst-video-sample.pl
new file mode 100644
index 0000000..23a07c0
--- /dev/null
+++ b/examples/gst-video-sample.pl
@@ -0,0 +1,107 @@
+#!/usr/bin/perl
+
+=head1 NAME
+
+gst-video-sample.pl - Embed a video in a Gtk2 window
+
+=head1 SYNOPSIS
+
+perl gst-video-sample.pl
+
+=head1 DESCRIPTION
+
+This program shows how to embed a video in a Gtk2 window. The window is created
+by the program using Gtk2 and the video is decoded by Gstreamer. Both frameworks
+are linked together in order to create a minimalist video player.
+
+=head1 AUTHOR
+
+Vala code from http://live.gnome.org/Vala/GStreamerSample ported to Perl.
+
+=cut
+
+use strict;
+use warnings;
+
+use Glib qw(TRUE FALSE);
+use GStreamer '-init';
+use GStreamer::Interfaces;
+use Gtk2 '-init';
+
+exit main();
+
+
+sub main {
+	# Create the main pipeline and GUI elements
+	my ($pipeline, $sink) = create_pipeline();
+	my ($window, $canvas, $buttons) = create_widgets();
+
+
+	# Buttons used to control the playback
+	add_button($buttons, 'gtk-media-play', sub {
+		$sink->set_xwindow_id($canvas->window->get_xid);
+		$pipeline->set_state('playing');
+	});
+
+	add_button($buttons, 'gtk-media-stop', sub {
+		$pipeline->set_state('ready');
+	});
+
+
+	# Run the program
+	Gtk2->main();
+
+	# Cleanup
+	$pipeline->set_state('null');
+	return 0;
+}
+
+
+sub create_pipeline {
+	my $pipeline = GStreamer::Pipeline->new('pipeline');
+
+	# The pipeline's elements
+	my ($src, $sink) = GStreamer::ElementFactory->make(
+		videotestsrc => 'source',
+		xvimagesink  => 'sink',
+	);
+
+	$pipeline->add($src, $sink);
+	$src->link($sink);
+
+	return ($pipeline, $sink);
+}
+
+
+sub create_widgets {
+	# Create the widgets
+	my $window = Gtk2::Window->new();
+	$window->set_title("Gst video test");
+
+	# This is where the video will be displayed
+	my $canvas = Gtk2::DrawingArea->new();
+	$canvas->set_size_request(300, 150);
+
+	my $vbox = Gtk2::VBox->new(FALSE, 0);
+	$vbox->pack_start($canvas, TRUE, TRUE, 0);
+
+	# Prepare a box that will hold the playback controls
+	my $buttons = Gtk2::HButtonBox->new();
+	$vbox->pack_start($buttons, FALSE, TRUE, 0);
+
+	$window->add($vbox);
+
+	$window->signal_connect(destroy => sub {Gtk2->main_quit()});
+	$window->show_all();
+
+	return ($window, $canvas, $buttons);
+}
+
+
+sub add_button {
+	my ($box, $stock, $callback) = @_;
+	my $button = Gtk2::Button->new_from_stock($stock);
+	$button->signal_connect(clicked => $callback);
+	$box->add($button);
+	$button->show_all();
+}



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