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

file.h

Go to the documentation of this file.
00001 #ifndef FILE_H
00002 #define FILE_H
00003 
00004 #include <stdlib.h>
00005 
00006 #include "asset.inc"
00007 #include "condition.inc"
00008 #include "edit.inc"
00009 #include "filebase.inc"
00010 #include "file.inc"
00011 #include "filethread.inc"
00012 #include "filexml.inc"
00013 #include "formatwindow.inc"
00014 #include "formattools.h"
00015 #include "framecache.inc"
00016 #include "guicast.h"
00017 #include "mutex.inc"
00018 #include "pluginserver.inc"
00019 #include "preferences.inc"
00020 #include "resample.inc"
00021 #include "vframe.inc"
00022 
00023 // ======================================= include file types here
00024 
00025 
00026 
00027 // generic file opened by user
00028 class File
00029 {
00030 public:
00031         File();
00032         ~File();
00033 
00034 // Get attributes for various file formats.
00035 // The dither parameter is carried over from recording, where dither is done at the device.
00036         int get_options(FormatTools *format, 
00037                         int audio_options,
00038                         int video_options,
00039                         int lock_compressor);
00040 
00041         int raise_window();
00042 // Close parameter window
00043         void close_window();
00044 
00045 // ===================================== start here
00046         int set_processors(int cpus);   // Set the number of cpus for certain codecs.
00047         int set_preload(int64_t size);     // Set the number of bytes to preload during reads.
00048 // When loading, the asset is deleted and a copy created in the EDL.
00049         void set_asset(Asset *asset);
00050 
00051 // Enable or disable frame caching.  Must be tied to file to know when 
00052 // to delete the file object.  Otherwise we'd delete just the cached frames
00053 // while the list of open files grew.
00054         void set_cache_frames(int value);
00055 // Delete oldest frame from cache.  Return 0 if successful.  Return 1 if 
00056 // nothing to delete.
00057         int purge_cache();
00058 
00059 // Format may be preset if the asset format is not 0.
00060         int open_file(Preferences *preferences, 
00061                 Asset *asset, 
00062                 int rd, 
00063                 int wr,
00064                 int64_t base_samplerate,
00065                 float base_framerate);
00066 
00067 // Get index from the file if one exists.  Returns 0 on success.
00068         int get_index(char *index_path);
00069 
00070 // start a thread for writing to avoid blocking during record
00071         int start_audio_thread(int64_t buffer_size, int ring_buffers);
00072         int stop_audio_thread();
00073 // The ring buffer must either be 1 or 2.
00074 // The buffer_size for video needs to be > 1 on SMP systems to utilize 
00075 // multiple processors.
00076 // For audio it's the number of samples per buffer.
00077 // compressed - if 1 write_compressed_frame is called
00078 //              if 0 write_frames is called
00079         int start_video_thread(int64_t buffer_size, 
00080                 int color_model, 
00081                 int ring_buffers, 
00082                 int compressed);
00083         int stop_video_thread();
00084         int lock_read();
00085         int unlock_read();
00086 
00087 // write any headers and close file
00088 // ignore_thread is used by SigHandler to break out of the threads.
00089         int close_file(int ignore_thread = 0);
00090 
00091 // set channel for buffer accesses
00092         int set_channel(int channel);
00093 
00094 // set layer for video read
00095         int set_layer(int layer);
00096 
00097 // get length of file normalized to base samplerate
00098         int64_t get_audio_length(int64_t base_samplerate = -1);
00099         int64_t get_video_length(float base_framerate = -1);
00100 
00101 // get current position
00102         int64_t get_audio_position(int64_t base_samplerate = -1);
00103         int64_t get_video_position(float base_framerate = -1);
00104         
00105 
00106 // set position in samples
00107         int set_audio_position(int64_t position, float base_samplerate);
00108 // set position in frames
00109         int set_video_position(int64_t position, float base_framerate);
00110 
00111 // write samples for the current channel
00112 // written to disk and file pointer updated after last channel is written
00113 // return 1 if failed
00114 // subsequent writes must be <= than first write's size because of buffers
00115         int write_samples(double **buffer, int64_t len);
00116 
00117 // Only called by filethread
00118         int write_frames(VFrame ***frames, int len);
00119 
00120 // For writing buffers in a background thread use these functions to get the buffer.
00121 // Get a pointer to a buffer to write to.
00122         double** get_audio_buffer();
00123         VFrame*** get_video_buffer();
00124 
00125 // Used by ResourcePixmap to directly access the cache.
00126         FrameCache* get_frame_cache();
00127 
00128 // Schedule a buffer for writing on the thread.
00129 // thread calls write_samples
00130         int write_audio_buffer(int64_t len);
00131         int write_video_buffer(int64_t len);
00132 
00133 // Read samples for one channel into a shared memory segment.
00134 // The offset is the offset in floats from the beginning of the buffer and the len
00135 // is the length in floats from the offset.
00136 // advances file pointer
00137 // return 1 if failed
00138         int read_samples(double *buffer, int64_t len, int64_t base_samplerate, float *buffer_float = 0);
00139 
00140 
00141 // Read frame of video into the argument
00142         int File::read_frame(VFrame *frame);
00143 
00144 
00145 // The following involve no extra copies.
00146 // Direct copy routines for direct copy playback
00147         int can_copy_from(Edit *edit, int64_t position, int output_w, int output_h); // This file can copy frames directly from the asset
00148         int get_render_strategy(ArrayList<int>* render_strategies);
00149         int64_t compressed_frame_size();
00150         int read_compressed_frame(VFrame *buffer);
00151         int write_compressed_frame(VFrame *buffer);
00152 
00153 // These are separated into two routines so a file doesn't have to be
00154 // allocated.
00155 // Get best colormodel to translate for hardware acceleration
00156         int get_best_colormodel(int driver);
00157         static int get_best_colormodel(Asset *asset, int driver);
00158 // Get nearest colormodel in format after the file is opened and the 
00159 // direction determined to know whether to use a temp.
00160         int colormodel_supported(int colormodel);
00161 
00162 // Used by CICache to calculate the total size of the cache.
00163 // Based on temporary frames and a call to the file subclass.
00164 // The return value is limited 1MB each in case of audio file.
00165 // The minimum setting for cache_size should be bigger than 1MB.
00166         int get_memory_usage();
00167 
00168         static int supports_video(ArrayList<PluginServer*> *plugindb, char *format);   // returns 1 if the format supports video or audio
00169         static int supports_audio(ArrayList<PluginServer*> *plugindb, char *format);
00170         static int supports_video(int format);   // returns 1 if the format supports video or audio
00171         static int supports_audio(int format);
00172         static int strtoformat(char *format);
00173         static char* formattostr(int format);
00174         static int strtoformat(ArrayList<PluginServer*> *plugindb, char *format);
00175         static char* formattostr(ArrayList<PluginServer*> *plugindb, int format);
00176         static int strtobits(char *bits);
00177         static char* bitstostr(int bits);
00178         static int str_to_byteorder(char *string);
00179         static char* byteorder_to_str(int byte_order);
00180         int bytes_per_sample(int bits); // Convert the bit descriptor into a byte count.
00181 
00182         Asset *asset;    // Copy of asset since File outlives EDL
00183         FileBase *file; // virtual class for file type
00184 // Threads for writing data in the background.
00185         FileThread *audio_thread, *video_thread; 
00186 
00187 // Temporary storage for color conversions
00188         VFrame *temp_frame;
00189 
00190 // Resampling engine
00191         Resample *resample;
00192         Resample_float *resample_float;
00193 
00194 // Lock writes while recording video and audio.
00195 // A binary lock won't do.  We need a FIFO lock.
00196         Condition *write_lock;
00197         int cpus;
00198         int64_t playback_preload;
00199 
00200 // Position information is migrated here to allow samplerate conversion.
00201 // Current position in file's samplerate.
00202 // Can't normalize to base samplerate because this would 
00203 // require fractional positioning to know if the file's position changed.
00204         int64_t current_sample;
00205         int64_t current_frame;
00206         int current_channel;
00207         int current_layer;
00208 
00209 // Position information normalized
00210         int64_t normalized_sample;
00211         int64_t normalized_sample_rate;
00212         Preferences *preferences;
00213 
00214 
00215 private:
00216         void reset_parameters();
00217 
00218         int getting_options;
00219         BC_WindowBase *format_window;
00220         Mutex *format_completion;
00221         FrameCache *frame_cache;
00222 // Copy read frames to the cache
00223         int use_cache;
00224 };
00225 
00226 #endif

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