no longer need ffmpeg patch0 which was for Termux
[goodguy/cinelerra.git] / cinelerra-5.1 / guicast / vicon.h
1 /*
2  * CINELERRA
3  * Copyright (C) 2016-2020 William Morrow
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published
7  * by the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA
19  */
20
21
22 #ifndef __VICON_H__
23 #define __VICON_H__
24
25 #include "arraylist.h"
26 #include "bccmodels.h"
27 #include "bcpopup.h"
28 #include "bcwindowbase.h"
29 #include "thread.h"
30 #include "vicon.inc"
31 #include "vframe.h"
32
33 class ViewPopup : public BC_Popup {
34 public:
35         VIconThread *vt;
36         virtual int keypress_event();
37         virtual int button_press_event() { return 0; }
38         virtual int button_release_event() { return 0; }
39         virtual int cursor_motion_event() { return 0; }
40         virtual void draw_vframe(VFrame *frame);
41
42         ViewPopup(VIconThread *vt, int x, int y, int w, int h);
43         ~ViewPopup();
44 };
45
46 class VIFrame {
47         unsigned char *img_data;
48 public:
49         VIFrame(int ww, int hh, int vcmdl) {
50                 int size = BC_CModels::calculate_datasize(ww, hh, -1, vcmdl);
51                 img_data = new unsigned char[size];
52                 vfrm = new VFrame(img_data, -1, ww, hh, vcmdl, -1);
53         }
54         ~VIFrame() { delete vfrm;  delete [] img_data; }
55         VFrame *vfrm;
56 };
57
58 class VIcon
59 {
60 public:
61         int w, h, in_use, hidden;
62         ArrayList<VIFrame *> images;
63         int64_t seq_no;
64         double cycle_start, age, frame_rate;
65         int audio_size, playing_audio;
66         uint8_t *audio_data;
67
68         int64_t vframes() { return images.size(); }
69         void reset() { seq_no = 0; cycle_start = 0; age = 0; }
70         void reset(double rate) { reset(); frame_rate = rate; }
71         void clear_images() { images.remove_all_objects(); }
72         void init_audio(int audio_size);
73
74         virtual int64_t set_seq_no(int64_t no) { return seq_no = no; }
75         virtual VFrame *frame() { return images[seq_no]->vfrm; }
76         virtual int get_vx() { return 0; }
77         virtual int get_vy() { return 0; }
78         virtual void load_audio() {}
79         virtual void start_audio() {}
80         virtual void stop_audio() {}
81
82         void add_image(VFrame *frm, int ww, int hh, int vcmdl);
83         void draw_vframe(VIconThread *vt, BC_WindowBase *wdw, int x, int y);
84         void dump(const char *dir);
85
86         VIcon(int vw=VICON_WIDTH, int vh=VICON_HEIGHT, double rate=VICON_RATE);
87         virtual ~VIcon();
88 };
89
90 class VIconThread : public Thread
91 {
92 public:
93         int done, interrupted;
94         BC_WindowBase *wdw;
95         Timer *timer;
96         Condition *draw_lock;
97         ViewPopup *view_win;
98         VIcon *viewing, *vicon, *solo;
99         int vw, vh, view_w, view_h;
100         int draw_x0, draw_y0;
101         int draw_x1, draw_y1;
102         int img_dirty, win_dirty;
103         double refresh_rate;
104         int64_t now;
105         int64_t draw_flash;
106         int64_t stop_age;
107         int64_t seq_no;
108
109         ArrayList<VIcon *>t_heap;
110         VIcon *low_vicon();
111         void add_vicon(VIcon *vicon);
112         int del_vicon(VIcon *vicon);
113         void run();
114         void flash();
115         int draw(VIcon *vicon);
116         int update_view(int do_audio);
117         void draw_images();
118         void start_drawing();
119         void stop_drawing();
120         void stop_viewing();
121         void reset_images();
122         void remove_vicon(int i);
123         int keypress_event(int key);
124         int cursor_inside(int x, int y);
125         void set_drawing_area(int x0, int y0, int x1, int y1);
126         void set_view_popup(VIcon *vicon);
127         int zoom_scale(int dir);
128         void close_view_popup();
129         void hide_vicons(int v=1);
130         int show_vicon(VIcon *next);
131         virtual ViewPopup *new_view_window(ViewPopup *vpopup);
132
133         virtual bool visible(VIcon *vicon, int x, int y);
134         virtual void drawing_started() {}
135         virtual void drawing_stopped() {}
136
137         VIconThread(BC_WindowBase *wdw,
138                 int vw=VICON_WIDTH, int vh=VICON_HEIGHT,
139                 int view_w=4*VICON_WIDTH, int view_h=4*VICON_HEIGHT);
140         ~VIconThread();
141 };
142
143 #endif