Merge CV, ver=5.1; ops/methods from HV, and interface from CV where possible
[goodguy/history.git] / cinelerra-5.1 / cinelerra / recordmonitor.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2011 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef RECORDMONITOR_H
23 #define RECORDMONITOR_H
24
25 #ifdef HAVE_FIREWIRE
26 #include "avc1394transport.h"
27 #endif
28 #include "bcdialog.h"
29 #include "canvas.h"
30 #include "channelpicker.inc"
31 #include "condition.inc"
32 #include "guicast.h"
33 #include "channelpicker.inc"
34 #include "libmjpeg.h"
35 #include "meterpanel.inc"
36 #include "preferences.inc"
37 #include "record.inc"
38 #include "recordgui.inc"
39 #include "recordscopes.inc"
40 #include "recordtransport.inc"
41 #include "recordmonitor.inc"
42 #include "signalstatus.inc"
43 #include "videodevice.inc"
44
45 class RecordMonitorThread;
46
47 class RecordMonitor : public Thread
48 {
49 public:
50         RecordMonitor(MWindow *mwindow, Record *record);
51         ~RecordMonitor();
52
53 // Show a frame
54         int update(VFrame *vframe);
55 // Update channel textbox
56         void update_channel(char *text);
57
58         MWindow *mwindow;
59         Record *record;
60 // Thread for slippery monitoring
61         RecordMonitorThread *thread;
62         RecordMonitorGUI *window;
63         VideoDevice *device;
64 // Fake config for monitoring
65         VideoOutConfig *config;
66
67         RecordScopeThread *scope_thread;
68
69         void run();
70         void close_threads();   // Stop all the child threads on exit
71         void create_objects();
72         void fix_size(int &w, int &h, int width_given, float aspect_ratio);
73         float get_scale(int w);
74         int get_mbuttons_height();
75         int get_canvas_height();
76         int get_channel_x();
77         int get_channel_y();
78         void reconfig();
79         void redraw();
80         void start_playback();
81         void stop_playback();
82         void display_vframe(VFrame *in, int x, int y,
83                 int alpha, double secs, double scale);
84         void undisplay_vframe();
85 };
86
87 class ReverseInterlace;
88 class RecordMonitorCanvas;
89
90 class RecordMonitorGUI : public BC_Window
91 {
92 public:
93         RecordMonitorGUI(MWindow *mwindow, Record *record,
94                 RecordMonitor *thread, int min_w);
95         ~RecordMonitorGUI();
96
97         void create_objects();
98         int cursor_leave_event();
99         int cursor_enter_event();
100         int button_release_event();
101         int cursor_motion_event();
102
103         void display_video_text(int x, int y, const char *text, int font,
104                 int bg_color, int color, int alpha, double secs, double scale);
105         void enable_signal_status(int enable);
106
107         MeterPanel *meters;
108         Canvas *canvas;
109 //      RecordTransport *record_transport;
110 #ifdef HAVE_FIREWIRE
111         AVC1394Transport *avc1394_transport;
112         AVC1394TransportThread *avc1394transport_thread;
113 #endif
114         RecordChannelPicker *channel_picker;
115         ScopeEnable *scope_toggle;
116         ReverseInterlace *reverse_interlace;
117         int cursor_x_origin, cursor_y_origin;
118         int translate_x_origin, translate_y_origin;
119         BC_PopupMenu *monitor_menu;
120         int current_operation;
121
122
123         int translation_event();
124         int button_press_event();
125         int resize_event(int w, int h);
126         int redraw();
127         int set_title();
128         int close_event();
129         int create_bitmap();
130         int keypress_event();
131
132         MWindow *mwindow;
133         BC_SubWindow *mbuttons;
134         BC_Bitmap *bitmap;
135         RecordMonitor *thread;
136         Record *record;
137 #ifdef HAVE_FIREWIRE
138         AVC1394Control *avc;
139         BC_Title *avc1394transport_title;
140         BC_Title *avc1394transport_timecode;
141 #endif
142         SignalStatus *signal_status;
143 };
144
145
146 class RecVideoMJPGThread;
147 class RecVideoDVThread;
148 class RecVideoOverlay;
149
150 class RecordMonitorThread : public Thread
151 {
152         void show_output_frame();
153         void render_uncompressed();
154         int render_jpeg();
155         int render_dv();
156         void process_scope();
157         void process_hist();
158
159         int ready;   // Ready to recieve the next frame
160         int done;
161         RecVideoMJPGThread *jpeg_engine;
162         RecVideoDVThread *dv_engine;
163 public:
164         RecordMonitorThread(MWindow *mwindow,
165                 Record *record,
166                 RecordMonitor *record_monitor);
167         ~RecordMonitorThread();
168
169         void reset_parameters();
170         void run();
171 // Calculate the best output format based on input drivers
172         void init_output_format();
173         int start_playback();
174         int stop_playback();
175         int write_frame(VFrame *new_frame);
176         int render_frame();
177         void lock_input();
178         void unlock_input();
179         void new_output_frame();
180         void display_vframe(VFrame *in, int x, int y,
181                 int alpha, double secs, double scale);
182         void undisplay_vframe();
183         int finished() { return done; }
184
185 // Input frame being rendered
186         VFrame *input_frame;
187 // Frames for the rendered output
188         VFrame *output_frame;
189 // Best color model given by device
190         int output_colormodel;
191 // Block until new input data
192         Condition *output_lock;
193         Condition *input_lock;
194         Record *record;
195         RecordMonitor *record_monitor;
196         MWindow *mwindow;
197 // If the input frame is the same data that the file handle uses
198         int shared_data;
199 // overlay data
200         RecVideoOverlay *ovly;
201 };
202
203 class RecordMonitorFullsize : public BC_MenuItem
204 {
205 public:
206         RecordMonitorFullsize(MWindow *mwindow, RecordMonitorGUI *window);
207
208         int handle_event();
209         MWindow *mwindow;
210         RecordMonitorGUI *window;
211 };
212
213 class RecordMonitorCanvas : public Canvas
214 {
215 public:
216         RecordMonitorCanvas(MWindow *mwindow, RecordMonitorGUI *window,
217                 Record *record, int x, int y, int w, int h);
218         ~RecordMonitorCanvas();
219
220         void zoom_resize_window(float percentage);
221         int button_press_event();
222         int button_release_event();
223         int cursor_motion_event();
224         int cursor_enter_event();
225         void reset_translation();
226         int keypress_event();
227         int get_output_w();
228         int get_output_h();
229         int get_fullscreen();
230         void set_fullscreen(int value);
231
232
233         RecordMonitorGUI *window;
234         MWindow *mwindow;
235         Record *record;
236 };
237
238 class ReverseInterlace : public BC_CheckBox
239 {
240 public:
241         ReverseInterlace(Record *record, int x, int y);
242         ~ReverseInterlace();
243         int handle_event();
244         Record *record;
245 };
246
247 class RecVideoMJPGThread
248 {
249 public:
250         RecVideoMJPGThread(Record *record,
251                 RecordMonitorThread *thread,
252                 int fields);
253         ~RecVideoMJPGThread();
254
255         int render_frame(VFrame *frame, long size);
256         int start_rendering();
257         int stop_rendering();
258
259         RecordMonitorThread *thread;
260         Record *record;
261
262 private:
263         mjpeg_t *mjpeg;
264         int fields;
265 };
266
267 class RecVideoDVThread
268 {
269 public:
270         RecVideoDVThread(Record *record, RecordMonitorThread *thread);
271         ~RecVideoDVThread();
272
273         int start_rendering();
274         int stop_rendering();
275         int render_frame(VFrame *frame, long size);
276
277         RecordMonitorThread *thread;
278         Record *record;
279
280 private:
281 // Don't want theme to need libdv to compile
282         void *dv;
283 };
284
285 class RecVideoOverlay
286 {
287         int x, y, ticks;
288         float scale, alpha;
289         VFrame *vframe;
290 public:
291         RecVideoOverlay(VFrame *vframe, int x, int y, int ticks, float scale, float alpha);
292         ~RecVideoOverlay();
293
294         int overlay(VFrame *out);
295 };
296
297
298 #endif