Various fixes.
authorCarl Hetherington <cth@carlh.net>
Sun, 16 Dec 2012 14:04:05 +0000 (14:04 +0000)
committerCarl Hetherington <cth@carlh.net>
Sun, 16 Dec 2012 14:04:05 +0000 (14:04 +0000)
src/lib/ffmpeg_decoder.cc
src/lib/imagemagick_decoder.cc
src/lib/video_decoder.cc
src/lib/video_decoder.h
src/wx/film_viewer.cc
src/wx/film_viewer.h

index 9fd6a0c05b91ad7e726b0b72e15a254ed07ac6f8..314ab7c06f99095073420e06f9f6affe9e1cb232 100644 (file)
@@ -547,8 +547,11 @@ FFmpegDecoder::filter_and_emit_video (AVFrame* frame)
 
        list<shared_ptr<Image> > images = graph->process (frame);
 
+       SourceFrame const sf = av_q2d (_format_context->streams[_video_stream]->time_base)
+               * av_frame_get_best_effort_timestamp(_frame) * frames_per_second();
+
        for (list<shared_ptr<Image> >::iterator i = images.begin(); i != images.end(); ++i) {
-               emit_video (*i);
+               emit_video (*i, sf);
        }
 }
 
@@ -558,11 +561,6 @@ FFmpegDecoder::seek (SourceFrame f)
        int64_t const t = static_cast<int64_t>(f) / (av_q2d (_format_context->streams[_video_stream]->time_base) * frames_per_second());
        int const r = av_seek_frame (_format_context, _video_stream, t, 0);
        avcodec_flush_buffers (_video_codec_context);
-
-       if (r >= 0) {
-               OutputChanged ();
-       }
-       
        return r < 0;
 }
 
index 3957da5ddd1df8e01be6306b6f4657d93733c146..9d11e043f4ceb7a46a71ab1b8a6fc54290c3bb37 100644 (file)
@@ -92,7 +92,7 @@ ImageMagickDecoder::pass ()
 
        delete magick_image;
        
-       emit_video (image);
+       emit_video (image, 0);
 
        ++_iter;
        return false;
index a8da40b7c39e08ada1e013d7cd90b8d157ff17c3..d3b441fbfc1d859ef6300ac97455414ddef6d3a1 100644 (file)
@@ -31,16 +31,17 @@ using boost::optional;
 VideoDecoder::VideoDecoder (shared_ptr<Film> f, shared_ptr<const DecodeOptions> o, Job* j)
        : Decoder (f, o, j)
        , _video_frame (0)
+       , _last_source_frame (0)
 {
 
 }
 
 /** Called by subclasses to tell the world that some video data is ready.
  *  We find a subtitle then emit it for listeners.
- *  @param frame to decode; caller manages memory.
+ *  @param frame to emit.
  */
 void
-VideoDecoder::emit_video (shared_ptr<Image> image)
+VideoDecoder::emit_video (shared_ptr<Image> image, SourceFrame f)
 {
        shared_ptr<Subtitle> sub;
        if (_timed_subtitle && _timed_subtitle->displayed_at (double (video_frame()) / _film->frames_per_second())) {
@@ -48,6 +49,7 @@ VideoDecoder::emit_video (shared_ptr<Image> image)
        }
 
        signal_video (image, sub);
+       _last_source_frame = f;
 }
 
 void
index a8296d918badc5b8ce61a0481bfb03752d56bfa3..41e876e0a58c59cf4af2e62fe69429cda0d83736 100644 (file)
@@ -55,11 +55,15 @@ public:
                return _subtitle_streams;
        }
 
+       SourceFrame last_source_frame () const {
+               return _last_source_frame;
+       }
+
 protected:
        
        virtual PixelFormat pixel_format () const = 0;
 
-       void emit_video (boost::shared_ptr<Image>);
+       void emit_video (boost::shared_ptr<Image>, SourceFrame);
        void emit_subtitle (boost::shared_ptr<TimedSubtitle>);
        void repeat_last_video ();
 
@@ -72,7 +76,8 @@ private:
        void signal_video (boost::shared_ptr<Image>, boost::shared_ptr<Subtitle>);
 
        SourceFrame _video_frame;
-
+       SourceFrame _last_source_frame;
+       
        boost::shared_ptr<TimedSubtitle> _timed_subtitle;
 
        boost::shared_ptr<Image> _last_image;
index 80516328c7682bc6779f1387a196419033ee740a..241b60e8a6bfbc81820b7ba64d5102f48c195599 100644 (file)
@@ -118,12 +118,7 @@ FilmViewer::set_film (shared_ptr<Film> f)
 void
 FilmViewer::decoder_changed ()
 {
-       shared_ptr<Image> last = _display;
-       while (last == _display) {
-               _decoders.video->pass ();
-       }
-       _panel->Refresh ();
-       _panel->Update ();
+       seek_and_update (_decoders.video->last_source_frame ());
 }
 
 void
@@ -137,15 +132,10 @@ FilmViewer::timer (wxTimerEvent& ev)
                _decoders.video->pass ();
        }
 
-#if 0  
-       if (_last_frame_in_seconds) {
-               double const video_length_in_seconds = static_cast<double>(_format_context->duration) / AV_TIME_BASE;
-               int const new_slider_position = 4096 * _last_frame_in_seconds / video_length_in_seconds;
-               if (new_slider_position != _slider->GetValue()) {
-                       _slider->SetValue (new_slider_position);
-               }
+       int const new_slider_position = 4096 * _decoders.video->last_source_frame() / _film->length().get();
+       if (new_slider_position != _slider->GetValue()) {
+               _slider->SetValue (new_slider_position);
        }
-#endif 
 }
 
 
@@ -166,7 +156,20 @@ FilmViewer::paint_panel (wxPaintEvent& ev)
 void
 FilmViewer::slider_moved (wxCommandEvent& ev)
 {
-       _decoders.video->seek (_slider->GetValue() * _film->length().get() / 4096);
+       seek_and_update (_slider->GetValue() * _film->length().get() / 4096);
+}
+
+void
+FilmViewer::seek_and_update (SourceFrame f)
+{
+       _decoders.video->seek (f);
+       
+       shared_ptr<Image> last = _display;
+       while (last == _display) {
+               _decoders.video->pass ();
+       }
+       _panel->Refresh ();
+       _panel->Update ();
 }
 
 void
index b1d0b99d34bafd3bc502e1968c8c9b0fdce81adb..8194d02062932ab930146699991e5e653bc59ce9 100644 (file)
@@ -52,6 +52,7 @@ private:
        void check_play_state ();
        void update_from_raw ();
        void decoder_changed ();
+       void seek_and_update (SourceFrame);
 
        boost::shared_ptr<Film> _film;