4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
22 #include "packagingengine.h"
23 #include "preferences.h"
24 #include "edlsession.h"
30 // Default packaging engine implementation, simply split the range up, and consider client's speed
32 PackagingEngineDefault::PackagingEngineDefault()
37 PackagingEngineDefault::~PackagingEngineDefault()
41 for(int i = 0; i < total_packages; i++)
48 int PackagingEngineDefault::create_packages_single_farm(
50 Preferences *preferences,
55 this->total_start = total_start;
56 this->total_end = total_end;
58 this->preferences = preferences;
59 this->default_asset = default_asset;
60 audio_position = Units::to_int64(total_start * default_asset->sample_rate);
61 video_position = Units::to_int64(total_start * default_asset->frame_rate);
62 audio_end = Units::to_int64(total_end * default_asset->sample_rate);
63 video_end = Units::to_int64(total_end * default_asset->frame_rate);
66 double total_len = total_end - total_start;
67 total_packages = preferences->renderfarm_job_count;
68 total_allocated = total_packages + preferences->get_enabled_nodes();
69 packages = new RenderPackage*[total_allocated];
70 package_len = total_len / total_packages;
71 min_package_len = 2.0 / edl->session->frame_rate;
74 //printf("PackageDispatcher::create_packages: %f / %d = %f\n", total_len, total_packages, package_len);
75 int current_number; // The number being injected into the filename.
76 int number_start; // Character in the filename path at which the number begins
77 int total_digits; // Total number of digits including padding the user specified.
79 Render::get_starting_number(default_asset->path,
85 for(int i = 0; i < total_allocated; i++)
87 RenderPackage *package = packages[i] = new RenderPackage;
89 // Create file number differently if image file sequence
90 Render::create_filename(package->path,
100 RenderPackage* PackagingEngineDefault::get_package_single_farm(double frames_per_second,
105 //printf("PackageDispatcher::get_package %ld %ld %ld %ld\n", audio_position, video_position, audio_end, video_end);
107 RenderPackage *result = 0;
108 float avg_frames_per_second = preferences->get_avg_rate(use_local_rate);
110 if(audio_position < audio_end ||
111 video_position < video_end)
115 result = packages[current_package];
116 result->audio_start = audio_position;
117 result->video_start = video_position;
118 result->video_do = default_asset->video_data;
119 result->audio_do = default_asset->audio_data;
121 if(current_package >= total_allocated - 1)
123 result->audio_end = audio_end;
124 result->video_end = video_end;
125 audio_position = result->audio_end;
126 video_position = result->video_end;
129 // No useful speed data. May get infinity for real fast jobs.
130 if(frames_per_second > 0x7fffff || frames_per_second < 0 ||
131 EQUIV(frames_per_second, 0) ||
132 EQUIV(avg_frames_per_second, 0))
134 scaled_len = MAX(package_len, min_package_len);
136 result->audio_end = audio_position +
137 Units::round(scaled_len * default_asset->sample_rate);
138 result->video_end = video_position +
139 Units::round(scaled_len * default_asset->frame_rate);
141 // If we get here without any useful speed data render the whole thing.
142 if(current_package >= total_packages - 1)
144 result->audio_end = audio_end;
145 result->video_end = video_end;
149 result->audio_end = MIN(audio_end, result->audio_end);
150 result->video_end = MIN(video_end, result->video_end);
153 audio_position = result->audio_end;
154 video_position = result->video_end;
157 // Useful speed data and future packages exist. Scale the
158 // package size to fit the requestor.
160 scaled_len = package_len *
162 avg_frames_per_second;
163 scaled_len = MAX(scaled_len, min_package_len);
165 result->audio_end = result->audio_start +
166 Units::to_int64(scaled_len * default_asset->sample_rate);
167 result->video_end = result->video_start +
168 Units::to_int64(scaled_len * default_asset->frame_rate);
170 result->audio_end = MIN(audio_end, result->audio_end);
171 result->video_end = MIN(video_end, result->video_end);
173 audio_position = result->audio_end;
174 video_position = result->video_end;
176 // Package size is no longer touched between total_packages and total_allocated
177 if(current_package < total_packages - 1)
179 package_len = (double)(audio_end - audio_position) /
180 (double)default_asset->sample_rate /
181 (double)(total_packages - current_package);
187 //printf("Dispatcher::get_package 50 %lld %lld %lld %lld\n",
188 //result->audio_start,
189 //result->video_start,
191 //result->video_end);
197 void PackagingEngineDefault::get_package_paths(ArrayList<char*> *path_list)
199 for(int i = 0; i < total_allocated; i++)
201 path_list->append(strdup(packages[i]->path));
203 path_list->set_free();
206 int64_t PackagingEngineDefault::get_progress_max()
208 return Units::to_int64(default_asset->sample_rate *
209 (total_end - total_start)) +
210 Units::to_int64(preferences->render_preroll *
212 default_asset->sample_rate);
215 int PackagingEngineDefault::packages_are_done()