1.1 --- a/gst-gmyth/concatmux/gstconcatmux.c Thu Jun 14 18:21:08 2007 +0100
1.2 +++ b/gst-gmyth/concatmux/gstconcatmux.c Mon Sep 24 16:06:54 2007 +0100
1.3 @@ -1,20 +1,16 @@
1.4 -/* concat muxer plugin for GStreamer
1.5 - * Copyright (C) 2004 Renato Filhps <renato.filho@indt.org.br>
1.6 - *
1.7 - * This library is free software; you can redistribute it and/or
1.8 - * modify it under the terms of the GNU Library General Public
1.9 - * License as published by the Free Software Foundation; either
1.10 - * version 2 of the License, or (at your option) any later version.
1.11 - *
1.12 - * This library is distributed in the hope that it will be useful,
1.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1.15 - * Library General Public License for more details.
1.16 - *
1.17 - * You should have received a copy of the GNU Library General Public
1.18 - * License along with this library; if not, write to the
1.19 - * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1.20 - * Boston, MA 02111-1307, USA.
1.21 +/*
1.22 + * concat muxer plugin for GStreamer Copyright (C) 2004 Renato Filhps
1.23 + * <renato.filho@indt.org.br> This library is free software; you can
1.24 + * redistribute it and/or modify it under the terms of the GNU Library
1.25 + * General Public License as published by the Free Software Foundation;
1.26 + * either version 2 of the License, or (at your option) any later version.
1.27 + * This library is distributed in the hope that it will be useful, but
1.28 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1.29 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
1.30 + * General Public License for more details. You should have received a copy
1.31 + * of the GNU Library General Public License along with this library; if
1.32 + * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite
1.33 + * 330, Boston, MA 02111-1307, USA.
1.34 */
1.35
1.36 /**
1.37 @@ -59,73 +55,83 @@
1.38 *
1.39 * The opaque #GstConcatMux structure.
1.40 */
1.41 -struct _GstConcatMux
1.42 -{
1.43 - GstElement element;
1.44 +struct _GstConcatMux {
1.45 + GstElement element;
1.46
1.47 - /* Caps */
1.48 - GstCaps *sink_caps;
1.49 + /*
1.50 + * Caps
1.51 + */
1.52 + GstCaps *sink_caps;
1.53
1.54 - /* pad */
1.55 - GstPad *srcpad;
1.56 - GstPad *sinkpad;
1.57 + /*
1.58 + * pad
1.59 + */
1.60 + GstPad *srcpad;
1.61 + GstPad *sinkpad;
1.62
1.63 - /* sinkpads */
1.64 - GSList *sinks;
1.65 - gint numpads;
1.66 + /*
1.67 + * sinkpads
1.68 + */
1.69 + GSList *sinks;
1.70 + gint numpads;
1.71
1.72 - /* offset in stream */
1.73 - guint64 offset;
1.74 - guint64 timeoffset;
1.75 - guint64 start_time;
1.76 + /*
1.77 + * offset in stream
1.78 + */
1.79 + guint64 offset;
1.80 + guint64 timeoffset;
1.81 + guint64 start_time;
1.82
1.83 - gboolean negotiated;
1.84 - gboolean resync;
1.85 - gboolean done;
1.86 + gboolean negotiated;
1.87 + gboolean resync;
1.88 + gboolean done;
1.89 };
1.90
1.91 -struct _GstConcatMuxClass
1.92 -{
1.93 - GstElementClass parent_class;
1.94 +struct _GstConcatMuxClass {
1.95 + GstElementClass parent_class;
1.96 };
1.97
1.98 -/* elementfactory information */
1.99 +/*
1.100 + * elementfactory information
1.101 + */
1.102 static const GstElementDetails gst_concat_mux_details =
1.103 GST_ELEMENT_DETAILS("Concat muxer",
1.104 - "Codec/Muxer",
1.105 - "mux concat streams",
1.106 - "Renato Filho <renato.filho@indt.org>");
1.107 + "Codec/Muxer",
1.108 + "mux concat streams",
1.109 + "Renato Filho <renato.filho@indt.org>");
1.110
1.111 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE("src",
1.112 - GST_PAD_SRC,
1.113 - GST_PAD_ALWAYS,
1.114 - GST_STATIC_CAPS_ANY);
1.115 + GST_PAD_SRC,
1.116 + GST_PAD_ALWAYS,
1.117 + GST_STATIC_CAPS_ANY);
1.118
1.119 -static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE("sink_%d",
1.120 - GST_PAD_SINK,
1.121 - GST_PAD_REQUEST,
1.122 - GST_STATIC_CAPS_ANY);
1.123 +static GstStaticPadTemplate sink_factory =
1.124 +GST_STATIC_PAD_TEMPLATE("sink_%d",
1.125 + GST_PAD_SINK,
1.126 + GST_PAD_REQUEST,
1.127 + GST_STATIC_CAPS_ANY);
1.128
1.129 -static void gst_concat_mux_base_init(gpointer g_class);
1.130 -static void gst_concat_mux_class_init(GstConcatMuxClass * klass);
1.131 -static void gst_concat_mux_init(GstConcatMux * concat_mux);
1.132 +static void gst_concat_mux_base_init(gpointer g_class);
1.133 +static void gst_concat_mux_class_init(GstConcatMuxClass * klass);
1.134 +static void gst_concat_mux_init(GstConcatMux * concat_mux);
1.135
1.136 -static void gst_concat_mux_finalize(GObject * object);
1.137 +static void gst_concat_mux_finalize(GObject * object);
1.138
1.139 static gboolean gst_concat_mux_handle_src_event(GstPad * pad,
1.140 - GstEvent * event);
1.141 + GstEvent * event);
1.142 static gboolean gst_concat_mux_handle_sink_event(GstPad * pad,
1.143 - GstEvent * event);
1.144 + GstEvent * event);
1.145
1.146 -static GstPad *gst_concat_mux_request_new_pad(GstElement * element,
1.147 - GstPadTemplate * templ,
1.148 - const gchar * name);
1.149 -static GstStateChangeReturn gst_concat_mux_change_state(GstElement * element,
1.150 - GstStateChange
1.151 - transition);
1.152 +static GstPad *gst_concat_mux_request_new_pad(GstElement * element,
1.153 + GstPadTemplate * templ,
1.154 + const gchar * name);
1.155 +static GstStateChangeReturn gst_concat_mux_change_state(GstElement *
1.156 + element,
1.157 + GstStateChange
1.158 + transition);
1.159
1.160 static GstFlowReturn gst_concat_mux_chain(GstPad * pad, GstBuffer * buf);
1.161 -static void gst_concat_mux_clear(GstConcatMux * mux);
1.162 +static void gst_concat_mux_clear(GstConcatMux * mux);
1.163
1.164
1.165 static GstElementClass *parent_class = NULL;
1.166 @@ -133,434 +139,416 @@
1.167 GType
1.168 gst_concat_mux_get_type(void)
1.169 {
1.170 - static GType concat_mux_type = 0;
1.171 + static GType concat_mux_type = 0;
1.172
1.173 - if (!concat_mux_type)
1.174 - {
1.175 - static const GTypeInfo concat_mux_info = {
1.176 - sizeof(GstConcatMuxClass),
1.177 - gst_concat_mux_base_init,
1.178 - NULL,
1.179 - (GClassInitFunc) gst_concat_mux_class_init,
1.180 - NULL,
1.181 - NULL,
1.182 - sizeof(GstConcatMux),
1.183 - 0,
1.184 - (GInstanceInitFunc) gst_concat_mux_init,
1.185 - };
1.186 + if (!concat_mux_type) {
1.187 + static const GTypeInfo concat_mux_info = {
1.188 + sizeof(GstConcatMuxClass),
1.189 + gst_concat_mux_base_init,
1.190 + NULL,
1.191 + (GClassInitFunc) gst_concat_mux_class_init,
1.192 + NULL,
1.193 + NULL,
1.194 + sizeof(GstConcatMux),
1.195 + 0,
1.196 + (GInstanceInitFunc) gst_concat_mux_init,
1.197 + };
1.198
1.199 - concat_mux_type =
1.200 - g_type_register_static(GST_TYPE_ELEMENT, "GstConcatMux",
1.201 - &concat_mux_info, 0);
1.202 - }
1.203 - return concat_mux_type;
1.204 + concat_mux_type =
1.205 + g_type_register_static(GST_TYPE_ELEMENT, "GstConcatMux",
1.206 + &concat_mux_info, 0);
1.207 + }
1.208 + return concat_mux_type;
1.209 }
1.210
1.211 static void
1.212 gst_concat_mux_base_init(gpointer g_class)
1.213 {
1.214 - GstElementClass *element_class = GST_ELEMENT_CLASS(g_class);
1.215 + GstElementClass *element_class = GST_ELEMENT_CLASS(g_class);
1.216
1.217 - gst_element_class_add_pad_template(element_class,
1.218 - gst_static_pad_template_get
1.219 - (&src_factory));
1.220 - gst_element_class_add_pad_template(element_class,
1.221 - gst_static_pad_template_get
1.222 - (&sink_factory));
1.223 + gst_element_class_add_pad_template(element_class,
1.224 + gst_static_pad_template_get
1.225 + (&src_factory));
1.226 + gst_element_class_add_pad_template(element_class,
1.227 + gst_static_pad_template_get
1.228 + (&sink_factory));
1.229
1.230 - gst_element_class_set_details(element_class, &gst_concat_mux_details);
1.231 + gst_element_class_set_details(element_class, &gst_concat_mux_details);
1.232 }
1.233
1.234 static void
1.235 gst_concat_mux_class_init(GstConcatMuxClass * klass)
1.236 {
1.237 - GObjectClass *gobject_class;
1.238 - GstElementClass *gstelement_class;
1.239 + GObjectClass *gobject_class;
1.240 + GstElementClass *gstelement_class;
1.241
1.242 - gobject_class = (GObjectClass *) klass;
1.243 - gstelement_class = (GstElementClass *) klass;
1.244 + gobject_class = (GObjectClass *) klass;
1.245 + gstelement_class = (GstElementClass *) klass;
1.246
1.247 - parent_class = g_type_class_peek_parent(klass);
1.248 + parent_class = g_type_class_peek_parent(klass);
1.249
1.250 - gobject_class->finalize = gst_concat_mux_finalize;
1.251 + gobject_class->finalize = gst_concat_mux_finalize;
1.252
1.253 - gstelement_class->request_new_pad = gst_concat_mux_request_new_pad;
1.254 - gstelement_class->change_state = gst_concat_mux_change_state;
1.255 + gstelement_class->request_new_pad = gst_concat_mux_request_new_pad;
1.256 + gstelement_class->change_state = gst_concat_mux_change_state;
1.257 }
1.258
1.259 static void
1.260 gst_concat_mux_init(GstConcatMux * concat_mux)
1.261 {
1.262 - GstElementClass *klass = GST_ELEMENT_GET_CLASS(concat_mux);
1.263 + GstElementClass *klass = GST_ELEMENT_GET_CLASS(concat_mux);
1.264
1.265 - concat_mux->srcpad =
1.266 - gst_pad_new_from_template(gst_element_class_get_pad_template(klass,
1.267 - "src"),
1.268 - "src");
1.269 - gst_pad_set_event_function(concat_mux->srcpad,
1.270 - gst_concat_mux_handle_src_event);
1.271 - gst_element_add_pad(GST_ELEMENT(concat_mux), concat_mux->srcpad);
1.272 + concat_mux->srcpad =
1.273 + gst_pad_new_from_template(gst_element_class_get_pad_template(klass,
1.274 + "src"),
1.275 + "src");
1.276 + gst_pad_set_event_function(concat_mux->srcpad,
1.277 + gst_concat_mux_handle_src_event);
1.278 + gst_element_add_pad(GST_ELEMENT(concat_mux), concat_mux->srcpad);
1.279 }
1.280
1.281 static void
1.282 gst_concat_mux_finalize(GObject * object)
1.283 {
1.284 - GstConcatMux *concat_mux;
1.285 + GstConcatMux *concat_mux;
1.286
1.287 - concat_mux = GST_CONCAT_MUX(object);
1.288 - gst_concat_mux_clear(GST_CONCAT_MUX(object));
1.289 + concat_mux = GST_CONCAT_MUX(object);
1.290 + gst_concat_mux_clear(GST_CONCAT_MUX(object));
1.291
1.292 - G_OBJECT_CLASS(parent_class)->finalize(object);
1.293 + G_OBJECT_CLASS(parent_class)->finalize(object);
1.294 }
1.295
1.296 static void
1.297 gst_concat_mux_free_pad(gpointer data, gpointer user_data)
1.298 {
1.299 - GMutex *mux;
1.300 + GMutex *mux;
1.301
1.302 - mux = gst_pad_get_element_private(GST_PAD(data));
1.303 - g_mutex_unlock(mux);
1.304 - g_mutex_free(mux);
1.305 - gst_object_unref(GST_OBJECT(data));
1.306 + mux = gst_pad_get_element_private(GST_PAD(data));
1.307 + g_mutex_unlock(mux);
1.308 + g_mutex_free(mux);
1.309 + gst_object_unref(GST_OBJECT(data));
1.310 }
1.311
1.312 static void
1.313 gst_concat_mux_clear(GstConcatMux * mux)
1.314 {
1.315 - mux->resync = TRUE;
1.316 - mux->timeoffset = 0;
1.317 - mux->offset = 0;
1.318 - mux->negotiated = FALSE;
1.319 - mux->done = TRUE;
1.320 - if (mux->sinks != NULL)
1.321 - {
1.322 - g_slist_foreach(mux->sinks, gst_concat_mux_free_pad, mux);
1.323 - g_slist_free(mux->sinks);
1.324 - mux->sinks = NULL;
1.325 - }
1.326 + mux->resync = TRUE;
1.327 + mux->timeoffset = 0;
1.328 + mux->offset = 0;
1.329 + mux->negotiated = FALSE;
1.330 + mux->done = TRUE;
1.331 + if (mux->sinks != NULL) {
1.332 + g_slist_foreach(mux->sinks, gst_concat_mux_free_pad, mux);
1.333 + g_slist_free(mux->sinks);
1.334 + mux->sinks = NULL;
1.335 + }
1.336 }
1.337
1.338
1.339 -static GstPadLinkReturn
1.340 +static GstPadLinkReturn
1.341 gst_concat_mux_sinkconnect(GstPad * pad, GstPad * peer)
1.342 {
1.343 - gchar *pad_name = NULL;
1.344 - GstConcatMux *concat_mux;
1.345 + gchar *pad_name = NULL;
1.346 + GstConcatMux *concat_mux;
1.347
1.348 - concat_mux = GST_CONCAT_MUX(gst_pad_get_parent(pad));
1.349 + concat_mux = GST_CONCAT_MUX(gst_pad_get_parent(pad));
1.350
1.351 - if (concat_mux->sink_caps != NULL)
1.352 - {
1.353 - GstCaps *peer_caps = gst_pad_get_caps(peer);
1.354 - GstCaps *intersect;
1.355 + if (concat_mux->sink_caps != NULL) {
1.356 + GstCaps *peer_caps = gst_pad_get_caps(peer);
1.357 + GstCaps *intersect;
1.358
1.359 - intersect = gst_caps_intersect(concat_mux->sink_caps, peer_caps);
1.360 - if (intersect == NULL)
1.361 - {
1.362 - gst_caps_unref(peer_caps);
1.363 - return GST_PAD_LINK_NOFORMAT;
1.364 - }
1.365 - gst_caps_unref(peer_caps);
1.366 - gst_caps_unref(intersect);
1.367 - }
1.368 - else
1.369 - {
1.370 - concat_mux->sink_caps = gst_pad_get_caps(pad);
1.371 - }
1.372 + intersect = gst_caps_intersect(concat_mux->sink_caps, peer_caps);
1.373 + if (intersect == NULL) {
1.374 + gst_caps_unref(peer_caps);
1.375 + return GST_PAD_LINK_NOFORMAT;
1.376 + }
1.377 + gst_caps_unref(peer_caps);
1.378 + gst_caps_unref(intersect);
1.379 + } else {
1.380 + concat_mux->sink_caps = gst_pad_get_caps(pad);
1.381 + }
1.382
1.383 - pad_name = gst_pad_get_name(pad);
1.384 + pad_name = gst_pad_get_name(pad);
1.385
1.386 - GST_DEBUG_OBJECT(concat_mux, "sinkconnect triggered on %s", pad_name);
1.387 + GST_DEBUG_OBJECT(concat_mux, "sinkconnect triggered on %s", pad_name);
1.388
1.389 - g_free(pad_name);
1.390 + g_free(pad_name);
1.391
1.392 - gst_object_unref(concat_mux);
1.393 + gst_object_unref(concat_mux);
1.394
1.395 - return GST_PAD_LINK_OK;
1.396 + return GST_PAD_LINK_OK;
1.397 }
1.398
1.399 -static GstPad *
1.400 +static GstPad *
1.401 gst_concat_mux_request_new_pad(GstElement * element,
1.402 - GstPadTemplate * templ, const gchar * req_name)
1.403 + GstPadTemplate * templ,
1.404 + const gchar * req_name)
1.405 {
1.406 - GstConcatMux *concat_mux;
1.407 - GstPad *newpad;
1.408 - GstElementClass *klass = GST_ELEMENT_GET_CLASS(element);
1.409 - GMutex *mutex;
1.410 + GstConcatMux *concat_mux;
1.411 + GstPad *newpad;
1.412 + GstElementClass *klass = GST_ELEMENT_GET_CLASS(element);
1.413 + GMutex *mutex;
1.414
1.415 - g_return_val_if_fail(templ != NULL, NULL);
1.416 + g_return_val_if_fail(templ != NULL, NULL);
1.417
1.418 - if (templ->direction != GST_PAD_SINK)
1.419 - {
1.420 - g_warning("concat_mux: request pad that is not a SINK pad\n");
1.421 - return NULL;
1.422 - }
1.423 + if (templ->direction != GST_PAD_SINK) {
1.424 + g_warning("concat_mux: request pad that is not a SINK pad\n");
1.425 + return NULL;
1.426 + }
1.427
1.428 - g_return_val_if_fail(GST_IS_CONCAT_MUX(element), NULL);
1.429 + g_return_val_if_fail(GST_IS_CONCAT_MUX(element), NULL);
1.430
1.431 - concat_mux = GST_CONCAT_MUX(element);
1.432 + concat_mux = GST_CONCAT_MUX(element);
1.433
1.434 - if (templ == gst_element_class_get_pad_template(klass, "sink_%d"))
1.435 - {
1.436 - gchar *name;
1.437 + if (templ == gst_element_class_get_pad_template(klass, "sink_%d")) {
1.438 + gchar *name;
1.439
1.440 - /* create new pad with the name */
1.441 - name = g_strdup_printf("sink_%02d", concat_mux->numpads);
1.442 - g_debug("NEw pad %s", name);
1.443 - newpad = gst_pad_new_from_template(templ, name);
1.444 - g_free(name);
1.445 - concat_mux->sinks = g_slist_append(concat_mux->sinks, newpad);
1.446 - g_debug("New sink %p / %d", newpad, g_slist_length(concat_mux->sinks));
1.447 - concat_mux->numpads++;
1.448 - }
1.449 - else
1.450 - {
1.451 - g_warning("concat_mux: this is not our template!\n");
1.452 - return NULL;
1.453 - }
1.454 + /*
1.455 + * create new pad with the name
1.456 + */
1.457 + name = g_strdup_printf("sink_%02d", concat_mux->numpads);
1.458 + g_debug("NEw pad %s", name);
1.459 + newpad = gst_pad_new_from_template(templ, name);
1.460 + g_free(name);
1.461 + concat_mux->sinks = g_slist_append(concat_mux->sinks, newpad);
1.462 + g_debug("New sink %p / %d", newpad,
1.463 + g_slist_length(concat_mux->sinks));
1.464 + concat_mux->numpads++;
1.465 + } else {
1.466 + g_warning("concat_mux: this is not our template!\n");
1.467 + return NULL;
1.468 + }
1.469
1.470 - mutex = g_mutex_new();
1.471 + mutex = g_mutex_new();
1.472
1.473 - if (concat_mux->sinkpad == NULL)
1.474 - {
1.475 - concat_mux->sinkpad = newpad;
1.476 - }
1.477 - else
1.478 - {
1.479 - g_mutex_lock(mutex);
1.480 - }
1.481 + if (concat_mux->sinkpad == NULL) {
1.482 + concat_mux->sinkpad = newpad;
1.483 + } else {
1.484 + g_mutex_lock(mutex);
1.485 + }
1.486
1.487 - gst_pad_set_element_private(newpad, mutex);
1.488 - /* setup some pad functions */
1.489 - gst_pad_set_link_function(newpad, gst_concat_mux_sinkconnect);
1.490 - gst_pad_set_event_function(newpad, gst_concat_mux_handle_sink_event);
1.491 - gst_pad_set_chain_function(newpad, gst_concat_mux_chain);
1.492 + gst_pad_set_element_private(newpad, mutex);
1.493 + /*
1.494 + * setup some pad functions
1.495 + */
1.496 + gst_pad_set_link_function(newpad, gst_concat_mux_sinkconnect);
1.497 + gst_pad_set_event_function(newpad, gst_concat_mux_handle_sink_event);
1.498 + gst_pad_set_chain_function(newpad, gst_concat_mux_chain);
1.499
1.500 - /* add the pad to the element */
1.501 - gst_element_add_pad(element, newpad);
1.502 + /*
1.503 + * add the pad to the element
1.504 + */
1.505 + gst_element_add_pad(element, newpad);
1.506
1.507 - return newpad;
1.508 + return newpad;
1.509 }
1.510
1.511 -/* handle events */
1.512 -static gboolean
1.513 +/*
1.514 + * handle events
1.515 + */
1.516 +static gboolean
1.517 gst_concat_mux_handle_src_event(GstPad * pad, GstEvent * event)
1.518 {
1.519 - GstConcatMux *concat_mux;
1.520 - GstEventType type;
1.521 + GstConcatMux *concat_mux;
1.522 + GstEventType type;
1.523
1.524 - concat_mux = GST_CONCAT_MUX(gst_pad_get_parent(pad));
1.525 + concat_mux = GST_CONCAT_MUX(gst_pad_get_parent(pad));
1.526
1.527 - type = event ? GST_EVENT_TYPE(event) : GST_EVENT_UNKNOWN;
1.528 + type = event ? GST_EVENT_TYPE(event) : GST_EVENT_UNKNOWN;
1.529
1.530 - switch (type)
1.531 - {
1.532 - case GST_EVENT_SEEK:
1.533 - /* disable seeking for now */
1.534 - return FALSE;
1.535 - default:
1.536 - break;
1.537 - }
1.538 + switch (type) {
1.539 + case GST_EVENT_SEEK:
1.540 + /*
1.541 + * disable seeking for now
1.542 + */
1.543 + return FALSE;
1.544 + default:
1.545 + break;
1.546 + }
1.547
1.548 - gst_object_unref(concat_mux);
1.549 + gst_object_unref(concat_mux);
1.550
1.551 - return gst_pad_event_default(pad, event);
1.552 + return gst_pad_event_default(pad, event);
1.553 }
1.554
1.555 -/* handle events */
1.556 -static gboolean
1.557 +/*
1.558 + * handle events
1.559 + */
1.560 +static gboolean
1.561 gst_concat_mux_handle_sink_event(GstPad * pad, GstEvent * event)
1.562 {
1.563 - GstConcatMux *mux;
1.564 - GstEventType type;
1.565 + GstConcatMux *mux;
1.566 + GstEventType type;
1.567
1.568 - mux = GST_CONCAT_MUX(gst_pad_get_parent(pad));
1.569 + mux = GST_CONCAT_MUX(gst_pad_get_parent(pad));
1.570
1.571 - type = event ? GST_EVENT_TYPE(event) : GST_EVENT_UNKNOWN;
1.572 + type = event ? GST_EVENT_TYPE(event) : GST_EVENT_UNKNOWN;
1.573
1.574 - switch (type)
1.575 - {
1.576 - case GST_EVENT_EOS:
1.577 - {
1.578 - mux->resync = TRUE;
1.579 - g_debug("sink EOS %p / %d", pad, g_slist_length(mux->sinks));
1.580 - /* mark pad eos */
1.581 - mux->sinks = g_slist_remove(mux->sinks, pad);
1.582 - g_debug("sink len %d", g_slist_length(mux->sinks));
1.583 - if (g_slist_length(mux->sinks) != 0)
1.584 - {
1.585 - GMutex *mutex;
1.586 - mux->sinkpad = mux->sinks->data;
1.587 - mutex = (GMutex *) gst_pad_get_element_private(mux->sinkpad);
1.588 - g_mutex_unlock(mutex);
1.589 - g_debug("sink pad %p", mux->sinkpad);
1.590 - return TRUE;
1.591 - }
1.592 + switch (type) {
1.593 + case GST_EVENT_EOS:
1.594 + {
1.595 + mux->resync = TRUE;
1.596 + g_debug("sink EOS %p / %d", pad, g_slist_length(mux->sinks));
1.597 + /*
1.598 + * mark pad eos
1.599 + */
1.600 + mux->sinks = g_slist_remove(mux->sinks, pad);
1.601 + g_debug("sink len %d", g_slist_length(mux->sinks));
1.602 + if (g_slist_length(mux->sinks) != 0) {
1.603 + GMutex *mutex;
1.604 + mux->sinkpad = mux->sinks->data;
1.605 + mutex =
1.606 + (GMutex *) gst_pad_get_element_private(mux->sinkpad);
1.607 + g_mutex_unlock(mutex);
1.608 + g_debug("sink pad %p", mux->sinkpad);
1.609 + return TRUE;
1.610 + }
1.611
1.612 - g_debug("sink list is empty");
1.613 - }
1.614 - default:
1.615 - break;
1.616 - }
1.617 + g_debug("sink list is empty");
1.618 + }
1.619 + default:
1.620 + break;
1.621 + }
1.622
1.623 - gst_object_unref(mux);
1.624 + gst_object_unref(mux);
1.625
1.626 - return gst_pad_event_default(pad, event);
1.627 + return gst_pad_event_default(pad, event);
1.628 }
1.629
1.630 -static GstFlowReturn
1.631 +static GstFlowReturn
1.632 gst_concat_mux_chain(GstPad * pad, GstBuffer * buf)
1.633 {
1.634 - GstConcatMux *mux = (GstConcatMux *) GST_PAD_PARENT(pad);
1.635 - GstBuffer *databuf = NULL;
1.636 - GstFlowReturn ret = GST_FLOW_OK;
1.637 - GMutex *mutex;
1.638 + GstConcatMux *mux = (GstConcatMux *) GST_PAD_PARENT(pad);
1.639 + GstBuffer *databuf = NULL;
1.640 + GstFlowReturn ret = GST_FLOW_OK;
1.641 + GMutex *mutex;
1.642
1.643
1.644 - mutex = (GMutex *) gst_pad_get_element_private(pad);
1.645 + mutex = (GMutex *) gst_pad_get_element_private(pad);
1.646
1.647 - g_mutex_lock(mutex);
1.648 - if (mux->done)
1.649 - {
1.650 - g_debug("DONE pad %p", pad);
1.651 - g_mutex_unlock(mutex);
1.652 - return GST_FLOW_OK;
1.653 - }
1.654 + g_mutex_lock(mutex);
1.655 + if (mux->done) {
1.656 + g_debug("DONE pad %p", pad);
1.657 + g_mutex_unlock(mutex);
1.658 + return GST_FLOW_OK;
1.659 + }
1.660
1.661 - databuf = gst_buffer_make_metadata_writable(buf);
1.662 + databuf = gst_buffer_make_metadata_writable(buf);
1.663
1.664 - if (!mux->negotiated)
1.665 - {
1.666 - /*
1.667 - GstCaps *newcaps;
1.668 - newcaps = gst_pad_get_caps (mux->sinkpad);
1.669 + if (!mux->negotiated) {
1.670 + /*
1.671 + * GstCaps *newcaps; newcaps = gst_pad_get_caps (mux->sinkpad);
1.672 + *
1.673 + * g_debug ("CAPS: %s",gst_caps_to_string (newcaps));
1.674 + *
1.675 + * if (!gst_pad_set_caps (mux->srcpad, newcaps)) goto nego_error;
1.676 + */
1.677 + mux->negotiated = TRUE;
1.678 + }
1.679
1.680 - g_debug ("CAPS: %s",gst_caps_to_string (newcaps));
1.681 + /*
1.682 + * g_debug ("Running [%s]\n" "\tTOFFSET [%"G_GUINT64_FORMAT"]\n"
1.683 + * "\tB_TSTAMP [%"G_GUINT64_FORMAT"]\n" "\tB_DURATION
1.684 + * [%"G_GUINT64_FORMAT"]\n" "\tOFFSET [%"G_GUINT64_FORMAT"]\n"
1.685 + * "\tB_OFFSET [%"G_GUINT64_FORMAT"]", gst_element_get_name (mux),
1.686 + * mux->timeoffset, GST_BUFFER_TIMESTAMP (databuf),
1.687 + * GST_BUFFER_DURATION (databuf), mux->offset, GST_BUFFER_OFFSET
1.688 + * (databuf));
1.689 + */
1.690
1.691 - if (!gst_pad_set_caps (mux->srcpad, newcaps))
1.692 - goto nego_error;
1.693 - */
1.694 - mux->negotiated = TRUE;
1.695 - }
1.696
1.697 - /*
1.698 - g_debug ("Running [%s]\n"
1.699 - "\tTOFFSET [%"G_GUINT64_FORMAT"]\n"
1.700 - "\tB_TSTAMP [%"G_GUINT64_FORMAT"]\n"
1.701 - "\tB_DURATION [%"G_GUINT64_FORMAT"]\n"
1.702 - "\tOFFSET [%"G_GUINT64_FORMAT"]\n"
1.703 - "\tB_OFFSET [%"G_GUINT64_FORMAT"]",
1.704 - gst_element_get_name (mux),
1.705 - mux->timeoffset,
1.706 - GST_BUFFER_TIMESTAMP (databuf),
1.707 - GST_BUFFER_DURATION (databuf),
1.708 - mux->offset,
1.709 - GST_BUFFER_OFFSET (databuf));
1.710 - */
1.711 + if (mux->resync) {
1.712 + g_debug("RESYNC [%s]", gst_element_get_name(mux));
1.713 + mux->timeoffset += GST_BUFFER_TIMESTAMP(databuf);
1.714 + GST_BUFFER_TIMESTAMP(databuf) = mux->timeoffset;
1.715 + mux->timeoffset += GST_BUFFER_DURATION(databuf);
1.716
1.717 + mux->offset += GST_BUFFER_OFFSET(databuf);
1.718 + GST_BUFFER_OFFSET(databuf) = mux->offset;
1.719 + mux->offset += GST_BUFFER_SIZE(databuf);
1.720 + mux->resync = FALSE;
1.721 + } else {
1.722
1.723 - if (mux->resync)
1.724 - {
1.725 - g_debug("RESYNC [%s]", gst_element_get_name(mux));
1.726 - mux->timeoffset += GST_BUFFER_TIMESTAMP(databuf);
1.727 - GST_BUFFER_TIMESTAMP(databuf) = mux->timeoffset;
1.728 - mux->timeoffset += GST_BUFFER_DURATION(databuf);
1.729 + GST_BUFFER_TIMESTAMP(databuf) = mux->timeoffset;
1.730 + mux->timeoffset += GST_BUFFER_DURATION(databuf);
1.731
1.732 - mux->offset += GST_BUFFER_OFFSET(databuf);
1.733 - GST_BUFFER_OFFSET(databuf) = mux->offset;
1.734 - mux->offset += GST_BUFFER_SIZE(databuf);
1.735 - mux->resync = FALSE;
1.736 - }
1.737 - else
1.738 - {
1.739 + GST_BUFFER_OFFSET(databuf) = mux->offset;
1.740 + mux->offset += GST_BUFFER_SIZE(databuf);
1.741 + }
1.742
1.743 - GST_BUFFER_TIMESTAMP(databuf) = mux->timeoffset;
1.744 - mux->timeoffset += GST_BUFFER_DURATION(databuf);
1.745 + gst_buffer_set_caps(databuf, GST_PAD_CAPS(pad));
1.746 + ret = gst_pad_push(mux->srcpad, databuf);
1.747
1.748 - GST_BUFFER_OFFSET(databuf) = mux->offset;
1.749 - mux->offset += GST_BUFFER_SIZE(databuf);
1.750 - }
1.751 + // gst_buffer_unref (buf);
1.752
1.753 - gst_buffer_set_caps(databuf, GST_PAD_CAPS(pad));
1.754 - ret = gst_pad_push(mux->srcpad, databuf);
1.755 -
1.756 - //gst_buffer_unref (buf);
1.757 -
1.758 - g_mutex_unlock(mutex);
1.759 - return ret;
1.760 -/*
1.761 -nego_error:
1.762 - {
1.763 - GST_WARNING_OBJECT (mux, "failed to set caps");
1.764 - GST_ELEMENT_ERROR (mux, CORE, NEGOTIATION, (NULL), (NULL));
1.765 - return GST_FLOW_NOT_NEGOTIATED;
1.766 - }
1.767 - */
1.768 - /*
1.769 - no_caps:
1.770 - {
1.771 - GST_WARNING_OBJECT (mux, "no caps on the incoming buffer %p", best->buffer);
1.772 - GST_ELEMENT_ERROR (mux, CORE, NEGOTIATION, (NULL), (NULL));
1.773 - ret = GST_FLOW_NOT_NEGOTIATED;
1.774 - goto beach;
1.775 - }
1.776 - */
1.777 + g_mutex_unlock(mutex);
1.778 + return ret;
1.779 + /*
1.780 + * nego_error: { GST_WARNING_OBJECT (mux, "failed to set caps");
1.781 + * GST_ELEMENT_ERROR (mux, CORE, NEGOTIATION, (NULL), (NULL)); return
1.782 + * GST_FLOW_NOT_NEGOTIATED; }
1.783 + */
1.784 + /*
1.785 + * no_caps: { GST_WARNING_OBJECT (mux, "no caps on the incoming buffer
1.786 + * %p", best->buffer); GST_ELEMENT_ERROR (mux, CORE, NEGOTIATION,
1.787 + * (NULL), (NULL)); ret = GST_FLOW_NOT_NEGOTIATED; goto beach; }
1.788 + */
1.789 }
1.790
1.791 -static GstStateChangeReturn
1.792 -gst_concat_mux_change_state(GstElement * element, GstStateChange transition)
1.793 +static GstStateChangeReturn
1.794 +gst_concat_mux_change_state(GstElement * element,
1.795 + GstStateChange transition)
1.796 {
1.797 - GstConcatMux *concat_mux;
1.798 - GstStateChangeReturn ret;
1.799 + GstConcatMux *concat_mux;
1.800 + GstStateChangeReturn ret;
1.801
1.802 - concat_mux = GST_CONCAT_MUX(element);
1.803 + concat_mux = GST_CONCAT_MUX(element);
1.804
1.805 - switch (transition)
1.806 - {
1.807 - case GST_STATE_CHANGE_READY_TO_PAUSED:
1.808 - concat_mux->done = FALSE;
1.809 - concat_mux->resync = TRUE;
1.810 - GST_DEBUG_OBJECT(concat_mux, "starting collect pads");
1.811 - break;
1.812 - case GST_STATE_CHANGE_PAUSED_TO_READY:
1.813 - GST_DEBUG_OBJECT(concat_mux, "stopping collect pads");
1.814 - gst_concat_mux_clear(concat_mux);
1.815 - break;
1.816 - default:
1.817 - break;
1.818 - }
1.819 + switch (transition) {
1.820 + case GST_STATE_CHANGE_READY_TO_PAUSED:
1.821 + concat_mux->done = FALSE;
1.822 + concat_mux->resync = TRUE;
1.823 + GST_DEBUG_OBJECT(concat_mux, "starting collect pads");
1.824 + break;
1.825 + case GST_STATE_CHANGE_PAUSED_TO_READY:
1.826 + GST_DEBUG_OBJECT(concat_mux, "stopping collect pads");
1.827 + gst_concat_mux_clear(concat_mux);
1.828 + break;
1.829 + default:
1.830 + break;
1.831 + }
1.832
1.833 - ret = GST_ELEMENT_CLASS(parent_class)->change_state(element, transition);
1.834 - if (ret == GST_STATE_CHANGE_FAILURE)
1.835 - return ret;
1.836 + ret =
1.837 + GST_ELEMENT_CLASS(parent_class)->change_state(element, transition);
1.838 + if (ret == GST_STATE_CHANGE_FAILURE)
1.839 + return ret;
1.840
1.841 - switch (transition)
1.842 - {
1.843 - default:
1.844 - break;
1.845 - }
1.846 + switch (transition) {
1.847 + default:
1.848 + break;
1.849 + }
1.850
1.851 - return ret;
1.852 + return ret;
1.853 }
1.854
1.855 gboolean
1.856 gst_concat_mux_plugin_init(GstPlugin * plugin)
1.857 {
1.858 #ifdef ENABLE_NLS
1.859 - setlocale(LC_ALL, "");
1.860 - bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
1.861 -#endif /* ENABLE_NLS */
1.862 + setlocale(LC_ALL, "");
1.863 + bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
1.864 +#endif /* ENABLE_NLS */
1.865
1.866 - GST_DEBUG_CATEGORY_INIT(gst_concat_mux_debug, "concatmux", 0,
1.867 - "concat muxer");
1.868 + GST_DEBUG_CATEGORY_INIT(gst_concat_mux_debug, "concatmux", 0,
1.869 + "concat muxer");
1.870
1.871 - return gst_element_register(plugin, "concatmux", GST_RANK_NONE,
1.872 - GST_TYPE_CONCAT_MUX);
1.873 + return gst_element_register(plugin, "concatmux", GST_RANK_NONE,
1.874 + GST_TYPE_CONCAT_MUX);
1.875 }
1.876
1.877 GST_PLUGIN_DEFINE(GST_VERSION_MAJOR,
1.878 - GST_VERSION_MINOR,
1.879 - "concatmux",
1.880 - "Concat streamers",
1.881 - gst_concat_mux_plugin_init, VERSION, GST_LICENSE,
1.882 - GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
1.883 + GST_VERSION_MINOR,
1.884 + "concatmux",
1.885 + "Concat streamers",
1.886 + gst_concat_mux_plugin_init, VERSION, GST_LICENSE,
1.887 + GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)