From: Carl Hetherington Date: Fri, 8 Jun 2018 09:35:05 +0000 (+0100) Subject: Remove details video properties from non-video content XML. X-Git-Tag: v2.13.27~1 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=82e518498a853af33f2b53ebac08ec3094a96f8e Remove details video properties from non-video content XML. --- diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index 26d3b88da..2233f5f8c 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -69,6 +69,17 @@ FFmpegContent::FFmpegContent (shared_ptr film, boost::filesystem::pa } +template +optional +get_optional_enum (cxml::ConstNodePtr node, string name) +{ + optional const v = node->optional_number_child(name); + if (!v) { + return optional(); + } + return static_cast(*v); +} + FFmpegContent::FFmpegContent (shared_ptr film, cxml::ConstNodePtr node, int version, list& notes) : Content (film, node) { @@ -109,12 +120,10 @@ FFmpegContent::FFmpegContent (shared_ptr film, cxml::ConstNodePtr no _first_video = ContentTime (f.get ()); } - _color_range = static_cast (node->optional_number_child("ColorRange").get_value_or (AVCOL_RANGE_UNSPECIFIED)); - _color_primaries = static_cast (node->optional_number_child("ColorPrimaries").get_value_or (AVCOL_PRI_UNSPECIFIED)); - _color_trc = static_cast ( - node->optional_number_child("ColorTransferCharacteristic").get_value_or (AVCOL_TRC_UNSPECIFIED) - ); - _colorspace = static_cast (node->optional_number_child("Colorspace").get_value_or (AVCOL_SPC_UNSPECIFIED)); + _color_range = get_optional_enum(node, "ColorRange"); + _color_primaries = get_optional_enum(node, "ColorPrimaries"); + _color_trc = get_optional_enum(node, "ColorTransferCharacteristic"); + _colorspace = get_optional_enum(node, "Colorspace"); _bits_per_pixel = node->optional_number_child ("BitsPerPixel"); } @@ -222,12 +231,20 @@ FFmpegContent::as_xml (xmlpp::Node* node, bool with_paths) const node->add_child("FirstVideo")->add_child_text (raw_convert (_first_video.get().get())); } - node->add_child("ColorRange")->add_child_text (raw_convert (static_cast (_color_range))); - node->add_child("ColorPrimaries")->add_child_text (raw_convert (static_cast (_color_primaries))); - node->add_child("ColorTransferCharacteristic")->add_child_text (raw_convert (static_cast (_color_trc))); - node->add_child("Colorspace")->add_child_text (raw_convert (static_cast (_colorspace))); + if (_color_range) { + node->add_child("ColorRange")->add_child_text (raw_convert (static_cast (*_color_range))); + } + if (_color_primaries) { + node->add_child("ColorPrimaries")->add_child_text (raw_convert (static_cast (*_color_primaries))); + } + if (_color_trc) { + node->add_child("ColorTransferCharacteristic")->add_child_text (raw_convert (static_cast (*_color_trc))); + } + if (_colorspace) { + node->add_child("Colorspace")->add_child_text (raw_convert (static_cast (*_colorspace))); + } if (_bits_per_pixel) { - node->add_child("BitsPerPixel")->add_child_text (raw_convert (_bits_per_pixel.get ())); + node->add_child("BitsPerPixel")->add_child_text (raw_convert (*_bits_per_pixel)); } } @@ -423,7 +440,7 @@ FFmpegContent::set_default_colour_conversion () boost::mutex::scoped_lock lm (_mutex); - switch (_colorspace) { + switch (_colorspace.get_value_or(AVCOL_SPC_UNSPECIFIED)) { case AVCOL_SPC_RGB: video->set_colour_conversion (PresetColourConversion::from_id ("srgb").conversion); break; @@ -461,7 +478,7 @@ FFmpegContent::add_properties (list& p) const int const sub = 219 * pow (2, _bits_per_pixel.get() - 8); int const total = pow (2, _bits_per_pixel.get()); - switch (_color_range) { + switch (_color_range.get_value_or(AVCOL_RANGE_UNSPECIFIED)) { case AVCOL_RANGE_UNSPECIFIED: /// TRANSLATORS: this means that the range of pixel values used in this /// file is unknown (not specified in the file). @@ -485,7 +502,7 @@ FFmpegContent::add_properties (list& p) const DCPOMATIC_ASSERT (false); } } else { - switch (_color_range) { + switch (_color_range.get_value_or(AVCOL_RANGE_UNSPECIFIED)) { case AVCOL_RANGE_UNSPECIFIED: /// TRANSLATORS: this means that the range of pixel values used in this /// file is unknown (not specified in the file). @@ -533,7 +550,7 @@ FFmpegContent::add_properties (list& p) const }; DCPOMATIC_ASSERT (AVCOL_PRI_NB <= 23); - p.push_back (UserProperty (UserProperty::VIDEO, _("Colour primaries"), primaries[_color_primaries])); + p.push_back (UserProperty (UserProperty::VIDEO, _("Colour primaries"), primaries[_color_primaries.get_value_or(AVCOL_PRI_UNSPECIFIED)])); char const * transfers[] = { _("Unspecified"), @@ -558,7 +575,7 @@ FFmpegContent::add_properties (list& p) const }; DCPOMATIC_ASSERT (AVCOL_TRC_NB <= 19); - p.push_back (UserProperty (UserProperty::VIDEO, _("Colour transfer characteristic"), transfers[_color_trc])); + p.push_back (UserProperty (UserProperty::VIDEO, _("Colour transfer characteristic"), transfers[_color_trc.get_value_or(AVCOL_TRC_UNSPECIFIED)])); char const * spaces[] = { _("RGB / sRGB (IEC61966-2-1)"), @@ -579,10 +596,10 @@ FFmpegContent::add_properties (list& p) const }; DCPOMATIC_ASSERT (AVCOL_SPC_NB == 15); - p.push_back (UserProperty (UserProperty::VIDEO, _("Colourspace"), spaces[_colorspace])); + p.push_back (UserProperty (UserProperty::VIDEO, _("Colourspace"), spaces[_colorspace.get_value_or(AVCOL_SPC_UNSPECIFIED)])); if (_bits_per_pixel) { - p.push_back (UserProperty (UserProperty::VIDEO, _("Bits per pixel"), _bits_per_pixel.get ())); + p.push_back (UserProperty (UserProperty::VIDEO, _("Bits per pixel"), *_bits_per_pixel)); } } diff --git a/src/lib/ffmpeg_content.h b/src/lib/ffmpeg_content.h index d9020ac01..64f6f9ff8 100644 --- a/src/lib/ffmpeg_content.h +++ b/src/lib/ffmpeg_content.h @@ -105,10 +105,10 @@ private: /** Video filters that should be used when generating DCPs */ std::vector _filters; - AVColorRange _color_range; - AVColorPrimaries _color_primaries; - AVColorTransferCharacteristic _color_trc; - AVColorSpace _colorspace; + boost::optional _color_range; + boost::optional _color_primaries; + boost::optional _color_trc; + boost::optional _colorspace; boost::optional _bits_per_pixel; };