1 /* multipart muxer plugin for GStreamer
2 * Copyright (C) 2004 Wim Taymans <wim@fluendo.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 /**
21 * SECTION:element-multipartmux
22 *
23 * MultipartMux uses the #GstCaps of the sink pad as the Content-type field for
24 * incoming buffers when muxing them to a multipart stream. Most of the time
25 * multipart streams are sequential JPEG frames.
26 *
27 * <refsect2>
28 * <title>Sample pipelines</title>
29 * |[
30 * gst-launch-1.0 videotestsrc ! video/x-raw, framerate='(fraction)'5/1 ! jpegenc ! multipartmux ! filesink location=/tmp/test.multipart
31 * ]| a pipeline to mux 5 JPEG frames per second into a multipart stream
32 * stored to a file.
33 * </refsect2>
34 */
35
36 /* FIXME: drop/merge tag events, or at least send them delayed after stream-start */
37 #ifdef HAVE_CONFIG_H
38 #include "config.h"
39 #endif
40
41 #include "multipartmux.h"
42
43 GST_DEBUG_CATEGORY_STATIC (gst_multipart_mux_debug);
44 #define GST_CAT_DEFAULT gst_multipart_mux_debug
45
46 #define DEFAULT_BOUNDARY "ThisRandomString"
47
48 enum
49 {
50 PROP_0,
51 PROP_BOUNDARY
52 /* FILL ME */
53 };
54
55 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
56 GST_PAD_SRC,
57 GST_PAD_ALWAYS,
58 GST_STATIC_CAPS ("multipart/x-mixed-replace")
59 );
60
61 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink_%u",
62 GST_PAD_SINK,
63 GST_PAD_REQUEST,
64 GST_STATIC_CAPS_ANY /* we can take anything, really */
65 );
66
67 typedef struct
68 {
69 const gchar *key;
70 const gchar *val;
71 } MimeTypeMap;
72
73 /* convert from gst structure names to mime types. Add more when needed. */
74 static const MimeTypeMap mimetypes[] = {
75 {"audio/x-mulaw", "audio/basic"},
76 {NULL, NULL}
77 };
78
79 static void gst_multipart_mux_finalize (GObject * object);
80
81 static gboolean gst_multipart_mux_handle_src_event (GstPad * pad,
82 GstObject * parent, GstEvent * event);
83 static GstPad *gst_multipart_mux_request_new_pad (GstElement * element,
84 GstPadTemplate * templ, const gchar * name, const GstCaps * caps);
85 static GstStateChangeReturn gst_multipart_mux_change_state (GstElement *
86 element, GstStateChange transition);
87
88 static gboolean gst_multipart_mux_sink_event (GstCollectPads * pads,
89 GstCollectData * pad, GstEvent * event, GstMultipartMux * mux);
90 static GstFlowReturn gst_multipart_mux_collected (GstCollectPads * pads,
91 GstMultipartMux * mux);
92
93 static void gst_multipart_mux_set_property (GObject * object, guint prop_id,
94 const GValue * value, GParamSpec * pspec);
95 static void gst_multipart_mux_get_property (GObject * object, guint prop_id,
96 GValue * value, GParamSpec * pspec);
97
98 #define gst_multipart_mux_parent_class parent_class
99 G_DEFINE_TYPE (GstMultipartMux, gst_multipart_mux, GST_TYPE_ELEMENT);
100
101 static void
gst_multipart_mux_class_init(GstMultipartMuxClass * klass)102 gst_multipart_mux_class_init (GstMultipartMuxClass * klass)
103 {
104 GObjectClass *gobject_class;
105 GstElementClass *gstelement_class;
106 gint i;
107
108 gobject_class = (GObjectClass *) klass;
109 gstelement_class = (GstElementClass *) klass;
110
111 parent_class = g_type_class_peek_parent (klass);
112
113 gobject_class->finalize = gst_multipart_mux_finalize;
114 gobject_class->get_property = gst_multipart_mux_get_property;
115 gobject_class->set_property = gst_multipart_mux_set_property;
116
117 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_BOUNDARY,
118 g_param_spec_string ("boundary", "Boundary", "Boundary string",
119 DEFAULT_BOUNDARY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
120
121 gstelement_class->request_new_pad = gst_multipart_mux_request_new_pad;
122 gstelement_class->change_state = gst_multipart_mux_change_state;
123
124 gst_element_class_add_static_pad_template (gstelement_class, &src_factory);
125 gst_element_class_add_static_pad_template (gstelement_class, &sink_factory);
126
127 gst_element_class_set_static_metadata (gstelement_class, "Multipart muxer",
128 "Codec/Muxer", "mux multipart streams", "Wim Taymans <wim@fluendo.com>");
129
130 /* populate mime types */
131 klass->mimetypes = g_hash_table_new (g_str_hash, g_str_equal);
132 for (i = 0; mimetypes[i].key; i++) {
133 g_hash_table_insert (klass->mimetypes, (gpointer) mimetypes[i].key,
134 (gpointer) mimetypes[i].val);
135 }
136 }
137
138 static void
gst_multipart_mux_init(GstMultipartMux * multipart_mux)139 gst_multipart_mux_init (GstMultipartMux * multipart_mux)
140 {
141 GstElementClass *klass = GST_ELEMENT_GET_CLASS (multipart_mux);
142
143 multipart_mux->srcpad =
144 gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
145 "src"), "src");
146 gst_pad_set_event_function (multipart_mux->srcpad,
147 gst_multipart_mux_handle_src_event);
148 gst_element_add_pad (GST_ELEMENT (multipart_mux), multipart_mux->srcpad);
149
150 multipart_mux->boundary = g_strdup (DEFAULT_BOUNDARY);
151
152 multipart_mux->collect = gst_collect_pads_new ();
153 gst_collect_pads_set_event_function (multipart_mux->collect,
154 (GstCollectPadsEventFunction)
155 GST_DEBUG_FUNCPTR (gst_multipart_mux_sink_event), multipart_mux);
156 gst_collect_pads_set_function (multipart_mux->collect,
157 (GstCollectPadsFunction) GST_DEBUG_FUNCPTR (gst_multipart_mux_collected),
158 multipart_mux);
159 }
160
161 static void
gst_multipart_mux_finalize(GObject * object)162 gst_multipart_mux_finalize (GObject * object)
163 {
164 GstMultipartMux *multipart_mux;
165
166 multipart_mux = GST_MULTIPART_MUX (object);
167
168 g_free (multipart_mux->boundary);
169
170 if (multipart_mux->collect)
171 gst_object_unref (multipart_mux->collect);
172
173 G_OBJECT_CLASS (parent_class)->finalize (object);
174 }
175
176 static GstPad *
gst_multipart_mux_request_new_pad(GstElement * element,GstPadTemplate * templ,const gchar * req_name,const GstCaps * caps)177 gst_multipart_mux_request_new_pad (GstElement * element,
178 GstPadTemplate * templ, const gchar * req_name, const GstCaps * caps)
179 {
180 GstMultipartMux *multipart_mux;
181 GstPad *newpad;
182 GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
183 gchar *name;
184
185 if (templ != gst_element_class_get_pad_template (klass, "sink_%u"))
186 goto wrong_template;
187
188 multipart_mux = GST_MULTIPART_MUX (element);
189
190 /* create new pad with the name */
191 name = g_strdup_printf ("sink_%u", multipart_mux->numpads);
192 newpad = gst_pad_new_from_template (templ, name);
193 g_free (name);
194
195 /* construct our own wrapper data structure for the pad to
196 * keep track of its status */
197 {
198 GstMultipartPadData *multipartpad;
199
200 multipartpad = (GstMultipartPadData *)
201 gst_collect_pads_add_pad (multipart_mux->collect, newpad,
202 sizeof (GstMultipartPadData), NULL, TRUE);
203
204 /* save a pointer to our data in the pad */
205 multipartpad->pad = newpad;
206 gst_pad_set_element_private (newpad, multipartpad);
207 multipart_mux->numpads++;
208 }
209
210 /* add the pad to the element */
211 gst_element_add_pad (element, newpad);
212
213 return newpad;
214
215 /* ERRORS */
216 wrong_template:
217 {
218 g_warning ("multipart_mux: this is not our template!");
219 return NULL;
220 }
221 }
222
223 /* handle events */
224 static gboolean
gst_multipart_mux_handle_src_event(GstPad * pad,GstObject * parent,GstEvent * event)225 gst_multipart_mux_handle_src_event (GstPad * pad, GstObject * parent,
226 GstEvent * event)
227 {
228 GstEventType type;
229
230 type = event ? GST_EVENT_TYPE (event) : GST_EVENT_UNKNOWN;
231
232 switch (type) {
233 case GST_EVENT_SEEK:
234 /* disable seeking for now */
235 return FALSE;
236 default:
237 break;
238 }
239
240 return gst_pad_event_default (pad, parent, event);
241 }
242
243 static const gchar *
gst_multipart_mux_get_mime(GstMultipartMux * mux,GstStructure * s)244 gst_multipart_mux_get_mime (GstMultipartMux * mux, GstStructure * s)
245 {
246 GstMultipartMuxClass *klass;
247 const gchar *mime;
248 const gchar *name;
249 gint rate;
250 gint channels;
251 gint bitrate = 0;
252
253 klass = GST_MULTIPART_MUX_GET_CLASS (mux);
254
255 name = gst_structure_get_name (s);
256
257 /* use hashtable to convert to mime type */
258 mime = g_hash_table_lookup (klass->mimetypes, name);
259 if (mime == NULL) {
260 if (!strcmp (name, "audio/x-adpcm"))
261 gst_structure_get_int (s, "bitrate", &bitrate);
262
263 switch (bitrate) {
264 case 16000:
265 mime = "audio/G726-16";
266 break;
267 case 24000:
268 mime = "audio/G726-24";
269 break;
270 case 32000:
271 mime = "audio/G726-32";
272 break;
273 case 40000:
274 mime = "audio/G726-40";
275 break;
276 default:
277 /* no mime type mapping, use name */
278 mime = name;
279 break;
280 }
281 }
282 /* RFC2046 requires audio/basic to be mulaw 8000Hz mono */
283 if (g_ascii_strcasecmp (mime, "audio/basic") == 0) {
284 if (gst_structure_get_int (s, "rate", &rate) &&
285 gst_structure_get_int (s, "channels", &channels)) {
286 if (rate != 8000 || channels != 1) {
287 mime = name;
288 }
289 } else {
290 mime = name;
291 }
292 }
293 return mime;
294 }
295
296 /*
297 * Given two pads, compare the buffers queued on it and return 0 if they have
298 * an equal priority, 1 if the new pad is better, -1 if the old pad is better
299 */
300 static gint
gst_multipart_mux_compare_pads(GstMultipartMux * multipart_mux,GstMultipartPadData * old,GstMultipartPadData * new)301 gst_multipart_mux_compare_pads (GstMultipartMux * multipart_mux,
302 GstMultipartPadData * old, GstMultipartPadData * new)
303 {
304 guint64 oldtime, newtime;
305
306 /* if the old pad doesn't contain anything or is even NULL, return
307 * the new pad as best candidate and vice versa */
308 if (old == NULL || old->buffer == NULL)
309 return 1;
310 if (new == NULL || new->buffer == NULL)
311 return -1;
312
313 if (GST_CLOCK_TIME_IS_VALID (old->dts_timestamp) &&
314 GST_CLOCK_TIME_IS_VALID (new->dts_timestamp)) {
315 oldtime = old->dts_timestamp;
316 newtime = new->dts_timestamp;
317 } else {
318 oldtime = old->pts_timestamp;
319 newtime = new->pts_timestamp;
320 }
321
322 /* no timestamp on old buffer, it must go first */
323 if (oldtime == GST_CLOCK_TIME_NONE)
324 return -1;
325
326 /* no timestamp on new buffer, it must go first */
327 if (newtime == GST_CLOCK_TIME_NONE)
328 return 1;
329
330 /* old buffer has higher timestamp, new one should go first */
331 if (newtime < oldtime)
332 return 1;
333 /* new buffer has higher timestamp, old one should go first */
334 else if (newtime > oldtime)
335 return -1;
336
337 /* same priority if all of the above failed */
338 return 0;
339 }
340
341 /* make sure a buffer is queued on all pads, returns a pointer to an multipartpad
342 * that holds the best buffer or NULL when no pad was usable */
343 static GstMultipartPadData *
gst_multipart_mux_queue_pads(GstMultipartMux * mux)344 gst_multipart_mux_queue_pads (GstMultipartMux * mux)
345 {
346 GSList *walk = NULL;
347 GstMultipartPadData *bestpad = NULL;
348
349 g_return_val_if_fail (GST_IS_MULTIPART_MUX (mux), NULL);
350
351 /* try to make sure we have a buffer from each usable pad first */
352 walk = mux->collect->data;
353 while (walk) {
354 GstCollectData *data = (GstCollectData *) walk->data;
355 GstMultipartPadData *pad = (GstMultipartPadData *) data;
356
357 walk = g_slist_next (walk);
358
359 /* try to get a new buffer for this pad if needed and possible */
360 if (pad->buffer == NULL) {
361 GstBuffer *buf = NULL;
362
363 buf = gst_collect_pads_pop (mux->collect, data);
364
365 /* Store timestamps with segment_start and preroll */
366 if (buf && GST_BUFFER_PTS_IS_VALID (buf)) {
367 pad->pts_timestamp =
368 gst_segment_to_running_time (&data->segment, GST_FORMAT_TIME,
369 GST_BUFFER_PTS (buf));
370 } else {
371 pad->pts_timestamp = GST_CLOCK_TIME_NONE;
372 }
373 if (buf && GST_BUFFER_DTS_IS_VALID (buf)) {
374 pad->dts_timestamp =
375 gst_segment_to_running_time (&data->segment, GST_FORMAT_TIME,
376 GST_BUFFER_DTS (buf));
377 } else {
378 pad->dts_timestamp = GST_CLOCK_TIME_NONE;
379 }
380
381
382 pad->buffer = buf;
383 }
384
385 /* we should have a buffer now, see if it is the best stream to
386 * pull on */
387 if (pad->buffer != NULL) {
388 if (gst_multipart_mux_compare_pads (mux, bestpad, pad) > 0) {
389 bestpad = pad;
390 }
391 }
392 }
393
394 return bestpad;
395 }
396
397 static gboolean
gst_multipart_mux_sink_event(GstCollectPads * pads,GstCollectData * data,GstEvent * event,GstMultipartMux * mux)398 gst_multipart_mux_sink_event (GstCollectPads * pads, GstCollectData * data,
399 GstEvent * event, GstMultipartMux * mux)
400 {
401 gboolean ret;
402
403 switch (GST_EVENT_TYPE (event)) {
404 case GST_EVENT_FLUSH_STOP:
405 {
406 mux->need_segment = TRUE;
407 break;
408 }
409 default:
410 break;
411 }
412
413 ret = gst_collect_pads_event_default (pads, data, event, FALSE);
414
415 return ret;
416 }
417
418 /* basic idea:
419 *
420 * 1) find a pad to pull on, this is done by pulling on all pads and
421 * looking at the buffers to decide which one should be muxed first.
422 * 2) create a new buffer for the header
423 * 3) push both buffers on best pad, go to 1
424 */
425 static GstFlowReturn
gst_multipart_mux_collected(GstCollectPads * pads,GstMultipartMux * mux)426 gst_multipart_mux_collected (GstCollectPads * pads, GstMultipartMux * mux)
427 {
428 GstMultipartPadData *best;
429 GstFlowReturn ret = GST_FLOW_OK;
430 gchar *header = NULL;
431 size_t headerlen;
432 GstBuffer *headerbuf = NULL;
433 GstBuffer *footerbuf = NULL;
434 GstBuffer *databuf = NULL;
435 GstStructure *structure = NULL;
436 GstCaps *caps;
437 const gchar *mime;
438
439 GST_DEBUG_OBJECT (mux, "all pads are collected");
440
441 if (mux->need_stream_start) {
442 gchar s_id[32];
443
444 /* stream-start (FIXME: create id based on input ids) */
445 g_snprintf (s_id, sizeof (s_id), "multipartmux-%08x", g_random_int ());
446 gst_pad_push_event (mux->srcpad, gst_event_new_stream_start (s_id));
447
448 mux->need_stream_start = FALSE;
449 }
450
451 /* queue buffers on all pads; find a buffer with the lowest timestamp */
452 best = gst_multipart_mux_queue_pads (mux);
453 if (!best)
454 /* EOS */
455 goto eos;
456 else if (!best->buffer)
457 goto buffer_error;
458
459 /* If not negotiated yet set caps on src pad */
460 if (!mux->negotiated) {
461 GstCaps *newcaps;
462
463 newcaps = gst_caps_new_simple ("multipart/x-mixed-replace",
464 "boundary", G_TYPE_STRING, mux->boundary, NULL);
465
466 if (!gst_pad_set_caps (mux->srcpad, newcaps)) {
467 gst_caps_unref (newcaps);
468 goto nego_error;
469 }
470
471 gst_caps_unref (newcaps);
472 mux->negotiated = TRUE;
473 }
474
475 /* see if we need to push a segment */
476 if (mux->need_segment) {
477 GstClockTime time;
478 GstSegment segment;
479
480 if (best->dts_timestamp != GST_CLOCK_TIME_NONE) {
481 time = best->dts_timestamp;
482 } else if (best->pts_timestamp != GST_CLOCK_TIME_NONE) {
483 time = best->pts_timestamp;
484 } else {
485 time = 0;
486 }
487
488 /* for the segment, we take the first timestamp we see, we don't know the
489 * length and the position is 0 */
490 gst_segment_init (&segment, GST_FORMAT_TIME);
491 segment.start = time;
492
493 gst_pad_push_event (mux->srcpad, gst_event_new_segment (&segment));
494
495 mux->need_segment = FALSE;
496 }
497
498 caps = gst_pad_get_current_caps (best->pad);
499 if (caps == NULL)
500 goto no_caps;
501
502 structure = gst_caps_get_structure (caps, 0);
503 if (!structure) {
504 gst_caps_unref (caps);
505 goto no_caps;
506 }
507
508 /* get the mime type for the structure */
509 mime = gst_multipart_mux_get_mime (mux, structure);
510 gst_caps_unref (caps);
511
512 header = g_strdup_printf ("--%s\r\nContent-Type: %s\r\n"
513 "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n",
514 mux->boundary, mime, gst_buffer_get_size (best->buffer));
515 headerlen = strlen (header);
516
517 headerbuf = gst_buffer_new_allocate (NULL, headerlen, NULL);
518 gst_buffer_fill (headerbuf, 0, header, headerlen);
519 g_free (header);
520
521 /* the header has the same timestamps as the data buffer (which we will push
522 * below) and has a duration of 0 */
523 GST_BUFFER_PTS (headerbuf) = best->pts_timestamp;
524 GST_BUFFER_DTS (headerbuf) = best->dts_timestamp;
525 GST_BUFFER_DURATION (headerbuf) = 0;
526 GST_BUFFER_OFFSET (headerbuf) = mux->offset;
527 mux->offset += headerlen;
528 GST_BUFFER_OFFSET_END (headerbuf) = mux->offset;
529
530 GST_DEBUG_OBJECT (mux, "pushing %" G_GSIZE_FORMAT " bytes header buffer",
531 headerlen);
532 ret = gst_pad_push (mux->srcpad, headerbuf);
533 if (ret != GST_FLOW_OK)
534 /* push always takes ownership of the buffer, even after an error, so we
535 * don't need to unref headerbuf here. */
536 goto beach;
537
538 /* take best->buffer, we don't need to unref it later as we will push it
539 * now. */
540 databuf = gst_buffer_make_writable (best->buffer);
541 best->buffer = NULL;
542
543 /* we need to updated the timestamps to match the running_time */
544 GST_BUFFER_PTS (databuf) = best->pts_timestamp;
545 GST_BUFFER_DTS (databuf) = best->dts_timestamp;
546 GST_BUFFER_OFFSET (databuf) = mux->offset;
547 mux->offset += gst_buffer_get_size (databuf);
548 GST_BUFFER_OFFSET_END (databuf) = mux->offset;
549 GST_BUFFER_FLAG_SET (databuf, GST_BUFFER_FLAG_DELTA_UNIT);
550
551 GST_DEBUG_OBJECT (mux, "pushing %" G_GSIZE_FORMAT " bytes data buffer",
552 gst_buffer_get_size (databuf));
553 ret = gst_pad_push (mux->srcpad, databuf);
554 if (ret != GST_FLOW_OK)
555 /* push always takes ownership of the buffer, even after an error, so we
556 * don't need to unref headerbuf here. */
557 goto beach;
558
559 footerbuf = gst_buffer_new_allocate (NULL, 2, NULL);
560 gst_buffer_fill (footerbuf, 0, "\r\n", 2);
561
562 /* the footer has the same timestamps as the data buffer and has a
563 * duration of 0 */
564 GST_BUFFER_PTS (footerbuf) = best->pts_timestamp;
565 GST_BUFFER_DTS (footerbuf) = best->dts_timestamp;
566 GST_BUFFER_DURATION (footerbuf) = 0;
567 GST_BUFFER_OFFSET (footerbuf) = mux->offset;
568 mux->offset += 2;
569 GST_BUFFER_OFFSET_END (footerbuf) = mux->offset;
570 GST_BUFFER_FLAG_SET (footerbuf, GST_BUFFER_FLAG_DELTA_UNIT);
571
572 GST_DEBUG_OBJECT (mux, "pushing 2 bytes footer buffer");
573 ret = gst_pad_push (mux->srcpad, footerbuf);
574
575 beach:
576 if (best && best->buffer) {
577 gst_buffer_unref (best->buffer);
578 best->buffer = NULL;
579 }
580 return ret;
581
582 /* ERRORS */
583 buffer_error:
584 {
585 /* There is a best but no buffer, this is not quite right.. */
586 GST_ELEMENT_ERROR (mux, STREAM, FAILED, (NULL), ("internal muxing error"));
587 ret = GST_FLOW_ERROR;
588 goto beach;
589 }
590 eos:
591 {
592 GST_DEBUG_OBJECT (mux, "Pushing EOS");
593 gst_pad_push_event (mux->srcpad, gst_event_new_eos ());
594 ret = GST_FLOW_EOS;
595 goto beach;
596 }
597 nego_error:
598 {
599 GST_WARNING_OBJECT (mux, "failed to set caps");
600 GST_ELEMENT_ERROR (mux, CORE, NEGOTIATION, (NULL), (NULL));
601 ret = GST_FLOW_NOT_NEGOTIATED;
602 goto beach;
603 }
604 no_caps:
605 {
606 GST_WARNING_OBJECT (mux, "no caps on the incoming buffer %p", best->buffer);
607 GST_ELEMENT_ERROR (mux, CORE, NEGOTIATION, (NULL), (NULL));
608 ret = GST_FLOW_NOT_NEGOTIATED;
609 goto beach;
610 }
611 }
612
613 static void
gst_multipart_mux_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)614 gst_multipart_mux_get_property (GObject * object,
615 guint prop_id, GValue * value, GParamSpec * pspec)
616 {
617 GstMultipartMux *mux;
618
619 mux = GST_MULTIPART_MUX (object);
620
621 switch (prop_id) {
622 case PROP_BOUNDARY:
623 g_value_set_string (value, mux->boundary);
624 break;
625 default:
626 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
627 break;
628 }
629 }
630
631 static void
gst_multipart_mux_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)632 gst_multipart_mux_set_property (GObject * object,
633 guint prop_id, const GValue * value, GParamSpec * pspec)
634 {
635 GstMultipartMux *mux;
636
637 mux = GST_MULTIPART_MUX (object);
638
639 switch (prop_id) {
640 case PROP_BOUNDARY:
641 g_free (mux->boundary);
642 mux->boundary = g_strdup (g_value_get_string (value));
643 break;
644 default:
645 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
646 break;
647 }
648 }
649
650 static GstStateChangeReturn
gst_multipart_mux_change_state(GstElement * element,GstStateChange transition)651 gst_multipart_mux_change_state (GstElement * element, GstStateChange transition)
652 {
653 GstMultipartMux *multipart_mux;
654 GstStateChangeReturn ret;
655
656 multipart_mux = GST_MULTIPART_MUX (element);
657
658 switch (transition) {
659 case GST_STATE_CHANGE_READY_TO_PAUSED:
660 multipart_mux->offset = 0;
661 multipart_mux->negotiated = FALSE;
662 multipart_mux->need_segment = TRUE;
663 multipart_mux->need_stream_start = TRUE;
664 GST_DEBUG_OBJECT (multipart_mux, "starting collect pads");
665 gst_collect_pads_start (multipart_mux->collect);
666 break;
667 case GST_STATE_CHANGE_PAUSED_TO_READY:
668 GST_DEBUG_OBJECT (multipart_mux, "stopping collect pads");
669 gst_collect_pads_stop (multipart_mux->collect);
670 break;
671 default:
672 break;
673 }
674
675 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
676 if (ret == GST_STATE_CHANGE_FAILURE)
677 return ret;
678
679 switch (transition) {
680 default:
681 break;
682 }
683
684 return ret;
685 }
686
687 gboolean
gst_multipart_mux_plugin_init(GstPlugin * plugin)688 gst_multipart_mux_plugin_init (GstPlugin * plugin)
689 {
690 GST_DEBUG_CATEGORY_INIT (gst_multipart_mux_debug, "multipartmux", 0,
691 "multipart muxer");
692
693 return gst_element_register (plugin, "multipartmux", GST_RANK_NONE,
694 GST_TYPE_MULTIPART_MUX);
695 }
696