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