#include "film.h"
#include "exceptions.h"
#include "frame_rate_change.h"
+#include "safe_stringstream.h"
#include "i18n.h"
int const VideoContentProperty::COLOUR_CONVERSION = 5;
using std::string;
-using std::stringstream;
using std::setprecision;
using std::cout;
using std::vector;
using boost::dynamic_pointer_cast;
using libdcp::raw_convert;
-vector<VideoContentScale> VideoContentScale::_scales;
-
VideoContent::VideoContent (shared_ptr<const Film> f)
: Content (f)
, _video_length (0)
+ , _original_video_frame_rate (0)
, _video_frame_rate (0)
, _video_frame_type (VIDEO_FRAME_TYPE_2D)
- , _scale (Ratio::from_id ("185"))
+ , _scale (Config::instance()->default_scale ())
{
- setup_default_colour_conversion ();
+ set_default_colour_conversion ();
}
VideoContent::VideoContent (shared_ptr<const Film> f, Time s, VideoContent::Frame len)
: Content (f, s)
, _video_length (len)
+ , _original_video_frame_rate (0)
, _video_frame_rate (0)
, _video_frame_type (VIDEO_FRAME_TYPE_2D)
- , _scale (Ratio::from_id ("185"))
+ , _scale (Config::instance()->default_scale ())
{
- setup_default_colour_conversion ();
+ set_default_colour_conversion ();
}
VideoContent::VideoContent (shared_ptr<const Film> f, boost::filesystem::path p)
: Content (f, p)
, _video_length (0)
+ , _original_video_frame_rate (0)
, _video_frame_rate (0)
, _video_frame_type (VIDEO_FRAME_TYPE_2D)
- , _scale (Ratio::from_id ("185"))
+ , _scale (Config::instance()->default_scale ())
{
- setup_default_colour_conversion ();
+ set_default_colour_conversion ();
}
VideoContent::VideoContent (shared_ptr<const Film> f, shared_ptr<const cxml::Node> node, int version)
_video_size.width = node->number_child<int> ("VideoWidth");
_video_size.height = node->number_child<int> ("VideoHeight");
_video_frame_rate = node->number_child<float> ("VideoFrameRate");
+ _original_video_frame_rate = node->optional_number_child<float> ("OriginalVideoFrameRate").get_value_or (_video_frame_rate);
_video_frame_type = static_cast<VideoFrameType> (node->number_child<int> ("VideoFrameType"));
_crop.left = node->number_child<int> ("LeftCrop");
_crop.right = node->number_child<int> ("RightCrop");
} else {
_scale = VideoContentScale (node->node_child ("Scale"));
}
-
- _colour_conversion = ColourConversion (node->node_child ("ColourConversion"));
+
+ if (node->optional_node_child ("ColourConversion")) {
+ _colour_conversion = ColourConversion (node->node_child ("ColourConversion"));
+ }
}
VideoContent::VideoContent (shared_ptr<const Film> f, vector<shared_ptr<Content> > c)
}
_video_size = ref->video_size ();
+ _original_video_frame_rate = ref->original_video_frame_rate ();
_video_frame_rate = ref->video_frame_rate ();
_video_frame_type = ref->video_frame_type ();
_crop = ref->crop ();
node->add_child("VideoWidth")->add_child_text (raw_convert<string> (_video_size.width));
node->add_child("VideoHeight")->add_child_text (raw_convert<string> (_video_size.height));
node->add_child("VideoFrameRate")->add_child_text (raw_convert<string> (_video_frame_rate));
+ node->add_child("OriginalVideoFrameRate")->add_child_text (raw_convert<string> (_original_video_frame_rate));
node->add_child("VideoFrameType")->add_child_text (raw_convert<string> (static_cast<int> (_video_frame_type)));
_crop.as_xml (node);
_scale.as_xml (node->add_child("Scale"));
- _colour_conversion.as_xml (node->add_child("ColourConversion"));
+ if (_colour_conversion) {
+ _colour_conversion.get().as_xml (node->add_child("ColourConversion"));
+ }
}
void
-VideoContent::setup_default_colour_conversion ()
+VideoContent::set_default_colour_conversion ()
{
- _colour_conversion = PresetColourConversion (_("sRGB"), 2.4, true, libdcp::colour_matrix::srgb_to_xyz, 2.6).conversion;
+ set_colour_conversion (PresetColourConversion (_("sRGB"), 2.4, true, libdcp::colour_matrix::srgb_to_xyz, 2.6).conversion);
}
void
boost::mutex::scoped_lock lm (_mutex);
_video_size = vs;
_video_frame_rate = vfr;
+ _original_video_frame_rate = vfr;
}
signal_changed (VideoContentProperty::VIDEO_SIZE);
return "";
}
- stringstream s;
+ SafeStringStream s;
s << String::compose (
_("%1x%2 pixels (%3:1)"),
string
VideoContent::identifier () const
{
- stringstream s;
+ SafeStringStream s;
s << Content::identifier()
<< "_" << crop().left
<< "_" << crop().right
<< "_" << crop().top
<< "_" << crop().bottom
- << "_" << scale().id()
- << "_" << colour_conversion().identifier ();
+ << "_" << scale().id();
+
+ if (colour_conversion()) {
+ s << "_" << colour_conversion().get().identifier ();
+ }
return s.str ();
}
assert (false);
}
+void
+VideoContent::unset_colour_conversion ()
+{
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _colour_conversion = boost::optional<ColourConversion> ();
+ }
+
+ signal_changed (VideoContentProperty::COLOUR_CONVERSION);
+}
+
void
VideoContent::set_colour_conversion (ColourConversion c)
{
signal_changed (VideoContentProperty::VIDEO_FRAME_RATE);
}
-VideoContentScale::VideoContentScale (Ratio const * r)
- : _ratio (r)
- , _scale (true)
-{
-
-}
-
-VideoContentScale::VideoContentScale ()
- : _ratio (0)
- , _scale (false)
-{
-
-}
-
-VideoContentScale::VideoContentScale (bool scale)
- : _ratio (0)
- , _scale (scale)
-{
-
-}
-
-VideoContentScale::VideoContentScale (shared_ptr<cxml::Node> node)
- : _ratio (0)
- , _scale (true)
-{
- optional<string> r = node->optional_string_child ("Ratio");
- if (r) {
- _ratio = Ratio::from_id (r.get ());
- } else {
- _scale = node->bool_child ("Scale");
- }
-}
-
-void
-VideoContentScale::as_xml (xmlpp::Node* node) const
-{
- if (_ratio) {
- node->add_child("Ratio")->add_child_text (_ratio->id ());
- } else {
- node->add_child("Scale")->add_child_text (_scale ? "1" : "0");
- }
-}
-
-string
-VideoContentScale::id () const
-{
- stringstream s;
-
- if (_ratio) {
- s << _ratio->id () << "_";
- } else {
- s << (_scale ? "S1" : "S0");
- }
-
- return s.str ();
-}
-
-string
-VideoContentScale::name () const
-{
- if (_ratio) {
- return _ratio->nickname ();
- }
-
- if (_scale) {
- return _("No stretch");
- }
-
- return _("No scale");
-}
-
-/** @param display_container Size of the container that we are displaying this content in.
- * @param film_container The size of the film's image.
- */
-libdcp::Size
-VideoContentScale::size (shared_ptr<const VideoContent> c, libdcp::Size display_container, libdcp::Size film_container) const
-{
- if (_ratio) {
- return fit_ratio_within (_ratio->ratio (), display_container);
- }
-
- libdcp::Size const ac = c->video_size_after_crop ();
-
- /* Force scale if the film_container is smaller than the content's image */
- if (_scale || film_container.width < ac.width || film_container.height < ac.height) {
- return fit_ratio_within (ac.ratio (), display_container);
- }
-
- /* Scale the image so that it will be in the right place in film_container, even if display_container is a
- different size.
- */
- return libdcp::Size (
- c->video_size().width * float(display_container.width) / film_container.width,
- c->video_size().height * float(display_container.height) / film_container.height
- );
-}
-
-void
-VideoContentScale::setup_scales ()
-{
- vector<Ratio const *> ratios = Ratio::all ();
- for (vector<Ratio const *>::const_iterator i = ratios.begin(); i != ratios.end(); ++i) {
- _scales.push_back (VideoContentScale (*i));
- }
-
- _scales.push_back (VideoContentScale (true));
- _scales.push_back (VideoContentScale (false));
-}
-
-bool
-operator== (VideoContentScale const & a, VideoContentScale const & b)
-{
- return (a.ratio() == b.ratio() && a.scale() == b.scale());
-}
-
-bool
-operator!= (VideoContentScale const & a, VideoContentScale const & b)
-{
- return (a.ratio() != b.ratio() || a.scale() != b.scale());
-}