Decoder handles crop changing.
authorCarl Hetherington <cth@carlh.net>
Sun, 16 Dec 2012 13:43:25 +0000 (13:43 +0000)
committerCarl Hetherington <cth@carlh.net>
Sun, 16 Dec 2012 13:43:25 +0000 (13:43 +0000)
src/lib/decoder.h
src/lib/ffmpeg_decoder.cc
src/lib/ffmpeg_decoder.h
src/wx/film_viewer.cc
src/wx/film_viewer.h

index be1fe38b6ef2ff52e6f0b6e22b4ec7785af5baf9..0d35ebb3a01675c3b75e7961f2975154dc4d9724 100644 (file)
@@ -63,6 +63,8 @@ public:
         */
        virtual bool seek (SourceFrame);
 
+       boost::signals2::signal<void()> OutputChanged;
+
 protected:
        /** our Film */
        boost::shared_ptr<Film> _film;
index b3b1acbbb4463dea5824dfcd5de6467d39bd8d34..51afc461a86d36a2d90bde325cf6a6f98c8d3458 100644 (file)
@@ -77,6 +77,8 @@ FFmpegDecoder::FFmpegDecoder (shared_ptr<Film> f, shared_ptr<const DecodeOptions
        setup_video ();
        setup_audio ();
        setup_subtitle ();
+
+       f->Changed.connect (bind (&FFmpegDecoder::film_changed, this, _1));
 }
 
 FFmpegDecoder::~FFmpegDecoder ()
@@ -526,6 +528,8 @@ FFmpegDecoder::set_subtitle_stream (shared_ptr<SubtitleStream> s)
 void
 FFmpegDecoder::filter_and_emit_video (AVFrame* frame)
 {
+       boost::mutex::scoped_lock lm (_filter_graphs_mutex);
+       
        shared_ptr<FilterGraph> graph;
 
        list<shared_ptr<FilterGraph> >::iterator i = _filter_graphs.begin();
@@ -554,6 +558,11 @@ 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;
 }
 
@@ -655,3 +664,21 @@ FFmpegDecoder::out_careful ()
                _film->log()->log (String::compose ("Frame removed at %1s", out_pts_seconds));
        }
 }
+
+void
+FFmpegDecoder::film_changed (Film::Property p)
+{
+       switch (p) {
+       case Film::CROP:
+       {
+               boost::mutex::scoped_lock lm (_filter_graphs_mutex);
+               _filter_graphs.clear ();
+       }
+       OutputChanged ();
+       break;
+
+       default:
+               break;
+       }
+}
+
index d483db1d97a418a40919d9855ac704200747e031..d5753393ece341e76c02851ebe6e3768681a9830 100644 (file)
@@ -26,6 +26,7 @@
 #include <stdint.h>
 #include <boost/shared_ptr.hpp>
 #include <boost/optional.hpp>
+#include <boost/thread/mutex.hpp>
 extern "C" {
 #include <libavcodec/avcodec.h>
 #include <libpostproc/postprocess.h>
@@ -34,6 +35,7 @@ extern "C" {
 #include "decoder.h"
 #include "video_decoder.h"
 #include "audio_decoder.h"
+#include "film.h"
 
 struct AVFilterGraph;
 struct AVCodecContext;
@@ -117,6 +119,8 @@ private:
        void maybe_add_subtitle ();
        boost::shared_ptr<AudioBuffers> deinterleave_audio (uint8_t* data, int size);
 
+       void film_changed (Film::Property);
+
        std::string stream_name (AVStream* s) const;
 
        AVFormatContext* _format_context;
@@ -137,4 +141,5 @@ private:
        boost::optional<double> _first_audio;
 
        std::list<boost::shared_ptr<FilterGraph> > _filter_graphs;
+       boost::mutex _filter_graphs_mutex;
 };
index 1ed560428e32777ef601422019d3389f7a2e1034..80516328c7682bc6779f1387a196419033ee740a 100644 (file)
@@ -109,11 +109,23 @@ FilmViewer::set_film (shared_ptr<Film> f)
        o->video_sync = false;
        _decoders = decoder_factory (_film, o, 0);
        _decoders.video->Video.connect (bind (&FilmViewer::process_video, this, _1, _2));
+       _decoders.video->OutputChanged.connect (boost::bind (&FilmViewer::decoder_changed, this));
 
        film_changed (Film::CROP);
        film_changed (Film::FORMAT);
 }
 
+void
+FilmViewer::decoder_changed ()
+{
+       shared_ptr<Image> last = _display;
+       while (last == _display) {
+               _decoders.video->pass ();
+       }
+       _panel->Refresh ();
+       _panel->Update ();
+}
+
 void
 FilmViewer::timer (wxTimerEvent& ev)
 {
@@ -154,16 +166,7 @@ FilmViewer::paint_panel (wxPaintEvent& ev)
 void
 FilmViewer::slider_moved (wxCommandEvent& ev)
 {
-       if (_decoders.video->seek (_slider->GetValue() * _film->length().get() / 4096)) {
-               return;
-       }
-       
-       shared_ptr<Image> last = _display;
-       while (last == _display) {
-               _decoders.video->pass ();
-       }
-       _panel->Refresh ();
-       _panel->Update ();
+       _decoders.video->seek (_slider->GetValue() * _film->length().get() / 4096);
 }
 
 void
index f0d4b628005ddb98ca140464b2223c9e37ad15d8..b1d0b99d34bafd3bc502e1968c8c9b0fdce81adb 100644 (file)
@@ -51,6 +51,7 @@ private:
        void calculate_sizes ();
        void check_play_state ();
        void update_from_raw ();
+       void decoder_changed ();
 
        boost::shared_ptr<Film> _film;