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"
81 //suppress noref warning
82 void *vorbis0_ov_callbacks[] = {
83 &OV_CALLBACKS_DEFAULT, &OV_CALLBACKS_NOCLOSE,
84 &OV_CALLBACKS_STREAMONLY, &OV_CALLBACKS_STREAMONLY_NOCLOSE,
91 format_completion = new Condition(1, "File::format_completion");
92 write_lock = new Condition(1, "File::write_lock");
93 frame_cache = new FrameCache;
95 forked = new Mutex("File::forked",0);
104 if(format_window) format_window->set_done(0);
105 format_completion->lock("File::~File");
106 format_completion->unlock();
109 if(temp_frame) delete temp_frame;
114 asset->Garbage::remove_user();
115 delete format_completion;
123 void File::reset_parameters()
141 normalized_sample = 0;
144 playback_subtitle = -1;
148 temp_samples_buffer = 0;
149 temp_frame_buffer = 0;
150 current_frame_buffer = 0;
151 audio_ring_buffers = 0;
152 video_ring_buffers = 0;
153 video_buffer_size = 0;
156 int File::raise_window()
158 if(getting_options && format_window)
160 format_window->raise_window();
161 format_window->flush();
166 void File::close_window()
170 format_window->lock_window("File::close_window");
171 format_window->set_done(1);
172 format_window->unlock_window();
177 int File::get_options(FormatTools *format,
178 int audio_options, int video_options)
180 BC_WindowBase *parent_window = format->window;
181 //ArrayList<PluginServer*> *plugindb = format->plugindb;
182 Asset *asset = format->asset;
183 const char *locked_compressor = format->locked_compressor;
186 format_completion->lock("File::get_options");
187 switch(asset->format)
190 FileAC3::get_parameters(parent_window,
197 FileDV::get_parameters(parent_window,
208 FileSndFile::get_parameters(parent_window,
215 FileMOV::get_parameters(parent_window,
223 FileFFMPEG::get_parameters(parent_window,
231 FileMPEG::get_parameters(parent_window,
238 FileMOV::get_parameters(parent_window,
245 case FILE_AVI_LAVTOOLS:
248 case FILE_AVI_AVIFILE:
249 FileAVI::get_parameters(parent_window,
258 FileJPEG::get_parameters(parent_window,
266 FileEXR::get_parameters(parent_window,
273 FileFLAC::get_parameters(parent_window,
281 FilePNG::get_parameters(parent_window,
289 FileTGA::get_parameters(parent_window,
297 FileTIFF::get_parameters(parent_window,
304 FileOGG::get_parameters(parent_window,
316 ErrorBox *errorbox = new ErrorBox(PROGRAM_NAME ": Error",
317 parent_window->get_abs_cursor_x(1),
318 parent_window->get_abs_cursor_y(1));
319 format_window = errorbox;
322 errorbox->create_objects(_("This format doesn't support audio."));
325 errorbox->create_objects(_("This format doesn't support video."));
326 errorbox->run_window();
332 format_completion->unlock();
345 int File::set_processors(int cpus) // Set the number of cpus for certain codecs
347 if( cpus > 8 ) // mpegvideo max_threads = 16, more causes errs
348 cpus = 8; // 8 cpus ought to decode just about anything
352 FileForker this_is(*forked);
353 file_fork->send_command(FileFork::SET_PROCESSORS, (unsigned char*)&cpus, sizeof(cpus));
354 file_fork->read_result();
358 // Set all instances so gets work.
364 int File::set_preload(int64_t size)
369 FileForker this_is(*forked);
370 file_fork->send_command(FileFork::SET_PRELOAD, (unsigned char*)&size, sizeof(size));
371 file_fork->read_result();
376 this->playback_preload = size;
380 void File::set_subtitle(int value)
385 FileForker this_is(*forked);
386 file_fork->send_command(FileFork::SET_SUBTITLE, (unsigned char*)&value, sizeof(value));
387 file_fork->read_result();
391 this->playback_subtitle = value;
392 if( file ) file->set_subtitle(value);
395 void File::set_interpolate_raw(int value)
400 FileForker this_is(*forked);
401 file_fork->send_command(FileFork::SET_INTERPOLATE_RAW, (unsigned char*)&value, sizeof(value));
402 file_fork->read_result();
407 this->interpolate_raw = value;
410 void File::set_white_balance_raw(int value)
415 FileForker this_is(*forked);
416 file_fork->send_command(FileFork::SET_WHITE_BALANCE_RAW, (unsigned char*)&value, sizeof(value));
417 file_fork->read_result();
421 this->white_balance_raw = value;
425 void File::set_cache_frames(int value)
427 // caching only done locally
432 int File::purge_cache()
434 // caching only done locally
436 if( frame_cache->cache_items() > 0 )
438 frame_cache->remove_all();
444 int File::delete_oldest()
446 // caching only done locally
447 return frame_cache->delete_oldest();
460 int File::open_file(Preferences *preferences,
468 this->preferences = preferences;
469 this->asset->copy_from(asset, 1);
474 if(debug) printf("File::open_file %d\n", __LINE__);
477 if( !is_fork && MWindow::file_server && (rd || wr) ) {
478 FileForker this_is(*forked);
479 // printf("File::open_file %d file_server=%p rd=%d wr=%d %d\n",
481 // MWindow::file_server,
484 // asset->ms_quantization);
485 file_fork = MWindow::file_server->new_filefork();
486 //printf("File::open_file %d\n", __LINE__);
489 // Convert to hash table
491 asset->save_defaults(&table, "", 1, 1, 1, 1, 1);
494 table.save_string(string);
495 int buffer_size = sizeof(int) * 7 + strlen(string) + 1;
496 unsigned char *buffer = new unsigned char[buffer_size];
498 *(int*)(buffer + offset) = rd;
499 offset += sizeof(int);
500 *(int*)(buffer + offset) = wr;
501 offset += sizeof(int);
502 *(int*)(buffer + offset) = cpus;
503 offset += sizeof(int);
504 *(int*)(buffer + offset) = white_balance_raw;
505 offset += sizeof(int);
506 *(int*)(buffer + offset) = interpolate_raw;
507 offset += sizeof(int);
508 *(int*)(buffer + offset) = playback_subtitle;
509 offset += sizeof(int);
510 *(int*)(buffer + offset) = current_program;
511 offset += sizeof(int);
512 memcpy(buffer + offset, string, strlen(string) + 1);
513 //printf("File::open_file %d\n", __LINE__);
514 file_fork->send_command(FileFork::OPEN_FILE,
519 //printf("File::open_file %d\n", __LINE__);
521 // Get the updated asset from the fork
522 result = file_fork->read_result();
523 //printf("File::open_file %d\n", __LINE__);
526 table.load_string((char*)file_fork->result_data);
528 asset->load_defaults(&table, "", 1, 1, 1, 1, 1);
529 this->asset->load_defaults(&table, "", 1, 1, 1, 1, 1);
530 //this->asset->dump();
532 //printf("File::open_file %d\n", __LINE__);
535 // If it's a scene renderer, close it & reopen it locally to get the
536 // full OpenGL support.
537 // Just doing 2D for now. Should be forked in case Festival crashes.
538 // if(rd && this->asset->format == FILE_SCENE)
540 // //printf("File::open_file %p %d\n", this, __LINE__);
542 // // Lie to get it to work properly
553 if(debug) printf("File::open_file %p %d\n", this, __LINE__);
555 switch(this->asset->format)
557 // get the format now
558 // If you add another format to case 0, you also need to add another case for the
559 // file format #define.
561 if(FileDB::check_sig(this->asset)) {
563 file = new FileDB(this->asset, this);
566 // if early probe enabled
567 if( preferences->ffmpeg_early_probe &&
568 FileFFMPEG::check_sig(this->asset)) {
569 file = new FileFFMPEG(this->asset, this);
574 if(!(stream = fopen(this->asset->path, "rb"))) {
580 result = fread(test, 16, 1, stream);
582 if(FileScene::check_sig(this->asset, test)) {
585 file = new FileScene(this->asset, this);
588 if(FileDV::check_sig(this->asset)) {
591 file = new FileDV(this->asset, this);
594 if(FileSndFile::check_sig(this->asset)) {
597 file = new FileSndFile(this->asset, this);
600 if(FilePNG::check_sig(this->asset)) {
603 file = new FilePNG(this->asset, this);
606 if(FileJPEG::check_sig(this->asset)) {
609 file = new FileJPEG(this->asset, this);
612 if(FileGIF::check_sig(this->asset)) {
615 file = new FileGIF(this->asset, this);
618 if(FileEXR::check_sig(this->asset, test)) {
621 file = new FileEXR(this->asset, this);
624 if(FileFLAC::check_sig(this->asset, test)) {
627 file = new FileFLAC(this->asset, this);
630 if(FileCR2::check_sig(this->asset)) {
633 file = new FileCR2(this->asset, this);
636 if(FileTGA::check_sig(this->asset)) {
639 file = new FileTGA(this->asset, this);
642 if(FileTIFF::check_sig(this->asset)) {
645 file = new FileTIFF(this->asset, this);
648 if(FileOGG::check_sig(this->asset)) {
651 file = new FileOGG(this->asset, this);
654 if(FileVorbis::check_sig(this->asset)) {
657 file = new FileVorbis(this->asset, this);
660 if(FileMPEG::check_sig(this->asset)) {
663 file = new FileMPEG(this->asset, this);
666 if( test[0] == '<' && (
667 !strncmp(&test[1],"EDL>",4) ||
668 !strncmp(&test[1],"HTAL>",5) ||
669 !strncmp(&test[1],"?xml",4) ) ) {
673 } // can't load project file
674 if(FileMOV::check_sig(this->asset)) {
676 // should be last because quicktime lacks a magic number
678 file = new FileMOV(this->asset, this);
681 if( !preferences->ffmpeg_early_probe &&
682 FileFFMPEG::check_sig(this->asset) ) {
684 file = new FileFFMPEG(this->asset, this);
689 return FILE_UNRECOGNIZED_CODEC;
692 // format already determined
694 file = new FileAC3(this->asset, this);
698 file = new FileScene(this->asset, this);
702 file = new FileFFMPEG(this->asset, this);
710 //printf("File::open_file 1\n");
711 file = new FileSndFile(this->asset, this);
716 file = new FilePNG(this->asset, this);
721 file = new FileJPEG(this->asset, this);
726 file = new FileGIF(this->asset, this);
731 file = new FileEXR(this->asset, this);
735 file = new FileFLAC(this->asset, this);
740 file = new FileCR2(this->asset, this);
745 file = new FileTGA(this->asset, this);
750 file = new FileTIFF(this->asset, this);
754 file = new FileDB(this->asset, this);
758 file = new FileMOV(this->asset, this);
764 file = new FileMPEG(this->asset, this);
768 file = new FileOGG(this->asset, this);
772 file = new FileVorbis(this->asset, this);
776 file = new FileMOV(this->asset, this);
779 case FILE_AVI_LAVTOOLS:
782 case FILE_AVI_AVIFILE:
783 file = new FileAVI(this->asset, this);
787 file = new FileDV(this->asset, this);
797 // Reopen file with correct parser and get header.
798 if(file->open_file(rd, wr)) {
799 delete file; file = 0;
800 return FILE_NOT_FOUND;
805 // Set extra writing parameters to mandatory settings.
807 if(this->asset->dither) file->set_dither();
811 // one frame image file, no specific length
812 if( !this->asset->audio_data && this->asset->video_data &&
813 this->asset->video_length <= 1 )
814 this->asset->video_length = -1;
817 // Synchronize header parameters
818 asset->copy_from(this->asset, 1);
821 if(debug) printf("File::open_file %d file=%p\n", __LINE__, file);
827 void File::delete_temp_samples_buffer()
830 if(temp_samples_buffer) {
831 for(int j = 0; j < audio_ring_buffers; j++) {
832 for(int i = 0; i < asset->channels; i++) {
833 delete temp_samples_buffer[j][i];
835 delete [] temp_samples_buffer[j];
838 delete [] temp_samples_buffer;
839 temp_samples_buffer = 0;
840 audio_ring_buffers = 0;
844 void File::delete_temp_frame_buffer()
847 if(temp_frame_buffer) {
848 for(int k = 0; k < video_ring_buffers; k++) {
849 for(int i = 0; i < asset->layers; i++) {
850 for(int j = 0; j < video_buffer_size; j++) {
851 delete temp_frame_buffer[k][i][j];
853 delete [] temp_frame_buffer[k][i];
855 delete [] temp_frame_buffer[k];
858 delete [] temp_frame_buffer;
859 temp_frame_buffer = 0;
860 video_ring_buffers = 0;
861 video_buffer_size = 0;
865 int File::close_file(int ignore_thread)
870 if(debug) printf("File::close_file file=%p file_fork=%p %d\n", file, file_fork, __LINE__);
873 FileForker this_is(*forked);
874 file_fork->send_command(FileFork::CLOSE_FILE, 0, 0);
875 file_fork->read_result();
878 asset->audio_length = current_sample = *(int64_t*)file_fork->result_data;
879 asset->video_length = current_frame = *(int64_t*)(file_fork->result_data + sizeof(int64_t));
882 if(debug) printf("File::close_file:%d current_sample=" _LD " current_frame=" _LD "\n",
892 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
900 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
902 // The file's asset is a copy of the argument passed to open_file so the
903 // user must copy lengths from the file's asset.
905 asset->audio_length = current_sample;
906 asset->video_length = current_frame;
912 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
914 delete_temp_samples_buffer();
915 delete_temp_frame_buffer();
916 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
918 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
921 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
927 int File::get_index(char *index_path)
931 FileForker this_is(*forked);
932 file_fork->send_command(FileFork::GET_INDEX, (unsigned char*)index_path, strlen(index_path) + 1);
933 int result = file_fork->read_result();
939 return file->get_index(index_path);
946 int File::start_audio_thread(int buffer_size, int ring_buffers)
948 this->audio_ring_buffers = ring_buffers;
953 FileForker this_is(*forked);
954 unsigned char buffer[sizeof(int) * 2];
955 int *ibfr = (int *)buffer;
956 ibfr[0] = buffer_size;
957 ibfr[1] = audio_ring_buffers;
958 file_fork->send_command(FileFork::START_AUDIO_THREAD, buffer, sizeof(buffer));
959 int result = file_fork->read_result();
962 //printf("File::start_audio_thread %d file_fork->result_data=%p\n", __LINE__, file_fork->result_data);
963 // Create server copy of buffer
964 delete_temp_samples_buffer();
965 //printf("File::start_audio_thread %d\n", __LINE__);
966 temp_samples_buffer = new Samples**[audio_ring_buffers];
967 //printf("File::start_audio_thread %d\n", __LINE__);
968 for(int i = 0; i < audio_ring_buffers; i++)
970 //printf("File::start_audio_thread %d\n", __LINE__);
971 temp_samples_buffer[i] = new Samples*[asset->channels];
972 //printf("File::start_audio_thread %d\n", __LINE__);
973 for(int j = 0; j < asset->channels; j++)
975 int offset = i * Samples::filefork_size() * asset->channels +
976 j * Samples::filefork_size();
977 //printf("File::start_audio_thread %d j=%d offset=%d\n", __LINE__, j, offset);
978 temp_samples_buffer[i][j] = new Samples;
979 temp_samples_buffer[i][j]->from_filefork(
980 file_fork->result_data +
982 //printf("File::start_audio_thread %d\n", __LINE__);
993 audio_thread = new FileThread(this, 1, 0);
994 audio_thread->start_writing(buffer_size, 0, ring_buffers, 0);
999 int File::start_video_thread(int buffer_size,
1004 this->video_ring_buffers = ring_buffers;
1005 this->video_buffer_size = buffer_size;
1010 FileForker this_is(*forked);
1011 // This resets variables
1012 delete_temp_frame_buffer();
1014 this->video_ring_buffers = ring_buffers;
1015 this->video_buffer_size = buffer_size;
1017 unsigned char buffer[sizeof(int) * 4];
1018 int *ibfr = (int *)buffer;
1019 ibfr[0] = buffer_size;
1020 ibfr[1] = color_model;
1021 ibfr[2] = video_ring_buffers;
1022 ibfr[3] = compressed;
1023 // Buffers are allocated
1024 file_fork->send_command(FileFork::START_VIDEO_THREAD,
1027 int result = file_fork->read_result();
1030 // Create server copy of buffer
1031 //printf("File::start_video_thread %d %d\n", __LINE__, video_ring_buffers);
1032 temp_frame_buffer = new VFrame***[video_ring_buffers];
1033 for(int i = 0; i < video_ring_buffers; i++)
1035 temp_frame_buffer[i] = new VFrame**[asset->layers];
1036 for(int j = 0; j < asset->layers; j++)
1038 temp_frame_buffer[i][j] = new VFrame*[video_buffer_size];
1039 //printf("File::start_video_thread %d %p\n", __LINE__, temp_frame_buffer[i][j]);
1040 for(int k = 0; k < video_buffer_size; k++)
1042 temp_frame_buffer[i][j][k] = new VFrame;
1043 temp_frame_buffer[i][j][k]->from_filefork(file_fork->result_data +
1044 i * asset->layers * video_buffer_size * VFrame::filefork_size() +
1045 j * video_buffer_size * VFrame::filefork_size() +
1046 k * VFrame::filefork_size());
1060 video_thread = new FileThread(this, 0, 1);
1061 video_thread->start_writing(buffer_size,
1069 int File::start_video_decode_thread()
1074 FileForker this_is(*forked);
1075 file_fork->send_command(FileFork::START_VIDEO_DECODE_THREAD, 0, 0);
1076 file_fork->read_result();
1082 // Currently, CR2 is the only one which won't work asynchronously, so
1083 // we're not using a virtual function yet.
1084 if(!video_thread /* && asset->format != FILE_CR2 */)
1086 video_thread = new FileThread(this, 0, 1);
1087 video_thread->start_reading();
1093 int File::stop_audio_thread()
1098 file_fork->send_command(FileFork::STOP_AUDIO_THREAD, 0, 0);
1099 file_fork->read_result();
1106 audio_thread->stop_writing();
1107 delete audio_thread;
1113 int File::stop_video_thread()
1118 FileForker this_is(*forked);
1119 file_fork->send_command(FileFork::STOP_VIDEO_THREAD, 0, 0);
1120 file_fork->read_result();
1127 video_thread->stop_reading();
1128 video_thread->stop_writing();
1129 delete video_thread;
1135 FileThread* File::get_video_thread()
1137 return video_thread;
1140 int File::set_channel(int channel)
1145 FileForker this_is(*forked);
1146 // Set it locally for get_channel
1147 current_channel = channel;
1148 file_fork->send_command(FileFork::SET_CHANNEL, (unsigned char*)&channel, sizeof(channel));
1149 int result = file_fork->read_result();
1154 if(file && channel < asset->channels)
1156 current_channel = channel;
1163 int File::get_channel()
1165 return current_channel;
1168 // if no>=0, sets new program
1169 // returns current program
1170 int File::set_program(int no)
1175 FileForker this_is(*forked);
1176 file_fork->send_command(FileFork::SET_PROGRAM, (unsigned char*)&no, sizeof(no));
1177 int result = file_fork->read_result();
1178 current_program = no < 0 ? result : no;
1182 int result = file ? file->set_program(no) : current_program;
1183 current_program = no < 0 ? result : no;
1187 int File::get_cell_time(int no, double &time)
1192 FileForker this_is(*forked);
1193 file_fork->send_command(FileFork::GET_CELL_TIME, (unsigned char*)&no, sizeof(no));
1194 int result = file_fork->read_result();
1195 time = *(double *)file_fork->result_data;
1200 return file ? file->get_cell_time(no, time) : -1;
1203 int File::get_system_time(int64_t &tm)
1208 FileForker this_is(*forked);
1209 file_fork->send_command(FileFork::GET_STT_TIME, 0, 0);
1210 int result = file_fork->read_result();
1211 tm = *(int64_t *)file_fork->result_data;
1216 return file ? file->get_system_time(tm) : -1;
1219 int File::get_audio_for_video(int vstream, int astream, int64_t &channel_mask)
1224 FileForker this_is(*forked);
1225 unsigned char buffer[2*sizeof(int)];
1227 *(int*)(buffer + offset) = vstream;
1228 offset += sizeof(int);
1229 *(int*)(buffer + offset) = astream;
1230 file_fork->send_command(FileFork::GET_AUDIO4VIDEO, buffer, sizeof(buffer));
1231 int result = file_fork->read_result();
1232 channel_mask = *(int64_t *)file_fork->result_data;
1237 return file ? file->get_audio_for_video(vstream, astream, channel_mask) : -1;
1240 int File::get_video_pid(int track)
1245 FileForker this_is(*forked);
1246 file_fork->send_command(FileFork::GET_VIDEO_PID,
1247 (unsigned char*)&track, sizeof(track));
1248 int result = file_fork->read_result();
1253 return file ? file->get_video_pid(track) : -1;
1258 int File::get_video_info(int track, int &pid, double &framerate,
1259 int &width, int &height, char *title)
1264 FileForker this_is(*forked);
1265 file_fork->send_command(FileFork::GET_VIDEO_INFO,
1266 (unsigned char*)&track, sizeof(track));
1267 int result = file_fork->read_result();
1269 unsigned char *bp = file_fork->result_data;
1270 framerate = *(double*)bp; bp += sizeof(framerate);
1271 pid = *(int *) bp; bp += sizeof(pid);
1272 width = *(int *) bp; bp += sizeof(width);
1273 height = *(int *) bp; bp += sizeof(height);
1274 strcpy(title, (char *)bp);
1281 file->get_video_info(track, pid, framerate, width, height, title);
1284 int File::select_video_stream(Asset *asset, int vstream)
1289 FileForker this_is(*forked);
1290 file_fork->send_command(FileFork::SELECT_VIDEO_STREAM,
1291 (unsigned char*)&vstream, sizeof(vstream));
1292 int result = file_fork->read_result();
1294 unsigned char *bp = file_fork->result_data;
1295 asset->frame_rate = *(double*) bp; bp += sizeof(asset->frame_rate);
1296 asset->video_length = *(int64_t *) bp; bp += sizeof(asset->video_length);
1297 asset->width = *(int *) bp; bp += sizeof(asset->width);
1298 asset->height = *(int *) bp; bp += sizeof(asset->height);
1303 file->select_video_stream(asset, vstream);
1306 int File::select_audio_stream(Asset *asset, int astream)
1311 FileForker this_is(*forked);
1312 file_fork->send_command(FileFork::SELECT_AUDIO_STREAM,
1313 (unsigned char*)&astream, sizeof(astream));
1314 int result = file_fork->read_result();
1316 unsigned char *bp = file_fork->result_data;
1317 asset->audio_length = *(int64_t *) bp; bp += sizeof(asset->audio_length);
1318 asset->sample_rate = *(int *) bp; bp += sizeof(asset->sample_rate);
1323 file->select_audio_stream(asset, astream);
1327 int File::get_thumbnail(int stream,
1328 int64_t &position, unsigned char *&thumbnail, int &ww, int &hh)
1330 return file->get_thumbnail(stream, position, thumbnail, ww, hh);
1333 int File::set_skimming(int track, int skim, skim_fn fn, void *vp)
1335 return file->set_skimming(track, skim, fn, vp);
1338 int File::skim_video(int track, void *vp, skim_fn fn)
1340 return file->skim_video(track, vp, fn);
1344 int File::set_layer(int layer, int is_thread)
1347 // thread should only call in the fork
1348 if(file_fork && !is_fork && !is_thread)
1350 FileForker this_is(*forked);
1351 file_fork->send_command(FileFork::SET_LAYER, (unsigned char*)&layer, sizeof(layer));
1352 int result = file_fork->read_result();
1353 current_layer = layer;
1358 if(file && layer < asset->layers)
1360 if(!is_thread && video_thread)
1362 video_thread->set_layer(layer);
1366 current_layer = layer;
1374 int64_t File::get_audio_length()
1379 FileForker this_is(*forked);
1380 file_fork->send_command(FileFork::GET_AUDIO_LENGTH, 0, 0);
1381 int64_t result = file_fork->read_result();
1386 int64_t result = asset->audio_length;
1387 int64_t base_samplerate = -1;
1390 if(base_samplerate > 0)
1391 return (int64_t)((double)result / asset->sample_rate * base_samplerate + 0.5);
1399 int64_t File::get_video_length()
1404 FileForker this_is(*forked);
1405 file_fork->send_command(FileFork::GET_VIDEO_LENGTH, 0, 0);
1406 int64_t result = file_fork->read_result();
1412 int64_t result = asset->video_length;
1413 float base_framerate = -1;
1416 if(base_framerate > 0)
1417 return (int64_t)((double)result / asset->frame_rate * base_framerate + 0.5);
1422 return -1; // infinity
1426 int64_t File::get_video_position()
1431 FileForker this_is(*forked);
1432 file_fork->send_command(FileFork::GET_VIDEO_POSITION, 0, 0);
1433 int64_t result = file_fork->read_result();
1438 float base_framerate = -1;
1439 if(base_framerate > 0)
1440 return (int64_t)((double)current_frame / asset->frame_rate * base_framerate + 0.5);
1442 return current_frame;
1445 int64_t File::get_audio_position()
1450 FileForker this_is(*forked);
1451 file_fork->send_command(FileFork::GET_AUDIO_POSITION, 0, 0);
1452 int64_t result = file_fork->read_result();
1458 // int64_t base_samplerate = -1;
1459 // if(base_samplerate > 0)
1461 // if(normalized_sample_rate == base_samplerate)
1462 // return normalized_sample;
1464 // return (int64_t)((double)current_sample /
1465 // asset->sample_rate *
1466 // base_samplerate +
1470 return current_sample;
1475 int File::set_audio_position(int64_t position)
1480 FileForker this_is(*forked);
1481 file_fork->send_command(FileFork::SET_AUDIO_POSITION,
1482 (unsigned char*)&position,
1484 int result = file_fork->read_result();
1493 #define REPOSITION(x, y) \
1494 (labs((x) - (y)) > 1)
1496 float base_samplerate = asset->sample_rate;
1497 current_sample = normalized_sample = position;
1499 // printf("File::set_audio_position %d normalized_sample=%ld\n",
1501 // normalized_sample);
1502 result = file->set_audio_position(current_sample);
1505 printf("File::set_audio_position position=" _LD
1506 " base_samplerate=%f asset=%p asset->sample_rate=%d\n",
1507 position, base_samplerate, asset, asset->sample_rate);
1510 //printf("File::set_audio_position %d %d %d\n", current_channel, current_sample, position);
1515 int File::set_video_position(int64_t position,
1519 // Thread should only call in the fork
1520 if(file_fork && !is_fork && !is_thread)
1522 FileForker this_is(*forked);
1523 //printf("File::set_video_position %d %lld\n", __LINE__, position);
1524 file_fork->send_command(FileFork::SET_VIDEO_POSITION, (unsigned char*)&position, sizeof(position));
1525 int result = file_fork->read_result();
1533 // Convert to file's rate
1534 // if(base_framerate > 0)
1535 // position = (int64_t)((double)position /
1537 // asset->frame_rate +
1541 if(video_thread && !is_thread)
1543 // Call thread. Thread calls this again to set the file state.
1544 video_thread->set_video_position(position);
1547 if(current_frame != position)
1551 current_frame = position;
1552 result = file->set_video_position(current_frame);
1559 // No resampling here.
1560 int File::write_samples(Samples **buffer, int64_t len)
1565 FileForker this_is(*forked);
1566 int entry_size = Samples::filefork_size();
1567 int buffer_size = entry_size * asset->channels + sizeof(int64_t);
1568 unsigned char fork_buffer[buffer_size];
1569 for(int i = 0; i < asset->channels; i++)
1571 buffer[i]->to_filefork(fork_buffer + entry_size * i);
1574 *(int64_t*)(fork_buffer +
1575 entry_size * asset->channels) = len;
1577 file_fork->send_command(FileFork::WRITE_SAMPLES,
1580 int result = file_fork->read_result();
1592 write_lock->lock("File::write_samples");
1594 // Convert to arrays for backwards compatability
1595 double *temp[asset->channels];
1596 for(int i = 0; i < asset->channels; i++)
1598 temp[i] = buffer[i]->get_data();
1601 result = file->write_samples(temp, len);
1602 current_sample += len;
1603 normalized_sample += len;
1604 asset->audio_length += len;
1605 write_lock->unlock();
1614 // Can't put any cmodel abstraction here because the filebase couldn't be
1616 int File::write_frames(VFrame ***frames, int len)
1618 //printf("File::write_frames %d\n", __LINE__);
1622 FileForker this_is(*forked);
1623 //printf("File::write_frames %d\n", __LINE__);
1624 int entry_size = frames[0][0]->filefork_size();
1625 unsigned char fork_buffer[entry_size * asset->layers * len + sizeof(int)];
1626 for(int i = 0; i < asset->layers; i++)
1628 for(int j = 0; j < len; j++)
1630 // printf("File::write_frames %d " _LD " %d\n",
1632 // frames[i][j]->get_number(),
1633 // frames[i][j]->get_keyframe());
1634 frames[i][j]->to_filefork(fork_buffer +
1636 entry_size * len * i +
1644 int *fbfr = (int *)fork_buffer;
1648 file_fork->send_command(FileFork::WRITE_FRAMES,
1650 sizeof(fork_buffer));
1652 int result = file_fork->read_result();
1655 //printf("File::write_frames %d\n", __LINE__);
1660 #endif // USE_FILEFORK
1664 // Store the counters in temps so the filebase can choose to overwrite them.
1666 int current_frame_temp = current_frame;
1667 int video_length_temp = asset->video_length;
1669 write_lock->lock("File::write_frames");
1672 result = file->write_frames(frames, len);
1675 current_frame = current_frame_temp + len;
1676 asset->video_length = video_length_temp + len;
1677 write_lock->unlock();
1682 // Only called by FileThread
1683 int File::write_compressed_frame(VFrame *buffer)
1686 write_lock->lock("File::write_compressed_frame");
1687 result = file->write_compressed_frame(buffer);
1689 asset->video_length++;
1690 write_lock->unlock();
1695 int File::write_audio_buffer(int64_t len)
1700 FileForker this_is(*forked);
1701 file_fork->send_command(FileFork::WRITE_AUDIO_BUFFER, (unsigned char*)&len, sizeof(len));
1702 int result = file_fork->read_result();
1710 result = audio_thread->write_buffer(len);
1715 int File::write_video_buffer(int64_t len)
1720 FileForker this_is(*forked);
1721 // Copy over sequence numbers for background rendering
1722 // frame sizes for direct copy
1723 //printf("File::write_video_buffer %d\n", __LINE__);
1724 int fork_buffer_size = sizeof(int64_t) +
1725 VFrame::filefork_size() * asset->layers * len;
1726 unsigned char fork_buffer[fork_buffer_size];
1727 int64_t *fbfr = (int64_t *)fork_buffer;
1730 for(int i = 0; i < asset->layers; i++)
1732 for(int j = 0; j < len; j++)
1734 // Send memory state
1735 current_frame_buffer[i][j]->to_filefork(fork_buffer +
1737 VFrame::filefork_size() * (len * i + j));
1738 // printf("File::write_video_buffer %d size=%d %d %02x %02x %02x %02x %02x %02x %02x %02x\n",
1740 // current_frame_buffer[i][j]->get_shmid(),
1741 // current_frame_buffer[i][j]->get_compressed_size(),
1742 // current_frame_buffer[i][j]->get_data()[0],
1743 // current_frame_buffer[i][j]->get_data()[1],
1744 // current_frame_buffer[i][j]->get_data()[2],
1745 // current_frame_buffer[i][j]->get_data()[3],
1746 // current_frame_buffer[i][j]->get_data()[4],
1747 // current_frame_buffer[i][j]->get_data()[5],
1748 // current_frame_buffer[i][j]->get_data()[6],
1749 // current_frame_buffer[i][j]->get_data()[7]);
1753 //printf("File::write_video_buffer %d\n", __LINE__);
1754 file_fork->send_command(FileFork::WRITE_VIDEO_BUFFER,
1757 //printf("File::write_video_buffer %d\n", __LINE__);
1758 int result = file_fork->read_result();
1759 //printf("File::write_video_buffer %d\n", __LINE__);
1767 result = video_thread->write_buffer(len);
1773 Samples** File::get_audio_buffer()
1778 FileForker this_is(*forked);
1779 file_fork->send_command(FileFork::GET_AUDIO_BUFFER, 0, 0);
1780 int result = file_fork->read_result();
1782 // Read parameters for a Samples buffer & create it in File
1783 // delete_temp_samples_buffer();
1784 // if(!temp_samples_buffer)
1786 // temp_samples_buffer = new Samples**[ring_buffers];
1787 // for(int i = 0; i < ring_buffers; i++) temp_samples_buffer[i] = 0;
1791 // temp_samples_buffer = new Samples*[asset->channels];
1792 // for(int i = 0; i < asset->channels; i++)
1794 // temp_samples_buffer[i] = new Samples;
1795 // temp_samples_buffer[i]->from_filefork(file_fork->result_data +
1796 // i * Samples::filefork_size());
1799 return temp_samples_buffer[result];
1803 if(audio_thread) return audio_thread->get_audio_buffer();
1807 VFrame*** File::get_video_buffer()
1812 FileForker this_is(*forked);
1814 file_fork->send_command(FileFork::GET_VIDEO_BUFFER, 0, 0);
1815 int result = file_fork->read_result();
1817 // Read parameters for a VFrame buffer & create it in File
1818 // delete_temp_frame_buffer();
1821 // temp_frame_size = *(int*)(file_fork->result_data +
1822 // file_fork->result_bytes -
1825 // //printf("File::get_video_buffer %d %p %d\n", __LINE__, this, asset->layers);
1826 // temp_frame_buffer = new VFrame**[asset->layers];
1828 // for(int i = 0; i < asset->layers; i++)
1831 // temp_frame_buffer[i] = new VFrame*[temp_frame_size];
1833 // for(int j = 0; j < temp_frame_size; j++)
1836 // temp_frame_buffer[i][j] = new VFrame;
1837 // printf("File::get_video_buffer %d %p\n", __LINE__, temp_frame_buffer[i][j]);
1839 // temp_frame_buffer[i][j]->from_filefork(file_fork->result_data +
1840 // i * temp_frame_size * VFrame::filefork_size() +
1841 // j * VFrame::filefork_size());
1847 current_frame_buffer = temp_frame_buffer[result];
1849 return current_frame_buffer;
1855 VFrame*** result = video_thread->get_video_buffer();
1864 int File::read_samples(Samples *samples, int64_t len)
1866 // Never try to read more samples than exist in the file
1867 if (current_sample + len > asset->audio_length) {
1868 len = asset->audio_length - current_sample;
1870 if(len <= 0) return 0;
1873 const int debug = 0;
1874 if(debug) PRINT_TRACE
1879 FileForker this_is(*forked);
1880 int buffer_bytes = Samples::filefork_size() + sizeof(int64_t);
1881 unsigned char buffer[buffer_bytes];
1882 samples->to_filefork(buffer);
1883 *(int64_t*)(buffer + Samples::filefork_size()) = len;
1884 if(debug) PRINT_TRACE
1885 file_fork->send_command(FileFork::READ_SAMPLES,
1888 if(debug) PRINT_TRACE
1889 int result = file_fork->read_result();
1892 if(result && !file_fork->child_running())
1895 result = open_file(preferences, asset, rd, wr);
1902 if(debug) PRINT_TRACE
1904 double *buffer = samples->get_data();
1906 int64_t base_samplerate = asset->sample_rate;
1910 // Resample recursively calls this with the asset sample rate
1911 if(base_samplerate == 0) base_samplerate = asset->sample_rate;
1913 if(debug) PRINT_TRACE
1914 result = file->read_samples(buffer, len);
1916 if(debug) PRINT_TRACE
1917 current_sample += len;
1919 normalized_sample += len;
1921 if(debug) PRINT_TRACE
1927 int File::read_frame(VFrame *frame, int is_thread)
1929 const int debug = 0;
1931 if(debug) PRINT_TRACE
1934 // is_thread is only true in the fork
1935 if(file_fork && !is_fork && !is_thread)
1937 FileForker this_is(*forked);
1938 unsigned char fork_buffer[VFrame::filefork_size()];
1939 if(debug) PRINT_TRACE
1941 frame->to_filefork(fork_buffer);
1942 file_fork->send_command(FileFork::READ_FRAME,
1944 VFrame::filefork_size());
1946 int result = file_fork->read_result();
1950 if(result && !file_fork->child_running())
1953 result = open_file(preferences, asset, rd, wr);
1957 frame->get_color_model() == BC_COMPRESSED)
1959 // Get compressed data from socket
1960 //printf("File::read_frame %d %d\n", __LINE__, file_fork->result_bytes);
1961 int header_size = sizeof(int) * 2;
1962 if(file_fork->result_bytes > header_size)
1964 //printf("File::read_frame %d %d\n", __LINE__, file_fork->result_bytes);
1965 frame->allocate_compressed_data(file_fork->result_bytes - header_size);
1966 frame->set_compressed_size(file_fork->result_bytes - header_size);
1967 frame->set_keyframe(*(int*)(file_fork->result_data + sizeof(int)));
1968 memcpy(frame->get_data(),
1969 file_fork->result_data + header_size,
1970 file_fork->result_bytes - header_size);
1973 // Get compressed data size
1975 frame->set_compressed_size(*(int*)file_fork->result_data);
1976 frame->set_keyframe(*(int*)(file_fork->result_data + sizeof(int)));
1977 //printf("File::read_frame %d %d\n", __LINE__, *(int*)(file_fork->result_data + sizeof(int)));
1986 //printf("File::read_frame %d\n", __LINE__);
1988 if(video_thread && !is_thread) return video_thread->read_frame(frame);
1990 //printf("File::read_frame %d\n", __LINE__);
1991 if(debug) PRINT_TRACE
1994 if(debug) PRINT_TRACE
1995 int supported_colormodel = colormodel_supported(frame->get_color_model());
1996 int advance_position = 1;
1999 if(use_cache && !is_fork &&
2000 frame_cache->get_frame(frame,
2005 // Can't advance position if cache used.
2006 //printf("File::read_frame %d\n", __LINE__);
2007 advance_position = 0;
2011 if(frame->get_color_model() != BC_COMPRESSED &&
2012 (supported_colormodel != frame->get_color_model() ||
2013 frame->get_w() != asset->width ||
2014 frame->get_h() != asset->height))
2017 // printf("File::read_frame %d\n", __LINE__);
2018 // Can't advance position here because it needs to be added to cache
2021 if(!temp_frame->params_match(asset->width, asset->height, supported_colormodel))
2028 // printf("File::read_frame %d\n", __LINE__);
2031 temp_frame = new VFrame(0,
2035 supported_colormodel,
2039 // printf("File::read_frame %d\n", __LINE__);
2040 temp_frame->copy_stacks(frame);
2041 file->read_frame(temp_frame);
2042 //for(int i = 0; i < 1000 * 1000; i++) ((float*)temp_frame->get_rows()[0])[i] = 1.0;
2043 // printf("File::read_frame %d %d %d %d %d %d\n",
2044 // temp_frame->get_color_model(),
2045 // temp_frame->get_w(),
2046 // temp_frame->get_h(),
2047 // frame->get_color_model(),
2050 BC_CModels::transfer(frame->get_rows(),
2051 temp_frame->get_rows(),
2055 temp_frame->get_y(),
2056 temp_frame->get_u(),
2057 temp_frame->get_v(),
2060 temp_frame->get_w(),
2061 temp_frame->get_h(),
2066 temp_frame->get_color_model(),
2067 frame->get_color_model(),
2069 temp_frame->get_w(),
2071 // printf("File::read_frame %d\n", __LINE__);
2075 // Can't advance position here because it needs to be added to cache
2076 //printf("File::read_frame %d\n", __LINE__);
2077 file->read_frame(frame);
2078 //for(int i = 0; i < 100 * 1000; i++) ((float*)frame->get_rows()[0])[i] = 1.0;
2081 //printf("File::read_frame %d use_cache=%d\n", __LINE__, use_cache);
2082 if(use_cache && !is_fork)
2083 frame_cache->put_frame(frame,
2084 current_frame, current_layer,
2085 asset->frame_rate, 1, 0);
2086 //printf("File::read_frame %d\n", __LINE__);
2088 if(advance_position) current_frame++;
2089 if(debug) PRINT_TRACE
2096 int File::can_copy_from(Asset *asset,
2101 if(!asset) return 0;
2106 FileForker this_is(*forked);
2108 asset->write(&xml, 1, "");
2109 xml.terminate_string();
2110 const char *xml_string = xml.string();
2111 long xml_length = strlen(xml_string);
2112 int buffer_size = xml_length + 1 +
2116 unsigned char *buffer = new unsigned char[buffer_size];
2117 *(int64_t*)(buffer) = position;
2118 *(int*)(buffer + sizeof(int64_t)) = output_w;
2119 *(int*)(buffer + sizeof(int64_t) + sizeof(int)) = output_h;
2127 file_fork->send_command(FileFork::CAN_COPY_FROM,
2130 int result = file_fork->read_result();
2138 return asset->width == output_w &&
2139 asset->height == output_h &&
2140 file->can_copy_from(asset, position);
2146 // Fill in queries about formats when adding formats here.
2149 int File::strtoformat(const char *format)
2151 return strtoformat(0, format);
2154 int File::strtoformat(ArrayList<PluginServer*> *plugindb, const char *format)
2156 if(!strcasecmp(format, _(AC3_NAME))) return FILE_AC3;
2157 if(!strcasecmp(format, _(SCENE_NAME))) return FILE_SCENE;
2158 if(!strcasecmp(format, _(WAV_NAME))) return FILE_WAV;
2159 if(!strcasecmp(format, _(PCM_NAME))) return FILE_PCM;
2160 if(!strcasecmp(format, _(AU_NAME))) return FILE_AU;
2161 if(!strcasecmp(format, _(AIFF_NAME))) return FILE_AIFF;
2162 if(!strcasecmp(format, _(SND_NAME))) return FILE_SND;
2163 if(!strcasecmp(format, _(PNG_NAME))) return FILE_PNG;
2164 if(!strcasecmp(format, _(PNG_LIST_NAME))) return FILE_PNG_LIST;
2165 if(!strcasecmp(format, _(TIFF_NAME))) return FILE_TIFF;
2166 if(!strcasecmp(format, _(TIFF_LIST_NAME))) return FILE_TIFF_LIST;
2167 if(!strcasecmp(format, _(JPEG_NAME))) return FILE_JPEG;
2168 if(!strcasecmp(format, _(JPEG_LIST_NAME))) return FILE_JPEG_LIST;
2169 if(!strcasecmp(format, _(EXR_NAME))) return FILE_EXR;
2170 if(!strcasecmp(format, _(EXR_LIST_NAME))) return FILE_EXR_LIST;
2171 if(!strcasecmp(format, _(FLAC_NAME))) return FILE_FLAC;
2172 if(!strcasecmp(format, _(CR2_NAME))) return FILE_CR2;
2173 if(!strcasecmp(format, _(CR2_LIST_NAME))) return FILE_CR2_LIST;
2174 if(!strcasecmp(format, _(MPEG_NAME))) return FILE_MPEG;
2175 if(!strcasecmp(format, _(AMPEG_NAME))) return FILE_AMPEG;
2176 if(!strcasecmp(format, _(VMPEG_NAME))) return FILE_VMPEG;
2177 if(!strcasecmp(format, _(TGA_NAME))) return FILE_TGA;
2178 if(!strcasecmp(format, _(TGA_LIST_NAME))) return FILE_TGA_LIST;
2179 if(!strcasecmp(format, _(MOV_NAME))) return FILE_MOV;
2180 if(!strcasecmp(format, _(AVI_NAME))) return FILE_AVI;
2181 if(!strcasecmp(format, _(AVI_LAVTOOLS_NAME))) return FILE_AVI_LAVTOOLS;
2182 if(!strcasecmp(format, _(AVI_ARNE2_NAME))) return FILE_AVI_ARNE2;
2183 if(!strcasecmp(format, _(AVI_ARNE1_NAME))) return FILE_AVI_ARNE1;
2184 if(!strcasecmp(format, _(AVI_AVIFILE_NAME))) return FILE_AVI_AVIFILE;
2185 if(!strcasecmp(format, _(OGG_NAME))) return FILE_OGG;
2186 if(!strcasecmp(format, _(VORBIS_NAME))) return FILE_VORBIS;
2187 if(!strcasecmp(format, _(RAWDV_NAME))) return FILE_RAWDV;
2188 if(!strcasecmp(format, _(FFMPEG_NAME))) return FILE_FFMPEG;
2189 if(!strcasecmp(format, _(DBASE_NAME))) return FILE_DB;
2195 const char* File::formattostr(int format)
2197 return formattostr(0, format);
2200 const char* File::formattostr(ArrayList<PluginServer*> *plugindb, int format)
2204 case FILE_SCENE: return _(SCENE_NAME);
2205 case FILE_AC3: return _(AC3_NAME);
2206 case FILE_WAV: return _(WAV_NAME);
2207 case FILE_PCM: return _(PCM_NAME);
2208 case FILE_AU: return _(AU_NAME);
2209 case FILE_AIFF: return _(AIFF_NAME);
2210 case FILE_SND: return _(SND_NAME);
2211 case FILE_PNG: return _(PNG_NAME);
2212 case FILE_PNG_LIST: return _(PNG_LIST_NAME);
2213 case FILE_JPEG: return _(JPEG_NAME);
2214 case FILE_JPEG_LIST: return _(JPEG_LIST_NAME);
2215 case FILE_CR2: return _(CR2_NAME);
2216 case FILE_CR2_LIST: return _(CR2_LIST_NAME);
2217 case FILE_FLAC: return _(FLAC_NAME);
2218 case FILE_EXR: return _(EXR_NAME);
2219 case FILE_EXR_LIST: return _(EXR_LIST_NAME);
2220 case FILE_MPEG: return _(MPEG_NAME);
2221 case FILE_AMPEG: return _(AMPEG_NAME);
2222 case FILE_VMPEG: return _(VMPEG_NAME);
2223 case FILE_TGA: return _(TGA_NAME);
2224 case FILE_TGA_LIST: return _(TGA_LIST_NAME);
2225 case FILE_TIFF: return _(TIFF_NAME);
2226 case FILE_TIFF_LIST: return _(TIFF_LIST_NAME);
2227 case FILE_MOV: return _(MOV_NAME);
2228 case FILE_AVI_LAVTOOLS: return _(AVI_LAVTOOLS_NAME);
2229 case FILE_AVI: return _(AVI_NAME);
2230 case FILE_AVI_ARNE2: return _(AVI_ARNE2_NAME);
2231 case FILE_AVI_ARNE1: return _(AVI_ARNE1_NAME);
2232 case FILE_AVI_AVIFILE: return _(AVI_AVIFILE_NAME);
2233 case FILE_OGG: return _(OGG_NAME);
2234 case FILE_VORBIS: return _(VORBIS_NAME);
2235 case FILE_RAWDV: return _(RAWDV_NAME);
2236 case FILE_FFMPEG: return _(FFMPEG_NAME);
2237 case FILE_DB: return _(DBASE_NAME);
2242 int File::strtobits(const char *bits)
2244 if(!strcasecmp(bits, _(NAME_8BIT))) return BITSLINEAR8;
2245 if(!strcasecmp(bits, _(NAME_16BIT))) return BITSLINEAR16;
2246 if(!strcasecmp(bits, _(NAME_24BIT))) return BITSLINEAR24;
2247 if(!strcasecmp(bits, _(NAME_32BIT))) return BITSLINEAR32;
2248 if(!strcasecmp(bits, _(NAME_ULAW))) return BITSULAW;
2249 if(!strcasecmp(bits, _(NAME_ADPCM))) return BITS_ADPCM;
2250 if(!strcasecmp(bits, _(NAME_FLOAT))) return BITSFLOAT;
2251 if(!strcasecmp(bits, _(NAME_IMA4))) return BITSIMA4;
2252 return BITSLINEAR16;
2255 const char* File::bitstostr(int bits)
2257 //printf("File::bitstostr\n");
2260 case BITSLINEAR8: return (NAME_8BIT);
2261 case BITSLINEAR16: return (NAME_16BIT);
2262 case BITSLINEAR24: return (NAME_24BIT);
2263 case BITSLINEAR32: return (NAME_32BIT);
2264 case BITSULAW: return (NAME_ULAW);
2265 case BITS_ADPCM: return (NAME_ADPCM);
2266 case BITSFLOAT: return (NAME_FLOAT);
2267 case BITSIMA4: return (NAME_IMA4);
2274 int File::str_to_byteorder(const char *string)
2276 if(!strcasecmp(string, _("Lo Hi"))) return 1;
2280 const char* File::byteorder_to_str(int byte_order)
2282 if(byte_order) return _("Lo Hi");
2286 int File::bytes_per_sample(int bits)
2290 case BITSLINEAR8: return 1;
2291 case BITSLINEAR16: return 2;
2292 case BITSLINEAR24: return 3;
2293 case BITSLINEAR32: return 4;
2294 case BITSULAW: return 1;
2295 case BITSIMA4: return 1;
2304 int File::get_best_colormodel(int driver)
2306 return get_best_colormodel(asset, driver);
2309 int File::get_best_colormodel(Asset *asset, int driver)
2311 switch(asset->format)
2313 case FILE_RAWDV: return FileDV::get_best_colormodel(asset, driver);
2314 case FILE_MOV: return FileMOV::get_best_colormodel(asset, driver);
2315 case FILE_AVI: return FileMOV::get_best_colormodel(asset, driver);
2316 case FILE_MPEG: return FileMPEG::get_best_colormodel(asset, driver);
2318 case FILE_JPEG_LIST: return FileJPEG::get_best_colormodel(asset, driver);
2320 case FILE_EXR_LIST: return FileEXR::get_best_colormodel(asset, driver);
2322 case FILE_PNG_LIST: return FilePNG::get_best_colormodel(asset, driver);
2324 case FILE_TGA_LIST: return FileTGA::get_best_colormodel(asset, driver);
2326 case FILE_CR2_LIST: return FileCR2::get_best_colormodel(asset, driver);
2327 case FILE_DB: return FileDB::get_best_colormodel(asset, driver);
2334 int File::colormodel_supported(int colormodel)
2339 FileForker this_is(*forked);
2340 unsigned char buffer[sizeof(int)];
2341 int *ibfr = (int *)buffer;
2342 ibfr[0] = colormodel;
2344 file_fork->send_command(FileFork::COLORMODEL_SUPPORTED,
2347 int result = file_fork->read_result();
2354 return file->colormodel_supported(colormodel);
2360 int64_t File::file_memory_usage()
2362 return file ? file->base_memory_usage() : 0;
2365 int64_t File::get_memory_usage()
2372 FileForker this_is(*forked);
2373 file_fork->send_command(FileFork::FILE_MEMORY_USAGE, 0, 0);
2374 result = file_fork->read_result();
2378 result += file_memory_usage();
2379 if(temp_frame) result += temp_frame->get_data_size();
2380 result += frame_cache->get_memory_usage();
2381 if(video_thread) result += video_thread->get_memory_usage();
2383 if(result < MIN_CACHEITEM_SIZE) result = MIN_CACHEITEM_SIZE;
2388 int File::supports_video(ArrayList<PluginServer*> *plugindb, char *format)
2390 int format_i = strtoformat(plugindb, format);
2392 return supports_video(format_i);
2396 int File::supports_audio(ArrayList<PluginServer*> *plugindb, char *format)
2398 int format_i = strtoformat(plugindb, format);
2400 return supports_audio(format_i);
2405 int File::supports_video(int format)
2407 //printf("File::supports_video %d\n", format);
2413 case FILE_JPEG_LIST:
2423 case FILE_TIFF_LIST:
2425 case FILE_AVI_LAVTOOLS:
2426 case FILE_AVI_ARNE2:
2428 case FILE_AVI_ARNE1:
2429 case FILE_AVI_AVIFILE:
2437 int File::supports_audio(int format)
2453 case FILE_AVI_LAVTOOLS:
2454 case FILE_AVI_ARNE2:
2455 case FILE_AVI_ARNE1:
2456 case FILE_AVI_AVIFILE:
2463 const char* File::get_tag(int format)
2467 case FILE_AC3: return "ac3";
2468 case FILE_AIFF: return "aif";
2469 case FILE_AMPEG: return "mp3";
2470 case FILE_AU: return "au";
2471 case FILE_AVI: return "avi";
2472 case FILE_RAWDV: return "dv";
2473 case FILE_DB: return "db";
2474 case FILE_EXR: return "exr";
2475 case FILE_EXR_LIST: return "exr";
2476 case FILE_FLAC: return "flac";
2477 case FILE_JPEG: return "jpg";
2478 case FILE_JPEG_LIST: return "jpg";
2479 case FILE_MOV: return "mov/mp4";
2480 case FILE_OGG: return "ogg";
2481 case FILE_PCM: return "pcm";
2482 case FILE_PNG: return "png";
2483 case FILE_PNG_LIST: return "png";
2484 case FILE_TGA: return "tga";
2485 case FILE_TGA_LIST: return "tga";
2486 case FILE_TIFF: return "tif";
2487 case FILE_TIFF_LIST: return "tif";
2488 case FILE_VMPEG: return "m2v";
2489 case FILE_VORBIS: return "ogg";
2490 case FILE_WAV: return "wav";
2491 case FILE_FFMPEG: return "ffmpg";
2496 const char* File::get_prefix(int format)
2499 case FILE_PCM: return "PCM";
2500 case FILE_WAV: return "WAV";
2501 case FILE_MOV: return "MOV";
2502 case FILE_PNG: return "PNG";
2503 case FILE_JPEG: return "JPEG";
2504 case FILE_TIFF: return "TIFF";
2505 case FILE_GIF: return "GIF";
2506 case FILE_JPEG_LIST: return "JPEG_LIST";
2507 case FILE_AU: return "AU";
2508 case FILE_AIFF: return "AIFF";
2509 case FILE_SND: return "SND";
2510 case FILE_AVI_LAVTOOLS: return "AVI_LAVTOOLS";
2511 case FILE_TGA_LIST: return "TGA_LIST";
2512 case FILE_TGA: return "TGA";
2513 case FILE_MPEG: return "MPEG";
2514 case FILE_AMPEG: return "AMPEG";
2515 case FILE_VMPEG: return "VMPEG";
2516 case FILE_RAWDV: return "RAWDV";
2517 case FILE_AVI_ARNE2: return "AVI_ARNE2";
2518 case FILE_AVI_ARNE1: return "AVI_ARNE1";
2519 case FILE_AVI_AVIFILE: return "AVI_AVIFILE";
2520 case FILE_TIFF_LIST: return "TIFF_LIST";
2521 case FILE_PNG_LIST: return "PNG_LIST";
2522 case FILE_AVI: return "AVI";
2523 case FILE_AC3: return "AC3";
2524 case FILE_EXR: return "EXR";
2525 case FILE_EXR_LIST: return "EXR_LIST";
2526 case FILE_CR2: return "CR2";
2527 case FILE_OGG: return "OGG";
2528 case FILE_VORBIS: return "VORBIS";
2529 case FILE_FLAC: return "FLAC";
2530 case FILE_FFMPEG: return "FFMPEG";
2531 case FILE_SCENE: return "SCENE";
2532 case FILE_CR2_LIST: return "CR2_LIST";
2533 case FILE_GIF_LIST: return "GIF_LIST";
2534 case FILE_DB: return "DB";
2540 PackagingEngine *File::new_packaging_engine(Asset *asset)
2542 PackagingEngine *result;
2543 switch (asset->format)
2546 result = (PackagingEngine*)new PackagingEngineOGG();
2549 result = (PackagingEngine*) new PackagingEngineDefault();
2557 int File::record_fd()
2559 return file ? file->record_fd() : -1;