gst/debug/progressreport.c: Add 'format' property to force querying to a particular format.

Original commit message from CVS:
* gst/debug/progressreport.c: (gst_progress_report_finalize),
(gst_progress_report_class_init), (gst_progress_report_init),
(gst_progress_report_do_query), (gst_progress_report_report),
(gst_progress_report_set_property),
(gst_progress_report_get_property):
Add 'format' property to force querying to a particular format.
This commit is contained in:
Tim-Philipp Müller 2006-04-21 17:15:29 +00:00
parent 48892690e6
commit b3debb82fd
2 changed files with 145 additions and 80 deletions

View file

@ -1,3 +1,12 @@
2006-04-21 Tim-Philipp Müller <tim at centricular dot net>
* gst/debug/progressreport.c: (gst_progress_report_finalize),
(gst_progress_report_class_init), (gst_progress_report_init),
(gst_progress_report_do_query), (gst_progress_report_report),
(gst_progress_report_set_property),
(gst_progress_report_get_property):
Add 'format' property to force querying to a particular format.
2006-04-21 Andy Wingo <wingo@pobox.com> 2006-04-21 Andy Wingo <wingo@pobox.com>
* ext/dv/gstdv.c (plugin_init): libdv is a marginal decoder, at * ext/dv/gstdv.c (plugin_init): libdv is a marginal decoder, at

View file

@ -2,6 +2,7 @@
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* Copyright (C) <2003> David Schleef <ds@schleef.org> * Copyright (C) <2003> David Schleef <ds@schleef.org>
* Copyright (C) <2004> Jan Schmidt <thaytan@mad.scientist.com> * Copyright (C) <2004> Jan Schmidt <thaytan@mad.scientist.com>
* Copyright (C) <2006> Tim-Philipp Müller <tim centricular net>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public
@ -37,7 +38,7 @@
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PROGRESS_REPORT,GstProgressReportClass)) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PROGRESS_REPORT,GstProgressReportClass))
#define GST_IS_PROGRESS_REPORT(obj) \ #define GST_IS_PROGRESS_REPORT(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PROGRESS_REPORT)) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PROGRESS_REPORT))
#define GST_IS_PROGRESS_REPORT_CLASS(obj) \ #define GST_IS_PROGRESS_REPORT_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PROGRESS_REPORT)) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PROGRESS_REPORT))
typedef struct _GstProgressReport GstProgressReport; typedef struct _GstProgressReport GstProgressReport;
@ -51,6 +52,10 @@ struct _GstProgressReport
gboolean silent; gboolean silent;
GTimeVal start_time; GTimeVal start_time;
GTimeVal last_report; GTimeVal last_report;
/* Format used for querying. Using a string here because the
* format might not be registered yet when the property is set */
gchar *format;
}; };
struct _GstProgressReportClass struct _GstProgressReportClass
@ -62,7 +67,8 @@ enum
{ {
ARG_0, ARG_0,
ARG_UPDATE_FREQ, ARG_UPDATE_FREQ,
ARG_SILENT ARG_SILENT,
ARG_FORMAT
}; };
GstStaticPadTemplate progress_report_src_template = GstStaticPadTemplate progress_report_src_template =
@ -85,6 +91,7 @@ GST_ELEMENT_DETAILS ("Progress report",
#define DEFAULT_UPDATE_FREQ 5 #define DEFAULT_UPDATE_FREQ 5
#define DEFAULT_SILENT FALSE #define DEFAULT_SILENT FALSE
#define DEFAULT_FORMAT "auto"
static void gst_progress_report_set_property (GObject * object, guint prop_id, static void gst_progress_report_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec); const GValue * value, GParamSpec * pspec);
@ -115,6 +122,17 @@ gst_progress_report_base_init (gpointer g_class)
gst_element_class_set_details (element_class, &progress_report_details); gst_element_class_set_details (element_class, &progress_report_details);
} }
static void
gst_progress_report_finalize (GObject * obj)
{
GstProgressReport *filter = GST_PROGRESS_REPORT (obj);
g_free (filter->format);
filter->format = NULL;
G_OBJECT_CLASS (parent_class)->finalize (obj);
}
static void static void
gst_progress_report_class_init (GstProgressReportClass * g_class) gst_progress_report_class_init (GstProgressReportClass * g_class)
{ {
@ -124,19 +142,24 @@ gst_progress_report_class_init (GstProgressReportClass * g_class)
gobject_class = G_OBJECT_CLASS (g_class); gobject_class = G_OBJECT_CLASS (g_class);
gstbasetrans_class = GST_BASE_TRANSFORM_CLASS (g_class); gstbasetrans_class = GST_BASE_TRANSFORM_CLASS (g_class);
gobject_class->finalize = gst_progress_report_finalize;
gobject_class->set_property = gst_progress_report_set_property; gobject_class->set_property = gst_progress_report_set_property;
gobject_class->get_property = gst_progress_report_get_property; gobject_class->get_property = gst_progress_report_get_property;
g_object_class_install_property (G_OBJECT_CLASS (g_class), g_object_class_install_property (gobject_class,
ARG_UPDATE_FREQ, g_param_spec_int ("update-freq", "Update Frequency", ARG_UPDATE_FREQ, g_param_spec_int ("update-freq", "Update Frequency",
"Number of seconds between reports when data is flowing", 1, G_MAXINT, "Number of seconds between reports when data is flowing", 1, G_MAXINT,
DEFAULT_UPDATE_FREQ, G_PARAM_READWRITE)); DEFAULT_UPDATE_FREQ, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (g_class), g_object_class_install_property (gobject_class,
ARG_SILENT, g_param_spec_boolean ("silent", ARG_SILENT, g_param_spec_boolean ("silent",
"Do not print output to stdout", "Do not print output to stdout", "Do not print output to stdout", "Do not print output to stdout",
DEFAULT_SILENT, G_PARAM_READWRITE)); DEFAULT_SILENT, G_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
ARG_FORMAT, g_param_spec_string ("format", "format",
"Format to use for the querying", DEFAULT_FORMAT, G_PARAM_READWRITE));
gstbasetrans_class->event = GST_DEBUG_FUNCPTR (gst_progress_report_event); gstbasetrans_class->event = GST_DEBUG_FUNCPTR (gst_progress_report_event);
gstbasetrans_class->transform_ip = gstbasetrans_class->transform_ip =
GST_DEBUG_FUNCPTR (gst_progress_report_transform_ip); GST_DEBUG_FUNCPTR (gst_progress_report_transform_ip);
@ -152,6 +175,85 @@ gst_progress_report_init (GstProgressReport * report,
report->update_freq = DEFAULT_UPDATE_FREQ; report->update_freq = DEFAULT_UPDATE_FREQ;
report->silent = DEFAULT_SILENT; report->silent = DEFAULT_SILENT;
report->format = g_strdup (DEFAULT_FORMAT);
}
static gboolean
gst_progress_report_do_query (GstProgressReport * filter, GstFormat format,
gint hh, gint mm, gint ss)
{
const gchar *format_name = NULL;
GstPad *sink_pad;
gint64 cur, total;
sink_pad = GST_BASE_TRANSFORM (filter)->sinkpad;
GST_LOG_OBJECT (filter, "querying using format %d (%s)", format,
gst_format_get_name (format));
if (!gst_pad_query_peer_position (sink_pad, &format, &cur) ||
!gst_pad_query_peer_duration (sink_pad, &format, &total)) {
return FALSE;
}
switch (format) {
case GST_FORMAT_BYTES:
format_name = "bytes";
break;
case GST_FORMAT_BUFFERS:
format_name = "buffers";
break;
case GST_FORMAT_PERCENT:
format_name = "percent";
break;
case GST_FORMAT_TIME:
format_name = "seconds";
cur /= GST_SECOND;
total /= GST_SECOND;
break;
case GST_FORMAT_DEFAULT:{
GstCaps *caps;
format_name = "bogounits";
caps = GST_PAD_CAPS (GST_BASE_TRANSFORM (filter)->sinkpad);
if (caps && gst_caps_is_fixed (caps) && !gst_caps_is_any (caps)) {
GstStructure *s = gst_caps_get_structure (caps, 0);
const gchar *mime_type = gst_structure_get_name (s);
if (g_str_has_prefix (mime_type, "video/") ||
g_str_has_prefix (mime_type, "image/")) {
format_name = "frames";
} else if (g_str_has_prefix (mime_type, "audio/")) {
format_name = "samples";
}
}
break;
}
default:{
const GstFormatDefinition *details;
details = gst_format_get_details (format);
if (details) {
format_name = details->nick;
} else {
format_name = "unknown";
}
break;
}
}
if (!filter->silent) {
if (total > 0) {
g_print ("%s (%02d:%02d:%02d): %" G_GINT64_FORMAT " / %"
G_GINT64_FORMAT " %s (%4.1f %%)\n", GST_OBJECT_NAME (filter), hh,
mm, ss, cur, total, format_name, (gdouble) cur / total * 100.0);
} else {
g_print ("%s (%02d:%02d:%02d): %" G_GINT64_FORMAT " %s\n",
GST_OBJECT_NAME (filter), hh, mm, ss, cur, format_name);
}
}
return TRUE;
} }
static void static void
@ -161,100 +263,41 @@ gst_progress_report_report (GstProgressReport * filter, GTimeVal cur_time)
GST_FORMAT_PERCENT, GST_FORMAT_BUFFERS, GST_FORMAT_PERCENT, GST_FORMAT_BUFFERS,
GST_FORMAT_DEFAULT GST_FORMAT_DEFAULT
}; };
GstPad *peer_pad; GstFormat format = GST_FORMAT_UNDEFINED;
gint64 cur_progress; gboolean done = FALSE;
gint64 total_progress;
gint hh, mm, ss, i;
glong run_time; glong run_time;
gint hh, mm, ss;
GST_OBJECT_LOCK (filter);
run_time = cur_time.tv_sec - filter->start_time.tv_sec; run_time = cur_time.tv_sec - filter->start_time.tv_sec;
hh = (run_time / 3600) % 100; hh = (run_time / 3600) % 100;
mm = (run_time / 60) % 60; mm = (run_time / 60) % 60;
ss = (run_time % 60); ss = (run_time % 60);
peer_pad = gst_pad_get_peer (GST_BASE_TRANSFORM (filter)->sinkpad); GST_OBJECT_LOCK (filter);
/* Query for the current time then attempt to set to time + offset */
for (i = 0; i < G_N_ELEMENTS (try_formats); ++i) {
const gchar *format_name = NULL;
GstFormat format;
format = try_formats[i]; if (filter->format != NULL && strcmp (filter->format, "auto") != 0) {
format = gst_format_get_by_nick (filter->format);
}
if (gst_pad_query_position (peer_pad, &format, &cur_progress) && if (format != GST_FORMAT_UNDEFINED) {
gst_pad_query_duration (peer_pad, &format, &total_progress)) { done = gst_progress_report_do_query (filter, format, hh, mm, ss);
switch (format) { } else {
case GST_FORMAT_BYTES: gint i;
format_name = "bytes";
break;
case GST_FORMAT_BUFFERS:
format_name = "buffers";
break;
case GST_FORMAT_PERCENT:
format_name = "percent";
break;
case GST_FORMAT_TIME:
format_name = "seconds";
cur_progress /= GST_SECOND;
total_progress /= GST_SECOND;
break;
case GST_FORMAT_DEFAULT:
{
GstCaps *caps;
format_name = "bogounits"; for (i = 0; i < G_N_ELEMENTS (try_formats); ++i) {
caps = GST_PAD_CAPS (GST_BASE_TRANSFORM (filter)->sinkpad); done = gst_progress_report_do_query (filter, try_formats[i], hh, mm, ss);
if (caps && gst_caps_is_fixed (caps) && !gst_caps_is_any (caps)) { if (done)
GstStructure *s = gst_caps_get_structure (caps, 0); break;
const gchar *mime_type = gst_structure_get_name (s);
if (g_str_has_prefix (mime_type, "video/")
|| g_str_has_prefix (mime_type, "image/")) {
format_name = "frames";
} else if (g_str_has_prefix (mime_type, "audio/")) {
format_name = "samples";
}
}
break;
}
default:
{
const GstFormatDefinition *details;
details = gst_format_get_details (format);
if (details) {
format_name = details->nick;
} else {
format_name = "unknown";
}
break;
}
}
if (!filter->silent) {
if (total_progress > 0) {
g_print ("%s (%02d:%02d:%02d): %" G_GINT64_FORMAT " / %"
G_GINT64_FORMAT " %s (%4.1f %%)\n", GST_OBJECT_NAME (filter), hh,
mm, ss, cur_progress, total_progress, format_name,
(gdouble) cur_progress / total_progress * 100.0);
} else {
g_print ("%s (%02d:%02d:%02d): %" G_GINT64_FORMAT " %s\n",
GST_OBJECT_NAME (filter), hh, mm, ss, cur_progress, format_name);
}
}
break;
} }
} }
if (i == G_N_ELEMENTS (try_formats)) { if (!done && !filter->silent) {
g_print ("%s (%2d:%2d:%2d): Could not query current position.\n", g_print ("%s (%2d:%2d:%2d): Could not query position and/or duration\n",
GST_OBJECT_NAME (filter), hh, mm, ss); GST_OBJECT_NAME (filter), hh, mm, ss);
} }
GST_OBJECT_UNLOCK (filter); GST_OBJECT_UNLOCK (filter);
gst_object_unref (peer_pad);
} }
static gboolean static gboolean
@ -339,6 +382,14 @@ gst_progress_report_set_property (GObject * object, guint prop_id,
filter->silent = g_value_get_boolean (value); filter->silent = g_value_get_boolean (value);
GST_OBJECT_UNLOCK (filter); GST_OBJECT_UNLOCK (filter);
break; break;
case ARG_FORMAT:
GST_OBJECT_LOCK (filter);
g_free (filter->format);
filter->format = g_value_dup_string (value);
if (filter->format == NULL)
filter->format = g_strdup ("auto");
GST_OBJECT_UNLOCK (filter);
break;
default: default:
break; break;
} }
@ -363,6 +414,11 @@ gst_progress_report_get_property (GObject * object, guint prop_id,
g_value_set_boolean (value, filter->silent); g_value_set_boolean (value, filter->silent);
GST_OBJECT_UNLOCK (filter); GST_OBJECT_UNLOCK (filter);
break; break;
case ARG_FORMAT:
GST_OBJECT_LOCK (filter);
g_value_set_string (value, filter->format);
GST_OBJECT_UNLOCK (filter);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;