6 #include "colormodels.h"
10 #include "filelist.inc"
11 #include "overlayframe.inc"
12 #include "strategies.inc"
15 #include <sys/types.h>
17 // inherited by every file interpreter
21 FileBase(Asset
*asset
, File
*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
,
39 BC_WindowBase
**format_window
,
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() {};
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
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
; };
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
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
,
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
,
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
148 int internal_byte_order
;
155 // ================================= Audio compression
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
;
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
;
177 int ima4_block_samples
;
178 OverlayFrame
*overlayer
;