- shared_ptr<const FilmState> fs = state_copy ();
- shared_ptr<Options> o (new Options (j2k_dir(), ".j2c", dir ("wavs")));
- o->out_size = format()->dcp_size ();
- if (dcp_frames() == 0) {
- /* Decode the whole film, no blacking */
- o->black_after = 0;
- } else {
- switch (dcp_trim_action()) {
- case CUT:
- /* Decode only part of the film, no blacking */
- o->black_after = 0;
- break;
- case BLACK_OUT:
- /* Decode the whole film, but black some frames out */
- o->black_after = dcp_frames ();
+ JobManager::instance()->add (shared_ptr<Job> (new TranscodeJob (shared_from_this())));
+}
+
+/** Start a job to send our DCP to the configured TMS */
+void
+Film::send_dcp_to_tms ()
+{
+ shared_ptr<Job> j (new SCPDCPJob (shared_from_this()));
+ JobManager::instance()->add (j);
+}
+
+/** Count the number of frames that have been encoded for this film.
+ * @return frame count.
+ */
+int
+Film::encoded_frames () const
+{
+ if (container() == 0) {
+ return 0;
+ }
+
+ int N = 0;
+ for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (info_dir ()); i != boost::filesystem::directory_iterator(); ++i) {
+ ++N;
+ boost::this_thread::interruption_point ();
+ }
+
+ return N;
+}
+
+/** Write state to our `metadata' file */
+void
+Film::write_metadata () const
+{
+ if (!boost::filesystem::exists (directory())) {
+ boost::filesystem::create_directory (directory());
+ }
+
+ boost::mutex::scoped_lock lm (_state_mutex);
+ LocaleGuard lg;
+
+ boost::filesystem::create_directories (directory());
+
+ xmlpp::Document doc;
+ xmlpp::Element* root = doc.create_root_node ("Metadata");
+
+ root->add_child("Version")->add_child_text (lexical_cast<string> (state_version));
+ root->add_child("Name")->add_child_text (_name);
+ root->add_child("UseDCIName")->add_child_text (_use_dci_name ? "1" : "0");
+
+ if (_dcp_content_type) {
+ root->add_child("DCPContentType")->add_child_text (_dcp_content_type->dci_name ());
+ }
+
+ if (_container) {
+ root->add_child("Container")->add_child_text (_container->id ());
+ }
+
+ root->add_child("Resolution")->add_child_text (resolution_to_string (_resolution));
+ root->add_child("Scaler")->add_child_text (_scaler->id ());
+ root->add_child("WithSubtitles")->add_child_text (_with_subtitles ? "1" : "0");
+ root->add_child("J2KBandwidth")->add_child_text (lexical_cast<string> (_j2k_bandwidth));
+ _dci_metadata.as_xml (root->add_child ("DCIMetadata"));
+ root->add_child("VideoFrameRate")->add_child_text (lexical_cast<string> (_video_frame_rate));
+ root->add_child("DCIDate")->add_child_text (boost::gregorian::to_iso_string (_dci_date));
+ root->add_child("AudioChannels")->add_child_text (lexical_cast<string> (_audio_channels));
+ root->add_child("ThreeD")->add_child_text (_three_d ? "1" : "0");
+ root->add_child("SequenceVideo")->add_child_text (_sequence_video ? "1" : "0");
+ _playlist->as_xml (root->add_child ("Playlist"));
+
+ doc.write_to_file_formatted (file ("metadata.xml"));
+
+ _dirty = false;
+}
+
+/** Read state from our metadata file */
+void
+Film::read_metadata ()
+{
+ boost::mutex::scoped_lock lm (_state_mutex);
+ LocaleGuard lg;
+
+ if (boost::filesystem::exists (file ("metadata")) && !boost::filesystem::exists (file ("metadata.xml"))) {
+ throw StringError (_("This film was created with an older version of DCP-o-matic, and unfortunately it cannot be loaded into this version. You will need to create a new Film, re-add your content and set it up again. Sorry!"));
+ }
+
+ cxml::File f (file ("metadata.xml"), "Metadata");
+
+ _name = f.string_child ("Name");
+ _use_dci_name = f.bool_child ("UseDCIName");
+
+ {
+ optional<string> c = f.optional_string_child ("DCPContentType");
+ if (c) {
+ _dcp_content_type = DCPContentType::from_dci_name (c.get ());