r136: This commit was manufactured by cvs2svn to create tag 'hv_1_1_8'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / asset.C
blob73355162531c4720996ace7e8900b2a65d93fa30
1 #include "asset.h"
2 #include "defaults.h"
3 #include "assets.h"
4 #include "edl.h"
5 #include "file.h"
6 #include "filesystem.h"
7 #include "filexml.h"
8 #include "quicktime.h"
11 #include <stdio.h>
12 #include <string.h>
15 Asset::Asset() : ListItem<Asset>()
17         init_values();
20 Asset::Asset(Asset &asset) : ListItem<Asset>()
22         init_values();
23         *this = asset;
26 Asset::Asset(const char *path) : ListItem<Asset>()
28         init_values();
29         strcpy(this->path, path);
32 Asset::Asset(const int plugin_type, const char *plugin_title) : ListItem<Asset>()
34         init_values();
37 Asset::~Asset()
39         if(index_offsets) delete [] index_offsets;
40 // Don't delete index buffer since it is shared with the index thread.
44 int Asset::init_values()
46         path[0] = 0;
47         strcpy(folder, MEDIA_FOLDER);
48 //      format = FILE_MOV;
49 // Has to be unknown for file probing to succeed
50         format = FILE_UNKNOWN;
51         channels = 0;
52         sample_rate = 0;
53         bits = 0;
54         byte_order = 0;
55         signed_ = 0;
56         header = 0;
57         dither = 0;
58         audio_data = 0;
59         video_data = 0;
60         audio_length = 0;
61         video_length = 0;
63         layers = 0;
64         frame_rate = 0;
65         width = 0;
66         height = 0;
67         strcpy(vcodec, QUICKTIME_YUV2);
68         strcpy(acodec, QUICKTIME_TWOS);
69         jpeg_quality = 100;
70         
71         ampeg_bitrate = 256;
72         ampeg_derivative = 3;
74         vorbis_vbr = 0;
75         vorbis_min_bitrate = -1;
76         vorbis_bitrate = 128000;
77         vorbis_max_bitrate = -1;
79         mp3_bitrate = 256000;
87 // mpeg parameters
88         vmpeg_iframe_distance = 45;
89         vmpeg_bframe_distance = 0;
90         vmpeg_progressive = 0;
91         vmpeg_denoise = 1;
92         vmpeg_bitrate = 1000000;
93         vmpeg_derivative = 1;
94         vmpeg_quantization = 15;
95         vmpeg_cmodel = 0;
96         vmpeg_fix_bitrate = 0;
97         vmpeg_seq_codes = 0;
99 // Divx parameters.  Defaults from encore2
100         divx_bitrate = 2000000;
101         divx_rc_period = 50;
102         divx_rc_reaction_ratio = 45;
103         divx_rc_reaction_period = 10;
104         divx_max_key_interval = 250;
105         divx_max_quantizer = 31;
106         divx_min_quantizer = 1;
107         divx_quantizer = 15;
108         divx_quality = 5;
109         divx_fix_bitrate = 1;
110         divx_use_deblocking = 1;
112         ms_bitrate = 1000000;
113         ms_bitrate_tolerance = 500000;
114         ms_quantization = 10;
115         ms_interlaced = 0;
116         ms_gop_size = 45;
117         ms_fix_bitrate = 1;
120         png_use_alpha = 0;
122         use_header = 1;
125         reset_index();
126         id = EDL::next_id();
127         return 0;
130 int Asset::reset_index()
132         index_status = INDEX_NOTTESTED;
133         index_start = old_index_end = index_end = 0;
134         index_offsets = 0;
135         index_zoom = 0;
136         index_bytes = 0;
137         index_buffer = 0;
138         return 0;
141 void Asset::copy_from(Asset *asset, int do_index)
143         copy_location(asset);
144         copy_format(asset, do_index);
147 void Asset::copy_location(Asset *asset)
149         strcpy(this->path, asset->path);
150         strcpy(this->folder, asset->folder);
153 void Asset::copy_format(Asset *asset, int do_index)
155         if(do_index) update_index(asset);
157         audio_data = asset->audio_data;
158         format = asset->format;
159         channels = asset->channels;
160         sample_rate = asset->sample_rate;
161         bits = asset->bits;
162         byte_order = asset->byte_order;
163         signed_ = asset->signed_;
164         header = asset->header;
165         dither = asset->dither;
166         mp3_bitrate = asset->mp3_bitrate;
167         use_header = asset->use_header;
170         video_data = asset->video_data;
171         layers = asset->layers;
172         frame_rate = asset->frame_rate;
173         width = asset->width;
174         height = asset->height;
175         strcpy(vcodec, asset->vcodec);
176         strcpy(acodec, asset->acodec);
178         this->audio_length = asset->audio_length;
179         this->video_length = asset->video_length;
182         ampeg_bitrate = asset->ampeg_bitrate;
183         ampeg_derivative = asset->ampeg_derivative;
186         vorbis_vbr = asset->vorbis_vbr;
187         vorbis_min_bitrate = asset->vorbis_min_bitrate;
188         vorbis_bitrate = asset->vorbis_bitrate;
189         vorbis_max_bitrate = asset->vorbis_max_bitrate;
193         jpeg_quality = asset->jpeg_quality;
195 // mpeg parameters
196         vmpeg_iframe_distance = asset->vmpeg_iframe_distance;
197         vmpeg_bframe_distance = asset->vmpeg_bframe_distance;
198         vmpeg_progressive = asset->vmpeg_progressive;
199         vmpeg_denoise = asset->vmpeg_denoise;
200         vmpeg_bitrate = asset->vmpeg_bitrate;
201         vmpeg_derivative = asset->vmpeg_derivative;
202         vmpeg_quantization = asset->vmpeg_quantization;
203         vmpeg_cmodel = asset->vmpeg_cmodel;
204         vmpeg_fix_bitrate = asset->vmpeg_fix_bitrate;
205         vmpeg_seq_codes = asset->vmpeg_seq_codes;
208         divx_bitrate = asset->divx_bitrate;
209         divx_rc_period = asset->divx_rc_period;
210         divx_rc_reaction_ratio = asset->divx_rc_reaction_ratio;
211         divx_rc_reaction_period = asset->divx_rc_reaction_period;
212         divx_max_key_interval = asset->divx_max_key_interval;
213         divx_max_quantizer = asset->divx_max_quantizer;
214         divx_min_quantizer = asset->divx_min_quantizer;
215         divx_quantizer = asset->divx_quantizer;
216         divx_quality = asset->divx_quality;
217         divx_fix_bitrate = asset->divx_fix_bitrate;
218         divx_use_deblocking = asset->divx_use_deblocking;
220         ms_bitrate = asset->ms_bitrate;
221         ms_bitrate_tolerance = asset->ms_bitrate_tolerance;
222         ms_interlaced = asset->ms_interlaced;
223         ms_quantization = asset->ms_quantization;
224         ms_gop_size = asset->ms_gop_size;
225         ms_fix_bitrate = asset->ms_fix_bitrate;
227         
228         png_use_alpha = asset->png_use_alpha;
231 int64_t Asset::get_index_offset(int channel)
233         if(channel < channels && index_offsets)
234                 return index_offsets[channel];
235         else
236                 return 0;
239 Asset& Asset::operator=(Asset &asset)
241         copy_location(&asset);
242         copy_format(&asset);
243         return *this;
247 int Asset::equivalent(Asset &asset, 
248         int test_audio, 
249         int test_video)
251         int result = (!strcmp(asset.path, path) &&
252                 format == asset.format);
254         if(test_audio && result)
255         {
256                 result = (channels == asset.channels && 
257                         sample_rate == asset.sample_rate && 
258                         bits == asset.bits && 
259                         byte_order == asset.byte_order && 
260                         signed_ == asset.signed_ && 
261                         header == asset.header && 
262                         dither == asset.dither &&
263                         !strcmp(acodec, asset.acodec));
264         }
267         if(test_video && result)
268         {
269                 result = (layers == asset.layers && 
270                         frame_rate == asset.frame_rate &&
271                         width == asset.width &&
272                         height == asset.height &&
273                         !strcmp(vcodec, asset.vcodec));
274         }
276         return result;
279 int Asset::operator==(Asset &asset)
282         return equivalent(asset, 
283                 1, 
284                 1);
287 int Asset::operator!=(Asset &asset)
289         return !(*this == asset);
292 int Asset::test_path(const char *path)
294         if(!strcasecmp(this->path, path)) 
295                 return 1; 
296         else 
297                 return 0;
300 int Asset::test_plugin_title(const char *path)
304 int Asset::read(FileXML *file, 
305         int expand_relative)
307         return read(0, file, expand_relative);
310 int Asset::read(ArrayList<PluginServer*> *plugindb, 
311         FileXML *file, 
312         int expand_relative)
314         int result = 0;
316 // Check for relative path.
317         if(expand_relative)
318         {
319                 char new_path[BCTEXTLEN];
320                 char asset_directory[BCTEXTLEN];
321                 char input_directory[BCTEXTLEN];
322                 FileSystem fs;
324                 strcpy(new_path, path);
325                 fs.set_current_dir("");
327                 fs.extract_dir(asset_directory, path);
329 // No path in asset
330                 if(!asset_directory[0])
331                 {
332                         fs.extract_dir(input_directory, file->filename);
334 // Input file has a path
335                         if(input_directory[0])
336                         {
337                                 sprintf(path, "%s/%s", input_directory, new_path);
338                         }
339                 }
340         }
343         while(!result)
344         {
345                 result = file->read_tag();
346                 if(!result)
347                 {
348                         if(file->tag.title_is("/ASSET"))
349                         {
350                                 result = 1;
351                         }
352                         else
353                         if(file->tag.title_is("AUDIO"))
354                         {
355                                 read_audio(file);
356                         }
357                         else
358                         if(file->tag.title_is("FORMAT"))
359                         {
360                                 char *string = file->tag.get_property("TYPE");
361                                 format = File::strtoformat(plugindb, string);
362                                 use_header = 
363                                         file->tag.get_property("USE_HEADER", use_header);
364                         }
365                         else
366                         if(file->tag.title_is("FOLDER"))
367                         {
368                                 strcpy(folder, file->read_text());
369                         }
370                         else
371                         if(file->tag.title_is("VIDEO"))
372                         {
373                                 read_video(file);
374                         }
375                         else
376                         if(file->tag.title_is("INDEX"))
377                         {
378                                 read_index(file);
379                         }
380                 }
381         }
383 //printf("Asset::read 2\n");
384         return 0;
387 int Asset::read_audio(FileXML *file)
389         channels = file->tag.get_property("CHANNELS", 2);
390 // This is loaded from the index file after the EDL but this 
391 // should be overridable in the EDL.
392         if(!sample_rate) sample_rate = file->tag.get_property("RATE", 44100);
393         bits = file->tag.get_property("BITS", 16);
394         byte_order = file->tag.get_property("BYTE_ORDER", 1);
395         signed_ = file->tag.get_property("SIGNED", 1);
396         header = file->tag.get_property("HEADER", 0);
397         dither = file->tag.get_property("DITHER", 0);
399         audio_length = file->tag.get_property("AUDIO_LENGTH", 0);
400         acodec[0] = 0;
401         file->tag.get_property("ACODEC", acodec);
402         
405         ampeg_bitrate = file->tag.get_property("AMPEG_BITRATE", ampeg_bitrate);
406         ampeg_derivative = file->tag.get_property("AMPEG_DERIVATIVE", ampeg_derivative);
408         vorbis_vbr = file->tag.get_property("VORBIS_VBR", vorbis_vbr);
409         vorbis_min_bitrate = file->tag.get_property("VORBIS_MIN_BITRATE", vorbis_min_bitrate);
410         vorbis_bitrate = file->tag.get_property("VORBIS_BITRATE", vorbis_bitrate);
411         vorbis_max_bitrate = file->tag.get_property("VORBIS_MAX_BITRATE", vorbis_max_bitrate);
413         mp3_bitrate = file->tag.get_property("MP3_BITRATE", mp3_bitrate);
416         audio_data = 1;
417         return 0;
420 int Asset::read_video(FileXML *file)
422         height = file->tag.get_property("HEIGHT", height);
423         width = file->tag.get_property("WIDTH", width);
424         layers = file->tag.get_property("LAYERS", layers);
425 // This is loaded from the index file after the EDL but this 
426 // should be overridable in the EDL.
427         if(!frame_rate) frame_rate = file->tag.get_property("FRAMERATE", frame_rate);
428         vcodec[0] = 0;
429         file->tag.get_property("VCODEC", vcodec);
431         video_length = file->tag.get_property("VIDEO_LENGTH", 0);
436         jpeg_quality = file->tag.get_property("JPEG_QUALITY", jpeg_quality);
441         vmpeg_iframe_distance = file->tag.get_property("VMPEG_IFRAME_DISTANCE", vmpeg_iframe_distance);
442         vmpeg_bframe_distance = file->tag.get_property("VMPEG_BFRAME_DISTANCE", vmpeg_bframe_distance);
443         vmpeg_progressive = file->tag.get_property("VMPEG_PROGRESSIVE", vmpeg_progressive);
444         vmpeg_denoise = file->tag.get_property("VMPEG_DENOISE", vmpeg_denoise);
445         vmpeg_bitrate = file->tag.get_property("VMPEG_BITRATE", vmpeg_bitrate);
446         vmpeg_derivative = file->tag.get_property("VMPEG_DERIVATIVE", vmpeg_derivative);
447         vmpeg_quantization = file->tag.get_property("VMPEG_QUANTIZATION", vmpeg_quantization);
448         vmpeg_cmodel = file->tag.get_property("VMPEG_CMODEL", vmpeg_cmodel);
449         vmpeg_fix_bitrate = file->tag.get_property("VMPEG_FIX_BITRATE", vmpeg_fix_bitrate);
450         vmpeg_seq_codes = file->tag.get_property("VMPEG_SEQ_CODES", vmpeg_seq_codes);
453         divx_bitrate = file->tag.get_property("DIVX_BITRATE", divx_bitrate);
454         divx_rc_period = file->tag.get_property("DIVX_RC_PERIOD", divx_rc_period);
455         divx_rc_reaction_ratio = file->tag.get_property("DIVX_RC_REACTION_RATIO", divx_rc_reaction_ratio);
456         divx_rc_reaction_period = file->tag.get_property("DIVX_RC_REACTION_PERIOD", divx_rc_reaction_period);
457         divx_max_key_interval = file->tag.get_property("DIVX_MAX_KEY_INTERVAL", divx_max_key_interval);
458         divx_max_quantizer = file->tag.get_property("DIVX_MAX_QUANTIZER", divx_max_quantizer);
459         divx_min_quantizer = file->tag.get_property("DIVX_MIN_QUANTIZER", divx_min_quantizer);
460         divx_quantizer = file->tag.get_property("DIVX_QUANTIZER", divx_quantizer);
461         divx_quality = file->tag.get_property("DIVX_QUALITY", divx_quality);
462         divx_fix_bitrate = file->tag.get_property("DIVX_FIX_BITRATE", divx_fix_bitrate);
463         divx_use_deblocking = file->tag.get_property("DIVX_USE_DEBLOCKING", divx_use_deblocking);
465         ms_bitrate = file->tag.get_property("MS_BITRATE", ms_bitrate);
466         ms_bitrate_tolerance = file->tag.get_property("MS_BITRATE_TOLERANCE", ms_bitrate_tolerance);
467         ms_interlaced = file->tag.get_property("MS_INTERLACED", ms_interlaced);
468         ms_quantization = file->tag.get_property("MS_QUANTIZATION", ms_quantization);
469         ms_gop_size = file->tag.get_property("MS_GOP_SIZE", ms_gop_size);
470         ms_fix_bitrate = file->tag.get_property("MS_FIX_BITRATE", ms_fix_bitrate);
474         png_use_alpha = file->tag.get_property("PNG_USE_ALPHA", png_use_alpha);
479         video_data = 1;
480         return 0;
483 int Asset::read_index(FileXML *file)
485         if(index_offsets) delete [] index_offsets;
486         index_offsets = new int64_t[channels];
487         for(int i = 0; i < channels; i++) index_offsets[i] = 0;
489         int current_offset = 0;
490         int result = 0;
492         index_zoom = file->tag.get_property("ZOOM", 1);
493         index_bytes = file->tag.get_property("BYTES", (int64_t)0);
495         while(!result)
496         {
497                 result = file->read_tag();
498                 if(!result)
499                 {
500                         if(file->tag.title_is("/INDEX"))
501                         {
502                                 result = 1;
503                         }
504                         else
505                         if(file->tag.title_is("OFFSET"))
506                         {
507                                 if(current_offset < channels)
508                                 {
509                                         index_offsets[current_offset++] = file->tag.get_property("FLOAT", 0);
510 //printf("Asset::read_index %d %d\n", current_offset - 1, index_offsets[current_offset - 1]);
511                                 }
512                         }
513                 }
514         }
515         return 0;
518 // Output path is the path of the output file if name truncation is desired.
519 // It is a "" if complete names should be used.
521 int Asset::write(FileXML *file, 
522         int include_index, 
523         char *output_path)
525         write(0, 
526                 file, 
527                 include_index, 
528                 output_path);
531 int Asset::write(ArrayList<PluginServer*> *plugindb, 
532         FileXML *file, 
533         int include_index, 
534         char *output_path)
536         char new_path[BCTEXTLEN];
537         char asset_directory[BCTEXTLEN];
538         char output_directory[BCTEXTLEN];
539         FileSystem fs;
541 // Make path relative
542         fs.extract_dir(asset_directory, path);
543         if(output_path && output_path[0]) 
544                 fs.extract_dir(output_directory, output_path);
545         else
546                 output_directory[0] = 0;
548 // Asset and EDL are in same directory.  Extract just the name.
549         if(!strcmp(asset_directory, output_directory))
550         {
551                 fs.extract_name(new_path, path);
552         }
553         else
554         {
555                 strcpy(new_path, path);
556         }
558         file->tag.set_title("ASSET");
559         file->tag.set_property("SRC", new_path);
560         file->append_tag();
561         file->append_newline();
563         file->tag.set_title("FOLDER");
564         file->append_tag();
565         file->append_text(folder);
566         file->tag.set_title("/FOLDER");
567         file->append_tag();
568         file->append_newline();
570 // Write the format information
571         file->tag.set_title("FORMAT");
573         file->tag.set_property("TYPE", 
574                 File::formattostr(plugindb, format));
575         file->tag.set_property("USE_HEADER", use_header);
577         file->append_tag();
578         file->append_newline();
580         if(audio_data) write_audio(file);
581         if(video_data) write_video(file);
582         if(index_status == 0 && include_index) write_index(file);  // index goes after source
584         file->tag.set_title("/ASSET");
585         file->append_tag();
586         file->append_newline();
587         return 0;
590 int Asset::write_audio(FileXML *file)
592         file->tag.set_title("AUDIO");
593         file->tag.set_property("CHANNELS", channels);
594         file->tag.set_property("RATE", sample_rate);
595         file->tag.set_property("BITS", bits);
596         file->tag.set_property("BYTE_ORDER", byte_order);
597         file->tag.set_property("SIGNED", signed_);
598         file->tag.set_property("HEADER", header);
599         file->tag.set_property("DITHER", dither);
600         if(acodec[0])
601                 file->tag.set_property("ACODEC", acodec);
602         
603         file->tag.set_property("AUDIO_LENGTH", audio_length);
608         file->tag.set_property("AMPEG_BITRATE", ampeg_bitrate);
609         file->tag.set_property("AMPEG_DERIVATIVE", ampeg_derivative);
611         file->tag.set_property("VORBIS_VBR", vorbis_vbr);
612         file->tag.set_property("VORBIS_MIN_BITRATE", vorbis_min_bitrate);
613         file->tag.set_property("VORBIS_BITRATE", vorbis_bitrate);
614         file->tag.set_property("VORBIS_MAX_BITRATE", vorbis_max_bitrate);
616         file->tag.set_property("MP3_BITRATE", mp3_bitrate);
621         file->append_tag();
622         file->append_newline();
623         return 0;
626 int Asset::write_video(FileXML *file)
628         file->tag.set_title("VIDEO");
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("FRAMERATE", frame_rate);
633         if(vcodec[0])
634                 file->tag.set_property("VCODEC", vcodec);
636         file->tag.set_property("VIDEO_LENGTH", video_length);
640         file->tag.set_property("JPEG_QUALITY", jpeg_quality);
642         file->tag.set_property("VMPEG_IFRAME_DISTANCE", vmpeg_iframe_distance);
643         file->tag.set_property("VMPEG_BFRAME_DISTANCE", vmpeg_bframe_distance);
644         file->tag.set_property("VMPEG_PROGRESSIVE", vmpeg_progressive);
645         file->tag.set_property("VMPEG_DENOISE", vmpeg_denoise);
646         file->tag.set_property("VMPEG_BITRATE", vmpeg_bitrate);
647         file->tag.set_property("VMPEG_DERIVATIVE", vmpeg_derivative);
648         file->tag.set_property("VMPEG_QUANTIZATION", vmpeg_quantization);
649         file->tag.set_property("VMPEG_CMODEL", vmpeg_cmodel);
650         file->tag.set_property("VMPEG_FIX_BITRATE", vmpeg_fix_bitrate);
651         file->tag.set_property("VMPEG_SEQ_CODES", vmpeg_seq_codes);
654         file->tag.set_property("DIVX_BITRATE", divx_bitrate);
655         file->tag.set_property("DIVX_RC_PERIOD", divx_rc_period);
656         file->tag.set_property("DIVX_RC_REACTION_RATIO", divx_rc_reaction_ratio);
657         file->tag.set_property("DIVX_RC_REACTION_PERIOD", divx_rc_reaction_period);
658         file->tag.set_property("DIVX_MAX_KEY_INTERVAL", divx_max_key_interval);
659         file->tag.set_property("DIVX_MAX_QUANTIZER", divx_max_quantizer);
660         file->tag.set_property("DIVX_MIN_QUANTIZER", divx_min_quantizer);
661         file->tag.set_property("DIVX_QUANTIZER", divx_quantizer);
662         file->tag.set_property("DIVX_QUALITY", divx_quality);
663         file->tag.set_property("DIVX_FIX_BITRATE", divx_fix_bitrate);
664         file->tag.set_property("DIVX_USE_DEBLOCKING", divx_use_deblocking);
667         file->tag.set_property("MS_BITRATE", ms_bitrate);
668         file->tag.set_property("MS_BITRATE_TOLERANCE", ms_bitrate_tolerance);
669         file->tag.set_property("MS_INTERLACED", ms_interlaced);
670         file->tag.set_property("MS_QUANTIZATION", ms_quantization);
671         file->tag.set_property("MS_GOP_SIZE", ms_gop_size);
672         file->tag.set_property("MS_FIX_BITRATE", ms_fix_bitrate);
676         file->tag.set_property("PNG_USE_ALPHA", png_use_alpha);
682         file->append_tag();
683         file->append_newline();
684         return 0;
687 int Asset::write_index(FileXML *file)
689         file->tag.set_title("INDEX");
690         file->tag.set_property("ZOOM", index_zoom);
691         file->tag.set_property("BYTES", index_bytes);
692         file->append_tag();
693         file->append_newline();
695         if(index_offsets)
696         {
697                 for(int i = 0; i < channels; i++)
698                 {
699                         file->tag.set_title("OFFSET");
700                         file->tag.set_property("FLOAT", index_offsets[i]);
701                         file->append_tag();
702                 }
703         }
705         file->append_newline();
706         file->tag.set_title("/INDEX");
707         file->append_tag();
708         file->append_newline();
709         return 0;
715 char* Asset::construct_param(char *param, char *prefix, char *return_value)
717         if(prefix)
718                 sprintf(return_value, "%s%s", prefix, param);
719         else
720                 strcpy(return_value, param);
721         return return_value;
724 #define UPDATE_DEFAULT(x, y) defaults->update(construct_param(x, prefix, string), y);
725 #define GET_DEFAULT(x, y) defaults->get(construct_param(x, prefix, string), y);
727 void Asset::load_defaults(Defaults *defaults, 
728         char *prefix, 
729         int do_format,
730         int do_compression,
731         int do_path,
732         int do_data_types,
733         int do_bits)
735         char string[BCTEXTLEN];
737 // Can't save codec here because it's specific to render, record, and effect.
738 // The codec has to be UNKNOWN for file probing to work.
740         if(do_path)
741         {
742                 GET_DEFAULT("PATH", path);
743         }
745         if(do_compression)
746         {
747                 GET_DEFAULT("AUDIO_CODEC", acodec);
748                 GET_DEFAULT("VIDEO_CODEC", vcodec);
749         }
751         if(do_format)
752         {
753                 format = GET_DEFAULT("FORMAT", format);
754         }
756         if(do_data_types)
757         {
758                 audio_data = GET_DEFAULT("AUDIO", 1);
759                 video_data = GET_DEFAULT("VIDEO", 1);
760         }
762         if(do_bits)
763         {
764                 bits = GET_DEFAULT("BITS", 16);
765                 dither = GET_DEFAULT("DITHER", 0);
766                 signed_ = GET_DEFAULT("SIGNED", 1);
767                 byte_order = GET_DEFAULT("BYTE_ORDER", 1);
768         }
770         ampeg_bitrate = GET_DEFAULT("AMPEG_BITRATE", ampeg_bitrate);
771         ampeg_derivative = GET_DEFAULT("AMPEG_DERIVATIVE", ampeg_derivative);
773         vorbis_vbr = GET_DEFAULT("VORBIS_VBR", vorbis_vbr);
774         vorbis_min_bitrate = GET_DEFAULT("VORBIS_MIN_BITRATE", vorbis_min_bitrate);
775         vorbis_bitrate = GET_DEFAULT("VORBIS_BITRATE", vorbis_bitrate);
776         vorbis_max_bitrate = GET_DEFAULT("VORBIS_MAX_BITRATE", vorbis_max_bitrate);
778         mp3_bitrate = GET_DEFAULT("MP3_BITRATE", mp3_bitrate);
782         jpeg_quality = GET_DEFAULT("JPEG_QUALITY", jpeg_quality);
784 // MPEG format information
785         vmpeg_iframe_distance = GET_DEFAULT("VMPEG_IFRAME_DISTANCE", vmpeg_iframe_distance);
786         vmpeg_bframe_distance = GET_DEFAULT("VMPEG_BFRAME_DISTANCE", vmpeg_bframe_distance);
787         vmpeg_progressive = GET_DEFAULT("VMPEG_PROGRESSIVE", vmpeg_progressive);
788         vmpeg_denoise = GET_DEFAULT("VMPEG_DENOISE", vmpeg_denoise);
789         vmpeg_bitrate = GET_DEFAULT("VMPEG_BITRATE", vmpeg_bitrate);
790         vmpeg_derivative = GET_DEFAULT("VMPEG_DERIVATIVE", vmpeg_derivative);
791         vmpeg_quantization = GET_DEFAULT("VMPEG_QUANTIZATION", vmpeg_quantization);
792         vmpeg_cmodel = GET_DEFAULT("VMPEG_CMODEL", vmpeg_cmodel);
793         vmpeg_fix_bitrate = GET_DEFAULT("VMPEG_FIX_BITRATE", vmpeg_fix_bitrate);
794         vmpeg_seq_codes = GET_DEFAULT("VMPEG_SEQ_CODES", vmpeg_seq_codes);
797         divx_bitrate = GET_DEFAULT("DIVX_BITRATE", divx_bitrate);
798         divx_rc_period = GET_DEFAULT("DIVX_RC_PERIOD", divx_rc_period);
799         divx_rc_reaction_ratio = GET_DEFAULT("DIVX_RC_REACTION_RATIO", divx_rc_reaction_ratio);
800         divx_rc_reaction_period = GET_DEFAULT("DIVX_RC_REACTION_PERIOD", divx_rc_reaction_period);
801         divx_max_key_interval = GET_DEFAULT("DIVX_MAX_KEY_INTERVAL", divx_max_key_interval);
802         divx_max_quantizer = GET_DEFAULT("DIVX_MAX_QUANTIZER", divx_max_quantizer);
803         divx_min_quantizer = GET_DEFAULT("DIVX_MIN_QUANTIZER", divx_min_quantizer);
804         divx_quantizer = GET_DEFAULT("DIVX_QUANTIZER", divx_quantizer);
805         divx_quality = GET_DEFAULT("DIVX_QUALITY", divx_quality);
806         divx_fix_bitrate = GET_DEFAULT("DIVX_FIX_BITRATE", divx_fix_bitrate);
807         divx_use_deblocking = GET_DEFAULT("DIVX_USE_DEBLOCKING", divx_use_deblocking);
809         ms_bitrate = GET_DEFAULT("MS_BITRATE", ms_bitrate);
810         ms_bitrate_tolerance = GET_DEFAULT("MS_BITRATE_TOLERANCE", ms_bitrate_tolerance);
811         ms_interlaced = GET_DEFAULT("MS_INTERLACED", ms_interlaced);
812         ms_quantization = GET_DEFAULT("MS_QUANTIZATION", ms_quantization);
813         ms_gop_size = GET_DEFAULT("MS_GOP_SIZE", ms_gop_size);
814         ms_fix_bitrate = GET_DEFAULT("MS_FIX_BITRATE", ms_fix_bitrate);
817         png_use_alpha = GET_DEFAULT("PNG_USE_ALPHA", png_use_alpha);
820 void Asset::save_defaults(Defaults *defaults, 
821         char *prefix,
822         int do_format,
823         int do_compression,
824         int do_path,
825         int do_data_types,
826         int do_bits)
828         char string[BCTEXTLEN];
830         UPDATE_DEFAULT("PATH", path);
832         if(do_format)
833         {
834                 UPDATE_DEFAULT("FORMAT", format);
835         }
837         if(do_data_types)
838         {
839                 UPDATE_DEFAULT("AUDIO", audio_data);
840                 UPDATE_DEFAULT("VIDEO", video_data);
841         }
843         if(do_compression)
844         {
845                 UPDATE_DEFAULT("AUDIO_CODEC", acodec);
846                 UPDATE_DEFAULT("VIDEO_CODEC", vcodec);
847         }
849         if(do_bits)
850         {
851                 UPDATE_DEFAULT("BITS", bits);
852                 UPDATE_DEFAULT("DITHER", dither);
853                 UPDATE_DEFAULT("SIGNED", signed_);
854                 UPDATE_DEFAULT("BYTE_ORDER", byte_order);
855         }
857         UPDATE_DEFAULT("AMPEG_BITRATE", ampeg_bitrate);
858         UPDATE_DEFAULT("AMPEG_DERIVATIVE", ampeg_derivative);
860         UPDATE_DEFAULT("VORBIS_VBR", vorbis_vbr);
861         UPDATE_DEFAULT("VORBIS_MIN_BITRATE", vorbis_min_bitrate);
862         UPDATE_DEFAULT("VORBIS_BITRATE", vorbis_bitrate);
863         UPDATE_DEFAULT("VORBIS_MAX_BITRATE", vorbis_max_bitrate);
864         
865         UPDATE_DEFAULT("MP3_BITRATE", mp3_bitrate);
871         UPDATE_DEFAULT("JPEG_QUALITY", jpeg_quality);
873 // MPEG format information
874         UPDATE_DEFAULT("VMPEG_IFRAME_DISTANCE", vmpeg_iframe_distance);
875         UPDATE_DEFAULT("VMPEG_BFRAME_DISTANCE", vmpeg_bframe_distance);
876         UPDATE_DEFAULT("VMPEG_PROGRESSIVE", vmpeg_progressive);
877         UPDATE_DEFAULT("VMPEG_DENOISE", vmpeg_denoise);
878         UPDATE_DEFAULT("VMPEG_BITRATE", vmpeg_bitrate);
879         UPDATE_DEFAULT("VMPEG_DERIVATIVE", vmpeg_derivative);
880         UPDATE_DEFAULT("VMPEG_QUANTIZATION", vmpeg_quantization);
881         UPDATE_DEFAULT("VMPEG_CMODEL", vmpeg_cmodel);
882         UPDATE_DEFAULT("VMPEG_FIX_BITRATE", vmpeg_fix_bitrate);
883         UPDATE_DEFAULT("VMPEG_SEQ_CODES", vmpeg_seq_codes);
887         UPDATE_DEFAULT("DIVX_BITRATE", divx_bitrate);
888         UPDATE_DEFAULT("DIVX_RC_PERIOD", divx_rc_period);
889         UPDATE_DEFAULT("DIVX_RC_REACTION_RATIO", divx_rc_reaction_ratio);
890         UPDATE_DEFAULT("DIVX_RC_REACTION_PERIOD", divx_rc_reaction_period);
891         UPDATE_DEFAULT("DIVX_MAX_KEY_INTERVAL", divx_max_key_interval);
892         UPDATE_DEFAULT("DIVX_MAX_QUANTIZER", divx_max_quantizer);
893         UPDATE_DEFAULT("DIVX_MIN_QUANTIZER", divx_min_quantizer);
894         UPDATE_DEFAULT("DIVX_QUANTIZER", divx_quantizer);
895         UPDATE_DEFAULT("DIVX_QUALITY", divx_quality);
896         UPDATE_DEFAULT("DIVX_FIX_BITRATE", divx_fix_bitrate);
897         UPDATE_DEFAULT("DIVX_USE_DEBLOCKING", divx_use_deblocking);
900         UPDATE_DEFAULT("MS_BITRATE", ms_bitrate);
901         UPDATE_DEFAULT("MS_BITRATE_TOLERANCE", ms_bitrate_tolerance);
902         UPDATE_DEFAULT("MS_INTERLACED", ms_interlaced);
903         UPDATE_DEFAULT("MS_QUANTIZATION", ms_quantization);
904         UPDATE_DEFAULT("MS_GOP_SIZE", ms_gop_size);
905         UPDATE_DEFAULT("MS_FIX_BITRATE", ms_fix_bitrate);
907         UPDATE_DEFAULT("PNG_USE_ALPHA", png_use_alpha);
918 int Asset::update_path(char *new_path)
920         strcpy(path, new_path);
921         return 0;
924 void Asset::update_index(Asset *asset)
926 //printf("Asset::update_index 1 %d\n", index_status);
927         index_status = asset->index_status;
928         index_zoom = asset->index_zoom;          // zoom factor of index data
929         index_start = asset->index_start;        // byte start of index data in the index file
930         index_bytes = asset->index_bytes;        // Total bytes in source file for comparison before rebuilding the index
931         index_end = asset->index_end;
932         old_index_end = asset->old_index_end;    // values for index build
933 //printf("Asset::update_index 1\n");
935         if(index_offsets)
936         {
937                 delete [] index_offsets;
938                 index_offsets = 0;
939         }
940         
941         if(asset->index_offsets)
942         {
943                 index_offsets = new int64_t[asset->channels];
944 //printf("Asset::update_index 1\n");
946                 int i;
947                 for(i = 0; i < asset->channels; i++)
948                 {
949                         index_offsets[i] = asset->index_offsets[i];  // offsets of channels in index file in floats
951                 }
952         }
953 //printf("Asset::update_index 1\n");
954         index_buffer = asset->index_buffer;    // pointer
955 //printf("Asset::update_index 2\n");
959 int Asset::dump()
961         printf("  asset::dump\n");
962         printf("   %p %s\n", this, path);
963         printf("   index_status %d\n", index_status);
964         printf("   format %d\n", format);
965         printf("   audio_data %d channels %d samplerate %d bits %d byte_order %d signed %d header %d dither %d acodec %c%c%c%c\n",
966                 audio_data, channels, sample_rate, bits, byte_order, signed_, header, dither, acodec[0], acodec[1], acodec[2], acodec[3]);
967         printf("   audio_length %lld\n", audio_length);
968         printf("   video_data %d layers %d framerate %f width %d height %d vcodec %c%c%c%c\n",
969                 video_data, layers, frame_rate, width, height, vcodec[0], vcodec[1], vcodec[2], vcodec[3]);
970         printf("   video_length %lld \n", video_length);
971         return 0;