prevent popup deactivation while button_down
[goodguy/history.git] / cinelerra-5.0 / cinelerra / file.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2009 Adam Williams <broadcast at earthling dot net>
5  * 
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  * 
20  */
21
22 #ifndef FILE_H
23 #define FILE_H
24
25 #include <stdlib.h>
26
27 #include "asset.inc"
28 #include "condition.inc"
29 #include "edit.inc"
30 #include "filebase.inc"
31 #include "file.inc"
32
33 #include "filethread.inc"
34 #include "filexml.inc"
35 #include "formattools.inc"
36 #include "formatwindow.inc"
37 #include "framecache.inc"
38 #include "guicast.h"
39 #include "mutex.inc"
40 #include "packagingengine.inc"
41 #include "pluginserver.inc"
42 #include "preferences.inc"
43 #include "samples.inc"
44 #include "vframe.inc"
45
46 // ======================================= include file types here
47
48
49
50 // generic file opened by user
51 class File
52 {
53 public:
54         File();
55         ~File();
56
57 // Get attributes for various file formats.
58 // The dither parameter is carried over from recording, where dither is done at the device.
59         int get_options(FormatTools *format,
60                 int audio_options,
61                 int video_options);
62
63         int raise_window();
64 // Close parameter window
65         void close_window();
66
67 // ===================================== start here
68         int set_processors(int cpus);   // Set the number of cpus for certain codecs.
69 // Set the number of bytes to preload during reads for Quicktime.
70         int set_preload(int64_t size);
71 // Set the subtitle for libzmpeg3.  -1 disables subtitles.
72         void set_subtitle(int value);
73 // Set whether to interpolate raw images
74         void set_interpolate_raw(int value);
75 // Set whether to white balance raw images.  Always 0 if no interpolation.
76         void set_white_balance_raw(int value);
77 // When loading, the asset is deleted and a copy created in the EDL.
78 //      void set_asset(Asset *asset);
79
80 // Enable or disable frame caching.  Must be tied to file to know when 
81 // to delete the file object.  Otherwise we'd delete just the cached frames
82 // while the list of open files grew.
83         void set_cache_frames(int value);
84 // Delete frame cache.  Return 0 if successful.  Return 1 if 
85 // nothing to delete.
86         int purge_cache();
87 // Delete oldest frame from cache.  Return 0 if successful.  Return 1 if 
88 // nothing to delete.
89         int delete_oldest();
90
91 // Format may be preset if the asset format is not 0.
92         int open_file(Preferences *preferences, 
93                 Asset *asset, 
94                 int rd, 
95                 int wr);
96
97 // Get index from the file if one exists.  Returns 0 on success.
98         int get_index(char *index_path);
99
100 // start a thread for writing to avoid blocking during record
101         int start_audio_thread(int buffer_size, int ring_buffers);
102         int stop_audio_thread();
103 // The ring buffer must either be 1 or 2.
104 // The buffer_size for video needs to be > 1 on SMP systems to utilize 
105 // multiple processors.
106 // For audio it's the number of samples per buffer.
107 // compressed - if 1 write_compressed_frame is called
108 //              if 0 write_frames is called
109         int start_video_thread(int buffer_size, 
110                 int color_model, 
111                 int ring_buffers, 
112                 int compressed);
113         int stop_video_thread();
114
115         int start_video_decode_thread();
116
117 // Return the thread.
118 // Used by functions that read only.
119         FileThread* get_video_thread();
120
121 // write any headers and close file
122 // ignore_thread is used by SigHandler to break out of the threads.
123         int close_file(int ignore_thread = 0);
124         void delete_temp_samples_buffer();
125         void delete_temp_frame_buffer();
126
127 // get length of file normalized to base samplerate
128         int64_t get_audio_length();
129         int64_t get_video_length();
130
131 // get current position
132         int64_t get_audio_position();
133         int64_t get_video_position();
134         
135
136
137 // write samples for the current channel
138 // written to disk and file pointer updated after last channel is written
139 // return 1 if failed
140 // subsequent writes must be <= than first write's size because of buffers
141         int write_samples(Samples **buffer, int64_t len);
142
143 // Only called by filethread to write an array of an array of channels of frames.
144         int write_frames(VFrame ***frames, int len);
145
146
147
148 // For writing buffers in a background thread use these functions to get the buffer.
149 // Get a pointer to a buffer to write to.
150         Samples** get_audio_buffer();
151         VFrame*** get_video_buffer();
152
153 // Used by ResourcePixmap to directly access the cache.
154         FrameCache* get_frame_cache();
155
156 // Schedule a buffer for writing on the thread.
157 // thread calls write_samples
158         int write_audio_buffer(int64_t len);
159         int write_video_buffer(int64_t len);
160
161
162
163
164 // set channel for buffer accesses
165         int set_channel(int channel);
166         int get_channel();
167
168 // set dvd program, no=-1 get current program
169         int set_program(int no);
170 // access cell times
171         int get_cell_time(int no, double &time);
172 // return stream pid
173         int get_video_pid(int track);
174 // return video info
175         int get_video_info(int track, int &pid, double &framerate,
176                 int &width, int &height, char *title);
177 // update asset with selected audio/video layer data
178         int select_video_stream(Asset *asset, int vstream);
179         int select_audio_stream(Asset *asset, int astream);
180 // get dvb system_time
181         int get_system_time(int64_t &tm);
182 // get dvb audio channels for video stream
183         int get_audio_for_video(int vstream, int astream, int64_t &channel_mask);
184 // get frame thumbnail data
185         int get_thumbnail(int stream,
186                 int64_t &position, unsigned char *&thumbnail, int &ww, int &hh);
187         int set_skimming(int track, int skim, skim_fn fn, void *vp);
188         int skim_video(int track, void *vp, skim_fn fn);
189
190 // set position in samples
191         int set_audio_position(int64_t position);
192
193 // Read samples for one channel into a shared memory segment.
194 // The offset is the offset in floats from the beginning of the buffer and the len
195 // is the length in floats from the offset.
196 // advances file pointer
197 // return 1 if failed
198         int read_samples(Samples *buffer, int64_t len);
199
200
201 // set layer for video read
202 // is_thread is used by FileThread::run to prevent recursive lockup.
203         int set_layer(int layer, int is_thread = 0);
204 // set position in frames
205 // is_thread is set by FileThread::run to prevent recursive lockup.
206 //      int set_video_position(int64_t position, float base_framerate /* = -1 */, int is_thread /* = 0 */);
207         int set_video_position(int64_t position, int is_thread /* = 0 */);
208
209 // Read frame of video into the argument
210 // is_thread is used by FileThread::run to prevent recursive lockup.
211         int read_frame(VFrame *frame, int is_thread = 0);
212
213
214 // The following involve no extra copies.
215 // Direct copy routines for direct copy playback
216         int can_copy_from(Asset *asset, int64_t position, int output_w, int output_h); // This file can copy frames directly from the asset
217         int get_render_strategy(ArrayList<int>* render_strategies);
218         int64_t compressed_frame_size();
219         int read_compressed_frame(VFrame *buffer);
220         int write_compressed_frame(VFrame *buffer);
221
222 // These are separated into two routines so a file doesn't have to be
223 // allocated.
224 // Get best colormodel to translate for hardware accelerated playback.
225 // Called by VRender.
226         int get_best_colormodel(int driver);
227 // Get best colormodel for hardware accelerated recording.
228 // Called by VideoDevice.
229         static int get_best_colormodel(Asset *asset, int driver);
230 // Get nearest colormodel that can be decoded without a temporary frame.
231 // Used by read_frame.
232         int colormodel_supported(int colormodel);
233
234 // stubs for now
235         static const char *compressiontostr(const char *codec) { return codec; }
236         static const char *strtocompression(const char *string) { return string; }
237 // subclass memory usage
238         int64_t file_memory_usage();
239 // Used by CICache to calculate the total size of the cache.
240 // Based on temporary frames and a call to the file subclass.
241 // The return value is limited 1MB each in case of audio file.
242 // The minimum setting for cache_size should be bigger than 1MB.
243         int64_t get_memory_usage();
244
245         static int supports_video(ArrayList<PluginServer*> *plugindb, char *format);   // returns 1 if the format supports video or audio
246         static int supports_audio(ArrayList<PluginServer*> *plugindb, char *format);
247 // Get the extension for the filename
248         static const char* get_tag(int format);
249         static const char* get_prefix(int format);
250         static int supports_video(int format);   // returns 1 if the format supports video or audio
251         static int supports_audio(int format);
252         static int strtoformat(const char *format);
253         static const char* formattostr(int format);
254         static int strtoformat(ArrayList<PluginServer*> *plugindb, const char *format);
255         static const char* formattostr(ArrayList<PluginServer*> *plugindb, int format);
256         static int strtobits(const char *bits);
257         static const char* bitstostr(int bits);
258         static int str_to_byteorder(const char *string);
259         static const char* byteorder_to_str(int byte_order);
260         int bytes_per_sample(int bits); // Convert the bit descriptor into a byte count.
261 // get record stream file descriptor
262         int record_fd();
263
264         Asset *asset;    // Copy of asset since File outlives EDL
265         FileBase *file; // virtual class for file type
266 // Threads for writing data in the background.
267         FileThread *audio_thread, *video_thread; 
268
269 // Temporary storage for color conversions
270         VFrame *temp_frame;
271
272 // Temporary storage for get_audio_buffer.
273 // [ring buffers][channels][Samples]
274         Samples ***temp_samples_buffer;
275
276 // Temporary storage for get_video_buffer.
277 // [Ring buffers][layers][temp_frame_size][VFrame]
278         VFrame ****temp_frame_buffer;
279 // Return value of get_video_buffer
280         VFrame ***current_frame_buffer;
281 // server copies of variables for threaded recording
282         int audio_ring_buffers;
283         int video_ring_buffers;
284 // Number of frames in the temp_frame_buffer
285         int video_buffer_size;
286
287
288 // Lock writes while recording video and audio.
289 // A binary lock won't do.  We need a FIFO lock.
290         Condition *write_lock;
291         int cpus;
292         int64_t playback_preload;
293         int playback_subtitle;
294         int interpolate_raw;
295         int white_balance_raw;
296
297 // Position information is migrated here to allow samplerate conversion.
298 // Current position in file's samplerate.
299 // Can't normalize to base samplerate because this would 
300 // require fractional positioning to know if the file's position changed.
301         int64_t current_sample;
302         int64_t current_frame;
303         int current_channel;
304         int current_layer;
305         int current_program;
306
307 // Position information normalized to project rates
308         int64_t normalized_sample;
309 //      int64_t normalized_sample_rate;
310         Preferences *preferences;
311         int wr, rd;
312         static PackagingEngine *new_packaging_engine(Asset *asset);
313
314 private:
315         void reset_parameters();
316
317         int getting_options;
318         BC_WindowBase *format_window;
319         Condition *format_completion;
320 // framecache is only active locally, not on fileserver
321         FrameCache *frame_cache;
322 // Copy read frames to the cache
323         int use_cache;
324
325 };
326
327 #endif