mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 18:21:04 +00:00
Some cleanups, add modplug seeking example.
Original commit message from CVS: Some cleanups, add modplug seeking example.
This commit is contained in:
parent
e964be4d97
commit
9f08fd8e6a
2 changed files with 172 additions and 105 deletions
|
@ -8,8 +8,9 @@ static GList *rate_pads = NULL;
|
||||||
static GList *seekable_elements = NULL;
|
static GList *seekable_elements = NULL;
|
||||||
|
|
||||||
static GstElement *pipeline;
|
static GstElement *pipeline;
|
||||||
static guint64 duration, position;
|
static guint64 duration;
|
||||||
static GtkAdjustment *adjustment;
|
static GtkAdjustment *adjustment;
|
||||||
|
static gboolean stats = FALSE;
|
||||||
|
|
||||||
static guint update_id;
|
static guint update_id;
|
||||||
|
|
||||||
|
@ -57,6 +58,37 @@ setup_dynamic_connection (GstElement *element, const gchar *padname, GstPad *tar
|
||||||
g_signal_connect (G_OBJECT (element), "new_pad", G_CALLBACK (dynamic_connect), connect);
|
g_signal_connect (G_OBJECT (element), "new_pad", G_CALLBACK (dynamic_connect), connect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GstElement*
|
||||||
|
make_mod_pipeline (const gchar *location)
|
||||||
|
{
|
||||||
|
GstElement *pipeline;
|
||||||
|
GstElement *src, *decoder, *audiosink;
|
||||||
|
GstPad *seekable;
|
||||||
|
|
||||||
|
pipeline = gst_pipeline_new ("app");
|
||||||
|
|
||||||
|
src = gst_element_factory_make (SOURCE, "src");
|
||||||
|
decoder = gst_element_factory_make ("modplug", "decoder");
|
||||||
|
audiosink = gst_element_factory_make ("osssink", "sink");
|
||||||
|
//g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
|
||||||
|
|
||||||
|
g_object_set (G_OBJECT (src), "location", location, NULL);
|
||||||
|
|
||||||
|
gst_bin_add (GST_BIN (pipeline), src);
|
||||||
|
gst_bin_add (GST_BIN (pipeline), decoder);
|
||||||
|
gst_bin_add (GST_BIN (pipeline), audiosink);
|
||||||
|
|
||||||
|
gst_element_connect (src, decoder);
|
||||||
|
gst_element_connect (decoder, audiosink);
|
||||||
|
|
||||||
|
seekable = gst_element_get_pad (decoder, "src");
|
||||||
|
seekable_pads = g_list_prepend (seekable_pads, seekable);
|
||||||
|
rate_pads = g_list_prepend (rate_pads, seekable);
|
||||||
|
rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink"));
|
||||||
|
|
||||||
|
return pipeline;
|
||||||
|
}
|
||||||
|
|
||||||
static GstElement*
|
static GstElement*
|
||||||
make_wav_pipeline (const gchar *location)
|
make_wav_pipeline (const gchar *location)
|
||||||
{
|
{
|
||||||
|
@ -452,76 +484,89 @@ query_rates (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
G_GNUC_UNUSED static void
|
G_GNUC_UNUSED static void
|
||||||
query_durations (GstPad *pad)
|
query_durations ()
|
||||||
{
|
{
|
||||||
gint i = 0;
|
GList *walk = seekable_pads;
|
||||||
|
|
||||||
g_print ("durations %8.8s: ", GST_PAD_NAME (pad));
|
while (walk) {
|
||||||
while (seek_formats[i].name) {
|
GstPad *pad = GST_PAD (walk->data);
|
||||||
gboolean res;
|
gint i = 0;
|
||||||
gint64 value;
|
|
||||||
GstFormat format;
|
|
||||||
|
|
||||||
format = seek_formats[i].format;
|
g_print ("durations %8.8s: ", GST_PAD_NAME (pad));
|
||||||
res = gst_pad_query (pad, GST_PAD_QUERY_TOTAL, &format, &value);
|
while (seek_formats[i].name) {
|
||||||
if (res) {
|
gboolean res;
|
||||||
g_print ("%s %13lld | ", seek_formats[i].name, value);
|
gint64 value;
|
||||||
if (seek_formats[i].format == GST_FORMAT_TIME)
|
GstFormat format;
|
||||||
duration = value;
|
|
||||||
|
format = seek_formats[i].format;
|
||||||
|
res = gst_pad_query (pad, GST_PAD_QUERY_TOTAL, &format, &value);
|
||||||
|
if (res) {
|
||||||
|
g_print ("%s %13lld | ", seek_formats[i].name, value);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
|
||||||
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
else {
|
g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
|
||||||
g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
|
|
||||||
}
|
walk = g_list_next (walk);
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
G_GNUC_UNUSED static void
|
G_GNUC_UNUSED static void
|
||||||
query_positions (GstPad *pad)
|
query_positions ()
|
||||||
{
|
{
|
||||||
gint i = 0;
|
GList *walk = seekable_pads;
|
||||||
|
|
||||||
g_print ("positions %8.8s: ", GST_PAD_NAME (pad));
|
while (walk) {
|
||||||
while (seek_formats[i].name) {
|
GstPad *pad = GST_PAD (walk->data);
|
||||||
gboolean res;
|
gint i = 0;
|
||||||
gint64 value;
|
|
||||||
GstFormat format;
|
|
||||||
|
|
||||||
format = seek_formats[i].format;
|
g_print ("positions %8.8s: ", GST_PAD_NAME (pad));
|
||||||
res = gst_pad_query (pad, GST_PAD_QUERY_POSITION, &format, &value);
|
while (seek_formats[i].name) {
|
||||||
if (res) {
|
gboolean res;
|
||||||
g_print ("%s %13lld | ", seek_formats[i].name, value);
|
gint64 value;
|
||||||
if (seek_formats[i].format == GST_FORMAT_TIME)
|
GstFormat format;
|
||||||
position = value;
|
|
||||||
|
format = seek_formats[i].format;
|
||||||
|
res = gst_pad_query (pad, GST_PAD_QUERY_POSITION, &format, &value);
|
||||||
|
if (res) {
|
||||||
|
g_print ("%s %13lld | ", seek_formats[i].name, value);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
|
||||||
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
else {
|
g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
|
||||||
g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
|
|
||||||
}
|
walk = g_list_next (walk);
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
update_scale (gpointer data)
|
update_scale (gpointer data)
|
||||||
{
|
{
|
||||||
GList *walk = seekable_pads;
|
|
||||||
GstClock *clock;
|
GstClock *clock;
|
||||||
|
guint64 position;
|
||||||
|
GstFormat format = GST_FORMAT_TIME;
|
||||||
|
|
||||||
|
duration = 0;
|
||||||
clock = gst_bin_get_clock (GST_BIN (pipeline));
|
clock = gst_bin_get_clock (GST_BIN (pipeline));
|
||||||
|
|
||||||
g_print ("clock: %13llu (%s)\n", gst_clock_get_time (clock), gst_object_get_name (GST_OBJECT (clock)));
|
if (seekable_pads) {
|
||||||
|
GstPad *pad = GST_PAD (seekable_pads->data);
|
||||||
while (walk) {
|
gst_pad_query (pad, GST_PAD_QUERY_TOTAL, &format, &duration);
|
||||||
GstPad *pad = GST_PAD (walk->data);
|
}
|
||||||
|
position = gst_clock_get_time (clock);
|
||||||
query_durations (pad);
|
|
||||||
query_positions (pad);
|
if (stats) {
|
||||||
|
g_print ("clock: %13llu (%s)\n", position, gst_object_get_name (GST_OBJECT (clock)));
|
||||||
walk = g_list_next (walk);
|
query_durations ();
|
||||||
|
query_positions ();
|
||||||
|
query_rates ();
|
||||||
}
|
}
|
||||||
query_rates ();
|
|
||||||
|
|
||||||
if (duration > 0) {
|
if (duration > 0) {
|
||||||
gtk_adjustment_set_value (adjustment, position * 100.0 / duration);
|
gtk_adjustment_set_value (adjustment, position * 100.0 / duration);
|
||||||
|
@ -633,12 +678,17 @@ main (int argc, char **argv)
|
||||||
GtkWidget *window, *hbox, *vbox,
|
GtkWidget *window, *hbox, *vbox,
|
||||||
*play_button, *pause_button, *stop_button,
|
*play_button, *pause_button, *stop_button,
|
||||||
*hscale;
|
*hscale;
|
||||||
|
struct poptOption options[] = {
|
||||||
gst_init (&argc, &argv);
|
{"stats", 's', POPT_ARG_NONE|POPT_ARGFLAG_STRIP, &stats, 0,
|
||||||
|
"Show pad stats", NULL},
|
||||||
|
POPT_TABLEEND
|
||||||
|
};
|
||||||
|
|
||||||
|
gst_init_with_popt_table (&argc, &argv, options);
|
||||||
gtk_init (&argc, &argv);
|
gtk_init (&argc, &argv);
|
||||||
|
|
||||||
if (argc != 3) {
|
if (argc != 3) {
|
||||||
g_print ("usage: %s <type 0=mp3 1=avi 2=mpeg1 3=mpegparse 4=vorbis 5=sid 6=flac> <filename>\n", argv[0]);
|
g_print ("usage: %s <type 0=mp3 1=avi 2=mpeg1 3=mpegparse 4=vorbis 5=sid 6=flac 7=wav> <filename>\n", argv[0]);
|
||||||
exit (-1);
|
exit (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -658,6 +708,8 @@ main (int argc, char **argv)
|
||||||
pipeline = make_flac_pipeline (argv[2]);
|
pipeline = make_flac_pipeline (argv[2]);
|
||||||
else if (atoi (argv[1]) == 7)
|
else if (atoi (argv[1]) == 7)
|
||||||
pipeline = make_wav_pipeline (argv[2]);
|
pipeline = make_wav_pipeline (argv[2]);
|
||||||
|
else if (atoi (argv[1]) == 8)
|
||||||
|
pipeline = make_mod_pipeline (argv[2]);
|
||||||
|
|
||||||
/* initialize gui elements ... */
|
/* initialize gui elements ... */
|
||||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||||
|
|
|
@ -7,13 +7,14 @@ static GList *rate_pads = NULL;
|
||||||
static GList *seekable_elements = NULL;
|
static GList *seekable_elements = NULL;
|
||||||
|
|
||||||
static GstElement *pipeline;
|
static GstElement *pipeline;
|
||||||
static guint64 duration, position;
|
|
||||||
static GtkAdjustment *adjustment;
|
static GtkAdjustment *adjustment;
|
||||||
|
static gboolean stats = FALSE;
|
||||||
|
static guint64 duration;
|
||||||
|
|
||||||
static guint update_id;
|
static guint update_id;
|
||||||
|
|
||||||
#define SOURCE "gnomevfssrc"
|
//#define SOURCE "gnomevfssrc"
|
||||||
//#define SOURCE "filesrc"
|
#define SOURCE "filesrc"
|
||||||
|
|
||||||
#define UPDATE_INTERVAL 500
|
#define UPDATE_INTERVAL 500
|
||||||
|
|
||||||
|
@ -36,6 +37,8 @@ make_spider_pipeline (const gchar *location, gboolean thread)
|
||||||
a_thread = gst_thread_new ("a_thread");
|
a_thread = gst_thread_new ("a_thread");
|
||||||
a_queue = gst_element_factory_make ("queue", "a_queue");
|
a_queue = gst_element_factory_make ("queue", "a_queue");
|
||||||
audiosink = gst_element_factory_make ("osssink", "a_sink");
|
audiosink = gst_element_factory_make ("osssink", "a_sink");
|
||||||
|
//g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
|
||||||
|
|
||||||
v_thread = gst_thread_new ("v_thread");
|
v_thread = gst_thread_new ("v_thread");
|
||||||
v_queue = gst_element_factory_make ("queue", "v_queue");
|
v_queue = gst_element_factory_make ("queue", "v_queue");
|
||||||
videosink = gst_element_factory_make ("xvideosink", "v_sink");
|
videosink = gst_element_factory_make ("xvideosink", "v_sink");
|
||||||
|
@ -134,76 +137,87 @@ query_rates (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
G_GNUC_UNUSED static void
|
G_GNUC_UNUSED static void
|
||||||
query_durations (GstElement *element)
|
query_durations ()
|
||||||
{
|
{
|
||||||
gint i = 0;
|
GList *walk = seekable_elements;
|
||||||
|
|
||||||
g_print ("durations %8.8s: ", GST_ELEMENT_NAME (element));
|
while (walk) {
|
||||||
while (seek_formats[i].name) {
|
GstElement *element = GST_ELEMENT (walk->data);
|
||||||
gboolean res;
|
gint i = 0;
|
||||||
gint64 value;
|
|
||||||
GstFormat format;
|
|
||||||
|
|
||||||
format = seek_formats[i].format;
|
g_print ("durations %8.8s: ", GST_ELEMENT_NAME (element));
|
||||||
res = gst_element_query (element, GST_PAD_QUERY_TOTAL, &format, &value);
|
while (seek_formats[i].name) {
|
||||||
if (res) {
|
gboolean res;
|
||||||
g_print ("%s %13lld | ", seek_formats[i].name, value);
|
gint64 value;
|
||||||
if (seek_formats[i].format == GST_FORMAT_TIME)
|
GstFormat format;
|
||||||
duration = value;
|
|
||||||
|
format = seek_formats[i].format;
|
||||||
|
res = gst_element_query (element, GST_PAD_QUERY_TOTAL, &format, &value);
|
||||||
|
if (res) {
|
||||||
|
g_print ("%s %13lld | ", seek_formats[i].name, value);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
|
||||||
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
else {
|
g_print (" %s\n", GST_ELEMENT_NAME (element));
|
||||||
g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
|
walk = g_list_next (walk);
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
g_print (" %s\n", GST_ELEMENT_NAME (element));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
G_GNUC_UNUSED static void
|
G_GNUC_UNUSED static void
|
||||||
query_positions (GstElement *element)
|
query_positions ()
|
||||||
{
|
{
|
||||||
gint i = 0;
|
GList *walk = seekable_elements;
|
||||||
|
|
||||||
g_print ("positions %8.8s: ", GST_ELEMENT_NAME (element));
|
while (walk) {
|
||||||
while (seek_formats[i].name) {
|
GstElement *element = GST_ELEMENT (walk->data);
|
||||||
gboolean res;
|
gint i = 0;
|
||||||
gint64 value;
|
|
||||||
GstFormat format;
|
|
||||||
|
|
||||||
format = seek_formats[i].format;
|
g_print ("positions %8.8s: ", GST_ELEMENT_NAME (element));
|
||||||
res = gst_element_query (element, GST_PAD_QUERY_POSITION, &format, &value);
|
while (seek_formats[i].name) {
|
||||||
if (res) {
|
gboolean res;
|
||||||
g_print ("%s %13lld | ", seek_formats[i].name, value);
|
gint64 value;
|
||||||
|
GstFormat format;
|
||||||
|
|
||||||
|
format = seek_formats[i].format;
|
||||||
|
res = gst_element_query (element, GST_PAD_QUERY_POSITION, &format, &value);
|
||||||
|
if (res) {
|
||||||
|
g_print ("%s %13lld | ", seek_formats[i].name, value);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
|
||||||
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
else {
|
g_print (" %s\n", GST_ELEMENT_NAME (element));
|
||||||
g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
|
walk = g_list_next (walk);
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
g_print (" %s\n", GST_ELEMENT_NAME (element));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
update_scale (gpointer data)
|
update_scale (gpointer data)
|
||||||
{
|
{
|
||||||
GList *walk = seekable_elements;
|
|
||||||
GstClock *clock;
|
GstClock *clock;
|
||||||
|
guint64 position;
|
||||||
|
GstFormat format = GST_FORMAT_TIME;
|
||||||
|
|
||||||
|
duration = 0;
|
||||||
clock = gst_bin_get_clock (GST_BIN (pipeline));
|
clock = gst_bin_get_clock (GST_BIN (pipeline));
|
||||||
|
|
||||||
position = gst_clock_get_time (clock);
|
if (seekable_elements) {
|
||||||
g_print ("clock: %13llu (%s)\n", position, gst_object_get_name (GST_OBJECT (clock)));
|
GstElement *element = GST_ELEMENT (seekable_elements->data);
|
||||||
|
gst_element_query (element, GST_PAD_QUERY_TOTAL, &format, &duration);
|
||||||
while (walk) {
|
|
||||||
GstElement *element = GST_ELEMENT (walk->data);
|
|
||||||
|
|
||||||
query_durations (element);
|
|
||||||
query_positions (element);
|
|
||||||
|
|
||||||
walk = g_list_next (walk);
|
|
||||||
}
|
}
|
||||||
query_rates ();
|
position = gst_clock_get_time (clock);
|
||||||
|
|
||||||
|
if (stats) {
|
||||||
|
g_print ("clock: %13llu (%s)\n", position, gst_object_get_name (GST_OBJECT (clock)));
|
||||||
|
query_durations ();
|
||||||
|
query_positions ();
|
||||||
|
query_rates ();
|
||||||
|
}
|
||||||
if (duration > 0) {
|
if (duration > 0) {
|
||||||
gtk_adjustment_set_value (adjustment, position * 100.0 / duration);
|
gtk_adjustment_set_value (adjustment, position * 100.0 / duration);
|
||||||
}
|
}
|
||||||
|
@ -216,9 +230,6 @@ iterate (gpointer data)
|
||||||
{
|
{
|
||||||
gboolean res = TRUE;
|
gboolean res = TRUE;
|
||||||
|
|
||||||
if (GST_FLAG_IS_SET (data, GST_BIN_SELF_SCHEDULABLE))
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
res = gst_bin_iterate (GST_BIN (data));
|
res = gst_bin_iterate (GST_BIN (data));
|
||||||
if (!res) {
|
if (!res) {
|
||||||
gtk_timeout_remove (update_id);
|
gtk_timeout_remove (update_id);
|
||||||
|
@ -259,7 +270,8 @@ stop_seek (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||||
gtk_idle_add ((GtkFunction) iterate, pipeline);
|
if (!GST_FLAG_IS_SET (pipeline, GST_BIN_SELF_SCHEDULABLE))
|
||||||
|
gtk_idle_add ((GtkFunction) iterate, pipeline);
|
||||||
update_id = gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline);
|
update_id = gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -270,7 +282,8 @@ play_cb (GtkButton * button, gpointer data)
|
||||||
{
|
{
|
||||||
if (gst_element_get_state (pipeline) != GST_STATE_PLAYING) {
|
if (gst_element_get_state (pipeline) != GST_STATE_PLAYING) {
|
||||||
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||||
gtk_idle_add ((GtkFunction) iterate, pipeline);
|
if (!GST_FLAG_IS_SET (pipeline, GST_BIN_SELF_SCHEDULABLE))
|
||||||
|
gtk_idle_add ((GtkFunction) iterate, pipeline);
|
||||||
update_id = gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline);
|
update_id = gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -303,6 +316,8 @@ main (int argc, char **argv)
|
||||||
struct poptOption options[] = {
|
struct poptOption options[] = {
|
||||||
{"threaded", 't', POPT_ARG_NONE|POPT_ARGFLAG_STRIP, &threaded, 0,
|
{"threaded", 't', POPT_ARG_NONE|POPT_ARGFLAG_STRIP, &threaded, 0,
|
||||||
"Run the pipeline in a toplevel thread", NULL},
|
"Run the pipeline in a toplevel thread", NULL},
|
||||||
|
{"stats", 's', POPT_ARG_NONE|POPT_ARGFLAG_STRIP, &stats, 0,
|
||||||
|
"Show element stats", NULL},
|
||||||
POPT_TABLEEND
|
POPT_TABLEEND
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue