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,
182 FileDV::get_parameters(parent_window,
194 FileSndFile::get_parameters(parent_window,
201 FileFFMPEG::get_parameters(parent_window,
209 FileMPEG::get_parameters(parent_window,
217 FileJPEG::get_parameters(parent_window,
225 FileEXR::get_parameters(parent_window,
232 FileFLAC::get_parameters(parent_window,
240 FilePNG::get_parameters(parent_window,
248 FileTGA::get_parameters(parent_window,
256 FileTIFF::get_parameters(parent_window,
263 FileOGG::get_parameters(parent_window,
275 ErrorBox *errorbox = new ErrorBox(_(PROGRAM_NAME ": Error"),
276 parent_window->get_abs_cursor_x(1),
277 parent_window->get_abs_cursor_y(1));
278 format_window = errorbox;
281 errorbox->create_objects(_("This format doesn't support audio."));
284 errorbox->create_objects(_("This format doesn't support video."));
285 errorbox->run_window();
291 format_completion->unlock();
304 int File::set_processors(int cpus) // Set the number of cpus for certain codecs
306 if( cpus > 8 ) // mpegvideo max_threads = 16, more causes errs
307 cpus = 8; // 8 cpus ought to decode just about anything
308 // Set all instances so gets work.
314 int File::set_preload(int64_t size)
316 this->playback_preload = size;
320 void File::set_subtitle(int value)
322 this->playback_subtitle = value;
323 if( file ) file->set_subtitle(value);
326 void File::set_interpolate_raw(int value)
328 this->interpolate_raw = value;
331 void File::set_white_balance_raw(int value)
333 this->white_balance_raw = value;
337 void File::set_cache_frames(int value)
339 // caching only done locally
344 int File::purge_cache()
346 // caching only done locally
348 if( frame_cache->cache_items() > 0 )
350 frame_cache->remove_all();
356 int File::delete_oldest()
358 // caching only done locally
359 return frame_cache->delete_oldest();
372 int File::open_file(Preferences *preferences,
379 this->preferences = preferences;
380 this->asset->copy_from(asset, 1);
385 if(debug) printf("File::open_file %d\n", __LINE__);
387 if(debug) printf("File::open_file %p %d\n", this, __LINE__);
389 switch(this->asset->format)
391 // get the format now
392 // If you add another format to case 0, you also need to add another case for the
393 // file format #define.
395 if(FileDB::check_sig(this->asset)) {
397 file = new FileDB(this->asset, this);
400 // if early probe enabled
401 if( preferences->ffmpeg_early_probe &&
402 FileFFMPEG::check_sig(this->asset)) {
403 file = new FileFFMPEG(this->asset, this);
408 if(!(stream = fopen(this->asset->path, "rb"))) {
413 char test[16]; memset(test,0,sizeof(test)); // int result =
414 fread(test, 16, 1, stream);
416 if(FileScene::check_sig(this->asset, test)) {
419 file = new FileScene(this->asset, this);
423 if(FileDV::check_sig(this->asset)) {
426 file = new FileDV(this->asset, this);
430 if(FileSndFile::check_sig(this->asset)) {
433 file = new FileSndFile(this->asset, this);
436 if(FilePNG::check_sig(this->asset)) {
439 file = new FilePNG(this->asset, this);
442 if(FileJPEG::check_sig(this->asset)) {
445 file = new FileJPEG(this->asset, this);
448 if(FileGIF::check_sig(this->asset)) {
451 file = new FileGIF(this->asset, this);
454 if(FileEXR::check_sig(this->asset, test)) {
457 file = new FileEXR(this->asset, this);
460 if(FileFLAC::check_sig(this->asset, test)) {
463 file = new FileFLAC(this->asset, this);
466 if(FileCR2::check_sig(this->asset)) {
469 file = new FileCR2(this->asset, this);
472 if(FileTGA::check_sig(this->asset)) {
475 file = new FileTGA(this->asset, this);
478 if(FileTIFF::check_sig(this->asset)) {
481 file = new FileTIFF(this->asset, this);
484 if(FileOGG::check_sig(this->asset)) {
487 file = new FileOGG(this->asset, this);
490 if(FileVorbis::check_sig(this->asset)) {
493 file = new FileVorbis(this->asset, this);
496 if(FileMPEG::check_sig(this->asset)) {
499 file = new FileMPEG(this->asset, this);
502 if( test[0] == '<' && (
503 !strncmp(&test[1],"EDL>",4) ||
504 !strncmp(&test[1],"HTAL>",5) ||
505 !strncmp(&test[1],"?xml",4) ) ) {
509 } // can't load project file
510 if( !preferences->ffmpeg_early_probe &&
511 FileFFMPEG::check_sig(this->asset) ) {
513 file = new FileFFMPEG(this->asset, this);
518 return FILE_UNRECOGNIZED_CODEC;
521 // format already determined
523 file = new FileAC3(this->asset, this);
527 file = new FileScene(this->asset, this);
531 file = new FileFFMPEG(this->asset, this);
539 //printf("File::open_file 1\n");
540 file = new FileSndFile(this->asset, this);
545 file = new FilePNG(this->asset, this);
550 file = new FileJPEG(this->asset, this);
555 file = new FileGIF(this->asset, this);
560 file = new FileEXR(this->asset, this);
564 file = new FileFLAC(this->asset, this);
569 file = new FileCR2(this->asset, this);
574 file = new FileTGA(this->asset, this);
579 file = new FileTIFF(this->asset, this);
583 file = new FileDB(this->asset, this);
589 file = new FileMPEG(this->asset, this);
593 file = new FileOGG(this->asset, this);
597 file = new FileVorbis(this->asset, this);
601 file = new FileDV(this->asset, this);
611 // Reopen file with correct parser and get header.
612 if(file->open_file(rd, wr)) {
613 delete file; file = 0;
614 return FILE_NOT_FOUND;
619 // Set extra writing parameters to mandatory settings.
621 if(this->asset->dither) file->set_dither();
625 // one frame image file, no specific length
626 if( !this->asset->audio_data &&
627 this->asset->video_data && !this->asset->single_frame &&
628 this->asset->video_length >= 0 && this->asset->video_length <= 1 ) {
629 this->asset->single_frame = 1;
630 this->asset->video_length = -1;
634 // Synchronize header parameters
635 asset->copy_from(this->asset, 1);
638 if(debug) printf("File::open_file %d file=%p\n", __LINE__, file);
644 void File::delete_temp_samples_buffer()
647 if(temp_samples_buffer) {
648 for(int j = 0; j < audio_ring_buffers; j++) {
649 for(int i = 0; i < asset->channels; i++) {
650 delete temp_samples_buffer[j][i];
652 delete [] temp_samples_buffer[j];
655 delete [] temp_samples_buffer;
656 temp_samples_buffer = 0;
657 audio_ring_buffers = 0;
661 void File::delete_temp_frame_buffer()
664 if(temp_frame_buffer) {
665 for(int k = 0; k < video_ring_buffers; k++) {
666 for(int i = 0; i < asset->layers; i++) {
667 for(int j = 0; j < video_buffer_size; j++) {
668 delete temp_frame_buffer[k][i][j];
670 delete [] temp_frame_buffer[k][i];
672 delete [] temp_frame_buffer[k];
675 delete [] temp_frame_buffer;
676 temp_frame_buffer = 0;
677 video_ring_buffers = 0;
678 video_buffer_size = 0;
682 int File::close_file(int ignore_thread)
686 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
694 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
696 // The file's asset is a copy of the argument passed to open_file so the
697 // user must copy lengths from the file's asset.
699 asset->audio_length = current_sample;
700 asset->video_length = current_frame;
706 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
708 delete_temp_samples_buffer();
709 delete_temp_frame_buffer();
710 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
712 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
715 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
721 int File::get_index(IndexFile *index_file, MainProgressBar *progress_bar)
723 return !file ? -1 : file->get_index(index_file, progress_bar);
728 int File::start_audio_thread(int buffer_size, int ring_buffers)
730 this->audio_ring_buffers = ring_buffers;
735 audio_thread = new FileThread(this, 1, 0);
736 audio_thread->start_writing(buffer_size, 0, ring_buffers, 0);
741 int File::start_video_thread(int buffer_size,
746 this->video_ring_buffers = ring_buffers;
747 this->video_buffer_size = buffer_size;
751 video_thread = new FileThread(this, 0, 1);
752 video_thread->start_writing(buffer_size,
760 int File::start_video_decode_thread()
762 // Currently, CR2 is the only one which won't work asynchronously, so
763 // we're not using a virtual function yet.
764 if(!video_thread /* && asset->format != FILE_CR2 */)
766 video_thread = new FileThread(this, 0, 1);
767 video_thread->start_reading();
773 int File::stop_audio_thread()
777 audio_thread->stop_writing();
784 int File::stop_video_thread()
788 video_thread->stop_reading();
789 video_thread->stop_writing();
796 FileThread* File::get_video_thread()
801 int File::set_channel(int channel)
803 if(file && channel < asset->channels)
805 current_channel = channel;
812 int File::get_channel()
814 return current_channel;
817 // if no>=0, sets new program
818 // returns current program
819 int File::set_program(int no)
821 int result = file ? file->set_program(no) : current_program;
822 current_program = no < 0 ? result : no;
826 int File::get_cell_time(int no, double &time)
828 return file ? file->get_cell_time(no, time) : -1;
831 int File::get_system_time(int64_t &tm)
833 return file ? file->get_system_time(tm) : -1;
836 int File::get_audio_for_video(int vstream, int astream, int64_t &channel_mask)
838 return file ? file->get_audio_for_video(vstream, astream, channel_mask) : -1;
841 int File::get_video_pid(int track)
843 return file ? file->get_video_pid(track) : -1;
848 int File::get_video_info(int track, int &pid, double &framerate,
849 int &width, int &height, char *title)
852 file->get_video_info(track, pid, framerate, width, height, title);
855 int File::select_video_stream(Asset *asset, int vstream)
858 file->select_video_stream(asset, vstream);
861 int File::select_audio_stream(Asset *asset, int astream)
864 file->select_audio_stream(asset, astream);
868 int File::get_thumbnail(int stream,
869 int64_t &position, unsigned char *&thumbnail, int &ww, int &hh)
871 return file->get_thumbnail(stream, position, thumbnail, ww, hh);
874 int File::set_skimming(int track, int skim, skim_fn fn, void *vp)
876 return file->set_skimming(track, skim, fn, vp);
879 int File::skim_video(int track, void *vp, skim_fn fn)
881 return file->skim_video(track, vp, fn);
885 int File::set_layer(int layer, int is_thread)
887 if(file && layer < asset->layers)
889 if(!is_thread && video_thread)
891 video_thread->set_layer(layer);
895 current_layer = layer;
903 int64_t File::get_audio_length()
905 int64_t result = asset->audio_length;
906 int64_t base_samplerate = -1;
909 if(base_samplerate > 0)
910 return (int64_t)((double)result / asset->sample_rate * base_samplerate + 0.5);
918 int64_t File::get_video_length()
920 int64_t result = asset->video_length;
921 float base_framerate = -1;
924 if(base_framerate > 0)
925 return (int64_t)((double)result / asset->frame_rate * base_framerate + 0.5);
930 return -1; // infinity
934 int64_t File::get_video_position()
936 float base_framerate = -1;
937 if(base_framerate > 0)
938 return (int64_t)((double)current_frame / asset->frame_rate * base_framerate + 0.5);
940 return current_frame;
943 int64_t File::get_audio_position()
945 // int64_t base_samplerate = -1;
946 // if(base_samplerate > 0)
948 // if(normalized_sample_rate == base_samplerate)
949 // return normalized_sample;
951 // return (int64_t)((double)current_sample /
952 // asset->sample_rate *
957 return current_sample;
962 int File::set_audio_position(int64_t position)
968 #define REPOSITION(x, y) \
969 (labs((x) - (y)) > 1)
971 float base_samplerate = asset->sample_rate;
972 current_sample = normalized_sample = position;
974 // printf("File::set_audio_position %d normalized_sample=%ld\n",
976 // normalized_sample);
977 result = file->set_audio_position(current_sample);
980 printf("File::set_audio_position position=%jd"
981 " base_samplerate=%f asset=%p asset->sample_rate=%d\n",
982 position, base_samplerate, asset, asset->sample_rate);
984 //printf("File::set_audio_position %d %d %d\n", current_channel, current_sample, position);
989 int File::set_video_position(int64_t position,
995 // Convert to file's rate
996 // if(base_framerate > 0)
997 // position = (int64_t)((double)position /
999 // asset->frame_rate +
1003 if(video_thread && !is_thread)
1005 // Call thread. Thread calls this again to set the file state.
1006 video_thread->set_video_position(position);
1009 if(current_frame != position)
1013 current_frame = position;
1014 result = file->set_video_position(current_frame);
1021 // No resampling here.
1022 int File::write_samples(Samples **buffer, int64_t len)
1028 write_lock->lock("File::write_samples");
1030 // Convert to arrays for backwards compatability
1031 double *temp[asset->channels];
1032 for(int i = 0; i < asset->channels; i++)
1034 temp[i] = buffer[i]->get_data();
1037 result = file->write_samples(temp, len);
1038 current_sample += len;
1039 normalized_sample += len;
1040 asset->audio_length += len;
1041 write_lock->unlock();
1050 // Can't put any cmodel abstraction here because the filebase couldn't be
1052 int File::write_frames(VFrame ***frames, int len)
1054 //printf("File::write_frames %d\n", __LINE__);
1056 // Store the counters in temps so the filebase can choose to overwrite them.
1058 int current_frame_temp = current_frame;
1059 int video_length_temp = asset->video_length;
1061 write_lock->lock("File::write_frames");
1064 result = file->write_frames(frames, len);
1067 current_frame = current_frame_temp + len;
1068 asset->video_length = video_length_temp + len;
1069 write_lock->unlock();
1074 // Only called by FileThread
1075 int File::write_compressed_frame(VFrame *buffer)
1078 write_lock->lock("File::write_compressed_frame");
1079 result = file->write_compressed_frame(buffer);
1081 asset->video_length++;
1082 write_lock->unlock();
1087 int File::write_audio_buffer(int64_t len)
1092 result = audio_thread->write_buffer(len);
1097 int File::write_video_buffer(int64_t len)
1102 result = video_thread->write_buffer(len);
1108 Samples** File::get_audio_buffer()
1110 if(audio_thread) return audio_thread->get_audio_buffer();
1114 VFrame*** File::get_video_buffer()
1118 VFrame*** result = video_thread->get_video_buffer();
1127 int File::read_samples(Samples *samples, int64_t len)
1129 // Never try to read more samples than exist in the file
1130 if (asset->audio_length >= 0 && current_sample + len > asset->audio_length) {
1131 len = asset->audio_length - current_sample;
1133 if(len <= 0) return 0;
1136 const int debug = 0;
1137 if(debug) PRINT_TRACE
1139 if(debug) PRINT_TRACE
1141 double *buffer = samples->get_data();
1143 int64_t base_samplerate = asset->sample_rate;
1147 // Resample recursively calls this with the asset sample rate
1148 if(base_samplerate == 0) base_samplerate = asset->sample_rate;
1150 if(debug) PRINT_TRACE
1151 result = file->read_samples(buffer, len);
1153 if(debug) PRINT_TRACE
1154 current_sample += len;
1156 normalized_sample += len;
1158 if(debug) PRINT_TRACE
1163 int File::read_frame(VFrame *frame, int is_thread)
1165 const int debug = 0;
1167 if(debug) PRINT_TRACE
1169 //printf("File::read_frame %d\n", __LINE__);
1171 if(video_thread && !is_thread) return video_thread->read_frame(frame);
1173 //printf("File::read_frame %d\n", __LINE__);
1174 if(debug) PRINT_TRACE
1175 if( !file ) return 1;
1176 if(debug) PRINT_TRACE
1178 int supported_colormodel = colormodel_supported(frame->get_color_model());
1179 int advance_position = 1;
1180 int cache_active = use_cache || asset->single_frame ? 1 : 0;
1181 int64_t cache_position = !asset->single_frame ? current_frame : -1;
1183 if( cache_active && frame_cache->get_frame(frame, cache_position,
1184 current_layer, asset->frame_rate) )
1186 // Can't advance position if cache used.
1187 //printf("File::read_frame %d\n", __LINE__);
1188 advance_position = 0;
1191 else if(frame->get_color_model() != BC_COMPRESSED &&
1192 (supported_colormodel != frame->get_color_model() ||
1193 frame->get_w() != asset->width ||
1194 frame->get_h() != asset->height))
1197 // printf("File::read_frame %d\n", __LINE__);
1198 // Can't advance position here because it needs to be added to cache
1201 if(!temp_frame->params_match(asset->width, asset->height, supported_colormodel))
1208 // printf("File::read_frame %d\n", __LINE__);
1211 temp_frame = new VFrame(0,
1215 supported_colormodel,
1219 // printf("File::read_frame %d\n", __LINE__);
1220 temp_frame->copy_stacks(frame);
1221 result = file->read_frame(temp_frame);
1223 frame->transfer_from(temp_frame);
1224 else if( result && frame->get_status() > 0 )
1225 frame->set_status(-1);
1226 //printf("File::read_frame %d\n", __LINE__);
1230 // Can't advance position here because it needs to be added to cache
1231 //printf("File::read_frame %d\n", __LINE__);
1232 result = file->read_frame(frame);
1233 if( result && frame->get_status() > 0 )
1234 frame->set_status(-1);
1235 //for(int i = 0; i < 100 * 1000; i++) ((float*)frame->get_rows()[0])[i] = 1.0;
1238 if( result && !current_frame )
1239 frame->clear_frame();
1241 if( cache_active && advance_position && frame->get_status() > 0 )
1242 frame_cache->put_frame(frame, cache_position,
1243 current_layer, asset->frame_rate, 1, 0);
1244 //printf("File::read_frame %d\n", __LINE__);
1246 if(advance_position) current_frame++;
1247 if(debug) PRINT_TRACE
1251 int File::can_copy_from(Asset *asset,
1256 if(!asset) return 0;
1260 return asset->width == output_w &&
1261 asset->height == output_h &&
1262 file->can_copy_from(asset, position);
1268 // Fill in queries about formats when adding formats here.
1271 int File::strtoformat(const char *format)
1273 return strtoformat(0, format);
1276 int File::strtoformat(ArrayList<PluginServer*> *plugindb, const char *format)
1278 if(!strcasecmp(format, _(AC3_NAME))) return FILE_AC3;
1279 if(!strcasecmp(format, _(SCENE_NAME))) return FILE_SCENE;
1280 if(!strcasecmp(format, _(WAV_NAME))) return FILE_WAV;
1281 if(!strcasecmp(format, _(PCM_NAME))) return FILE_PCM;
1282 if(!strcasecmp(format, _(AU_NAME))) return FILE_AU;
1283 if(!strcasecmp(format, _(AIFF_NAME))) return FILE_AIFF;
1284 if(!strcasecmp(format, _(SND_NAME))) return FILE_SND;
1285 if(!strcasecmp(format, _(PNG_NAME))) return FILE_PNG;
1286 if(!strcasecmp(format, _(PNG_LIST_NAME))) return FILE_PNG_LIST;
1287 if(!strcasecmp(format, _(TIFF_NAME))) return FILE_TIFF;
1288 if(!strcasecmp(format, _(TIFF_LIST_NAME))) return FILE_TIFF_LIST;
1289 if(!strcasecmp(format, _(JPEG_NAME))) return FILE_JPEG;
1290 if(!strcasecmp(format, _(JPEG_LIST_NAME))) return FILE_JPEG_LIST;
1291 if(!strcasecmp(format, _(EXR_NAME))) return FILE_EXR;
1292 if(!strcasecmp(format, _(EXR_LIST_NAME))) return FILE_EXR_LIST;
1293 if(!strcasecmp(format, _(FLAC_NAME))) return FILE_FLAC;
1294 if(!strcasecmp(format, _(CR2_NAME))) return FILE_CR2;
1295 if(!strcasecmp(format, _(CR2_LIST_NAME))) return FILE_CR2_LIST;
1296 if(!strcasecmp(format, _(MPEG_NAME))) return FILE_MPEG;
1297 if(!strcasecmp(format, _(AMPEG_NAME))) return FILE_AMPEG;
1298 if(!strcasecmp(format, _(VMPEG_NAME))) return FILE_VMPEG;
1299 if(!strcasecmp(format, _(TGA_NAME))) return FILE_TGA;
1300 if(!strcasecmp(format, _(TGA_LIST_NAME))) return FILE_TGA_LIST;
1301 if(!strcasecmp(format, _(OGG_NAME))) return FILE_OGG;
1302 if(!strcasecmp(format, _(VORBIS_NAME))) return FILE_VORBIS;
1303 if(!strcasecmp(format, _(RAWDV_NAME))) return FILE_RAWDV;
1304 if(!strcasecmp(format, _(FFMPEG_NAME))) return FILE_FFMPEG;
1305 if(!strcasecmp(format, _(DBASE_NAME))) return FILE_DB;
1311 const char* File::formattostr(int format)
1313 return formattostr(0, format);
1316 const char* File::formattostr(ArrayList<PluginServer*> *plugindb, int format)
1320 case FILE_SCENE: return _(SCENE_NAME);
1321 case FILE_AC3: return _(AC3_NAME);
1322 case FILE_WAV: return _(WAV_NAME);
1323 case FILE_PCM: return _(PCM_NAME);
1324 case FILE_AU: return _(AU_NAME);
1325 case FILE_AIFF: return _(AIFF_NAME);
1326 case FILE_SND: return _(SND_NAME);
1327 case FILE_PNG: return _(PNG_NAME);
1328 case FILE_PNG_LIST: return _(PNG_LIST_NAME);
1329 case FILE_JPEG: return _(JPEG_NAME);
1330 case FILE_JPEG_LIST: return _(JPEG_LIST_NAME);
1331 case FILE_CR2: return _(CR2_NAME);
1332 case FILE_CR2_LIST: return _(CR2_LIST_NAME);
1333 case FILE_FLAC: return _(FLAC_NAME);
1334 case FILE_EXR: return _(EXR_NAME);
1335 case FILE_EXR_LIST: return _(EXR_LIST_NAME);
1336 case FILE_MPEG: return _(MPEG_NAME);
1337 case FILE_AMPEG: return _(AMPEG_NAME);
1338 case FILE_VMPEG: return _(VMPEG_NAME);
1339 case FILE_TGA: return _(TGA_NAME);
1340 case FILE_TGA_LIST: return _(TGA_LIST_NAME);
1341 case FILE_TIFF: return _(TIFF_NAME);
1342 case FILE_TIFF_LIST: return _(TIFF_LIST_NAME);
1343 case FILE_OGG: return _(OGG_NAME);
1344 case FILE_VORBIS: return _(VORBIS_NAME);
1345 case FILE_RAWDV: return _(RAWDV_NAME);
1346 case FILE_FFMPEG: return _(FFMPEG_NAME);
1347 case FILE_DB: return _(DBASE_NAME);
1349 return _("Unknown");
1352 int File::strtobits(const char *bits)
1354 if(!strcasecmp(bits, _(NAME_8BIT))) return BITSLINEAR8;
1355 if(!strcasecmp(bits, _(NAME_16BIT))) return BITSLINEAR16;
1356 if(!strcasecmp(bits, _(NAME_24BIT))) return BITSLINEAR24;
1357 if(!strcasecmp(bits, _(NAME_32BIT))) return BITSLINEAR32;
1358 if(!strcasecmp(bits, _(NAME_ULAW))) return BITSULAW;
1359 if(!strcasecmp(bits, _(NAME_ADPCM))) return BITS_ADPCM;
1360 if(!strcasecmp(bits, _(NAME_FLOAT))) return BITSFLOAT;
1361 return BITSLINEAR16;
1364 const char* File::bitstostr(int bits)
1366 //printf("File::bitstostr\n");
1369 case BITSLINEAR8: return (NAME_8BIT);
1370 case BITSLINEAR16: return (NAME_16BIT);
1371 case BITSLINEAR24: return (NAME_24BIT);
1372 case BITSLINEAR32: return (NAME_32BIT);
1373 case BITSULAW: return (NAME_ULAW);
1374 case BITS_ADPCM: return (NAME_ADPCM);
1375 case BITSFLOAT: return (NAME_FLOAT);
1377 return _("Unknown");
1382 int File::str_to_byteorder(const char *string)
1384 if(!strcasecmp(string, _("Lo Hi"))) return 1;
1388 const char* File::byteorder_to_str(int byte_order)
1390 if(byte_order) return _("Lo Hi");
1394 int File::bytes_per_sample(int bits)
1398 case BITSLINEAR8: return 1;
1399 case BITSLINEAR16: return 2;
1400 case BITSLINEAR24: return 3;
1401 case BITSLINEAR32: return 4;
1402 case BITSULAW: return 1;
1411 int File::get_best_colormodel(int driver)
1413 return get_best_colormodel(asset, driver);
1416 int File::get_best_colormodel(Asset *asset, int driver)
1418 switch(asset->format)
1420 #ifdef HAVE_FIREWIRE
1421 case FILE_RAWDV: return FileDV::get_best_colormodel(asset, driver);
1423 case FILE_MPEG: return FileMPEG::get_best_colormodel(asset, driver);
1425 case FILE_JPEG_LIST: return FileJPEG::get_best_colormodel(asset, driver);
1427 case FILE_EXR_LIST: return FileEXR::get_best_colormodel(asset, driver);
1429 case FILE_PNG_LIST: return FilePNG::get_best_colormodel(asset, driver);
1431 case FILE_TGA_LIST: return FileTGA::get_best_colormodel(asset, driver);
1433 case FILE_CR2_LIST: return FileCR2::get_best_colormodel(asset, driver);
1434 case FILE_DB: return FileDB::get_best_colormodel(asset, driver);
1435 case FILE_FFMPEG: return FileFFMPEG::get_best_colormodel(asset, driver);
1442 int File::colormodel_supported(int colormodel)
1445 return file->colormodel_supported(colormodel);
1451 int64_t File::file_memory_usage()
1453 return file ? file->base_memory_usage() : 0;
1456 int64_t File::get_memory_usage()
1460 result += file_memory_usage();
1461 if(temp_frame) result += temp_frame->get_data_size();
1462 result += frame_cache->get_memory_usage();
1463 if(video_thread) result += video_thread->get_memory_usage();
1465 if(result < MIN_CACHEITEM_SIZE) result = MIN_CACHEITEM_SIZE;
1470 int File::supports_video(ArrayList<PluginServer*> *plugindb, char *format)
1472 int format_i = strtoformat(plugindb, format);
1474 return supports_video(format_i);
1478 int File::supports_audio(ArrayList<PluginServer*> *plugindb, char *format)
1480 int format_i = strtoformat(plugindb, format);
1482 return supports_audio(format_i);
1487 int File::supports_video(int format)
1489 //printf("File::supports_video %d\n", format);
1494 case FILE_JPEG_LIST:
1504 case FILE_TIFF_LIST:
1513 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 File::get_exe_path(char *result, char *bnp)
1628 // Get executable path, basename
1629 int len = readlink("/proc/self/exe", result, BCTEXTLEN-1);
1632 char *ptr = strrchr(result, '/');
1633 if( ptr ) *ptr++ = 0; else ptr = result;
1634 if( bnp ) strncpy(bnp, ptr, BCTEXTLEN);
1642 void File::getenv_path(char *result, const char *path)
1644 char *rp = result, *ep = rp + BCTEXTLEN-1;
1645 const char *cp = path;
1646 // any env var can be used here to expand a path as:
1647 // "path...$id...": and id is a word as alpha,alnum...
1648 // expands as "path...getenv(id)..."
1649 // CIN_PATH, CIN_LIB are set in main.C,
1650 for( int ch=*cp++; ch && rp < ep; ch=*cp++ ) {
1651 if( ch == '$' && isalpha(*cp) ) { // scan alpha,alnum...
1652 const char *bp = cp; char *p = rp;
1653 while( p < ep && *bp && (isalnum(*bp) || *bp == '_') ) *p++ = *bp++;
1655 const char *envp = getenv(rp); // read env value
1656 if( !envp ) continue;
1657 while( *envp && rp < ep ) *rp++ = *envp++;
1658 cp = bp; // subst id=value
1666 char File::cinexe_path[BCTEXTLEN];
1667 char File::cinpkg_path[BCTEXTLEN];
1668 char File::cindat_path[BCTEXTLEN];
1669 char File::cinlib_path[BCTEXTLEN];
1670 char File::cincfg_path[BCTEXTLEN];
1671 char File::cinplg_path[BCTEXTLEN];
1672 char File::cinlad_path[BCTEXTLEN];
1673 char File::cinlcl_path[BCTEXTLEN];
1675 void File::init_cin_path()
1677 char env_path[BCTEXTLEN], env_pkg[BCTEXTLEN];
1678 // these values are advertised for forks/shell scripts
1679 get_exe_path(env_path, env_pkg);
1680 snprintf(cinexe_path, sizeof(cinexe_path), "CIN_PATH=%s", env_path);
1681 putenv(cinexe_path);
1682 snprintf(cinpkg_path, sizeof(cinpkg_path), "CIN_PKG=%s", env_pkg);
1683 putenv(cinpkg_path);
1685 getenv_path(env_path, CINDAT_DIR);
1686 snprintf(cindat_path, sizeof(cindat_path), "CIN_DAT=%s", env_path);
1687 putenv(cindat_path);
1689 getenv_path(env_path, CINLIB_DIR);
1690 snprintf(cinlib_path, sizeof(cinlib_path), "CIN_LIB=%s", env_path);
1691 putenv(cinlib_path);
1693 getenv_path(env_path, CONFIG_DIR);
1694 snprintf(cincfg_path, sizeof(cincfg_path), "CIN_CONFIG=%s", env_path);
1695 putenv(cincfg_path);
1697 getenv_path(env_path, PLUGIN_DIR);
1698 snprintf(cinplg_path, sizeof(cinplg_path), "CIN_PLUGIN=%s", env_path);
1699 putenv(cinplg_path);
1701 getenv_path(env_path, LADSPA_DIR);
1702 snprintf(cinlad_path, sizeof(cinlad_path), "CIN_LADSPA=%s", env_path);
1703 putenv(cinlad_path);
1705 getenv_path(env_path, LOCALE_DIR);
1706 snprintf(cinlcl_path, sizeof(cinlcl_path), "CIN_LOCALE=%s", env_path);
1707 putenv(cinlcl_path);