2 Copyright (C) 2014 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/reel_picture_asset.h
21 * @brief ReelPictureAsset class.
25 #include "reel_picture_asset.h"
26 #include "picture_mxf.h"
27 #include "compose.hpp"
28 #include <libcxml/cxml.h>
32 using std::stringstream;
33 using boost::shared_ptr;
36 ReelPictureAsset::ReelPictureAsset ()
37 : _frame_rate (Fraction (24, 1))
38 , _screen_aspect_ratio (Fraction (1998, 1080))
43 ReelPictureAsset::ReelPictureAsset (boost::shared_ptr<PictureMXF> content, int64_t entry_point)
44 : ReelAsset (content, entry_point)
45 , _frame_rate (content->frame_rate ())
46 , _screen_aspect_ratio (content->screen_aspect_ratio ())
51 ReelPictureAsset::ReelPictureAsset (boost::shared_ptr<const cxml::Node> node)
54 _frame_rate = Fraction (node->string_child ("FrameRate"));
56 _screen_aspect_ratio = Fraction (node->string_child ("ScreenAspectRatio"));
57 } catch (XMLError& e) {
58 /* Maybe it's not a fraction */
61 float f = node->number_child<float> ("ScreenAspectRatio");
62 _screen_aspect_ratio = Fraction (f * 1000, 1000);
63 } catch (bad_cast& e) {
69 ReelPictureAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const
71 ReelAsset::write_to_cpl (node, standard);
73 xmlpp::Node::NodeList c = node->get_children ();
74 xmlpp::Node::NodeList::iterator i = c.begin();
75 while (i != c.end() && (*i)->get_name() != cpl_node_name ()) {
79 assert (i != c.end ());
81 (*i)->add_child ("FrameRate")->add_child_text (String::compose ("%1 %2", _frame_rate.numerator, _frame_rate.denominator));
82 if (standard == INTEROP) {
84 s << std::fixed << std::setprecision (2) << (float (_screen_aspect_ratio.numerator) / _screen_aspect_ratio.denominator);
85 (*i)->add_child ("ScreenAspectRatio")->add_child_text (s.str ());
87 (*i)->add_child ("ScreenAspectRatio")->add_child_text (
88 String::compose ("%1 %2", _screen_aspect_ratio.numerator, _screen_aspect_ratio.denominator)