Make storage of VideoFrameType robust by using a string in the XML rather than a...
authorCarl Hetherington <cth@carlh.net>
Mon, 13 Jun 2016 12:48:45 +0000 (13:48 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 13 Jun 2016 12:48:45 +0000 (13:48 +0100)
src/lib/film.cc
src/lib/types.cc
src/lib/types.h
src/lib/video_content.cc

index db8da56b49e3ec748f54caf8ee49dd8ebc5269b3..ff5cba0001bd1a794e2d6099151ca6f2f62aa631 100644 (file)
@@ -111,8 +111,10 @@ using boost::is_any_of;
  * 33 -> 34
  * Content only contains audio/subtitle-related tags if those things
  * are present.
+ * 34 -> 35
+ * VideoFrameType in VideoContent is a string rather than an integer.
  */
-int const Film::current_state_version = 34;
+int const Film::current_state_version = 35;
 
 /** Construct a Film object in a given directory.
  *
index ba062c3f8f0834194cc951fa8a506aa22bce3f1e..ce50814644de70bd866d6a3d6bd11803f80d8cf7 100644 (file)
@@ -88,3 +88,46 @@ Crop::as_xml (xmlpp::Node* node) const
        node->add_child("TopCrop")->add_child_text (raw_convert<string> (top));
        node->add_child("BottomCrop")->add_child_text (raw_convert<string> (bottom));
 }
+
+string
+video_frame_type_to_string (VideoFrameType t)
+{
+       switch (t) {
+       case VIDEO_FRAME_TYPE_2D:
+               return "2d";
+       case VIDEO_FRAME_TYPE_3D_LEFT_RIGHT:
+               return "3d-left-right";
+       case VIDEO_FRAME_TYPE_3D_TOP_BOTTOM:
+               return "3d-top-bottom";
+       case VIDEO_FRAME_TYPE_3D_ALTERNATE:
+               return "3d-alternate";
+       case VIDEO_FRAME_TYPE_3D_LEFT:
+               return "3d-left";
+       case VIDEO_FRAME_TYPE_3D_RIGHT:
+               return "3d-right";
+       default:
+               DCPOMATIC_ASSERT (false);
+       }
+
+       DCPOMATIC_ASSERT (false);
+}
+
+VideoFrameType
+string_to_video_frame_type (string s)
+{
+       if (s == "2d") {
+               return VIDEO_FRAME_TYPE_2D;
+       } else if (s == "3d-left-right") {
+               return VIDEO_FRAME_TYPE_3D_LEFT_RIGHT;
+       } else if (s == "3d-top-bottom") {
+               return VIDEO_FRAME_TYPE_3D_TOP_BOTTOM;
+       } else if (s == "3d-alternate") {
+               return VIDEO_FRAME_TYPE_3D_ALTERNATE;
+       } else if (s == "3d-left") {
+               return VIDEO_FRAME_TYPE_3D_LEFT;
+       } else if (s == "3d-right") {
+               return VIDEO_FRAME_TYPE_3D_RIGHT;
+       }
+
+       DCPOMATIC_ASSERT (false);
+}
index ab51e38a9d7a1f8dabd3f749847928b36450bdf9..8513fde519efac8b9a1d2dbd4b372e957949c29f 100644 (file)
@@ -87,6 +87,9 @@ enum VideoFrameType
        VIDEO_FRAME_TYPE_3D_RIGHT
 };
 
+std::string video_frame_type_to_string (VideoFrameType);
+VideoFrameType string_to_video_frame_type (std::string);
+
 enum Eyes
 {
        EYES_BOTH,
index 473bd784c7887cf0e12838af28a9eb98a4d81db4..66c63961e8142bb90c3778fe3fdefdf17d8ae281 100644 (file)
@@ -99,7 +99,33 @@ VideoContent::VideoContent (Content* parent, cxml::ConstNodePtr node, int versio
        }
 
        _length = node->number_child<Frame> ("VideoLength");
-       _frame_type = static_cast<VideoFrameType> (node->number_child<int> ("VideoFrameType"));
+
+       if (version <= 34) {
+               /* Snapshot of the VideoFrameType enum at version 34 */
+               switch (node->number_child<int> ("VideoFrameType")) {
+               case 0:
+                       _frame_type = VIDEO_FRAME_TYPE_2D;
+                       break;
+               case 1:
+                       _frame_type = VIDEO_FRAME_TYPE_3D_LEFT_RIGHT;
+                       break;
+               case 2:
+                       _frame_type = VIDEO_FRAME_TYPE_3D_TOP_BOTTOM;
+                       break;
+               case 3:
+                       _frame_type = VIDEO_FRAME_TYPE_3D_ALTERNATE;
+                       break;
+               case 4:
+                       _frame_type = VIDEO_FRAME_TYPE_3D_LEFT;
+                       break;
+               case 5:
+                       _frame_type = VIDEO_FRAME_TYPE_3D_RIGHT;
+                       break;
+               }
+       } else {
+               _frame_type = string_to_video_frame_type (node->string_child ("VideoFrameType"));
+       }
+
        _sample_aspect_ratio = node->optional_number_child<double> ("SampleAspectRatio");
        _crop.left = node->number_child<int> ("LeftCrop");
        _crop.right = node->number_child<int> ("RightCrop");
@@ -187,7 +213,7 @@ VideoContent::as_xml (xmlpp::Node* node) const
        node->add_child("VideoLength")->add_child_text (raw_convert<string> (_length));
        node->add_child("VideoWidth")->add_child_text (raw_convert<string> (_size.width));
        node->add_child("VideoHeight")->add_child_text (raw_convert<string> (_size.height));
-       node->add_child("VideoFrameType")->add_child_text (raw_convert<string> (static_cast<int> (_frame_type)));
+       node->add_child("VideoFrameType")->add_child_text (video_frame_type_to_string (_frame_type));
        if (_sample_aspect_ratio) {
                node->add_child("SampleAspectRatio")->add_child_text (raw_convert<string> (_sample_aspect_ratio.get ()));
        }