multifile: error out if no filename was set
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-good / gst / multifile / gstimagesequencesrc.c
1 /* GStreamer
2  * Copyright (C) 2006 David A. Schleef ds@schleef.org
3  * Copyright (C) 2019 Cesar Fabian Orccon Chipana
4  * Copyright (C) 2020 Thibault Saunier <tsaunier@igalia.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin Street, Suite 500,
19  * Boston, MA 02110-1335, USA.
20  */
21
22 /**
23  * SECTION:element-imagesequencesrc
24  *
25  * Stream image sequences from image files.
26  *
27  * ```
28  * gst-launch-1.0 imagesequencesrc location=image-%05d.jpg start-index=1 stop-index=50 framerate=24/1 ! decodebin ! videoconvert ! autovideosink
29  * ```
30  *
31  * This elements implements the #GstURIHandler interface meaning that you can use it with playbin,
32  * (make sure to quote the URI for the filename pattern, like: `%2505d` instead of the `%05d` you would use
33  * when dealing with the location).
34  *
35  * Note that you can pass the #imagesequencesrc:framerate, #imagesequencesrc:start-index and #imagesequencesrc:stop-index
36  * properties directly in the URI using its 'query' component, for example:
37  *
38  * ```
39  * gst-launch-1.0 playbin uri="imagesequence://path/to/image-%2505d.jpeg?start-index=0&framerate=30/1"
40  * ```
41  */
42
43 #ifdef HAVE_CONFIG_H
44 #  include "config.h"
45 #endif
46
47 #include <gst/gst.h>
48 #include <gst/base/gsttypefindhelper.h>
49 #include <glib/gi18n-lib.h>
50
51 #include "gstimagesequencesrc.h"
52
53 #define LOCK(self) (g_rec_mutex_lock (&self->fields_lock))
54 #define UNLOCK(self) (g_rec_mutex_unlock (&self->fields_lock))
55
56 static GstFlowReturn gst_image_sequence_src_create (GstPushSrc * src,
57     GstBuffer ** buffer);
58
59
60 static void gst_image_sequence_src_set_property (GObject * object,
61     guint prop_id, const GValue * value, GParamSpec * pspec);
62 static void gst_image_sequence_src_get_property (GObject * object,
63     guint prop_id, GValue * value, GParamSpec * pspec);
64 static GstCaps *gst_image_sequence_src_getcaps (GstBaseSrc * src,
65     GstCaps * filter);
66 static gboolean gst_image_sequence_src_query (GstBaseSrc * src,
67     GstQuery * query);
68 static void gst_image_sequence_src_set_caps (GstImageSequenceSrc * self,
69     GstCaps * caps);
70 static void gst_image_sequence_src_set_duration (GstImageSequenceSrc * self);
71 static gint gst_image_sequence_src_count_frames (GstImageSequenceSrc * self,
72     gboolean can_read);
73
74
75 static GstStaticPadTemplate gst_image_sequence_src_pad_template =
76 GST_STATIC_PAD_TEMPLATE ("src",
77     GST_PAD_SRC,
78     GST_PAD_ALWAYS,
79     GST_STATIC_CAPS_ANY);
80
81 GST_DEBUG_CATEGORY_STATIC (gst_image_sequence_src_debug);
82 #define GST_CAT_DEFAULT gst_image_sequence_src_debug
83
84 enum
85 {
86   PROP_0,
87   PROP_LOCATION,
88   PROP_START_INDEX,
89   PROP_STOP_INDEX,
90   PROP_FRAMERATE
91 };
92
93 #define DEFAULT_LOCATION "%05d"
94 #define DEFAULT_START_INDEX 0
95 #define DEFAULT_STOP_INDEX -1
96 #define DEFAULT_FRAMERATE 30
97
98 /* Call with LOCK taken */
99 static gboolean
100 gst_image_sequence_src_set_location (GstImageSequenceSrc * self,
101     const gchar * location)
102 {
103   g_free (self->path);
104   if (location != NULL)
105     self->path = g_strdup (location);
106   else
107     self->path = NULL;
108
109   return TRUE;
110 }
111
112 /*** GSTURIHANDLER INTERFACE *************************************************/
113
114 static GstURIType
115 gst_image_sequence_src_uri_get_type (GType type)
116 {
117   return GST_URI_SRC;
118 }
119
120 static const gchar *const *
121 gst_image_sequence_src_uri_get_protocols (GType type)
122 {
123   static const gchar *protocols[] = { "imagesequence", NULL };
124
125   return protocols;
126 }
127
128 static gchar *
129 gst_image_sequence_src_uri_get_uri (GstURIHandler * handler)
130 {
131   GstImageSequenceSrc *self = GST_IMAGE_SEQUENCE_SRC (handler);
132   gchar *uri = NULL;
133
134   LOCK (self);
135   if (self->uri)
136     uri = gst_uri_to_string (self->uri);
137   else if (self->path)
138     uri = gst_uri_construct ("imagesequence", self->path);
139   UNLOCK (self);
140
141   return uri;
142 }
143
144 static gboolean
145 gst_image_sequence_src_uri_set_uri (GstURIHandler * handler, const gchar * uri,
146     GError ** err)
147 {
148   gchar *hostname = NULL, *location = NULL, *path, *tmp;
149   gboolean ret = FALSE;
150   GstImageSequenceSrc *self = GST_IMAGE_SEQUENCE_SRC (handler);
151   GstUri *ruri = gst_uri_from_string (uri);
152   GHashTable *query = NULL;
153
154   if (!ruri) {
155     g_set_error (err, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
156         "imagesequencesrc URI is invalid: '%s'", uri);
157     goto beach;
158   }
159
160
161   LOCK (self);
162   g_clear_pointer (&self->uri, gst_uri_unref);
163   self->uri = ruri;
164   path = gst_uri_get_path (ruri);
165   tmp = gst_filename_to_uri (path, err);
166   location = g_filename_from_uri (tmp, &hostname, err);
167   g_free (tmp);
168   g_free (path);
169   query = gst_uri_get_query_table (ruri);
170   if (!location || (err != NULL && *err != NULL)) {
171     GST_WARNING_OBJECT (self, "Invalid URI '%s' for imagesequencesrc: %s", uri,
172         (err != NULL && *err != NULL) ? (*err)->message : "unknown error");
173     goto beach;
174   }
175
176   if (hostname && strcmp (hostname, "localhost")) {
177     /* Only 'localhost' is permitted */
178     GST_WARNING_OBJECT (self, "Invalid hostname '%s' for filesrc", hostname);
179     g_set_error (err, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
180         "File URI with invalid hostname '%s'", hostname);
181     goto beach;
182   }
183 #ifdef G_OS_WIN32
184   /* Unfortunately, g_filename_from_uri() doesn't handle some UNC paths
185    * correctly on windows, it leaves them with an extra backslash
186    * at the start if they're of the mozilla-style file://///host/path/file
187    * form. Correct this.
188    */
189   if (location[0] == '\\' && location[1] == '\\' && location[2] == '\\')
190     memmove (location, location + 1, strlen (location + 1) + 1);
191 #endif
192
193   ret = gst_image_sequence_src_set_location (self, location);
194
195   if (query) {
196     GHashTableIter iter;
197     gpointer key, value;
198
199     g_hash_table_iter_init (&iter, query);
200     while (g_hash_table_iter_next (&iter, &key, &value)) {
201       GST_INFO_OBJECT (self, "Setting property from URI: %s=%s", (gchar *) key,
202           (gchar *) value);
203       gst_util_set_object_arg (G_OBJECT (self), key, value);
204     }
205   }
206
207 beach:
208   UNLOCK (self);
209
210   g_free (location);
211   g_free (hostname);
212   g_clear_pointer (&query, g_hash_table_unref);
213
214   return ret;
215 }
216
217 static void
218 gst_image_sequence_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
219 {
220   GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
221
222   iface->get_type = gst_image_sequence_src_uri_get_type;
223   iface->get_protocols = gst_image_sequence_src_uri_get_protocols;
224   iface->get_uri = gst_image_sequence_src_uri_get_uri;
225   iface->set_uri = gst_image_sequence_src_uri_set_uri;
226 }
227
228 #define gst_image_sequence_src_parent_class parent_class
229 #define _do_init \
230   G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, gst_image_sequence_src_uri_handler_init); \
231   GST_DEBUG_CATEGORY_INIT (gst_image_sequence_src_debug, "imagesequencesrc", \
232       0, "imagesequencesrc element");
233 G_DEFINE_TYPE_WITH_CODE (GstImageSequenceSrc, gst_image_sequence_src,
234     GST_TYPE_PUSH_SRC, _do_init);
235 GST_ELEMENT_REGISTER_DEFINE (imagesequencesrc, "imagesequencesrc",
236     GST_RANK_NONE, gst_image_sequence_src_get_type ());
237
238 static gboolean
239 is_seekable (GstBaseSrc * src)
240 {
241   GstImageSequenceSrc *self = GST_IMAGE_SEQUENCE_SRC (src);
242
243   if ((self->n_frames != 0) && (self->fps_n) && (self->fps_d))
244     return TRUE;
245   return FALSE;
246 }
247
248
249 static gboolean
250 do_seek (GstBaseSrc * bsrc, GstSegment * segment)
251 {
252   GstImageSequenceSrc *self;
253
254   self = GST_IMAGE_SEQUENCE_SRC (bsrc);
255
256   self->reverse = segment->rate < 0;
257   if (self->reverse) {
258     segment->time = segment->start;
259   }
260
261   self->index =
262       self->start_index +
263       segment->position * self->fps_n / (self->fps_d * GST_SECOND);
264
265   return TRUE;
266 }
267
268 static void
269 gst_image_sequence_src_finalize (GObject * object)
270 {
271   GstImageSequenceSrc *self = GST_IMAGE_SEQUENCE_SRC (object);
272
273   g_clear_pointer (&self->path, g_free);
274   g_rec_mutex_clear (&self->fields_lock);
275
276   G_OBJECT_CLASS (parent_class)->finalize (object);
277 }
278
279 static void
280 gst_image_sequence_src_dispose (GObject * object)
281 {
282   GstImageSequenceSrc *self = GST_IMAGE_SEQUENCE_SRC (object);
283
284   gst_clear_caps (&self->caps);
285   g_clear_pointer (&self->uri, gst_uri_unref);
286
287   G_OBJECT_CLASS (parent_class)->dispose (object);
288 }
289
290 static void
291 gst_image_sequence_src_class_init (GstImageSequenceSrcClass * klass)
292 {
293   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
294   GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
295   GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass);
296   GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass);
297
298   gobject_class->set_property = gst_image_sequence_src_set_property;
299   gobject_class->get_property = gst_image_sequence_src_get_property;
300
301
302   g_object_class_install_property (gobject_class, PROP_LOCATION,
303       g_param_spec_string ("location", "File Location",
304           "Pattern to create file names of input files.  File names are "
305           "created by calling sprintf() with the pattern and the current "
306           "index.", DEFAULT_LOCATION,
307           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
308   g_object_class_install_property (gobject_class, PROP_START_INDEX,
309       g_param_spec_int ("start-index", "Start Index",
310           "Start value of index.  The initial value of index can be set "
311           "either by setting index or start-index.  When the end of the loop "
312           "is reached, the index will be set to the value start-index.",
313           0, INT_MAX, DEFAULT_START_INDEX,
314           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
315   g_object_class_install_property (gobject_class, PROP_STOP_INDEX,
316       g_param_spec_int ("stop-index", "Stop Index",
317           "Stop value of index.  The special value -1 means no stop.",
318           -1, INT_MAX, DEFAULT_STOP_INDEX,
319           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
320   g_object_class_install_property (gobject_class, PROP_FRAMERATE,
321       gst_param_spec_fraction ("framerate", "Framerate",
322           "The output framerate.",
323           1, 1, G_MAXINT, 1, DEFAULT_FRAMERATE, 1,
324           G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
325
326   gobject_class->finalize = gst_image_sequence_src_finalize;
327   gobject_class->dispose = gst_image_sequence_src_dispose;
328
329   gstbasesrc_class->get_caps = gst_image_sequence_src_getcaps;
330   gstbasesrc_class->query = gst_image_sequence_src_query;
331   gstbasesrc_class->is_seekable = is_seekable;
332   gstbasesrc_class->do_seek = do_seek;
333
334   gstpushsrc_class->create = gst_image_sequence_src_create;
335
336   gst_element_class_add_static_pad_template (gstelement_class,
337       &gst_image_sequence_src_pad_template);
338   gst_element_class_set_static_metadata (gstelement_class,
339       "Image Sequence Source", "Source/File/Video",
340       "Create a video stream from a sequence of image files",
341       "Cesar Fabian Orccon Chipana <cfoch.fabian@gmail.com>\n"
342       "Thibault Saunier <tsaunier@igalia.com>");
343 }
344
345 static void
346 gst_image_sequence_src_init (GstImageSequenceSrc * self)
347 {
348   GstBaseSrc *bsrc;
349
350   GST_DEBUG_CATEGORY_INIT (gst_image_sequence_src_debug, "imagesequencesrc", 0,
351       "imagesequencesrc element");
352
353   bsrc = GST_BASE_SRC (self);
354   gst_base_src_set_format (bsrc, GST_FORMAT_TIME);
355
356   g_rec_mutex_init (&self->fields_lock);
357   self->start_index = DEFAULT_START_INDEX;
358   self->index = 0;
359   self->stop_index = DEFAULT_STOP_INDEX;
360   self->path = g_strdup (DEFAULT_LOCATION);
361   self->caps = NULL;
362   self->n_frames = 0;
363   self->fps_n = 30;
364   self->fps_d = 1;
365 }
366
367 static GstCaps *
368 gst_image_sequence_src_getcaps (GstBaseSrc * src, GstCaps * filter)
369 {
370   GstImageSequenceSrc *self = GST_IMAGE_SEQUENCE_SRC (src);
371
372   GST_DEBUG_OBJECT (self, "returning %" GST_PTR_FORMAT, self->caps);
373
374   if (filter) {
375     if (self->caps)
376       return gst_caps_intersect_full (filter, self->caps,
377           GST_CAPS_INTERSECT_FIRST);
378     else
379       return gst_caps_ref (filter);
380   }
381
382   return gst_caps_new_any ();
383 }
384
385 static gboolean
386 gst_image_sequence_src_query (GstBaseSrc * bsrc, GstQuery * query)
387 {
388   gboolean ret;
389   GstImageSequenceSrc *self;
390
391   self = GST_IMAGE_SEQUENCE_SRC (bsrc);
392
393   switch (GST_QUERY_TYPE (query)) {
394     case GST_QUERY_DURATION:
395     {
396       GstFormat format;
397
398       gst_query_parse_duration (query, &format, NULL);
399
400       switch (format) {
401         case GST_FORMAT_TIME:
402           LOCK (self);
403           if (self->n_frames <= 0) {
404             gst_image_sequence_src_count_frames (self, FALSE);
405             gst_image_sequence_src_set_duration (self);
406           }
407
408           if (self->n_frames > 0)
409             gst_query_set_duration (query, format, self->duration);
410           UNLOCK (self);
411
412           ret = TRUE;
413           break;
414         default:
415           ret = GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
416       }
417       break;
418     }
419     default:
420       ret = GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
421       break;
422   }
423
424   return ret;
425 }
426
427 static void
428 gst_image_sequence_src_set_property (GObject * object, guint prop_id,
429     const GValue * value, GParamSpec * pspec)
430 {
431   GstImageSequenceSrc *self = GST_IMAGE_SEQUENCE_SRC (object);
432
433   LOCK (self);
434   switch (prop_id) {
435     case PROP_LOCATION:
436       gst_image_sequence_src_set_location (self, g_value_get_string (value));
437       break;
438     case PROP_START_INDEX:
439       self->start_index = g_value_get_int (value);
440       gst_image_sequence_src_count_frames (self, FALSE);
441       break;
442     case PROP_STOP_INDEX:
443       self->stop_index = g_value_get_int (value);
444       gst_image_sequence_src_count_frames (self, FALSE);
445       break;
446     case PROP_FRAMERATE:
447       self->fps_n = gst_value_get_fraction_numerator (value);
448       self->fps_d = gst_value_get_fraction_denominator (value);
449       break;
450     default:
451       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
452       break;
453   }
454   UNLOCK (self);
455 }
456
457 static void
458 gst_image_sequence_src_get_property (GObject * object, guint prop_id,
459     GValue * value, GParamSpec * pspec)
460 {
461   GstImageSequenceSrc *self = GST_IMAGE_SEQUENCE_SRC (object);
462
463   LOCK (self);
464   switch (prop_id) {
465     case PROP_LOCATION:
466       g_value_set_string (value, self->path);
467       break;
468     case PROP_START_INDEX:
469       g_value_set_int (value, self->start_index);
470       break;
471     case PROP_STOP_INDEX:
472       g_value_set_int (value, self->stop_index);
473       break;
474     case PROP_FRAMERATE:
475       self->fps_n = gst_value_get_fraction_numerator (value);
476       self->fps_d = gst_value_get_fraction_denominator (value);
477       GST_DEBUG_OBJECT (self, "Set (framerate) property to (%d/%d)",
478           self->fps_n, self->fps_d);
479       break;
480     default:
481       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
482       break;
483   }
484   UNLOCK (self);
485 }
486
487 /* Call with LOCK */
488 static gint
489 gst_image_sequence_src_count_frames (GstImageSequenceSrc * self,
490     gboolean can_read)
491 {
492   if (can_read && self->stop_index < 0 && self->path) {
493     gint i;
494
495     for (i = self->start_index;; i++) {
496       gchar *filename = g_strdup_printf (self->path, i);
497
498       if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
499         i--;
500         g_free (filename);
501         break;
502       }
503
504       g_free (filename);
505     }
506     if (i > self->start_index)
507       self->stop_index = i;
508   }
509
510   if (self->stop_index >= self->start_index)
511     self->n_frames = self->stop_index - self->start_index + 1;
512   return self->n_frames;
513 }
514
515 static void
516 gst_image_sequence_src_set_caps (GstImageSequenceSrc * self, GstCaps * caps)
517 {
518   GstCaps *new_caps;
519
520   g_assert (caps != NULL);
521   new_caps = gst_caps_copy (caps);
522
523   if (self->n_frames > 0) {
524     GValue fps = G_VALUE_INIT;
525     g_value_init (&fps, GST_TYPE_FRACTION);
526     gst_value_set_fraction (&fps, self->fps_n, self->fps_d);
527     gst_caps_set_value (new_caps, "framerate", &fps);
528     g_value_unset (&fps);
529   }
530
531   gst_caps_replace (&self->caps, new_caps);
532   gst_pad_set_caps (GST_BASE_SRC_PAD (self), new_caps);
533
534   GST_DEBUG_OBJECT (self, "Setting new caps: %" GST_PTR_FORMAT, new_caps);
535
536   gst_caps_unref (new_caps);
537 }
538
539 /* Call with LOCK */
540 static void
541 gst_image_sequence_src_set_duration (GstImageSequenceSrc * self)
542 {
543   GstClockTime old_duration = self->duration;
544
545   if (self->n_frames <= 0)
546     return;
547
548   /* Calculate duration */
549   self->duration =
550       gst_util_uint64_scale (GST_SECOND * self->n_frames, self->fps_d,
551       self->fps_n);
552
553   if (self->duration != old_duration) {
554     UNLOCK (self);
555     gst_element_post_message (GST_ELEMENT (self),
556         gst_message_new_duration_changed (GST_OBJECT (self)));
557     LOCK (self);
558   }
559 }
560
561 /* Call with LOCK */
562 static gchar *
563 gst_image_sequence_src_get_filename (GstImageSequenceSrc * self)
564 {
565   gchar *filename;
566
567   GST_DEBUG ("Reading filename at index %d.", self->index);
568   if (self->path != NULL) {
569     filename = g_strdup_printf (self->path, self->index);
570   } else {
571     GST_WARNING_OBJECT (self, "No filename location set!");
572     filename = NULL;
573   }
574
575   return filename;
576 }
577
578 static GstFlowReturn
579 gst_image_sequence_src_create (GstPushSrc * src, GstBuffer ** buffer)
580 {
581   GstImageSequenceSrc *self;
582   gsize size;
583   gchar *data;
584   gchar *filename;
585   GstBuffer *buf;
586   gboolean ret;
587   GError *error = NULL;
588   gint fps_n, fps_d, start_index, stop_index;
589
590   self = GST_IMAGE_SEQUENCE_SRC (src);
591
592   LOCK (self);
593   start_index = self->start_index;
594   stop_index = self->stop_index;
595   if (self->index > stop_index && stop_index > 0) {
596     UNLOCK (self);
597
598     return GST_FLOW_EOS;
599   }
600
601   if (self->index < self->start_index)
602     self->index = self->start_index;
603
604   g_assert (start_index <= self->index &&
605       (self->index <= stop_index || stop_index <= 0));
606
607   filename = gst_image_sequence_src_get_filename (self);
608   fps_n = self->fps_n;
609   fps_d = self->fps_d;
610   UNLOCK (self);
611
612   if (!filename)
613     goto error_no_filename;
614
615   ret = g_file_get_contents (filename, &data, &size, &error);
616   if (!ret)
617     goto handle_error;
618
619   buf = gst_buffer_new_wrapped (data, size);
620
621   if (!self->caps) {
622     GstCaps *caps;
623     caps = gst_type_find_helper_for_buffer (NULL, buf, NULL);
624     if (!caps) {
625       GST_ELEMENT_ERROR (self, STREAM, TYPE_NOT_FOUND, (NULL),
626           ("Could not determine image type."));
627
628       return GST_FLOW_NOT_SUPPORTED;
629     }
630
631     LOCK (self);
632     gst_image_sequence_src_count_frames (self, TRUE);
633     gst_image_sequence_src_set_duration (self);
634     UNLOCK (self);
635
636     gst_image_sequence_src_set_caps (self, caps);
637     gst_caps_unref (caps);
638   }
639
640   GST_BUFFER_PTS (buf) =
641       gst_util_uint64_scale_ceil ((self->index - start_index) * GST_SECOND,
642       fps_d, fps_n);
643   GST_BUFFER_DURATION (buf) = gst_util_uint64_scale (GST_SECOND, fps_d, fps_n);
644   GST_BUFFER_OFFSET (buf) = self->index - start_index;
645   GST_LOG_OBJECT (self, "index: %d, %s - %" GST_PTR_FORMAT, self->index,
646       filename, buf);
647
648   g_free (filename);
649   *buffer = buf;
650
651   self->index += self->reverse ? -1 : 1;
652   return GST_FLOW_OK;
653
654 error_no_filename:
655   {
656     GST_ELEMENT_ERROR (self, RESOURCE, NOT_FOUND,
657         (_("No file name specified for reading.")), (NULL));
658     return GST_FLOW_ERROR;
659   }
660 handle_error:
661   {
662     if (error != NULL) {
663       GST_ELEMENT_ERROR (self, RESOURCE, READ,
664           ("Error while reading from file \"%s\".", filename),
665           ("%s", error->message));
666       g_error_free (error);
667     } else {
668       GST_ELEMENT_ERROR (self, RESOURCE, READ,
669           ("Error while reading from file \"%s\".", filename),
670           ("%s", g_strerror (errno)));
671     }
672     g_free (filename);
673     return GST_FLOW_ERROR;
674   }
675 }