initial commit
[goodguy/history.git] / cinelerra-5.0 / 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 #include "avc1394transport.h"
26 #include "bcdialog.h"
27 #include "canvas.h"
28 #include "channelpicker.inc"
29 #include "condition.inc"
30 #include "guicast.h"
31 #include "channelpicker.inc"
32 #include "libmjpeg.h"
33 #include "meterpanel.inc"
34 #include "preferences.inc"
35 #include "record.inc"
36 #include "recordgui.inc"
37 #include "recordscopes.inc"
38 #include "recordtransport.inc"
39 #include "recordmonitor.inc"
40 #include "signalstatus.inc"
41 #include "videodevice.inc"
42
43 class RecordMonitorThread;
44
45 class RecordMonitor : public Thread
46 {
47 public:
48         RecordMonitor(MWindow *mwindow, Record *record);
49         ~RecordMonitor();
50
51 // Show a frame 
52         int update(VFrame *vframe);
53 // Update channel textbox
54         void update_channel(char *text);
55
56         MWindow *mwindow;
57         Record *record;
58 // Thread for slippery monitoring
59         RecordMonitorThread *thread; 
60         RecordMonitorGUI *window;
61         VideoDevice *device;
62 // Fake config for monitoring
63         VideoOutConfig *config;
64
65         RecordScopeThread *scope_thread;
66
67         void run();
68         int close_threads();   // Stop all the child threads on exit
69         void create_objects();
70         int fix_size(int &w, int &h, int width_given, float aspect_ratio);
71         float get_scale(int w);
72         int get_mbuttons_height();
73         int get_canvas_height();
74         int get_channel_x();
75         int get_channel_y();
76         void reconfig();
77         void redraw();
78         void start_playback();
79         void stop_playback();
80         void display_vframe(VFrame *in, int x, int y,
81                 int alpha, double secs, double scale);
82         void undisplay_vframe();
83 };
84
85 class ReverseInterlace;
86 class RecordMonitorCanvas;
87
88 class RecordMonitorGUI : public BC_Window
89 {
90 public:
91         RecordMonitorGUI(MWindow *mwindow, Record *record, 
92                 RecordMonitor *thread, int min_w);
93         ~RecordMonitorGUI();
94
95         void create_objects();
96         int cursor_leave_event();
97         int cursor_enter_event();
98         int button_release_event();
99         int cursor_motion_event();
100
101         void display_video_text(int x, int y, const char *text, int font,
102                 int bg_color, int color, int alpha, double secs, double scale);
103         void enable_signal_status(int enable);
104
105         MeterPanel *meters;
106         Canvas *canvas;
107 //      RecordTransport *record_transport;
108         AVC1394Transport *avc1394_transport;
109         AVC1394TransportThread *avc1394transport_thread;
110         RecordChannelPicker *channel_picker;
111         ScopeEnable *scope_toggle;
112         ReverseInterlace *reverse_interlace;
113         int cursor_x_origin, cursor_y_origin;
114         int translate_x_origin, translate_y_origin;
115         BC_PopupMenu *monitor_menu;
116         int current_operation;
117
118
119         int translation_event();
120         int button_press_event();
121         int resize_event(int w, int h);
122         int redraw();
123         int set_title();
124         int close_event();
125         int create_bitmap();
126         int keypress_event();
127
128         MWindow *mwindow;
129         BC_SubWindow *mbuttons;
130         BC_Bitmap *bitmap;
131         RecordMonitor *thread;
132         Record *record;
133         AVC1394Control *avc;
134         BC_Title *avc1394transport_title;
135         BC_Title *avc1394transport_timecode;
136         SignalStatus *signal_status;
137 };
138
139
140 class RecVideoMJPGThread;
141 class RecVideoDVThread;
142 class RecVideoOverlay;
143
144 class RecordMonitorThread : public Thread
145 {
146         void show_output_frame();
147         void render_uncompressed();
148         int render_jpeg();
149         int render_dv();
150         void process_scope();
151         void process_hist();
152
153         int ready;   // Ready to recieve the next frame
154         int done;
155         RecVideoMJPGThread *jpeg_engine;
156         RecVideoDVThread *dv_engine;
157 public:
158         RecordMonitorThread(MWindow *mwindow, 
159                 Record *record, 
160                 RecordMonitor *record_monitor);
161         ~RecordMonitorThread();
162
163         void reset_parameters();
164         void run();
165 // Calculate the best output format based on input drivers
166         void init_output_format();
167         int start_playback();
168         int stop_playback();
169         int write_frame(VFrame *new_frame);
170         int render_frame();
171         void lock_input();
172         void unlock_input();
173         void new_output_frame();
174         void display_vframe(VFrame *in, int x, int y,
175                 int alpha, double secs, double scale);
176         void undisplay_vframe();
177         int finished() { return done; }
178
179 // Input frame being rendered
180         VFrame *input_frame;    
181 // Frames for the rendered output
182         VFrame *output_frame;
183 // Best color model given by device
184         int output_colormodel;
185 // Block until new input data
186         Condition *output_lock;
187         Condition *input_lock;
188         Record *record;
189         RecordMonitor *record_monitor;
190         MWindow *mwindow;
191 // If the input frame is the same data that the file handle uses
192         int shared_data;
193 // overlay data
194         RecVideoOverlay *ovly;
195 };
196
197 class RecordMonitorFullsize : public BC_MenuItem
198 {
199 public:
200         RecordMonitorFullsize(MWindow *mwindow, RecordMonitorGUI *window);
201
202         int handle_event();
203         MWindow *mwindow;
204         RecordMonitorGUI *window;
205 };
206
207 class RecordMonitorCanvas : public Canvas
208 {
209 public:
210         RecordMonitorCanvas(MWindow *mwindow, RecordMonitorGUI *window, 
211                 Record *record, int x, int y, int w, int h);
212         ~RecordMonitorCanvas();
213         
214         void zoom_resize_window(float percentage);
215         int button_press_event();
216         int button_release_event();
217         int cursor_motion_event();
218         int cursor_enter_event();
219         void reset_translation();
220         int keypress_event();
221         int get_output_w();
222         int get_output_h();
223         int get_fullscreen();
224         void set_fullscreen(int value);
225
226
227         RecordMonitorGUI *window;
228         MWindow *mwindow;
229         Record *record;
230 };
231
232 class ReverseInterlace : public BC_CheckBox
233 {
234 public:
235         ReverseInterlace(Record *record, int x, int y);
236         ~ReverseInterlace();
237         int handle_event();
238         Record *record;
239 };
240
241 class RecVideoMJPGThread
242 {
243 public:
244         RecVideoMJPGThread(Record *record, 
245                 RecordMonitorThread *thread,
246                 int fields);
247         ~RecVideoMJPGThread();
248
249         int render_frame(VFrame *frame, long size);
250         int start_rendering();
251         int stop_rendering();
252
253         RecordMonitorThread *thread;
254         Record *record;
255
256 private:
257         mjpeg_t *mjpeg;
258         int fields;
259 };
260
261 class RecVideoDVThread
262 {
263 public:
264         RecVideoDVThread(Record *record, RecordMonitorThread *thread);
265         ~RecVideoDVThread();
266
267         int start_rendering();
268         int stop_rendering();
269         int render_frame(VFrame *frame, long size);
270
271         RecordMonitorThread *thread;
272         Record *record;
273
274 private:
275 // Don't want theme to need libdv to compile
276         void *dv;
277 };
278
279 class RecVideoOverlay
280 {
281         int x, y, ticks;
282         float scale, alpha;
283         VFrame *vframe;
284 public:
285         RecVideoOverlay(VFrame *vframe, int x, int y, int ticks, float scale, float alpha);
286         ~RecVideoOverlay();
287
288         int overlay(VFrame *out);
289 };
290
291
292 #endif