Use SafeStringStream instead of std::stringstream to try to fix random crashes on...
[dcpomatic.git] / src / lib / player.cc
index 68df8ea709afd905955be97dd410366092f5a612..2d2977606786097f6b827ec07a8048dd7c90da59 100644 (file)
@@ -36,6 +36,7 @@
 #include "log.h"
 #include "scaler.h"
 #include "player_video_frame.h"
+#include "frame_rate_change.h"
 
 #define LOG_GENERAL(...) _film->log()->log (String::compose (__VA_ARGS__), Log::TYPE_GENERAL);
 
@@ -94,7 +95,7 @@ Player::pass ()
        } type = VIDEO;
 
        for (list<shared_ptr<Piece> >::iterator i = _pieces.begin(); i != _pieces.end(); ++i) {
-               if ((*i)->decoder->done ()) {
+               if ((*i)->decoder->done () || (*i)->content->length_after_trim() == 0) {
                        continue;
                }
 
@@ -149,7 +150,12 @@ Player::pass ()
                                if (re) {
                                        shared_ptr<const AudioBuffers> b = re->flush ();
                                        if (b->frames ()) {
-                                               process_audio (earliest, b, ac->audio_length (), true);
+                                               process_audio (
+                                                       earliest,
+                                                       b,
+                                                       ac->audio_length() * ac->output_audio_frame_rate() / ac->content_audio_frame_rate(),
+                                                       true
+                                                       );
                                        }
                                }
                        }
@@ -201,7 +207,7 @@ Player::process_video (weak_ptr<Piece> weak_piece, shared_ptr<const ImageProxy>
        shared_ptr<VideoContent> content = dynamic_pointer_cast<VideoContent> (piece->content);
        assert (content);
 
-       FrameRateConversion frc (content->video_frame_rate(), _film->video_frame_rate());
+       FrameRateChange frc (content->video_frame_rate(), _film->video_frame_rate());
        if (frc.skip && (frame % 2) == 1) {
                return;
        }