Clean up audio passing round a bit.
[dcpomatic.git] / src / lib / decoder.h
index 198dfb8dcb6d1ccd0cb2f52fc5119aa6d785e981..85b256f5bbe592629b8dad0c2b9c12396816aa73 100644 (file)
 #include <stdint.h>
 #include <boost/shared_ptr.hpp>
 #include <sigc++/sigc++.h>
-extern "C" {
-#include <libswresample/swresample.h>
-}      
 #include "util.h"
+#include "stream.h"
 
 class Job;
 class FilmState;
@@ -40,6 +38,8 @@ class Options;
 class Image;
 class Log;
 class DelayLine;
+class TimedSubtitle;
+class Subtitle;
 
 /** @class Decoder.
  *  @brief Parent class for decoders of content.
@@ -69,6 +69,7 @@ public:
        /** @return format of audio samples */
        virtual AVSampleFormat audio_sample_format () const = 0;
        virtual int64_t audio_channel_layout () const = 0;
+       virtual bool has_subtitles () const = 0;
 
        void process_begin ();
        bool pass ();
@@ -79,20 +80,27 @@ public:
        int last_video_frame () const {
                return _video_frame;
        }
+
+       virtual std::vector<Stream> audio_streams () const {
+               return std::vector<Stream> ();
+       }
        
-       int decoding_frames () const;
+       virtual std::vector<Stream> subtitle_streams () const {
+               return std::vector<Stream> ();
+       }
 
+       virtual void set_audio_stream (Stream s) {}
+       virtual void set_subtitle_stream (Stream s) {}
+       
        /** Emitted when a video frame is ready.
         *  First parameter is the frame.
         *  Second parameter is its index within the content.
+        *  Third parameter is either 0 or a subtitle that should be on this frame.
         */
-       sigc::signal<void, boost::shared_ptr<Image>, int> Video;
+       sigc::signal<void, boost::shared_ptr<Image>, int, boost::shared_ptr<Subtitle> > Video;
 
-       /** Emitted when some audio data is ready.
-        *  First parameter is the interleaved sample data, format is given in the FilmState.
-        *  Second parameter is the size of the data.
-        */
-       sigc::signal<void, uint8_t *, int> Audio;
+       /** Emitted when some audio data is ready */
+       sigc::signal<void, boost::shared_ptr<AudioBuffers> > Audio;
        
 protected:
        /** perform a single pass at our content */
@@ -104,7 +112,8 @@ protected:
        virtual int sample_aspect_ratio_denominator () const = 0;
        
        void process_video (AVFrame *);
-       void process_audio (uint8_t *, int, int);
+       void process_audio (uint8_t *, int);
+       void process_subtitle (boost::shared_ptr<TimedSubtitle>);
 
        /** our FilmState */
        boost::shared_ptr<const FilmState> _fs;
@@ -125,6 +134,8 @@ protected:
 
 private:
        void setup_video_filters ();
+       void emit_audio (uint8_t* data, int size);
+       int bytes_per_audio_sample () const;
        
        /** last video frame to be processed */
        int _video_frame;
@@ -132,8 +143,6 @@ private:
        AVFilterContext* _buffer_src_context;
        AVFilterContext* _buffer_sink_context;
 
-       SwrContext* _swr_context;
-
        bool _have_setup_video_filters;
        DelayLine* _delay_line;
        int _delay_in_bytes;
@@ -141,7 +150,9 @@ private:
        /* Number of audio frames that we have pushed to the encoder
           (at the DCP sample rate).
        */
-       int _audio_frames_processed;
+       int64_t _audio_frames_processed;
+
+       boost::shared_ptr<TimedSubtitle> _timed_subtitle;
 };
 
 #endif