r136: This commit was manufactured by cvs2svn to create tag 'hv_1_1_8'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / file.C
blob414de6b8a5eb833da86c08441cb92a2d29f2a02f
1 #include "asset.h"
2 #include "byteorder.h"
3 #include "edit.h"
4 #include "errorbox.h"
5 #include "file.h"
6 #include "fileavi.h"
7 #include "filebase.h"
8 #include "filexml.h"
9 #include "filejpeg.h"
10 #include "filemov.h"
11 #include "filempeg.h"
12 #include "filepng.h"
13 #include "filesndfile.h"
14 #include "filetga.h"
15 #include "filethread.h"
16 #include "filetiff.h"
17 #include "filevorbis.h"
18 #include "formatwindow.h"
19 #include "pluginserver.h"
20 #include "resample.h"
21 #include "stringfile.h"
22 #include "vframe.h"
25 #include <libintl.h>
26 #define _(String) gettext(String)
27 #define gettext_noop(String) String
28 #define N_(String) gettext_noop (String)
31 File::File()
33         cpus = 1;
34         asset = new Asset;
35         reset_parameters();
38 File::~File()
40         if(getting_options)
41         {
42                 if(format_window) format_window->set_done(0);
43                 format_completion.lock("File::~File");
44                 format_completion.unlock();
45         }
47         if(temp_frame)
48         {
49                 delete temp_frame;
50         }
52         if(return_frame)
53         {
54                 delete return_frame;
55         }
57         close_file();
58         reset_parameters();
59         delete asset;
62 void File::reset_parameters()
64         file = 0;
65         audio_thread = 0;
66         video_thread = 0;
67         getting_options = 0;
68         format_window = 0;
69         temp_frame = 0;
70         temp_frame = 0;
71         return_frame = 0;
72         current_sample = 0;
73         current_frame = 0;
74         current_channel = 0;
75         current_layer = 0;
76         normalized_sample = 0;
77         normalized_sample_rate = 0;
78         resample = 0;
82 int File::raise_window()
84         if(getting_options && format_window)
85         {
86                 format_window->raise_window();
87                 format_window->flush();
88         }
89         return 0;
92 void File::close_window()
94         if(getting_options)
95         {
96                 format_window->lock_window("File::close_window");
97                 format_window->set_done(1);
98                 format_window->unlock_window();
99                 getting_options = 0;
100         }
103 int File::get_options(BC_WindowBase *parent_window, 
104         ArrayList<PluginServer*> *plugindb, 
105         Asset *asset, 
106         int audio_options, 
107         int video_options,
108         int lock_compressor)
110         getting_options = 1;
111         format_completion.lock("File::get_options");
112         switch(asset->format)
113         {
114                 case FILE_PCM:
115                 case FILE_WAV:
116                 case FILE_AU:
117                 case FILE_AIFF:
118                 case FILE_SND:
119                         FileSndFile::get_parameters(parent_window, 
120                                 asset, 
121                                 format_window, 
122                                 audio_options, 
123                                 video_options);
124                         break;
125                 case FILE_MOV:
126                         FileMOV::get_parameters(parent_window, 
127                                 asset, 
128                                 format_window, 
129                                 audio_options, 
130                                 video_options,
131                                 lock_compressor);
132                         break;
133                 case FILE_AMPEG:
134                 case FILE_VMPEG:
135                         FileMPEG::get_parameters(parent_window, 
136                                 asset, 
137                                 format_window, 
138                                 audio_options, 
139                                 video_options);
140                         break;
141                 case FILE_AVI:
142                         FileMOV::get_parameters(parent_window, 
143                                 asset, 
144                                 format_window, 
145                                 audio_options, 
146                                 video_options,
147                                 lock_compressor);
148                         break;
149                 case FILE_AVI_LAVTOOLS:
150                 case FILE_AVI_ARNE2:
151                 case FILE_AVI_ARNE1:
152                 case FILE_AVI_AVIFILE:
153                         FileAVI::get_parameters(parent_window, 
154                                 asset, 
155                                 format_window, 
156                                 audio_options, 
157                                 video_options,
158                                 lock_compressor);
159                         break;
160                 case FILE_JPEG:
161                 case FILE_JPEG_LIST:
162                         FileJPEG::get_parameters(parent_window, 
163                                 asset, 
164                                 format_window, 
165                                 audio_options, 
166                                 video_options);
167                         break;
168                 case FILE_PNG:
169                 case FILE_PNG_LIST:
170                         FilePNG::get_parameters(parent_window, 
171                                 asset, 
172                                 format_window, 
173                                 audio_options, 
174                                 video_options);
175                         break;
176                 case FILE_TGA:
177                 case FILE_TGA_LIST:
178                         FileTGA::get_parameters(parent_window, 
179                                 asset, 
180                                 format_window, 
181                                 audio_options, 
182                                 video_options);
183                         break;
184                 case FILE_TIFF:
185                 case FILE_TIFF_LIST:
186                         FileTIFF::get_parameters(parent_window, 
187                                 asset, 
188                                 format_window, 
189                                 audio_options, 
190                                 video_options);
191                         break;
192                 case FILE_VORBIS:
193                         FileVorbis::get_parameters(parent_window,
194                                 asset,
195                                 format_window,
196                                 audio_options,
197                                 video_options);
198                         break;
199                 default:
200                         break;
201         }
203         if(!format_window)
204         {
205                 ErrorBox *errorbox = new ErrorBox(PROGRAM_NAME ": Error",
206                         parent_window->get_abs_cursor_x(),
207                         parent_window->get_abs_cursor_y());
208                 format_window = errorbox;
209                 getting_options = 1;
210                 if(audio_options)
211                         errorbox->create_objects(_("This format doesn't support audio."));
212                 else
213                 if(video_options)
214                         errorbox->create_objects(_("This format doesn't support video."));
215                 errorbox->run_window();
216                 delete errorbox;
217         }
219         getting_options = 0;
220         format_window = 0;
221         format_completion.unlock();
222         return 0;
225 void File::set_asset(Asset *asset)
227         *this->asset = *asset;
230 int File::set_processors(int cpus)   // Set the number of cpus for certain codecs
232 //printf("File::set_processors 1 %d\n", cpus);
233         this->cpus = cpus;
234         return 0;
237 int File::set_preload(int64_t size)
239         this->playback_preload = size;
240         return 0;
243 int File::open_file(ArrayList<PluginServer*> *plugindb, 
244         Asset *asset, 
245         int rd, 
246         int wr,
247         int64_t base_samplerate,
248         float base_framerate)
250         *this->asset = *asset;
251         file = 0;
254 //printf("File::open_file 1 %s %d\n", asset->path, asset->format);
255         switch(this->asset->format)
256         {
257 // get the format now
258 // If you add another format to case 0, you also need to add another case for the
259 // file format #define.
260                 case FILE_UNKNOWN:
261                         FILE *stream;
262                         if(!(stream = fopen(this->asset->path, "rb")))
263                         {
264 // file not found
265                                 return 1;
266                         }
268                         char test[16];
269                         fread(test, 16, 1, stream);
271 //                      if(FileAVI::check_sig(this->asset))
272 //                      {
273 //                              fclose(stream);
274 //                              file = new FileAVI(this->asset, this);
275 //                      }
276 //                      else
277                         if(FileSndFile::check_sig(this->asset))
278                         {
279 // libsndfile
280                                 fclose(stream);
281                                 file = new FileSndFile(this->asset, this);
282                         }
283                         else
284                         if(FilePNG::check_sig(this->asset))
285                         {
286 // PNG file
287                                 fclose(stream);
288                                 file = new FilePNG(this->asset, this);
289                         }
290                         else
291                         if(FileJPEG::check_sig(this->asset))
292                         {
293 // JPEG file
294                                 fclose(stream);
295                                 file = new FileJPEG(this->asset, this);
296                         }
297                         else
298                         if(FileTGA::check_sig(this->asset))
299                         {
300 // TGA file
301                                 fclose(stream);
302                                 file = new FileTGA(this->asset, this);
303                         }
304                         else
305                         if(FileTIFF::check_sig(this->asset))
306                         {
307 // TIFF file
308                                 fclose(stream);
309                                 file = new FileTIFF(this->asset, this);
310                         }
311                         else
312                         if(FileVorbis::check_sig(this->asset))
313                         {
314 // MPEG file
315                                 fclose(stream);
316                                 file = new FileVorbis(this->asset, this);
317                         }
318                         else
319                         if(FileMPEG::check_sig(this->asset))
320                         {
321 // MPEG file
322                                 fclose(stream);
323                                 file = new FileMPEG(this->asset, this);
324                         }
325                         else
326                         if(test[0] == '<' && test[1] == 'E' && test[2] == 'D' && test[3] == 'L' && test[4] == '>' ||
327                                 test[0] == '<' && test[1] == 'H' && test[2] == 'T' && test[3] == 'A' && test[4] == 'L' && test[5] == '>' ||
328                                 test[0] == '<' && test[1] == '?' && test[2] == 'x' && test[3] == 'm' && test[4] == 'l')
329                         {
330 // XML file
331                                 fclose(stream);
332                                 return FILE_IS_XML;
333                         }    // can't load project file
334                         else
335                         if(FileMOV::check_sig(this->asset))
336                         {
337 // MOV file
338 // should be last because quicktime lacks a magic number
339                                 fclose(stream);
340                                 file = new FileMOV(this->asset, this);
341                         }
342                         else
343                         {
344 // PCM file
345                                 fclose(stream);
346                                 return FILE_UNRECOGNIZED_CODEC;
347                         }   // need more info
348                         break;
350 // format already determined
351                 case FILE_PCM:
352                 case FILE_WAV:
353                 case FILE_AU:
354                 case FILE_AIFF:
355                 case FILE_SND:
356 //printf("File::open_file 1\n");
357                         file = new FileSndFile(this->asset, this);
358                         break;
360                 case FILE_PNG:
361                 case FILE_PNG_LIST:
362                         file = new FilePNG(this->asset, this);
363                         break;
365                 case FILE_JPEG:
366                 case FILE_JPEG_LIST:
367                         file = new FileJPEG(this->asset, this);
368                         break;
370                 case FILE_TGA_LIST:
371                 case FILE_TGA:
372                         file = new FileTGA(this->asset, this);
373                         break;
375                 case FILE_TIFF:
376                 case FILE_TIFF_LIST:
377                         file = new FileTIFF(this->asset, this);
378                         break;
380                 case FILE_MOV:
381                         file = new FileMOV(this->asset, this);
382                         break;
384                 case FILE_MPEG:
385                 case FILE_AMPEG:
386                 case FILE_VMPEG:
387                         file = new FileMPEG(this->asset, this);
388                         break;
390                 case FILE_VORBIS:
391                         file = new FileVorbis(this->asset, this);
392                         break;
394                 case FILE_AVI:
395                         file = new FileMOV(this->asset, this);
396                         break;
398                 case FILE_AVI_LAVTOOLS:
399                 case FILE_AVI_ARNE2:
400                 case FILE_AVI_ARNE1:
401                 case FILE_AVI_AVIFILE:
402                         file = new FileAVI(this->asset, this);
403                         break;
405 // try plugins
406                 default:
407                         return 1;
408                         break;
409         }
410 //printf("File::open_file 2\n");
412 // Reopen file with correct parser and get header.
413         if(file->open_file(rd, wr))
414         {
415 //printf("File::open_file 2.5\n");
416                 delete file;
417                 file = 0;
418         }
419 //printf("File::open_file 3\n");
422 // Set extra writing parameters to mandatory settings.
423         if(file && wr)
424         {
425                 if(this->asset->dither) file->set_dither();
426         }
428 // Synchronize header parameters
429         *asset = *this->asset;
431         if(file)
432                 return FILE_OK;
433         else
434                 return FILE_NOT_FOUND;
437 int File::close_file(int ignore_thread)
439         if(!ignore_thread)
440         {
441                 stop_audio_thread();
442                 stop_video_thread();
443         }
445         if(file) 
446         {
447 // The file's asset is a copy of the argument passed to open_file so the
448 // user must copy lengths from the file's asset.
449                 if(asset && file->wr)
450                 {
451                         asset->audio_length = current_sample;
452                         asset->video_length = current_frame;
453                 }
454                 file->close_file();
455                 delete file;
456         }
458         if(resample) delete resample;
460         reset_parameters();
461         return 0;
464 int File::start_audio_thread(int64_t buffer_size, int ring_buffers)
466         audio_thread = new FileThread(this, 1, 0);
467         audio_thread->start_writing(buffer_size, 0, ring_buffers, 0);
468         return 0;
471 int File::start_video_thread(int64_t buffer_size, 
472         int color_model, 
473         int ring_buffers, 
474         int compressed)
476         video_thread = new FileThread(this, 0, 1);
477 //printf("File::start_video_thread 1\n");
478         video_thread->start_writing(buffer_size, 
479                 color_model, 
480                 ring_buffers, 
481                 compressed);
482 //printf("File::start_video_thread 2\n");
483         return 0;
486 int File::stop_audio_thread()
488 //printf("File::stop_audio_thread 1\n");
489         if(audio_thread)
490         {
491                 audio_thread->stop_writing();
492                 delete audio_thread;
493                 audio_thread = 0;
494         }
495         return 0;
498 int File::stop_video_thread()
500 //printf("File::stop_video_thread 1\n");
501         if(video_thread)
502         {
503                 video_thread->stop_writing();
504                 delete video_thread;
505                 video_thread = 0;
506         }
507         return 0;
510 int File::lock_read()
512 //      read_lock.lock();
513         return 0;
516 int File::unlock_read()
518 //      read_lock.unlock();
519         return 0;
522 int File::set_channel(int channel) 
524         if(file && channel < asset->channels)
525         {
526                 current_channel = channel;
527                 return 0;
528         }
529         else
530                 return 1;
533 int File::set_layer(int layer) 
535         if(file && layer < asset->layers)
536         {
537                 current_layer = layer;
538 //printf("File::set_layer 1 %d\n", layer);
539                 return 0; 
540         }
541         else
542                 return 1;
545 int64_t File::get_audio_length(int64_t base_samplerate) 
547         int64_t result = asset->audio_length;
548         if(result > 0)
549         {
550                 if(base_samplerate > 0)
551                         return (int64_t)((double)result / asset->sample_rate * base_samplerate + 0.5);
552                 else
553                         return result;
554         }
555         else
556                 return -1;
559 int64_t File::get_video_length(float base_framerate)
561         int64_t result = asset->video_length;
562         if(result > 0)
563         {
564                 if(base_framerate > 0)
565                         return (int64_t)((double)result / asset->frame_rate * base_framerate + 0.5); 
566                 else
567                         return result;
568         }
569         else
570                 return -1;  // infinity
574 int64_t File::get_video_position(float base_framerate) 
576         if(base_framerate > 0)
577                 return (int64_t)((double)current_frame / asset->frame_rate * base_framerate + 0.5);
578         else
579                 return current_frame;
582 int64_t File::get_audio_position(int64_t base_samplerate) 
584         if(base_samplerate > 0)
585         {
586                 if(normalized_sample_rate == base_samplerate)
587                         return normalized_sample;
588                 else
589                         return (int64_t)((double)current_sample / 
590                                 asset->sample_rate * 
591                                 base_samplerate + 
592                                 0.5);
593         }
594         else
595                 return current_sample;
600 // The base samplerate must be nonzero if the base samplerate in the calling
601 // function is expected to change as this forces the resampler to reset.
603 int File::set_audio_position(int64_t position, float base_samplerate) 
605         int result = 0;
607         if(!file) return 1;
609 #define REPOSITION(x, y) \
610         (labs((x) - (y)) > 1)
614         if((base_samplerate && REPOSITION(normalized_sample, position)) ||
615                 (!base_samplerate && REPOSITION(current_sample, position)))
616         {
617 // Can't reset resampler since one seek operation is done 
618 // for every channel to be read at the same position.
620 // Use a conditional reset for just the case of different base_samplerates
621                 if(base_samplerate > 0)
622                 {
623                         if(normalized_sample_rate &&
624                                 normalized_sample_rate != base_samplerate && 
625                                 resample)
626                                 resample->reset(-1);
628                         normalized_sample = position;
629                         normalized_sample_rate = (int64_t)((base_samplerate > 0) ? 
630                                 base_samplerate : 
631                                 asset->sample_rate);
633 // Convert position to file's rate
634                         if(base_samplerate > 0)
635                                 current_sample = Units::round((double)position / 
636                                         base_samplerate * 
637                                         asset->sample_rate);
638                 }
639                 else
640                 {
641                         current_sample = position;
642                         normalized_sample = Units::round((double)position / 
643                                         asset->sample_rate * 
644                                         normalized_sample_rate);
645 // Can not set the normalized sample rate since this would reset the resampler.
646                 }
648                 result = file->set_audio_position(current_sample);
650                 if(result)
651                         printf("File::set_audio_position position=%d base_samplerate=%f asset=%p asset->sample_rate=%d\n",
652                                 position, base_samplerate, asset, asset->sample_rate);
653         }
655 //printf("File::set_audio_position %d %d %d\n", current_channel, current_sample, position);
657         return result;
660 int File::set_video_position(int64_t position, float base_framerate) 
662         int result = 0;
663         if(!file) return 0;
665 // Convert to file's rate
666         if(base_framerate > 0)
667                 position = (int64_t)((double)position / base_framerate * asset->frame_rate + 0.5);
669         if(current_frame != position && file)
670         {
671                 current_frame = position;
672                 result = file->set_video_position(current_frame);
673         }
675         return result;
678 // No resampling here.
679 int File::write_samples(double **buffer, int64_t len)
681         int result = 1;
682         
683         if(file)
684         {
685                 write_lock.lock("File::write_samples");
686                 result = file->write_samples(buffer, len);
687                 current_sample += len;
688                 normalized_sample += len;
689                 asset->audio_length += len;
690                 write_lock.unlock();
691         }
692         return result;
695 // Can't put any cmodel abstraction here because the filebase couldn't be
696 // parallel.
697 int File::write_frames(VFrame ***frames, int len)
699 // Store the counters in temps so the filebase can choose to overwrite them.
700         int result;
701         int current_frame_temp = current_frame;
702         int video_length_temp = asset->video_length;
703         write_lock.lock("File::write_frames");
708         result = file->write_frames(frames, len);
714         current_frame = current_frame_temp + len;
715         asset->video_length = video_length_temp + len;
716         write_lock.unlock();
717         return result;
720 int File::write_compressed_frame(VFrame *buffer)
722         int result = 0;
723         write_lock.lock("File::write_compressed_frame");
724         result = file->write_compressed_frame(buffer);
725         current_frame++;
726         asset->video_length++;
727         write_lock.unlock();
728         return result;
732 int File::write_audio_buffer(int64_t len)
734         int result = 0;
735         if(audio_thread)
736         {
737                 result = audio_thread->write_buffer(len);
738         }
739         return result;
742 int File::write_video_buffer(int64_t len)
744         int result = 0;
745         if(video_thread)
746         {
747                 result = video_thread->write_buffer(len);
748         }
750         return result;
753 double** File::get_audio_buffer()
755         if(audio_thread) return audio_thread->get_audio_buffer();
756         return 0;
759 VFrame*** File::get_video_buffer()
761         if(video_thread) return video_thread->get_video_buffer();
762         return 0;
766 int File::read_samples(double *buffer, int64_t len, int64_t base_samplerate)
768         int result = 0;
769 //printf("File::read_samples 1\n");
771 // Load with resampling 
772         if(file)
773         {
774 // Resample recursively calls this with the asset sample rate
775                 if(base_samplerate == 0) base_samplerate = asset->sample_rate;
777 //printf("File::read_samples 2 %d %d\n", base_samplerate, asset->sample_rate);
778                 if(base_samplerate != asset->sample_rate)
779                 {
780 //printf("File::read_samples 3\n");
781                         if(!resample)
782                         {
783 //printf("File::read_samples 4\n");
784                                 resample = new Resample(this, asset->channels);
785                         }
787 //printf("File::read_samples 5\n");
788                         current_sample += resample->resample(buffer, 
789                                 len, 
790                                 asset->sample_rate, 
791                                 base_samplerate,
792                                 current_channel,
793                                 current_sample,
794                                 normalized_sample);
795 //printf("File::read_samples 6\n");
796                 }
797                 else
798 // Load directly
799                 {
800 //printf("File::read_samples 7\n");
801                         result = file->read_samples(buffer, len);
802 //printf("File::read_samples 8\n");
803                         current_sample += len;
804                 }
806                 normalized_sample += len;
807         }
808         return result;
811 int File::read_compressed_frame(VFrame *buffer)
813         int result = 1;
814         if(file)
815                 result = file->read_compressed_frame(buffer);
816         current_frame++;
817         return result;
820 int64_t File::compressed_frame_size()
822         if(file)
823                 return file->compressed_frame_size();
824         else 
825                 return 0;
828 // Return a pointer to a frame in the video file for drawing purposes.
829 // The temporary frame is created by the file handler so that still frame
830 // files don't have to copy to a new buffer.
831 VFrame* File::read_frame(int color_model)
833         VFrame* result = 0;
834 //printf("File::read_frame 1\n");
835         if(file)
836         {
837 //printf("File::read_frame 2\n");
838                 if(return_frame && 
839                         (return_frame->get_w() != asset->width || 
840                         return_frame->get_h() != asset->height || 
841                         return_frame->get_color_model() != color_model))
842                 {
843                         delete return_frame;
844                         return_frame = 0;
845                 }
847 //printf("File::read_frame 3\n");
848                 if(!return_frame)
849                 {
850                         return_frame = new VFrame(0,
851                                 asset->width,
852                                 asset->height,
853                                 color_model);
854                 }
855 //printf("File::read_frame 4\n");
857                 read_frame(return_frame);
858 //printf("File::read_frame 5\n");
859                 result = return_frame;
860         }
861 //printf("File::read_frame 6\n");
863         return result;
867 int File::read_frame(VFrame *frame)
869         if(file)
870         {
871 //printf("File::read_frame 1\n");
872                 int supported_colormodel = colormodel_supported(frame->get_color_model());
874 //printf("File::read_frame 1 %d %d\n", supported_colormodel, frame->get_color_model());
875 // Need temp
876 //printf("File::read_frame 2\n");
877                 if(frame->get_color_model() != BC_COMPRESSED &&
878                         (supported_colormodel != frame->get_color_model() ||
879                         frame->get_w() != asset->width ||
880                         frame->get_h() != asset->height))
881                 {
882 //printf("File::read_frame 3\n");
883                         if(temp_frame)
884                         {
885                                 if(!temp_frame->params_match(asset->width, asset->height, supported_colormodel))
886                                 {
887                                         delete temp_frame;
888                                         temp_frame = 0;
889                                 }
890                         }
891 //printf("File::read_frame 4 %p %d %d %d\n", asset , asset->width, asset->height, supported_colormodel);
893                         if(!temp_frame)
894                         {
895                                 temp_frame = new VFrame(0,
896                                         asset->width,
897                                         asset->height,
898                                         supported_colormodel);
899                         }
901 //printf("File::read_frame 5 %d %d\n", 
902 //      temp_frame->get_color_model(), 
903 //      frame->get_color_model());
904                         file->read_frame(temp_frame);
905                         cmodel_transfer(frame->get_rows(), 
906                                 temp_frame->get_rows(),
907                                 0,
908                                 0,
909                                 0,
910                                 0,
911                                 0,
912                                 0,
913                                 0, 
914                                 0, 
915                                 temp_frame->get_w(), 
916                                 temp_frame->get_h(),
917                                 0, 
918                                 0, 
919                                 frame->get_w(), 
920                                 frame->get_h(),
921                                 temp_frame->get_color_model(), 
922                                 frame->get_color_model(),
923                                 0,
924                                 temp_frame->get_w(),
925                                 frame->get_w());
926 //printf("File::read_frame 6\n");
927                 }
928                 else
929                 {
930 //printf("File::read_frame 7\n");
931                         file->read_frame(frame);
932 //printf("File::read_frame 8\n");
933                 }
935 //printf("File::read_frame 9\n");
936                 current_frame++;
937 //printf("File::read_frame 2 %d\n", supported_colormodel);
938                 return 0;
939         }
940         else
941                 return 1;
944 int File::can_copy_from(Edit *edit, int64_t position, int output_w, int output_h)
946         if(file)
947         {
948                 return edit->asset->width == output_w &&
949                         edit->asset->height == output_h &&
950                         file->can_copy_from(edit, position);
951         }
952         else
953                 return 0;
956 // Fill in queries about formats when adding formats here.
959 int File::strtoformat(char *format)
961         return strtoformat(0, format);
964 int File::strtoformat(ArrayList<PluginServer*> *plugindb, char *format)
966         if(!strcasecmp(format, _(WAV_NAME))) return FILE_WAV;
967         else
968         if(!strcasecmp(format, _(PCM_NAME))) return FILE_PCM;
969         else
970         if(!strcasecmp(format, _(AU_NAME))) return FILE_AU;
971         else
972         if(!strcasecmp(format, _(AIFF_NAME))) return FILE_AIFF;
973         else
974         if(!strcasecmp(format, _(SND_NAME))) return FILE_SND;
975         else
976         if(!strcasecmp(format, _(PNG_NAME))) return FILE_PNG;
977         else
978         if(!strcasecmp(format, _(PNG_LIST_NAME))) return FILE_PNG_LIST;
979         else
980         if(!strcasecmp(format, _(TIFF_NAME))) return FILE_TIFF;
981         else
982         if(!strcasecmp(format, _(TIFF_LIST_NAME))) return FILE_TIFF_LIST;
983         else
984         if(!strcasecmp(format, _(JPEG_NAME))) return FILE_JPEG;
985         else
986         if(!strcasecmp(format, _(JPEG_LIST_NAME))) return FILE_JPEG_LIST;
987         else
988         if(!strcasecmp(format, _(MPEG_NAME))) return FILE_MPEG;
989         else
990         if(!strcasecmp(format, _(AMPEG_NAME))) return FILE_AMPEG;
991         else
992         if(!strcasecmp(format, _(VMPEG_NAME))) return FILE_VMPEG;
993         else
994         if(!strcasecmp(format, _(TGA_NAME))) return FILE_TGA;
995         else
996         if(!strcasecmp(format, _(TGA_LIST_NAME))) return FILE_TGA_LIST;
997         else
998         if(!strcasecmp(format, _(MOV_NAME))) return FILE_MOV;
999         else
1000         if(!strcasecmp(format, _(AVI_NAME))) return FILE_AVI;
1001         else
1002         if(!strcasecmp(format, _(AVI_LAVTOOLS_NAME))) return FILE_AVI_LAVTOOLS;
1003         else
1004         if(!strcasecmp(format, _(AVI_ARNE2_NAME))) return FILE_AVI_ARNE2;
1005         else
1006         if(!strcasecmp(format, _(AVI_ARNE1_NAME))) return FILE_AVI_ARNE1;
1007         else
1008         if(!strcasecmp(format, _(AVI_AVIFILE_NAME))) return FILE_AVI_AVIFILE;
1009         else
1010         if(!strcasecmp(format, _(VORBIS_NAME))) return FILE_VORBIS;
1012         return 0;
1015 char* File::formattostr(int format)
1017         return formattostr(0, format);
1020 char* File::formattostr(ArrayList<PluginServer*> *plugindb, int format)
1022         switch(format)
1023         {
1024                 case FILE_WAV:
1025                         return _(WAV_NAME);
1026                         break;
1027                 case FILE_PCM:
1028                         return _(PCM_NAME);
1029                         break;
1030                 case FILE_AU:
1031                         return _(AU_NAME);
1032                         break;
1033                 case FILE_AIFF:
1034                         return _(AIFF_NAME);
1035                         break;
1036                 case FILE_SND:
1037                         return _(SND_NAME);
1038                         break;
1039                 case FILE_PNG:
1040                         return _(PNG_NAME);
1041                         break;
1042                 case FILE_PNG_LIST:
1043                         return _(PNG_LIST_NAME);
1044                         break;
1045                 case FILE_JPEG:
1046                         return _(JPEG_NAME);
1047                         break;
1048                 case FILE_JPEG_LIST:
1049                         return _(JPEG_LIST_NAME);
1050                         break;
1051                 case FILE_MPEG:
1052                         return _(MPEG_NAME);
1053                         break;
1054                 case FILE_AMPEG:
1055                         return _(AMPEG_NAME);
1056                         break;
1057                 case FILE_VMPEG:
1058                         return _(VMPEG_NAME);
1059                         break;
1060                 case FILE_TGA:
1061                         return _(TGA_NAME);
1062                         break;
1063                 case FILE_TGA_LIST:
1064                         return _(TGA_LIST_NAME);
1065                         break;
1066                 case FILE_TIFF:
1067                         return _(TIFF_NAME);
1068                         break;
1069                 case FILE_TIFF_LIST:
1070                         return _(TIFF_LIST_NAME);
1071                         break;
1072                 case FILE_MOV:
1073                         return _(MOV_NAME);
1074                         break;
1075                 case FILE_AVI_LAVTOOLS:
1076                         return _(AVI_LAVTOOLS_NAME);
1077                         break;
1078                 case FILE_AVI:
1079                         return _(AVI_NAME);
1080                         break;
1081                 case FILE_AVI_ARNE2:
1082                         return _(AVI_ARNE2_NAME);
1083                         break;
1084                 case FILE_AVI_ARNE1:
1085                         return _(AVI_ARNE1_NAME);
1086                         break;
1087                 case FILE_AVI_AVIFILE:
1088                         return _(AVI_AVIFILE_NAME);
1089                         break;
1090                 case FILE_VORBIS:
1091                         return _(VORBIS_NAME);
1092                         break;
1094                 default:
1095                         return _("Unknown");
1096                         break;
1097         }
1098         return "Unknown";
1101 int File::strtobits(char *bits)
1103         if(!strcasecmp(bits, _(NAME_8BIT))) return BITSLINEAR8;
1104         if(!strcasecmp(bits, _(NAME_16BIT))) return BITSLINEAR16;
1105         if(!strcasecmp(bits, _(NAME_24BIT))) return BITSLINEAR24;
1106         if(!strcasecmp(bits, _(NAME_32BIT))) return BITSLINEAR32;
1107         if(!strcasecmp(bits, _(NAME_ULAW))) return BITSULAW;
1108         if(!strcasecmp(bits, _(NAME_ADPCM))) return BITS_ADPCM;
1109         if(!strcasecmp(bits, _(NAME_FLOAT))) return BITSFLOAT;
1110         if(!strcasecmp(bits, _(NAME_IMA4))) return BITSIMA4;
1111         return BITSLINEAR16;
1114 char* File::bitstostr(int bits)
1116 //printf("File::bitstostr\n");
1117         switch(bits)
1118         {
1119                 case BITSLINEAR8:
1120                         return (NAME_8BIT);
1121                         break;
1122                 case BITSLINEAR16:
1123                         return (NAME_16BIT);
1124                         break;
1125                 case BITSLINEAR24:
1126                         return (NAME_24BIT);
1127                         break;
1128                 case BITSLINEAR32:
1129                         return (NAME_32BIT);
1130                         break;
1131                 case BITSULAW:
1132                         return (NAME_ULAW);
1133                         break;
1134                 case BITS_ADPCM:
1135                         return (NAME_ADPCM);
1136                         break;
1137                 case BITSFLOAT:
1138                         return (NAME_FLOAT);
1139                         break;
1140                 case BITSIMA4:
1141                         return (NAME_IMA4);
1142                         break;
1143         }
1144         return "Unknown";
1149 int File::str_to_byteorder(char *string)
1151         if(!strcasecmp(string, _("Lo Hi"))) return 1;
1152         return 0;
1155 char* File::byteorder_to_str(int byte_order)
1157         if(byte_order) return _("Lo Hi");
1158         return _("Hi Lo");
1161 int File::bytes_per_sample(int bits)
1163         switch(bits)
1164         {
1165                 case BITSLINEAR8:
1166                         return 1;
1167                         break;
1168                 case BITSLINEAR16:
1169                         return 2;
1170                         break;
1171                 case BITSLINEAR24:
1172                         return 3;
1173                         break;
1174                 case BITSLINEAR32:
1175                         return 4;
1176                         break;
1177                 case BITSULAW:
1178                         return 1;
1179                         break;
1180                 case BITSIMA4:
1181                         return 1;
1182                         break;
1183         }
1184         return 1;
1191 int File::get_best_colormodel(int driver)
1193         return get_best_colormodel(asset, driver);
1196 int File::get_best_colormodel(Asset *asset, int driver)
1198         switch(asset->format)
1199         {
1200                 case FILE_MOV:
1201                         return FileMOV::get_best_colormodel(asset, driver);
1202                         break;
1203                 
1204                 case FILE_MPEG:
1205                         return FileMPEG::get_best_colormodel(asset, driver);
1206                         break;
1207                 
1208                 case FILE_JPEG:
1209                 case FILE_JPEG_LIST:
1210                         return FileJPEG::get_best_colormodel(asset, driver);
1211                         break;
1212                 
1213                 case FILE_PNG:
1214                 case FILE_PNG_LIST:
1215                         return FilePNG::get_best_colormodel(asset, driver);
1216                         break;
1217                 
1218                 case FILE_TGA:
1219                 case FILE_TGA_LIST:
1220                         return FileTGA::get_best_colormodel(asset, driver);
1221                         break;
1222         }
1224         return BC_RGB888;
1228 int File::colormodel_supported(int colormodel)
1230         if(file)
1231                 return file->colormodel_supported(colormodel);
1233         return BC_RGB888;
1240 int File::supports_video(ArrayList<PluginServer*> *plugindb, char *format)
1242         int i, format_i = strtoformat(plugindb, format);
1243         
1244         return supports_video(format_i);
1246 //      for(i = 0; i < plugindb->total; i++)
1247 //      {       
1248 //              if(plugindb->values[i]->fileio && 
1249 //                      !strcmp(plugindb->values[i]->title, format))
1250 //              {
1251 //                      if(plugindb->values[i]->video) return 1;
1252 //              }
1253 //      }
1255         return 0;
1258 int File::supports_audio(ArrayList<PluginServer*> *plugindb, char *format)
1260         int i, format_i = strtoformat(plugindb, format);
1262         return supports_audio(format_i);
1264 //      for(i = 0; i < plugindb->total; i++)
1265 //      {       
1266 //              if(plugindb->values[i]->fileio && 
1267 //                      !strcmp(plugindb->values[i]->title, format))
1268 //              {
1269 //                      if(plugindb->values[i]->audio) return 1;
1270 //              }
1271 //      }
1273         return 0;
1277 int File::supports_video(int format)
1279 //printf("File::supports_video %d\n", format);
1280         switch(format)
1281         {
1282                 case FILE_MOV:
1283                 case FILE_JPEG:
1284                 case FILE_JPEG_LIST:
1285                 case FILE_PNG:
1286                 case FILE_PNG_LIST:
1287                 case FILE_TGA:
1288                 case FILE_TGA_LIST:
1289                 case FILE_TIFF:
1290                 case FILE_TIFF_LIST:
1291                 case FILE_VMPEG:
1292                 case FILE_AVI_LAVTOOLS:
1293                 case FILE_AVI_ARNE2:
1294                 case FILE_AVI:
1295                 case FILE_AVI_ARNE1:
1296                 case FILE_AVI_AVIFILE:
1297                         return 1;
1298                         break;
1300                 default:
1301                         return 0;
1302                         break;
1303         }
1306 int File::supports_audio(int format)
1308         switch(format)
1309         {
1310                 case FILE_PCM:
1311                 case FILE_WAV:
1312                 case FILE_MOV:
1313                 case FILE_AMPEG:
1314                 case FILE_VORBIS:
1315                 case FILE_AU:
1316                 case FILE_AIFF:
1317                 case FILE_SND:
1318                 case FILE_AVI:
1319                 case FILE_AVI_LAVTOOLS:
1320                 case FILE_AVI_ARNE2:
1321                 case FILE_AVI_ARNE1:
1322                 case FILE_AVI_AVIFILE:
1323                         return 1;
1324                 
1325                 default:
1326                         return 0;
1327                         break;
1328         }