r1009: Move the dependencies to newer package names
[cinelerra_cv/mob.git] / cinelerra / fileavi.C
blobae2a3c780467c7dbc6c7a61fe6d84cb828649878
1 #include "asset.h"
3 #ifdef USE_AVIFILE
4 #include "avifile.h"
5 #include "creators.h"
6 #include "except.h"
7 #include "avm_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 "interlacemodes.h"
16 #include "mwindow.inc"
17 #include "vframe.h"
20 #include <string.h>
22 #include <libintl.h>
23 #define _(String) gettext(String)
24 #define gettext_noop(String) String
25 #define N_(String) gettext_noop (String)
31 #ifdef USE_AVIFILE
32 int FileAVI::avifile_initialized = 0;
33 #endif
38 // Status of AVI derivatives:
39 // Arne2 - depends on Kino, DV only
40 // Lavtools - 2 gig limited
53 FileAVI::FileAVI(Asset *asset, File *file)
54  : FileBase(asset, file)
56         reset();
59 FileAVI::~FileAVI()
61         close_file();
64 int FileAVI::check_sig(Asset *asset)
66 // Pick whoever gets the most tracks
67         int score_lavtools = 0;
68         int score_arne2 = 0;
69         int score_arne1 = 0;
70         int score_avifile = 0;
71         int final = 0;
72         int result = 0;
78         check_sig_lavtools(asset, score_lavtools);
79         check_sig_arne2(asset, score_arne2);
80         check_sig_arne1(asset, score_arne1);
81         check_sig_avifile(asset, score_avifile);
83         if(score_lavtools > final) 
84         {
85                 final = score_lavtools;
86                 result = FILE_AVI_LAVTOOLS;
87         }
88         if(score_arne2 > final)
89         {
90                 final = score_arne2;
91                 result = FILE_AVI_ARNE2;
92         }
93         if(score_arne1 > final)
94         {
95                 final = score_arne1;
96                 result = FILE_AVI_ARNE1;
97         }
98         if(score_avifile > final)
99         {
100                 final = score_avifile;
101                 result = FILE_AVI_AVIFILE;
102         }
110         return result;
113 int FileAVI::check_sig_arne2(Asset *asset, int &score)
115         return 0;
118 int FileAVI::check_sig_arne1(Asset *asset, int &score)
120         return 0;
123 int FileAVI::check_sig_lavtools(Asset *asset, int &score)
125         return 0;
128 int FileAVI::check_sig_avifile(Asset *asset, int &score)
130 return 0;
131 #ifdef USE_AVIFILE
132         IAviReadFile *in_fd = 0;
134         try
135         {
136                 in_fd = CreateIAviReadFile(asset->path);
137         }
138         catch(FatalError& error)
139         {
140                 if(in_fd) delete in_fd;
141                 return 0;
142         }
144         int vtracks = in_fd->VideoStreamCount();
145         int atracks = in_fd->AudioStreamCount();
147         delete in_fd;
148         
149         score = vtracks + atracks;
150         return 1;
151 #endif
152         return 0;
156 char* FileAVI::vcodec_to_fourcc(char *input, char *output)
158 #ifdef USE_AVIFILE
159         initialize_avifile();
160         for(avm::vector<CodecInfo>::iterator i = video_codecs.begin();
161                 i < video_codecs.end();
162                 i++)
163         {
164                 if(i->direction & CodecInfo::Encode)
165                 {
166                         if(!strcasecmp(i->GetName(), input))
167                         {
168                                 memcpy(output, (char*)&i->fourcc, 4);
169                                 output[4] = 0;
170                                 return output;
171                         }
172                 }
173         }
174         
175         output[0] = 0;
176         return output;
177 #else
178         return input;
179 #endif
182 char* FileAVI::fourcc_to_vcodec(char *input, char *output)
184 #ifdef USE_AVIFILE
185 // Construct codec item list
186         initialize_avifile();
187         for(avm::vector<CodecInfo>::iterator i = video_codecs.begin();
188                 i < video_codecs.end();
189                 i++)
190         {
191                 if(i->direction & CodecInfo::Encode)
192                 {
193                         if(!memcmp((char*)&i->fourcc, input, 4))
194                         {
195                                 memcpy(output, (char*)&i->fourcc, 4);
196                                 strcpy(output, i->GetName());;
197                                 return output;
198                         }
199                 }
200         }
201         
202         output[0] = 0;
203         return output;
204 #else
205         return input;
206 #endif
210 char* FileAVI::acodec_to_fourcc(char *input, char *output)
212 #ifdef USE_AVIFILE
213 // Construct codec item list
214         initialize_avifile();
215         for(avm::vector<CodecInfo>::iterator i = audio_codecs.begin();
216                 i < audio_codecs.end();
217                 i++)
218         {
219                 if(i->direction & CodecInfo::Encode)
220                 {
221                         if(!strcasecmp(i->GetName(), input))
222                         {
223                                 memcpy(output, (char*)&i->fourcc, 4);
224                                 output[4] = 0;
225                                 return output;
226                         }
227                 }
228         }
230         output[0] = 0;
231         return output;
232 #else
233         return input;
234 #endif
237 char* FileAVI::fourcc_to_acodec(char *input, char *output)
239 #ifdef USE_AVIFILE
240 // Construct codec item list
241         initialize_avifile();
242         for(avm::vector<CodecInfo>::iterator i = audio_codecs.begin();
243                 i < audio_codecs.end();
244                 i++)
245         {
246                 if(i->direction & CodecInfo::Encode)
247                 {
248                         if(!memcmp((char*)&i->fourcc, input, 4))
249                         {
250                                 memcpy(output, (char*)&i->fourcc, 4);
251                                 strcpy(output, i->GetName());
252                                 return output;
253                         }
254                 }
255         }
256         
257         output[0] = 0;
258         return output;
259 #else
260         return input;
261 #endif
265 void FileAVI::initialize_avifile()
267 #ifdef USE_AVIFILE
268         if(!avifile_initialized)
269         {
270         BITMAPINFOHEADER bih;
271         bih.biCompression = 0xffffffff;
272         Creators::CreateVideoDecoder(bih, 0, 0);
274         WAVEFORMATEX wih;
275         memset(&wih, 0xff, sizeof(WAVEFORMATEX));
276                 Creators::CreateAudioDecoder(&wih, 0);
277                 avifile_initialized = 1;
278         }
279 #endif
283 int FileAVI::open_file(int rd, int wr)
285         if(wr)
286         {
287                 switch(asset->format)
288                 {
289                         case FILE_AVI_LAVTOOLS:
290                                 return open_lavtools_out(asset);
291                                 break;
293                         case FILE_AVI_ARNE2:
294                                 return open_arne2_out(asset);
295                                 break;
297                         case FILE_AVI_ARNE1:
298                                 return open_arne1_out(asset);
299                                 break;
301                         case FILE_AVI_AVIFILE:
302                                 return open_avifile_out(asset);
303                                 break;
304                 }
305         }
306         else
307         if(rd)
308         {
309                 asset->format = check_sig(asset);
312                 switch(asset->format)
313                 {
314                         case FILE_AVI_LAVTOOLS:
315                                 return open_lavtools_in(asset);
316                                 break;
318                         case FILE_AVI_ARNE2:
319                                 return open_arne2_in(asset);
320                                 break;
322                         case FILE_AVI_ARNE1:
323                                 return open_arne1_in(asset);
324                                 break;
326                         case FILE_AVI_AVIFILE:
327                                 return open_avifile_in(asset);
328                                 break;
329                 }
330         }
332         return 0;
337 int FileAVI::open_avifile_out(Asset *asset)
339 #ifdef USE_AVIFILE
340         try
341         {
342                 out_fd = CreateIAviWriteFile(asset->path);
343         }
344         catch(FatalError& error)
345         {
346                 error.Print();
347                 close_file();
348                 return 1;
349         }
351         if(asset->video_data)
352         {
353                 out_color_model = get_best_colormodel(-1, -1);
354                 out_bitmap_info = new BitmapInfo(asset->width, asset->height, 
355                         cmodel_bc_to_avi(out_color_model));
356                 for(int i = 0; i < asset->layers && i < MAX_STREAMS; i++)
357                 {
358                         vstream_out[i] = out_fd->AddVideoStream(*(uint32_t*)asset->vcodec, 
359                                 out_bitmap_info, 
360                                 int(1000000.0 / asset->frame_rate));
361                 }
362         }
364         if(asset->audio_data)
365         {
366                 WAVEFORMATEX wfm;
367                 wfm.wFormatTag = 1; // PCM
368                 wfm.nChannels = asset->channels;
369                 wfm.nSamplesPerSec = asset->sample_rate;
370                 wfm.nAvgBytesPerSec = 2 * asset->sample_rate * asset->channels;
371                 wfm.nBlockAlign = 2 * asset->channels;
372                 wfm.wBitsPerSample = 16;
373                 wfm.cbSize = 0;
375                 for(int i = 0; i < asset->channels && i < MAX_STREAMS; i++)
376                 {
377                         astream_out[i] = out_fd->AddStream(AviStream::Audio,
378                                 &wfm, 
379                                 sizeof(wfm),
380                                 1,                   // uncompressed PCM data
381                                 wfm.nAvgBytesPerSec, // bytes/sec
382                                 wfm.nBlockAlign);    // bytes/sample
383                 }
384         }
386         return 0;
387 #endif
388         return 1;
391 int FileAVI::open_arne2_out(Asset *asset)
393         
394         return 0;
397 int FileAVI::open_arne1_out(Asset *asset)
399         return 0;
402 int FileAVI::open_lavtools_out(Asset *asset)
404         return 0;
407         
408         
409         
412 int FileAVI::open_avifile_in(Asset *asset)
414 #ifdef USE_AVIFILE
415         try
416         {
417                 in_fd = CreateIAviReadFile(asset->path);
418         }
419         catch(FatalError& error)
420         {
421                 error.Print();
422                 close_file();
423                 return 1;
424         }
426         asset->layers = in_fd->VideoStreamCount();
427         if(asset->layers)
428         {
429                 for(int i = 0; i < asset->layers && i < MAX_STREAMS; i++)
430                 {
431                         vstream_in[i] = in_fd->GetStream(i, IAviReadStream::Video);
432                         vstream_in[i]->StartStreaming();
433                         vstream_in[i]->GetDecoder()->SetDestFmt(24);
434                         vstream_in[i]->Seek(0);
435 //printf("FileAVI::open_file %d %p\n", i, vstream[i]);
436                 }
438                 StreamInfo *stream_info = vstream_in[0]->GetStreamInfo();
439                 asset->video_data = 1;
440                 if(!asset->frame_rate)
441                         asset->frame_rate = (double)1 / vstream_in[0]->GetFrameTime();
442                 asset->video_length = stream_info->GetStreamFrames();
443             BITMAPINFOHEADER bh;
444                 vstream_in[0]->GetVideoFormatInfo(&bh, sizeof(bh));
445             asset->width = bh.biWidth;
446             asset->height = bh.biHeight;
447                 asset->interlace_mode = BC_ILACE_MODE_UNDETECTED; // FIXME
449                 uint32_t fourcc = stream_info->GetFormat();
450                 asset->vcodec[0] = ((char*)&fourcc)[0];
451                 asset->vcodec[1] = ((char*)&fourcc)[1];
452                 asset->vcodec[2] = ((char*)&fourcc)[2];
453                 asset->vcodec[3] = ((char*)&fourcc)[3];
454                 source_cmodel = BC_RGB888;
455                 delete stream_info;
456         }
458         asset->audio_data = in_fd->AudioStreamCount();
460         if(asset->audio_data)
461         {
462                 char *extinfo;
464                 for(int i = 0; i < 1 && i < MAX_STREAMS; i++)
465                 {
466                         astream_in[i] = in_fd->GetStream(i, IAviReadStream::Audio);
467                         astream_in[i]->StartStreaming();
468                 }
470                 StreamInfo *stream_info = astream_in[0]->GetStreamInfo();
471                 asset->channels = stream_info->GetAudioChannels();
472                 if(asset->sample_rate == 0)
473                         asset->sample_rate = stream_info->GetAudioSamplesPerSec();
474                 asset->bits = MAX(16, stream_info->GetAudioBitsPerSample());
475                 asset->audio_length = stream_info->GetStreamFrames();
476                 delete stream_info;
477         }
478 asset->dump();
479         return 0;
480 #endif
481         return 1;
484 int FileAVI::open_arne2_in(Asset *asset)
486         return 0;
489 int FileAVI::open_arne1_in(Asset *asset)
491         return 0;
494 int FileAVI::open_lavtools_in(Asset *asset)
496         return 0;
516 int FileAVI::close_file()
518 #ifdef USE_AVIFILE
519         if(in_fd) delete in_fd;
520         if(out_fd) delete out_fd;
521         if(out_bitmap_info) delete out_bitmap_info;
522 #endif
523         if(temp_audio) delete [] temp_audio;
524         reset();
527 int FileAVI::cmodel_bc_to_avi(int input)
529 #ifdef USE_AVIFILE
530         switch(input)
531         {
532                 case BC_YUV422:
533                         return fccYUY2;
534                         break;
536                 case BC_YUV420P:
537                         return fccYV12;
538                         break;
539         }
540 #endif
541         return 24;
544 void FileAVI::reset()
546 #ifdef USE_AVIFILE
547         in_fd = 0;
548         out_fd = 0;
549         out_bitmap_info = 0;
550 #endif
551         temp_audio = 0;
552         temp_allocated = 0;
555 int FileAVI::get_best_colormodel(int driver, int colormodel)
557         if(colormodel > -1)
558         {
559                 return colormodel;
560         }
561         else
562         {
563                 
564                 return BC_RGB888;
565         }
569 void FileAVI::get_parameters(BC_WindowBase *parent_window, 
570                 Asset *asset, 
571                 BC_WindowBase* &format_window,
572                 int audio_options,
573                 int video_options,
574                 char *locked_compressor)
576         if(audio_options)
577         {
578                 AVIConfigAudio *window = new AVIConfigAudio(parent_window, asset);
579                 format_window = window;
580                 window->create_objects();
581                 window->run_window();
582                 delete window;
583         }
584         else
585         if(video_options)
586         {
587 //printf("FileAVI::get_parameters 1\n");
588                 AVIConfigVideo *window = new AVIConfigVideo(parent_window,
589                         asset,
590                         locked_compressor);
591                 format_window = window;
592                 window->create_objects();
593                 window->run_window();
594                 delete window;
595         }
598 int FileAVI::set_audio_position(int64_t x)
600 #ifdef USE_AVIFILE
601 // quicktime sets positions for each track seperately so store position in audio_position
602         if(x >= 0 && x < asset->audio_length)
603                 return astream_in[file->current_layer]->Seek(x);
604         else
605                 return 1;
606 #endif
609 int FileAVI::set_video_position(int64_t x)
611 #ifdef USE_AVIFILE
612         if(x >= 0 && x < asset->video_length)
613                 return vstream_in[file->current_layer]->Seek(x);
614         else
615                 return 1;
616 #endif
619 int FileAVI::read_samples(double *buffer, int64_t len)
621 #ifdef USE_AVIFILE
622         Unsigned samples_read, bytes_read;
624 printf("FileAVI::read_samples 1\n");
625         if(temp_audio && temp_allocated < len * asset->bits / 8 * asset->channels)
626         {
627                 delete [] temp_audio;
628                 temp_allocated = 0;
629         }
630         if(!temp_allocated)
631         {
632                 temp_allocated = len * asset->bits / 8 * asset->channels;
633                 temp_audio = new unsigned char[temp_allocated];
634         }
636         astream_in[0]->ReadFrames((void*)temp_audio, 
637                 (unsigned int)temp_allocated,
638                 (unsigned int)len,
639                 samples_read, 
640                 bytes_read);
641         
642 // Extract single channel
643         switch(asset->bits)
644         {
645                 case 16:
646                 {
647                         int16_t *temp_int16 = (int16_t*)temp_audio;
648                         for(int i = 0, j = file->current_channel; 
649                                 i < len;
650                                 i++, j += asset->channels)
651                         {
652                                 buffer[i] = (double)temp_int16[j] / 32767;
653                         }
654                         break;
655                 }
656         }
658 #endif
661         return 0;
664 int FileAVI::read_frame(VFrame *frame)
666         int result = 0;
668 #ifdef USE_AVIFILE
669         vstream_in[file->current_layer]->ReadFrame();
670         CImage *temp_image = vstream_in[file->current_layer]->GetFrame();
671 //printf("FileAVI::read_frame 1 %d %d\n", source_cmodel, frame->get_color_model());
672         switch(source_cmodel)
673         {
674                 case BC_RGB888:
675                         if(frame->get_color_model() == BC_RGB888)
676                                 bcopy(temp_image->Data(), 
677                                         frame->get_data(), 
678                                         VFrame::calculate_data_size(asset->width, 
679                                                 asset->height, 
680                                                 -1, 
681                                                 BC_RGB888));
682                         break;
683         }
684 #endif
685         return result;
688 int64_t FileAVI::compressed_frame_size()
690         int result = 0;
691         return result;
694 int FileAVI::read_compressed_frame(VFrame *buffer)
696         int64_t result = 0;
698         return result;
701 int FileAVI::write_compressed_frame(VFrame *buffer)
703         int result = 0;
705         return result;
708 int FileAVI::write_frames(VFrame ***frames, int len)
710         return 0;
714 int FileAVI::write_samples(double **buffer, int64_t len)
716         return 0;
723 AVIConfigAudio::AVIConfigAudio(BC_WindowBase *parent_window, Asset *asset)
724  : BC_Window(PROGRAM_NAME ": Audio compression",
725         parent_window->get_abs_cursor_x(1),
726         parent_window->get_abs_cursor_y(1),
727         calculate_w(asset->format),
728         calculate_h(asset->format))
730         this->parent_window = parent_window;
731         this->asset = asset;
734 AVIConfigAudio::~AVIConfigAudio()
738 int AVIConfigAudio::calculate_w(int format)
740         switch(format)
741         {
742                 case FILE_AVI_AVIFILE: return 400; break;
743                 case FILE_AVI_ARNE2: return 250; break;
744         }
747 int AVIConfigAudio::calculate_h(int format)
749         switch(format)
750         {
751                 case FILE_AVI_AVIFILE: return 200; break;
752                 case FILE_AVI_ARNE2: return 100; break;
753         }
756 int AVIConfigAudio::create_objects()
758         switch(asset->format)
759         {
760 #ifdef USE_AVIFILE
761                 case FILE_AVI_AVIFILE:
762                 {
763                         generate_codeclist();
765                         int x = 10, y = 10;
766                         BC_Title *title;
767                         add_subwindow(title = new BC_Title(x, y, _("Codec: ")));
768                         list = new AVIACodecList(this, x, y);
769                         list->create_objects();
770                         y += list->get_h();
771                         break;
772                 }
773 #endif
775                 case FILE_AVI_ARNE2:
776                         add_subwindow(new BC_Title(10, 10, _("Compressor: 16 bit PCM")));
777                         break;
778         }
780         add_subwindow(new BC_OKButton(this));
781         return 0;
784 int AVIConfigAudio::close_event()
786         return 1;
789 int AVIConfigAudio::generate_codeclist()
791         FileAVI::initialize_avifile();
792         codec_items.remove_all_objects();
794         switch(asset->format)
795         {
796 #ifdef USE_AVIFILE
797                 case FILE_AVI_AVIFILE:
798                         for(avm::vector<CodecInfo>::iterator i = audio_codecs.begin();
799                                 i < audio_codecs.end();
800                                 i++)
801                         {
802                                 if(i->direction & CodecInfo::Encode)
803                                 {
804                                         codec_items.append(new BC_ListBoxItem((char*)i->GetName()));
805                                 }
806                         }
807                         break;
808 #endif
809         }
811         return 0;
814 void AVIConfigAudio::update_codecs()
816         
827 AVIACodecList::AVIACodecList(AVIConfigAudio *gui, int x, int y)
828  : BC_PopupTextBox(gui,
829                 &gui->codec_items,
830                 FileAVI::fourcc_to_acodec(gui->asset->acodec, gui->string),
831                 x, 
832                 y,
833                 200,
834                 400)
836         this->gui = gui;
839 AVIACodecList::~AVIACodecList()
843 int AVIACodecList::handle_event()
845         strcpy(gui->asset->acodec, FileAVI::acodec_to_fourcc(get_text(), gui->string));
846         return 1;
853 AVIConfigVideo::AVIConfigVideo(BC_WindowBase *parent_window, 
854                 Asset *asset, 
855                 char *locked_compressor)
856  : BC_Window(PROGRAM_NAME ": Video Compression",
857         parent_window->get_abs_cursor_x(1),
858         parent_window->get_abs_cursor_y(1),
859         calculate_w(asset->format),
860         calculate_h(asset->format))
862         this->parent_window = parent_window;
863         this->asset = asset;
864         this->locked_compressor = locked_compressor;
865         reset();
868 AVIConfigVideo::~AVIConfigVideo()
870         codec_items.remove_all_objects();
871         attribute_items[0].remove_all_objects();
872         attribute_items[1].remove_all_objects();
875 void AVIConfigVideo::reset()
877         attributes = 0;
878         attribute = 0;
881 int AVIConfigVideo::calculate_w(int format)
883         switch(format)
884         {
885                 case FILE_AVI_AVIFILE: return 400; break;
886                 case FILE_AVI_ARNE2: return 250; break;
887         }
890 int AVIConfigVideo::calculate_h(int format)
892         switch(format)
893         {
894                 case FILE_AVI_AVIFILE: return 320; break;
895                 case FILE_AVI_ARNE2: return 100; break;
896         }
899 int AVIConfigVideo::create_objects()
901         switch(asset->format)
902         {
903 #ifdef USE_AVIFILE
904                 case FILE_AVI_AVIFILE:
905                 {
906                         generate_codeclist();
907                         generate_attributelist();
909                         int x = 10, y = 10, x1 = 90;
910                         BC_Title *title;
911                         add_subwindow(title = new BC_Title(x, y, _("Codec: ")));
912                         list = new AVIVCodecList(this, x1, y);
913                         list->create_objects();
914                         y += list->get_h() + 5;
916                         add_subwindow(title = new BC_Title(x, y, _("Attributes:")));
917                         add_subwindow(attributes = new AVIVAttributeList(this, x1, y));
918                         y += attributes->get_h() + 5;
920                         add_subwindow(new BC_Title(x, y, _("Value:")));
921                         add_subwindow(attribute = new AVIVAttribute(this, x1, y));
922                         break;
923                 }
924 #endif
926                 case FILE_AVI_ARNE2:
927                         add_subwindow(new BC_Title(10, 10, _("Compressor: Consumer DV")));
928                         break;
929         }
931         add_subwindow(new BC_OKButton(this));
932         return 0;
935 int AVIConfigVideo::close_event()
937         return 1;
940 int AVIConfigVideo::generate_codeclist()
942         FileAVI::initialize_avifile();
943         switch(asset->format)
944         {
945                 case FILE_AVI_AVIFILE:
946 #ifdef USE_AVIFILE
947 // Construct codec item list
948                         for(avm::vector<CodecInfo>::iterator i = video_codecs.begin();
949                                 i < video_codecs.end();
950                                 i++)
951                         {
952                                 if(i->direction & CodecInfo::Encode)
953                                 {
954                                         codec_items.append(new BC_ListBoxItem((char*)i->GetName()));
955                                 }
956                         }
957 #endif
958                         break;
959         }
961         return 0;
964 void AVIConfigVideo::generate_attributelist()
966 #ifdef USE_AVIFILE
967 // Remember selection number
968         int selection_number = attributes ? attributes->get_selection_number(0, 0) : -1;
969         attribute_items[0].remove_all_objects();
970         attribute_items[1].remove_all_objects();
971         FileAVI::initialize_avifile();
973         for(avm::vector<CodecInfo>::iterator i = video_codecs.begin();
974                 i < video_codecs.end();
975                 i++)
976         {
977                 if(!memcmp((char*)&i->fourcc, asset->vcodec, 4))
978                 {
979                         avm::vector<AttributeInfo>& attributes = i->encoder_info;
981                         for(avm::vector<AttributeInfo>::const_iterator j = attributes.begin();
982                                 j != attributes.end();
983                                 j++)
984                         {
985                                 char *name = (char*)j->GetName();
986                                 char value[BCTEXTLEN];
987                                 value[0] = 0;
989 //printf("AVIConfigVideo::generate_attributelist %d\n", j->kind);
990                                 switch(j->kind)
991                                 {
992                                         case AttributeInfo::Integer:
993                                         {
994                                                 int temp = 0;
995                                                 Creators::GetCodecAttr(*i, name, temp);
996                                                 sprintf(value, "%d", temp);
997                                                 break;
998                                         }
1000                                         case AttributeInfo::Select:
1001                                         {
1002                                                 int temp = 0;
1003                                                 Creators::GetCodecAttr(*i, name, temp);
1004                                                 sprintf(value, "%d ( %s )", temp, j->options[temp].c_str());
1005                                                 break;
1006                                         }
1008                                         case AttributeInfo::String:
1009                                         {
1010                                                 const char * temp = 0;
1011                                                 Creators::GetCodecAttr(*i, name, &temp);
1012                                                 if(temp) strncpy(value, temp, BCTEXTLEN);
1013                                                 break;
1014                                         }
1015                                 }
1017                                 attribute_items[0].append(new BC_ListBoxItem(name));
1018                                 attribute_items[1].append(new BC_ListBoxItem(value));
1020                                 int current_number = j - attributes.begin();
1021                                 if(current_number == selection_number)
1022                                 {
1023                                         attribute_items[0].values[current_number]->set_selected(1);
1024                                         attribute_items[1].values[current_number]->set_selected(1);
1025                                 }
1026                         }
1027                 }
1028         }
1029 #endif
1032 char* AVIConfigVideo::get_current_attribute_text()
1034         BC_ListBoxItem *item = attributes->get_selection(0, 0);
1036         if(item)
1037         {
1038                 return item->get_text();
1039         }
1040         else
1041                 return "";
1044 char* AVIConfigVideo::get_current_attribute_value()
1046         BC_ListBoxItem *item = attributes->get_selection(1, 0);
1048         if(item)
1049         {
1050                 return item->get_text();
1051         }
1052         else
1053                 return "";
1056 void AVIConfigVideo::set_current_attribute(char *text)
1058 #ifdef USE_AVIFILE
1059         int number = attributes->get_selection_number(0, 0);
1061         if(number >= 0)
1062         {
1063                 FileAVI::initialize_avifile();
1065                 for(avm::vector<CodecInfo>::iterator i = video_codecs.begin();
1066                         i < video_codecs.end();
1067                         i++)
1068                 {
1069                         if(!memcmp((char*)&i->fourcc, asset->vcodec, 4))
1070                         {
1071                                 avm::vector<AttributeInfo>& attributes = i->encoder_info;
1072                                 AttributeInfo& attribute = attributes[number];
1074                                 switch(attribute.kind)
1075                                 {
1076                                         case AttributeInfo::Integer:
1077                                                 Creators::SetCodecAttr(*i, attribute.GetName(), atol(text));
1078                                                 break;
1080                                         case AttributeInfo::Select:
1081                                                 Creators::SetCodecAttr(*i, attribute.GetName(), atol(text));
1082                                                 break;
1084                                         case AttributeInfo::String:
1085                                                 Creators::SetCodecAttr(*i, attribute.GetName(), text);
1086                                                 break;
1087                                 }
1088                         }
1089                 }
1090                 
1091                 
1092                 update_attribute(1);
1093         }
1094 #endif
1099 void AVIConfigVideo::update_attribute(int recursive)
1101         generate_attributelist();
1102         attributes->update(attribute_items,
1103                                                 0,
1104                                                 0,
1105                                                 2,
1106                                                 attributes->get_xposition(),
1107                                                 attributes->get_yposition(), 
1108                                                 0,
1109                                                 1);
1111         if(!recursive) attribute->update(get_current_attribute_value());
1122 AVIVCodecList::AVIVCodecList(AVIConfigVideo *gui, int x, int y)
1123  : BC_PopupTextBox(gui,
1124                 &gui->codec_items,
1125                 FileAVI::fourcc_to_vcodec(gui->asset->vcodec, gui->string),
1126                 x, 
1127                 y,
1128                 280,
1129                 400)
1131         this->gui = gui;
1134 AVIVCodecList::~AVIVCodecList()
1138 int AVIVCodecList::handle_event()
1140         strcpy(gui->asset->vcodec, FileAVI::vcodec_to_fourcc(get_text(), gui->string));
1141         gui->update_attribute(0);
1142         return 1;
1147 AVIVAttributeList::AVIVAttributeList(AVIConfigVideo *gui, int x, int y)
1148  : BC_ListBox(x, 
1149                 y,
1150                 300,
1151                 200,
1152                 LISTBOX_TEXT,
1153                 gui->attribute_items,
1154                 0,
1155                 0,
1156                 2)
1158         this->gui = gui;
1161 int AVIVAttributeList::handle_event()
1163         gui->update_attribute(0);
1164         return 1;
1167 int AVIVAttributeList::selection_changed()
1169         gui->update_attribute(0);
1170         return 1;
1176 AVIVAttribute::AVIVAttribute(AVIConfigVideo *gui, int x, int y)
1177  : BC_TextBox(x, y, 300, 1, gui->get_current_attribute_value())
1179         this->gui = gui;
1182 int AVIVAttribute::handle_event()
1184         gui->set_current_attribute(get_text());
1185         return 1;