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