summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2016-06-13 13:48:45 +0100
committerCarl Hetherington <cth@carlh.net>2016-06-13 13:48:45 +0100
commit1daaa67c21d4d28757cdcb06c5e26aec3817867c (patch)
treee31238b3445857d9dcaac38e1ee699064b35a416 /src/lib
parenta136864bf39e952ea6058510a594798588e56a03 (diff)
Make storage of VideoFrameType robust by using a string in the XML rather than a casted enum.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/film.cc4
-rw-r--r--src/lib/types.cc43
-rw-r--r--src/lib/types.h3
-rw-r--r--src/lib/video_content.cc30
4 files changed, 77 insertions, 3 deletions
diff --git a/src/lib/film.cc b/src/lib/film.cc
index db8da56b4..ff5cba000 100644
--- a/src/lib/film.cc
+++ b/src/lib/film.cc
@@ -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.
*
diff --git a/src/lib/types.cc b/src/lib/types.cc
index ba062c3f8..ce5081464 100644
--- a/src/lib/types.cc
+++ b/src/lib/types.cc
@@ -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);
+}
diff --git a/src/lib/types.h b/src/lib/types.h
index ab51e38a9..8513fde51 100644
--- a/src/lib/types.h
+++ b/src/lib/types.h
@@ -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,
diff --git a/src/lib/video_content.cc b/src/lib/video_content.cc
index 473bd784c..66c63961e 100644
--- a/src/lib/video_content.cc
+++ b/src/lib/video_content.cc
@@ -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 ()));
}