proxy bug fixes, add moveobj, sams icons, ladspa fixes, pot sigfpe
[goodguy/history.git] / cinelerra-5.1 / cinelerra / proxy.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2015 Adam Williams <broadcast at earthling dot net>
5  * 
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  * 
20  */
21
22 #include "assets.h"
23 #include "bcsignals.h"
24 #include "clip.h"
25 #include "confirmsave.h"
26 #include "cstrdup.h"
27 #include "edl.h"
28 #include "edlsession.h"
29 #include "errorbox.h"
30 #include "file.h"
31 #include "filesystem.h"
32 #include "formattools.h"
33 #include "language.h"
34 #include "mainprogress.h"
35 #include "mainundo.h"
36 #include "mutex.h"
37 #include "mwindow.h"
38 #include "mwindowgui.h"
39 #include "overlayframe.h"
40 #include "preferences.h"
41 #include "proxy.h"
42 #include "theme.h"
43
44 #define WIDTH 400
45 #define HEIGHT 320
46 #define MAX_SCALE 16
47
48 ProxyMenuItem::ProxyMenuItem(MWindow *mwindow)
49  : BC_MenuItem(_("Proxy settings..."),  _("Alt-P"), 'p')
50 {
51         this->mwindow = mwindow;
52         set_alt();
53 }
54
55 void ProxyMenuItem::create_objects()
56 {
57         thread = new ProxyThread(mwindow);
58 }
59
60 int ProxyMenuItem::handle_event()
61 {
62         mwindow->gui->unlock_window();
63         thread->start();
64         mwindow->gui->lock_window("ProxyMenuItem::handle_event");
65
66         return 1;
67 }
68
69 ProxyThread::ProxyThread(MWindow *mwindow)
70 {
71         this->mwindow = mwindow;
72         gui = 0;
73         asset = new Asset;
74         progress = 0;
75         counter_lock = new Mutex("ProxyThread::counter_lock");
76         bzero(size_text, sizeof(char*) * MAX_SIZES);
77         bzero(size_factors, sizeof(int) * MAX_SIZES);
78         total_sizes = 0;
79 }
80 ProxyThread::~ProxyThread()
81 {
82         for( int i=0; i<MAX_SIZES; ++i ) delete [] size_text[i];
83         asset->remove_user();
84 }
85
86 BC_Window* ProxyThread::new_gui()
87 {
88         asset->format = FILE_FFMPEG;
89         asset->load_defaults(mwindow->defaults, "PROXY_", 1, 1, 0, 0, 0);
90         mwindow->gui->lock_window("ProxyThread::new_gui");
91         int x = mwindow->gui->get_abs_cursor_x(0) - WIDTH / 2;
92         int y = mwindow->gui->get_abs_cursor_y(0) - HEIGHT / 2;
93
94         gui = new ProxyWindow(mwindow, this, x, y);
95         gui->create_objects();
96         mwindow->gui->unlock_window();
97         return gui;
98 }
99
100 void ProxyThread::scale_to_text(char *string, int scale)
101 {
102         strcpy(string, size_text[0]);
103         for( int i = 0; i < total_sizes; i++ ) {
104                 if( scale == size_factors[i] ) {
105                         strcpy(string, size_text[i]);
106                         break;
107                 }
108         }
109 }
110
111
112 void ProxyThread::calculate_sizes()
113 {
114         for( int i=1; i<total_sizes; ++i ) {
115                 delete [] size_text[i];
116                 size_text[i] = 0;
117                 size_factors[i] = 0;
118         }
119         total_sizes = 1;
120
121         int orig_w = mwindow->edl->session->output_w * orig_scale;
122         int orig_h = mwindow->edl->session->output_h * orig_scale;
123
124         if( !use_scaler ) {
125 // w,h should stay even for yuv
126                 int ow = orig_w, oh = orig_h;
127                 if( BC_CModels::is_yuv(mwindow->edl->session->color_model) ) {
128                         ow /= 2;  oh /= 2;
129                 }
130                 for( int i=2; i<MAX_SCALE; ++i ) {
131                         if( (ow % i) != 0 ) continue;
132                         if( (oh % i) != 0 ) continue;
133                         size_factors[total_sizes++] = i;
134                 }
135         }
136         else {
137                 size_factors[total_sizes++] = 2;   size_factors[total_sizes++] = 3;
138                 size_factors[total_sizes++] = 8;   size_factors[total_sizes++] = 12;
139                 size_factors[total_sizes++] = 16;  size_factors[total_sizes++] = 24;
140                 size_factors[total_sizes++] = 32;
141         }
142         for( int i=1; i<total_sizes; ++i ) {
143                 char string[BCTEXTLEN];
144                 sprintf(string, "1/%d", size_factors[i]);
145                 size_text[i] = cstrdup(string);
146         }
147 }
148
149 void ProxyThread::handle_close_event(int result)
150 {
151         asset->save_defaults(mwindow->defaults, "PROXY_", 1, 1, 0, 0, 0); 
152
153         if( !result )
154                 to_proxy();
155 }
156
157 void ProxyThread::to_proxy()
158 {
159 // test for new files
160         ArrayList<char *> confirm_paths;
161         confirm_paths.set_array_delete();
162 // all proxy assets
163         ArrayList<Indexable*> proxy_assets;
164 // assets which must be created
165         ArrayList<Asset*> needed_assets;
166 // original assets
167         ArrayList<Indexable*> orig_assets;
168 // original assets which match the needed_assets
169         ArrayList<Asset*> needed_orig_assets;
170         Asset *proxy_asset = 0;
171         Asset *orig_asset = 0;
172
173         mwindow->edl->Garbage::add_user();
174         mwindow->save_backup();
175         mwindow->undo->update_undo_before(_("proxy"), this);
176
177         EDL *&edl = mwindow->edl;
178         EDLSession *&session = edl->session;
179         Assets *&assets = edl->assets;
180
181 // revert project to original size from current size
182 // remove all session proxy assets at the at the current proxy_scale
183         if( session->proxy_scale > 1 ) {
184                 orig_asset = assets->first;
185                 for( ; orig_asset; orig_asset=orig_asset->next ) {
186                         char new_path[BCTEXTLEN];
187                         to_proxy_path(new_path, orig_asset, session->proxy_scale);
188                         proxy_asset = assets->get_asset(new_path);
189                         if( !proxy_asset ) continue;
190 // test if proxy asset was already added to proxy_assets
191                         int got_it = 0;
192                         for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
193                                 got_it = !strcmp(proxy_assets[i]->path, new_path);
194                         if( got_it ) continue;
195 // add pointer to existing EDL asset if it exists
196 // EDL won't delete it unless it's the same pointer.
197                         proxy_assets.append(proxy_asset);
198                         proxy_asset->Garbage::add_user();
199                         orig_assets.append(orig_asset);
200                         orig_asset->Garbage::add_user();
201                 }
202
203 // convert from the proxy assets to the original assets
204                 mwindow->set_proxy(0, 1, &proxy_assets, &orig_assets);
205
206 // remove the proxy assets
207                 mwindow->remove_assets_from_project(0, 0, &proxy_assets, NULL);
208                 for( int i=0; i<proxy_assets.size(); ++i )
209                         proxy_assets.get(i)->Garbage::remove_user();
210                 proxy_assets.remove_all();
211                 for( int i = 0; i < orig_assets.size(); i++ )
212                         orig_assets.get(i)->Garbage::remove_user();
213                 orig_assets.remove_all();
214         }
215
216 // convert to new size if not original size
217         if( new_scale != 1 ) {
218                 orig_asset = assets->first;
219                 for( ; orig_asset; orig_asset=orig_asset->next ) {
220                         if( !orig_asset->video_data ) continue;
221                         char new_path[BCTEXTLEN];
222                         to_proxy_path(new_path, orig_asset, new_scale);
223 // add to proxy_assets & orig_assets if it isn't already there.
224                         int got_it = 0;
225                         for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
226                                 got_it = !strcmp(proxy_assets[i]->path, new_path);
227                         if( !got_it ) {
228                                 proxy_asset = new Asset;
229 // new compression parameters
230                                 proxy_asset->copy_format(asset, 0);
231                                 proxy_asset->update_path(new_path);
232                                 proxy_asset->audio_data = 0;
233                                 proxy_asset->video_data = 1;
234                                 proxy_asset->layers = 1;
235                                 proxy_asset->width = orig_asset->width / new_scale;
236                                 if( proxy_asset->width & 1 ) ++proxy_asset->width;
237                                 proxy_asset->actual_width = proxy_asset->width;
238                                 proxy_asset->height = orig_asset->height / new_scale;
239                                 if( proxy_asset->height & 1 ) ++proxy_asset->height;
240                                 proxy_asset->actual_height = proxy_asset->height;
241                                 proxy_asset->frame_rate = orig_asset->frame_rate;
242                                 proxy_asset->video_length = orig_asset->video_length;
243                                 proxy_assets.append(proxy_asset);
244                                 orig_asset->add_user();
245                                 orig_assets.append(orig_asset);
246                         }
247
248 // test if proxy file exists.
249                         int exists = 0;
250                         FILE *fd = fopen(new_path, "r");
251                         if( fd ) {
252                                 exists = 1;
253                                 fclose(fd);
254                                 FileSystem fs;
255 // got it if proxy file is newer than original.
256                                 got_it = fs.get_date(new_path) > fs.get_date(asset->path);
257                         }
258                         else
259                                 got_it = 0;
260
261                         if( !got_it ) {
262                                 if( exists ) // prompt user to overwrite
263                                         confirm_paths.append(cstrdup(new_path));
264
265                                 needed_assets.append(proxy_asset);
266                                 proxy_asset->add_user();
267                                 needed_orig_assets.append(orig_asset);
268                                 orig_asset->add_user();
269 //printf("ProxyThread::handle_close_event %d %s\n", __LINE__, new_path);
270                         }
271                 }
272
273 // test for existing files
274                 int result = 0;
275                 if( confirm_paths.size() ) {
276                         result = ConfirmSave::test_files(mwindow, &confirm_paths);
277                         confirm_paths.remove_all_objects();
278                 }
279
280                 if( !result ) {
281                         int canceled = 0;
282                         failed = 0;
283
284 // create proxy assets which don't already exist
285                         if( needed_orig_assets.size() > 0 ) {
286                                 int64_t total_len = 0;
287                                 for( int i = 0; i < needed_orig_assets.size(); i++ )
288                                         total_len += needed_orig_assets.get(i)->video_length;
289 // start progress bar.  MWindow is locked inside this
290                                 progress = mwindow->mainprogress->
291                                         start_progress(_("Creating proxy files..."), total_len);
292                                 total_rendered = 0;
293
294                                 ProxyFarm engine(mwindow, this,
295                                         &needed_assets, &needed_orig_assets);
296                                 engine.process_packages();
297 printf("failed=%d canceled=%d\n", failed, progress->is_cancelled());
298
299 // stop progress bar
300                                 canceled = progress->is_cancelled();
301                                 progress->stop_progress();
302                                 delete progress;  progress = 0;
303
304                                 if( failed && !canceled ) {
305                                         int cx, cy;
306                                         mwindow->gui->get_abs_cursor_xy(cx, cy, 1);
307                                         ErrorBox error_box(PROGRAM_NAME ": Error", cx, cy);
308                                         error_box.create_objects(_("Error making proxy."));
309                                         error_box.raise_window();
310                                         error_box.run_window();
311                                 }
312                         }
313
314 // resize project
315                         if( !failed && !canceled ) {
316                                 mwindow->set_proxy(use_scaler, new_scale, &orig_assets, &proxy_assets);
317                         }
318                 }
319
320                 for( int i = 0; i < proxy_assets.size(); i++ )
321                         proxy_assets.get(i)->Garbage::remove_user();
322                 for( int i = 0; i < orig_assets.size(); i++ )
323                         orig_assets.get(i)->Garbage::remove_user();
324                 for( int i = 0; i < needed_assets.size(); i++ )
325                         needed_assets.get(i)->Garbage::remove_user();
326                 for( int i = 0; i < needed_orig_assets.size(); i++ )
327                         needed_orig_assets.get(i)->Garbage::remove_user();
328         }
329
330         mwindow->undo->update_undo_after(_("proxy"), LOAD_ALL);
331         mwindow->edl->Garbage::remove_user();
332         mwindow->restart_brender();
333
334         mwindow->gui->lock_window("ProxyThread::to_proxy");
335         mwindow->update_project(LOAD_ALL);
336         mwindow->gui->unlock_window();
337 }
338
339
340 void ProxyThread::to_proxy_path(char *new_path, Asset *asset, int scale)
341 {
342         strcpy(new_path, asset->path);
343         char prxy[BCTEXTLEN];
344         sprintf(prxy, ".proxy%d", scale);
345 // path is already a proxy
346         if( strstr(new_path, prxy) ) return;
347         int len = strlen(new_path);
348 // insert proxy prxy
349         char *ptr = strrchr(new_path, '.');
350         if( ptr ) {
351                 char *cp = new_path + len;
352                 int n = strlen(prxy);
353                 char *bp = cp + n;
354                 for( *bp=0; cp>ptr; ) *--bp = *--cp;
355                 for( cp= prxy+n; bp>ptr; ) *--bp = *--cp;
356 //printf("ProxyThread::to_proxy_path %d %s %s\n", __LINE__, new_path), asset->path);
357         }
358         else
359                 strcpy(new_path+len, prxy);
360 }
361
362 void ProxyThread::from_proxy_path(char *new_path, Asset *asset, int scale)
363 {
364         char prxy[BCTEXTLEN];
365         sprintf(prxy, ".proxy%d", scale);
366         strcpy(new_path, asset->path);
367         char *ptr = strstr(asset->path, prxy);
368         if( !ptr ) return;
369         int n = strlen(prxy);
370         for( char *cp=ptr+n; --n>=0; ++ptr,++cp ) *ptr = *cp;
371         *ptr = 0;
372 }
373
374 void ProxyThread::update_progress()
375 {
376         counter_lock->lock();
377         total_rendered++;
378         counter_lock->unlock();
379         progress->update(total_rendered);
380 }
381
382 int ProxyThread::is_canceled()
383 {
384         return progress->is_cancelled();
385 }
386
387
388
389 ProxyWindow::ProxyWindow(MWindow *mwindow, ProxyThread *thread, int x, int y)
390  : BC_Window(_(PROGRAM_NAME ": Proxy settings"), x, y, WIDTH, HEIGHT,
391                 -1, -1, 0, 0, 1)
392 {
393         this->mwindow = mwindow;
394         this->thread = thread;
395         format_tools = 0;
396 }
397
398 ProxyWindow::~ProxyWindow()
399 {
400         lock_window("ProxyWindow::~ProxyWindow");
401         delete format_tools;
402         unlock_window();
403 }
404
405
406 void ProxyWindow::create_objects()
407 {
408         lock_window("ProxyWindow::create_objects");
409
410         int margin = mwindow->theme->widget_border;
411         int x = margin;
412         int y = margin;
413         thread->use_scaler = mwindow->edl->session->proxy_use_scaler;
414         thread->orig_scale = mwindow->edl->session->proxy_scale;
415         thread->new_scale = thread->orig_scale;
416
417         BC_Title *text;
418         add_subwindow(text = new BC_Title(x, y, 
419                 _("What size should the project\n"
420                   "be scaled to for editing?")));
421         y += text->get_h() * 2 + margin;
422
423         add_subwindow(text = new BC_Title(x, y, _("Scale factor:")));
424         x += text->get_w() + margin;
425
426         thread->size_text[0] = cstrdup(_("Original size"));
427         thread->size_factors[0] = 1;
428         thread->total_sizes = 1;
429         int popupmenu_w = BC_PopupMenu::calculate_w(get_text_width(MEDIUMFONT, thread->size_text[0]));
430         add_subwindow(scale_factor = new ProxyMenu(mwindow, this, x, y, popupmenu_w, ""));
431         scale_factor->update_sizes();
432         x += scale_factor->get_w() + margin;
433
434         ProxyTumbler *tumbler;
435         add_subwindow(tumbler = new ProxyTumbler(mwindow, this, x, y));
436         y += tumbler->get_h() + margin;
437         x = margin;
438         add_subwindow(use_scaler = new ProxyUseScaler(mwindow, this, x, y));
439         y += use_scaler->get_h() + margin;
440         y += 25;
441
442         x = margin;
443         add_subwindow(text = new BC_Title(x, y, _("New media dimensions: ")));
444         x += text->get_w() + margin;
445         add_subwindow(new_dimensions = new BC_Title(x, y, ""));
446
447         x = margin;
448         y += new_dimensions->get_h() * 2 + margin;
449
450
451         format_tools = new ProxyFormatTools(mwindow, this, thread->asset);
452         format_tools->create_objects(x, y, 0, 1, 0, 0, 0, 1, 0, 1, // skip the path
453                 0, 0);
454
455         update();
456
457         add_subwindow(new BC_OKButton(this));
458         add_subwindow(new BC_CancelButton(this));
459         show_window(1);
460         unlock_window();
461 }
462
463 ProxyFormatTools::ProxyFormatTools(MWindow *mwindow, ProxyWindow *pwindow, Asset *asset)
464  : FormatTools(mwindow, pwindow, asset)
465 {
466         this->pwindow = pwindow;
467 }
468
469 void ProxyFormatTools::update_format()
470 {
471         FormatTools::update_format();
472         pwindow->use_scaler->update();
473 }
474
475 void ProxyWindow::update()
476 {
477 // preview the new size
478         char string[BCTEXTLEN];
479 //printf("ProxyWindow::update %d %d %d %d %d\n", 
480 // __LINE__, mwindow->edl->session->output_w, mwindow->edl->session->output_h,
481 // thread->orig_scale, thread->new_scale);
482         int orig_w = mwindow->edl->session->output_w * thread->orig_scale;
483         int orig_h = mwindow->edl->session->output_h * thread->orig_scale;
484         int new_w = orig_w / thread->new_scale;
485         if( new_w & 1 ) ++new_w;
486         int new_h = orig_h / thread->new_scale;
487         if( new_h & 1 ) ++new_h;
488         sprintf(string, "%dx%d", new_w, new_h);
489         new_dimensions->update(string);
490         thread->scale_to_text(string, thread->new_scale);
491         scale_factor->set_text(string);
492         use_scaler->update();
493 }
494
495
496 ProxyUseScaler::ProxyUseScaler(MWindow *mwindow, ProxyWindow *pwindow, int x, int y)
497  : BC_CheckBox(x, y, pwindow->thread->use_scaler, _("Use scaler   (FFMPEG only)"))
498 {
499         this->mwindow = mwindow;
500         this->pwindow = pwindow;
501 }
502
503 void ProxyUseScaler::update()
504 {
505         ProxyThread *thread = pwindow->thread;
506         if( thread->asset->format != FILE_FFMPEG ) thread->use_scaler = 0;
507         BC_CheckBox::update(thread->use_scaler);
508         int scaler_avail = thread->asset->format == FILE_FFMPEG ? 1 : 0;
509         if( !scaler_avail &&  enabled ) disable();
510         if( scaler_avail  && !enabled ) enable();
511 }
512
513 int ProxyUseScaler::handle_event()
514 {
515         pwindow->thread->new_scale = 1;
516         pwindow->thread->use_scaler = get_value();
517         pwindow->scale_factor->update_sizes();
518         pwindow->update();
519         return 1;
520 }
521
522
523 ProxyMenu::ProxyMenu(MWindow *mwindow, ProxyWindow *pwindow,
524                 int x, int y, int w, const char *text)
525  : BC_PopupMenu(x, y, w, text, 1)
526 {
527         this->mwindow = mwindow;
528         this->pwindow = pwindow;
529 }
530
531 void ProxyMenu::update_sizes()
532 {
533         while( total_items() > 0 ) del_item(0);
534         ProxyThread *thread = pwindow->thread;
535         thread->calculate_sizes();
536         for( int i=0; i < thread->total_sizes; i++ )
537                 add_item(new BC_MenuItem(thread->size_text[i]));
538 }
539
540 int ProxyMenu::handle_event()
541 {
542         for( int i = 0; i < pwindow->thread->total_sizes; i++ ) {
543                 if( !strcmp(get_text(), pwindow->thread->size_text[i]) ) {
544                         pwindow->thread->new_scale = pwindow->thread->size_factors[i];
545                         if( pwindow->thread->new_scale == 1 )
546                                 pwindow->thread->use_scaler = 0;
547                         pwindow->update();
548                         break;
549                 }
550         }
551         return 1;
552 }
553
554
555 ProxyTumbler::ProxyTumbler(MWindow *mwindow, ProxyWindow *pwindow, int x, int y)
556  : BC_Tumbler(x, y, 0)
557 {
558         this->mwindow = mwindow;
559         this->pwindow = pwindow;
560 }
561
562 int ProxyTumbler::handle_up_event()
563 {
564         if( pwindow->thread->new_scale > 1 ) {
565                 int i;
566                 for( i = 0; i < pwindow->thread->total_sizes; i++ ) {
567                         if( pwindow->thread->new_scale == pwindow->thread->size_factors[i] ) {
568                                 i--;
569                                 pwindow->thread->new_scale = pwindow->thread->size_factors[i];
570                                 pwindow->update();
571                                 return 1;
572                         }
573                 }               
574         }
575
576         return 0;
577 }
578
579 int ProxyTumbler::handle_down_event()
580 {
581         int i;
582         for( i = 0; i < pwindow->thread->total_sizes - 1; i++ ) {
583                 if( pwindow->thread->new_scale == pwindow->thread->size_factors[i] ) {
584                         i++;
585                         pwindow->thread->new_scale = pwindow->thread->size_factors[i];
586                         pwindow->update();
587                         return 1;
588                 }
589         }
590
591         return 0;
592 }
593
594
595 ProxyPackage::ProxyPackage()
596  : LoadPackage()
597 {
598 }
599
600 ProxyClient::ProxyClient(MWindow *mwindow, ProxyThread *thread, ProxyFarm *server)
601  : LoadClient(server)
602 {
603         this->mwindow = mwindow;
604         this->thread = thread;
605 }
606
607 void ProxyClient::process_package(LoadPackage *ptr)
608 {
609         ProxyPackage *package = (ProxyPackage*)ptr;
610         if( thread->failed ) return;
611
612         File src_file;
613         File dst_file;
614         EDL *edl = mwindow->edl;
615         Preferences *preferences = mwindow->preferences;
616         int processors = 1;
617
618         int result;
619         src_file.set_processors(processors);
620         src_file.set_preload(edl->session->playback_preload);
621         src_file.set_subtitle(edl->session->decode_subtitles ? 
622                 edl->session->subtitle_number : -1);
623         src_file.set_interpolate_raw(edl->session->interpolate_raw);
624         src_file.set_white_balance_raw(edl->session->white_balance_raw);
625
626 //printf("%s %s\n", package->orig_asset->path, package->proxy_asset->path);
627
628
629         result = src_file.open_file(preferences, package->orig_asset, 1, 0);
630         if( result ) {
631 // go to the next asset if the reader fails
632 //              thread->failed = 1;
633                 return;
634         }
635
636         dst_file.set_processors(processors);
637         result = dst_file.open_file(preferences, package->proxy_asset, 0, 1);
638         if( result ) {
639                 thread->failed = 1;
640                 return;
641         }
642
643         dst_file.start_video_thread(1, edl->session->color_model,
644                         processors > 1 ? 2 : 1, 0);
645
646         VFrame src_frame(0, -1,
647                 package->orig_asset->width, package->orig_asset->height, 
648                 edl->session->color_model, -1);
649
650         OverlayFrame scaler(processors);
651
652         for( int64_t i = 0; i < package->orig_asset->video_length &&
653              !thread->failed && !thread->is_canceled(); i++ ) {
654                 src_file.set_video_position(i, 0);
655                 result = src_file.read_frame(&src_frame);
656 //printf("result=%d\n", result);
657
658                 if( result ) {
659 // go to the next asset if the reader fails
660 //                      thread->failed = 1;
661                         break;
662                 }
663
664 // have to write after getting the video buffer or it locks up
665                 VFrame ***dst_frames = dst_file.get_video_buffer();
666                 VFrame *dst_frame = dst_frames[0][0];
667                 scaler.overlay(dst_frame, &src_frame,
668                         0, 0, src_frame.get_w(), src_frame.get_h(),
669                         0, 0, dst_frame->get_w(), dst_frame->get_h(),
670                         1.0, TRANSFER_REPLACE, NEAREST_NEIGHBOR);
671                 result = dst_file.write_video_buffer(1);
672                 if( result ) {
673 // only fail if the writer fails
674                         thread->failed = 1;
675                         break;
676                 }
677                 else {
678                         thread->update_progress();
679                 }
680         }
681 }
682
683
684 ProxyFarm::ProxyFarm(MWindow *mwindow, ProxyThread *thread,
685         ArrayList<Asset*> *proxy_assets, ArrayList<Asset*> *orig_assets)
686  : LoadServer(MIN(mwindow->preferences->processors, proxy_assets->size()), 
687         proxy_assets->size())
688 {
689         this->mwindow = mwindow;
690         this->thread = thread;
691         this->proxy_assets = proxy_assets;
692         this->orig_assets = orig_assets;
693 }
694
695 void ProxyFarm::init_packages()
696 {
697         for( int i = 0; i < get_total_packages(); i++ ) {
698         ProxyPackage *package = (ProxyPackage*)get_package(i);
699         package->proxy_asset = proxy_assets->get(i);
700                 package->orig_asset = orig_assets->get(i);
701         }
702 }
703
704 LoadClient* ProxyFarm::new_client()
705 {
706         return new ProxyClient(mwindow, thread, this);
707 }
708
709 LoadPackage* ProxyFarm::new_package()
710 {
711         return new ProxyPackage;
712 }
713