1 #include "packagingengine.h"
2 #include "preferences.h"
3 #include "edlsession.h"
9 // Default packaging engine implementation, simply split the range up, and consider client's speed
11 PackagingEngineDefault::PackagingEngineDefault()
16 PackagingEngineDefault::~PackagingEngineDefault()
20 for(int i = 0; i < total_packages; i++)
27 int PackagingEngineDefault::create_packages_single_farm(
29 Preferences *preferences,
34 this->total_start = total_start;
35 this->total_end = total_end;
37 this->preferences = preferences;
38 this->default_asset = default_asset;
39 audio_position = Units::to_int64(total_start * default_asset->sample_rate);
40 video_position = Units::to_int64(total_start * default_asset->frame_rate);
41 audio_end = Units::to_int64(total_end * default_asset->sample_rate);
42 video_end = Units::to_int64(total_end * default_asset->frame_rate);
45 double total_len = total_end - total_start;
46 total_packages = preferences->renderfarm_job_count;
47 total_allocated = total_packages + preferences->get_enabled_nodes();
48 packages = new RenderPackage*[total_allocated];
49 package_len = total_len / total_packages;
50 min_package_len = 2.0 / edl->session->frame_rate;
53 //printf("PackageDispatcher::create_packages: %f / %d = %f\n", total_len, total_packages, package_len);
54 int current_number; // The number being injected into the filename.
55 int number_start; // Character in the filename path at which the number begins
56 int total_digits; // Total number of digits including padding the user specified.
58 Render::get_starting_number(default_asset->path,
64 for(int i = 0; i < total_allocated; i++)
66 RenderPackage *package = packages[i] = new RenderPackage;
68 // Create file number differently if image file sequence
69 Render::create_filename(package->path,
79 RenderPackage* PackagingEngineDefault::get_package_single_farm(double frames_per_second,
84 //printf("PackageDispatcher::get_package %ld %ld %ld %ld\n", audio_position, video_position, audio_end, video_end);
86 RenderPackage *result = 0;
87 float avg_frames_per_second = preferences->get_avg_rate(use_local_rate);
89 if(audio_position < audio_end ||
90 video_position < video_end)
94 result = packages[current_package];
95 result->audio_start = audio_position;
96 result->video_start = video_position;
97 result->video_do = default_asset->video_data;
98 result->audio_do = default_asset->audio_data;
100 if(current_package >= total_allocated - 1)
102 result->audio_end = audio_end;
103 result->video_end = video_end;
104 audio_position = result->audio_end;
105 video_position = result->video_end;
108 // No useful speed data. May get infinity for real fast jobs.
109 if(frames_per_second > 0x7fffff || frames_per_second < 0 ||
110 EQUIV(frames_per_second, 0) ||
111 EQUIV(avg_frames_per_second, 0))
113 scaled_len = MAX(package_len, min_package_len);
115 result->audio_end = audio_position +
116 Units::round(scaled_len * default_asset->sample_rate);
117 result->video_end = video_position +
118 Units::round(scaled_len * default_asset->frame_rate);
120 // If we get here without any useful speed data render the whole thing.
121 if(current_package >= total_packages - 1)
123 result->audio_end = audio_end;
124 result->video_end = video_end;
128 result->audio_end = MIN(audio_end, result->audio_end);
129 result->video_end = MIN(video_end, result->video_end);
132 audio_position = result->audio_end;
133 video_position = result->video_end;
136 // Useful speed data and future packages exist. Scale the
137 // package size to fit the requestor.
139 scaled_len = package_len *
141 avg_frames_per_second;
142 scaled_len = MAX(scaled_len, min_package_len);
144 result->audio_end = result->audio_start +
145 Units::to_int64(scaled_len * default_asset->sample_rate);
146 result->video_end = result->video_start +
147 Units::to_int64(scaled_len * default_asset->frame_rate);
149 result->audio_end = MIN(audio_end, result->audio_end);
150 result->video_end = MIN(video_end, result->video_end);
152 audio_position = result->audio_end;
153 video_position = result->video_end;
155 // Package size is no longer touched between total_packages and total_allocated
156 if(current_package < total_packages - 1)
158 package_len = (double)(audio_end - audio_position) /
159 (double)default_asset->sample_rate /
160 (double)(total_packages - current_package);
166 //printf("Dispatcher::get_package 50 %lld %lld %lld %lld\n",
167 //result->audio_start,
168 //result->video_start,
170 //result->video_end);
176 void PackagingEngineDefault::get_package_paths(ArrayList<char*> *path_list)
178 for(int i = 0; i < total_allocated; i++)
180 path_list->append(strdup(packages[i]->path));
182 path_list->set_free();
185 int64_t PackagingEngineDefault::get_progress_max()
187 return Units::to_int64(default_asset->sample_rate *
188 (total_end - total_start)) +
189 Units::to_int64(preferences->render_preroll *
191 default_asset->sample_rate);
194 int PackagingEngineDefault::packages_are_done()