Basic ffmpeg film viewer.
authorCarl Hetherington <cth@carlh.net>
Sat, 15 Dec 2012 22:29:09 +0000 (22:29 +0000)
committerCarl Hetherington <cth@carlh.net>
Sat, 15 Dec 2012 22:29:09 +0000 (22:29 +0000)
run/dvdomatic
src/tools/dvdomatic.cc
src/wx/ffmpeg_player.cc [new file with mode: 0644]
src/wx/ffmpeg_player.h [new file with mode: 0644]
src/wx/film_viewer.cc
src/wx/film_viewer.h
src/wx/wscript

index 70906a2546b8f276d0065cc40f37d4d28632713b..ff38970646e168179858fa04977c8a2cf0ce3bfa 100755 (executable)
@@ -3,10 +3,10 @@
 export LD_LIBRARY_PATH=build/src/lib:build/src/wx:build/src/asdcplib/src:$LD_LIBRARY_PATH
 if [ "$1" == "--debug" ]; then
     shift
-    gdb --args build/src/tools/dvdomatic $*
+    gdb --args build/src/tools/dvdomatic "$*"
 elif [ "$1" == "--valgrind" ]; then
     shift
     valgrind --tool="memcheck" build/src/tools/dvdomatic $*
 else
-    build/src/tools/dvdomatic $*
+    build/src/tools/dvdomatic "$*"
 fi
index 993c41563ba1be47dcfbfcf7e38460e3fac5756e..d5d5bfc2f906ac21c0a7499c636df5041739a98d 100644 (file)
@@ -226,7 +226,6 @@ public:
 
                /* XXX: calling these here is a bit of a hack */
                film_editor->setup_visibility ();
