update po files, plus a few fixes and improvements
[goodguy/history.git] / cinelerra-5.1 / cinelerra / file.C
1 /*
2  * CINELERRA
3  * Copyright (C) 2010 Adam Williams <broadcast at earthling dot net>
4  *
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.
9  *
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.
14  *
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
18  *
19  */
20
21 #include <stdio.h>
22 #include <stdint.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <string.h>
26 #include <stdarg.h>
27 #include <ctype.h>
28 #include <limits.h>
29 // work arounds (centos)
30 #include <lzma.h>
31 #ifndef INT64_MAX
32 #define INT64_MAX 9223372036854775807LL
33 #endif
34
35 #include "asset.h"
36 #include "bchash.h"
37 #include "bcsignals.h"
38 #include "byteorder.h"
39 #include "cache.inc"
40 #include "condition.h"
41 #include "errorbox.h"
42 #include "fileac3.h"
43 #include "filebase.h"
44 #include "filecr2.h"
45 #include "filedb.h"
46 #include "filedv.h"
47 #include "fileexr.h"
48 #include "fileffmpeg.h"
49 #include "fileflac.h"
50 #include "filegif.h"
51 #include "file.h"
52 #include "filejpeg.h"
53 #include "filempeg.h"
54 #undef HAVE_STDLIB_H // automake conflict
55 #include "fileogg.h"
56 #include "filepng.h"
57 #include "filescene.h"
58 #include "filesndfile.h"
59 #include "filetga.h"
60 #include "filethread.h"
61 #include "filetiff.h"
62 #include "filevorbis.h"
63 #include "filexml.h"
64 #include "formatwindow.h"
65 #include "formattools.h"
66 #include "framecache.h"
67 #include "language.h"
68 #include "mainprogress.inc"
69 #include "mutex.h"
70 #include "mwindow.h"
71 #include "packagingengine.h"
72 #include "pluginserver.h"
73 #include "preferences.h"
74 #include "samples.h"
75 #include "vframe.h"
76
77 //suppress noref warning
78 void *vorbis0_ov_callbacks[] = {
79  &OV_CALLBACKS_DEFAULT, &OV_CALLBACKS_NOCLOSE,
80  &OV_CALLBACKS_STREAMONLY, &OV_CALLBACKS_STREAMONLY_NOCLOSE,
81 };
82
83 File::File()
84 {
85         cpus = 1;
86         asset = new Asset;
87         format_completion = new Condition(1, "File::format_completion");
88         write_lock = new Condition(1, "File::write_lock");
89         frame_cache = new FrameCache;
90         reset_parameters();
91 }
92
93 File::~File()
94 {
95         if(getting_options)
96         {
97                 if(format_window) format_window->set_done(0);
98                 format_completion->lock("File::~File");
99                 format_completion->unlock();
100         }
101
102         if(temp_frame) delete temp_frame;
103
104
105         close_file(0);
106
107         asset->Garbage::remove_user();
108         delete format_completion;
109         delete write_lock;
110         delete frame_cache;
111 }
112
113 void File::reset_parameters()
114 {
115         file = 0;
116         audio_thread = 0;
117         video_thread = 0;
118         getting_options = 0;
119         format_window = 0;
120         temp_frame = 0;
121         current_sample = 0;
122         current_frame = 0;
123         current_channel = 0;
124         current_program = 0;
125         current_layer = 0;
126         normalized_sample = 0;
127         use_cache = 0;
128         preferences = 0;
129         playback_subtitle = -1;
130         interpolate_raw = 1;
131
132
133         temp_samples_buffer = 0;
134         temp_frame_buffer = 0;
135         current_frame_buffer = 0;
136         audio_ring_buffers = 0;
137         video_ring_buffers = 0;
138         video_buffer_size = 0;
139 }
140
141 int File::raise_window()
142 {
143         if(getting_options && format_window)
144         {
145                 format_window->raise_window();
146                 format_window->flush();
147         }
148         return 0;
149 }
150
151 void File::close_window()
152 {
153         if(getting_options)
154         {
155                 format_window->lock_window("File::close_window");
156                 format_window->set_done(1);
157                 format_window->unlock_window();
158                 getting_options = 0;
159         }
160 }
161
162 int File::get_options(FormatTools *format,
163         int audio_options, int video_options)
164 {
165         BC_WindowBase *parent_window = format->window;
166         //ArrayList<PluginServer*> *plugindb = format->plugindb;
167         Asset *asset = format->asset;
168
169         getting_options = 1;
170         format_completion->lock("File::get_options");
171         switch(asset->format)
172         {
173                 case FILE_AC3:
174                         FileAC3::get_parameters(parent_window,
175                                 asset,
176                                 format_window,
177                                 audio_options,
178                                 video_options);
179                         break;
180                 case FILE_RAWDV:
181                         FileDV::get_parameters(parent_window,
182                                 asset,
183                                 format_window,
184                                 audio_options,
185                                 video_options);
186                         break;
187                 case FILE_PCM:
188                 case FILE_WAV:
189                 case FILE_AU:
190                 case FILE_AIFF:
191                 case FILE_SND:
192                         FileSndFile::get_parameters(parent_window,
193                                 asset,
194                                 format_window,
195                                 audio_options,
196                                 video_options);
197                         break;
198                 case FILE_FFMPEG:
199                         FileFFMPEG::get_parameters(parent_window,
200                                 asset,
201                                 format_window,
202                                 audio_options,
203                                 video_options);
204                         break;
205                 case FILE_AMPEG:
206                 case FILE_VMPEG:
207                         FileMPEG::get_parameters(parent_window,
208                                 asset,
209                                 format_window,
210                                 audio_options,
211                                 video_options);
212                         break;
213                 case FILE_JPEG:
214                 case FILE_JPEG_LIST:
215                         FileJPEG::get_parameters(parent_window,
216                                 asset,
217                                 format_window,
218                                 audio_options,
219                                 video_options);
220                         break;
221                 case FILE_EXR:
222                 case FILE_EXR_LIST:
223                         FileEXR::get_parameters(parent_window,
224                                 asset,
225                                 format_window,
226                                 audio_options,
227                                 video_options);
228                         break;
229                 case FILE_FLAC:
230                         FileFLAC::get_parameters(parent_window,
231                                 asset,
232                                 format_window,
233                                 audio_options,
234                                 video_options);
235                         break;
236                 case FILE_PNG:
237                 case FILE_PNG_LIST:
238                         FilePNG::get_parameters(parent_window,
239                                 asset,
240                                 format_window,
241                                 audio_options,
242                                 video_options);
243                         break;
244                 case FILE_TGA:
245                 case FILE_TGA_LIST:
246                         FileTGA::get_parameters(parent_window,
247                                 asset,
248                                 format_window,
249                                 audio_options,
250                                 video_options);
251                         break;
252                 case FILE_TIFF:
253                 case FILE_TIFF_LIST:
254                         FileTIFF::get_parameters(parent_window,
255                                 asset,
256                                 format_window,
257                                 audio_options,
258                                 video_options);
259                         break;
260                 case FILE_OGG:
261                         FileOGG::get_parameters(parent_window,
262                                 asset,
263                                 format_window,
264                                 audio_options,
265                                 video_options);
266                         break;
267                 default:
268                         break;
269         }
270
271         if(!format_window)
272         {
273                 ErrorBox *errorbox = new ErrorBox(_(PROGRAM_NAME ": Error"),
274                         parent_window->get_abs_cursor_x(1),
275                         parent_window->get_abs_cursor_y(1));
276                 format_window = errorbox;
277                 getting_options = 1;
278                 if(audio_options)
279                         errorbox->create_objects(_("This format doesn't support audio."));
280                 else
281                 if(video_options)
282                         errorbox->create_objects(_("This format doesn't support video."));
283                 errorbox->run_window();
284                 delete errorbox;
285         }
286
287         getting_options = 0;
288         format_window = 0;
289         format_completion->unlock();
290         return 0;
291 }
292
293
294
295
296
297
298
299
300
301
302 int File::set_processors(int cpus)   // Set the number of cpus for certain codecs
303 {
304         if( cpus > 8 )          // mpegvideo max_threads = 16, more causes errs
305                 cpus = 8;       //  8 cpus ought to decode just about anything
306 // Set all instances so gets work.
307         this->cpus = cpus;
308
309         return 0;
310 }
311
312 int File::set_preload(int64_t size)
313 {
314         this->playback_preload = size;
315         return 0;
316 }
317
318 void File::set_subtitle(int value)
319 {
320         this->playback_subtitle = value;
321         if( file ) file->set_subtitle(value);
322 }
323
324 void File::set_interpolate_raw(int value)
325 {
326         this->interpolate_raw = value;
327 }
328
329 void File::set_white_balance_raw(int value)
330 {
331         this->white_balance_raw = value;
332 }
333
334
335 void File::set_cache_frames(int value)
336 {
337 // caching only done locally
338         if(!video_thread)
339                 use_cache = value;
340 }
341
342 int File::purge_cache()
343 {
344 // caching only done locally
345         int result = 0;
346         if( frame_cache->cache_items() > 0 )
347         {
348                 frame_cache->remove_all();
349                 result = 1;
350         }
351         return result;
352 }
353
354 int File::delete_oldest()
355 {
356 // caching only done locally
357         return frame_cache->delete_oldest();
358 }
359
360
361
362
363
364
365
366
367
368
369
370 int File::open_file(Preferences *preferences,
371         Asset *asset,
372         int rd,
373         int wr)
374 {
375         const int debug = 0;
376
377         this->preferences = preferences;
378         this->asset->copy_from(asset, 1);
379         this->rd = rd;
380         this->wr = wr;
381         file = 0;
382
383         if(debug) printf("File::open_file %d\n", __LINE__);
384
385         if(debug) printf("File::open_file %p %d\n", this, __LINE__);
386
387         switch(this->asset->format)
388         {
389 // get the format now
390 // If you add another format to case 0, you also need to add another case for the
391 // file format #define.
392                 case FILE_UNKNOWN:
393                         if(FileDB::check_sig(this->asset)) {
394 // MediaDb file
395                                 file = new FileDB(this->asset, this);
396                                 break;
397                         }
398 // if early probe enabled
399                         if( preferences->ffmpeg_early_probe &&
400                             FileFFMPEG::check_sig(this->asset)) {
401                                 file = new FileFFMPEG(this->asset, this);
402                                 break;
403                         }
404
405                         FILE *stream;
406                         if(!(stream = fopen(this->asset->path, "rb"))) {
407 // file not found
408                                 return 1;
409                         }
410
411                         char test[16];  memset(test,0,sizeof(test)); // int result =
412                         fread(test, 16, 1, stream);
413
414                         if(FileScene::check_sig(this->asset, test)) {
415 // scene file
416                                 fclose(stream);
417                                 file = new FileScene(this->asset, this);
418                                 break;
419                         }
420                         if(FileDV::check_sig(this->asset)) {
421 // libdv
422                                 fclose(stream);
423                                 file = new FileDV(this->asset, this);
424                                 break;
425                         }
426                         if(FileSndFile::check_sig(this->asset)) {
427 // libsndfile
428                                 fclose(stream);
429                                 file = new FileSndFile(this->asset, this);
430                                 break;
431                         }
432                         if(FilePNG::check_sig(this->asset)) {
433 // PNG file
434                                 fclose(stream);
435                                 file = new FilePNG(this->asset, this);
436                                 break;
437                         }
438                         if(FileJPEG::check_sig(this->asset)) {
439 // JPEG file
440                                 fclose(stream);
441                                 file = new FileJPEG(this->asset, this);
442                                 break;
443                         }
444                         if(FileGIF::check_sig(this->asset)) {
445 // GIF file
446                                 fclose(stream);
447                                 file = new FileGIF(this->asset, this);
448                                 break;
449                         }
450                         if(FileEXR::check_sig(this->asset, test)) {
451 // EXR file
452                                 fclose(stream);
453                                 file = new FileEXR(this->asset, this);
454                                 break;
455                         }
456                         if(FileFLAC::check_sig(this->asset, test)) {
457 // FLAC file
458                                 fclose(stream);
459                                 file = new FileFLAC(this->asset, this);
460                                 break;
461                         }
462                         if(FileCR2::check_sig(this->asset)) {
463 // CR2 file
464                                 fclose(stream);
465                                 file = new FileCR2(this->asset, this);
466                                 break;
467                         }
468                         if(FileTGA::check_sig(this->asset)) {
469 // TGA file
470                                 fclose(stream);
471                                 file = new FileTGA(this->asset, this);
472                                 break;
473                         }
474                         if(FileTIFF::check_sig(this->asset)) {
475 // TIFF file
476                                 fclose(stream);
477                                 file = new FileTIFF(this->asset, this);
478                                 break;
479                         }
480                         if(FileOGG::check_sig(this->asset)) {
481 // OGG file
482                                 fclose(stream);
483                                 file = new FileOGG(this->asset, this);
484                                 break;
485                         }
486                         if(FileVorbis::check_sig(this->asset)) {
487 // VorbisFile file
488                                 fclose(stream);
489                                 file = new FileVorbis(this->asset, this);
490                                 break;
491                         }
492                         if(FileMPEG::check_sig(this->asset)) {
493 // MPEG file
494                                 fclose(stream);
495                                 file = new FileMPEG(this->asset, this);
496                                 break;
497                         }
498                         if( test[0] == '<' && (
499                                 !strncmp(&test[1],"EDL>",4) ||
500                                 !strncmp(&test[1],"HTAL>",5) ||
501                                 !strncmp(&test[1],"?xml",4) ) ) {
502 // XML file
503                                 fclose(stream);
504                                 return FILE_IS_XML;
505                         }    // can't load project file
506                         if( !preferences->ffmpeg_early_probe &&
507                             FileFFMPEG::check_sig(this->asset) ) {
508                                 fclose(stream);
509                                 file = new FileFFMPEG(this->asset, this);
510                                 break;
511                         }
512 // PCM file
513                         fclose(stream);
514                         return FILE_UNRECOGNIZED_CODEC;
515                         break;
516
517 // format already determined
518                 case FILE_AC3:
519                         file = new FileAC3(this->asset, this);
520                         break;
521
522                 case FILE_SCENE:
523                         file = new FileScene(this->asset, this);
524                         break;
525
526                 case FILE_FFMPEG:
527                         file = new FileFFMPEG(this->asset, this);
528                         break;
529
530                 case FILE_PCM:
531                 case FILE_WAV:
532                 case FILE_AU:
533                 case FILE_AIFF:
534                 case FILE_SND:
535 //printf("File::open_file 1\n");
536                         file = new FileSndFile(this->asset, this);
537                         break;
538
539                 case FILE_PNG:
540                 case FILE_PNG_LIST:
541                         file = new FilePNG(this->asset, this);
542                         break;
543
544                 case FILE_JPEG:
545                 case FILE_JPEG_LIST:
546                         file = new FileJPEG(this->asset, this);
547                         break;
548
549                 case FILE_GIF:
550                 case FILE_GIF_LIST:
551                         file = new FileGIF(this->asset, this);
552                         break;
553
554                 case FILE_EXR:
555                 case FILE_EXR_LIST:
556                         file = new FileEXR(this->asset, this);
557                         break;
558
559                 case FILE_FLAC:
560                         file = new FileFLAC(this->asset, this);
561                         break;
562
563                 case FILE_CR2:
564                 case FILE_CR2_LIST:
565                         file = new FileCR2(this->asset, this);
566                         break;
567
568                 case FILE_TGA_LIST:
569                 case FILE_TGA:
570                         file = new FileTGA(this->asset, this);
571                         break;
572
573                 case FILE_TIFF:
574                 case FILE_TIFF_LIST:
575                         file = new FileTIFF(this->asset, this);
576                         break;
577
578                 case FILE_DB:
579                         file = new FileDB(this->asset, this);
580                         break;
581
582                 case FILE_MPEG:
583                 case FILE_AMPEG:
584                 case FILE_VMPEG:
585                         file = new FileMPEG(this->asset, this);
586                         break;
587
588                 case FILE_OGG:
589                         file = new FileOGG(this->asset, this);
590                         break;
591
592                 case FILE_VORBIS:
593                         file = new FileVorbis(this->asset, this);
594                         break;
595
596                 case FILE_RAWDV:
597                         file = new FileDV(this->asset, this);
598                         break;
599
600 // try plugins
601                 default:
602                         return 1;
603                         break;
604         }
605
606
607 // Reopen file with correct parser and get header.
608         if(file->open_file(rd, wr)) {
609                 delete file;  file = 0;
610                 return FILE_NOT_FOUND;
611         }
612
613
614
615 // Set extra writing parameters to mandatory settings.
616         if( wr ) {
617                 if(this->asset->dither) file->set_dither();
618         }
619
620         if( rd ) {
621 // one frame image file, no specific length
622                 if( !this->asset->audio_data && this->asset->video_data &&
623                     this->asset->video_length <= 1 )
624                         this->asset->video_length = -1;
625         }
626
627 // Synchronize header parameters
628         asset->copy_from(this->asset, 1);
629 //asset->dump();
630
631         if(debug) printf("File::open_file %d file=%p\n", __LINE__, file);
632 // sleep(1);
633
634         return FILE_OK;
635 }
636
637 void File::delete_temp_samples_buffer()
638 {
639
640         if(temp_samples_buffer) {
641                 for(int j = 0; j < audio_ring_buffers; j++) {
642                         for(int i = 0; i < asset->channels; i++) {
643                                 delete temp_samples_buffer[j][i];
644                         }
645                         delete [] temp_samples_buffer[j];
646                 }
647
648                 delete [] temp_samples_buffer;
649                 temp_samples_buffer = 0;
650                 audio_ring_buffers = 0;
651         }
652 }
653
654 void File::delete_temp_frame_buffer()
655 {
656
657         if(temp_frame_buffer) {
658                 for(int k = 0; k < video_ring_buffers; k++) {
659                         for(int i = 0; i < asset->layers; i++) {
660                                 for(int j = 0; j < video_buffer_size; j++) {
661                                         delete temp_frame_buffer[k][i][j];
662                                 }
663                                 delete [] temp_frame_buffer[k][i];
664                         }
665                         delete [] temp_frame_buffer[k];
666                 }
667
668                 delete [] temp_frame_buffer;
669                 temp_frame_buffer = 0;
670                 video_ring_buffers = 0;
671                 video_buffer_size = 0;
672         }
673 }
674
675 int File::close_file(int ignore_thread)
676 {
677         const int debug = 0;
678
679         if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
680
681         if(!ignore_thread) {
682                 stop_audio_thread();
683                 stop_video_thread();
684         }
685
686
687         if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
688         if(file) {
689 // The file's asset is a copy of the argument passed to open_file so the
690 // user must copy lengths from the file's asset.
691                 if(asset && wr) {
692                         asset->audio_length = current_sample;
693                         asset->video_length = current_frame;
694                 }
695
696                 file->close_file();
697                 delete file;
698         }
699         if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
700
701         delete_temp_samples_buffer();
702         delete_temp_frame_buffer();
703         if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
704
705         if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
706
707         reset_parameters();
708         if(debug) printf("File::close_file file=%p %d\n", file, __LINE__);
709         return 0;
710 }
711
712
713
714 int File::get_index(IndexFile *index_file, MainProgressBar *progress_bar)
715 {
716         return !file ? -1 : file->get_index(index_file, progress_bar);
717 }
718
719
720
721 int File::start_audio_thread(int buffer_size, int ring_buffers)
722 {
723         this->audio_ring_buffers = ring_buffers;
724
725
726         if(!audio_thread)
727         {
728                 audio_thread = new FileThread(this, 1, 0);
729                 audio_thread->start_writing(buffer_size, 0, ring_buffers, 0);
730         }
731         return 0;
732 }
733
734 int File::start_video_thread(int buffer_size,
735         int color_model,
736         int ring_buffers,
737         int compressed)
738 {
739         this->video_ring_buffers = ring_buffers;
740         this->video_buffer_size = buffer_size;
741
742         if(!video_thread)
743         {
744                 video_thread = new FileThread(this, 0, 1);
745                 video_thread->start_writing(buffer_size,
746                         color_model,
747                         ring_buffers,
748                         compressed);
749         }
750         return 0;
751 }
752
753 int File::start_video_decode_thread()
754 {
755 // Currently, CR2 is the only one which won't work asynchronously, so
756 // we're not using a virtual function yet.
757         if(!video_thread /* && asset->format != FILE_CR2 */)
758         {
759                 video_thread = new FileThread(this, 0, 1);
760                 video_thread->start_reading();
761                 use_cache = 0;
762         }
763         return 0;
764 }
765
766 int File::stop_audio_thread()
767 {
768         if(audio_thread)
769         {
770                 audio_thread->stop_writing();
771                 delete audio_thread;
772                 audio_thread = 0;
773         }
774         return 0;
775 }
776
777 int File::stop_video_thread()
778 {
779         if(video_thread)
780         {
781                 video_thread->stop_reading();
782                 video_thread->stop_writing();
783                 delete video_thread;
784                 video_thread = 0;
785         }
786         return 0;
787 }
788
789 FileThread* File::get_video_thread()
790 {
791         return video_thread;
792 }
793
794 int File::set_channel(int channel)
795 {
796         if(file && channel < asset->channels)
797         {
798                 current_channel = channel;
799                 return 0;
800         }
801         else
802                 return 1;
803 }
804
805 int File::get_channel()
806 {
807         return current_channel;
808 }
809
810 // if no>=0, sets new program
811 //  returns current program
812 int File::set_program(int no)
813 {
814         int result = file ? file->set_program(no) : current_program;
815         current_program = no < 0 ? result : no;
816         return result;
817 }
818
819 int File::get_cell_time(int no, double &time)
820 {
821         return file ? file->get_cell_time(no, time) : -1;
822 }
823
824 int File::get_system_time(int64_t &tm)
825 {
826         return file ? file->get_system_time(tm) : -1;
827 }
828
829 int File::get_audio_for_video(int vstream, int astream, int64_t &channel_mask)
830 {
831         return file ? file->get_audio_for_video(vstream, astream, channel_mask) : -1;
832 }
833
834 int File::get_video_pid(int track)
835 {
836         return file ? file->get_video_pid(track) : -1;
837 }
838
839
840
841 int File::get_video_info(int track, int &pid, double &framerate,
842                 int &width, int &height, char *title)
843 {
844         return !file ? -1 :
845                  file->get_video_info(track, pid, framerate, width, height, title);
846 }
847
848 int File::select_video_stream(Asset *asset, int vstream)
849 {
850         return !file ? -1 :
851                  file->select_video_stream(asset, vstream);
852 }
853
854 int File::select_audio_stream(Asset *asset, int astream)
855 {
856         return !file ? -1 :
857                  file->select_audio_stream(asset, astream);
858 }
859
860
861 int File::get_thumbnail(int stream,
862         int64_t &position, unsigned char *&thumbnail, int &ww, int &hh)
863 {
864         return file->get_thumbnail(stream, position, thumbnail, ww, hh);
865 }
866
867 int File::set_skimming(int track, int skim, skim_fn fn, void *vp)
868 {
869         return file->set_skimming(track, skim, fn, vp);
870 }
871
872 int File::skim_video(int track, void *vp, skim_fn fn)
873 {
874         return file->skim_video(track, vp, fn);
875 }
876
877
878 int File::set_layer(int layer, int is_thread)
879 {
880         if(file && layer < asset->layers)
881         {
882                 if(!is_thread && video_thread)
883                 {
884                         video_thread->set_layer(layer);
885                 }
886                 else
887                 {
888                         current_layer = layer;
889                 }
890                 return 0;
891         }
892         else
893                 return 1;
894 }
895
896 int64_t File::get_audio_length()
897 {
898         int64_t result = asset->audio_length;
899         int64_t base_samplerate = -1;
900         if(result > 0)
901         {
902                 if(base_samplerate > 0)
903                         return (int64_t)((double)result / asset->sample_rate * base_samplerate + 0.5);
904                 else
905                         return result;
906         }
907         else
908                 return -1;
909 }
910
911 int64_t File::get_video_length()
912 {
913         int64_t result = asset->video_length;
914         float base_framerate = -1;
915         if(result > 0)
916         {
917                 if(base_framerate > 0)
918                         return (int64_t)((double)result / asset->frame_rate * base_framerate + 0.5);
919                 else
920                         return result;
921         }
922         else
923                 return -1;  // infinity
924 }
925
926
927 int64_t File::get_video_position()
928 {
929         float base_framerate = -1;
930         if(base_framerate > 0)
931                 return (int64_t)((double)current_frame / asset->frame_rate * base_framerate + 0.5);
932         else
933                 return current_frame;
934 }
935
936 int64_t File::get_audio_position()
937 {
938 //      int64_t base_samplerate = -1;
939 //      if(base_samplerate > 0)
940 //      {
941 //              if(normalized_sample_rate == base_samplerate)
942 //                      return normalized_sample;
943 //              else
944 //                      return (int64_t)((double)current_sample /
945 //                              asset->sample_rate *
946 //                              base_samplerate +
947 //                              0.5);
948 //      }
949 //      else
950                 return current_sample;
951 }
952
953
954
955 int File::set_audio_position(int64_t position)
956 {
957         int result = 0;
958
959         if(!file) return 1;
960
961 #define REPOSITION(x, y) \
962         (labs((x) - (y)) > 1)
963
964         float base_samplerate = asset->sample_rate;
965         current_sample = normalized_sample = position;
966
967 // printf("File::set_audio_position %d normalized_sample=%ld\n",
968 // __LINE__,
969 // normalized_sample);
970                 result = file->set_audio_position(current_sample);
971
972                 if(result)
973                         printf("File::set_audio_position position=%jd"
974                                 " base_samplerate=%f asset=%p asset->sample_rate=%d\n",
975                                 position, base_samplerate, asset, asset->sample_rate);
976
977 //printf("File::set_audio_position %d %d %d\n", current_channel, current_sample, position);
978
979         return result;
980 }
981
982 int File::set_video_position(int64_t position,
983         int is_thread)
984 {
985         int result = 0;
986         if(!file) return 0;
987
988 // Convert to file's rate
989 //      if(base_framerate > 0)
990 //              position = (int64_t)((double)position /
991 //                      base_framerate *
992 //                      asset->frame_rate +
993 //                      0.5);
994
995
996         if(video_thread && !is_thread)
997         {
998 // Call thread.  Thread calls this again to set the file state.
999                 video_thread->set_video_position(position);
1000         }
1001         else
1002         if(current_frame != position)
1003         {
1004                 if(file)
1005                 {
1006                         current_frame = position;
1007                         result = file->set_video_position(current_frame);
1008                 }
1009         }
1010
1011         return result;
1012 }
1013
1014 // No resampling here.
1015 int File::write_samples(Samples **buffer, int64_t len)
1016 {
1017         int result = 1;
1018
1019         if(file)
1020         {
1021                 write_lock->lock("File::write_samples");
1022
1023 // Convert to arrays for backwards compatability
1024                 double *temp[asset->channels];
1025                 for(int i = 0; i < asset->channels; i++)
1026                 {
1027                         temp[i] = buffer[i]->get_data();
1028                 }
1029
1030                 result = file->write_samples(temp, len);
1031                 current_sample += len;
1032                 normalized_sample += len;
1033                 asset->audio_length += len;
1034                 write_lock->unlock();
1035         }
1036         return result;
1037 }
1038
1039
1040
1041
1042
1043 // Can't put any cmodel abstraction here because the filebase couldn't be
1044 // parallel.
1045 int File::write_frames(VFrame ***frames, int len)
1046 {
1047 //printf("File::write_frames %d\n", __LINE__);
1048 //PRINT_TRACE
1049 // Store the counters in temps so the filebase can choose to overwrite them.
1050         int result;
1051         int current_frame_temp = current_frame;
1052         int video_length_temp = asset->video_length;
1053
1054         write_lock->lock("File::write_frames");
1055
1056 //PRINT_TRACE
1057         result = file->write_frames(frames, len);
1058 //PRINT_TRACE
1059
1060         current_frame = current_frame_temp + len;
1061         asset->video_length = video_length_temp + len;
1062         write_lock->unlock();
1063 //PRINT_TRACE
1064         return result;
1065 }
1066
1067 // Only called by FileThread
1068 int File::write_compressed_frame(VFrame *buffer)
1069 {
1070         int result = 0;
1071         write_lock->lock("File::write_compressed_frame");
1072         result = file->write_compressed_frame(buffer);
1073         current_frame++;
1074         asset->video_length++;
1075         write_lock->unlock();
1076         return result;
1077 }
1078
1079
1080 int File::write_audio_buffer(int64_t len)
1081 {
1082         int result = 0;
1083         if(audio_thread)
1084         {
1085                 result = audio_thread->write_buffer(len);
1086         }
1087         return result;
1088 }
1089
1090 int File::write_video_buffer(int64_t len)
1091 {
1092         int result = 0;
1093         if(video_thread)
1094         {
1095                 result = video_thread->write_buffer(len);
1096         }
1097
1098         return result;
1099 }
1100
1101 Samples** File::get_audio_buffer()
1102 {
1103         if(audio_thread) return audio_thread->get_audio_buffer();
1104         return 0;
1105 }
1106
1107 VFrame*** File::get_video_buffer()
1108 {
1109         if(video_thread)
1110         {
1111                 VFrame*** result = video_thread->get_video_buffer();
1112
1113                 return result;
1114         }
1115
1116         return 0;
1117 }
1118
1119
1120 int File::read_samples(Samples *samples, int64_t len)
1121 {
1122 // Never try to read more samples than exist in the file
1123         if (current_sample + len > asset->audio_length) {
1124                 len = asset->audio_length - current_sample;
1125         }
1126         if(len <= 0) return 0;
1127
1128         int result = 0;
1129         const int debug = 0;
1130         if(debug) PRINT_TRACE
1131
1132         if(debug) PRINT_TRACE
1133
1134         double *buffer = samples->get_data();
1135
1136         int64_t base_samplerate = asset->sample_rate;
1137
1138         if(file)
1139         {
1140 // Resample recursively calls this with the asset sample rate
1141                 if(base_samplerate == 0) base_samplerate = asset->sample_rate;
1142
1143                 if(debug) PRINT_TRACE
1144                 result = file->read_samples(buffer, len);
1145
1146                 if(debug) PRINT_TRACE
1147                 current_sample += len;
1148
1149                 normalized_sample += len;
1150         }
1151         if(debug) PRINT_TRACE
1152
1153         return result;
1154 }
1155
1156 int File::read_frame(VFrame *frame, int is_thread)
1157 {
1158         const int debug = 0;
1159
1160         if(debug) PRINT_TRACE
1161
1162 //printf("File::read_frame %d\n", __LINE__);
1163
1164         if(video_thread && !is_thread) return video_thread->read_frame(frame);
1165
1166 //printf("File::read_frame %d\n", __LINE__);
1167         if(debug) PRINT_TRACE
1168         if( !file ) return 1;
1169         if(debug) PRINT_TRACE
1170         int supported_colormodel = colormodel_supported(frame->get_color_model());
1171         int advance_position = 1;
1172         int cache_active = use_cache || asset->video_length < 0 ? 1 : 0;
1173         int64_t cache_position = asset->video_length >= 0 ? current_frame : -1;
1174 // Test cache
1175         if( cache_active && frame_cache->get_frame(frame, cache_position,
1176                         current_layer, asset->frame_rate) )
1177         {
1178 // Can't advance position if cache used.
1179 //printf("File::read_frame %d\n", __LINE__);
1180                 advance_position = 0;
1181         }
1182 // Need temp
1183         else if(frame->get_color_model() != BC_COMPRESSED &&
1184                 (supported_colormodel != frame->get_color_model() ||
1185                 frame->get_w() != asset->width ||
1186                 frame->get_h() != asset->height))
1187         {
1188
1189 //                      printf("File::read_frame %d\n", __LINE__);
1190 // Can't advance position here because it needs to be added to cache
1191                 if(temp_frame)
1192                 {
1193                         if(!temp_frame->params_match(asset->width, asset->height, supported_colormodel))
1194                         {
1195                                 delete temp_frame;
1196                                 temp_frame = 0;
1197                         }
1198                 }
1199
1200 //                      printf("File::read_frame %d\n", __LINE__);
1201                 if(!temp_frame)
1202                 {
1203                         temp_frame = new VFrame(0,
1204                                 -1,
1205                                 asset->width,
1206                                 asset->height,
1207                                 supported_colormodel,
1208                                 -1);
1209                 }
1210
1211 //                      printf("File::read_frame %d\n", __LINE__);
1212                 temp_frame->copy_stacks(frame);
1213                 int result = file->read_frame(temp_frame);
1214                 if( result && frame->get_status() > 0 )
1215                         frame->set_status(-1);
1216 //for(int i = 0; i < 1000 * 1000; i++) ((float*)temp_frame->get_rows()[0])[i] = 1.0;
1217 // printf("File::read_frame %d %d %d %d %d %d\n",
1218 // temp_frame->get_color_model(),
1219 // temp_frame->get_w(),
1220 // temp_frame->get_h(),
1221 // frame->get_color_model(),
1222 // frame->get_w(),
1223 // frame->get_h());
1224                 BC_CModels::transfer(frame->get_rows(), temp_frame->get_rows(),
1225                         frame->get_y(), frame->get_u(), frame->get_v(),
1226                         temp_frame->get_y(), temp_frame->get_u(), temp_frame->get_v(),
1227                         0, 0, temp_frame->get_w(), temp_frame->get_h(),
1228                         0, 0, frame->get_w(), frame->get_h(),
1229                         temp_frame->get_color_model(),
1230                         frame->get_color_model(), 0, temp_frame->get_w(),
1231                         frame->get_w());
1232 //                      printf("File::read_frame %d\n", __LINE__);
1233         }
1234         else
1235         {
1236 // Can't advance position here because it needs to be added to cache
1237 //printf("File::read_frame %d\n", __LINE__);
1238                 int result = file->read_frame(frame);
1239                 if( result && frame->get_status() > 0 )
1240                         frame->set_status(-1);
1241 //for(int i = 0; i < 100 * 1000; i++) ((float*)frame->get_rows()[0])[i] = 1.0;
1242         }
1243
1244         if( cache_active && advance_position && frame->get_status() > 0 )
1245                 frame_cache->put_frame(frame, cache_position,
1246                         current_layer, asset->frame_rate, 1, 0);
1247 //printf("File::read_frame %d\n", __LINE__);
1248
1249         if(advance_position) current_frame++;
1250         if(debug) PRINT_TRACE
1251         return 0;
1252 }
1253
1254 int File::can_copy_from(Asset *asset,
1255         int64_t position,
1256         int output_w,
1257         int output_h)
1258 {
1259         if(!asset) return 0;
1260
1261         if(file)
1262         {
1263                 return asset->width == output_w &&
1264                         asset->height == output_h &&
1265                         file->can_copy_from(asset, position);
1266         }
1267         else
1268                 return 0;
1269 }
1270
1271 // Fill in queries about formats when adding formats here.
1272
1273
1274 int File::strtoformat(const char *format)
1275 {
1276         return strtoformat(0, format);
1277 }
1278
1279 int File::strtoformat(ArrayList<PluginServer*> *plugindb, const char *format)
1280 {
1281         if(!strcasecmp(format, _(AC3_NAME))) return FILE_AC3;
1282         if(!strcasecmp(format, _(SCENE_NAME))) return FILE_SCENE;
1283         if(!strcasecmp(format, _(WAV_NAME))) return FILE_WAV;
1284         if(!strcasecmp(format, _(PCM_NAME))) return FILE_PCM;
1285         if(!strcasecmp(format, _(AU_NAME))) return FILE_AU;
1286         if(!strcasecmp(format, _(AIFF_NAME))) return FILE_AIFF;
1287         if(!strcasecmp(format, _(SND_NAME))) return FILE_SND;
1288         if(!strcasecmp(format, _(PNG_NAME))) return FILE_PNG;
1289         if(!strcasecmp(format, _(PNG_LIST_NAME))) return FILE_PNG_LIST;
1290         if(!strcasecmp(format, _(TIFF_NAME))) return FILE_TIFF;
1291         if(!strcasecmp(format, _(TIFF_LIST_NAME))) return FILE_TIFF_LIST;
1292         if(!strcasecmp(format, _(JPEG_NAME))) return FILE_JPEG;
1293         if(!strcasecmp(format, _(JPEG_LIST_NAME))) return FILE_JPEG_LIST;
1294         if(!strcasecmp(format, _(EXR_NAME))) return FILE_EXR;
1295         if(!strcasecmp(format, _(EXR_LIST_NAME))) return FILE_EXR_LIST;
1296         if(!strcasecmp(format, _(FLAC_NAME))) return FILE_FLAC;
1297         if(!strcasecmp(format, _(CR2_NAME))) return FILE_CR2;
1298         if(!strcasecmp(format, _(CR2_LIST_NAME))) return FILE_CR2_LIST;
1299         if(!strcasecmp(format, _(MPEG_NAME))) return FILE_MPEG;
1300         if(!strcasecmp(format, _(AMPEG_NAME))) return FILE_AMPEG;
1301         if(!strcasecmp(format, _(VMPEG_NAME))) return FILE_VMPEG;
1302         if(!strcasecmp(format, _(TGA_NAME))) return FILE_TGA;
1303         if(!strcasecmp(format, _(TGA_LIST_NAME))) return FILE_TGA_LIST;
1304         if(!strcasecmp(format, _(OGG_NAME))) return FILE_OGG;
1305         if(!strcasecmp(format, _(VORBIS_NAME))) return FILE_VORBIS;
1306         if(!strcasecmp(format, _(RAWDV_NAME))) return FILE_RAWDV;
1307         if(!strcasecmp(format, _(FFMPEG_NAME))) return FILE_FFMPEG;
1308         if(!strcasecmp(format, _(DBASE_NAME))) return FILE_DB;
1309
1310         return 0;
1311 }
1312
1313
1314 const char* File::formattostr(int format)
1315 {
1316         return formattostr(0, format);
1317 }
1318
1319 const char* File::formattostr(ArrayList<PluginServer*> *plugindb, int format)
1320 {
1321         switch(format)
1322         {
1323                 case FILE_SCENE:        return _(SCENE_NAME);
1324                 case FILE_AC3:          return _(AC3_NAME);
1325                 case FILE_WAV:          return _(WAV_NAME);
1326                 case FILE_PCM:          return _(PCM_NAME);
1327                 case FILE_AU:           return _(AU_NAME);
1328                 case FILE_AIFF:         return _(AIFF_NAME);
1329                 case FILE_SND:          return _(SND_NAME);
1330                 case FILE_PNG:          return _(PNG_NAME);
1331                 case FILE_PNG_LIST:     return _(PNG_LIST_NAME);
1332                 case FILE_JPEG:         return _(JPEG_NAME);
1333                 case FILE_JPEG_LIST:    return _(JPEG_LIST_NAME);
1334                 case FILE_CR2:          return _(CR2_NAME);
1335                 case FILE_CR2_LIST:     return _(CR2_LIST_NAME);
1336                 case FILE_FLAC:         return _(FLAC_NAME);
1337                 case FILE_EXR:          return _(EXR_NAME);
1338                 case FILE_EXR_LIST:     return _(EXR_LIST_NAME);
1339                 case FILE_MPEG:         return _(MPEG_NAME);
1340                 case FILE_AMPEG:        return _(AMPEG_NAME);
1341                 case FILE_VMPEG:        return _(VMPEG_NAME);
1342                 case FILE_TGA:          return _(TGA_NAME);
1343                 case FILE_TGA_LIST:     return _(TGA_LIST_NAME);
1344                 case FILE_TIFF:         return _(TIFF_NAME);
1345                 case FILE_TIFF_LIST:    return _(TIFF_LIST_NAME);
1346                 case FILE_OGG:          return _(OGG_NAME);
1347                 case FILE_VORBIS:       return _(VORBIS_NAME);
1348                 case FILE_RAWDV:        return _(RAWDV_NAME);
1349                 case FILE_FFMPEG:       return _(FFMPEG_NAME);
1350                 case FILE_DB:           return _(DBASE_NAME);
1351         }
1352         return _("Unknown");
1353 }
1354
1355 int File::strtobits(const char *bits)
1356 {
1357         if(!strcasecmp(bits, _(NAME_8BIT))) return BITSLINEAR8;
1358         if(!strcasecmp(bits, _(NAME_16BIT))) return BITSLINEAR16;
1359         if(!strcasecmp(bits, _(NAME_24BIT))) return BITSLINEAR24;
1360         if(!strcasecmp(bits, _(NAME_32BIT))) return BITSLINEAR32;
1361         if(!strcasecmp(bits, _(NAME_ULAW))) return BITSULAW;
1362         if(!strcasecmp(bits, _(NAME_ADPCM))) return BITS_ADPCM;
1363         if(!strcasecmp(bits, _(NAME_FLOAT))) return BITSFLOAT;
1364         return BITSLINEAR16;
1365 }
1366
1367 const char* File::bitstostr(int bits)
1368 {
1369 //printf("File::bitstostr\n");
1370         switch(bits)
1371         {
1372                 case BITSLINEAR8:       return (NAME_8BIT);
1373                 case BITSLINEAR16:      return (NAME_16BIT);
1374                 case BITSLINEAR24:      return (NAME_24BIT);
1375                 case BITSLINEAR32:      return (NAME_32BIT);
1376                 case BITSULAW:          return (NAME_ULAW);
1377                 case BITS_ADPCM:        return (NAME_ADPCM);
1378                 case BITSFLOAT:         return (NAME_FLOAT);
1379         }
1380         return _("Unknown");
1381 }
1382
1383
1384
1385 int File::str_to_byteorder(const char *string)
1386 {
1387         if(!strcasecmp(string, _("Lo Hi"))) return 1;
1388         return 0;
1389 }
1390
1391 const char* File::byteorder_to_str(int byte_order)
1392 {
1393         if(byte_order) return _("Lo Hi");
1394         return _("Hi Lo");
1395 }
1396
1397 int File::bytes_per_sample(int bits)
1398 {
1399         switch(bits)
1400         {
1401                 case BITSLINEAR8:       return 1;
1402                 case BITSLINEAR16:      return 2;
1403                 case BITSLINEAR24:      return 3;
1404                 case BITSLINEAR32:      return 4;
1405                 case BITSULAW:          return 1;
1406         }
1407         return 1;
1408 }
1409
1410
1411
1412
1413
1414 int File::get_best_colormodel(int driver)
1415 {
1416         return get_best_colormodel(asset, driver);
1417 }
1418
1419 int File::get_best_colormodel(Asset *asset, int driver)
1420 {
1421         switch(asset->format)
1422         {
1423                 case FILE_RAWDV:        return FileDV::get_best_colormodel(asset, driver);
1424                 case FILE_MPEG:         return FileMPEG::get_best_colormodel(asset, driver);
1425                 case FILE_JPEG:
1426                 case FILE_JPEG_LIST:    return FileJPEG::get_best_colormodel(asset, driver);
1427                 case FILE_EXR:
1428                 case FILE_EXR_LIST:     return FileEXR::get_best_colormodel(asset, driver);
1429                 case FILE_PNG:
1430                 case FILE_PNG_LIST:     return FilePNG::get_best_colormodel(asset, driver);
1431                 case FILE_TGA:
1432                 case FILE_TGA_LIST:     return FileTGA::get_best_colormodel(asset, driver);
1433                 case FILE_CR2:
1434                 case FILE_CR2_LIST:     return FileCR2::get_best_colormodel(asset, driver);
1435                 case FILE_DB:           return FileDB::get_best_colormodel(asset, driver);
1436                 case FILE_FFMPEG:       return FileFFMPEG::get_best_colormodel(asset, driver);
1437         }
1438
1439         return BC_RGB888;
1440 }
1441
1442
1443 int File::colormodel_supported(int colormodel)
1444 {
1445         if(file)
1446                 return file->colormodel_supported(colormodel);
1447
1448         return BC_RGB888;
1449 }
1450
1451
1452 int64_t File::file_memory_usage()
1453 {
1454         return file ? file->base_memory_usage() : 0;
1455 }
1456
1457 int64_t File::get_memory_usage()
1458 {
1459         int64_t result = 0;
1460
1461         result += file_memory_usage();
1462         if(temp_frame) result += temp_frame->get_data_size();
1463         result += frame_cache->get_memory_usage();
1464         if(video_thread) result += video_thread->get_memory_usage();
1465
1466         if(result < MIN_CACHEITEM_SIZE) result = MIN_CACHEITEM_SIZE;
1467         return result;
1468 }
1469
1470
1471 int File::supports_video(ArrayList<PluginServer*> *plugindb, char *format)
1472 {
1473         int format_i = strtoformat(plugindb, format);
1474
1475         return supports_video(format_i);
1476         return 0;
1477 }
1478
1479 int File::supports_audio(ArrayList<PluginServer*> *plugindb, char *format)
1480 {
1481         int format_i = strtoformat(plugindb, format);
1482
1483         return supports_audio(format_i);
1484         return 0;
1485 }
1486
1487
1488 int File::supports_video(int format)
1489 {
1490 //printf("File::supports_video %d\n", format);
1491         switch(format)
1492         {
1493                 case FILE_OGG:
1494                 case FILE_JPEG:
1495                 case FILE_JPEG_LIST:
1496                 case FILE_CR2:
1497                 case FILE_CR2_LIST:
1498                 case FILE_EXR:
1499                 case FILE_EXR_LIST:
1500                 case FILE_PNG:
1501                 case FILE_PNG_LIST:
1502                 case FILE_TGA:
1503                 case FILE_TGA_LIST:
1504                 case FILE_TIFF:
1505                 case FILE_TIFF_LIST:
1506                 case FILE_VMPEG:
1507                 case FILE_FFMPEG:
1508                 case FILE_RAWDV:
1509                         return 1;
1510         }
1511         return 0;
1512 }
1513
1514 int File::supports_audio(int format)
1515 {
1516         switch(format)
1517         {
1518                 case FILE_AC3:
1519                 case FILE_FLAC:
1520                 case FILE_PCM:
1521                 case FILE_WAV:
1522                 case FILE_OGG:
1523                 case FILE_VORBIS:
1524                 case FILE_AMPEG:
1525                 case FILE_AU:
1526                 case FILE_AIFF:
1527                 case FILE_SND:
1528                 case FILE_FFMPEG:
1529                         return 1;
1530         }
1531         return 0;
1532 }
1533
1534 const char* File::get_tag(int format)
1535 {
1536         switch(format)
1537         {
1538                 case FILE_AC3:          return "ac3";
1539                 case FILE_AIFF:         return "aif";
1540                 case FILE_AMPEG:        return "mp3";
1541                 case FILE_AU:           return "au";
1542                 case FILE_RAWDV:        return "dv";
1543                 case FILE_DB:           return "db";
1544                 case FILE_EXR:          return "exr";
1545                 case FILE_EXR_LIST:     return "exr";
1546                 case FILE_FLAC:         return "flac";
1547                 case FILE_JPEG:         return "jpg";
1548                 case FILE_JPEG_LIST:    return "jpg";
1549                 case FILE_OGG:          return "ogg";
1550                 case FILE_PCM:          return "pcm";
1551                 case FILE_PNG:          return "png";
1552                 case FILE_PNG_LIST:     return "png";
1553                 case FILE_TGA:          return "tga";
1554                 case FILE_TGA_LIST:     return "tga";
1555                 case FILE_TIFF:         return "tif";
1556                 case FILE_TIFF_LIST:    return "tif";
1557                 case FILE_VMPEG:        return "m2v";
1558                 case FILE_VORBIS:       return "ogg";
1559                 case FILE_WAV:          return "wav";
1560                 case FILE_FFMPEG:       return "ffmpg";
1561         }
1562         return 0;
1563 }
1564
1565 const char* File::get_prefix(int format)
1566 {
1567         switch(format) {
1568         case FILE_PCM:          return "PCM";
1569         case FILE_WAV:          return "WAV";
1570         case FILE_PNG:          return "PNG";
1571         case FILE_JPEG:         return "JPEG";
1572         case FILE_TIFF:         return "TIFF";
1573         case FILE_GIF:          return "GIF";
1574         case FILE_JPEG_LIST:    return "JPEG_LIST";
1575         case FILE_AU:           return "AU";
1576         case FILE_AIFF:         return "AIFF";
1577         case FILE_SND:          return "SND";
1578         case FILE_TGA_LIST:     return "TGA_LIST";
1579         case FILE_TGA:          return "TGA";
1580         case FILE_MPEG:         return "MPEG";
1581         case FILE_AMPEG:        return "AMPEG";
1582         case FILE_VMPEG:        return "VMPEG";
1583         case FILE_RAWDV:        return "RAWDV";
1584         case FILE_TIFF_LIST:    return "TIFF_LIST";
1585         case FILE_PNG_LIST:     return "PNG_LIST";
1586         case FILE_AC3:          return "AC3";
1587         case FILE_EXR:          return "EXR";
1588         case FILE_EXR_LIST:     return "EXR_LIST";
1589         case FILE_CR2:          return "CR2";
1590         case FILE_OGG:          return "OGG";
1591         case FILE_VORBIS:       return "VORBIS";
1592         case FILE_FLAC:         return "FLAC";
1593         case FILE_FFMPEG:       return "FFMPEG";
1594         case FILE_SCENE:        return "SCENE";
1595         case FILE_CR2_LIST:     return "CR2_LIST";
1596         case FILE_GIF_LIST:     return "GIF_LIST";
1597         case FILE_DB:           return "DB";
1598         }
1599         return _("UNKNOWN");
1600 }
1601
1602
1603 PackagingEngine *File::new_packaging_engine(Asset *asset)
1604 {
1605         PackagingEngine *result;
1606         switch (asset->format)
1607         {
1608                 case FILE_OGG:
1609                         result = (PackagingEngine*)new PackagingEngineOGG();
1610                         break;
1611                 default:
1612                         result = (PackagingEngine*) new PackagingEngineDefault();
1613                         break;
1614         }
1615
1616         return result;
1617 }
1618
1619
1620 int File::record_fd()
1621 {
1622         return file ? file->record_fd() : -1;
1623 }
1624
1625
1626 void get_exe_path(char *result)
1627 {
1628 // Get executable path
1629         int len = readlink("/proc/self/exe", result, BCTEXTLEN-1);
1630         if( len >= 0 ) {
1631                 result[len] = 0;
1632                 char *ptr = strrchr(result, '/');
1633                 if( ptr ) *ptr = 0;
1634         }
1635         else
1636                 result[0] = 0;
1637 }
1638