Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
felipec committed Feb 23, 2008
0 parents commit 32c2265
Show file tree
Hide file tree
Showing 5 changed files with 333 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Makefile
@@ -0,0 +1,18 @@
CC=gcc

GST_LIBS=`pkg-config --libs gstreamer-0.10` -lgstinterfaces-0.10
GST_CFLAGS=`pkg-config --cflags gstreamer-0.10`
GTK_LIBS=`pkg-config --libs gtk+-2.0`
GTK_CFLAGS=`pkg-config --cflags gtk+-2.0`

CFLAGS=-ggdb

BINS=gst-player

all: $(BINS)

gst-player: ui.c gst-backend.c
$(CC) $(CFLAGS) $(GTK_CFLAGS) $(GTK_LIBS) $(GST_CFLAGS) $(GST_LIBS) $+ -o $@

clean:
rm -rf $(BINS)
11 changes: 11 additions & 0 deletions features.txt
@@ -0,0 +1,11 @@
0.0.1:
* play
* pause
* stop
* seek
* keyboard bindings
* full-screen

0.0.2:
* button images
* media player widget
118 changes: 118 additions & 0 deletions gst-backend.c
@@ -0,0 +1,118 @@
/*
* Copyright (C) 2008 Felipe Contreras.
*
* 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
*/

#include <gst/gst.h>
#include <gst/interfaces/xoverlay.h>

#include "gst-backend.h"

static GstElement *pipeline;
static GstElement *bin;
static GstElement *videosink;
static gpointer window;

static gboolean
bus_cb (GstBus *bus,
GstMessage *msg,
gpointer data)
{
switch (GST_MESSAGE_TYPE (msg))
{
case GST_MESSAGE_EOS:
{
g_debug ("end-of-stream");
break;
}
case GST_MESSAGE_ERROR:
{
gchar *debug;
GError *err;

gst_message_parse_error (msg, &err, &debug);
g_free (debug);

g_warning ("Error: %s", err->message);
g_error_free (err);
break;
}
default:
break;
}

return TRUE;
}

void
backend_init (int *argc,
char **argv[])
{
gst_init (argc, argv);
}

void
backend_set_window (gpointer window_)
{
window = window_;
}

void
backend_play (const char *uri)
{
backend_stop ();

pipeline = gst_pipeline_new ("gst-player");

bin = gst_element_factory_make ("playbin", "bin");
videosink = gst_element_factory_make ("ximagesink", "videosink");

g_object_set (G_OBJECT (bin), "video-sink", videosink, NULL);

gst_bin_add (GST_BIN (pipeline), bin);

{
GstBus *bus;
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_bus_add_watch (bus, bus_cb, NULL);
gst_object_unref (bus);
}

g_object_set (G_OBJECT (bin), "uri", uri, NULL);

if (GST_IS_X_OVERLAY (videosink))
{
gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (videosink), GPOINTER_TO_INT (window));
}

gst_element_set_state (pipeline, GST_STATE_PLAYING);
}

void
backend_stop (void)
{
if (pipeline)
{
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (GST_OBJECT (pipeline));
pipeline = NULL;
}
}

void
backend_deinit (void)
{
}
28 changes: 28 additions & 0 deletions gst-backend.h
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2008 Felipe Contreras.
*
* 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
*/

#ifndef GST_BACKEND_H
#define GST_BACKEND_H

void backend_init (int *argc, char **argv[]);
void backend_deinit (void);
void backend_set_window (gpointer window);
void backend_play (const char *uri);
void backend_stop (void);

#endif /* GST_BACKEND_H */
158 changes: 158 additions & 0 deletions ui.c
@@ -0,0 +1,158 @@
/*
* Copyright (C) 2008 Felipe Contreras.
*
* 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
*/

#include <gtk/gtk.h>
#include <gdk/gdkx.h>

#include <string.h>

static char *uri_to_play;
static GtkWidget *video_output;

static void
play_cb (GtkWidget *widget,
gpointer data)
{
/* backend_play (); */
}

static void
stop_cb (GtkWidget *widget,
gpointer data)
{
backend_stop ();
}

static gboolean
delete_event (GtkWidget *widget,
GdkEvent *event,
gpointer data)
{
return FALSE;
}

static void
destroy (GtkWidget *widget,
gpointer data)
{
gtk_main_quit ();
}

static void
start (void)
{
GtkWidget *window;
GtkWidget *button;
GtkWidget *hbox;
GtkWidget *vbox;

window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

g_signal_connect (G_OBJECT (window), "delete_event",
G_CALLBACK (delete_event), NULL);

g_signal_connect (G_OBJECT (window), "destroy",
G_CALLBACK (destroy), NULL);

gtk_container_set_border_width (GTK_CONTAINER (window), 2);

vbox = gtk_vbox_new (FALSE, 0);

gtk_container_add (GTK_CONTAINER (window), vbox);

gtk_widget_show (vbox);

hbox = gtk_hbox_new (FALSE, 0);

gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 2);

gtk_widget_show (hbox);

{
video_output = gtk_drawing_area_new ();

gtk_box_pack_start (GTK_BOX (vbox), video_output, TRUE, TRUE, 2);

gtk_widget_set_size_request (video_output, 128, 128);

gtk_widget_show (video_output);
}

{
button = gtk_button_new_with_label ("Play");

g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (play_cb), NULL);

gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 2);

gtk_widget_show (button);
}

{
button = gtk_button_new_with_label ("Stop");

g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (stop_cb), NULL);

gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 2);

gtk_widget_show (button);
}

gtk_widget_show (window);
}

static gboolean
init (gpointer data)
{
backend_set_window (GDK_WINDOW_XWINDOW (video_output->window));

if (uri_to_play)
backend_play (uri_to_play);

return FALSE;
}

int
main (int argc,
char *argv[])
{
gtk_init (&argc, &argv);
backend_init (&argc, &argv);

start ();

if (argc > 1)
{
if (strchr (argv[1], ':'))
uri_to_play = g_strdup (argv[1]);
else
uri_to_play = g_strdup_printf ("file://%s", argv[1]);
}

g_idle_add (init, NULL);

gtk_main ();

g_free (uri_to_play);

backend_deinit ();

return 0;
}

0 comments on commit 32c2265

Please sign in to comment.