-               film_viewer->setup_visibility ();
                
                film_editor->FileChanged.connect (bind (&Frame::file_changed, this, _1));
                if (film) {
diff --git a/src/wx/ffmpeg_player.cc b/src/wx/ffmpeg_player.cc
new file mode 100644 (file)
index 0000000..8273687
--- /dev/null
@@ -0,0 +1,417 @@
+/*
+    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <wx/wx.h>
+#include <wx/tglbtn.h>
+#include <iostream>
+#include <stdint.h>
+extern "C" {
+#include <libavcodec/avcodec.h>        
+#include <libavformat/avformat.h>
+#include <libswscale/swscale.h>
+}
+#include "wx/ffmpeg_player.h"
+
+using namespace std;
+
+FFmpegPlayer::FFmpegPlayer (wxWindow* parent)
+       : _format_context (0)
+       , _video_stream (-1)
+       , _frame (0)
+       , _video_codec_context (0)
+       , _video_codec (0)
+       , _scale_context (0)
+       , _frame_valid (false)
+       , _panel (new wxPanel (parent))
+       , _slider (new wxSlider (parent, wxID_ANY, 0, 0, 4096))
+       , _play_button (new wxToggleButton (parent, wxID_ANY, wxT ("Play")))
+       , _panel_width (0)
+       , _panel_height (0)
+       , _full_width (0)
+       , _full_height (0)
+       , _top_crop_in_source (0)
+       , _bottom_crop_in_source (0)
+       , _left_crop_in_source (0)
+       , _right_crop_in_source (0)
+       , _ratio (1.85)
+{
+       _rgb[0] = 0;
+
+       avcodec_register_all ();
+       av_register_all ();
+       
+       _frame = avcodec_alloc_frame ();
+       if (!_frame) {
+               cerr << "could not allocate frame\n";
+       }
+       
+       _panel->Bind (wxEVT_PAINT, &FFmpegPlayer::paint_panel, this);
+       _panel->Bind (wxEVT_SIZE, &FFmpegPlayer::panel_sized, this);
+       _slider->Bind (wxEVT_SCROLL_THUMBTRACK, &FFmpegPlayer::slider_moved, this);
+       _slider->Bind (wxEVT_SCROLL_PAGEUP, &FFmpegPlayer::slider_moved, this);
+       _slider->Bind (wxEVT_SCROLL_PAGEDOWN, &FFmpegPlayer::slider_moved, this);
+       _play_button->Bind (wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, &FFmpegPlayer::play_clicked, this);
+       _timer.Bind (wxEVT_TIMER, &FFmpegPlayer::timer, this);
+}
+
+FFmpegPlayer::~FFmpegPlayer ()
+{
+       delete[] _rgb[0];
+       
+       if (_scale_context) {
+               sws_freeContext (_scale_context);
+       }
+       
+       if (_video_codec_context) {
+               avcodec_close (_video_codec_context);
+       }
+       
+       av_free (_frame);
+
+       if (_format_context) {
+               avformat_close_input (&_format_context);
+       }
+}
+
+void
+FFmpegPlayer::timer (wxTimerEvent& ev)
+{
+       if (!can_display ()) {
+               return;
+       }
+       
+       _panel->Refresh ();
+       _panel->Update ();
+       decode_frame ();
+       convert_frame ();
+}
+
+void
+FFmpegPlayer::update_panel ()
+{
+       _panel->Refresh ();
+       _panel->Update ();
+}
+
+void
+FFmpegPlayer::decode_frame ()
+{
+       assert (_format_context);
+       
+       while (1) {
+               int r = av_read_frame (_format_context, &_packet);
+               if (r < 0) {
+                       return;
+               }
+               
+               avcodec_get_frame_defaults (_frame);
+               if (_packet.stream_index == _video_stream) {
+                       int frame_finished;
+                       int const r = avcodec_decode_video2 (_video_codec_context, _frame, &frame_finished, &_packet);
+                       if (r >= 0 && frame_finished) {
+                               _frame_valid = true;
+                               av_free_packet (&_packet);
+                               return;
+                       }
+               }
+               
+               av_free_packet (&_packet);
+       }
+}
+
+void
+FFmpegPlayer::convert_frame ()
+{
+       if (!_scale_context || !_rgb[0] || !_frame_valid) {
+               return;
+       }
+       
+       sws_scale (
+               _scale_context,
+               _frame->data, _frame->linesize,
+               0, _video_codec_context->height,
+               _rgb, _rgb_stride
+               );
+       
+       uint8_t* in = _rgb[0];
+       uint8_t* out = _rgb[0];
+       
+       in += top_crop_in_view() * _full_width * 3;
+       for (int y = 0; y < cropped_height_in_view(); ++y) {
+               /* in is the start of the appropriate full-width line */
+               memmove (out, in + left_crop_in_view() * 3, cropped_width_in_view() * 3);
+               in += _full_width * 3;
+               out += cropped_width_in_view() * 3;
+       }
+}
+
+void
+FFmpegPlayer::paint_panel (wxPaintEvent& ev)
+{
+       wxPaintDC dc (_panel);
+       
+       wxImage i (cropped_width_in_view(), cropped_height_in_view(), _rgb[0], true);
+       wxBitmap b (i);
+       dc.DrawBitmap (b, 0, 0);
+}
+
+void
+FFmpegPlayer::slider_moved (wxCommandEvent& ev)
+{
+       if (!can_display ()) {
+               return;
+       }
+       
+       int const video_length_in_frames = (double(_format_context->duration) / AV_TIME_BASE) * frames_per_second();
+       int const new_frame = video_length_in_frames * _slider->GetValue() / 4096;
+       int64_t const t = static_cast<int64_t>(new_frame) / (av_q2d (_format_context->streams[_video_stream]->time_base) * frames_per_second());
+       av_seek_frame (_format_context, _video_stream, t, 0);
+       avcodec_flush_buffers (_video_codec_context);
+
+       decode_frame ();
+       convert_frame ();
+       update_panel ();
+}
+
+float
+FFmpegPlayer::frames_per_second () const
+{
+       assert (_format_context);
+       
+       AVStream* s = _format_context->streams[_video_stream];
+       
+       if (s->avg_frame_rate.num && s->avg_frame_rate.den) {
+               return av_q2d (s->avg_frame_rate);
+       }
+       
+       return av_q2d (s->r_frame_rate);
+}
+
+void
+FFmpegPlayer::allocate_buffer_and_scaler ()
+{
+       if (!_format_context || !_panel_width || !_panel_height) {
+               return;
+       }
+
+       float const panel_ratio = static_cast<float> (_panel_width) / _panel_height;
+       
+       int new_width;
+       int new_height;
+       if (panel_ratio < _ratio) {
+               /* panel is less widescreen than the target ratio; clamp width */
+               new_width = _panel_width;
+               new_height = new_width / _ratio;
+       } else {
+               /* panel is more widescreen than the target ratio; clamp height */
+               new_height = _panel_height;
+               new_width = new_height * _ratio;
+       }
+
+        if (new_width == 0 || new_height == 0) {
+            return;
+       }
+       
+       _full_height = new_height + ((_top_crop_in_source + _bottom_crop_in_source) * height_source_to_view_scaling());
+       _full_width = new_width + ((_left_crop_in_source + _right_crop_in_source) * width_source_to_view_scaling());
+       
+       delete[] _rgb[0];
+       
+       _rgb[0] = new uint8_t[_full_width * _full_height * 3];
+        memset (_rgb[0], 0, _full_width * _full_height * 3);
+       _rgb_stride[0] = _full_width * 3;
+       
+       if (_scale_context) {
+               sws_freeContext (_scale_context);
+       }
+       
+       _scale_context = sws_getContext (
+               _video_codec_context->width, _video_codec_context->height, _video_codec_context->pix_fmt,
+               _full_width, _full_height, PIX_FMT_RGB24,
+               SWS_BICUBIC, 0, 0, 0
+               );
+
+       if (!_scale_context) {
+               cout << "could not allocate sc\n";
+       }
+}
+
+float
+FFmpegPlayer::width_source_to_view_scaling () const
+{
+       return static_cast<float> (_full_width) / _video_codec_context->width;
+}
+
+float
+FFmpegPlayer::height_source_to_view_scaling () const
+{
+       return static_cast<float> (_full_height) / _video_codec_context->height;
+}
+
+int
+FFmpegPlayer::cropped_width_in_view () const
+{
+       return _full_width - ((_left_crop_in_source + _right_crop_in_source) * width_source_to_view_scaling());
+}
+
+int
+FFmpegPlayer::cropped_height_in_view () const
+{
+       return _full_height - ((_top_crop_in_source + _bottom_crop_in_source) * height_source_to_view_scaling());
+}
+
+int
+FFmpegPlayer::left_crop_in_view () const
+{
+       return _left_crop_in_source * width_source_to_view_scaling();
+}
+
+int
+FFmpegPlayer::top_crop_in_view () const
+{
+       return _top_crop_in_source * height_source_to_view_scaling();
+}
+
+void
+FFmpegPlayer::panel_sized (wxSizeEvent& ev)
+{
+       _panel_width = ev.GetSize().GetWidth();
+       _panel_height = ev.GetSize().GetHeight();
+       allocate_buffer_and_scaler ();
+
+       convert_frame ();
+       update_panel ();
+}
+
+void
+FFmpegPlayer::set_file (string f)
+{
+       if (_video_codec_context) {
+               avcodec_close (_video_codec_context);
+       }
+
+       if (_format_context) {
+               avformat_close_input (&_format_context);
+       }
+       
+       if (avformat_open_input (&_format_context, f.c_str(), 0, 0) < 0) {
+               cerr << "avformat_open_input failed.\n";
+       }
+       
+       if (avformat_find_stream_info (_format_context, 0) < 0) {
+               cerr << "avformat_find_stream_info failed.\n";
+       }
+       
+       for (uint32_t i = 0; i < _format_context->nb_streams; ++i) {
+               AVStream* s = _format_context->streams[i];
+               if (s->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
+                       _video_stream = i;
+               } else if (s->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
+                       /* XXX */
+               }
+       }
+       
+       if (_video_stream < 0) {
+               cerr << "could not find video stream\n";
+       }
+       
+       _video_codec_context = _format_context->streams[_video_stream]->codec;
+       _video_codec = avcodec_find_decoder (_video_codec_context->codec_id);
+       
+       if (_video_codec == 0) {
+               cerr << "could not find video decoder\n";
+       }
+       
+       if (avcodec_open2 (_video_codec_context, _video_codec, 0) < 0) {
+               cerr << "could not open video decoder\n";
+       }
+
+       allocate_buffer_and_scaler ();
+       check_play_state ();
+       update_panel ();
+}
+
+void
+FFmpegPlayer::set_top_crop (int t)
+{
+       _top_crop_in_source = t;
+
+       convert_frame ();
+       update_panel ();
+}
+
+void
+FFmpegPlayer::set_bottom_crop (int b)
+{
+       _bottom_crop_in_source = b;
+
+       convert_frame ();
+       update_panel ();
+}
+
+void
+FFmpegPlayer::set_left_crop (int l)
+{
+       _left_crop_in_source = l;
+
+       convert_frame ();
+       update_panel ();
+}
+
+void
+FFmpegPlayer::set_right_crop (int r)
+{
+       _right_crop_in_source = r;
+
+       convert_frame ();
+       update_panel ();
+}
+
+void
+FFmpegPlayer::set_ratio (float r)
+{
+       _ratio = r;
+       allocate_buffer_and_scaler ();
+
+       convert_frame ();
+       update_panel ();
+}
+
+void
+FFmpegPlayer::play_clicked (wxCommandEvent &)
+{
+       check_play_state ();
+}
+
+void
+FFmpegPlayer::check_play_state ()
+{
+       if (_play_button->GetValue()) {
+               _timer.Start (1000 / frames_per_second());
+       } else {
+               _timer.Stop ();
+       }
+}
+
+bool
+FFmpegPlayer::can_display () const
+{
+       return (_format_context && _scale_context);
+}
+       
diff --git a/src/wx/ffmpeg_player.h b/src/wx/ffmpeg_player.h
new file mode 100644 (file)
index 0000000..3acb538
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <wx/wx.h>
+#include <stdint.h>
+extern "C" {
+#include <libavcodec/avcodec.h>        
+#include <libavformat/avformat.h>
+#include <libswscale/swscale.h>
+}
+
+class wxToggleButton;
+
+class FFmpegPlayer
+{
+public:
+       FFmpegPlayer (wxWindow* parent);
+       ~FFmpegPlayer ();
+
+       void set_file (std::string);
+
+       wxPanel* panel () const {
+               return _panel;
+       }
+
+       wxSlider* slider () const {
+               return _slider;
+       }
+
+       wxToggleButton* play_button () const {
+               return _play_button;
+       }
+
+       void set_top_crop (int t);
+       void set_bottom_crop (int b);
+       void set_left_crop (int l);
+       void set_right_crop (int r);
+       void set_ratio (float r);
+
+private:
+       void timer (wxTimerEvent& ev);
+       void decode_frame ();
+       void convert_frame ();
+       void paint_panel (wxPaintEvent& ev);
+       void slider_moved (wxCommandEvent& ev);
+       float frames_per_second () const;
+       void allocate_buffer_and_scaler ();
+       float width_source_to_view_scaling () const;
+       float height_source_to_view_scaling () const;
+       int cropped_width_in_view () const;
+       int cropped_height_in_view () const;
+       int left_crop_in_view () const;
+       int top_crop_in_view () const;
+       void panel_sized (wxSizeEvent &);
+       void play_clicked (wxCommandEvent &);
+       void check_play_state ();
+       void update_panel ();
+       bool can_display () const;
+
+       AVFormatContext* _format_context;
+       int _video_stream;
+       AVFrame* _frame;
+       AVCodecContext* _video_codec_context;
+       AVCodec* _video_codec;
+       AVPacket _packet;
+       struct SwsContext* _scale_context;
+       bool _frame_valid;
+       uint8_t* _rgb[1];
+       int _rgb_stride[1];
+
+       wxPanel* _panel;
+       wxSlider* _slider;
+       wxToggleButton* _play_button;
+       
+       wxTimer _timer;
+       int _panel_width;
+       int _panel_height;
+       int _full_width;
+       int _full_height;
+       int _top_crop_in_source;
+       int _bottom_crop_in_source;
+       int _left_crop_in_source;
+       int _right_crop_in_source;
+       float _ratio;
+};
index a821323586dd2cce1c5e29b275aac541667bca7f..edeb8fd3f9e9d2f040fd5e94360fe317717d4485 100644 (file)
 */
 
 /** @file  src/film_viewer.cc
- *  @brief A wx widget to view `thumbnails' of a Film.
+ *  @brief A wx widget to view a preview of a Film.
  */
 
 #include <iostream>
 #include <iomanip>
