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,
219 ebml->streamable ? GST_FORMAT_TIME : GST_FORMAT_BYTES);
220 segment.start = new_pos;
222 segment.position = 0;
224 res = gst_pad_push_event (ebml->srcpad, gst_event_new_segment (&segment));
227 GST_WARNING ("seek to %" G_GUINT64_FORMAT "failed", new_pos);
233 * gst_ebml_write_flush_cache:
234 * @ebml: a #GstEbmlWrite.
235 * @timestamp: timestamp of the buffer.
240 gst_ebml_write_flush_cache (GstEbmlWrite * ebml, gboolean is_keyframe,
241 GstClockTime timestamp)
248 buffer = gst_byte_writer_free_and_get_buffer (ebml->cache);
250 GST_DEBUG ("Flushing cache of size %" G_GSIZE_FORMAT,
251 gst_buffer_get_size (buffer));
252 GST_BUFFER_TIMESTAMP (buffer) = timestamp;
253 GST_BUFFER_OFFSET (buffer) = ebml->pos - gst_buffer_get_size (buffer);
254 GST_BUFFER_OFFSET_END (buffer) = ebml->pos;
255 if (ebml->last_write_result == GST_FLOW_OK) {
256 if (GST_BUFFER_OFFSET (buffer) != ebml->last_pos) {
257 gst_ebml_writer_send_segment_event (ebml, GST_BUFFER_OFFSET (buffer));
258 GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
260 GST_BUFFER_FLAG_UNSET (buffer, GST_BUFFER_FLAG_DISCONT);
262 if (ebml->writing_streamheader) {
263 GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_HEADER);
265 GST_BUFFER_FLAG_UNSET (buffer, GST_BUFFER_FLAG_HEADER);
268 GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT);
270 ebml->last_pos = ebml->pos;
271 ebml->last_write_result = gst_pad_push (ebml->srcpad, buffer);
273 gst_buffer_unref (buffer);
279 * gst_ebml_write_element_new:
280 * @ebml: a #GstEbmlWrite.
281 * @size: size of the requested buffer.
283 * Create a buffer for one element. If there is
284 * a cache, use that instead.
286 * Returns: A new #GstBuffer.
289 gst_ebml_write_element_new (GstEbmlWrite * ebml, GstMapInfo * map, guint size)
291 /* Create new buffer of size + ID + length */
297 buf = gst_buffer_new_and_alloc (size);
298 GST_BUFFER_TIMESTAMP (buf) = ebml->timestamp;
300 /* FIXME unmap not possible */
301 gst_buffer_map (buf, map, GST_MAP_WRITE);
308 * gst_ebml_write_element_id:
309 * @data_inout: Pointer to data pointer
310 * @id: Element ID that should be written.
312 * Write element ID into a buffer.
315 gst_ebml_write_element_id (guint8 ** data_inout, guint32 id)
317 guint8 *data = *data_inout;
318 guint bytes = 4, mask = 0x10;
321 while (!(id & (mask << ((bytes - 1) * 8))) && bytes > 0) {
326 /* if invalid ID, use dummy */
328 GST_WARNING ("Invalid ID, voiding");
330 id = GST_EBML_ID_VOID;
334 *data_inout += bytes;
336 data[bytes] = id & 0xff;
343 * gst_ebml_write_element_size:
344 * @data_inout: Pointer to data pointer
345 * @size: Element length.
347 * Write element length into a buffer.
350 gst_ebml_write_element_size (guint8 ** data_inout, guint64 size)
352 guint8 *data = *data_inout;
353 guint bytes = 1, mask = 0x80;
355 if (size != GST_EBML_SIZE_UNKNOWN) {
356 /* how many bytes? - use mask-1 because an all-1 bitset is not allowed */
357 while (bytes <= 8 && (size >> ((bytes - 1) * 8)) >= (mask - 1)) {
362 /* if invalid size, use max. */
364 GST_WARNING ("Invalid size, writing size unknown");
367 /* Now here's a real FIXME: we cannot read those yet! */
368 size = GST_EBML_SIZE_UNKNOWN;
375 /* write out, BE, with length size marker */
376 *data_inout += bytes;
377 while (bytes-- > 0) {
378 data[bytes] = size & 0xff;
387 * gst_ebml_write_element_data:
388 * @data_inout: Pointer to data pointer
389 * @write: Data that should be written.
390 * @length: Length of the data.
392 * Write element data into a buffer.
395 gst_ebml_write_element_data (guint8 ** data_inout, guint8 * write,
398 memcpy (*data_inout, write, length);
399 *data_inout += length;
404 * gst_ebml_write_element_push:
405 * @ebml: #GstEbmlWrite
406 * @buf: #GstBuffer to be written.
407 * @buf_data: Start of data to push from @buf (or NULL for whole buffer).
408 * @buf_data_end: Data pointer positioned after the last byte in @buf_data (or
409 * NULL for whole buffer).
411 * Write out buffer by moving it to the next element.
414 gst_ebml_write_element_push (GstEbmlWrite * ebml, GstBuffer * buf,
415 guint8 * buf_data, guint8 * buf_data_end)
423 data_size = buf_data_end - buf_data;
425 data_size = gst_buffer_get_size (buf);
427 ebml->pos += data_size;
429 /* if there's no cache, then don't push it! */
430 if (ebml->writing_streamheader) {
432 gst_buffer_map (buf, &map, GST_MAP_READ);
436 GST_WARNING ("Failed to map buffer");
437 else if (!gst_byte_writer_put_data (ebml->streamheader, buf_data,
439 GST_WARNING ("Error writing data to streamheader");
443 gst_buffer_map (buf, &map, GST_MAP_READ);
447 GST_WARNING ("Failed to map buffer");
448 else if (!gst_byte_writer_put_data (ebml->cache, buf_data, data_size))
449 GST_WARNING ("Error writing data to cache");
451 gst_buffer_unmap (buf, &map);
452 gst_buffer_unref (buf);
456 if (buf_data && map.data)
457 gst_buffer_unmap (buf, &map);
459 if (ebml->last_write_result == GST_FLOW_OK) {
460 buf = gst_buffer_make_writable (buf);
461 GST_BUFFER_OFFSET (buf) = ebml->pos - data_size;
462 GST_BUFFER_OFFSET_END (buf) = ebml->pos;
463 if (ebml->writing_streamheader) {
464 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_HEADER);
466 GST_BUFFER_FLAG_UNSET (buf, GST_BUFFER_FLAG_HEADER);
468 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
470 if (GST_BUFFER_OFFSET (buf) != ebml->last_pos) {
471 gst_ebml_writer_send_segment_event (ebml, GST_BUFFER_OFFSET (buf));
472 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
474 GST_BUFFER_FLAG_UNSET (buf, GST_BUFFER_FLAG_DISCONT);
476 ebml->last_pos = ebml->pos;
477 ebml->last_write_result = gst_pad_push (ebml->srcpad, buf);
479 gst_buffer_unref (buf);
485 * gst_ebml_write_seek:
486 * @ebml: #GstEbmlWrite
487 * @pos: Seek position.
492 gst_ebml_write_seek (GstEbmlWrite * ebml, guint64 pos)
494 if (ebml->writing_streamheader) {
495 GST_DEBUG ("wanting to seek to pos %" G_GUINT64_FORMAT, pos);
496 if (pos >= ebml->streamheader_pos &&
497 pos <= ebml->streamheader_pos + ebml->streamheader->parent.size) {
498 gst_byte_writer_set_pos (ebml->streamheader,
499 pos - ebml->streamheader_pos);
500 GST_DEBUG ("seeked in streamheader to position %" G_GUINT64_FORMAT,
501 pos - ebml->streamheader_pos);
504 ("we are writing streamheader still and seek is out of bounds");
507 /* Cache seeking. A bit dangerous, we assume the client writer
508 * knows what he's doing... */
511 if (pos >= ebml->cache_pos &&
512 pos <= ebml->cache_pos + ebml->cache->parent.size) {
513 GST_DEBUG ("seeking in cache to %" G_GUINT64_FORMAT, pos);
515 gst_byte_writer_set_pos (ebml->cache, ebml->pos - ebml->cache_pos);
518 GST_LOG ("Seek outside cache range. Clearing...");
519 gst_ebml_write_flush_cache (ebml, FALSE, GST_CLOCK_TIME_NONE);
523 GST_INFO ("scheduling seek to %" G_GUINT64_FORMAT, pos);
529 * gst_ebml_write_get_uint_size:
530 * @num: Number to be encoded.
532 * Get number of bytes needed to write a uint.
534 * Returns: Encoded uint length.
537 gst_ebml_write_get_uint_size (guint64 num)
542 while (size < 8 && num >= (G_GINT64_CONSTANT (1) << (size * 8))) {
551 * gst_ebml_write_set_uint:
552 * @data_inout: Pointer to data pointer
553 * @num: Number to be written.
554 * @size: Encoded number length.
556 * Write an uint into a buffer.
559 gst_ebml_write_set_uint (guint8 ** data_inout, guint64 num, guint size)
561 guint8 *data = *data_inout;
566 data[size] = num & 0xff;
573 * gst_ebml_write_uint:
574 * @ebml: #GstEbmlWrite
576 * @num: Number to be written.
578 * Write uint element.
581 gst_ebml_write_uint (GstEbmlWrite * ebml, guint32 id, guint64 num)
584 guint8 *data_start, *data_end;
585 guint size = gst_ebml_write_get_uint_size (num);
588 buf = gst_ebml_write_element_new (ebml, &map, sizeof (num));
589 data_end = data_start = map.data;
592 gst_ebml_write_element_id (&data_end, id);
593 gst_ebml_write_element_size (&data_end, size);
594 gst_ebml_write_set_uint (&data_end, num, size);
595 gst_buffer_unmap (buf, &map);
596 gst_buffer_set_size (buf, (data_end - data_start));
598 gst_ebml_write_element_push (ebml, buf, data_start, data_end);
603 * gst_ebml_write_sint:
604 * @ebml: #GstEbmlWrite
606 * @num: Number to be written.
608 * Write sint element.
611 gst_ebml_write_sint (GstEbmlWrite * ebml, guint32 id, gint64 num)
614 guint8 *data_start, *data_end;
617 /* if the signed number is on the edge of a extra-byte,
618 * then we'll fall over when detecting it. Example: if I
619 * have a number (-)0x8000 (G_MINSHORT), then my abs()<<1
620 * will be 0x10000; this is G_MAXUSHORT+1! So: if (<0) -1. */
621 guint64 unum = (num < 0 ? (-num - 1) << 1 : num << 1);
622 guint size = gst_ebml_write_get_uint_size (unum);
624 buf = gst_ebml_write_element_new (ebml, &map, sizeof (num));
625 data_end = data_start = map.data;
631 unum = ((guint64) 0x80) << ((size - 1) * 8);
633 unum |= ((guint64) 0x80) << ((size - 1) * 8);
637 gst_ebml_write_element_id (&data_end, id);
638 gst_ebml_write_element_size (&data_end, size);
639 gst_ebml_write_set_uint (&data_end, unum, size);
640 gst_buffer_unmap (buf, &map);
641 gst_buffer_set_size (buf, (data_end - data_start));
643 gst_ebml_write_element_push (ebml, buf, data_start, data_end);
648 * gst_ebml_write_float:
649 * @ebml: #GstEbmlWrite
651 * @num: Number to be written.
653 * Write float element.
656 gst_ebml_write_float (GstEbmlWrite * ebml, guint32 id, gdouble num)
660 guint8 *data_start, *data_end;
662 buf = gst_ebml_write_element_new (ebml, &map, sizeof (num));
663 data_end = data_start = map.data;
665 gst_ebml_write_element_id (&data_end, id);
666 gst_ebml_write_element_size (&data_end, 8);
667 num = GDOUBLE_TO_BE (num);
668 gst_ebml_write_element_data (&data_end, (guint8 *) & num, 8);
669 gst_buffer_unmap (buf, &map);
670 gst_buffer_set_size (buf, (data_end - data_start));
672 gst_ebml_write_element_push (ebml, buf, data_start, data_end);
677 * gst_ebml_write_ascii:
678 * @ebml: #GstEbmlWrite
680 * @str: String to be written.
682 * Write string element.
685 gst_ebml_write_ascii (GstEbmlWrite * ebml, guint32 id, const gchar * str)
687 gint len = strlen (str) + 1; /* add trailing '\0' */
690 guint8 *data_start, *data_end;
692 buf = gst_ebml_write_element_new (ebml, &map, len);
693 data_end = data_start = map.data;
695 gst_ebml_write_element_id (&data_end, id);
696 gst_ebml_write_element_size (&data_end, len);
697 gst_ebml_write_element_data (&data_end, (guint8 *) str, len);
698 gst_buffer_unmap (buf, &map);
699 gst_buffer_set_size (buf, (data_end - data_start));
701 gst_ebml_write_element_push (ebml, buf, data_start, data_end);
706 * gst_ebml_write_utf8:
707 * @ebml: #GstEbmlWrite
709 * @str: String to be written.
711 * Write utf8 encoded string element.
714 gst_ebml_write_utf8 (GstEbmlWrite * ebml, guint32 id, const gchar * str)
716 gst_ebml_write_ascii (ebml, id, str);
721 * gst_ebml_write_date:
722 * @ebml: #GstEbmlWrite
724 * @date: Date in seconds since the unix epoch.
726 * Write date element.
729 gst_ebml_write_date (GstEbmlWrite * ebml, guint32 id, gint64 date)
731 gst_ebml_write_sint (ebml, id, (date - GST_EBML_DATE_OFFSET) * GST_SECOND);
735 * gst_ebml_write_master_start:
736 * @ebml: #GstEbmlWrite
739 * Start wiriting mater element.
741 * Master writing is annoying. We use a size marker of
742 * the max. allowed length, so that we can later fill it
745 * Returns: Master starting position.
748 gst_ebml_write_master_start (GstEbmlWrite * ebml, guint32 id)
750 guint64 pos = ebml->pos;
753 guint8 *data_start, *data_end;
755 buf = gst_ebml_write_element_new (ebml, &map, 0);
756 data_end = data_start = map.data;
758 gst_ebml_write_element_id (&data_end, id);
759 pos += data_end - data_start;
760 gst_ebml_write_element_size (&data_end, GST_EBML_SIZE_UNKNOWN);
761 gst_buffer_unmap (buf, &map);
762 gst_buffer_set_size (buf, (data_end - data_start));
764 gst_ebml_write_element_push (ebml, buf, data_start, data_end);
771 * gst_ebml_write_master_finish_full:
772 * @ebml: #GstEbmlWrite
773 * @startpos: Master starting position.
775 * Finish writing master element. Size of master element is difference between
776 * current position and the element start, and @extra_size added to this.
779 gst_ebml_write_master_finish_full (GstEbmlWrite * ebml, guint64 startpos,
782 guint64 pos = ebml->pos;
783 guint8 *data = g_malloc (8);
784 GstBuffer *buf = gst_buffer_new_wrapped (data, 8);
786 gst_ebml_write_seek (ebml, startpos);
788 GST_WRITE_UINT64_BE (data,
789 (G_GINT64_CONSTANT (1) << 56) | (pos - startpos - 8 + extra_size));
791 gst_ebml_write_element_push (ebml, buf, NULL, NULL);
792 gst_ebml_write_seek (ebml, pos);
796 gst_ebml_write_master_finish (GstEbmlWrite * ebml, guint64 startpos)
798 gst_ebml_write_master_finish_full (ebml, startpos, 0);
802 * gst_ebml_write_binary:
803 * @ebml: #GstEbmlWrite
805 * @binary: Data to be written.
806 * @length: Length of the data
808 * Write an element with binary data.
811 gst_ebml_write_binary (GstEbmlWrite * ebml,
812 guint32 id, guint8 * binary, guint64 length)
816 guint8 *data_start, *data_end;
818 buf = gst_ebml_write_element_new (ebml, &map, length);
819 data_end = data_start = map.data;
821 gst_ebml_write_element_id (&data_end, id);
822 gst_ebml_write_element_size (&data_end, length);
823 gst_ebml_write_element_data (&data_end, binary, length);
824 gst_buffer_unmap (buf, &map);
825 gst_buffer_set_size (buf, (data_end - data_start));
827 gst_ebml_write_element_push (ebml, buf, data_start, data_end);
832 * gst_ebml_write_buffer_header:
833 * @ebml: #GstEbmlWrite
835 * @length: Length of the data
837 * Write header of the binary element (use with gst_ebml_write_buffer function).
839 * For things like video frames and audio samples,
840 * you want to use this function, as it doesn't have
841 * the overhead of memcpy() that other functions
842 * such as write_binary() do have.
845 gst_ebml_write_buffer_header (GstEbmlWrite * ebml, guint32 id, guint64 length)
849 guint8 *data_start, *data_end;
851 buf = gst_ebml_write_element_new (ebml, &map, 0);
852 data_end = data_start = map.data;
854 gst_ebml_write_element_id (&data_end, id);
855 gst_ebml_write_element_size (&data_end, length);
856 gst_buffer_unmap (buf, &map);
857 gst_buffer_set_size (buf, (data_end - data_start));
859 gst_ebml_write_element_push (ebml, buf, data_start, data_end);
864 * gst_ebml_write_buffer:
865 * @ebml: #GstEbmlWrite
866 * @buf: #GstBuffer cointaining the data.
868 * Write binary element (see gst_ebml_write_buffer_header).
871 gst_ebml_write_buffer (GstEbmlWrite * ebml, GstBuffer * buf)
873 gst_ebml_write_element_push (ebml, buf, NULL, NULL);
878 * gst_ebml_replace_uint:
879 * @ebml: #GstEbmlWrite
880 * @pos: Position of the uint that should be replaced.
883 * Replace uint with a new value.
885 * When replacing a uint, we assume that it is *always*
886 * 8-byte, since that's the safest guess we can do. This
887 * is just for simplicity.
889 * FIXME: this function needs to be replaced with something
890 * proper. This is a crude hack.
893 gst_ebml_replace_uint (GstEbmlWrite * ebml, guint64 pos, guint64 num)
895 guint64 oldpos = ebml->pos;
896 guint8 *data_start, *data_end;
899 data_start = g_malloc (8);
900 data_end = data_start;
901 buf = gst_buffer_new_wrapped (data_start, 8);
903 gst_ebml_write_seek (ebml, pos);
904 gst_ebml_write_set_uint (&data_end, num, 8);
906 gst_ebml_write_element_push (ebml, buf, data_start, data_end);
907 gst_ebml_write_seek (ebml, oldpos);
911 * gst_ebml_write_header:
912 * @ebml: #GstEbmlWrite
913 * @doctype: Document type.
914 * @version: Document type version.
919 gst_ebml_write_header (GstEbmlWrite * ebml, const gchar * doctype,
924 /* write the basic EBML header */
925 gst_ebml_write_set_cache (ebml, 0x40);
926 pos = gst_ebml_write_master_start (ebml, GST_EBML_ID_HEADER);
927 #if (GST_EBML_VERSION != 1)
928 gst_ebml_write_uint (ebml, GST_EBML_ID_EBMLVERSION, GST_EBML_VERSION);
929 gst_ebml_write_uint (ebml, GST_EBML_ID_EBMLREADVERSION, GST_EBML_VERSION);
932 /* we don't write these until they're "non-default" (never!) */
933 gst_ebml_write_uint (ebml, GST_EBML_ID_EBMLMAXIDLENGTH, sizeof (guint32));
934 gst_ebml_write_uint (ebml, GST_EBML_ID_EBMLMAXSIZELENGTH, sizeof (guint64));
936 gst_ebml_write_ascii (ebml, GST_EBML_ID_DOCTYPE, doctype);
937 gst_ebml_write_uint (ebml, GST_EBML_ID_DOCTYPEVERSION, version);
938 gst_ebml_write_uint (ebml, GST_EBML_ID_DOCTYPEREADVERSION, version);
939 gst_ebml_write_master_finish (ebml, pos);
940 gst_ebml_write_flush_cache (ebml, FALSE, 0);