Various bits.
[dcpomatic.git] / src / lib / encoder.h
index 96e7a1d25e08742597da886b84e0346c89de1caf..86880bc34942561ba12a1488feb00663c2c9d6d8 100644 (file)
@@ -21,7 +21,7 @@
 #define DVDOMATIC_ENCODER_H
 
 /** @file src/encoder.h
- *  @brief Parent class for classes which can encode video and audio frames.
+ *  @brief Encoder to J2K and WAV for DCP.
  */
 
 #include <boost/shared_ptr.hpp>
@@ -39,7 +39,6 @@ extern "C" {
 #include <libswresample/swresample.h>
 }
 #endif
-#include <sndfile.h>
 #include "util.h"
 #include "video_sink.h"
 #include "audio_sink.h"
@@ -51,6 +50,7 @@ class Film;
 class ServerDescription;
 class DCPVideoFrame;
 class EncodedData;
+class Writer;
 
 /** @class Encoder
  *  @brief Encoder to J2K and WAV for DCP.
@@ -62,7 +62,7 @@ class EncodedData;
 class Encoder : public VideoSink, public AudioSink
 {
 public:
-       Encoder (boost::shared_ptr<const Film> f);
+       Encoder (boost::shared_ptr<Film> f);
        virtual ~Encoder ();
 
        /** Called to indicate that a processing run is about to begin */
@@ -82,25 +82,21 @@ public:
        virtual void process_end ();
 
        float current_frames_per_second () const;
-       bool skipping () const;
        int video_frames_out () const;
 
 private:
        
        void frame_done ();
-       void frame_skipped ();
        
-       void close_sound_files ();
-       void write_audio (boost::shared_ptr<const AudioBuffers> audio);
+       void write_audio (boost::shared_ptr<const AudioBuffers> data);
 
        void encoder_thread (ServerDescription *);
-       void terminate_worker_threads ();
-       void link (std::string, std::string) const;
+       void terminate_threads ();
 
        /** Film that we are encoding */
-       boost::shared_ptr<const Film> _film;
+       boost::shared_ptr<Film> _film;
 
-       /** Mutex for _time_history, _just_skipped and _last_frame */
+       /** Mutex for _time_history and _last_frame */
        mutable boost::mutex _history_mutex;
        /** List of the times of completion of the last _history_size frames;
            first is the most recently completed.
@@ -108,46 +104,24 @@ private:
        std::list<struct timeval> _time_history;
        /** Number of frames that we should keep history for */
        static int const _history_size;
-       /** true if the last frame we processed was skipped (because it was already done) */
-       bool _just_skipped;
 
        /** Number of video frames received so far */
        SourceFrame _video_frames_in;
-       /** Number of audio frames received so far */
-       int64_t _audio_frames_in;
        /** Number of video frames written for the DCP so far */
        int _video_frames_out;
-       /** Number of audio frames written for the DCP so far */
-       int64_t _audio_frames_out;
-
-       void writer_thread ();
-       void terminate_writer_thread ();
 
 #if HAVE_SWRESAMPLE    
        SwrContext* _swr_context;
 #endif
 
-       /** List of links that we need to create when all frames have been processed;
-        *  such that we need to call link (first, second) for each member of this list.
-        *  In other words, `first' is a `real' frame and `second' should be a link to `first'.
-        *  Frames are DCP frames.
-        */
-       std::list<std::pair<int, int> > _links_required;
-
-       std::vector<SNDFILE*> _sound_files;
-
-       boost::optional<int> _last_real_frame;
-       bool _terminate_encoder;
-       std::list<boost::shared_ptr<DCPVideoFrame> > _encode_queue;
-       std::list<boost::thread *> _worker_threads;
-       mutable boost::mutex _worker_mutex;
-       boost::condition _worker_condition;
-
-       boost::thread* _writer_thread;
-       bool _terminate_writer;
-       std::list<std::pair<boost::shared_ptr<EncodedData>, int> > _write_queue;
-       mutable boost::mutex _writer_mutex;
-       boost::condition _writer_condition;
+       bool _have_a_real_frame;
+       bool _terminate;
+       std::list<boost::shared_ptr<DCPVideoFrame> > _queue;
+       std::list<boost::thread *> _threads;
+       mutable boost::mutex _mutex;
+       boost::condition _condition;
+
+       boost::shared_ptr<Writer> _writer;
 };
 
 #endif