3 #include "confirmsave.h"
5 #include "edlsession.h"
9 #include "packagedispatcher.h"
10 #include "packagerenderer.h"
11 #include "preferences.h"
17 PackageDispatcher::PackageDispatcher()
20 package_lock = new Mutex("PackageDispatcher::package_lock");
24 PackageDispatcher::~PackageDispatcher()
28 for(int i = 0; i < total_packages; i++)
33 delete packaging_engine;
37 int PackageDispatcher::create_packages(MWindow *mwindow,
39 Preferences *preferences,
48 this->mwindow = mwindow;
50 this->preferences = preferences;
51 this->strategy = strategy;
52 this->default_asset = default_asset;
53 this->total_start = total_start;
54 this->total_end = total_end;
56 nodes = preferences->get_enabled_nodes();
57 audio_position = Units::to_int64(total_start * default_asset->sample_rate);
58 video_position = Units::to_int64(total_start * default_asset->frame_rate);
59 audio_end = Units::to_int64(total_end * default_asset->sample_rate);
60 video_end = Units::to_int64(total_end * default_asset->frame_rate);
64 // printf("PackageDispatcher::create_packages 1 %d %f %f\n",
67 // default_asset->frame_rate);
71 if(strategy == SINGLE_PASS)
73 total_len = this->total_end - this->total_start;
74 package_len = total_len;
75 min_package_len = total_len;
78 packages = new RenderPackage*[total_allocated];
79 packages[0] = new RenderPackage;
80 packages[0]->audio_start = audio_position;
81 packages[0]->audio_end = audio_end;
82 packages[0]->video_start = video_position;
83 packages[0]->video_end = video_end;
84 packages[0]->audio_do = default_asset->audio_data;
85 packages[0]->video_do = default_asset->video_data;
86 strcpy(packages[0]->path, default_asset->path);
89 if(strategy == SINGLE_PASS_FARM)
91 packaging_engine = File::new_packaging_engine(default_asset);
92 packaging_engine->create_packages_single_farm(
100 if(strategy == FILE_PER_LABEL || strategy == FILE_PER_LABEL_FARM)
102 Label *label = edl->labels->first;
104 packages = new RenderPackage*[edl->labels->total() + 2];
106 Render::get_starting_number(default_asset->path,
112 while(audio_position < audio_end)
114 RenderPackage *package =
115 packages[total_packages] =
117 package->audio_start = audio_position;
118 package->video_start = video_position;
119 package->audio_do = default_asset->audio_data;
120 package->video_do = default_asset->video_data;
124 (label->position < (double)audio_position / default_asset->sample_rate ||
125 EQUIV(label->position, (double)audio_position / default_asset->sample_rate)))
132 package->audio_end = Units::to_int64(total_end * default_asset->sample_rate);
133 package->video_end = Units::to_int64(total_end * default_asset->frame_rate);
137 package->audio_end = Units::to_int64(label->position * default_asset->sample_rate);
138 package->video_end = Units::to_int64(label->position * default_asset->frame_rate);
141 if(package->audio_end > audio_end)
143 package->audio_end = audio_end;
146 if(package->video_end > video_end)
148 package->video_end = video_end;
151 audio_position = package->audio_end;
152 video_position = package->video_end;
153 // Create file number differently if image file sequence
154 Render::create_filename(package->path,
164 total_allocated = total_packages;
167 if(strategy == BRENDER_FARM)
169 total_len = this->total_end - this->total_start;
171 // Create packages as they're requested.
176 Render::get_starting_number(default_asset->path,
183 if(preferences->renderfarm_nodes.total == 1)
185 package_len = total_len;
186 min_package_len = total_len;
190 package_len = preferences->brender_fragment /
191 edl->session->frame_rate;
192 min_package_len = 1.0 / edl->session->frame_rate;
196 // Test existence of every output file.
197 // Only if this isn't a background render or non interactive.
198 if(strategy != BRENDER_FARM &&
202 ArrayList<char*> paths;
203 get_package_paths(&paths);
204 result = ConfirmSave::test_files(mwindow, &paths);
205 paths.remove_all_objects();
211 void PackageDispatcher::get_package_paths(ArrayList<char*> *path_list)
213 if (strategy == SINGLE_PASS_FARM)
214 packaging_engine->get_package_paths(path_list);
217 for(int i = 0; i < total_allocated; i++)
218 path_list->append(strdup(packages[i]->path));
219 path_list->set_free();
224 RenderPackage* PackageDispatcher::get_package(double frames_per_second,
228 package_lock->lock("PackageDispatcher::get_package");
229 // printf("PackageDispatcher::get_package 1 %f\n",
230 // frames_per_second);
232 preferences->set_rate(frames_per_second, client_number);
233 if(mwindow) mwindow->preferences->copy_rates_from(preferences);
234 float avg_frames_per_second = preferences->get_avg_rate(use_local_rate);
236 RenderPackage *result = 0;
237 //printf("PackageDispatcher::get_package 1 %d\n", strategy);
238 if(strategy == SINGLE_PASS ||
239 strategy == FILE_PER_LABEL ||
240 strategy == FILE_PER_LABEL_FARM)
242 if(current_package < total_packages)
244 result = packages[current_package];
249 if(strategy == SINGLE_PASS_FARM)
251 result = packaging_engine->get_package_single_farm(frames_per_second,
256 if(strategy == BRENDER_FARM)
258 //printf("Dispatcher::get_package 1 %d %d\n", video_position, video_end);
259 if(video_position < video_end)
261 // Allocate new packages
262 if(total_packages == 0)
264 total_allocated = 256;
265 packages = new RenderPackage*[total_allocated];
268 if(total_packages >= total_allocated)
270 RenderPackage **old_packages = packages;
271 total_allocated *= 2;
272 packages = new RenderPackage*[total_allocated];
275 total_packages * sizeof(RenderPackage*));
276 delete [] old_packages;
279 // Calculate package.
280 result = packages[total_packages] = new RenderPackage;
283 // No load balancing data exists
284 if(EQUIV(frames_per_second, 0) ||
285 EQUIV(avg_frames_per_second, 0))
287 scaled_len = package_len;
290 // Load balancing data exists
292 scaled_len = package_len *
294 avg_frames_per_second;
297 scaled_len = MAX(scaled_len, min_package_len);
299 // Always an image file sequence
300 result->audio_start = audio_position;
301 result->video_start = video_position;
302 result->audio_end = result->audio_start +
303 Units::to_int64(scaled_len * default_asset->sample_rate);
304 result->video_end = result->video_start +
305 Units::to_int64(scaled_len * default_asset->frame_rate);
306 if(result->video_end == result->video_start) result->video_end++;
307 audio_position = result->audio_end;
308 video_position = result->video_end;
309 result->audio_do = default_asset->audio_data;
310 result->video_do = default_asset->video_data;
313 // The frame numbers are read from the vframe objects themselves.
314 Render::create_filename(result->path,
319 //printf("PackageDispatcher::get_package 2 %s\n", result->path);
327 package_lock->unlock();
329 //printf("PackageDispatcher::get_package %p\n", result);
334 ArrayList<Asset*>* PackageDispatcher::get_asset_list()
336 ArrayList<Asset*> *assets = new ArrayList<Asset*>;
338 for(int i = 0; i < current_package; i++)
340 Asset *asset = new Asset;
341 *asset = *default_asset;
342 strcpy(asset->path, packages[i]->path);
343 asset->video_length = packages[i]->video_end - packages[i]->video_start;
344 asset->audio_length = packages[i]->audio_end - packages[i]->audio_start;
345 assets->append(asset);
351 int64_t PackageDispatcher::get_progress_max()
353 if (strategy == SINGLE_PASS_FARM)
354 return packaging_engine->get_progress_max();
356 return Units::to_int64(default_asset->sample_rate *
357 (total_end - total_start)) +
358 Units::to_int64(preferences->render_preroll *
360 default_asset->sample_rate);
363 int PackageDispatcher::get_total_packages()
365 return total_allocated;
368 int PackageDispatcher::packages_are_done()
370 if (packaging_engine)
371 return packaging_engine->packages_are_done();