summaryrefslogtreecommitdiff
path: root/subprojects/gst-plugins-good/gst/matroska/ebml-write.h
blob: 08a170e21487e0c428fae5d74a6c2a6f3c994d18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* GStreamer EBML I/O
 * (c) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
 * (c) 2005 Michal Benes <michal.benes@xeris.cz>
 *
 * 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
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifndef __GST_EBML_WRITE_H__
#define __GST_EBML_WRITE_H__

#include <glib.h>
#include <gst/gst.h>
#include <gst/base/gstbytewriter.h>

G_BEGIN_DECLS

#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))
#define GST_IS_EBML_WRITE_CLASS(klass) \
  (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))

typedef struct _GstEbmlWrite {
  GstObject object;

  GstPad *srcpad;
  guint64 pos;
  guint64 last_pos;
  GstClockTime timestamp;

  GstByteWriter *cache;
  guint64 cache_pos;

  GstFlowReturn last_write_result;

  gboolean writing_streamheader;
  GstByteWriter *streamheader;
  guint64 streamheader_pos;

  GstCaps *caps;

  gboolean streamable;
} GstEbmlWrite;

typedef struct _GstEbmlWriteClass {
  GstObjectClass parent;
} GstEbmlWriteClass;

GType   gst_ebml_write_get_type      (void);

GstEbmlWrite *gst_ebml_write_new     (GstPad *srcpad);
void    gst_ebml_write_reset         (GstEbmlWrite *ebml);

GstFlowReturn gst_ebml_last_write_result (GstEbmlWrite *ebml);

/* Used to create streamheaders */
void    gst_ebml_start_streamheader  (GstEbmlWrite *ebml);
GstBuffer*    gst_ebml_stop_streamheader   (GstEbmlWrite *ebml);

/*
 * Caching means that we do not push one buffer for
 * each element, but fill this one until a flush.
 */
void    gst_ebml_write_set_cache     (GstEbmlWrite *ebml,
                                      guint         size);
void    gst_ebml_write_flush_cache   (GstEbmlWrite *ebml,
                                      gboolean is_keyframe,
                                      GstClockTime timestamp);

/*
 * Seeking.
 */
void    gst_ebml_write_seek          (GstEbmlWrite *ebml,
                                      guint64       pos);

/*
 * Data writing.
 */
void    gst_ebml_write_uint          (GstEbmlWrite *ebml,
                                      guint32       id,
                                      guint64       num);
void    gst_ebml_write_sint          (GstEbmlWrite *ebml,
                                      guint32       id,
                                      gint64        num);
void    gst_ebml_write_float         (GstEbmlWrite *ebml,
                                      guint32       id,
                                      gdouble       num);
void    gst_ebml_write_ascii         (GstEbmlWrite *ebml,
                                      guint32       id,
                                      const gchar  *str);
void    gst_ebml_write_utf8          (GstEbmlWrite *ebml,
                                      guint32       id,
                                      const gchar  *str);
void    gst_ebml_write_date          (GstEbmlWrite *ebml,
                                      guint32       id,
                                      gint64        date);
guint64 gst_ebml_write_master_start  (GstEbmlWrite *ebml,
                                      guint32       id);
void    gst_ebml_write_master_finish (GstEbmlWrite *ebml,
                                      guint64       startpos);
void    gst_ebml_write_master_finish_full (GstEbmlWrite * ebml,
                                      guint64 startpos,
                                      guint64 extra_size);
void    gst_ebml_write_binary        (GstEbmlWrite *ebml,
                                      guint32       id,
                                      guchar       *binary,
                                      guint64       length);
void    gst_ebml_write_header        (GstEbmlWrite *ebml,
                                      const gchar  *doctype,
                                      guint         version);

/*
 * Note: this is supposed to be used only for media data.
 */
void    gst_ebml_write_buffer_header (GstEbmlWrite *ebml,
                                      guint32       id,
                                      guint64       length);
void    gst_ebml_write_buffer        (GstEbmlWrite *ebml,
                                      GstBuffer    *data);

/*
 * A hack, basically... See matroska-mux.c. I should actually
 * make a nice _replace_element_with_size() or so, but this
 * works for now.
 */
void    gst_ebml_replace_uint        (GstEbmlWrite *ebml,
                                      guint64       pos,
                                      guint64       num);

G_END_DECLS

#endif /* __GST_EBML_WRITE_H__ */