lock bufferfree func, fix potential segfault
[gst-plugin-dreamsource.git] / src / gstdreamaudiosource.c
1 /*
2  * GStreamer dreamaudiosource
3  * Copyright 2014-2015 Andreas Frisch <fraxinas@opendreambox.org>
4  *
5  * This program is licensed under the Creative Commons
6  * Attribution-NonCommercial-ShareAlike 3.0 Unported
7  * License. To view a copy of this license, visit
8  * http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to
9  * Creative Commons,559 Nathan Abbott Way,Stanford,California 94305,USA.
10  *
11  * Alternatively, this program may be distributed and executed on
12  * hardware which is licensed by Dream Property GmbH.
13  *
14  * This program is NOT free software. It is open source, you are allowed
15  * to modify it (if you keep the license), but it may not be commercially
16  * distributed other than under the conditions noted above.
17  */
18
19 #ifdef HAVE_CONFIG_H
20 #include <config.h>
21 #endif
22
23 #include <gst/gst.h>
24 #include <sys/poll.h>
25 #include <sys/socket.h>
26 #include "gstdreamaudiosource.h"
27
28 #define CONTROL_STOP            'S'     /* stop the select call */
29 #define CONTROL_SOCKETS(src)   src->control_sock
30 #define WRITE_SOCKET(src)      src->control_sock[1]
31 #define READ_SOCKET(src)       src->control_sock[0]
32
33 #define SEND_COMMAND(src, command)          \
34 G_STMT_START {                              \
35   int G_GNUC_UNUSED _res; unsigned char c; c = command;   \
36   _res = write (WRITE_SOCKET(src), &c, 1);  \
37 } G_STMT_END
38
39 #define READ_COMMAND(src, command, res)        \
40 G_STMT_START {                                 \
41   res = read(READ_SOCKET(src), &command, 1);   \
42 } G_STMT_END
43
44
45 GST_DEBUG_CATEGORY_STATIC (dreamaudiosource_debug);
46 #define GST_CAT_DEFAULT dreamaudiosource_debug
47
48 enum
49 {
50         SIGNAL_GET_BASE_PTS,
51         LAST_SIGNAL
52 };
53 enum
54 {
55         ARG_0,
56         ARG_BITRATE,
57 };
58
59 static guint gst_dreamaudiosource_signals[LAST_SIGNAL] = { 0 };
60
61 #define DEFAULT_BITRATE 128
62
63 static GstStaticPadTemplate srctemplate =
64     GST_STATIC_PAD_TEMPLATE ("src",
65         GST_PAD_SRC,
66         GST_PAD_ALWAYS,
67         GST_STATIC_CAPS ("audio/mpeg, "
68         "mpegversion = 4,"
69         "stream-format = (string) adts")
70     );
71
72 #define gst_dreamaudiosource_parent_class parent_class
73 G_DEFINE_TYPE (GstDreamAudioSource, gst_dreamaudiosource, GST_TYPE_PUSH_SRC);
74
75 static GstCaps *gst_dreamaudiosource_getcaps (GstBaseSrc * psrc, GstCaps * filter);
76 static gboolean gst_dreamaudiosource_start (GstBaseSrc * bsrc);
77 static gboolean gst_dreamaudiosource_stop (GstBaseSrc * bsrc);
78 static gboolean gst_dreamaudiosource_unlock (GstBaseSrc * bsrc);
79 static void gst_dreamaudiosource_dispose (GObject * gobject);
80 static GstFlowReturn gst_dreamaudiosource_create (GstPushSrc * psrc, GstBuffer ** outbuf);
81
82 static void gst_dreamaudiosource_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec);
83 static void gst_dreamaudiosource_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec);
84
85 static GstStateChangeReturn gst_dreamaudiosource_change_state (GstElement * element, GstStateChange transition);
86 static gint64 gst_dreamaudiosource_get_base_pts (GstDreamAudioSource *self);
87
88 static void
89 gst_dreamaudiosource_class_init (GstDreamAudioSourceClass * klass)
90 {
91         GObjectClass *gobject_class;
92         GstElementClass *gstelement_class;
93         GstBaseSrcClass *gstbasesrc_class;
94         GstPushSrcClass *gstpush_src_class;
95
96         gobject_class = (GObjectClass *) klass;
97         gstelement_class = (GstElementClass *) klass;
98         gstbasesrc_class = (GstBaseSrcClass *) klass;
99         gstpush_src_class = (GstPushSrcClass *) klass;
100
101         gobject_class->set_property = gst_dreamaudiosource_set_property;
102         gobject_class->get_property = gst_dreamaudiosource_get_property;
103         gobject_class->dispose = gst_dreamaudiosource_dispose;
104
105         gst_element_class_add_pad_template (gstelement_class,
106                                             gst_static_pad_template_get (&srctemplate));
107
108         gst_element_class_set_static_metadata (gstelement_class,
109             "Dream Audio source", "Source/Audio",
110             "Provide an audio elementary stream from Dreambox encoder device",
111             "Andreas Frisch <fraxinas@opendreambox.org>");
112
113         gstelement_class->change_state = gst_dreamaudiosource_change_state;
114
115         gstbasesrc_class->get_caps = gst_dreamaudiosource_getcaps;
116         gstbasesrc_class->start = gst_dreamaudiosource_start;
117         gstbasesrc_class->stop = gst_dreamaudiosource_stop;
118         gstbasesrc_class->unlock = gst_dreamaudiosource_unlock;
119
120         gstpush_src_class->create = gst_dreamaudiosource_create;
121
122         g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BITRATE,
123           g_param_spec_int ("bitrate", "Bitrate (kb/s)",
124             "Bitrate in kbit/sec", 16, 320, DEFAULT_BITRATE,
125             G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
126
127         gst_dreamaudiosource_signals[SIGNAL_GET_BASE_PTS] =
128                 g_signal_new ("get-base-pts",
129                 G_TYPE_FROM_CLASS (klass),
130                 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
131                 G_STRUCT_OFFSET (GstDreamAudioSourceClass, get_base_pts),
132                 NULL, NULL, gst_dreamsource_marshal_INT64__VOID, G_TYPE_INT64, 0);
133
134         klass->get_base_pts = gst_dreamaudiosource_get_base_pts;
135
136 }
137
138 static gint64
139 gst_dreamaudiosource_get_base_pts (GstDreamAudioSource *self)
140 {
141         GST_DEBUG_OBJECT (self, "gst_dreamaudiosource_get_base_pts %" GST_TIME_FORMAT"", GST_TIME_ARGS (self->base_pts) );
142         return self->base_pts;
143 }
144
145 static void gst_dreamaudiosource_set_bitrate (GstDreamAudioSource * self, uint32_t bitrate)
146 {
147         if (!self->encoder || !self->encoder->fd)
148                 return;
149         uint32_t abr = bitrate*1000;
150         int ret = ioctl(self->encoder->fd, AENC_SET_BITRATE, &abr);
151         if (ret != 0)
152         {
153                 GST_WARNING_OBJECT (self, "can't set audio bitrate to %i bytes/s!", abr);
154                 return;
155         }
156         GST_INFO_OBJECT (self, "set audio bitrate to %i kBytes/s", bitrate);
157         self->audio_info.bitrate = abr;
158 }
159
160 gboolean
161 gst_dreamaudiosource_plugin_init (GstPlugin *plugin)
162 {
163         GST_DEBUG_CATEGORY_INIT (dreamaudiosource_debug, "dreamaudiosource", 0, "dreamaudiosource");
164         return gst_element_register (plugin, "dreamaudiosource", GST_RANK_PRIMARY, GST_TYPE_DREAMAUDIOSOURCE);
165 }
166
167 static void
168 gst_dreamaudiosource_init (GstDreamAudioSource * self)
169 {
170         self->encoder = NULL;
171         self->descriptors_available = 0;
172
173         g_mutex_init (&self->mutex);
174         READ_SOCKET (self) = -1;
175         WRITE_SOCKET (self) = -1;
176
177         gst_base_src_set_format (GST_BASE_SRC (self), GST_FORMAT_TIME);
178         gst_base_src_set_live (GST_BASE_SRC (self), TRUE);
179
180         self->encoder = malloc(sizeof(EncoderInfo));
181
182         if(!self->encoder) {
183                 GST_ERROR_OBJECT(self,"out of space");
184                 return;
185         }
186
187         char fn_buf[32];
188         sprintf(fn_buf, "/dev/aenc%d", 0);
189         self->encoder->fd = open(fn_buf, O_RDWR | O_SYNC);
190         if(self->encoder->fd <= 0) {
191                 GST_ERROR_OBJECT(self,"cannot open device %s (%s)", fn_buf, strerror(errno));
192                 free(self->encoder);
193                 self->encoder = NULL;
194                 return;
195         }
196
197         int flags = fcntl(self->encoder->fd, F_GETFL, 0);
198         fcntl(self->encoder->fd, F_SETFL, flags | O_NONBLOCK);
199
200         self->encoder->buffer = malloc(ABUFSIZE);
201         if(!self->encoder->buffer) {
202                 GST_ERROR_OBJECT(self,"cannot alloc buffer");
203                 return;
204         }
205
206         self->encoder->cdb = (unsigned char *)mmap(0, AMMAPSIZE, PROT_READ, MAP_PRIVATE, self->encoder->fd, 0);
207         if(!self->encoder->cdb || self->encoder->cdb== MAP_FAILED) {
208                 GST_ERROR_OBJECT(self,"cannot mmap cdb: %s (%d)", strerror(errno));
209                 return;
210         }
211
212 #ifdef dump
213         self->dumpfd = open("/media/hdd/movie/dreamaudiosource.dump", O_WRONLY | O_CREAT | O_TRUNC);
214         GST_DEBUG_OBJECT (self, "dumpfd = %i (%s)", self->dumpfd, (self->dumpfd > 0) ? "OK" : strerror(errno));
215 #endif
216
217         gst_dreamaudiosource_set_bitrate(self, DEFAULT_BITRATE);
218 }
219
220 static void
221 gst_dreamaudiosource_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec)
222 {
223         GstDreamAudioSource *self = GST_DREAMAUDIOSOURCE (object);
224
225         switch (prop_id) {
226                 case ARG_BITRATE:
227                         gst_dreamaudiosource_set_bitrate(self, g_value_get_int (value));
228                         break;
229                 default:
230                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
231                         break;
232         }
233 }
234
235 static void
236 gst_dreamaudiosource_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec)
237 {
238         GstDreamAudioSource *self = GST_DREAMAUDIOSOURCE (object);
239
240         switch (prop_id) {
241                 case ARG_BITRATE:
242                         g_value_set_int (value, self->audio_info.bitrate/1000);
243                         break;
244                 default:
245                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
246                         break;
247         }
248 }
249
250 static GstCaps *
251 gst_dreamaudiosource_getcaps (GstBaseSrc * bsrc, GstCaps * filter)
252 {
253         GstDreamAudioSource *self = GST_DREAMAUDIOSOURCE (bsrc);
254         GstPadTemplate *pad_template;
255         GstCaps *caps;
256
257         pad_template = gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS(self), "src");
258         g_return_val_if_fail (pad_template != NULL, NULL);
259
260         if (self->encoder == NULL) {
261                 GST_DEBUG_OBJECT (self, "encoder not opened -> use template caps");
262                 caps = gst_pad_template_get_caps (pad_template);
263         }
264         else
265         {
266                 caps = gst_caps_make_writable(gst_pad_template_get_caps (pad_template));
267         }
268
269         GST_DEBUG_OBJECT (self, "return caps %" GST_PTR_FORMAT, caps);
270         return caps;
271 }
272
273 static gboolean gst_dreamaudiosource_unlock (GstBaseSrc * bsrc)
274 {
275         GstDreamAudioSource *self = GST_DREAMAUDIOSOURCE (bsrc);
276         GST_LOG_OBJECT (self, "stop creating buffers");
277         SEND_COMMAND (self, CONTROL_STOP);
278         return TRUE;
279 }
280
281 static void
282 gst_dreamaudiosource_free_buffer (struct _bufferdebug * bufferdebug)
283 {
284         GST_OBJECT_LOCK (bufferdebug->self);
285         GList *list = g_list_first (bufferdebug->self->buffers_list);
286         int count = 0;
287         while (list) {
288                 GST_TRACE_OBJECT (bufferdebug->self, "buffers_list[%i] = %" GST_PTR_FORMAT "", count, list->data);
289                 count++;
290                 list = g_list_next (list);
291         }
292         bufferdebug->self->buffers_list = g_list_remove(g_list_first (bufferdebug->self->buffers_list), bufferdebug->buffer);
293         GST_TRACE_OBJECT (bufferdebug->self, "removing %" GST_PTR_FORMAT " @ %" GST_TIME_FORMAT " from list -> new length=%i", bufferdebug->buffer, GST_TIME_ARGS (bufferdebug->buffer_pts), g_list_length(bufferdebug->self->buffers_list));
294         GST_OBJECT_UNLOCK (bufferdebug->self);
295 }
296
297 static GstFlowReturn
298 gst_dreamaudiosource_create (GstPushSrc * psrc, GstBuffer ** outbuf)
299 {
300         GstDreamAudioSource *self = GST_DREAMAUDIOSOURCE (psrc);
301         EncoderInfo *enc = self->encoder;
302
303         static int dumpoffset;
304
305         GST_LOG_OBJECT (self, "new buffer requested");
306
307         if (!enc) {
308                 GST_WARNING_OBJECT (self, "encoder device not opened!");
309                 return GST_FLOW_ERROR;
310         }
311
312         while (1)
313         {
314                 *outbuf = NULL;
315
316                 if (self->descriptors_available == 0)
317                 {
318                         self->descriptors_count = 0;
319                         struct pollfd rfd[2];
320
321                         rfd[0].fd = enc->fd;
322                         rfd[0].events = POLLIN;
323                         rfd[1].fd = READ_SOCKET (self);
324                         rfd[1].events = POLLIN | POLLERR | POLLHUP | POLLPRI;
325
326                         int ret = poll(rfd, 2, 200);
327
328                         if (G_UNLIKELY (ret == -1))
329                         {
330                                 GST_ERROR_OBJECT (self, "SELECT ERROR!");
331                                 return GST_FLOW_ERROR;
332                         }
333                         else if ( ret == 0 )
334                         {
335                                 GST_LOG_OBJECT (self, "SELECT TIMEOUT");
336                                 //!!! TODO generate dummy payload
337                                 *outbuf = gst_buffer_new();
338                         }
339                         else if ( G_UNLIKELY (rfd[1].revents) )
340                         {
341                                 char command;
342                                 READ_COMMAND (self, command, ret);
343                                 GST_LOG_OBJECT (self, "CONTROL_STOP!");
344                                 return GST_FLOW_FLUSHING;
345                         }
346                         else if ( G_LIKELY(rfd[0].revents & POLLIN) )
347                         {
348                                 int rlen = read(enc->fd, enc->buffer, ABUFSIZE);
349                                 if (rlen <= 0 || rlen % ABDSIZE ) {
350                                         if ( errno == 512 )
351                                                 return GST_FLOW_FLUSHING;
352                                         GST_WARNING_OBJECT (self, "read error %s (%i)", strerror(errno), errno);
353                                         return GST_FLOW_ERROR;
354                                 }
355                                 self->descriptors_available = rlen / ABDSIZE;
356                                 GST_LOG_OBJECT (self, "encoder buffer was empty, %d descriptors available", self->descriptors_available);
357                         }
358                 }
359
360                 while (self->descriptors_count < self->descriptors_available) {
361                         off_t offset = self->descriptors_count * ABDSIZE;
362                         AudioBufferDescriptor *desc = (AudioBufferDescriptor*)(&enc->buffer[offset]);
363
364                         uint32_t f = desc->stCommon.uiFlags;
365
366                         GST_LOG_OBJECT (self, "descriptors_count=%d, descriptors_available=%u\tuiOffset=%u, uiLength=%"G_GSIZE_FORMAT"", self->descriptors_count, self->descriptors_available, desc->stCommon.uiOffset, desc->stCommon.uiLength);
367
368                         if (f & CDB_FLAG_METADATA) {
369                                 GST_LOG_OBJECT (self, "CDB_FLAG_METADATA... skip outdated packet");
370                                 self->descriptors_count = self->descriptors_available;
371                                 continue;
372                         }
373
374                         struct _bufferdebug * bdg = malloc(sizeof(struct _bufferdebug));
375                         *outbuf = gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY, enc->cdb, AMMAPSIZE, desc->stCommon.uiOffset, desc->stCommon.uiLength, bdg, (GDestroyNotify)gst_dreamaudiosource_free_buffer);
376                         bdg->self = self;
377                         bdg->buffer = *outbuf;
378                         self->buffers_list = g_list_append(self->buffers_list, *outbuf);
379
380                         if (f & CDB_FLAG_PTS_VALID)
381                         {
382                                 if (G_UNLIKELY (self->base_pts == GST_CLOCK_TIME_NONE))
383                                 {
384                                         if (self->dreamvideosrc)
385                                         {
386                                                 g_mutex_lock (&self->mutex);
387                                                 guint64 videosource_base_pts;
388                                                 g_signal_emit_by_name(self->dreamvideosrc, "get-base-pts", &videosource_base_pts);
389                                                 if (videosource_base_pts != GST_CLOCK_TIME_NONE)
390                                                 {
391                                                         GST_DEBUG_OBJECT (self, "use DREAMVIDEOSOURCE's base_pts=%" GST_TIME_FORMAT "", GST_TIME_ARGS (videosource_base_pts) );
392                                                         self->base_pts = videosource_base_pts;
393                                                 }
394                                                 g_mutex_unlock (&self->mutex);
395                                         }
396                                         else
397                                         {
398                                                 self->base_pts = MPEGTIME_TO_GSTTIME(desc->stCommon.uiPTS);
399                                                 GST_DEBUG_OBJECT (self, "use mpeg stream pts as base_pts=%" GST_TIME_FORMAT"", GST_TIME_ARGS (self->base_pts) );
400                                         }
401                                 }
402                                 GstClockTime buffer_time = MPEGTIME_TO_GSTTIME(desc->stCommon.uiPTS);
403                                 if (self->base_pts != GST_CLOCK_TIME_NONE && buffer_time > self->base_pts )
404                                 {
405                                         buffer_time -= self->base_pts;
406                                         GST_BUFFER_PTS(*outbuf) = buffer_time;
407                                         GST_BUFFER_DTS(*outbuf) = buffer_time;
408                                 }
409                                 bdg->buffer_pts = buffer_time;
410                         }
411
412 #ifdef dump
413                         int wret = write(self->dumpfd, (unsigned char*)(enc->cdb + desc->stCommon.uiOffset), desc->stCommon.uiLength);
414                         dumpoffset += wret;
415                         GST_LOG_OBJECT (self, "read %"G_GSIZE_FORMAT" dumped %i total 0x%08X", desc->stCommon.uiLength, wret, dumpoffset );
416 #endif
417                         self->descriptors_count++;
418
419                         break;
420                 }
421
422                 if (self->descriptors_count == self->descriptors_available) {
423                         GST_LOG_OBJECT (self, "self->descriptors_count == self->descriptors_available -> release %i consumed descriptors", self->descriptors_count);
424                         /* release consumed descs */
425                         if (write(enc->fd, &self->descriptors_count, 4) != 4) {
426                                 GST_WARNING_OBJECT (self, "release consumed descs write error!");
427                                 return GST_FLOW_ERROR;
428                         }
429                         self->descriptors_available = 0;
430                 }
431
432                 if (*outbuf)
433                 {
434                         GST_DEBUG_OBJECT (self, "pushing %" GST_PTR_FORMAT "", *outbuf );
435                         return GST_FLOW_OK;
436                 }
437         }
438
439         return GST_FLOW_ERROR;
440 }
441
442 static GstStateChangeReturn gst_dreamaudiosource_change_state (GstElement * element, GstStateChange transition)
443 {
444         GstDreamAudioSource *self = GST_DREAMAUDIOSOURCE (element);
445         int ret;
446         switch (transition) {
447                 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
448                         GST_LOG_OBJECT (self, "GST_STATE_CHANGE_PAUSED_TO_PLAYING");
449                         self->base_pts = GST_CLOCK_TIME_NONE;
450                         ret = ioctl(self->encoder->fd, AENC_START);
451                         if ( ret != 0 )
452                         {
453                                 GST_ERROR_OBJECT(self,"can't start encoder ioctl!");
454                                 return GST_STATE_CHANGE_FAILURE;
455                         }
456                         self->descriptors_available = 0;
457                         GST_INFO_OBJECT (self, "started encoder!");
458                         break;
459                 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
460                         GST_LOG_OBJECT (self, "GST_STATE_CHANGE_PLAYING_TO_PAUSED self->descriptors_count=%i self->descriptors_available=%i", self->descriptors_count, self->descriptors_available);
461                         GST_OBJECT_LOCK (self);
462                         while (self->descriptors_count < self->descriptors_available)
463                                 GST_LOG_OBJECT (self, "flushing self->descriptors_count=%i", self->descriptors_count++);
464                         if (self->descriptors_count)
465                                 write(self->encoder->fd, &self->descriptors_count, 4);
466                         ret = ioctl(self->encoder->fd, AENC_STOP);
467                         GST_OBJECT_UNLOCK (self);
468                         if ( ret != 0 )
469                         {
470                                 GST_ERROR_OBJECT(self,"can't stop encoder ioctl!");
471                                 return GST_STATE_CHANGE_FAILURE;
472                         }
473                         GST_INFO_OBJECT (self, "stopped encoder!");
474                         break;
475                 default:
476                         break;
477         }
478         if (GST_ELEMENT_CLASS (parent_class)->change_state)
479                 return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
480         return GST_STATE_CHANGE_SUCCESS;
481 }
482
483 static gboolean
484 gst_dreamaudiosource_start (GstBaseSrc * bsrc)
485 {
486         GstDreamAudioSource *self = GST_DREAMAUDIOSOURCE (bsrc);
487         self->dreamvideosrc = gst_bin_get_by_name_recurse_up(GST_BIN(GST_ELEMENT_PARENT(self)), "dreamvideosource0");
488
489         int control_sock[2];
490         if (socketpair (PF_UNIX, SOCK_STREAM, 0, control_sock) < 0)
491         {
492                 GST_ELEMENT_ERROR (self, RESOURCE, OPEN_READ_WRITE, (NULL), GST_ERROR_SYSTEM);
493                 return FALSE;
494         }
495         READ_SOCKET (self) = control_sock[0];
496         WRITE_SOCKET (self) = control_sock[1];
497         fcntl (READ_SOCKET (self), F_SETFL, O_NONBLOCK);
498         fcntl (WRITE_SOCKET (self), F_SETFL, O_NONBLOCK);
499
500         GST_DEBUG_OBJECT (self, "started. reference to dreamvideosource=%" GST_PTR_FORMAT"", self->dreamvideosrc);
501         return TRUE;
502 }
503
504 static gboolean
505 gst_dreamaudiosource_stop (GstBaseSrc * bsrc)
506 {
507         GstDreamAudioSource *self = GST_DREAMAUDIOSOURCE (bsrc);
508         if (self->dreamvideosrc)
509                 gst_object_unref(self->dreamvideosrc);
510         GST_DEBUG_OBJECT (self, "stop");
511         return TRUE;
512 }
513
514 static void
515 gst_dreamaudiosource_dispose (GObject * gobject)
516 {
517         GstDreamAudioSource *self = GST_DREAMAUDIOSOURCE (gobject);
518         if (self->encoder) {
519                 if (self->encoder->buffer)
520                         free(self->encoder->buffer);
521                 if (self->encoder->cdb)
522                         munmap(self->encoder->cdb, AMMAPSIZE);
523                 if (self->encoder->fd)
524                         close(self->encoder->fd);
525                 free(self->encoder);
526         }
527 #ifdef dump
528         close(self->dumpfd);
529 #endif
530         g_list_free(self->buffers_list);
531         g_mutex_clear (&self->mutex);
532         GST_DEBUG_OBJECT (self, "disposed");
533         G_OBJECT_CLASS (parent_class)->dispose (gobject);
534 }