3 * Copyright (C) 2010 Adam Williams <broadcast at earthling dot net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 // work arounds (centos)
32 #define INT64_MAX 9223372036854775807LL
37 #include "bcsignals.h"
38 #include "byteorder.h"
40 #include "condition.h"
48 #include "fileffmpeg.h"
54 #undef HAVE_STDLIB_H // automake conflict
57 #include "filescene.h"
58 #include "filesndfile.h"
60 #include "filethread.h"
62 #include "filevorbis.h"
64 #include "formatwindow.h"
65 #include "formattools.h"
66 #include "framecache.h"
68 #include "mainprogress.inc"
71 #include "packagingengine.h"
72 #include "pluginserver.h"
73 #include "preferences.h"
77 //suppress noref warning
78 void *vorbis0_ov_callbacks[] = {
79 &OV_CALLBACKS_DEFAULT, &OV_CALLBACKS_NOCLOSE,
80 &OV_CALLBACKS_STREAMONLY, &OV_CALLBACKS_STREAMONLY_NOCLOSE,
87 format_completion = new Condition(1, "File::format_completion");
88 write_lock = new Condition(1, "File::write_lock");
89 frame_cache = new FrameCache;
97 if(format_window) format_window->set_done(0);
98 format_completion->lock("File::~File");
99 format_completion->unlock();
102 if(temp_frame) delete temp_frame;
107 asset->Garbage::remove_user();
108 delete format_completion;
113 void File::reset_parameters()
126 normalized_sample = 0;
129 playback_subtitle = -1;
133 temp_samples_buffer = 0;
134 temp_frame_buffer = 0;
135 current_frame_buffer = 0;
136 audio_ring_buffers = 0;
137 video_ring_buffers = 0;
138 video_buffer_size = 0;
141 int File::raise_window()
143 if(getting_options && format_window)
145 format_window->raise_window();
146 format_window->flush();
151 void File::close_window()
155 format_window->lock_window("File::close_window");
156 format_window->set_done(1);
157 format_window->unlock_window();
162 int File::get_options(FormatTools *format,
163 int audio_options, int video_options)
165 BC_WindowBase *parent_window = format->window;
166 //ArrayList<PluginServer*> *plugindb = format->plugindb;
167 Asset *asset = format->asset;
170 format_completion->lock("File::get_options");
171 switch(asset->format)
174 FileAC3::get_parameters(parent_window,
181 FileDV::get_parameters(parent_window,
192 FileSndFile::get_parameters(parent_window,
199 FileFFMPEG::get_parameters(parent_window,
207 FileMPEG::get_parameters(parent_window,
215 FileJPEG::get_parameters(parent_window,
223 FileEXR::get_parameters(parent_window,
230 FileFLAC::get_parameters(parent_window,
238 FilePNG::get_parameters(parent_window,
246 FileTGA::get_parameters(parent_window,
254 FileTIFF::get_parameters(parent_window,
261 FileOGG::get_parameters(parent_window,
273 ErrorBox *errorbox = new ErrorBox(_(PROGRAM_NAME ": Error"),
274 parent_window->get_abs_cursor_x(1),
275 parent_window->get_abs_cursor_y(1));
276 format_window = errorbox;
279 errorbox->create_objects(_("This format doesn't support audio."));
282 errorbox->create_objects(_("This format doesn't support video."));
283 errorbox->run_window();
289 format_completion->unlock();
302 int File::set_processors(int cpus) // Set the number of cpus for certain codecs
304 if( cpus > 8 ) // mpegvideo max_threads = 16, more causes errs
305 cpus = 8; // 8 cpus ought to decode just about anything
306 // Set all instances so gets work.
312 int File::set_preload(int64_t size)
314 this->playback_preload = size;
318 void File::set_subtitle(int value)
320 this->playback_subtitle = value;
321 if( file ) file->set_subtitle(value);
324 void File::set_interpolate_raw(int value)
326 this->interpolate_raw = value;
329 void File::set_white_balance_raw(int value)
331 this->white_balance_raw = value;
335 void File::set_cache_frames(int value)
337 // caching only done locally
342 int File::purge_cache()
344 // caching only done locally
346 if( frame_cache->cache_items() > 0 )
348 frame_cache->remove_all();
354 int File::delete_oldest()
356 // caching only done locally
357 return frame_cache->delete_oldest();
370 int File::open_file(Preferences *preferences,
377 this->preferences = preferences;
378 this->asset->copy_from(asset, 1);
383 if(debug) printf("File::open_file %d\n", __LINE__);
385 if(debug) printf("File::open_file %p %d\n", this, __LINE__);
387 switch(this->asset->format)
389 // get the format now
390 // If you add another format to case 0, you also need to add another case for the
391 // file format #define.
393 if(FileDB::check_sig(this->asset)) {
395 file = new FileDB(this->asset, this);
398 // if early probe enabled
399 if( preferences->ffmpeg_early_probe &&
400 FileFFMPEG::check_sig(this->asset)) {
401 file = new FileFFMPEG(this->asset, this);
406 if(!(stream = fopen(this->asset->path, "rb"))) {
411 char test[16]; memset(test,0,sizeof(test)); // int result =
412 fread(test, 16, 1, stream);
414 if(FileScene::check_sig(this->asset, test)) {
417 file = new FileScene(this->asset, this);
420 if(FileDV::check_sig(this->asset)) {
423 file = new FileDV(this->asset, this);
426 if(FileSndFile::check_sig(this->asset)) {
429 file = new FileSndFile(this->asset, this);
432 if(FilePNG::check_sig(this->asset)) {
435 file = new FilePNG(this->asset, this);
438 if(FileJPEG::check_sig(this->asset)) {
441 file = new FileJPEG(this->asset, this);
444 if(FileGIF::check_sig(this->asset)) {
447 file = new FileGIF(this->asset, this);
450 if(FileEXR::check_sig(this->asset, test)) {
453 file = new FileEXR(this->asset, this);
456 if(FileFLAC::check_sig(this->asset, test)) {
459 file = new FileFLAC(this->asset, this);
462 if(FileCR2::check_sig(this->asset)) {
465 file = new FileCR2(this->asset, this);
468 if(FileTGA::check_sig(this->asset)) {
471 file = new FileTGA(this->asset, this);
474 if(FileTIFF::check_sig(this->asset)) {
477 file = new FileTIFF(this->asset, this);
480 if(FileOGG::check_sig(this->asset)) {
483 file = new FileOGG(this->asset, this);
486 if(FileVorbis::check_sig(this->asset)) {
489 file = new FileVorbis(this->asset, this);
492 if(FileMPEG::check_sig(this->asset)) {
495 file = new FileMPEG(this->asset, this);
498 if( test[0] == '<' && (
499 !strncmp(&test[1],"EDL>",4) ||
500 !strncmp(&test[1],"HTAL>",5) ||
501 !strncmp(&test[1],"?xml",4) ) ) {
505 } // can't load project file
506 if( !preferences->ffmpeg_early_probe &&
507 FileFFMPEG::check_sig(this->asset) ) {
509 file = new FileFFMPEG(this->asset, this);
514 return FILE_UNRECOGNIZED_CODEC;
517 // format already determined
519 file = new FileAC3(this->asset, this);
523 file = new FileScene(this->asset, this);
527 file = new FileFFMPEG(this->asset, this);
535 //printf("File::open_file 1\n");
536 file = new FileSndFile(this->asset, this);
541 file = new FilePNG(this->asset, this);
546 file = new FileJPEG(this->asset, this);
551 file = new FileGIF(this->asset, this);
556 file = new FileEXR(this->asset, this);
560 file = new FileFLAC(this->asset, this);
565 file = new FileCR2(this->asset, this);
570 file = new FileTGA(this->asset, this);
575 file = new FileTIFF(this->asset, this);
579 file = new FileDB(this->asset, this);
585 file = new FileMPEG(this->asset, this);
589 file = new FileOGG(this->asset, this);
593 file = new FileVorbis(this->asset, this);
597 file = new FileDV(this->asset, this);
607 // Reopen file with correct parser and get header.
608 if(file->open_file(rd, wr)) {
609 delete file; file = 0;
610 return FILE_NOT_FOUND;
615 // Set extra writing parameters to mandatory settings.
617 if(this->asset->dither) file->set_dither();
621 // one frame image file, no specific length
622 if( !this->asset->audio_data && this->asset->video_data &&
623 this->asset->video_length <= 1 )
624 this->asset->video_length = -1;
627 // Synchronize header parameters
628 asset->copy_from(this->asset, 1);
631 if(debug) printf("File::open_file %d file=%p\n", __LINE__, file);
637 void File::delete_temp_samples_buffer()
640 if(temp_samples_buffer) {
641 for(int j = 0; j < audio_ring_buffers; j++) {
642 for(int i = 0; i < asset->channels; i++) {
643 delete temp_samples_buffer[j][i];
645 delete [] temp_samples_buffer[j];
648 delete [] temp_samples_buffer;
649 temp_samples_buffer = 0;
650 audio_ring_buffers = 0;
654 void File::delete_temp_frame_buffer()
657 if(temp_frame_buffer) {
658 for(int k = 0; k < video_ring_buffers; k++) {
659 for(int i = 0; i < asset->layers; i++) {
660 for(int j = 0; j < video_buffer_size; j++) {
661 delete temp_frame_buffer[k][i][j];
663 delete [] temp_frame_buffer[k][i];
665 delete [] temp_frame_buffer[k];
668 delete [] temp_frame_buffer;
669 temp_frame_buffer = 0;
670 video_ring_buffers = 0;
671 video_buffer_size = 0;
675 int File::close_file(int ignore_thread)
679 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
687 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
689 // The file's asset is a copy of the argument passed to open_file so the
690 // user must copy lengths from the file's asset.
692 asset->audio_length = current_sample;
693 asset->video_length = current_frame;
699 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
701 delete_temp_samples_buffer();
702 delete_temp_frame_buffer();
703 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
705 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
708 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
714 int File::get_index(IndexFile *index_file, MainProgressBar *progress_bar)
716 return !file ? -1 : file->get_index(index_file, progress_bar);
721 int File::start_audio_thread(int buffer_size, int ring_buffers)
723 this->audio_ring_buffers = ring_buffers;
728 audio_thread = new FileThread(this, 1, 0);
729 audio_thread->start_writing(buffer_size, 0, ring_buffers, 0);
734 int File::start_video_thread(int buffer_size,
739 this->video_ring_buffers = ring_buffers;
740 this->video_buffer_size = buffer_size;
744 video_thread = new FileThread(this, 0, 1);
745 video_thread->start_writing(buffer_size,
753 int File::start_video_decode_thread()
755 // Currently, CR2 is the only one which won't work asynchronously, so
756 // we're not using a virtual function yet.
757 if(!video_thread /* && asset->format != FILE_CR2 */)
759 video_thread = new FileThread(this, 0, 1);
760 video_thread->start_reading();
766 int File::stop_audio_thread()
770 audio_thread->stop_writing();
777 int File::stop_video_thread()
781 video_thread->stop_reading();
782 video_thread->stop_writing();
789 FileThread* File::get_video_thread()
794 int File::set_channel(int channel)
796 if(file && channel < asset->channels)
798 current_channel = channel;
805 int File::get_channel()
807 return current_channel;
810 // if no>=0, sets new program
811 // returns current program
812 int File::set_program(int no)
814 int result = file ? file->set_program(no) : current_program;
815 current_program = no < 0 ? result : no;
819 int File::get_cell_time(int no, double &time)
821 return file ? file->get_cell_time(no, time) : -1;
824 int File::get_system_time(int64_t &tm)
826 return file ? file->get_system_time(tm) : -1;
829 int File::get_audio_for_video(int vstream, int astream, int64_t &channel_mask)
831 return file ? file->get_audio_for_video(vstream, astream, channel_mask) : -1;
834 int File::get_video_pid(int track)
836 return file ? file->get_video_pid(track) : -1;
841 int File::get_video_info(int track, int &pid, double &framerate,
842 int &width, int &height, char *title)
845 file->get_video_info(track, pid, framerate, width, height, title);
848 int File::select_video_stream(Asset *asset, int vstream)
851 file->select_video_stream(asset, vstream);
854 int File::select_audio_stream(Asset *asset, int astream)
857 file->select_audio_stream(asset, astream);
861 int File::get_thumbnail(int stream,
862 int64_t &position, unsigned char *&thumbnail, int &ww, int &hh)
864 return file->get_thumbnail(stream, position, thumbnail, ww, hh);
867 int File::set_skimming(int track, int skim, skim_fn fn, void *vp)
869 return file->set_skimming(track, skim, fn, vp);
872 int File::skim_video(int track, void *vp, skim_fn fn)
874 return file->skim_video(track, vp, fn);
878 int File::set_layer(int layer, int is_thread)
880 if(file && layer < asset->layers)
882 if(!is_thread && video_thread)
884 video_thread->set_layer(layer);
888 current_layer = layer;
896 int64_t File::get_audio_length()
898 int64_t result = asset->audio_length;
899 int64_t base_samplerate = -1;
902 if(base_samplerate > 0)
903 return (int64_t)((double)result / asset->sample_rate * base_samplerate + 0.5);
911 int64_t File::get_video_length()
913 int64_t result = asset->video_length;
914 float base_framerate = -1;
917 if(base_framerate > 0)
918 return (int64_t)((double)result / asset->frame_rate * base_framerate + 0.5);
923 return -1; // infinity
927 int64_t File::get_video_position()
929 float base_framerate = -1;
930 if(base_framerate > 0)
931 return (int64_t)((double)current_frame / asset->frame_rate * base_framerate + 0.5);
933 return current_frame;
936 int64_t File::get_audio_position()
938 // int64_t base_samplerate = -1;
939 // if(base_samplerate > 0)
941 // if(normalized_sample_rate == base_samplerate)
942 // return normalized_sample;
944 // return (int64_t)((double)current_sample /
945 // asset->sample_rate *
950 return current_sample;
955 int File::set_audio_position(int64_t position)
961 #define REPOSITION(x, y) \
962 (labs((x) - (y)) > 1)
964 float base_samplerate = asset->sample_rate;
965 current_sample = normalized_sample = position;
967 // printf("File::set_audio_position %d normalized_sample=%ld\n",
969 // normalized_sample);
970 result = file->set_audio_position(current_sample);
973 printf("File::set_audio_position position=%jd"
974 " base_samplerate=%f asset=%p asset->sample_rate=%d\n",
975 position, base_samplerate, asset, asset->sample_rate);
977 //printf("File::set_audio_position %d %d %d\n", current_channel, current_sample, position);
982 int File::set_video_position(int64_t position,
988 // Convert to file's rate
989 // if(base_framerate > 0)
990 // position = (int64_t)((double)position /
992 // asset->frame_rate +
996 if(video_thread && !is_thread)
998 // Call thread. Thread calls this again to set the file state.
999 video_thread->set_video_position(position);
1002 if(current_frame != position)
1006 current_frame = position;
1007 result = file->set_video_position(current_frame);
1014 // No resampling here.
1015 int File::write_samples(Samples **buffer, int64_t len)
1021 write_lock->lock("File::write_samples");
1023 // Convert to arrays for backwards compatability
1024 double *temp[asset->channels];
1025 for(int i = 0; i < asset->channels; i++)
1027 temp[i] = buffer[i]->get_data();
1030 result = file->write_samples(temp, len);
1031 current_sample += len;
1032 normalized_sample += len;
1033 asset->audio_length += len;
1034 write_lock->unlock();
1043 // Can't put any cmodel abstraction here because the filebase couldn't be
1045 int File::write_frames(VFrame ***frames, int len)
1047 //printf("File::write_frames %d\n", __LINE__);
1049 // Store the counters in temps so the filebase can choose to overwrite them.
1051 int current_frame_temp = current_frame;
1052 int video_length_temp = asset->video_length;
1054 write_lock->lock("File::write_frames");
1057 result = file->write_frames(frames, len);
1060 current_frame = current_frame_temp + len;
1061 asset->video_length = video_length_temp + len;
1062 write_lock->unlock();
1067 // Only called by FileThread
1068 int File::write_compressed_frame(VFrame *buffer)
1071 write_lock->lock("File::write_compressed_frame");
1072 result = file->write_compressed_frame(buffer);
1074 asset->video_length++;
1075 write_lock->unlock();
1080 int File::write_audio_buffer(int64_t len)
1085 result = audio_thread->write_buffer(len);
1090 int File::write_video_buffer(int64_t len)
1095 result = video_thread->write_buffer(len);
1101 Samples** File::get_audio_buffer()
1103 if(audio_thread) return audio_thread->get_audio_buffer();
1107 VFrame*** File::get_video_buffer()
1111 VFrame*** result = video_thread->get_video_buffer();
1120 int File::read_samples(Samples *samples, int64_t len)
1122 // Never try to read more samples than exist in the file
1123 if (current_sample + len > asset->audio_length) {
1124 len = asset->audio_length - current_sample;
1126 if(len <= 0) return 0;
1129 const int debug = 0;
1130 if(debug) PRINT_TRACE
1132 if(debug) PRINT_TRACE
1134 double *buffer = samples->get_data();
1136 int64_t base_samplerate = asset->sample_rate;
1140 // Resample recursively calls this with the asset sample rate
1141 if(base_samplerate == 0) base_samplerate = asset->sample_rate;
1143 if(debug) PRINT_TRACE
1144 result = file->read_samples(buffer, len);
1146 if(debug) PRINT_TRACE
1147 current_sample += len;
1149 normalized_sample += len;
1151 if(debug) PRINT_TRACE
1156 int File::read_frame(VFrame *frame, int is_thread)
1158 const int debug = 0;
1160 if(debug) PRINT_TRACE
1162 //printf("File::read_frame %d\n", __LINE__);
1164 if(video_thread && !is_thread) return video_thread->read_frame(frame);
1166 //printf("File::read_frame %d\n", __LINE__);
1167 if(debug) PRINT_TRACE
1168 if( !file ) return 1;
1169 if(debug) PRINT_TRACE
1170 int supported_colormodel = colormodel_supported(frame->get_color_model());
1171 int advance_position = 1;
1172 int cache_active = use_cache || asset->video_length < 0 ? 1 : 0;
1173 int64_t cache_position = asset->video_length >= 0 ? current_frame : -1;
1175 if( cache_active && frame_cache->get_frame(frame, cache_position,
1176 current_layer, asset->frame_rate) )
1178 // Can't advance position if cache used.
1179 //printf("File::read_frame %d\n", __LINE__);
1180 advance_position = 0;
1183 else if(frame->get_color_model() != BC_COMPRESSED &&
1184 (supported_colormodel != frame->get_color_model() ||
1185 frame->get_w() != asset->width ||
1186 frame->get_h() != asset->height))
1189 // printf("File::read_frame %d\n", __LINE__);
1190 // Can't advance position here because it needs to be added to cache
1193 if(!temp_frame->params_match(asset->width, asset->height, supported_colormodel))
1200 // printf("File::read_frame %d\n", __LINE__);
1203 temp_frame = new VFrame(0,
1207 supported_colormodel,
1211 // printf("File::read_frame %d\n", __LINE__);
1212 temp_frame->copy_stacks(frame);
1213 int result = file->read_frame(temp_frame);
1214 if( result && frame->get_status() > 0 )
1215 frame->set_status(-1);
1216 //for(int i = 0; i < 1000 * 1000; i++) ((float*)temp_frame->get_rows()[0])[i] = 1.0;
1217 // printf("File::read_frame %d %d %d %d %d %d\n",
1218 // temp_frame->get_color_model(),
1219 // temp_frame->get_w(),
1220 // temp_frame->get_h(),
1221 // frame->get_color_model(),
1224 BC_CModels::transfer(frame->get_rows(), temp_frame->get_rows(),
1225 frame->get_y(), frame->get_u(), frame->get_v(),
1226 temp_frame->get_y(), temp_frame->get_u(), temp_frame->get_v(),
1227 0, 0, temp_frame->get_w(), temp_frame->get_h(),
1228 0, 0, frame->get_w(), frame->get_h(),
1229 temp_frame->get_color_model(),
1230 frame->get_color_model(), 0, temp_frame->get_w(),
1232 // printf("File::read_frame %d\n", __LINE__);
1236 // Can't advance position here because it needs to be added to cache
1237 //printf("File::read_frame %d\n", __LINE__);
1238 int result = file->read_frame(frame);
1239 if( result && frame->get_status() > 0 )
1240 frame->set_status(-1);
1241 //for(int i = 0; i < 100 * 1000; i++) ((float*)frame->get_rows()[0])[i] = 1.0;
1244 if( cache_active && advance_position && frame->get_status() > 0 )
1245 frame_cache->put_frame(frame, cache_position,
1246 current_layer, asset->frame_rate, 1, 0);
1247 //printf("File::read_frame %d\n", __LINE__);
1249 if(advance_position) current_frame++;
1250 if(debug) PRINT_TRACE
1254 int File::can_copy_from(Asset *asset,
1259 if(!asset) return 0;
1263 return asset->width == output_w &&
1264 asset->height == output_h &&
1265 file->can_copy_from(asset, position);
1271 // Fill in queries about formats when adding formats here.
1274 int File::strtoformat(const char *format)
1276 return strtoformat(0, format);
1279 int File::strtoformat(ArrayList<PluginServer*> *plugindb, const char *format)
1281 if(!strcasecmp(format, _(AC3_NAME))) return FILE_AC3;
1282 if(!strcasecmp(format, _(SCENE_NAME))) return FILE_SCENE;
1283 if(!strcasecmp(format, _(WAV_NAME))) return FILE_WAV;
1284 if(!strcasecmp(format, _(PCM_NAME))) return FILE_PCM;
1285 if(!strcasecmp(format, _(AU_NAME))) return FILE_AU;
1286 if(!strcasecmp(format, _(AIFF_NAME))) return FILE_AIFF;
1287 if(!strcasecmp(format, _(SND_NAME))) return FILE_SND;
1288 if(!strcasecmp(format, _(PNG_NAME))) return FILE_PNG;
1289 if(!strcasecmp(format, _(PNG_LIST_NAME))) return FILE_PNG_LIST;
1290 if(!strcasecmp(format, _(TIFF_NAME))) return FILE_TIFF;
1291 if(!strcasecmp(format, _(TIFF_LIST_NAME))) return FILE_TIFF_LIST;
1292 if(!strcasecmp(format, _(JPEG_NAME))) return FILE_JPEG;
1293 if(!strcasecmp(format, _(JPEG_LIST_NAME))) return FILE_JPEG_LIST;
1294 if(!strcasecmp(format, _(EXR_NAME))) return FILE_EXR;
1295 if(!strcasecmp(format, _(EXR_LIST_NAME))) return FILE_EXR_LIST;
1296 if(!strcasecmp(format, _(FLAC_NAME))) return FILE_FLAC;
1297 if(!strcasecmp(format, _(CR2_NAME))) return FILE_CR2;
1298 if(!strcasecmp(format, _(CR2_LIST_NAME))) return FILE_CR2_LIST;
1299 if(!strcasecmp(format, _(MPEG_NAME))) return FILE_MPEG;
1300 if(!strcasecmp(format, _(AMPEG_NAME))) return FILE_AMPEG;
1301 if(!strcasecmp(format, _(VMPEG_NAME))) return FILE_VMPEG;
1302 if(!strcasecmp(format, _(TGA_NAME))) return FILE_TGA;
1303 if(!strcasecmp(format, _(TGA_LIST_NAME))) return FILE_TGA_LIST;
1304 if(!strcasecmp(format, _(OGG_NAME))) return FILE_OGG;
1305 if(!strcasecmp(format, _(VORBIS_NAME))) return FILE_VORBIS;
1306 if(!strcasecmp(format, _(RAWDV_NAME))) return FILE_RAWDV;
1307 if(!strcasecmp(format, _(FFMPEG_NAME))) return FILE_FFMPEG;
1308 if(!strcasecmp(format, _(DBASE_NAME))) return FILE_DB;
1314 const char* File::formattostr(int format)
1316 return formattostr(0, format);
1319 const char* File::formattostr(ArrayList<PluginServer*> *plugindb, int format)
1323 case FILE_SCENE: return _(SCENE_NAME);
1324 case FILE_AC3: return _(AC3_NAME);
1325 case FILE_WAV: return _(WAV_NAME);
1326 case FILE_PCM: return _(PCM_NAME);
1327 case FILE_AU: return _(AU_NAME);
1328 case FILE_AIFF: return _(AIFF_NAME);
1329 case FILE_SND: return _(SND_NAME);
1330 case FILE_PNG: return _(PNG_NAME);
1331 case FILE_PNG_LIST: return _(PNG_LIST_NAME);
1332 case FILE_JPEG: return _(JPEG_NAME);
1333 case FILE_JPEG_LIST: return _(JPEG_LIST_NAME);
1334 case FILE_CR2: return _(CR2_NAME);
1335 case FILE_CR2_LIST: return _(CR2_LIST_NAME);
1336 case FILE_FLAC: return _(FLAC_NAME);
1337 case FILE_EXR: return _(EXR_NAME);
1338 case FILE_EXR_LIST: return _(EXR_LIST_NAME);
1339 case FILE_MPEG: return _(MPEG_NAME);
1340 case FILE_AMPEG: return _(AMPEG_NAME);
1341 case FILE_VMPEG: return _(VMPEG_NAME);
1342 case FILE_TGA: return _(TGA_NAME);
1343 case FILE_TGA_LIST: return _(TGA_LIST_NAME);
1344 case FILE_TIFF: return _(TIFF_NAME);
1345 case FILE_TIFF_LIST: return _(TIFF_LIST_NAME);
1346 case FILE_OGG: return _(OGG_NAME);
1347 case FILE_VORBIS: return _(VORBIS_NAME);
1348 case FILE_RAWDV: return _(RAWDV_NAME);
1349 case FILE_FFMPEG: return _(FFMPEG_NAME);
1350 case FILE_DB: return _(DBASE_NAME);
1352 return _("Unknown");
1355 int File::strtobits(const char *bits)
1357 if(!strcasecmp(bits, _(NAME_8BIT))) return BITSLINEAR8;
1358 if(!strcasecmp(bits, _(NAME_16BIT))) return BITSLINEAR16;
1359 if(!strcasecmp(bits, _(NAME_24BIT))) return BITSLINEAR24;
1360 if(!strcasecmp(bits, _(NAME_32BIT))) return BITSLINEAR32;
1361 if(!strcasecmp(bits, _(NAME_ULAW))) return BITSULAW;
1362 if(!strcasecmp(bits, _(NAME_ADPCM))) return BITS_ADPCM;
1363 if(!strcasecmp(bits, _(NAME_FLOAT))) return BITSFLOAT;
1364 return BITSLINEAR16;
1367 const char* File::bitstostr(int bits)
1369 //printf("File::bitstostr\n");
1372 case BITSLINEAR8: return (NAME_8BIT);
1373 case BITSLINEAR16: return (NAME_16BIT);
1374 case BITSLINEAR24: return (NAME_24BIT);
1375 case BITSLINEAR32: return (NAME_32BIT);
1376 case BITSULAW: return (NAME_ULAW);
1377 case BITS_ADPCM: return (NAME_ADPCM);
1378 case BITSFLOAT: return (NAME_FLOAT);
1380 return _("Unknown");
1385 int File::str_to_byteorder(const char *string)
1387 if(!strcasecmp(string, _("Lo Hi"))) return 1;
1391 const char* File::byteorder_to_str(int byte_order)
1393 if(byte_order) return _("Lo Hi");
1397 int File::bytes_per_sample(int bits)
1401 case BITSLINEAR8: return 1;
1402 case BITSLINEAR16: return 2;
1403 case BITSLINEAR24: return 3;
1404 case BITSLINEAR32: return 4;
1405 case BITSULAW: return 1;
1414 int File::get_best_colormodel(int driver)
1416 return get_best_colormodel(asset, driver);
1419 int File::get_best_colormodel(Asset *asset, int driver)
1421 switch(asset->format)
1423 case FILE_RAWDV: return FileDV::get_best_colormodel(asset, driver);
1424 case FILE_MPEG: return FileMPEG::get_best_colormodel(asset, driver);
1426 case FILE_JPEG_LIST: return FileJPEG::get_best_colormodel(asset, driver);
1428 case FILE_EXR_LIST: return FileEXR::get_best_colormodel(asset, driver);
1430 case FILE_PNG_LIST: return FilePNG::get_best_colormodel(asset, driver);
1432 case FILE_TGA_LIST: return FileTGA::get_best_colormodel(asset, driver);
1434 case FILE_CR2_LIST: return FileCR2::get_best_colormodel(asset, driver);
1435 case FILE_DB: return FileDB::get_best_colormodel(asset, driver);
1436 case FILE_FFMPEG: return FileFFMPEG::get_best_colormodel(asset, driver);
1443 int File::colormodel_supported(int colormodel)
1446 return file->colormodel_supported(colormodel);
1452 int64_t File::file_memory_usage()
1454 return file ? file->base_memory_usage() : 0;
1457 int64_t File::get_memory_usage()
1461 result += file_memory_usage();
1462 if(temp_frame) result += temp_frame->get_data_size();
1463 result += frame_cache->get_memory_usage();
1464 if(video_thread) result += video_thread->get_memory_usage();
1466 if(result < MIN_CACHEITEM_SIZE) result = MIN_CACHEITEM_SIZE;
1471 int File::supports_video(ArrayList<PluginServer*> *plugindb, char *format)
1473 int format_i = strtoformat(plugindb, format);
1475 return supports_video(format_i);
1479 int File::supports_audio(ArrayList<PluginServer*> *plugindb, char *format)
1481 int format_i = strtoformat(plugindb, format);
1483 return supports_audio(format_i);
1488 int File::supports_video(int format)
1490 //printf("File::supports_video %d\n", format);
1495 case FILE_JPEG_LIST:
1505 case FILE_TIFF_LIST:
1514 int File::supports_audio(int format)
1534 const char* File::get_tag(int format)
1538 case FILE_AC3: return "ac3";
1539 case FILE_AIFF: return "aif";
1540 case FILE_AMPEG: return "mp3";
1541 case FILE_AU: return "au";
1542 case FILE_RAWDV: return "dv";
1543 case FILE_DB: return "db";
1544 case FILE_EXR: return "exr";
1545 case FILE_EXR_LIST: return "exr";
1546 case FILE_FLAC: return "flac";
1547 case FILE_JPEG: return "jpg";
1548 case FILE_JPEG_LIST: return "jpg";
1549 case FILE_OGG: return "ogg";
1550 case FILE_PCM: return "pcm";
1551 case FILE_PNG: return "png";
1552 case FILE_PNG_LIST: return "png";
1553 case FILE_TGA: return "tga";
1554 case FILE_TGA_LIST: return "tga";
1555 case FILE_TIFF: return "tif";
1556 case FILE_TIFF_LIST: return "tif";
1557 case FILE_VMPEG: return "m2v";
1558 case FILE_VORBIS: return "ogg";
1559 case FILE_WAV: return "wav";
1560 case FILE_FFMPEG: return "ffmpg";
1565 const char* File::get_prefix(int format)
1568 case FILE_PCM: return "PCM";
1569 case FILE_WAV: return "WAV";
1570 case FILE_PNG: return "PNG";
1571 case FILE_JPEG: return "JPEG";
1572 case FILE_TIFF: return "TIFF";
1573 case FILE_GIF: return "GIF";
1574 case FILE_JPEG_LIST: return "JPEG_LIST";
1575 case FILE_AU: return "AU";
1576 case FILE_AIFF: return "AIFF";
1577 case FILE_SND: return "SND";
1578 case FILE_TGA_LIST: return "TGA_LIST";
1579 case FILE_TGA: return "TGA";
1580 case FILE_MPEG: return "MPEG";
1581 case FILE_AMPEG: return "AMPEG";
1582 case FILE_VMPEG: return "VMPEG";
1583 case FILE_RAWDV: return "RAWDV";
1584 case FILE_TIFF_LIST: return "TIFF_LIST";
1585 case FILE_PNG_LIST: return "PNG_LIST";
1586 case FILE_AC3: return "AC3";
1587 case FILE_EXR: return "EXR";
1588 case FILE_EXR_LIST: return "EXR_LIST";
1589 case FILE_CR2: return "CR2";
1590 case FILE_OGG: return "OGG";
1591 case FILE_VORBIS: return "VORBIS";
1592 case FILE_FLAC: return "FLAC";
1593 case FILE_FFMPEG: return "FFMPEG";
1594 case FILE_SCENE: return "SCENE";
1595 case FILE_CR2_LIST: return "CR2_LIST";
1596 case FILE_GIF_LIST: return "GIF_LIST";
1597 case FILE_DB: return "DB";
1599 return _("UNKNOWN");
1603 PackagingEngine *File::new_packaging_engine(Asset *asset)
1605 PackagingEngine *result;
1606 switch (asset->format)
1609 result = (PackagingEngine*)new PackagingEngineOGG();
1612 result = (PackagingEngine*) new PackagingEngineDefault();
1620 int File::record_fd()
1622 return file ? file->record_fd() : -1;
1626 void get_exe_path(char *result)
1628 // Get executable path
1629 int len = readlink("/proc/self/exe", result, BCTEXTLEN-1);
1632 char *ptr = strrchr(result, '/');