2 * Copyright (C) 2008-2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
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.
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.
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.
20 #ifndef __MXF_DEMUX_H__
21 #define __MXF_DEMUX_H__
24 #include <gst/base/gstadapter.h>
25 #include <gst/base/gstflowcombiner.h>
26 #include <gst/video/video.h>
28 #include "mxfessence.h"
32 #define GST_TYPE_MXF_DEMUX \
33 (gst_mxf_demux_get_type())
34 #define GST_MXF_DEMUX(obj) \
35 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MXF_DEMUX,GstMXFDemux))
36 #define GST_MXF_DEMUX_CLASS(klass) \
37 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MXF_DEMUX,GstMXFDemuxClass))
38 #define GST_IS_MXF_DEMUX(obj) \
39 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MXF_DEMUX))
40 #define GST_IS_MXF_DEMUX_CLASS(klass) \
41 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MXF_DEMUX))
42 typedef struct _GstMXFDemux GstMXFDemux;
43 typedef struct _GstMXFDemuxClass GstMXFDemuxClass;
45 #define GST_TYPE_MXF_DEMUX_PAD (gst_mxf_demux_pad_get_type())
46 #define GST_MXF_DEMUX_PAD(pad) (G_TYPE_CHECK_INSTANCE_CAST((pad),GST_TYPE_MXF_DEMUX_PAD,GstMXFDemuxPad))
47 #define GST_MXF_DEMUX_PAD_CAST(pad) ((GstMXFDemuxPad *) pad)
48 #define GST_IS_MXF_DEMUX_PAD(pad) (G_TYPE_CHECK_INSTANCE_TYPE((pad),GST_TYPE_MXF_DEMUX_PAD))
49 typedef struct _GstMXFDemuxPad GstMXFDemuxPad;
50 typedef struct _GstMXFDemuxPadClass GstMXFDemuxPadClass;
54 * GstMXFKLV is used to pass around information about a KLV.
56 * It optionally contains the content of the klv (data field).
60 guint64 offset; /* absolute offset of K */
61 gsize length; /* Size of data (i.e. V) */
62 guint64 data_offset; /* relative offset of data (i.e. size of 'KL') */
63 GstBuffer *data; /* Can be NULL in pull-mode. */
65 /* For partial reads (ex: clip/custom wrapping essence), the amount of data
66 * already consumed within. If 0, all of length+data_offset was consumed */
72 GST_MXF_DEMUX_STATE_UNKNOWN, /* Still looking for run-in/klv */
73 GST_MXF_DEMUX_STATE_KLV, /* Next read/fetch is a KLV */
74 GST_MXF_DEMUX_STATE_ESSENCE /* Next read/fetch is within a KLV (i.e. non-frame-wrapped) */
77 typedef struct _GstMXFDemuxPartition GstMXFDemuxPartition;
78 typedef struct _GstMXFDemuxEssenceTrack GstMXFDemuxEssenceTrack;
80 struct _GstMXFDemuxPartition
82 MXFPartitionPack partition;
84 gboolean parsed_metadata;
86 /* Relative offset at which essence starts within this partition.
88 * For Frame wrapping, the position of the first KLV
89 * For Clip/Custom wrapping, the position of the first byte of essence in the KLV
91 guint64 essence_container_offset;
93 /* If the partition contains a single essence track, point to it */
94 GstMXFDemuxEssenceTrack *single_track;
96 /* For clip-based wrapping, the essence KLV */
100 #define MXF_INDEX_DELTA_ID_UNKNOWN -1
101 #define MXF_INDEX_DELTA_ID_IGNORE -2
103 struct _GstMXFDemuxEssenceTrack
107 guint32 track_number;
109 /* delta id, the position of this track in the container package delta table
110 * (if the track is in an interleaved essence container)
113 * * -1 Not discovered yet
114 * * -2 Ignore delta entry (if index table is not present or not complete)
119 MXFUMID source_package_uid;
121 /* Position and duration in edit units */
127 MXFMetadataSourcePackage *source_package;
128 MXFMetadataTimelineTrack *source_track;
130 gpointer mapping_data;
131 const MXFEssenceElementHandler *handler;
132 MXFEssenceElementHandleFunc handle_func;
139 MXFEssenceWrapping wrapping;
141 /* Minimum number of edit unit to send in one go.
143 * Used for raw audio track */
144 guint min_edit_units;
149 /* absolute byte offset excluding run_in, 0 if uninitialized */
152 /* PTS edit unit number or G_MAXUINT64 */
155 /* DTS edit unit number if we got here via PTS */
158 /* Duration in edit units */
162 gboolean initialized;
164 /* Size, used for non-frame-wrapped content */
173 /* Array of MXFIndexTableSegment, sorted by DTS
174 * Note: Can be empty and can be sparse (i.e. not cover every edit unit) */
177 /* Delta entry to which reordering should be applied (-1 == no reordering) */
178 gint reordered_delta_entry;
180 /* Array of gint8 reverse temporal offsets.
181 * Contains the shift to apply to an entry DTS to get the PTS
183 * Can be NULL if the content doesn't have temporal shifts (i.e. all present
184 * entries have a temporal offset of 0) */
185 GArray *reverse_temporal_offsets;
187 /* Greatest temporal offset value contained within offsets.
188 * Unsigned because the smallest value is 0 (no reordering) */
189 guint max_temporal_offset;
190 } GstMXFDemuxIndexTable;
192 struct _GstMXFDemuxPad
197 gboolean need_segment;
199 GstClockTime position;
200 gdouble position_accumulated_error;
201 /* Current position in the material track (in edit units) */
202 gint64 current_material_track_position;
204 gboolean eos, discont;
208 MXFMetadataGenericPackage *material_package;
209 MXFMetadataTimelineTrack *material_track;
211 GstVideoTimeCode start_timecode;
213 guint current_component_index;
214 MXFMetadataSourceClip *current_component;
216 /* Position in the material track where this component started */
217 gint64 current_component_start_position;
219 /* Position/duration in the source track */
220 gint64 current_component_start;
221 gint64 current_component_duration;
223 /* Current essence track and position (in edit units) */
224 GstMXFDemuxEssenceTrack *current_essence_track;
225 gint64 current_essence_track_position;
228 struct _GstMXFDemuxPadClass
241 GstMXFDemuxState state;
243 gboolean have_group_id;
248 GstFlowCombiner *flowcombiner;
253 GstEvent *close_seg_event;
257 gboolean random_access;
262 guint64 header_partition_pack_offset;
263 guint64 footer_partition_pack_offset;
267 GstMXFDemuxPartition *current_partition;
269 GPtrArray *essence_tracks;
271 GList *pending_index_table_segments;
272 GList *index_tables; /* one per BodySID / IndexSID */
273 gboolean index_table_segments_collected;
275 GArray *random_index_pack;
278 GRWLock metadata_lock;
279 gboolean update_metadata;
280 gboolean pull_footer_metadata;
282 gboolean metadata_resolved;
283 MXFMetadataPreface *preface;
284 GHashTable *metadata;
286 /* Current Material Package */
287 MXFUMID current_package_uid;
288 MXFMetadataGenericPackage *current_package;
289 gchar *current_package_string;
294 gchar *requested_package_string;
295 GstClockTime max_drift;
298 gboolean temporal_order_misuse;
301 struct _GstMXFDemuxClass
303 GstElementClass parent_class;
306 GType gst_mxf_demux_get_type (void);
310 #endif /* __MXF_DEMUX_H__ */