port 7.2 mods: align_edits foreground plugin refresh_frame tweak, rework soundlevel...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / bdcreate.C
1 #include "asset.h"
2 #include "bchash.h"
3 #include "bdcreate.h"
4 #include "clip.h"
5 #include "edl.h"
6 #include "edit.h"
7 #include "edits.h"
8 #include "edlsession.h"
9 #include "file.h"
10 #include "filexml.h"
11 #include "interlacemodes.h"
12 #include "keyframe.h"
13 #include "mainerror.h"
14 #include "mainundo.h"
15 #include "mwindow.h"
16 #include "mwindowgui.h"
17 #include "plugin.h"
18 #include "pluginset.h"
19 #include "preferences.h"
20 #include "rescale.h"
21 #include "track.h"
22 #include "tracks.h"
23
24 #include <unistd.h>
25 #include <fcntl.h>
26 #include <errno.h>
27 #include <sys/stat.h>
28 #include <sys/statfs.h>
29
30 // BD Creation
31
32 // selected by timezone
33 #define BD_1920x1080_2997i      0
34 #define BD_1920x1080_25i        3
35
36 static struct bd_format {
37         const char *name;
38         int w, h;
39         double framerate;
40         int wide, interlaced;
41 } bd_formats[] = {
42 // framerates are frames, not fields, per second, *=not standard
43         { "1920x1080 29.97i",   1920,1080, 29.97,  1, ILACE_MODE_TOP_FIRST },
44         { "1920x1080 29.97p*",  1920,1080, 29.97,  1, ILACE_MODE_FAKE_INTERLACE },
45         { "1920x1080 24p",      1920,1080, 24.,    1, ILACE_MODE_NOTINTERLACED },
46         { "1920x1080 25i",      1920,1080, 25.,    1, ILACE_MODE_TOP_FIRST },
47         { "1920x1080 25p*",     1920,1080, 25.,    1, ILACE_MODE_FAKE_INTERLACE },
48         { "1920x1080 23.976p",  1920,1080, 23.976, 1, ILACE_MODE_NOTINTERLACED },
49         { "1440x1080 29.97i",   1440,1080, 29.97, -1, ILACE_MODE_TOP_FIRST },
50         { "1440x1080 25i",      1440,1080, 25.,   -1, ILACE_MODE_TOP_FIRST },
51         { "1440x1080 24p",      1440,1080, 24.,   -1, ILACE_MODE_NOTINTERLACED },
52         { "1440x1080 23.976p",  1440,1080, 23.976,-1, ILACE_MODE_NOTINTERLACED },
53         { "1280x720  59.94p",   1280,720,  59.94,  1, ILACE_MODE_NOTINTERLACED },
54         { "1280x720  50p",      1280,720,  50.,    1, ILACE_MODE_NOTINTERLACED },
55         { "1280x720  29.97p*",  1280,720,  29.97,  1, ILACE_MODE_NOTINTERLACED },
56         { "1280x720  25p*",     1280,720,  25.,    1, ILACE_MODE_NOTINTERLACED },
57         { "1280x720  24p",      1280,720,  24.,    1, ILACE_MODE_NOTINTERLACED },
58         { "1280x720  23.976p",  1280,720,  23.976, 1, ILACE_MODE_NOTINTERLACED },
59         { "720x576   25i",       720,576,  25.,    0, ILACE_MODE_BOTTOM_FIRST },
60         { "720x576   25p*",      720,576,  25.,    0, ILACE_MODE_NOTINTERLACED },
61         { "720x480   29.97i",    720,480,  29.97,  0, ILACE_MODE_BOTTOM_FIRST },
62         { "720x480   29.97p*",   720,480,  29.97,  0, ILACE_MODE_NOTINTERLACED },
63 };
64
65 const int64_t CreateBD_Thread::BD_SIZE = 25000000000;
66 const int CreateBD_Thread::BD_STREAMS = 1;
67 const int CreateBD_Thread::BD_WIDTH = 1920;
68 const int CreateBD_Thread::BD_HEIGHT = 1080;
69 const double CreateBD_Thread::BD_WIDE_ASPECT_WIDTH = 16.;
70 const double CreateBD_Thread::BD_WIDE_ASPECT_HEIGHT = 9.;
71 const double CreateBD_Thread::BD_ASPECT_WIDTH = 4.;
72 const double CreateBD_Thread::BD_ASPECT_HEIGHT = 3.;
73 const double CreateBD_Thread::BD_FRAMERATE = 24000. / 1001.;
74 //const int CreateBD_Thread::BD_MAX_BITRATE = 40000000;
75 const int CreateBD_Thread::BD_MAX_BITRATE = 10000000;
76 const int CreateBD_Thread::BD_CHANNELS = 2;
77 const int CreateBD_Thread::BD_WIDE_CHANNELS = 6;
78 const double CreateBD_Thread::BD_SAMPLERATE = 48000;
79 const double CreateBD_Thread::BD_KAUDIO_RATE = 192;
80 const int CreateBD_Thread::BD_INTERLACE_MODE = ILACE_MODE_NOTINTERLACED;
81
82 CreateBD_MenuItem::CreateBD_MenuItem(MWindow *mwindow)
83  : BC_MenuItem(_("BD Render..."), _("Ctrl-d"), 'd')
84 {
85         set_ctrl(1);
86         this->mwindow = mwindow;
87 }
88
89 int CreateBD_MenuItem::handle_event()
90 {
91         mwindow->create_bd->start();
92         return 1;
93 }
94
95 BD_BatchRenderJob::BD_BatchRenderJob(Preferences *preferences, int labeled, int farmed)
96  : BatchRenderJob("BD_JOB", preferences, labeled, farmed)
97 {
98 }
99
100 int BD_BatchRenderJob::get_udfs_mount(char *udfs, char *mopts, char *mntpt)
101 {
102         int ret = 0;
103 // default: mount -t udf -o loop $dir/bd.udfs $dir/udfs
104         strcpy(udfs,"$dir/bd.udfs");
105         strcpy(mopts,"-t udf -o loop $dir/bd.udfs ");
106         strcpy(mntpt,"$dir/udfs");
107         const char *home = getenv("HOME");
108         if( !home ) return ret;
109         FILE *fp = fopen("/etc/fstab","r");
110         if( !fp ) return ret;
111         int len = strlen(home);
112         char line[BCTEXTLEN], typ[BCTEXTLEN], file[BCTEXTLEN];
113         char mpnt[BCTEXTLEN], opts[BCTEXTLEN];
114         while( fgets(line,sizeof(line),fp) ) {
115 // search "/etc/fstab" for: $HOME/img_file $HOME/bluray udf noauto,loop,rw,user
116                 if( line[0] == '#' || line[0] == ';' ) continue;
117                 if( sscanf(line,"%s %s %s %s ", &file[0], &mpnt[0], &typ[0], &opts[0]) != 4 )
118                         continue;
119                 if( strcmp("udf", typ) ) continue;
120                 if( strncmp(home, file, len) || file[len] != '/' ) continue;
121                 if( strncmp(home, mpnt, len) ) continue;
122                 if( strcmp(&mpnt[len], "/bluray") ) continue;
123                 int loop = 0, user = 0, rw = 0, noauto = 0;
124                 char *op = opts, *ep = op + sizeof(opts)-1;
125                 while( op < ep && *op ) {
126                         char opt[BCTEXTLEN], *cp = opt;
127                         while( op < ep && *op && (*cp=*op++)!=',' ) ++cp;
128                         *cp = 0;
129                         if( !strcmp("loop", opt) ) loop = 1;
130                         else if( !strcmp("user", opt) ) user = 1;
131                         else if( !strcmp("noauto", opt) ) noauto = 1;
132                         else if( !strcmp("rw", opt) ) rw = 1;
133                 }
134                 if( loop && user && rw && noauto ) {
135                         strcpy(udfs, file);
136                         strcpy(mopts, "");
137                         strcpy(mntpt, mpnt);
138                         ret = 1;
139                         break;
140                 }
141         }
142         fclose(fp);
143         return ret;
144 }
145
146 char *BD_BatchRenderJob::create_script(EDL *edl, ArrayList<Indexable *> *idxbls)
147 {
148         char script[BCTEXTLEN];
149         strcpy(script, edl_path);
150         FILE *fp = 0;
151         char *bp = strrchr(script,'/');
152         int fd = -1;
153         if( bp ) {
154                 strcpy(bp, "/bd.sh");
155                 fd = open(script, O_WRONLY+O_CREAT+O_TRUNC, 0755);
156         }
157         if( fd >= 0 )
158                 fp = fdopen(fd, "w");
159         if( !fp ) {
160                 char err[BCTEXTLEN], msg[BCTEXTLEN];
161                 strerror_r(errno, err, sizeof(err));
162                 sprintf(msg, _("Unable to save: %s\n-- %s"), script, err);
163                 MainError::show_error(msg);
164                 return 0;
165         }
166         char udfs[BCTEXTLEN], mopts[BCTEXTLEN], mntpt[BCTEXTLEN];
167         int is_usr_mnt = get_udfs_mount(udfs, mopts, mntpt);
168         const char *exec_path = File::get_cinlib_path();
169         fprintf(fp,"#!/bin/bash -ex\n");
170         fprintf(fp,"sdir=`dirname $0`\n");
171         fprintf(fp,"dir=`cd \"$sdir\"; pwd`\n");
172         fprintf(fp,"PATH=$PATH:%s\n",exec_path);
173         fprintf(fp,"mkdir -p $dir/udfs\n");
174         fprintf(fp,"sz=`du -cb $dir/bd.m2ts* | tail -1 | sed -e 's/[ \t].*//'`\n");
175         fprintf(fp,"blks=$((sz/2048 + 4096))\n");
176         fprintf(fp,"rm -f %s\n", udfs);
177         fprintf(fp,"mkudffs -b 2048 %s $blks\n", udfs);
178         fprintf(fp,"mount %s%s\n", mopts, mntpt);
179         fprintf(fp,"bdwrite %s $dir/bd.m2ts*\n",mntpt);
180         fprintf(fp,"umount %s\n",mntpt);
181         if( is_usr_mnt )
182                 fprintf(fp,"mv -f %s $dir/bd.udfs\n", udfs);
183         fprintf(fp,"echo To burn bluray, load writable media and run:\n");
184         fprintf(fp,"echo for WORM: growisofs -dvd-compat -Z /dev/bd=$dir/bd.udfs\n");
185         fprintf(fp,"echo for RW:   dd if=$dir/bd.udfs of=/dev/bd bs=2048000\n");
186         fprintf(fp,"kill $$\n");
187         fprintf(fp,"\n");
188         fclose(fp);
189         return cstrdup(script);
190 }
191
192
193 CreateBD_Thread::CreateBD_Thread(MWindow *mwindow)
194  : BC_DialogThread()
195 {
196         this->mwindow = mwindow;
197         this->gui = 0;
198         this->use_deinterlace = 0;
199         this->use_scale = Rescale::none;
200         this->use_histogram = 0;
201         this->use_inverse_telecine = 0;
202         this->use_wide_audio = 0;
203         this->use_resize_tracks = 0;
204         this->use_labeled = 0;
205         this->use_farmed = 0;
206
207         this->bd_size = BD_SIZE;
208         this->bd_width = BD_WIDTH;
209         this->bd_height = BD_HEIGHT;
210         this->bd_aspect_width = BD_WIDE_ASPECT_WIDTH;
211         this->bd_aspect_height = BD_WIDE_ASPECT_HEIGHT;
212         this->bd_framerate = BD_FRAMERATE;
213         this->bd_samplerate = BD_SAMPLERATE;
214         this->bd_max_bitrate = BD_MAX_BITRATE;
215         this->bd_kaudio_rate = BD_KAUDIO_RATE;
216         this->max_w = this->max_h = 0;
217 }
218
219 CreateBD_Thread::~CreateBD_Thread()
220 {
221         close_window();
222 }
223
224 int CreateBD_Thread::create_bd_jobs(ArrayList<BatchRenderJob*> *jobs, const char *asset_dir)
225 {
226         EDL *edl = mwindow->edl;
227         if( !edl || !edl->session ) {
228                 char msg[BCTEXTLEN];
229                 sprintf(msg, _("No EDL/Session"));
230                 MainError::show_error(msg);
231                 return 1;
232         }
233         EDLSession *session = edl->session;
234
235         double total_length = edl->tracks->total_length();
236         if( total_length <= 0 ) {
237                 char msg[BCTEXTLEN];
238                 sprintf(msg, _("No content: %s"), asset_title);
239                 MainError::show_error(msg);
240                 return 1;
241         }
242
243         if( mkdir(asset_dir, 0777) ) {
244                 char err[BCTEXTLEN], msg[BCTEXTLEN];
245                 strerror_r(errno, err, sizeof(err));
246                 sprintf(msg, _("Unable to create directory: %s\n-- %s"), asset_dir, err);
247                 MainError::show_error(msg);
248                 return 1;
249         }
250
251         double old_samplerate = session->sample_rate;
252         double old_framerate = session->frame_rate;
253
254         session->video_channels = BD_STREAMS;
255         session->video_tracks = BD_STREAMS;
256         session->frame_rate = bd_framerate;
257         session->output_w = bd_width;
258         session->output_h = bd_height;
259         session->aspect_w = bd_aspect_width;
260         session->aspect_h = bd_aspect_height;
261         session->sample_rate = bd_samplerate;
262         session->audio_channels = session->audio_tracks =
263                 use_wide_audio ? BD_WIDE_CHANNELS : BD_CHANNELS;
264         session->interlace_mode = bd_interlace_mode;
265
266         session->audio_channels = session->audio_tracks =
267                 !use_wide_audio ? BD_CHANNELS : BD_WIDE_CHANNELS;
268         for( int i=0; i<MAX_CHANNELS; ++i )
269                 session->achannel_positions[i] = default_audio_channel_position(i, session->audio_channels);
270         int audio_mapping = edl->tracks->recordable_audio_tracks() == BD_WIDE_CHANNELS &&
271                 !use_wide_audio ? MWindow::AUDIO_5_1_TO_2 : MWindow::AUDIO_1_TO_1;
272         mwindow->remap_audio(audio_mapping);
273
274         double new_samplerate = session->sample_rate;
275         double new_framerate = session->frame_rate;
276         edl->retrack();
277         edl->rechannel();
278         edl->resample(old_samplerate, new_samplerate, TRACK_AUDIO);
279         edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
280
281         int64_t aud_size = ((bd_kaudio_rate * total_length)/8 + 1000-1) * 1000;
282         int64_t vid_size = bd_size*0.96 - aud_size;
283         int64_t vid_bitrate = (vid_size * 8) / total_length;
284         vid_bitrate /= 1000;  vid_bitrate *= 1000;
285         if( vid_bitrate > bd_max_bitrate ) vid_bitrate = bd_max_bitrate;
286
287         char xml_filename[BCTEXTLEN];
288         sprintf(xml_filename, "%s/bd.xml", asset_dir);
289         FileXML xml_file;
290         edl->save_xml(&xml_file, xml_filename);
291         xml_file.terminate_string();
292         if( xml_file.write_to_file(xml_filename) ) {
293                 char msg[BCTEXTLEN];
294                 sprintf(msg, _("Unable to save: %s"), xml_filename);
295                 MainError::show_error(msg);
296                 return 1;
297         }
298
299         BatchRenderJob *job = new BD_BatchRenderJob(mwindow->preferences,
300                 use_labeled, use_farmed);
301         jobs->append(job);
302         strcpy(&job->edl_path[0], xml_filename);
303         Asset *asset = job->asset;
304
305         asset->layers = BD_STREAMS;
306         asset->frame_rate = session->frame_rate;
307         asset->width = session->output_w;
308         asset->height = session->output_h;
309         asset->aspect_ratio = session->aspect_w / session->aspect_h;
310         asset->interlace_mode = session->interlace_mode;
311
312         char option_path[BCTEXTLEN];
313         sprintf(&asset->path[0],"%s/bd.m2ts", asset_dir);
314         asset->format = FILE_FFMPEG;
315         strcpy(asset->fformat, "m2ts");
316
317         asset->audio_data = 1;
318         strcpy(asset->acodec, "bluray.m2ts");
319         //mwindow->defaults->get("DEFAULT_BLURAY_ACODEC", asset->acodec);
320         FFMPEG::set_option_path(option_path, "audio/%s", asset->acodec);
321         FFMPEG::load_options(option_path, asset->ff_audio_options,
322                          sizeof(asset->ff_audio_options));
323         asset->ff_audio_bitrate = bd_kaudio_rate * 1000;
324
325         asset->video_data = 1;
326         const char *vcodec = "bluray.m2ts";
327         switch( asset->interlace_mode ) {
328         case ILACE_MODE_TOP_FIRST:    vcodec = "bluray_tff.m2ts";  break;
329         case ILACE_MODE_BOTTOM_FIRST: vcodec = "bluray_bff.m2ts";  break;
330         case ILACE_MODE_FAKE_INTERLACE : vcodec = "bluray_fakeinterlace.m2ts";  break;
331         }
332         strcpy(asset->vcodec, vcodec);
333         //mwindow->defaults->get("DEFAULT_BLURAY_VCODEC", asset->vcodec);
334         FFMPEG::set_option_path(option_path, "video/%s", asset->vcodec);
335         FFMPEG::load_options(option_path, asset->ff_video_options,
336                  sizeof(asset->ff_video_options));
337         asset->ff_video_bitrate = vid_bitrate;
338         asset->ff_video_quality = -1;
339         return 0;
340 }
341
342 void CreateBD_Thread::handle_close_event(int result)
343 {
344         if( result ) return;
345         mwindow->defaults->update("WORK_DIRECTORY", tmp_path);
346         mwindow->batch_render->load_defaults(mwindow->defaults);
347         mwindow->undo->update_undo_before();
348         KeyFrame keyframe;  char data[BCTEXTLEN];
349         if( use_deinterlace ) {
350                 sprintf(data,"<DEINTERLACE MODE=1>");
351                 keyframe.set_data(data);
352                 insert_video_plugin("Deinterlace", &keyframe);
353         }
354         if( use_inverse_telecine ) {
355                 sprintf(data,"<IVTC FRAME_OFFSET=0 FIRST_FIELD=0 "
356                         "AUTOMATIC=1 AUTO_THRESHOLD=2.0e+00 PATTERN=2>");
357                 keyframe.set_data(data);
358                 insert_video_plugin("Inverse Telecine", &keyframe);
359         }
360         if( use_scale != Rescale::none ) {
361                 double bd_aspect = bd_aspect_height > 0 ? bd_aspect_width / bd_aspect_height : 1;
362
363                 Tracks *tracks = mwindow->edl->tracks;
364                 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
365                         if( vtrk->data_type != TRACK_VIDEO ) continue;
366                         if( !vtrk->record ) continue;
367                         vtrk->expand_view = 1;
368                         PluginSet *plugin_set = new PluginSet(mwindow->edl, vtrk);
369                         vtrk->plugin_set.append(plugin_set);
370                         Edits *edits = vtrk->edits;
371                         for( Edit *edit=edits->first; edit; edit=edit->next ) {
372                                 Indexable *indexable = edit->get_source();
373                                 if( !indexable ) continue;
374                                 Rescale in(indexable);
375                                 Rescale out(bd_width, bd_height, bd_aspect);
376                                 float src_w, src_h, dst_w, dst_h;
377                                 in.rescale(out,use_scale, src_w,src_h, dst_w,dst_h);
378                                 sprintf(data,"<SCALERATIO TYPE=%d"
379                                         " IN_W=%d IN_H=%d IN_ASPECT_RATIO=%f"
380                                         " OUT_W=%d OUT_H=%d OUT_ASPECT_RATIO=%f"
381                                         " SRC_X=%f SRC_Y=%f SRC_W=%f SRC_H=%f"
382                                         " DST_X=%f DST_Y=%f DST_W=%f DST_H=%f>", use_scale,
383                                         in.w, in.h, in.aspect, out.w, out.h, out.aspect,
384                                         0., 0., src_w, src_h, 0., 0., dst_w, dst_h);
385                                 keyframe.set_data(data);
386                                 plugin_set->insert_plugin(_("Scale Ratio"),
387                                         edit->startproject, edit->length,
388                                         PLUGIN_STANDALONE, 0, &keyframe, 0);
389                         }
390                         vtrk->optimize();
391                 }
392         }
393         if( use_resize_tracks )
394                 resize_tracks();
395         if( use_histogram ) {
396 #if 0
397                 sprintf(data, "<HISTOGRAM OUTPUT_MIN_0=0 OUTPUT_MAX_0=1 "
398                         "OUTPUT_MIN_1=0 OUTPUT_MAX_1=1 "
399                         "OUTPUT_MIN_2=0 OUTPUT_MAX_2=1 "
400                         "OUTPUT_MIN_3=0 OUTPUT_MAX_3=1 "
401                         "AUTOMATIC=0 THRESHOLD=9.0-01 PLOT=0 SPLIT=0>"
402                         "<POINTS></POINTS><POINTS></POINTS><POINTS></POINTS>"
403                         "<POINTS><POINT X=6.0e-02 Y=0>"
404                                 "<POINT X=9.4e-01 Y=1></POINTS>");
405 #else
406                 sprintf(data, "<HISTOGRAM AUTOMATIC=0 THRESHOLD=1.0e-01 "
407                         "PLOT=0 SPLIT=0 W=440 H=500 PARADE=0 MODE=3 "
408                         "LOW_OUTPUT_0=0 HIGH_OUTPUT_0=1 LOW_INPUT_0=0 HIGH_INPUT_0=1 GAMMA_0=1 "
409                         "LOW_OUTPUT_1=0 HIGH_OUTPUT_1=1 LOW_INPUT_1=0 HIGH_INPUT_1=1 GAMMA_1=1 "
410                         "LOW_OUTPUT_2=0 HIGH_OUTPUT_2=1 LOW_INPUT_2=0 HIGH_INPUT_2=1 GAMMA_2=1 "
411                         "LOW_OUTPUT_3=0 HIGH_OUTPUT_3=1 LOW_INPUT_3=0.044 HIGH_INPUT_3=0.956 "
412                         "GAMMA_3=1>");
413 #endif
414                 keyframe.set_data(data);
415                 insert_video_plugin("Histogram", &keyframe);
416         }
417
418         char asset_dir[BCTEXTLEN], jobs_path[BCTEXTLEN];
419         snprintf(asset_dir, sizeof(asset_dir), "%s/%s", tmp_path, asset_title);
420         snprintf(jobs_path, sizeof(jobs_path), "%s/bd.jobs", asset_dir);
421         mwindow->batch_render->reset(jobs_path);
422         int ret = create_bd_jobs(&mwindow->batch_render->jobs, asset_dir);
423         mwindow->undo->update_undo_after(_("create bd"), LOAD_ALL);
424         mwindow->resync_guis();
425         if( ret ) return;
426         mwindow->batch_render->save_jobs();
427         mwindow->batch_render->start(-use_farmed, -use_labeled);
428 }
429
430 BC_Window* CreateBD_Thread::new_gui()
431 {
432         strcpy(tmp_path, "/tmp");
433         mwindow->defaults->get("WORK_DIRECTORY", tmp_path);
434         memset(asset_title,0,sizeof(asset_title));
435         time_t dt;      time(&dt);
436         struct tm dtm;  localtime_r(&dt, &dtm);
437         sprintf(asset_title, "bd_%02d%02d%02d-%02d%02d%02d",
438                 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
439                 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
440         use_deinterlace = 0;
441         use_scale = Rescale::none;
442         use_histogram = 0;
443         use_inverse_telecine = 0;
444         use_wide_audio = 0;
445         use_resize_tracks = 0;
446         use_labeled = 0;
447         use_farmed = 0;
448         use_standard = !strcmp(mwindow->default_std(),"NTSC") ?
449                  BD_1920x1080_2997i : BD_1920x1080_25i;
450         bd_size = BD_SIZE;
451         bd_width = BD_WIDTH;
452         bd_height = BD_HEIGHT;
453         bd_aspect_width = BD_WIDE_ASPECT_WIDTH;
454         bd_aspect_height = BD_WIDE_ASPECT_HEIGHT;
455         bd_framerate = BD_FRAMERATE;
456         bd_samplerate = BD_SAMPLERATE;
457         bd_max_bitrate = BD_MAX_BITRATE;
458         bd_kaudio_rate = BD_KAUDIO_RATE;
459         bd_interlace_mode = BD_INTERLACE_MODE;
460         max_w = 0; max_h = 0;
461
462         int has_standard = -1;
463         if( mwindow->edl ) {
464                 EDLSession *session = mwindow->edl->session;
465 // match the session to any known standard
466                 for( int i=0; i<(int)(sizeof(bd_formats)/sizeof(bd_formats[0])); ++i ) {
467                         if( !EQUIV(session->frame_rate, bd_formats[i].framerate) ) continue;
468                         if( session->output_w != bd_formats[i].w ) continue;
469                         if( session->output_h != bd_formats[i].h ) continue;
470                         has_standard = i;  break;
471                 }
472         }
473         if( has_standard >= 0 )
474                 use_standard = has_standard;
475
476         option_presets();
477         int scr_x = mwindow->gui->get_screen_x(0, -1);
478         int scr_w = mwindow->gui->get_screen_w(0, -1);
479         int scr_h = mwindow->gui->get_screen_h(0, -1);
480         int w = xS(560), h = yS(290);
481         int x = scr_x + scr_w/2 - w/2, y = scr_h/2 - h/2;
482
483         gui = new CreateBD_GUI(this, x, y, w, h);
484         gui->create_objects();
485
486         if( getuid() != 0 ) {
487                 mwindow->show_warning(
488                         &mwindow->preferences->bd_warn_root,
489                         _("Must be root to mount UDFS images\n"));
490         }
491         return gui;
492 }
493
494
495 CreateBD_OK::CreateBD_OK(CreateBD_GUI *gui, int x, int y)
496  : BC_OKButton(x, y)
497 {
498         this->gui = gui;
499         set_tooltip(_("end setup, start batch render"));
500 }
501
502 CreateBD_OK::~CreateBD_OK()
503 {
504 }
505
506 int CreateBD_OK::button_press_event()
507 {
508         if(get_buttonpress() == 1 && is_event_win() && cursor_inside()) {
509                 gui->set_done(0);
510                 return 1;
511         }
512         return 0;
513 }
514
515 int CreateBD_OK::keypress_event()
516 {
517         return 0;
518 }
519
520
521 CreateBD_Cancel::CreateBD_Cancel(CreateBD_GUI *gui, int x, int y)
522  : BC_CancelButton(x, y)
523 {
524         this->gui = gui;
525 }
526
527 CreateBD_Cancel::~CreateBD_Cancel()
528 {
529 }
530
531 int CreateBD_Cancel::button_press_event()
532 {
533         if(get_buttonpress() == 1 && is_event_win() && cursor_inside()) {
534                 gui->set_done(1);
535                 return 1;
536         }
537         return 0;
538 }
539
540
541 CreateBD_DiskSpace::CreateBD_DiskSpace(CreateBD_GUI *gui, int x, int y)
542  : BC_Title(x, y, "", MEDIUMFONT, GREEN)
543 {
544         this->gui = gui;
545 }
546
547 CreateBD_DiskSpace::~CreateBD_DiskSpace()
548 {
549 }
550
551 int64_t CreateBD_DiskSpace::tmp_path_space()
552 {
553         const char *path = gui->thread->tmp_path;
554         if( access(path,R_OK+W_OK) ) return 0;
555         struct statfs sfs;
556         if( statfs(path, &sfs) ) return 0;
557         return (int64_t)sfs.f_bsize * sfs.f_bfree;
558 }
559
560 void CreateBD_DiskSpace::update()
561 {
562         static const char *suffix[] = { "", "KB", "MB", "GB", "TB", "PB" };
563         int64_t disk_space = tmp_path_space();
564         double media_size = 100e9, msz = 0, m = 1;
565         char sfx[BCSTRLEN];
566         if( sscanf(gui->media_size->get_text(), "%lf%s", &msz, sfx) == 2 ) {
567                 int i = sizeof(suffix)/sizeof(suffix[0]);
568                 while( --i >= 0 && strcmp(sfx, suffix[i]) );
569                 while( --i >= 0 ) m *= 1000;
570                 media_size = msz * m;
571         }
572         int color = disk_space < media_size*2 ? RED : GREEN;
573         int i = 0;
574         for( int64_t space=disk_space; i<5 && (space/=1000)>0; disk_space=space, ++i );
575         char text[BCTEXTLEN];
576         sprintf(text, "%s%3jd%s", _("disk space: "), disk_space, suffix[i]);
577         gui->disk_space->BC_Title::update(text);
578         gui->disk_space->set_color(color);
579 }
580
581 CreateBD_TmpPath::CreateBD_TmpPath(CreateBD_GUI *gui, int x, int y, int w)
582  : BC_TextBox(x, y, w, 1, -(int)sizeof(gui->thread->tmp_path),
583                 gui->thread->tmp_path, 1, MEDIUMFONT)
584 {
585         this->gui = gui;
586 }
587
588 CreateBD_TmpPath::~CreateBD_TmpPath()
589 {
590 }
591
592 int CreateBD_TmpPath::handle_event()
593 {
594         get_text();
595         gui->disk_space->update();
596         return 1;
597 }
598
599
600 CreateBD_AssetTitle::CreateBD_AssetTitle(CreateBD_GUI *gui, int x, int y, int w)
601  : BC_TextBox(x, y, w, 1, -(int)sizeof(gui->thread->asset_title),
602                 gui->thread->asset_title, 1, MEDIUMFONT)
603 {
604         this->gui = gui;
605 }
606
607 CreateBD_AssetTitle::~CreateBD_AssetTitle()
608 {
609 }
610
611 int CreateBD_AssetTitle::handle_event()
612 {
613         get_text();
614         return 1;
615 }
616
617 CreateBD_Deinterlace::CreateBD_Deinterlace(CreateBD_GUI *gui, int x, int y)
618  : BC_CheckBox(x, y, &gui->thread->use_deinterlace, _("Deinterlace"))
619 {
620         this->gui = gui;
621 }
622
623 CreateBD_Deinterlace::~CreateBD_Deinterlace()
624 {
625 }
626
627 int CreateBD_Deinterlace::handle_event()
628 {
629         if( get_value() ) {
630                 gui->need_inverse_telecine->set_value(0);
631                 gui->thread->use_inverse_telecine = 0;
632         }
633         return BC_CheckBox::handle_event();
634 }
635
636
637 CreateBD_InverseTelecine::CreateBD_InverseTelecine(CreateBD_GUI *gui, int x, int y)
638  : BC_CheckBox(x, y, &gui->thread->use_inverse_telecine, _("Inverse Telecine"))
639 {
640         this->gui = gui;
641 }
642
643 CreateBD_InverseTelecine::~CreateBD_InverseTelecine()
644 {
645 }
646
647 int CreateBD_InverseTelecine::handle_event()
648 {
649         if( get_value() ) {
650                 gui->need_deinterlace->set_value(0);
651                 gui->thread->use_deinterlace = 0;
652         }
653         return BC_CheckBox::handle_event();
654 }
655
656
657 CreateBD_ResizeTracks::CreateBD_ResizeTracks(CreateBD_GUI *gui, int x, int y)
658  : BC_CheckBox(x, y, &gui->thread->use_resize_tracks, _("Resize Tracks"))
659 {
660         this->gui = gui;
661 }
662
663 CreateBD_ResizeTracks::~CreateBD_ResizeTracks()
664 {
665 }
666
667
668 CreateBD_Histogram::CreateBD_Histogram(CreateBD_GUI *gui, int x, int y)
669  : BC_CheckBox(x, y, &gui->thread->use_histogram, _("Histogram"))
670 {
671         this->gui = gui;
672 }
673
674 CreateBD_Histogram::~CreateBD_Histogram()
675 {
676 }
677
678 CreateBD_LabelChapters::CreateBD_LabelChapters(CreateBD_GUI *gui, int x, int y)
679  : BC_CheckBox(x, y, &gui->thread->use_labeled, _("Chapters at Labels"))
680 {
681         this->gui = gui;
682 }
683
684 CreateBD_LabelChapters::~CreateBD_LabelChapters()
685 {
686 }
687
688 CreateBD_UseRenderFarm::CreateBD_UseRenderFarm(CreateBD_GUI *gui, int x, int y)
689  : BC_CheckBox(x, y, &gui->thread->use_farmed, _("Use render farm"))
690 {
691         this->gui = gui;
692 }
693
694 CreateBD_UseRenderFarm::~CreateBD_UseRenderFarm()
695 {
696 }
697
698
699 CreateBD_WideAudio::CreateBD_WideAudio(CreateBD_GUI *gui, int x, int y)
700  : BC_CheckBox(x, y, &gui->thread->use_wide_audio, _("Audio 5.1"))
701 {
702         this->gui = gui;
703 }
704
705 CreateBD_WideAudio::~CreateBD_WideAudio()
706 {
707 }
708
709
710 CreateBD_GUI::CreateBD_GUI(CreateBD_Thread *thread, int x, int y, int w, int h)
711  : BC_Window(_(PROGRAM_NAME ": Create BD"), x, y, w, h, xS(50), yS(50), 1, 0, 1)
712 {
713         this->thread = thread;
714         at_x = at_y = tmp_x = tmp_y = 0;
715         ok_x = ok_y = ok_w = ok_h = 0;
716         cancel_x = cancel_y = cancel_w = cancel_h = 0;
717         asset_title = 0;
718         tmp_path = 0;
719         btmp_path = 0;
720         disk_space = 0;
721         standard = 0;
722         scale = 0;
723         need_deinterlace = 0;
724         need_inverse_telecine = 0;
725         need_resize_tracks = 0;
726         need_histogram = 0;
727         non_standard = 0;
728         need_wide_audio = 0;
729         need_labeled = 0;
730         need_farmed = 0;
731         ok = 0;
732         cancel = 0;
733 }
734
735 CreateBD_GUI::~CreateBD_GUI()
736 {
737 }
738
739 void CreateBD_GUI::create_objects()
740 {
741         int xs10 = xS(10), xs35 = xS(35);
742         int xs160 = xS(160), xs170 = xS(170);
743         int ys5 = yS(5), ys10 = yS(10);
744         lock_window("CreateBD_GUI::create_objects");
745         int pady = BC_TextBox::calculate_h(this, MEDIUMFONT, 0, 1) + ys5;
746         int padx = BC_Title::calculate_w(this, (char*)"X", MEDIUMFONT);
747         int x = padx/2, y = pady/2;
748         BC_Title *title = new BC_Title(x, y, _("Title:"), MEDIUMFONT, YELLOW);
749         add_subwindow(title);
750         at_x = x + title->get_w();  at_y = y;
751         asset_title = new CreateBD_AssetTitle(this, at_x, at_y, get_w()-at_x-xs10);
752         add_subwindow(asset_title);
753         y += title->get_h() + pady/2;
754         title = new BC_Title(x, y, _("Work path:"), MEDIUMFONT, YELLOW);
755         add_subwindow(title);
756         tmp_x = x + title->get_w();  tmp_y = y;
757         tmp_path = new CreateBD_TmpPath(this, tmp_x, tmp_y,  get_w()-tmp_x-xs35);
758         add_subwindow(tmp_path);
759         btmp_path = new BrowseButton(thread->mwindow->theme, this, tmp_path,
760                 tmp_x+tmp_path->get_w(), tmp_y, "/tmp",
761                 _("Work path"), _("Select a Work directory:"), 1);
762         add_subwindow(btmp_path);
763         y += title->get_h() + pady/2;
764         disk_space = new CreateBD_DiskSpace(this, x, y);
765         add_subwindow(disk_space);
766         int x0 = get_w() - xs170;
767         title = new BC_Title(x0, y, _("Media:"), MEDIUMFONT, YELLOW);
768         add_subwindow(title);
769         int x1 =  x0+title->get_w()+padx;
770         media_size = new CreateBD_MediaSize(this, x1, y);
771         media_size->create_objects();
772         media_sizes.append(new BC_ListBoxItem("25GB"));
773         media_sizes.append(new BC_ListBoxItem("50GB"));
774         media_size->update_list(&media_sizes);
775         media_size->update(media_sizes[0]->get_text());
776         disk_space->update();
777         y += disk_space->get_h() + pady/2;
778         title = new BC_Title(x, y, _("Format:"), MEDIUMFONT, YELLOW);
779         add_subwindow(title);
780         standard = new CreateBD_Format(this, title->get_w() + padx, y);
781         add_subwindow(standard);
782         standard->create_objects();
783         standard->set_text(bd_formats[thread->use_standard].name);
784         x0 -= xS(60);
785         title = new BC_Title(x0, y, _("Scale:"), MEDIUMFONT, YELLOW);
786         add_subwindow(title);
787         x1 = x0+title->get_w()+padx;
788         scale = new CreateBD_Scale(this, x1, y);
789         add_subwindow(scale);
790         scale->create_objects();
791         y += standard->get_h() + pady/2;
792         x1 = x;  int y1 = y;
793         need_deinterlace = new CreateBD_Deinterlace(this, x1, y);
794         add_subwindow(need_deinterlace);
795         y += need_deinterlace->get_h() + pady/2;
796         need_histogram = new CreateBD_Histogram(this, x1, y);
797         add_subwindow(need_histogram);
798         y += need_histogram->get_h() + pady/2;
799         non_standard = new BC_Title(x1, y+ys5, "", MEDIUMFONT, RED);
800         add_subwindow(non_standard);
801         x1 += xs160;  y = y1;
802         need_inverse_telecine = new CreateBD_InverseTelecine(this, x1, y);
803         add_subwindow(need_inverse_telecine);
804         y += need_inverse_telecine->get_h() + pady/2;
805         need_wide_audio = new CreateBD_WideAudio(this, x1, y);
806         add_subwindow(need_wide_audio);
807         y += need_wide_audio->get_h() + pady/2;
808         need_resize_tracks = new CreateBD_ResizeTracks(this, x1, y);
809         add_subwindow(need_resize_tracks);
810         x1 += xs160;  y = y1;
811         need_labeled = new CreateBD_LabelChapters(this, x1, y);
812         add_subwindow(need_labeled);
813         y += need_labeled->get_h() + pady/2;
814         need_farmed = new CreateBD_UseRenderFarm(this, x1, y);
815         add_subwindow(need_farmed);
816         ok_w = BC_OKButton::calculate_w();
817         ok_h = BC_OKButton::calculate_h();
818         ok_x = xs10;
819         ok_y = get_h() - ok_h - xs10;
820         ok = new CreateBD_OK(this, ok_x, ok_y);
821         add_subwindow(ok);
822         cancel_w = BC_CancelButton::calculate_w();
823         cancel_h = BC_CancelButton::calculate_h();
824         cancel_x = get_w() - cancel_w - xs10,
825         cancel_y = get_h() - cancel_h - ys10;
826         cancel = new CreateBD_Cancel(this, cancel_x, cancel_y);
827         add_subwindow(cancel);
828         show_window();
829         unlock_window();
830 }
831
832 int CreateBD_GUI::resize_event(int w, int h)
833 {
834         int xs10 = xS(10), xs35 = xS(35);
835         int ys10 = yS(10);
836         asset_title->reposition_window(at_x, at_y, get_w()-at_x-xs10);
837         tmp_path->reposition_window(tmp_x, tmp_y,  get_w()-tmp_x-xs35);
838         btmp_path->reposition_window(tmp_x+tmp_path->get_w(), tmp_y);
839         ok_y = h - ok_h - ys10;
840         ok->reposition_window(ok_x, ok_y);
841         cancel_x = w - cancel_w - xs10,
842         cancel_y = h - cancel_h - ys10;
843         cancel->reposition_window(cancel_x, cancel_y);
844         return 0;
845 }
846
847 int CreateBD_GUI::translation_event()
848 {
849         return 1;
850 }
851
852 int CreateBD_GUI::close_event()
853 {
854         set_done(1);
855         return 1;
856 }
857
858 void CreateBD_GUI::update()
859 {
860         scale->set_value(thread->use_scale);
861         need_deinterlace->set_value(thread->use_deinterlace);
862         need_inverse_telecine->set_value(thread->use_inverse_telecine);
863         need_resize_tracks->set_value(thread->use_resize_tracks);
864         need_histogram->set_value(thread->use_histogram);
865         need_wide_audio->set_value(thread->use_wide_audio);
866         need_labeled->set_value(thread->use_labeled);
867         need_farmed->set_value(thread->use_farmed);
868 }
869
870 int CreateBD_Thread::
871 insert_video_plugin(const char *title, KeyFrame *default_keyframe)
872 {
873         Tracks *tracks = mwindow->edl->tracks;
874         for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
875                 if( vtrk->data_type != TRACK_VIDEO ) continue;
876                 if( !vtrk->record ) continue;
877                 vtrk->expand_view = 1;
878                 PluginSet *plugin_set = new PluginSet(mwindow->edl, vtrk);
879                 vtrk->plugin_set.append(plugin_set);
880                 Edits *edits = vtrk->edits;
881                 for( Edit *edit=edits->first; edit; edit=edit->next ) {
882                         plugin_set->insert_plugin(_(title),
883                                 edit->startproject, edit->length,
884                                 PLUGIN_STANDALONE, 0, default_keyframe, 0);
885                 }
886                 vtrk->optimize();
887         }
888         return 0;
889 }
890
891 int CreateBD_Thread::
892 resize_tracks()
893 {
894         Tracks *tracks = mwindow->edl->tracks;
895         int trk_w = max_w, trk_h = max_h;
896         if( trk_w < bd_width ) trk_w = bd_width;
897         if( trk_h < bd_height ) trk_h = bd_height;
898         for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
899                 if( vtrk->data_type != TRACK_VIDEO ) continue;
900                 if( !vtrk->record ) continue;
901                 vtrk->track_w = trk_w;
902                 vtrk->track_h = trk_h;
903         }
904         return 0;
905 }
906
907 int CreateBD_Thread::
908 option_presets()
909 {
910 // reset only probed options
911         use_deinterlace = 0;
912         use_scale = Rescale::none;
913         use_resize_tracks = 0;
914         use_wide_audio = 0;
915         use_labeled = 0;
916         use_farmed = 0;
917
918         if( !mwindow->edl ) return 1;
919
920         bd_width = bd_formats[use_standard].w;
921         bd_height = bd_formats[use_standard].h;
922         bd_framerate = bd_formats[use_standard].framerate;
923         int wide = bd_formats[use_standard].wide;
924         bd_aspect_width  = wide < 0 ? 1. :
925                 wide > 0 ? BD_WIDE_ASPECT_WIDTH  : BD_ASPECT_WIDTH;
926         bd_aspect_height = wide < 0 ? 1. :
927                 wide > 0 ? BD_WIDE_ASPECT_HEIGHT : BD_ASPECT_HEIGHT;
928         bd_interlace_mode = bd_formats[use_standard].interlaced;
929         double bd_aspect = bd_aspect_width / bd_aspect_height;
930
931         Tracks *tracks = mwindow->edl->tracks;
932         max_w = 0;  max_h = 0;
933         int has_deinterlace = 0, has_scale = 0;
934         for( Track *trk=tracks->first; trk; trk=trk->next ) {
935                 if( !trk->record ) continue;
936                 Edits *edits = trk->edits;
937                 switch( trk->data_type ) {
938                 case TRACK_VIDEO:
939                         for( Edit *edit=edits->first; edit; edit=edit->next ) {
940                                 if( edit->silence() ) continue;
941                                 Indexable *indexable = edit->get_source();
942                                 int w = indexable->get_w();
943                                 if( w > max_w ) max_w = w;
944                                 if( w != bd_width ) use_scale = Rescale::scaled;
945                                 int h = indexable->get_h();
946                                 if( h > max_h ) max_h = h;
947                                 if( h != bd_height ) use_scale = Rescale::scaled;
948                                 float aw, ah;
949                                 MWindow::create_aspect_ratio(aw, ah, w, h);
950                                 double aspect = ah > 0 ? aw / ah : 1;
951                                 if( wide >= 0 && !EQUIV(aspect, bd_aspect) )
952                                         use_scale = Rescale::scaled;
953                         }
954                         for( int i=0; i<trk->plugin_set.size(); ++i ) {
955                                 for( Plugin *plugin = (Plugin*)trk->plugin_set[i]->first;
956                                                 plugin; plugin=(Plugin*)plugin->next ) {
957                                         if( !strcmp(plugin->title, "Deinterlace") )
958                                                 has_deinterlace = 1;
959                                         if( !strcmp(plugin->title, "Auto Scale") ||
960                                             !strcmp(plugin->title, "Scale Ratio") ||
961                                             !strcmp(plugin->title, "Scale") )
962                                                 has_scale = 1;
963                                 }
964                         }
965                         break;
966                 }
967         }
968         if( has_scale )
969                 use_scale = Rescale::none;
970         if( use_scale != Rescale::none ) {
971                 if( max_w != bd_width ) use_resize_tracks = 1;
972                 if( max_h != bd_height ) use_resize_tracks = 1;
973         }
974         for( Track *trk=tracks->first; trk && !use_resize_tracks; trk=trk->next ) {
975                 if( !trk->record ) continue;
976                 switch( trk->data_type ) {
977                 case TRACK_VIDEO:
978                         if( trk->track_w != max_w ) use_resize_tracks = 1;
979                         if( trk->track_h != max_h ) use_resize_tracks = 1;
980                         break;
981                 }
982         }
983         if( !has_deinterlace && max_h > 2*bd_height ) use_deinterlace = 1;
984
985         if( tracks->recordable_audio_tracks() == BD_WIDE_CHANNELS )
986                 use_wide_audio = 1;
987
988         return 0;
989 }
990
991
992 CreateBD_FormatItem::CreateBD_FormatItem(CreateBD_Format *popup,
993                 int standard, const char *name)
994  : BC_MenuItem(name)
995 {
996         this->popup = popup;
997         this->standard = standard;
998 }
999
1000 CreateBD_FormatItem::~CreateBD_FormatItem()
1001 {
1002 }
1003
1004 int CreateBD_FormatItem::handle_event()
1005 {
1006         const char *text = get_text();
1007         int standard = this->standard;
1008         if( standard < 0 ) {
1009                 BC_SubMenu *submenu = get_submenu();
1010                 CreateBD_FormatItem *sub_item0 =
1011                         (CreateBD_FormatItem *)submenu->get_item(0);
1012                 standard = sub_item0->standard;
1013                 text = sub_item0->get_text();
1014         }
1015         popup->gui->thread->use_standard = standard;
1016         popup->set_text(text);
1017         int n = strlen(text)-1;
1018         int not_standard = n >= 0 && text[n] == '*' ? 1 : 0;
1019         popup->gui->non_standard->update(not_standard ? _("* non-standard format") : "", 0);
1020         return popup->handle_event();
1021 }
1022
1023
1024 CreateBD_Format::CreateBD_Format(CreateBD_GUI *gui, int x, int y)
1025  : BC_PopupMenu(x, y, xS(200), bd_formats[gui->thread->use_standard].name, 1)
1026 {
1027         this->gui = gui;
1028 }
1029
1030 CreateBD_Format::~CreateBD_Format()
1031 {
1032 }
1033
1034 void CreateBD_Format::create_objects()
1035 {
1036         BC_SubMenu *submenu = 0;
1037         CreateBD_FormatItem *item = 0;
1038         int ww = 0, hh = 0;
1039         for( int i=0; i<(int)(sizeof(bd_formats)/sizeof(bd_formats[0])); ++i ) {
1040                 if( ww != bd_formats[i].w || hh != bd_formats[i].h ) {
1041                         ww = bd_formats[i].w;  hh = bd_formats[i].h;
1042                         char string[BCSTRLEN];
1043                         sprintf(string, "%dx%d", ww,hh);
1044                         add_item(item = new CreateBD_FormatItem(this, -1, string));
1045                         item->add_submenu(submenu = new BC_SubMenu());
1046                 }
1047                 submenu->add_submenuitem(new CreateBD_FormatItem(this, i, bd_formats[i].name));
1048         }
1049 }
1050
1051 int CreateBD_Format::handle_event()
1052 {
1053         gui->thread->option_presets();
1054         gui->update();
1055         return 1;
1056 }
1057
1058
1059 CreateBD_ScaleItem::CreateBD_ScaleItem(CreateBD_Scale *popup,
1060                 int scale, const char *text)
1061  : BC_MenuItem(text)
1062 {
1063         this->popup = popup;
1064         this->scale = scale;
1065 }
1066
1067 CreateBD_ScaleItem::~CreateBD_ScaleItem()
1068 {
1069 }
1070
1071 int CreateBD_ScaleItem::handle_event()
1072 {
1073         popup->gui->thread->use_scale = scale;
1074         popup->set_value(scale);
1075         return popup->handle_event();
1076 }
1077
1078
1079 CreateBD_Scale::CreateBD_Scale(CreateBD_GUI *gui, int x, int y)
1080  : BC_PopupMenu(x, y, xS(140), "", 1)
1081 {
1082         this->gui = gui;
1083 }
1084
1085 CreateBD_Scale::~CreateBD_Scale()
1086 {
1087 }
1088
1089 void CreateBD_Scale::create_objects()
1090 {
1091
1092         for( int i=0; i<(int)Rescale::n_scale_types; ++i ) {
1093                 add_item(new CreateBD_ScaleItem(this, i, Rescale::scale_types[i]));
1094         }
1095         set_value(gui->thread->use_scale);
1096 }
1097
1098 int CreateBD_Scale::handle_event()
1099 {
1100         gui->update();
1101         return 1;
1102 }
1103
1104
1105 CreateBD_MediaSize::CreateBD_MediaSize(CreateBD_GUI *gui, int x, int y)
1106  : BC_PopupTextBox(gui, 0, 0, x, y, xS(70),yS(50))
1107 {
1108         this->gui = gui;
1109 }
1110
1111 CreateBD_MediaSize::~CreateBD_MediaSize()
1112 {
1113 }
1114
1115 int CreateBD_MediaSize::handle_event()
1116 {
1117         gui->disk_space->update();
1118         return 1;
1119 }
1120