r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / assets.C
blob233f1f4b422203dea4ad38075221e601a364716c
1 #include "assets.h"
2 #include "awindowgui.inc"
3 #include "batch.h"
4 #include "cache.h"
5 #include "defaults.h"
6 #include "edl.h"
7 #include "file.h"
8 #include "filexml.h"
9 #include "filesystem.h"
10 #include "indexfile.h"
11 #include "quicktime.h"
12 #include "mainsession.h"
13 #include "threadindexer.h"
14 #include <string.h>
16 Assets::Assets(EDL *edl) : List<Asset>()
18         this->edl = edl;
21 Assets::~Assets()
23         delete_all();
26 int Assets::load(ArrayList<PluginServer*> *plugindb, 
27         FileXML *file, 
28         uint32_t load_flags)
30         int result = 0;
32 //printf("Assets::load 1\n");
33         while(!result)
34         {
35                 result = file->read_tag();
36                 if(!result)
37                 {
38                         if(file->tag.title_is("/ASSETS"))
39                         {
40                                 result = 1;
41                         }
42                         else
43                         if(file->tag.title_is("ASSET"))
44                         {
45 //printf("Assets::load 2\n");
46                                 char *path = file->tag.get_property("SRC");
47 //printf("Assets::load 3\n");
48                                 Asset new_asset(path ? path : SILENCE);
49 //printf("Assets::load 4\n");
50                                 new_asset.read(plugindb, file);
51 //printf("Assets::load 5\n");
52                                 update(&new_asset);
53 //printf("Assets::load 6\n");
54                         }
55                 }
56         }
57 //printf("Assets::load 7\n");
58         return 0;
61 int Assets::save(ArrayList<PluginServer*> *plugindb, FileXML *file, char *path)
63         file->tag.set_title("ASSETS");
64         file->append_tag();
65         file->append_newline();
67         for(Asset* current = first; current; current = NEXT)
68         {
69                 current->write(plugindb, 
70                         file, 
71                         0, 
72                         path);
73         }
75         file->tag.set_title("/ASSETS");
76         file->append_tag();
77         file->append_newline(); 
78         file->append_newline(); 
79         return 0;
82 Assets& Assets::operator=(Assets &assets)
84         while(last) delete last;
86         for(Asset *current = assets.first; current; current = NEXT)
87         {
88                 Asset *new_asset;
89                 append(new_asset = new Asset);
90                 new_asset->copy_from(current, 1);
91         }
93         return *this;
97 void Assets::update_index(Asset *asset)
99         for(Asset* current = first; current; current = NEXT)
100         {
101                 if(current->test_path(asset->path))
102                 {
103                         current->update_index(asset);
104                 }
105         }
108 Asset* Assets::update(Asset *asset)
110         if(!asset) return 0;
112         for(Asset* current = first; current; current = NEXT)
113         {
114 // Asset already exists.
115                 if(current->test_path(asset->path)) 
116                 {
117                         return current;
118                 }
119         }
121 // Asset doesn't exist.
122         Asset *asset_copy = new Asset(*asset);
123         append(asset_copy);
124         return asset_copy;
127 int Assets::delete_all()
129         while(last)
130         {
131                 remove(last);
132         }
133         return 0;
136 Asset* Assets::update(const char *path)
138         Asset* current = first;
140         while(current)
141         {
142                 if(current->test_path(path)) 
143                 {
144                         return current;
145                 }
146                 current = NEXT;
147         }
149         return append(new Asset(path));
152 Asset* Assets::get_asset(const char *filename)
154         Asset* current = first;
155         Asset* result = 0;
157         while(current)
158         {
159 //printf("Assets::get_asset %p %s\n", filename, filename);
160                 if(current->test_path(filename))
161                 {
162                         result = current;
163                         break;
164                 }
165                 current = current->next;
166         }
168         return result;  
171 Asset* Assets::remove_asset(Asset *asset)
173         delete asset;
177 int Assets::number_of(Asset *asset)
179         int i;
180         Asset *current;
182         for(i = 0, current = first; current && current != asset; i++, current = NEXT)
183                 ;
185         return i;
188 Asset* Assets::asset_number(int number)
190         int i;
191         Asset *current;
193         for(i = 0, current = first; i < number && current; i++, current = NEXT)
194                 ;
195         
196         return current;
199 int Assets::update_old_filename(char *old_filename, char *new_filename)
201         for(Asset* current = first; current; current = NEXT)
202         {
203                 if(!strcmp(current->path, old_filename))
204                 {
205                         current->update_path(new_filename);
206                 }
207         }
208         return 0;
212 int Assets::dump()
214         for(Asset *current = first; current; current = NEXT)
215         {
216                 current->dump();
217         }
218         return 0;
222 // ==========================================================
224 Asset::Asset() : ListItem<Asset>()
226         init_values();
229 Asset::Asset(Asset &asset) : ListItem<Asset>()
231         init_values();
232         *this = asset;
235 Asset::Asset(const char *path) : ListItem<Asset>()
237         init_values();
238         strcpy(this->path, path);
241 Asset::Asset(const int plugin_type, const char *plugin_title) : ListItem<Asset>()
243         init_values();
246 Asset::~Asset()
248         if(index_offsets) delete [] index_offsets;
249 // Don't delete index buffer since it is shared with the index thread.
253 int Asset::init_values()
255         path[0] = 0;
256         strcpy(folder, MEDIA_FOLDER);
257 //      format = FILE_MOV;
258 // Has to be unknown for file probing to succeed
259         format = FILE_UNKNOWN;
260         channels = 0;
261         sample_rate = 0;
262         bits = 0;
263         byte_order = 0;
264         signed_ = 0;
265         header = 0;
266         dither = 0;
267         audio_data = 0;
268         video_data = 0;
269         audio_length = 0;
270         video_length = 0;
272         layers = 0;
273         frame_rate = 0;
274         width = 0;
275         height = 0;
276         strcpy(vcodec, QUICKTIME_YUV2);
277         strcpy(acodec, QUICKTIME_TWOS);
278         jpeg_quality = 100;
279         
280         ampeg_bitrate = 256;
281         ampeg_derivative = 3;
283         vorbis_vbr = 0;
284         vorbis_min_bitrate = -1;
285         vorbis_bitrate = 128000;
286         vorbis_max_bitrate = -1;
288         mp3_bitrate = 256000;
296 // mpeg parameters
297         vmpeg_iframe_distance = 45;
298         vmpeg_bframe_distance = 0;
299         vmpeg_progressive = 0;
300         vmpeg_denoise = 1;
301         vmpeg_bitrate = 1000000;
302         vmpeg_derivative = 1;
303         vmpeg_quantization = 15;
304         vmpeg_cmodel = 0;
305         vmpeg_fix_bitrate = 0;
306         vmpeg_seq_codes = 0;
308 // Divx parameters.  Defaults from encore2
309         divx_bitrate = 2000000;
310         divx_rc_period = 50;
311         divx_rc_reaction_ratio = 45;
312         divx_rc_reaction_period = 10;
313         divx_max_key_interval = 250;
314         divx_max_quantizer = 31;
315         divx_min_quantizer = 1;
316         divx_quantizer = 15;
317         divx_quality = 5;
318         divx_fix_bitrate = 1;
319         divx_use_deblocking = 1;
321         ms_bitrate = 1000000;
322         ms_bitrate_tolerance = 500000;
323         ms_quantization = 10;
324         ms_interlaced = 0;
325         ms_gop_size = 45;
326         ms_fix_bitrate = 1;
329         png_use_alpha = 0;
331         use_header = 1;
334         reset_index();
335         id = EDL::next_id();
336         return 0;
339 int Asset::reset_index()
341         index_status = INDEX_NOTTESTED;
342         index_start = old_index_end = index_end = 0;
343         index_offsets = 0;
344         index_zoom = 0;
345         index_bytes = 0;
346         index_buffer = 0;
347         return 0;
350 void Asset::copy_from(Asset *asset, int do_index)
352         copy_location(asset);
353         copy_format(asset, do_index);
356 void Asset::copy_location(Asset *asset)
358         strcpy(this->path, asset->path);
359         strcpy(this->folder, asset->folder);
362 void Asset::copy_format(Asset *asset, int do_index)
364         if(do_index) update_index(asset);
366         audio_data = asset->audio_data;
367         format = asset->format;
368         channels = asset->channels;
369         sample_rate = asset->sample_rate;
370         bits = asset->bits;
371         byte_order = asset->byte_order;
372         signed_ = asset->signed_;
373         header = asset->header;
374         dither = asset->dither;
375         mp3_bitrate = asset->mp3_bitrate;
376         use_header = asset->use_header;
379         video_data = asset->video_data;
380         layers = asset->layers;
381         frame_rate = asset->frame_rate;
382         width = asset->width;
383         height = asset->height;
384         strcpy(vcodec, asset->vcodec);
385         strcpy(acodec, asset->acodec);
387         this->audio_length = asset->audio_length;
388         this->video_length = asset->video_length;
391         ampeg_bitrate = asset->ampeg_bitrate;
392         ampeg_derivative = asset->ampeg_derivative;
395         vorbis_vbr = asset->vorbis_vbr;
396         vorbis_min_bitrate = asset->vorbis_min_bitrate;
397         vorbis_bitrate = asset->vorbis_bitrate;
398         vorbis_max_bitrate = asset->vorbis_max_bitrate;
402         jpeg_quality = asset->jpeg_quality;
404 // mpeg parameters
405         vmpeg_iframe_distance = asset->vmpeg_iframe_distance;
406         vmpeg_bframe_distance = asset->vmpeg_bframe_distance;
407         vmpeg_progressive = asset->vmpeg_progressive;
408         vmpeg_denoise = asset->vmpeg_denoise;
409         vmpeg_bitrate = asset->vmpeg_bitrate;
410         vmpeg_derivative = asset->vmpeg_derivative;
411         vmpeg_quantization = asset->vmpeg_quantization;
412         vmpeg_cmodel = asset->vmpeg_cmodel;
413         vmpeg_fix_bitrate = asset->vmpeg_fix_bitrate;
414         vmpeg_seq_codes = asset->vmpeg_seq_codes;
417         divx_bitrate = asset->divx_bitrate;
418         divx_rc_period = asset->divx_rc_period;
419         divx_rc_reaction_ratio = asset->divx_rc_reaction_ratio;
420         divx_rc_reaction_period = asset->divx_rc_reaction_period;
421         divx_max_key_interval = asset->divx_max_key_interval;
422         divx_max_quantizer = asset->divx_max_quantizer;
423         divx_min_quantizer = asset->divx_min_quantizer;
424         divx_quantizer = asset->divx_quantizer;
425         divx_quality = asset->divx_quality;
426         divx_fix_bitrate = asset->divx_fix_bitrate;
427         divx_use_deblocking = asset->divx_use_deblocking;
429         ms_bitrate = asset->ms_bitrate;
430         ms_bitrate_tolerance = asset->ms_bitrate_tolerance;
431         ms_interlaced = asset->ms_interlaced;
432         ms_quantization = asset->ms_quantization;
433         ms_gop_size = asset->ms_gop_size;
434         ms_fix_bitrate = asset->ms_fix_bitrate;
436         
437         png_use_alpha = asset->png_use_alpha;
440 int64_t Asset::get_index_offset(int channel)
442         if(channel < channels && index_offsets)
443                 return index_offsets[channel];
444         else
445                 return 0;
448 Asset& Asset::operator=(Asset &asset)
450         copy_location(&asset);
451         copy_format(&asset);
452         return *this;
456 int Asset::equivalent(Asset &asset, 
457         int test_audio, 
458         int test_video)
460         int result = (!strcmp(asset.path, path) &&
461                 format == asset.format);
463         if(test_audio && result)
464         {
465                 result = (channels == asset.channels && 
466                         sample_rate == asset.sample_rate && 
467                         bits == asset.bits && 
468                         byte_order == asset.byte_order && 
469                         signed_ == asset.signed_ && 
470                         header == asset.header && 
471                         dither == asset.dither &&
472                         !strcmp(acodec, asset.acodec));
473         }
476         if(test_video && result)
477         {
478                 result = (layers == asset.layers && 
479                         frame_rate == asset.frame_rate &&
480                         width == asset.width &&
481                         height == asset.height &&
482                         !strcmp(vcodec, asset.vcodec));
483         }
485         return result;
488 int Asset::operator==(Asset &asset)
491         return equivalent(asset, 
492                 1, 
493                 1);
496 int Asset::operator!=(Asset &asset)
498         return !(*this == asset);
501 int Asset::test_path(const char *path)
503         if(!strcasecmp(this->path, path)) 
504                 return 1; 
505         else 
506                 return 0;
509 int Asset::test_plugin_title(const char *path)
513 int Asset::read(ArrayList<PluginServer*> *plugindb, FileXML *file)
515         int result = 0;
517 // Check for relative path.
518         char new_path[1024];
519         strcpy(new_path, path);
520         char asset_directory[1024], input_directory[1024];
521         FileSystem fs;
522         fs.set_current_dir("");
524         fs.extract_dir(asset_directory, path);
526 //printf("Asset::read 1\n");
527 // No path in asset
528         if(!asset_directory[0])
529         {
530                 fs.extract_dir(input_directory, file->filename);
531 //printf("Asset::read 2 %s %s\n", input_directory, new_path);
533 // Input file has a path
534                 if(input_directory[0])
535                 {
536                         sprintf(path, "%s/%s", input_directory, new_path);
537                 }
538         }
540         while(!result)
541         {
542                 result = file->read_tag();
543                 if(!result)
544                 {
545                         if(file->tag.title_is("/ASSET"))
546                         {
547                                 result = 1;
548                         }
549                         else
550                         if(file->tag.title_is("AUDIO"))
551                         {
552                                 read_audio(file);
553                         }
554                         else
555                         if(file->tag.title_is("FORMAT"))
556                         {
557                                 char *string = file->tag.get_property("TYPE");
558                                 format = File::strtoformat(plugindb, string);
559                                 use_header = 
560                                         file->tag.get_property("USE_HEADER", use_header);
561                         }
562                         else
563                         if(file->tag.title_is("FOLDER"))
564                         {
565                                 strcpy(folder, file->read_text());
566                         }
567                         else
568                         if(file->tag.title_is("VIDEO"))
569                         {
570                                 read_video(file);
571                         }
572                         else
573                         if(file->tag.title_is("INDEX"))
574                         {
575                                 read_index(file);
576                         }
577                 }
578         }
580 //printf("Asset::read 2\n");
581         return 0;
584 int Asset::read_audio(FileXML *file)
586         channels = file->tag.get_property("CHANNELS", 2);
587 // This is loaded from the index file after the EDL but this 
588 // should be overridable in the EDL.
589         if(!sample_rate) sample_rate = file->tag.get_property("RATE", 44100);
590         bits = file->tag.get_property("BITS", 16);
591         byte_order = file->tag.get_property("BYTE_ORDER", 1);
592         signed_ = file->tag.get_property("SIGNED", 1);
593         header = file->tag.get_property("HEADER", 0);
594         dither = file->tag.get_property("DITHER", 0);
596         audio_length = file->tag.get_property("AUDIO_LENGTH", 0);
597         acodec[0] = 0;
598         file->tag.get_property("ACODEC", acodec);
599         
602         ampeg_bitrate = file->tag.get_property("AMPEG_BITRATE", ampeg_bitrate);
603         ampeg_derivative = file->tag.get_property("AMPEG_DERIVATIVE", ampeg_derivative);
605         vorbis_vbr = file->tag.get_property("VORBIS_VBR", vorbis_vbr);
606         vorbis_min_bitrate = file->tag.get_property("VORBIS_MIN_BITRATE", vorbis_min_bitrate);
607         vorbis_bitrate = file->tag.get_property("VORBIS_BITRATE", vorbis_bitrate);
608         vorbis_max_bitrate = file->tag.get_property("VORBIS_MAX_BITRATE", vorbis_max_bitrate);
610         mp3_bitrate = file->tag.get_property("MP3_BITRATE", mp3_bitrate);
613         audio_data = 1;
614         return 0;
617 int Asset::read_video(FileXML *file)
619         height = file->tag.get_property("HEIGHT", height);
620         width = file->tag.get_property("WIDTH", width);
621         layers = file->tag.get_property("LAYERS", layers);
622 // This is loaded from the index file after the EDL but this 
623 // should be overridable in the EDL.
624         if(!frame_rate) frame_rate = file->tag.get_property("FRAMERATE", frame_rate);
625         vcodec[0] = 0;
626         file->tag.get_property("VCODEC", vcodec);
628         video_length = file->tag.get_property("VIDEO_LENGTH", 0);
633         jpeg_quality = file->tag.get_property("JPEG_QUALITY", jpeg_quality);
638         vmpeg_iframe_distance = file->tag.get_property("VMPEG_IFRAME_DISTANCE", vmpeg_iframe_distance);
639         vmpeg_bframe_distance = file->tag.get_property("VMPEG_BFRAME_DISTANCE", vmpeg_bframe_distance);
640         vmpeg_progressive = file->tag.get_property("VMPEG_PROGRESSIVE", vmpeg_progressive);
641         vmpeg_denoise = file->tag.get_property("VMPEG_DENOISE", vmpeg_denoise);
642         vmpeg_bitrate = file->tag.get_property("VMPEG_BITRATE", vmpeg_bitrate);
643         vmpeg_derivative = file->tag.get_property("VMPEG_DERIVATIVE", vmpeg_derivative);
644         vmpeg_quantization = file->tag.get_property("VMPEG_QUANTIZATION", vmpeg_quantization);
645         vmpeg_cmodel = file->tag.get_property("VMPEG_CMODEL", vmpeg_cmodel);
646         vmpeg_fix_bitrate = file->tag.get_property("VMPEG_FIX_BITRATE", vmpeg_fix_bitrate);
647         vmpeg_seq_codes = file->tag.get_property("VMPEG_SEQ_CODES", vmpeg_seq_codes);
650         divx_bitrate = file->tag.get_property("DIVX_BITRATE", divx_bitrate);
651         divx_rc_period = file->tag.get_property("DIVX_RC_PERIOD", divx_rc_period);
652         divx_rc_reaction_ratio = file->tag.get_property("DIVX_RC_REACTION_RATIO", divx_rc_reaction_ratio);
653         divx_rc_reaction_period = file->tag.get_property("DIVX_RC_REACTION_PERIOD", divx_rc_reaction_period);
654         divx_max_key_interval = file->tag.get_property("DIVX_MAX_KEY_INTERVAL", divx_max_key_interval);
655         divx_max_quantizer = file->tag.get_property("DIVX_MAX_QUANTIZER", divx_max_quantizer);
656         divx_min_quantizer = file->tag.get_property("DIVX_MIN_QUANTIZER", divx_min_quantizer);
657         divx_quantizer = file->tag.get_property("DIVX_QUANTIZER", divx_quantizer);
658         divx_quality = file->tag.get_property("DIVX_QUALITY", divx_quality);
659         divx_fix_bitrate = file->tag.get_property("DIVX_FIX_BITRATE", divx_fix_bitrate);
660         divx_use_deblocking = file->tag.get_property("DIVX_USE_DEBLOCKING", divx_use_deblocking);
662         ms_bitrate = file->tag.get_property("MS_BITRATE", ms_bitrate);
663         ms_bitrate_tolerance = file->tag.get_property("MS_BITRATE_TOLERANCE", ms_bitrate_tolerance);
664         ms_interlaced = file->tag.get_property("MS_INTERLACED", ms_interlaced);
665         ms_quantization = file->tag.get_property("MS_QUANTIZATION", ms_quantization);
666         ms_gop_size = file->tag.get_property("MS_GOP_SIZE", ms_gop_size);
667         ms_fix_bitrate = file->tag.get_property("MS_FIX_BITRATE", ms_fix_bitrate);
671         png_use_alpha = file->tag.get_property("PNG_USE_ALPHA", png_use_alpha);
676         video_data = 1;
677         return 0;
680 int Asset::read_index(FileXML *file)
682         if(index_offsets) delete [] index_offsets;
683         index_offsets = new int64_t[channels];
684         for(int i = 0; i < channels; i++) index_offsets[i] = 0;
686         int current_offset = 0;
687         int result = 0;
689         index_zoom = file->tag.get_property("ZOOM", 1);
690         index_bytes = file->tag.get_property("BYTES", (int64_t)0);
692         while(!result)
693         {
694                 result = file->read_tag();
695                 if(!result)
696                 {
697                         if(file->tag.title_is("/INDEX"))
698                         {
699                                 result = 1;
700                         }
701                         else
702                         if(file->tag.title_is("OFFSET"))
703                         {
704                                 if(current_offset < channels)
705                                 {
706                                         index_offsets[current_offset++] = file->tag.get_property("FLOAT", 0);
707 //printf("Asset::read_index %d %d\n", current_offset - 1, index_offsets[current_offset - 1]);
708                                 }
709                         }
710                 }
711         }
712         return 0;
715 // Output path is the path of the output file if name truncation is desired.
716 // It is a "" if complete names should be used.
718 int Asset::write(ArrayList<PluginServer*> *plugindb, 
719         FileXML *file, 
720         int include_index, 
721         char *output_path)
723         char new_path[1024];
724         char asset_directory[1024], output_directory[1024];
725         FileSystem fs;
727 // Make path relative
728         fs.extract_dir(asset_directory, path);
729         if(output_path && output_path[0]) 
730                 fs.extract_dir(output_directory, output_path);
731         else
732                 output_directory[0] = 0;
734         if(!strcmp(asset_directory, output_directory))
735         {
736                 fs.extract_name(new_path, path);
737         }
738         else
739         {
740                 strcpy(new_path, path);
741         }
743         file->tag.set_title("ASSET");
744         file->tag.set_property("SRC", new_path);
745         file->append_tag();
746         file->append_newline();
748         file->tag.set_title("FOLDER");
749         file->append_tag();
750         file->append_text(folder);
751         file->tag.set_title("/FOLDER");
752         file->append_tag();
753         file->append_newline();
755 // Write the format information
756         file->tag.set_title("FORMAT");
758         {
759                 file->tag.set_property("TYPE", 
760                         File::formattostr(plugindb, format));
761                 file->tag.set_property("USE_HEADER", use_header);
762         }
764         file->append_tag();
765         file->append_newline();
767         if(audio_data) write_audio(file);
768         if(video_data) write_video(file);
769         if(index_status == 0 && include_index) write_index(file);  // index goes after source
771         file->tag.set_title("/ASSET");
772         file->append_tag();
773         file->append_newline();
774         return 0;
777 int Asset::write_audio(FileXML *file)
779         file->tag.set_title("AUDIO");
780         file->tag.set_property("CHANNELS", channels);
781         file->tag.set_property("RATE", sample_rate);
782         file->tag.set_property("BITS", bits);
783         file->tag.set_property("BYTE_ORDER", byte_order);
784         file->tag.set_property("SIGNED", signed_);
785         file->tag.set_property("HEADER", header);
786         file->tag.set_property("DITHER", dither);
787         if(acodec[0])
788                 file->tag.set_property("ACODEC", acodec);
789         
790         file->tag.set_property("AUDIO_LENGTH", audio_length);
795         file->tag.set_property("AMPEG_BITRATE", ampeg_bitrate);
796         file->tag.set_property("AMPEG_DERIVATIVE", ampeg_derivative);
798         file->tag.set_property("VORBIS_VBR", vorbis_vbr);
799         file->tag.set_property("VORBIS_MIN_BITRATE", vorbis_min_bitrate);
800         file->tag.set_property("VORBIS_BITRATE", vorbis_bitrate);
801         file->tag.set_property("VORBIS_MAX_BITRATE", vorbis_max_bitrate);
803         file->tag.set_property("MP3_BITRATE", mp3_bitrate);
808         file->append_tag();
809         file->append_newline();
810         return 0;
813 int Asset::write_video(FileXML *file)
815         file->tag.set_title("VIDEO");
816         file->tag.set_property("HEIGHT", height);
817         file->tag.set_property("WIDTH", width);
818         file->tag.set_property("LAYERS", layers);
819         file->tag.set_property("FRAMERATE", frame_rate);
820         if(vcodec[0])
821                 file->tag.set_property("VCODEC", vcodec);
823         file->tag.set_property("VIDEO_LENGTH", video_length);
827         file->tag.set_property("JPEG_QUALITY", jpeg_quality);
829         file->tag.set_property("VMPEG_IFRAME_DISTANCE", vmpeg_iframe_distance);
830         file->tag.set_property("VMPEG_BFRAME_DISTANCE", vmpeg_bframe_distance);
831         file->tag.set_property("VMPEG_PROGRESSIVE", vmpeg_progressive);
832         file->tag.set_property("VMPEG_DENOISE", vmpeg_denoise);
833         file->tag.set_property("VMPEG_BITRATE", vmpeg_bitrate);
834         file->tag.set_property("VMPEG_DERIVATIVE", vmpeg_derivative);
835         file->tag.set_property("VMPEG_QUANTIZATION", vmpeg_quantization);
836         file->tag.set_property("VMPEG_CMODEL", vmpeg_cmodel);
837         file->tag.set_property("VMPEG_FIX_BITRATE", vmpeg_fix_bitrate);
838         file->tag.set_property("VMPEG_SEQ_CODES", vmpeg_seq_codes);
841         file->tag.set_property("DIVX_BITRATE", divx_bitrate);
842         file->tag.set_property("DIVX_RC_PERIOD", divx_rc_period);
843         file->tag.set_property("DIVX_RC_REACTION_RATIO", divx_rc_reaction_ratio);
844         file->tag.set_property("DIVX_RC_REACTION_PERIOD", divx_rc_reaction_period);
845         file->tag.set_property("DIVX_MAX_KEY_INTERVAL", divx_max_key_interval);
846         file->tag.set_property("DIVX_MAX_QUANTIZER", divx_max_quantizer);
847         file->tag.set_property("DIVX_MIN_QUANTIZER", divx_min_quantizer);
848         file->tag.set_property("DIVX_QUANTIZER", divx_quantizer);
849         file->tag.set_property("DIVX_QUALITY", divx_quality);
850         file->tag.set_property("DIVX_FIX_BITRATE", divx_fix_bitrate);
851         file->tag.set_property("DIVX_USE_DEBLOCKING", divx_use_deblocking);
854         file->tag.set_property("MS_BITRATE", ms_bitrate);
855         file->tag.set_property("MS_BITRATE_TOLERANCE", ms_bitrate_tolerance);
856         file->tag.set_property("MS_INTERLACED", ms_interlaced);
857         file->tag.set_property("MS_QUANTIZATION", ms_quantization);
858         file->tag.set_property("MS_GOP_SIZE", ms_gop_size);
859         file->tag.set_property("MS_FIX_BITRATE", ms_fix_bitrate);
863         file->tag.set_property("PNG_USE_ALPHA", png_use_alpha);
869         file->append_tag();
870         file->append_newline();
871         return 0;
874 int Asset::write_index(FileXML *file)
876         file->tag.set_title("INDEX");
877         file->tag.set_property("ZOOM", index_zoom);
878         file->tag.set_property("BYTES", index_bytes);
879         file->append_tag();
880         file->append_newline();
882         if(index_offsets)
883         {
884                 for(int i = 0; i < channels; i++)
885                 {
886                         file->tag.set_title("OFFSET");
887                         file->tag.set_property("FLOAT", index_offsets[i]);
888                         file->append_tag();
889                 }
890         }
892         file->append_newline();
893         file->tag.set_title("/INDEX");
894         file->append_tag();
895         file->append_newline();
896         return 0;
902 char* Asset::construct_param(char *param, char *prefix, char *return_value)
904         if(prefix)
905                 sprintf(return_value, "%s%s", prefix, param);
906         else
907                 strcpy(return_value, param);
908         return return_value;
911 #define UPDATE_DEFAULT(x, y) defaults->update(construct_param(x, prefix, string), y);
912 #define GET_DEFAULT(x, y) defaults->get(construct_param(x, prefix, string), y);
914 void Asset::load_defaults(Defaults *defaults, 
915         char *prefix, 
916         int do_codecs)
918         char string[BCTEXTLEN];
920 // Can't save codec here because it's specific to render, record, and effect.
921 // The codec has to be UNKNOWN for file probing to work.
923         if(do_codecs)
924         {
925                 GET_DEFAULT("PATH", path);
926                 format = GET_DEFAULT("FORMAT", format);
927                 GET_DEFAULT("AUDIO_CODEC", acodec);
928         }
929         ampeg_bitrate = GET_DEFAULT("AMPEG_BITRATE", ampeg_bitrate);
930         ampeg_derivative = GET_DEFAULT("AMPEG_DERIVATIVE", ampeg_derivative);
932         vorbis_vbr = GET_DEFAULT("VORBIS_VBR", vorbis_vbr);
933         vorbis_min_bitrate = GET_DEFAULT("VORBIS_MIN_BITRATE", vorbis_min_bitrate);
934         vorbis_bitrate = GET_DEFAULT("VORBIS_BITRATE", vorbis_bitrate);
935         vorbis_max_bitrate = GET_DEFAULT("VORBIS_MAX_BITRATE", vorbis_max_bitrate);
937         mp3_bitrate = GET_DEFAULT("MP3_BITRATE", mp3_bitrate);
940 // Can't save codec here because it's specific to render, record, and effect
941         if(do_codecs) GET_DEFAULT("VIDEO_CODEC", vcodec);
943         jpeg_quality = GET_DEFAULT("JPEG_QUALITY", jpeg_quality);
945 // MPEG format information
946         vmpeg_iframe_distance = GET_DEFAULT("VMPEG_IFRAME_DISTANCE", vmpeg_iframe_distance);
947         vmpeg_bframe_distance = GET_DEFAULT("VMPEG_BFRAME_DISTANCE", vmpeg_bframe_distance);
948         vmpeg_progressive = GET_DEFAULT("VMPEG_PROGRESSIVE", vmpeg_progressive);
949         vmpeg_denoise = GET_DEFAULT("VMPEG_DENOISE", vmpeg_denoise);
950         vmpeg_bitrate = GET_DEFAULT("VMPEG_BITRATE", vmpeg_bitrate);
951         vmpeg_derivative = GET_DEFAULT("VMPEG_DERIVATIVE", vmpeg_derivative);
952         vmpeg_quantization = GET_DEFAULT("VMPEG_QUANTIZATION", vmpeg_quantization);
953         vmpeg_cmodel = GET_DEFAULT("VMPEG_CMODEL", vmpeg_cmodel);
954         vmpeg_fix_bitrate = GET_DEFAULT("VMPEG_FIX_BITRATE", vmpeg_fix_bitrate);
955         vmpeg_seq_codes = GET_DEFAULT("VMPEG_SEQ_CODES", vmpeg_seq_codes);
958         divx_bitrate = GET_DEFAULT("DIVX_BITRATE", divx_bitrate);
959         divx_rc_period = GET_DEFAULT("DIVX_RC_PERIOD", divx_rc_period);
960         divx_rc_reaction_ratio = GET_DEFAULT("DIVX_RC_REACTION_RATIO", divx_rc_reaction_ratio);
961         divx_rc_reaction_period = GET_DEFAULT("DIVX_RC_REACTION_PERIOD", divx_rc_reaction_period);
962         divx_max_key_interval = GET_DEFAULT("DIVX_MAX_KEY_INTERVAL", divx_max_key_interval);
963         divx_max_quantizer = GET_DEFAULT("DIVX_MAX_QUANTIZER", divx_max_quantizer);
964         divx_min_quantizer = GET_DEFAULT("DIVX_MIN_QUANTIZER", divx_min_quantizer);
965         divx_quantizer = GET_DEFAULT("DIVX_QUANTIZER", divx_quantizer);
966         divx_quality = GET_DEFAULT("DIVX_QUALITY", divx_quality);
967         divx_fix_bitrate = GET_DEFAULT("DIVX_FIX_BITRATE", divx_fix_bitrate);
968         divx_use_deblocking = GET_DEFAULT("DIVX_USE_DEBLOCKING", divx_use_deblocking);
970         ms_bitrate = GET_DEFAULT("MS_BITRATE", ms_bitrate);
971         ms_bitrate_tolerance = GET_DEFAULT("MS_BITRATE_TOLERANCE", ms_bitrate_tolerance);
972         ms_interlaced = GET_DEFAULT("MS_INTERLACED", ms_interlaced);
973         ms_quantization = GET_DEFAULT("MS_QUANTIZATION", ms_quantization);
974         ms_gop_size = GET_DEFAULT("MS_GOP_SIZE", ms_gop_size);
975         ms_fix_bitrate = GET_DEFAULT("MS_FIX_BITRATE", ms_fix_bitrate);
978         png_use_alpha = GET_DEFAULT("PNG_USE_ALPHA", png_use_alpha);
981 void Asset::save_defaults(Defaults *defaults, char *prefix)
983         char string[BCTEXTLEN];
985         UPDATE_DEFAULT("PATH", path);
986         UPDATE_DEFAULT("FORMAT", format);
987         UPDATE_DEFAULT("AUDIO_CODEC", acodec);
988         UPDATE_DEFAULT("AMPEG_BITRATE", ampeg_bitrate);
989         UPDATE_DEFAULT("AMPEG_DERIVATIVE", ampeg_derivative);
991         UPDATE_DEFAULT("VORBIS_VBR", vorbis_vbr);
992         UPDATE_DEFAULT("VORBIS_MIN_BITRATE", vorbis_min_bitrate);
993         UPDATE_DEFAULT("VORBIS_BITRATE", vorbis_bitrate);
994         UPDATE_DEFAULT("VORBIS_MAX_BITRATE", vorbis_max_bitrate);
995         
996         UPDATE_DEFAULT("MP3_BITRATE", mp3_bitrate);
1001         UPDATE_DEFAULT("VIDEO_CODEC", vcodec);
1003         UPDATE_DEFAULT("JPEG_QUALITY", jpeg_quality);
1005 // MPEG format information
1006         UPDATE_DEFAULT("VMPEG_IFRAME_DISTANCE", vmpeg_iframe_distance);
1007         UPDATE_DEFAULT("VMPEG_BFRAME_DISTANCE", vmpeg_bframe_distance);
1008         UPDATE_DEFAULT("VMPEG_PROGRESSIVE", vmpeg_progressive);
1009         UPDATE_DEFAULT("VMPEG_DENOISE", vmpeg_denoise);
1010         UPDATE_DEFAULT("VMPEG_BITRATE", vmpeg_bitrate);
1011         UPDATE_DEFAULT("VMPEG_DERIVATIVE", vmpeg_derivative);
1012         UPDATE_DEFAULT("VMPEG_QUANTIZATION", vmpeg_quantization);
1013         UPDATE_DEFAULT("VMPEG_CMODEL", vmpeg_cmodel);
1014         UPDATE_DEFAULT("VMPEG_FIX_BITRATE", vmpeg_fix_bitrate);
1015         UPDATE_DEFAULT("VMPEG_SEQ_CODES", vmpeg_seq_codes);
1019         UPDATE_DEFAULT("DIVX_BITRATE", divx_bitrate);
1020         UPDATE_DEFAULT("DIVX_RC_PERIOD", divx_rc_period);
1021         UPDATE_DEFAULT("DIVX_RC_REACTION_RATIO", divx_rc_reaction_ratio);
1022         UPDATE_DEFAULT("DIVX_RC_REACTION_PERIOD", divx_rc_reaction_period);
1023         UPDATE_DEFAULT("DIVX_MAX_KEY_INTERVAL", divx_max_key_interval);
1024         UPDATE_DEFAULT("DIVX_MAX_QUANTIZER", divx_max_quantizer);
1025         UPDATE_DEFAULT("DIVX_MIN_QUANTIZER", divx_min_quantizer);
1026         UPDATE_DEFAULT("DIVX_QUANTIZER", divx_quantizer);
1027         UPDATE_DEFAULT("DIVX_QUALITY", divx_quality);
1028         UPDATE_DEFAULT("DIVX_FIX_BITRATE", divx_fix_bitrate);
1029         UPDATE_DEFAULT("DIVX_USE_DEBLOCKING", divx_use_deblocking);
1032         UPDATE_DEFAULT("MS_BITRATE", ms_bitrate);
1033         UPDATE_DEFAULT("MS_BITRATE_TOLERANCE", ms_bitrate_tolerance);
1034         UPDATE_DEFAULT("MS_INTERLACED", ms_interlaced);
1035         UPDATE_DEFAULT("MS_QUANTIZATION", ms_quantization);
1036         UPDATE_DEFAULT("MS_GOP_SIZE", ms_gop_size);
1037         UPDATE_DEFAULT("MS_FIX_BITRATE", ms_fix_bitrate);
1039         UPDATE_DEFAULT("PNG_USE_ALPHA", png_use_alpha);
1050 int Asset::update_path(char *new_path)
1052         strcpy(path, new_path);
1053         return 0;
1056 void Asset::update_index(Asset *asset)
1058 //printf("Asset::update_index 1 %d\n", index_status);
1059         index_status = asset->index_status;
1060         index_zoom = asset->index_zoom;          // zoom factor of index data
1061         index_start = asset->index_start;        // byte start of index data in the index file
1062         index_bytes = asset->index_bytes;        // Total bytes in source file for comparison before rebuilding the index
1063         index_end = asset->index_end;
1064         old_index_end = asset->old_index_end;    // values for index build
1065 //printf("Asset::update_index 1\n");
1067         if(index_offsets)
1068         {
1069                 delete [] index_offsets;
1070                 index_offsets = 0;
1071         }
1072         
1073         if(asset->index_offsets)
1074         {
1075                 index_offsets = new int64_t[asset->channels];
1076 //printf("Asset::update_index 1\n");
1078                 int i;
1079                 for(i = 0; i < asset->channels; i++)
1080                 {
1081                         index_offsets[i] = asset->index_offsets[i];  // offsets of channels in index file in floats
1083                 }
1084         }
1085 //printf("Asset::update_index 1\n");
1086         index_buffer = asset->index_buffer;    // pointer
1087 //printf("Asset::update_index 2\n");
1091 int Asset::dump()
1093         printf("  asset::dump\n");
1094         printf("   %p %s\n", this, path);
1095         printf("   index_status %d\n", index_status);
1096         printf("   format %d\n", format);
1097         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",
1098                 audio_data, channels, sample_rate, bits, byte_order, signed_, header, dither, acodec[0], acodec[1], acodec[2], acodec[3]);
1099         printf("   audio_length %lld\n", audio_length);
1100         printf("   video_data %d layers %d framerate %f width %d height %d vcodec %c%c%c%c\n",
1101                 video_data, layers, frame_rate, width, height, vcodec[0], vcodec[1], vcodec[2], vcodec[3]);
1102         printf("   video_length %lld \n", video_length);
1103         return 0;