initial commit
[goodguy/history.git] / cinelerra-5.0 / cinelerra / vdevicelml.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 VDEVICELML_H
23 #define VDEVICELML_H
24
25 #include "guicast.h"
26 #include "vdevicebase.h"
27
28 // ./quicktime
29 #include "jpeg.h"
30 #include "quicktime.h"
31
32 #define INPUT_BUFFER_SIZE 65536
33
34 class VDeviceLML : public VDeviceBase
35 {
36 public:
37         VDeviceLML(VideoDevice *device);
38         ~VDeviceLML();
39
40         int open_input();
41         int open_output();
42         int close_all();
43         int read_buffer(VFrame *frame);
44         int write_buffer(VFrame *frame, EDL *edl);
45         int reset_parameters();
46         ArrayList<int>* get_render_strategies();
47
48 private:
49         int reopen_input();
50
51         inline unsigned char get_byte()
52         {
53                 if(!input_buffer) input_buffer = new unsigned char[INPUT_BUFFER_SIZE];
54                 if(input_position >= INPUT_BUFFER_SIZE) refill_input();
55                 return input_buffer[input_position++];
56         };
57
58         inline unsigned long next_bytes(int total)
59         {
60                 unsigned long result = 0;
61                 int i;
62
63                 if(!input_buffer) input_buffer = new unsigned char[INPUT_BUFFER_SIZE];
64                 if(input_position + total > INPUT_BUFFER_SIZE) refill_input();
65
66                 for(i = 0; i < total; i++)
67                 {
68                         result <<= 8;
69                         result |= input_buffer[input_position + i];
70                 }
71                 return result;
72         };
73
74         int refill_input();
75         inline int write_byte(unsigned char byte)
76         {
77                 if(!frame_buffer)
78                 {
79                         frame_buffer = new unsigned char[256000];
80                         frame_allocated = 256000;
81                 }
82
83                 if(frame_size >= frame_allocated)
84                 {
85                         unsigned char *new_frame = new unsigned char[frame_allocated * 2];
86                         memcpy(new_frame, frame_buffer, frame_size);
87                         delete frame_buffer;
88                         frame_buffer = new_frame;
89                         frame_allocated *= 2;
90                 }
91
92                 frame_buffer[frame_size++] = byte;
93                 return 0;
94         };
95
96         int write_fake_marker();
97
98         FILE *jvideo_fd;
99         unsigned char *input_buffer, *frame_buffer;
100         long input_position;
101         long frame_size, frame_allocated;
102         int input_error;
103 //      quicktime_mjpeg_hdr jpeg_header;
104         long last_frame_no;
105         ArrayList<int> render_strategies;
106 };
107
108 #endif