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"
55 #undef HAVE_STDLIB_H // automake conflict
58 #include "filescene.h"
59 #include "fileserver.h"
60 #include "filesndfile.h"
62 #include "filethread.h"
64 #include "filevorbis.h"
67 #include "formatwindow.h"
68 #include "formattools.h"
69 #include "framecache.h"
73 #include "packagingengine.h"
74 #include "pluginserver.h"
75 #include "preferences.h"
79 //suppress noref warning
80 void *vorbis0_ov_callbacks[] = {
81 &OV_CALLBACKS_DEFAULT, &OV_CALLBACKS_NOCLOSE,
82 &OV_CALLBACKS_STREAMONLY, &OV_CALLBACKS_STREAMONLY_NOCLOSE,
89 format_completion = new Condition(1, "File::format_completion");
90 write_lock = new Condition(1, "File::write_lock");
91 frame_cache = new FrameCache;
93 forked = new Mutex("File::forked",0);
102 if(format_window) format_window->set_done(0);
103 format_completion->lock("File::~File");
104 format_completion->unlock();
107 if(temp_frame) delete temp_frame;
112 asset->Garbage::remove_user();
113 delete format_completion;
121 void File::reset_parameters()
139 normalized_sample = 0;
142 playback_subtitle = -1;
146 temp_samples_buffer = 0;
147 temp_frame_buffer = 0;
148 current_frame_buffer = 0;
149 audio_ring_buffers = 0;
150 video_ring_buffers = 0;
151 video_buffer_size = 0;
154 int File::raise_window()
156 if(getting_options && format_window)
158 format_window->raise_window();
159 format_window->flush();
164 void File::close_window()
168 format_window->lock_window("File::close_window");
169 format_window->set_done(1);
170 format_window->unlock_window();
175 int File::get_options(FormatTools *format,
176 int audio_options, int video_options)
178 BC_WindowBase *parent_window = format->window;
179 //ArrayList<PluginServer*> *plugindb = format->plugindb;
180 Asset *asset = format->asset;
183 format_completion->lock("File::get_options");
184 switch(asset->format)
187 FileAC3::get_parameters(parent_window,
194 FileDV::get_parameters(parent_window,
205 FileSndFile::get_parameters(parent_window,
212 FileFFMPEG::get_parameters(parent_window,
220 FileMPEG::get_parameters(parent_window,
228 FileJPEG::get_parameters(parent_window,
236 FileEXR::get_parameters(parent_window,
243 FileFLAC::get_parameters(parent_window,
251 FilePNG::get_parameters(parent_window,
259 FileTGA::get_parameters(parent_window,
267 FileTIFF::get_parameters(parent_window,
274 FileOGG::get_parameters(parent_window,
286 ErrorBox *errorbox = new ErrorBox(_(PROGRAM_NAME ": Error"),
287 parent_window->get_abs_cursor_x(1),
288 parent_window->get_abs_cursor_y(1));
289 format_window = errorbox;
292 errorbox->create_objects(_("This format doesn't support audio."));
295 errorbox->create_objects(_("This format doesn't support video."));
296 errorbox->run_window();
302 format_completion->unlock();
315 int File::set_processors(int cpus) // Set the number of cpus for certain codecs
317 if( cpus > 8 ) // mpegvideo max_threads = 16, more causes errs
318 cpus = 8; // 8 cpus ought to decode just about anything
322 FileForker this_is(*forked);
323 file_fork->send_command(FileFork::SET_PROCESSORS, (unsigned char*)&cpus, sizeof(cpus));
324 file_fork->read_result();
328 // Set all instances so gets work.
334 int File::set_preload(int64_t size)
339 FileForker this_is(*forked);
340 file_fork->send_command(FileFork::SET_PRELOAD, (unsigned char*)&size, sizeof(size));
341 file_fork->read_result();
346 this->playback_preload = size;
350 void File::set_subtitle(int value)
355 FileForker this_is(*forked);
356 file_fork->send_command(FileFork::SET_SUBTITLE, (unsigned char*)&value, sizeof(value));
357 file_fork->read_result();
361 this->playback_subtitle = value;
362 if( file ) file->set_subtitle(value);
365 void File::set_interpolate_raw(int value)
370 FileForker this_is(*forked);
371 file_fork->send_command(FileFork::SET_INTERPOLATE_RAW, (unsigned char*)&value, sizeof(value));
372 file_fork->read_result();
377 this->interpolate_raw = value;
380 void File::set_white_balance_raw(int value)
385 FileForker this_is(*forked);
386 file_fork->send_command(FileFork::SET_WHITE_BALANCE_RAW, (unsigned char*)&value, sizeof(value));
387 file_fork->read_result();
391 this->white_balance_raw = value;
395 void File::set_cache_frames(int value)
397 // caching only done locally
402 int File::purge_cache()
404 // caching only done locally
406 if( frame_cache->cache_items() > 0 )
408 frame_cache->remove_all();
414 int File::delete_oldest()
416 // caching only done locally
417 return frame_cache->delete_oldest();
430 int File::open_file(Preferences *preferences,
438 this->preferences = preferences;
439 this->asset->copy_from(asset, 1);
444 if(debug) printf("File::open_file %d\n", __LINE__);
447 if( !is_fork && MWindow::file_server && (rd || wr) ) {
448 FileForker this_is(*forked);
449 // printf("File::open_file %d file_server=%p rd=%d wr=%d %d\n",
451 // MWindow::file_server,
454 // asset->ms_quantization);
455 file_fork = MWindow::file_server->new_filefork();
456 //printf("File::open_file %d\n", __LINE__);
459 // Convert to hash table
461 asset->save_defaults(&table, "", 1, 1, 1, 1, 1);
464 table.save_string(string);
465 int buffer_size = sizeof(int) * 7 + strlen(string) + 1;
466 unsigned char *buffer = new unsigned char[buffer_size];
468 *(int*)(buffer + offset) = rd;
469 offset += sizeof(int);
470 *(int*)(buffer + offset) = wr;
471 offset += sizeof(int);
472 *(int*)(buffer + offset) = cpus;
473 offset += sizeof(int);
474 *(int*)(buffer + offset) = white_balance_raw;
475 offset += sizeof(int);
476 *(int*)(buffer + offset) = interpolate_raw;
477 offset += sizeof(int);
478 *(int*)(buffer + offset) = playback_subtitle;
479 offset += sizeof(int);
480 *(int*)(buffer + offset) = current_program;
481 offset += sizeof(int);
482 memcpy(buffer + offset, string, strlen(string) + 1);
483 //printf("File::open_file %d\n", __LINE__);
484 file_fork->send_command(FileFork::OPEN_FILE,
489 //printf("File::open_file %d\n", __LINE__);
491 // Get the updated asset from the fork
492 result = file_fork->read_result();
493 //printf("File::open_file %d\n", __LINE__);
496 table.load_string((char*)file_fork->result_data);
498 asset->load_defaults(&table, "", 1, 1, 1, 1, 1);
499 this->asset->load_defaults(&table, "", 1, 1, 1, 1, 1);
500 //this->asset->dump();
502 //printf("File::open_file %d\n", __LINE__);
505 // If it's a scene renderer, close it & reopen it locally to get the
506 // full OpenGL support.
507 // Just doing 2D for now. Should be forked in case Festival crashes.
508 // if(rd && this->asset->format == FILE_SCENE)
510 // //printf("File::open_file %p %d\n", this, __LINE__);
512 // // Lie to get it to work properly
523 if(debug) printf("File::open_file %p %d\n", this, __LINE__);
525 switch(this->asset->format)
527 // get the format now
528 // If you add another format to case 0, you also need to add another case for the
529 // file format #define.
531 if(FileDB::check_sig(this->asset)) {
533 file = new FileDB(this->asset, this);
536 // if early probe enabled
537 if( preferences->ffmpeg_early_probe &&
538 FileFFMPEG::check_sig(this->asset)) {
539 file = new FileFFMPEG(this->asset, this);
544 if(!(stream = fopen(this->asset->path, "rb"))) {
550 result = fread(test, 16, 1, stream);
552 if(FileScene::check_sig(this->asset, test)) {
555 file = new FileScene(this->asset, this);
558 if(FileDV::check_sig(this->asset)) {
561 file = new FileDV(this->asset, this);
564 if(FileSndFile::check_sig(this->asset)) {
567 file = new FileSndFile(this->asset, this);
570 if(FilePNG::check_sig(this->asset)) {
573 file = new FilePNG(this->asset, this);
576 if(FileJPEG::check_sig(this->asset)) {
579 file = new FileJPEG(this->asset, this);
582 if(FileGIF::check_sig(this->asset)) {
585 file = new FileGIF(this->asset, this);
588 if(FileEXR::check_sig(this->asset, test)) {
591 file = new FileEXR(this->asset, this);
594 if(FileFLAC::check_sig(this->asset, test)) {
597 file = new FileFLAC(this->asset, this);
600 if(FileCR2::check_sig(this->asset)) {
603 file = new FileCR2(this->asset, this);
606 if(FileTGA::check_sig(this->asset)) {
609 file = new FileTGA(this->asset, this);
612 if(FileTIFF::check_sig(this->asset)) {
615 file = new FileTIFF(this->asset, this);
618 if(FileOGG::check_sig(this->asset)) {
621 file = new FileOGG(this->asset, this);
624 if(FileVorbis::check_sig(this->asset)) {
627 file = new FileVorbis(this->asset, this);
630 if(FileMPEG::check_sig(this->asset)) {
633 file = new FileMPEG(this->asset, this);
636 if( test[0] == '<' && (
637 !strncmp(&test[1],"EDL>",4) ||
638 !strncmp(&test[1],"HTAL>",5) ||
639 !strncmp(&test[1],"?xml",4) ) ) {
643 } // can't load project file
644 if( !preferences->ffmpeg_early_probe &&
645 FileFFMPEG::check_sig(this->asset) ) {
647 file = new FileFFMPEG(this->asset, this);
652 return FILE_UNRECOGNIZED_CODEC;
655 // format already determined
657 file = new FileAC3(this->asset, this);
661 file = new FileScene(this->asset, this);
665 file = new FileFFMPEG(this->asset, this);
673 //printf("File::open_file 1\n");
674 file = new FileSndFile(this->asset, this);
679 file = new FilePNG(this->asset, this);
684 file = new FileJPEG(this->asset, this);
689 file = new FileGIF(this->asset, this);
694 file = new FileEXR(this->asset, this);
698 file = new FileFLAC(this->asset, this);
703 file = new FileCR2(this->asset, this);
708 file = new FileTGA(this->asset, this);
713 file = new FileTIFF(this->asset, this);
717 file = new FileDB(this->asset, this);
723 file = new FileMPEG(this->asset, this);
727 file = new FileOGG(this->asset, this);
731 file = new FileVorbis(this->asset, this);
735 file = new FileDV(this->asset, this);
745 // Reopen file with correct parser and get header.
746 if(file->open_file(rd, wr)) {
747 delete file; file = 0;
748 return FILE_NOT_FOUND;
753 // Set extra writing parameters to mandatory settings.
755 if(this->asset->dither) file->set_dither();
759 // one frame image file, no specific length
760 if( !this->asset->audio_data && this->asset->video_data &&
761 this->asset->video_length <= 1 )
762 this->asset->video_length = -1;
765 // Synchronize header parameters
766 asset->copy_from(this->asset, 1);
769 if(debug) printf("File::open_file %d file=%p\n", __LINE__, file);
775 void File::delete_temp_samples_buffer()
778 if(temp_samples_buffer) {
779 for(int j = 0; j < audio_ring_buffers; j++) {
780 for(int i = 0; i < asset->channels; i++) {
781 delete temp_samples_buffer[j][i];
783 delete [] temp_samples_buffer[j];
786 delete [] temp_samples_buffer;
787 temp_samples_buffer = 0;
788 audio_ring_buffers = 0;
792 void File::delete_temp_frame_buffer()
795 if(temp_frame_buffer) {
796 for(int k = 0; k < video_ring_buffers; k++) {
797 for(int i = 0; i < asset->layers; i++) {
798 for(int j = 0; j < video_buffer_size; j++) {
799 delete temp_frame_buffer[k][i][j];
801 delete [] temp_frame_buffer[k][i];
803 delete [] temp_frame_buffer[k];
806 delete [] temp_frame_buffer;
807 temp_frame_buffer = 0;
808 video_ring_buffers = 0;
809 video_buffer_size = 0;
813 int File::close_file(int ignore_thread)
818 if(debug) printf("File::close_file file=%p file_fork=%p %d\n", file, file_fork, __LINE__);
821 FileForker this_is(*forked);
822 file_fork->send_command(FileFork::CLOSE_FILE, 0, 0);
823 file_fork->read_result();
826 asset->audio_length = current_sample = *(int64_t*)file_fork->result_data;
827 asset->video_length = current_frame = *(int64_t*)(file_fork->result_data + sizeof(int64_t));
830 if(debug) printf("File::close_file:%d current_sample=" _LD " current_frame=" _LD "\n",
840 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
848 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
850 // The file's asset is a copy of the argument passed to open_file so the
851 // user must copy lengths from the file's asset.
853 asset->audio_length = current_sample;
854 asset->video_length = current_frame;
860 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
862 delete_temp_samples_buffer();
863 delete_temp_frame_buffer();
864 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
866 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
869 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
875 int File::get_index(char *index_path)
879 FileForker this_is(*forked);
880 file_fork->send_command(FileFork::GET_INDEX, (unsigned char*)index_path, strlen(index_path) + 1);
881 int result = file_fork->read_result();
887 return file->get_index(index_path);
894 int File::start_audio_thread(int buffer_size, int ring_buffers)
896 this->audio_ring_buffers = ring_buffers;
901 FileForker this_is(*forked);
902 unsigned char buffer[sizeof(int) * 2];
903 int *ibfr = (int *)buffer;
904 ibfr[0] = buffer_size;
905 ibfr[1] = audio_ring_buffers;
906 file_fork->send_command(FileFork::START_AUDIO_THREAD, buffer, sizeof(buffer));
907 int result = file_fork->read_result();
910 //printf("File::start_audio_thread %d file_fork->result_data=%p\n", __LINE__, file_fork->result_data);
911 // Create server copy of buffer
912 delete_temp_samples_buffer();
913 //printf("File::start_audio_thread %d\n", __LINE__);
914 temp_samples_buffer = new Samples**[audio_ring_buffers];
915 //printf("File::start_audio_thread %d\n", __LINE__);
916 for(int i = 0; i < audio_ring_buffers; i++)
918 //printf("File::start_audio_thread %d\n", __LINE__);
919 temp_samples_buffer[i] = new Samples*[asset->channels];
920 //printf("File::start_audio_thread %d\n", __LINE__);
921 for(int j = 0; j < asset->channels; j++)
923 int offset = i * Samples::filefork_size() * asset->channels +
924 j * Samples::filefork_size();
925 //printf("File::start_audio_thread %d j=%d offset=%d\n", __LINE__, j, offset);
926 temp_samples_buffer[i][j] = new Samples;
927 temp_samples_buffer[i][j]->from_filefork(
928 file_fork->result_data +
930 //printf("File::start_audio_thread %d\n", __LINE__);
941 audio_thread = new FileThread(this, 1, 0);
942 audio_thread->start_writing(buffer_size, 0, ring_buffers, 0);
947 int File::start_video_thread(int buffer_size,
952 this->video_ring_buffers = ring_buffers;
953 this->video_buffer_size = buffer_size;
958 FileForker this_is(*forked);
959 // This resets variables
960 delete_temp_frame_buffer();
962 this->video_ring_buffers = ring_buffers;
963 this->video_buffer_size = buffer_size;
965 unsigned char buffer[sizeof(int) * 4];
966 int *ibfr = (int *)buffer;
967 ibfr[0] = buffer_size;
968 ibfr[1] = color_model;
969 ibfr[2] = video_ring_buffers;
970 ibfr[3] = compressed;
971 // Buffers are allocated
972 file_fork->send_command(FileFork::START_VIDEO_THREAD,
975 int result = file_fork->read_result();
978 // Create server copy of buffer
979 //printf("File::start_video_thread %d %d\n", __LINE__, video_ring_buffers);
980 temp_frame_buffer = new VFrame***[video_ring_buffers];
981 for(int i = 0; i < video_ring_buffers; i++)
983 temp_frame_buffer[i] = new VFrame**[asset->layers];
984 for(int j = 0; j < asset->layers; j++)
986 temp_frame_buffer[i][j] = new VFrame*[video_buffer_size];
987 //printf("File::start_video_thread %d %p\n", __LINE__, temp_frame_buffer[i][j]);
988 for(int k = 0; k < video_buffer_size; k++)
990 temp_frame_buffer[i][j][k] = new VFrame;
991 temp_frame_buffer[i][j][k]->from_filefork(file_fork->result_data +
992 i * asset->layers * video_buffer_size * VFrame::filefork_size() +
993 j * video_buffer_size * VFrame::filefork_size() +
994 k * VFrame::filefork_size());
1008 video_thread = new FileThread(this, 0, 1);
1009 video_thread->start_writing(buffer_size,
1017 int File::start_video_decode_thread()
1022 FileForker this_is(*forked);
1023 file_fork->send_command(FileFork::START_VIDEO_DECODE_THREAD, 0, 0);
1024 file_fork->read_result();
1030 // Currently, CR2 is the only one which won't work asynchronously, so
1031 // we're not using a virtual function yet.
1032 if(!video_thread /* && asset->format != FILE_CR2 */)
1034 video_thread = new FileThread(this, 0, 1);
1035 video_thread->start_reading();
1041 int File::stop_audio_thread()
1046 file_fork->send_command(FileFork::STOP_AUDIO_THREAD, 0, 0);
1047 file_fork->read_result();
1054 audio_thread->stop_writing();
1055 delete audio_thread;
1061 int File::stop_video_thread()
1066 FileForker this_is(*forked);
1067 file_fork->send_command(FileFork::STOP_VIDEO_THREAD, 0, 0);
1068 file_fork->read_result();
1075 video_thread->stop_reading();
1076 video_thread->stop_writing();
1077 delete video_thread;
1083 FileThread* File::get_video_thread()
1085 return video_thread;
1088 int File::set_channel(int channel)
1093 FileForker this_is(*forked);
1094 // Set it locally for get_channel
1095 current_channel = channel;
1096 file_fork->send_command(FileFork::SET_CHANNEL, (unsigned char*)&channel, sizeof(channel));
1097 int result = file_fork->read_result();
1102 if(file && channel < asset->channels)
1104 current_channel = channel;
1111 int File::get_channel()
1113 return current_channel;
1116 // if no>=0, sets new program
1117 // returns current program
1118 int File::set_program(int no)
1123 FileForker this_is(*forked);
1124 file_fork->send_command(FileFork::SET_PROGRAM, (unsigned char*)&no, sizeof(no));
1125 int result = file_fork->read_result();
1126 current_program = no < 0 ? result : no;
1130 int result = file ? file->set_program(no) : current_program;
1131 current_program = no < 0 ? result : no;
1135 int File::get_cell_time(int no, double &time)
1140 FileForker this_is(*forked);
1141 file_fork->send_command(FileFork::GET_CELL_TIME, (unsigned char*)&no, sizeof(no));
1142 int result = file_fork->read_result();
1143 time = *(double *)file_fork->result_data;
1148 return file ? file->get_cell_time(no, time) : -1;
1151 int File::get_system_time(int64_t &tm)
1156 FileForker this_is(*forked);
1157 file_fork->send_command(FileFork::GET_STT_TIME, 0, 0);
1158 int result = file_fork->read_result();
1159 tm = *(int64_t *)file_fork->result_data;
1164 return file ? file->get_system_time(tm) : -1;
1167 int File::get_audio_for_video(int vstream, int astream, int64_t &channel_mask)
1172 FileForker this_is(*forked);
1173 unsigned char buffer[2*sizeof(int)];
1175 *(int*)(buffer + offset) = vstream;
1176 offset += sizeof(int);
1177 *(int*)(buffer + offset) = astream;
1178 file_fork->send_command(FileFork::GET_AUDIO4VIDEO, buffer, sizeof(buffer));
1179 int result = file_fork->read_result();
1180 channel_mask = *(int64_t *)file_fork->result_data;
1185 return file ? file->get_audio_for_video(vstream, astream, channel_mask) : -1;
1188 int File::get_video_pid(int track)
1193 FileForker this_is(*forked);
1194 file_fork->send_command(FileFork::GET_VIDEO_PID,
1195 (unsigned char*)&track, sizeof(track));
1196 int result = file_fork->read_result();
1201 return file ? file->get_video_pid(track) : -1;
1206 int File::get_video_info(int track, int &pid, double &framerate,
1207 int &width, int &height, char *title)
1212 FileForker this_is(*forked);
1213 file_fork->send_command(FileFork::GET_VIDEO_INFO,
1214 (unsigned char*)&track, sizeof(track));
1215 int result = file_fork->read_result();
1217 unsigned char *bp = file_fork->result_data;
1218 framerate = *(double*)bp; bp += sizeof(framerate);
1219 pid = *(int *) bp; bp += sizeof(pid);
1220 width = *(int *) bp; bp += sizeof(width);
1221 height = *(int *) bp; bp += sizeof(height);
1222 strcpy(title, (char *)bp);
1229 file->get_video_info(track, pid, framerate, width, height, title);
1232 int File::select_video_stream(Asset *asset, int vstream)
1237 FileForker this_is(*forked);
1238 file_fork->send_command(FileFork::SELECT_VIDEO_STREAM,
1239 (unsigned char*)&vstream, sizeof(vstream));
1240 int result = file_fork->read_result();
1242 unsigned char *bp = file_fork->result_data;
1243 asset->frame_rate = *(double*) bp; bp += sizeof(asset->frame_rate);
1244 asset->video_length = *(int64_t *) bp; bp += sizeof(asset->video_length);
1245 asset->width = *(int *) bp; bp += sizeof(asset->width);
1246 asset->height = *(int *) bp; bp += sizeof(asset->height);
1251 file->select_video_stream(asset, vstream);
1254 int File::select_audio_stream(Asset *asset, int astream)
1259 FileForker this_is(*forked);
1260 file_fork->send_command(FileFork::SELECT_AUDIO_STREAM,
1261 (unsigned char*)&astream, sizeof(astream));
1262 int result = file_fork->read_result();
1264 unsigned char *bp = file_fork->result_data;
1265 asset->audio_length = *(int64_t *) bp; bp += sizeof(asset->audio_length);
1266 asset->sample_rate = *(int *) bp; bp += sizeof(asset->sample_rate);
1271 file->select_audio_stream(asset, astream);
1275 int File::get_thumbnail(int stream,
1276 int64_t &position, unsigned char *&thumbnail, int &ww, int &hh)
1278 return file->get_thumbnail(stream, position, thumbnail, ww, hh);
1281 int File::set_skimming(int track, int skim, skim_fn fn, void *vp)
1283 return file->set_skimming(track, skim, fn, vp);
1286 int File::skim_video(int track, void *vp, skim_fn fn)
1288 return file->skim_video(track, vp, fn);
1292 int File::set_layer(int layer, int is_thread)
1295 // thread should only call in the fork
1296 if(file_fork && !is_fork && !is_thread)
1298 FileForker this_is(*forked);
1299 file_fork->send_command(FileFork::SET_LAYER, (unsigned char*)&layer, sizeof(layer));
1300 int result = file_fork->read_result();
1301 current_layer = layer;
1306 if(file && layer < asset->layers)
1308 if(!is_thread && video_thread)
1310 video_thread->set_layer(layer);
1314 current_layer = layer;
1322 int64_t File::get_audio_length()
1327 FileForker this_is(*forked);
1328 file_fork->send_command(FileFork::GET_AUDIO_LENGTH, 0, 0);
1329 int64_t result = file_fork->read_result();
1334 int64_t result = asset->audio_length;
1335 int64_t base_samplerate = -1;
1338 if(base_samplerate > 0)
1339 return (int64_t)((double)result / asset->sample_rate * base_samplerate + 0.5);
1347 int64_t File::get_video_length()
1352 FileForker this_is(*forked);
1353 file_fork->send_command(FileFork::GET_VIDEO_LENGTH, 0, 0);
1354 int64_t result = file_fork->read_result();
1360 int64_t result = asset->video_length;
1361 float base_framerate = -1;
1364 if(base_framerate > 0)
1365 return (int64_t)((double)result / asset->frame_rate * base_framerate + 0.5);
1370 return -1; // infinity
1374 int64_t File::get_video_position()
1379 FileForker this_is(*forked);
1380 file_fork->send_command(FileFork::GET_VIDEO_POSITION, 0, 0);
1381 int64_t result = file_fork->read_result();
1386 float base_framerate = -1;
1387 if(base_framerate > 0)
1388 return (int64_t)((double)current_frame / asset->frame_rate * base_framerate + 0.5);
1390 return current_frame;
1393 int64_t File::get_audio_position()
1398 FileForker this_is(*forked);
1399 file_fork->send_command(FileFork::GET_AUDIO_POSITION, 0, 0);
1400 int64_t result = file_fork->read_result();
1406 // int64_t base_samplerate = -1;
1407 // if(base_samplerate > 0)
1409 // if(normalized_sample_rate == base_samplerate)
1410 // return normalized_sample;
1412 // return (int64_t)((double)current_sample /
1413 // asset->sample_rate *
1414 // base_samplerate +
1418 return current_sample;
1423 int File::set_audio_position(int64_t position)
1428 FileForker this_is(*forked);
1429 file_fork->send_command(FileFork::SET_AUDIO_POSITION,
1430 (unsigned char*)&position,
1432 int result = file_fork->read_result();
1441 #define REPOSITION(x, y) \
1442 (labs((x) - (y)) > 1)
1444 float base_samplerate = asset->sample_rate;
1445 current_sample = normalized_sample = position;
1447 // printf("File::set_audio_position %d normalized_sample=%ld\n",
1449 // normalized_sample);
1450 result = file->set_audio_position(current_sample);
1453 printf("File::set_audio_position position=" _LD
1454 " base_samplerate=%f asset=%p asset->sample_rate=%d\n",
1455 position, base_samplerate, asset, asset->sample_rate);
1458 //printf("File::set_audio_position %d %d %d\n", current_channel, current_sample, position);
1463 int File::set_video_position(int64_t position,
1467 // Thread should only call in the fork
1468 if(file_fork && !is_fork && !is_thread)
1470 FileForker this_is(*forked);
1471 //printf("File::set_video_position %d %lld\n", __LINE__, position);
1472 file_fork->send_command(FileFork::SET_VIDEO_POSITION, (unsigned char*)&position, sizeof(position));
1473 int result = file_fork->read_result();
1481 // Convert to file's rate
1482 // if(base_framerate > 0)
1483 // position = (int64_t)((double)position /
1485 // asset->frame_rate +
1489 if(video_thread && !is_thread)
1491 // Call thread. Thread calls this again to set the file state.
1492 video_thread->set_video_position(position);
1495 if(current_frame != position)
1499 current_frame = position;
1500 result = file->set_video_position(current_frame);
1507 // No resampling here.
1508 int File::write_samples(Samples **buffer, int64_t len)
1513 FileForker this_is(*forked);
1514 int entry_size = Samples::filefork_size();
1515 int buffer_size = entry_size * asset->channels + sizeof(int64_t);
1516 unsigned char fork_buffer[buffer_size];
1517 for(int i = 0; i < asset->channels; i++)
1519 buffer[i]->to_filefork(fork_buffer + entry_size * i);
1522 *(int64_t*)(fork_buffer +
1523 entry_size * asset->channels) = len;
1525 file_fork->send_command(FileFork::WRITE_SAMPLES,
1528 int result = file_fork->read_result();
1540 write_lock->lock("File::write_samples");
1542 // Convert to arrays for backwards compatability
1543 double *temp[asset->channels];
1544 for(int i = 0; i < asset->channels; i++)
1546 temp[i] = buffer[i]->get_data();
1549 result = file->write_samples(temp, len);
1550 current_sample += len;
1551 normalized_sample += len;
1552 asset->audio_length += len;
1553 write_lock->unlock();
1562 // Can't put any cmodel abstraction here because the filebase couldn't be
1564 int File::write_frames(VFrame ***frames, int len)
1566 //printf("File::write_frames %d\n", __LINE__);
1570 FileForker this_is(*forked);
1571 //printf("File::write_frames %d\n", __LINE__);
1572 int entry_size = frames[0][0]->filefork_size();
1573 unsigned char fork_buffer[entry_size * asset->layers * len + sizeof(int)];
1574 for(int i = 0; i < asset->layers; i++)
1576 for(int j = 0; j < len; j++)
1578 // printf("File::write_frames %d " _LD " %d\n",
1580 // frames[i][j]->get_number(),
1581 // frames[i][j]->get_keyframe());
1582 frames[i][j]->to_filefork(fork_buffer +
1584 entry_size * len * i +
1592 int *fbfr = (int *)fork_buffer;
1596 file_fork->send_command(FileFork::WRITE_FRAMES,
1598 sizeof(fork_buffer));
1600 int result = file_fork->read_result();
1603 //printf("File::write_frames %d\n", __LINE__);
1608 #endif // USE_FILEFORK
1612 // Store the counters in temps so the filebase can choose to overwrite them.
1614 int current_frame_temp = current_frame;
1615 int video_length_temp = asset->video_length;
1617 write_lock->lock("File::write_frames");
1620 result = file->write_frames(frames, len);
1623 current_frame = current_frame_temp + len;
1624 asset->video_length = video_length_temp + len;
1625 write_lock->unlock();
1630 // Only called by FileThread
1631 int File::write_compressed_frame(VFrame *buffer)
1634 write_lock->lock("File::write_compressed_frame");
1635 result = file->write_compressed_frame(buffer);
1637 asset->video_length++;
1638 write_lock->unlock();
1643 int File::write_audio_buffer(int64_t len)
1648 FileForker this_is(*forked);
1649 file_fork->send_command(FileFork::WRITE_AUDIO_BUFFER, (unsigned char*)&len, sizeof(len));
1650 int result = file_fork->read_result();
1658 result = audio_thread->write_buffer(len);
1663 int File::write_video_buffer(int64_t len)
1668 FileForker this_is(*forked);
1669 // Copy over sequence numbers for background rendering
1670 // frame sizes for direct copy
1671 //printf("File::write_video_buffer %d\n", __LINE__);
1672 int fork_buffer_size = sizeof(int64_t) +
1673 VFrame::filefork_size() * asset->layers * len;
1674 unsigned char fork_buffer[fork_buffer_size];
1675 int64_t *fbfr = (int64_t *)fork_buffer;
1678 for(int i = 0; i < asset->layers; i++)
1680 for(int j = 0; j < len; j++)
1682 // Send memory state
1683 current_frame_buffer[i][j]->to_filefork(fork_buffer +
1685 VFrame::filefork_size() * (len * i + j));
1686 // printf("File::write_video_buffer %d size=%d %d %02x %02x %02x %02x %02x %02x %02x %02x\n",
1688 // current_frame_buffer[i][j]->get_shmid(),
1689 // current_frame_buffer[i][j]->get_compressed_size(),
1690 // current_frame_buffer[i][j]->get_data()[0],
1691 // current_frame_buffer[i][j]->get_data()[1],
1692 // current_frame_buffer[i][j]->get_data()[2],
1693 // current_frame_buffer[i][j]->get_data()[3],
1694 // current_frame_buffer[i][j]->get_data()[4],
1695 // current_frame_buffer[i][j]->get_data()[5],
1696 // current_frame_buffer[i][j]->get_data()[6],
1697 // current_frame_buffer[i][j]->get_data()[7]);
1701 //printf("File::write_video_buffer %d\n", __LINE__);
1702 file_fork->send_command(FileFork::WRITE_VIDEO_BUFFER,
1705 //printf("File::write_video_buffer %d\n", __LINE__);
1706 int result = file_fork->read_result();
1707 //printf("File::write_video_buffer %d\n", __LINE__);
1715 result = video_thread->write_buffer(len);
1721 Samples** File::get_audio_buffer()
1726 FileForker this_is(*forked);
1727 file_fork->send_command(FileFork::GET_AUDIO_BUFFER, 0, 0);
1728 int result = file_fork->read_result();
1730 // Read parameters for a Samples buffer & create it in File
1731 // delete_temp_samples_buffer();
1732 // if(!temp_samples_buffer)
1734 // temp_samples_buffer = new Samples**[ring_buffers];
1735 // for(int i = 0; i < ring_buffers; i++) temp_samples_buffer[i] = 0;
1739 // temp_samples_buffer = new Samples*[asset->channels];
1740 // for(int i = 0; i < asset->channels; i++)
1742 // temp_samples_buffer[i] = new Samples;
1743 // temp_samples_buffer[i]->from_filefork(file_fork->result_data +
1744 // i * Samples::filefork_size());
1747 return temp_samples_buffer[result];
1751 if(audio_thread) return audio_thread->get_audio_buffer();
1755 VFrame*** File::get_video_buffer()
1760 FileForker this_is(*forked);
1762 file_fork->send_command(FileFork::GET_VIDEO_BUFFER, 0, 0);
1763 int result = file_fork->read_result();
1765 // Read parameters for a VFrame buffer & create it in File
1766 // delete_temp_frame_buffer();
1769 // temp_frame_size = *(int*)(file_fork->result_data +
1770 // file_fork->result_bytes -
1773 // //printf("File::get_video_buffer %d %p %d\n", __LINE__, this, asset->layers);
1774 // temp_frame_buffer = new VFrame**[asset->layers];
1776 // for(int i = 0; i < asset->layers; i++)
1779 // temp_frame_buffer[i] = new VFrame*[temp_frame_size];
1781 // for(int j = 0; j < temp_frame_size; j++)
1784 // temp_frame_buffer[i][j] = new VFrame;
1785 // printf("File::get_video_buffer %d %p\n", __LINE__, temp_frame_buffer[i][j]);
1787 // temp_frame_buffer[i][j]->from_filefork(file_fork->result_data +
1788 // i * temp_frame_size * VFrame::filefork_size() +
1789 // j * VFrame::filefork_size());
1795 current_frame_buffer = temp_frame_buffer[result];
1797 return current_frame_buffer;
1803 VFrame*** result = video_thread->get_video_buffer();
1812 int File::read_samples(Samples *samples, int64_t len)
1814 // Never try to read more samples than exist in the file
1815 if (current_sample + len > asset->audio_length) {
1816 len = asset->audio_length - current_sample;
1818 if(len <= 0) return 0;
1821 const int debug = 0;
1822 if(debug) PRINT_TRACE
1827 FileForker this_is(*forked);
1828 int buffer_bytes = Samples::filefork_size() + sizeof(int64_t);
1829 unsigned char buffer[buffer_bytes];
1830 samples->to_filefork(buffer);
1831 *(int64_t*)(buffer + Samples::filefork_size()) = len;
1832 if(debug) PRINT_TRACE
1833 file_fork->send_command(FileFork::READ_SAMPLES,
1836 if(debug) PRINT_TRACE
1837 int result = file_fork->read_result();
1840 if(result && !file_fork->child_running())
1843 result = open_file(preferences, asset, rd, wr);
1850 if(debug) PRINT_TRACE
1852 double *buffer = samples->get_data();
1854 int64_t base_samplerate = asset->sample_rate;
1858 // Resample recursively calls this with the asset sample rate
1859 if(base_samplerate == 0) base_samplerate = asset->sample_rate;
1861 if(debug) PRINT_TRACE
1862 result = file->read_samples(buffer, len);
1864 if(debug) PRINT_TRACE
1865 current_sample += len;
1867 normalized_sample += len;
1869 if(debug) PRINT_TRACE
1875 int File::read_frame(VFrame *frame, int is_thread)
1877 const int debug = 0;
1879 if(debug) PRINT_TRACE
1882 // is_thread is only true in the fork
1883 if(file_fork && !is_fork && !is_thread)
1885 FileForker this_is(*forked);
1886 unsigned char fork_buffer[VFrame::filefork_size()];
1887 if(debug) PRINT_TRACE
1889 frame->to_filefork(fork_buffer);
1890 file_fork->send_command(FileFork::READ_FRAME,
1892 VFrame::filefork_size());
1894 int result = file_fork->read_result();
1898 if(result && !file_fork->child_running())
1901 result = open_file(preferences, asset, rd, wr);
1905 frame->get_color_model() == BC_COMPRESSED)
1907 // Get compressed data from socket
1908 //printf("File::read_frame %d %d\n", __LINE__, file_fork->result_bytes);
1909 int header_size = sizeof(int) * 2;
1910 if(file_fork->result_bytes > header_size)
1912 //printf("File::read_frame %d %d\n", __LINE__, file_fork->result_bytes);
1913 frame->allocate_compressed_data(file_fork->result_bytes - header_size);
1914 frame->set_compressed_size(file_fork->result_bytes - header_size);
1915 frame->set_keyframe(*(int*)(file_fork->result_data + sizeof(int)));
1916 memcpy(frame->get_data(),
1917 file_fork->result_data + header_size,
1918 file_fork->result_bytes - header_size);
1921 // Get compressed data size
1923 frame->set_compressed_size(*(int*)file_fork->result_data);
1924 frame->set_keyframe(*(int*)(file_fork->result_data + sizeof(int)));
1925 //printf("File::read_frame %d %d\n", __LINE__, *(int*)(file_fork->result_data + sizeof(int)));
1934 //printf("File::read_frame %d\n", __LINE__);
1936 if(video_thread && !is_thread) return video_thread->read_frame(frame);
1938 //printf("File::read_frame %d\n", __LINE__);
1939 if(debug) PRINT_TRACE
1942 if(debug) PRINT_TRACE
1943 int supported_colormodel = colormodel_supported(frame->get_color_model());
1944 int advance_position = 1;
1947 if(use_cache && !is_fork &&
1948 frame_cache->get_frame(frame,
1953 // Can't advance position if cache used.
1954 //printf("File::read_frame %d\n", __LINE__);
1955 advance_position = 0;
1959 if(frame->get_color_model() != BC_COMPRESSED &&
1960 (supported_colormodel != frame->get_color_model() ||
1961 frame->get_w() != asset->width ||
1962 frame->get_h() != asset->height))
1965 // printf("File::read_frame %d\n", __LINE__);
1966 // Can't advance position here because it needs to be added to cache
1969 if(!temp_frame->params_match(asset->width, asset->height, supported_colormodel))
1976 // printf("File::read_frame %d\n", __LINE__);
1979 temp_frame = new VFrame(0,
1983 supported_colormodel,
1987 // printf("File::read_frame %d\n", __LINE__);
1988 temp_frame->copy_stacks(frame);
1989 file->read_frame(temp_frame);
1990 //for(int i = 0; i < 1000 * 1000; i++) ((float*)temp_frame->get_rows()[0])[i] = 1.0;
1991 // printf("File::read_frame %d %d %d %d %d %d\n",
1992 // temp_frame->get_color_model(),
1993 // temp_frame->get_w(),
1994 // temp_frame->get_h(),
1995 // frame->get_color_model(),
1998 BC_CModels::transfer(frame->get_rows(),
1999 temp_frame->get_rows(),
2003 temp_frame->get_y(),
2004 temp_frame->get_u(),
2005 temp_frame->get_v(),
2008 temp_frame->get_w(),
2009 temp_frame->get_h(),
2014 temp_frame->get_color_model(),
2015 frame->get_color_model(),
2017 temp_frame->get_w(),
2019 // printf("File::read_frame %d\n", __LINE__);
2023 // Can't advance position here because it needs to be added to cache
2024 //printf("File::read_frame %d\n", __LINE__);
2025 file->read_frame(frame);
2026 //for(int i = 0; i < 100 * 1000; i++) ((float*)frame->get_rows()[0])[i] = 1.0;
2029 //printf("File::read_frame %d use_cache=%d\n", __LINE__, use_cache);
2030 if(use_cache && !is_fork)
2031 frame_cache->put_frame(frame,
2032 current_frame, current_layer,
2033 asset->frame_rate, 1, 0);
2034 //printf("File::read_frame %d\n", __LINE__);
2036 if(advance_position) current_frame++;
2037 if(debug) PRINT_TRACE
2044 int File::can_copy_from(Asset *asset,
2049 if(!asset) return 0;
2054 FileForker this_is(*forked);
2056 asset->write(&xml, 1, "");
2057 xml.terminate_string();
2058 const char *xml_string = xml.string();
2059 long xml_length = strlen(xml_string);
2060 int buffer_size = xml_length + 1 +
2064 unsigned char *buffer = new unsigned char[buffer_size];
2065 *(int64_t*)(buffer) = position;
2066 *(int*)(buffer + sizeof(int64_t)) = output_w;
2067 *(int*)(buffer + sizeof(int64_t) + sizeof(int)) = output_h;
2075 file_fork->send_command(FileFork::CAN_COPY_FROM,
2078 int result = file_fork->read_result();
2086 return asset->width == output_w &&
2087 asset->height == output_h &&
2088 file->can_copy_from(asset, position);
2094 // Fill in queries about formats when adding formats here.
2097 int File::strtoformat(const char *format)
2099 return strtoformat(0, format);
2102 int File::strtoformat(ArrayList<PluginServer*> *plugindb, const char *format)
2104 if(!strcasecmp(format, _(AC3_NAME))) return FILE_AC3;
2105 if(!strcasecmp(format, _(SCENE_NAME))) return FILE_SCENE;
2106 if(!strcasecmp(format, _(WAV_NAME))) return FILE_WAV;
2107 if(!strcasecmp(format, _(PCM_NAME))) return FILE_PCM;
2108 if(!strcasecmp(format, _(AU_NAME))) return FILE_AU;
2109 if(!strcasecmp(format, _(AIFF_NAME))) return FILE_AIFF;
2110 if(!strcasecmp(format, _(SND_NAME))) return FILE_SND;
2111 if(!strcasecmp(format, _(PNG_NAME))) return FILE_PNG;
2112 if(!strcasecmp(format, _(PNG_LIST_NAME))) return FILE_PNG_LIST;
2113 if(!strcasecmp(format, _(TIFF_NAME))) return FILE_TIFF;
2114 if(!strcasecmp(format, _(TIFF_LIST_NAME))) return FILE_TIFF_LIST;
2115 if(!strcasecmp(format, _(JPEG_NAME))) return FILE_JPEG;
2116 if(!strcasecmp(format, _(JPEG_LIST_NAME))) return FILE_JPEG_LIST;
2117 if(!strcasecmp(format, _(EXR_NAME))) return FILE_EXR;
2118 if(!strcasecmp(format, _(EXR_LIST_NAME))) return FILE_EXR_LIST;
2119 if(!strcasecmp(format, _(FLAC_NAME))) return FILE_FLAC;
2120 if(!strcasecmp(format, _(CR2_NAME))) return FILE_CR2;
2121 if(!strcasecmp(format, _(CR2_LIST_NAME))) return FILE_CR2_LIST;
2122 if(!strcasecmp(format, _(MPEG_NAME))) return FILE_MPEG;
2123 if(!strcasecmp(format, _(AMPEG_NAME))) return FILE_AMPEG;
2124 if(!strcasecmp(format, _(VMPEG_NAME))) return FILE_VMPEG;
2125 if(!strcasecmp(format, _(TGA_NAME))) return FILE_TGA;
2126 if(!strcasecmp(format, _(TGA_LIST_NAME))) return FILE_TGA_LIST;
2127 if(!strcasecmp(format, _(OGG_NAME))) return FILE_OGG;
2128 if(!strcasecmp(format, _(VORBIS_NAME))) return FILE_VORBIS;
2129 if(!strcasecmp(format, _(RAWDV_NAME))) return FILE_RAWDV;
2130 if(!strcasecmp(format, _(FFMPEG_NAME))) return FILE_FFMPEG;
2131 if(!strcasecmp(format, _(DBASE_NAME))) return FILE_DB;
2137 const char* File::formattostr(int format)
2139 return formattostr(0, format);
2142 const char* File::formattostr(ArrayList<PluginServer*> *plugindb, int format)
2146 case FILE_SCENE: return _(SCENE_NAME);
2147 case FILE_AC3: return _(AC3_NAME);
2148 case FILE_WAV: return _(WAV_NAME);
2149 case FILE_PCM: return _(PCM_NAME);
2150 case FILE_AU: return _(AU_NAME);
2151 case FILE_AIFF: return _(AIFF_NAME);
2152 case FILE_SND: return _(SND_NAME);
2153 case FILE_PNG: return _(PNG_NAME);
2154 case FILE_PNG_LIST: return _(PNG_LIST_NAME);
2155 case FILE_JPEG: return _(JPEG_NAME);
2156 case FILE_JPEG_LIST: return _(JPEG_LIST_NAME);
2157 case FILE_CR2: return _(CR2_NAME);
2158 case FILE_CR2_LIST: return _(CR2_LIST_NAME);
2159 case FILE_FLAC: return _(FLAC_NAME);
2160 case FILE_EXR: return _(EXR_NAME);
2161 case FILE_EXR_LIST: return _(EXR_LIST_NAME);
2162 case FILE_MPEG: return _(MPEG_NAME);
2163 case FILE_AMPEG: return _(AMPEG_NAME);
2164 case FILE_VMPEG: return _(VMPEG_NAME);
2165 case FILE_TGA: return _(TGA_NAME);
2166 case FILE_TGA_LIST: return _(TGA_LIST_NAME);
2167 case FILE_TIFF: return _(TIFF_NAME);
2168 case FILE_TIFF_LIST: return _(TIFF_LIST_NAME);
2169 case FILE_OGG: return _(OGG_NAME);
2170 case FILE_VORBIS: return _(VORBIS_NAME);
2171 case FILE_RAWDV: return _(RAWDV_NAME);
2172 case FILE_FFMPEG: return _(FFMPEG_NAME);
2173 case FILE_DB: return _(DBASE_NAME);
2175 return _("Unknown");
2178 int File::strtobits(const char *bits)
2180 if(!strcasecmp(bits, _(NAME_8BIT))) return BITSLINEAR8;
2181 if(!strcasecmp(bits, _(NAME_16BIT))) return BITSLINEAR16;
2182 if(!strcasecmp(bits, _(NAME_24BIT))) return BITSLINEAR24;
2183 if(!strcasecmp(bits, _(NAME_32BIT))) return BITSLINEAR32;
2184 if(!strcasecmp(bits, _(NAME_ULAW))) return BITSULAW;
2185 if(!strcasecmp(bits, _(NAME_ADPCM))) return BITS_ADPCM;
2186 if(!strcasecmp(bits, _(NAME_FLOAT))) return BITSFLOAT;
2187 return BITSLINEAR16;
2190 const char* File::bitstostr(int bits)
2192 //printf("File::bitstostr\n");
2195 case BITSLINEAR8: return (NAME_8BIT);
2196 case BITSLINEAR16: return (NAME_16BIT);
2197 case BITSLINEAR24: return (NAME_24BIT);
2198 case BITSLINEAR32: return (NAME_32BIT);
2199 case BITSULAW: return (NAME_ULAW);
2200 case BITS_ADPCM: return (NAME_ADPCM);
2201 case BITSFLOAT: return (NAME_FLOAT);
2203 return _("Unknown");
2208 int File::str_to_byteorder(const char *string)
2210 if(!strcasecmp(string, _("Lo Hi"))) return 1;
2214 const char* File::byteorder_to_str(int byte_order)
2216 if(byte_order) return _("Lo Hi");
2220 int File::bytes_per_sample(int bits)
2224 case BITSLINEAR8: return 1;
2225 case BITSLINEAR16: return 2;
2226 case BITSLINEAR24: return 3;
2227 case BITSLINEAR32: return 4;
2228 case BITSULAW: return 1;
2237 int File::get_best_colormodel(int driver)
2239 return get_best_colormodel(asset, driver);
2242 int File::get_best_colormodel(Asset *asset, int driver)
2244 switch(asset->format)
2246 case FILE_RAWDV: return FileDV::get_best_colormodel(asset, driver);
2247 case FILE_MPEG: return FileMPEG::get_best_colormodel(asset, driver);
2249 case FILE_JPEG_LIST: return FileJPEG::get_best_colormodel(asset, driver);
2251 case FILE_EXR_LIST: return FileEXR::get_best_colormodel(asset, driver);
2253 case FILE_PNG_LIST: return FilePNG::get_best_colormodel(asset, driver);
2255 case FILE_TGA_LIST: return FileTGA::get_best_colormodel(asset, driver);
2257 case FILE_CR2_LIST: return FileCR2::get_best_colormodel(asset, driver);
2258 case FILE_DB: return FileDB::get_best_colormodel(asset, driver);
2265 int File::colormodel_supported(int colormodel)
2270 FileForker this_is(*forked);
2271 unsigned char buffer[sizeof(int)];
2272 int *ibfr = (int *)buffer;
2273 ibfr[0] = colormodel;
2275 file_fork->send_command(FileFork::COLORMODEL_SUPPORTED,
2278 int result = file_fork->read_result();
2285 return file->colormodel_supported(colormodel);
2291 int64_t File::file_memory_usage()
2293 return file ? file->base_memory_usage() : 0;
2296 int64_t File::get_memory_usage()
2303 FileForker this_is(*forked);
2304 file_fork->send_command(FileFork::FILE_MEMORY_USAGE, 0, 0);
2305 result = file_fork->read_result();
2309 result += file_memory_usage();
2310 if(temp_frame) result += temp_frame->get_data_size();
2311 result += frame_cache->get_memory_usage();
2312 if(video_thread) result += video_thread->get_memory_usage();
2314 if(result < MIN_CACHEITEM_SIZE) result = MIN_CACHEITEM_SIZE;
2319 int File::supports_video(ArrayList<PluginServer*> *plugindb, char *format)
2321 int format_i = strtoformat(plugindb, format);
2323 return supports_video(format_i);
2327 int File::supports_audio(ArrayList<PluginServer*> *plugindb, char *format)
2329 int format_i = strtoformat(plugindb, format);
2331 return supports_audio(format_i);
2336 int File::supports_video(int format)
2338 //printf("File::supports_video %d\n", format);
2343 case FILE_JPEG_LIST:
2353 case FILE_TIFF_LIST:
2362 int File::supports_audio(int format)
2382 const char* File::get_tag(int format)
2386 case FILE_AC3: return "ac3";
2387 case FILE_AIFF: return "aif";
2388 case FILE_AMPEG: return "mp3";
2389 case FILE_AU: return "au";
2390 case FILE_RAWDV: return "dv";
2391 case FILE_DB: return "db";
2392 case FILE_EXR: return "exr";
2393 case FILE_EXR_LIST: return "exr";
2394 case FILE_FLAC: return "flac";
2395 case FILE_JPEG: return "jpg";
2396 case FILE_JPEG_LIST: return "jpg";
2397 case FILE_OGG: return "ogg";
2398 case FILE_PCM: return "pcm";
2399 case FILE_PNG: return "png";
2400 case FILE_PNG_LIST: return "png";
2401 case FILE_TGA: return "tga";
2402 case FILE_TGA_LIST: return "tga";
2403 case FILE_TIFF: return "tif";
2404 case FILE_TIFF_LIST: return "tif";
2405 case FILE_VMPEG: return "m2v";
2406 case FILE_VORBIS: return "ogg";
2407 case FILE_WAV: return "wav";
2408 case FILE_FFMPEG: return "ffmpg";
2413 const char* File::get_prefix(int format)
2416 case FILE_PCM: return "PCM";
2417 case FILE_WAV: return "WAV";
2418 case FILE_PNG: return "PNG";
2419 case FILE_JPEG: return "JPEG";
2420 case FILE_TIFF: return "TIFF";
2421 case FILE_GIF: return "GIF";
2422 case FILE_JPEG_LIST: return "JPEG_LIST";
2423 case FILE_AU: return "AU";
2424 case FILE_AIFF: return "AIFF";
2425 case FILE_SND: return "SND";
2426 case FILE_TGA_LIST: return "TGA_LIST";
2427 case FILE_TGA: return "TGA";
2428 case FILE_MPEG: return "MPEG";
2429 case FILE_AMPEG: return "AMPEG";
2430 case FILE_VMPEG: return "VMPEG";
2431 case FILE_RAWDV: return "RAWDV";
2432 case FILE_TIFF_LIST: return "TIFF_LIST";
2433 case FILE_PNG_LIST: return "PNG_LIST";
2434 case FILE_AC3: return "AC3";
2435 case FILE_EXR: return "EXR";
2436 case FILE_EXR_LIST: return "EXR_LIST";
2437 case FILE_CR2: return "CR2";
2438 case FILE_OGG: return "OGG";
2439 case FILE_VORBIS: return "VORBIS";
2440 case FILE_FLAC: return "FLAC";
2441 case FILE_FFMPEG: return "FFMPEG";
2442 case FILE_SCENE: return "SCENE";
2443 case FILE_CR2_LIST: return "CR2_LIST";
2444 case FILE_GIF_LIST: return "GIF_LIST";
2445 case FILE_DB: return "DB";
2447 return _("UNKNOWN");
2451 PackagingEngine *File::new_packaging_engine(Asset *asset)
2453 PackagingEngine *result;
2454 switch (asset->format)
2457 result = (PackagingEngine*)new PackagingEngineOGG();
2460 result = (PackagingEngine*) new PackagingEngineDefault();
2468 int File::record_fd()
2470 return file ? file->record_fd() : -1;
2474 void get_exe_path(char *result)
2476 // Get executable path
2477 pid_t pid = getpid();
2478 char proc_path[BCTEXTLEN];
2481 sprintf(proc_path, "/proc/%d/exe", pid);
2482 if((len = readlink(proc_path, result, BCTEXTLEN)) >= 0)
2485 //printf("Preferences::Preferences %d %s\n", __LINE__, result);
2486 char *ptr = strrchr(result, '/');