+#include <wx/tglbtn.h>
 #include "lib/film.h"
 #include "lib/format.h"
 #include "lib/util.h"
 #include "lib/subtitle.h"
 #include "film_viewer.h"
 #include "wx_util.h"
+#include "ffmpeg_player.h"
 
 using std::string;
 using std::pair;
 using std::max;
 using boost::shared_ptr;
 
-class ThumbPanel : public wxPanel
-{
-public:
-       ThumbPanel (wxPanel* parent, shared_ptr<Film> film)
-               : wxPanel (parent)
-               , _film (film)
-               , _index (0)
-               , _frame_rebuild_needed (false)
-               , _composition_needed (false)
-       {}
-
-       /** Handle a paint event */
-       void paint_event (wxPaintEvent& ev)
-       {
-               if (!_film || _film->thumbs().size() == 0) {
-                       wxPaintDC dc (this);
-                       return;
-               }
-
-               if (_frame_rebuild_needed) {
-                       _image.reset (new wxImage (std_to_wx (_film->thumb_file (_index))));
-
-                       _subtitle.reset ();
-                       pair<Position, string> s = _film->thumb_subtitle (_index);
-                       if (!s.second.empty ()) {
-                               _subtitle.reset (new SubtitleView (s.first, std_to_wx (s.second)));
-                       }
-
-                       _frame_rebuild_needed = false;
-                       compose ();
-               }
-
-               if (_composition_needed) {
-                       compose ();
-               }
-
-               wxPaintDC dc (this);
-               if (_bitmap) {
-                       dc.DrawBitmap (*_bitmap, 0, 0, false);
-               }
-
-               if (_film->with_subtitles() && _subtitle) {
-                       dc.DrawBitmap (*_subtitle->bitmap, _subtitle->transformed_area.x, _subtitle->transformed_area.y, true);
-               }
-       }
-
-       /** Handle a size event */
-       void size_event (wxSizeEvent &)
-       {
-               if (!_image) {
-                       return;
-               }
-
-               recompose ();
-       }
-
-       /** @param n Thumbnail index */
-       void set (int n)
-       {
-               _index = n;
-               _frame_rebuild_needed = true;
-               Refresh ();
-       }
-
-       void set_film (shared_ptr<Film> f)
-       {
-               _film = f;
-               if (!_film) {
-                       clear ();
-                       _frame_rebuild_needed = true;
-                       Refresh ();
-               } else {
-                       _frame_rebuild_needed = true;
-                       Refresh ();
-               }
-       }
-
-       /** Clear our thumbnail image */
-       void clear ()
-       {
-               _bitmap.reset ();
-               _image.reset ();
-               _subtitle.reset ();
-       }
-
-       void recompose ()
-       {
-               _composition_needed = true;
-               Refresh ();
-       }
-
-       DECLARE_EVENT_TABLE ();
-
-private:
-
-       void compose ()
-       {
-               _composition_needed = false;
-               
-               if (!_film || !_image) {
-                       return;
-               }
-
-               /* Size of the view */
-               int vw, vh;
-               GetSize (&vw, &vh);
-
-               Crop const fc = _film->crop ();
-
-               /* Cropped rectangle */
-               Rect cropped_area (
-                       fc.left,
-                       fc.top,
-                       _image->GetWidth() - (fc.left + fc.right),
-                       _image->GetHeight() - (fc.top + fc.bottom)
-                       );
-
-               /* Target ratio */
-               float const target = _film->format() ? _film->format()->ratio_as_float (_film) : 1.78;
-
-               _transformed_image = _image->GetSubImage (wxRect (cropped_area.x, cropped_area.y, cropped_area.width, cropped_area.height));
-
-               float x_scale = 1;
-               float y_scale = 1;
-
-               if ((float (vw) / vh) > target) {
-                       /* view is longer (horizontally) than the ratio; fit height */
-                       _transformed_image.Rescale (vh * target, vh, wxIMAGE_QUALITY_HIGH);
-                       x_scale = vh * target / cropped_area.width;
-                       y_scale = float (vh) / cropped_area.height;
-               } else {
-                       /* view is shorter (horizontally) than the ratio; fit width */
-                       _transformed_image.Rescale (vw, vw / target, wxIMAGE_QUALITY_HIGH);
-                       x_scale = float (vw) / cropped_area.width;
-                       y_scale = (vw / target) / cropped_area.height;
-               }
-
-               _bitmap.reset (new wxBitmap (_transformed_image));
-
-               if (_subtitle) {
-
-                       _subtitle->transformed_area = subtitle_transformed_area (
-                               x_scale, y_scale, _subtitle->base_area, _film->subtitle_offset(), _film->subtitle_scale()
-                               );
-
-                       _subtitle->transformed_image = _subtitle->base_image;
-                       _subtitle->transformed_image.Rescale (_subtitle->transformed_area.width, _subtitle->transformed_area.height, wxIMAGE_QUALITY_HIGH);
-                       _subtitle->transformed_area.x -= rint (_film->crop().left * x_scale);
-                       _subtitle->transformed_area.y -= rint (_film->crop().top * y_scale);
-                       _subtitle->bitmap.reset (new wxBitmap (_subtitle->transformed_image));
-               }
-       }
-
-       shared_ptr<Film> _film;
-       shared_ptr<wxImage> _image;
-       wxImage _transformed_image;
-       /** currently-displayed thumbnail index */
-       int _index;
-       shared_ptr<wxBitmap> _bitmap;
-       bool _frame_rebuild_needed;
-       bool _composition_needed;
-
-       struct SubtitleView
-       {
-               SubtitleView (Position p, wxString const & i)
-                       : base_image (i)
-               {
-                       base_area.x = p.x;
-                       base_area.y = p.y;
-                       base_area.width = base_image.GetWidth ();
-                       base_area.height = base_image.GetHeight ();
-               }
-
-               Rect base_area;
-               Rect transformed_area;
-               wxImage base_image;
-               wxImage transformed_image;
-               shared_ptr<wxBitmap> bitmap;
-       };
-
-       shared_ptr<SubtitleView> _subtitle;
-};
-
-BEGIN_EVENT_TABLE (ThumbPanel, wxPanel)
-EVT_PAINT (ThumbPanel::paint_event)
-EVT_SIZE (ThumbPanel::size_event)
-END_EVENT_TABLE ()
-
 FilmViewer::FilmViewer (shared_ptr<Film> f, wxWindow* p)
        : wxPanel (p)
