Merge branch 'master' into plot-audio
[dcpomatic.git] / src / lib / film.cc
index 36ebe719975bdb11a80133c3edc57e0fe9890956..f36614689c64a23d9bc65f09083fd2a2a91f27ba 100644 (file)
@@ -51,6 +51,7 @@
 #include "video_decoder.h"
 #include "audio_decoder.h"
 #include "external_audio_decoder.h"
+#include "analyse_audio_job.h"
 
 using std::string;
 using std::stringstream;
@@ -237,11 +238,18 @@ Film::video_mxf_filename () const
        return video_state_identifier() + ".mxf";
 }
 
-/** Add suitable Jobs to the JobManager to create a DCP for this Film.
- *  @param true to transcode, false to use the WAV and J2K files that are already there.
- */
+string
+Film::audio_analysis_path () const
+{
+       boost::filesystem::path p;
+       p /= "analysis";
+       p /= content_digest();
+       return file (p.string ());
+}
+
+/** Add suitable Jobs to the JobManager to create a DCP for this Film */
 void
-Film::make_dcp (bool transcode)
+Film::make_dcp ()
 {
        set_dci_date_today ();
        
@@ -298,15 +306,26 @@ Film::make_dcp (bool transcode)
 
        shared_ptr<Job> r;
 
-       if (transcode) {
-               if (dcp_ab()) {
-                       r = JobManager::instance()->add (shared_ptr<Job> (new ABTranscodeJob (shared_from_this(), od, shared_ptr<Job> ())));
-               } else {
-                       r = JobManager::instance()->add (shared_ptr<Job> (new TranscodeJob (shared_from_this(), od, shared_ptr<Job> ())));
-               }
+       if (dcp_ab()) {
+               r = JobManager::instance()->add (shared_ptr<Job> (new ABTranscodeJob (shared_from_this(), od)));
+       } else {
+               r = JobManager::instance()->add (shared_ptr<Job> (new TranscodeJob (shared_from_this(), od)));
        }
 }
 
+/** Start a job to analyse the audio of our content file */
+void
+Film::analyse_audio ()
+{
+       if (_analyse_audio_job) {
+               return;
+       }
+
+       _analyse_audio_job.reset (new AnalyseAudioJob (shared_from_this()));
+       _analyse_audio_job->Finished.connect (bind (&Film::analyse_audio_finished, this));
+       JobManager::instance()->add (_analyse_audio_job);
+}
+
 /** Start a job to examine our content file */
 void
 Film::examine_content ()
@@ -315,11 +334,17 @@ Film::examine_content ()
                return;
        }
 
-       _examine_content_job.reset (new ExamineContentJob (shared_from_this(), shared_ptr<Job> ()));
+       _examine_content_job.reset (new ExamineContentJob (shared_from_this()));
        _examine_content_job->Finished.connect (bind (&Film::examine_content_finished, this));
        JobManager::instance()->add (_examine_content_job);
 }
 
+void
+Film::analyse_audio_finished ()
+{
+       _analyse_audio_job.reset ();
+}
+
 void
 Film::examine_content_finished ()
 {
@@ -330,7 +355,7 @@ Film::examine_content_finished ()
 void
 Film::send_dcp_to_tms ()
 {
-       shared_ptr<Job> j (new SCPDCPJob (shared_from_this(), shared_ptr<Job> ()));
+       shared_ptr<Job> j (new SCPDCPJob (shared_from_this()));
        JobManager::instance()->add (j);
 }
 
@@ -874,6 +899,13 @@ Film::set_content (string c)
                        set_content_audio_streams (d.audio->audio_streams ());
                }
 
+               {
+                       boost::mutex::scoped_lock lm (_state_mutex);
+                       _content = c;
+               }
+               
+               signal_changed (CONTENT);
+               
                /* Start off with the first audio and subtitle streams */
                if (d.audio && !d.audio->audio_streams().empty()) {
                        set_content_audio_stream (d.audio->audio_streams().front());
@@ -883,13 +915,6 @@ Film::set_content (string c)
                        set_subtitle_stream (d.video->subtitle_streams().front());
                }
                
-               {
-                       boost::mutex::scoped_lock lm (_state_mutex);
-                       _content = c;
-               }
-               
-               signal_changed (CONTENT);
-               
                examine_content ();
 
        } catch (...) {