2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program 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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /** @file src/cpl_file.cc
21 * @brief Classes used to parse a CPL.
31 using boost::shared_ptr;
32 using namespace dcp::parse;
34 CPL::CPL (string file)
36 cxml::Document f ("CompositionPlaylist");
39 id = f.string_child ("Id");
40 annotation_text = f.optional_string_child ("AnnotationText").get_value_or ("");
41 issue_date = f.string_child ("IssueDate");
42 creator = f.optional_string_child ("Creator").get_value_or ("");
43 content_title_text = f.string_child ("ContentTitleText");
44 content_kind = content_kind_from_string (f.string_child ("ContentKind"));
45 content_version = optional_type_child<ContentVersion> (f, "ContentVersion");
46 f.ignore_child ("RatingList");
47 reels = type_grand_children<Reel> (f, "ReelList", "Reel");
49 f.ignore_child ("Issuer");
50 f.ignore_child ("Signer");
51 f.ignore_child ("Signature");
56 ContentVersion::ContentVersion (shared_ptr<const cxml::Node> node)
58 id = node->optional_string_child ("Id").get_value_or ("");
59 label_text = node->string_child ("LabelText");
63 Reel::Reel (shared_ptr<const cxml::Node> node)
65 id = node->string_child ("Id");
66 asset_list = type_child<CPLAssetList> (node, "AssetList");
68 node->ignore_child ("AnnotationText");
72 CPLAssetList::CPLAssetList (shared_ptr<const cxml::Node> node)
74 main_picture = optional_type_child<MainPicture> (node, "MainPicture");
75 main_stereoscopic_picture = optional_type_child<MainStereoscopicPicture> (node, "MainStereoscopicPicture");
76 main_sound = optional_type_child<MainSound> (node, "MainSound");
77 main_subtitle = optional_type_child<MainSubtitle> (node, "MainSubtitle");
82 MainPicture::MainPicture (shared_ptr<const cxml::Node> node)
88 MainStereoscopicPicture::MainStereoscopicPicture (shared_ptr<const cxml::Node> node)
94 Picture::Picture (shared_ptr<const cxml::Node> node)
96 id = node->string_child ("Id");
97 annotation_text = node->optional_string_child ("AnnotationText").get_value_or ("");
98 edit_rate = Fraction (node->string_child ("EditRate"));
99 intrinsic_duration = node->number_child<int64_t> ("IntrinsicDuration");
100 entry_point = node->number_child<int64_t> ("EntryPoint");
101 duration = node->number_child<int64_t> ("Duration");
102 frame_rate = Fraction (node->string_child ("FrameRate"));
104 screen_aspect_ratio = Fraction (node->string_child ("ScreenAspectRatio"));
105 } catch (XMLError& e) {
106 /* Maybe it's not a fraction */
109 float f = node->number_child<float> ("ScreenAspectRatio");
110 screen_aspect_ratio = Fraction (f * 1000, 1000);
111 } catch (bad_cast& e) {
115 key_id = node->optional_string_child ("KeyId").get_value_or ("");
117 node->ignore_child ("Hash");
122 MainSound::MainSound (shared_ptr<const cxml::Node> node)
124 id = node->string_child ("Id");
125 annotation_text = node->optional_string_child ("AnnotationText").get_value_or ("");
126 edit_rate = Fraction (node->string_child ("EditRate"));
127 intrinsic_duration = node->number_child<int64_t> ("IntrinsicDuration");
128 entry_point = node->number_child<int64_t> ("EntryPoint");
129 duration = node->number_child<int64_t> ("Duration");
130 key_id = node->optional_string_child ("KeyId").get_value_or ("");
132 node->ignore_child ("Hash");
133 node->ignore_child ("Language");
138 MainSubtitle::MainSubtitle (shared_ptr<const cxml::Node> node)
140 id = node->string_child ("Id");
141 annotation_text = node->optional_string_child ("AnnotationText").get_value_or ("");
142 edit_rate = Fraction (node->string_child ("EditRate"));
143 intrinsic_duration = node->number_child<int64_t> ("IntrinsicDuration");
144 entry_point = node->number_child<int64_t> ("EntryPoint");
145 duration = node->number_child<int64_t> ("Duration");
147 node->ignore_child ("Hash");
148 node->ignore_child ("Language");