Basic support for selection of audio / subtitle streams.
[dcpomatic.git] / src / lib / film_state.cc
index fed5068639e23ba350b6433f1c58e1f9d5d22ae2..0d0bd6313667ca5e14c5d80322f600ea32868582 100644 (file)
@@ -49,6 +49,7 @@ FilmState::write_metadata (ofstream& f) const
 {
        /* User stuff */
        f << "name " << name << "\n";
+       f << "use_dci_name " << use_dci_name << "\n";
        f << "content " << content << "\n";
        if (dcp_content_type) {
                f << "dcp_content_type " << dcp_content_type->pretty_name () << "\n";
@@ -78,12 +79,20 @@ FilmState::write_metadata (ofstream& f) const
        }
        
        f << "dcp_ab " << (dcp_ab ? "1" : "0") << "\n";
+       f << "selected_audio_stream " << audio_stream << "\n";
        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";
+       f << "audio_language " << audio_language << "\n";
+       f << "subtitle_language " << subtitle_language << "\n";
+       f << "territory " << territory << "\n";
+       f << "rating " << rating << "\n";
+       f << "studio " << studio << "\n";
+       f << "facility " << facility << "\n";
+       f << "package_type " << package_type << "\n";
 
        /* Cached stuff; this is information about our content; we could
           look it up each time, but that's slow.
@@ -98,7 +107,16 @@ 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 << "selected_subtitle_stream " << subtitle_stream << "\n";
        f << "has_subtitles " << has_subtitles << "\n";
+
+       for (vector<Stream>::const_iterator i = audio_streams.begin(); i != audio_streams.end(); ++i) {
+               f << "audio_stream " << i->to_string () << "\n";
+       }
+
+       for (vector<Stream>::const_iterator i = subtitle_streams.begin(); i != subtitle_streams.end(); ++i) {
+               f << "subtitle_stream " << i->to_string () << "\n";
+       }
 }
 
 /** Read state from a key / value pair.
@@ -111,6 +129,8 @@ FilmState::read_metadata (string k, string v)
        /* User-specified stuff */
        if (k == "name") {
                name = v;
+       } else if (k == "use_dci_name") {
+               use_dci_name = (v == "1");
        } else if (k == "content") {
                content = v;
        } else if (k == "dcp_content_type") {
@@ -141,6 +161,8 @@ FilmState::read_metadata (string k, string v)
                }
        } else if (k == "dcp_ab") {
                dcp_ab = (v == "1");
+       } else if (k == "selected_audio_stream") {
+               audio_stream = atoi (v.c_str ());
        } else if (k == "audio_gain") {
                audio_gain = atof (v.c_str ());
        } else if (k == "audio_delay") {
@@ -153,6 +175,22 @@ FilmState::read_metadata (string k, string v)
                subtitle_offset = atoi (v.c_str ());
        } else if (k == "subtitle_scale") {
                subtitle_scale = atof (v.c_str ());
+       } else if (k == "selected_subtitle_stream") {
+               subtitle_stream = atoi (v.c_str ());
+       } else if (k == "audio_language") {
+               audio_language = v;
+       } else if (k == "subtitle_language") {
+               subtitle_language = v;
+       } else if (k == "territory") {
+               territory = v;
+       } else if (k == "rating") {
+               rating = v;
+       } else if (k == "studio") {
+               studio = v;
+       } else if (k == "facility") {
+               facility = v;
+       } else if (k == "package_type") {
+               package_type = v;
        }
        
        /* Cached stuff */
@@ -178,6 +216,10 @@ FilmState::read_metadata (string k, string v)
                content_digest = v;
        } else if (k == "has_subtitles") {
                has_subtitles = (v == "1");
+       } else if (k == "audio_stream") {
+               audio_streams.push_back (Stream (v));
+       } else if (k == "subtitle_stream") {
+               subtitle_streams.push_back (Stream (v));
        }
 }
 
@@ -331,11 +373,25 @@ FilmState::dcp_length () const
        return length;
 }
 
+/** @return a DCI-compliant name for a DCP of this film */
 string
 FilmState::dci_name () const
 {
        stringstream d;
-       d << dci_name_prefix << "_";
+
+       string fixed_name = to_upper_copy (name);
+       for (size_t i = 0; i < fixed_name.length(); ++i) {
+               if (fixed_name[i] == ' ') {
+                       fixed_name[i] = '-';
+               }
+       }
+
+       /* Spec is that the name part should be maximum 14 characters, as I understand it */
+       if (fixed_name.length() > 14) {
+               fixed_name = fixed_name.substr (0, 14);
+       }
+
+       d << fixed_name << "_";
 
        if (dcp_content_type) {
                d << dcp_content_type->dci_name() << "_";
@@ -347,9 +403,14 @@ FilmState::dci_name () const
 
        if (!audio_language.empty ()) {
                d << audio_language;
-               if (!subtitle_language.empty ()) {
-                       d << "-" << subtitle_language;
+               if (with_subtitles) {
+                       if (!subtitle_language.empty ()) {
+                               d << "-" << subtitle_language;
+                       } else {
+                               d << "-XX";
+                       }
                }
+                       
                d << "_";
        }
 
@@ -363,10 +424,10 @@ FilmState::dci_name () const
 
        switch (audio_channels) {
        case 1:
-               d << "1_";
+               d << "10_";
                break;
        case 2:
-               d << "2_";
+               d << "20_";
                break;
        case 6:
                d << "51_";
@@ -380,7 +441,7 @@ FilmState::dci_name () const
        }
 
        gregorian::date today = gregorian::day_clock::local_day ();
-       d << gregorian::to_iso_extended_string (today) << "_";
+       d << gregorian::to_iso_string (today) << "_";
 
        if (!facility.empty ()) {
                d << facility << "_";
@@ -392,3 +453,16 @@ FilmState::dci_name () const
 
        return d.str ();
 }
+
+/** @return name to give the DCP */
+string
+FilmState::dcp_name () const
+{
+       if (use_dci_name) {
+               return dci_name ();
+       }
+
+       return name;
+}
+
+