diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-12-16 13:43:25 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-12-16 13:43:25 +0000 |
| commit | 3171c89fef95b19c8889996caaac73eea71cf388 (patch) | |
| tree | deeeda477690ff9af5a67bd210270b5da7806371 /src | |
| parent | 1f2bc4d8f3601ad1e12b94f37b3889fcd003509b (diff) | |
Decoder handles crop changing.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/decoder.h | 2 | ||||
| -rw-r--r-- | src/lib/ffmpeg_decoder.cc | 27 | ||||
| -rw-r--r-- | src/lib/ffmpeg_decoder.h | 5 | ||||
| -rw-r--r-- | src/wx/film_viewer.cc | 23 | ||||
| -rw-r--r-- | src/wx/film_viewer.h | 1 |
5 files changed, 48 insertions, 10 deletions
diff --git a/src/lib/decoder.h b/src/lib/decoder.h index be1fe38b6..0d35ebb3a 100644 --- a/src/lib/decoder.h +++ b/src/lib/decoder.h @@ -63,6 +63,8 @@ public: */ virtual bool seek (SourceFrame); + boost::signals2::signal<void()> OutputChanged; + protected: /** our Film */ boost::shared_ptr<Film> _film; diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index b3b1acbbb..51afc461a 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -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; + } +} + diff --git a/src/lib/ffmpeg_decoder.h b/src/lib/ffmpeg_decoder.h index d483db1d9..d5753393e 100644 --- a/src/lib/ffmpeg_decoder.h +++ b/src/lib/ffmpeg_decoder.h @@ -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; }; diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc index 1ed560428..80516328c 100644 --- a/src/wx/film_viewer.cc +++ b/src/wx/film_viewer.cc @@ -109,12 +109,24 @@ 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) { _panel->Refresh (); @@ -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 diff --git a/src/wx/film_viewer.h b/src/wx/film_viewer.h index f0d4b6280..b1d0b99d3 100644 --- a/src/wx/film_viewer.h +++ b/src/wx/film_viewer.h @@ -51,6 +51,7 @@ private: void calculate_sizes (); void check_play_state (); void update_from_raw (); + void decoder_changed (); boost::shared_ptr<Film> _film; |
