Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

fileavi.C

Go to the documentation of this file.
00001 #include "asset.h"
00002 
00003 #ifdef USE_AVIFILE
00004 #include "avifile.h"
00005 #include "creators.h"
00006 #include "except.h"
00007 #include "avm_fourcc.h"
00008 #include "StreamInfo.h"
00009 #endif
00010 
00011 #include "clip.h"
00012 #include "file.h"
00013 #include "fileavi.h"
00014 #include "fileavi.inc"
00015 #include "interlacemodes.h"
00016 #include "mwindow.inc"
00017 #include "vframe.h"
00018 
00019 
00020 #include <string.h>
00021 
00022 #include <libintl.h>
00023 #define _(String) gettext(String)
00024 #define gettext_noop(String) String
00025 #define N_(String) gettext_noop (String)
00026 
00027 
00028 
00029 
00030 
00031 #ifdef USE_AVIFILE
00032 int FileAVI::avifile_initialized = 0;
00033 #endif
00034 
00035 
00036 
00037 
00038 // Status of AVI derivatives:
00039 // Arne2 - depends on Kino, DV only
00040 // Lavtools - 2 gig limited
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 FileAVI::FileAVI(Asset *asset, File *file)
00054  : FileBase(asset, file)
00055 {
00056         reset();
00057 }
00058 
00059 FileAVI::~FileAVI()
00060 {
00061         close_file();
00062 }
00063 
00064 int FileAVI::check_sig(Asset *asset)
00065 {
00066 // Pick whoever gets the most tracks
00067         int score_lavtools = 0;
00068         int score_arne2 = 0;
00069         int score_arne1 = 0;
00070         int score_avifile = 0;
00071         int final = 0;
00072         int result = 0;
00073 
00074 
00075 
00076 
00077 
00078         check_sig_lavtools(asset, score_lavtools);
00079         check_sig_arne2(asset, score_arne2);
00080         check_sig_arne1(asset, score_arne1);
00081         check_sig_avifile(asset, score_avifile);
00082 
00083         if(score_lavtools > final) 
00084         {
00085                 final = score_lavtools;
00086                 result = FILE_AVI_LAVTOOLS;
00087         }
00088         if(score_arne2 > final)
00089         {
00090                 final = score_arne2;
00091                 result = FILE_AVI_ARNE2;
00092         }
00093         if(score_arne1 > final)
00094         {
00095                 final = score_arne1;
00096                 result = FILE_AVI_ARNE1;
00097         }
00098         if(score_avifile > final)
00099         {
00100                 final = score_avifile;
00101                 result = FILE_AVI_AVIFILE;
00102         }
00103 
00104 
00105 
00106 
00107 
00108 
00109 
00110         return result;
00111 }
00112 
00113 int FileAVI::check_sig_arne2(Asset *asset, int &score)
00114 {
00115         return 0;
00116 }
00117 
00118 int FileAVI::check_sig_arne1(Asset *asset, int &score)
00119 {
00120         return 0;
00121 }
00122 
00123 int FileAVI::check_sig_lavtools(Asset *asset, int &score)
00124 {
00125         return 0;
00126 }
00127 
00128 int FileAVI::check_sig_avifile(Asset *asset, int &score)
00129 {
00130 return 0;
00131 #ifdef USE_AVIFILE
00132         IAviReadFile *in_fd = 0;
00133 
00134         try
00135         {
00136                 in_fd = CreateIAviReadFile(asset->path);
00137         }
00138         catch(FatalError& error)
00139         {
00140                 if(in_fd) delete in_fd;
00141                 return 0;
00142         }
00143 
00144         int vtracks = in_fd->VideoStreamCount();
00145         int atracks = in_fd->AudioStreamCount();
00146 
00147         delete in_fd;
00148         
00149         score = vtracks + atracks;
00150         return 1;
00151 #endif
00152         return 0;
00153 }
00154 
00155 
00156 char* FileAVI::vcodec_to_fourcc(char *input, char *output)
00157 {
00158 #ifdef USE_AVIFILE
00159         initialize_avifile();
00160         for(avm::vector<CodecInfo>::iterator i = video_codecs.begin();
00161                 i < video_codecs.end();
00162                 i++)
00163         {
00164                 if(i->direction & CodecInfo::Encode)
00165                 {
00166                         if(!strcasecmp(i->GetName(), input))
00167                         {
00168                                 memcpy(output, (char*)&i->fourcc, 4);
00169                                 output[4] = 0;
00170                                 return output;
00171                         }
00172                 }
00173         }
00174         
00175         output[0] = 0;
00176         return output;
00177 #else
00178         return input;
00179 #endif
00180 }
00181 
00182 char* FileAVI::fourcc_to_vcodec(char *input, char *output)
00183 {
00184 #ifdef USE_AVIFILE
00185 // Construct codec item list
00186         initialize_avifile();
00187         for(avm::vector<CodecInfo>::iterator i = video_codecs.begin();
00188                 i < video_codecs.end();
00189                 i++)
00190         {
00191                 if(i->direction & CodecInfo::Encode)
00192                 {
00193                         if(!memcmp((char*)&i->fourcc, input, 4))
00194                         {
00195                                 memcpy(output, (char*)&i->fourcc, 4);
00196                                 strcpy(output, i->GetName());;
00197                                 return output;
00198                         }
00199                 }
00200         }
00201         
00202         output[0] = 0;
00203         return output;
00204 #else
00205         return input;
00206 #endif
00207 }
00208 
00209 
00210 char* FileAVI::acodec_to_fourcc(char *input, char *output)
00211 {
00212 #ifdef USE_AVIFILE
00213 // Construct codec item list
00214         initialize_avifile();
00215         for(avm::vector<CodecInfo>::iterator i = audio_codecs.begin();
00216                 i < audio_codecs.end();
00217                 i++)
00218         {
00219                 if(i->direction & CodecInfo::Encode)
00220                 {
00221                         if(!strcasecmp(i->GetName(), input))
00222                         {
00223                                 memcpy(output, (char*)&i->fourcc, 4);
00224                                 output[4] = 0;
00225                                 return output;
00226                         }
00227                 }
00228         }
00229 
00230         output[0] = 0;
00231         return output;
00232 #else
00233         return input;
00234 #endif
00235 }
00236 
00237 char* FileAVI::fourcc_to_acodec(char *input, char *output)
00238 {
00239 #ifdef USE_AVIFILE
00240 // Construct codec item list
00241         initialize_avifile();
00242         for(avm::vector<CodecInfo>::iterator i = audio_codecs.begin();
00243                 i < audio_codecs.end();
00244                 i++)
00245         {
00246                 if(i->direction & CodecInfo::Encode)
00247                 {
00248                         if(!memcmp((char*)&i->fourcc, input, 4))
00249                         {
00250                                 memcpy(output, (char*)&i->fourcc, 4);
00251                                 strcpy(output, i->GetName());
00252                                 return output;
00253                         }
00254                 }
00255         }
00256         
00257         output[0] = 0;
00258         return output;
00259 #else
00260         return input;
00261 #endif
00262 }
00263 
00264 
00265 void FileAVI::initialize_avifile()
00266 {
00267 #ifdef USE_AVIFILE
00268         if(!avifile_initialized)
00269         {
00270         BITMAPINFOHEADER bih;
00271         bih.biCompression = 0xffffffff;
00272         Creators::CreateVideoDecoder(bih, 0, 0);
00273 
00274         WAVEFORMATEX wih;
00275         memset(&wih, 0xff, sizeof(WAVEFORMATEX));
00276                 Creators::CreateAudioDecoder(&wih, 0);
00277                 avifile_initialized = 1;
00278         }
00279 #endif
00280 }
00281 
00282 
00283 int FileAVI::open_file(int rd, int wr)
00284 {
00285         if(wr)
00286         {
00287                 switch(asset->format)
00288                 {
00289                         case FILE_AVI_LAVTOOLS:
00290                                 return open_lavtools_out(asset);
00291                                 break;
00292 
00293                         case FILE_AVI_ARNE2:
00294                                 return open_arne2_out(asset);
00295                                 break;
00296 
00297                         case FILE_AVI_ARNE1:
00298                                 return open_arne1_out(asset);
00299                                 break;
00300 
00301                         case FILE_AVI_AVIFILE:
00302                                 return open_avifile_out(asset);
00303                                 break;
00304                 }
00305         }
00306         else
00307         if(rd)
00308         {
00309                 asset->format = check_sig(asset);
00310 
00311 
00312                 switch(asset->format)
00313                 {
00314                         case FILE_AVI_LAVTOOLS:
00315                                 return open_lavtools_in(asset);
00316                                 break;
00317 
00318                         case FILE_AVI_ARNE2:
00319                                 return open_arne2_in(asset);
00320                                 break;
00321 
00322                         case FILE_AVI_ARNE1:
00323                                 return open_arne1_in(asset);
00324                                 break;
00325 
00326                         case FILE_AVI_AVIFILE:
00327                                 return open_avifile_in(asset);
00328                                 break;
00329                 }
00330         }
00331 
00332         return 0;
00333 }
00334 
00335 
00336 
00337 int FileAVI::open_avifile_out(Asset *asset)
00338 {
00339 #ifdef USE_AVIFILE
00340         try
00341         {
00342                 out_fd = CreateIAviWriteFile(asset->path);
00343         }
00344         catch(FatalError& error)
00345         {
00346                 error.Print();
00347                 close_file();
00348                 return 1;
00349         }
00350 
00351         if(asset->video_data)
00352         {
00353                 out_color_model = get_best_colormodel(-1, -1);
00354                 out_bitmap_info = new BitmapInfo(asset->width, asset->height, 
00355                         cmodel_bc_to_avi(out_color_model));
00356                 for(int i = 0; i < asset->layers && i < MAX_STREAMS; i++)
00357                 {
00358                         vstream_out[i] = out_fd->AddVideoStream(*(uint32_t*)asset->vcodec, 
00359                                 out_bitmap_info, 
00360                                 int(1000000.0 / asset->frame_rate));
00361                 }
00362         }
00363 
00364         if(asset->audio_data)
00365         {
00366                 WAVEFORMATEX wfm;
00367                 wfm.wFormatTag = 1; // PCM
00368                 wfm.nChannels = asset->channels;
00369                 wfm.nSamplesPerSec = asset->sample_rate;
00370                 wfm.nAvgBytesPerSec = 2 * asset->sample_rate * asset->channels;
00371                 wfm.nBlockAlign = 2 * asset->channels;
00372                 wfm.wBitsPerSample = 16;
00373                 wfm.cbSize = 0;
00374 
00375                 for(int i = 0; i < asset->channels && i < MAX_STREAMS; i++)
00376                 {
00377                         astream_out[i] = out_fd->AddStream(AviStream::Audio,
00378                                 &wfm, 
00379                                 sizeof(wfm),
00380                                 1,                   // uncompressed PCM data
00381                                 wfm.nAvgBytesPerSec, // bytes/sec
00382                                 wfm.nBlockAlign);    // bytes/sample
00383                 }
00384         }
00385 
00386         return 0;
00387 #endif
00388         return 1;
00389 }
00390 
00391 int FileAVI::open_arne2_out(Asset *asset)
00392 {
00393         
00394         return 0;
00395 }
00396 
00397 int FileAVI::open_arne1_out(Asset *asset)
00398 {
00399         return 0;
00400 }
00401 
00402 int FileAVI::open_lavtools_out(Asset *asset)
00403 {
00404         return 0;
00405 }
00406 
00407         
00408         
00409         
00410 
00411 
00412 int FileAVI::open_avifile_in(Asset *asset)
00413 {
00414 #ifdef USE_AVIFILE
00415         try
00416         {
00417                 in_fd = CreateIAviReadFile(asset->path);
00418         }
00419         catch(FatalError& error)
00420         {
00421                 error.Print();
00422                 close_file();
00423                 return 1;
00424         }
00425 
00426         asset->layers = in_fd->VideoStreamCount();
00427         if(asset->layers)
00428         {
00429                 for(int i = 0; i < asset->layers && i < MAX_STREAMS; i++)
00430                 {
00431                         vstream_in[i] = in_fd->GetStream(i, IAviReadStream::Video);
00432                         vstream_in[i]->StartStreaming();
00433                         vstream_in[i]->GetDecoder()->SetDestFmt(24);
00434                         vstream_in[i]->Seek(0);
00435 //printf("FileAVI::open_file %d %p\n", i, vstream[i]);
00436                 }
00437 
00438                 StreamInfo *stream_info = vstream_in[0]->GetStreamInfo();
00439                 asset->video_data = 1;
00440                 if(!asset->frame_rate)
00441                         asset->frame_rate = (double)1 / vstream_in[0]->GetFrameTime();
00442                 asset->video_length = stream_info->GetStreamFrames();
00443             BITMAPINFOHEADER bh;
00444                 vstream_in[0]->GetVideoFormatInfo(&bh, sizeof(bh));
00445             asset->width = bh.biWidth;
00446             asset->height = bh.biHeight;
00447                 asset->interlace_mode = BC_ILACE_MODE_UNDETECTED; // FIXME
00448 
00449                 uint32_t fourcc = stream_info->GetFormat();
00450                 asset->vcodec[0] = ((char*)&fourcc)[0];
00451                 asset->vcodec[1] = ((char*)&fourcc)[1];
00452                 asset->vcodec[2] = ((char*)&fourcc)[2];
00453                 asset->vcodec[3] = ((char*)&fourcc)[3];
00454                 source_cmodel = BC_RGB888;
00455                 delete stream_info;
00456         }
00457 
00458         asset->audio_data = in_fd->AudioStreamCount();
00459 
00460         if(asset->audio_data)
00461         {
00462                 char *extinfo;
00463 
00464                 for(int i = 0; i < 1 && i < MAX_STREAMS; i++)
00465                 {
00466                         astream_in[i] = in_fd->GetStream(i, IAviReadStream::Audio);
00467                         astream_in[i]->StartStreaming();
00468                 }
00469 
00470                 StreamInfo *stream_info = astream_in[0]->GetStreamInfo();
00471                 asset->channels = stream_info->GetAudioChannels();
00472                 if(asset->sample_rate == 0)
00473                         asset->sample_rate = stream_info->GetAudioSamplesPerSec();
00474                 asset->bits = MAX(16, stream_info->GetAudioBitsPerSample());
00475                 asset->audio_length = stream_info->GetStreamFrames();
00476                 delete stream_info;
00477         }
00478 asset->dump();
00479         return 0;
00480 #endif
00481         return 1;
00482 }
00483 
00484 int FileAVI::open_arne2_in(Asset *asset)
00485 {
00486         return 0;
00487 }
00488 
00489 int FileAVI::open_arne1_in(Asset *asset)
00490 {
00491         return 0;
00492 }
00493 
00494 int FileAVI::open_lavtools_in(Asset *asset)
00495 {
00496         return 0;
00497 }
00498 
00499 
00500 
00501 
00502 
00503 
00504 
00505 
00506 
00507 
00508 
00509 
00510 
00511 
00512 
00513 
00514 
00515 
00516 int FileAVI::close_file()
00517 {
00518 #ifdef USE_AVIFILE
00519         if(in_fd) delete in_fd;
00520         if(out_fd) delete out_fd;
00521         if(out_bitmap_info) delete out_bitmap_info;
00522 #endif
00523         if(temp_audio) delete [] temp_audio;
00524         reset();
00525 }
00526 
00527 int FileAVI::cmodel_bc_to_avi(int input)
00528 {
00529 #ifdef USE_AVIFILE
00530         switch(input)
00531         {
00532                 case BC_YUV422:
00533                         return fccYUY2;
00534                         break;
00535 
00536                 case BC_YUV420P:
00537                         return fccYV12;
00538                         break;
00539         }
00540 #endif
00541         return 24;
00542 }
00543 
00544 void FileAVI::reset()
00545 {
00546 #ifdef USE_AVIFILE
00547         in_fd = 0;
00548         out_fd = 0;
00549         out_bitmap_info = 0;
00550 #endif
00551         temp_audio = 0;
00552         temp_allocated = 0;
00553 }
00554 
00555 int FileAVI::get_best_colormodel(int driver, int colormodel)
00556 {
00557         if(colormodel > -1)
00558         {
00559                 return colormodel;
00560         }
00561         else
00562         {
00563                 
00564                 return BC_RGB888;
00565         }
00566 }
00567 
00568 
00569 void FileAVI::get_parameters(BC_WindowBase *parent_window, 
00570                 Asset *asset, 
00571                 BC_WindowBase* &format_window,
00572                 int audio_options,
00573                 int video_options,
00574                 int lock_compressor)
00575 {
00576         if(audio_options)
00577         {
00578                 AVIConfigAudio *window = new AVIConfigAudio(parent_window, asset);
00579                 format_window = window;
00580                 window->create_objects();
00581                 window->run_window();
00582                 delete window;
00583         }
00584         else
00585         if(video_options)
00586         {
00587 //printf("FileAVI::get_parameters 1\n");
00588                 AVIConfigVideo *window = new AVIConfigVideo(parent_window,
00589                         asset,
00590                         lock_compressor);
00591                 format_window = window;
00592                 window->create_objects();
00593                 window->run_window();
00594                 delete window;
00595         }
00596 }
00597 
00598 int FileAVI::set_audio_position(int64_t x)
00599 {
00600 #ifdef USE_AVIFILE
00601 // quicktime sets positions for each track seperately so store position in audio_position
00602         if(x >= 0 && x < asset->audio_length)
00603                 return astream_in[file->current_layer]->Seek(x);
00604         else
00605                 return 1;
00606 #endif
00607 }
00608 
00609 int FileAVI::set_video_position(int64_t x)
00610 {
00611 #ifdef USE_AVIFILE
00612         if(x >= 0 && x < asset->video_length)
00613                 return vstream_in[file->current_layer]->Seek(x);
00614         else
00615                 return 1;
00616 #endif
00617 }
00618 
00619 int FileAVI::read_samples(double *buffer, int64_t len)
00620 {
00621 #ifdef USE_AVIFILE
00622         Unsigned samples_read, bytes_read;
00623 
00624 printf("FileAVI::read_samples 1\n");
00625         if(temp_audio && temp_allocated < len * asset->bits / 8 * asset->channels)
00626         {
00627                 delete [] temp_audio;
00628                 temp_allocated = 0;
00629         }
00630         if(!temp_allocated)
00631         {
00632                 temp_allocated = len * asset->bits / 8 * asset->channels;
00633                 temp_audio = new unsigned char[temp_allocated];
00634         }
00635 
00636         astream_in[0]->ReadFrames((void*)temp_audio, 
00637                 (unsigned int)temp_allocated,
00638                 (unsigned int)len,
00639                 samples_read, 
00640                 bytes_read);
00641         
00642 // Extract single channel
00643         switch(asset->bits)
00644         {
00645                 case 16:
00646                 {
00647                         int16_t *temp_int16 = (int16_t*)temp_audio;
00648                         for(int i = 0, j = file->current_channel; 
00649                                 i < len;
00650                                 i++, j += asset->channels)
00651                         {
00652                                 buffer[i] = (double)temp_int16[j] / 32767;
00653                         }
00654                         break;
00655                 }
00656         }
00657 
00658 #endif
00659 
00660 
00661         return 0;
00662 }
00663 
00664 int FileAVI::read_frame(VFrame *frame)
00665 {
00666         int result = 0;
00667 
00668 #ifdef USE_AVIFILE
00669         vstream_in[file->current_layer]->ReadFrame();
00670         CImage *temp_image = vstream_in[file->current_layer]->GetFrame();
00671 //printf("FileAVI::read_frame 1 %d %d\n", source_cmodel, frame->get_color_model());
00672         switch(source_cmodel)
00673         {
00674                 case BC_RGB888:
00675                         if(frame->get_color_model() == BC_RGB888)
00676                                 bcopy(temp_image->Data(), 
00677                                         frame->get_data(), 
00678                                         VFrame::calculate_data_size(asset->width, 
00679                                                 asset->height, 
00680                                                 -1, 
00681                                                 BC_RGB888));
00682                         break;
00683         }
00684 #endif
00685         return result;
00686 }
00687 
00688 int64_t FileAVI::compressed_frame_size()
00689 {
00690         int result = 0;
00691         return result;
00692 }
00693 
00694 int FileAVI::read_compressed_frame(VFrame *buffer)
00695 {
00696         int64_t result = 0;
00697 
00698         return result;
00699 }
00700 
00701 int FileAVI::write_compressed_frame(VFrame *buffer)
00702 {
00703         int result = 0;
00704 
00705         return result;
00706 }
00707 
00708 int FileAVI::write_frames(VFrame ***frames, int len)
00709 {
00710         return 0;
00711 }
00712 
00713 
00714 int FileAVI::write_samples(double **buffer, int64_t len)
00715 {
00716         return 0;
00717 }
00718 
00719 
00720 
00721 
00722 
00723 AVIConfigAudio::AVIConfigAudio(BC_WindowBase *parent_window, Asset *asset)
00724  : BC_Window(PROGRAM_NAME ": Audio compression",
00725         parent_window->get_abs_cursor_x(1),
00726         parent_window->get_abs_cursor_y(1),
00727         calculate_w(asset->format),
00728         calculate_h(asset->format))
00729 {
00730         this->parent_window = parent_window;
00731         this->asset = asset;
00732 }
00733 
00734 AVIConfigAudio::~AVIConfigAudio()
00735 {
00736 }
00737 
00738 int AVIConfigAudio::calculate_w(int format)
00739 {
00740         switch(format)
00741         {
00742                 case FILE_AVI_AVIFILE: return 400; break;
00743                 case FILE_AVI_ARNE2: return 250; break;
00744         }
00745 }
00746 
00747 int AVIConfigAudio::calculate_h(int format)
00748 {
00749         switch(format)
00750         {
00751                 case FILE_AVI_AVIFILE: return 200; break;
00752                 case FILE_AVI_ARNE2: return 100; break;
00753         }
00754 }
00755 
00756 int AVIConfigAudio::create_objects()
00757 {
00758         switch(asset->format)
00759         {
00760 #ifdef USE_AVIFILE
00761                 case FILE_AVI_AVIFILE:
00762                 {
00763                         generate_codeclist();
00764 
00765                         int x = 10, y = 10;
00766                         BC_Title *title;
00767                         add_subwindow(title = new BC_Title(x, y, _("Codec: ")));
00768                         list = new AVIACodecList(this, x, y);
00769                         list->create_objects();
00770                         y += list->get_h();
00771                         break;
00772                 }
00773 #endif
00774 
00775                 case FILE_AVI_ARNE2:
00776                         add_subwindow(new BC_Title(10, 10, _("Compressor: 16 bit PCM")));
00777                         break;
00778         }
00779 
00780         add_subwindow(new BC_OKButton(this));
00781         return 0;
00782 }
00783 
00784 int AVIConfigAudio::close_event()
00785 {
00786         return 1;
00787 }
00788 
00789 int AVIConfigAudio::generate_codeclist()
00790 {
00791         FileAVI::initialize_avifile();
00792         codec_items.remove_all_objects();
00793 
00794         switch(asset->format)
00795         {
00796 #ifdef USE_AVIFILE
00797                 case FILE_AVI_AVIFILE:
00798                         for(avm::vector<CodecInfo>::iterator i = audio_codecs.begin();
00799                                 i < audio_codecs.end();
00800                                 i++)
00801                         {
00802                                 if(i->direction & CodecInfo::Encode)
00803                                 {
00804                                         codec_items.append(new BC_ListBoxItem((char*)i->GetName()));
00805                                 }
00806                         }
00807                         break;
00808 #endif
00809         }
00810 
00811         return 0;
00812 }
00813 
00814 void AVIConfigAudio::update_codecs()
00815 {
00816         
00817 }
00818 
00819 
00820 
00821 
00822 
00823 
00824 
00825 
00826 
00827 AVIACodecList::AVIACodecList(AVIConfigAudio *gui, int x, int y)
00828  : BC_PopupTextBox(gui,
00829                 &gui->codec_items,
00830                 FileAVI::fourcc_to_acodec(gui->asset->acodec, gui->string),
00831                 x, 
00832                 y,
00833                 200,
00834                 400)
00835 {
00836         this->gui = gui;
00837 }
00838 
00839 AVIACodecList::~AVIACodecList()
00840 {
00841 }
00842 
00843 int AVIACodecList::handle_event()
00844 {
00845         strcpy(gui->asset->acodec, FileAVI::acodec_to_fourcc(get_text(), gui->string));
00846         return 1;
00847 }
00848 
00849 
00850 
00851 
00852 
00853 AVIConfigVideo::AVIConfigVideo(BC_WindowBase *parent_window, 
00854                 Asset *asset, 
00855                 int lock_compressor)
00856  : BC_Window(PROGRAM_NAME ": Video Compression",
00857         parent_window->get_abs_cursor_x(1),
00858         parent_window->get_abs_cursor_y(1),
00859         calculate_w(asset->format),
00860         calculate_h(asset->format))
00861 {
00862         this->parent_window = parent_window;
00863         this->asset = asset;
00864         this->lock_compressor = lock_compressor;
00865         reset();
00866 }
00867 
00868 AVIConfigVideo::~AVIConfigVideo()
00869 {
00870         codec_items.remove_all_objects();
00871         attribute_items[0].remove_all_objects();
00872         attribute_items[1].remove_all_objects();
00873 }
00874 
00875 void AVIConfigVideo::reset()
00876 {
00877         attributes = 0;
00878         attribute = 0;
00879 }
00880 
00881 int AVIConfigVideo::calculate_w(int format)
00882 {
00883         switch(format)
00884         {
00885                 case FILE_AVI_AVIFILE: return 400; break;
00886                 case FILE_AVI_ARNE2: return 250; break;
00887         }
00888 }
00889 
00890 int AVIConfigVideo::calculate_h(int format)
00891 {
00892         switch(format)
00893         {
00894                 case FILE_AVI_AVIFILE: return 320; break;
00895                 case FILE_AVI_ARNE2: return 100; break;
00896         }
00897 }
00898 
00899 int AVIConfigVideo::create_objects()
00900 {
00901         switch(asset->format)
00902         {
00903 #ifdef USE_AVIFILE
00904                 case FILE_AVI_AVIFILE:
00905                 {
00906                         generate_codeclist();
00907                         generate_attributelist();
00908 
00909                         int x = 10, y = 10, x1 = 90;
00910                         BC_Title *title;
00911                         add_subwindow(title = new BC_Title(x, y, _("Codec: ")));
00912                         list = new AVIVCodecList(this, x1, y);
00913                         list->create_objects();
00914                         y += list->get_h() + 5;
00915 
00916                         add_subwindow(title = new BC_Title(x, y, _("Attributes:")));
00917                         add_subwindow(attributes = new AVIVAttributeList(this, x1, y));
00918                         y += attributes->get_h() + 5;
00919 
00920                         add_subwindow(new BC_Title(x, y, _("Value:")));
00921                         add_subwindow(attribute = new AVIVAttribute(this, x1, y));
00922                         break;
00923                 }
00924 #endif
00925 
00926                 case FILE_AVI_ARNE2:
00927                         add_subwindow(new BC_Title(10, 10, _("Compressor: Consumer DV")));
00928                         break;
00929         }
00930 
00931         add_subwindow(new BC_OKButton(this));
00932         return 0;
00933 }
00934 
00935 int AVIConfigVideo::close_event()
00936 {
00937         return 1;
00938 }
00939 
00940 int AVIConfigVideo::generate_codeclist()
00941 {
00942         FileAVI::initialize_avifile();
00943         switch(asset->format)
00944         {
00945                 case FILE_AVI_AVIFILE:
00946 #ifdef USE_AVIFILE
00947 // Construct codec item list
00948                         for(avm::vector<CodecInfo>::iterator i = video_codecs.begin();
00949                                 i < video_codecs.end();
00950                                 i++)
00951                         {
00952                                 if(i->direction & CodecInfo::Encode)
00953                                 {
00954                                         codec_items.append(new BC_ListBoxItem((char*)i->GetName()));
00955                                 }
00956                         }
00957 #endif
00958                         break;
00959         }
00960 
00961         return 0;
00962 }
00963 
00964 void AVIConfigVideo::generate_attributelist()
00965 {
00966 #ifdef USE_AVIFILE
00967 // Remember selection number
00968         int selection_number = attributes ? attributes->get_selection_number(0, 0) : -1;
00969         attribute_items[0].remove_all_objects();
00970         attribute_items[1].remove_all_objects();
00971         FileAVI::initialize_avifile();
00972 
00973         for(avm::vector<CodecInfo>::iterator i = video_codecs.begin();
00974                 i < video_codecs.end();
00975                 i++)
00976         {
00977                 if(!memcmp((char*)&i->fourcc, asset->vcodec, 4))
00978                 {
00979                         avm::vector<AttributeInfo>& attributes = i->encoder_info;
00980 
00981                         for(avm::vector<AttributeInfo>::const_iterator j = attributes.begin();
00982                                 j != attributes.end();
00983                                 j++)
00984                         {
00985                                 char *name = (char*)j->GetName();
00986                                 char value[BCTEXTLEN];
00987                                 value[0] = 0;
00988 
00989 //printf("AVIConfigVideo::generate_attributelist %d\n", j->kind);
00990                                 switch(j->kind)
00991                                 {
00992                                         case AttributeInfo::Integer:
00993                                         {
00994                                                 int temp = 0;
00995                                                 Creators::GetCodecAttr(*i, name, temp);
00996                                                 sprintf(value, "%d", temp);
00997                                                 break;
00998                                         }
00999 
01000                                         case AttributeInfo::Select:
01001                                         {
01002                                                 int temp = 0;
01003                                                 Creators::GetCodecAttr(*i, name, temp);
01004                                                 sprintf(value, "%d ( %s )", temp, j->options[temp].c_str());
01005                                                 break;
01006                                         }
01007 
01008                                         case AttributeInfo::String:
01009                                         {
01010                                                 const char * temp = 0;
01011                                                 Creators::GetCodecAttr(*i, name, &temp);
01012                                                 if(temp) strncpy(value, temp, BCTEXTLEN);
01013                                                 break;
01014                                         }
01015                                 }
01016 
01017                                 attribute_items[0].append(new BC_ListBoxItem(name));
01018                                 attribute_items[1].append(new BC_ListBoxItem(value));
01019 
01020                                 int current_number = j - attributes.begin();
01021                                 if(current_number == selection_number)
01022                                 {
01023                                         attribute_items[0].values[current_number]->set_selected(1);
01024                                         attribute_items[1].values[current_number]->set_selected(1);
01025                                 }
01026                         }
01027                 }
01028         }
01029 #endif
01030 }
01031 
01032 char* AVIConfigVideo::get_current_attribute_text()
01033 {
01034         BC_ListBoxItem *item = attributes->get_selection(0, 0);
01035 
01036         if(item)
01037         {
01038                 return item->get_text();
01039         }
01040         else
01041                 return "";
01042 }
01043 
01044 char* AVIConfigVideo::get_current_attribute_value()
01045 {
01046         BC_ListBoxItem *item = attributes->get_selection(1, 0);
01047 
01048         if(item)
01049         {
01050                 return item->get_text();
01051         }
01052         else
01053                 return "";
01054 }
01055 
01056 void AVIConfigVideo::set_current_attribute(char *text)
01057 {
01058 #ifdef USE_AVIFILE
01059         int number = attributes->get_selection_number(0, 0);
01060 
01061         if(number >= 0)
01062         {
01063                 FileAVI::initialize_avifile();
01064 
01065                 for(avm::vector<CodecInfo>::iterator i = video_codecs.begin();
01066                         i < video_codecs.end();
01067                         i++)
01068                 {
01069                         if(!memcmp((char*)&i->fourcc, asset->vcodec, 4))
01070                         {
01071                                 avm::vector<AttributeInfo>& attributes = i->encoder_info;
01072                                 AttributeInfo& attribute = attributes[number];
01073 
01074                                 switch(attribute.kind)
01075                                 {
01076                                         case AttributeInfo::Integer:
01077                                                 Creators::SetCodecAttr(*i, attribute.GetName(), atol(text));
01078                                                 break;
01079 
01080                                         case AttributeInfo::Select:
01081                                                 Creators::SetCodecAttr(*i, attribute.GetName(), atol(text));
01082                                                 break;
01083 
01084                                         case AttributeInfo::String:
01085                                                 Creators::SetCodecAttr(*i, attribute.GetName(), text);
01086                                                 break;
01087                                 }
01088                         }
01089                 }
01090                 
01091                 
01092                 update_attribute(1);
01093         }
01094 #endif
01095 }
01096 
01097 
01098 
01099 void AVIConfigVideo::update_attribute(int recursive)
01100 {
01101         generate_attributelist();
01102         attributes->update(attribute_items,
01103                                                 0,
01104                                                 0,
01105                                                 2,
01106                                                 attributes->get_xposition(),
01107                                                 attributes->get_yposition(), 
01108                                                 0,
01109                                                 1);
01110 
01111         if(!recursive) attribute->update(get_current_attribute_value());
01112 }
01113 
01114 
01115 
01116 
01117 
01118 
01119 
01120 
01121 
01122 AVIVCodecList::AVIVCodecList(AVIConfigVideo *gui, int x, int y)
01123  : BC_PopupTextBox(gui,
01124                 &gui->codec_items,
01125                 FileAVI::fourcc_to_vcodec(gui->asset->vcodec, gui->string),
01126                 x, 
01127                 y,
01128                 280,
01129                 400)
01130 {
01131         this->gui = gui;
01132 }
01133 
01134 AVIVCodecList::~AVIVCodecList()
01135 {
01136 }
01137 
01138 int AVIVCodecList::handle_event()
01139 {
01140         strcpy(gui->asset->vcodec, FileAVI::vcodec_to_fourcc(get_text(), gui->string));
01141         gui->update_attribute(0);
01142         return 1;
01143 }
01144 
01145 
01146 
01147 AVIVAttributeList::AVIVAttributeList(AVIConfigVideo *gui, int x, int y)
01148  : BC_ListBox(x, 
01149                 y,
01150                 300,
01151                 200,
01152                 LISTBOX_TEXT,
01153                 gui->attribute_items,
01154                 0,
01155                 0,
01156                 2)
01157 {
01158         this->gui = gui;
01159 }
01160 
01161 int AVIVAttributeList::handle_event()
01162 {
01163         gui->update_attribute(0);
01164         return 1;
01165 }
01166 
01167 int AVIVAttributeList::selection_changed()
01168 {
01169         gui->update_attribute(0);
01170         return 1;
01171 }
01172 
01173 
01174 
01175 
01176 AVIVAttribute::AVIVAttribute(AVIConfigVideo *gui, int x, int y)
01177  : BC_TextBox(x, y, 300, 1, gui->get_current_attribute_value())
01178 {
01179         this->gui = gui;
01180 }
01181 
01182 int AVIVAttribute::handle_event()
01183 {
01184         gui->set_current_attribute(get_text());
01185         return 1;
01186 }
01187 
01188 
01189 

Generated on Sun Jan 8 13:38:54 2006 for Cinelerra-svn by  doxygen 1.4.4