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