+       , _player (new FFmpegPlayer (this))
 {
-       _sizer = new wxBoxSizer (wxVERTICAL);
-       SetSizer (_sizer);
-       
-       _thumb_panel = new ThumbPanel (this, f);
-       _sizer->Add (_thumb_panel, 1, wxEXPAND);
+       wxBoxSizer* v_sizer = new wxBoxSizer (wxVERTICAL);
+       SetSizer (v_sizer);
 
-       int const m = max ((size_t) 1, f ? f->thumbs().size() - 1 : 0);
-       _slider = new wxSlider (this, wxID_ANY, 0, 0, m);
-       _sizer->Add (_slider, 0, wxEXPAND | wxLEFT | wxRIGHT);
-       set_thumbnail (0);
+       v_sizer->Add (_player->panel(), 1, wxEXPAND);
 
-       _slider->Connect (wxID_ANY, wxEVT_COMMAND_SLIDER_UPDATED, wxCommandEventHandler (FilmViewer::slider_changed), 0, this);
+       wxBoxSizer* h_sizer = new wxBoxSizer (wxHORIZONTAL);
+       h_sizer->Add (_player->play_button(), 0, wxEXPAND);
+       h_sizer->Add (_player->slider(), 1, wxEXPAND);
 
-       set_film (_film);
-}
+       v_sizer->Add (h_sizer, 0, wxEXPAND);
 
