r602: Fix baver's code... don't insert timecode when show_tc is not set
[cinelerra_cv/mob.git] / cinelerra / file.h
blob1a8819b3c7868bedaa6eaf360197270b616a9a80
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 "resample.inc"
20 #include "vframe.inc"
22 // ======================================= include file types here
26 // generic file opened by user
27 class File
29 public:
30 File();
31 ~File();
33 // Get attributes for various file formats.
34 // The dither parameter is carried over from recording, where dither is done at the device.
35 int get_options(FormatTools *format,
36 int audio_options,
37 int video_options,
38 int lock_compressor);
40 int raise_window();
41 // Close parameter window
42 void close_window();
44 // ===================================== start here
45 int set_processors(int cpus); // Set the number of cpus for certain codecs.
46 int set_preload(int64_t size); // Set the number of bytes to preload during reads.
47 // When loading, the asset is deleted and a copy created in the EDL.
48 void set_asset(Asset *asset);
50 // Enable or disable frame caching. Must be tied to file to know when
51 // to delete the file object. Otherwise we'd delete just the cached frames
52 // while the list of open files grew.
53 void set_cache_frames(int value);
54 // Delete oldest frame from cache. Return 0 if successful. Return 1 if
55 // nothing to delete.
56 int purge_cache();
58 // Format may be preset if the asset format is not 0.
59 int open_file(ArrayList<PluginServer*> *plugindb,
60 Asset *asset,
61 int rd,
62 int wr,
63 int64_t base_samplerate,
64 float base_framerate);
66 // start a thread for writing to avoid blocking during record
67 int start_audio_thread(int64_t buffer_size, int ring_buffers);
68 int stop_audio_thread();
69 // The ring buffer must either be 1 or 2.
70 // The buffer_size for video needs to be > 1 on SMP systems to utilize
71 // multiple processors.
72 // For audio it's the number of samples per buffer.
73 // compressed - if 1 write_compressed_frame is called
74 // if 0 write_frames is called
75 int start_video_thread(int64_t buffer_size,
76 int color_model,
77 int ring_buffers,
78 int compressed);
79 int stop_video_thread();
80 int lock_read();
81 int unlock_read();
83 // write any headers and close file
84 // ignore_thread is used by SigHandler to break out of the threads.
85 int close_file(int ignore_thread = 0);
87 // set channel for buffer accesses
88 int set_channel(int channel);
90 // set layer for video read
91 int set_layer(int layer);
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);
102 // set position in samples
103 int set_audio_position(int64_t position, float base_samplerate);
104 // set position in frames
105 int set_video_position(int64_t position, float base_framerate);
107 // write samples for the current channel
108 // written to disk and file pointer updated after last channel is written
109 // return 1 if failed
110 // subsequent writes must be <= than first write's size because of buffers
111 int write_samples(double **buffer, int64_t len);
113 // Only called by filethread
114 int write_frames(VFrame ***frames, int len);
116 // For writing buffers in a background thread use these functions to get the buffer.
117 // Get a pointer to a buffer to write to.
118 double** get_audio_buffer();
119 VFrame*** get_video_buffer();
121 // Used by ResourcePixmap to directly access the cache.
122 FrameCache* get_frame_cache();
124 // Schedule a buffer for writing on the thread.
125 // thread calls write_samples
126 int write_audio_buffer(int64_t len);
127 int write_video_buffer(int64_t len);
129 // Read samples for one channel into a shared memory segment.
130 // The offset is the offset in floats from the beginning of the buffer and the len
131 // is the length in floats from the offset.
132 // advances file pointer
133 // return 1 if failed
134 int read_samples(double *buffer, int64_t len, int64_t base_samplerate, float *buffer_float = 0);
137 // Read frame of video into the argument
138 int File::read_frame(VFrame *frame);
141 // The following involve no extra copies.
142 // Direct copy routines for direct copy playback
143 int can_copy_from(Edit *edit, int64_t position, int output_w, int output_h); // This file can copy frames directly from the asset
144 int get_render_strategy(ArrayList<int>* render_strategies);
145 int64_t compressed_frame_size();
146 int read_compressed_frame(VFrame *buffer);
147 int write_compressed_frame(VFrame *buffer);
149 // These are separated into two routines so a file doesn't have to be
150 // allocated.
151 // Get best colormodel to translate for hardware acceleration
152 int get_best_colormodel(int driver);
153 static int get_best_colormodel(Asset *asset, int driver);
154 // Get nearest colormodel in format after the file is opened and the
155 // direction determined to know whether to use a temp.
156 int colormodel_supported(int colormodel);
158 // Used by CICache to calculate the total size of the cache.
159 // Based on temporary frames and a call to the file subclass.
160 // The return value is limited 1MB each in case of audio file.
161 // The minimum setting for cache_size should be bigger than 1MB.
162 int get_memory_usage();
164 static int supports_video(ArrayList<PluginServer*> *plugindb, char *format); // returns 1 if the format supports video or audio
165 static int supports_audio(ArrayList<PluginServer*> *plugindb, char *format);
166 static int supports_video(int format); // returns 1 if the format supports video or audio
167 static int supports_audio(int format);
168 static int strtoformat(char *format);
169 static char* formattostr(int format);
170 static int strtoformat(ArrayList<PluginServer*> *plugindb, char *format);
171 static char* formattostr(ArrayList<PluginServer*> *plugindb, int format);
172 static int strtobits(char *bits);
173 static char* bitstostr(int bits);
174 static int str_to_byteorder(char *string);
175 static char* byteorder_to_str(int byte_order);
176 int bytes_per_sample(int bits); // Convert the bit descriptor into a byte count.
178 Asset *asset; // Copy of asset since File outlives EDL
179 FileBase *file; // virtual class for file type
180 // Threads for writing data in the background.
181 FileThread *audio_thread, *video_thread;
183 // Temporary storage for color conversions
184 VFrame *temp_frame;
186 // Resampling engine
187 Resample *resample;
188 Resample_float *resample_float;
190 // Lock writes while recording video and audio.
191 // A binary lock won't do. We need a FIFO lock.
192 Condition *write_lock;
193 int cpus;
194 int64_t playback_preload;
196 // Position information is migrated here to allow samplerate conversion.
197 // Current position in file's samplerate.
198 // Can't normalize to base samplerate because this would
199 // require fractional positioning to know if the file's position changed.
200 int64_t current_sample;
201 int64_t current_frame;
202 int current_channel;
203 int current_layer;
205 // Position information normalized
206 int64_t normalized_sample;
207 int64_t normalized_sample_rate;
210 private:
211 void reset_parameters();
213 int getting_options;
214 BC_WindowBase *format_window;
215 Mutex *format_completion;
216 FrameCache *frame_cache;
217 // Copy read frames to the cache
218 int use_cache;
221 #endif