2003-12-14 16:59:09 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2003 Julien Moutte <julien@moutte.net>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library 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.
|
|
|
|
*/
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-01-31 00:29:21 +00:00
|
|
|
#include <gst/play/play.h>
|
2003-12-14 16:59:09 +00:00
|
|
|
|
|
|
|
static GMainLoop *loop = NULL;
|
2003-12-14 17:31:07 +00:00
|
|
|
static gint64 length = 0;
|
2003-12-14 16:59:09 +00:00
|
|
|
|
2003-12-16 14:56:06 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
print_tag (const GstTagList * list, const gchar * tag, gpointer unused)
|
2003-12-16 14:56:06 +00:00
|
|
|
{
|
|
|
|
gint i, count;
|
|
|
|
|
|
|
|
count = gst_tag_list_get_tag_size (list, tag);
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
gchar *str;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-12-16 14:56:06 +00:00
|
|
|
if (gst_tag_get_type (tag) == G_TYPE_STRING) {
|
|
|
|
g_assert (gst_tag_list_get_string_index (list, tag, i, &str));
|
|
|
|
} else {
|
2004-03-14 22:34:33 +00:00
|
|
|
str =
|
|
|
|
g_strdup_value_contents (gst_tag_list_get_value_index (list, tag, i));
|
2003-12-16 14:56:06 +00:00
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-12-16 14:56:06 +00:00
|
|
|
if (i == 0) {
|
|
|
|
g_print ("%15s: %s\n", gst_tag_get_nick (tag), str);
|
|
|
|
} else {
|
|
|
|
g_print (" : %s\n", str);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
got_found_tag (GstPlay * play, GstElement * source, GstTagList * tag_list)
|
2003-12-16 14:56:06 +00:00
|
|
|
{
|
|
|
|
gst_tag_list_foreach (tag_list, print_tag, NULL);
|
|
|
|
}
|
|
|
|
|
2003-12-14 16:59:09 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
got_time_tick (GstPlay * play, gint64 time_nanos)
|
2003-12-14 16:59:09 +00:00
|
|
|
{
|
2004-03-01 15:53:04 +00:00
|
|
|
g_print ("time tick %f\n", time_nanos / (float) GST_SECOND);
|
2003-12-14 16:59:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
got_stream_length (GstPlay * play, gint64 length_nanos)
|
2003-12-14 16:59:09 +00:00
|
|
|
{
|
examples/gstplay/player.c: Adding some new lines in g_print calls.
Original commit message from CVS:
* examples/gstplay/player.c: (got_time_tick), (got_stream_length),
(got_video_size): Adding some new lines in g_print calls.
* sys/ximage/ximagesink.c: (gst_ximagesink_xwindow_new),
(gst_ximagesink_xwindow_destroy), (gst_ximagesink_xwindow_resize),
(gst_ximagesink_handle_xevents), (gst_ximagesink_fixate),
(gst_ximagesink_sinkconnect), (gst_ximagesink_change_state),
(gst_ximagesink_chain), (gst_ximagesink_buffer_new),
(gst_ximagesink_set_xwindow_id), (gst_ximagesink_get_desired_size):
Complete code review, reverting some stuff i disagree with, adding
some fixes : time synchronization on invalid timestamps, renegotiation
of private window.
* sys/ximage/ximagesink.h:
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_xwindow_destroy),
(gst_xvimagesink_xwindow_resize), (gst_xvimagesink_handle_xevents),
(gst_xvimagesink_get_xv_support), (gst_xvimagesink_xcontext_get),
(gst_xvimagesink_fixate), (gst_xvimagesink_sinkconnect),
(gst_xvimagesink_change_state), (gst_xvimagesink_chain),
(gst_xvimagesink_buffer_new),
(gst_xvimagesink_navigation_send_event),
(gst_xvimagesink_set_xwindow_id),
(gst_xvimagesink_get_desired_size),
(gst_xvimagesink_xoverlay_init): Complete code review, reverting some
stuff i disagree with, adding some fixes : Renegotiation of private
window, implementing get_desired_size.
2004-01-07 15:33:41 +00:00
|
|
|
g_print ("got length %llu\n", length_nanos);
|
2003-12-14 17:31:07 +00:00
|
|
|
length = length_nanos;
|
2003-12-14 16:59:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
got_video_size (GstPlay * play, gint width, gint height)
|
2003-12-14 16:59:09 +00:00
|
|
|
{
|
examples/gstplay/player.c: Adding some new lines in g_print calls.
Original commit message from CVS:
* examples/gstplay/player.c: (got_time_tick), (got_stream_length),
(got_video_size): Adding some new lines in g_print calls.
* sys/ximage/ximagesink.c: (gst_ximagesink_xwindow_new),
(gst_ximagesink_xwindow_destroy), (gst_ximagesink_xwindow_resize),
(gst_ximagesink_handle_xevents), (gst_ximagesink_fixate),
(gst_ximagesink_sinkconnect), (gst_ximagesink_change_state),
(gst_ximagesink_chain), (gst_ximagesink_buffer_new),
(gst_ximagesink_set_xwindow_id), (gst_ximagesink_get_desired_size):
Complete code review, reverting some stuff i disagree with, adding
some fixes : time synchronization on invalid timestamps, renegotiation
of private window.
* sys/ximage/ximagesink.h:
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_xwindow_destroy),
(gst_xvimagesink_xwindow_resize), (gst_xvimagesink_handle_xevents),
(gst_xvimagesink_get_xv_support), (gst_xvimagesink_xcontext_get),
(gst_xvimagesink_fixate), (gst_xvimagesink_sinkconnect),
(gst_xvimagesink_change_state), (gst_xvimagesink_chain),
(gst_xvimagesink_buffer_new),
(gst_xvimagesink_navigation_send_event),
(gst_xvimagesink_set_xwindow_id),
(gst_xvimagesink_get_desired_size),
(gst_xvimagesink_xoverlay_init): Complete code review, reverting some
stuff i disagree with, adding some fixes : Renegotiation of private
window, implementing get_desired_size.
2004-01-07 15:33:41 +00:00
|
|
|
g_print ("got video size %d, %d\n", width, height);
|
2003-12-14 16:59:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
got_eos (GstPlay * play)
|
2003-12-14 16:59:09 +00:00
|
|
|
{
|
2004-02-15 17:41:28 +00:00
|
|
|
g_print ("End Of Stream\n");
|
2003-12-14 16:59:09 +00:00
|
|
|
g_main_loop_quit (loop);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
seek_timer (GstPlay * play)
|
2003-12-14 16:59:09 +00:00
|
|
|
{
|
2003-12-14 17:31:07 +00:00
|
|
|
gst_play_seek_to_time (play, length / 2);
|
2003-12-14 16:59:09 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
idle_iterate (GstPlay * play)
|
2003-12-14 16:59:09 +00:00
|
|
|
{
|
|
|
|
gst_bin_iterate (GST_BIN (play));
|
|
|
|
return (GST_STATE (GST_ELEMENT (play)) == GST_STATE_PLAYING);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
GstPlay *play;
|
|
|
|
GstElement *data_src, *video_sink, *audio_sink, *vis_element;
|
2004-03-05 02:30:10 +00:00
|
|
|
GError *error = NULL;
|
2003-12-14 16:59:09 +00:00
|
|
|
|
|
|
|
/* Initing GStreamer library */
|
|
|
|
gst_init (&argc, &argv);
|
|
|
|
|
|
|
|
if (argc != 2) {
|
|
|
|
g_print ("usage: %s <video filename>\n", argv[0]);
|
|
|
|
exit (-1);
|
|
|
|
}
|
2003-12-19 14:39:03 +00:00
|
|
|
|
2003-12-14 16:59:09 +00:00
|
|
|
loop = g_main_loop_new (NULL, FALSE);
|
|
|
|
|
|
|
|
/* Creating the GstPlay object */
|
2004-01-31 15:56:32 +00:00
|
|
|
play = gst_play_new (&error);
|
2004-03-14 22:34:33 +00:00
|
|
|
if (error) {
|
2004-01-31 15:56:32 +00:00
|
|
|
g_print ("Error: could not create play object:\n%s\n", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
return 1;
|
|
|
|
}
|
2003-12-14 16:59:09 +00:00
|
|
|
|
|
|
|
/* Getting default audio and video plugins from GConf */
|
|
|
|
audio_sink = gst_element_factory_make ("osssink", "audio_sink");
|
2004-01-18 21:46:58 +00:00
|
|
|
video_sink = gst_element_factory_make ("ximagesink", "video_sink");
|
2003-12-14 16:59:09 +00:00
|
|
|
vis_element = gst_element_factory_make ("goom", "vis_element");
|
|
|
|
data_src = gst_element_factory_make ("gnomevfssrc", "source");
|
2003-12-19 14:39:03 +00:00
|
|
|
|
2003-12-14 16:59:09 +00:00
|
|
|
/* Let's send them to GstPlay object */
|
|
|
|
gst_play_set_audio_sink (play, audio_sink);
|
|
|
|
gst_play_set_video_sink (play, video_sink);
|
|
|
|
gst_play_set_data_src (play, data_src);
|
|
|
|
gst_play_set_visualization (play, vis_element);
|
2003-12-19 14:39:03 +00:00
|
|
|
|
2003-12-14 16:59:09 +00:00
|
|
|
/* Setting location we want to play */
|
|
|
|
gst_play_set_location (play, argv[1]);
|
|
|
|
|
2003-12-21 22:11:46 +00:00
|
|
|
/* Uncomment that line to get an XML dump of the pipeline */
|
2003-12-14 16:59:09 +00:00
|
|
|
/* gst_xml_write_file (GST_ELEMENT (play), stdout); */
|
2003-12-19 14:39:03 +00:00
|
|
|
|
2003-12-14 16:59:09 +00:00
|
|
|
g_signal_connect (G_OBJECT (play), "time_tick",
|
2004-03-14 22:34:33 +00:00
|
|
|
G_CALLBACK (got_time_tick), NULL);
|
2003-12-14 16:59:09 +00:00
|
|
|
g_signal_connect (G_OBJECT (play), "stream_length",
|
2004-03-14 22:34:33 +00:00
|
|
|
G_CALLBACK (got_stream_length), NULL);
|
2003-12-14 16:59:09 +00:00
|
|
|
g_signal_connect (G_OBJECT (play), "have_video_size",
|
2004-03-14 22:34:33 +00:00
|
|
|
G_CALLBACK (got_video_size), NULL);
|
2003-12-16 14:56:06 +00:00
|
|
|
g_signal_connect (G_OBJECT (play), "found_tag",
|
2004-03-14 22:34:33 +00:00
|
|
|
G_CALLBACK (got_found_tag), NULL);
|
2004-03-01 15:53:04 +00:00
|
|
|
g_signal_connect (G_OBJECT (play), "error",
|
2004-03-14 22:34:33 +00:00
|
|
|
G_CALLBACK (gst_element_default_error), NULL);
|
|
|
|
g_signal_connect (G_OBJECT (play), "eos", G_CALLBACK (got_eos), NULL);
|
2003-12-19 14:39:03 +00:00
|
|
|
|
2003-12-14 16:59:09 +00:00
|
|
|
/* Change state to PLAYING */
|
|
|
|
gst_element_set_state (GST_ELEMENT (play), GST_STATE_PLAYING);
|
|
|
|
|
|
|
|
g_idle_add ((GSourceFunc) idle_iterate, play);
|
|
|
|
g_timeout_add (20000, (GSourceFunc) seek_timer, play);
|
2003-12-19 14:39:03 +00:00
|
|
|
|
2003-12-14 16:59:09 +00:00
|
|
|
g_main_loop_run (loop);
|
|
|
|
|
2004-02-15 17:41:28 +00:00
|
|
|
g_print ("setting pipeline to ready\n");
|
|
|
|
|
2003-12-21 19:48:40 +00:00
|
|
|
gst_element_set_state (GST_ELEMENT (play), GST_STATE_READY);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-02-15 17:41:28 +00:00
|
|
|
/* unref
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_object_unref (GST_OBJECT (play)); */
|
2003-12-14 16:59:09 +00:00
|
|
|
|
|
|
|
exit (0);
|
|
|
|
}
|