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"
49 #include "fileffmpeg.h"
57 #undef HAVE_STDLIB_H // automake conflict
60 #include "filescene.h"
61 #include "fileserver.h"
62 #include "filesndfile.h"
64 #include "filethread.h"
66 #include "filevorbis.h"
69 #include "formatwindow.h"
70 #include "formattools.h"
71 #include "framecache.h"
75 #include "packagingengine.h"
76 #include "pluginserver.h"
77 #include "preferences.h"
79 #include "stringfile.h"
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;
181 const char *locked_compressor = format->locked_compressor;
184 format_completion->lock("File::get_options");
185 switch(asset->format)
188 FileAC3::get_parameters(parent_window,
195 FileDV::get_parameters(parent_window,
206 FileSndFile::get_parameters(parent_window,
213 FileMOV::get_parameters(parent_window,
221 FileFFMPEG::get_parameters(parent_window,
229 FileMPEG::get_parameters(parent_window,
236 FileMOV::get_parameters(parent_window,
243 case FILE_AVI_LAVTOOLS:
246 case FILE_AVI_AVIFILE:
247 FileAVI::get_parameters(parent_window,
256 FileJPEG::get_parameters(parent_window,
264 FileEXR::get_parameters(parent_window,
271 FileFLAC::get_parameters(parent_window,
279 FilePNG::get_parameters(parent_window,
287 FileTGA::get_parameters(parent_window,
295 FileTIFF::get_parameters(parent_window,
302 FileOGG::get_parameters(parent_window,
314 ErrorBox *errorbox = new ErrorBox(PROGRAM_NAME ": Error",
315 parent_window->get_abs_cursor_x(1),
316 parent_window->get_abs_cursor_y(1));
317 format_window = errorbox;
320 errorbox->create_objects(_("This format doesn't support audio."));
323 errorbox->create_objects(_("This format doesn't support video."));
324 errorbox->run_window();
330 format_completion->unlock();
343 int File::set_processors(int cpus) // Set the number of cpus for certain codecs
345 if( cpus > 8 ) // mpegvideo max_threads = 16, more causes errs
346 cpus = 8; // 8 cpus ought to decode just about anything
350 FileForker this_is(*forked);
351 file_fork->send_command(FileFork::SET_PROCESSORS, (unsigned char*)&cpus, sizeof(cpus));
352 file_fork->read_result();
356 // Set all instances so gets work.
362 int File::set_preload(int64_t size)
367 FileForker this_is(*forked);
368 file_fork->send_command(FileFork::SET_PRELOAD, (unsigned char*)&size, sizeof(size));
369 file_fork->read_result();
374 this->playback_preload = size;
378 void File::set_subtitle(int value)
383 FileForker this_is(*forked);
384 file_fork->send_command(FileFork::SET_SUBTITLE, (unsigned char*)&value, sizeof(value));
385 file_fork->read_result();
389 this->playback_subtitle = value;
390 if( file ) file->set_subtitle(value);
393 void File::set_interpolate_raw(int value)
398 FileForker this_is(*forked);
399 file_fork->send_command(FileFork::SET_INTERPOLATE_RAW, (unsigned char*)&value, sizeof(value));
400 file_fork->read_result();
405 this->interpolate_raw = value;
408 void File::set_white_balance_raw(int value)
413 FileForker this_is(*forked);
414 file_fork->send_command(FileFork::SET_WHITE_BALANCE_RAW, (unsigned char*)&value, sizeof(value));
415 file_fork->read_result();
419 this->white_balance_raw = value;
423 void File::set_cache_frames(int value)
425 // caching only done locally
430 int File::purge_cache()
432 // caching only done locally
434 if( frame_cache->cache_items() > 0 )
436 frame_cache->remove_all();
442 int File::delete_oldest()
444 // caching only done locally
445 return frame_cache->delete_oldest();
458 int File::open_file(Preferences *preferences,
466 this->preferences = preferences;
467 this->asset->copy_from(asset, 1);
472 if(debug) printf("File::open_file %d\n", __LINE__);
475 if( !is_fork && MWindow::file_server && (rd || wr) ) {
476 FileForker this_is(*forked);
477 // printf("File::open_file %d file_server=%p rd=%d wr=%d %d\n",
479 // MWindow::file_server,
482 // asset->ms_quantization);
483 file_fork = MWindow::file_server->new_filefork();
484 //printf("File::open_file %d\n", __LINE__);
487 // Convert to hash table
489 asset->save_defaults(&table, "", 1, 1, 1, 1, 1);
492 table.save_string(string);
493 int buffer_size = sizeof(int) * 7 + strlen(string) + 1;
494 unsigned char *buffer = new unsigned char[buffer_size];
496 *(int*)(buffer + offset) = rd;
497 offset += sizeof(int);
498 *(int*)(buffer + offset) = wr;
499 offset += sizeof(int);
500 *(int*)(buffer + offset) = cpus;
501 offset += sizeof(int);
502 *(int*)(buffer + offset) = white_balance_raw;
503 offset += sizeof(int);
504 *(int*)(buffer + offset) = interpolate_raw;
505 offset += sizeof(int);
506 *(int*)(buffer + offset) = playback_subtitle;
507 offset += sizeof(int);
508 *(int*)(buffer + offset) = current_program;
509 offset += sizeof(int);
510 memcpy(buffer + offset, string, strlen(string) + 1);
511 //printf("File::open_file %d\n", __LINE__);
512 file_fork->send_command(FileFork::OPEN_FILE,
517 //printf("File::open_file %d\n", __LINE__);
519 // Get the updated asset from the fork
520 result = file_fork->read_result();
521 //printf("File::open_file %d\n", __LINE__);
524 table.load_string((char*)file_fork->result_data);
526 asset->load_defaults(&table, "", 1, 1, 1, 1, 1);
527 this->asset->load_defaults(&table, "", 1, 1, 1, 1, 1);
528 //this->asset->dump();
530 //printf("File::open_file %d\n", __LINE__);
533 // If it's a scene renderer, close it & reopen it locally to get the
534 // full OpenGL support.
535 // Just doing 2D for now. Should be forked in case Festival crashes.
536 // if(rd && this->asset->format == FILE_SCENE)
538 // //printf("File::open_file %p %d\n", this, __LINE__);
540 // // Lie to get it to work properly
551 if(debug) printf("File::open_file %p %d\n", this, __LINE__);
553 switch(this->asset->format)
555 // get the format now
556 // If you add another format to case 0, you also need to add another case for the
557 // file format #define.
559 if(FileDB::check_sig(this->asset)) {
561 file = new FileDB(this->asset, this);
564 // if early probe enabled
565 if( preferences->ffmpeg_early_probe &&
566 FileFFMPEG::check_sig(this->asset)) {
567 file = new FileFFMPEG(this->asset, this);
572 if(!(stream = fopen(this->asset->path, "rb"))) {
578 result = fread(test, 16, 1, stream);
580 if(FileScene::check_sig(this->asset, test)) {
583 file = new FileScene(this->asset, this);
586 if(FileDV::check_sig(this->asset)) {
589 file = new FileDV(this->asset, this);
592 if(FileSndFile::check_sig(this->asset)) {
595 file = new FileSndFile(this->asset, this);
598 if(FilePNG::check_sig(this->asset)) {
601 file = new FilePNG(this->asset, this);
604 if(FileJPEG::check_sig(this->asset)) {
607 file = new FileJPEG(this->asset, this);
610 if(FileGIF::check_sig(this->asset)) {
613 file = new FileGIF(this->asset, this);
616 if(FileEXR::check_sig(this->asset, test)) {
619 file = new FileEXR(this->asset, this);
622 if(FileFLAC::check_sig(this->asset, test)) {
625 file = new FileFLAC(this->asset, this);
628 if(FileCR2::check_sig(this->asset)) {
631 file = new FileCR2(this->asset, this);
634 if(FileTGA::check_sig(this->asset)) {
637 file = new FileTGA(this->asset, this);
640 if(FileTIFF::check_sig(this->asset)) {
643 file = new FileTIFF(this->asset, this);
646 if(FileOGG::check_sig(this->asset)) {
649 file = new FileOGG(this->asset, this);
652 if(FileVorbis::check_sig(this->asset)) {
655 file = new FileVorbis(this->asset, this);
658 if(FileMPEG::check_sig(this->asset)) {
661 file = new FileMPEG(this->asset, this);
664 if( test[0] == '<' && (
665 !strncmp(&test[1],"EDL>",4) ||
666 !strncmp(&test[1],"HTAL>",5) ||
667 !strncmp(&test[1],"?xml",4) ) ) {
671 } // can't load project file
672 if(FileMOV::check_sig(this->asset)) {
674 // should be last because quicktime lacks a magic number
676 file = new FileMOV(this->asset, this);
679 if( !preferences->ffmpeg_early_probe &&
680 FileFFMPEG::check_sig(this->asset) ) {
682 file = new FileFFMPEG(this->asset, this);
687 return FILE_UNRECOGNIZED_CODEC;
690 // format already determined
692 file = new FileAC3(this->asset, this);
696 file = new FileScene(this->asset, this);
700 file = new FileFFMPEG(this->asset, this);
708 //printf("File::open_file 1\n");
709 file = new FileSndFile(this->asset, this);
714 file = new FilePNG(this->asset, this);
719 file = new FileJPEG(this->asset, this);
724 file = new FileGIF(this->asset, this);
729 file = new FileEXR(this->asset, this);
733 file = new FileFLAC(this->asset, this);
738 file = new FileCR2(this->asset, this);
743 file = new FileTGA(this->asset, this);
748 file = new FileTIFF(this->asset, this);
752 file = new FileDB(this->asset, this);
756 file = new FileMOV(this->asset, this);
762 file = new FileMPEG(this->asset, this);
766 file = new FileOGG(this->asset, this);
770 file = new FileVorbis(this->asset, this);
774 file = new FileMOV(this->asset, this);
777 case FILE_AVI_LAVTOOLS:
780 case FILE_AVI_AVIFILE:
781 file = new FileAVI(this->asset, this);
785 file = new FileDV(this->asset, this);
795 // Reopen file with correct parser and get header.
796 if(file->open_file(rd, wr)) {
798 return FILE_NOT_FOUND;
803 // Set extra writing parameters to mandatory settings.
805 if(this->asset->dither) file->set_dither();
809 // one frame image file, no specific length
810 if( !this->asset->audio_data && this->asset->video_data &&
811 this->asset->video_length == 1 )
812 this->asset->video_length = -1;
815 // Synchronize header parameters
816 asset->copy_from(this->asset, 1);
819 if(debug) printf("File::open_file %d file=%p\n", __LINE__, file);
825 void File::delete_temp_samples_buffer()
828 if(temp_samples_buffer) {
829 for(int j = 0; j < audio_ring_buffers; j++) {
830 for(int i = 0; i < asset->channels; i++) {
831 delete temp_samples_buffer[j][i];
833 delete [] temp_samples_buffer[j];
836 delete [] temp_samples_buffer;
837 temp_samples_buffer = 0;
838 audio_ring_buffers = 0;
842 void File::delete_temp_frame_buffer()
845 if(temp_frame_buffer) {
846 for(int k = 0; k < video_ring_buffers; k++) {
847 for(int i = 0; i < asset->layers; i++) {
848 for(int j = 0; j < video_buffer_size; j++) {
849 delete temp_frame_buffer[k][i][j];
851 delete [] temp_frame_buffer[k][i];
853 delete [] temp_frame_buffer[k];
856 delete [] temp_frame_buffer;
857 temp_frame_buffer = 0;
858 video_ring_buffers = 0;
859 video_buffer_size = 0;
863 int File::close_file(int ignore_thread)
868 if(debug) printf("File::close_file file=%p file_fork=%p %d\n", file, file_fork, __LINE__);
871 FileForker this_is(*forked);
872 file_fork->send_command(FileFork::CLOSE_FILE, 0, 0);
873 file_fork->read_result();
876 asset->audio_length = current_sample = *(int64_t*)file_fork->result_data;
877 asset->video_length = current_frame = *(int64_t*)(file_fork->result_data + sizeof(int64_t));
880 if(debug) printf("File::close_file:%d current_sample=" _LD " current_frame=" _LD "\n",
890 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
898 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
900 // The file's asset is a copy of the argument passed to open_file so the
901 // user must copy lengths from the file's asset.
903 asset->audio_length = current_sample;
904 asset->video_length = current_frame;
910 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
912 delete_temp_samples_buffer();
913 delete_temp_frame_buffer();
914 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
916 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
919 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
925 int File::get_index(char *index_path)
929 FileForker this_is(*forked);
930 file_fork->send_command(FileFork::GET_INDEX, (unsigned char*)index_path, strlen(index_path) + 1);
931 int result = file_fork->read_result();
937 return file->get_index(index_path);
944 int File::start_audio_thread(int buffer_size, int ring_buffers)
946 this->audio_ring_buffers = ring_buffers;
951 FileForker this_is(*forked);
952 unsigned char buffer[sizeof(int) * 2];
953 int *ibfr = (int *)buffer;
954 ibfr[0] = buffer_size;
955 ibfr[1] = audio_ring_buffers;
956 file_fork->send_command(FileFork::START_AUDIO_THREAD, buffer, sizeof(buffer));
957 int result = file_fork->read_result();
960 //printf("File::start_audio_thread %d file_fork->result_data=%p\n", __LINE__, file_fork->result_data);
961 // Create server copy of buffer
962 delete_temp_samples_buffer();
963 //printf("File::start_audio_thread %d\n", __LINE__);
964 temp_samples_buffer = new Samples**[audio_ring_buffers];
965 //printf("File::start_audio_thread %d\n", __LINE__);
966 for(int i = 0; i < audio_ring_buffers; i++)
968 //printf("File::start_audio_thread %d\n", __LINE__);
969 temp_samples_buffer[i] = new Samples*[asset->channels];
970 //printf("File::start_audio_thread %d\n", __LINE__);
971 for(int j = 0; j < asset->channels; j++)
973 int offset = i * Samples::filefork_size() * asset->channels +
974 j * Samples::filefork_size();
975 //printf("File::start_audio_thread %d j=%d offset=%d\n", __LINE__, j, offset);
976 temp_samples_buffer[i][j] = new Samples;
977 temp_samples_buffer[i][j]->from_filefork(
978 file_fork->result_data +
980 //printf("File::start_audio_thread %d\n", __LINE__);
991 audio_thread = new FileThread(this, 1, 0);
992 audio_thread->start_writing(buffer_size, 0, ring_buffers, 0);
997 int File::start_video_thread(int buffer_size,
1002 this->video_ring_buffers = ring_buffers;
1003 this->video_buffer_size = buffer_size;
1008 FileForker this_is(*forked);
1009 // This resets variables
1010 delete_temp_frame_buffer();
1012 this->video_ring_buffers = ring_buffers;
1013 this->video_buffer_size = buffer_size;
1015 unsigned char buffer[sizeof(int) * 4];
1016 int *ibfr = (int *)buffer;
1017 ibfr[0] = buffer_size;
1018 ibfr[1] = color_model;
1019 ibfr[2] = video_ring_buffers;
1020 ibfr[3] = compressed;
1021 // Buffers are allocated
1022 file_fork->send_command(FileFork::START_VIDEO_THREAD,
1025 int result = file_fork->read_result();
1028 // Create server copy of buffer
1029 //printf("File::start_video_thread %d %d\n", __LINE__, video_ring_buffers);
1030 temp_frame_buffer = new VFrame***[video_ring_buffers];
1031 for(int i = 0; i < video_ring_buffers; i++)
1033 temp_frame_buffer[i] = new VFrame**[asset->layers];
1034 for(int j = 0; j < asset->layers; j++)
1036 temp_frame_buffer[i][j] = new VFrame*[video_buffer_size];
1037 //printf("File::start_video_thread %d %p\n", __LINE__, temp_frame_buffer[i][j]);
1038 for(int k = 0; k < video_buffer_size; k++)
1040 temp_frame_buffer[i][j][k] = new VFrame;
1041 temp_frame_buffer[i][j][k]->from_filefork(file_fork->result_data +
1042 i * asset->layers * video_buffer_size * VFrame::filefork_size() +
1043 j * video_buffer_size * VFrame::filefork_size() +
1044 k * VFrame::filefork_size());
1058 video_thread = new FileThread(this, 0, 1);
1059 video_thread->start_writing(buffer_size,
1067 int File::start_video_decode_thread()
1072 FileForker this_is(*forked);
1073 file_fork->send_command(FileFork::START_VIDEO_DECODE_THREAD, 0, 0);
1074 file_fork->read_result();
1080 // Currently, CR2 is the only one which won't work asynchronously, so
1081 // we're not using a virtual function yet.
1082 if(!video_thread /* && asset->format != FILE_CR2 */)
1084 video_thread = new FileThread(this, 0, 1);
1085 video_thread->start_reading();
1091 int File::stop_audio_thread()
1096 file_fork->send_command(FileFork::STOP_AUDIO_THREAD, 0, 0);
1097 file_fork->read_result();
1104 audio_thread->stop_writing();
1105 delete audio_thread;
1111 int File::stop_video_thread()
1116 FileForker this_is(*forked);
1117 file_fork->send_command(FileFork::STOP_VIDEO_THREAD, 0, 0);
1118 file_fork->read_result();
1125 video_thread->stop_reading();
1126 video_thread->stop_writing();
1127 delete video_thread;
1133 FileThread* File::get_video_thread()
1135 return video_thread;
1138 int File::set_channel(int channel)
1143 FileForker this_is(*forked);
1144 // Set it locally for get_channel
1145 current_channel = channel;
1146 file_fork->send_command(FileFork::SET_CHANNEL, (unsigned char*)&channel, sizeof(channel));
1147 int result = file_fork->read_result();
1152 if(file && channel < asset->channels)
1154 current_channel = channel;
1161 int File::get_channel()
1163 return current_channel;
1166 // if no>=0, sets new program
1167 // returns current program
1168 int File::set_program(int no)
1173 FileForker this_is(*forked);
1174 file_fork->send_command(FileFork::SET_PROGRAM, (unsigned char*)&no, sizeof(no));
1175 int result = file_fork->read_result();
1176 current_program = no < 0 ? result : no;
1180 int result = file ? file->set_program(no) : current_program;
1181 current_program = no < 0 ? result : no;
1185 int File::get_cell_time(int no, double &time)
1190 FileForker this_is(*forked);
1191 file_fork->send_command(FileFork::GET_CELL_TIME, (unsigned char*)&no, sizeof(no));
1192 int result = file_fork->read_result();
1193 time = *(double *)file_fork->result_data;
1198 return file ? file->get_cell_time(no, time) : -1;
1201 int File::get_system_time(int64_t &tm)
1206 FileForker this_is(*forked);
1207 file_fork->send_command(FileFork::GET_STT_TIME, 0, 0);
1208 int result = file_fork->read_result();
1209 tm = *(int64_t *)file_fork->result_data;
1214 return file ? file->get_system_time(tm) : -1;
1217 int File::get_audio_for_video(int vstream, int astream, int64_t &channel_mask)
1222 FileForker this_is(*forked);
1223 unsigned char buffer[2*sizeof(int)];
1225 *(int*)(buffer + offset) = vstream;
1226 offset += sizeof(int);
1227 *(int*)(buffer + offset) = astream;
1228 file_fork->send_command(FileFork::GET_AUDIO4VIDEO, buffer, sizeof(buffer));
1229 int result = file_fork->read_result();
1230 channel_mask = *(int64_t *)file_fork->result_data;
1235 return file ? file->get_audio_for_video(vstream, astream, channel_mask) : -1;
1238 int File::get_video_pid(int track)
1243 FileForker this_is(*forked);
1244 file_fork->send_command(FileFork::GET_VIDEO_PID,
1245 (unsigned char*)&track, sizeof(track));
1246 int result = file_fork->read_result();
1251 return file ? file->get_video_pid(track) : -1;
1256 int File::get_video_info(int track, int &pid, double &framerate,
1257 int &width, int &height, char *title)
1262 FileForker this_is(*forked);
1263 file_fork->send_command(FileFork::GET_VIDEO_INFO,
1264 (unsigned char*)&track, sizeof(track));
1265 int result = file_fork->read_result();
1267 unsigned char *bp = file_fork->result_data;
1268 framerate = *(double*)bp; bp += sizeof(framerate);
1269 pid = *(int *) bp; bp += sizeof(pid);
1270 width = *(int *) bp; bp += sizeof(width);
1271 height = *(int *) bp; bp += sizeof(height);
1272 strcpy(title, (char *)bp);
1279 file->get_video_info(track, pid, framerate, width, height, title);
1282 int File::select_video_stream(Asset *asset, int vstream)
1287 FileForker this_is(*forked);
1288 file_fork->send_command(FileFork::SELECT_VIDEO_STREAM,
1289 (unsigned char*)&vstream, sizeof(vstream));
1290 int result = file_fork->read_result();
1292 unsigned char *bp = file_fork->result_data;
1293 asset->frame_rate = *(double*) bp; bp += sizeof(asset->frame_rate);
1294 asset->video_length = *(int64_t *) bp; bp += sizeof(asset->video_length);
1295 asset->width = *(int *) bp; bp += sizeof(asset->width);
1296 asset->height = *(int *) bp; bp += sizeof(asset->height);
1301 file->select_video_stream(asset, vstream);
1304 int File::select_audio_stream(Asset *asset, int astream)
1309 FileForker this_is(*forked);
1310 file_fork->send_command(FileFork::SELECT_AUDIO_STREAM,
1311 (unsigned char*)&astream, sizeof(astream));
1312 int result = file_fork->read_result();
1314 unsigned char *bp = file_fork->result_data;
1315 asset->audio_length = *(int64_t *) bp; bp += sizeof(asset->audio_length);
1316 asset->sample_rate = *(int *) bp; bp += sizeof(asset->sample_rate);
1321 file->select_audio_stream(asset, astream);
1325 int File::get_thumbnail(int stream,
1326 int64_t &position, unsigned char *&thumbnail, int &ww, int &hh)
1328 return file->get_thumbnail(stream, position, thumbnail, ww, hh);
1331 int File::set_skimming(int track, int skim, skim_fn fn, void *vp)
1333 return file->set_skimming(track, skim, fn, vp);
1336 int File::skim_video(int track, void *vp, skim_fn fn)
1338 return file->skim_video(track, vp, fn);
1342 int File::set_layer(int layer, int is_thread)
1345 // thread should only call in the fork
1346 if(file_fork && !is_fork && !is_thread)
1348 FileForker this_is(*forked);
1349 file_fork->send_command(FileFork::SET_LAYER, (unsigned char*)&layer, sizeof(layer));
1350 int result = file_fork->read_result();
1351 current_layer = layer;
1356 if(file && layer < asset->layers)
1358 if(!is_thread && video_thread)
1360 video_thread->set_layer(layer);
1364 current_layer = layer;
1372 int64_t File::get_audio_length()
1377 FileForker this_is(*forked);
1378 file_fork->send_command(FileFork::GET_AUDIO_LENGTH, 0, 0);
1379 int64_t result = file_fork->read_result();
1384 int64_t result = asset->audio_length;
1385 int64_t base_samplerate = -1;
1388 if(base_samplerate > 0)
1389 return (int64_t)((double)result / asset->sample_rate * base_samplerate + 0.5);
1397 int64_t File::get_video_length()
1402 FileForker this_is(*forked);
1403 file_fork->send_command(FileFork::GET_VIDEO_LENGTH, 0, 0);
1404 int64_t result = file_fork->read_result();
1410 int64_t result = asset->video_length;
1411 float base_framerate = -1;
1414 if(base_framerate > 0)
1415 return (int64_t)((double)result / asset->frame_rate * base_framerate + 0.5);
1420 return -1; // infinity
1424 int64_t File::get_video_position()
1429 FileForker this_is(*forked);
1430 file_fork->send_command(FileFork::GET_VIDEO_POSITION, 0, 0);
1431 int64_t result = file_fork->read_result();
1436 float base_framerate = -1;
1437 if(base_framerate > 0)
1438 return (int64_t)((double)current_frame / asset->frame_rate * base_framerate + 0.5);
1440 return current_frame;
1443 int64_t File::get_audio_position()
1448 FileForker this_is(*forked);
1449 file_fork->send_command(FileFork::GET_AUDIO_POSITION, 0, 0);
1450 int64_t result = file_fork->read_result();
1456 // int64_t base_samplerate = -1;
1457 // if(base_samplerate > 0)
1459 // if(normalized_sample_rate == base_samplerate)
1460 // return normalized_sample;
1462 // return (int64_t)((double)current_sample /
1463 // asset->sample_rate *
1464 // base_samplerate +
1468 return current_sample;
1473 int File::set_audio_position(int64_t position)
1478 FileForker this_is(*forked);
1479 file_fork->send_command(FileFork::SET_AUDIO_POSITION,
1480 (unsigned char*)&position,
1482 int result = file_fork->read_result();
1491 #define REPOSITION(x, y) \
1492 (labs((x) - (y)) > 1)
1494 float base_samplerate = asset->sample_rate;
1495 current_sample = normalized_sample = position;
1497 // printf("File::set_audio_position %d normalized_sample=%ld\n",
1499 // normalized_sample);
1500 result = file->set_audio_position(current_sample);
1503 printf("File::set_audio_position position=" _LD
1504 " base_samplerate=%f asset=%p asset->sample_rate=%d\n",
1505 position, base_samplerate, asset, asset->sample_rate);
1508 //printf("File::set_audio_position %d %d %d\n", current_channel, current_sample, position);
1513 int File::set_video_position(int64_t position,
1517 // Thread should only call in the fork
1518 if(file_fork && !is_fork && !is_thread)
1520 FileForker this_is(*forked);
1521 //printf("File::set_video_position %d %lld\n", __LINE__, position);
1522 file_fork->send_command(FileFork::SET_VIDEO_POSITION, (unsigned char*)&position, sizeof(position));
1523 int result = file_fork->read_result();
1531 // Convert to file's rate
1532 // if(base_framerate > 0)
1533 // position = (int64_t)((double)position /
1535 // asset->frame_rate +
1539 if(video_thread && !is_thread)
1541 // Call thread. Thread calls this again to set the file state.
1542 video_thread->set_video_position(position);
1545 if(current_frame != position)
1549 current_frame = position;
1550 result = file->set_video_position(current_frame);
1557 // No resampling here.
1558 int File::write_samples(Samples **buffer, int64_t len)
1563 FileForker this_is(*forked);
1564 int entry_size = Samples::filefork_size();
1565 int buffer_size = entry_size * asset->channels + sizeof(int64_t);
1566 unsigned char fork_buffer[buffer_size];
1567 for(int i = 0; i < asset->channels; i++)
1569 buffer[i]->to_filefork(fork_buffer + entry_size * i);
1572 *(int64_t*)(fork_buffer +
1573 entry_size * asset->channels) = len;
1575 file_fork->send_command(FileFork::WRITE_SAMPLES,
1578 int result = file_fork->read_result();
1590 write_lock->lock("File::write_samples");
1592 // Convert to arrays for backwards compatability
1593 double *temp[asset->channels];
1594 for(int i = 0; i < asset->channels; i++)
1596 temp[i] = buffer[i]->get_data();
1599 result = file->write_samples(temp, len);
1600 current_sample += len;
1601 normalized_sample += len;
1602 asset->audio_length += len;
1603 write_lock->unlock();
1612 // Can't put any cmodel abstraction here because the filebase couldn't be
1614 int File::write_frames(VFrame ***frames, int len)
1616 //printf("File::write_frames %d\n", __LINE__);
1620 FileForker this_is(*forked);
1621 //printf("File::write_frames %d\n", __LINE__);
1622 int entry_size = frames[0][0]->filefork_size();
1623 unsigned char fork_buffer[entry_size * asset->layers * len + sizeof(int)];
1624 for(int i = 0; i < asset->layers; i++)
1626 for(int j = 0; j < len; j++)
1628 // printf("File::write_frames %d " _LD " %d\n",
1630 // frames[i][j]->get_number(),
1631 // frames[i][j]->get_keyframe());
1632 frames[i][j]->to_filefork(fork_buffer +
1634 entry_size * len * i +
1642 int *fbfr = (int *)fork_buffer;
1646 file_fork->send_command(FileFork::WRITE_FRAMES,
1648 sizeof(fork_buffer));
1650 int result = file_fork->read_result();
1653 //printf("File::write_frames %d\n", __LINE__);
1658 #endif // USE_FILEFORK
1662 // Store the counters in temps so the filebase can choose to overwrite them.
1664 int current_frame_temp = current_frame;
1665 int video_length_temp = asset->video_length;
1667 write_lock->lock("File::write_frames");
1670 result = file->write_frames(frames, len);
1673 current_frame = current_frame_temp + len;
1674 asset->video_length = video_length_temp + len;
1675 write_lock->unlock();
1680 // Only called by FileThread
1681 int File::write_compressed_frame(VFrame *buffer)
1684 write_lock->lock("File::write_compressed_frame");
1685 result = file->write_compressed_frame(buffer);
1687 asset->video_length++;
1688 write_lock->unlock();
1693 int File::write_audio_buffer(int64_t len)
1698 FileForker this_is(*forked);
1699 file_fork->send_command(FileFork::WRITE_AUDIO_BUFFER, (unsigned char*)&len, sizeof(len));
1700 int result = file_fork->read_result();
1708 result = audio_thread->write_buffer(len);
1713 int File::write_video_buffer(int64_t len)
1718 FileForker this_is(*forked);
1719 // Copy over sequence numbers for background rendering
1720 // frame sizes for direct copy
1721 //printf("File::write_video_buffer %d\n", __LINE__);
1722 int fork_buffer_size = sizeof(int64_t) +
1723 VFrame::filefork_size() * asset->layers * len;
1724 unsigned char fork_buffer[fork_buffer_size];
1725 int64_t *fbfr = (int64_t *)fork_buffer;
1728 for(int i = 0; i < asset->layers; i++)
1730 for(int j = 0; j < len; j++)
1732 // Send memory state
1733 current_frame_buffer[i][j]->to_filefork(fork_buffer +
1735 VFrame::filefork_size() * (len * i + j));
1736 // printf("File::write_video_buffer %d size=%d %d %02x %02x %02x %02x %02x %02x %02x %02x\n",
1738 // current_frame_buffer[i][j]->get_shmid(),
1739 // current_frame_buffer[i][j]->get_compressed_size(),
1740 // current_frame_buffer[i][j]->get_data()[0],
1741 // current_frame_buffer[i][j]->get_data()[1],
1742 // current_frame_buffer[i][j]->get_data()[2],
1743 // current_frame_buffer[i][j]->get_data()[3],
1744 // current_frame_buffer[i][j]->get_data()[4],
1745 // current_frame_buffer[i][j]->get_data()[5],
1746 // current_frame_buffer[i][j]->get_data()[6],
1747 // current_frame_buffer[i][j]->get_data()[7]);
1751 //printf("File::write_video_buffer %d\n", __LINE__);
1752 file_fork->send_command(FileFork::WRITE_VIDEO_BUFFER,
1755 //printf("File::write_video_buffer %d\n", __LINE__);
1756 int result = file_fork->read_result();
1757 //printf("File::write_video_buffer %d\n", __LINE__);
1765 result = video_thread->write_buffer(len);
1771 Samples** File::get_audio_buffer()
1776 FileForker this_is(*forked);
1777 file_fork->send_command(FileFork::GET_AUDIO_BUFFER, 0, 0);
1778 int result = file_fork->read_result();
1780 // Read parameters for a Samples buffer & create it in File
1781 // delete_temp_samples_buffer();
1782 // if(!temp_samples_buffer)
1784 // temp_samples_buffer = new Samples**[ring_buffers];
1785 // for(int i = 0; i < ring_buffers; i++) temp_samples_buffer[i] = 0;
1789 // temp_samples_buffer = new Samples*[asset->channels];
1790 // for(int i = 0; i < asset->channels; i++)
1792 // temp_samples_buffer[i] = new Samples;
1793 // temp_samples_buffer[i]->from_filefork(file_fork->result_data +
1794 // i * Samples::filefork_size());
1797 return temp_samples_buffer[result];
1801 if(audio_thread) return audio_thread->get_audio_buffer();
1805 VFrame*** File::get_video_buffer()
1810 FileForker this_is(*forked);
1812 file_fork->send_command(FileFork::GET_VIDEO_BUFFER, 0, 0);
1813 int result = file_fork->read_result();
1815 // Read parameters for a VFrame buffer & create it in File
1816 // delete_temp_frame_buffer();
1819 // temp_frame_size = *(int*)(file_fork->result_data +
1820 // file_fork->result_bytes -
1823 // //printf("File::get_video_buffer %d %p %d\n", __LINE__, this, asset->layers);
1824 // temp_frame_buffer = new VFrame**[asset->layers];
1826 // for(int i = 0; i < asset->layers; i++)
1829 // temp_frame_buffer[i] = new VFrame*[temp_frame_size];
1831 // for(int j = 0; j < temp_frame_size; j++)
1834 // temp_frame_buffer[i][j] = new VFrame;
1835 // printf("File::get_video_buffer %d %p\n", __LINE__, temp_frame_buffer[i][j]);
1837 // temp_frame_buffer[i][j]->from_filefork(file_fork->result_data +
1838 // i * temp_frame_size * VFrame::filefork_size() +
1839 // j * VFrame::filefork_size());
1845 current_frame_buffer = temp_frame_buffer[result];
1847 return current_frame_buffer;
1853 VFrame*** result = video_thread->get_video_buffer();
1862 int File::read_samples(Samples *samples, int64_t len)
1864 // Never try to read more samples than exist in the file
1865 if (current_sample + len > asset->audio_length) {
1866 len = asset->audio_length - current_sample;
1868 if(len <= 0) return 0;
1871 const int debug = 0;
1872 if(debug) PRINT_TRACE
1877 FileForker this_is(*forked);
1878 int buffer_bytes = Samples::filefork_size() + sizeof(int64_t);
1879 unsigned char buffer[buffer_bytes];
1880 samples->to_filefork(buffer);
1881 *(int64_t*)(buffer + Samples::filefork_size()) = len;
1882 if(debug) PRINT_TRACE
1883 file_fork->send_command(FileFork::READ_SAMPLES,
1886 if(debug) PRINT_TRACE
1887 int result = file_fork->read_result();
1890 if(result && !file_fork->child_running())
1893 result = open_file(preferences, asset, rd, wr);
1900 if(debug) PRINT_TRACE
1902 double *buffer = samples->get_data();
1904 int64_t base_samplerate = asset->sample_rate;
1908 // Resample recursively calls this with the asset sample rate
1909 if(base_samplerate == 0) base_samplerate = asset->sample_rate;
1911 if(debug) PRINT_TRACE
1912 result = file->read_samples(buffer, len);
1914 if(debug) PRINT_TRACE
1915 current_sample += len;
1917 normalized_sample += len;
1919 if(debug) PRINT_TRACE
1925 int File::read_frame(VFrame *frame, int is_thread)
1927 const int debug = 0;
1929 if(debug) PRINT_TRACE
1932 // is_thread is only true in the fork
1933 if(file_fork && !is_fork && !is_thread)
1935 FileForker this_is(*forked);
1936 unsigned char fork_buffer[VFrame::filefork_size()];
1937 if(debug) PRINT_TRACE
1939 frame->to_filefork(fork_buffer);
1940 file_fork->send_command(FileFork::READ_FRAME,
1942 VFrame::filefork_size());
1944 int result = file_fork->read_result();
1948 if(result && !file_fork->child_running())
1951 result = open_file(preferences, asset, rd, wr);
1955 frame->get_color_model() == BC_COMPRESSED)
1957 // Get compressed data from socket
1958 //printf("File::read_frame %d %d\n", __LINE__, file_fork->result_bytes);
1959 int header_size = sizeof(int) * 2;
1960 if(file_fork->result_bytes > header_size)
1962 //printf("File::read_frame %d %d\n", __LINE__, file_fork->result_bytes);
1963 frame->allocate_compressed_data(file_fork->result_bytes - header_size);
1964 frame->set_compressed_size(file_fork->result_bytes - header_size);
1965 frame->set_keyframe(*(int*)(file_fork->result_data + sizeof(int)));
1966 memcpy(frame->get_data(),
1967 file_fork->result_data + header_size,
1968 file_fork->result_bytes - header_size);
1971 // Get compressed data size
1973 frame->set_compressed_size(*(int*)file_fork->result_data);
1974 frame->set_keyframe(*(int*)(file_fork->result_data + sizeof(int)));
1975 //printf("File::read_frame %d %d\n", __LINE__, *(int*)(file_fork->result_data + sizeof(int)));
1984 //printf("File::read_frame %d\n", __LINE__);
1986 if(video_thread && !is_thread) return video_thread->read_frame(frame);
1988 //printf("File::read_frame %d\n", __LINE__);
1989 if(debug) PRINT_TRACE
1992 if(debug) PRINT_TRACE
1993 int supported_colormodel = colormodel_supported(frame->get_color_model());
1994 int advance_position = 1;
1997 if(use_cache && !is_fork &&
1998 frame_cache->get_frame(frame,
2003 // Can't advance position if cache used.
2004 //printf("File::read_frame %d\n", __LINE__);
2005 advance_position = 0;
2009 if(frame->get_color_model() != BC_COMPRESSED &&
2010 (supported_colormodel != frame->get_color_model() ||
2011 frame->get_w() != asset->width ||
2012 frame->get_h() != asset->height))
2015 // printf("File::read_frame %d\n", __LINE__);
2016 // Can't advance position here because it needs to be added to cache
2019 if(!temp_frame->params_match(asset->width, asset->height, supported_colormodel))
2026 // printf("File::read_frame %d\n", __LINE__);
2029 temp_frame = new VFrame(0,
2033 supported_colormodel,
2037 // printf("File::read_frame %d\n", __LINE__);
2038 temp_frame->copy_stacks(frame);
2039 file->read_frame(temp_frame);
2040 //for(int i = 0; i < 1000 * 1000; i++) ((float*)temp_frame->get_rows()[0])[i] = 1.0;
2041 // printf("File::read_frame %d %d %d %d %d %d\n",
2042 // temp_frame->get_color_model(),
2043 // temp_frame->get_w(),
2044 // temp_frame->get_h(),
2045 // frame->get_color_model(),
2048 BC_CModels::transfer(frame->get_rows(),
2049 temp_frame->get_rows(),
2053 temp_frame->get_y(),
2054 temp_frame->get_u(),
2055 temp_frame->get_v(),
2058 temp_frame->get_w(),
2059 temp_frame->get_h(),
2064 temp_frame->get_color_model(),
2065 frame->get_color_model(),
2067 temp_frame->get_w(),
2069 // printf("File::read_frame %d\n", __LINE__);
2073 // Can't advance position here because it needs to be added to cache
2074 //printf("File::read_frame %d\n", __LINE__);
2075 file->read_frame(frame);
2076 //for(int i = 0; i < 100 * 1000; i++) ((float*)frame->get_rows()[0])[i] = 1.0;
2079 //printf("File::read_frame %d use_cache=%d\n", __LINE__, use_cache);
2080 if(use_cache && !is_fork)
2081 frame_cache->put_frame(frame,
2082 current_frame, current_layer,
2083 asset->frame_rate, 1, 0);
2084 //printf("File::read_frame %d\n", __LINE__);
2086 if(advance_position) current_frame++;
2087 if(debug) PRINT_TRACE
2094 int File::can_copy_from(Asset *asset,
2099 if(!asset) return 0;
2104 FileForker this_is(*forked);
2106 asset->write(&xml, 1, "");
2107 xml.terminate_string();
2108 const char *xml_string = xml.string();
2109 long xml_length = strlen(xml_string);
2110 int buffer_size = xml_length + 1 +
2114 unsigned char *buffer = new unsigned char[buffer_size];
2115 *(int64_t*)(buffer) = position;
2116 *(int*)(buffer + sizeof(int64_t)) = output_w;
2117 *(int*)(buffer + sizeof(int64_t) + sizeof(int)) = output_h;
2125 file_fork->send_command(FileFork::CAN_COPY_FROM,
2128 int result = file_fork->read_result();
2136 return asset->width == output_w &&
2137 asset->height == output_h &&
2138 file->can_copy_from(asset, position);
2144 // Fill in queries about formats when adding formats here.
2147 int File::strtoformat(const char *format)
2149 return strtoformat(0, format);
2152 int File::strtoformat(ArrayList<PluginServer*> *plugindb, const char *format)
2154 if(!strcasecmp(format, _(AC3_NAME))) return FILE_AC3;
2155 if(!strcasecmp(format, _(SCENE_NAME))) return FILE_SCENE;
2156 if(!strcasecmp(format, _(WAV_NAME))) return FILE_WAV;
2157 if(!strcasecmp(format, _(PCM_NAME))) return FILE_PCM;
2158 if(!strcasecmp(format, _(AU_NAME))) return FILE_AU;
2159 if(!strcasecmp(format, _(AIFF_NAME))) return FILE_AIFF;
2160 if(!strcasecmp(format, _(SND_NAME))) return FILE_SND;
2161 if(!strcasecmp(format, _(PNG_NAME))) return FILE_PNG;
2162 if(!strcasecmp(format, _(PNG_LIST_NAME))) return FILE_PNG_LIST;
2163 if(!strcasecmp(format, _(TIFF_NAME))) return FILE_TIFF;
2164 if(!strcasecmp(format, _(TIFF_LIST_NAME))) return FILE_TIFF_LIST;
2165 if(!strcasecmp(format, _(JPEG_NAME))) return FILE_JPEG;
2166 if(!strcasecmp(format, _(JPEG_LIST_NAME))) return FILE_JPEG_LIST;
2167 if(!strcasecmp(format, _(EXR_NAME))) return FILE_EXR;
2168 if(!strcasecmp(format, _(EXR_LIST_NAME))) return FILE_EXR_LIST;
2169 if(!strcasecmp(format, _(FLAC_NAME))) return FILE_FLAC;
2170 if(!strcasecmp(format, _(CR2_NAME))) return FILE_CR2;
2171 if(!strcasecmp(format, _(CR2_LIST_NAME))) return FILE_CR2_LIST;
2172 if(!strcasecmp(format, _(MPEG_NAME))) return FILE_MPEG;
2173 if(!strcasecmp(format, _(AMPEG_NAME))) return FILE_AMPEG;
2174 if(!strcasecmp(format, _(VMPEG_NAME))) return FILE_VMPEG;
2175 if(!strcasecmp(format, _(TGA_NAME))) return FILE_TGA;
2176 if(!strcasecmp(format, _(TGA_LIST_NAME))) return FILE_TGA_LIST;
2177 if(!strcasecmp(format, _(MOV_NAME))) return FILE_MOV;
2178 if(!strcasecmp(format, _(AVI_NAME))) return FILE_AVI;
2179 if(!strcasecmp(format, _(AVI_LAVTOOLS_NAME))) return FILE_AVI_LAVTOOLS;
2180 if(!strcasecmp(format, _(AVI_ARNE2_NAME))) return FILE_AVI_ARNE2;
2181 if(!strcasecmp(format, _(AVI_ARNE1_NAME))) return FILE_AVI_ARNE1;
2182 if(!strcasecmp(format, _(AVI_AVIFILE_NAME))) return FILE_AVI_AVIFILE;
2183 if(!strcasecmp(format, _(OGG_NAME))) return FILE_OGG;
2184 if(!strcasecmp(format, _(VORBIS_NAME))) return FILE_VORBIS;
2185 if(!strcasecmp(format, _(RAWDV_NAME))) return FILE_RAWDV;
2186 if(!strcasecmp(format, _(FFMPEG_NAME))) return FILE_FFMPEG;
2187 if(!strcasecmp(format, _(DBASE_NAME))) return FILE_DB;
2193 const char* File::formattostr(int format)
2195 return formattostr(0, format);
2198 const char* File::formattostr(ArrayList<PluginServer*> *plugindb, int format)
2202 case FILE_SCENE: return _(SCENE_NAME);
2203 case FILE_AC3: return _(AC3_NAME);
2204 case FILE_WAV: return _(WAV_NAME);
2205 case FILE_PCM: return _(PCM_NAME);
2206 case FILE_AU: return _(AU_NAME);
2207 case FILE_AIFF: return _(AIFF_NAME);
2208 case FILE_SND: return _(SND_NAME);
2209 case FILE_PNG: return _(PNG_NAME);
2210 case FILE_PNG_LIST: return _(PNG_LIST_NAME);
2211 case FILE_JPEG: return _(JPEG_NAME);
2212 case FILE_JPEG_LIST: return _(JPEG_LIST_NAME);
2213 case FILE_CR2: return _(CR2_NAME);
2214 case FILE_CR2_LIST: return _(CR2_LIST_NAME);
2215 case FILE_FLAC: return _(FLAC_NAME);
2216 case FILE_EXR: return _(EXR_NAME);
2217 case FILE_EXR_LIST: return _(EXR_LIST_NAME);
2218 case FILE_MPEG: return _(MPEG_NAME);
2219 case FILE_AMPEG: return _(AMPEG_NAME);
2220 case FILE_VMPEG: return _(VMPEG_NAME);
2221 case FILE_TGA: return _(TGA_NAME);
2222 case FILE_TGA_LIST: return _(TGA_LIST_NAME);
2223 case FILE_TIFF: return _(TIFF_NAME);
2224 case FILE_TIFF_LIST: return _(TIFF_LIST_NAME);
2225 case FILE_MOV: return _(MOV_NAME);
2226 case FILE_AVI_LAVTOOLS: return _(AVI_LAVTOOLS_NAME);
2227 case FILE_AVI: return _(AVI_NAME);
2228 case FILE_AVI_ARNE2: return _(AVI_ARNE2_NAME);
2229 case FILE_AVI_ARNE1: return _(AVI_ARNE1_NAME);
2230 case FILE_AVI_AVIFILE: return _(AVI_AVIFILE_NAME);
2231 case FILE_OGG: return _(OGG_NAME);
2232 case FILE_VORBIS: return _(VORBIS_NAME);
2233 case FILE_RAWDV: return _(RAWDV_NAME);
2234 case FILE_FFMPEG: return _(FFMPEG_NAME);
2235 case FILE_DB: return _(DBASE_NAME);
2240 int File::strtobits(const char *bits)
2242 if(!strcasecmp(bits, _(NAME_8BIT))) return BITSLINEAR8;
2243 if(!strcasecmp(bits, _(NAME_16BIT))) return BITSLINEAR16;
2244 if(!strcasecmp(bits, _(NAME_24BIT))) return BITSLINEAR24;
2245 if(!strcasecmp(bits, _(NAME_32BIT))) return BITSLINEAR32;
2246 if(!strcasecmp(bits, _(NAME_ULAW))) return BITSULAW;
2247 if(!strcasecmp(bits, _(NAME_ADPCM))) return BITS_ADPCM;
2248 if(!strcasecmp(bits, _(NAME_FLOAT))) return BITSFLOAT;
2249 if(!strcasecmp(bits, _(NAME_IMA4))) return BITSIMA4;
2250 return BITSLINEAR16;
2253 const char* File::bitstostr(int bits)
2255 //printf("File::bitstostr\n");
2258 case BITSLINEAR8: return (NAME_8BIT);
2259 case BITSLINEAR16: return (NAME_16BIT);
2260 case BITSLINEAR24: return (NAME_24BIT);
2261 case BITSLINEAR32: return (NAME_32BIT);
2262 case BITSULAW: return (NAME_ULAW);
2263 case BITS_ADPCM: return (NAME_ADPCM);
2264 case BITSFLOAT: return (NAME_FLOAT);
2265 case BITSIMA4: return (NAME_IMA4);
2272 int File::str_to_byteorder(const char *string)
2274 if(!strcasecmp(string, _("Lo Hi"))) return 1;
2278 const char* File::byteorder_to_str(int byte_order)
2280 if(byte_order) return _("Lo Hi");
2284 int File::bytes_per_sample(int bits)
2288 case BITSLINEAR8: return 1;
2289 case BITSLINEAR16: return 2;
2290 case BITSLINEAR24: return 3;
2291 case BITSLINEAR32: return 4;
2292 case BITSULAW: return 1;
2293 case BITSIMA4: return 1;
2302 int File::get_best_colormodel(int driver)
2304 return get_best_colormodel(asset, driver);
2307 int File::get_best_colormodel(Asset *asset, int driver)
2309 switch(asset->format)
2311 case FILE_RAWDV: return FileDV::get_best_colormodel(asset, driver);
2312 case FILE_MOV: return FileMOV::get_best_colormodel(asset, driver);
2313 case FILE_AVI: return FileMOV::get_best_colormodel(asset, driver);
2314 case FILE_MPEG: return FileMPEG::get_best_colormodel(asset, driver);
2316 case FILE_JPEG_LIST: return FileJPEG::get_best_colormodel(asset, driver);
2318 case FILE_EXR_LIST: return FileEXR::get_best_colormodel(asset, driver);
2320 case FILE_PNG_LIST: return FilePNG::get_best_colormodel(asset, driver);
2322 case FILE_TGA_LIST: return FileTGA::get_best_colormodel(asset, driver);
2324 case FILE_CR2_LIST: return FileCR2::get_best_colormodel(asset, driver);
2325 case FILE_DB: return FileDB::get_best_colormodel(asset, driver);
2332 int File::colormodel_supported(int colormodel)
2337 FileForker this_is(*forked);
2338 unsigned char buffer[sizeof(int)];
2339 int *ibfr = (int *)buffer;
2340 ibfr[0] = colormodel;
2342 file_fork->send_command(FileFork::COLORMODEL_SUPPORTED,
2345 int result = file_fork->read_result();
2352 return file->colormodel_supported(colormodel);
2358 int64_t File::file_memory_usage()
2360 return file ? file->base_memory_usage() : 0;
2363 int64_t File::get_memory_usage()
2370 FileForker this_is(*forked);
2371 file_fork->send_command(FileFork::FILE_MEMORY_USAGE, 0, 0);
2372 result = file_fork->read_result();
2376 result += file_memory_usage();
2377 if(temp_frame) result += temp_frame->get_data_size();
2378 result += frame_cache->get_memory_usage();
2379 if(video_thread) result += video_thread->get_memory_usage();
2381 if(result < MIN_CACHEITEM_SIZE) result = MIN_CACHEITEM_SIZE;
2386 int File::supports_video(ArrayList<PluginServer*> *plugindb, char *format)
2388 int format_i = strtoformat(plugindb, format);
2390 return supports_video(format_i);
2394 int File::supports_audio(ArrayList<PluginServer*> *plugindb, char *format)
2396 int format_i = strtoformat(plugindb, format);
2398 return supports_audio(format_i);
2403 int File::supports_video(int format)
2405 //printf("File::supports_video %d\n", format);
2411 case FILE_JPEG_LIST:
2421 case FILE_TIFF_LIST:
2423 case FILE_AVI_LAVTOOLS:
2424 case FILE_AVI_ARNE2:
2426 case FILE_AVI_ARNE1:
2427 case FILE_AVI_AVIFILE:
2435 int File::supports_audio(int format)
2451 case FILE_AVI_LAVTOOLS:
2452 case FILE_AVI_ARNE2:
2453 case FILE_AVI_ARNE1:
2454 case FILE_AVI_AVIFILE:
2461 const char* File::get_tag(int format)
2465 case FILE_AC3: return "ac3";
2466 case FILE_AIFF: return "aif";
2467 case FILE_AMPEG: return "mp3";
2468 case FILE_AU: return "au";
2469 case FILE_AVI: return "avi";
2470 case FILE_RAWDV: return "dv";
2471 case FILE_DB: return "db";
2472 case FILE_EXR: return "exr";
2473 case FILE_EXR_LIST: return "exr";
2474 case FILE_FLAC: return "flac";
2475 case FILE_JPEG: return "jpg";
2476 case FILE_JPEG_LIST: return "jpg";
2477 case FILE_MOV: return "mov/mp4";
2478 case FILE_OGG: return "ogg";
2479 case FILE_PCM: return "pcm";
2480 case FILE_PNG: return "png";
2481 case FILE_PNG_LIST: return "png";
2482 case FILE_TGA: return "tga";
2483 case FILE_TGA_LIST: return "tga";
2484 case FILE_TIFF: return "tif";
2485 case FILE_TIFF_LIST: return "tif";
2486 case FILE_VMPEG: return "m2v";
2487 case FILE_VORBIS: return "ogg";
2488 case FILE_WAV: return "wav";
2489 case FILE_FFMPEG: return "media";
2494 const char* File::get_prefix(int format)
2497 case FILE_PCM: return "PCM";
2498 case FILE_WAV: return "WAV";
2499 case FILE_MOV: return "MOV";
2500 case FILE_PNG: return "PNG";
2501 case FILE_JPEG: return "JPEG";
2502 case FILE_TIFF: return "TIFF";
2503 case FILE_GIF: return "GIF";
2504 case FILE_JPEG_LIST: return "JPEG_LIST";
2505 case FILE_AU: return "AU";
2506 case FILE_AIFF: return "AIFF";
2507 case FILE_SND: return "SND";
2508 case FILE_AVI_LAVTOOLS: return "AVI_LAVTOOLS";
2509 case FILE_TGA_LIST: return "TGA_LIST";
2510 case FILE_TGA: return "TGA";
2511 case FILE_MPEG: return "MPEG";
2512 case FILE_AMPEG: return "AMPEG";
2513 case FILE_VMPEG: return "VMPEG";
2514 case FILE_RAWDV: return "RAWDV";
2515 case FILE_AVI_ARNE2: return "AVI_ARNE2";
2516 case FILE_AVI_ARNE1: return "AVI_ARNE1";
2517 case FILE_AVI_AVIFILE: return "AVI_AVIFILE";
2518 case FILE_TIFF_LIST: return "TIFF_LIST";
2519 case FILE_PNG_LIST: return "PNG_LIST";
2520 case FILE_AVI: return "AVI";
2521 case FILE_AC3: return "AC3";
2522 case FILE_EXR: return "EXR";
2523 case FILE_EXR_LIST: return "EXR_LIST";
2524 case FILE_CR2: return "CR2";
2525 case FILE_OGG: return "OGG";
2526 case FILE_VORBIS: return "VORBIS";
2527 case FILE_FLAC: return "FLAC";
2528 case FILE_FFMPEG: return "FFMPEG";
2529 case FILE_SCENE: return "SCENE";
2530 case FILE_CR2_LIST: return "CR2_LIST";
2531 case FILE_GIF_LIST: return "GIF_LIST";
2532 case FILE_DB: return "DB";
2538 PackagingEngine *File::new_packaging_engine(Asset *asset)
2540 PackagingEngine *result;
2541 switch (asset->format)
2544 result = (PackagingEngine*)new PackagingEngineOGG();
2547 result = (PackagingEngine*) new PackagingEngineDefault();
2555 int File::record_fd()
2557 return file ? file->record_fd() : -1;