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"
82 //suppress noref warning
83 void *vorbis0_ov_callbacks[] = {
84 &OV_CALLBACKS_DEFAULT, &OV_CALLBACKS_NOCLOSE,
85 &OV_CALLBACKS_STREAMONLY, &OV_CALLBACKS_STREAMONLY_NOCLOSE,
92 format_completion = new Condition(1, "File::format_completion");
93 write_lock = new Condition(1, "File::write_lock");
94 frame_cache = new FrameCache;
96 forked = new Mutex("File::forked",0);
105 if(format_window) format_window->set_done(0);
106 format_completion->lock("File::~File");
107 format_completion->unlock();
110 if(temp_frame) delete temp_frame;
115 asset->Garbage::remove_user();
116 delete format_completion;
124 void File::reset_parameters()
142 normalized_sample = 0;
145 playback_subtitle = -1;
149 temp_samples_buffer = 0;
150 temp_frame_buffer = 0;
151 current_frame_buffer = 0;
152 audio_ring_buffers = 0;
153 video_ring_buffers = 0;
154 video_buffer_size = 0;
157 int File::raise_window()
159 if(getting_options && format_window)
161 format_window->raise_window();
162 format_window->flush();
167 void File::close_window()
171 format_window->lock_window("File::close_window");
172 format_window->set_done(1);
173 format_window->unlock_window();
178 int File::get_options(FormatTools *format,
179 int audio_options, int video_options)
181 BC_WindowBase *parent_window = format->window;
182 //ArrayList<PluginServer*> *plugindb = format->plugindb;
183 Asset *asset = format->asset;
184 const char *locked_compressor = format->locked_compressor;
187 format_completion->lock("File::get_options");
188 switch(asset->format)
191 FileAC3::get_parameters(parent_window,
198 FileDV::get_parameters(parent_window,
209 FileSndFile::get_parameters(parent_window,
216 FileMOV::get_parameters(parent_window,
224 FileFFMPEG::get_parameters(parent_window,
232 FileMPEG::get_parameters(parent_window,
239 FileMOV::get_parameters(parent_window,
246 case FILE_AVI_LAVTOOLS:
249 case FILE_AVI_AVIFILE:
250 FileAVI::get_parameters(parent_window,
259 FileJPEG::get_parameters(parent_window,
267 FileEXR::get_parameters(parent_window,
274 FileFLAC::get_parameters(parent_window,
282 FilePNG::get_parameters(parent_window,
290 FileTGA::get_parameters(parent_window,
298 FileTIFF::get_parameters(parent_window,
305 FileOGG::get_parameters(parent_window,
317 ErrorBox *errorbox = new ErrorBox(PROGRAM_NAME ": Error",
318 parent_window->get_abs_cursor_x(1),
319 parent_window->get_abs_cursor_y(1));
320 format_window = errorbox;
323 errorbox->create_objects(_("This format doesn't support audio."));
326 errorbox->create_objects(_("This format doesn't support video."));
327 errorbox->run_window();
333 format_completion->unlock();
346 int File::set_processors(int cpus) // Set the number of cpus for certain codecs
348 if( cpus > 8 ) // mpegvideo max_threads = 16, more causes errs
349 cpus = 8; // 8 cpus ought to decode just about anything
353 FileForker this_is(*forked);
354 file_fork->send_command(FileFork::SET_PROCESSORS, (unsigned char*)&cpus, sizeof(cpus));
355 file_fork->read_result();
359 // Set all instances so gets work.
365 int File::set_preload(int64_t size)
370 FileForker this_is(*forked);
371 file_fork->send_command(FileFork::SET_PRELOAD, (unsigned char*)&size, sizeof(size));
372 file_fork->read_result();
377 this->playback_preload = size;
381 void File::set_subtitle(int value)
386 FileForker this_is(*forked);
387 file_fork->send_command(FileFork::SET_SUBTITLE, (unsigned char*)&value, sizeof(value));
388 file_fork->read_result();
392 this->playback_subtitle = value;
393 if( file ) file->set_subtitle(value);
396 void File::set_interpolate_raw(int value)
401 FileForker this_is(*forked);
402 file_fork->send_command(FileFork::SET_INTERPOLATE_RAW, (unsigned char*)&value, sizeof(value));
403 file_fork->read_result();
408 this->interpolate_raw = value;
411 void File::set_white_balance_raw(int value)
416 FileForker this_is(*forked);
417 file_fork->send_command(FileFork::SET_WHITE_BALANCE_RAW, (unsigned char*)&value, sizeof(value));
418 file_fork->read_result();
422 this->white_balance_raw = value;
426 void File::set_cache_frames(int value)
428 // caching only done locally
433 int File::purge_cache()
435 // caching only done locally
437 if( frame_cache->cache_items() > 0 )
439 frame_cache->remove_all();
445 int File::delete_oldest()
447 // caching only done locally
448 return frame_cache->delete_oldest();
461 int File::open_file(Preferences *preferences,
469 this->preferences = preferences;
470 this->asset->copy_from(asset, 1);
475 if(debug) printf("File::open_file %d\n", __LINE__);
478 if( !is_fork && MWindow::file_server && (rd || wr) ) {
479 FileForker this_is(*forked);
480 // printf("File::open_file %d file_server=%p rd=%d wr=%d %d\n",
482 // MWindow::file_server,
485 // asset->ms_quantization);
486 file_fork = MWindow::file_server->new_filefork();
487 //printf("File::open_file %d\n", __LINE__);
490 // Convert to hash table
492 asset->save_defaults(&table, "", 1, 1, 1, 1, 1);
495 table.save_string(string);
496 int buffer_size = sizeof(int) * 7 + strlen(string) + 1;
497 unsigned char *buffer = new unsigned char[buffer_size];
499 *(int*)(buffer + offset) = rd;
500 offset += sizeof(int);
501 *(int*)(buffer + offset) = wr;
502 offset += sizeof(int);
503 *(int*)(buffer + offset) = cpus;
504 offset += sizeof(int);
505 *(int*)(buffer + offset) = white_balance_raw;
506 offset += sizeof(int);
507 *(int*)(buffer + offset) = interpolate_raw;
508 offset += sizeof(int);
509 *(int*)(buffer + offset) = playback_subtitle;
510 offset += sizeof(int);
511 *(int*)(buffer + offset) = current_program;
512 offset += sizeof(int);
513 memcpy(buffer + offset, string, strlen(string) + 1);
514 //printf("File::open_file %d\n", __LINE__);
515 file_fork->send_command(FileFork::OPEN_FILE,
520 //printf("File::open_file %d\n", __LINE__);
522 // Get the updated asset from the fork
523 result = file_fork->read_result();
524 //printf("File::open_file %d\n", __LINE__);
527 table.load_string((char*)file_fork->result_data);
529 asset->load_defaults(&table, "", 1, 1, 1, 1, 1);
530 this->asset->load_defaults(&table, "", 1, 1, 1, 1, 1);
531 //this->asset->dump();
533 //printf("File::open_file %d\n", __LINE__);
536 // If it's a scene renderer, close it & reopen it locally to get the
537 // full OpenGL support.
538 // Just doing 2D for now. Should be forked in case Festival crashes.
539 // if(rd && this->asset->format == FILE_SCENE)
541 // //printf("File::open_file %p %d\n", this, __LINE__);
543 // // Lie to get it to work properly
554 if(debug) printf("File::open_file %p %d\n", this, __LINE__);
556 switch(this->asset->format)
558 // get the format now
559 // If you add another format to case 0, you also need to add another case for the
560 // file format #define.
562 if(FileDB::check_sig(this->asset)) {
564 file = new FileDB(this->asset, this);
567 // if early probe enabled
568 if( preferences->ffmpeg_early_probe &&
569 FileFFMPEG::check_sig(this->asset)) {
570 file = new FileFFMPEG(this->asset, this);
575 if(!(stream = fopen(this->asset->path, "rb"))) {
581 result = fread(test, 16, 1, stream);
583 if(FileScene::check_sig(this->asset, test)) {
586 file = new FileScene(this->asset, this);
589 if(FileDV::check_sig(this->asset)) {
592 file = new FileDV(this->asset, this);
595 if(FileSndFile::check_sig(this->asset)) {
598 file = new FileSndFile(this->asset, this);
601 if(FilePNG::check_sig(this->asset)) {
604 file = new FilePNG(this->asset, this);
607 if(FileJPEG::check_sig(this->asset)) {
610 file = new FileJPEG(this->asset, this);
613 if(FileGIF::check_sig(this->asset)) {
616 file = new FileGIF(this->asset, this);
619 if(FileEXR::check_sig(this->asset, test)) {
622 file = new FileEXR(this->asset, this);
625 if(FileFLAC::check_sig(this->asset, test)) {
628 file = new FileFLAC(this->asset, this);
631 if(FileCR2::check_sig(this->asset)) {
634 file = new FileCR2(this->asset, this);
637 if(FileTGA::check_sig(this->asset)) {
640 file = new FileTGA(this->asset, this);
643 if(FileTIFF::check_sig(this->asset)) {
646 file = new FileTIFF(this->asset, this);
649 if(FileOGG::check_sig(this->asset)) {
652 file = new FileOGG(this->asset, this);
655 if(FileVorbis::check_sig(this->asset)) {
658 file = new FileVorbis(this->asset, this);
661 if(FileMPEG::check_sig(this->asset)) {
664 file = new FileMPEG(this->asset, this);
667 if( test[0] == '<' && (
668 !strncmp(&test[1],"EDL>",4) ||
669 !strncmp(&test[1],"HTAL>",5) ||
670 !strncmp(&test[1],"?xml",4) ) ) {
674 } // can't load project file
675 if(FileMOV::check_sig(this->asset)) {
677 // should be last because quicktime lacks a magic number
679 file = new FileMOV(this->asset, this);
682 if( !preferences->ffmpeg_early_probe &&
683 FileFFMPEG::check_sig(this->asset) ) {
685 file = new FileFFMPEG(this->asset, this);
690 return FILE_UNRECOGNIZED_CODEC;
693 // format already determined
695 file = new FileAC3(this->asset, this);
699 file = new FileScene(this->asset, this);
703 file = new FileFFMPEG(this->asset, this);
711 //printf("File::open_file 1\n");
712 file = new FileSndFile(this->asset, this);
717 file = new FilePNG(this->asset, this);
722 file = new FileJPEG(this->asset, this);
727 file = new FileGIF(this->asset, this);
732 file = new FileEXR(this->asset, this);
736 file = new FileFLAC(this->asset, this);
741 file = new FileCR2(this->asset, this);
746 file = new FileTGA(this->asset, this);
751 file = new FileTIFF(this->asset, this);
755 file = new FileDB(this->asset, this);
759 file = new FileMOV(this->asset, this);
765 file = new FileMPEG(this->asset, this);
769 file = new FileOGG(this->asset, this);
773 file = new FileVorbis(this->asset, this);
777 file = new FileMOV(this->asset, this);
780 case FILE_AVI_LAVTOOLS:
783 case FILE_AVI_AVIFILE:
784 file = new FileAVI(this->asset, this);
788 file = new FileDV(this->asset, this);
798 // Reopen file with correct parser and get header.
799 if(file->open_file(rd, wr)) {
801 return FILE_NOT_FOUND;
806 // Set extra writing parameters to mandatory settings.
808 if(this->asset->dither) file->set_dither();
812 // one frame image file, no specific length
813 if( !this->asset->audio_data && this->asset->video_data &&
814 this->asset->video_length <= 1 )
815 this->asset->video_length = -1;
818 // Synchronize header parameters
819 asset->copy_from(this->asset, 1);
822 if(debug) printf("File::open_file %d file=%p\n", __LINE__, file);
828 void File::delete_temp_samples_buffer()
831 if(temp_samples_buffer) {
832 for(int j = 0; j < audio_ring_buffers; j++) {
833 for(int i = 0; i < asset->channels; i++) {
834 delete temp_samples_buffer[j][i];
836 delete [] temp_samples_buffer[j];
839 delete [] temp_samples_buffer;
840 temp_samples_buffer = 0;
841 audio_ring_buffers = 0;
845 void File::delete_temp_frame_buffer()
848 if(temp_frame_buffer) {
849 for(int k = 0; k < video_ring_buffers; k++) {
850 for(int i = 0; i < asset->layers; i++) {
851 for(int j = 0; j < video_buffer_size; j++) {
852 delete temp_frame_buffer[k][i][j];
854 delete [] temp_frame_buffer[k][i];
856 delete [] temp_frame_buffer[k];
859 delete [] temp_frame_buffer;
860 temp_frame_buffer = 0;
861 video_ring_buffers = 0;
862 video_buffer_size = 0;
866 int File::close_file(int ignore_thread)
871 if(debug) printf("File::close_file file=%p file_fork=%p %d\n", file, file_fork, __LINE__);
874 FileForker this_is(*forked);
875 file_fork->send_command(FileFork::CLOSE_FILE, 0, 0);
876 file_fork->read_result();
879 asset->audio_length = current_sample = *(int64_t*)file_fork->result_data;
880 asset->video_length = current_frame = *(int64_t*)(file_fork->result_data + sizeof(int64_t));
883 if(debug) printf("File::close_file:%d current_sample=" _LD " current_frame=" _LD "\n",
893 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
901 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
903 // The file's asset is a copy of the argument passed to open_file so the
904 // user must copy lengths from the file's asset.
906 asset->audio_length = current_sample;
907 asset->video_length = current_frame;
913 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
915 delete_temp_samples_buffer();
916 delete_temp_frame_buffer();
917 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__);
922 if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
928 int File::get_index(char *index_path)
932 FileForker this_is(*forked);
933 file_fork->send_command(FileFork::GET_INDEX, (unsigned char*)index_path, strlen(index_path) + 1);
934 int result = file_fork->read_result();
940 return file->get_index(index_path);
947 int File::start_audio_thread(int buffer_size, int ring_buffers)
949 this->audio_ring_buffers = ring_buffers;
954 FileForker this_is(*forked);
955 unsigned char buffer[sizeof(int) * 2];
956 int *ibfr = (int *)buffer;
957 ibfr[0] = buffer_size;
958 ibfr[1] = audio_ring_buffers;
959 file_fork->send_command(FileFork::START_AUDIO_THREAD, buffer, sizeof(buffer));
960 int result = file_fork->read_result();
963 //printf("File::start_audio_thread %d file_fork->result_data=%p\n", __LINE__, file_fork->result_data);
964 // Create server copy of buffer
965 delete_temp_samples_buffer();
966 //printf("File::start_audio_thread %d\n", __LINE__);
967 temp_samples_buffer = new Samples**[audio_ring_buffers];
968 //printf("File::start_audio_thread %d\n", __LINE__);
969 for(int i = 0; i < audio_ring_buffers; i++)
971 //printf("File::start_audio_thread %d\n", __LINE__);
972 temp_samples_buffer[i] = new Samples*[asset->channels];
973 //printf("File::start_audio_thread %d\n", __LINE__);
974 for(int j = 0; j < asset->channels; j++)
976 int offset = i * Samples::filefork_size() * asset->channels +
977 j * Samples::filefork_size();
978 //printf("File::start_audio_thread %d j=%d offset=%d\n", __LINE__, j, offset);
979 temp_samples_buffer[i][j] = new Samples;
980 temp_samples_buffer[i][j]->from_filefork(
981 file_fork->result_data +
983 //printf("File::start_audio_thread %d\n", __LINE__);
994 audio_thread = new FileThread(this, 1, 0);
995 audio_thread->start_writing(buffer_size, 0, ring_buffers, 0);
1000 int File::start_video_thread(int buffer_size,
1005 this->video_ring_buffers = ring_buffers;
1006 this->video_buffer_size = buffer_size;
1011 FileForker this_is(*forked);
1012 // This resets variables
1013 delete_temp_frame_buffer();
1015 this->video_ring_buffers = ring_buffers;
1016 this->video_buffer_size = buffer_size;
1018 unsigned char buffer[sizeof(int) * 4];
1019 int *ibfr = (int *)buffer;
1020 ibfr[0] = buffer_size;
1021 ibfr[1] = color_model;
1022 ibfr[2] = video_ring_buffers;
1023 ibfr[3] = compressed;
1024 // Buffers are allocated
1025 file_fork->send_command(FileFork::START_VIDEO_THREAD,
1028 int result = file_fork->read_result();
1031 // Create server copy of buffer
1032 //printf("File::start_video_thread %d %d\n", __LINE__, video_ring_buffers);
1033 temp_frame_buffer = new VFrame***[video_ring_buffers];
1034 for(int i = 0; i < video_ring_buffers; i++)
1036 temp_frame_buffer[i] = new VFrame**[asset->layers];
1037 for(int j = 0; j < asset->layers; j++)
1039 temp_frame_buffer[i][j] = new VFrame*[video_buffer_size];
1040 //printf("File::start_video_thread %d %p\n", __LINE__, temp_frame_buffer[i][j]);
1041 for(int k = 0; k < video_buffer_size; k++)
1043 temp_frame_buffer[i][j][k] = new VFrame;
1044 temp_frame_buffer[i][j][k]->from_filefork(file_fork->result_data +
1045 i * asset->layers * video_buffer_size * VFrame::filefork_size() +
1046 j * video_buffer_size * VFrame::filefork_size() +
1047 k * VFrame::filefork_size());
1061 video_thread = new FileThread(this, 0, 1);
1062 video_thread->start_writing(buffer_size,
1070 int File::start_video_decode_thread()
1075 FileForker this_is(*forked);
1076 file_fork->send_command(FileFork::START_VIDEO_DECODE_THREAD, 0, 0);
1077 file_fork->read_result();
1083 // Currently, CR2 is the only one which won't work asynchronously, so
1084 // we're not using a virtual function yet.
1085 if(!video_thread /* && asset->format != FILE_CR2 */)
1087 video_thread = new FileThread(this, 0, 1);
1088 video_thread->start_reading();
1094 int File::stop_audio_thread()
1099 file_fork->send_command(FileFork::STOP_AUDIO_THREAD, 0, 0);
1100 file_fork->read_result();
1107 audio_thread->stop_writing();
1108 delete audio_thread;
1114 int File::stop_video_thread()
1119 FileForker this_is(*forked);
1120 file_fork->send_command(FileFork::STOP_VIDEO_THREAD, 0, 0);
1121 file_fork->read_result();
1128 video_thread->stop_reading();
1129 video_thread->stop_writing();
1130 delete video_thread;
1136 FileThread* File::get_video_thread()
1138 return video_thread;
1141 int File::set_channel(int channel)
1146 FileForker this_is(*forked);
1147 // Set it locally for get_channel
1148 current_channel = channel;
1149 file_fork->send_command(FileFork::SET_CHANNEL, (unsigned char*)&channel, sizeof(channel));
1150 int result = file_fork->read_result();
1155 if(file && channel < asset->channels)
1157 current_channel = channel;
1164 int File::get_channel()
1166 return current_channel;
1169 // if no>=0, sets new program
1170 // returns current program
1171 int File::set_program(int no)
1176 FileForker this_is(*forked);
1177 file_fork->send_command(FileFork::SET_PROGRAM, (unsigned char*)&no, sizeof(no));
1178 int result = file_fork->read_result();
1179 current_program = no < 0 ? result : no;
1183 int result = file ? file->set_program(no) : current_program;
1184 current_program = no < 0 ? result : no;
1188 int File::get_cell_time(int no, double &time)
1193 FileForker this_is(*forked);
1194 file_fork->send_command(FileFork::GET_CELL_TIME, (unsigned char*)&no, sizeof(no));
1195 int result = file_fork->read_result();
1196 time = *(double *)file_fork->result_data;
1201 return file ? file->get_cell_time(no, time) : -1;
1204 int File::get_system_time(int64_t &tm)
1209 FileForker this_is(*forked);
1210 file_fork->send_command(FileFork::GET_STT_TIME, 0, 0);
1211 int result = file_fork->read_result();
1212 tm = *(int64_t *)file_fork->result_data;
1217 return file ? file->get_system_time(tm) : -1;
1220 int File::get_audio_for_video(int vstream, int astream, int64_t &channel_mask)
1225 FileForker this_is(*forked);
1226 unsigned char buffer[2*sizeof(int)];
1228 *(int*)(buffer + offset) = vstream;
1229 offset += sizeof(int);
1230 *(int*)(buffer + offset) = astream;
1231 file_fork->send_command(FileFork::GET_AUDIO4VIDEO, buffer, sizeof(buffer));
1232 int result = file_fork->read_result();
1233 channel_mask = *(int64_t *)file_fork->result_data;
1238 return file ? file->get_audio_for_video(vstream, astream, channel_mask) : -1;
1241 int File::get_video_pid(int track)
1246 FileForker this_is(*forked);
1247 file_fork->send_command(FileFork::GET_VIDEO_PID,
1248 (unsigned char*)&track, sizeof(track));
1249 int result = file_fork->read_result();
1254 return file ? file->get_video_pid(track) : -1;
1259 int File::get_video_info(int track, int &pid, double &framerate,
1260 int &width, int &height, char *title)
1265 FileForker this_is(*forked);
1266 file_fork->send_command(FileFork::GET_VIDEO_INFO,
1267 (unsigned char*)&track, sizeof(track));
1268 int result = file_fork->read_result();
1270 unsigned char *bp = file_fork->result_data;
1271 framerate = *(double*)bp; bp += sizeof(framerate);
1272 pid = *(int *) bp; bp += sizeof(pid);
1273 width = *(int *) bp; bp += sizeof(width);
1274 height = *(int *) bp; bp += sizeof(height);
1275 strcpy(title, (char *)bp);
1282 file->get_video_info(track, pid, framerate, width, height, title);
1285 int File::select_video_stream(Asset *asset, int vstream)
1290 FileForker this_is(*forked);
1291 file_fork->send_command(FileFork::SELECT_VIDEO_STREAM,
1292 (unsigned char*)&vstream, sizeof(vstream));
1293 int result = file_fork->read_result();
1295 unsigned char *bp = file_fork->result_data;
1296 asset->frame_rate = *(double*) bp; bp += sizeof(asset->frame_rate);
1297 asset->video_length = *(int64_t *) bp; bp += sizeof(asset->video_length);
1298 asset->width = *(int *) bp; bp += sizeof(asset->width);
1299 asset->height = *(int *) bp; bp += sizeof(asset->height);
1304 file->select_video_stream(asset, vstream);
1307 int File::select_audio_stream(Asset *asset, int astream)
1312 FileForker this_is(*forked);
1313 file_fork->send_command(FileFork::SELECT_AUDIO_STREAM,
1314 (unsigned char*)&astream, sizeof(astream));
1315 int result = file_fork->read_result();
1317 unsigned char *bp = file_fork->result_data;
1318 asset->audio_length = *(int64_t *) bp; bp += sizeof(asset->audio_length);
1319 asset->sample_rate = *(int *) bp; bp += sizeof(asset->sample_rate);
1324 file->select_audio_stream(asset, astream);
1328 int File::get_thumbnail(int stream,
1329 int64_t &position, unsigned char *&thumbnail, int &ww, int &hh)
1331 return file->get_thumbnail(stream, position, thumbnail, ww, hh);
1334 int File::set_skimming(int track, int skim, skim_fn fn, void *vp)
1336 return file->set_skimming(track, skim, fn, vp);
1339 int File::skim_video(int track, void *vp, skim_fn fn)
1341 return file->skim_video(track, vp, fn);
1345 int File::set_layer(int layer, int is_thread)
1348 // thread should only call in the fork
1349 if(file_fork && !is_fork && !is_thread)
1351 FileForker this_is(*forked);
1352 file_fork->send_command(FileFork::SET_LAYER, (unsigned char*)&layer, sizeof(layer));
1353 int result = file_fork->read_result();
1354 current_layer = layer;
1359 if(file && layer < asset->layers)
1361 if(!is_thread && video_thread)
1363 video_thread->set_layer(layer);
1367 current_layer = layer;
1375 int64_t File::get_audio_length()
1380 FileForker this_is(*forked);
1381 file_fork->send_command(FileFork::GET_AUDIO_LENGTH, 0, 0);
1382 int64_t result = file_fork->read_result();
1387 int64_t result = asset->audio_length;
1388 int64_t base_samplerate = -1;
1391 if(base_samplerate > 0)
1392 return (int64_t)((double)result / asset->sample_rate * base_samplerate + 0.5);
1400 int64_t File::get_video_length()
1405 FileForker this_is(*forked);
1406 file_fork->send_command(FileFork::GET_VIDEO_LENGTH, 0, 0);
1407 int64_t result = file_fork->read_result();
1413 int64_t result = asset->video_length;
1414 float base_framerate = -1;
1417 if(base_framerate > 0)
1418 return (int64_t)((double)result / asset->frame_rate * base_framerate + 0.5);
1423 return -1; // infinity
1427 int64_t File::get_video_position()
1432 FileForker this_is(*forked);
1433 file_fork->send_command(FileFork::GET_VIDEO_POSITION, 0, 0);
1434 int64_t result = file_fork->read_result();
1439 float base_framerate = -1;
1440 if(base_framerate > 0)
1441 return (int64_t)((double)current_frame / asset->frame_rate * base_framerate + 0.5);
1443 return current_frame;
1446 int64_t File::get_audio_position()
1451 FileForker this_is(*forked);
1452 file_fork->send_command(FileFork::GET_AUDIO_POSITION, 0, 0);
1453 int64_t result = file_fork->read_result();
1459 // int64_t base_samplerate = -1;
1460 // if(base_samplerate > 0)
1462 // if(normalized_sample_rate == base_samplerate)
1463 // return normalized_sample;
1465 // return (int64_t)((double)current_sample /
1466 // asset->sample_rate *
1467 // base_samplerate +
1471 return current_sample;
1476 int File::set_audio_position(int64_t position)
1481 FileForker this_is(*forked);
1482 file_fork->send_command(FileFork::SET_AUDIO_POSITION,
1483 (unsigned char*)&position,
1485 int result = file_fork->read_result();
1494 #define REPOSITION(x, y) \
1495 (labs((x) - (y)) > 1)
1497 float base_samplerate = asset->sample_rate;
1498 current_sample = normalized_sample = position;
1500 // printf("File::set_audio_position %d normalized_sample=%ld\n",
1502 // normalized_sample);
1503 result = file->set_audio_position(current_sample);
1506 printf("File::set_audio_position position=" _LD
1507 " base_samplerate=%f asset=%p asset->sample_rate=%d\n",
1508 position, base_samplerate, asset, asset->sample_rate);
1511 //printf("File::set_audio_position %d %d %d\n", current_channel, current_sample, position);
1516 int File::set_video_position(int64_t position,
1520 // Thread should only call in the fork
1521 if(file_fork && !is_fork && !is_thread)
1523 FileForker this_is(*forked);
1524 //printf("File::set_video_position %d %lld\n", __LINE__, position);
1525 file_fork->send_command(FileFork::SET_VIDEO_POSITION, (unsigned char*)&position, sizeof(position));
1526 int result = file_fork->read_result();
1534 // Convert to file's rate
1535 // if(base_framerate > 0)
1536 // position = (int64_t)((double)position /
1538 // asset->frame_rate +
1542 if(video_thread && !is_thread)
1544 // Call thread. Thread calls this again to set the file state.
1545 video_thread->set_video_position(position);
1548 if(current_frame != position)
1552 current_frame = position;
1553 result = file->set_video_position(current_frame);
1560 // No resampling here.
1561 int File::write_samples(Samples **buffer, int64_t len)
1566 FileForker this_is(*forked);
1567 int entry_size = Samples::filefork_size();
1568 int buffer_size = entry_size * asset->channels + sizeof(int64_t);
1569 unsigned char fork_buffer[buffer_size];
1570 for(int i = 0; i < asset->channels; i++)
1572 buffer[i]->to_filefork(fork_buffer + entry_size * i);
1575 *(int64_t*)(fork_buffer +
1576 entry_size * asset->channels) = len;
1578 file_fork->send_command(FileFork::WRITE_SAMPLES,
1581 int result = file_fork->read_result();
1593 write_lock->lock("File::write_samples");
1595 // Convert to arrays for backwards compatability
1596 double *temp[asset->channels];
1597 for(int i = 0; i < asset->channels; i++)
1599 temp[i] = buffer[i]->get_data();
1602 result = file->write_samples(temp, len);
1603 current_sample += len;
1604 normalized_sample += len;
1605 asset->audio_length += len;
1606 write_lock->unlock();
1615 // Can't put any cmodel abstraction here because the filebase couldn't be
1617 int File::write_frames(VFrame ***frames, int len)
1619 //printf("File::write_frames %d\n", __LINE__);
1623 FileForker this_is(*forked);
1624 //printf("File::write_frames %d\n", __LINE__);
1625 int entry_size = frames[0][0]->filefork_size();
1626 unsigned char fork_buffer[entry_size * asset->layers * len + sizeof(int)];
1627 for(int i = 0; i < asset->layers; i++)
1629 for(int j = 0; j < len; j++)
1631 // printf("File::write_frames %d " _LD " %d\n",
1633 // frames[i][j]->get_number(),
1634 // frames[i][j]->get_keyframe());
1635 frames[i][j]->to_filefork(fork_buffer +
1637 entry_size * len * i +
1645 int *fbfr = (int *)fork_buffer;
1649 file_fork->send_command(FileFork::WRITE_FRAMES,
1651 sizeof(fork_buffer));
1653 int result = file_fork->read_result();
1656 //printf("File::write_frames %d\n", __LINE__);
1661 #endif // USE_FILEFORK
1665 // Store the counters in temps so the filebase can choose to overwrite them.
1667 int current_frame_temp = current_frame;
1668 int video_length_temp = asset->video_length;
1670 write_lock->lock("File::write_frames");
1673 result = file->write_frames(frames, len);
1676 current_frame = current_frame_temp + len;
1677 asset->video_length = video_length_temp + len;
1678 write_lock->unlock();
1683 // Only called by FileThread
1684 int File::write_compressed_frame(VFrame *buffer)
1687 write_lock->lock("File::write_compressed_frame");
1688 result = file->write_compressed_frame(buffer);
1690 asset->video_length++;
1691 write_lock->unlock();
1696 int File::write_audio_buffer(int64_t len)
1701 FileForker this_is(*forked);
1702 file_fork->send_command(FileFork::WRITE_AUDIO_BUFFER, (unsigned char*)&len, sizeof(len));
1703 int result = file_fork->read_result();
1711 result = audio_thread->write_buffer(len);
1716 int File::write_video_buffer(int64_t len)
1721 FileForker this_is(*forked);
1722 // Copy over sequence numbers for background rendering
1723 // frame sizes for direct copy
1724 //printf("File::write_video_buffer %d\n", __LINE__);
1725 int fork_buffer_size = sizeof(int64_t) +
1726 VFrame::filefork_size() * asset->layers * len;
1727 unsigned char fork_buffer[fork_buffer_size];
1728 int64_t *fbfr = (int64_t *)fork_buffer;
1731 for(int i = 0; i < asset->layers; i++)
1733 for(int j = 0; j < len; j++)
1735 // Send memory state
1736 current_frame_buffer[i][j]->to_filefork(fork_buffer +
1738 VFrame::filefork_size() * (len * i + j));
1739 // printf("File::write_video_buffer %d size=%d %d %02x %02x %02x %02x %02x %02x %02x %02x\n",
1741 // current_frame_buffer[i][j]->get_shmid(),
1742 // current_frame_buffer[i][j]->get_compressed_size(),
1743 // current_frame_buffer[i][j]->get_data()[0],
1744 // current_frame_buffer[i][j]->get_data()[1],
1745 // current_frame_buffer[i][j]->get_data()[2],
1746 // current_frame_buffer[i][j]->get_data()[3],
1747 // current_frame_buffer[i][j]->get_data()[4],
1748 // current_frame_buffer[i][j]->get_data()[5],
1749 // current_frame_buffer[i][j]->get_data()[6],
1750 // current_frame_buffer[i][j]->get_data()[7]);
1754 //printf("File::write_video_buffer %d\n", __LINE__);
1755 file_fork->send_command(FileFork::WRITE_VIDEO_BUFFER,
1758 //printf("File::write_video_buffer %d\n", __LINE__);
1759 int result = file_fork->read_result();
1760 //printf("File::write_video_buffer %d\n", __LINE__);
1768 result = video_thread->write_buffer(len);
1774 Samples** File::get_audio_buffer()
1779 FileForker this_is(*forked);
1780 file_fork->send_command(FileFork::GET_AUDIO_BUFFER, 0, 0);
1781 int result = file_fork->read_result();
1783 // Read parameters for a Samples buffer & create it in File
1784 // delete_temp_samples_buffer();
1785 // if(!temp_samples_buffer)
1787 // temp_samples_buffer = new Samples**[ring_buffers];
1788 // for(int i = 0; i < ring_buffers; i++) temp_samples_buffer[i] = 0;
1792 // temp_samples_buffer = new Samples*[asset->channels];
1793 // for(int i = 0; i < asset->channels; i++)
1795 // temp_samples_buffer[i] = new Samples;
1796 // temp_samples_buffer[i]->from_filefork(file_fork->result_data +
1797 // i * Samples::filefork_size());
1800 return temp_samples_buffer[result];
1804 if(audio_thread) return audio_thread->get_audio_buffer();
1808 VFrame*** File::get_video_buffer()
1813 FileForker this_is(*forked);
1815 file_fork->send_command(FileFork::GET_VIDEO_BUFFER, 0, 0);
1816 int result = file_fork->read_result();
1818 // Read parameters for a VFrame buffer & create it in File
1819 // delete_temp_frame_buffer();
1822 // temp_frame_size = *(int*)(file_fork->result_data +
1823 // file_fork->result_bytes -
1826 // //printf("File::get_video_buffer %d %p %d\n", __LINE__, this, asset->layers);
1827 // temp_frame_buffer = new VFrame**[asset->layers];
1829 // for(int i = 0; i < asset->layers; i++)
1832 // temp_frame_buffer[i] = new VFrame*[temp_frame_size];
1834 // for(int j = 0; j < temp_frame_size; j++)
1837 // temp_frame_buffer[i][j] = new VFrame;
1838 // printf("File::get_video_buffer %d %p\n", __LINE__, temp_frame_buffer[i][j]);
1840 // temp_frame_buffer[i][j]->from_filefork(file_fork->result_data +
1841 // i * temp_frame_size * VFrame::filefork_size() +
1842 // j * VFrame::filefork_size());
1848 current_frame_buffer = temp_frame_buffer[result];
1850 return current_frame_buffer;
1856 VFrame*** result = video_thread->get_video_buffer();
1865 int File::read_samples(Samples *samples, int64_t len)
1867 // Never try to read more samples than exist in the file
1868 if (current_sample + len > asset->audio_length) {
1869 len = asset->audio_length - current_sample;
1871 if(len <= 0) return 0;
1874 const int debug = 0;
1875 if(debug) PRINT_TRACE
1880 FileForker this_is(*forked);
1881 int buffer_bytes = Samples::filefork_size() + sizeof(int64_t);
1882 unsigned char buffer[buffer_bytes];
1883 samples->to_filefork(buffer);
1884 *(int64_t*)(buffer + Samples::filefork_size()) = len;
1885 if(debug) PRINT_TRACE
1886 file_fork->send_command(FileFork::READ_SAMPLES,
1889 if(debug) PRINT_TRACE
1890 int result = file_fork->read_result();
1893 if(result && !file_fork->child_running())
1896 result = open_file(preferences, asset, rd, wr);
1903 if(debug) PRINT_TRACE
1905 double *buffer = samples->get_data();
1907 int64_t base_samplerate = asset->sample_rate;
1911 // Resample recursively calls this with the asset sample rate
1912 if(base_samplerate == 0) base_samplerate = asset->sample_rate;
1914 if(debug) PRINT_TRACE
1915 result = file->read_samples(buffer, len);
1917 if(debug) PRINT_TRACE
1918 current_sample += len;
1920 normalized_sample += len;
1922 if(debug) PRINT_TRACE
1928 int File::read_frame(VFrame *frame, int is_thread)
1930 const int debug = 0;
1932 if(debug) PRINT_TRACE
1935 // is_thread is only true in the fork
1936 if(file_fork && !is_fork && !is_thread)
1938 FileForker this_is(*forked);
1939 unsigned char fork_buffer[VFrame::filefork_size()];
1940 if(debug) PRINT_TRACE
1942 frame->to_filefork(fork_buffer);
1943 file_fork->send_command(FileFork::READ_FRAME,
1945 VFrame::filefork_size());
1947 int result = file_fork->read_result();
1951 if(result && !file_fork->child_running())
1954 result = open_file(preferences, asset, rd, wr);
1958 frame->get_color_model() == BC_COMPRESSED)
1960 // Get compressed data from socket
1961 //printf("File::read_frame %d %d\n", __LINE__, file_fork->result_bytes);
1962 int header_size = sizeof(int) * 2;
1963 if(file_fork->result_bytes > header_size)
1965 //printf("File::read_frame %d %d\n", __LINE__, file_fork->result_bytes);
1966 frame->allocate_compressed_data(file_fork->result_bytes - header_size);
1967 frame->set_compressed_size(file_fork->result_bytes - header_size);
1968 frame->set_keyframe(*(int*)(file_fork->result_data + sizeof(int)));
1969 memcpy(frame->get_data(),
1970 file_fork->result_data + header_size,
1971 file_fork->result_bytes - header_size);
1974 // Get compressed data size
1976 frame->set_compressed_size(*(int*)file_fork->result_data);
1977 frame->set_keyframe(*(int*)(file_fork->result_data + sizeof(int)));
1978 //printf("File::read_frame %d %d\n", __LINE__, *(int*)(file_fork->result_data + sizeof(int)));
1987 //printf("File::read_frame %d\n", __LINE__);
1989 if(video_thread && !is_thread) return video_thread->read_frame(frame);
1991 //printf("File::read_frame %d\n", __LINE__);
1992 if(debug) PRINT_TRACE
1995 if(debug) PRINT_TRACE
1996 int supported_colormodel = colormodel_supported(frame->get_color_model());
1997 int advance_position = 1;
2000 if(use_cache && !is_fork &&
2001 frame_cache->get_frame(frame,
2006 // Can't advance position if cache used.
2007 //printf("File::read_frame %d\n", __LINE__);
2008 advance_position = 0;
2012 if(frame->get_color_model() != BC_COMPRESSED &&
2013 (supported_colormodel != frame->get_color_model() ||
2014 frame->get_w() != asset->width ||
2015 frame->get_h() != asset->height))
2018 // printf("File::read_frame %d\n", __LINE__);
2019 // Can't advance position here because it needs to be added to cache
2022 if(!temp_frame->params_match(asset->width, asset->height, supported_colormodel))
2029 // printf("File::read_frame %d\n", __LINE__);
2032 temp_frame = new VFrame(0,
2036 supported_colormodel,
2040 // printf("File::read_frame %d\n", __LINE__);
2041 temp_frame->copy_stacks(frame);
2042 file->read_frame(temp_frame);
2043 //for(int i = 0; i < 1000 * 1000; i++) ((float*)temp_frame->get_rows()[0])[i] = 1.0;
2044 // printf("File::read_frame %d %d %d %d %d %d\n",
2045 // temp_frame->get_color_model(),
2046 // temp_frame->get_w(),
2047 // temp_frame->get_h(),
2048 // frame->get_color_model(),
2051 BC_CModels::transfer(frame->get_rows(),
2052 temp_frame->get_rows(),
2056 temp_frame->get_y(),
2057 temp_frame->get_u(),
2058 temp_frame->get_v(),
2061 temp_frame->get_w(),
2062 temp_frame->get_h(),
2067 temp_frame->get_color_model(),
2068 frame->get_color_model(),
2070 temp_frame->get_w(),
2072 // printf("File::read_frame %d\n", __LINE__);
2076 // Can't advance position here because it needs to be added to cache
2077 //printf("File::read_frame %d\n", __LINE__);
2078 file->read_frame(frame);
2079 //for(int i = 0; i < 100 * 1000; i++) ((float*)frame->get_rows()[0])[i] = 1.0;
2082 //printf("File::read_frame %d use_cache=%d\n", __LINE__, use_cache);
2083 if(use_cache && !is_fork)
2084 frame_cache->put_frame(frame,
2085 current_frame, current_layer,
2086 asset->frame_rate, 1, 0);
2087 //printf("File::read_frame %d\n", __LINE__);
2089 if(advance_position) current_frame++;
2090 if(debug) PRINT_TRACE
2097 int File::can_copy_from(Asset *asset,
2102 if(!asset) return 0;
2107 FileForker this_is(*forked);
2109 asset->write(&xml, 1, "");
2110 xml.terminate_string();
2111 const char *xml_string = xml.string();
2112 long xml_length = strlen(xml_string);
2113 int buffer_size = xml_length + 1 +
2117 unsigned char *buffer = new unsigned char[buffer_size];
2118 *(int64_t*)(buffer) = position;
2119 *(int*)(buffer + sizeof(int64_t)) = output_w;
2120 *(int*)(buffer + sizeof(int64_t) + sizeof(int)) = output_h;
2128 file_fork->send_command(FileFork::CAN_COPY_FROM,
2131 int result = file_fork->read_result();
2139 return asset->width == output_w &&
2140 asset->height == output_h &&
2141 file->can_copy_from(asset, position);
2147 // Fill in queries about formats when adding formats here.
2150 int File::strtoformat(const char *format)
2152 return strtoformat(0, format);
2155 int File::strtoformat(ArrayList<PluginServer*> *plugindb, const char *format)
2157 if(!strcasecmp(format, _(AC3_NAME))) return FILE_AC3;
2158 if(!strcasecmp(format, _(SCENE_NAME))) return FILE_SCENE;
2159 if(!strcasecmp(format, _(WAV_NAME))) return FILE_WAV;
2160 if(!strcasecmp(format, _(PCM_NAME))) return FILE_PCM;
2161 if(!strcasecmp(format, _(AU_NAME))) return FILE_AU;
2162 if(!strcasecmp(format, _(AIFF_NAME))) return FILE_AIFF;
2163 if(!strcasecmp(format, _(SND_NAME))) return FILE_SND;
2164 if(!strcasecmp(format, _(PNG_NAME))) return FILE_PNG;
2165 if(!strcasecmp(format, _(PNG_LIST_NAME))) return FILE_PNG_LIST;
2166 if(!strcasecmp(format, _(TIFF_NAME))) return FILE_TIFF;
2167 if(!strcasecmp(format, _(TIFF_LIST_NAME))) return FILE_TIFF_LIST;
2168 if(!strcasecmp(format, _(JPEG_NAME))) return FILE_JPEG;
2169 if(!strcasecmp(format, _(JPEG_LIST_NAME))) return FILE_JPEG_LIST;
2170 if(!strcasecmp(format, _(EXR_NAME))) return FILE_EXR;
2171 if(!strcasecmp(format, _(EXR_LIST_NAME))) return FILE_EXR_LIST;
2172 if(!strcasecmp(format, _(FLAC_NAME))) return FILE_FLAC;
2173 if(!strcasecmp(format, _(CR2_NAME))) return FILE_CR2;
2174 if(!strcasecmp(format, _(CR2_LIST_NAME))) return FILE_CR2_LIST;
2175 if(!strcasecmp(format, _(MPEG_NAME))) return FILE_MPEG;
2176 if(!strcasecmp(format, _(AMPEG_NAME))) return FILE_AMPEG;
2177 if(!strcasecmp(format, _(VMPEG_NAME))) return FILE_VMPEG;
2178 if(!strcasecmp(format, _(TGA_NAME))) return FILE_TGA;
2179 if(!strcasecmp(format, _(TGA_LIST_NAME))) return FILE_TGA_LIST;
2180 if(!strcasecmp(format, _(MOV_NAME))) return FILE_MOV;
2181 if(!strcasecmp(format, _(AVI_NAME))) return FILE_AVI;
2182 if(!strcasecmp(format, _(AVI_LAVTOOLS_NAME))) return FILE_AVI_LAVTOOLS;
2183 if(!strcasecmp(format, _(AVI_ARNE2_NAME))) return FILE_AVI_ARNE2;
2184 if(!strcasecmp(format, _(AVI_ARNE1_NAME))) return FILE_AVI_ARNE1;
2185 if(!strcasecmp(format, _(AVI_AVIFILE_NAME))) return FILE_AVI_AVIFILE;
2186 if(!strcasecmp(format, _(OGG_NAME))) return FILE_OGG;
2187 if(!strcasecmp(format, _(VORBIS_NAME))) return FILE_VORBIS;
2188 if(!strcasecmp(format, _(RAWDV_NAME))) return FILE_RAWDV;
2189 if(!strcasecmp(format, _(FFMPEG_NAME))) return FILE_FFMPEG;
2190 if(!strcasecmp(format, _(DBASE_NAME))) return FILE_DB;
2196 const char* File::formattostr(int format)
2198 return formattostr(0, format);
2201 const char* File::formattostr(ArrayList<PluginServer*> *plugindb, int format)
2205 case FILE_SCENE: return _(SCENE_NAME);
2206 case FILE_AC3: return _(AC3_NAME);
2207 case FILE_WAV: return _(WAV_NAME);
2208 case FILE_PCM: return _(PCM_NAME);
2209 case FILE_AU: return _(AU_NAME);
2210 case FILE_AIFF: return _(AIFF_NAME);
2211 case FILE_SND: return _(SND_NAME);
2212 case FILE_PNG: return _(PNG_NAME);
2213 case FILE_PNG_LIST: return _(PNG_LIST_NAME);
2214 case FILE_JPEG: return _(JPEG_NAME);
2215 case FILE_JPEG_LIST: return _(JPEG_LIST_NAME);
2216 case FILE_CR2: return _(CR2_NAME);
2217 case FILE_CR2_LIST: return _(CR2_LIST_NAME);
2218 case FILE_FLAC: return _(FLAC_NAME);
2219 case FILE_EXR: return _(EXR_NAME);
2220 case FILE_EXR_LIST: return _(EXR_LIST_NAME);
2221 case FILE_MPEG: return _(MPEG_NAME);
2222 case FILE_AMPEG: return _(AMPEG_NAME);
2223 case FILE_VMPEG: return _(VMPEG_NAME);
2224 case FILE_TGA: return _(TGA_NAME);
2225 case FILE_TGA_LIST: return _(TGA_LIST_NAME);
2226 case FILE_TIFF: return _(TIFF_NAME);
2227 case FILE_TIFF_LIST: return _(TIFF_LIST_NAME);
2228 case FILE_MOV: return _(MOV_NAME);
2229 case FILE_AVI_LAVTOOLS: return _(AVI_LAVTOOLS_NAME);
2230 case FILE_AVI: return _(AVI_NAME);
2231 case FILE_AVI_ARNE2: return _(AVI_ARNE2_NAME);
2232 case FILE_AVI_ARNE1: return _(AVI_ARNE1_NAME);
2233 case FILE_AVI_AVIFILE: return _(AVI_AVIFILE_NAME);
2234 case FILE_OGG: return _(OGG_NAME);
2235 case FILE_VORBIS: return _(VORBIS_NAME);
2236 case FILE_RAWDV: return _(RAWDV_NAME);
2237 case FILE_FFMPEG: return _(FFMPEG_NAME);
2238 case FILE_DB: return _(DBASE_NAME);
2243 int File::strtobits(const char *bits)
2245 if(!strcasecmp(bits, _(NAME_8BIT))) return BITSLINEAR8;
2246 if(!strcasecmp(bits, _(NAME_16BIT))) return BITSLINEAR16;
2247 if(!strcasecmp(bits, _(NAME_24BIT))) return BITSLINEAR24;
2248 if(!strcasecmp(bits, _(NAME_32BIT))) return BITSLINEAR32;
2249 if(!strcasecmp(bits, _(NAME_ULAW))) return BITSULAW;
2250 if(!strcasecmp(bits, _(NAME_ADPCM))) return BITS_ADPCM;
2251 if(!strcasecmp(bits, _(NAME_FLOAT))) return BITSFLOAT;
2252 if(!strcasecmp(bits, _(NAME_IMA4))) return BITSIMA4;
2253 return BITSLINEAR16;
2256 const char* File::bitstostr(int bits)
2258 //printf("File::bitstostr\n");
2261 case BITSLINEAR8: return (NAME_8BIT);
2262 case BITSLINEAR16: return (NAME_16BIT);
2263 case BITSLINEAR24: return (NAME_24BIT);
2264 case BITSLINEAR32: return (NAME_32BIT);
2265 case BITSULAW: return (NAME_ULAW);
2266 case BITS_ADPCM: return (NAME_ADPCM);
2267 case BITSFLOAT: return (NAME_FLOAT);
2268 case BITSIMA4: return (NAME_IMA4);
2275 int File::str_to_byteorder(const char *string)
2277 if(!strcasecmp(string, _("Lo Hi"))) return 1;
2281 const char* File::byteorder_to_str(int byte_order)
2283 if(byte_order) return _("Lo Hi");
2287 int File::bytes_per_sample(int bits)
2291 case BITSLINEAR8: return 1;
2292 case BITSLINEAR16: return 2;
2293 case BITSLINEAR24: return 3;
2294 case BITSLINEAR32: return 4;
2295 case BITSULAW: return 1;
2296 case BITSIMA4: return 1;
2305 int File::get_best_colormodel(int driver)
2307 return get_best_colormodel(asset, driver);
2310 int File::get_best_colormodel(Asset *asset, int driver)
2312 switch(asset->format)
2314 case FILE_RAWDV: return FileDV::get_best_colormodel(asset, driver);
2315 case FILE_MOV: return FileMOV::get_best_colormodel(asset, driver);
2316 case FILE_AVI: return FileMOV::get_best_colormodel(asset, driver);
2317 case FILE_MPEG: return FileMPEG::get_best_colormodel(asset, driver);
2319 case FILE_JPEG_LIST: return FileJPEG::get_best_colormodel(asset, driver);
2321 case FILE_EXR_LIST: return FileEXR::get_best_colormodel(asset, driver);
2323 case FILE_PNG_LIST: return FilePNG::get_best_colormodel(asset, driver);
2325 case FILE_TGA_LIST: return FileTGA::get_best_colormodel(asset, driver);
2327 case FILE_CR2_LIST: return FileCR2::get_best_colormodel(asset, driver);
2328 case FILE_DB: return FileDB::get_best_colormodel(asset, driver);
2335 int File::colormodel_supported(int colormodel)
2340 FileForker this_is(*forked);
2341 unsigned char buffer[sizeof(int)];
2342 int *ibfr = (int *)buffer;
2343 ibfr[0] = colormodel;
2345 file_fork->send_command(FileFork::COLORMODEL_SUPPORTED,
2348 int result = file_fork->read_result();
2355 return file->colormodel_supported(colormodel);
2361 int64_t File::file_memory_usage()
2363 return file ? file->base_memory_usage() : 0;
2366 int64_t File::get_memory_usage()
2373 FileForker this_is(*forked);
2374 file_fork->send_command(FileFork::FILE_MEMORY_USAGE, 0, 0);
2375 result = file_fork->read_result();
2379 result += file_memory_usage();
2380 if(temp_frame) result += temp_frame->get_data_size();
2381 result += frame_cache->get_memory_usage();
2382 if(video_thread) result += video_thread->get_memory_usage();
2384 if(result < MIN_CACHEITEM_SIZE) result = MIN_CACHEITEM_SIZE;
2389 int File::supports_video(ArrayList<PluginServer*> *plugindb, char *format)
2391 int format_i = strtoformat(plugindb, format);
2393 return supports_video(format_i);
2397 int File::supports_audio(ArrayList<PluginServer*> *plugindb, char *format)
2399 int format_i = strtoformat(plugindb, format);
2401 return supports_audio(format_i);
2406 int File::supports_video(int format)
2408 //printf("File::supports_video %d\n", format);
2414 case FILE_JPEG_LIST:
2424 case FILE_TIFF_LIST:
2426 case FILE_AVI_LAVTOOLS:
2427 case FILE_AVI_ARNE2:
2429 case FILE_AVI_ARNE1:
2430 case FILE_AVI_AVIFILE:
2438 int File::supports_audio(int format)
2454 case FILE_AVI_LAVTOOLS:
2455 case FILE_AVI_ARNE2:
2456 case FILE_AVI_ARNE1:
2457 case FILE_AVI_AVIFILE:
2464 const char* File::get_tag(int format)
2468 case FILE_AC3: return "ac3";
2469 case FILE_AIFF: return "aif";
2470 case FILE_AMPEG: return "mp3";
2471 case FILE_AU: return "au";
2472 case FILE_AVI: return "avi";
2473 case FILE_RAWDV: return "dv";
2474 case FILE_DB: return "db";
2475 case FILE_EXR: return "exr";
2476 case FILE_EXR_LIST: return "exr";
2477 case FILE_FLAC: return "flac";
2478 case FILE_JPEG: return "jpg";
2479 case FILE_JPEG_LIST: return "jpg";
2480 case FILE_MOV: return "mov/mp4";
2481 case FILE_OGG: return "ogg";
2482 case FILE_PCM: return "pcm";
2483 case FILE_PNG: return "png";
2484 case FILE_PNG_LIST: return "png";
2485 case FILE_TGA: return "tga";
2486 case FILE_TGA_LIST: return "tga";
2487 case FILE_TIFF: return "tif";
2488 case FILE_TIFF_LIST: return "tif";
2489 case FILE_VMPEG: return "m2v";
2490 case FILE_VORBIS: return "ogg";
2491 case FILE_WAV: return "wav";
2492 case FILE_FFMPEG: return "media";
2497 const char* File::get_prefix(int format)
2500 case FILE_PCM: return "PCM";
2501 case FILE_WAV: return "WAV";
2502 case FILE_MOV: return "MOV";
2503 case FILE_PNG: return "PNG";
2504 case FILE_JPEG: return "JPEG";
2505 case FILE_TIFF: return "TIFF";
2506 case FILE_GIF: return "GIF";
2507 case FILE_JPEG_LIST: return "JPEG_LIST";
2508 case FILE_AU: return "AU";
2509 case FILE_AIFF: return "AIFF";
2510 case FILE_SND: return "SND";
2511 case FILE_AVI_LAVTOOLS: return "AVI_LAVTOOLS";
2512 case FILE_TGA_LIST: return "TGA_LIST";
2513 case FILE_TGA: return "TGA";
2514 case FILE_MPEG: return "MPEG";
2515 case FILE_AMPEG: return "AMPEG";
2516 case FILE_VMPEG: return "VMPEG";
2517 case FILE_RAWDV: return "RAWDV";
2518 case FILE_AVI_ARNE2: return "AVI_ARNE2";
2519 case FILE_AVI_ARNE1: return "AVI_ARNE1";
2520 case FILE_AVI_AVIFILE: return "AVI_AVIFILE";
2521 case FILE_TIFF_LIST: return "TIFF_LIST";
2522 case FILE_PNG_LIST: return "PNG_LIST";
2523 case FILE_AVI: return "AVI";
2524 case FILE_AC3: return "AC3";
2525 case FILE_EXR: return "EXR";
2526 case FILE_EXR_LIST: return "EXR_LIST";
2527 case FILE_CR2: return "CR2";
2528 case FILE_OGG: return "OGG";
2529 case FILE_VORBIS: return "VORBIS";
2530 case FILE_FLAC: return "FLAC";
2531 case FILE_FFMPEG: return "FFMPEG";
2532 case FILE_SCENE: return "SCENE";
2533 case FILE_CR2_LIST: return "CR2_LIST";
2534 case FILE_GIF_LIST: return "GIF_LIST";
2535 case FILE_DB: return "DB";
2541 PackagingEngine *File::new_packaging_engine(Asset *asset)
2543 PackagingEngine *result;
2544 switch (asset->format)
2547 result = (PackagingEngine*)new PackagingEngineOGG();
2550 result = (PackagingEngine*) new PackagingEngineDefault();
2558 int File::record_fd()
2560 return file ? file->record_fd() : -1;