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