Tim-Philipp Müller | b5ee422 | 2007-02-07 20:39:16 +0000 | [diff] [blame] | 1 | /* GStreamer Progress Report Element |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 2 | * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> |
| 3 | * Copyright (C) <2003> David Schleef <ds@schleef.org> |
| 4 | * Copyright (C) <2004> Jan Schmidt <thaytan@mad.scientist.com> |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 5 | * Copyright (C) <2006> Tim-Philipp Müller <tim centricular net> |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Library General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Library General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Library General Public |
| 18 | * License along with this library; if not, write to the |
Tim-Philipp Müller | 230cf41 | 2012-11-04 00:07:18 +0000 | [diff] [blame] | 19 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
| 20 | * Boston, MA 02110-1301, USA. |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 21 | */ |
| 22 | |
Tim-Philipp Müller | b5ee422 | 2007-02-07 20:39:16 +0000 | [diff] [blame] | 23 | /** |
| 24 | * SECTION:element-progressreport |
Tim-Philipp Müller | b5ee422 | 2007-02-07 20:39:16 +0000 | [diff] [blame] | 25 | * |
Tim-Philipp Müller | b5ee422 | 2007-02-07 20:39:16 +0000 | [diff] [blame] | 26 | * The progressreport element can be put into a pipeline to report progress, |
| 27 | * which is done by doing upstream duration and position queries in regular |
| 28 | * (real-time) intervals. Both the interval and the prefered query format |
Stefan Kost | a99d3f8 | 2009-01-28 12:29:42 +0200 | [diff] [blame] | 29 | * can be specified via the #GstProgressReport:update-freq and the |
| 30 | * #GstProgressReport:format property. |
| 31 | * |
Tim-Philipp Müller | b5ee422 | 2007-02-07 20:39:16 +0000 | [diff] [blame] | 32 | * Element messages containing a "progress" structure are posted on the bus |
| 33 | * whenever progress has been queried (since gst-plugins-good 0.10.6 only). |
Stefan Kost | a99d3f8 | 2009-01-28 12:29:42 +0200 | [diff] [blame] | 34 | * |
Tim-Philipp Müller | b5ee422 | 2007-02-07 20:39:16 +0000 | [diff] [blame] | 35 | * Since the element was originally designed for debugging purposes, it will |
| 36 | * by default also print information about the current progress to the |
Stefan Kost | a99d3f8 | 2009-01-28 12:29:42 +0200 | [diff] [blame] | 37 | * terminal. This can be prevented by setting the #GstProgressReport:silent |
| 38 | * property to %TRUE. |
| 39 | * |
Tim-Philipp Müller | b5ee422 | 2007-02-07 20:39:16 +0000 | [diff] [blame] | 40 | * This element is most useful in transcoding pipelines or other situations |
| 41 | * where just querying the pipeline might not lead to the wanted result. For |
| 42 | * progress in TIME format, the element is best placed in a 'raw stream' |
| 43 | * section of the pipeline (or after any demuxers/decoders/parsers). |
Stefan Kost | a99d3f8 | 2009-01-28 12:29:42 +0200 | [diff] [blame] | 44 | * |
Tim-Philipp Müller | 6bbee32 | 2007-02-08 11:09:15 +0000 | [diff] [blame] | 45 | * Three more things should be pointed out: firstly, the element will only |
| 46 | * query progress when data flow happens. If data flow is stalled for some |
| 47 | * reason, no progress messages will be posted. Secondly, there are other |
| 48 | * elements (like qtdemux, for example) that may also post "progress" element |
| 49 | * messages on the bus. Applications should check the source of any element |
| 50 | * messages they receive, if needed. Finally, applications should not take |
| 51 | * action on receiving notification of progress being 100%, they should only |
| 52 | * take action when they receive an EOS message (since the progress reported |
| 53 | * is in reference to an internal point of a pipeline and not the pipeline as |
| 54 | * a whole). |
Stefan Kost | a99d3f8 | 2009-01-28 12:29:42 +0200 | [diff] [blame] | 55 | * |
| 56 | * <refsect2> |
Tim-Philipp Müller | b5ee422 | 2007-02-07 20:39:16 +0000 | [diff] [blame] | 57 | * <title>Example launch line</title> |
Stefan Kost | a99d3f8 | 2009-01-28 12:29:42 +0200 | [diff] [blame] | 58 | * |[ |
Tim-Philipp Müller | 4bb52bb | 2012-08-26 22:39:55 +0100 | [diff] [blame] | 59 | * gst-launch-1.0 -m filesrc location=foo.ogg ! decodebin ! progressreport update-freq=1 ! audioconvert ! audioresample ! autoaudiosink |
Stefan Kost | a99d3f8 | 2009-01-28 12:29:42 +0200 | [diff] [blame] | 60 | * ]| This shows a progress query where a duration is available. |
| 61 | * |[ |
Tim-Philipp Müller | 4bb52bb | 2012-08-26 22:39:55 +0100 | [diff] [blame] | 62 | * gst-launch-1.0 -m audiotestsrc ! progressreport update-freq=1 ! audioconvert ! autoaudiosink |
Stefan Kost | a99d3f8 | 2009-01-28 12:29:42 +0200 | [diff] [blame] | 63 | * ]| This shows a progress query where no duration is available. |
Tim-Philipp Müller | b5ee422 | 2007-02-07 20:39:16 +0000 | [diff] [blame] | 64 | * </refsect2> |
| 65 | */ |
| 66 | |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 67 | #ifdef HAVE_CONFIG_H |
| 68 | #include "config.h" |
| 69 | #endif |
| 70 | |
| 71 | #include <gst/gst.h> |
| 72 | #include <string.h> |
| 73 | #include <math.h> |
| 74 | #include <time.h> |
| 75 | |
Tim-Philipp Müller | b5ee422 | 2007-02-07 20:39:16 +0000 | [diff] [blame] | 76 | #include "progressreport.h" |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 77 | |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 78 | |
| 79 | enum |
| 80 | { |
Luis de Bethencourt | 9391622 | 2015-04-27 11:22:11 +0100 | [diff] [blame] | 81 | PROP_0, |
| 82 | PROP_UPDATE_FREQ, |
| 83 | PROP_SILENT, |
| 84 | PROP_DO_QUERY, |
| 85 | PROP_FORMAT |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 88 | GstStaticPadTemplate progress_report_src_template = |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 89 | GST_STATIC_PAD_TEMPLATE ("src", |
| 90 | GST_PAD_SRC, |
| 91 | GST_PAD_ALWAYS, |
| 92 | GST_STATIC_CAPS_ANY); |
| 93 | |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 94 | GstStaticPadTemplate progress_report_sink_template = |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 95 | GST_STATIC_PAD_TEMPLATE ("sink", |
| 96 | GST_PAD_SINK, |
| 97 | GST_PAD_ALWAYS, |
| 98 | GST_STATIC_CAPS_ANY); |
| 99 | |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 100 | #define DEFAULT_UPDATE_FREQ 5 |
| 101 | #define DEFAULT_SILENT FALSE |
Mark Nauwelaerts | 1d44962 | 2010-12-06 12:17:21 +0100 | [diff] [blame] | 102 | #define DEFAULT_DO_QUERY TRUE |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 103 | #define DEFAULT_FORMAT "auto" |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 104 | |
| 105 | static void gst_progress_report_set_property (GObject * object, guint prop_id, |
| 106 | const GValue * value, GParamSpec * pspec); |
| 107 | static void gst_progress_report_get_property (GObject * object, guint prop_id, |
| 108 | GValue * value, GParamSpec * pspec); |
| 109 | |
Wim Taymans | 984a0b5 | 2011-07-22 21:19:45 +0200 | [diff] [blame] | 110 | static gboolean gst_progress_report_sink_event (GstBaseTransform * trans, |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 111 | GstEvent * event); |
| 112 | static GstFlowReturn gst_progress_report_transform_ip (GstBaseTransform * trans, |
| 113 | GstBuffer * buf); |
| 114 | |
| 115 | static gboolean gst_progress_report_start (GstBaseTransform * trans); |
| 116 | static gboolean gst_progress_report_stop (GstBaseTransform * trans); |
| 117 | |
Edward Hervey | a8effac | 2011-06-07 12:06:08 +0200 | [diff] [blame] | 118 | #define gst_progress_report_parent_class parent_class |
| 119 | G_DEFINE_TYPE (GstProgressReport, gst_progress_report, GST_TYPE_BASE_TRANSFORM); |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 120 | |
| 121 | static void |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 122 | gst_progress_report_finalize (GObject * obj) |
| 123 | { |
| 124 | GstProgressReport *filter = GST_PROGRESS_REPORT (obj); |
| 125 | |
| 126 | g_free (filter->format); |
| 127 | filter->format = NULL; |
| 128 | |
| 129 | G_OBJECT_CLASS (parent_class)->finalize (obj); |
| 130 | } |
| 131 | |
| 132 | static void |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 133 | gst_progress_report_class_init (GstProgressReportClass * g_class) |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 134 | { |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 135 | GstBaseTransformClass *gstbasetrans_class; |
Edward Hervey | a8effac | 2011-06-07 12:06:08 +0200 | [diff] [blame] | 136 | GstElementClass *element_class; |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 137 | GObjectClass *gobject_class; |
| 138 | |
| 139 | gobject_class = G_OBJECT_CLASS (g_class); |
Edward Hervey | a8effac | 2011-06-07 12:06:08 +0200 | [diff] [blame] | 140 | element_class = GST_ELEMENT_CLASS (g_class); |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 141 | gstbasetrans_class = GST_BASE_TRANSFORM_CLASS (g_class); |
| 142 | |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 143 | gobject_class->finalize = gst_progress_report_finalize; |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 144 | gobject_class->set_property = gst_progress_report_set_property; |
| 145 | gobject_class->get_property = gst_progress_report_get_property; |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 146 | |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 147 | g_object_class_install_property (gobject_class, |
Luis de Bethencourt | 9391622 | 2015-04-27 11:22:11 +0100 | [diff] [blame] | 148 | PROP_UPDATE_FREQ, g_param_spec_int ("update-freq", "Update Frequency", |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 149 | "Number of seconds between reports when data is flowing", 1, G_MAXINT, |
Stefan Kost | d8167e3 | 2010-10-13 17:21:23 +0300 | [diff] [blame] | 150 | DEFAULT_UPDATE_FREQ, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 151 | |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 152 | g_object_class_install_property (gobject_class, |
Luis de Bethencourt | 9391622 | 2015-04-27 11:22:11 +0100 | [diff] [blame] | 153 | PROP_SILENT, g_param_spec_boolean ("silent", |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 154 | "Do not print output to stdout", "Do not print output to stdout", |
Stefan Kost | d8167e3 | 2010-10-13 17:21:23 +0300 | [diff] [blame] | 155 | DEFAULT_SILENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 156 | |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 157 | g_object_class_install_property (gobject_class, |
Luis de Bethencourt | 9391622 | 2015-04-27 11:22:11 +0100 | [diff] [blame] | 158 | PROP_DO_QUERY, g_param_spec_boolean ("do-query", |
Mark Nauwelaerts | 1d44962 | 2010-12-06 12:17:21 +0100 | [diff] [blame] | 159 | "Use a query instead of buffer metadata to determine stream position", |
| 160 | "Use a query instead of buffer metadata to determine stream position", |
| 161 | DEFAULT_DO_QUERY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); |
| 162 | |
| 163 | g_object_class_install_property (gobject_class, |
Luis de Bethencourt | 9391622 | 2015-04-27 11:22:11 +0100 | [diff] [blame] | 164 | PROP_FORMAT, g_param_spec_string ("format", "format", |
Stefan Kost | d8167e3 | 2010-10-13 17:21:23 +0300 | [diff] [blame] | 165 | "Format to use for the querying", DEFAULT_FORMAT, |
| 166 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 167 | |
Vineeth TM | 1071309 | 2016-03-04 10:30:12 +0900 | [diff] [blame] | 168 | gst_element_class_add_static_pad_template (element_class, |
| 169 | &progress_report_sink_template); |
| 170 | gst_element_class_add_static_pad_template (element_class, |
| 171 | &progress_report_src_template); |
Edward Hervey | a8effac | 2011-06-07 12:06:08 +0200 | [diff] [blame] | 172 | |
Tim-Philipp Müller | e09ae57 | 2012-04-10 00:51:41 +0100 | [diff] [blame] | 173 | gst_element_class_set_static_metadata (element_class, "Progress report", |
Edward Hervey | a8effac | 2011-06-07 12:06:08 +0200 | [diff] [blame] | 174 | "Testing", |
| 175 | "Periodically query and report on processing progress", |
| 176 | "Jan Schmidt <thaytan@mad.scientist.com>"); |
| 177 | |
Wim Taymans | 984a0b5 | 2011-07-22 21:19:45 +0200 | [diff] [blame] | 178 | gstbasetrans_class->sink_event = |
| 179 | GST_DEBUG_FUNCPTR (gst_progress_report_sink_event); |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 180 | gstbasetrans_class->transform_ip = |
| 181 | GST_DEBUG_FUNCPTR (gst_progress_report_transform_ip); |
| 182 | gstbasetrans_class->start = GST_DEBUG_FUNCPTR (gst_progress_report_start); |
| 183 | gstbasetrans_class->stop = GST_DEBUG_FUNCPTR (gst_progress_report_stop); |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | static void |
Edward Hervey | a8effac | 2011-06-07 12:06:08 +0200 | [diff] [blame] | 187 | gst_progress_report_init (GstProgressReport * report) |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 188 | { |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 189 | gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (report), TRUE); |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 190 | |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 191 | report->update_freq = DEFAULT_UPDATE_FREQ; |
| 192 | report->silent = DEFAULT_SILENT; |
Mark Nauwelaerts | 1d44962 | 2010-12-06 12:17:21 +0100 | [diff] [blame] | 193 | report->do_query = DEFAULT_DO_QUERY; |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 194 | report->format = g_strdup (DEFAULT_FORMAT); |
| 195 | } |
| 196 | |
Tim-Philipp Müller | b5ee422 | 2007-02-07 20:39:16 +0000 | [diff] [blame] | 197 | static void |
| 198 | gst_progress_report_post_progress (GstProgressReport * filter, |
| 199 | GstFormat format, gint64 current, gint64 total) |
| 200 | { |
| 201 | GstStructure *s = NULL; |
| 202 | |
| 203 | if (current >= 0 && total > 0) { |
| 204 | gdouble perc; |
| 205 | |
| 206 | perc = gst_util_guint64_to_gdouble (current) * 100.0 / |
| 207 | gst_util_guint64_to_gdouble (total); |
| 208 | perc = CLAMP (perc, 0.0, 100.0); |
| 209 | |
| 210 | /* we provide a "percent" field of integer type to stay compatible |
| 211 | * with qtdemux, but add a second "percent-double" field for those who |
| 212 | * want more precision and are too lazy to calculate it themselves */ |
| 213 | s = gst_structure_new ("progress", "percent", G_TYPE_INT, (gint) perc, |
| 214 | "percent-double", G_TYPE_DOUBLE, perc, "current", G_TYPE_INT64, current, |
| 215 | "total", G_TYPE_INT64, total, NULL); |
| 216 | } else if (current >= 0) { |
| 217 | s = gst_structure_new ("progress", "current", G_TYPE_INT64, current, NULL); |
| 218 | } |
| 219 | |
| 220 | if (s) { |
| 221 | GST_LOG_OBJECT (filter, "posting progress message: %" GST_PTR_FORMAT, s); |
| 222 | gst_structure_set (s, "format", GST_TYPE_FORMAT, format, NULL); |
| 223 | /* can't post it right here because we're holding the object lock */ |
| 224 | filter->pending_msg = gst_message_new_element (GST_OBJECT_CAST (filter), s); |
| 225 | } |
| 226 | } |
| 227 | |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 228 | static gboolean |
| 229 | gst_progress_report_do_query (GstProgressReport * filter, GstFormat format, |
Mark Nauwelaerts | 1d44962 | 2010-12-06 12:17:21 +0100 | [diff] [blame] | 230 | gint hh, gint mm, gint ss, GstBuffer * buf) |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 231 | { |
| 232 | const gchar *format_name = NULL; |
| 233 | GstPad *sink_pad; |
| 234 | gint64 cur, total; |
| 235 | |
| 236 | sink_pad = GST_BASE_TRANSFORM (filter)->sinkpad; |
| 237 | |
| 238 | GST_LOG_OBJECT (filter, "querying using format %d (%s)", format, |
| 239 | gst_format_get_name (format)); |
| 240 | |
Mark Nauwelaerts | 1d44962 | 2010-12-06 12:17:21 +0100 | [diff] [blame] | 241 | if (filter->do_query || !buf) { |
| 242 | GST_LOG_OBJECT (filter, "using upstream query"); |
Wim Taymans | e7918a5 | 2011-11-15 18:01:16 +0100 | [diff] [blame] | 243 | if (!gst_pad_peer_query_position (sink_pad, format, &cur) || |
| 244 | !gst_pad_peer_query_duration (sink_pad, format, &total)) { |
Mark Nauwelaerts | 1d44962 | 2010-12-06 12:17:21 +0100 | [diff] [blame] | 245 | return FALSE; |
| 246 | } |
| 247 | } else { |
| 248 | GstBaseTransform *base = GST_BASE_TRANSFORM (filter); |
| 249 | |
| 250 | GST_LOG_OBJECT (filter, "using buffer metadata"); |
Wim Taymans | 1c4ec02 | 2011-07-10 11:40:40 +0200 | [diff] [blame] | 251 | if (format == GST_FORMAT_TIME && base->segment.format == GST_FORMAT_TIME) { |
Mark Nauwelaerts | 1d44962 | 2010-12-06 12:17:21 +0100 | [diff] [blame] | 252 | cur = gst_segment_to_stream_time (&base->segment, format, |
| 253 | GST_BUFFER_TIMESTAMP (buf)); |
| 254 | total = base->segment.duration; |
William Manley | 77cdb23 | 2015-12-18 15:34:52 +0000 | [diff] [blame] | 255 | } else if (format == GST_FORMAT_BUFFERS) { |
| 256 | cur = filter->buffer_count; |
| 257 | total = -1; |
Mark Nauwelaerts | 1d44962 | 2010-12-06 12:17:21 +0100 | [diff] [blame] | 258 | } else { |
| 259 | return FALSE; |
| 260 | } |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | switch (format) { |
| 264 | case GST_FORMAT_BYTES: |
| 265 | format_name = "bytes"; |
| 266 | break; |
| 267 | case GST_FORMAT_BUFFERS: |
| 268 | format_name = "buffers"; |
| 269 | break; |
| 270 | case GST_FORMAT_PERCENT: |
| 271 | format_name = "percent"; |
| 272 | break; |
| 273 | case GST_FORMAT_TIME: |
| 274 | format_name = "seconds"; |
| 275 | cur /= GST_SECOND; |
| 276 | total /= GST_SECOND; |
| 277 | break; |
| 278 | case GST_FORMAT_DEFAULT:{ |
| 279 | GstCaps *caps; |
| 280 | |
| 281 | format_name = "bogounits"; |
Wim Taymans | 1c4ec02 | 2011-07-10 11:40:40 +0200 | [diff] [blame] | 282 | caps = gst_pad_get_current_caps (GST_BASE_TRANSFORM (filter)->sinkpad); |
| 283 | if (caps) { |
| 284 | if (gst_caps_is_fixed (caps) && !gst_caps_is_any (caps)) { |
| 285 | GstStructure *s = gst_caps_get_structure (caps, 0); |
| 286 | const gchar *mime_type = gst_structure_get_name (s); |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 287 | |
Wim Taymans | 1c4ec02 | 2011-07-10 11:40:40 +0200 | [diff] [blame] | 288 | if (g_str_has_prefix (mime_type, "video/") || |
| 289 | g_str_has_prefix (mime_type, "image/")) { |
| 290 | format_name = "frames"; |
| 291 | } else if (g_str_has_prefix (mime_type, "audio/")) { |
| 292 | format_name = "samples"; |
| 293 | } |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 294 | } |
Wim Taymans | 1c4ec02 | 2011-07-10 11:40:40 +0200 | [diff] [blame] | 295 | gst_caps_unref (caps); |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 296 | } |
| 297 | break; |
| 298 | } |
| 299 | default:{ |
| 300 | const GstFormatDefinition *details; |
| 301 | |
| 302 | details = gst_format_get_details (format); |
| 303 | if (details) { |
| 304 | format_name = details->nick; |
| 305 | } else { |
| 306 | format_name = "unknown"; |
| 307 | } |
| 308 | break; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | if (!filter->silent) { |
| 313 | if (total > 0) { |
| 314 | g_print ("%s (%02d:%02d:%02d): %" G_GINT64_FORMAT " / %" |
| 315 | G_GINT64_FORMAT " %s (%4.1f %%)\n", GST_OBJECT_NAME (filter), hh, |
| 316 | mm, ss, cur, total, format_name, (gdouble) cur / total * 100.0); |
| 317 | } else { |
| 318 | g_print ("%s (%02d:%02d:%02d): %" G_GINT64_FORMAT " %s\n", |
| 319 | GST_OBJECT_NAME (filter), hh, mm, ss, cur, format_name); |
| 320 | } |
| 321 | } |
| 322 | |
Tim-Philipp Müller | b5ee422 | 2007-02-07 20:39:16 +0000 | [diff] [blame] | 323 | gst_progress_report_post_progress (filter, format, cur, total); |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 324 | return TRUE; |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | static void |
Mark Nauwelaerts | 1d44962 | 2010-12-06 12:17:21 +0100 | [diff] [blame] | 328 | gst_progress_report_report (GstProgressReport * filter, GTimeVal cur_time, |
| 329 | GstBuffer * buf) |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 330 | { |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 331 | GstFormat try_formats[] = { GST_FORMAT_TIME, GST_FORMAT_BYTES, |
| 332 | GST_FORMAT_PERCENT, GST_FORMAT_BUFFERS, |
| 333 | GST_FORMAT_DEFAULT |
| 334 | }; |
Tim-Philipp Müller | b5ee422 | 2007-02-07 20:39:16 +0000 | [diff] [blame] | 335 | GstMessage *msg; |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 336 | GstFormat format = GST_FORMAT_UNDEFINED; |
| 337 | gboolean done = FALSE; |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 338 | glong run_time; |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 339 | gint hh, mm, ss; |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 340 | |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 341 | run_time = cur_time.tv_sec - filter->start_time.tv_sec; |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 342 | |
| 343 | hh = (run_time / 3600) % 100; |
| 344 | mm = (run_time / 60) % 60; |
| 345 | ss = (run_time % 60); |
| 346 | |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 347 | GST_OBJECT_LOCK (filter); |
Jan Schmidt | 4d97abb | 2004-05-21 13:28:24 +0000 | [diff] [blame] | 348 | |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 349 | if (filter->format != NULL && strcmp (filter->format, "auto") != 0) { |
| 350 | format = gst_format_get_by_nick (filter->format); |
| 351 | } |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 352 | |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 353 | if (format != GST_FORMAT_UNDEFINED) { |
Mark Nauwelaerts | 1d44962 | 2010-12-06 12:17:21 +0100 | [diff] [blame] | 354 | done = gst_progress_report_do_query (filter, format, hh, mm, ss, buf); |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 355 | } else { |
| 356 | gint i; |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 357 | |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 358 | for (i = 0; i < G_N_ELEMENTS (try_formats); ++i) { |
Mark Nauwelaerts | 1d44962 | 2010-12-06 12:17:21 +0100 | [diff] [blame] | 359 | done = gst_progress_report_do_query (filter, try_formats[i], hh, mm, ss, |
| 360 | buf); |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 361 | if (done) |
| 362 | break; |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 363 | } |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 364 | } |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 365 | |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 366 | if (!done && !filter->silent) { |
| 367 | g_print ("%s (%2d:%2d:%2d): Could not query position and/or duration\n", |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 368 | GST_OBJECT_NAME (filter), hh, mm, ss); |
| 369 | } |
| 370 | |
Tim-Philipp Müller | b5ee422 | 2007-02-07 20:39:16 +0000 | [diff] [blame] | 371 | msg = filter->pending_msg; |
| 372 | filter->pending_msg = NULL; |
Andy Wingo | 0d470f5 | 2005-11-21 16:36:05 +0000 | [diff] [blame] | 373 | GST_OBJECT_UNLOCK (filter); |
Tim-Philipp Müller | b5ee422 | 2007-02-07 20:39:16 +0000 | [diff] [blame] | 374 | |
Tim-Philipp Müller | 106db1b | 2007-04-20 17:25:50 +0000 | [diff] [blame] | 375 | if (msg) { |
| 376 | gst_element_post_message (GST_ELEMENT_CAST (filter), msg); |
| 377 | } |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | static gboolean |
Wim Taymans | 984a0b5 | 2011-07-22 21:19:45 +0200 | [diff] [blame] | 381 | gst_progress_report_sink_event (GstBaseTransform * trans, GstEvent * event) |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 382 | { |
| 383 | GstProgressReport *filter; |
| 384 | |
| 385 | filter = GST_PROGRESS_REPORT (trans); |
| 386 | |
Wim Taymans | 984a0b5 | 2011-07-22 21:19:45 +0200 | [diff] [blame] | 387 | switch (GST_EVENT_TYPE (event)) { |
| 388 | case GST_EVENT_EOS: |
| 389 | { |
| 390 | GTimeVal cur_time; |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 391 | |
Wim Taymans | 984a0b5 | 2011-07-22 21:19:45 +0200 | [diff] [blame] | 392 | g_get_current_time (&cur_time); |
| 393 | gst_progress_report_report (filter, cur_time, NULL); |
| 394 | break; |
| 395 | } |
| 396 | default: |
| 397 | break; |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 398 | } |
Wim Taymans | 984a0b5 | 2011-07-22 21:19:45 +0200 | [diff] [blame] | 399 | return GST_BASE_TRANSFORM_CLASS (parent_class)->sink_event (trans, event); |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | static GstFlowReturn |
| 403 | gst_progress_report_transform_ip (GstBaseTransform * trans, GstBuffer * buf) |
| 404 | { |
| 405 | GstProgressReport *filter; |
| 406 | gboolean need_update; |
| 407 | GTimeVal cur_time; |
| 408 | |
| 409 | g_get_current_time (&cur_time); |
| 410 | |
| 411 | filter = GST_PROGRESS_REPORT (trans); |
| 412 | |
| 413 | /* Check if update_freq seconds have passed since the last update */ |
Andy Wingo | 0d470f5 | 2005-11-21 16:36:05 +0000 | [diff] [blame] | 414 | GST_OBJECT_LOCK (filter); |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 415 | need_update = |
| 416 | ((cur_time.tv_sec - filter->last_report.tv_sec) >= filter->update_freq); |
William Manley | 77cdb23 | 2015-12-18 15:34:52 +0000 | [diff] [blame] | 417 | filter->buffer_count++; |
Andy Wingo | 0d470f5 | 2005-11-21 16:36:05 +0000 | [diff] [blame] | 418 | GST_OBJECT_UNLOCK (filter); |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 419 | |
| 420 | if (need_update) { |
Mark Nauwelaerts | 1d44962 | 2010-12-06 12:17:21 +0100 | [diff] [blame] | 421 | gst_progress_report_report (filter, cur_time, buf); |
Andy Wingo | 0d470f5 | 2005-11-21 16:36:05 +0000 | [diff] [blame] | 422 | GST_OBJECT_LOCK (filter); |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 423 | filter->last_report = cur_time; |
Andy Wingo | 0d470f5 | 2005-11-21 16:36:05 +0000 | [diff] [blame] | 424 | GST_OBJECT_UNLOCK (filter); |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | return GST_FLOW_OK; |
| 428 | } |
| 429 | |
| 430 | static gboolean |
| 431 | gst_progress_report_start (GstBaseTransform * trans) |
| 432 | { |
| 433 | GstProgressReport *filter; |
| 434 | |
| 435 | filter = GST_PROGRESS_REPORT (trans); |
| 436 | |
| 437 | g_get_current_time (&filter->last_report); |
| 438 | filter->start_time = filter->last_report; |
William Manley | 77cdb23 | 2015-12-18 15:34:52 +0000 | [diff] [blame] | 439 | filter->buffer_count = 0; |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 440 | |
| 441 | return TRUE; |
| 442 | } |
| 443 | |
| 444 | static gboolean |
| 445 | gst_progress_report_stop (GstBaseTransform * trans) |
| 446 | { |
| 447 | /* anything we should be doing here? */ |
| 448 | return TRUE; |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | static void |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 452 | gst_progress_report_set_property (GObject * object, guint prop_id, |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 453 | const GValue * value, GParamSpec * pspec) |
| 454 | { |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 455 | GstProgressReport *filter; |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 456 | |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 457 | filter = GST_PROGRESS_REPORT (object); |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 458 | |
| 459 | switch (prop_id) { |
Luis de Bethencourt | 9391622 | 2015-04-27 11:22:11 +0100 | [diff] [blame] | 460 | case PROP_UPDATE_FREQ: |
Andy Wingo | 0d470f5 | 2005-11-21 16:36:05 +0000 | [diff] [blame] | 461 | GST_OBJECT_LOCK (filter); |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 462 | filter->update_freq = g_value_get_int (value); |
Andy Wingo | 0d470f5 | 2005-11-21 16:36:05 +0000 | [diff] [blame] | 463 | GST_OBJECT_UNLOCK (filter); |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 464 | break; |
Luis de Bethencourt | 9391622 | 2015-04-27 11:22:11 +0100 | [diff] [blame] | 465 | case PROP_SILENT: |
Andy Wingo | 0d470f5 | 2005-11-21 16:36:05 +0000 | [diff] [blame] | 466 | GST_OBJECT_LOCK (filter); |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 467 | filter->silent = g_value_get_boolean (value); |
Andy Wingo | 0d470f5 | 2005-11-21 16:36:05 +0000 | [diff] [blame] | 468 | GST_OBJECT_UNLOCK (filter); |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 469 | break; |
Luis de Bethencourt | 9391622 | 2015-04-27 11:22:11 +0100 | [diff] [blame] | 470 | case PROP_DO_QUERY: |
Mark Nauwelaerts | 1d44962 | 2010-12-06 12:17:21 +0100 | [diff] [blame] | 471 | GST_OBJECT_LOCK (filter); |
| 472 | filter->do_query = g_value_get_boolean (value); |
| 473 | GST_OBJECT_UNLOCK (filter); |
| 474 | break; |
Luis de Bethencourt | 9391622 | 2015-04-27 11:22:11 +0100 | [diff] [blame] | 475 | case PROP_FORMAT: |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 476 | GST_OBJECT_LOCK (filter); |
| 477 | g_free (filter->format); |
| 478 | filter->format = g_value_dup_string (value); |
| 479 | if (filter->format == NULL) |
| 480 | filter->format = g_strdup ("auto"); |
| 481 | GST_OBJECT_UNLOCK (filter); |
| 482 | break; |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 483 | default: |
| 484 | break; |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | static void |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 489 | gst_progress_report_get_property (GObject * object, guint prop_id, |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 490 | GValue * value, GParamSpec * pspec) |
| 491 | { |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 492 | GstProgressReport *filter; |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 493 | |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 494 | filter = GST_PROGRESS_REPORT (object); |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 495 | |
| 496 | switch (prop_id) { |
Luis de Bethencourt | 9391622 | 2015-04-27 11:22:11 +0100 | [diff] [blame] | 497 | case PROP_UPDATE_FREQ: |
Andy Wingo | 0d470f5 | 2005-11-21 16:36:05 +0000 | [diff] [blame] | 498 | GST_OBJECT_LOCK (filter); |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 499 | g_value_set_int (value, filter->update_freq); |
Andy Wingo | 0d470f5 | 2005-11-21 16:36:05 +0000 | [diff] [blame] | 500 | GST_OBJECT_UNLOCK (filter); |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 501 | break; |
Luis de Bethencourt | 9391622 | 2015-04-27 11:22:11 +0100 | [diff] [blame] | 502 | case PROP_SILENT: |
Andy Wingo | 0d470f5 | 2005-11-21 16:36:05 +0000 | [diff] [blame] | 503 | GST_OBJECT_LOCK (filter); |
Tim-Philipp Müller | 2fa12d1 | 2005-10-05 11:38:29 +0000 | [diff] [blame] | 504 | g_value_set_boolean (value, filter->silent); |
Andy Wingo | 0d470f5 | 2005-11-21 16:36:05 +0000 | [diff] [blame] | 505 | GST_OBJECT_UNLOCK (filter); |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 506 | break; |
Luis de Bethencourt | 9391622 | 2015-04-27 11:22:11 +0100 | [diff] [blame] | 507 | case PROP_DO_QUERY: |
Mark Nauwelaerts | 1d44962 | 2010-12-06 12:17:21 +0100 | [diff] [blame] | 508 | GST_OBJECT_LOCK (filter); |
| 509 | g_value_set_boolean (value, filter->do_query); |
| 510 | GST_OBJECT_UNLOCK (filter); |
| 511 | break; |
Luis de Bethencourt | 9391622 | 2015-04-27 11:22:11 +0100 | [diff] [blame] | 512 | case PROP_FORMAT: |
Tim-Philipp Müller | b3debb8 | 2006-04-21 17:15:29 +0000 | [diff] [blame] | 513 | GST_OBJECT_LOCK (filter); |
| 514 | g_value_set_string (value, filter->format); |
| 515 | GST_OBJECT_UNLOCK (filter); |
| 516 | break; |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 517 | default: |
| 518 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 519 | break; |
| 520 | } |
| 521 | } |