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"
23 // ======================================= include file types here
27 // generic file opened by user
34 // Get attributes for various file formats.
35 // The dither parameter is carried over from recording, where dither is done at the device.
36 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 int set_preload(int64_t size
); // Set the number of bytes to preload during reads.
48 // When loading, the asset is deleted and a copy created in the EDL.
49 void set_asset(Asset
*asset
);
51 // Enable or disable frame caching. Must be tied to file to know when
52 // to delete the file object. Otherwise we'd delete just the cached frames
53 // while the list of open files grew.
54 void set_cache_frames(int value
);
55 // Delete oldest frame from cache. Return 0 if successful. Return 1 if
59 // Format may be preset if the asset format is not 0.
60 int open_file(Preferences
*preferences
,
64 int64_t base_samplerate
,
65 float base_framerate
);
67 // Get index from the file if one exists. Returns 0 on success.
68 int get_index(char *index_path
);
70 // start a thread for writing to avoid blocking during record
71 int start_audio_thread(int64_t buffer_size
, int ring_buffers
);
72 int stop_audio_thread();
73 // The ring buffer must either be 1 or 2.
74 // The buffer_size for video needs to be > 1 on SMP systems to utilize
75 // multiple processors.
76 // For audio it's the number of samples per buffer.
77 // compressed - if 1 write_compressed_frame is called
78 // if 0 write_frames is called
79 int start_video_thread(int64_t buffer_size
,
83 int stop_video_thread();
87 // write any headers and close file
88 // ignore_thread is used by SigHandler to break out of the threads.
89 int close_file(int ignore_thread
= 0);
91 // set channel for buffer accesses
92 int set_channel(int channel
);
94 // set layer for video read
95 int set_layer(int layer
);
97 // get length of file normalized to base samplerate
98 int64_t get_audio_length(int64_t base_samplerate
= -1);
99 int64_t get_video_length(float base_framerate
= -1);
101 // get current position
102 int64_t get_audio_position(int64_t base_samplerate
= -1);
103 int64_t get_video_position(float base_framerate
= -1);
106 // set position in samples
107 int set_audio_position(int64_t position
, float base_samplerate
);
108 // set position in frames
109 int set_video_position(int64_t position
, float base_framerate
);
111 // write samples for the current channel
112 // written to disk and file pointer updated after last channel is written
113 // return 1 if failed
114 // subsequent writes must be <= than first write's size because of buffers
115 int write_samples(double **buffer
, int64_t len
);
117 // Only called by filethread
118 int write_frames(VFrame
***frames
, int len
);
120 // For writing buffers in a background thread use these functions to get the buffer.
121 // Get a pointer to a buffer to write to.
122 double** get_audio_buffer();
123 VFrame
*** get_video_buffer();
125 // Used by ResourcePixmap to directly access the cache.
126 FrameCache
* get_frame_cache();
128 // Schedule a buffer for writing on the thread.
129 // thread calls write_samples
130 int write_audio_buffer(int64_t len
);
131 int write_video_buffer(int64_t len
);
133 // Read samples for one channel into a shared memory segment.
134 // The offset is the offset in floats from the beginning of the buffer and the len
135 // is the length in floats from the offset.
136 // advances file pointer
137 // return 1 if failed
138 int read_samples(double *buffer
, int64_t len
, int64_t base_samplerate
, float *buffer_float
= 0);
141 // Read frame of video into the argument
142 int read_frame(VFrame
*frame
);
145 // The following involve no extra copies.
146 // Direct copy routines for direct copy playback
147 int can_copy_from(Edit
*edit
, int64_t position
, int output_w
, int output_h
); // This file can copy frames directly from the asset
148 int get_render_strategy(ArrayList
<int>* render_strategies
);
149 int64_t compressed_frame_size();
150 int read_compressed_frame(VFrame
*buffer
);
151 int write_compressed_frame(VFrame
*buffer
);
153 // These are separated into two routines so a file doesn't have to be
155 // Get best colormodel to translate for hardware acceleration
156 int get_best_colormodel(int driver
);
157 static int get_best_colormodel(Asset
*asset
, int driver
);
158 // Get nearest colormodel in format after the file is opened and the
159 // direction determined to know whether to use a temp.
160 int colormodel_supported(int colormodel
);
162 // Used by CICache to calculate the total size of the cache.
163 // Based on temporary frames and a call to the file subclass.
164 // The return value is limited 1MB each in case of audio file.
165 // The minimum setting for cache_size should be bigger than 1MB.
166 int get_memory_usage();
168 static int supports_video(ArrayList
<PluginServer
*> *plugindb
, char *format
); // returns 1 if the format supports video or audio
169 static int supports_audio(ArrayList
<PluginServer
*> *plugindb
, char *format
);
170 static int supports_video(int format
); // returns 1 if the format supports video or audio
171 static int supports_audio(int format
);
172 static int strtoformat(char *format
);
173 static char* formattostr(int format
);
174 static int strtoformat(ArrayList
<PluginServer
*> *plugindb
, char *format
);
175 static char* formattostr(ArrayList
<PluginServer
*> *plugindb
, int format
);
176 static int strtobits(char *bits
);
177 static char* bitstostr(int bits
);
178 static int str_to_byteorder(char *string
);
179 static char* byteorder_to_str(int byte_order
);
180 int bytes_per_sample(int bits
); // Convert the bit descriptor into a byte count.
182 Asset
*asset
; // Copy of asset since File outlives EDL
183 FileBase
*file
; // virtual class for file type
184 // Threads for writing data in the background.
185 FileThread
*audio_thread
, *video_thread
;
187 // Temporary storage for color conversions
192 Resample_float
*resample_float
;
194 // Lock writes while recording video and audio.
195 // A binary lock won't do. We need a FIFO lock.
196 Condition
*write_lock
;
198 int64_t playback_preload
;
200 // Position information is migrated here to allow samplerate conversion.
201 // Current position in file's samplerate.
202 // Can't normalize to base samplerate because this would
203 // require fractional positioning to know if the file's position changed.
204 int64_t current_sample
;
205 int64_t current_frame
;
209 // Position information normalized
210 int64_t normalized_sample
;
211 int64_t normalized_sample_rate
;
212 Preferences
*preferences
;
216 void reset_parameters();
219 BC_WindowBase
*format_window
;
220 Mutex
*format_completion
;
221 FrameCache
*frame_cache
;
222 // Copy read frames to the cache