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