Make viewer cope with multiple video frames being emitted on a single pass.
[dcpomatic.git] / src / wx / film_viewer.h
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file  src/film_viewer.h
21  *  @brief A wx widget to view `thumbnails' of a Film.
22  */
23
24 #include <wx/wx.h>
25 #include "lib/film.h"
26
27 class wxToggleButton;
28 class FFmpegPlayer;
29 class Image;
30 class RGBPlusAlphaImage;
31
32 /** @class FilmViewer
33  *  @brief A wx widget to view a preview of a Film.
34  *
35  *  The film takes the following path through the viewer:
36  *
37  *  1.  fetch_next_frame() asks our _player to decode some data.  If it does, process_video()
38  *      will be called.
39  *
40  *  2.  process_video() takes the image from the player (_frame).
41  *
42  *  3.  fetch_next_frame() calls _panel->Refresh() and _panel->Update() which results in
43  *      paint_panel() being called; this creates frame_bitmap from _frame and blits it to the display.
44  *
45  * fetch_current_frame_again() asks the player to re-emit its current frame on the next pass(), and then
46  * starts from step #1.
47  */
48 class FilmViewer : public wxPanel
49 {
50 public:
51         FilmViewer (boost::shared_ptr<Film>, wxWindow *);
52
53         void set_film (boost::shared_ptr<Film>);
54
55 private:
56         void paint_panel (wxPaintEvent &);
57         void panel_sized (wxSizeEvent &);
58         void slider_moved (wxScrollEvent &);
59         void play_clicked (wxCommandEvent &);
60         void timer (wxTimerEvent &);
61         void process_video (boost::shared_ptr<const Image>, Time);
62         void calculate_sizes ();
63         void check_play_state ();
64         void fetch_current_frame_again ();
65         void fetch_next_frame ();
66         void active_jobs_changed (bool);
67         void back_clicked (wxCommandEvent &);
68         void forward_clicked (wxCommandEvent &);
69         void player_changed ();
70
71         boost::shared_ptr<Film> _film;
72         boost::shared_ptr<Player> _player;
73
74         wxSizer* _v_sizer;
75         wxPanel* _panel;
76         wxSlider* _slider;
77         wxButton* _back_button;
78         wxButton* _forward_button;
79         wxStaticText* _frame_number;
80         wxStaticText* _timecode;
81         wxToggleButton* _play_button;
82         wxTimer _timer;
83
84         boost::shared_ptr<const Image> _frame;
85         bool _got_frame;
86
87         /** Size of our output (including padding if we have any) */
88         libdcp::Size _out_size;
89         /** Size of the panel that we have available */
90         libdcp::Size _panel_size;
91
92         std::list<std::pair<boost::shared_ptr<const Image>, Time> > _queue;
93 };