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