2 * (c) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
3 * (c) 2005 Michal Benes <michal.benes@xeris.cz>
5 * ebml-write.c: write EBML data to file/stream
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
29 #include "ebml-write.h"
33 GST_DEBUG_CATEGORY_STATIC (gst_ebml_write_debug);
34 #define GST_CAT_DEFAULT gst_ebml_write_debug
37 GST_DEBUG_CATEGORY_INIT (gst_ebml_write_debug, "ebmlwrite", 0, "Write EBML structured data")
38 #define parent_class gst_ebml_write_parent_class
39 G_DEFINE_TYPE_WITH_CODE (GstEbmlWrite, gst_ebml_write, GST_TYPE_OBJECT,
42 static void gst_ebml_write_finalize (GObject * object);
45 gst_ebml_write_class_init (GstEbmlWriteClass * klass)
47 GObjectClass *object = G_OBJECT_CLASS (klass);
49 object->finalize = gst_ebml_write_finalize;
53 gst_ebml_write_init (GstEbmlWrite * ebml)
57 ebml->last_pos = G_MAXUINT64; /* force segment event */
60 ebml->streamheader = NULL;
61 ebml->streamheader_pos = 0;
62 ebml->writing_streamheader = FALSE;
67 gst_ebml_write_finalize (GObject * object)
69 GstEbmlWrite *ebml = GST_EBML_WRITE (object);
71 gst_object_unref (ebml->srcpad);
74 gst_byte_writer_free (ebml->cache);
78 if (ebml->streamheader) {
79 gst_byte_writer_free (ebml->streamheader);
80 ebml->streamheader = NULL;
84 gst_caps_unref (ebml->caps);
88 G_OBJECT_CLASS (parent_class)->finalize (object);
94 * @srcpad: Source pad to which the output will be pushed.
96 * Creates a new #GstEbmlWrite.
98 * Returns: a new #GstEbmlWrite
101 gst_ebml_write_new (GstPad * srcpad)
104 GST_EBML_WRITE (g_object_new (GST_TYPE_EBML_WRITE, NULL));
106 ebml->srcpad = gst_object_ref (srcpad);
107 ebml->timestamp = GST_CLOCK_TIME_NONE;
109 gst_ebml_write_reset (ebml);
116 * gst_ebml_write_reset:
117 * @ebml: a #GstEbmlWrite.
119 * Reset internal state of #GstEbmlWrite.
122 gst_ebml_write_reset (GstEbmlWrite * ebml)
125 ebml->last_pos = G_MAXUINT64; /* force segment event */
128 gst_byte_writer_free (ebml->cache);
133 gst_caps_unref (ebml->caps);
137 ebml->last_write_result = GST_FLOW_OK;
138 ebml->timestamp = GST_CLOCK_TIME_NONE;
143 * gst_ebml_last_write_result:
144 * @ebml: a #GstEbmlWrite.
146 * Returns: GST_FLOW_OK if there was not write error since the last call of
147 * gst_ebml_last_write_result or code of the error.
150 gst_ebml_last_write_result (GstEbmlWrite * ebml)
152 GstFlowReturn res = ebml->last_write_result;
154 ebml->last_write_result = GST_FLOW_OK;
161 gst_ebml_start_streamheader (GstEbmlWrite * ebml)
163 g_return_if_fail (ebml->streamheader == NULL);
165 GST_DEBUG ("Starting streamheader at %" G_GUINT64_FORMAT, ebml->pos);
166 ebml->streamheader = gst_byte_writer_new_with_size (1000, FALSE);
167 ebml->streamheader_pos = ebml->pos;
168 ebml->writing_streamheader = TRUE;
172 gst_ebml_stop_streamheader (GstEbmlWrite * ebml)
176 if (!ebml->streamheader)
179 buffer = gst_byte_writer_free_and_get_buffer (ebml->streamheader);
180 ebml->streamheader = NULL;
181 GST_DEBUG ("Streamheader was size %" G_GSIZE_FORMAT,
182 gst_buffer_get_size (buffer));
184 ebml->writing_streamheader = FALSE;
189 * gst_ebml_write_set_cache:
190 * @ebml: a #GstEbmlWrite.
191 * @size: size of the cache.
194 * The idea is that you use this for writing a lot
195 * of small elements. This will just "queue" all of
196 * them and they'll be pushed to the next element all
197 * at once. This saves memory and time for buffer
198 * allocation and init, and it looks better.
201 gst_ebml_write_set_cache (GstEbmlWrite * ebml, guint size)
203 g_return_if_fail (ebml->cache == NULL);
205 GST_DEBUG ("Starting cache at %" G_GUINT64_FORMAT, ebml->pos);
206 ebml->cache = gst_byte_writer_new_with_size (size, FALSE);
207 ebml->cache_pos = ebml->pos;
211 gst_ebml_writer_send_segment_event (GstEbmlWrite * ebml, guint64 new_pos)
216 GST_INFO ("seeking to %" G_GUINT64_FORMAT, new_pos);
218 gst_segment_init (&segment, GST_FORMAT_BYTES);
219 segment.start = new_pos;
221 segment.position = 0;
223 res = gst_pad_push_event (ebml->srcpad, gst_event_new_segment (&segment));
226 GST_WARNING ("seek to %" G_GUINT64_FORMAT "failed", new_pos);
232 * gst_ebml_write_flush_cache:
233 * @ebml: a #GstEbmlWrite.
234 * @timestamp: timestamp of the buffer.
239 gst_ebml_write_flush_cache (GstEbmlWrite * ebml, gboolean is_keyframe,
240 GstClockTime timestamp)
247 buffer = gst_byte_writer_free_and_get_buffer (ebml->cache);
249 GST_DEBUG ("Flushing cache of size %" G_GSIZE_FORMAT,
250 gst_buffer_get_size (buffer));
251 GST_BUFFER_TIMESTAMP (buffer) = timestamp;
252 GST_BUFFER_OFFSET (buffer) = ebml->pos - gst_buffer_get_size (buffer);
253 GST_BUFFER_OFFSET_END (buffer) = ebml->pos;
254 if (ebml->last_write_result == GST_FLOW_OK) {
255 if (GST_BUFFER_OFFSET (buffer) != ebml->last_pos) {
256 gst_ebml_writer_send_segment_event (ebml, GST_BUFFER_OFFSET (buffer));
257 GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
259 if (ebml->writing_streamheader) {
260 GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_HEADER);
263 GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT);
265 ebml->last_pos = ebml->pos;
266 ebml->last_write_result = gst_pad_push (ebml->srcpad, buffer);
268 gst_buffer_unref (buffer);
274 * gst_ebml_write_element_new:
275 * @ebml: a #GstEbmlWrite.
276 * @size: size of the requested buffer.
278 * Create a buffer for one element. If there is
279 * a cache, use that instead.
281 * Returns: A new #GstBuffer.
284 gst_ebml_write_element_new (GstEbmlWrite * ebml, GstMapInfo * map, guint size)
286 /* Create new buffer of size + ID + length */
292 buf = gst_buffer_new_and_alloc (size);
293 GST_BUFFER_TIMESTAMP (buf) = ebml->timestamp;
295 /* FIXME unmap not possible */
296 gst_buffer_map (buf, map, GST_MAP_WRITE);
303 * gst_ebml_write_element_id:
304 * @data_inout: Pointer to data pointer
305 * @id: Element ID that should be written.
307 * Write element ID into a buffer.
310 gst_ebml_write_element_id (guint8 ** data_inout, guint32 id)
312 guint8 *data = *data_inout;
313 guint bytes = 4, mask = 0x10;
316 while (!(id & (mask << ((bytes - 1) * 8))) && bytes > 0) {
321 /* if invalid ID, use dummy */
323 GST_WARNING ("Invalid ID, voiding");
325 id = GST_EBML_ID_VOID;
329 *data_inout += bytes;
331 data[bytes] = id & 0xff;
338 * gst_ebml_write_element_size:
339 * @data_inout: Pointer to data pointer
340 * @size: Element length.
342 * Write element length into a buffer.
345 gst_ebml_write_element_size (guint8 ** data_inout, guint64 size)
347 guint8 *data = *data_inout;
348 guint bytes = 1, mask = 0x80;
350 if (size != GST_EBML_SIZE_UNKNOWN) {
351 /* how many bytes? - use mask-1 because an all-1 bitset is not allowed */
352 while ((size >> ((bytes - 1) * 8)) >= (mask - 1) && bytes <= 8) {
357 /* if invalid size, use max. */
359 GST_WARNING ("Invalid size, writing size unknown");
362 /* Now here's a real FIXME: we cannot read those yet! */
363 size = GST_EBML_SIZE_UNKNOWN;
370 /* write out, BE, with length size marker */
371 *data_inout += bytes;
372 while (bytes-- > 0) {
373 data[bytes] = size & 0xff;
382 * gst_ebml_write_element_data:
383 * @data_inout: Pointer to data pointer
384 * @write: Data that should be written.
385 * @length: Length of the data.
387 * Write element data into a buffer.
390 gst_ebml_write_element_data (guint8 ** data_inout, guint8 * write,
393 memcpy (*data_inout, write, length);
394 *data_inout += length;
399 * gst_ebml_write_element_push:
400 * @ebml: #GstEbmlWrite
401 * @buf: #GstBuffer to be written.
402 * @buf_data: Start of data to push from @buf (or NULL for whole buffer).
403 * @buf_data_end: Data pointer positioned after the last byte in @buf_data (or
404 * NULL for whole buffer).
406 * Write out buffer by moving it to the next element.
409 gst_ebml_write_element_push (GstEbmlWrite * ebml, GstBuffer * buf,
410 guint8 * buf_data, guint8 * buf_data_end)
418 data_size = buf_data_end - buf_data;
420 data_size = gst_buffer_get_size (buf);
422 ebml->pos += data_size;
424 /* if there's no cache, then don't push it! */
425 if (ebml->writing_streamheader) {
427 gst_buffer_map (buf, &map, GST_MAP_READ);
431 GST_WARNING ("Failed to map buffer");
432 else if (!gst_byte_writer_put_data (ebml->streamheader, buf_data,
434 GST_WARNING ("Error writing data to streamheader");
438 gst_buffer_map (buf, &map, GST_MAP_READ);
442 GST_WARNING ("Failed to map buffer");
443 else if (!gst_byte_writer_put_data (ebml->cache, buf_data, data_size))
444 GST_WARNING ("Error writing data to cache");
446 gst_buffer_unmap (buf, &map);
447 gst_buffer_unref (buf);
451 if (buf_data && map.data)
452 gst_buffer_unmap (buf, &map);
454 if (ebml->last_write_result == GST_FLOW_OK) {
455 buf = gst_buffer_make_writable (buf);
456 GST_BUFFER_OFFSET (buf) = ebml->pos - data_size;
457 GST_BUFFER_OFFSET_END (buf) = ebml->pos;
458 if (ebml->writing_streamheader) {
459 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_HEADER);
461 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
463 if (GST_BUFFER_OFFSET (buf) != ebml->last_pos) {
464 gst_ebml_writer_send_segment_event (ebml, GST_BUFFER_OFFSET (buf));
465 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
467 ebml->last_pos = ebml->pos;
468 ebml->last_write_result = gst_pad_push (ebml->srcpad, buf);
470 gst_buffer_unref (buf);
476 * gst_ebml_write_seek:
477 * @ebml: #GstEbmlWrite
478 * @pos: Seek position.
483 gst_ebml_write_seek (GstEbmlWrite * ebml, guint64 pos)
485 if (ebml->writing_streamheader) {
486 GST_DEBUG ("wanting to seek to pos %" G_GUINT64_FORMAT, pos);
487 if (pos >= ebml->streamheader_pos &&
488 pos <= ebml->streamheader_pos + ebml->streamheader->parent.size) {
489 gst_byte_writer_set_pos (ebml->streamheader,
490 pos - ebml->streamheader_pos);
491 GST_DEBUG ("seeked in streamheader to position %" G_GUINT64_FORMAT,
492 pos - ebml->streamheader_pos);
495 ("we are writing streamheader still and seek is out of bounds");
498 /* Cache seeking. A bit dangerous, we assume the client writer
499 * knows what he's doing... */
502 if (pos >= ebml->cache_pos &&
503 pos <= ebml->cache_pos + ebml->cache->parent.size) {
504 GST_DEBUG ("seeking in cache to %" G_GUINT64_FORMAT, pos);
506 gst_byte_writer_set_pos (ebml->cache, ebml->pos - ebml->cache_pos);
509 GST_LOG ("Seek outside cache range. Clearing...");
510 gst_ebml_write_flush_cache (ebml, FALSE, GST_CLOCK_TIME_NONE);
514 GST_INFO ("scheduling seek to %" G_GUINT64_FORMAT, pos);
520 * gst_ebml_write_get_uint_size:
521 * @num: Number to be encoded.
523 * Get number of bytes needed to write a uint.
525 * Returns: Encoded uint length.
528 gst_ebml_write_get_uint_size (guint64 num)
533 while (num >= (G_GINT64_CONSTANT (1) << (size * 8)) && size < 8) {
542 * gst_ebml_write_set_uint:
543 * @data_inout: Pointer to data pointer
544 * @num: Number to be written.
545 * @size: Encoded number length.
547 * Write an uint into a buffer.
550 gst_ebml_write_set_uint (guint8 ** data_inout, guint64 num, guint size)
552 guint8 *data = *data_inout;
557 data[size] = num & 0xff;
564 * gst_ebml_write_uint:
565 * @ebml: #GstEbmlWrite
567 * @num: Number to be written.
569 * Write uint element.
572 gst_ebml_write_uint (GstEbmlWrite * ebml, guint32 id, guint64 num)
575 guint8 *data_start, *data_end;
576 guint size = gst_ebml_write_get_uint_size (num);
579 buf = gst_ebml_write_element_new (ebml, &map, sizeof (num));
580 data_end = data_start = map.data;
583 gst_ebml_write_element_id (&data_end, id);
584 gst_ebml_write_element_size (&data_end, size);
585 gst_ebml_write_set_uint (&data_end, num, size);
586 gst_buffer_unmap (buf, &map);
587 gst_buffer_set_size (buf, (data_end - data_start));
589 gst_ebml_write_element_push (ebml, buf, data_start, data_end);
594 * gst_ebml_write_sint:
595 * @ebml: #GstEbmlWrite
597 * @num: Number to be written.
599 * Write sint element.
602 gst_ebml_write_sint (GstEbmlWrite * ebml, guint32 id, gint64 num)
605 guint8 *data_start, *data_end;
608 /* if the signed number is on the edge of a extra-byte,
609 * then we'll fall over when detecting it. Example: if I
610 * have a number (-)0x8000 (G_MINSHORT), then my abs()<<1
611 * will be 0x10000; this is G_MAXUSHORT+1! So: if (<0) -1. */
612 guint64 unum = (num < 0 ? (-num - 1) << 1 : num << 1);
613 guint size = gst_ebml_write_get_uint_size (unum);
615 buf = gst_ebml_write_element_new (ebml, &map, sizeof (num));
616 data_end = data_start = map.data;
622 unum = 0x80 << (size - 1);
624 unum |= 0x80 << (size - 1);
628 gst_ebml_write_element_id (&data_end, id);
629 gst_ebml_write_element_size (&data_end, size);
630 gst_ebml_write_set_uint (&data_end, unum, size);
631 gst_buffer_unmap (buf, &map);
632 gst_buffer_set_size (buf, (data_end - data_start));
634 gst_ebml_write_element_push (ebml, buf, data_start, data_end);
639 * gst_ebml_write_float:
640 * @ebml: #GstEbmlWrite
642 * @num: Number to be written.
644 * Write float element.
647 gst_ebml_write_float (GstEbmlWrite * ebml, guint32 id, gdouble num)
651 guint8 *data_start, *data_end;
653 buf = gst_ebml_write_element_new (ebml, &map, sizeof (num));
654 data_end = data_start = map.data;
656 gst_ebml_write_element_id (&data_end, id);
657 gst_ebml_write_element_size (&data_end, 8);
658 num = GDOUBLE_TO_BE (num);
659 gst_ebml_write_element_data (&data_end, (guint8 *) & num, 8);
660 gst_buffer_unmap (buf, &map);
661 gst_buffer_set_size (buf, (data_end - data_start));
663 gst_ebml_write_element_push (ebml, buf, data_start, data_end);
668 * gst_ebml_write_ascii:
669 * @ebml: #GstEbmlWrite
671 * @str: String to be written.
673 * Write string element.
676 gst_ebml_write_ascii (GstEbmlWrite * ebml, guint32 id, const gchar * str)
678 gint len = strlen (str) + 1; /* add trailing '\0' */
681 guint8 *data_start, *data_end;
683 buf = gst_ebml_write_element_new (ebml, &map, len);
684 data_end = data_start = map.data;
686 gst_ebml_write_element_id (&data_end, id);
687 gst_ebml_write_element_size (&data_end, len);
688 gst_ebml_write_element_data (&data_end, (guint8 *) str, len);
689 gst_buffer_unmap (buf, &map);
690 gst_buffer_set_size (buf, (data_end - data_start));
692 gst_ebml_write_element_push (ebml, buf, data_start, data_end);
697 * gst_ebml_write_utf8:
698 * @ebml: #GstEbmlWrite
700 * @str: String to be written.
702 * Write utf8 encoded string element.
705 gst_ebml_write_utf8 (GstEbmlWrite * ebml, guint32 id, const gchar * str)
707 gst_ebml_write_ascii (ebml, id, str);
712 * gst_ebml_write_date:
713 * @ebml: #GstEbmlWrite
715 * @date: Date in seconds since the unix epoch.
717 * Write date element.
720 gst_ebml_write_date (GstEbmlWrite * ebml, guint32 id, gint64 date)
722 gst_ebml_write_sint (ebml, id, (date - GST_EBML_DATE_OFFSET) * GST_SECOND);
726 * gst_ebml_write_master_start:
727 * @ebml: #GstEbmlWrite
730 * Start wiriting mater element.
732 * Master writing is annoying. We use a size marker of
733 * the max. allowed length, so that we can later fill it
736 * Returns: Master starting position.
739 gst_ebml_write_master_start (GstEbmlWrite * ebml, guint32 id)
741 guint64 pos = ebml->pos;
744 guint8 *data_start, *data_end;
746 buf = gst_ebml_write_element_new (ebml, &map, 0);
747 data_end = data_start = map.data;
749 gst_ebml_write_element_id (&data_end, id);
750 pos += data_end - data_start;
751 gst_ebml_write_element_size (&data_end, GST_EBML_SIZE_UNKNOWN);
752 gst_buffer_unmap (buf, &map);
753 gst_buffer_set_size (buf, (data_end - data_start));
755 gst_ebml_write_element_push (ebml, buf, data_start, data_end);
762 * gst_ebml_write_master_finish_full:
763 * @ebml: #GstEbmlWrite
764 * @startpos: Master starting position.
766 * Finish writing master element. Size of master element is difference between
767 * current position and the element start, and @extra_size added to this.
770 gst_ebml_write_master_finish_full (GstEbmlWrite * ebml, guint64 startpos,
773 guint64 pos = ebml->pos;
774 guint8 *data = g_malloc (8);
775 GstBuffer *buf = gst_buffer_new_wrapped (data, 8);
777 gst_ebml_write_seek (ebml, startpos);
779 GST_WRITE_UINT64_BE (data,
780 (G_GINT64_CONSTANT (1) << 56) | (pos - startpos - 8 + extra_size));
782 gst_ebml_write_element_push (ebml, buf, NULL, NULL);
783 gst_ebml_write_seek (ebml, pos);
787 gst_ebml_write_master_finish (GstEbmlWrite * ebml, guint64 startpos)
789 gst_ebml_write_master_finish_full (ebml, startpos, 0);
793 * gst_ebml_write_binary:
794 * @ebml: #GstEbmlWrite
796 * @binary: Data to be written.
797 * @length: Length of the data
799 * Write an element with binary data.
802 gst_ebml_write_binary (GstEbmlWrite * ebml,
803 guint32 id, guint8 * binary, guint64 length)
807 guint8 *data_start, *data_end;
809 buf = gst_ebml_write_element_new (ebml, &map, length);
810 data_end = data_start = map.data;
812 gst_ebml_write_element_id (&data_end, id);
813 gst_ebml_write_element_size (&data_end, length);
814 gst_ebml_write_element_data (&data_end, binary, length);
815 gst_buffer_unmap (buf, &map);
816 gst_buffer_set_size (buf, (data_end - data_start));
818 gst_ebml_write_element_push (ebml, buf, data_start, data_end);
823 * gst_ebml_write_buffer_header:
824 * @ebml: #GstEbmlWrite
826 * @length: Length of the data
828 * Write header of the binary element (use with gst_ebml_write_buffer function).
830 * For things like video frames and audio samples,
831 * you want to use this function, as it doesn't have
832 * the overhead of memcpy() that other functions
833 * such as write_binary() do have.
836 gst_ebml_write_buffer_header (GstEbmlWrite * ebml, guint32 id, guint64 length)
840 guint8 *data_start, *data_end;
842 buf = gst_ebml_write_element_new (ebml, &map, 0);
843 data_end = data_start = map.data;
845 gst_ebml_write_element_id (&data_end, id);
846 gst_ebml_write_element_size (&data_end, length);
847 gst_buffer_unmap (buf, &map);
848 gst_buffer_set_size (buf, (data_end - data_start));
850 gst_ebml_write_element_push (ebml, buf, data_start, data_end);
855 * gst_ebml_write_buffer:
856 * @ebml: #GstEbmlWrite
857 * @buf: #GstBuffer cointaining the data.
859 * Write binary element (see gst_ebml_write_buffer_header).
862 gst_ebml_write_buffer (GstEbmlWrite * ebml, GstBuffer * buf)
864 gst_ebml_write_element_push (ebml, buf, NULL, NULL);
869 * gst_ebml_replace_uint:
870 * @ebml: #GstEbmlWrite
871 * @pos: Position of the uint that should be replaced.
874 * Replace uint with a new value.
876 * When replacing a uint, we assume that it is *always*
877 * 8-byte, since that's the safest guess we can do. This
878 * is just for simplicity.
880 * FIXME: this function needs to be replaced with something
881 * proper. This is a crude hack.
884 gst_ebml_replace_uint (GstEbmlWrite * ebml, guint64 pos, guint64 num)
886 guint64 oldpos = ebml->pos;
887 guint8 *data_start, *data_end;
890 data_start = g_malloc (8);
891 data_end = data_start;
892 buf = gst_buffer_new_wrapped (data_start, 8);
894 gst_ebml_write_seek (ebml, pos);
895 gst_ebml_write_set_uint (&data_end, num, 8);
897 gst_ebml_write_element_push (ebml, buf, data_start, data_end);
898 gst_ebml_write_seek (ebml, oldpos);
902 * gst_ebml_write_header:
903 * @ebml: #GstEbmlWrite
904 * @doctype: Document type.
905 * @version: Document type version.
910 gst_ebml_write_header (GstEbmlWrite * ebml, const gchar * doctype,
915 /* write the basic EBML header */
916 gst_ebml_write_set_cache (ebml, 0x40);
917 pos = gst_ebml_write_master_start (ebml, GST_EBML_ID_HEADER);
918 #if (GST_EBML_VERSION != 1)
919 gst_ebml_write_uint (ebml, GST_EBML_ID_EBMLVERSION, GST_EBML_VERSION);
920 gst_ebml_write_uint (ebml, GST_EBML_ID_EBMLREADVERSION, GST_EBML_VERSION);
923 /* we don't write these until they're "non-default" (never!) */
924 gst_ebml_write_uint (ebml, GST_EBML_ID_EBMLMAXIDLENGTH, sizeof (guint32));
925 gst_ebml_write_uint (ebml, GST_EBML_ID_EBMLMAXSIZELENGTH, sizeof (guint64));
927 gst_ebml_write_ascii (ebml, GST_EBML_ID_DOCTYPE, doctype);
928 gst_ebml_write_uint (ebml, GST_EBML_ID_DOCTYPEVERSION, version);
929 gst_ebml_write_uint (ebml, GST_EBML_ID_DOCTYPEREADVERSION, version);
930 gst_ebml_write_master_finish (ebml, pos);
931 gst_ebml_write_flush_cache (ebml, FALSE, 0);