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>
* 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) <2003> David Schleef <ds@schleef.org>
* 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
* 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))
#define GST_IS_PROGRESS_REPORT(obj) \
(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))
typedef struct _GstProgressReport GstProgressReport;
@ -51,6 +52,10 @@ struct _GstProgressReport
gboolean silent;
GTimeVal start_time;
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
@ -62,7 +67,8 @@ enum
{
ARG_0,
ARG_UPDATE_FREQ,
ARG_SILENT
ARG_SILENT,
ARG_FORMAT
};
GstStaticPadTemplate progress_report_src_template =
@ -85,6 +91,7 @@ GST_ELEMENT_DETAILS ("Progress report",
#define DEFAULT_UPDATE_FREQ 5
#define DEFAULT_SILENT FALSE
#define DEFAULT_FORMAT "auto"
static void gst_progress_report_set_property (GObject * object, guint prop_id,
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);
}
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
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);
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->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",
"Number of seconds between reports when data is flowing", 1, G_MAXINT,
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",
"Do not print output to stdout", "Do not print output to stdout",
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->transform_ip =
GST_DEBUG_FUNCPTR (gst_progress_report_transform_ip);
@ -152,38 +175,27 @@ gst_progress_report_init (GstProgressReport * report,
report->update_freq = DEFAULT_UPDATE_FREQ;
report->silent = DEFAULT_SILENT;
report->format = g_strdup (DEFAULT_FORMAT);
}
static void
gst_progress_report_report (GstProgressReport * filter, GTimeVal cur_time)
static gboolean
gst_progress_report_do_query (GstProgressReport * filter, GstFormat format,
gint hh, gint mm, gint ss)
{
GstFormat try_formats[] = { GST_FORMAT_TIME, GST_FORMAT_BYTES,
GST_FORMAT_PERCENT, GST_FORMAT_BUFFERS,
GST_FORMAT_DEFAULT
};
GstPad *peer_pad;
gint64 cur_progress;
gint64 total_progress;
gint hh, mm, ss, i;
glong run_time;
GST_OBJECT_LOCK (filter);
run_time = cur_time.tv_sec - filter->start_time.tv_sec;
hh = (run_time / 3600) % 100;
mm = (run_time / 60) % 60;
ss = (run_time % 60);
peer_pad = gst_pad_get_peer (GST_BASE_TRANSFORM (filter)->sinkpad);
/* 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;
GstPad *sink_pad;
gint64 cur, total;
format = try_formats[i];
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;
}
if (gst_pad_query_position (peer_pad, &format, &cur_progress) &&
gst_pad_query_duration (peer_pad, &format, &total_progress)) {
switch (format) {
case GST_FORMAT_BYTES:
format_name = "bytes";
@ -196,11 +208,10 @@ gst_progress_report_report (GstProgressReport * filter, GTimeVal cur_time)
break;
case GST_FORMAT_TIME:
format_name = "seconds";
cur_progress /= GST_SECOND;
total_progress /= GST_SECOND;
cur /= GST_SECOND;
total /= GST_SECOND;
break;
case GST_FORMAT_DEFAULT:
{
case GST_FORMAT_DEFAULT:{
GstCaps *caps;
format_name = "bogounits";
@ -209,8 +220,8 @@ gst_progress_report_report (GstProgressReport * filter, GTimeVal cur_time)
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/")) {
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";
@ -218,8 +229,7 @@ gst_progress_report_report (GstProgressReport * filter, GTimeVal cur_time)
}
break;
}
default:
{
default:{
const GstFormatDefinition *details;
details = gst_format_get_details (format);
@ -233,28 +243,61 @@ gst_progress_report_report (GstProgressReport * filter, GTimeVal cur_time)
}
if (!filter->silent) {
if (total_progress > 0) {
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_progress, total_progress, format_name,
(gdouble) cur_progress / total_progress * 100.0);
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_progress, format_name);
GST_OBJECT_NAME (filter), hh, mm, ss, cur, format_name);
}
}
return TRUE;
}
static void
gst_progress_report_report (GstProgressReport * filter, GTimeVal cur_time)
{
GstFormat try_formats[] = { GST_FORMAT_TIME, GST_FORMAT_BYTES,
GST_FORMAT_PERCENT, GST_FORMAT_BUFFERS,
GST_FORMAT_DEFAULT
};
GstFormat format = GST_FORMAT_UNDEFINED;
gboolean done = FALSE;
glong run_time;
gint hh, mm, ss;
run_time = cur_time.tv_sec - filter->start_time.tv_sec;
hh = (run_time / 3600) % 100;
mm = (run_time / 60) % 60;
ss = (run_time % 60);
GST_OBJECT_LOCK (filter);
if (filter->format != NULL && strcmp (filter->format, "auto") != 0) {
format = gst_format_get_by_nick (filter->format);
}
if (format != GST_FORMAT_UNDEFINED) {
done = gst_progress_report_do_query (filter, format, hh, mm, ss);
} else {
gint i;
for (i = 0; i < G_N_ELEMENTS (try_formats); ++i) {
done = gst_progress_report_do_query (filter, try_formats[i], hh, mm, ss);
if (done)
break;
}
}
if (i == G_N_ELEMENTS (try_formats)) {
g_print ("%s (%2d:%2d:%2d): Could not query current position.\n",
if (!done && !filter->silent) {
g_print ("%s (%2d:%2d:%2d): Could not query position and/or duration\n",
GST_OBJECT_NAME (filter), hh, mm, ss);
}
GST_OBJECT_UNLOCK (filter);
gst_object_unref (peer_pad);
}
static gboolean
@ -339,6 +382,14 @@ gst_progress_report_set_property (GObject * object, guint prop_id,
filter->silent = g_value_get_boolean (value);
GST_OBJECT_UNLOCK (filter);
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:
break;
}
@ -363,6 +414,11 @@ gst_progress_report_get_property (GObject * object, guint prop_id,
g_value_set_boolean (value, filter->silent);
GST_OBJECT_UNLOCK (filter);
break;
case ARG_FORMAT:
GST_OBJECT_LOCK (filter);
g_value_set_string (value, filter->format);
GST_OBJECT_UNLOCK (filter);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;