Merge CV, ver=5.1; ops/methods from HV, and interface from CV where possible
[goodguy/history.git] / cinelerra-5.1 / cinelerra / vdevicebuz.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 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 VDEVICEBUZ_H
23 #define VDEVICEBUZ_H
24
25 #include "buz.h"
26 #include "channel.inc"
27 #include "condition.inc"
28 #include "guicast.h"
29 #include "libmjpeg.h"
30 #include "mutex.inc"
31 #include "thread.h"
32 #include "vdevicebase.h"
33 #include "vdevicebuz.inc"
34 #include "vframe.inc"
35
36
37 #define INPUT_BUFFER_SIZE 0x40000
38
39 // Let's get real.  The Buz driver doesn't work.  If the buffers overflow
40 // for enough time it locks up and can't be recovered except by a
41 // SIGINT and restart.  We need to cascade the buffer reading in another
42 // ring buffer thread, have it read continuously, and cancel it if it
43 // dies.  How about if we do this in SCHED_RR and wait for it to die before
44 // implementing cancellation?
45
46
47 class VDeviceBUZInput : public Thread
48 {
49 public:
50         VDeviceBUZInput(VDeviceBUZ *device);
51         ~VDeviceBUZInput();
52         void start();
53         void run();
54         void get_buffer(char **ptr, int *size);
55         void put_buffer();
56         void increment_counter(int *counter);
57         void decrement_counter(int *counter);
58         VDeviceBUZ *device;
59
60         char **buffer;
61         int *buffer_size;
62         int total_buffers;
63         int current_inbuffer;
64         int current_outbuffer;
65         Condition *output_lock;
66         Mutex *buffer_lock;
67         int done;
68 };
69
70
71 class VDeviceBUZ : public VDeviceBase
72 {
73 public:
74         VDeviceBUZ(VideoDevice *device);
75         ~VDeviceBUZ();
76
77         friend class VDeviceBUZInput;
78
79         int open_input();
80         int open_output();
81         int close_all();
82         int read_buffer(VFrame *frame);
83         int write_buffer(VFrame *frames, EDL *edl);
84         void reset_parameters();
85         ArrayList<int>* get_render_strategies();
86         int set_channel(Channel *channel);
87         int get_norm(int norm);
88         static void get_inputs(ArrayList<Channel*> *input_sources);
89         int set_picture(PictureConfig *picture);
90         int get_best_colormodel(int colormodel);
91         int create_channeldb(ArrayList<Channel*> *channeldb);
92         void new_output_buffer(VFrame *output, int colormodel);
93
94
95 private:
96         int open_input_core(Channel *channel);
97         void close_input_core();
98         int open_output_core(Channel *channel);
99         int close_output_core();
100
101         int jvideo_fd;
102         char *input_buffer, *frame_buffer, *output_buffer;
103         long frame_size, frame_allocated;
104         int input_error;
105         long last_frame_no;
106         ArrayList<int> render_strategies;
107 // Temporary frame for compressing output data
108         VFrame *temp_frame;
109 // Frame given to user to acquire data
110         VFrame *user_frame;
111         mjpeg_t *mjpeg;
112         Mutex *tuner_lock;
113         VDeviceBUZInput *input_thread;
114
115         struct buz_params bparm;
116         struct buz_requestbuffers breq;
117 // Can't CSYNC the first loop
118         int total_loops;
119 // Number of output frame to load
120         int output_number;
121
122         int brightness;
123         int hue;
124         int color;
125         int contrast;
126         int whiteness;
127 };
128
129 #endif