Move audio into Encoder so that J2KStillEncoder can use it too. Rename J2KWAVEncoder...
[dcpomatic.git] / src / lib / transcode_job.cc
index 9113593f0c1976c4967df5df7e9c7bea509d38d4..b429c4646e67f751f285e3033d47cf71eef4b72f 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 "film_state.h"
 #include "log.h"
 #include "encoder_factory.h"
+#include "encoder.h"
 
-using namespace std;
-using namespace boost;
+using std::string;
+using std::stringstream;
+using std::fixed;
+using std::setprecision;
+using boost::shared_ptr;
 
-/** @param s FilmState to use.
+/** @param s Film to use.
  *  @param o Options.
- *  @param l A log that we can write to.
+ *  @param req Job that must be completed before this job is run.
  */
-TranscodeJob::TranscodeJob (shared_ptr<const FilmState> s, shared_ptr<const Options> o, Log* l)
-       : Job (s, o, l)
+TranscodeJob::TranscodeJob (shared_ptr<Film> f, shared_ptr<const DecodeOptions> od, shared_ptr<const EncodeOptions> oe, shared_ptr<Job> req)
+       : Job (f, req)
+       , _decode_opt (od)
+       , _encode_opt (oe)
 {
        
 }
@@ -48,9 +52,7 @@ TranscodeJob::TranscodeJob (shared_ptr<const FilmState> s, shared_ptr<const Opti
 string
 TranscodeJob::name () const
 {
-       stringstream s;
-       s << "Transcode " << _fs->name;
-       return s.str ();
+       return String::compose ("Transcode %1", _film->name());
 }
 
 void
@@ -58,24 +60,22 @@ TranscodeJob::run ()
 {
        try {
 
-               _log->log ("Transcode job starting");
+               _film->log()->log ("Transcode job starting");
+               _film->log()->log (String::compose ("Audio delay is %1ms", _film->audio_delay()));
 
-               _encoder = encoder_factory (_fs, _opt, _log);
-               Transcoder w (_fs, _opt, this, _log, _encoder);
+               _encoder = encoder_factory (_film, _encode_opt);
+               Transcoder w (_film, _decode_opt, this, _encoder);
                w.go ();
                set_progress (1);
                set_state (FINISHED_OK);
 
-               _log->log ("Transcode job completed successfully");
+               _film->log()->log ("Transcode job completed successfully");
 
        } catch (std::exception& e) {
 
-               stringstream s;
                set_progress (1);
                set_state (FINISHED_ERROR);
-
-               s << "Transcode job failed (" << e.what() << ")";
-               _log->log (s.str ());
+               _film->log()->log (String::compose ("Transcode job failed (%1)", e.what()));
 
                throw;
        }
@@ -100,7 +100,12 @@ TranscodeJob::status () const
 
        stringstream s;
 
-       s << Job::status () << "; " << fixed << setprecision (1) << fps << " frames per second";
+       s << Job::status ();
+
+       if (!finished ()) {
+               s << "; " << fixed << setprecision (1) << fps << " frames per second";
+       }
+       
        return s.str ();
 }
 
@@ -112,5 +117,11 @@ TranscodeJob::remaining_time () const
                return 0;
        }
 
-       return ((_fs->length - _encoder->last_frame()) / fps);
+       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;
 }