-void
-FilmViewer::set_thumbnail (int n)
-{
-       if (_film == 0 || int (_film->thumbs().size()) <= n) {
-               return;
-       }
-
-       _thumb_panel->set (n);
-}
-
-void
-FilmViewer::slider_changed (wxCommandEvent &)
-{
-       set_thumbnail (_slider->GetValue ());
+       set_film (_film);
 }
 
 void
@@ -266,27 +63,27 @@ FilmViewer::film_changed (Film::Property p)
        ensure_ui_thread ();
        
        switch (p) {
-       case Film::THUMBS:
-               if (_film && _film->thumbs().size() > 1) {
-                       _slider->SetRange (0, _film->thumbs().size() - 1);
-               } else {
-                       _thumb_panel->clear ();
-                       _slider->SetRange (0, 1);
-               }
                
-               _slider->SetValue (0);
-               set_thumbnail (0);
-               break;
        case Film::CONTENT:
-               setup_visibility ();
+               _player->set_file (_film->content_path ());
                break;
+               
        case Film::CROP:
+       {
+               Crop c = _film->crop ();
+               _player->set_left_crop (c.left);
+               _player->set_right_crop (c.right);
+               _player->set_top_crop (c.top);
+               _player->set_bottom_crop (c.bottom);
+       }
+       break;
+
        case Film::FORMAT:
-       case Film::WITH_SUBTITLES:
-       case Film::SUBTITLE_OFFSET:
-       case Film::SUBTITLE_SCALE:
-               _thumb_panel->recompose ();
+               if (_film->format()) {
+                       _player->set_ratio (_film->format()->ratio_as_float(_film));
+               }
                break;
+               
        default:
                break;
        }
