]> git.sesse.net Git - vlc/blob - modules/access/dcp/dcpparser.h
DCP: Read multiple reels
[vlc] / modules / access / dcp / dcpparser.h
1 /*****************************************************************************
2  * Copyright (C) 2013 VLC authors and VideoLAN
3  *
4  * Authors: Nicolas Bertrand <nico@isf.cc>
5  *          Jean-Baptiste Kempf <jb@videolan.org>
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by
9  * the Free Software Foundation; either version 2.1 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this program; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
20  *****************************************************************************/
21
22 /**
23  * @file dcpparser.h
24  * @brief Parse DCP XML files
25  */
26
27
28 #ifndef _DCPPARSER_H
29 #define _DCPPARSER_H
30
31 #ifdef HAVE_CONFIG_H
32 #include "config.h"
33 #endif
34
35 /* VLC core API headers */
36 #include <vlc_common.h>
37 #include <vlc_demux.h>
38 #include <vlc_plugin.h>
39
40 #include <iostream>
41 #include <string>
42 #include <list>
43 #include <vector>
44
45 using namespace std;
46 typedef enum {
47     TRACK_UNKNOWN = 0,
48     TRACK_PICTURE,
49     TRACK_SOUND,
50     TRACK_SUBTITLE
51 } TrackType_t;
52
53 typedef enum {
54     XML_UNKNOWN = 0,
55     XML_ASSETMAP,
56     XML_CPL,
57     XML_PKL,
58     XML_SUB,
59 } XmlType_t;
60
61
62 class Asset;
63 class AssetList: public std::list<Asset *> {};
64 class PKL;
65
66
67 /* This struct stores useful information about an MXF for demux() */
68 struct info_reel
69 {
70     string filename;
71     int i_entrypoint;
72     int i_duration;
73     int i_correction;       /* entrypoint - sum of previous durations */
74     int i_absolute_end;     /* correction + duration */
75 };
76
77 /* This struct stores the most important information about the DCP */
78 struct dcp_t
79 {
80     string path;                    /* Path to DCP directory */
81
82     vector<PKL *> pkls;
83     AssetList *p_asset_list;
84
85     vector<info_reel> audio_reels;
86     vector<info_reel> video_reels;
87
88     dcp_t():
89         p_asset_list(NULL) {};
90
91     ~dcp_t( ) {
92         vlc_delete_all(pkls);
93         if ( p_asset_list != NULL ) {
94             vlc_delete_all(*p_asset_list);
95             delete(p_asset_list);
96
97         }
98     }
99 };
100
101 class XmlFile
102 {
103 public:
104     XmlFile( demux_t * p_demux, string s_path):
105     p_demux(p_demux), s_path(s_path),
106     p_stream(NULL),
107     p_xml(NULL),
108     p_xmlReader(NULL),
109     type(XML_UNKNOWN) {}
110
111     virtual ~XmlFile( );
112
113     virtual int Parse() = 0;
114
115     bool IsCPL() { return type == XML_CPL; }
116 protected:
117     demux_t      *p_demux;
118     string       s_path;
119     stream_t     *p_stream;
120
121     xml_t        *p_xml;
122     xml_reader_t *p_xmlReader;
123
124     int OpenXml();
125     void CloseXml();
126
127     XmlType_t type;
128 };
129
130 class Chunk {
131 public:
132     Chunk(demux_t * demux):
133         i_vol_index(1), i_offset(0), i_length(0),
134         p_demux(demux) {};
135     int Parse(xml_reader_t *p_xmlReader, string p_node, int p_type);
136     string getPath() { return this->s_path; };
137 private:
138     string s_path;
139     int i_vol_index;
140     int i_offset;
141     int i_length;
142     demux_t      *p_demux;
143 };
144
145 class Asset {
146 public:
147     /* Constructor */
148     Asset (demux_t * demux):
149         b_is_packing_list(false),  ui_size(0),
150         i_intrisic_duration(0), i_entry_point(0), i_duration(0),
151         p_demux(demux) {}
152     virtual ~Asset() ;
153
154     void setId(string p_string ) { this->s_id = p_string; };
155     void setPath(string p_string) { this->s_path = p_string; };
156     void setAnnotation(string p_string) {
157         if (this->s_annotation.empty())
158             this->s_annotation = p_string;
159         else
160             this->s_annotation = this->s_annotation + "--" + p_string;
161     };
162     void setPackingList(bool p_bool) { this->s_path = p_bool; };
163     void setEntryPoint(int i_val) { this->i_entry_point = i_val; };
164     void setDuration (int i_val) { this->i_duration = i_val; };
165     void setIntrinsicDuration (int i_val) { this->i_intrisic_duration = i_val; };
166     string getId() const { return this->s_id; } ;
167     string getPath() const { return this->s_path; };
168     string getType() const { return this->s_type; };
169     string getOriginalFilename() const { return this->s_original_filename; };
170     int getEntryPoint() const { return this->i_entry_point; };
171     int getDuration() const { return this->i_duration; };
172     int getIntrinsicDuration() const { return this->i_intrisic_duration; };
173
174     bool isPackingList() const { return this->b_is_packing_list; };
175
176     int Parse( xml_reader_t *p_xmlReader, string node, int type);
177     int ParsePKL( xml_reader_t *p_xmlReader);
178
179     // TODO: remove
180     void Dump();
181
182 private:
183     string      s_id;
184     string      s_path;
185     string      s_annotation;
186     bool        b_is_packing_list;
187     string      s_hash;
188     uint32_t    ui_size;
189     string      s_type;
190     string      s_original_filename;
191     TrackType_t e_track_type;
192     string      s_edit_rate;
193     int         i_intrisic_duration;
194     int         i_entry_point;
195     int         i_duration;
196     /* encryption attribute */
197     string      s_key_id;
198     /* Picture attributes */
199     string      s_frame_rate;
200     string      s_screen_aspect_ratio;
201     /* sound and subtitle */
202     string      s_language;
203
204     demux_t     *p_demux;
205     std::vector<Chunk> chunk_vec;
206
207
208     int parseChunkList( xml_reader_t *p_xmlReader, string p_node, int p_type);
209
210 };
211
212
213
214 class Reel
215 {
216 public:
217     Reel(demux_t * demux, AssetList *asset_list, xml_reader_t *xmlReader)
218         : p_asset_list(asset_list), p_xmlReader(xmlReader), p_demux(demux)
219          {};
220     int Parse(string p_node, int p_type);
221     Asset * getTrack(TrackType_t e_track);
222
223 private:
224     AssetList *p_asset_list;
225     xml_reader_t *p_xmlReader;
226     demux_t      *p_demux;
227
228     string s_id;
229     string s_annotation;
230     Asset  *p_picture_track;
231     Asset  *p_sound_track;
232     Asset  *p_subtitle_track;
233
234     int ParseAssetList(string p_node, int p_type);
235     int ParseAsset(string p_node, int p_type, TrackType_t e_track);
236 };
237
238 class CPL : public XmlFile
239 {
240 public:
241     CPL(demux_t *, string, AssetList*);
242     ~CPL();
243     virtual int Parse();
244
245     Reel *getReel(int pos) { return this->vec_reel[pos]; } ;
246     std::vector<Reel *> getReelList() { return this->vec_reel; } ;
247
248 private :
249     AssetList *asset_list;
250
251     string s_id;
252     string s_annotation;
253     string s_icon_id;
254     string s_issue_date;
255     string s_issuer;
256     string s_creator;
257     string s_content_title;
258     string s_content_kind;
259     /* TODO:  ContentVersion, RatingList, signer and signature */
260
261     std::vector<Reel *>   vec_reel;
262     int DummyParse(string p_node, int p_type);
263     int ParseReelList(string p_node, int p_type);
264 };
265
266
267 class PKL : public XmlFile
268 {
269 public:
270     PKL ( demux_t * p_demux, string s_path, AssetList *asset_list,
271          string s_dcp_path);
272     ~PKL();
273     virtual int Parse();
274
275     int FindCPLs();
276     CPL *getCPL(int pos) { return this->vec_cpl[pos]; };
277
278 private:
279     AssetList *asset_list;
280
281     string s_id;
282     string s_annotation;
283     string s_issue_date;
284     string s_issuer;
285     string s_creator;
286     string s_icon_id;
287     string s_group_id;
288     string s_dcp_path;
289     std::vector<CPL *> vec_cpl;
290
291     int ParseAssetList(string p_node, int p_type);
292     int ParseAsset(string p_node, int p_type);
293     int ParseSigner(string p_node, int p_type);
294     int ParseSignature(string p_node, int p_type);
295
296 };
297
298 class AssetMap : public XmlFile {
299
300 public:
301     AssetMap( demux_t * p_demux, string s_path, dcp_t *_p_dcp)
302         : XmlFile( p_demux, s_path ), p_dcp( _p_dcp) {};
303     ~AssetMap();
304
305     static Asset * getAssetById(AssetList*, const string p_id);
306
307     virtual int Parse();
308 private:
309     dcp_t *p_dcp;
310
311     int ParseAssetList (xml_reader_t *p_xmlReader, const string p_node, int p_type);
312 };
313 #endif /* _DCPPARSER_H */