Fix lack of audio with trimmed DCPs.
[dcpomatic.git] / src / lib / transcode_job.cc
index 5e9e58667864b2dbf533ed7574b5eddb5b68e4ca..dfb9b107192748f7dbe8c6b4f2280cd69fa05057 100644 (file)
 #include <iostream>
 #include <iomanip>
 #include "transcode_job.h"
-#include "j2k_wav_encoder.h"
 #include "film.h"
 #include "format.h"
 #include "transcoder.h"
 #include "log.h"
-#include "encoder_factory.h"
+#include "encoder.h"
 
 using std::string;
 using std::stringstream;
@@ -39,10 +38,12 @@ using boost::shared_ptr;
 
 /** @param s Film to use.
  *  @param o Options.
+ *  @param req Job that must be completed before this job is run.
  */
-TranscodeJob::TranscodeJob (shared_ptr<Film> f, shared_ptr<const Options> o, shared_ptr<Job> req)
+TranscodeJob::TranscodeJob (shared_ptr<Film> f, shared_ptr<const DecodeOptions> od, shared_ptr<const EncodeOptions> oe, shared_ptr<Job> req)
        : Job (f, req)
-       , _opt (o)
+       , _decode_opt (od)
+       , _encode_opt (oe)
 {
        
 }
@@ -61,8 +62,8 @@ TranscodeJob::run ()
                _film->log()->log ("Transcode job starting");
                _film->log()->log (String::compose ("Audio delay is %1ms", _film->audio_delay()));
 
-               _encoder = encoder_factory (_film, _opt);
-               Transcoder w (_film, _opt, this, _encoder);
+               _encoder.reset (new Encoder (_film, _encode_opt));
+               Transcoder w (_film, _decode_opt, this, _encoder);
                w.go ();
                set_progress (1);
                set_state (FINISHED_OK);
@@ -115,7 +116,11 @@ TranscodeJob::remaining_time () const
                return 0;
        }
 
-       /* We assume that dcp_length() is valid */
+       if (!_film->dcp_length()) {
+               return 0;
+       }
+
+       /* We assume that dcp_length() is valid, if it is set */
        SourceFrame const left = _film->dcp_trim_start() + _film->dcp_length().get() - _encoder->video_frame();
        return left / fps;
 }