r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / fileavi.C
blob07dcff04b5e30a946b069d3a79e920978c65bde5
1 #include "assets.h"
3 #ifdef USE_AVIFILE
4 #include "avifile.h"
5 #include "creators.h"
6 #include "except.h"
7 #include "fourcc.h"
8 #include "StreamInfo.h"
9 #endif
11 #include "clip.h"
12 #include "file.h"
13 #include "fileavi.h"
14 #include "fileavi.inc"
15 #include "mwindow.inc"
16 #include "vframe.h"
19 #include <string.h>
21 #include <libintl.h>
22 #define _(String) gettext(String)
23 #define gettext_noop(String) String
24 #define N_(String) gettext_noop (String)
30 #ifdef USE_AVIFILE
31 int FileAVI::avifile_initialized = 0;
32 #endif
37 // Status of AVI derivatives:
38 // Arne2 - depends on Kino, DV only
39 // Lavtools - 2 gig limited
52 FileAVI::FileAVI(Asset *asset, File *file)
53  : FileBase(asset, file)
55         reset();
58 FileAVI::~FileAVI()
60         close_file();
63 int FileAVI::check_sig(Asset *asset)
65 // Pick whoever gets the most tracks
66         int score_lavtools = 0;
67         int score_arne2 = 0;
68         int score_arne1 = 0;
69         int score_avifile = 0;
70         int final = 0;
71         int result = 0;
77         check_sig_lavtools(asset, score_lavtools);
78         check_sig_arne2(asset, score_arne2);
79         check_sig_arne1(asset, score_arne1);
80         check_sig_avifile(asset, score_avifile);
82         if(score_lavtools > final) 
83         {
84                 final = score_lavtools;
85                 result = FILE_AVI_LAVTOOLS;
86         }
87         if(score_arne2 > final)
88         {
89                 final = score_arne2;
90                 result = FILE_AVI_ARNE2;
91         }
92         if(score_arne1 > final)
93         {
94                 final = score_arne1;
95                 result = FILE_AVI_ARNE1;
96         }
97         if(score_avifile > final)
98         {
99                 final = score_avifile;
100                 result = FILE_AVI_AVIFILE;
101         }
109         return result;
112 int FileAVI::check_sig_arne2(Asset *asset, int &score)
114         return 0;
117 int FileAVI::check_sig_arne1(Asset *asset, int &score)
119         return 0;
122 int FileAVI::check_sig_lavtools(Asset *asset, int &score)
124         return 0;
127 int FileAVI::check_sig_avifile(Asset *asset, int &score)
129 return 0;
130 #ifdef USE_AVIFILE
131         IAviReadFile *in_fd = 0;
133         try
134         {
135                 in_fd = CreateIAviReadFile(asset->path);
136         }
137         catch(FatalError& error)
138         {
139                 if(in_fd) delete in_fd;
140                 return 0;
141         }
143         int vtracks = in_fd->VideoStreamCount();
144         int atracks = in_fd->AudioStreamCount();
146         delete in_fd;
147         
148         score = vtracks + atracks;
149         return 1;
150 #endif
151         return 0;
155 char* FileAVI::vcodec_to_fourcc(char *input, char *output)
157 #ifdef USE_AVIFILE
158         initialize_avifile();
159         for(avm::vector<CodecInfo>::iterator i = video_codecs.begin();
160                 i < video_codecs.end();
161                 i++)
162         {
163                 if(i->direction & CodecInfo::Encode)
164                 {
165                         if(!strcasecmp(i->GetName(), input))
166                         {
167                                 memcpy(output, (char*)&i->fourcc, 4);
168                                 output[4] = 0;
169                                 return output;
170                         }
171                 }
172         }
173         
174         output[0] = 0;
175         return output;
176 #else
177         return input;
178 #endif
181 char* FileAVI::fourcc_to_vcodec(char *input, char *output)
183 #ifdef USE_AVIFILE
184 // Construct codec item list
185         initialize_avifile();
186         for(avm::vector<CodecInfo>::iterator i = video_codecs.begin();
187                 i < video_codecs.end();
188                 i++)
189         {
190                 if(i->direction & CodecInfo::Encode)
191                 {
192                         if(!memcmp((char*)&i->fourcc, input, 4))
193                         {
194                                 memcpy(output, (char*)&i->fourcc, 4);
195                                 strcpy(output, i->GetName());;
196                                 return output;
197                         }
198                 }
199         }
200         
201         output[0] = 0;
202         return output;
203 #else
204         return input;
205 #endif
209 char* FileAVI::acodec_to_fourcc(char *input, char *output)
211 #ifdef USE_AVIFILE
212 // Construct codec item list
213         initialize_avifile();
214         for(avm::vector<CodecInfo>::iterator i = audio_codecs.begin();
215                 i < audio_codecs.end();
216                 i++)
217         {
218                 if(i->direction & CodecInfo::Encode)
219                 {
220                         if(!strcasecmp(i->GetName(), input))
221                         {
222                                 memcpy(output, (char*)&i->fourcc, 4);
223                                 output[4] = 0;
224                                 return output;
225                         }
226                 }
227         }
229         output[0] = 0;
230         return output;
231 #else
232         return input;
233 #endif
236 char* FileAVI::fourcc_to_acodec(char *input, char *output)
238 #ifdef USE_AVIFILE
239 // Construct codec item list
240         initialize_avifile();
241         for(avm::vector<CodecInfo>::iterator i = audio_codecs.begin();
242                 i < audio_codecs.end();
243                 i++)
244         {
245                 if(i->direction & CodecInfo::Encode)
246                 {
247                         if(!memcmp((char*)&i->fourcc, input, 4))
248                         {
249                                 memcpy(output, (char*)&i->fourcc, 4);
250                                 strcpy(output, i->GetName());
251                                 return output;
252                         }
253                 }
254         }
255         
256         output[0] = 0;
257         return output;
258 #else
259         return input;
260 #endif
264 void FileAVI::initialize_avifile()
266 #ifdef USE_AVIFILE
267         if(!avifile_initialized)
268         {
269         BITMAPINFOHEADER bih;
270         bih.biCompression = 0xffffffff;
271         Creators::CreateVideoDecoder(bih, 0, 0);
273         WAVEFORMATEX wih;
274         memset(&wih, 0xff, sizeof(WAVEFORMATEX));
275                 Creators::CreateAudioDecoder(&wih, 0);
276                 avifile_initialized = 1;
277         }
278 #endif
282 int FileAVI::open_file(int rd, int wr)
284         if(wr)
285         {
286                 switch(asset->format)
287                 {
288                         case FILE_AVI_LAVTOOLS:
289                                 return open_lavtools_out(asset);
290                                 break;
292                         case FILE_AVI_ARNE2:
293                                 return open_arne2_out(asset);
294                                 break;
296                         case FILE_AVI_ARNE1:
297                                 return open_arne1_out(asset);
298                                 break;
300                         case FILE_AVI_AVIFILE:
301                                 return open_avifile_out(asset);
302                                 break;
303                 }
304         }
305         else
306         if(rd)
307         {
308                 asset->format = check_sig(asset);
311                 switch(asset->format)
312                 {
313                         case FILE_AVI_LAVTOOLS:
314                                 return open_lavtools_in(asset);
315                                 break;
317                         case FILE_AVI_ARNE2:
318                                 return open_arne2_in(asset);
319                                 break;
321                         case FILE_AVI_ARNE1:
322                                 return open_arne1_in(asset);
323                                 break;
325                         case FILE_AVI_AVIFILE:
326                                 return open_avifile_in(asset);
327                                 break;
328                 }
329         }
331         return 0;
336 int FileAVI::open_avifile_out(Asset *asset)
338 #ifdef USE_AVIFILE
339         try
340         {
341                 out_fd = CreateIAviWriteFile(asset->path);
342         }
343         catch(FatalError& error)
344         {
345                 error.Print();
346                 close_file();
347                 return 1;
348         }
350         if(asset->video_data)
351         {
352                 out_color_model = get_best_colormodel(-1, -1);
353                 out_bitmap_info = new BitmapInfo(asset->width, asset->height, 
354                         cmodel_bc_to_avi(out_color_model));
355                 for(int i = 0; i < asset->layers && i < MAX_STREAMS; i++)
356                 {
357                         vstream_out[i] = out_fd->AddVideoStream(*(uint32_t*)asset->vcodec, 
358                                 out_bitmap_info, 
359                                 int(1000000.0 / asset->frame_rate));
360                 }
361         }
363         if(asset->audio_data)
364         {
365                 WAVEFORMATEX wfm;
366                 wfm.wFormatTag = 1; // PCM
367                 wfm.nChannels = asset->channels;
368                 wfm.nSamplesPerSec = asset->sample_rate;
369                 wfm.nAvgBytesPerSec = 2 * asset->sample_rate * asset->channels;
370                 wfm.nBlockAlign = 2 * asset->channels;
371                 wfm.wBitsPerSample = 16;
372                 wfm.cbSize = 0;
374                 for(int i = 0; i < asset->channels && i < MAX_STREAMS; i++)
375                 {
376                         astream_out[i] = out_fd->AddStream(AviStream::Audio,
377                                 &wfm, 
378                                 sizeof(wfm),
379                                 1,                   // uncompressed PCM data
380                                 wfm.nAvgBytesPerSec, // bytes/sec
381                                 wfm.nBlockAlign);    // bytes/sample
382                 }
383         }
385         return 0;
386 #endif
387         return 1;
390 int FileAVI::open_arne2_out(Asset *asset)
392         
393         return 0;
396 int FileAVI::open_arne1_out(Asset *asset)
398         return 0;
401 int FileAVI::open_lavtools_out(Asset *asset)
403         return 0;
406         
407         
408         
411 int FileAVI::open_avifile_in(Asset *asset)
413 #ifdef USE_AVIFILE
414         try
415         {
416                 in_fd = CreateIAviReadFile(asset->path);
417         }
418         catch(FatalError& error)
419         {
420                 error.Print();
421                 close_file();
422                 return 1;
423         }
425         asset->layers = in_fd->VideoStreamCount();
426         if(asset->layers)
427         {
428                 for(int i = 0; i < asset->layers && i < MAX_STREAMS; i++)
429                 {
430                         vstream_in[i] = in_fd->GetStream(i, IAviReadStream::Video);
431                         vstream_in[i]->StartStreaming();
432                         vstream_in[i]->GetDecoder()->SetDestFmt(24);
433                         vstream_in[i]->Seek(0);
434 //printf("FileAVI::open_file %d %p\n", i, vstream[i]);
435                 }
437                 StreamInfo *stream_info = vstream_in[0]->GetStreamInfo();
438                 asset->video_data = 1;
439                 if(!asset->frame_rate)
440                         asset->frame_rate = (double)1 / vstream_in[0]->GetFrameTime();
441                 asset->video_length = stream_info->GetStreamFrames();
442             BITMAPINFOHEADER bh;
443                 vstream_in[0]->GetVideoFormatInfo(&bh, sizeof(bh));
444             asset->width = bh.biWidth;
445             asset->height = bh.biHeight;
447                 uint32_t fourcc = stream_info->GetFormat();
448                 asset->vcodec[0] = ((char*)&fourcc)[0];
449                 asset->vcodec[1] = ((char*)&fourcc)[1];
450                 asset->vcodec[2] = ((char*)&fourcc)[2];
451                 asset->vcodec[3] = ((char*)&fourcc)[3];
452                 source_cmodel = BC_RGB888;
453                 delete stream_info;
454         }
456         asset->audio_data = in_fd->AudioStreamCount();
458         if(asset->audio_data)
459         {
460                 char *extinfo;
462                 for(int i = 0; i < 1 && i < MAX_STREAMS; i++)
463                 {
464                         astream_in[i] = in_fd->GetStream(i, IAviReadStream::Audio);
465                         astream_in[i]->StartStreaming();
466                 }
468                 StreamInfo *stream_info = astream_in[0]->GetStreamInfo();
469                 asset->channels = stream_info->GetAudioChannels();
470                 if(asset->sample_rate == 0)
471                         asset->sample_rate = stream_info->GetAudioSamplesPerSec();
472                 asset->bits = MAX(16, stream_info->GetAudioBitsPerSample());
473                 asset->audio_length = stream_info->GetStreamFrames();
474                 delete stream_info;
475         }
476 asset->dump();
477         return 0;
478 #endif
479         return 1;
482 int FileAVI::open_arne2_in(Asset *asset)
484         return 0;
487 int FileAVI::open_arne1_in(Asset *asset)
489         return 0;
492 int FileAVI::open_lavtools_in(Asset *asset)
494         return 0;
514 int FileAVI::close_file()
516 #ifdef USE_AVIFILE
517         if(in_fd) delete in_fd;
518         if(out_fd) delete out_fd;
519         if(out_bitmap_info) delete out_bitmap_info;
520 #endif
521         if(temp_audio) delete [] temp_audio;
522         reset();
525 int FileAVI::cmodel_bc_to_avi(int input)
527 #ifdef USE_AVIFILE
528         switch(input)
529         {
530                 case BC_YUV422:
531                         return fccYUY2;
532                         break;
534                 case BC_YUV420P:
535                         return fccYV12;
536                         break;
537         }
538 #endif
539         return 24;
542 void FileAVI::reset()
544 #ifdef USE_AVIFILE
545         in_fd = 0;
546         out_fd = 0;
547         out_bitmap_info = 0;
548 #endif
549         temp_audio = 0;
550         temp_allocated = 0;
553 int FileAVI::get_best_colormodel(int driver, int colormodel)
555         if(colormodel > -1)
556         {
557                 return colormodel;
558         }
559         else
560         {
561                 
562                 return BC_RGB888;
563         }
567 void FileAVI::get_parameters(BC_WindowBase *parent_window, 
568                 Asset *asset, 
569                 BC_WindowBase* &format_window,
570                 int audio_options,
571                 int video_options,
572                 int lock_compressor)
574         if(audio_options)
575         {
576                 AVIConfigAudio *window = new AVIConfigAudio(parent_window, asset);
577                 format_window = window;
578                 window->create_objects();
579                 window->run_window();
580                 delete window;
581         }
582         else
583         if(video_options)
584         {
585 //printf("FileAVI::get_parameters 1\n");
586                 AVIConfigVideo *window = new AVIConfigVideo(parent_window,
587                         asset,
588                         lock_compressor);
589                 format_window = window;
590                 window->create_objects();
591                 window->run_window();
592                 delete window;
593         }
596 int FileAVI::set_audio_position(int64_t x)
598 #ifdef USE_AVIFILE
599 // quicktime sets positions for each track seperately so store position in audio_position
600         if(x >= 0 && x < asset->audio_length)
601                 return astream_in[file->current_layer]->Seek(x);
602         else
603                 return 1;
604 #endif
607 int FileAVI::set_video_position(int64_t x)
609 #ifdef USE_AVIFILE
610         if(x >= 0 && x < asset->video_length)
611                 return vstream_in[file->current_layer]->Seek(x);
612         else
613                 return 1;
614 #endif
617 int FileAVI::read_samples(double *buffer, int64_t len)
619 #ifdef USE_AVIFILE
620         Unsigned samples_read, bytes_read;
622 printf("FileAVI::read_samples 1\n");
623         if(temp_audio && temp_allocated < len * asset->bits / 8 * asset->channels)
624         {
625                 delete [] temp_audio;
626                 temp_allocated = 0;
627         }
628         if(!temp_allocated)
629         {
630                 temp_allocated = len * asset->bits / 8 * asset->channels;
631                 temp_audio = new unsigned char[temp_allocated];
632         }
634         astream_in[0]->ReadFrames((void*)temp_audio, 
635                 (unsigned int)temp_allocated,
636                 (unsigned int)len,
637                 samples_read, 
638                 bytes_read);
639         
640 // Extract single channel
641         switch(asset->bits)
642         {
643                 case 16:
644                 {
645                         int16_t *temp_int16 = (int16_t*)temp_audio;
646                         for(int i = 0, j = file->current_channel; 
647                                 i < len;
648                                 i++, j += asset->channels)
649                         {
650                                 buffer[i] = (double)temp_int16[j] / 32767;
651                         }
652                         break;
653                 }
654         }
656 #endif
659         return 0;
662 int FileAVI::read_frame(VFrame *frame)
664         int result = 0;
666 #ifdef USE_AVIFILE
667         vstream_in[file->current_layer]->ReadFrame();
668         CImage *temp_image = vstream_in[file->current_layer]->GetFrame();
669 //printf("FileAVI::read_frame 1 %d %d\n", source_cmodel, frame->get_color_model());
670         switch(source_cmodel)
671         {
672                 case BC_RGB888:
673                         if(frame->get_color_model() == BC_RGB888)
674                                 bcopy(temp_image->Data(), 
675                                         frame->get_data(), 
676                                         VFrame::calculate_data_size(asset->width, 
677                                                 asset->height, 
678                                                 -1, 
679                                                 BC_RGB888));
680                         break;
681         }
682 #endif
683         return result;
686 int64_t FileAVI::compressed_frame_size()
688         int result = 0;
689         return result;
692 int FileAVI::read_compressed_frame(VFrame *buffer)
694         int64_t result = 0;
696         return result;
699 int FileAVI::write_compressed_frame(VFrame *buffer)
701         int result = 0;
703         return result;
706 int FileAVI::write_frames(VFrame ***frames, int len)
708         return 0;
712 int FileAVI::write_samples(double **buffer, int64_t len)
714         return 0;
721 AVIConfigAudio::AVIConfigAudio(BC_WindowBase *parent_window, Asset *asset)
722  : BC_Window(PROGRAM_NAME ": Audio compression",
723         parent_window->get_abs_cursor_x(),
724         parent_window->get_abs_cursor_y(),
725         calculate_w(asset->format),
726         calculate_h(asset->format))
728         this->parent_window = parent_window;
729         this->asset = asset;
732 AVIConfigAudio::~AVIConfigAudio()
736 int AVIConfigAudio::calculate_w(int format)
738         switch(format)
739         {
740                 case FILE_AVI_AVIFILE: return 400; break;
741                 case FILE_AVI_ARNE2: return 250; break;
742         }
745 int AVIConfigAudio::calculate_h(int format)
747         switch(format)
748         {
749                 case FILE_AVI_AVIFILE: return 200; break;
750                 case FILE_AVI_ARNE2: return 100; break;
751         }
754 int AVIConfigAudio::create_objects()
756         switch(asset->format)
757         {
758 #ifdef USE_AVIFILE
759                 case FILE_AVI_AVIFILE:
760                 {
761                         generate_codeclist();
763                         int x = 10, y = 10;
764                         BC_Title *title;
765                         add_subwindow(title = new BC_Title(x, y, _("Codec: ")));
766                         list = new AVIACodecList(this, x, y);
767                         list->create_objects();
768                         y += list->get_h();
769                         break;
770                 }
771 #endif
773                 case FILE_AVI_ARNE2:
774                         add_subwindow(new BC_Title(10, 10, _("Compressor: 16 bit PCM")));
775                         break;
776         }
778         add_subwindow(new BC_OKButton(this));
779         return 0;
782 int AVIConfigAudio::close_event()
784         return 1;
787 int AVIConfigAudio::generate_codeclist()
789         FileAVI::initialize_avifile();
790         codec_items.remove_all_objects();
792         switch(asset->format)
793         {
794 #ifdef USE_AVIFILE
795                 case FILE_AVI_AVIFILE:
796                         for(avm::vector<CodecInfo>::iterator i = audio_codecs.begin();
797                                 i < audio_codecs.end();
798                                 i++)
799                         {
800                                 if(i->direction & CodecInfo::Encode)
801                                 {
802                                         codec_items.append(new BC_ListBoxItem((char*)i->GetName()));
803                                 }
804                         }
805                         break;
806 #endif
807         }
809         return 0;
812 void AVIConfigAudio::update_codecs()
814         
825 AVIACodecList::AVIACodecList(AVIConfigAudio *gui, int x, int y)
826  : BC_PopupTextBox(gui,
827                 &gui->codec_items,
828                 FileAVI::fourcc_to_acodec(gui->asset->acodec, gui->string),
829                 x, 
830                 y,
831                 200,
832                 400)
834         this->gui = gui;
837 AVIACodecList::~AVIACodecList()
841 int AVIACodecList::handle_event()
843         strcpy(gui->asset->acodec, FileAVI::acodec_to_fourcc(get_text(), gui->string));
844         return 1;
851 AVIConfigVideo::AVIConfigVideo(BC_WindowBase *parent_window, 
852                 Asset *asset, 
853                 int lock_compressor)
854  : BC_Window(PROGRAM_NAME ": Video Compression",
855         parent_window->get_abs_cursor_x(),
856         parent_window->get_abs_cursor_y(),
857         calculate_w(asset->format),
858         calculate_h(asset->format))
860         this->parent_window = parent_window;
861         this->asset = asset;
862         this->lock_compressor = lock_compressor;
863         reset();
866 AVIConfigVideo::~AVIConfigVideo()
868         codec_items.remove_all_objects();
869         attribute_items[0].remove_all_objects();
870         attribute_items[1].remove_all_objects();
873 void AVIConfigVideo::reset()
875         attributes = 0;
876         attribute = 0;
879 int AVIConfigVideo::calculate_w(int format)
881         switch(format)
882         {
883                 case FILE_AVI_AVIFILE: return 400; break;
884                 case FILE_AVI_ARNE2: return 250; break;
885         }
888 int AVIConfigVideo::calculate_h(int format)
890         switch(format)
891         {
892                 case FILE_AVI_AVIFILE: return 320; break;
893                 case FILE_AVI_ARNE2: return 100; break;
894         }
897 int AVIConfigVideo::create_objects()
899         switch(asset->format)
900         {
901 #ifdef USE_AVIFILE
902                 case FILE_AVI_AVIFILE:
903                 {
904                         generate_codeclist();
905                         generate_attributelist();
907                         int x = 10, y = 10, x1 = 90;
908                         BC_Title *title;
909                         add_subwindow(title = new BC_Title(x, y, _("Codec: ")));
910                         list = new AVIVCodecList(this, x1, y);
911                         list->create_objects();
912                         y += list->get_h() + 5;
914                         add_subwindow(title = new BC_Title(x, y, _("Attributes:")));
915                         add_subwindow(attributes = new AVIVAttributeList(this, x1, y));
916                         y += attributes->get_h() + 5;
918                         add_subwindow(new BC_Title(x, y, _("Value:")));
919                         add_subwindow(attribute = new AVIVAttribute(this, x1, y));
920                         break;
921                 }
922 #endif
924                 case FILE_AVI_ARNE2:
925                         add_subwindow(new BC_Title(10, 10, _("Compressor: Consumer DV")));
926                         break;
927         }
929         add_subwindow(new BC_OKButton(this));
930         return 0;
933 int AVIConfigVideo::close_event()
935         return 1;
938 int AVIConfigVideo::generate_codeclist()
940         FileAVI::initialize_avifile();
941         switch(asset->format)
942         {
943                 case FILE_AVI_AVIFILE:
944 #ifdef USE_AVIFILE
945 // Construct codec item list
946                         for(avm::vector<CodecInfo>::iterator i = video_codecs.begin();
947                                 i < video_codecs.end();
948                                 i++)
949                         {
950                                 if(i->direction & CodecInfo::Encode)
951                                 {
952                                         codec_items.append(new BC_ListBoxItem((char*)i->GetName()));
953                                 }
954                         }
955 #endif
956                         break;
957         }
959         return 0;
962 void AVIConfigVideo::generate_attributelist()
964 #ifdef USE_AVIFILE
965 // Remember selection number
966         int selection_number = attributes ? attributes->get_selection_number(0, 0) : -1;
967         attribute_items[0].remove_all_objects();
968         attribute_items[1].remove_all_objects();
969         FileAVI::initialize_avifile();
971         for(avm::vector<CodecInfo>::iterator i = video_codecs.begin();
972                 i < video_codecs.end();
973                 i++)
974         {
975                 if(!memcmp((char*)&i->fourcc, asset->vcodec, 4))
976                 {
977                         avm::vector<AttributeInfo>& attributes = i->encoder_info;
979                         for(avm::vector<AttributeInfo>::const_iterator j = attributes.begin();
980                                 j < attributes.end();
981                                 j++)
982                         {
983                                 char *name = (char*)j->GetName();
984                                 char value[BCTEXTLEN];
985                                 value[0] = 0;
987 //printf("AVIConfigVideo::generate_attributelist %d\n", j->kind);
988                                 switch(j->kind)
989                                 {
990                                         case AttributeInfo::Integer:
991                                         {
992                                                 int temp = 0;
993                                                 Creators::GetCodecAttr(*i, name, temp);
994                                                 sprintf(value, "%d", temp);
995                                                 break;
996                                         }
998                                         case AttributeInfo::Select:
999                                         {
1000                                                 int temp = 0;
1001                                                 Creators::GetCodecAttr(*i, name, temp);
1002                                                 sprintf(value, "%d ( %s )", temp, j->options[temp].c_str());
1003                                                 break;
1004                                         }
1006                                         case AttributeInfo::String:
1007                                                 Creators::GetCodecAttr(*i, name, value, BCTEXTLEN);
1008                                                 break;
1009                                 }
1011                                 attribute_items[0].append(new BC_ListBoxItem(name));
1012                                 attribute_items[1].append(new BC_ListBoxItem(value));
1014                                 int current_number = j - attributes.begin();
1015                                 if(current_number == selection_number)
1016                                 {
1017                                         attribute_items[0].values[current_number]->set_selected(1);
1018                                         attribute_items[1].values[current_number]->set_selected(1);
1019                                 }
1020                         }
1021                 }
1022         }
1023 #endif
1026 char* AVIConfigVideo::get_current_attribute_text()
1028         BC_ListBoxItem *item = attributes->get_selection(0, 0);
1030         if(item)
1031         {
1032                 return item->get_text();
1033         }
1034         else
1035                 return "";
1038 char* AVIConfigVideo::get_current_attribute_value()
1040         BC_ListBoxItem *item = attributes->get_selection(1, 0);
1042         if(item)
1043         {
1044                 return item->get_text();
1045         }
1046         else
1047                 return "";
1050 void AVIConfigVideo::set_current_attribute(char *text)
1052 #ifdef USE_AVIFILE
1053         int number = attributes->get_selection_number(0, 0);
1055         if(number >= 0)
1056         {
1057                 FileAVI::initialize_avifile();
1059                 for(avm::vector<CodecInfo>::iterator i = video_codecs.begin();
1060                         i < video_codecs.end();
1061                         i++)
1062                 {
1063                         if(!memcmp((char*)&i->fourcc, asset->vcodec, 4))
1064                         {
1065                                 avm::vector<AttributeInfo>& attributes = i->encoder_info;
1066                                 AttributeInfo& attribute = attributes[number];
1068                                 switch(attribute.kind)
1069                                 {
1070                                         case AttributeInfo::Integer:
1071                                                 Creators::SetCodecAttr(*i, attribute.GetName(), atol(text));
1072                                                 break;
1074                                         case AttributeInfo::Select:
1075                                                 Creators::SetCodecAttr(*i, attribute.GetName(), atol(text));
1076                                                 break;
1078                                         case AttributeInfo::String:
1079                                                 Creators::SetCodecAttr(*i, attribute.GetName(), text);
1080                                                 break;
1081                                 }
1082                         }
1083                 }
1084                 
1085                 
1086                 update_attribute(1);
1087         }
1088 #endif
1093 void AVIConfigVideo::update_attribute(int recursive)
1095         generate_attributelist();
1096         attributes->update(attribute_items,
1097                                                 0,
1098                                                 0,
1099                                                 2,
1100                                                 attributes->get_xposition(),
1101                                                 attributes->get_yposition(), 
1102                                                 0,
1103                                                 1);
1105         if(!recursive) attribute->update(get_current_attribute_value());
1116 AVIVCodecList::AVIVCodecList(AVIConfigVideo *gui, int x, int y)
1117  : BC_PopupTextBox(gui,
1118                 &gui->codec_items,
1119                 FileAVI::fourcc_to_vcodec(gui->asset->vcodec, gui->string),
1120                 x, 
1121                 y,
1122                 280,
1123                 400)
1125         this->gui = gui;
1128 AVIVCodecList::~AVIVCodecList()
1132 int AVIVCodecList::handle_event()
1134         strcpy(gui->asset->vcodec, FileAVI::vcodec_to_fourcc(get_text(), gui->string));
1135         gui->update_attribute(0);
1136         return 1;
1141 AVIVAttributeList::AVIVAttributeList(AVIConfigVideo *gui, int x, int y)
1142  : BC_ListBox(x, 
1143                 y,
1144                 300,
1145                 200,
1146                 LISTBOX_TEXT,
1147                 gui->attribute_items,
1148                 0,
1149                 0,
1150                 2)
1152         this->gui = gui;
1155 int AVIVAttributeList::handle_event()
1157         gui->update_attribute(0);
1158         return 1;
1161 int AVIVAttributeList::selection_changed()
1163         gui->update_attribute(0);
1164         return 1;
1170 AVIVAttribute::AVIVAttribute(AVIConfigVideo *gui, int x, int y)
1171  : BC_TextBox(x, y, 300, 1, gui->get_current_attribute_value())
1173         this->gui = gui;
1176 int AVIVAttribute::handle_event()
1178         gui->set_current_attribute(get_text());
1179         return 1;