@@ -300,25 +97,13 @@ FilmViewer::set_film (shared_ptr<Film> f)
        }
        
        _film = f;
-       _thumb_panel->set_film (_film);
 
        if (!_film) {
                return;
        }
 
        _film->Changed.connect (bind (&FilmViewer::film_changed, this, _1));
+       film_changed (Film::CONTENT);
        film_changed (Film::CROP);
-       film_changed (Film::THUMBS);
-       setup_visibility ();
-}
-
-void
-FilmViewer::setup_visibility ()
-{
-       if (!_film) {
-               return;
-       }
-
-       ContentType const c = _film->content_type ();
-       _slider->Show (c == VIDEO);
+       film_changed (Film::FORMAT);
 }
index 95bdf099da3f2d03877892299f118e9604a3edf1..f290166c738c966f8a1bb8b1690573a50bd88c2a 100644 (file)
 #include <wx/wx.h>
 #include "lib/film.h"
 
-class ThumbPanel;
+class FFmpegPlayer;
 
 /** @class FilmViewer
- *  @brief A wx widget to view `thumbnails' of a Film.
+ *  @brief A wx widget to view a preview of a Film.
  */
 class FilmViewer : public wxPanel
 {
@@ -35,15 +35,10 @@ public:
        FilmViewer (boost::shared_ptr<Film>, wxWindow *);
 
        void set_film (boost::shared_ptr<Film>);
-       void setup_visibility ();
 
 private:
-       void slider_changed (wxCommandEvent &);
-       void set_thumbnail (int);
        void film_changed (Film::Property);
 
        boost::shared_ptr<Film> _film;
-       wxBoxSizer* _sizer;
-       ThumbPanel* _thumb_panel;
-       wxSlider* _slider;
+       FFmpegPlayer* _player;
 };
index 4dbb04eeacaa4cc0da3155f09e6243e5934b7dbb..2ab7feee787b7323844fff4233ab92399e697c52 100644 (file)
@@ -20,6 +20,7 @@ def build(bld):
                  film_viewer.cc
                  filter_dialog.cc
                  filter_view.cc
+                 ffmpeg_player.cc
                  gain_calculator_dialog.cc
                  job_manager_view.cc
                  job_wrapper.cc