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"
63 #include "formatwindow.h"
64 #include "formattools.h"
65 #include "framecache.h"
67 #include "mainprogress.inc"
70 #include "packagingengine.h"
71 #include "pluginserver.h"
72 #include "preferences.h"
73 #include "probeprefs.h"
81 format_completion = new Condition(1, "File::format_completion");
82 write_lock = new Condition(1, "File::write_lock");
83 frame_cache = new FrameCache;
89 if( getting_options ) {
90 if( format_window ) format_window->set_done(0);
91 format_completion->lock("File::~File");
92 format_completion->unlock();
96 //printf("File::~File %d temp_debug=%d\n", __LINE__, --temp_debug);
102 asset->Garbage::remove_user();
103 delete format_completion;
108 void File::reset_parameters()
121 normalized_sample = 0;
124 playback_subtitle = -1;
128 temp_samples_buffer = 0;
129 temp_frame_buffer = 0;
130 current_frame_buffer = 0;
131 audio_ring_buffers = 0;
132 video_ring_buffers = 0;
133 video_buffer_size = 0;
136 int File::raise_window()
138 if( getting_options && format_window ) {
139 format_window->raise_window();
140 format_window->flush();
145 void File::close_window()
147 if( getting_options ) {
148 format_window->lock_window("File::close_window");
149 format_window->set_done(1);
150 format_window->unlock_window();
155 int File::get_options(FormatTools *format,
156 int audio_options, int video_options)
158 BC_WindowBase *parent_window = format->window;
159 Asset *asset = format->asset;
160 EDL *edl = format->mwindow ? format->mwindow->edl : 0;
163 format_completion->lock("File::get_options");
164 switch( asset->format ) {
165 #ifdef HAVE_CIN_3RDPARTY
166 case FILE_AC3: FileAC3::get_parameters(parent_window, asset, format_window,
167 audio_options, video_options, edl);
172 FileDV::get_parameters(parent_window, asset, format_window,
173 audio_options, video_options, edl);
181 FileSndFile::get_parameters(parent_window, asset, format_window,
182 audio_options, video_options, edl);
185 FileFFMPEG::get_parameters(parent_window, asset, format_window,
186 audio_options, video_options, edl);
191 FileMPEG::get_parameters(parent_window, asset, format_window,
192 audio_options, video_options, edl);
197 FileJPEG::get_parameters(parent_window, asset, format_window,
198 audio_options, video_options, edl);
203 FileEXR::get_parameters(parent_window, asset, format_window,
204 audio_options, video_options, edl);
208 FileFLAC::get_parameters(parent_window, asset, format_window,
209 audio_options, video_options, edl);
213 FilePNG::get_parameters(parent_window, asset, format_window,
214 audio_options, video_options, edl);
218 FilePPM::get_parameters(parent_window, asset, format_window,
219 audio_options, video_options, edl);
223 FileTGA::get_parameters(parent_window, asset, format_window,
224 audio_options, video_options, edl);
228 FileTIFF::get_parameters(parent_window, asset, format_window,
229 audio_options, video_options, edl);
235 if( !format_window ) {
236 ErrorBox *errorbox = new ErrorBox(_(PROGRAM_NAME ": Error"),
237 parent_window->get_abs_cursor_x(1),
238 parent_window->get_abs_cursor_y(1));
239 format_window = errorbox;
242 errorbox->create_objects(_("This format doesn't support audio."));
245 errorbox->create_objects(_("This format doesn't support video."));
246 errorbox->run_window();
252 format_completion->unlock();
256 int File::can_scale_input(Asset *asset)
258 switch( asset->format ) {
268 if( asset->video_length < 0 )
275 int File::set_processors(int cpus) // Set the number of cpus for certain codecs
277 if( cpus > 8 ) // mpegvideo max_threads = 16, more causes errs
278 cpus = 8; // 8 cpus ought to decode just about anything
279 // Set all instances so gets work.
285 int File::set_preload(int64_t size)
287 this->playback_preload = size;
291 void File::set_subtitle(int value)
293 this->playback_subtitle = value;
294 if( file ) file->set_subtitle(value);
297 void File::set_interpolate_raw(int value)
299 this->interpolate_raw = value;
302 void File::set_white_balance_raw(int value)
304 this->white_balance_raw = value;
307 void File::set_cache_frames(int value)
309 // caching only done locally
314 int File::purge_cache()
316 // caching only done locally
318 if( frame_cache->cache_items() > 0 ) {
319 frame_cache->remove_all();
325 int File::delete_oldest()
327 // return the number of bytes freed
328 return frame_cache->delete_oldest();
331 // file driver in order of probe precidence
332 // can be reordered in preferences->interface
333 const char *File::default_probes[] = {
356 const int File::nb_probes =
357 sizeof(File::default_probes)/sizeof(File::default_probes[0]);
362 FILE *fp = fopen(this->asset->path, "rb");
363 if( !fp ) return FILE_NOT_FOUND;
365 memset(data,0,sizeof(data));
366 int ret = fread(data, 1, 16, fp);
368 if( !ret ) return FILE_NOT_FOUND;
370 for( int i=0; i<preferences->file_probes.size(); ++i ) {
371 ProbePref *pref = preferences->file_probes[i];
372 if( !pref->armed ) continue;
373 if( !strncmp(pref->name,"FFMPEG",6) ) { // FFMPEG Early/Late
374 if( !FileFFMPEG::check_sig(this->asset) ) continue;
375 file = new FileFFMPEG(this->asset, this);
378 #ifdef HAVE_COMMERCIAL
379 if( !strcmp(pref->name,"DB") ) { // MediaDB
380 if( !FileDB::check_sig(this->asset) ) continue;
381 file = new FileDB(this->asset, this);
385 if( !strcmp(pref->name,"Scene") ) { // scene file
386 if( !FileScene::check_sig(this->asset, data)) continue;
387 file = new FileScene(this->asset, this);
391 if( !strcmp(pref->name,"DV") ) { // libdv
392 if( !FileDV::check_sig(this->asset) ) continue;
393 file = new FileDV(this->asset, this);
397 if( !strcmp(pref->name,"SndFile") ) { // libsndfile
398 if( !FileSndFile::check_sig(this->asset) ) continue;
399 file = new FileSndFile(this->asset, this);
402 if( !strcmp(pref->name,"PNG") ) { // PNG file
403 if( !FilePNG::check_sig(this->asset) ) continue;
404 file = new FilePNG(this->asset, this);
407 if( !strcmp(pref->name,"PPM") ) { // PPM file
408 if( !FilePPM::check_sig(this->asset) ) continue;
409 file = new FilePPM(this->asset, this);
412 if( !strcmp(pref->name,"JPEG") ) { // JPEG file
413 if( !FileJPEG::check_sig(this->asset) ) continue;
414 file = new FileJPEG(this->asset, this);
417 if( !strcmp(pref->name,"GIF") ) { // GIF file
418 if( !FileGIF::check_sig(this->asset)) continue;
419 file = new FileGIF(this->asset, this);
423 if( !strcmp(pref->name,"EXR") ) { // EXR file
424 if( !FileEXR::check_sig(this->asset, data)) continue;
425 file = new FileEXR(this->asset, this);
429 if( !strcmp(pref->name,"FLAC") ) { // FLAC file
430 if( !FileFLAC::check_sig(this->asset, data)) continue;
431 file = new FileFLAC(this->asset, this);
434 if( !strcmp(pref->name,"CR2") ) { // CR2 file
435 if( !FileCR2::check_sig(this->asset)) continue;
436 file = new FileCR2(this->asset, this);
439 if( !strcmp(pref->name,"TGA") ) { // TGA file
440 if( !FileTGA::check_sig(this->asset) ) continue;
441 file = new FileTGA(this->asset, this);
444 if( !strcmp(pref->name,"TIFF") ) { // TIFF file
445 if( !FileTIFF::check_sig(this->asset) ) continue;
446 file = new FileTIFF(this->asset, this);
450 if( !strcmp(pref->name,"MPEG") ) { // MPEG file
451 if( !FileMPEG::check_sig(this->asset) ) continue;
452 file = new FileMPEG(this->asset, this);
456 if( !strcmp(pref->name,"EDL") ) { // XML file
457 if( data[0] != '<' ) continue;
458 if( !strncmp(&data[1],"EDL>",4) ||
459 !strncmp(&data[1],"HTAL>",5) ||
460 !strncmp(&data[1],"?xml",4) )
464 return FILE_UNRECOGNIZED_CODEC; // maybe PCM file ?
467 int File::open_file(Preferences *preferences,
474 this->preferences = preferences;
475 this->asset->copy_from(asset, 1);
480 if( debug ) printf("File::open_file %p %d\n", this, __LINE__);
482 switch( this->asset->format ) {
483 // get the format now
484 // If you add another format to case 0, you also need to add another case for the
485 // file format #define.
488 if( ret != FILE_OK ) return ret;
490 // format already determined
491 #ifdef HAVE_CIN_3RDPARTY
493 file = new FileAC3(this->asset, this);
497 file = new FileScene(this->asset, this);
501 file = new FileFFMPEG(this->asset, this);
509 //printf("File::open_file 1\n");
510 file = new FileSndFile(this->asset, this);
515 file = new FilePNG(this->asset, this);
520 file = new FilePPM(this->asset, this);
525 file = new FileJPEG(this->asset, this);
530 file = new FileGIF(this->asset, this);
535 file = new FileEXR(this->asset, this);
539 file = new FileFLAC(this->asset, this);
544 file = new FileCR2(this->asset, this);
549 file = new FileTGA(this->asset, this);
554 file = new FileTIFF(this->asset, this);
556 #ifdef HAVE_COMMERCIAL
558 file = new FileDB(this->asset, this);
566 file = new FileMPEG(this->asset, this);
571 file = new FileDV(this->asset, this);
581 // Reopen file with correct parser and get header.
582 if( file->open_file(rd, wr) ) {
583 delete file; file = 0;
584 return FILE_NOT_FOUND;
589 // Set extra writing parameters to mandatory settings.
591 if( this->asset->dither ) file->set_dither();
595 // one frame image file, not brender, no specific length
596 if( !this->asset->audio_data && this->asset->use_header &&
597 this->asset->video_data && !this->asset->single_frame &&
598 this->asset->video_length >= 0 && this->asset->video_length <= 1 ) {
599 this->asset->single_frame = 1;
600 this->asset->video_length = -1;
604 // Synchronize header parameters
605 asset->copy_from(this->asset, 1);
608 if( debug ) printf("File::open_file %d file=%p\n", __LINE__, file);
614 void File::delete_temp_samples_buffer()
617 if( temp_samples_buffer ) {
618 for( int j = 0; j < audio_ring_buffers; j++ ) {
619 for( int i = 0; i < asset->channels; i++ ) {
620 delete temp_samples_buffer[j][i];
622 delete [] temp_samples_buffer[j];
625 delete [] temp_samples_buffer;
626 temp_samples_buffer = 0;
627 audio_ring_buffers = 0;
631 void File::delete_temp_frame_buffer()
634 if( temp_frame_buffer ) {
635 for( int k = 0; k < video_ring_buffers; k++ ) {
636 for( int i = 0; i < asset->layers; i++ ) {
637 for( int j = 0; j < video_buffer_size; j++ ) {
638 delete temp_frame_buffer[k][i][j];
640 delete [] temp_frame_buffer[k][i];
642 delete [] temp_frame_buffer[k];
645 delete [] temp_frame_buffer;
646 temp_frame_buffer = 0;
647 video_ring_buffers = 0;
648 video_buffer_size = 0;
652 int File::close_file(int ignore_thread)
656 if( debug ) printf("File::close_file file=%p %d\n", file, __LINE__);
658 if( !ignore_thread ) {
664 if( debug ) printf("File::close_file file=%p %d\n", file, __LINE__);
666 // The file's asset is a copy of the argument passed to open_file so the
667 // user must copy lengths from the file's asset.
669 asset->audio_length = current_sample;
670 asset->video_length = current_frame;
676 if( debug ) printf("File::close_file file=%p %d\n", file, __LINE__);
678 delete_temp_samples_buffer();
679 delete_temp_frame_buffer();
680 if( debug ) printf("File::close_file file=%p %d\n", file, __LINE__);
682 if( debug ) printf("File::close_file file=%p %d\n", file, __LINE__);
685 if( debug ) printf("File::close_file file=%p %d\n", file, __LINE__);
691 int File::get_index(IndexFile *index_file, MainProgressBar *progress_bar)
693 return !file ? -1 : file->get_index(index_file, progress_bar);
698 int File::start_audio_thread(int buffer_size, int ring_buffers)
700 this->audio_ring_buffers = ring_buffers;
703 if( !audio_thread ) {
704 audio_thread = new FileThread(this, 1, 0);
705 audio_thread->start_writing(buffer_size, 0, ring_buffers, 0);
710 int File::start_video_thread(int buffer_size,
715 this->video_ring_buffers = ring_buffers;
716 this->video_buffer_size = buffer_size;
718 if( !video_thread ) {
719 video_thread = new FileThread(this, 0, 1);
720 video_thread->start_writing(buffer_size,
728 int File::start_video_decode_thread()
730 // Currently, CR2 is the only one which won't work asynchronously, so
731 // we're not using a virtual function yet.
732 if( !video_thread /* && asset->format != FILE_CR2 */ ) {
733 video_thread = new FileThread(this, 0, 1);
734 video_thread->start_reading();
740 int File::stop_audio_thread()
743 audio_thread->stop_writing();
750 int File::stop_video_thread()
753 video_thread->stop_reading();
754 video_thread->stop_writing();
761 FileThread* File::get_video_thread()
766 int File::set_channel(int channel)
768 if( file && channel < asset->channels ) {
769 current_channel = channel;
776 int File::get_channel()
778 return current_channel;
781 // if no>=0, sets new program
782 // returns current program
783 int File::set_program(int no)
785 int result = file ? file->set_program(no) : current_program;
786 current_program = no < 0 ? result : no;
790 int File::get_cell_time(int no, double &time)
792 return file ? file->get_cell_time(no, time) : -1;
795 int File::get_system_time(int64_t &tm)
797 return file ? file->get_system_time(tm) : -1;
800 int File::get_audio_for_video(int vstream, int astream, int64_t &channel_mask)
802 return file ? file->get_audio_for_video(vstream, astream, channel_mask) : -1;
805 int File::get_video_pid(int track)
807 return file ? file->get_video_pid(track) : -1;
812 int File::get_video_info(int track, int &pid, double &framerate,
813 int &width, int &height, char *title)
816 file->get_video_info(track, pid, framerate, width, height, title);
819 int File::select_video_stream(Asset *asset, int vstream)
822 file->select_video_stream(asset, vstream);
825 int File::select_audio_stream(Asset *asset, int astream)
828 file->select_audio_stream(asset, astream);
832 int File::get_thumbnail(int stream,
833 int64_t &position, unsigned char *&thumbnail, int &ww, int &hh)
835 return file->get_thumbnail(stream, position, thumbnail, ww, hh);
838 int File::set_skimming(int track, int skim, skim_fn fn, void *vp)
840 return file->set_skimming(track, skim, fn, vp);
843 int File::skim_video(int track, void *vp, skim_fn fn)
845 return file->skim_video(track, vp, fn);
849 int File::set_layer(int layer, int is_thread)
851 if( file && layer < asset->layers ) {
852 if( !is_thread && video_thread ) {
853 video_thread->set_layer(layer);
856 current_layer = layer;
864 int64_t File::get_audio_length()
866 int64_t result = asset->audio_length;
867 int64_t base_samplerate = -1;
869 if( base_samplerate > 0 )
870 return (int64_t)((double)result / asset->sample_rate * base_samplerate + 0.5);
878 int64_t File::get_video_length()
880 int64_t result = asset->video_length;
881 float base_framerate = -1;
883 if( base_framerate > 0 )
884 return (int64_t)((double)result / asset->frame_rate * base_framerate + 0.5);
889 return -1; // infinity
893 int64_t File::get_video_position()
895 float base_framerate = -1;
896 if( base_framerate > 0 )
897 return (int64_t)((double)current_frame / asset->frame_rate * base_framerate + 0.5);
899 return current_frame;
902 int64_t File::get_audio_position()
904 // int64_t base_samplerate = -1;
905 // if( base_samplerate > 0 )
907 // if( normalized_sample_rate == base_samplerate )
908 // return normalized_sample;
910 // return (int64_t)((double)current_sample /
911 // asset->sample_rate *
916 return current_sample;
921 int File::set_audio_position(int64_t position)
925 if( !file ) return 1;
927 #define REPOSITION(x, y) \
928 (labs((x) - (y)) > 1)
930 float base_samplerate = asset->sample_rate;
931 current_sample = normalized_sample = position;
933 // printf("File::set_audio_position %d normalized_sample=%ld\n",
935 // normalized_sample);
936 result = file->set_audio_position(current_sample);
939 printf("File::set_audio_position position=%jd"
940 " base_samplerate=%f asset=%p asset->sample_rate=%d\n",
941 position, base_samplerate, asset, asset->sample_rate);
943 //printf("File::set_audio_position %d %d %d\n", current_channel, current_sample, position);
948 int File::set_video_position(int64_t position,
952 if( !file ) return 0;
954 // Convert to file's rate
955 // if( base_framerate > 0 )
956 // position = (int64_t)((double)position /
958 // asset->frame_rate +
962 if( video_thread && !is_thread ) {
963 // Call thread. Thread calls this again to set the file state.
964 video_thread->set_video_position(position);
967 if( current_frame != position ) {
969 current_frame = position;
970 result = file->set_video_position(current_frame);
977 // No resampling here.
978 int File::write_samples(Samples **buffer, int64_t len)
983 write_lock->lock("File::write_samples");
985 // Convert to arrays for backwards compatability
986 double *temp[asset->channels];
987 for( int i = 0; i < asset->channels; i++ ) {
988 temp[i] = buffer[i]->get_data();
991 result = file->write_samples(temp, len);
992 current_sample += len;
993 normalized_sample += len;
994 asset->audio_length += len;
995 write_lock->unlock();
1004 // Can't put any cmodel abstraction here because the filebase couldn't be
1006 int File::write_frames(VFrame ***frames, int len)
1008 //printf("File::write_frames %d\n", __LINE__);
1010 // Store the counters in temps so the filebase can choose to overwrite them.
1012 int current_frame_temp = current_frame;
1013 int video_length_temp = asset->video_length;
1015 write_lock->lock("File::write_frames");
1018 result = file->write_frames(frames, len);
1021 current_frame = current_frame_temp + len;
1022 asset->video_length = video_length_temp + len;
1023 write_lock->unlock();
1028 // Only called by FileThread
1029 int File::write_compressed_frame(VFrame *buffer)
1032 write_lock->lock("File::write_compressed_frame");
1033 result = file->write_compressed_frame(buffer);
1035 asset->video_length++;
1036 write_lock->unlock();
1041 int File::write_audio_buffer(int64_t len)
1044 if( audio_thread ) {
1045 result = audio_thread->write_buffer(len);
1050 int File::write_video_buffer(int64_t len)
1053 if( video_thread ) {
1054 result = video_thread->write_buffer(len);
1060 Samples** File::get_audio_buffer()
1062 if( audio_thread ) return audio_thread->get_audio_buffer();
1066 VFrame*** File::get_video_buffer()
1068 if( video_thread ) {
1069 VFrame*** result = video_thread->get_video_buffer();
1078 int File::read_samples(Samples *samples, int64_t len)
1080 // Never try to read more samples than exist in the file
1081 if( asset->audio_length >= 0 && current_sample + len > asset->audio_length ) {
1082 len = asset->audio_length - current_sample;
1084 if( len <= 0 ) return 0;
1087 const int debug = 0;
1088 if( debug ) PRINT_TRACE
1090 if( debug ) PRINT_TRACE
1092 double *buffer = samples->get_data();
1094 int64_t base_samplerate = asset->sample_rate;
1097 // Resample recursively calls this with the asset sample rate
1098 if( base_samplerate == 0 ) base_samplerate = asset->sample_rate;
1100 if( debug ) PRINT_TRACE
1101 result = file->read_samples(buffer, len);
1103 if( debug ) PRINT_TRACE
1104 current_sample += len;
1106 normalized_sample += len;
1108 if( debug ) PRINT_TRACE
1113 int File::read_frame(VFrame *frame, int is_thread)
1115 const int debug = 0;
1116 //printf("File::read_frame pos=%jd cache=%d 1frame=%d\n",
1117 // current_frame, use_cache, asset->single_frame);
1118 if( video_thread && !is_thread ) return video_thread->read_frame(frame);
1119 if( !file ) return 1;
1120 if( debug ) PRINT_TRACE
1122 int supported_colormodel = colormodel_supported(frame->get_color_model());
1123 int advance_position = 1;
1124 int cache_active = use_cache || asset->single_frame ? 1 : 0;
1125 int64_t cache_position = !asset->single_frame ? current_frame : -1;
1128 if( cache_active && frame_cache->get_frame(frame, cache_position,
1129 current_layer, asset->frame_rate) ) {
1130 // Can't advance position if cache used.
1131 //printf("File::read_frame %d\n", __LINE__);
1132 advance_position = 0;
1135 else if( frame->get_color_model() != BC_COMPRESSED &&
1136 (supported_colormodel != frame->get_color_model() ||
1137 (!file->can_scale_input() &&
1138 (frame->get_w() != asset->width ||
1139 frame->get_h() != asset->height))) ) {
1141 // printf("File::read_frame %d\n", __LINE__);
1142 // Can't advance position here because it needs to be added to cache
1144 if( !temp_frame->params_match(asset->width, asset->height, supported_colormodel) ) {
1151 temp_frame = new VFrame(asset->width, asset->height, supported_colormodel, 0);
1154 // printf("File::read_frame %d\n", __LINE__);
1155 temp_frame->copy_stacks(frame);
1156 result = file->read_frame(temp_frame);
1158 frame->transfer_from(temp_frame);
1159 else if( result && frame->get_status() > 0 )
1160 frame->set_status(-1);
1161 //printf("File::read_frame %d\n", __LINE__);
1164 // Can't advance position here because it needs to be added to cache
1165 //printf("File::read_frame %d\n", __LINE__);
1166 result = file->read_frame(frame);
1167 if( result && frame->get_status() > 0 )
1168 frame->set_status(-1);
1169 //for( int i = 0; i < 100 * 1000; i++ ) ((float*)frame->get_rows()[0])[i] = 1.0;
1172 if( result && !current_frame )
1173 frame->clear_frame();
1175 if( cache_active && advance_position && frame->get_status() > 0 )
1176 frame_cache->put_frame(frame, cache_position,
1177 current_layer, asset->frame_rate, 1, 0);
1178 //printf("File::read_frame %d\n", __LINE__);
1180 if( advance_position ) current_frame++;
1181 if( debug ) PRINT_TRACE
1185 int File::can_copy_from(Asset *asset, int64_t position, int output_w, int output_h)
1187 if( asset && file ) {
1188 return asset->width == output_w &&
1189 asset->height == output_h &&
1190 file->can_copy_from(asset, position);
1195 // Fill in queries about formats when adding formats here.
1198 int File::strtoformat(const char *format)
1200 if( !strcasecmp(format, _(AC3_NAME)) ) return FILE_AC3;
1201 if( !strcasecmp(format, _(SCENE_NAME)) ) return FILE_SCENE;
1202 if( !strcasecmp(format, _(WAV_NAME)) ) return FILE_WAV;
1203 if( !strcasecmp(format, _(PCM_NAME)) ) return FILE_PCM;
1204 if( !strcasecmp(format, _(AU_NAME)) ) return FILE_AU;
1205 if( !strcasecmp(format, _(AIFF_NAME)) ) return FILE_AIFF;
1206 if( !strcasecmp(format, _(SND_NAME)) ) return FILE_SND;
1207 if( !strcasecmp(format, _(PNG_NAME)) ) return FILE_PNG;
1208 if( !strcasecmp(format, _(PNG_LIST_NAME)) ) return FILE_PNG_LIST;
1209 if( !strcasecmp(format, _(PPM_NAME)) ) return FILE_PPM;
1210 if( !strcasecmp(format, _(PPM_LIST_NAME)) ) return FILE_PPM_LIST;
1211 if( !strcasecmp(format, _(TIFF_NAME)) ) return FILE_TIFF;
1212 if( !strcasecmp(format, _(TIFF_LIST_NAME)) ) return FILE_TIFF_LIST;
1213 if( !strcasecmp(format, _(JPEG_NAME)) ) return FILE_JPEG;
1214 if( !strcasecmp(format, _(JPEG_LIST_NAME)) ) return FILE_JPEG_LIST;
1215 if( !strcasecmp(format, _(EXR_NAME)) ) return FILE_EXR;
1216 if( !strcasecmp(format, _(EXR_LIST_NAME)) ) return FILE_EXR_LIST;
1217 if( !strcasecmp(format, _(FLAC_NAME)) ) return FILE_FLAC;
1218 if( !strcasecmp(format, _(CR2_NAME)) ) return FILE_CR2;
1219 if( !strcasecmp(format, _(CR2_LIST_NAME)) ) return FILE_CR2_LIST;
1220 if( !strcasecmp(format, _(MPEG_NAME)) ) return FILE_MPEG;
1221 if( !strcasecmp(format, _(AMPEG_NAME)) ) return FILE_AMPEG;
1222 if( !strcasecmp(format, _(VMPEG_NAME)) ) return FILE_VMPEG;
1223 if( !strcasecmp(format, _(TGA_NAME)) ) return FILE_TGA;
1224 if( !strcasecmp(format, _(TGA_LIST_NAME)) ) return FILE_TGA_LIST;
1225 if( !strcasecmp(format, _(RAWDV_NAME)) ) return FILE_RAWDV;
1226 if( !strcasecmp(format, _(FFMPEG_NAME)) ) return FILE_FFMPEG;
1227 if( !strcasecmp(format, _(DBASE_NAME)) ) return FILE_DB;
1233 const char* File::formattostr(int format)
1236 case FILE_SCENE: return _(SCENE_NAME);
1237 case FILE_AC3: return _(AC3_NAME);
1238 case FILE_WAV: return _(WAV_NAME);
1239 case FILE_PCM: return _(PCM_NAME);
1240 case FILE_AU: return _(AU_NAME);
1241 case FILE_AIFF: return _(AIFF_NAME);
1242 case FILE_SND: return _(SND_NAME);
1243 case FILE_PNG: return _(PNG_NAME);
1244 case FILE_PNG_LIST: return _(PNG_LIST_NAME);
1245 case FILE_PPM: return _(PPM_NAME);
1246 case FILE_PPM_LIST: return _(PPM_LIST_NAME);
1247 case FILE_JPEG: return _(JPEG_NAME);
1248 case FILE_JPEG_LIST: return _(JPEG_LIST_NAME);
1249 case FILE_CR2: return _(CR2_NAME);
1250 case FILE_CR2_LIST: return _(CR2_LIST_NAME);
1251 case FILE_FLAC: return _(FLAC_NAME);
1252 case FILE_EXR: return _(EXR_NAME);
1253 case FILE_EXR_LIST: return _(EXR_LIST_NAME);
1254 #ifdef HAVE_LIBZMPEG
1255 case FILE_MPEG: return _(MPEG_NAME);
1257 case FILE_AMPEG: return _(AMPEG_NAME);
1258 case FILE_VMPEG: return _(VMPEG_NAME);
1259 case FILE_TGA: return _(TGA_NAME);
1260 case FILE_TGA_LIST: return _(TGA_LIST_NAME);
1261 case FILE_TIFF: return _(TIFF_NAME);
1262 case FILE_TIFF_LIST: return _(TIFF_LIST_NAME);
1263 case FILE_RAWDV: return _(RAWDV_NAME);
1264 case FILE_FFMPEG: return _(FFMPEG_NAME);
1265 case FILE_DB: return _(DBASE_NAME);
1267 return _("Unknown");
1270 int File::strtobits(const char *bits)
1272 if( !strcasecmp(bits, _(NAME_8BIT)) ) return BITSLINEAR8;
1273 if( !strcasecmp(bits, _(NAME_16BIT)) ) return BITSLINEAR16;
1274 if( !strcasecmp(bits, _(NAME_24BIT)) ) return BITSLINEAR24;
1275 if( !strcasecmp(bits, _(NAME_32BIT)) ) return BITSLINEAR32;
1276 if( !strcasecmp(bits, _(NAME_ULAW)) ) return BITSULAW;
1277 if( !strcasecmp(bits, _(NAME_ADPCM)) ) return BITS_ADPCM;
1278 if( !strcasecmp(bits, _(NAME_FLOAT)) ) return BITSFLOAT;
1279 return BITSLINEAR16;
1282 const char* File::bitstostr(int bits)
1284 //printf("File::bitstostr\n");
1286 case BITSLINEAR8: return (NAME_8BIT);
1287 case BITSLINEAR16: return (NAME_16BIT);
1288 case BITSLINEAR24: return (NAME_24BIT);
1289 case BITSLINEAR32: return (NAME_32BIT);
1290 case BITSULAW: return (NAME_ULAW);
1291 case BITS_ADPCM: return (NAME_ADPCM);
1292 case BITSFLOAT: return (NAME_FLOAT);
1294 return _("Unknown");
1299 int File::str_to_byteorder(const char *string)
1301 if( !strcasecmp(string, _("Lo Hi")) ) return 1;
1305 const char* File::byteorder_to_str(int byte_order)
1307 if( byte_order ) return _("Lo Hi");
1311 int File::bytes_per_sample(int bits)
1314 case BITSLINEAR8: return 1;
1315 case BITSLINEAR16: return 2;
1316 case BITSLINEAR24: return 3;
1317 case BITSLINEAR32: return 4;
1318 case BITSULAW: return 1;
1324 int File::get_best_colormodel(int driver, int vstream)
1326 return file ? file->get_best_colormodel(driver, vstream) :
1327 get_best_colormodel(asset, driver);
1330 int File::get_best_colormodel(Asset *asset, int driver)
1332 switch( asset->format ) {
1334 case FILE_RAWDV: return FileDV::get_best_colormodel(asset, driver);
1336 #ifdef HAVE_LIBZMPEG
1337 case FILE_MPEG: return FileMPEG::get_best_colormodel(asset, driver);
1340 case FILE_JPEG_LIST: return FileJPEG::get_best_colormodel(asset, driver);
1343 case FILE_EXR_LIST: return FileEXR::get_best_colormodel(asset, driver);
1346 case FILE_PNG_LIST: return FilePNG::get_best_colormodel(asset, driver);
1348 case FILE_PPM_LIST: return FilePPM::get_best_colormodel(asset, driver);
1350 case FILE_TGA_LIST: return FileTGA::get_best_colormodel(asset, driver);
1352 case FILE_CR2_LIST: return FileCR2::get_best_colormodel(asset, driver);
1353 #ifdef HAVE_COMMERCIAL
1354 case FILE_DB: return FileDB::get_best_colormodel(asset, driver);
1356 case FILE_FFMPEG: return FileFFMPEG::get_best_colormodel(asset, driver);
1363 int File::colormodel_supported(int colormodel)
1366 return file->colormodel_supported(colormodel);
1372 int64_t File::file_memory_usage()
1374 return file ? file->base_memory_usage() : 0;
1377 int64_t File::get_memory_usage()
1381 result += file_memory_usage();
1382 if( temp_frame ) result += temp_frame->get_data_size();
1383 result += frame_cache->get_memory_usage();
1384 if( video_thread ) result += video_thread->get_memory_usage();
1386 if( result < MIN_CACHEITEM_SIZE ) result = MIN_CACHEITEM_SIZE;
1391 int File::renders_video(int format)
1395 case FILE_JPEG_LIST:
1407 case FILE_TIFF_LIST:
1415 int File::renders_video(Asset *asset)
1417 return asset->format == FILE_FFMPEG ?
1418 FFMPEG::renders_video(asset->fformat) :
1419 renders_video(asset->format);
1422 int File::renders_audio(int format)
1439 int File::renders_audio(Asset *asset)
1441 return asset->format == FILE_FFMPEG ?
1442 FFMPEG::renders_audio(asset->fformat) :
1443 renders_audio(asset->format);
1446 int File::is_image_render(int format)
1461 const char* File::get_tag(int format)
1464 case FILE_AC3: return "ac3";
1465 case FILE_AIFF: return "aif";
1466 case FILE_AMPEG: return "mp3";
1467 case FILE_AU: return "au";
1468 case FILE_RAWDV: return "dv";
1469 case FILE_DB: return "db";
1470 case FILE_EXR: return "exr";
1471 case FILE_EXR_LIST: return "exr";
1472 case FILE_FLAC: return "flac";
1473 case FILE_JPEG: return "jpg";
1474 case FILE_JPEG_LIST: return "jpg";
1475 case FILE_PCM: return "pcm";
1476 case FILE_PNG: return "png";
1477 case FILE_PNG_LIST: return "png";
1478 case FILE_PPM: return "ppm";
1479 case FILE_PPM_LIST: return "ppm";
1480 case FILE_TGA: return "tga";
1481 case FILE_TGA_LIST: return "tga";
1482 case FILE_TIFF: return "tif";
1483 case FILE_TIFF_LIST: return "tif";
1484 case FILE_VMPEG: return "m2v";
1485 case FILE_WAV: return "wav";
1486 case FILE_FFMPEG: return "ffmpg";
1491 const char* File::get_prefix(int format)
1494 case FILE_PCM: return "PCM";
1495 case FILE_WAV: return "WAV";
1496 case FILE_PNG: return "PNG";
1497 case FILE_PPM: return "PPM";
1498 case FILE_JPEG: return "JPEG";
1499 case FILE_TIFF: return "TIFF";
1500 case FILE_GIF: return "GIF";
1501 case FILE_JPEG_LIST: return "JPEG_LIST";
1502 case FILE_AU: return "AU";
1503 case FILE_AIFF: return "AIFF";
1504 case FILE_SND: return "SND";
1505 case FILE_TGA_LIST: return "TGA_LIST";
1506 case FILE_TGA: return "TGA";
1507 case FILE_MPEG: return "MPEG";
1508 case FILE_AMPEG: return "AMPEG";
1509 case FILE_VMPEG: return "VMPEG";
1510 case FILE_RAWDV: return "RAWDV";
1511 case FILE_TIFF_LIST: return "TIFF_LIST";
1512 case FILE_PNG_LIST: return "PNG_LIST";
1513 case FILE_PPM_LIST: return "PPM_LIST";
1514 case FILE_AC3: return "AC3";
1515 case FILE_EXR: return "EXR";
1516 case FILE_EXR_LIST: return "EXR_LIST";
1517 case FILE_CR2: return "CR2";
1518 case FILE_FLAC: return "FLAC";
1519 case FILE_FFMPEG: return "FFMPEG";
1520 case FILE_SCENE: return "SCENE";
1521 case FILE_CR2_LIST: return "CR2_LIST";
1522 case FILE_GIF_LIST: return "GIF_LIST";
1523 case FILE_DB: return "DB";
1525 return _("UNKNOWN");
1529 PackagingEngine *File::new_packaging_engine(Asset *asset)
1531 PackagingEngine *result = (PackagingEngine*) new PackagingEngineDefault();
1536 int File::record_fd()
1538 return file ? file->record_fd() : -1;
1542 void File::get_exe_path(char *result, char *bnp)
1544 // Get executable path, basename
1545 int len = readlink("/proc/self/exe", result, BCTEXTLEN-1);
1548 char *ptr = strrchr(result, '/');
1549 if( ptr ) *ptr++ = 0; else ptr = result;
1550 if( bnp ) strncpy(bnp, ptr, BCTEXTLEN);
1558 void File::getenv_path(char *result, const char *path)
1560 char *rp = result, *ep = rp + BCTEXTLEN-1;
1561 const char *cp = path;
1562 // any env var can be used here to expand a path as:
1563 // "path...$id...": and id is a word as alpha,alnum...
1564 // expands as "path...getenv(id)..."
1565 // CIN_PATH, CIN_LIB are set in main.C,
1566 for( int ch=*cp++; ch && rp < ep; ch=*cp++ ) {
1567 if( ch == '$' && isalpha(*cp) ) { // scan alpha,alnum...
1568 const char *bp = cp; char *p = rp;
1569 while( p < ep && *bp && (isalnum(*bp) || *bp == '_') ) *p++ = *bp++;
1571 const char *envp = getenv(rp); // read env value
1572 if( !envp ) continue;
1573 while( *envp && rp < ep ) *rp++ = *envp++;
1574 cp = bp; // subst id=value
1582 void File::setenv_path(const char *var, const char *path, int overwrite)
1584 char env_path[BCTEXTLEN];
1585 getenv_path(env_path, path);
1586 setenv(var, env_path, overwrite);
1589 void File::init_cin_path()
1591 char env_path[BCTEXTLEN], env_pkg[BCTEXTLEN];
1592 // these values are advertised for forks/shell scripts
1593 get_exe_path(env_path, env_pkg);
1594 setenv_path("CIN_PATH", env_path, 1);
1595 setenv_path("CIN_PKG", env_pkg, 1);
1596 setenv_path("CIN_DAT", CINDAT_DIR, 0);
1597 setenv_path("CIN_LIB", CINLIB_DIR, 0);
1598 setenv_path("CIN_CONFIG", CONFIG_DIR, 0);
1599 setenv_path("CIN_PLUGIN", PLUGIN_DIR, 0);
1600 setenv_path("CIN_LADSPA", LADSPA_DIR, 0);
1601 setenv_path("CIN_LOCALE", LOCALE_DIR, 0);
1602 setenv_path("CIN_BROWSER", CIN_BROWSER, 0);