add LastFrame plugin, add bld_scripts
[goodguy/history.git] / cinelerra-5.0 / cinelerra / asset.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
22 #include "asset.h"
23 #include "assets.h"
24 #include "bchash.h"
25 #include "bcsignals.h"
26 #include "clip.h"
27 #include "edl.h"
28 #include "file.h"
29 #include "filesystem.h"
30 #include "filexml.h"
31 #include "format.inc"
32 #include "indexstate.h"
33
34 #include <stdio.h>
35 #include <string.h>
36
37
38 Asset::Asset()
39  : Indexable(1), ListItem<Asset>()
40 {
41         init_values();
42 }
43
44 Asset::Asset(Asset &asset)
45  : Indexable(1), ListItem<Asset>()
46 {
47         init_values();
48         this->copy_from(&asset, 1);
49 }
50
51 Asset::Asset(const char *path)
52  : Indexable(1), ListItem<Asset>()
53 {
54         init_values();
55         strcpy(this->path, path);
56 }
57
58 Asset::Asset(const int plugin_type, const char *plugin_title)
59  : Indexable(1), ListItem<Asset>()
60 {
61         init_values();
62 }
63
64 Asset::~Asset()
65 {
66 }
67
68 int Asset::init_values()
69 {
70         path[0] = 0;
71 // Has to be unknown for file probing to succeed
72         format = FILE_UNKNOWN;
73         fformat[0] = 0;
74         bits = 0;
75         byte_order = 0;
76         signed_ = 0;
77         header = 0;
78         dither = 0;
79         reset_audio();
80         reset_video();
81
82         strcpy(vcodec, "");
83         strcpy(acodec, "");
84
85         ff_audio_options[0] = 0;
86         ff_video_options[0] = 0;
87         ff_audio_bitrate = 0;
88         ff_video_bitrate = 0;
89         ff_video_quality = 0;
90
91         jpeg_quality = 100;
92         aspect_ratio = -1;
93
94         ampeg_bitrate = 256;
95         ampeg_derivative = 3;
96
97         vorbis_vbr = 0;
98         vorbis_min_bitrate = -1;
99         vorbis_bitrate = 128000;
100         vorbis_max_bitrate = -1;
101
102         theora_fix_bitrate = 1;
103         theora_bitrate = 860000;
104         theora_quality = 16;
105         theora_sharpness = 2;
106         theora_keyframe_frequency = 64;
107         theora_keyframe_force_frequency = 64;
108
109         mp3_bitrate = 256000;
110
111
112         mp4a_bitrate = 256000;
113         mp4a_quantqual = 100;
114
115
116
117 // mpeg parameters
118         vmpeg_iframe_distance = 45;
119         vmpeg_pframe_distance = 0;
120         vmpeg_progressive = 0;
121         vmpeg_denoise = 1;
122         vmpeg_bitrate = 1000000;
123         vmpeg_derivative = 1;
124         vmpeg_quantization = 15;
125         vmpeg_cmodel = BC_YUV420P;
126         vmpeg_fix_bitrate = 0;
127         vmpeg_seq_codes = 0;
128         vmpeg_preset = 0;
129         vmpeg_field_order = 0;
130
131 // Divx parameters.  BC_Hash from encore2
132         divx_bitrate = 2000000;
133         divx_rc_period = 50;
134         divx_rc_reaction_ratio = 45;
135         divx_rc_reaction_period = 10;
136         divx_max_key_interval = 250;
137         divx_max_quantizer = 31;
138         divx_min_quantizer = 1;
139         divx_quantizer = 5;
140         divx_quality = 5;
141         divx_fix_bitrate = 1;
142         divx_use_deblocking = 1;
143
144         h264_bitrate = 2000000;
145         h264_quantizer = 5;
146         h264_fix_bitrate = 0;
147
148         ms_bitrate = 1000000;
149         ms_bitrate_tolerance = 500000;
150         ms_quantization = 10;
151         ms_interlaced = 0;
152         ms_gop_size = 45;
153         ms_fix_bitrate = 1;
154
155         ac3_bitrate = 128;
156
157         png_use_alpha = 0;
158         exr_use_alpha = 0;
159         exr_compression = 0;
160
161         tiff_cmodel = 0;
162         tiff_compression = 0;
163
164         use_header = 1;
165
166         id = EDL::next_id();
167
168         return 0;
169 }
170
171 void Asset::reset_audio()
172 {
173         audio_data = 0;
174         channels = 0;
175         sample_rate = 0;
176         audio_length = 0;
177 }
178
179 void Asset::reset_video()
180 {
181         video_data = 0;
182         layers = 0;
183         actual_width = width = 0;
184         actual_height = height = 0;
185         video_length = 0;
186         vmpeg_cmodel = BC_YUV420P;
187         frame_rate = 0;
188         program = -1;
189 }
190
191
192 void Asset::boundaries()
193 {
194 //printf("Asset::boundaries %d %d %f\n", __LINE__, sample_rate, frame_rate);
195 // sample_rate & frame_rate are user defined
196 //      CLAMP(sample_rate, 1, 1000000);
197 //      CLAMP(frame_rate, 0.001, 1000000);
198         CLAMP(channels, 0, 16);
199         CLAMP(width, 0, 10000);
200         CLAMP(height, 0, 10000);
201 //printf("Asset::boundaries %d %d %f\n", __LINE__, sample_rate, frame_rate);
202 }
203
204 void Asset::copy_from(Asset *asset, int do_index)
205 {
206         copy_location(asset);
207         copy_format(asset, do_index);
208 }
209
210 void Asset::copy_location(Asset *asset)
211 {
212         strcpy(this->path, asset->path);
213         strcpy(this->folder, asset->folder);
214 }
215
216 void Asset::copy_format(Asset *asset, int do_index)
217 {
218         if(do_index) update_index(asset);
219
220         audio_data = asset->audio_data;
221         format = asset->format;
222         strcpy(fformat, asset->fformat);
223         channels = asset->channels;
224         sample_rate = asset->sample_rate;
225         bits = asset->bits;
226         byte_order = asset->byte_order;
227         signed_ = asset->signed_;
228         header = asset->header;
229         dither = asset->dither;
230         mp3_bitrate = asset->mp3_bitrate;
231         mp4a_bitrate = asset->mp4a_bitrate;
232         mp4a_quantqual = asset->mp4a_quantqual;
233         use_header = asset->use_header;
234         aspect_ratio = asset->aspect_ratio;
235
236         video_data = asset->video_data;
237         layers = asset->layers;
238         program = asset->program;
239         frame_rate = asset->frame_rate;
240         width = asset->width;
241         height = asset->height;
242         actual_width = asset->actual_width;
243         actual_height = asset->actual_height;
244         strcpy(vcodec, asset->vcodec);
245         strcpy(acodec, asset->acodec);
246
247         strcpy(ff_audio_options, asset->ff_audio_options);
248         strcpy(ff_video_options, asset->ff_video_options);
249         ff_audio_bitrate = asset->ff_audio_bitrate;
250         ff_video_bitrate = asset->ff_video_bitrate;
251         ff_video_quality = asset->ff_video_quality;
252
253         this->audio_length = asset->audio_length;
254         this->video_length = asset->video_length;
255
256
257         ampeg_bitrate = asset->ampeg_bitrate;
258         ampeg_derivative = asset->ampeg_derivative;
259
260
261         vorbis_vbr = asset->vorbis_vbr;
262         vorbis_min_bitrate = asset->vorbis_min_bitrate;
263         vorbis_bitrate = asset->vorbis_bitrate;
264         vorbis_max_bitrate = asset->vorbis_max_bitrate;
265
266         
267         theora_fix_bitrate = asset->theora_fix_bitrate;
268         theora_bitrate = asset->theora_bitrate;
269         theora_quality = asset->theora_quality;
270         theora_sharpness = asset->theora_sharpness;
271         theora_keyframe_frequency = asset->theora_keyframe_frequency;
272         theora_keyframe_force_frequency = asset->theora_keyframe_frequency;
273
274
275         jpeg_quality = asset->jpeg_quality;
276
277 // mpeg parameters
278         vmpeg_iframe_distance = asset->vmpeg_iframe_distance;
279         vmpeg_pframe_distance = asset->vmpeg_pframe_distance;
280         vmpeg_progressive = asset->vmpeg_progressive;
281         vmpeg_denoise = asset->vmpeg_denoise;
282         vmpeg_bitrate = asset->vmpeg_bitrate;
283         vmpeg_derivative = asset->vmpeg_derivative;
284         vmpeg_quantization = asset->vmpeg_quantization;
285         vmpeg_cmodel = asset->vmpeg_cmodel;
286         vmpeg_fix_bitrate = asset->vmpeg_fix_bitrate;
287         vmpeg_seq_codes = asset->vmpeg_seq_codes;
288         vmpeg_preset = asset->vmpeg_preset;
289         vmpeg_field_order = asset->vmpeg_field_order;
290
291
292         divx_bitrate = asset->divx_bitrate;
293         divx_rc_period = asset->divx_rc_period;
294         divx_rc_reaction_ratio = asset->divx_rc_reaction_ratio;
295         divx_rc_reaction_period = asset->divx_rc_reaction_period;
296         divx_max_key_interval = asset->divx_max_key_interval;
297         divx_max_quantizer = asset->divx_max_quantizer;
298         divx_min_quantizer = asset->divx_min_quantizer;
299         divx_quantizer = asset->divx_quantizer;
300         divx_quality = asset->divx_quality;
301         divx_fix_bitrate = asset->divx_fix_bitrate;
302         divx_use_deblocking = asset->divx_use_deblocking;
303
304         h264_bitrate = asset->h264_bitrate;
305         h264_quantizer = asset->h264_quantizer;
306         h264_fix_bitrate = asset->h264_fix_bitrate;
307
308
309         ms_bitrate = asset->ms_bitrate;
310         ms_bitrate_tolerance = asset->ms_bitrate_tolerance;
311         ms_interlaced = asset->ms_interlaced;
312         ms_quantization = asset->ms_quantization;
313         ms_gop_size = asset->ms_gop_size;
314         ms_fix_bitrate = asset->ms_fix_bitrate;
315
316         
317         ac3_bitrate = asset->ac3_bitrate;
318         
319         png_use_alpha = asset->png_use_alpha;
320         exr_use_alpha = asset->exr_use_alpha;
321         exr_compression = asset->exr_compression;
322
323         tiff_cmodel = asset->tiff_cmodel;
324         tiff_compression = asset->tiff_compression;
325 }
326
327 int64_t Asset::get_index_offset(int channel)
328 {
329         return index_state->get_index_offset(channel);
330 }
331
332 int64_t Asset::get_index_size(int channel)
333 {
334         return index_state->get_index_size(channel);
335 }
336
337
338 char* Asset::get_compression_text(int audio, int video)
339 {
340         if(audio) {
341                 switch(format) {
342                 case FILE_FFMPEG:
343                         if( acodec[0] ) return acodec;
344                         break;
345                 }
346         }
347         if(video) {
348                 switch(format) {
349                 case FILE_FFMPEG:
350                         if( vcodec[0] ) return vcodec;
351                         break;
352                 }
353         }
354         return 0;
355 }
356
357 Asset& Asset::operator=(Asset &asset)
358 {
359 printf("Asset::operator=\n");
360         copy_location(&asset);
361         copy_format(&asset, 1);
362         return *this;
363 }
364
365
366 int Asset::equivalent(Asset &asset, 
367         int test_audio, 
368         int test_video)
369 {
370         int result = (!strcmp(asset.path, path) &&
371                 format == asset.format);
372
373         if(result && format == FILE_FFMPEG)
374                 result = !strcmp(fformat, asset.fformat);
375
376         if(test_audio && result)
377         {
378                 result = (channels == asset.channels && 
379                         sample_rate == asset.sample_rate && 
380                         bits == asset.bits && 
381                         byte_order == asset.byte_order && 
382                         signed_ == asset.signed_ && 
383                         header == asset.header && 
384                         dither == asset.dither &&
385                         !strcmp(acodec, asset.acodec));
386                 if(result && format == FILE_FFMPEG)
387                         result = !strcmp(ff_audio_options, asset.ff_audio_options) &&
388                                 ff_audio_bitrate == asset.ff_audio_bitrate;
389                                 
390         }
391
392
393         if(test_video && result)
394         {
395                 result = (layers == asset.layers && 
396                         program == asset.program && 
397                         frame_rate == asset.frame_rate &&
398                         width == asset.width &&
399                         height == asset.height &&
400                         !strcmp(vcodec, asset.vcodec));
401                 if(result && format == FILE_FFMPEG)
402                         result = !strcmp(ff_video_options, asset.ff_video_options) &&
403                                 ff_video_bitrate == asset.ff_video_bitrate &&
404                                 ff_video_quality == asset.ff_video_quality;
405         }
406
407         return result;
408 }
409
410 int Asset::operator==(Asset &asset)
411 {
412
413         return equivalent(asset, 
414                 1, 
415                 1);
416 }
417
418 int Asset::operator!=(Asset &asset)
419 {
420         return !(*this == asset);
421 }
422
423 int Asset::test_path(const char *path)
424 {
425         if(!strcasecmp(this->path, path)) 
426                 return 1; 
427         else 
428                 return 0;
429 }
430
431 int Asset::test_plugin_title(const char *path)
432 {
433         return 0;
434 }
435
436 int Asset::read(FileXML *file, 
437         int expand_relative)
438 {
439         int result = 0;
440
441 // Check for relative path.
442         if(expand_relative)
443         {
444                 char new_path[BCTEXTLEN];
445                 char asset_directory[BCTEXTLEN];
446                 char input_directory[BCTEXTLEN];
447                 FileSystem fs;
448
449                 strcpy(new_path, path);
450                 fs.set_current_dir("");
451
452                 fs.extract_dir(asset_directory, path);
453
454 // No path in asset.
455 // Take path of XML file.
456                 if(!asset_directory[0])
457                 {
458                         fs.extract_dir(input_directory, file->filename);
459
460 // Input file has a path
461                         if(input_directory[0])
462                         {
463                                 fs.join_names(path, input_directory, new_path);
464                         }
465                 }
466         }
467
468
469         while(!result)
470         {
471                 result = file->read_tag();
472                 if(!result)
473                 {
474                         if(file->tag.title_is("/ASSET"))
475                         {
476                                 result = 1;
477                         }
478                         else
479                         if(file->tag.title_is("AUDIO"))
480                         {
481                                 read_audio(file);
482                         }
483                         else
484                         if(file->tag.title_is("AUDIO_OMIT"))
485                         {
486                                 read_audio(file);
487                         }
488                         else
489                         if(file->tag.title_is("FORMAT"))
490                         {
491                                 const char *string = file->tag.get_property("TYPE");
492                                 format = File::strtoformat(string);
493                                 use_header = 
494                                         file->tag.get_property("USE_HEADER", use_header);
495                                 file->tag.get_property("FFORMAT", fformat);
496                         }
497                         else
498                         if(file->tag.title_is("FOLDER"))
499                         {
500                                 strcpy(folder, file->read_text());
501                         }
502                         else
503                         if(file->tag.title_is("VIDEO"))
504                         {
505                                 read_video(file);
506                         }
507                         else
508                         if(file->tag.title_is("VIDEO_OMIT"))
509                         {
510                                 read_video(file);
511                         }
512                         else
513                         if(file->tag.title_is("INDEX"))
514                         {
515                                 read_index(file);
516                         }
517                 }
518         }
519
520         boundaries();
521 //printf("Asset::read 2\n");
522         return 0;
523 }
524
525 int Asset::read_audio(FileXML *file)
526 {
527         if(file->tag.title_is("AUDIO")) audio_data = 1;
528         channels = file->tag.get_property("CHANNELS", 2);
529 // This is loaded from the index file after the EDL but this 
530 // should be overridable in the EDL.
531         if(!sample_rate) sample_rate = file->tag.get_property("RATE", 44100);
532         bits = file->tag.get_property("BITS", 16);
533         byte_order = file->tag.get_property("BYTE_ORDER", 1);
534         signed_ = file->tag.get_property("SIGNED", 1);
535         header = file->tag.get_property("HEADER", 0);
536         dither = file->tag.get_property("DITHER", 0);
537
538         audio_length = file->tag.get_property("AUDIO_LENGTH", (int64_t)0);
539         acodec[0] = 0;
540         file->tag.get_property("ACODEC", acodec);
541
542         return 0;
543 }
544
545 int Asset::read_video(FileXML *file)
546 {
547         if(file->tag.title_is("VIDEO")) video_data = 1;
548         actual_height = file->tag.get_property("ACTUAL_HEIGHT", actual_height);
549         actual_width = file->tag.get_property("ACTUAL_WIDTH", actual_width);
550         height = file->tag.get_property("HEIGHT", height);
551         width = file->tag.get_property("WIDTH", width);
552         layers = file->tag.get_property("LAYERS", layers);
553         program = file->tag.get_property("PROGRAM", program);
554 // This is loaded from the index file after the EDL but this 
555 // should be overridable in the EDL.
556         if(EQUIV(frame_rate, 0)) frame_rate = file->tag.get_property("FRAMERATE", frame_rate);
557         vcodec[0] = 0;
558         file->tag.get_property("VCODEC", vcodec);
559
560         video_length = file->tag.get_property("VIDEO_LENGTH", (int64_t)0);
561
562         return 0;
563 }
564
565 int Asset::read_index(FileXML *file)
566 {
567         index_state->read_xml(file, channels);
568         return 0;
569 }
570
571 // Output path is the path of the output file if name truncation is desired.
572 // It is a "" if complete names should be used.
573
574 int Asset::write(FileXML *file, 
575         int include_index, 
576         const char *output_path)
577 {
578         char new_path[BCTEXTLEN];
579         char asset_directory[BCTEXTLEN];
580         char output_directory[BCTEXTLEN];
581         FileSystem fs;
582
583 // Make path relative
584         fs.extract_dir(asset_directory, path);
585         if(output_path && output_path[0]) 
586                 fs.extract_dir(output_directory, output_path);
587         else
588                 output_directory[0] = 0;
589
590 // Asset and EDL are in same directory.  Extract just the name.
591         if(!strcmp(asset_directory, output_directory))
592         {
593                 fs.extract_name(new_path, path);
594         }
595         else
596         {
597                 strcpy(new_path, path);
598         }
599
600         file->tag.set_title("ASSET");
601         file->tag.set_property("SRC", new_path);
602         file->append_tag();
603         file->append_newline();
604
605         file->tag.set_title("FOLDER");
606         file->append_tag();
607         file->append_text(folder);
608         file->tag.set_title("/FOLDER");
609         file->append_tag();
610         file->append_newline();
611
612 // Write the format information
613         file->tag.set_title("FORMAT");
614
615         file->tag.set_property("TYPE", 
616                 File::formattostr(format));
617         file->tag.set_property("USE_HEADER", use_header);
618         file->tag.set_property("FFORMAT", fformat);
619
620         file->append_tag();
621         file->append_newline();
622
623 // Requiring data to exist caused batch render to lose settings.
624 // But the only way to know if an asset doesn't have audio or video data 
625 // is to not write the block.
626 // So change the block name if the asset doesn't have the data.
627         write_audio(file);
628         write_video(file);
629 // index goes after source
630         if(index_state->index_status == INDEX_READY && include_index) 
631                 write_index(file);  
632
633         file->tag.set_title("/ASSET");
634         file->append_tag();
635         file->append_newline();
636         return 0;
637 }
638
639 int Asset::write_audio(FileXML *file)
640 {
641 // Let the reader know if the asset has the data by naming the block.
642         if(audio_data)
643                 file->tag.set_title("AUDIO");
644         else
645                 file->tag.set_title("AUDIO_OMIT");
646 // Necessary for PCM audio
647         file->tag.set_property("CHANNELS", channels);
648         file->tag.set_property("RATE", sample_rate);
649         file->tag.set_property("BITS", bits);
650         file->tag.set_property("BYTE_ORDER", byte_order);
651         file->tag.set_property("SIGNED", signed_);
652         file->tag.set_property("HEADER", header);
653         file->tag.set_property("DITHER", dither);
654         if(acodec[0])
655                 file->tag.set_property("ACODEC", acodec);
656         
657         file->tag.set_property("AUDIO_LENGTH", audio_length);
658
659
660
661 // Rely on defaults operations for these.
662
663 //      file->tag.set_property("AMPEG_BITRATE", ampeg_bitrate);
664 //      file->tag.set_property("AMPEG_DERIVATIVE", ampeg_derivative);
665 // 
666 //      file->tag.set_property("VORBIS_VBR", vorbis_vbr);
667 //      file->tag.set_property("VORBIS_MIN_BITRATE", vorbis_min_bitrate);
668 //      file->tag.set_property("VORBIS_BITRATE", vorbis_bitrate);
669 //      file->tag.set_property("VORBIS_MAX_BITRATE", vorbis_max_bitrate);
670 // 
671 //      file->tag.set_property("MP3_BITRATE", mp3_bitrate);
672 // 
673
674
675
676         file->append_tag();
677         file->append_newline();
678         return 0;
679 }
680
681 int Asset::write_video(FileXML *file)
682 {
683         if(video_data)
684                 file->tag.set_title("VIDEO");
685         else
686                 file->tag.set_title("VIDEO_OMIT");
687         file->tag.set_property("ACTUAL_HEIGHT", actual_height);
688         file->tag.set_property("ACTUAL_WIDTH", actual_width);
689         file->tag.set_property("HEIGHT", height);
690         file->tag.set_property("WIDTH", width);
691         file->tag.set_property("LAYERS", layers);
692         file->tag.set_property("PROGRAM", program);
693         file->tag.set_property("FRAMERATE", frame_rate);
694         if(vcodec[0])
695                 file->tag.set_property("VCODEC", vcodec);
696
697         file->tag.set_property("VIDEO_LENGTH", video_length);
698
699
700
701
702         file->append_tag();
703         file->append_newline();
704         return 0;
705 }
706
707 int Asset::write_index(FileXML *file)
708 {
709         index_state->write_xml(file);
710         return 0;
711 }
712
713
714
715 const char* Asset::construct_param(const char *param, 
716         const char *prefix, 
717         char *return_value)
718 {
719         if(prefix)
720                 sprintf(return_value, "%s%s", prefix, param);
721         else
722                 strcpy(return_value, param);
723         return return_value;
724 }
725
726 #define UPDATE_DEFAULT(x, y) defaults->update(construct_param(x, prefix, string), y);
727 #define GET_DEFAULT(x, y) defaults->get(construct_param(x, prefix, string), y);
728
729 void Asset::load_defaults(BC_Hash *defaults, 
730         const char *prefix, 
731         int do_format,
732         int do_compression,
733         int do_path,
734         int do_data_types,
735         int do_bits)
736 {
737         char string[BCTEXTLEN];
738
739 // Can't save codec here because it's specific to render, record, and effect.
740 // The codec has to be UNKNOWN for file probing to work.
741
742         if(do_path)
743         {
744                 GET_DEFAULT("PATH", path);
745         }
746
747         if(do_compression)
748         {
749                 GET_DEFAULT("AUDIO_CODEC", acodec);
750                 GET_DEFAULT("VIDEO_CODEC", vcodec);
751         }
752
753         if(do_format)
754         {
755                 format = GET_DEFAULT("FORMAT", format);
756                 use_header = GET_DEFAULT("USE_HEADER", use_header);
757                 GET_DEFAULT("FFORMAT", fformat);
758         }
759
760         if(do_data_types)
761         {
762                 audio_data = GET_DEFAULT("AUDIO", 1);
763                 video_data = GET_DEFAULT("VIDEO", 1);
764         }
765
766         if(do_bits)
767         {
768                 bits = GET_DEFAULT("BITS", 16);
769                 dither = GET_DEFAULT("DITHER", 0);
770                 signed_ = GET_DEFAULT("SIGNED", 1);
771                 byte_order = GET_DEFAULT("BYTE_ORDER", 1);
772
773
774
775 // Used by filefork
776                 channels = GET_DEFAULT("CHANNELS", 2);
777                 if(!sample_rate) sample_rate = GET_DEFAULT("RATE", 44100);
778                 header = GET_DEFAULT("HEADER", 0);
779                 audio_length = GET_DEFAULT("AUDIO_LENGTH", (int64_t)0);
780
781
782
783                 height = GET_DEFAULT("HEIGHT", height);
784                 width = GET_DEFAULT("WIDTH", width);
785                 actual_height = GET_DEFAULT("ACTUAL_HEIGHT", actual_height);
786                 actual_width = GET_DEFAULT("ACTUAL_WIDTH", actual_width);
787                 program = GET_DEFAULT("PROGRAM", program);
788                 layers = GET_DEFAULT("LAYERS", layers);
789                 if(EQUIV(frame_rate, 0)) frame_rate = GET_DEFAULT("FRAMERATE", frame_rate);
790                 video_length = GET_DEFAULT("VIDEO_LENGTH", (int64_t)0);
791         }
792
793         ampeg_bitrate = GET_DEFAULT("AMPEG_BITRATE", ampeg_bitrate);
794         ampeg_derivative = GET_DEFAULT("AMPEG_DERIVATIVE", ampeg_derivative);
795
796         vorbis_vbr = GET_DEFAULT("VORBIS_VBR", vorbis_vbr);
797         vorbis_min_bitrate = GET_DEFAULT("VORBIS_MIN_BITRATE", vorbis_min_bitrate);
798         vorbis_bitrate = GET_DEFAULT("VORBIS_BITRATE", vorbis_bitrate);
799         vorbis_max_bitrate = GET_DEFAULT("VORBIS_MAX_BITRATE", vorbis_max_bitrate);
800
801         theora_fix_bitrate = GET_DEFAULT("THEORA_FIX_BITRATE", theora_fix_bitrate);
802         theora_bitrate = GET_DEFAULT("THEORA_BITRATE", theora_bitrate);
803         theora_quality = GET_DEFAULT("THEORA_QUALITY", theora_quality);
804         theora_sharpness = GET_DEFAULT("THEORA_SHARPNESS", theora_sharpness);
805         theora_keyframe_frequency = GET_DEFAULT("THEORA_KEYFRAME_FREQUENCY", theora_keyframe_frequency);
806         theora_keyframe_force_frequency = GET_DEFAULT("THEORA_FORCE_KEYFRAME_FREQUENCY", theora_keyframe_force_frequency);
807
808         GET_DEFAULT("FF_AUDIO_OPTIONS", ff_audio_options);
809         ff_audio_bitrate = GET_DEFAULT("FF_AUDIO_BITRATE", ff_audio_bitrate);
810         GET_DEFAULT("FF_VIDEO_OPTIONS", ff_video_options);
811         ff_video_bitrate = GET_DEFAULT("FF_VIDEO_BITRATE", ff_video_bitrate);
812         ff_video_quality = GET_DEFAULT("FF_VIDEO_QUALITY", ff_video_quality);
813
814         mp3_bitrate = GET_DEFAULT("MP3_BITRATE", mp3_bitrate);
815         mp4a_bitrate = GET_DEFAULT("MP4A_BITRATE", mp4a_bitrate);
816         mp4a_quantqual = GET_DEFAULT("MP4A_QUANTQUAL", mp4a_quantqual);
817
818         jpeg_quality = GET_DEFAULT("JPEG_QUALITY", jpeg_quality);
819         aspect_ratio = GET_DEFAULT("ASPECT_RATIO", aspect_ratio);
820
821 // MPEG format information
822         vmpeg_iframe_distance = GET_DEFAULT("VMPEG_IFRAME_DISTANCE", vmpeg_iframe_distance);
823         vmpeg_pframe_distance = GET_DEFAULT("VMPEG_PFRAME_DISTANCE", vmpeg_pframe_distance);
824         vmpeg_progressive = GET_DEFAULT("VMPEG_PROGRESSIVE", vmpeg_progressive);
825         vmpeg_denoise = GET_DEFAULT("VMPEG_DENOISE", vmpeg_denoise);
826         vmpeg_bitrate = GET_DEFAULT("VMPEG_BITRATE", vmpeg_bitrate);
827         vmpeg_derivative = GET_DEFAULT("VMPEG_DERIVATIVE", vmpeg_derivative);
828         vmpeg_quantization = GET_DEFAULT("VMPEG_QUANTIZATION", vmpeg_quantization);
829         vmpeg_cmodel = GET_DEFAULT("VMPEG_CMODEL", vmpeg_cmodel);
830         vmpeg_fix_bitrate = GET_DEFAULT("VMPEG_FIX_BITRATE", vmpeg_fix_bitrate);
831         vmpeg_seq_codes = GET_DEFAULT("VMPEG_SEQ_CODES", vmpeg_seq_codes);
832         vmpeg_preset = GET_DEFAULT("VMPEG_PRESET", vmpeg_preset);
833         vmpeg_field_order = GET_DEFAULT("VMPEG_FIELD_ORDER", vmpeg_field_order);
834
835         h264_bitrate = GET_DEFAULT("H264_BITRATE", h264_bitrate);
836         h264_quantizer = GET_DEFAULT("H264_QUANTIZER", h264_quantizer);
837         h264_fix_bitrate = GET_DEFAULT("H264_FIX_BITRATE", h264_fix_bitrate);
838
839
840         divx_bitrate = GET_DEFAULT("DIVX_BITRATE", divx_bitrate);
841         divx_rc_period = GET_DEFAULT("DIVX_RC_PERIOD", divx_rc_period);
842         divx_rc_reaction_ratio = GET_DEFAULT("DIVX_RC_REACTION_RATIO", divx_rc_reaction_ratio);
843         divx_rc_reaction_period = GET_DEFAULT("DIVX_RC_REACTION_PERIOD", divx_rc_reaction_period);
844         divx_max_key_interval = GET_DEFAULT("DIVX_MAX_KEY_INTERVAL", divx_max_key_interval);
845         divx_max_quantizer = GET_DEFAULT("DIVX_MAX_QUANTIZER", divx_max_quantizer);
846         divx_min_quantizer = GET_DEFAULT("DIVX_MIN_QUANTIZER", divx_min_quantizer);
847         divx_quantizer = GET_DEFAULT("DIVX_QUANTIZER", divx_quantizer);
848         divx_quality = GET_DEFAULT("DIVX_QUALITY", divx_quality);
849         divx_fix_bitrate = GET_DEFAULT("DIVX_FIX_BITRATE", divx_fix_bitrate);
850         divx_use_deblocking = GET_DEFAULT("DIVX_USE_DEBLOCKING", divx_use_deblocking);
851
852         ms_bitrate = GET_DEFAULT("MS_BITRATE", ms_bitrate);
853         ms_bitrate_tolerance = GET_DEFAULT("MS_BITRATE_TOLERANCE", ms_bitrate_tolerance);
854         ms_interlaced = GET_DEFAULT("MS_INTERLACED", ms_interlaced);
855         ms_quantization = GET_DEFAULT("MS_QUANTIZATION", ms_quantization);
856         ms_gop_size = GET_DEFAULT("MS_GOP_SIZE", ms_gop_size);
857         ms_fix_bitrate = GET_DEFAULT("MS_FIX_BITRATE", ms_fix_bitrate);
858
859         ac3_bitrate = GET_DEFAULT("AC3_BITRATE", ac3_bitrate);
860
861         png_use_alpha = GET_DEFAULT("PNG_USE_ALPHA", png_use_alpha);
862         exr_use_alpha = GET_DEFAULT("EXR_USE_ALPHA", exr_use_alpha);
863         exr_compression = GET_DEFAULT("EXR_COMPRESSION", exr_compression);
864         tiff_cmodel = GET_DEFAULT("TIFF_CMODEL", tiff_cmodel);
865         tiff_compression = GET_DEFAULT("TIFF_COMPRESSION", tiff_compression);
866
867         boundaries();
868 }
869
870 void Asset::save_defaults(BC_Hash *defaults, 
871         const char *prefix,
872         int do_format,
873         int do_compression,
874         int do_path,
875         int do_data_types,
876         int do_bits)
877 {
878         char string[BCTEXTLEN];
879
880         UPDATE_DEFAULT("PATH", path);
881
882
883
884
885         if(do_format)
886         {
887                 UPDATE_DEFAULT("FORMAT", format);
888                 UPDATE_DEFAULT("USE_HEADER", use_header);
889                 UPDATE_DEFAULT("FFORMAT", fformat);
890         }
891
892         if(do_data_types)
893         {
894                 UPDATE_DEFAULT("AUDIO", audio_data);
895                 UPDATE_DEFAULT("VIDEO", video_data);
896         }
897
898         if(do_compression)
899         {
900                 UPDATE_DEFAULT("AUDIO_CODEC", acodec);
901                 UPDATE_DEFAULT("VIDEO_CODEC", vcodec);
902
903                 UPDATE_DEFAULT("AMPEG_BITRATE", ampeg_bitrate);
904                 UPDATE_DEFAULT("AMPEG_DERIVATIVE", ampeg_derivative);
905
906                 UPDATE_DEFAULT("VORBIS_VBR", vorbis_vbr);
907                 UPDATE_DEFAULT("VORBIS_MIN_BITRATE", vorbis_min_bitrate);
908                 UPDATE_DEFAULT("VORBIS_BITRATE", vorbis_bitrate);
909                 UPDATE_DEFAULT("VORBIS_MAX_BITRATE", vorbis_max_bitrate);
910
911                 UPDATE_DEFAULT("FF_AUDIO_OPTIONS", ff_audio_options);
912                 UPDATE_DEFAULT("FF_AUDIO_BITRATE", ff_audio_bitrate);
913                 UPDATE_DEFAULT("FF_VIDEO_OPTIONS", ff_video_options);
914                 UPDATE_DEFAULT("FF_VIDEO_BITRATE", ff_video_bitrate);
915                 UPDATE_DEFAULT("FF_VIDEO_QUALITY", ff_video_quality);
916
917                 UPDATE_DEFAULT("THEORA_FIX_BITRATE", theora_fix_bitrate);
918                 UPDATE_DEFAULT("THEORA_BITRATE", theora_bitrate);
919                 UPDATE_DEFAULT("THEORA_QUALITY", theora_quality);
920                 UPDATE_DEFAULT("THEORA_SHARPNESS", theora_sharpness);
921                 UPDATE_DEFAULT("THEORA_KEYFRAME_FREQUENCY", theora_keyframe_frequency);
922                 UPDATE_DEFAULT("THEORA_FORCE_KEYFRAME_FREQUENCY", theora_keyframe_force_frequency);
923
924
925
926                 UPDATE_DEFAULT("MP3_BITRATE", mp3_bitrate);
927                 UPDATE_DEFAULT("MP4A_BITRATE", mp4a_bitrate);
928                 UPDATE_DEFAULT("MP4A_QUANTQUAL", mp4a_quantqual);
929
930
931
932
933
934                 UPDATE_DEFAULT("JPEG_QUALITY", jpeg_quality);
935                 UPDATE_DEFAULT("ASPECT_RATIO", aspect_ratio);
936
937 // MPEG format information
938                 UPDATE_DEFAULT("VMPEG_IFRAME_DISTANCE", vmpeg_iframe_distance);
939                 UPDATE_DEFAULT("VMPEG_PFRAME_DISTANCE", vmpeg_pframe_distance);
940                 UPDATE_DEFAULT("VMPEG_PROGRESSIVE", vmpeg_progressive);
941                 UPDATE_DEFAULT("VMPEG_DENOISE", vmpeg_denoise);
942                 UPDATE_DEFAULT("VMPEG_BITRATE", vmpeg_bitrate);
943                 UPDATE_DEFAULT("VMPEG_DERIVATIVE", vmpeg_derivative);
944                 UPDATE_DEFAULT("VMPEG_QUANTIZATION", vmpeg_quantization);
945                 UPDATE_DEFAULT("VMPEG_CMODEL", vmpeg_cmodel);
946                 UPDATE_DEFAULT("VMPEG_FIX_BITRATE", vmpeg_fix_bitrate);
947                 UPDATE_DEFAULT("VMPEG_SEQ_CODES", vmpeg_seq_codes);
948                 UPDATE_DEFAULT("VMPEG_PRESET", vmpeg_preset);
949                 UPDATE_DEFAULT("VMPEG_FIELD_ORDER", vmpeg_field_order);
950
951                 UPDATE_DEFAULT("H264_BITRATE", h264_bitrate);
952                 UPDATE_DEFAULT("H264_QUANTIZER", h264_quantizer);
953                 UPDATE_DEFAULT("H264_FIX_BITRATE", h264_fix_bitrate);
954
955                 UPDATE_DEFAULT("DIVX_BITRATE", divx_bitrate);
956                 UPDATE_DEFAULT("DIVX_RC_PERIOD", divx_rc_period);
957                 UPDATE_DEFAULT("DIVX_RC_REACTION_RATIO", divx_rc_reaction_ratio);
958                 UPDATE_DEFAULT("DIVX_RC_REACTION_PERIOD", divx_rc_reaction_period);
959                 UPDATE_DEFAULT("DIVX_MAX_KEY_INTERVAL", divx_max_key_interval);
960                 UPDATE_DEFAULT("DIVX_MAX_QUANTIZER", divx_max_quantizer);
961                 UPDATE_DEFAULT("DIVX_MIN_QUANTIZER", divx_min_quantizer);
962                 UPDATE_DEFAULT("DIVX_QUANTIZER", divx_quantizer);
963                 UPDATE_DEFAULT("DIVX_QUALITY", divx_quality);
964                 UPDATE_DEFAULT("DIVX_FIX_BITRATE", divx_fix_bitrate);
965                 UPDATE_DEFAULT("DIVX_USE_DEBLOCKING", divx_use_deblocking);
966
967
968                 UPDATE_DEFAULT("MS_BITRATE", ms_bitrate);
969                 UPDATE_DEFAULT("MS_BITRATE_TOLERANCE", ms_bitrate_tolerance);
970                 UPDATE_DEFAULT("MS_INTERLACED", ms_interlaced);
971                 UPDATE_DEFAULT("MS_QUANTIZATION", ms_quantization);
972                 UPDATE_DEFAULT("MS_GOP_SIZE", ms_gop_size);
973                 UPDATE_DEFAULT("MS_FIX_BITRATE", ms_fix_bitrate);
974
975                 UPDATE_DEFAULT("AC3_BITRATE", ac3_bitrate);
976
977
978                 UPDATE_DEFAULT("PNG_USE_ALPHA", png_use_alpha);
979                 UPDATE_DEFAULT("EXR_USE_ALPHA", exr_use_alpha);
980                 UPDATE_DEFAULT("EXR_COMPRESSION", exr_compression);
981                 UPDATE_DEFAULT("TIFF_CMODEL", tiff_cmodel);
982                 UPDATE_DEFAULT("TIFF_COMPRESSION", tiff_compression);
983         }
984
985         if(do_bits)
986         {
987                 UPDATE_DEFAULT("BITS", bits);
988                 UPDATE_DEFAULT("DITHER", dither);
989                 UPDATE_DEFAULT("SIGNED", signed_);
990                 UPDATE_DEFAULT("BYTE_ORDER", byte_order);
991
992
993
994
995
996
997 // Used by filefork
998                 UPDATE_DEFAULT("CHANNELS", channels);
999                 UPDATE_DEFAULT("RATE", sample_rate);
1000                 UPDATE_DEFAULT("HEADER", header);
1001                 UPDATE_DEFAULT("AUDIO_LENGTH", audio_length);
1002
1003
1004
1005                 UPDATE_DEFAULT("HEIGHT", height);
1006                 UPDATE_DEFAULT("WIDTH", width);
1007                 UPDATE_DEFAULT("ACTUAL_HEIGHT", actual_height);
1008                 UPDATE_DEFAULT("ACTUAL_WIDTH", actual_width);
1009                 UPDATE_DEFAULT("PROGRAM", program);
1010                 UPDATE_DEFAULT("LAYERS", layers);
1011                 UPDATE_DEFAULT("FRAMERATE", frame_rate);
1012                 UPDATE_DEFAULT("VIDEO_LENGTH", video_length);
1013
1014         }
1015 }
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025 int Asset::dump(FILE *fp)
1026 {
1027         fprintf(fp,"  asset::dump\n");
1028         fprintf(fp,"   this=%p path=%s\n", this, path);
1029         fprintf(fp,"   index_status %d\n", index_state->index_status);
1030         fprintf(fp,"   format %d\n", format);
1031         fprintf(fp,"   fformat=\"%s\"\n", fformat);
1032         fprintf(fp,"   ff_audio_options=\"%s\"\n", ff_audio_options);
1033         fprintf(fp,"   ff_audio_bitrate=%d\n", ff_audio_bitrate);
1034         fprintf(fp,"   ff_video_options=\"%s\"\n", ff_video_options);
1035         fprintf(fp,"   ff_video_bitrate=%d\n", ff_video_bitrate);
1036         fprintf(fp,"   ff_video_quality=%d\n", ff_video_quality);
1037         fprintf(fp,"   audio_data %d channels %d samplerate %d bits %d"
1038                 " byte_order %d signed %d header %d dither %d acodec %c%c%c%c\n",
1039                 audio_data, channels, sample_rate, bits, byte_order, signed_,
1040                 header, dither, acodec[0], acodec[1], acodec[2], acodec[3]);
1041         fprintf(fp,"   audio_length " _LD "\n", audio_length);
1042         fprintf(fp,"   video_data %d program %d layers %d framerate %f width %d"
1043                 " height %d vcodec %c%c%c%c aspect_ratio %f\n",
1044                 video_data, layers, program, frame_rate, width, height,
1045                 vcodec[0], vcodec[1], vcodec[2], vcodec[3], aspect_ratio);
1046         fprintf(fp,"   video_length " _LD " \n", video_length);
1047         fprintf(fp,"   ms_bitrate_tolerance=%d\n", ms_bitrate_tolerance);
1048         fprintf(fp,"   ms_quantization=%d\n", ms_quantization);
1049         fprintf(fp,"   ms_fix_bitrate=%d\n", ms_fix_bitrate);
1050         fprintf(fp,"   ms_interlaced=%d\n", ms_interlaced);
1051         fprintf(fp,"   h264_bitrate=%d\n", h264_bitrate);
1052         fprintf(fp,"   h264_quantizer=%d\n", h264_quantizer);
1053         fprintf(fp,"   h264_fix_bitrate=%d\n", h264_fix_bitrate);
1054         return 0;
1055 }
1056
1057
1058 // For Indexable
1059 int Asset::get_audio_channels()
1060 {
1061         return channels;
1062 }
1063
1064 int Asset::get_sample_rate()
1065 {
1066         return sample_rate;
1067 }
1068
1069 int64_t Asset::get_audio_samples()
1070 {
1071         return audio_length;
1072 }
1073
1074 int Asset::have_audio()
1075 {
1076         return audio_data;
1077 }
1078
1079 int Asset::have_video()
1080 {
1081         return video_data;
1082 }
1083
1084 int Asset::get_w()
1085 {
1086         return width;
1087 }
1088
1089 int Asset::get_h()
1090 {
1091         return height;
1092 }
1093
1094 double Asset::get_frame_rate()
1095 {
1096         return frame_rate;
1097 }
1098
1099
1100 int Asset::get_video_layers()
1101 {
1102         return layers;
1103 }
1104
1105 int Asset::get_program()
1106 {
1107         return program;
1108 }
1109
1110 int64_t Asset::get_video_frames()
1111 {
1112         return video_length;
1113 }