Compiles; strange hang on adding content to a film.
[dcpomatic.git] / src / lib / video_content.cc
index 9fc5cf1a22f486f868d6da64a5d770086332244f..9fb2b9bce8f3a4c12860ee6bae4ab00e8b2ef59f 100644 (file)
@@ -1,11 +1,37 @@
+/*
+    Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <libcxml/cxml.h>
 #include "video_content.h"
 #include "video_decoder.h"
 
+#include "i18n.h"
+
 int const VideoContentProperty::VIDEO_LENGTH = 0;
 int const VideoContentProperty::VIDEO_SIZE = 1;
 int const VideoContentProperty::VIDEO_FRAME_RATE = 2;
 
+using std::string;
+using std::stringstream;
+using std::setprecision;
 using boost::shared_ptr;
+using boost::lexical_cast;
 
 VideoContent::VideoContent (boost::filesystem::path f)
        : Content (f)
@@ -14,15 +40,67 @@ VideoContent::VideoContent (boost::filesystem::path f)
 
 }
 
+VideoContent::VideoContent (shared_ptr<const cxml::Node> node)
+       : Content (node)
+{
+       _video_length = node->number_child<ContentVideoFrame> ("VideoLength");
+       _video_size.width = node->number_child<int> ("VideoWidth");
+       _video_size.height = node->number_child<int> ("VideoHeight");
+       _video_frame_rate = node->number_child<float> ("VideoFrameRate");
+}
+
+VideoContent::VideoContent (VideoContent const & o)
+       : Content (o)
+       , _video_length (o._video_length)
+       , _video_size (o._video_size)
+       , _video_frame_rate (o._video_frame_rate)
+{
+
+}
+
+void
+VideoContent::as_xml (xmlpp::Node* node) const
+{
+       boost::mutex::scoped_lock lm (_mutex);
+       node->add_child("VideoLength")->add_child_text (lexical_cast<string> (_video_length));
+       node->add_child("VideoWidth")->add_child_text (lexical_cast<string> (_video_size.width));
+       node->add_child("VideoHeight")->add_child_text (lexical_cast<string> (_video_size.height));
+       node->add_child("VideoFrameRate")->add_child_text (lexical_cast<string> (_video_frame_rate));
+}
+
 void
 VideoContent::take_from_video_decoder (shared_ptr<VideoDecoder> d)
 {
+       /* These decoder calls could call other content methods which take a lock on the mutex */
+       libdcp::Size const vs = d->native_size ();
+       float const vfr = d->video_frame_rate ();
+       
         {
                 boost::mutex::scoped_lock lm (_mutex);
-                _video_size = d->native_size ();
-                _video_frame_rate = d->frames_per_second ();
+                _video_size = vs;
+               _video_frame_rate = vfr;
         }
         
-        Changed (VideoContentProperty::VIDEO_SIZE);
-        Changed (VideoContentProperty::VIDEO_FRAME_RATE);
+        signal_changed (VideoContentProperty::VIDEO_SIZE);
+        signal_changed (VideoContentProperty::VIDEO_FRAME_RATE);
+}
+
+
+string
+VideoContent::information () const
+{
+       if (video_size().width == 0 || video_size().height == 0) {
+               return "";
+       }
+       
+       stringstream s;
+
+       s << String::compose (
+               _("%1x%2 pixels (%3:1)"),
+               video_size().width,
+               video_size().height,
+               setprecision (3), float (video_size().width) / video_size().height
+               );
+       
+       return s.str ();
 }