Basic ffmpeg film viewer.
[dcpomatic.git] / src / wx / ffmpeg_player.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 #include <wx/wx.h>
21 #include <stdint.h>
22 extern "C" {
23 #include <libavcodec/avcodec.h> 
24 #include <libavformat/avformat.h>
25 #include <libswscale/swscale.h>
26 }
27
28 class wxToggleButton;
29
30 class FFmpegPlayer
31 {
32 public:
33         FFmpegPlayer (wxWindow* parent);
34         ~FFmpegPlayer ();
35
36         void set_file (std::string);
37
38         wxPanel* panel () const {
39                 return _panel;
40         }
41
42         wxSlider* slider () const {
43                 return _slider;
44         }
45
46         wxToggleButton* play_button () const {
47                 return _play_button;
48         }
49
50         void set_top_crop (int t);
51         void set_bottom_crop (int b);
52         void set_left_crop (int l);
53         void set_right_crop (int r);
54         void set_ratio (float r);
55
56 private:
57         void timer (wxTimerEvent& ev);
58         void decode_frame ();
59         void convert_frame ();
60         void paint_panel (wxPaintEvent& ev);
61         void slider_moved (wxCommandEvent& ev);
62         float frames_per_second () const;
63         void allocate_buffer_and_scaler ();
64         float width_source_to_view_scaling () const;
65         float height_source_to_view_scaling () const;
66         int cropped_width_in_view () const;
67         int cropped_height_in_view () const;
68         int left_crop_in_view () const;
69         int top_crop_in_view () const;
70         void panel_sized (wxSizeEvent &);
71         void play_clicked (wxCommandEvent &);
72         void check_play_state ();
73         void update_panel ();
74         bool can_display () const;
75
76         AVFormatContext* _format_context;
77         int _video_stream;
78         AVFrame* _frame;
79         AVCodecContext* _video_codec_context;
80         AVCodec* _video_codec;
81         AVPacket _packet;
82         struct SwsContext* _scale_context;
83         bool _frame_valid;
84         uint8_t* _rgb[1];
85         int _rgb_stride[1];
86
87         wxPanel* _panel;
88         wxSlider* _slider;
89         wxToggleButton* _play_button;
90         
91         wxTimer _timer;
92         int _panel_width;
93         int _panel_height;
94         int _full_width;
95         int _full_height;
96         int _top_crop_in_source;
97         int _bottom_crop_in_source;
98         int _left_crop_in_source;
99         int _right_crop_in_source;
100         float _ratio;
101 };