• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * Copyright (C) 2008-2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 /* Definitions of the basic MXF types, excluding structural metadata */
21 
22 #ifndef __MXF_TYPES_H__
23 #define __MXF_TYPES_H__
24 
25 #include <gst/gst.h>
26 
27 #include "mxful.h"
28 
29 typedef struct {
30   guint8 u[16];
31 } MXFUUID;
32 
33 /* SMPTE 377M 3.2 */
34 typedef struct {
35   guint8 u[32];
36 } MXFUMID;
37 
38 /* SMPTE 377M 3.3 */
39 typedef struct {
40   gint16 year;
41   guint8 month;
42   guint8 day;
43   guint8 hour;
44   guint8 minute;
45   guint8 second;
46   guint16 msecond;
47 } MXFTimestamp;
48 
49 /* SMPTE 377M 3.3 */
50 typedef struct {
51   guint16 major;
52   guint16 minor;
53   guint16 patch;
54   guint16 build;
55   guint16 release;
56 } MXFProductVersion;
57 
58 /* SMPTE 377M 3.3 */
59 typedef struct {
60   gint32 n;
61   gint32 d;
62 } MXFFraction;
63 
64 /* SMPTE 377M 8.3 */
65 typedef struct {
66   MXFUL ul;
67   guint16 size;
68   guint8 *data;
69 
70   gboolean g_slice; /* TRUE if data was allocated by GSlice */
71 } MXFLocalTag;
72 
73 /* SMPTE 377M 11.1 */
74 typedef struct {
75   guint32 body_sid;
76   guint64 offset;
77 } MXFRandomIndexPackEntry;
78 
79 typedef enum {
80   MXF_OP_UNKNOWN = 0,
81   MXF_OP_ATOM,
82   MXF_OP_1a,
83   MXF_OP_1b,
84   MXF_OP_1c,
85   MXF_OP_2a,
86   MXF_OP_2b,
87   MXF_OP_2c,
88   MXF_OP_3a,
89   MXF_OP_3b,
90   MXF_OP_3c,
91 } MXFOperationalPattern;
92 
93 typedef enum {
94   MXF_PARTITION_PACK_HEADER,
95   MXF_PARTITION_PACK_BODY,
96   MXF_PARTITION_PACK_FOOTER
97 } MXFPartitionPackType;
98 
99 /* SMPTE 377M 6.1, Table 1 and 2 */
100 typedef struct {
101   MXFPartitionPackType type;
102 
103   gboolean closed;
104   gboolean complete;
105 
106   guint16 major_version;
107   guint16 minor_version;
108 
109   guint32 kag_size;
110 
111   guint64 this_partition;
112   guint64 prev_partition;
113   guint64 footer_partition;
114 
115   guint64 header_byte_count;
116   guint64 index_byte_count;
117 
118   guint32 index_sid;
119 
120   guint64 body_offset;
121 
122   guint32 body_sid;
123 
124   MXFUL operational_pattern;
125 
126   guint32 n_essence_containers;
127   MXFUL *essence_containers;
128 } MXFPartitionPack;
129 
130 /* SMPTE 377M 8.1 */
131 typedef struct {
132   guint64 offset;
133   GHashTable *mappings;
134   GHashTable *reverse_mappings;
135   guint16 next_free_tag;
136 } MXFPrimerPack;
137 
138 /* SMPTE 377M 10.2.3 */
139 typedef struct {
140   gint8 pos_table_index;
141   guint8 slice;
142   guint32 element_delta;
143 } MXFDeltaEntry;
144 
145 typedef struct {
146   gint8 temporal_offset;
147   gint8 key_frame_offset;
148 
149   guint8 flags;
150   guint64 stream_offset;
151 
152   guint32 *slice_offset;
153   MXFFraction *pos_table;
154 } MXFIndexEntry;
155 
156 typedef struct {
157   MXFUUID instance_id;
158   MXFFraction index_edit_rate;
159   gint64 index_start_position;
160   gint64 index_duration;
161   guint32 edit_unit_byte_count;
162   guint32 index_sid;
163   guint32 body_sid;
164   guint8 slice_count;
165   guint8 pos_table_count;
166 
167   guint32 n_delta_entries;
168   MXFDeltaEntry *delta_entries;
169 
170   guint32 n_index_entries;
171   MXFIndexEntry *index_entries;
172 
173   /* Computed fields (i.e. not present in file) */
174 
175   /* Initial essence offset covered by this segment */
176   guint64 segment_start_offset;
177 } MXFIndexTableSegment;
178 
179 #define GST_TAG_MXF_UMID "mxf-umid"
180 #define GST_TAG_MXF_STRUCTURE "mxf-structure"
181 #define GST_TAG_MXF_DESCRIPTIVE_METADATA_FRAMEWORK "mxf-descriptive-metadata-framework"
182 
183 void mxf_uuid_init (MXFUUID *uuid, GHashTable *hashtable);
184 gboolean mxf_uuid_is_equal (const MXFUUID *a, const MXFUUID *b);
185 gboolean mxf_uuid_is_zero (const MXFUUID *uuid);
186 guint mxf_uuid_hash (const MXFUUID *uuid);
187 gchar * mxf_uuid_to_string (const MXFUUID *uuid, gchar str[48]);
188 MXFUUID * mxf_uuid_from_string (const gchar *str, MXFUUID *uuid);
189 gboolean mxf_uuid_array_parse (MXFUUID ** array, guint32 * count, const guint8 * data, guint size);
190 
191 gchar *mxf_umid_to_string (const MXFUMID * umid, gchar str[96]);
192 MXFUMID *mxf_umid_from_string (const gchar *str, MXFUMID * umid);
193 gboolean mxf_umid_is_equal (const MXFUMID *a, const MXFUMID *b);
194 gboolean mxf_umid_is_zero (const MXFUMID *umid);
195 void mxf_umid_init (MXFUMID *umid);
196 
197 gboolean mxf_is_mxf_packet (const MXFUL *ul);
198 
199 gboolean mxf_is_partition_pack (const MXFUL *ul);
200 gboolean mxf_is_header_partition_pack (const MXFUL *ul);
201 gboolean mxf_is_body_partition_pack (const MXFUL *ul);
202 gboolean mxf_is_footer_partition_pack (const MXFUL *ul);
203 
204 gboolean mxf_is_primer_pack (const MXFUL *ul);
205 
206 gboolean mxf_is_metadata (const MXFUL *ul);
207 gboolean mxf_is_descriptive_metadata (const MXFUL *ul);
208 
209 gboolean mxf_is_random_index_pack (const MXFUL *ul);
210 gboolean mxf_is_index_table_segment (const MXFUL *ul);
211 
212 gboolean mxf_is_generic_container_system_item (const MXFUL *ul);
213 gboolean mxf_is_generic_container_essence_element (const MXFUL *ul);
214 gboolean mxf_is_avid_essence_container_essence_element (const MXFUL * key);
215 
216 gboolean mxf_is_generic_container_essence_container_label (const MXFUL *ul);
217 gboolean mxf_is_avid_essence_container_label (const MXFUL *ul);
218 
219 gboolean mxf_is_fill (const MXFUL *ul);
220 
221 guint mxf_ber_encode_size (guint size, guint8 ber[9]);
222 
223 gchar * mxf_utf16_to_utf8 (const guint8 * data, guint size);
224 guint8 * mxf_utf8_to_utf16 (const gchar *str, guint16 *size);
225 
226 gboolean mxf_product_version_parse (MXFProductVersion * product_version,
227     const guint8 * data, guint size);
228 gboolean mxf_product_version_is_valid (const MXFProductVersion *version);
229 void mxf_product_version_write (const MXFProductVersion *version, guint8 *data);
230 
231 
232 gboolean mxf_fraction_parse (MXFFraction *fraction, const guint8 *data, guint size);
233 gdouble mxf_fraction_to_double (const MXFFraction *fraction);
234 
235 gboolean mxf_timestamp_parse (MXFTimestamp * timestamp, const guint8 * data, guint size);
236 gboolean mxf_timestamp_is_unknown (const MXFTimestamp *a);
237 gint mxf_timestamp_compare (const MXFTimestamp *a, const MXFTimestamp *b);
238 gchar *mxf_timestamp_to_string (const MXFTimestamp *t, gchar str[32]);
239 void mxf_timestamp_set_now (MXFTimestamp *timestamp);
240 void mxf_timestamp_write (const MXFTimestamp *timestamp, guint8 *data);
241 
242 void mxf_op_set_atom (MXFUL *ul, gboolean single_sourceclip, gboolean single_essence_track);
243 void mxf_op_set_generalized (MXFUL *ul, MXFOperationalPattern pattern, gboolean internal_essence, gboolean streamable, gboolean single_track);
244 
245 GstBuffer * mxf_fill_to_buffer (guint size);
246 
247 gboolean mxf_partition_pack_parse (const MXFUL *ul, MXFPartitionPack *pack, const guint8 *data, guint size);
248 void mxf_partition_pack_reset (MXFPartitionPack *pack);
249 GstBuffer * mxf_partition_pack_to_buffer (const MXFPartitionPack *pack);
250 
251 gboolean mxf_primer_pack_parse (const MXFUL *ul, MXFPrimerPack *pack, const guint8 *data, guint size);
252 void mxf_primer_pack_reset (MXFPrimerPack *pack);
253 guint16 mxf_primer_pack_add_mapping (MXFPrimerPack *primer, guint16 local_tag, const MXFUL *ul);
254 GstBuffer * mxf_primer_pack_to_buffer (const MXFPrimerPack *pack);
255 
256 gboolean mxf_random_index_pack_parse (const MXFUL *ul, const guint8 *data, guint size, GArray **array);
257 GstBuffer * mxf_random_index_pack_to_buffer (const GArray *array);
258 
259 gboolean mxf_index_table_segment_parse (const MXFUL *ul, MXFIndexTableSegment *segment, const guint8 *data, guint size);
260 void mxf_index_table_segment_reset (MXFIndexTableSegment *segment);
261 GstBuffer * mxf_index_table_segment_to_buffer (const MXFIndexTableSegment *segment);
262 
263 gboolean mxf_local_tag_parse (const guint8 * data, guint size, guint16 * tag,
264     guint16 * tag_size, const guint8 ** tag_data);
265 void mxf_local_tag_free (MXFLocalTag *tag);
266 
267 gboolean mxf_local_tag_add_to_hash_table (const MXFPrimerPack *primer,
268   guint16 tag, const guint8 *tag_data, guint16 tag_size,
269   GHashTable **hash_table);
270 gboolean mxf_local_tag_insert (MXFLocalTag *tag, GHashTable **hash_table);
271 
272 #endif /* __MXF_TYPES_H__ */
273