Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

filebase.h

Go to the documentation of this file.
00001 #ifndef FILEBASE_H
00002 #define FILEBASE_H
00003 
00004 #include "asset.inc"
00005 #include "assets.inc"
00006 #include "colormodels.h"
00007 #include "edit.inc"
00008 #include "guicast.h"
00009 #include "file.inc"
00010 #include "filelist.inc"
00011 #include "overlayframe.inc"
00012 #include "strategies.inc"
00013 #include "vframe.inc"
00014 
00015 #include <sys/types.h>
00016 
00017 // inherited by every file interpreter
00018 class FileBase
00019 {
00020 public:
00021         FileBase(Asset *asset, File *file);
00022         virtual ~FileBase();
00023 
00024 
00025         friend class File;
00026         friend class FileList;
00027         friend class FrameWriter;
00028 
00029 
00030 
00031 
00032         int get_mode(char *mode, int rd, int wr);
00033         int reset_parameters();
00034 
00035 
00036 
00037         virtual void get_parameters(BC_WindowBase *parent_window, 
00038                         Asset *asset, 
00039                         BC_WindowBase **format_window,
00040                         int audio_options,
00041                         int video_options,
00042                         int lock_compressor) {};
00043 
00044 
00045 
00046         virtual int get_index(char *index_path) { return 1; };
00047         virtual int check_header() { return 0; };  // Test file to see if it is of this type.
00048         virtual int reset_parameters_derived() {};
00049         virtual int read_header() {};     // WAV files for getting header
00050         virtual int open_file(int rd, int wr) {};
00051         virtual int close_file();
00052         virtual int close_file_derived() {};
00053         int set_dither();
00054         virtual int seek_end() { return 0; };
00055         virtual int seek_start() { return 0; };
00056         virtual int64_t get_video_position() { return 0; };
00057         virtual int64_t get_audio_position() { return 0; };
00058         virtual int set_video_position(int64_t x) { return 0; };
00059         virtual int set_audio_position(int64_t x) { return 0; };
00060 
00061 // Subclass should call this to add the base class allocation.
00062 // Only used in read mode.
00063         virtual int get_memory_usage() { return 0; };
00064 
00065         virtual int write_samples(double **buffer, 
00066                 int64_t len) { return 0; };
00067         virtual int write_frames(VFrame ***frames, int len) { return 0; };
00068         virtual int read_compressed_frame(VFrame *buffer) { return 0; };
00069         virtual int write_compressed_frame(VFrame *buffers) { return 0; };
00070         virtual int64_t compressed_frame_size() { return 0; };
00071 // Doubles are used to allow resampling
00072 
00073         virtual int read_samples(double *buffer, int64_t len) { return 0; };
00074 
00075 
00076         virtual int prefer_samples_float() {return 0;};
00077         virtual int read_samples_float(float *buffer, int64_t len) { return 0; };
00078 
00079         virtual int read_frame(VFrame *frame) { return 1; };
00080 
00081 // Return either the argument or another colormodel which read_frame should
00082 // use.
00083         virtual int colormodel_supported(int colormodel) { return BC_RGB888; };
00084 // This file can copy compressed frames directly from the asset
00085         virtual int can_copy_from(Edit *edit, int64_t position) { return 0; }; 
00086         virtual int get_render_strategy(ArrayList<int>* render_strategies) { return VRENDER_VPIXEL; };
00087 
00088 protected:
00089 // Return 1 if the render_strategy is present on the list.
00090         static int search_render_strategies(ArrayList<int>* render_strategies, int render_strategy);
00091 
00092 // convert samples into file format
00093         int64_t samples_to_raw(char *out_buffer, 
00094                                                         float **in_buffer, // was **buffer
00095                                                         int64_t input_len, 
00096                                                         int bits, 
00097                                                         int channels,
00098                                                         int byte_order,
00099                                                         int signed_);
00100 
00101 // overwrites the buffer from PCM data depending on feather.
00102         int raw_to_samples(float *out_buffer, char *in_buffer, 
00103                 int64_t samples, int bits, int channels, int channel, int feather, 
00104                 float lfeather_len, float lfeather_gain, float lfeather_slope);
00105 
00106 // Overwrite the buffer from float data using feather.
00107         int overlay_float_buffer(float *out_buffer, float *in_buffer, 
00108                 int64_t samples, 
00109                 float lfeather_len, float lfeather_gain, float lfeather_slope);
00110 
00111 // convert a frame to and from file format
00112 
00113         int64_t frame_to_raw(unsigned char *out_buffer,
00114                                         VFrame *in_frame,
00115                                         int w,
00116                                         int h,
00117                                         int use_alpha,
00118                                         int use_float,
00119                                         int color_model);
00120 
00121 // allocate a buffer for translating int to float
00122         int get_audio_buffer(char **buffer, int64_t len, int64_t bits, int64_t channels); // audio
00123 
00124 // Allocate a buffer for feathering floats
00125         int get_float_buffer(float **buffer, int64_t len);
00126 
00127 // allocate a buffer for translating video to VFrame
00128         int get_video_buffer(unsigned char **buffer, int depth); // video
00129         int get_row_pointers(unsigned char *buffer, unsigned char ***pointers, int depth);
00130         static int match4(char *in, char *out);   // match 4 bytes for a quicktime type
00131 
00132         int64_t ima4_samples_to_bytes(int64_t samples, int channels);
00133         int64_t ima4_bytes_to_samples(int64_t bytes, int channels);
00134 
00135         char *audio_buffer_in, *audio_buffer_out;    // for raw audio reads and writes
00136         float *float_buffer;          // for floating point feathering
00137         unsigned char *video_buffer_in, *video_buffer_out;
00138         unsigned char **row_pointers_in, **row_pointers_out;
00139         int64_t prev_buffer_position;  // for audio determines if reading raw data is necessary
00140         int64_t prev_frame_position;   // for video determines if reading raw video data is necessary
00141         int64_t prev_bytes; // determines if new raw buffer is needed and used for getting memory usage
00142         int64_t prev_len;
00143         int prev_track;
00144         int prev_layer;
00145         Asset *asset;
00146         int wr, rd;
00147         int dither;
00148         int internal_byte_order;
00149         File *file;
00150 
00151 private:
00152 
00153 
00154 
00155 // ================================= Audio compression
00156 // ULAW
00157         float ulawtofloat(char ulaw);
00158         char floattoulaw(float value);
00159         int generate_ulaw_tables();
00160         int delete_ulaw_tables();
00161         float *ulawtofloat_table, *ulawtofloat_ptr;
00162         unsigned char *floattoulaw_table, *floattoulaw_ptr;
00163 
00164 // IMA4
00165         int init_ima4();
00166         int delete_ima4();
00167         int ima4_decode_block(int16_t *output, unsigned char *input);
00168         int ima4_decode_sample(int *predictor, int nibble, int *index, int *step);
00169         int ima4_encode_block(unsigned char *output, int16_t *input, int step, int channel);
00170         int ima4_encode_sample(int *last_sample, int *last_index, int *nibble, int next_sample);
00171 
00172         static int ima4_step[89];
00173         static int ima4_index[16];
00174         int *last_ima4_samples;
00175         int *last_ima4_indexes;
00176         int ima4_block_size;
00177         int ima4_block_samples;
00178         OverlayFrame *overlayer;
00179 };
00180 
00181 #endif

Generated on Sun Jan 8 13:38:54 2006 for Cinelerra-svn by  doxygen 1.4.4