3 * Copyright (c) 2008,2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * SECTION:element-flvmux
24 * flvmux muxes different streams into an FLV file.
27 * <title>Example launch line</title>
29 * gst-launch -v filesrc location=/path/to/audio ! decodebin2 ! queue ! flvmux name=m ! filesink location=file.flv filesrc location=/path/to/video ! decodebin2 ! queue ! m.
30 * ]| This pipeline muxes an audio and video file into a single FLV file.
41 #include "gstflvmux.h"
44 GST_DEBUG_CATEGORY_STATIC (flvmux_debug);
45 #define GST_CAT_DEFAULT flvmux_debug
53 #define DEFAULT_STREAMABLE FALSE
54 #define MAX_INDEX_ENTRIES 128
56 static GstStaticPadTemplate src_templ = GST_STATIC_PAD_TEMPLATE ("src",
59 GST_STATIC_CAPS ("video/x-flv")
62 static GstStaticPadTemplate videosink_templ = GST_STATIC_PAD_TEMPLATE ("video",
65 GST_STATIC_CAPS ("video/x-flash-video; "
66 "video/x-flash-screen; "
67 "video/x-vp6-flash; " "video/x-vp6-alpha; "
68 "video/x-h264, stream-format=avc;")
71 static GstStaticPadTemplate audiosink_templ = GST_STATIC_PAD_TEMPLATE ("audio",
75 ("audio/x-adpcm, layout = (string) swf, channels = (int) { 1, 2 }, rate = (int) { 5512, 11025, 22050, 44100 }; "
76 "audio/mpeg, mpegversion = (int) 1, layer = (int) 3, channels = (int) { 1, 2 }, rate = (int) { 5512, 8000, 11025, 22050, 44100 }, parsed = (boolean) TRUE; "
77 "audio/mpeg, mpegversion = (int) { 2, 4 }, framed = (boolean) TRUE; "
78 "audio/x-nellymoser, channels = (int) { 1, 2 }, rate = (int) { 5512, 8000, 11025, 16000, 22050, 44100 }; "
79 "audio/x-raw-int, endianness = (int) LITTLE_ENDIAN, channels = (int) { 1, 2 }, width = (int) 8, depth = (int) 8, rate = (int) { 5512, 11025, 22050, 44100 }, signed = (boolean) FALSE; "
80 "audio/x-raw-int, endianness = (int) LITTLE_ENDIAN, channels = (int) { 1, 2 }, width = (int) 16, depth = (int) 16, rate = (int) { 5512, 11025, 22050, 44100 }, signed = (boolean) TRUE; "
81 "audio/x-alaw, channels = (int) { 1, 2 }, rate = (int) { 5512, 11025, 22050, 44100 }; "
82 "audio/x-mulaw, channels = (int) { 1, 2 }, rate = (int) { 5512, 11025, 22050, 44100 }; "
83 "audio/x-speex, channels = (int) { 1, 2 }, rate = (int) { 5512, 11025, 22050, 44100 };")
86 #define _do_init(type) \
88 static const GInterfaceInfo tag_setter_info = { \
93 g_type_add_interface_static (type, GST_TYPE_TAG_SETTER, \
97 GST_BOILERPLATE_FULL (GstFlvMux, gst_flv_mux, GstElement, GST_TYPE_ELEMENT,
100 static void gst_flv_mux_finalize (GObject * object);
102 gst_flv_mux_handle_buffer (GstCollectPads2 * pads, GstCollectData2 * cdata,
103 GstBuffer * buf, gpointer user_data);
105 gst_flv_mux_handle_sink_event (GstCollectPads2 * pads, GstCollectData2 * data,
106 GstEvent * event, gpointer user_data);
108 static gboolean gst_flv_mux_handle_src_event (GstPad * pad, GstEvent * event);
109 static GstPad *gst_flv_mux_request_new_pad (GstElement * element,
110 GstPadTemplate * templ, const gchar * name);
111 static void gst_flv_mux_release_pad (GstElement * element, GstPad * pad);
113 static void gst_flv_mux_get_property (GObject * object,
114 guint prop_id, GValue * value, GParamSpec * pspec);
115 static void gst_flv_mux_set_property (GObject * object,
116 guint prop_id, const GValue * value, GParamSpec * pspec);
118 static GstStateChangeReturn
119 gst_flv_mux_change_state (GstElement * element, GstStateChange transition);
121 static void gst_flv_mux_reset (GstElement * element);
122 static void gst_flv_mux_reset_pad (GstFlvMux * mux, GstFlvPad * pad,
129 } GstFlvMuxIndexEntry;
132 gst_flv_mux_index_entry_free (GstFlvMuxIndexEntry * entry)
134 g_slice_free (GstFlvMuxIndexEntry, entry);
138 gst_flv_mux_base_init (gpointer g_class)
140 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
142 gst_element_class_add_static_pad_template (element_class,
144 gst_element_class_add_static_pad_template (element_class,
146 gst_element_class_add_static_pad_template (element_class, &src_templ);
147 gst_element_class_set_details_simple (element_class, "FLV muxer",
149 "Muxes video/audio streams into a FLV stream",
150 "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
152 GST_DEBUG_CATEGORY_INIT (flvmux_debug, "flvmux", 0, "FLV muxer");
156 gst_flv_mux_class_init (GstFlvMuxClass * klass)
158 GObjectClass *gobject_class;
159 GstElementClass *gstelement_class;
161 GST_DEBUG_CATEGORY_INIT (flvmux_debug, "flvmux", 0, "FLV muxer");
163 gobject_class = (GObjectClass *) klass;
164 gstelement_class = (GstElementClass *) klass;
166 gobject_class->get_property = gst_flv_mux_get_property;
167 gobject_class->set_property = gst_flv_mux_set_property;
168 gobject_class->finalize = gst_flv_mux_finalize;
170 /* FIXME: ideally the right mode of operation should be detected
171 * automatically using queries when parameter not specified. */
173 * GstFlvMux:streamable
175 * If True, the output will be streaming friendly. (ie without indexes and
180 g_object_class_install_property (gobject_class, PROP_STREAMABLE,
181 g_param_spec_boolean ("streamable", "streamable",
182 "If set to true, the output should be as if it is to be streamed "
183 "and hence no indexes written or duration written.",
184 DEFAULT_STREAMABLE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
186 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_flv_mux_change_state);
187 gstelement_class->request_new_pad =
188 GST_DEBUG_FUNCPTR (gst_flv_mux_request_new_pad);
189 gstelement_class->release_pad = GST_DEBUG_FUNCPTR (gst_flv_mux_release_pad);
193 gst_flv_mux_init (GstFlvMux * mux, GstFlvMuxClass * g_class)
195 mux->srcpad = gst_pad_new_from_static_template (&src_templ, "src");
196 gst_pad_set_event_function (mux->srcpad, gst_flv_mux_handle_src_event);
197 gst_element_add_pad (GST_ELEMENT (mux), mux->srcpad);
200 mux->streamable = DEFAULT_STREAMABLE;
202 mux->new_tags = FALSE;
204 mux->collect = gst_collect_pads2_new ();
205 gst_collect_pads2_set_buffer_function (mux->collect,
206 GST_DEBUG_FUNCPTR (gst_flv_mux_handle_buffer), mux);
207 gst_collect_pads2_set_event_function (mux->collect,
208 GST_DEBUG_FUNCPTR (gst_flv_mux_handle_sink_event), mux);
209 gst_collect_pads2_set_clip_function (mux->collect,
210 GST_DEBUG_FUNCPTR (gst_collect_pads2_clip_running_time), mux);
212 gst_flv_mux_reset (GST_ELEMENT (mux));
216 gst_flv_mux_finalize (GObject * object)
218 GstFlvMux *mux = GST_FLV_MUX (object);
220 gst_object_unref (mux->collect);
222 G_OBJECT_CLASS (parent_class)->finalize (object);
226 gst_flv_mux_reset (GstElement * element)
228 GstFlvMux *mux = GST_FLV_MUX (element);
231 for (sl = mux->collect->data; sl != NULL; sl = g_slist_next (sl)) {
232 GstFlvPad *cpad = (GstFlvPad *) sl->data;
234 gst_flv_mux_reset_pad (mux, cpad, cpad->video);
237 g_list_foreach (mux->index, (GFunc) gst_flv_mux_index_entry_free, NULL);
238 g_list_free (mux->index);
242 mux->have_audio = mux->have_video = FALSE;
243 mux->duration = GST_CLOCK_TIME_NONE;
244 mux->new_tags = FALSE;
246 mux->state = GST_FLV_MUX_STATE_HEADER;
249 gst_tag_setter_reset_tags (GST_TAG_SETTER (mux));
253 gst_flv_mux_handle_src_event (GstPad * pad, GstEvent * event)
257 type = event ? GST_EVENT_TYPE (event) : GST_EVENT_UNKNOWN;
261 /* disable seeking for now */
267 return gst_pad_event_default (pad, event);
271 gst_flv_mux_handle_sink_event (GstCollectPads2 * pads, GstCollectData2 * data,
272 GstEvent * event, gpointer user_data)
274 GstFlvMux *mux = GST_FLV_MUX (user_data);
276 switch (GST_EVENT_TYPE (event)) {
279 GstTagSetter *setter = GST_TAG_SETTER (mux);
280 const GstTagMergeMode mode = gst_tag_setter_get_tag_merge_mode (setter);
282 gst_event_parse_tag (event, &list);
283 gst_tag_setter_merge_tags (setter, list, mode);
284 mux->new_tags = TRUE;
291 /* now GstCollectPads2 can take care of the rest, e.g. EOS */
296 gst_flv_mux_video_pad_setcaps (GstPad * pad, GstCaps * caps)
298 GstFlvMux *mux = GST_FLV_MUX (gst_pad_get_parent (pad));
299 GstFlvPad *cpad = (GstFlvPad *) gst_pad_get_element_private (pad);
303 s = gst_caps_get_structure (caps, 0);
305 if (strcmp (gst_structure_get_name (s), "video/x-flash-video") == 0) {
306 cpad->video_codec = 2;
307 } else if (strcmp (gst_structure_get_name (s), "video/x-flash-screen") == 0) {
308 cpad->video_codec = 3;
309 } else if (strcmp (gst_structure_get_name (s), "video/x-vp6-flash") == 0) {
310 cpad->video_codec = 4;
311 } else if (strcmp (gst_structure_get_name (s), "video/x-vp6-alpha") == 0) {
312 cpad->video_codec = 5;
313 } else if (strcmp (gst_structure_get_name (s), "video/x-h264") == 0) {
314 cpad->video_codec = 7;
319 if (ret && gst_structure_has_field (s, "codec_data")) {
320 const GValue *val = gst_structure_get_value (s, "codec_data");
323 cpad->video_codec_data = gst_buffer_ref (gst_value_get_buffer (val));
326 gst_object_unref (mux);
332 gst_flv_mux_audio_pad_setcaps (GstPad * pad, GstCaps * caps)
334 GstFlvMux *mux = GST_FLV_MUX (gst_pad_get_parent (pad));
335 GstFlvPad *cpad = (GstFlvPad *) gst_pad_get_element_private (pad);
339 s = gst_caps_get_structure (caps, 0);
341 if (strcmp (gst_structure_get_name (s), "audio/x-adpcm") == 0) {
342 const gchar *layout = gst_structure_get_string (s, "layout");
343 if (layout && strcmp (layout, "swf") == 0) {
344 cpad->audio_codec = 1;
348 } else if (strcmp (gst_structure_get_name (s), "audio/mpeg") == 0) {
351 if (gst_structure_get_int (s, "mpegversion", &mpegversion)) {
352 if (mpegversion == 1) {
355 if (gst_structure_get_int (s, "layer", &layer) && layer == 3) {
358 if (gst_structure_get_int (s, "rate", &rate) && rate == 8000)
359 cpad->audio_codec = 14;
361 cpad->audio_codec = 2;
365 } else if (mpegversion == 4 || mpegversion == 2) {
366 cpad->audio_codec = 10;
373 } else if (strcmp (gst_structure_get_name (s), "audio/x-nellymoser") == 0) {
376 if (gst_structure_get_int (s, "rate", &rate)
377 && gst_structure_get_int (s, "channels", &channels)) {
378 if (channels == 1 && rate == 16000)
379 cpad->audio_codec = 4;
380 else if (channels == 1 && rate == 8000)
381 cpad->audio_codec = 5;
383 cpad->audio_codec = 6;
385 cpad->audio_codec = 6;
387 } else if (strcmp (gst_structure_get_name (s), "audio/x-raw-int") == 0) {
390 if (gst_structure_get_int (s, "endianness", &endianness)
391 && endianness == G_LITTLE_ENDIAN)
392 cpad->audio_codec = 3;
395 } else if (strcmp (gst_structure_get_name (s), "audio/x-alaw") == 0) {
396 cpad->audio_codec = 7;
397 } else if (strcmp (gst_structure_get_name (s), "audio/x-mulaw") == 0) {
398 cpad->audio_codec = 8;
399 } else if (strcmp (gst_structure_get_name (s), "audio/x-speex") == 0) {
400 cpad->audio_codec = 11;
406 gint rate, channels, width;
408 if (gst_structure_get_int (s, "rate", &rate)) {
409 if (cpad->audio_codec == 10)
411 else if (rate == 5512)
413 else if (rate == 11025)
415 else if (rate == 22050)
417 else if (rate == 44100)
419 else if (rate == 8000 && (cpad->audio_codec == 5
420 || cpad->audio_codec == 14))
422 else if (rate == 16000 && cpad->audio_codec == 4)
426 } else if (cpad->audio_codec == 10) {
432 if (gst_structure_get_int (s, "channels", &channels)) {
433 if (cpad->audio_codec == 4 || cpad->audio_codec == 5
434 || cpad->audio_codec == 6)
436 else if (cpad->audio_codec == 10)
438 else if (channels == 1)
440 else if (channels == 2)
444 } else if (cpad->audio_codec == 4 || cpad->audio_codec == 5
445 || cpad->audio_codec == 6) {
447 } else if (cpad->audio_codec == 10) {
453 if (gst_structure_get_int (s, "width", &width)) {
454 if (cpad->audio_codec != 3)
458 else if (width == 16)
462 } else if (cpad->audio_codec != 3) {
469 if (ret && gst_structure_has_field (s, "codec_data")) {
470 const GValue *val = gst_structure_get_value (s, "codec_data");
473 cpad->audio_codec_data = gst_buffer_ref (gst_value_get_buffer (val));
476 gst_object_unref (mux);
482 gst_flv_mux_reset_pad (GstFlvMux * mux, GstFlvPad * cpad, gboolean video)
486 if (cpad->audio_codec_data)
487 gst_buffer_unref (cpad->audio_codec_data);
488 cpad->audio_codec_data = NULL;
489 cpad->audio_codec = G_MAXUINT;
490 cpad->rate = G_MAXUINT;
491 cpad->width = G_MAXUINT;
492 cpad->channels = G_MAXUINT;
494 if (cpad->video_codec_data)
495 gst_buffer_unref (cpad->video_codec_data);
496 cpad->video_codec_data = NULL;
497 cpad->video_codec = G_MAXUINT;
498 cpad->last_timestamp = 0;
502 gst_flv_mux_request_new_pad (GstElement * element,
503 GstPadTemplate * templ, const gchar * pad_name)
505 GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
506 GstFlvMux *mux = GST_FLV_MUX (element);
509 const gchar *name = NULL;
510 GstPadSetCapsFunction setcapsfunc = NULL;
513 if (mux->state != GST_FLV_MUX_STATE_HEADER) {
514 GST_WARNING_OBJECT (mux, "Can't request pads after writing header");
518 if (templ == gst_element_class_get_pad_template (klass, "audio")) {
519 if (mux->have_audio) {
520 GST_WARNING_OBJECT (mux, "Already have an audio pad");
523 mux->have_audio = TRUE;
526 setcapsfunc = GST_DEBUG_FUNCPTR (gst_flv_mux_audio_pad_setcaps);
527 } else if (templ == gst_element_class_get_pad_template (klass, "video")) {
528 if (mux->have_video) {
529 GST_WARNING_OBJECT (mux, "Already have a video pad");
532 mux->have_video = TRUE;
535 setcapsfunc = GST_DEBUG_FUNCPTR (gst_flv_mux_video_pad_setcaps);
537 GST_WARNING_OBJECT (mux, "Invalid template");
541 pad = gst_pad_new_from_template (templ, name);
543 gst_collect_pads2_add_pad (mux->collect, pad, sizeof (GstFlvPad));
545 cpad->audio_codec_data = NULL;
546 cpad->video_codec_data = NULL;
547 gst_flv_mux_reset_pad (mux, cpad, video);
549 gst_pad_set_setcaps_function (pad, setcapsfunc);
550 gst_pad_set_active (pad, TRUE);
551 gst_element_add_pad (element, pad);
557 gst_flv_mux_release_pad (GstElement * element, GstPad * pad)
559 GstFlvMux *mux = GST_FLV_MUX (GST_PAD_PARENT (pad));
560 GstFlvPad *cpad = (GstFlvPad *) gst_pad_get_element_private (pad);
562 gst_flv_mux_reset_pad (mux, cpad, cpad->video);
563 gst_collect_pads2_remove_pad (mux->collect, pad);
564 gst_element_remove_pad (element, pad);
568 gst_flv_mux_push (GstFlvMux * mux, GstBuffer * buffer)
570 gst_buffer_set_caps (buffer, GST_PAD_CAPS (mux->srcpad));
571 /* pushing the buffer that rewrites the header will make it no longer be the
572 * total output size in bytes, but it doesn't matter at that point */
573 mux->byte_count += GST_BUFFER_SIZE (buffer);
575 return gst_pad_push (mux->srcpad, buffer);
579 gst_flv_mux_create_header (GstFlvMux * mux)
584 header = gst_buffer_new_and_alloc (9 + 4);
585 data = GST_BUFFER_DATA (header);
590 data[3] = 0x01; /* Version */
592 data[4] = (mux->have_audio << 2) | mux->have_video; /* flags */
593 GST_WRITE_UINT32_BE (data + 5, 9); /* data offset */
594 GST_WRITE_UINT32_BE (data + 9, 0); /* previous tag size */
600 gst_flv_mux_preallocate_index (GstFlvMux * mux)
604 gint preallocate_size;
606 /* preallocate index of size:
607 * - 'keyframes' ECMA array key: 2 + 9 = 11 bytes
608 * - nested ECMA array header, length and end marker: 8 bytes
609 * - 'times' and 'filepositions' keys: 22 bytes
610 * - two strict arrays headers and lengths: 10 bytes
611 * - each index entry: 18 bytes
613 preallocate_size = 11 + 8 + 22 + 10 + MAX_INDEX_ENTRIES * 18;
614 GST_DEBUG_OBJECT (mux, "preallocating %d bytes for the index",
617 tmp = gst_buffer_new_and_alloc (preallocate_size);
618 data = GST_BUFFER_DATA (tmp);
620 /* prefill the space with a gstfiller: <spaces> script tag variable */
621 GST_WRITE_UINT16_BE (data, 9); /* 9 characters */
622 memcpy (data + 2, "gstfiller", 9);
623 GST_WRITE_UINT8 (data + 11, AMF0_STRING_MARKER); /* a string value */
624 GST_WRITE_UINT16_BE (data + 12, preallocate_size - 14);
625 memset (data + 14, ' ', preallocate_size - 14); /* the rest is spaces */
630 gst_flv_mux_create_number_script_value (const gchar * name, gdouble value)
632 GstBuffer *tmp = gst_buffer_new_and_alloc (2 + strlen (name) + 1 + 8);
633 guint8 *data = GST_BUFFER_DATA (tmp);
634 gsize len = strlen (name);
636 GST_WRITE_UINT16_BE (data, len);
637 data += 2; /* name length */
638 memcpy (data, name, len);
640 *data++ = AMF0_NUMBER_MARKER; /* double type */
641 GST_WRITE_DOUBLE_BE (data, value);
647 gst_flv_mux_create_metadata (GstFlvMux * mux)
649 const GstTagList *tags;
650 GstBuffer *script_tag, *tmp;
652 gint i, n_tags, tags_written = 0;
654 tags = gst_tag_setter_get_tag_list (GST_TAG_SETTER (mux));
656 GST_DEBUG_OBJECT (mux, "tags = %" GST_PTR_FORMAT, tags);
658 script_tag = gst_buffer_new_and_alloc (11);
659 data = GST_BUFFER_DATA (script_tag);
663 /* Data size, unknown for now */
669 data[4] = data[5] = data[6] = data[7] = 0;
672 data[8] = data[9] = data[10] = 0;
674 tmp = gst_buffer_new_and_alloc (13);
675 data = GST_BUFFER_DATA (tmp);
676 data[0] = AMF0_STRING_MARKER; /* string */
678 data[2] = 10; /* length 10 */
679 memcpy (&data[3], "onMetaData", 10);
681 script_tag = gst_buffer_join (script_tag, tmp);
683 n_tags = (tags) ? gst_structure_n_fields ((GstStructure *) tags) : 0;
684 tmp = gst_buffer_new_and_alloc (5);
685 data = GST_BUFFER_DATA (tmp);
686 data[0] = 8; /* ECMA array */
687 GST_WRITE_UINT32_BE (data + 1, n_tags);
688 script_tag = gst_buffer_join (script_tag, tmp);
690 /* Some players expect the 'duration' to be always set. Fill it out later,
691 after querying the pads or after getting EOS */
692 if (!mux->streamable) {
693 tmp = gst_flv_mux_create_number_script_value ("duration", 86400);
694 script_tag = gst_buffer_join (script_tag, tmp);
697 /* Sometimes the information about the total file size is useful for the
698 player. It will be filled later, after getting EOS */
699 tmp = gst_flv_mux_create_number_script_value ("filesize", 0);
700 script_tag = gst_buffer_join (script_tag, tmp);
703 /* Preallocate space for the index to be written at EOS */
704 tmp = gst_flv_mux_preallocate_index (mux);
705 script_tag = gst_buffer_join (script_tag, tmp);
707 GST_DEBUG_OBJECT (mux, "not preallocating index, streamable mode");
710 for (i = 0; tags && i < n_tags; i++) {
711 const gchar *tag_name =
712 gst_structure_nth_field_name ((const GstStructure *) tags, i);
713 if (!strcmp (tag_name, GST_TAG_DURATION)) {
716 if (!gst_tag_list_get_uint64 (tags, GST_TAG_DURATION, &dur))
719 } else if (!strcmp (tag_name, GST_TAG_ARTIST) ||
720 !strcmp (tag_name, GST_TAG_TITLE)) {
722 const gchar *t = NULL;
724 if (!strcmp (tag_name, GST_TAG_ARTIST))
726 else if (!strcmp (tag_name, GST_TAG_TITLE))
729 if (!gst_tag_list_get_string (tags, tag_name, &s))
732 tmp = gst_buffer_new_and_alloc (2 + strlen (t) + 1 + 2 + strlen (s));
733 data = GST_BUFFER_DATA (tmp);
734 data[0] = 0; /* tag name length */
735 data[1] = strlen (t);
736 memcpy (&data[2], t, strlen (t));
737 data[2 + strlen (t)] = 2; /* string */
738 data[3 + strlen (t)] = (strlen (s) >> 8) & 0xff;
739 data[4 + strlen (t)] = (strlen (s)) & 0xff;
740 memcpy (&data[5 + strlen (t)], s, strlen (s));
741 script_tag = gst_buffer_join (script_tag, tmp);
748 if (mux->duration == GST_CLOCK_TIME_NONE) {
751 GstFormat fmt = GST_FORMAT_TIME;
754 for (l = mux->collect->data; l; l = l->next) {
755 GstCollectData2 *cdata = l->data;
757 fmt = GST_FORMAT_TIME;
759 if (gst_pad_query_peer_duration (cdata->pad, &fmt, (gint64 *) & dur) &&
760 fmt == GST_FORMAT_TIME && dur != GST_CLOCK_TIME_NONE) {
761 if (mux->duration == GST_CLOCK_TIME_NONE)
764 mux->duration = MAX (dur, mux->duration);
769 if (!mux->streamable && mux->duration != GST_CLOCK_TIME_NONE) {
771 d = gst_guint64_to_gdouble (mux->duration);
772 d /= (gdouble) GST_SECOND;
774 GST_DEBUG_OBJECT (mux, "determined the duration to be %f", d);
775 data = GST_BUFFER_DATA (script_tag);
776 GST_WRITE_DOUBLE_BE (data + 29 + 2 + 8 + 1, d);
779 if (mux->have_video) {
780 GstPad *video_pad = NULL;
782 GSList *l = mux->collect->data;
784 for (; l; l = l->next) {
786 if (cpad && cpad->video) {
787 video_pad = cpad->collect.pad;
792 if (video_pad && GST_PAD_CAPS (video_pad)) {
793 GstStructure *s = gst_caps_get_structure (GST_PAD_CAPS (video_pad), 0);
797 GST_DEBUG_OBJECT (mux, "putting videocodecid %d in the metadata",
800 tmp = gst_flv_mux_create_number_script_value ("videocodecid",
802 script_tag = gst_buffer_join (script_tag, tmp);
805 if (gst_structure_get_int (s, "width", &size)) {
806 GST_DEBUG_OBJECT (mux, "putting width %d in the metadata", size);
808 tmp = gst_flv_mux_create_number_script_value ("width", size);
809 script_tag = gst_buffer_join (script_tag, tmp);
813 if (gst_structure_get_int (s, "height", &size)) {
814 GST_DEBUG_OBJECT (mux, "putting height %d in the metadata", size);
816 tmp = gst_flv_mux_create_number_script_value ("height", size);
817 script_tag = gst_buffer_join (script_tag, tmp);
821 if (gst_structure_get_fraction (s, "pixel-aspect-ratio", &num, &den)) {
825 GST_DEBUG_OBJECT (mux, "putting AspectRatioX %f in the metadata", d);
827 tmp = gst_flv_mux_create_number_script_value ("AspectRatioX", d);
828 script_tag = gst_buffer_join (script_tag, tmp);
832 GST_DEBUG_OBJECT (mux, "putting AspectRatioY %f in the metadata", d);
834 tmp = gst_flv_mux_create_number_script_value ("AspectRatioY", d);
835 script_tag = gst_buffer_join (script_tag, tmp);
839 if (gst_structure_get_fraction (s, "framerate", &num, &den)) {
842 gst_util_fraction_to_double (num, den, &d);
843 GST_DEBUG_OBJECT (mux, "putting framerate %f in the metadata", d);
845 tmp = gst_flv_mux_create_number_script_value ("framerate", d);
846 script_tag = gst_buffer_join (script_tag, tmp);
852 if (mux->have_audio) {
853 GstPad *audio_pad = NULL;
855 GSList *l = mux->collect->data;
857 for (; l; l = l->next) {
859 if (cpad && !cpad->video) {
860 audio_pad = cpad->collect.pad;
866 GST_DEBUG_OBJECT (mux, "putting audiocodecid %d in the metadata",
869 tmp = gst_flv_mux_create_number_script_value ("audiocodecid",
871 script_tag = gst_buffer_join (script_tag, tmp);
877 const gchar *s = "GStreamer FLV muxer";
879 tmp = gst_buffer_new_and_alloc (2 + 15 + 1 + 2 + strlen (s));
880 data = GST_BUFFER_DATA (tmp);
881 data[0] = 0; /* 15 bytes name */
883 memcpy (&data[2], "metadatacreator", 15);
884 data[17] = 2; /* string */
885 data[18] = (strlen (s) >> 8) & 0xff;
886 data[19] = (strlen (s)) & 0xff;
887 memcpy (&data[20], s, strlen (s));
888 script_tag = gst_buffer_join (script_tag, tmp);
894 GTimeVal tv = { 0, };
898 static const gchar *weekdays[] = {
899 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
901 static const gchar *months[] = {
902 "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
903 "Aug", "Sep", "Oct", "Nov", "Dec"
906 g_get_current_time (&tv);
910 s = g_strdup_printf ("%s %s %d %d:%d:%d %d", weekdays[tm->tm_wday],
911 months[tm->tm_mon], tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec,
914 tmp = gst_buffer_new_and_alloc (2 + 12 + 1 + 2 + strlen (s));
915 data = GST_BUFFER_DATA (tmp);
916 data[0] = 0; /* 12 bytes name */
918 memcpy (&data[2], "creationdate", 12);
919 data[14] = 2; /* string */
920 data[15] = (strlen (s) >> 8) & 0xff;
921 data[16] = (strlen (s)) & 0xff;
922 memcpy (&data[17], s, strlen (s));
923 script_tag = gst_buffer_join (script_tag, tmp);
929 tmp = gst_buffer_new_and_alloc (2 + 0 + 1);
930 data = GST_BUFFER_DATA (tmp);
931 data[0] = 0; /* 0 byte size */
933 data[2] = 9; /* end marker */
934 script_tag = gst_buffer_join (script_tag, tmp);
937 tmp = gst_buffer_new_and_alloc (4);
938 data = GST_BUFFER_DATA (tmp);
939 GST_WRITE_UINT32_BE (data, GST_BUFFER_SIZE (script_tag));
940 script_tag = gst_buffer_join (script_tag, tmp);
942 data = GST_BUFFER_DATA (script_tag);
943 data[1] = ((GST_BUFFER_SIZE (script_tag) - 11 - 4) >> 16) & 0xff;
944 data[2] = ((GST_BUFFER_SIZE (script_tag) - 11 - 4) >> 8) & 0xff;
945 data[3] = ((GST_BUFFER_SIZE (script_tag) - 11 - 4) >> 0) & 0xff;
947 GST_WRITE_UINT32_BE (data + 11 + 13 + 1, tags_written);
953 gst_flv_mux_buffer_to_tag_internal (GstFlvMux * mux, GstBuffer * buffer,
954 GstFlvPad * cpad, gboolean is_codec_data)
960 (GST_BUFFER_TIMESTAMP_IS_VALID (buffer)) ? GST_BUFFER_TIMESTAMP (buffer) /
961 GST_MSECOND : cpad->last_timestamp / GST_MSECOND;
966 if (cpad->video_codec == 7)
967 size += 4 + GST_BUFFER_SIZE (buffer);
969 size += GST_BUFFER_SIZE (buffer);
972 if (cpad->audio_codec == 10)
973 size += 1 + GST_BUFFER_SIZE (buffer);
975 size += GST_BUFFER_SIZE (buffer);
979 tag = gst_buffer_new_and_alloc (size);
980 GST_BUFFER_TIMESTAMP (tag) = timestamp * GST_MSECOND;
981 data = GST_BUFFER_DATA (tag);
982 memset (data, 0, size);
984 data[0] = (cpad->video) ? 9 : 8;
986 data[1] = ((size - 11 - 4) >> 16) & 0xff;
987 data[2] = ((size - 11 - 4) >> 8) & 0xff;
988 data[3] = ((size - 11 - 4) >> 0) & 0xff;
990 /* wrap the timestamp every G_MAXINT32 miliseconds */
991 timestamp &= 0x7fffffff;
992 data[4] = (timestamp >> 16) & 0xff;
993 data[5] = (timestamp >> 8) & 0xff;
994 data[6] = (timestamp >> 0) & 0xff;
995 data[7] = (timestamp >> 24) & 0xff;
997 data[8] = data[9] = data[10] = 0;
1000 if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT))
1005 data[11] |= cpad->video_codec & 0x0f;
1007 if (cpad->video_codec == 7) {
1008 data[12] = is_codec_data ? 0 : 1;
1010 /* FIXME: what to do about composition time */
1011 data[13] = data[14] = data[15] = 0;
1013 memcpy (data + 11 + 1 + 4, GST_BUFFER_DATA (buffer),
1014 GST_BUFFER_SIZE (buffer));
1016 memcpy (data + 11 + 1, GST_BUFFER_DATA (buffer),
1017 GST_BUFFER_SIZE (buffer));
1020 data[11] |= (cpad->audio_codec << 4) & 0xf0;
1021 data[11] |= (cpad->rate << 2) & 0x0c;
1022 data[11] |= (cpad->width << 1) & 0x02;
1023 data[11] |= (cpad->channels << 0) & 0x01;
1025 if (cpad->audio_codec == 10) {
1026 data[12] = is_codec_data ? 0 : 1;
1028 memcpy (data + 11 + 1 + 1, GST_BUFFER_DATA (buffer),
1029 GST_BUFFER_SIZE (buffer));
1031 memcpy (data + 11 + 1, GST_BUFFER_DATA (buffer),
1032 GST_BUFFER_SIZE (buffer));
1036 GST_WRITE_UINT32_BE (data + size - 4, size - 4);
1038 gst_buffer_copy_metadata (tag, buffer, GST_BUFFER_COPY_TIMESTAMPS);
1039 /* mark the buffer if it's an audio buffer and there's also video being muxed
1040 * or it's a video interframe */
1041 if ((mux->have_video && !cpad->video) ||
1042 GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT))
1043 GST_BUFFER_FLAG_SET (tag, GST_BUFFER_FLAG_DELTA_UNIT);
1045 GST_BUFFER_OFFSET (tag) = GST_BUFFER_OFFSET_END (tag) =
1046 GST_BUFFER_OFFSET_NONE;
1051 static inline GstBuffer *
1052 gst_flv_mux_buffer_to_tag (GstFlvMux * mux, GstBuffer * buffer,
1055 return gst_flv_mux_buffer_to_tag_internal (mux, buffer, cpad, FALSE);
1058 static inline GstBuffer *
1059 gst_flv_mux_codec_data_buffer_to_tag (GstFlvMux * mux, GstBuffer * buffer,
1062 return gst_flv_mux_buffer_to_tag_internal (mux, buffer, cpad, TRUE);
1066 gst_flv_mux_put_buffer_in_streamheader (GValue * streamheader,
1069 GValue value = { 0 };
1072 g_value_init (&value, GST_TYPE_BUFFER);
1073 buf = gst_buffer_copy (buffer);
1074 gst_value_set_buffer (&value, buf);
1075 gst_buffer_unref (buf);
1076 gst_value_array_append_value (streamheader, &value);
1077 g_value_unset (&value);
1080 static GstFlowReturn
1081 gst_flv_mux_write_header (GstFlvMux * mux)
1083 GstBuffer *header, *metadata;
1084 GstBuffer *video_codec_data, *audio_codec_data;
1086 GstStructure *structure;
1087 GValue streamheader = { 0 };
1091 header = gst_flv_mux_create_header (mux);
1092 metadata = gst_flv_mux_create_metadata (mux);
1093 video_codec_data = NULL;
1094 audio_codec_data = NULL;
1096 for (l = mux->collect->data; l != NULL; l = l->next) {
1097 GstFlvPad *cpad = l->data;
1099 /* Get H.264 and AAC codec data, if present */
1100 if (cpad && cpad->video && cpad->video_codec == 7) {
1101 if (cpad->video_codec_data == NULL)
1102 GST_WARNING_OBJECT (mux, "Codec data for video stream not found, "
1103 "output might not be playable");
1106 gst_flv_mux_codec_data_buffer_to_tag (mux, cpad->video_codec_data,
1108 } else if (cpad && !cpad->video && cpad->audio_codec == 10) {
1109 if (cpad->audio_codec_data == NULL)
1110 GST_WARNING_OBJECT (mux, "Codec data for audio stream not found, "
1111 "output might not be playable");
1114 gst_flv_mux_codec_data_buffer_to_tag (mux, cpad->audio_codec_data,
1119 /* mark buffers that will go in the streamheader */
1120 GST_BUFFER_FLAG_SET (header, GST_BUFFER_FLAG_IN_CAPS);
1121 GST_BUFFER_FLAG_SET (metadata, GST_BUFFER_FLAG_IN_CAPS);
1122 if (video_codec_data != NULL) {
1123 GST_BUFFER_FLAG_SET (video_codec_data, GST_BUFFER_FLAG_IN_CAPS);
1124 /* mark as a delta unit, so downstream will not try to synchronize on that
1125 * buffer - to actually start playback you need a real video keyframe */
1126 GST_BUFFER_FLAG_SET (video_codec_data, GST_BUFFER_FLAG_DELTA_UNIT);
1128 if (audio_codec_data != NULL) {
1129 GST_BUFFER_FLAG_SET (audio_codec_data, GST_BUFFER_FLAG_IN_CAPS);
1132 /* put buffers in streamheader */
1133 g_value_init (&streamheader, GST_TYPE_ARRAY);
1134 gst_flv_mux_put_buffer_in_streamheader (&streamheader, header);
1135 gst_flv_mux_put_buffer_in_streamheader (&streamheader, metadata);
1136 if (video_codec_data != NULL)
1137 gst_flv_mux_put_buffer_in_streamheader (&streamheader, video_codec_data);
1138 if (audio_codec_data != NULL)
1139 gst_flv_mux_put_buffer_in_streamheader (&streamheader, audio_codec_data);
1141 /* create the caps and put the streamheader in them */
1142 caps = gst_caps_new_simple ("video/x-flv", NULL);
1143 caps = gst_caps_make_writable (caps);
1144 structure = gst_caps_get_structure (caps, 0);
1145 gst_structure_set_value (structure, "streamheader", &streamheader);
1146 g_value_unset (&streamheader);
1148 if (GST_PAD_CAPS (mux->srcpad) == NULL)
1149 gst_pad_set_caps (mux->srcpad, caps);
1151 gst_caps_unref (caps);
1153 /* push the header buffer, the metadata and the codec info, if any */
1154 ret = gst_flv_mux_push (mux, header);
1155 if (ret != GST_FLOW_OK)
1157 ret = gst_flv_mux_push (mux, metadata);
1158 if (ret != GST_FLOW_OK)
1160 if (video_codec_data != NULL) {
1161 ret = gst_flv_mux_push (mux, video_codec_data);
1162 if (ret != GST_FLOW_OK)
1165 if (audio_codec_data != NULL) {
1166 ret = gst_flv_mux_push (mux, audio_codec_data);
1167 if (ret != GST_FLOW_OK)
1174 gst_flv_mux_update_index (GstFlvMux * mux, GstBuffer * buffer, GstFlvPad * cpad)
1177 * Add the tag byte offset and to the index if it's a valid seek point, which
1178 * means it's either a video keyframe or if there is no video pad (in that
1179 * case every FLV tag is a valid seek point)
1181 if (mux->have_video &&
1183 GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT)))
1186 if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer)) {
1187 GstFlvMuxIndexEntry *entry = g_slice_new (GstFlvMuxIndexEntry);
1188 entry->position = mux->byte_count;
1190 gst_guint64_to_gdouble (GST_BUFFER_TIMESTAMP (buffer)) / GST_SECOND;
1191 mux->index = g_list_prepend (mux->index, entry);
1195 static GstFlowReturn
1196 gst_flv_mux_write_buffer (GstFlvMux * mux, GstFlvPad * cpad, GstBuffer * buffer)
1201 /* clipping function arranged for running_time */
1203 if (!mux->streamable)
1204 gst_flv_mux_update_index (mux, buffer, cpad);
1206 tag = gst_flv_mux_buffer_to_tag (mux, buffer, cpad);
1208 gst_buffer_unref (buffer);
1210 ret = gst_flv_mux_push (mux, tag);
1212 if (ret == GST_FLOW_OK && GST_BUFFER_TIMESTAMP_IS_VALID (tag))
1213 cpad->last_timestamp = GST_BUFFER_TIMESTAMP (tag);
1219 gst_flv_mux_determine_duration (GstFlvMux * mux)
1222 GstClockTime duration = GST_CLOCK_TIME_NONE;
1224 GST_DEBUG_OBJECT (mux, "trying to determine the duration "
1225 "from pad timestamps");
1227 for (l = mux->collect->data; l != NULL; l = l->next) {
1228 GstFlvPad *cpad = l->data;
1230 if (cpad && (cpad->last_timestamp != GST_CLOCK_TIME_NONE)) {
1231 if (duration == GST_CLOCK_TIME_NONE)
1232 duration = cpad->last_timestamp;
1234 duration = MAX (duration, cpad->last_timestamp);
1238 if (duration == GST_CLOCK_TIME_NONE) {
1239 GST_DEBUG_OBJECT (mux, "not able to determine duration "
1240 "from pad timestamps, assuming 0");
1247 static GstFlowReturn
1248 gst_flv_mux_rewrite_header (GstFlvMux * mux)
1250 GstBuffer *rewrite, *index, *tmp;
1255 guint32 index_len, allocate_size;
1256 guint32 i, index_skip;
1258 if (mux->streamable)
1261 /* seek back to the preallocated index space */
1262 event = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_BYTES,
1263 13 + 29, GST_CLOCK_TIME_NONE, 13 + 29);
1264 if (!gst_pad_push_event (mux->srcpad, event)) {
1265 GST_WARNING_OBJECT (mux, "Seek to rewrite header failed");
1269 /* if we were not able to determine the duration before, set it now */
1270 if (mux->duration == GST_CLOCK_TIME_NONE)
1271 mux->duration = gst_flv_mux_determine_duration (mux);
1273 /* rewrite the duration tag */
1274 d = gst_guint64_to_gdouble (mux->duration);
1275 d /= (gdouble) GST_SECOND;
1277 GST_DEBUG_OBJECT (mux, "determined the final duration to be %f", d);
1279 rewrite = gst_flv_mux_create_number_script_value ("duration", d);
1281 /* rewrite the filesize tag */
1282 d = gst_guint64_to_gdouble (mux->byte_count);
1284 GST_DEBUG_OBJECT (mux, "putting total filesize %f in the metadata", d);
1286 tmp = gst_flv_mux_create_number_script_value ("filesize", d);
1287 rewrite = gst_buffer_join (rewrite, tmp);
1290 /* no index, so push buffer and return */
1291 return gst_flv_mux_push (mux, rewrite);
1294 /* rewrite the index */
1295 mux->index = g_list_reverse (mux->index);
1296 index_len = g_list_length (mux->index);
1298 /* We write at most MAX_INDEX_ENTRIES elements */
1299 if (index_len > MAX_INDEX_ENTRIES) {
1300 index_skip = 1 + index_len / MAX_INDEX_ENTRIES;
1301 index_len = (index_len + index_skip - 1) / index_skip;
1306 GST_DEBUG_OBJECT (mux, "Index length is %d", index_len);
1307 /* see size calculation in gst_flv_mux_preallocate_index */
1308 allocate_size = 11 + 8 + 22 + 10 + index_len * 18;
1309 GST_DEBUG_OBJECT (mux, "Allocating %d bytes for index", allocate_size);
1310 index = gst_buffer_new_and_alloc (allocate_size);
1311 data = GST_BUFFER_DATA (index);
1313 GST_WRITE_UINT16_BE (data, 9); /* the 'keyframes' key */
1314 memcpy (data + 2, "keyframes", 9);
1315 GST_WRITE_UINT8 (data + 11, 8); /* nested ECMA array */
1316 GST_WRITE_UINT32_BE (data + 12, 2); /* two elements */
1317 GST_WRITE_UINT16_BE (data + 16, 5); /* first string key: 'times' */
1318 memcpy (data + 18, "times", 5);
1319 GST_WRITE_UINT8 (data + 23, 10); /* strict array */
1320 GST_WRITE_UINT32_BE (data + 24, index_len);
1323 /* the keyframes' times */
1324 for (i = 0, l = mux->index; l; l = l->next, i++) {
1325 GstFlvMuxIndexEntry *entry = l->data;
1327 if (i % index_skip != 0)
1329 GST_WRITE_UINT8 (data, 0); /* numeric (aka double) */
1330 GST_WRITE_DOUBLE_BE (data + 1, entry->time);
1334 GST_WRITE_UINT16_BE (data, 13); /* second string key: 'filepositions' */
1335 memcpy (data + 2, "filepositions", 13);
1336 GST_WRITE_UINT8 (data + 15, 10); /* strict array */
1337 GST_WRITE_UINT32_BE (data + 16, index_len);
1340 /* the keyframes' file positions */
1341 for (i = 0, l = mux->index; l; l = l->next, i++) {
1342 GstFlvMuxIndexEntry *entry = l->data;
1344 if (i % index_skip != 0)
1346 GST_WRITE_UINT8 (data, 0);
1347 GST_WRITE_DOUBLE_BE (data + 1, entry->position);
1351 GST_WRITE_UINT24_BE (data, 9); /* finish the ECMA array */
1353 /* If there is space left in the prefilled area, reinsert the filler.
1354 There is at least 18 bytes free, so it will always fit. */
1355 if (index_len < MAX_INDEX_ENTRIES) {
1358 guint32 remaining_filler_size;
1360 tmp = gst_buffer_new_and_alloc (14);
1361 data = GST_BUFFER_DATA (tmp);
1362 GST_WRITE_UINT16_BE (data, 9);
1363 memcpy (data + 2, "gstfiller", 9);
1364 GST_WRITE_UINT8 (data + 11, 2); /* string */
1366 /* There is 18 bytes per remaining index entry minus what is used for
1367 * the'gstfiller' key. The rest is already filled with spaces, so just need
1368 * to update length. */
1369 remaining_filler_size = (MAX_INDEX_ENTRIES - index_len) * 18 - 14;
1370 GST_DEBUG_OBJECT (mux, "Remaining filler size is %d bytes",
1371 remaining_filler_size);
1372 GST_WRITE_UINT16_BE (data + 12, remaining_filler_size);
1373 index = gst_buffer_join (index, tmp);
1376 rewrite = gst_buffer_join (rewrite, index);
1378 gst_buffer_set_caps (rewrite, GST_PAD_CAPS (mux->srcpad));
1379 return gst_flv_mux_push (mux, rewrite);
1382 static GstFlowReturn
1383 gst_flv_mux_handle_buffer (GstCollectPads2 * pads, GstCollectData2 * cdata,
1384 GstBuffer * buffer, gpointer user_data)
1386 GstFlvMux *mux = GST_FLV_MUX (user_data);
1388 GstClockTime best_time;
1391 if (mux->state == GST_FLV_MUX_STATE_HEADER) {
1392 if (mux->collect->data == NULL) {
1393 GST_ELEMENT_ERROR (mux, STREAM, MUX, (NULL),
1394 ("No input streams configured"));
1395 return GST_FLOW_ERROR;
1398 if (gst_pad_push_event (mux->srcpad,
1399 gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_BYTES, 0, -1, 0)))
1400 ret = gst_flv_mux_write_header (mux);
1402 ret = GST_FLOW_ERROR;
1404 if (ret != GST_FLOW_OK)
1406 mux->state = GST_FLV_MUX_STATE_DATA;
1409 if (mux->new_tags) {
1410 GstBuffer *buf = gst_flv_mux_create_metadata (mux);
1411 gst_flv_mux_push (mux, buf);
1412 mux->new_tags = FALSE;
1415 best = (GstFlvPad *) cdata;
1418 best_time = GST_BUFFER_TIMESTAMP (buffer);
1420 best_time = GST_CLOCK_TIME_NONE;
1423 /* The FLV timestamp is an int32 field. For non-live streams error out if a
1424 bigger timestamp is seen, for live the timestamp will get wrapped in
1425 gst_flv_mux_buffer_to_tag */
1426 if (!mux->streamable && GST_CLOCK_TIME_IS_VALID (best_time)
1427 && best_time / GST_MSECOND > G_MAXINT32) {
1428 GST_WARNING_OBJECT (mux, "Timestamp larger than FLV supports - EOS");
1429 gst_buffer_unref (buffer);
1435 return gst_flv_mux_write_buffer (mux, best, buffer);
1437 gst_flv_mux_rewrite_header (mux);
1438 gst_pad_push_event (mux->srcpad, gst_event_new_eos ());
1439 return GST_FLOW_UNEXPECTED;
1444 gst_flv_mux_get_property (GObject * object,
1445 guint prop_id, GValue * value, GParamSpec * pspec)
1447 GstFlvMux *mux = GST_FLV_MUX (object);
1450 case PROP_STREAMABLE:
1451 g_value_set_boolean (value, mux->streamable);
1454 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1460 gst_flv_mux_set_property (GObject * object,
1461 guint prop_id, const GValue * value, GParamSpec * pspec)
1463 GstFlvMux *mux = GST_FLV_MUX (object);
1466 case PROP_STREAMABLE:
1467 mux->streamable = g_value_get_boolean (value);
1468 if (mux->streamable)
1469 gst_tag_setter_set_tag_merge_mode (GST_TAG_SETTER (mux),
1470 GST_TAG_MERGE_REPLACE);
1472 gst_tag_setter_set_tag_merge_mode (GST_TAG_SETTER (mux),
1473 GST_TAG_MERGE_KEEP);
1476 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1481 static GstStateChangeReturn
1482 gst_flv_mux_change_state (GstElement * element, GstStateChange transition)
1484 GstStateChangeReturn ret;
1485 GstFlvMux *mux = GST_FLV_MUX (element);
1487 switch (transition) {
1488 case GST_STATE_CHANGE_NULL_TO_READY:
1490 case GST_STATE_CHANGE_READY_TO_PAUSED:
1491 gst_collect_pads2_start (mux->collect);
1493 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1495 case GST_STATE_CHANGE_PAUSED_TO_READY:
1496 gst_collect_pads2_stop (mux->collect);
1502 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1504 switch (transition) {
1505 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1507 case GST_STATE_CHANGE_PAUSED_TO_READY:
1508 gst_flv_mux_reset (GST_ELEMENT (mux));
1510 case GST_STATE_CHANGE_READY_TO_NULL: