Accessor for ClosedCaptionsDialog.
[dcpomatic.git] / src / lib / audio_decoder.cc
index b4aa2bacda401b35d7ca3c5420b210545a9f5450..a5e86f22b8e352d529fa39e69149ad10cca9fec4 100644 (file)
@@ -21,6 +21,7 @@
 #include "audio_decoder.h"
 #include "audio_buffers.h"
 #include "audio_content.h"
+#include "dcpomatic_log.h"
 #include "log.h"
 #include "resampler.h"
 #include "compose.hpp"
 
 #include "i18n.h"
 
-#define LOG_GENERAL(...) _log->log (String::compose (__VA_ARGS__), LogEntry::TYPE_GENERAL);
-
 using std::cout;
 using std::map;
 using std::pair;
 using boost::shared_ptr;
 using boost::optional;
+using namespace dcpomatic;
 
-AudioDecoder::AudioDecoder (Decoder* parent, shared_ptr<const AudioContent> content, shared_ptr<Log> log, bool fast)
-       : DecoderPart (parent, log)
+AudioDecoder::AudioDecoder (Decoder* parent, shared_ptr<const AudioContent> content, bool fast)
+       : DecoderPart (parent)
        , _content (content)
        , _fast (fast)
 {
@@ -49,7 +49,7 @@ AudioDecoder::AudioDecoder (Decoder* parent, shared_ptr<const AudioContent> cont
 }
 
 void
-AudioDecoder::emit (AudioStreamPtr stream, shared_ptr<const AudioBuffers> data, ContentTime time)
+AudioDecoder::emit (shared_ptr<const Film> film, AudioStreamPtr stream, shared_ptr<const AudioBuffers> data, ContentTime time)
 {
        if (ignore ()) {
                return;
@@ -66,7 +66,7 @@ AudioDecoder::emit (AudioStreamPtr stream, shared_ptr<const AudioBuffers> data,
                        silence (_content->delay ());
                }
                time += ContentTime::from_seconds (_content->delay() / 1000.0);
-               _positions[stream] = time.frames_round (_content->resampled_frame_rate ());
+               _positions[stream] = time.frames_round (_content->resampled_frame_rate(film));
        }
 
        shared_ptr<Resampler> resampler;
@@ -74,15 +74,15 @@ AudioDecoder::emit (AudioStreamPtr stream, shared_ptr<const AudioBuffers> data,
        if (i != _resamplers.end ()) {
                resampler = i->second;
        } else {
-               if (stream->frame_rate() != _content->resampled_frame_rate()) {
+               if (stream->frame_rate() != _content->resampled_frame_rate(film)) {
                        LOG_GENERAL (
                                "Creating new resampler from %1 to %2 with %3 channels",
                                stream->frame_rate(),
-                               _content->resampled_frame_rate(),
+                               _content->resampled_frame_rate(film),
                                stream->channels()
                                );
 
-                       resampler.reset (new Resampler (stream->frame_rate(), _content->resampled_frame_rate(), stream->channels()));
+                       resampler.reset (new Resampler (stream->frame_rate(), _content->resampled_frame_rate(film), stream->channels()));
                        if (_fast) {
                                resampler->set_fast ();
                        }
@@ -104,25 +104,25 @@ AudioDecoder::emit (AudioStreamPtr stream, shared_ptr<const AudioBuffers> data,
 
 /** @return Time just after the last thing that was emitted from a given stream */
 ContentTime
-AudioDecoder::stream_position (AudioStreamPtr stream) const
+AudioDecoder::stream_position (shared_ptr<const Film> film, AudioStreamPtr stream) const
 {
        PositionMap::const_iterator i = _positions.find (stream);
        DCPOMATIC_ASSERT (i != _positions.end ());
-       return ContentTime::from_frames (i->second, _content->resampled_frame_rate());
+       return ContentTime::from_frames (i->second, _content->resampled_frame_rate(film));
 }
 
-ContentTime
-AudioDecoder::position () const
+boost::optional<ContentTime>
+AudioDecoder::position (shared_ptr<const Film> film) const
 {
        optional<ContentTime> p;
        for (PositionMap::const_iterator i = _positions.begin(); i != _positions.end(); ++i) {
-               ContentTime const ct = stream_position (i->first);
+               ContentTime const ct = stream_position (film, i->first);
                if (!p || ct < *p) {
                        p = ct;
                }
        }
 
-       return p.get_value_or(ContentTime());
+       return p;
 }
 
 void