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 gst_flv_mux_parent_class parent_class
87 G_DEFINE_TYPE_WITH_CODE (GstFlvMux, gst_flv_mux, GST_TYPE_ELEMENT,
88 G_IMPLEMENT_INTERFACE (GST_TYPE_TAG_SETTER, NULL));
90 static void gst_flv_mux_finalize (GObject * object);
92 gst_flv_mux_handle_buffer (GstCollectPads2 * pads, GstCollectData2 * cdata,
93 GstBuffer * buf, gpointer user_data);
95 gst_flv_mux_handle_sink_event (GstCollectPads2 * pads, GstCollectData2 * data,
96 GstEvent * event, gpointer user_data);
98 static gboolean gst_flv_mux_handle_src_event (GstPad * pad, GstObject * parent,
100 static GstPad *gst_flv_mux_request_new_pad (GstElement * element,
101 GstPadTemplate * templ, const gchar * req_name, const GstCaps * caps);
102 static void gst_flv_mux_release_pad (GstElement * element, GstPad * pad);
104 static gboolean gst_flv_mux_video_pad_setcaps (GstPad * pad, GstCaps * caps);
105 static gboolean gst_flv_mux_audio_pad_setcaps (GstPad * pad, GstCaps * caps);
107 static void gst_flv_mux_get_property (GObject * object,
108 guint prop_id, GValue * value, GParamSpec * pspec);
109 static void gst_flv_mux_set_property (GObject * object,
110 guint prop_id, const GValue * value, GParamSpec * pspec);
112 static GstStateChangeReturn
113 gst_flv_mux_change_state (GstElement * element, GstStateChange transition);
115 static void gst_flv_mux_reset (GstElement * element);
116 static void gst_flv_mux_reset_pad (GstFlvMux * mux, GstFlvPad * pad,
123 } GstFlvMuxIndexEntry;
126 gst_flv_mux_index_entry_free (GstFlvMuxIndexEntry * entry)
128 g_slice_free (GstFlvMuxIndexEntry, entry);
132 _gst_buffer_new_wrapped (gpointer mem, gsize size, GFreeFunc free_func)
136 buf = gst_buffer_new ();
137 gst_buffer_take_memory (buf, -1,
138 gst_memory_new_wrapped (free_func ? 0 : GST_MEMORY_FLAG_READONLY,
139 mem, free_func, size, 0, size));
145 _gst_buffer_new_and_alloc (gsize size, GstBuffer ** buffer, guint8 ** data)
147 g_return_if_fail (data != NULL);
148 g_return_if_fail (buffer != NULL);
150 *data = g_malloc (size);
151 *buffer = _gst_buffer_new_wrapped (*data, size, g_free);
155 gst_flv_mux_class_init (GstFlvMuxClass * klass)
157 GObjectClass *gobject_class;
158 GstElementClass *gstelement_class;
160 GST_DEBUG_CATEGORY_INIT (flvmux_debug, "flvmux", 0, "FLV muxer");
162 gobject_class = (GObjectClass *) klass;
163 gstelement_class = (GstElementClass *) klass;
165 gobject_class->get_property = gst_flv_mux_get_property;
166 gobject_class->set_property = gst_flv_mux_set_property;
167 gobject_class->finalize = gst_flv_mux_finalize;
169 /* FIXME: ideally the right mode of operation should be detected
170 * automatically using queries when parameter not specified. */
172 * GstFlvMux:streamable
174 * If True, the output will be streaming friendly. (ie without indexes and
179 g_object_class_install_property (gobject_class, PROP_STREAMABLE,
180 g_param_spec_boolean ("streamable", "streamable",
181 "If set to true, the output should be as if it is to be streamed "
182 "and hence no indexes written or duration written.",
183 DEFAULT_STREAMABLE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
185 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_flv_mux_change_state);
186 gstelement_class->request_new_pad =
187 GST_DEBUG_FUNCPTR (gst_flv_mux_request_new_pad);
188 gstelement_class->release_pad = GST_DEBUG_FUNCPTR (gst_flv_mux_release_pad);
190 gst_element_class_add_pad_template (gstelement_class,
191 gst_static_pad_template_get (&videosink_templ));
192 gst_element_class_add_pad_template (gstelement_class,
193 gst_static_pad_template_get (&audiosink_templ));
194 gst_element_class_add_pad_template (gstelement_class,
195 gst_static_pad_template_get (&src_templ));
196 gst_element_class_set_details_simple (gstelement_class, "FLV muxer",
198 "Muxes video/audio streams into a FLV stream",
199 "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
201 GST_DEBUG_CATEGORY_INIT (flvmux_debug, "flvmux", 0, "FLV muxer");
205 gst_flv_mux_init (GstFlvMux * mux)
207 mux->srcpad = gst_pad_new_from_static_template (&src_templ, "src");
208 gst_pad_set_event_function (mux->srcpad, gst_flv_mux_handle_src_event);
209 gst_element_add_pad (GST_ELEMENT (mux), mux->srcpad);
212 mux->streamable = DEFAULT_STREAMABLE;
214 mux->new_tags = FALSE;
216 mux->collect = gst_collect_pads2_new ();
217 gst_collect_pads2_set_buffer_function (mux->collect,
218 GST_DEBUG_FUNCPTR (gst_flv_mux_handle_buffer), mux);
219 gst_collect_pads2_set_event_function (mux->collect,
220 GST_DEBUG_FUNCPTR (gst_flv_mux_handle_sink_event), mux);
221 gst_collect_pads2_set_clip_function (mux->collect,
222 GST_DEBUG_FUNCPTR (gst_collect_pads2_clip_running_time), mux);
224 gst_flv_mux_reset (GST_ELEMENT (mux));
228 gst_flv_mux_finalize (GObject * object)
230 GstFlvMux *mux = GST_FLV_MUX (object);
232 gst_object_unref (mux->collect);
234 G_OBJECT_CLASS (parent_class)->finalize (object);
238 gst_flv_mux_reset (GstElement * element)
240 GstFlvMux *mux = GST_FLV_MUX (element);
243 for (sl = mux->collect->data; sl != NULL; sl = g_slist_next (sl)) {
244 GstFlvPad *cpad = (GstFlvPad *) sl->data;
246 gst_flv_mux_reset_pad (mux, cpad, cpad->video);
249 g_list_foreach (mux->index, (GFunc) gst_flv_mux_index_entry_free, NULL);
250 g_list_free (mux->index);
254 mux->have_audio = mux->have_video = FALSE;
255 mux->duration = GST_CLOCK_TIME_NONE;
256 mux->new_tags = FALSE;
258 mux->state = GST_FLV_MUX_STATE_HEADER;
261 gst_tag_setter_reset_tags (GST_TAG_SETTER (mux));
265 gst_flv_mux_handle_src_event (GstPad * pad, GstObject * parent,
270 type = event ? GST_EVENT_TYPE (event) : GST_EVENT_UNKNOWN;
274 /* disable seeking for now */
280 return gst_pad_event_default (pad, parent, event);
284 gst_flv_mux_handle_sink_event (GstCollectPads2 * pads, GstCollectData2 * data,
285 GstEvent * event, gpointer user_data)
287 GstFlvMux *mux = GST_FLV_MUX (user_data);
288 gboolean ret = FALSE;
290 switch (GST_EVENT_TYPE (event)) {
296 gst_event_parse_caps (event, &caps);
298 /* find stream data */
299 flvpad = (GstFlvPad *) data;
303 ret = gst_flv_mux_video_pad_setcaps (data->pad, caps);
305 ret = gst_flv_mux_audio_pad_setcaps (data->pad, caps);
309 gst_event_unref (event);
314 GstTagSetter *setter = GST_TAG_SETTER (mux);
315 const GstTagMergeMode mode = gst_tag_setter_get_tag_merge_mode (setter);
317 gst_event_parse_tag (event, &list);
318 gst_tag_setter_merge_tags (setter, list, mode);
319 mux->new_tags = TRUE;
326 /* now GstCollectPads2 can take care of the rest, e.g. EOS */
331 gst_flv_mux_video_pad_setcaps (GstPad * pad, GstCaps * caps)
333 GstFlvMux *mux = GST_FLV_MUX (gst_pad_get_parent (pad));
334 GstFlvPad *cpad = (GstFlvPad *) gst_pad_get_element_private (pad);
338 s = gst_caps_get_structure (caps, 0);
340 if (strcmp (gst_structure_get_name (s), "video/x-flash-video") == 0) {
341 cpad->video_codec = 2;
342 } else if (strcmp (gst_structure_get_name (s), "video/x-flash-screen") == 0) {
343 cpad->video_codec = 3;
344 } else if (strcmp (gst_structure_get_name (s), "video/x-vp6-flash") == 0) {
345 cpad->video_codec = 4;
346 } else if (strcmp (gst_structure_get_name (s), "video/x-vp6-alpha") == 0) {
347 cpad->video_codec = 5;
348 } else if (strcmp (gst_structure_get_name (s), "video/x-h264") == 0) {
349 cpad->video_codec = 7;
354 if (ret && gst_structure_has_field (s, "codec_data")) {
355 const GValue *val = gst_structure_get_value (s, "codec_data");
358 cpad->video_codec_data = gst_buffer_ref (gst_value_get_buffer (val));
361 gst_object_unref (mux);
367 gst_flv_mux_audio_pad_setcaps (GstPad * pad, GstCaps * caps)
369 GstFlvMux *mux = GST_FLV_MUX (gst_pad_get_parent (pad));
370 GstFlvPad *cpad = (GstFlvPad *) gst_pad_get_element_private (pad);
374 s = gst_caps_get_structure (caps, 0);
376 if (strcmp (gst_structure_get_name (s), "audio/x-adpcm") == 0) {
377 const gchar *layout = gst_structure_get_string (s, "layout");
378 if (layout && strcmp (layout, "swf") == 0) {
379 cpad->audio_codec = 1;
383 } else if (strcmp (gst_structure_get_name (s), "audio/mpeg") == 0) {
386 if (gst_structure_get_int (s, "mpegversion", &mpegversion)) {
387 if (mpegversion == 1) {
390 if (gst_structure_get_int (s, "layer", &layer) && layer == 3) {
393 if (gst_structure_get_int (s, "rate", &rate) && rate == 8000)
394 cpad->audio_codec = 14;
396 cpad->audio_codec = 2;
400 } else if (mpegversion == 4 || mpegversion == 2) {
401 cpad->audio_codec = 10;
408 } else if (strcmp (gst_structure_get_name (s), "audio/x-nellymoser") == 0) {
411 if (gst_structure_get_int (s, "rate", &rate)
412 && gst_structure_get_int (s, "channels", &channels)) {
413 if (channels == 1 && rate == 16000)
414 cpad->audio_codec = 4;
415 else if (channels == 1 && rate == 8000)
416 cpad->audio_codec = 5;
418 cpad->audio_codec = 6;
420 cpad->audio_codec = 6;
422 } else if (strcmp (gst_structure_get_name (s), "audio/x-raw-int") == 0) {
425 if (gst_structure_get_int (s, "endianness", &endianness)
426 && endianness == G_LITTLE_ENDIAN)
427 cpad->audio_codec = 3;
430 } else if (strcmp (gst_structure_get_name (s), "audio/x-alaw") == 0) {
431 cpad->audio_codec = 7;
432 } else if (strcmp (gst_structure_get_name (s), "audio/x-mulaw") == 0) {
433 cpad->audio_codec = 8;
434 } else if (strcmp (gst_structure_get_name (s), "audio/x-speex") == 0) {
435 cpad->audio_codec = 11;
441 gint rate, channels, width;
443 if (gst_structure_get_int (s, "rate", &rate)) {
444 if (cpad->audio_codec == 10)
446 else if (rate == 5512)
448 else if (rate == 11025)
450 else if (rate == 22050)
452 else if (rate == 44100)
454 else if (rate == 8000 && (cpad->audio_codec == 5
455 || cpad->audio_codec == 14))
457 else if (rate == 16000 && cpad->audio_codec == 4)
461 } else if (cpad->audio_codec == 10) {
467 if (gst_structure_get_int (s, "channels", &channels)) {
468 if (cpad->audio_codec == 4 || cpad->audio_codec == 5
469 || cpad->audio_codec == 6)
471 else if (cpad->audio_codec == 10)
473 else if (channels == 1)
475 else if (channels == 2)
479 } else if (cpad->audio_codec == 4 || cpad->audio_codec == 5
480 || cpad->audio_codec == 6) {
482 } else if (cpad->audio_codec == 10) {
488 if (gst_structure_get_int (s, "width", &width)) {
489 if (cpad->audio_codec != 3)
493 else if (width == 16)
497 } else if (cpad->audio_codec != 3) {
504 if (ret && gst_structure_has_field (s, "codec_data")) {
505 const GValue *val = gst_structure_get_value (s, "codec_data");
508 cpad->audio_codec_data = gst_buffer_ref (gst_value_get_buffer (val));
511 gst_object_unref (mux);
517 gst_flv_mux_reset_pad (GstFlvMux * mux, GstFlvPad * cpad, gboolean video)
521 if (cpad->audio_codec_data)
522 gst_buffer_unref (cpad->audio_codec_data);
523 cpad->audio_codec_data = NULL;
524 cpad->audio_codec = G_MAXUINT;
525 cpad->rate = G_MAXUINT;
526 cpad->width = G_MAXUINT;
527 cpad->channels = G_MAXUINT;
529 if (cpad->video_codec_data)
530 gst_buffer_unref (cpad->video_codec_data);
531 cpad->video_codec_data = NULL;
532 cpad->video_codec = G_MAXUINT;
533 cpad->last_timestamp = 0;
537 gst_flv_mux_request_new_pad (GstElement * element,
538 GstPadTemplate * templ, const gchar * req_name, const GstCaps * caps)
540 GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
541 GstFlvMux *mux = GST_FLV_MUX (element);
544 const gchar *name = NULL;
547 if (mux->state != GST_FLV_MUX_STATE_HEADER) {
548 GST_WARNING_OBJECT (mux, "Can't request pads after writing header");
552 if (templ == gst_element_class_get_pad_template (klass, "audio")) {
553 if (mux->have_audio) {
554 GST_WARNING_OBJECT (mux, "Already have an audio pad");
557 mux->have_audio = TRUE;
560 } else if (templ == gst_element_class_get_pad_template (klass, "video")) {
561 if (mux->have_video) {
562 GST_WARNING_OBJECT (mux, "Already have a video pad");
565 mux->have_video = TRUE;
569 GST_WARNING_OBJECT (mux, "Invalid template");
573 pad = gst_pad_new_from_template (templ, name);
575 gst_collect_pads2_add_pad (mux->collect, pad, sizeof (GstFlvPad));
577 cpad->audio_codec_data = NULL;
578 cpad->video_codec_data = NULL;
579 gst_flv_mux_reset_pad (mux, cpad, video);
581 gst_pad_set_active (pad, TRUE);
582 gst_element_add_pad (element, pad);
588 gst_flv_mux_release_pad (GstElement * element, GstPad * pad)
590 GstFlvMux *mux = GST_FLV_MUX (GST_PAD_PARENT (pad));
591 GstFlvPad *cpad = (GstFlvPad *) gst_pad_get_element_private (pad);
593 gst_flv_mux_reset_pad (mux, cpad, cpad->video);
594 gst_collect_pads2_remove_pad (mux->collect, pad);
595 gst_element_remove_pad (element, pad);
599 gst_flv_mux_push (GstFlvMux * mux, GstBuffer * buffer)
601 /* pushing the buffer that rewrites the header will make it no longer be the
602 * total output size in bytes, but it doesn't matter at that point */
603 mux->byte_count += gst_buffer_get_size (buffer);
605 return gst_pad_push (mux->srcpad, buffer);
609 gst_flv_mux_create_header (GstFlvMux * mux)
614 _gst_buffer_new_and_alloc (9 + 4, &header, &data);
619 data[3] = 0x01; /* Version */
621 data[4] = (mux->have_audio << 2) | mux->have_video; /* flags */
622 GST_WRITE_UINT32_BE (data + 5, 9); /* data offset */
623 GST_WRITE_UINT32_BE (data + 9, 0); /* previous tag size */
629 gst_flv_mux_preallocate_index (GstFlvMux * mux)
633 gint preallocate_size;
635 /* preallocate index of size:
636 * - 'keyframes' ECMA array key: 2 + 9 = 11 bytes
637 * - nested ECMA array header, length and end marker: 8 bytes
638 * - 'times' and 'filepositions' keys: 22 bytes
639 * - two strict arrays headers and lengths: 10 bytes
640 * - each index entry: 18 bytes
642 preallocate_size = 11 + 8 + 22 + 10 + MAX_INDEX_ENTRIES * 18;
643 GST_DEBUG_OBJECT (mux, "preallocating %d bytes for the index",
646 _gst_buffer_new_and_alloc (preallocate_size, &tmp, &data);
648 /* prefill the space with a gstfiller: <spaces> script tag variable */
649 GST_WRITE_UINT16_BE (data, 9); /* 9 characters */
650 memcpy (data + 2, "gstfiller", 9);
651 GST_WRITE_UINT8 (data + 11, AMF0_STRING_MARKER); /* a string value */
652 GST_WRITE_UINT16_BE (data + 12, preallocate_size - 14);
653 memset (data + 14, ' ', preallocate_size - 14); /* the rest is spaces */
658 gst_flv_mux_create_number_script_value (const gchar * name, gdouble value)
662 gsize len = strlen (name);
664 _gst_buffer_new_and_alloc (2 + len + 1 + 8, &tmp, &data);
666 GST_WRITE_UINT16_BE (data, len);
667 data += 2; /* name length */
668 memcpy (data, name, len);
670 *data++ = AMF0_NUMBER_MARKER; /* double type */
671 GST_WRITE_DOUBLE_BE (data, value);
677 gst_flv_mux_create_metadata (GstFlvMux * mux, gboolean full)
679 const GstTagList *tags;
680 GstBuffer *script_tag, *tmp;
682 gint i, n_tags, tags_written = 0;
684 tags = gst_tag_setter_get_tag_list (GST_TAG_SETTER (mux));
686 GST_DEBUG_OBJECT (mux, "tags = %" GST_PTR_FORMAT, tags);
688 /* FIXME perhaps some bytewriter'ing here ... */
690 _gst_buffer_new_and_alloc (11, &script_tag, &data);
694 /* Data size, unknown for now */
700 data[4] = data[5] = data[6] = data[7] = 0;
703 data[8] = data[9] = data[10] = 0;
705 _gst_buffer_new_and_alloc (13, &tmp, &data);
706 data[0] = AMF0_STRING_MARKER; /* string */
708 data[2] = 10; /* length 10 */
709 memcpy (&data[3], "onMetaData", 10);
711 script_tag = gst_buffer_join (script_tag, tmp);
713 n_tags = (tags) ? gst_structure_n_fields ((GstStructure *) tags) : 0;
714 _gst_buffer_new_and_alloc (5, &tmp, &data);
715 data[0] = 8; /* ECMA array */
716 GST_WRITE_UINT32_BE (data + 1, n_tags);
717 script_tag = gst_buffer_join (script_tag, tmp);
722 /* Some players expect the 'duration' to be always set. Fill it out later,
723 after querying the pads or after getting EOS */
724 if (!mux->streamable) {
725 tmp = gst_flv_mux_create_number_script_value ("duration", 86400);
726 script_tag = gst_buffer_join (script_tag, tmp);
729 /* Sometimes the information about the total file size is useful for the
730 player. It will be filled later, after getting EOS */
731 tmp = gst_flv_mux_create_number_script_value ("filesize", 0);
732 script_tag = gst_buffer_join (script_tag, tmp);
735 /* Preallocate space for the index to be written at EOS */
736 tmp = gst_flv_mux_preallocate_index (mux);
737 script_tag = gst_buffer_join (script_tag, tmp);
739 GST_DEBUG_OBJECT (mux, "not preallocating index, streamable mode");
743 for (i = 0; tags && i < n_tags; i++) {
744 const gchar *tag_name =
745 gst_structure_nth_field_name ((const GstStructure *) tags, i);
746 if (!strcmp (tag_name, GST_TAG_DURATION)) {
749 if (!gst_tag_list_get_uint64 (tags, GST_TAG_DURATION, &dur))
752 } else if (!strcmp (tag_name, GST_TAG_ARTIST) ||
753 !strcmp (tag_name, GST_TAG_TITLE)) {
755 const gchar *t = NULL;
757 if (!strcmp (tag_name, GST_TAG_ARTIST))
759 else if (!strcmp (tag_name, GST_TAG_TITLE))
762 if (!gst_tag_list_get_string (tags, tag_name, &s))
765 _gst_buffer_new_and_alloc (2 + strlen (t) + 1 + 2 + strlen (s),
767 data[0] = 0; /* tag name length */
768 data[1] = strlen (t);
769 memcpy (&data[2], t, strlen (t));
770 data[2 + strlen (t)] = 2; /* string */
771 data[3 + strlen (t)] = (strlen (s) >> 8) & 0xff;
772 data[4 + strlen (t)] = (strlen (s)) & 0xff;
773 memcpy (&data[5 + strlen (t)], s, strlen (s));
774 script_tag = gst_buffer_join (script_tag, tmp);
784 if (mux->duration == GST_CLOCK_TIME_NONE) {
788 for (l = mux->collect->data; l; l = l->next) {
789 GstCollectData2 *cdata = l->data;
791 if (gst_pad_peer_query_duration (cdata->pad, GST_FORMAT_TIME,
792 (gint64 *) & dur) && dur != GST_CLOCK_TIME_NONE) {
793 if (mux->duration == GST_CLOCK_TIME_NONE)
796 mux->duration = MAX (dur, mux->duration);
801 if (!mux->streamable && mux->duration != GST_CLOCK_TIME_NONE) {
803 d = gst_guint64_to_gdouble (mux->duration);
804 d /= (gdouble) GST_SECOND;
806 GST_DEBUG_OBJECT (mux, "determined the duration to be %f", d);
807 data = gst_buffer_map (script_tag, NULL, NULL, GST_MAP_WRITE);
808 GST_WRITE_DOUBLE_BE (data + 29 + 2 + 8 + 1, d);
809 gst_buffer_unmap (script_tag, data, -1);
812 if (mux->have_video) {
813 GstPad *video_pad = NULL;
815 GSList *l = mux->collect->data;
817 for (; l; l = l->next) {
819 if (cpad && cpad->video) {
820 video_pad = cpad->collect.pad;
825 if (video_pad && gst_pad_has_current_caps (video_pad)) {
831 GST_DEBUG_OBJECT (mux, "putting videocodecid %d in the metadata",
834 tmp = gst_flv_mux_create_number_script_value ("videocodecid",
836 script_tag = gst_buffer_join (script_tag, tmp);
839 caps = gst_pad_get_current_caps (video_pad);
840 s = gst_caps_get_structure (caps, 0);
841 gst_caps_unref (caps);
843 if (gst_structure_get_int (s, "width", &size)) {
844 GST_DEBUG_OBJECT (mux, "putting width %d in the metadata", size);
846 tmp = gst_flv_mux_create_number_script_value ("width", size);
847 script_tag = gst_buffer_join (script_tag, tmp);
851 if (gst_structure_get_int (s, "height", &size)) {
852 GST_DEBUG_OBJECT (mux, "putting height %d in the metadata", size);
854 tmp = gst_flv_mux_create_number_script_value ("height", size);
855 script_tag = gst_buffer_join (script_tag, tmp);
859 if (gst_structure_get_fraction (s, "pixel-aspect-ratio", &num, &den)) {
863 GST_DEBUG_OBJECT (mux, "putting AspectRatioX %f in the metadata", d);
865 tmp = gst_flv_mux_create_number_script_value ("AspectRatioX", d);
866 script_tag = gst_buffer_join (script_tag, tmp);
870 GST_DEBUG_OBJECT (mux, "putting AspectRatioY %f in the metadata", d);
872 tmp = gst_flv_mux_create_number_script_value ("AspectRatioY", d);
873 script_tag = gst_buffer_join (script_tag, tmp);
877 if (gst_structure_get_fraction (s, "framerate", &num, &den)) {
880 gst_util_fraction_to_double (num, den, &d);
881 GST_DEBUG_OBJECT (mux, "putting framerate %f in the metadata", d);
883 tmp = gst_flv_mux_create_number_script_value ("framerate", d);
884 script_tag = gst_buffer_join (script_tag, tmp);
890 if (mux->have_audio) {
891 GstPad *audio_pad = NULL;
893 GSList *l = mux->collect->data;
895 for (; l; l = l->next) {
897 if (cpad && !cpad->video) {
898 audio_pad = cpad->collect.pad;
904 GST_DEBUG_OBJECT (mux, "putting audiocodecid %d in the metadata",
907 tmp = gst_flv_mux_create_number_script_value ("audiocodecid",
909 script_tag = gst_buffer_join (script_tag, tmp);
915 const gchar *s = "GStreamer FLV muxer";
917 _gst_buffer_new_and_alloc (2 + 15 + 1 + 2 + strlen (s), &tmp, &data);
918 data[0] = 0; /* 15 bytes name */
920 memcpy (&data[2], "metadatacreator", 15);
921 data[17] = 2; /* string */
922 data[18] = (strlen (s) >> 8) & 0xff;
923 data[19] = (strlen (s)) & 0xff;
924 memcpy (&data[20], s, strlen (s));
925 script_tag = gst_buffer_join (script_tag, tmp);
931 GTimeVal tv = { 0, };
935 static const gchar *weekdays[] = {
936 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
938 static const gchar *months[] = {
939 "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
940 "Aug", "Sep", "Oct", "Nov", "Dec"
943 g_get_current_time (&tv);
947 s = g_strdup_printf ("%s %s %d %d:%d:%d %d", weekdays[tm->tm_wday],
948 months[tm->tm_mon], tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec,
951 _gst_buffer_new_and_alloc (2 + 12 + 1 + 2 + strlen (s), &tmp, &data);
952 data[0] = 0; /* 12 bytes name */
954 memcpy (&data[2], "creationdate", 12);
955 data[14] = 2; /* string */
956 data[15] = (strlen (s) >> 8) & 0xff;
957 data[16] = (strlen (s)) & 0xff;
958 memcpy (&data[17], s, strlen (s));
959 script_tag = gst_buffer_join (script_tag, tmp);
968 gst_buffer_unref (script_tag);
973 _gst_buffer_new_and_alloc (2 + 0 + 1, &tmp, &data);
974 data[0] = 0; /* 0 byte size */
976 data[2] = 9; /* end marker */
977 script_tag = gst_buffer_join (script_tag, tmp);
980 _gst_buffer_new_and_alloc (4, &tmp, &data);
981 GST_WRITE_UINT32_BE (data, gst_buffer_get_size (script_tag));
982 script_tag = gst_buffer_join (script_tag, tmp);
984 data = gst_buffer_map (script_tag, NULL, NULL, GST_MAP_WRITE);
985 data[1] = ((gst_buffer_get_size (script_tag) - 11 - 4) >> 16) & 0xff;
986 data[2] = ((gst_buffer_get_size (script_tag) - 11 - 4) >> 8) & 0xff;
987 data[3] = ((gst_buffer_get_size (script_tag) - 11 - 4) >> 0) & 0xff;
989 GST_WRITE_UINT32_BE (data + 11 + 13 + 1, tags_written);
990 gst_buffer_unmap (script_tag, data, -1);
997 gst_flv_mux_buffer_to_tag_internal (GstFlvMux * mux, GstBuffer * buffer,
998 GstFlvPad * cpad, gboolean is_codec_data)
1004 (GST_BUFFER_TIMESTAMP_IS_VALID (buffer)) ? GST_BUFFER_TIMESTAMP (buffer) /
1005 GST_MSECOND : cpad->last_timestamp / GST_MSECOND;
1009 bdata = gst_buffer_map (buffer, &bsize, NULL, GST_MAP_READ);
1014 if (cpad->video_codec == 7)
1020 if (cpad->audio_codec == 10)
1027 _gst_buffer_new_and_alloc (size, &tag, &data);
1028 GST_BUFFER_TIMESTAMP (tag) = timestamp * GST_MSECOND;
1029 memset (data, 0, size);
1031 data[0] = (cpad->video) ? 9 : 8;
1033 data[1] = ((size - 11 - 4) >> 16) & 0xff;
1034 data[2] = ((size - 11 - 4) >> 8) & 0xff;
1035 data[3] = ((size - 11 - 4) >> 0) & 0xff;
1037 /* wrap the timestamp every G_MAXINT32 miliseconds */
1038 timestamp &= 0x7fffffff;
1039 data[4] = (timestamp >> 16) & 0xff;
1040 data[5] = (timestamp >> 8) & 0xff;
1041 data[6] = (timestamp >> 0) & 0xff;
1042 data[7] = (timestamp >> 24) & 0xff;
1044 data[8] = data[9] = data[10] = 0;
1047 if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT))
1052 data[11] |= cpad->video_codec & 0x0f;
1054 if (cpad->video_codec == 7) {
1055 data[12] = is_codec_data ? 0 : 1;
1057 /* FIXME: what to do about composition time */
1058 data[13] = data[14] = data[15] = 0;
1060 memcpy (data + 11 + 1 + 4, bdata, bsize);
1062 memcpy (data + 11 + 1, bdata, bsize);
1065 data[11] |= (cpad->audio_codec << 4) & 0xf0;
1066 data[11] |= (cpad->rate << 2) & 0x0c;
1067 data[11] |= (cpad->width << 1) & 0x02;
1068 data[11] |= (cpad->channels << 0) & 0x01;
1070 if (cpad->audio_codec == 10) {
1071 data[12] = is_codec_data ? 0 : 1;
1073 memcpy (data + 11 + 1 + 1, bdata, bsize);
1075 memcpy (data + 11 + 1, bdata, bsize);
1079 gst_buffer_unmap (buffer, bdata, -1);
1081 GST_WRITE_UINT32_BE (data + size - 4, size - 4);
1083 GST_BUFFER_TIMESTAMP (tag) = GST_BUFFER_TIMESTAMP (buffer);
1084 GST_BUFFER_DURATION (tag) = GST_BUFFER_DURATION (buffer);
1085 GST_BUFFER_OFFSET (tag) = GST_BUFFER_OFFSET (buffer);
1086 GST_BUFFER_OFFSET_END (tag) = GST_BUFFER_OFFSET_END (buffer);
1088 /* mark the buffer if it's an audio buffer and there's also video being muxed
1089 * or it's a video interframe */
1090 if ((mux->have_video && !cpad->video) ||
1091 GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT))
1092 GST_BUFFER_FLAG_SET (tag, GST_BUFFER_FLAG_DELTA_UNIT);
1094 GST_BUFFER_OFFSET (tag) = GST_BUFFER_OFFSET_END (tag) =
1095 GST_BUFFER_OFFSET_NONE;
1100 static inline GstBuffer *
1101 gst_flv_mux_buffer_to_tag (GstFlvMux * mux, GstBuffer * buffer,
1104 return gst_flv_mux_buffer_to_tag_internal (mux, buffer, cpad, FALSE);
1107 static inline GstBuffer *
1108 gst_flv_mux_codec_data_buffer_to_tag (GstFlvMux * mux, GstBuffer * buffer,
1111 return gst_flv_mux_buffer_to_tag_internal (mux, buffer, cpad, TRUE);
1115 gst_flv_mux_put_buffer_in_streamheader (GValue * streamheader,
1118 GValue value = { 0 };
1121 g_value_init (&value, GST_TYPE_BUFFER);
1122 buf = gst_buffer_copy (buffer);
1123 gst_value_set_buffer (&value, buf);
1124 gst_buffer_unref (buf);
1125 gst_value_array_append_value (streamheader, &value);
1126 g_value_unset (&value);
1129 static GstFlowReturn
1130 gst_flv_mux_write_header (GstFlvMux * mux)
1132 GstBuffer *header, *metadata;
1133 GstBuffer *video_codec_data, *audio_codec_data;
1135 GstStructure *structure;
1136 GValue streamheader = { 0 };
1140 header = gst_flv_mux_create_header (mux);
1141 metadata = gst_flv_mux_create_metadata (mux, TRUE);
1142 video_codec_data = NULL;
1143 audio_codec_data = NULL;
1145 for (l = mux->collect->data; l != NULL; l = l->next) {
1146 GstFlvPad *cpad = l->data;
1148 /* Get H.264 and AAC codec data, if present */
1149 if (cpad && cpad->video && cpad->video_codec == 7) {
1150 if (cpad->video_codec_data == NULL)
1151 GST_WARNING_OBJECT (mux, "Codec data for video stream not found, "
1152 "output might not be playable");
1155 gst_flv_mux_codec_data_buffer_to_tag (mux, cpad->video_codec_data,
1157 } else if (cpad && !cpad->video && cpad->audio_codec == 10) {
1158 if (cpad->audio_codec_data == NULL)
1159 GST_WARNING_OBJECT (mux, "Codec data for audio stream not found, "
1160 "output might not be playable");
1163 gst_flv_mux_codec_data_buffer_to_tag (mux, cpad->audio_codec_data,
1168 /* mark buffers that will go in the streamheader */
1169 GST_BUFFER_FLAG_SET (header, GST_BUFFER_FLAG_IN_CAPS);
1170 GST_BUFFER_FLAG_SET (metadata, GST_BUFFER_FLAG_IN_CAPS);
1171 if (video_codec_data != NULL) {
1172 GST_BUFFER_FLAG_SET (video_codec_data, GST_BUFFER_FLAG_IN_CAPS);
1173 /* mark as a delta unit, so downstream will not try to synchronize on that
1174 * buffer - to actually start playback you need a real video keyframe */
1175 GST_BUFFER_FLAG_SET (video_codec_data, GST_BUFFER_FLAG_DELTA_UNIT);
1177 if (audio_codec_data != NULL) {
1178 GST_BUFFER_FLAG_SET (audio_codec_data, GST_BUFFER_FLAG_IN_CAPS);
1181 /* put buffers in streamheader */
1182 g_value_init (&streamheader, GST_TYPE_ARRAY);
1183 gst_flv_mux_put_buffer_in_streamheader (&streamheader, header);
1184 gst_flv_mux_put_buffer_in_streamheader (&streamheader, metadata);
1185 if (video_codec_data != NULL)
1186 gst_flv_mux_put_buffer_in_streamheader (&streamheader, video_codec_data);
1187 if (audio_codec_data != NULL)
1188 gst_flv_mux_put_buffer_in_streamheader (&streamheader, audio_codec_data);
1190 /* create the caps and put the streamheader in them */
1191 caps = gst_caps_new_empty_simple ("video/x-flv");
1192 structure = gst_caps_get_structure (caps, 0);
1193 gst_structure_set_value (structure, "streamheader", &streamheader);
1194 g_value_unset (&streamheader);
1196 if (!gst_pad_has_current_caps (mux->srcpad))
1197 gst_pad_set_caps (mux->srcpad, caps);
1199 gst_caps_unref (caps);
1201 /* push the header buffer, the metadata and the codec info, if any */
1202 ret = gst_flv_mux_push (mux, header);
1203 if (ret != GST_FLOW_OK)
1205 ret = gst_flv_mux_push (mux, metadata);
1206 if (ret != GST_FLOW_OK)
1208 if (video_codec_data != NULL) {
1209 ret = gst_flv_mux_push (mux, video_codec_data);
1210 if (ret != GST_FLOW_OK)
1213 if (audio_codec_data != NULL) {
1214 ret = gst_flv_mux_push (mux, audio_codec_data);
1215 if (ret != GST_FLOW_OK)
1222 gst_flv_mux_update_index (GstFlvMux * mux, GstBuffer * buffer, GstFlvPad * cpad)
1225 * Add the tag byte offset and to the index if it's a valid seek point, which
1226 * means it's either a video keyframe or if there is no video pad (in that
1227 * case every FLV tag is a valid seek point)
1229 if (mux->have_video &&
1231 GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT)))
1234 if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer)) {
1235 GstFlvMuxIndexEntry *entry = g_slice_new (GstFlvMuxIndexEntry);
1236 entry->position = mux->byte_count;
1238 gst_guint64_to_gdouble (GST_BUFFER_TIMESTAMP (buffer)) / GST_SECOND;
1239 mux->index = g_list_prepend (mux->index, entry);
1243 static GstFlowReturn
1244 gst_flv_mux_write_buffer (GstFlvMux * mux, GstFlvPad * cpad, GstBuffer * buffer)
1249 /* clipping function arranged for running_time */
1251 if (!mux->streamable)
1252 gst_flv_mux_update_index (mux, buffer, cpad);
1254 tag = gst_flv_mux_buffer_to_tag (mux, buffer, cpad);
1256 gst_buffer_unref (buffer);
1258 ret = gst_flv_mux_push (mux, tag);
1260 if (ret == GST_FLOW_OK && GST_BUFFER_TIMESTAMP_IS_VALID (tag))
1261 cpad->last_timestamp = GST_BUFFER_TIMESTAMP (tag);
1267 gst_flv_mux_determine_duration (GstFlvMux * mux)
1270 GstClockTime duration = GST_CLOCK_TIME_NONE;
1272 GST_DEBUG_OBJECT (mux, "trying to determine the duration "
1273 "from pad timestamps");
1275 for (l = mux->collect->data; l != NULL; l = l->next) {
1276 GstFlvPad *cpad = l->data;
1278 if (cpad && (cpad->last_timestamp != GST_CLOCK_TIME_NONE)) {
1279 if (duration == GST_CLOCK_TIME_NONE)
1280 duration = cpad->last_timestamp;
1282 duration = MAX (duration, cpad->last_timestamp);
1289 static GstFlowReturn
1290 gst_flv_mux_rewrite_header (GstFlvMux * mux)
1292 GstBuffer *rewrite, *index, *tmp;
1297 guint32 index_len, allocate_size;
1298 guint32 i, index_skip;
1302 if (mux->streamable)
1305 /* seek back to the preallocated index space */
1306 gst_segment_init (&segment, GST_FORMAT_BYTES);
1307 segment.start = segment.time = 13 + 29;
1308 event = gst_event_new_segment (&segment);
1309 if (!gst_pad_push_event (mux->srcpad, event)) {
1310 GST_WARNING_OBJECT (mux, "Seek to rewrite header failed");
1314 /* determine duration now based on our own timestamping,
1315 * so that it is likely many times better and consistent
1316 * than whatever obtained by some query */
1317 dur = gst_flv_mux_determine_duration (mux);
1318 if (dur != GST_CLOCK_TIME_NONE)
1319 mux->duration = dur;
1321 /* rewrite the duration tag */
1322 d = gst_guint64_to_gdouble (mux->duration);
1323 d /= (gdouble) GST_SECOND;
1325 GST_DEBUG_OBJECT (mux, "determined the final duration to be %f", d);
1327 rewrite = gst_flv_mux_create_number_script_value ("duration", d);
1329 /* rewrite the filesize tag */
1330 d = gst_guint64_to_gdouble (mux->byte_count);
1332 GST_DEBUG_OBJECT (mux, "putting total filesize %f in the metadata", d);
1334 tmp = gst_flv_mux_create_number_script_value ("filesize", d);
1335 rewrite = gst_buffer_join (rewrite, tmp);
1338 /* no index, so push buffer and return */
1339 return gst_flv_mux_push (mux, rewrite);
1342 /* rewrite the index */
1343 mux->index = g_list_reverse (mux->index);
1344 index_len = g_list_length (mux->index);
1346 /* We write at most MAX_INDEX_ENTRIES elements */
1347 if (index_len > MAX_INDEX_ENTRIES) {
1348 index_skip = 1 + index_len / MAX_INDEX_ENTRIES;
1349 index_len = (index_len + index_skip - 1) / index_skip;
1354 GST_DEBUG_OBJECT (mux, "Index length is %d", index_len);
1355 /* see size calculation in gst_flv_mux_preallocate_index */
1356 allocate_size = 11 + 8 + 22 + 10 + index_len * 18;
1357 GST_DEBUG_OBJECT (mux, "Allocating %d bytes for index", allocate_size);
1358 _gst_buffer_new_and_alloc (allocate_size, &index, &data);
1360 GST_WRITE_UINT16_BE (data, 9); /* the 'keyframes' key */
1361 memcpy (data + 2, "keyframes", 9);
1362 GST_WRITE_UINT8 (data + 11, 8); /* nested ECMA array */
1363 GST_WRITE_UINT32_BE (data + 12, 2); /* two elements */
1364 GST_WRITE_UINT16_BE (data + 16, 5); /* first string key: 'times' */
1365 memcpy (data + 18, "times", 5);
1366 GST_WRITE_UINT8 (data + 23, 10); /* strict array */
1367 GST_WRITE_UINT32_BE (data + 24, index_len);
1370 /* the keyframes' times */
1371 for (i = 0, l = mux->index; l; l = l->next, i++) {
1372 GstFlvMuxIndexEntry *entry = l->data;
1374 if (i % index_skip != 0)
1376 GST_WRITE_UINT8 (data, 0); /* numeric (aka double) */
1377 GST_WRITE_DOUBLE_BE (data + 1, entry->time);
1381 GST_WRITE_UINT16_BE (data, 13); /* second string key: 'filepositions' */
1382 memcpy (data + 2, "filepositions", 13);
1383 GST_WRITE_UINT8 (data + 15, 10); /* strict array */
1384 GST_WRITE_UINT32_BE (data + 16, index_len);
1387 /* the keyframes' file positions */
1388 for (i = 0, l = mux->index; l; l = l->next, i++) {
1389 GstFlvMuxIndexEntry *entry = l->data;
1391 if (i % index_skip != 0)
1393 GST_WRITE_UINT8 (data, 0);
1394 GST_WRITE_DOUBLE_BE (data + 1, entry->position);
1398 GST_WRITE_UINT24_BE (data, 9); /* finish the ECMA array */
1400 /* If there is space left in the prefilled area, reinsert the filler.
1401 There is at least 18 bytes free, so it will always fit. */
1402 if (index_len < MAX_INDEX_ENTRIES) {
1405 guint32 remaining_filler_size;
1407 _gst_buffer_new_and_alloc (14, &tmp, &data);
1408 GST_WRITE_UINT16_BE (data, 9);
1409 memcpy (data + 2, "gstfiller", 9);
1410 GST_WRITE_UINT8 (data + 11, 2); /* string */
1412 /* There is 18 bytes per remaining index entry minus what is used for
1413 * the'gstfiller' key. The rest is already filled with spaces, so just need
1414 * to update length. */
1415 remaining_filler_size = (MAX_INDEX_ENTRIES - index_len) * 18 - 14;
1416 GST_DEBUG_OBJECT (mux, "Remaining filler size is %d bytes",
1417 remaining_filler_size);
1418 GST_WRITE_UINT16_BE (data + 12, remaining_filler_size);
1419 index = gst_buffer_join (index, tmp);
1422 rewrite = gst_buffer_join (rewrite, index);
1424 return gst_flv_mux_push (mux, rewrite);
1427 static GstFlowReturn
1428 gst_flv_mux_handle_buffer (GstCollectPads2 * pads, GstCollectData2 * cdata,
1429 GstBuffer * buffer, gpointer user_data)
1431 GstFlvMux *mux = GST_FLV_MUX (user_data);
1433 GstClockTime best_time;
1436 if (mux->state == GST_FLV_MUX_STATE_HEADER) {
1439 if (mux->collect->data == NULL) {
1440 GST_ELEMENT_ERROR (mux, STREAM, MUX, (NULL),
1441 ("No input streams configured"));
1442 return GST_FLOW_ERROR;
1445 gst_segment_init (&segment, GST_FORMAT_BYTES);
1446 if (gst_pad_push_event (mux->srcpad, gst_event_new_segment (&segment)))
1447 ret = gst_flv_mux_write_header (mux);
1449 ret = GST_FLOW_ERROR;
1451 if (ret != GST_FLOW_OK)
1453 mux->state = GST_FLV_MUX_STATE_DATA;
1456 if (mux->new_tags) {
1457 GstBuffer *buf = gst_flv_mux_create_metadata (mux, FALSE);
1459 gst_flv_mux_push (mux, buf);
1460 mux->new_tags = FALSE;
1463 best = (GstFlvPad *) cdata;
1466 best_time = GST_BUFFER_TIMESTAMP (buffer);
1468 best_time = GST_CLOCK_TIME_NONE;
1471 /* The FLV timestamp is an int32 field. For non-live streams error out if a
1472 bigger timestamp is seen, for live the timestamp will get wrapped in
1473 gst_flv_mux_buffer_to_tag */
1474 if (!mux->streamable && GST_CLOCK_TIME_IS_VALID (best_time)
1475 && best_time / GST_MSECOND > G_MAXINT32) {
1476 GST_WARNING_OBJECT (mux, "Timestamp larger than FLV supports - EOS");
1477 gst_buffer_unref (buffer);
1483 return gst_flv_mux_write_buffer (mux, best, buffer);
1485 gst_flv_mux_rewrite_header (mux);
1486 gst_pad_push_event (mux->srcpad, gst_event_new_eos ());
1487 return GST_FLOW_EOS;
1492 gst_flv_mux_get_property (GObject * object,
1493 guint prop_id, GValue * value, GParamSpec * pspec)
1495 GstFlvMux *mux = GST_FLV_MUX (object);
1498 case PROP_STREAMABLE:
1499 g_value_set_boolean (value, mux->streamable);
1502 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1508 gst_flv_mux_set_property (GObject * object,
1509 guint prop_id, const GValue * value, GParamSpec * pspec)
1511 GstFlvMux *mux = GST_FLV_MUX (object);
1514 case PROP_STREAMABLE:
1515 mux->streamable = g_value_get_boolean (value);
1516 if (mux->streamable)
1517 gst_tag_setter_set_tag_merge_mode (GST_TAG_SETTER (mux),
1518 GST_TAG_MERGE_REPLACE);
1520 gst_tag_setter_set_tag_merge_mode (GST_TAG_SETTER (mux),
1521 GST_TAG_MERGE_KEEP);
1524 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1529 static GstStateChangeReturn
1530 gst_flv_mux_change_state (GstElement * element, GstStateChange transition)
1532 GstStateChangeReturn ret;
1533 GstFlvMux *mux = GST_FLV_MUX (element);
1535 switch (transition) {
1536 case GST_STATE_CHANGE_NULL_TO_READY:
1538 case GST_STATE_CHANGE_READY_TO_PAUSED:
1539 gst_collect_pads2_start (mux->collect);
1541 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1543 case GST_STATE_CHANGE_PAUSED_TO_READY:
1544 gst_collect_pads2_stop (mux->collect);
1550 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1552 switch (transition) {
1553 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1555 case GST_STATE_CHANGE_PAUSED_TO_READY:
1556 gst_flv_mux_reset (GST_ELEMENT (mux));
1558 case GST_STATE_CHANGE_READY_TO_NULL: