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 } MXFIndexTableSegment;
173 
174 #define GST_TAG_MXF_UMID "mxf-umid"
175 #define GST_TAG_MXF_STRUCTURE "mxf-structure"
176 #define GST_TAG_MXF_DESCRIPTIVE_METADATA_FRAMEWORK "mxf-descriptive-metadata-framework"
177 
178 void mxf_uuid_init (MXFUUID *uuid, GHashTable *hashtable);
179 gboolean mxf_uuid_is_equal (const MXFUUID *a, const MXFUUID *b);
180 gboolean mxf_uuid_is_zero (const MXFUUID *uuid);
181 guint mxf_uuid_hash (const MXFUUID *uuid);
182 gchar * mxf_uuid_to_string (const MXFUUID *uuid, gchar str[48]);
183 MXFUUID * mxf_uuid_from_string (const gchar *str, MXFUUID *uuid);
184 gboolean mxf_uuid_array_parse (MXFUUID ** array, guint32 * count, const guint8 * data, guint size);
185 
186 gchar *mxf_umid_to_string (const MXFUMID * umid, gchar str[96]);
187 MXFUMID *mxf_umid_from_string (const gchar *str, MXFUMID * umid);
188 gboolean mxf_umid_is_equal (const MXFUMID *a, const MXFUMID *b);
189 gboolean mxf_umid_is_zero (const MXFUMID *umid);
190 void mxf_umid_init (MXFUMID *umid);
191 
192 gboolean mxf_is_mxf_packet (const MXFUL *ul);
193 
194 gboolean mxf_is_partition_pack (const MXFUL *ul);
195 gboolean mxf_is_header_partition_pack (const MXFUL *ul);
196 gboolean mxf_is_body_partition_pack (const MXFUL *ul);
197 gboolean mxf_is_footer_partition_pack (const MXFUL *ul);
198 
199 gboolean mxf_is_primer_pack (const MXFUL *ul);
200 
201 gboolean mxf_is_metadata (const MXFUL *ul);
202 gboolean mxf_is_descriptive_metadata (const MXFUL *ul);
203 
204 gboolean mxf_is_random_index_pack (const MXFUL *ul);
205 gboolean mxf_is_index_table_segment (const MXFUL *ul);
206 
207 gboolean mxf_is_generic_container_system_item (const MXFUL *ul);
208 gboolean mxf_is_generic_container_essence_element (const MXFUL *ul);
209 gboolean mxf_is_avid_essence_container_essence_element (const MXFUL * key);
210 
211 gboolean mxf_is_generic_container_essence_container_label (const MXFUL *ul);
212 gboolean mxf_is_avid_essence_container_label (const MXFUL *ul);
213 
214 gboolean mxf_is_fill (const MXFUL *ul);
215 
216 guint mxf_ber_encode_size (guint size, guint8 ber[9]);
217 
218 gchar * mxf_utf16_to_utf8 (const guint8 * data, guint size);
219 guint8 * mxf_utf8_to_utf16 (const gchar *str, guint16 *size);
220 
221 gboolean mxf_product_version_parse (MXFProductVersion * product_version,
222     const guint8 * data, guint size);
223 gboolean mxf_product_version_is_valid (const MXFProductVersion *version);
224 void mxf_product_version_write (const MXFProductVersion *version, guint8 *data);
225 
226 
227 gboolean mxf_fraction_parse (MXFFraction *fraction, const guint8 *data, guint size);
228 gdouble mxf_fraction_to_double (const MXFFraction *fraction);
229 
230 gboolean mxf_timestamp_parse (MXFTimestamp * timestamp, const guint8 * data, guint size);
231 gboolean mxf_timestamp_is_unknown (const MXFTimestamp *a);
232 gint mxf_timestamp_compare (const MXFTimestamp *a, const MXFTimestamp *b);
233 gchar *mxf_timestamp_to_string (const MXFTimestamp *t, gchar str[32]);
234 void mxf_timestamp_set_now (MXFTimestamp *timestamp);
235 void mxf_timestamp_write (const MXFTimestamp *timestamp, guint8 *data);
236 
237 void mxf_op_set_atom (MXFUL *ul, gboolean single_sourceclip, gboolean single_essence_track);
238 void mxf_op_set_generalized (MXFUL *ul, MXFOperationalPattern pattern, gboolean internal_essence, gboolean streamable, gboolean single_track);
239 
240 GstBuffer * mxf_fill_to_buffer (guint size);
241 
242 gboolean mxf_partition_pack_parse (const MXFUL *ul, MXFPartitionPack *pack, const guint8 *data, guint size);
243 void mxf_partition_pack_reset (MXFPartitionPack *pack);
244 GstBuffer * mxf_partition_pack_to_buffer (const MXFPartitionPack *pack);
245 
246 gboolean mxf_primer_pack_parse (const MXFUL *ul, MXFPrimerPack *pack, const guint8 *data, guint size);
247 void mxf_primer_pack_reset (MXFPrimerPack *pack);
248 guint16 mxf_primer_pack_add_mapping (MXFPrimerPack *primer, guint16 local_tag, const MXFUL *ul);
249 GstBuffer * mxf_primer_pack_to_buffer (const MXFPrimerPack *pack);
250 
251 gboolean mxf_random_index_pack_parse (const MXFUL *ul, const guint8 *data, guint size, GArray **array);
252 GstBuffer * mxf_random_index_pack_to_buffer (const GArray *array);
253 
254 gboolean mxf_index_table_segment_parse (const MXFUL *ul, MXFIndexTableSegment *segment, const guint8 *data, guint size);
255 void mxf_index_table_segment_reset (MXFIndexTableSegment *segment);
256 GstBuffer * mxf_index_table_segment_to_buffer (const MXFIndexTableSegment *segment);
257 
258 gboolean mxf_local_tag_parse (const guint8 * data, guint size, guint16 * tag,
259     guint16 * tag_size, const guint8 ** tag_data);
260 void mxf_local_tag_free (MXFLocalTag *tag);
261 
262 gboolean mxf_local_tag_add_to_hash_table (const MXFPrimerPack *primer,
263   guint16 tag, const guint8 *tag_data, guint16 tag_size,
264   GHashTable **hash_table);
265 gboolean mxf_local_tag_insert (MXFLocalTag *tag, GHashTable **hash_table);
266 
267 #endif /* __MXF_TYPES_H__ */
268