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 #ifndef __MXF_DEMUX_H__
21 #define __MXF_DEMUX_H__
22 
23 #include <gst/gst.h>
24 #include <gst/base/gstadapter.h>
25 #include <gst/base/gstflowcombiner.h>
26 #include <gst/video/video.h>
27 
28 #include "mxfessence.h"
29 
30 G_BEGIN_DECLS
31 
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;
44 
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;
51 
52 typedef struct
53 {
54   MXFPartitionPack partition;
55   MXFPrimerPack primer;
56   gboolean parsed_metadata;
57   guint64 essence_container_offset;
58 } GstMXFDemuxPartition;
59 
60 typedef struct
61 {
62   guint32 body_sid;
63   guint32 index_sid;
64   guint32 track_number;
65 
66   guint32 track_id;
67   MXFUMID source_package_uid;
68 
69   gint64 position;
70   gint64 duration;
71 
72   GArray *offsets;
73 
74   MXFMetadataSourcePackage *source_package;
75   MXFMetadataTimelineTrack *source_track;
76 
77   gpointer mapping_data;
78   const MXFEssenceElementHandler *handler;
79   MXFEssenceElementHandleFunc handle_func;
80 
81   GstTagList *tags;
82 
83   GstCaps *caps;
84   gboolean intra_only;
85 } GstMXFDemuxEssenceTrack;
86 
87 typedef struct
88 {
89   /* 0 if uninitialized */
90   guint64 offset;
91 
92   /* PTS edit unit number or G_MAXUINT64 */
93   guint64 pts;
94 
95   /* DTS edit unit number if we got here via PTS */
96   guint64 dts;
97 
98   gboolean keyframe;
99   gboolean initialized;
100 } GstMXFDemuxIndex;
101 
102 typedef struct
103 {
104   guint32 body_sid;
105   guint32 index_sid;
106 
107   /* offsets indexed by DTS */
108   GArray *offsets;
109 } GstMXFDemuxIndexTable;
110 
111 struct _GstMXFDemuxPad
112 {
113   GstPad parent;
114 
115   guint32 track_id;
116   gboolean need_segment;
117 
118   GstClockTime position;
119   gdouble position_accumulated_error;
120   /* Current position in the material track */
121   gint64 current_material_track_position;
122 
123   gboolean eos, discont;
124 
125   GstTagList *tags;
126 
127   MXFMetadataGenericPackage *material_package;
128   MXFMetadataTimelineTrack *material_track;
129 
130   GstVideoTimeCode start_timecode;
131 
132   guint current_component_index;
133   MXFMetadataSourceClip *current_component;
134 
135   /* Position in the material track where this component started */
136   gint64 current_component_start_position;
137 
138   /* Position/duration in the source track */
139   gint64 current_component_start;
140   gint64 current_component_duration;
141 
142   GstMXFDemuxEssenceTrack *current_essence_track;
143   gint64 current_essence_track_position;
144 };
145 
146 struct _GstMXFDemuxPadClass
147 {
148   GstPadClass parent;
149 };
150 
151 struct _GstMXFDemux
152 {
153   GstElement element;
154 
155   GstPad *sinkpad;
156   GPtrArray *src;
157 
158   /* < private > */
159   gboolean have_group_id;
160   guint group_id;
161 
162   GstAdapter *adapter;
163 
164   GstFlowCombiner *flowcombiner;
165 
166   GstSegment segment;
167   guint32 seqnum;
168 
169   GstEvent *close_seg_event;
170 
171   guint64 offset;
172 
173   gboolean random_access;
174   gboolean flushing;
175 
176   guint64 run_in;
177 
178   guint64 header_partition_pack_offset;
179   guint64 footer_partition_pack_offset;
180 
181   /* MXF file state */
182   GList *partitions;
183   GstMXFDemuxPartition *current_partition;
184 
185   GArray *essence_tracks;
186 
187   GList *pending_index_table_segments;
188   GList *index_tables; /* one per BodySID / IndexSID */
189   gboolean index_table_segments_collected;
190 
191   GArray *random_index_pack;
192 
193   /* Metadata */
194   GRWLock metadata_lock;
195   gboolean update_metadata;
196   gboolean pull_footer_metadata;
197 
198   gboolean metadata_resolved;
199   MXFMetadataPreface *preface;
200   GHashTable *metadata;
201 
202   MXFUMID current_package_uid;
203   MXFMetadataGenericPackage *current_package;
204   gchar *current_package_string;
205 
206   GstTagList *tags;
207 
208   /* Properties */
209   gchar *requested_package_string;
210   GstClockTime max_drift;
211 };
212 
213 struct _GstMXFDemuxClass
214 {
215   GstElementClass parent_class;
216 };
217 
218 GType gst_mxf_demux_get_type (void);
219 
220 G_END_DECLS
221 
222 #endif /* __MXF_DEMUX_H__ */
223