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

filemov.C

Go to the documentation of this file.
00001 #include "asset.h"
00002 #include "bcsignals.h"
00003 #include "bitspopup.h"
00004 #include "byteorder.h"
00005 #include "condition.h"
00006 #include "edit.h"
00007 #include "file.h"
00008 #include "filemov.h"
00009 #include "guicast.h"
00010 #include "language.h"
00011 #include "mwindow.inc"
00012 #include "vframe.h"
00013 #include "videodevice.inc"
00014 
00015 #include <unistd.h>
00016 #include <libdv/dv.h>
00017 
00018 #if 0
00019 N_("MPEG-4")
00020 N_("Dual H.264")
00021 N_("Dual MPEG-4")
00022 N_("H.264")
00023 N_("H.263")
00024 N_("Microsoft MPEG-4")
00025 N_("DV")
00026 N_("PNG")
00027 N_("PNG with Alpha")
00028 N_("Uncompressed RGB")
00029 N_("Uncompressed RGBA")
00030 N_("YUV 4:2:0 Planar")
00031 N_("Component Video")
00032 N_("YUV 4:1:1 Packed")
00033 N_("Component Y'CbCr 8-bit 4:4:4")
00034 N_("Component Y'CbCrA 8-bit 4:4:4:4")
00035 N_("Component Y'CbCr 10-bit 4:4:4")
00036 N_("JPEG Photo")
00037 N_("Motion JPEG A")
00038 
00039 
00040 N_("Twos complement")
00041 N_("Unsigned")
00042 N_("IMA-4")
00043 N_("U-Law")
00044 N_("Vorbis")
00045 N_("MP3")
00046 N_("MPEG-4 Audio")
00047 #endif
00048 
00049 #define DIVX_NAME "MPEG-4"
00050 #define HV64_NAME "Dual H.264"
00051 #define MP4V_NAME "MPEG-4 Video"
00052 #define H264_NAME "H.264"
00053 #define H263_NAME "H.263"
00054 #define HV60_NAME "Dual MPEG-4"
00055 #define DIV3_NAME "Microsoft MPEG-4"
00056 #define DV_NAME "DV"
00057 #define PNG_NAME "PNG"
00058 #define PNGA_NAME "PNG with Alpha"
00059 #define RGB_NAME "Uncompressed RGB"
00060 #define RGBA_NAME "Uncompressed RGBA"
00061 #define YUV420_NAME "YUV 4:2:0 Planar"
00062 #define YUV422_NAME "Component Video"
00063 #define YUV411_NAME "YUV 4:1:1 Packed"
00064 #define YUV444_NAME "Component Y'CbCr 8-bit 4:4:4"
00065 #define YUVA4444_NAME "Component Y'CbCrA 8-bit 4:4:4:4"
00066 #define YUV444_10BIT_NAME "Component Y'CbCr 10-bit 4:4:4"
00067 #define QTJPEG_NAME "JPEG Photo"
00068 #define MJPA_NAME "Motion JPEG A"
00069 
00070 #define TWOS_NAME "Twos complement"
00071 #define RAW_NAME "Unsigned"
00072 #define IMA4_NAME "IMA-4"
00073 #define ULAW_NAME "U-Law"
00074 //#define VORBIS_NAME "Vorbis"
00075 #define MP3_NAME "MP3"
00076 #define MP4A_NAME "MPEG-4 Audio"
00077 #define VORBIS_NAME "OGG Vorbis"
00078 
00079 
00080 
00081 
00082 
00083 FileMOV::FileMOV(Asset *asset, File *file)
00084  : FileBase(asset, file)
00085 {
00086         reset_parameters();
00087         if(asset->format == FILE_UNKNOWN)
00088                 asset->format = FILE_MOV;
00089         asset->byte_order = 0;
00090         suffix_number = 0;
00091         threadframe_lock = new Mutex("FileMOV::threadframe_lock");
00092 }
00093 
00094 FileMOV::~FileMOV()
00095 {
00096         close_file();
00097         delete threadframe_lock;
00098 }
00099 
00100 void FileMOV::get_parameters(BC_WindowBase *parent_window, 
00101         Asset *asset, 
00102         BC_WindowBase* &format_window,
00103         int audio_options,
00104         int video_options,
00105         int lock_compressor)
00106 {
00107         fix_codecs(asset);
00108         if(audio_options)
00109         {
00110                 MOVConfigAudio *window = new MOVConfigAudio(parent_window, asset);
00111                 format_window = window;
00112                 window->create_objects();
00113                 window->run_window();
00114                 delete window;
00115         }
00116         else
00117         if(video_options)
00118         {
00119                 MOVConfigVideo *window = new MOVConfigVideo(parent_window, 
00120                         asset, 
00121                         lock_compressor);
00122                 format_window = window;
00123                 window->create_objects();
00124                 window->run_window();
00125                 delete window;
00126         }
00127 }
00128 
00129 void FileMOV::fix_codecs(Asset *asset)
00130 {
00131 //      if(asset->format == FILE_MOV)
00132 //      {
00133 //              if(!strcasecmp(asset->acodec, QUICKTIME_MP3))
00134 //                      strcpy(asset->acodec, QUICKTIME_TWOS);
00135 //      }
00136 //      else
00137 //      {
00138 //              if(strcasecmp(asset->vcodec, QUICKTIME_DIV3))
00139 //              {
00140 //                      strcpy(asset->vcodec, QUICKTIME_DIV3);
00141 //              }
00142 //              strcpy(asset->acodec, QUICKTIME_MP3);
00143 //      }
00144 }
00145 
00146 int FileMOV::check_sig(Asset *asset)
00147 {
00148         return quicktime_check_sig(asset->path);
00149 }
00150 
00151 
00152 int FileMOV::reset_parameters_derived()
00153 {
00154         fd = 0;
00155         prev_track = 0;
00156         quicktime_atracks = 0;
00157         quicktime_vtracks = 0;
00158         depth = 24;
00159         threads = 0;
00160         frames_correction = 0;
00161         samples_correction = 0;
00162         temp_float = 0;
00163         temp_allocated = 0;
00164 }
00165 
00166 
00167 // Just create the Quicktime objects since this routine is also called
00168 // for reopening.
00169 int FileMOV::open_file(int rd, int wr)
00170 {
00171 
00172         this->rd = rd;
00173         this->wr = wr;
00174 
00175         if(suffix_number == 0) strcpy(prefix_path, asset->path);
00176 
00177         if(!(fd = quicktime_open(asset->path, rd, wr)))
00178         {
00179                 printf(_("FileMOV::open_file %s: No such file or directory\n"), asset->path);
00180                 return 1;
00181         }
00182 
00183         quicktime_set_cpus(fd, file->cpus);
00184 
00185         if(rd)
00186         {
00187                 format_to_asset();
00188                 
00189                 // If DV stream, get the timecode
00190                 if(match4(asset->vcodec, QUICKTIME_DV))
00191                 {
00192                         char tc[12];
00193                         dv_decoder_t *tmp_decoder = dv_decoder_new(0,0,0);
00194                         VFrame *frame = new VFrame(0, 0, 0, BC_COMPRESSED);
00195                         
00196                         read_frame(frame);
00197                         set_video_position(0);
00198                         
00199                         if(dv_parse_header(tmp_decoder, frame->get_data()) > -1)
00200                         {
00201                                 dv_parse_packs(tmp_decoder, frame->get_data());
00202                                 dv_get_timestamp(tmp_decoder, tc);
00203                                 printf("Timestamp %s\n", tc);
00204                         
00205                                 float seconds = Units::text_to_seconds(tc,
00206                                                                                 1, // Use 1 as sample rate, doesn't matter
00207                                                                                 TIME_HMSF,
00208                                                                                 tmp_decoder->height == 576 ? 25 : 30, // FIXME
00209                                                                                 0);
00210                                 // Get frame number
00211                                 asset->tcstart = int64_t(seconds * (tmp_decoder->height == 576 ? 25 : 30));
00212                         }
00213                         
00214                 }
00215         }
00216 
00217         if(wr) asset_to_format();
00218 
00219 // Set decoding parameter
00220         quicktime_set_parameter(fd, "divx_use_deblocking", &asset->divx_use_deblocking);
00221 
00222 // Set timecode offset
00223         quicktime_set_frame_start(fd, asset->tcstart);
00224 
00225         return 0;
00226 }
00227 
00228 int FileMOV::close_file()
00229 {
00230 //printf("FileMOV::close_file 1 %s\n", asset->path);
00231         if(fd)
00232         {
00233                 if(wr) quicktime_set_framerate(fd, asset->frame_rate);
00234                 quicktime_close(fd);
00235         }
00236 
00237 //printf("FileMOV::close_file 1\n");
00238         if(threads)
00239         {
00240                 for(int i = 0; i < file->cpus; i++)
00241                 {
00242                         threads[i]->stop_encoding();
00243                         delete threads[i];
00244                 }
00245                 delete [] threads;
00246                 threads = 0;
00247         }
00248 
00249 //printf("FileMOV::close_file 1\n");
00250         threadframes.remove_all_objects();
00251 
00252 
00253         if(temp_float) 
00254         {
00255                 for(int i = 0; i < asset->channels; i++)
00256                         delete [] temp_float[i];
00257                 delete [] temp_float;
00258         }
00259 
00260 //printf("FileMOV::close_file 1\n");
00261         reset_parameters();
00262         FileBase::close_file();
00263 //printf("FileMOV::close_file 2\n");
00264         return 0;
00265 }
00266 
00267 void FileMOV::set_frame_start(int64_t offset)
00268 {
00269         quicktime_set_frame_start(fd, offset);
00270 }
00271 
00272 void FileMOV::asset_to_format()
00273 {
00274         if(!fd) return;
00275         char audio_codec[5];
00276 
00277         fix_codecs(asset);
00278 
00279 // Fix up the Quicktime file.
00280         quicktime_set_copyright(fd, _("Made with Cinelerra for Linux"));
00281         quicktime_set_info(fd, "Quicktime for Linux");
00282 
00283         if(asset->audio_data)
00284         {
00285                 quicktime_atracks = quicktime_set_audio(fd, 
00286                                 asset->channels, 
00287                                 asset->sample_rate, 
00288                                 asset->bits, 
00289                                 asset->acodec);
00290                 quicktime_set_parameter(fd, "vorbis_vbr", &asset->vorbis_vbr);
00291                 quicktime_set_parameter(fd, "vorbis_min_bitrate", &asset->vorbis_min_bitrate);
00292                 quicktime_set_parameter(fd, "vorbis_bitrate", &asset->vorbis_bitrate);
00293                 quicktime_set_parameter(fd, "vorbis_max_bitrate", &asset->vorbis_max_bitrate);
00294                 quicktime_set_parameter(fd, "mp3_bitrate", &asset->mp3_bitrate);
00295                 quicktime_set_parameter(fd, "mp4a_bitrate", &asset->mp4a_bitrate);
00296         }
00297 
00298         if(asset->video_data)
00299         {
00300                 char string[16];
00301 // Set up the alpha channel compressors
00302                 if(!strcmp(asset->vcodec, MOV_RGBA))
00303                 {
00304                         strcpy(string, QUICKTIME_RAW);
00305                         depth = 32;
00306                 }
00307                 else
00308                 if(!strcmp(asset->vcodec, MOV_PNGA))
00309                 {
00310                         strcpy(string, QUICKTIME_PNG);
00311                         depth = 32;
00312                 }
00313                 else
00314                 if(!strcmp(asset->vcodec, QUICKTIME_YUVA4444))
00315                 {
00316                         strcpy(string, asset->vcodec);
00317                         depth = 32;
00318                 }
00319                 else
00320                 {
00321                         strcpy(string, asset->vcodec);
00322                         depth = 24;
00323                 }
00324 
00325                 quicktime_vtracks = quicktime_set_video(fd, 
00326                                         asset->layers, 
00327                                         asset->width, 
00328                                         asset->height,
00329                                         asset->frame_rate,
00330                                         string);
00331 
00332 
00333 
00334                 for(int i = 0; i < asset->layers; i++)
00335                         quicktime_set_depth(fd, depth, i);
00336 
00337                 quicktime_set_parameter(fd, "jpeg_quality", &asset->jpeg_quality);
00338 
00339 // set the compression parameters if there are any
00340                 quicktime_set_parameter(fd, "divx_bitrate", &asset->divx_bitrate);
00341                 quicktime_set_parameter(fd, "divx_rc_period", &asset->divx_rc_period);
00342                 quicktime_set_parameter(fd, "divx_rc_reaction_ratio", &asset->divx_rc_reaction_ratio);
00343                 quicktime_set_parameter(fd, "divx_rc_reaction_period", &asset->divx_rc_reaction_period);
00344                 quicktime_set_parameter(fd, "divx_max_key_interval", &asset->divx_max_key_interval);
00345                 quicktime_set_parameter(fd, "divx_max_quantizer", &asset->divx_max_quantizer);
00346                 quicktime_set_parameter(fd, "divx_min_quantizer", &asset->divx_min_quantizer);
00347                 quicktime_set_parameter(fd, "divx_quantizer", &asset->divx_quantizer);
00348                 quicktime_set_parameter(fd, "divx_quality", &asset->divx_quality);
00349                 quicktime_set_parameter(fd, "divx_fix_bitrate", &asset->divx_fix_bitrate);
00350 
00351                 quicktime_set_parameter(fd, "ffmpeg_bitrate", &asset->ms_bitrate);
00352                 quicktime_set_parameter(fd, "ffmpeg_bitrate_tolerance", &asset->ms_bitrate_tolerance);
00353                 quicktime_set_parameter(fd, "ffmpeg_interlaced", &asset->ms_interlaced);
00354                 quicktime_set_parameter(fd, "ffmpeg_quantizer", &asset->ms_quantization);
00355                 quicktime_set_parameter(fd, "ffmpeg_gop_size", &asset->ms_gop_size);
00356                 quicktime_set_parameter(fd, "ffmpeg_fix_bitrate", &asset->ms_fix_bitrate);
00357 
00358                 quicktime_set_parameter(fd, "h264_bitrate", &asset->h264_bitrate);
00359                 quicktime_set_parameter(fd, "h264_quantizer", &asset->h264_quantizer);
00360                 quicktime_set_parameter(fd, "h264_fix_bitrate", &asset->h264_fix_bitrate);
00361 
00362 
00363         }
00364 //printf("FileMOV::asset_to_format 3.4\n");
00365 
00366 //printf("FileMOV::asset_to_format 4 %d %d\n", wr, 
00367 //                              asset->format);
00368 
00369         if(wr && asset->format == FILE_AVI)
00370         {
00371                 quicktime_set_avi(fd, 1);
00372         }
00373 }
00374 
00375 
00376 void FileMOV::format_to_asset()
00377 {
00378         if(!fd) return;
00379 
00380         if(quicktime_is_avi(fd)) asset->format = FILE_AVI;
00381         asset->audio_data = quicktime_has_audio(fd);
00382         if(asset->audio_data)
00383         {
00384                 asset->channels = 0;
00385                 int qt_tracks = quicktime_audio_tracks(fd);
00386                 for(int i = 0; i < qt_tracks; i++)
00387                         asset->channels += quicktime_track_channels(fd, i);
00388         
00389                 if(!asset->sample_rate)
00390                         asset->sample_rate = quicktime_sample_rate(fd, 0);
00391                 asset->bits = quicktime_audio_bits(fd, 0);
00392                 asset->audio_length = quicktime_audio_length(fd, 0);
00393                 strncpy(asset->acodec, quicktime_audio_compressor(fd, 0), 4);
00394         }
00395 
00396 // determine if the video can be read before declaring video data
00397         if(quicktime_has_video(fd) && quicktime_supported_video(fd, 0))
00398                         asset->video_data = 1;
00399 
00400         if(asset->video_data)
00401         {
00402                 depth = quicktime_video_depth(fd, 0);
00403                 asset->layers = quicktime_video_tracks(fd);
00404                 asset->width = quicktime_video_width(fd, 0);
00405                 asset->height = quicktime_video_height(fd, 0);
00406                 asset->video_length = quicktime_video_length(fd, 0);
00407 // Don't want a user configured frame rate to get destroyed
00408                 if(!asset->frame_rate)
00409                         asset->frame_rate = quicktime_frame_rate(fd, 0);
00410                 if(!asset->interlace_mode)
00411                         asset->interlace_mode = quicktime_video_interlacemode(fd, 0);
00412 
00413                 strncpy(asset->vcodec, quicktime_video_compressor(fd, 0), 4);
00414         }
00415 }
00416 
00417 int FileMOV::colormodel_supported(int colormodel)
00418 {
00419         return colormodel;
00420 }
00421 
00422 int FileMOV::get_best_colormodel(Asset *asset, int driver)
00423 {
00424         switch(driver)
00425         {
00426                 case PLAYBACK_X11:
00427                         return BC_RGB888;
00428                         break;
00429                 case PLAYBACK_X11_XV:
00430                         if(match4(asset->vcodec, QUICKTIME_YUV420)) return BC_YUV420P;
00431                         if(match4(asset->vcodec, QUICKTIME_YUV422)) return BC_YUV422P;
00432                         if(match4(asset->vcodec, QUICKTIME_JPEG)) return BC_YUV420P;
00433                         if(match4(asset->vcodec, QUICKTIME_MJPA)) return BC_YUV422P;
00434                         if(match4(asset->vcodec, QUICKTIME_DV)) return BC_YUV422;
00435                         if(match4(asset->vcodec, QUICKTIME_DVSD)) return BC_YUV422;
00436                         if(match4(asset->vcodec, QUICKTIME_HV60)) return BC_YUV420P;
00437                         if(match4(asset->vcodec, QUICKTIME_DIVX)) return BC_YUV420P;
00438                         if(match4(asset->vcodec, QUICKTIME_DVSD)) return BC_YUV422;
00439                         if(match4(asset->vcodec, QUICKTIME_MP4V)) return BC_YUV420P;
00440                         if(match4(asset->vcodec, QUICKTIME_H263)) return BC_YUV420P;
00441                         if(match4(asset->vcodec, QUICKTIME_H264)) return BC_YUV420P;
00442                         if(match4(asset->vcodec, QUICKTIME_HV64)) return BC_YUV420P;
00443                         if(match4(asset->vcodec, QUICKTIME_DIV3)) return BC_YUV420P;
00444                         break;
00445                 case PLAYBACK_DV1394:
00446                 case PLAYBACK_FIREWIRE:
00447                         if(match4(asset->vcodec, QUICKTIME_DV) || 
00448                                 match4(asset->vcodec, QUICKTIME_DVSD)) return BC_COMPRESSED;
00449                         return BC_YUV422P;
00450                         break;
00451                 case PLAYBACK_LML:
00452                 case PLAYBACK_BUZ:
00453                         if(match4(asset->vcodec, QUICKTIME_MJPA)) 
00454                                 return BC_COMPRESSED;
00455                         else
00456                                 return BC_YUV422P;
00457                         break;
00458                 case VIDEO4LINUX:
00459                 case VIDEO4LINUX2:
00460                         if(!strncasecmp(asset->vcodec, QUICKTIME_YUV420, 4)) return BC_YUV422;
00461                         else
00462                         if(!strncasecmp(asset->vcodec, QUICKTIME_YUV422, 4)) return BC_YUV422;
00463                         else
00464                         if(!strncasecmp(asset->vcodec, QUICKTIME_YUV411, 4)) return BC_YUV411P;
00465                         else
00466                         if(!strncasecmp(asset->vcodec, QUICKTIME_JPEG, 4)) return BC_YUV420P;
00467                         else
00468                         if(!strncasecmp(asset->vcodec, QUICKTIME_MJPA, 4)) return BC_YUV422P;
00469                         else
00470                         if(!strncasecmp(asset->vcodec, QUICKTIME_HV60, 4)) return BC_YUV420P;
00471                         else
00472                         if(!strncasecmp(asset->vcodec, QUICKTIME_DIVX, 4)) return BC_YUV420P;
00473                         else
00474                         if(!strncasecmp(asset->vcodec, QUICKTIME_H263, 4)) return BC_YUV420P;
00475                         else
00476                         if(!strncasecmp(asset->vcodec, QUICKTIME_DIV3, 4)) return BC_YUV420P;
00477                         break;
00478                 case CAPTURE_BUZ:
00479                 case CAPTURE_LML:
00480                 case VIDEO4LINUX2JPEG:
00481                         if(!strncasecmp(asset->vcodec, QUICKTIME_MJPA, 4)) 
00482                                 return BC_COMPRESSED;
00483                         else
00484                                 return BC_YUV422;
00485                         break;
00486                 case CAPTURE_FIREWIRE:
00487                 case CAPTURE_IEC61883:
00488                         if(!strncasecmp(asset->vcodec, QUICKTIME_DV, 4) ||
00489                                 !strncasecmp(asset->vcodec, QUICKTIME_DVSD, 4)) 
00490                                 return BC_COMPRESSED;
00491                         else
00492                                 return BC_YUV422;
00493                         break;
00494         }
00495         return BC_RGB888;
00496 }
00497 
00498 int FileMOV::can_copy_from(Edit *edit, int64_t position)
00499 {
00500         if(!fd) return 0;
00501 
00502 //printf("FileMOV::can_copy_from 1 %d %s %s\n", edit->asset->format, edit->asset->vcodec, this->asset->vcodec);
00503         if(edit->asset->format == FILE_JPEG_LIST && 
00504                 match4(this->asset->vcodec, QUICKTIME_JPEG))
00505                 return 1;
00506         else
00507         if((edit->asset->format == FILE_MOV || 
00508                 edit->asset->format == FILE_AVI))
00509         {
00510                 if(match4(edit->asset->vcodec, this->asset->vcodec))
00511                         return 1;
00512 // there are combinations where the same codec has multiple fourcc codes
00513 // check for DV...
00514                 int is_edit_dv = 0;
00515                 int is_this_dv = 0;
00516                 if (match4(edit->asset->vcodec, QUICKTIME_DV) || 
00517                         match4(edit->asset->vcodec, QUICKTIME_DVSD))
00518                         is_edit_dv = 1;
00519                 if (match4(this->asset->vcodec, QUICKTIME_DV) || 
00520                         match4(this->asset->vcodec, QUICKTIME_DVSD))
00521                         is_this_dv = 1;
00522                 if (is_this_dv && is_edit_dv)
00523                         return 1;
00524         }
00525         else
00526         if(edit->asset->format == FILE_RAWDV)
00527         {
00528                 if(match4(this->asset->vcodec, QUICKTIME_DV) || match4(this->asset->vcodec, QUICKTIME_DVSD))
00529                         return 1;
00530         }
00531 
00532 
00533         return 0;
00534 }
00535 
00536 
00537 int64_t FileMOV::get_audio_length()
00538 {
00539         if(!fd) return 0;
00540         int64_t result = quicktime_audio_length(fd, 0) + samples_correction;
00541 
00542         return result;
00543 }
00544 
00545 int FileMOV::set_audio_position(int64_t x)
00546 {
00547         if(!fd) return 1;
00548 // quicktime sets positions for each track seperately so store position in audio_position
00549         if(x >= 0 && x < asset->audio_length)
00550                 return quicktime_set_audio_position(fd, x, 0);
00551         else
00552                 return 1;
00553 }
00554 
00555 int FileMOV::set_video_position(int64_t x)
00556 {
00557         if(!fd) return 1;
00558         if(x >= 0 && x < asset->video_length)
00559         {
00560                 int result = quicktime_set_video_position(fd, x, file->current_layer);
00561                 return result;
00562         }else
00563                 return 1;
00564 }
00565 
00566 
00567 void FileMOV::new_audio_temp(int64_t len)
00568 {
00569         if(temp_allocated && temp_allocated < len)
00570         {
00571                 for(int i = 0; i < asset->channels; i++)
00572                         delete [] temp_float[i];
00573                 delete [] temp_float;
00574                 temp_allocated = 0;
00575         }
00576 
00577         if(!temp_allocated)
00578         {
00579                 temp_allocated = len;
00580                 temp_float = new float*[asset->channels];
00581                 for(int i = 0; i < asset->channels; i++)
00582                         temp_float[i] = new float[len];
00583         }
00584 }
00585 
00586 
00587 
00588 int FileMOV::write_samples(double **buffer, int64_t len)
00589 {
00590         int i, j;
00591         int64_t bytes;
00592         int result = 0, track_channels = 0;
00593         int chunk_size;
00594 
00595         if(!fd) return 0;
00596 
00597         if(quicktime_supported_audio(fd, 0))
00598         {
00599 // Use Quicktime's compressor. (Always used)
00600 // Allocate temp buffer
00601                 new_audio_temp(len);
00602 
00603 // Copy to float buffer
00604                 for(i = 0; i < asset->channels; i++)
00605                 {
00606                         for(j = 0; j < len; j++)
00607                         {
00608                                 temp_float[i][j] = buffer[i][j];
00609                         }
00610                 }
00611 
00612 // Because of the way Quicktime's compressors work we want to limit the chunk
00613 // size to speed up decompression.
00614                 float **channel_ptr;
00615                 channel_ptr = new float*[asset->channels];
00616 
00617                 for(j = 0; j < len && !result; )
00618                 {
00619                         chunk_size = asset->sample_rate;
00620                         if(j + chunk_size > len) chunk_size = len - j;
00621 
00622                         for(i = 0; i < asset->channels; i++)
00623                         {
00624                                 channel_ptr[i] = &temp_float[i][j];
00625                         }
00626 
00627                         result = quicktime_encode_audio(fd, 0, channel_ptr, chunk_size);
00628                         j += asset->sample_rate;
00629                 }
00630 
00631                 delete [] channel_ptr;
00632         }
00633         return result;
00634 }
00635 
00636 int FileMOV::write_frames(VFrame ***frames, int len)
00637 {
00638 //printf("FileMOV::write_frames 1\n");
00639         int i, j, k, result = 0;
00640         int default_compressor = 1;
00641         if(!fd) return 0;
00642 
00643         for(i = 0; i < asset->layers && !result; i++)
00644         {
00645 
00646 
00647 
00648 
00649 
00650 // Fix direct copy cases for format conversions.
00651                 if(frames[i][0]->get_color_model() == BC_COMPRESSED)
00652                 {
00653                         default_compressor = 0;
00654                         for(j = 0; j < len && !result; j++)
00655                         {
00656                                 VFrame *frame = frames[i][j];
00657 
00658 
00659 
00660 // Special handling for DIVX
00661 // Determine keyframe status.
00662 // Write VOL header in the first frame if none exists
00663                                 if(!strcmp(asset->vcodec, QUICKTIME_DIVX) ||
00664                                         !strcmp(asset->vcodec, QUICKTIME_H263) ||
00665                                         !strcmp(asset->vcodec, QUICKTIME_HV60))
00666                                 {
00667                                         if(quicktime_mpeg4_is_key(frame->get_data(), 
00668                                                 frame->get_compressed_size(),
00669                                                 asset->vcodec))
00670                                                 quicktime_insert_keyframe(fd, file->current_frame + j, i);
00671 
00672 
00673 // Write header
00674                                         if(!(file->current_frame + j) && 
00675                                                 !quicktime_mpeg4_has_vol(frame->get_data()))
00676                                         {
00677                                                 VFrame *temp_frame = new VFrame;
00678 
00679                                                 temp_frame->allocate_compressed_data(frame->get_compressed_size() + 
00680                                                         0xff);
00681                                                 int bytes = quicktime_mpeg4_write_vol(temp_frame->get_data(),
00682                                                         asset->width, 
00683                                                         asset->height, 
00684                                                         60000, 
00685                                                         asset->frame_rate);
00686                                                 memcpy(temp_frame->get_data() + bytes, 
00687                                                         frame->get_data(), 
00688                                                         frame->get_compressed_size());
00689                                                 temp_frame->set_compressed_size(frame->get_compressed_size() + bytes);
00690 
00691                                                 result = quicktime_write_frame(fd,
00692                                                         temp_frame->get_data(),
00693                                                         temp_frame->get_compressed_size(),
00694                                                         i);
00695 
00696                                                 delete temp_frame;
00697 
00698 
00699                                         }
00700                                         else
00701                                         {
00702                                                 result = quicktime_write_frame(fd,
00703                                                         frame->get_data(),
00704                                                         frame->get_compressed_size(),
00705                                                         i);
00706                                         }
00707                                 }
00708                                 else
00709 // Determine keyframe status
00710                                 if(!strcmp(asset->vcodec, QUICKTIME_H264) ||
00711                                         !strcmp(asset->vcodec, QUICKTIME_HV64) ||
00712                                         !strcmp(asset->vcodec, QUICKTIME_MP4V))
00713                                 {
00714                                         if(frame->get_keyframe() || file->current_frame + j == 0)
00715                                                 quicktime_insert_keyframe(fd, file->current_frame + j, i);
00716 
00717 // Write frame
00718                                                 result = quicktime_write_frame(fd,
00719                                                         frame->get_data(),
00720                                                         frame->get_compressed_size(),
00721                                                         i);
00722                                 }
00723                                 else
00724                                 if(!strcmp(asset->vcodec, QUICKTIME_DIV3))
00725                                 {
00726                                         if(quicktime_mpeg4_is_key(frame->get_data(), 
00727                                                 frame->get_compressed_size(),
00728                                                 asset->vcodec))
00729                                                 quicktime_insert_keyframe(fd, file->current_frame + j, i);
00730                                         result = quicktime_write_frame(fd,
00731                                                 frame->get_data(),
00732                                                 frame->get_compressed_size(),
00733                                                 i);
00734                                 }
00735                                 else
00736                                 if(!strcmp(asset->vcodec, QUICKTIME_MJPA))
00737                                 {
00738                                         long field2_offset;
00739 
00740 // Create extra space for markers
00741                                         if(frame->get_compressed_allocated() - frame->get_compressed_size() < 0x100)
00742                                                 frame->allocate_compressed_data(frame->get_compressed_size() + 0x100);
00743 
00744                                         unsigned char *data = frame->get_data();
00745                                         long data_size = frame->get_compressed_size();
00746                                         long data_allocated = frame->get_compressed_allocated();
00747 
00748 // Sometimes get 0 length frames
00749                                         if(data_size)
00750                                         {
00751                                                 if(asset->format == FILE_MOV)
00752                                                 {
00753                                                         mjpeg_insert_quicktime_markers(&data,
00754                                                                 &data_size,
00755                                                                 &data_allocated,
00756                                                                 2,
00757                                                                 &field2_offset);
00758                                                 }
00759                                                 else
00760                                                 {
00761                                                         mjpeg_insert_avi_markers(&data,
00762                                                                 &data_size,
00763                                                                 &data_allocated,
00764                                                                 2,
00765                                                                 &field2_offset);
00766                                                 }
00767                                                 frame->set_compressed_size(data_size);
00768                                                 result = quicktime_write_frame(fd,
00769                                                         frame->get_data(),
00770                                                         frame->get_compressed_size(),
00771                                                         i);
00772                                         }
00773                                         else
00774                                                 printf("FileMOV::write_frames data_size=%d\n", data_size);
00775                                 }
00776                                 else
00777                                         result = quicktime_write_frame(fd,
00778                                                 frame->get_data(),
00779                                                 frame->get_compressed_size(),
00780                                                 i);
00781                                 
00782                                 
00783                         }
00784                 }
00785                 else
00786                 if(match4(asset->vcodec, QUICKTIME_YUV420) ||
00787                         match4(asset->vcodec, QUICKTIME_YUV422) ||
00788                         match4(asset->vcodec, QUICKTIME_RAW))
00789                 {
00790 // Direct copy planes where possible
00791                         default_compressor = 0;
00792                         for(j = 0; j < len && !result; j++)
00793                         {
00794                                 VFrame *frame = frames[i][j];
00795 //printf("FileMOV::write_frames 1 %d\n", frame->get_color_model());
00796                                 quicktime_set_cmodel(fd, frame->get_color_model());
00797                                 if(cmodel_is_planar(frame->get_color_model()))
00798                                 {
00799                                         unsigned char *planes[3];
00800                                         planes[0] = frame->get_y();
00801                                         planes[1] = frame->get_u();
00802                                         planes[2] = frame->get_v();
00803                                         result = quicktime_encode_video(fd, planes, i);
00804                                 }
00805                                 else
00806                                 {
00807                                         result = quicktime_encode_video(fd, frame->get_rows(), i);
00808 //printf("FileMOV::write_frames 2 %d\n", result);
00809                                 }
00810 //printf("FileMOV::write_frames 2\n");
00811                         }
00812                 }
00813                 else
00814                 if(file->cpus > 1 && 
00815                         (match4(asset->vcodec, QUICKTIME_JPEG) || 
00816                         match4(asset->vcodec, QUICKTIME_MJPA)))
00817                 {
00818                         default_compressor = 0;
00819 // Compress symmetrically on an SMP system.
00820                         ThreadStruct *threadframe;
00821                         int fields = match4(asset->vcodec, QUICKTIME_MJPA) ? 2 : 1;
00822 
00823 // Set up threads for symmetric compression.
00824                         if(!threads)
00825                         {
00826                                 threads = new FileMOVThread*[file->cpus];
00827                                 for(j = 0; j < file->cpus; j++)
00828                                 {
00829                                         threads[j] = new FileMOVThread(this, fields);
00830                                         threads[j]->start_encoding();
00831                                 }
00832                         }
00833 
00834 // Set up the frame structures for asynchronous compression.
00835 // The mjpeg object must exist in each threadframe because it is where the output
00836 // is stored.
00837                         while(threadframes.total < len)
00838                         {
00839                                 threadframes.append(threadframe = new ThreadStruct);
00840                         }
00841 
00842 // Load thread frame structures with new frames.
00843                         for(j = 0; j < len; j++)
00844                         {
00845                                 VFrame *frame = frames[i][j];
00846                                 threadframes.values[j]->input = frame;
00847                                 threadframes.values[j]->completion_lock->lock("FileMOV::write_frames 1");
00848                         }
00849                         total_threadframes = len;
00850                         current_threadframe = 0;
00851 
00852 // Start the threads compressing
00853                         for(j = 0; j < file->cpus; j++)
00854                         {
00855                                 threads[j]->encode_buffer();
00856                         }
00857 
00858 
00859 // Write the frames as they're finished
00860                         for(j = 0; j < len; j++)
00861                         {
00862                                 threadframes.values[j]->completion_lock->lock("FileMOV::write_frames 1");
00863                                 threadframes.values[j]->completion_lock->unlock();
00864                                 if(!result)
00865                                 {
00866                                         result = quicktime_write_frame(fd, 
00867                                                 threadframes.values[j]->output,
00868                                                 threadframes.values[j]->output_size,
00869                                                 i);
00870                                 }
00871                         }
00872                 }
00873 
00874                 if(default_compressor)
00875                 {
00876 //printf("FileMOV::write_frames 3\n");
00877 // Use the library's built in compressor.
00878                         for(j = 0; j < len && !result; j++)
00879                         {
00880 //printf("FileMOV::write_frames 4\n");
00881                                 VFrame *frame = frames[i][j];
00882                                 quicktime_set_cmodel(fd, frame->get_color_model());
00883 //printf("FileMOV::write_frames 5\n");
00884                                 if(cmodel_is_planar(frame->get_color_model()))
00885                                 {
00886                                         unsigned char *planes[3];
00887                                         planes[0] = frame->get_y();
00888                                         planes[1] = frame->get_u();
00889                                         planes[2] = frame->get_v();
00890                                         result = quicktime_encode_video(fd, planes, i);
00891                                 }
00892                                 else
00893                                 {
00894                                         result = quicktime_encode_video(fd, frame->get_rows(), i);
00895                                 }
00896                         }
00897                 }
00898 //printf("FileMOV::write_frames 4\n");
00899         }
00900 
00901 
00902 //printf("FileMOV::write_frames 100\n");
00903         return result;
00904 }
00905 
00906 
00907 
00908 int FileMOV::read_frame(VFrame *frame)
00909 {
00910         if(!fd) return 1;
00911         int result = 0;
00912 
00913         switch(frame->get_color_model())
00914         {
00915                 case BC_COMPRESSED:
00916                         frame->allocate_compressed_data(quicktime_frame_size(fd, file->current_frame, file->current_layer));
00917                         frame->set_compressed_size(quicktime_frame_size(fd, file->current_frame, file->current_layer));
00918                         frame->set_keyframe((quicktime_get_keyframe_before(fd, 
00919                                 file->current_frame, 
00920                                 file->current_layer) == file->current_frame));
00921 //printf("FileMOV::read_frame 1 %lld %d\n", file->current_frame, frame->get_keyframe());
00922                         result = quicktime_read_frame(fd, 
00923                                 frame->get_data(), 
00924                                 file->current_layer);
00925                         break;
00926 
00927 // Progressive
00928                 case BC_YUV420P:
00929                 case BC_YUV422P:
00930                 {
00931                         unsigned char *row_pointers[3];
00932                         row_pointers[0] = frame->get_y();
00933                         row_pointers[1] = frame->get_u();
00934                         row_pointers[2] = frame->get_v();
00935 
00936                         quicktime_set_cmodel(fd, frame->get_color_model());
00937                         quicktime_decode_video(fd, 
00938                                 row_pointers,
00939                                 file->current_layer);
00940                 }
00941                         break;
00942 
00943 // Packed
00944                 default:
00945                         quicktime_set_cmodel(fd, frame->get_color_model());
00946                         result = quicktime_decode_video(fd, 
00947                                 frame->get_rows(),
00948                                 file->current_layer);
00949 //for(int i = 0; i < 10000; i++) frame->get_rows()[0][i] = 0xff;
00950                         break;
00951         }
00952 
00953 
00954 
00955         return result;
00956 }
00957 
00958 
00959 
00960 int64_t FileMOV::compressed_frame_size()
00961 {
00962         if(!fd) return 0;
00963         return quicktime_frame_size(fd, file->current_frame, file->current_layer);
00964 }
00965 
00966 int FileMOV::read_compressed_frame(VFrame *buffer)
00967 {
00968         int64_t result;
00969         if(!fd) return 0;
00970 
00971         result = quicktime_read_frame(fd, buffer->get_data(), file->current_layer);
00972         buffer->set_compressed_size(result);
00973         buffer->set_keyframe((quicktime_get_keyframe_before(fd, 
00974                 file->current_frame, 
00975                 file->current_layer) == file->current_frame));
00976         result = !result;
00977         return result;
00978 }
00979 
00980 int FileMOV::write_compressed_frame(VFrame *buffer)
00981 {
00982         int result = 0;
00983         if(!fd) return 0;
00984 
00985         result = quicktime_write_frame(fd, 
00986                 buffer->get_data(), 
00987                 buffer->get_compressed_size(), 
00988                 file->current_layer);
00989         return result;
00990 }
00991 
00992 
00993 
00994 int FileMOV::read_raw(VFrame *frame, 
00995                 float in_x1, float in_y1, float in_x2, float in_y2,
00996                 float out_x1, float out_y1, float out_x2, float out_y2, 
00997                 int use_float, int interpolate)
00998 {
00999         int64_t i, color_channels, result = 0;
01000         if(!fd) return 0;
01001 
01002         quicktime_set_video_position(fd, file->current_frame, file->current_layer);
01003 // Develop importing strategy
01004         switch(frame->get_color_model())
01005         {
01006                 case BC_RGB888:
01007                         result = quicktime_decode_video(fd, frame->get_rows(), file->current_layer);
01008                         break;
01009                 case BC_RGBA8888:
01010                         break;
01011                 case BC_RGB161616:
01012                         break;
01013                 case BC_RGBA16161616:
01014                         break;
01015                 case BC_YUV888:
01016                         break;
01017                 case BC_YUVA8888:
01018                         break;
01019                 case BC_YUV161616:
01020                         break;
01021                 case BC_YUVA16161616:
01022                         break;
01023                 case BC_YUV420P:
01024                         break;
01025         }
01026         return result;
01027 }
01028 
01029 // Overlay samples
01030 int FileMOV::read_samples(double *buffer, int64_t len)
01031 {
01032         int qt_track, qt_channel;
01033 
01034         if(!fd) return 0;
01035 
01036         if(quicktime_track_channels(fd, 0) > file->current_channel &&
01037                 quicktime_supported_audio(fd, 0))
01038         {
01039 
01040 //printf("FileMOV::read_samples 2 %ld %ld\n", file->current_sample, quicktime_audio_position(fd, 0));
01041                 new_audio_temp(len);
01042 
01043 //printf("FileMOV::read_samples 3 %ld %ld\n", file->current_sample, quicktime_audio_position(fd, 0));
01044                 if(quicktime_decode_audio(fd, 0, temp_float[0], len, file->current_channel))
01045                 {
01046                         printf("FileMOV::read_samples: quicktime_decode_audio failed\n");
01047                         return 1;
01048                 }
01049                 else
01050                 {
01051                         for(int i = 0; i < len; i++) buffer[i] = temp_float[0][i];
01052                 }
01053 
01054 // if(file->current_channel == 0)
01055 // for(int i = 0; i < len; i++)
01056 // {
01057 //      int16_t value;
01058 //      value = (int16_t)(temp_float[0][i] * 32767);
01059 //      fwrite(&value, 2, 1, stdout);
01060 // }
01061 //printf("FileMOV::read_samples 4 %ld %ld\n", file->current_sample, quicktime_audio_position(fd, 0));
01062         }
01063 
01064         return 0;
01065 }
01066 
01067 
01068 char* FileMOV::strtocompression(char *string)
01069 {
01070         if(!strcasecmp(string, _(DIVX_NAME))) return QUICKTIME_DIVX;
01071         if(!strcasecmp(string, _(H264_NAME))) return QUICKTIME_H264;
01072         if(!strcasecmp(string, _(HV64_NAME))) return QUICKTIME_HV64;
01073         if(!strcasecmp(string, _(MP4V_NAME))) return QUICKTIME_MP4V;
01074         if(!strcasecmp(string, _(H263_NAME))) return QUICKTIME_H263;
01075         if(!strcasecmp(string, _(HV60_NAME))) return QUICKTIME_HV60;
01076         if(!strcasecmp(string, _(DIV3_NAME))) return QUICKTIME_DIV3;
01077         if(!strcasecmp(string, _(DV_NAME))) return QUICKTIME_DVSD;
01078 //      if(!strcasecmp(string, _(DV_NAME))) return QUICKTIME_DV;
01079         if(!strcasecmp(string, _(PNG_NAME))) return QUICKTIME_PNG;
01080         if(!strcasecmp(string, _(PNGA_NAME))) return MOV_PNGA;
01081         if(!strcasecmp(string, _(RGB_NAME))) return QUICKTIME_RAW;
01082         if(!strcasecmp(string, _(RGBA_NAME))) return MOV_RGBA;
01083         if(!strcasecmp(string, _(QTJPEG_NAME))) return QUICKTIME_JPEG;
01084         if(!strcasecmp(string, _(MJPA_NAME))) return QUICKTIME_MJPA;
01085         if(!strcasecmp(string, _(YUV420_NAME))) return QUICKTIME_YUV420;
01086         if(!strcasecmp(string, _(YUV411_NAME))) return QUICKTIME_YUV411;
01087         if(!strcasecmp(string, _(YUV422_NAME))) return QUICKTIME_YUV422;
01088         if(!strcasecmp(string, _(YUV444_NAME))) return QUICKTIME_YUV444;
01089         if(!strcasecmp(string, _(YUVA4444_NAME))) return QUICKTIME_YUVA4444;
01090         if(!strcasecmp(string, _(YUV444_10BIT_NAME))) return QUICKTIME_YUV444_10bit;
01091 
01092         if(!strcasecmp(string, _(TWOS_NAME))) return QUICKTIME_TWOS;
01093         if(!strcasecmp(string, _(RAW_NAME))) return QUICKTIME_RAW;
01094         if(!strcasecmp(string, _(IMA4_NAME))) return QUICKTIME_IMA4;
01095         if(!strcasecmp(string, _(ULAW_NAME))) return QUICKTIME_ULAW;
01096         if(!strcasecmp(string, _(MP3_NAME))) return QUICKTIME_MP3;
01097         if(!strcasecmp(string, _(MP4A_NAME))) return QUICKTIME_MP4A;
01098         if(!strcasecmp(string, _(VORBIS_NAME))) return QUICKTIME_VORBIS;
01099 
01100 
01101 
01102         return QUICKTIME_RAW;
01103 }
01104 
01105 char* FileMOV::compressiontostr(char *string)
01106 {
01107         if(match4(string, QUICKTIME_H263)) return _(H263_NAME);
01108         if(match4(string, QUICKTIME_H264)) return _(H264_NAME);
01109         if(match4(string, QUICKTIME_HV64)) return _(HV64_NAME);
01110         if(match4(string, QUICKTIME_DIVX)) return _(DIVX_NAME);
01111         if(match4(string, QUICKTIME_MP4V)) return _(MP4V_NAME);
01112         if(match4(string, QUICKTIME_HV60)) return _(HV60_NAME);
01113         if(match4(string, QUICKTIME_DIV3)) return _(DIV3_NAME);
01114         if(match4(string, QUICKTIME_DV)) return _(DV_NAME);
01115         if(match4(string, QUICKTIME_DVSD)) return _(DV_NAME);
01116         if(match4(string, MOV_PNGA)) return _(PNGA_NAME);
01117         if(match4(string, QUICKTIME_RAW)) return _(RGB_NAME);
01118         if(match4(string, MOV_RGBA)) return _(RGBA_NAME);
01119         if(match4(string, QUICKTIME_JPEG)) return _(QTJPEG_NAME);
01120         if(match4(string, QUICKTIME_MJPA)) return _(MJPA_NAME);
01121         if(match4(string, QUICKTIME_YUV420)) return _(YUV420_NAME);
01122         if(match4(string, QUICKTIME_YUV411)) return _(YUV411_NAME);
01123         if(match4(string, QUICKTIME_YUV422)) return _(YUV422_NAME);
01124         if(match4(string, QUICKTIME_YUV444)) return _(YUV444_NAME);
01125         if(match4(string, QUICKTIME_YUVA4444)) return _(YUVA4444_NAME);
01126         if(match4(string, QUICKTIME_YUV444_10bit)) return _(YUV444_10BIT_NAME);
01127 
01128 
01129 
01130 
01131 
01132         if(match4(string, QUICKTIME_TWOS)) return _(TWOS_NAME);
01133         if(match4(string, QUICKTIME_RAW)) return _(RAW_NAME);
01134         if(match4(string, QUICKTIME_IMA4)) return _(IMA4_NAME);
01135         if(match4(string, QUICKTIME_ULAW)) return _(ULAW_NAME);
01136         if(match4(string, QUICKTIME_MP3)) return _(MP3_NAME);
01137         if(match4(string, QUICKTIME_MP4A)) return _(MP4A_NAME);
01138         if(match4(string, QUICKTIME_VORBIS)) return _(VORBIS_NAME);
01139 
01140 
01141 
01142         return _("Unknown");
01143 }
01144 
01145 
01146 
01147 
01148 
01149 ThreadStruct::ThreadStruct()
01150 {
01151         input = 0;
01152         output = 0;
01153         output_allocated = 0;
01154         output_size = 0;
01155         completion_lock = new Condition(1, "ThreadStruct::completion_lock");
01156 }
01157 
01158 ThreadStruct::~ThreadStruct()
01159 {
01160         if(output) delete [] output;
01161         delete completion_lock;
01162 }
01163 
01164 void ThreadStruct::load_output(mjpeg_t *mjpeg)
01165 {
01166         if(output_allocated < mjpeg_output_size(mjpeg))
01167         {
01168                 delete [] output;
01169                 output = 0;
01170         }
01171         if(!output)
01172         {
01173                 output_allocated = mjpeg_output_size(mjpeg);
01174                 output = new unsigned char[output_allocated];
01175         }
01176         
01177         output_size = mjpeg_output_size(mjpeg);
01178         memcpy(output, mjpeg_output_buffer(mjpeg), output_size);
01179 }
01180 
01181 
01182 FileMOVThread::FileMOVThread(FileMOV *filemov, int fields) : Thread()
01183 {
01184         this->filemov = filemov;
01185         this->fields = fields;
01186         mjpeg = 0;
01187         input_lock = new Condition(1, "FileMOVThread::input_lock");
01188 }
01189 
01190 FileMOVThread::~FileMOVThread()
01191 {
01192         delete input_lock;
01193 }
01194 
01195 int FileMOVThread::start_encoding()
01196 {
01197         mjpeg = mjpeg_new(filemov->asset->width, 
01198                 filemov->asset->height, 
01199                 fields);
01200         mjpeg_set_quality(mjpeg, filemov->asset->jpeg_quality);
01201         mjpeg_set_float(mjpeg, 0);
01202         done = 0;
01203         set_synchronous(1);
01204         input_lock->lock("FileMOVThread::start_encoding");
01205         start();
01206 }
01207 
01208 int FileMOVThread::stop_encoding()
01209 {
01210         done = 1;
01211         input_lock->unlock();
01212         join();
01213         if(mjpeg) mjpeg_delete(mjpeg);
01214 }
01215 
01216 int FileMOVThread::encode_buffer()
01217 {
01218         input_lock->unlock();
01219 }
01220 
01221 void FileMOVThread::run()
01222 {
01223         while(!done)
01224         {
01225                 input_lock->lock("FileMOVThread::run");
01226 
01227                 if(!done)
01228                 {
01229 // Get a frame to compress.
01230                         filemov->threadframe_lock->lock("FileMOVThread::stop_encoding");
01231                         if(filemov->current_threadframe < filemov->total_threadframes)
01232                         {
01233 // Frame is available to process.
01234                                 input_lock->unlock();
01235                                 threadframe = filemov->threadframes.values[filemov->current_threadframe];
01236                                 VFrame *frame = threadframe->input;
01237 
01238                                 filemov->current_threadframe++;
01239                                 filemov->threadframe_lock->unlock();
01240 
01241                                 mjpeg_compress(mjpeg, 
01242                                         frame->get_rows(), 
01243                                         frame->get_y(), 
01244                                         frame->get_u(), 
01245                                         frame->get_v(),
01246                                         frame->get_color_model(),
01247                                         1);
01248 
01249                                 if(fields > 1)
01250                                 {
01251                                         unsigned char *data = mjpeg_output_buffer(mjpeg);
01252                                         long data_size = mjpeg_output_size(mjpeg);
01253                                         long data_allocated = mjpeg_output_allocated(mjpeg);
01254                                         long field2_offset;
01255 
01256                                         if(filemov->asset->format == FILE_MOV)
01257                                         {
01258                                                 mjpeg_insert_quicktime_markers(&data,
01259                                                         &data_size,
01260                                                         &data_allocated,
01261                                                         2,
01262                                                         &field2_offset);
01263                                         }
01264                                         else
01265                                         {
01266                                                 mjpeg_insert_avi_markers(&data,
01267                                                         &data_size,
01268                                                         &data_allocated,
01269                                                         2,
01270                                                         &field2_offset);
01271                                         }
01272                                         mjpeg_set_output_size(mjpeg, data_size);
01273                                 }
01274                                 threadframe->load_output(mjpeg);
01275                                 threadframe->completion_lock->unlock();
01276                         }
01277                         else
01278                                 filemov->threadframe_lock->unlock();
01279                 }
01280         }
01281 }
01282 
01283 
01284 
01285 
01286 
01287 
01288 MOVConfigAudio::MOVConfigAudio(BC_WindowBase *parent_window, Asset *asset)
01289  : BC_Window(PROGRAM_NAME ": Audio Compression",
01290         parent_window->get_abs_cursor_x(1),
01291         parent_window->get_abs_cursor_y(1),
01292         350,
01293         250)
01294 {
01295         this->parent_window = parent_window;
01296         this->asset = asset;
01297         compression_popup = 0;
01298         reset();
01299 }
01300 
01301 MOVConfigAudio::~MOVConfigAudio()
01302 {
01303         if(compression_popup) delete compression_popup;
01304         if(bits_popup) delete bits_popup;
01305         compression_items.remove_all_objects();
01306 }
01307 
01308 
01309 void MOVConfigAudio::reset()
01310 {
01311         bits_popup = 0;
01312         bits_title = 0;
01313         dither = 0;
01314         vorbis_min_bitrate = 0;
01315         vorbis_bitrate = 0;
01316         vorbis_max_bitrate = 0;
01317         vorbis_vbr = 0;
01318         mp3_bitrate = 0;
01319         mp4a_bitrate = 0;
01320         mp4a_quantqual = 0;
01321 }
01322 
01323 int MOVConfigAudio::create_objects()
01324 {
01325         int x = 10, y = 10;
01326 
01327 
01328         if(asset->format == FILE_MOV)
01329         {
01330                 compression_items.append(new BC_ListBoxItem(_(TWOS_NAME)));
01331                 compression_items.append(new BC_ListBoxItem(_(RAW_NAME)));
01332                 compression_items.append(new BC_ListBoxItem(_(IMA4_NAME)));
01333                 compression_items.append(new BC_ListBoxItem(_(MP3_NAME)));
01334                 compression_items.append(new BC_ListBoxItem(_(ULAW_NAME)));
01335                 compression_items.append(new BC_ListBoxItem(_(VORBIS_NAME)));
01336                 compression_items.append(new BC_ListBoxItem(_(MP4A_NAME)));
01337         }
01338         else
01339         {
01340                 compression_items.append(new BC_ListBoxItem(_(TWOS_NAME)));
01341                 compression_items.append(new BC_ListBoxItem(_(MP3_NAME)));
01342                 compression_items.append(new BC_ListBoxItem(_(VORBIS_NAME)));
01343                 compression_items.append(new BC_ListBoxItem(_(MP4A_NAME)));
01344         }
01345 
01346         add_tool(new BC_Title(x, y, _("Compression:")));
01347         y += 25;
01348         compression_popup = new MOVConfigAudioPopup(this, x, y);
01349         compression_popup->create_objects();
01350 
01351         update_parameters();
01352 
01353         add_subwindow(new BC_OKButton(this));
01354         return 0;
01355 }
01356 
01357 void MOVConfigAudio::update_parameters()
01358 {
01359         int x = 10, y = 70;
01360         if(bits_title) delete bits_title;
01361         if(bits_popup) delete bits_popup;
01362         if(dither) delete dither;
01363         if(vorbis_min_bitrate) delete vorbis_min_bitrate;
01364         if(vorbis_bitrate) delete vorbis_bitrate;
01365         if(vorbis_max_bitrate) delete vorbis_max_bitrate;
01366         if(vorbis_vbr) delete vorbis_vbr;
01367         if(mp3_bitrate) delete mp3_bitrate;
01368         delete mp4a_bitrate;
01369         delete mp4a_quantqual;
01370 
01371         reset();
01372 
01373 
01374 
01375         if(!strcasecmp(asset->acodec, QUICKTIME_TWOS) ||
01376                 !strcasecmp(asset->acodec, QUICKTIME_RAW))
01377         {
01378                 add_subwindow(bits_title = new BC_Title(x, y, _("Bits per channel:")));
01379                 bits_popup = new BitsPopup(this, 
01380                         x + 150, 
01381                         y, 
01382                         &asset->bits, 
01383                         0, 
01384                         0, 
01385                         0, 
01386                         0, 
01387                         0);
01388                 bits_popup->create_objects();
01389                 y += 40;
01390                 add_subwindow(dither = new BC_CheckBox(x, y, &asset->dither, _("Dither")));
01391         }
01392         else
01393         if(!strcasecmp(asset->acodec, QUICKTIME_IMA4))
01394         {
01395         }
01396         else
01397         if(!strcasecmp(asset->acodec, QUICKTIME_MP3))
01398         {
01399                 mp3_bitrate = new MOVConfigAudioNum(this, 
01400                         _("Bitrate:"), 
01401                         x, 
01402                         y, 
01403                         &asset->mp3_bitrate);
01404                 mp3_bitrate->set_increment(1000);
01405                 mp3_bitrate->create_objects();
01406         }
01407         else
01408         if(!strcasecmp(asset->acodec, QUICKTIME_ULAW))
01409         {
01410         }
01411         else
01412         if(!strcasecmp(asset->acodec, QUICKTIME_VORBIS))
01413         {
01414                 add_subwindow(vorbis_vbr = new MOVConfigAudioToggle(this,
01415                         _("Variable bitrate"),
01416                         x,
01417                         y,
01418                         &asset->vorbis_vbr));
01419                 y += 35;
01420                 vorbis_min_bitrate = new MOVConfigAudioNum(this, 
01421                         _("Min bitrate:"), 
01422                         x, 
01423                         y, 
01424                         &asset->vorbis_min_bitrate);
01425                 vorbis_min_bitrate->set_increment(1000);
01426                 y += 30;
01427                 vorbis_bitrate = new MOVConfigAudioNum(this, 
01428                         _("Avg bitrate:"), 
01429                         x, 
01430                         y, 
01431                         &asset->vorbis_bitrate);
01432                 vorbis_bitrate->set_increment(1000);
01433                 y += 30;
01434                 vorbis_max_bitrate = new MOVConfigAudioNum(this, 
01435                         _("Max bitrate:"), 
01436                         x, 
01437                         y, 
01438                         &asset->vorbis_max_bitrate);
01439                 vorbis_max_bitrate->set_increment(1000);
01440 
01441 
01442 
01443                 vorbis_min_bitrate->create_objects();
01444                 vorbis_bitrate->create_objects();
01445                 vorbis_max_bitrate->create_objects();
01446         }
01447         else
01448         if(!strcasecmp(asset->acodec, QUICKTIME_MP4A))
01449         {
01450                 mp4a_bitrate = new MOVConfigAudioNum(this, 
01451                         _("Bitrate:"), 
01452                         x, 
01453                         y, 
01454                         &asset->mp4a_bitrate);
01455                 mp4a_bitrate->set_increment(1000);
01456                 mp4a_bitrate->create_objects();
01457 
01458                 y += 30;
01459                 mp4a_quantqual = new MOVConfigAudioNum(this, 
01460                         _("Quantization Quality (%):"), 
01461                         x, 
01462                         y, 
01463                         &asset->mp4a_quantqual);
01464                 mp4a_quantqual->set_increment(1);
01465                 mp4a_quantqual->create_objects();
01466         }
01467 }
01468 
01469 int MOVConfigAudio::close_event()
01470 {
01471         set_done(0);
01472         return 1;
01473 }
01474 
01475 
01476 
01477 
01478 
01479 MOVConfigAudioToggle::MOVConfigAudioToggle(MOVConfigAudio *popup,
01480         char *title_text,
01481         int x,
01482         int y,
01483         int *output)
01484  : BC_CheckBox(x, y, *output, title_text)
01485 {
01486         this->popup = popup;
01487         this->output = output;
01488 }
01489 int MOVConfigAudioToggle::handle_event()
01490 {
01491         *output = get_value();
01492         return 1;
01493 }
01494 
01495 
01496 
01497 
01498 
01499 MOVConfigAudioNum::MOVConfigAudioNum(MOVConfigAudio *popup, char *title_text, int x, int y, int *output)
01500  : BC_TumbleTextBox(popup, 
01501                 (int64_t)*output,
01502                 (int64_t)-1,
01503                 (int64_t)25000000,
01504                 popup->get_w() - 150, 
01505                 y, 
01506                 100)
01507 {
01508         this->popup = popup;
01509         this->title_text = title_text;
01510         this->output = output;
01511         this->x = x;
01512         this->y = y;
01513 }
01514 
01515 MOVConfigAudioNum::~MOVConfigAudioNum()
01516 {
01517         if(!popup->get_deleting()) delete title;
01518 }
01519 
01520 void MOVConfigAudioNum::create_objects()
01521 {
01522         popup->add_subwindow(title = new BC_Title(x, y, title_text));
01523         BC_TumbleTextBox::create_objects();
01524 }
01525 
01526 int MOVConfigAudioNum::handle_event()
01527 {
01528         *output = atol(get_text());
01529         return 1;
01530 }
01531 
01532 
01533 
01534 
01535 
01536 
01537 
01538 
01539 MOVConfigAudioPopup::MOVConfigAudioPopup(MOVConfigAudio *popup, int x, int y)
01540  : BC_PopupTextBox(popup, 
01541                 &popup->compression_items,
01542                 FileMOV::compressiontostr(popup->asset->acodec),
01543                 x, 
01544                 y, 
01545                 300,
01546                 300)
01547 {
01548         this->popup = popup;
01549 }
01550 
01551 int MOVConfigAudioPopup::handle_event()
01552 {
01553         strcpy(popup->asset->acodec, FileMOV::strtocompression(get_text()));
01554         popup->update_parameters();
01555         return 1;
01556 }
01557 
01558 
01559 
01560 
01561 
01562 
01563 
01564 
01565 
01566 
01567 
01568 
01569 
01570 
01571 
01572 
01573 
01574 MOVConfigVideo::MOVConfigVideo(BC_WindowBase *parent_window, 
01575         Asset *asset, 
01576         int lock_compressor)
01577  : BC_Window(PROGRAM_NAME ": Video Compression",
01578         parent_window->get_abs_cursor_x(1),
01579         parent_window->get_abs_cursor_y(1),
01580         420,
01581         420)
01582 {
01583         this->parent_window = parent_window;
01584         this->asset = asset;
01585         this->lock_compressor = lock_compressor;
01586         compression_popup = 0;
01587         reset();
01588 }
01589 
01590 MOVConfigVideo::~MOVConfigVideo()
01591 {
01592         if(compression_popup) delete compression_popup;
01593         compression_items.remove_all_objects();
01594 }
01595 
01596 int MOVConfigVideo::create_objects()
01597 {
01598         int x = 10, y = 10;
01599 
01600         if(asset->format == FILE_MOV)
01601         {
01602                 compression_items.append(new BC_ListBoxItem(_(H264_NAME)));
01603                 compression_items.append(new BC_ListBoxItem(_(HV64_NAME)));
01604 //              compression_items.append(new BC_ListBoxItem(_(DIVX_NAME)));
01605                 compression_items.append(new BC_ListBoxItem(_(MP4V_NAME)));
01606                 compression_items.append(new BC_ListBoxItem(_(HV60_NAME)));
01607                 compression_items.append(new BC_ListBoxItem(_(DIV3_NAME)));
01608                 compression_items.append(new BC_ListBoxItem(_(DV_NAME)));
01609                 compression_items.append(new BC_ListBoxItem(_(QTJPEG_NAME)));
01610                 compression_items.append(new BC_ListBoxItem(_(MJPA_NAME)));
01611                 compression_items.append(new BC_ListBoxItem(_(PNG_NAME)));
01612                 compression_items.append(new BC_ListBoxItem(_(PNGA_NAME)));
01613                 compression_items.append(new BC_ListBoxItem(_(RGB_NAME)));
01614                 compression_items.append(new BC_ListBoxItem(_(RGBA_NAME)));
01615                 compression_items.append(new BC_ListBoxItem(_(YUV420_NAME)));
01616                 compression_items.append(new BC_ListBoxItem(_(YUV422_NAME)));
01617                 compression_items.append(new BC_ListBoxItem(_(YUV444_NAME)));
01618                 compression_items.append(new BC_ListBoxItem(_(YUVA4444_NAME)));
01619                 compression_items.append(new BC_ListBoxItem(_(YUV444_10BIT_NAME)));
01620         }
01621         else
01622         {
01623                 compression_items.append(new BC_ListBoxItem(_(H264_NAME)));
01624                 compression_items.append(new BC_ListBoxItem(_(HV64_NAME)));
01625 //              compression_items.append(new BC_ListBoxItem(_(DIVX_NAME)));
01626                 compression_items.append(new BC_ListBoxItem(_(MP4V_NAME)));
01627                 compression_items.append(new BC_ListBoxItem(_(HV60_NAME)));
01628                 compression_items.append(new BC_ListBoxItem(_(DIV3_NAME)));
01629                 compression_items.append(new BC_ListBoxItem(_(DV_NAME)));
01630                 compression_items.append(new BC_ListBoxItem(_(QTJPEG_NAME)));
01631                 compression_items.append(new BC_ListBoxItem(_(MJPA_NAME)));
01632                 compression_items.append(new BC_ListBoxItem(_(PNG_NAME)));
01633         }
01634 
01635         add_subwindow(new BC_Title(x, y, _("Compression:")));
01636         y += 25;
01637 
01638         if(!lock_compressor)
01639         {
01640                 compression_popup = new MOVConfigVideoPopup(this, x, y);
01641                 compression_popup->create_objects();
01642         }
01643         else
01644         {
01645                 add_subwindow(new BC_Title(x, 
01646                         y, 
01647                         FileMOV::compressiontostr(asset->vcodec),
01648                         MEDIUMFONT,
01649                         RED,
01650                         0));
01651         }
01652         y += 40;
01653 
01654         param_x = x;
01655         param_y = y;
01656         update_parameters();
01657 
01658         add_subwindow(new BC_OKButton(this));
01659         return 0;
01660 }
01661 
01662 int MOVConfigVideo::close_event()
01663 {
01664         set_done(0);
01665         return 1;
01666 }
01667 
01668 
01669 void MOVConfigVideo::reset()
01670 {
01671         jpeg_quality = 0;
01672         jpeg_quality_title = 0;
01673 
01674         divx_bitrate = 0;
01675         divx_rc_period = 0;
01676         divx_rc_reaction_ratio = 0;
01677         divx_rc_reaction_period = 0;
01678         divx_max_key_interval = 0;
01679         divx_max_quantizer = 0;
01680         divx_min_quantizer = 0;
01681         divx_quantizer = 0;
01682         divx_quality = 0;
01683         divx_fix_bitrate = 0;
01684         divx_fix_quant = 0;
01685 
01686         h264_bitrate = 0;
01687         h264_quantizer = 0;
01688         h264_fix_bitrate = 0;
01689         h264_fix_quant = 0;
01690 
01691         ms_bitrate = 0;
01692         ms_bitrate_tolerance = 0;
01693         ms_quantization = 0;
01694         ms_interlaced = 0;
01695         ms_gop_size = 0;
01696         ms_fix_bitrate = 0;
01697         ms_fix_quant = 0;
01698 }
01699 
01700 void MOVConfigVideo::update_parameters()
01701 {
01702         if(jpeg_quality)
01703         {
01704                 delete jpeg_quality_title;
01705                 delete jpeg_quality;
01706         }
01707 
01708         if(divx_bitrate) delete divx_bitrate;
01709         if(divx_rc_period) delete divx_rc_period;
01710         if(divx_rc_reaction_ratio) delete divx_rc_reaction_ratio;
01711         if(divx_rc_reaction_period) delete divx_rc_reaction_period;
01712         if(divx_max_key_interval) delete divx_max_key_interval;
01713         if(divx_max_quantizer) delete divx_max_quantizer;
01714         if(divx_min_quantizer) delete divx_min_quantizer;
01715         if(divx_quantizer) delete divx_quantizer;
01716         if(divx_quality) delete divx_quality;
01717         if(divx_fix_quant) delete divx_fix_quant;
01718         if(divx_fix_bitrate) delete divx_fix_bitrate;
01719 
01720         if(ms_bitrate) delete ms_bitrate;
01721         if(ms_bitrate_tolerance) delete ms_bitrate_tolerance;
01722         if(ms_interlaced) delete ms_interlaced;
01723         if(ms_quantization) delete ms_quantization;
01724         if(ms_gop_size) delete ms_gop_size;
01725         if(ms_fix_bitrate) delete ms_fix_bitrate;
01726         if(ms_fix_quant) delete ms_fix_quant;
01727 
01728         delete h264_bitrate;
01729         delete h264_quantizer;
01730         delete h264_fix_bitrate;
01731         delete h264_fix_quant;
01732 
01733         reset();
01734 
01735 
01736 // H264 parameters
01737         if(!strcmp(asset->vcodec, QUICKTIME_H264) ||
01738                 !strcmp(asset->vcodec, QUICKTIME_HV64))
01739         {
01740                 int x = param_x, y = param_y;
01741                 h264_bitrate = new MOVConfigVideoNum(this, 
01742                         _("Bitrate:"), 
01743                         x, 
01744                         y, 
01745                         &asset->h264_bitrate);
01746                 h264_bitrate->set_increment(1000000);
01747                 h264_bitrate->create_objects();
01748                 add_subwindow(h264_fix_bitrate = new MOVConfigVideoFixBitrate(x + 260, 
01749                                 y,
01750                                 &asset->h264_fix_bitrate,
01751                                 1));
01752                 y += 30;
01753                 h264_quantizer = new MOVConfigVideoNum(this, 
01754                         _("Quantization:"), 
01755                         x, 
01756                         y, 
01757                         0,
01758                         51,
01759                         &asset->h264_quantizer);
01760                 h264_quantizer->create_objects();
01761                 add_subwindow(h264_fix_quant = new MOVConfigVideoFixQuant(x + 260, 
01762                                 y,
01763                                 &asset->h264_fix_bitrate,
01764                                 0));
01765                 h264_fix_bitrate->opposite = h264_fix_quant;
01766                 h264_fix_quant->opposite = h264_fix_bitrate;
01767         }
01768         else
01769 // ffmpeg parameters
01770         if(!strcmp(asset->vcodec, QUICKTIME_MP4V) ||
01771                 !strcmp(asset->vcodec, QUICKTIME_DIV3))
01772         {
01773                 int x = param_x, y = param_y;
01774                 ms_bitrate = new MOVConfigVideoNum(this, 
01775                         _("Bitrate:"), 
01776                         x, 
01777                         y, 
01778                         &asset->ms_bitrate);
01779                 ms_bitrate->set_increment(1000000);
01780                 ms_bitrate->create_objects();
01781                 add_subwindow(ms_fix_bitrate = new MOVConfigVideoFixBitrate(x + 260, 
01782                                 y,
01783                                 &asset->ms_fix_bitrate,
01784                                 1));
01785                 y += 30;
01786 
01787                 ms_bitrate_tolerance = new MOVConfigVideoNum(this, 
01788                         _("Bitrate tolerance:"), 
01789                         x, 
01790                         y, 
01791                         &asset->ms_bitrate_tolerance);
01792                 ms_bitrate_tolerance->create_objects();
01793                 y += 30;
01794                 ms_quantization = new MOVConfigVideoNum(this, 
01795                         _("Quantization:"), 
01796                         x, 
01797                         y, 
01798                         &asset->ms_quantization);
01799                 ms_quantization->create_objects();
01800                 add_subwindow(ms_fix_quant = new MOVConfigVideoFixQuant(x + 260, 
01801                                 y,
01802                                 &asset->ms_fix_bitrate,
01803                                 0));
01804                 ms_fix_bitrate->opposite = ms_fix_quant;
01805                 ms_fix_quant->opposite = ms_fix_bitrate;
01806 
01807 
01808                 y += 30;
01809                 add_subwindow(ms_interlaced = new MOVConfigVideoCheckBox(_("Interlaced"), 
01810                         x, 
01811                         y, 
01812                         &asset->ms_interlaced));
01813                 y += 30;
01814                 ms_gop_size = new MOVConfigVideoNum(this, 
01815                         _("Keyframe interval:"), 
01816                         x, 
01817                         y, 
01818                         &asset->ms_gop_size);
01819                 ms_gop_size->create_objects();
01820         }
01821         else
01822 // OpenDivx parameters
01823         if(!strcmp(asset->vcodec, QUICKTIME_DIVX) ||
01824                 !strcmp(asset->vcodec, QUICKTIME_H263) ||
01825                 !strcmp(asset->vcodec, QUICKTIME_HV60))
01826         {
01827                 int x = param_x, y = param_y;
01828                 divx_bitrate = new MOVConfigVideoNum(this, 
01829                         _("Bitrate:"), 
01830                         x, 
01831                         y, 
01832                         &asset->divx_bitrate);
01833                 divx_bitrate->set_increment(1000000);
01834                 divx_bitrate->create_objects();
01835                 add_subwindow(divx_fix_bitrate = 
01836                         new MOVConfigVideoFixBitrate(x + 260, 
01837                                 y,
01838                                 &asset->divx_fix_bitrate,
01839                                 1));
01840                 y += 30;
01841                 divx_quantizer = new MOVConfigVideoNum(this, 
01842                         _("Quantizer:"), 
01843                         x, 
01844                         y, 
01845                         &asset->divx_quantizer);
01846                 divx_quantizer->create_objects();
01847                 add_subwindow(divx_fix_quant =
01848                         new MOVConfigVideoFixQuant(x + 260, 
01849                                 y,
01850                                 &asset->divx_fix_bitrate,
01851                                 0));
01852                 divx_fix_quant->opposite = divx_fix_bitrate;
01853                 divx_fix_bitrate->opposite = divx_fix_quant;
01854                 y += 30;
01855                 divx_rc_period = new MOVConfigVideoNum(this, 
01856                         _("RC Period:"), 
01857                         x, 
01858                         y, 
01859                         &asset->divx_rc_period);
01860                 divx_rc_period->create_objects();
01861                 y += 30;
01862                 divx_rc_reaction_ratio = new MOVConfigVideoNum(this, 
01863                         _("Reaction Ratio:"), 
01864                         x, 
01865                         y, 
01866                         &asset->divx_rc_reaction_ratio);
01867                 divx_rc_reaction_ratio->create_objects();
01868                 y += 30;
01869                 divx_rc_reaction_period = new MOVConfigVideoNum(this, 
01870                         _("Reaction Period:"), 
01871                         x, 
01872                         y, 
01873                         &asset->divx_rc_reaction_period);
01874                 divx_rc_reaction_period->create_objects();
01875                 y += 30;
01876                 divx_max_key_interval = new MOVConfigVideoNum(this, 
01877                         _("Max Key Interval:"), 
01878                         x, 
01879                         y, 
01880                         &asset->divx_max_key_interval);
01881                 divx_max_key_interval->create_objects();
01882                 y += 30;
01883                 divx_max_quantizer = new MOVConfigVideoNum(this, 
01884                         _("Max Quantizer:"), 
01885                         x, 
01886                         y, 
01887                         &asset->divx_max_quantizer);
01888                 divx_max_quantizer->create_objects();
01889                 y += 30;
01890                 divx_min_quantizer = new MOVConfigVideoNum(this, 
01891                         _("Min Quantizer:"), 
01892                         x, 
01893                         y, 
01894                         &asset->divx_min_quantizer);
01895                 divx_min_quantizer->create_objects();
01896                 y += 30;
01897                 divx_quality = new MOVConfigVideoNum(this, 
01898                         _("Quality:"), 
01899                         x, 
01900                         y, 
01901                         &asset->divx_quality);
01902                 divx_quality->create_objects();
01903         }
01904         else
01905         if(!strcmp(asset->vcodec, QUICKTIME_JPEG) ||
01906                 !strcmp(asset->vcodec, QUICKTIME_MJPA))
01907         {
01908                 add_subwindow(jpeg_quality_title = new BC_Title(param_x, param_y, _("Quality:")));
01909                 add_subwindow(jpeg_quality = new BC_ISlider(param_x + 80, 
01910                         param_y,
01911                         0,
01912                         200,
01913                         200,
01914                         0,
01915                         100,
01916                         asset->jpeg_quality,
01917                         0,
01918                         0,
01919                         &asset->jpeg_quality));
01920         }
01921 }
01922 
01923 
01924 
01925 
01926 
01927 MOVConfigVideoNum::MOVConfigVideoNum(MOVConfigVideo *popup, char *title_text, int x, int y, int *output)
01928  : BC_TumbleTextBox(popup, 
01929                 (int64_t)*output,
01930                 (int64_t)1,
01931                 (int64_t)25000000,
01932                 x + 130, 
01933                 y, 
01934                 100)
01935 {
01936         this->popup = popup;
01937         this->title_text = title_text;
01938         this->output = output;
01939         this->x = x;
01940         this->y = y;
01941 }
01942 
01943 MOVConfigVideoNum::MOVConfigVideoNum(MOVConfigVideo *popup, 
01944         char *title_text, 
01945         int x, 
01946         int y, 
01947         int min,
01948         int max,
01949         int *output)
01950  : BC_TumbleTextBox(popup, 
01951                 (int64_t)*output,
01952                 (int64_t)min,
01953                 (int64_t)max,
01954                 x + 130, 
01955                 y, 
01956                 100)
01957 {
01958         this->popup = popup;
01959         this->title_text = title_text;
01960         this->output = output;
01961         this->x = x;
01962         this->y = y;
01963 }
01964 
01965 MOVConfigVideoNum::~MOVConfigVideoNum()
01966 {
01967         if(!popup->get_deleting()) delete title;
01968 }
01969 
01970 void MOVConfigVideoNum::create_objects()
01971 {
01972         popup->add_subwindow(title = new BC_Title(x, y, title_text));
01973         BC_TumbleTextBox::create_objects();
01974 }
01975 
01976 int MOVConfigVideoNum::handle_event()
01977 {
01978         *output = atol(get_text());
01979         return 1;
01980 }
01981 
01982 
01983 
01984 
01985 
01986 
01987 
01988 MOVConfigVideoCheckBox::MOVConfigVideoCheckBox(char *title_text, int x, int y, int *output)
01989  : BC_CheckBox(x, y, *output, title_text)
01990 {
01991         this->output = output;
01992 }
01993 
01994 int MOVConfigVideoCheckBox::handle_event()
01995 {
01996         *output = get_value();
01997         return 1;
01998 }
01999 
02000 
02001 
02002 
02003 
02004 
02005 MOVConfigVideoFixBitrate::MOVConfigVideoFixBitrate(int x, 
02006         int y,
02007         int *output,
02008         int value)
02009  : BC_Radial(x, 
02010         y, 
02011         *output == value, 
02012         _("Fix bitrate"))
02013 {
02014         this->output = output;
02015         this->value = value;
02016 }
02017 
02018 int MOVConfigVideoFixBitrate::handle_event()
02019 {
02020         *output = value;
02021         opposite->update(0);
02022         return 1;
02023 }
02024 
02025 
02026 
02027 
02028 
02029 
02030 MOVConfigVideoFixQuant::MOVConfigVideoFixQuant(int x, 
02031         int y,
02032         int *output,
02033         int value)
02034  : BC_Radial(x, 
02035         y, 
02036         *output == value, 
02037         _("Fix quantization"))
02038 {
02039         this->output = output;
02040         this->value = value;
02041 }
02042 
02043 int MOVConfigVideoFixQuant::handle_event()
02044 {
02045         *output = value;
02046         opposite->update(0);
02047         return 1;
02048 }
02049 
02050 
02051 
02052 
02053 
02054 MOVConfigVideoPopup::MOVConfigVideoPopup(MOVConfigVideo *popup, int x, int y)
02055  : BC_PopupTextBox(popup, 
02056                 &popup->compression_items,
02057                 FileMOV::compressiontostr(popup->asset->vcodec),
02058                 x, 
02059                 y, 
02060                 300,
02061                 300)
02062 {
02063         this->popup = popup;
02064 }
02065 
02066 int MOVConfigVideoPopup::handle_event()
02067 {
02068         strcpy(popup->asset->vcodec, FileMOV::strtocompression(get_text()));
02069         popup->update_parameters();
02070         return 1;
02071 }
02072 
02073 
02074 
02075 
02076 
02077 
02078 
02079 
02080 

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