1 /* GStreamer EBML I/O 2 * (c) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net> 3 * (c) 2005 Michal Benes <michal.benes@xeris.cz> 4 * 5 * ebml-write.c: write EBML data to file/stream 6 * 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. 11 * 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. 16 * 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. 21 */ 22 23 #ifndef __GST_EBML_WRITE_H__ 24 #define __GST_EBML_WRITE_H__ 25 26 #include <glib.h> 27 #include <gst/gst.h> 28 #include <gst/base/gstbytewriter.h> 29 30 G_BEGIN_DECLS 31 32 #define GST_TYPE_EBML_WRITE \ 33 (gst_ebml_write_get_type ()) 34 #define GST_EBML_WRITE(obj) \ 35 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_EBML_WRITE, GstEbmlWrite)) 36 #define GST_EBML_WRITE_CLASS(klass) \ 37 (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_EBML_WRITE, GstEbmlWriteClass)) 38 #define GST_IS_EBML_WRITE(obj) \ 39 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_EBML_WRITE)) 40 #define GST_IS_EBML_WRITE_CLASS(klass) \ 41 (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_EBML_WRITE)) 42 #define GST_EBML_WRITE_GET_CLASS(obj) \ 43 (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_EBML_WRITE, GstEbmlWriteClass)) 44 45 typedef struct _GstEbmlWrite { 46 GstObject object; 47 48 GstPad *srcpad; 49 guint64 pos; 50 guint64 last_pos; 51 GstClockTime timestamp; 52 53 GstByteWriter *cache; 54 guint64 cache_pos; 55 56 GstFlowReturn last_write_result; 57 58 gboolean writing_streamheader; 59 GstByteWriter *streamheader; 60 guint64 streamheader_pos; 61 62 GstCaps *caps; 63 64 gboolean streamable; 65 } GstEbmlWrite; 66 67 typedef struct _GstEbmlWriteClass { 68 GstObjectClass parent; 69 } GstEbmlWriteClass; 70 71 GType gst_ebml_write_get_type (void); 72 73 GstEbmlWrite *gst_ebml_write_new (GstPad *srcpad); 74 void gst_ebml_write_reset (GstEbmlWrite *ebml); 75 76 GstFlowReturn gst_ebml_last_write_result (GstEbmlWrite *ebml); 77 78 /* Used to create streamheaders */ 79 void gst_ebml_start_streamheader (GstEbmlWrite *ebml); 80 GstBuffer* gst_ebml_stop_streamheader (GstEbmlWrite *ebml); 81 82 /* 83 * Caching means that we do not push one buffer for 84 * each element, but fill this one until a flush. 85 */ 86 void gst_ebml_write_set_cache (GstEbmlWrite *ebml, 87 guint size); 88 void gst_ebml_write_flush_cache (GstEbmlWrite *ebml, 89 gboolean is_keyframe, 90 GstClockTime timestamp); 91 92 /* 93 * Seeking. 94 */ 95 void gst_ebml_write_seek (GstEbmlWrite *ebml, 96 guint64 pos); 97 98 /* 99 * Data writing. 100 */ 101 void gst_ebml_write_uint (GstEbmlWrite *ebml, 102 guint32 id, 103 guint64 num); 104 void gst_ebml_write_sint (GstEbmlWrite *ebml, 105 guint32 id, 106 gint64 num); 107 void gst_ebml_write_float (GstEbmlWrite *ebml, 108 guint32 id, 109 gdouble num); 110 void gst_ebml_write_ascii (GstEbmlWrite *ebml, 111 guint32 id, 112 const gchar *str); 113 void gst_ebml_write_utf8 (GstEbmlWrite *ebml, 114 guint32 id, 115 const gchar *str); 116 void gst_ebml_write_date (GstEbmlWrite *ebml, 117 guint32 id, 118 gint64 date); 119 guint64 gst_ebml_write_master_start (GstEbmlWrite *ebml, 120 guint32 id); 121 void gst_ebml_write_master_finish (GstEbmlWrite *ebml, 122 guint64 startpos); 123 void gst_ebml_write_master_finish_full (GstEbmlWrite * ebml, 124 guint64 startpos, 125 guint64 extra_size); 126 void gst_ebml_write_binary (GstEbmlWrite *ebml, 127 guint32 id, 128 guchar *binary, 129 guint64 length); 130 void gst_ebml_write_header (GstEbmlWrite *ebml, 131 const gchar *doctype, 132 guint version); 133 134 /* 135 * Note: this is supposed to be used only for media data. 136 */ 137 void gst_ebml_write_buffer_header (GstEbmlWrite *ebml, 138 guint32 id, 139 guint64 length); 140 void gst_ebml_write_buffer (GstEbmlWrite *ebml, 141 GstBuffer *data); 142 143 /* 144 * A hack, basically... See matroska-mux.c. I should actually 145 * make a nice _replace_element_with_size() or so, but this 146 * works for now. 147 */ 148 void gst_ebml_replace_uint (GstEbmlWrite *ebml, 149 guint64 pos, 150 guint64 num); 151 152 G_END_DECLS 153 154 #endif /* __GST_EBML_WRITE_H__ */ 155