Round image line sizes up to 32. Seems to help with LHS image corruption with both...
[dcpomatic.git] / src / lib / film_state.cc
index e0ad20417adbee8f450d241df6df144e70918cf1..a4d88d0e05a295cffe096231dd9956a4335fa687 100644 (file)
@@ -35,6 +35,7 @@
 #include "format.h"
 #include "dcp_content_type.h"
 #include "util.h"
+#include "exceptions.h"
 
 using namespace std;
 using namespace boost;
@@ -79,6 +80,9 @@ FilmState::write_metadata (ofstream& f) const
        f << "audio_gain " << audio_gain << "\n";
        f << "audio_delay " << audio_delay << "\n";
        f << "still_duration " << still_duration << "\n";
+       f << "with_subtitles " << with_subtitles << "\n";
+       f << "subtitle_offset " << subtitle_offset << "\n";
+       f << "subtitle_scale " << subtitle_scale << "\n";
 
        /* Cached stuff; this is information about our content; we could
           look it up each time, but that's slow.
@@ -93,6 +97,7 @@ FilmState::write_metadata (ofstream& f) const
        f << "audio_sample_rate " << audio_sample_rate << "\n";
        f << "audio_sample_format " << audio_sample_format_to_string (audio_sample_format) << "\n";
        f << "content_digest " << content_digest << "\n";
+       f << "has_subtitles " << has_subtitles << "\n";
 }
 
 /** Read state from a key / value pair.
@@ -141,6 +146,12 @@ FilmState::read_metadata (string k, string v)
                audio_delay = atoi (v.c_str ());
        } else if (k == "still_duration") {
                still_duration = atoi (v.c_str ());
+       } else if (k == "with_subtitles") {
+               with_subtitles = (v == "1");
+       } else if (k == "subtitle_offset") {
+               subtitle_offset = atoi (v.c_str ());
+       } else if (k == "subtitle_scale") {
+               subtitle_scale = atof (v.c_str ());
        }
        
        /* Cached stuff */
@@ -164,11 +175,8 @@ FilmState::read_metadata (string k, string v)
                audio_sample_format = audio_sample_format_from_string (v);
        } else if (k == "content_digest") {
                content_digest = v;
-       }
-       
-       /* Itsy bitsy hack: compute digest here if don't have one (for backwards compatibility) */
-       if (content_digest.empty() && !content.empty()) {
-               content_digest = md5_digest (content_path ());
+       } else if (k == "has_subtitles") {
+               has_subtitles = (v == "1");
        }
 }
 
@@ -188,10 +196,22 @@ FilmState::thumb_file (int n) const
  */
 string
 FilmState::thumb_file_for_frame (int n) const
+{
+       return thumb_base_for_frame(n) + ".png";
+}
+
+string
+FilmState::thumb_base (int n) const
+{
+       return thumb_base_for_frame (thumb_frame (n));
+}
+
+string
+FilmState::thumb_base_for_frame (int n) const
 {
        stringstream s;
        s.width (8);
-       s << setfill('0') << n << ".tiff";
+       s << setfill('0') << n;
        
        filesystem::path p;
        p /= dir ("thumbs");
@@ -256,10 +276,13 @@ ContentType
 FilmState::content_type () const
 {
 #if BOOST_FILESYSTEM_VERSION == 3
-       string const ext = filesystem::path(content).extension().string();
+       string ext = filesystem::path(content).extension().string();
 #else
-       string const ext = filesystem::path(content).extension();
+       string ext = filesystem::path(content).extension();
 #endif
+
+       transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
+       
        if (ext == ".tif" || ext == ".tiff" || ext == ".jpg" || ext == ".jpeg" || ext == ".png") {
                return STILL;
        }
@@ -280,3 +303,31 @@ FilmState::bytes_per_sample () const
 
        return 0;
 }
+
+int
+FilmState::target_sample_rate () const
+{
+       /* Resample to a DCI-approved sample rate */
+       double t = dcp_audio_sample_rate (audio_sample_rate);
+
+       /* Compensate for the fact that video will be rounded to the
+          nearest integer number of frames per second.
+       */
+       if (rint (frames_per_second) != frames_per_second) {
+               t *= frames_per_second / rint (frames_per_second);
+       }
+
+       return rint (t);
+}
+
+int
+FilmState::dcp_length () const
+{
+       if (dcp_frames) {
+               return dcp_frames;
+       }
+
+       return length;
+}
+
+