r665: Merged the official release 2.0.
[cinelerra_cv.git] / cinelerra / filebase.h
blob38960be6c25988790304257884249a9294459869
1 #ifndef FILEBASE_H
2 #define FILEBASE_H
4 #include "asset.inc"
5 #include "assets.inc"
6 #include "colormodels.h"
7 #include "edit.inc"
8 #include "guicast.h"
9 #include "file.inc"
10 #include "filelist.inc"
11 #include "overlayframe.inc"
12 #include "strategies.inc"
13 #include "vframe.inc"
15 #include <sys/types.h>
17 // inherited by every file interpreter
18 class FileBase
20 public:
21 FileBase(Asset *asset, File *file);
22 virtual ~FileBase();
25 friend class File;
26 friend class FileList;
27 friend class FrameWriter;
32 int get_mode(char *mode, int rd, int wr);
33 int reset_parameters();
37 virtual void get_parameters(BC_WindowBase *parent_window,
38 Asset *asset,
39 BC_WindowBase **format_window,
40 int audio_options,
41 int video_options,
42 int lock_compressor) {};
46 virtual int get_index(char *index_path) { return 1; };
47 virtual int check_header() { return 0; }; // Test file to see if it is of this type.
48 virtual int reset_parameters_derived() {};
49 virtual int read_header() {}; // WAV files for getting header
50 virtual int open_file(int rd, int wr) {};
51 virtual int close_file();
52 virtual int close_file_derived() {};
53 int set_dither();
54 virtual int seek_end() { return 0; };
55 virtual int seek_start() { return 0; };
56 virtual int64_t get_video_position() { return 0; };
57 virtual int64_t get_audio_position() { return 0; };
58 virtual int set_video_position(int64_t x) { return 0; };
59 virtual int set_audio_position(int64_t x) { return 0; };
61 // Subclass should call this to add the base class allocation.
62 // Only used in read mode.
63 virtual int get_memory_usage() { return 0; };
65 virtual int write_samples(double **buffer,
66 int64_t len) { return 0; };
67 virtual int write_frames(VFrame ***frames, int len) { return 0; };
68 virtual int read_compressed_frame(VFrame *buffer) { return 0; };
69 virtual int write_compressed_frame(VFrame *buffers) { return 0; };
70 virtual int64_t compressed_frame_size() { return 0; };
71 // Doubles are used to allow resampling
73 virtual int read_samples(double *buffer, int64_t len) { return 0; };
76 virtual int prefer_samples_float() {return 0;};
77 virtual int read_samples_float(float *buffer, int64_t len) { return 0; };
79 virtual int read_frame(VFrame *frame) { return 1; };
81 // Return either the argument or another colormodel which read_frame should
82 // use.
83 virtual int colormodel_supported(int colormodel) { return BC_RGB888; };
84 // This file can copy compressed frames directly from the asset
85 virtual int can_copy_from(Edit *edit, int64_t position) { return 0; };
86 virtual int get_render_strategy(ArrayList<int>* render_strategies) { return VRENDER_VPIXEL; };
88 protected:
89 // Return 1 if the render_strategy is present on the list.
90 static int search_render_strategies(ArrayList<int>* render_strategies, int render_strategy);
92 // convert samples into file format
93 int64_t samples_to_raw(char *out_buffer,
94 float **in_buffer, // was **buffer
95 int64_t input_len,
96 int bits,
97 int channels,
98 int byte_order,
99 int signed_);
101 // overwrites the buffer from PCM data depending on feather.
102 int raw_to_samples(float *out_buffer, char *in_buffer,
103 int64_t samples, int bits, int channels, int channel, int feather,
104 float lfeather_len, float lfeather_gain, float lfeather_slope);
106 // Overwrite the buffer from float data using feather.
107 int overlay_float_buffer(float *out_buffer, float *in_buffer,
108 int64_t samples,
109 float lfeather_len, float lfeather_gain, float lfeather_slope);
111 // convert a frame to and from file format
113 int64_t frame_to_raw(unsigned char *out_buffer,
114 VFrame *in_frame,
115 int w,
116 int h,
117 int use_alpha,
118 int use_float,
119 int color_model);
121 // allocate a buffer for translating int to float
122 int get_audio_buffer(char **buffer, int64_t len, int64_t bits, int64_t channels); // audio
124 // Allocate a buffer for feathering floats
125 int get_float_buffer(float **buffer, int64_t len);
127 // allocate a buffer for translating video to VFrame
128 int get_video_buffer(unsigned char **buffer, int depth); // video
129 int get_row_pointers(unsigned char *buffer, unsigned char ***pointers, int depth);
130 static int match4(char *in, char *out); // match 4 bytes for a quicktime type
132 int64_t ima4_samples_to_bytes(int64_t samples, int channels);
133 int64_t ima4_bytes_to_samples(int64_t bytes, int channels);
135 char *audio_buffer_in, *audio_buffer_out; // for raw audio reads and writes
136 float *float_buffer; // for floating point feathering
137 unsigned char *video_buffer_in, *video_buffer_out;
138 unsigned char **row_pointers_in, **row_pointers_out;
139 int64_t prev_buffer_position; // for audio determines if reading raw data is necessary
140 int64_t prev_frame_position; // for video determines if reading raw video data is necessary
141 int64_t prev_bytes; // determines if new raw buffer is needed and used for getting memory usage
142 int64_t prev_len;
143 int prev_track;
144 int prev_layer;
145 Asset *asset;
146 int wr, rd;
147 int dither;
148 int internal_byte_order;
149 File *file;
151 private:
155 // ================================= Audio compression
156 // ULAW
157 float ulawtofloat(char ulaw);
158 char floattoulaw(float value);
159 int generate_ulaw_tables();
160 int delete_ulaw_tables();
161 float *ulawtofloat_table, *ulawtofloat_ptr;
162 unsigned char *floattoulaw_table, *floattoulaw_ptr;
164 // IMA4
165 int init_ima4();
166 int delete_ima4();
167 int ima4_decode_block(int16_t *output, unsigned char *input);
168 int ima4_decode_sample(int *predictor, int nibble, int *index, int *step);
169 int ima4_encode_block(unsigned char *output, int16_t *input, int step, int channel);
170 int ima4_encode_sample(int *last_sample, int *last_index, int *nibble, int next_sample);
172 static int ima4_step[89];
173 static int ima4_index[16];
174 int *last_ima4_samples;
175 int *last_ima4_indexes;
176 int ima4_block_size;
177 int ima4_block_samples;
178 OverlayFrame *overlayer;
181 #endif