ebml-write.h 5.53 KB
Newer Older
1 2
/* GStreamer EBML I/O
 * (c) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
3
 * (c) 2005 Michal Benes <michal.benes@xeris.cz>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * ebml-write.c: write EBML data to file/stream
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
Tim-Philipp Müller's avatar
Tim-Philipp Müller committed
19 20
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
21 22 23 24 25 26 27
 */

#ifndef __GST_EBML_WRITE_H__
#define __GST_EBML_WRITE_H__

#include <glib.h>
#include <gst/gst.h>
28
#include <gst/base/gstbytewriter.h>
29 30

G_BEGIN_DECLS
Johan Dahlin's avatar
Johan Dahlin committed
31

32 33 34 35 36 37 38 39
#define GST_TYPE_EBML_WRITE \
  (gst_ebml_write_get_type ())
#define GST_EBML_WRITE(obj) \
  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_EBML_WRITE, GstEbmlWrite))
#define GST_EBML_WRITE_CLASS(klass) \
  (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_EBML_WRITE, GstEbmlWriteClass))
#define GST_IS_EBML_WRITE(obj) \
  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_EBML_WRITE))
Stefan Kost's avatar
Stefan Kost committed
40
#define GST_IS_EBML_WRITE_CLASS(klass) \
41 42 43
  (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_EBML_WRITE))
#define GST_EBML_WRITE_GET_CLASS(obj) \
  (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_EBML_WRITE, GstEbmlWriteClass))
Johan Dahlin's avatar
Johan Dahlin committed
44 45

typedef struct _GstEbmlWrite {
46
  GstObject object;
47 48 49

  GstPad *srcpad;
  guint64 pos;
50
  guint64 last_pos;
51
  GstClockTime timestamp;
52

53 54
  GstByteWriter *cache;
  guint64 cache_pos;
55 56 57

  GstFlowReturn last_write_result;

58 59 60
  gboolean writing_streamheader;
  GstByteWriter *streamheader;
  guint64 streamheader_pos;
61 62

  GstCaps *caps;
63 64

  gboolean streamable;
65 66
} GstEbmlWrite;

Johan Dahlin's avatar
Johan Dahlin committed
67
typedef struct _GstEbmlWriteClass {
68
  GstObjectClass parent;
69 70
} GstEbmlWriteClass;

Johan Dahlin's avatar
Johan Dahlin committed
71
GType   gst_ebml_write_get_type      (void);
72

73 74 75 76 77
GstEbmlWrite *gst_ebml_write_new     (GstPad *srcpad);
void    gst_ebml_write_reset         (GstEbmlWrite *ebml);

GstFlowReturn gst_ebml_last_write_result (GstEbmlWrite *ebml);

78 79 80 81
/* Used to create streamheaders */
void    gst_ebml_start_streamheader  (GstEbmlWrite *ebml);
GstBuffer*    gst_ebml_stop_streamheader   (GstEbmlWrite *ebml);

82 83 84 85
/*
 * Caching means that we do not push one buffer for
 * each element, but fill this one until a flush.
 */
Johan Dahlin's avatar
Johan Dahlin committed
86
void    gst_ebml_write_set_cache     (GstEbmlWrite *ebml,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
87
                                      guint         size);
88
void    gst_ebml_write_flush_cache   (GstEbmlWrite *ebml,
89 90
                                      gboolean is_keyframe,
                                      GstClockTime timestamp);
91 92 93 94

/*
 * Seeking.
 */
Johan Dahlin's avatar
Johan Dahlin committed
95
void    gst_ebml_write_seek          (GstEbmlWrite *ebml,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
96
                                      guint64       pos);
97 98 99 100

/*
 * Data writing. 
 */
Johan Dahlin's avatar
Johan Dahlin committed
101
void    gst_ebml_write_uint          (GstEbmlWrite *ebml,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
102 103
                                      guint32       id,
                                      guint64       num);
Johan Dahlin's avatar
Johan Dahlin committed
104
void    gst_ebml_write_sint          (GstEbmlWrite *ebml,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
105 106
                                      guint32       id,
                                      gint64        num);
Johan Dahlin's avatar
Johan Dahlin committed
107
void    gst_ebml_write_float         (GstEbmlWrite *ebml,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
108 109
                                      guint32       id,
                                      gdouble       num);
Johan Dahlin's avatar
Johan Dahlin committed
110
void    gst_ebml_write_ascii         (GstEbmlWrite *ebml,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
111 112
                                      guint32       id,
                                      const gchar  *str);
Johan Dahlin's avatar
Johan Dahlin committed
113
void    gst_ebml_write_utf8          (GstEbmlWrite *ebml,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
114 115
                                      guint32       id,
                                      const gchar  *str);
Johan Dahlin's avatar
Johan Dahlin committed
116
void    gst_ebml_write_date          (GstEbmlWrite *ebml,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
117 118
                                      guint32       id,
                                      gint64        date);
Johan Dahlin's avatar
Johan Dahlin committed
119
guint64 gst_ebml_write_master_start  (GstEbmlWrite *ebml,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
120
                                      guint32       id);
Johan Dahlin's avatar
Johan Dahlin committed
121
void    gst_ebml_write_master_finish (GstEbmlWrite *ebml,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
122
                                      guint64       startpos);
123 124 125
void    gst_ebml_write_master_finish_full (GstEbmlWrite * ebml,
                                      guint64 startpos,
                                      guint64 extra_size);
Johan Dahlin's avatar
Johan Dahlin committed
126
void    gst_ebml_write_binary        (GstEbmlWrite *ebml,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
127 128 129
                                      guint32       id,
                                      guchar       *binary,
                                      guint64       length);
Johan Dahlin's avatar
Johan Dahlin committed
130
void    gst_ebml_write_header        (GstEbmlWrite *ebml,
131
                                      const gchar  *doctype,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
132
                                      guint         version);
133 134 135 136

/*
 * Note: this is supposed to be used only for media data.
 */
Johan Dahlin's avatar
Johan Dahlin committed
137
void    gst_ebml_write_buffer_header (GstEbmlWrite *ebml,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
138 139
                                      guint32       id,
                                      guint64       length);
Johan Dahlin's avatar
Johan Dahlin committed
140
void    gst_ebml_write_buffer        (GstEbmlWrite *ebml,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
141
                                      GstBuffer    *data);
142 143 144 145 146 147

/*
 * A hack, basically... See matroska-mux.c. I should actually
 * make a nice _replace_element_with_size() or so, but this
 * works for now.
 */
Johan Dahlin's avatar
Johan Dahlin committed
148
void    gst_ebml_replace_uint        (GstEbmlWrite *ebml,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
149 150
                                      guint64       pos,
                                      guint64       num);
151 152

G_END_DECLS
Johan Dahlin's avatar
Johan Dahlin committed
153

154
#endif /* __GST_EBML_WRITE_H__ */