r851: Merge 2.1:
[cinelerra_cv/ct.git] / cinelerra / file.h
blobdd8c64bd73229782348be7f15e0ad28836ef7896
1 #ifndef FILE_H
2 #define FILE_H
4 #include <stdlib.h>
6 #include "asset.inc"
7 #include "condition.inc"
8 #include "edit.inc"
9 #include "filebase.inc"
10 #include "file.inc"
11 #include "filethread.inc"
12 #include "filexml.inc"
13 #include "formatwindow.inc"
14 #include "formattools.h"
15 #include "framecache.inc"
16 #include "guicast.h"
17 #include "mutex.inc"
18 #include "pluginserver.inc"
19 #include "preferences.inc"
20 #include "resample.inc"
21 #include "vframe.inc"
22 #include "packagingengine.h"
24 // ======================================= include file types here
28 // generic file opened by user
29 class File
31 public:
32 File();
33 ~File();
35 // Get attributes for various file formats.
36 // The dither parameter is carried over from recording, where dither is done at the device.
37 int get_options(FormatTools *format,
38 int audio_options,
39 int video_options,
40 int lock_compressor);
42 int raise_window();
43 // Close parameter window
44 void close_window();
46 // ===================================== start here
47 int set_processors(int cpus); // Set the number of cpus for certain codecs.
48 // Set the number of bytes to preload during reads for Quicktime.
49 int set_preload(int64_t size);
50 // When loading, the asset is deleted and a copy created in the EDL.
51 void set_asset(Asset *asset);
53 // Enable or disable frame caching. Must be tied to file to know when
54 // to delete the file object. Otherwise we'd delete just the cached frames
55 // while the list of open files grew.
56 void set_cache_frames(int value);
57 // Delete oldest frame from cache. Return 0 if successful. Return 1 if
58 // nothing to delete.
59 int purge_cache();
61 // Format may be preset if the asset format is not 0.
62 int open_file(Preferences *preferences,
63 Asset *asset,
64 int rd,
65 int wr,
66 int64_t base_samplerate,
67 float base_framerate);
69 // Get index from the file if one exists. Returns 0 on success.
70 int get_index(char *index_path);
72 // start a thread for writing to avoid blocking during record
73 int start_audio_thread(int64_t buffer_size, int ring_buffers);
74 int stop_audio_thread();
75 // The ring buffer must either be 1 or 2.
76 // The buffer_size for video needs to be > 1 on SMP systems to utilize
77 // multiple processors.
78 // For audio it's the number of samples per buffer.
79 // compressed - if 1 write_compressed_frame is called
80 // if 0 write_frames is called
81 int start_video_thread(int64_t buffer_size,
82 int color_model,
83 int ring_buffers,
84 int compressed);
85 int stop_video_thread();
86 int lock_read();
87 int unlock_read();
89 // write any headers and close file
90 // ignore_thread is used by SigHandler to break out of the threads.
91 int close_file(int ignore_thread = 0);
93 // get length of file normalized to base samplerate
94 int64_t get_audio_length(int64_t base_samplerate = -1);
95 int64_t get_video_length(float base_framerate = -1);
97 // get current position
98 int64_t get_audio_position(int64_t base_samplerate = -1);
99 int64_t get_video_position(float base_framerate = -1);
103 // write samples for the current channel
104 // written to disk and file pointer updated after last channel is written
105 // return 1 if failed
106 // subsequent writes must be <= than first write's size because of buffers
107 int write_samples(double **buffer, int64_t len);
109 // Only called by filethread to write an array of an array of channels of frames.
110 int write_frames(VFrame ***frames, int len);
114 // For writing buffers in a background thread use these functions to get the buffer.
115 // Get a pointer to a buffer to write to.
116 double** get_audio_buffer();
117 VFrame*** get_video_buffer();
119 // Used by ResourcePixmap to directly access the cache.
120 FrameCache* get_frame_cache();
122 // Schedule a buffer for writing on the thread.
123 // thread calls write_samples
124 int write_audio_buffer(int64_t len);
125 int write_video_buffer(int64_t len);
130 // set channel for buffer accesses
131 int set_channel(int channel);
132 // set position in samples
133 int set_audio_position(int64_t position, float base_samplerate);
135 // Read samples for one channel into a shared memory segment.
136 // The offset is the offset in floats from the beginning of the buffer and the len
137 // is the length in floats from the offset.
138 // advances file pointer
139 // return 1 if failed
140 int read_samples(double *buffer, int64_t len, int64_t base_samplerate, float *buffer_float = 0);
143 // set layer for video read
144 int set_layer(int layer);
145 // set position in frames
146 int set_video_position(int64_t position, float base_framerate);
148 // Read frame of video into the argument
149 int read_frame(VFrame *frame);
152 // The following involve no extra copies.
153 // Direct copy routines for direct copy playback
154 int can_copy_from(Edit *edit, int64_t position, int output_w, int output_h); // This file can copy frames directly from the asset
155 int get_render_strategy(ArrayList<int>* render_strategies);
156 int64_t compressed_frame_size();
157 int read_compressed_frame(VFrame *buffer);
158 int write_compressed_frame(VFrame *buffer);
160 // These are separated into two routines so a file doesn't have to be
161 // allocated.
162 // Get best colormodel to translate for hardware acceleration
163 int get_best_colormodel(int driver);
164 static int get_best_colormodel(Asset *asset, int driver);
165 // Get nearest colormodel in format after the file is opened and the
166 // direction determined to know whether to use a temp.
167 int colormodel_supported(int colormodel);
169 // Used by CICache to calculate the total size of the cache.
170 // Based on temporary frames and a call to the file subclass.
171 // The return value is limited 1MB each in case of audio file.
172 // The minimum setting for cache_size should be bigger than 1MB.
173 int64_t get_memory_usage();
175 static int supports_video(ArrayList<PluginServer*> *plugindb, char *format); // returns 1 if the format supports video or audio
176 static int supports_audio(ArrayList<PluginServer*> *plugindb, char *format);
177 // Get the extension for the filename
178 static char* get_tag(int format);
179 static int supports_video(int format); // returns 1 if the format supports video or audio
180 static int supports_audio(int format);
181 static int strtoformat(char *format);
182 static char* formattostr(int format);
183 static int strtoformat(ArrayList<PluginServer*> *plugindb, char *format);
184 static char* formattostr(ArrayList<PluginServer*> *plugindb, int format);
185 static int strtobits(char *bits);
186 static char* bitstostr(int bits);
187 static int str_to_byteorder(char *string);
188 static char* byteorder_to_str(int byte_order);
189 int bytes_per_sample(int bits); // Convert the bit descriptor into a byte count.
191 Asset *asset; // Copy of asset since File outlives EDL
192 FileBase *file; // virtual class for file type
193 // Threads for writing data in the background.
194 FileThread *audio_thread, *video_thread;
196 // Temporary storage for color conversions
197 VFrame *temp_frame;
199 // Resampling engine
200 Resample *resample;
201 Resample_float *resample_float;
203 // Lock writes while recording video and audio.
204 // A binary lock won't do. We need a FIFO lock.
205 Condition *write_lock;
206 int cpus;
207 int64_t playback_preload;
209 // Position information is migrated here to allow samplerate conversion.
210 // Current position in file's samplerate.
211 // Can't normalize to base samplerate because this would
212 // require fractional positioning to know if the file's position changed.
213 int64_t current_sample;
214 int64_t current_frame;
215 int current_channel;
216 int current_layer;
218 // Position information normalized
219 int64_t normalized_sample;
220 int64_t normalized_sample_rate;
221 Preferences *preferences;
223 static PackagingEngine *new_packaging_engine(Asset *asset);
225 private:
226 void reset_parameters();
228 int getting_options;
229 BC_WindowBase *format_window;
230 Mutex *format_completion;
231 FrameCache *frame_cache;
232 // Copy read frames to the cache
233 int use_cache;
236 #endif