Seeking tweaks.
authorCarl Hetherington <cth@carlh.net>
Fri, 24 May 2013 16:36:41 +0000 (17:36 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 24 May 2013 16:36:41 +0000 (17:36 +0100)
src/lib/black_decoder.cc
src/lib/black_decoder.h
src/lib/decoder.h
src/lib/imagemagick_decoder.cc
src/lib/imagemagick_decoder.h
src/lib/player.cc
src/lib/player.h
src/lib/silence_decoder.cc
src/lib/silence_decoder.h
src/lib/sndfile_decoder.h

index e8e1a3df2e2ce967bb5ae79d0fcfef16a82e85da..3cdd5eef5c7202e28aa37ef17fd46963b06e0c2d 100644 (file)
@@ -70,3 +70,25 @@ BlackDecoder::seek (Time t)
 {
        _next_video = t;
 }
+
+void
+BlackDecoder::seek_back ()
+{
+       boost::shared_ptr<const Film> f = _film.lock ();
+       if (!f) {
+               return;
+       }
+
+       _next_video -= f->video_frames_to_time (2);
+}
+
+void
+BlackDecoder::seek_forward ()
+{
+       boost::shared_ptr<const Film> f = _film.lock ();
+       if (!f) {
+               return;
+       }
+
+       _next_video += f->video_frames_to_time (1);
+}
index b4beb0fdd4da2f61a3a0a3289bb06f1ff5d30cd4..3aa63e22f23c5c07aac6d4c9d4eeb4f41348ae9a 100644 (file)
@@ -30,6 +30,8 @@ public:
        
        void pass ();
        void seek (Time);
+       void seek_back ();
+       void seek_forward ();
        Time next () const;
 
        /* VideoDecoder */
index be9555dc4ffccb21b1c45ebd3d7fda4880d96e13..edb532b9cc8474e0e474ac882d95d114fae71925 100644 (file)
@@ -57,14 +57,15 @@ public:
        /** Seek this decoder to as close as possible to some time,
         *  expressed relative to our source's start.
         *  @param t Time.
+        *  @param a true to try hard to be accurate, otherwise false.
         */
-       virtual void seek (Time) {}
+       virtual void seek (Time) = 0;
 
        /** Seek back one video frame */
-       virtual void seek_back () {}
+       virtual void seek_back () = 0;
 
        /** Seek forward one video frame */
-       virtual void seek_forward () {}
+       virtual void seek_forward () = 0;
 
        /** @return Approximate time of the next content that we will emit,
         *  expressed relative to the start of our source.
index b2bbb4118299dc7213b217c4d0ca8989d5a950f1..15c919e87ac3e867f9cbbf3ab97a2bb3ebf3a013 100644 (file)
@@ -111,6 +111,28 @@ ImageMagickDecoder::seek (Time t)
        _next_video = t;
 }
 
+void
+ImageMagickDecoder::seek_back ()
+{
+       boost::shared_ptr<const Film> f = _film.lock ();
+       if (!f) {
+               return;
+       }
+       
+       _next_video -= f->video_frames_to_time (2);
+}
+
+void
+ImageMagickDecoder::seek_forward ()
+{
+       boost::shared_ptr<const Film> f = _film.lock ();
+       if (!f) {
+               return;
+       }
+       
+       _next_video += f->video_frames_to_time (1);
+}
+
 Time
 ImageMagickDecoder::next () const
 {
index 26dbb8ca0dbbb0626e16466595a2871ce7692e52..6640032babe4f376a29732fe9edcc1517a55a9e0 100644 (file)
@@ -34,6 +34,8 @@ public:
 
        void pass ();
        void seek (Time);
+       void seek_back ();
+       void seek_forward ();
        Time next () const;
 
        /* VideoDecoder */
index 8a13efd0c7e7e3b5734027a5c5bab6abec5a173c..d3886721b1849b47aff45ffd781a364c8cac0508 100644 (file)
@@ -103,13 +103,14 @@ Player::pass ()
         shared_ptr<Piece> earliest;
 
        for (list<shared_ptr<Piece> >::iterator i = _pieces.begin(); i != _pieces.end(); ++i) {
-//             cout << "check " << (*i)->decoder->next() << " cf " << (*i)->content->end() << "\n";
+               cout << "check " << (*i)->content->file() << " start=" << (*i)->content->start() << ", next=" << (*i)->decoder->next() << ", end=" << (*i)->content->end() << "\n";
                if (((*i)->decoder->next() + (*i)->content->start()) >= (*i)->content->end()) {
                        continue;
                }
                
                Time const t = (*i)->content->start() + (*i)->decoder->next();
                if (t < earliest_t) {
+                       cout << "\t candidate; " << t << " " << (t / TIME_HZ) << ".\n";
                        earliest_t = t;
                        earliest = *i;
                }
@@ -120,7 +121,7 @@ Player::pass ()
        }
 
        cout << "PASS:\n";
-       cout << "\tpass ";
+       cout << "\tpass " << earliest->content->file() << " ";
        if (dynamic_pointer_cast<FFmpegContent> (earliest->content)) {
                cout << " FFmpeg.\n";
        } else if (dynamic_pointer_cast<ImageMagickContent> (earliest->content)) {
@@ -135,6 +136,7 @@ Player::pass ()
        
        earliest->decoder->pass ();
        _position = earliest->content->start() + earliest->decoder->next ();
+       cout << "\tpassed to " << _position << " " << (_position / TIME_HZ) << "\n";
 
         return false;
 }
@@ -142,6 +144,8 @@ Player::pass ()
 void
 Player::process_video (weak_ptr<Content> weak_content, shared_ptr<const Image> image, bool same, shared_ptr<Subtitle> sub, Time time)
 {
+       cout << "[V]\n";
+       
        shared_ptr<Content> content = weak_content.lock ();
        if (!content) {
                return;
@@ -207,6 +211,7 @@ Player::seek (Time t)
                Time s = t - (*i)->content->start ();
                s = max (static_cast<Time> (0), s);
                s = min ((*i)->content->length(), s);
+               cout << "seek [" << (*i)->content->file() << "," << (*i)->content->start() << "," << (*i)->content->end() << "] to " << s << "\n";
                (*i)->decoder->seek (s);
        }
 
@@ -217,13 +222,13 @@ Player::seek (Time t)
 void
 Player::seek_back ()
 {
-       /* XXX */
+
 }
 
 void
 Player::seek_forward ()
 {
-       /* XXX */
+
 }
 
 struct ContentSorter
index a5fe844f0af88ca76321c5163c8afa5fa18134dc..4d23d1951ab53b9256b4e471bc9080f93229ba07 100644 (file)
@@ -67,6 +67,7 @@ private:
        void setup_pieces ();
        void playlist_changed ();
        void content_changed (boost::weak_ptr<Content>, int);
+       void do_seek (Time, bool);
 
        boost::shared_ptr<const Film> _film;
        boost::shared_ptr<const Playlist> _playlist;
index 9eee5bb108baa495d96ea7c4d3056a228fe32ad3..e787262f5054510e6b4117ee96e6e8a5691b53ae 100644 (file)
@@ -49,6 +49,28 @@ SilenceDecoder::seek (Time t)
        _next_audio = t;
 }
 
+void
+SilenceDecoder::seek_back ()
+{
+       boost::shared_ptr<const Film> f = _film.lock ();
+       if (!f) {
+               return;
+       }
+
+       _next_audio -= f->video_frames_to_time (2);
+}
+
+void
+SilenceDecoder::seek_forward ()
+{
+       boost::shared_ptr<const Film> f = _film.lock ();
+       if (!f) {
+               return;
+       }
+
+       _next_audio += f->video_frames_to_time (1);
+}
+
 Time
 SilenceDecoder::next () const
 {
index e2a004d618543da126246adcdf29b51741db9843..8452bc43f99c2a88629f94aadb6c3191ada15eb1 100644 (file)
@@ -30,5 +30,7 @@ public:
 
        void pass ();
        void seek (Time);
+       void seek_back ();
+       void seek_forward ();
        Time next () const;
 };
index 1dc484fdc92bf2bef5a80717951c6a17ca9cbdf0..b4fa5bc58a8a5538bd6e711f5dc2478664e8e9a2 100644 (file)
@@ -30,6 +30,9 @@ public:
        ~SndfileDecoder ();
 
        void pass ();
+       void seek (Time) {}
+       void seek_back () {}
+       void seek_forward () {}
        Time next () const;
 
        int audio_channels () const;