7 #include "condition.inc"
9 #include "filebase.inc"
11 #include "filethread.inc"
12 #include "filexml.inc"
13 #include "formatwindow.inc"
14 #include "formattools.h"
15 #include "framecache.inc"
18 #include "pluginserver.inc"
19 #include "preferences.inc"
20 #include "resample.inc"
22 #include "packagingengine.h"
24 // ======================================= include file types here
28 // generic file opened by user
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
,
42 // Close parameter window
45 // ===================================== start here
46 int set_processors(int cpus
); // Set the number of cpus for certain codecs.
47 // Set the number of bytes to preload during reads for Quicktime.
48 int set_preload(int64_t size
);
49 // Set the subtitle for libmpeg3. -1 disables subtitles.
50 void set_subtitle(int value
);
51 // Set whether to interpolate raw images
52 void set_interpolate_raw(int value
);
53 // Set whether to white balance raw images. Always 0 if no interpolation.
54 void set_white_balance_raw(int value
);
55 // When loading, the asset is deleted and a copy created in the EDL.
56 void set_asset(Asset_GC asset
);
58 // Enable or disable frame caching. Must be tied to file to know when
59 // to delete the file object. Otherwise we'd delete just the cached frames
60 // while the list of open files grew.
61 void set_cache_frames(int value
);
62 // Delete oldest frame from cache. Return 0 if successful. Return 1 if
66 // Format may be preset if the asset format is not 0.
67 int open_file(Preferences
*preferences
,
71 int64_t base_samplerate
,
72 float base_framerate
);
74 // Get index from the file if one exists. Returns 0 on success.
75 int get_index(char *index_path
);
77 // start a thread for writing to avoid blocking during record
78 int start_audio_thread(int64_t buffer_size
, int ring_buffers
);
79 int stop_audio_thread();
80 // The ring buffer must either be 1 or 2.
81 // The buffer_size for video needs to be > 1 on SMP systems to utilize
82 // multiple processors.
83 // For audio it's the number of samples per buffer.
84 // compressed - if 1 write_compressed_frame is called
85 // if 0 write_frames is called
86 int start_video_thread(int64_t buffer_size
,
90 int stop_video_thread();
92 int start_video_decode_thread();
95 // Used by functions that read only.
96 FileThread
* get_video_thread();
98 // write any headers and close file
99 // ignore_thread is used by SigHandler to break out of the threads.
100 int close_file(int ignore_thread
= 0);
102 // get length of file normalized to base samplerate
103 int64_t get_audio_length(int64_t base_samplerate
= -1);
104 int64_t get_video_length(float base_framerate
= -1);
106 // get current position
107 int64_t get_audio_position(int64_t base_samplerate
= -1);
108 int64_t get_video_position(float base_framerate
= -1);
112 // write samples for the current channel
113 // written to disk and file pointer updated after last channel is written
114 // return 1 if failed
115 // subsequent writes must be <= than first write's size because of buffers
116 int write_samples(double **buffer
, int64_t len
);
118 // Only called by filethread to write an array of an array of channels of frames.
119 int write_frames(VFrame
***frames
, int len
);
123 // For writing buffers in a background thread use these functions to get the buffer.
124 // Get a pointer to a buffer to write to.
125 double** get_audio_buffer();
126 VFrame
*** get_video_buffer();
128 // Used by ResourcePixmap to directly access the cache.
129 FrameCache
* get_frame_cache();
131 // Schedule a buffer for writing on the thread.
132 // thread calls write_samples
133 int write_audio_buffer(int64_t len
);
134 int write_video_buffer(int64_t len
);
139 // set channel for buffer accesses
140 int set_channel(int channel
);
141 // set position in samples
142 int set_audio_position(int64_t position
, float base_samplerate
);
144 // Read samples for one channel into a shared memory segment.
145 // The offset is the offset in floats from the beginning of the buffer and the len
146 // is the length in floats from the offset.
147 // advances file pointer
148 // return 1 if failed
149 int read_samples(double *buffer
, int64_t len
, int64_t base_samplerate
, float *buffer_float
= 0);
152 // set layer for video read
153 // is_thread is used by FileThread::run to prevent recursive lockup.
154 int set_layer(int layer
, int is_thread
= 0);
155 // set position in frames
156 // is_thread is used by FileThread::run to prevent recursive lockup.
157 int set_video_position(int64_t position
, float base_framerate
= -1, int is_thread
= 0);
159 // Read frame of video into the argument
160 // is_thread is used by FileThread::run to prevent recursive lockup.
161 int read_frame(VFrame
*frame
, int is_thread
= 0);
164 // The following involve no extra copies.
165 // Direct copy routines for direct copy playback
166 int can_copy_from(Edit
*edit
, int64_t position
, int output_w
, int output_h
); // This file can copy frames directly from the asset
167 int get_render_strategy(ArrayList
<int>* render_strategies
);
168 int64_t compressed_frame_size();
169 int read_compressed_frame(VFrame
*buffer
);
170 int write_compressed_frame(VFrame
*buffer
);
172 // These are separated into two routines so a file doesn't have to be
174 // Get best colormodel to translate for hardware accelerated playback.
175 // Called by VRender.
176 int get_best_colormodel(int driver
);
177 // Get best colormodel for hardware accelerated recording.
178 // Called by VideoDevice.
179 static int get_best_colormodel(Asset_GC asset
, int driver
);
180 // Get nearest colormodel that can be decoded without a temporary frame.
181 // Used by read_frame.
182 int colormodel_supported(int colormodel
);
184 // Used by CICache to calculate the total size of the cache.
185 // Based on temporary frames and a call to the file subclass.
186 // The return value is limited 1MB each in case of audio file.
187 // The minimum setting for cache_size should be bigger than 1MB.
188 int64_t get_memory_usage();
190 static int supports_video(ArrayList
<PluginServer
*> *plugindb
, char *format
); // returns 1 if the format supports video or audio
191 static int supports_audio(ArrayList
<PluginServer
*> *plugindb
, char *format
);
192 // Get the extension for the filename
193 static char* get_tag(int format
);
194 static int supports_video(int format
); // returns 1 if the format supports video or audio
195 static int supports_audio(int format
);
196 static int strtoformat(char *format
);
197 static char* formattostr(int format
);
198 static int strtoformat(ArrayList
<PluginServer
*> *plugindb
, char *format
);
199 static char* formattostr(ArrayList
<PluginServer
*> *plugindb
, int format
);
200 static int strtobits(char *bits
);
201 static char* bitstostr(int bits
);
202 static int str_to_byteorder(char *string
);
203 static char* byteorder_to_str(int byte_order
);
204 int bytes_per_sample(int bits
); // Convert the bit descriptor into a byte count.
206 Asset_GC asset
; // Copy of asset since File outlives EDL
207 FileBase
*file
; // virtual class for file type
208 // Threads for writing data in the background.
209 FileThread
*audio_thread
, *video_thread
;
211 // Temporary storage for color conversions
216 Resample_float
*resample_float
;
218 // Lock writes while recording video and audio.
219 // A binary lock won't do. We need a FIFO lock.
220 Condition
*write_lock
;
222 int64_t playback_preload
;
223 int playback_subtitle
;
225 int white_balance_raw
;
227 // Position information is migrated here to allow samplerate conversion.
228 // Current position in file's samplerate.
229 // Can't normalize to base samplerate because this would
230 // require fractional positioning to know if the file's position changed.
231 int64_t current_sample
;
232 int64_t current_frame
;
236 // Position information normalized
237 int64_t normalized_sample
;
238 int64_t normalized_sample_rate
;
239 Preferences
*preferences
;
241 static PackagingEngine
*new_packaging_engine(Asset_GC asset
);
244 void reset_parameters();
247 BC_WindowBase
*format_window
;
248 Mutex
*format_completion
;
249 FrameCache
*frame_cache
;
250 // Copy read frames to the cache
258 // c-file-style: "linux"