Take Film pointer out of Content.
[dcpomatic.git] / src / lib / audio_decoder.h
index fbb1ad4d45f8d9a0988c3706dcd46564df45a6ec..50e361e8f19f80cb181bc8a55d3e80f1aa73da8c 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 #include "decoder.h"
 #include "content_audio.h"
 #include "audio_stream.h"
+#include "decoder_part.h"
 #include <boost/enable_shared_from_this.hpp>
+#include <boost/signals2.hpp>
 
 class AudioBuffers;
 class AudioContent;
 class AudioDecoderStream;
 class Log;
+class Film;
+class Resampler;
 
 /** @class AudioDecoder.
  *  @brief Parent class for audio decoders.
  */
-class AudioDecoder : public boost::enable_shared_from_this<AudioDecoder>
+class AudioDecoder : public boost::enable_shared_from_this<AudioDecoder>, public DecoderPart
 {
 public:
-       AudioDecoder (Decoder* parent, boost::shared_ptr<const AudioContent>, bool fast, boost::shared_ptr<Log> log);
+       AudioDecoder (Decoder* parent, boost::shared_ptr<const AudioContent> content, bool fast);
 
-       /** Try to fetch some audio from a specific place in this content.
-        *  @param frame Frame to start from (after resampling, if applicable)
-        *  @param length Frames to get (after resampling, if applicable)
-        *  @param accurate true to try hard to return frames from exactly `frame', false if we don't mind nearby frames.
-        *  @return Time-stamped audio data which may or may not be from the location (and of the length) requested.
-        */
-       ContentAudio get (AudioStreamPtr stream, Frame time, Frame length, bool accurate);
-
-       void set_ignore ();
+       ContentTime position (boost::shared_ptr<const Film> film) const;
+       void emit (boost::shared_ptr<const Film> film, AudioStreamPtr stream, boost::shared_ptr<const AudioBuffers>, ContentTime);
+       void seek ();
+       void flush ();
 
-       bool fast () const {
-               return _fast;
-       }
+       ContentTime stream_position (boost::shared_ptr<const Film> film, AudioStreamPtr stream) const;
 
-       void give (AudioStreamPtr stream, boost::shared_ptr<const AudioBuffers>, ContentTime);
-       void flush ();
-       void seek (ContentTime t, bool accurate);
+       /** @return Number of frames of data that were accepted */
+       boost::signals2::signal<void (AudioStreamPtr, ContentAudio)> Data;
 
 private:
-       /** An AudioDecoderStream object to manage each stream in _audio_content */
-       std::map<AudioStreamPtr, boost::shared_ptr<AudioDecoderStream> > _streams;
-       bool _ignore;
+       void silence (int milliseconds);
+
+       boost::shared_ptr<const AudioContent> _content;
+       /** Frame after the last one that was emitted from Data (i.e. at the resampled rate, if applicable)
+        *  for each AudioStream.
+        */
+       typedef std::map<AudioStreamPtr, Frame> PositionMap;
+       PositionMap _positions;
+       typedef std::map<AudioStreamPtr, boost::shared_ptr<Resampler> > ResamplerMap;
+       ResamplerMap _resamplers;
+
        bool _fast;
 };