Some fixes to playback of drop-frame content.
authorCarl Hetherington <cth@carlh.net>
Tue, 24 Dec 2013 02:52:35 +0000 (02:52 +0000)
committerCarl Hetherington <cth@carlh.net>
Tue, 24 Dec 2013 02:52:35 +0000 (02:52 +0000)
src/lib/decoder.cc
src/lib/decoder.h
src/lib/player.cc
test/seek_zero_test.cc

index 18c5acd3551b3442eea6e8882d16f08f658f48b2..7f4973737faff0146f971f91c846cc4c8a5dabef 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "film.h"
 #include "decoder.h"
+#include "decoded.h"
 
 #include "i18n.h"
 
@@ -37,10 +38,19 @@ Decoder::Decoder (shared_ptr<const Film> f)
 
 }
 
+class DecodedSorter
+{
+public:
+       bool operator() (shared_ptr<Decoded> a, shared_ptr<Decoded> b)
+       {
+               return a->dcp_time < b->dcp_time;
+       }
+};
+
 shared_ptr<Decoded>
 Decoder::peek ()
 {
-       while (_pending.empty () && !pass ()) {}
+       while (_pending.empty() && !pass ()) {}
 
        if (_pending.empty ()) {
                return shared_ptr<Decoded> ();
@@ -49,15 +59,12 @@ Decoder::peek ()
        return _pending.front ();
 }
 
-shared_ptr<Decoded>
-Decoder::get ()
+void
+Decoder::consume ()
 {
-       shared_ptr<Decoded> d = peek ();
-       if (d) {
+       if (!_pending.empty ()) {
                _pending.pop_front ();
        }
-
-       return d;
 }
 
 void
index 654cacad4bc63d71131483422fcb231fe9a0729a..1c6aff3596c24d157c1d48d60249040a6fc45753 100644 (file)
@@ -49,7 +49,7 @@ public:
        virtual void seek (ContentTime time, bool accurate);
        
        boost::shared_ptr<Decoded> peek ();
-       boost::shared_ptr<Decoded> get ();
+       void consume ();
 
 protected:
 
index 0f2cc0365d642ca1489f07a757d143d7178e8583..3e282136fe604db7443564ba2034975353ab8c52 100644 (file)
@@ -147,7 +147,7 @@ Player::pass ()
                if (_just_did_inaccurate_seek) {
                        /* Just emit; no subtlety */
                        emit_video (earliest_piece, dv);
-                       earliest_piece->decoder->get ();
+                       earliest_piece->decoder->consume ();
                } else if (earliest_time > (_video_position + half_frame)) {
 
                        /* See if we're inside some video content */
@@ -167,14 +167,14 @@ Player::pass ()
                } else {
 
                        if (
-                               dv->dcp_time >= _video_position &&
+                               abs (dv->dcp_time - _video_position) < half_frame &&
                                !earliest_piece->content->trimmed (dv->dcp_time - earliest_piece->content->position ())
                                ) {
 
                                emit_video (earliest_piece, dv);
                        }
                
-                       earliest_piece->decoder->get ();
+                       earliest_piece->decoder->consume ();
                }
 
        } else if (da && _audio) {
@@ -182,13 +182,13 @@ Player::pass ()
                        emit_silence (earliest_time - _audio_position);
                } else {
                        emit_audio (earliest_piece, da);
-                       earliest_piece->decoder->get ();
+                       earliest_piece->decoder->consume ();
                }
        } else if (ds && _video) {
                _in_subtitle.piece = earliest_piece;
                _in_subtitle.subtitle = ds;
                update_subtitle ();
-               earliest_piece->decoder->get ();
+               earliest_piece->decoder->consume ();
        }
 
        _just_did_inaccurate_seek = false;
index d298a772bf91c8f2f887367b7b04c58d46c44a31..0987f6b9b20e44f9a48da63a68cf2cb3fece309f 100644 (file)
@@ -45,10 +45,10 @@ BOOST_AUTO_TEST_CASE (seek_zero_test)
        wait_for_jobs ();
 
        FFmpegDecoder decoder (film, content, true, false);
-       shared_ptr<Decoded> a = decoder.get ();
+       shared_ptr<Decoded> a = decoder.peek ();
        cout << a->content_time << "\n";
        decoder.seek (0, true);
-       shared_ptr<Decoded> b = decoder.get ();
+       shared_ptr<Decoded> b = decoder.peek ();
        cout << b->content_time << "\n";
 
        /* a will be after no seek, and b after a seek to zero, which should