2 #include "audioconfig.h"
3 #include "audiodevice.inc"
8 #include "filesystem.h"
10 #include "preferences.h"
12 #include "videoconfig.h"
13 #include "videodevice.inc"
16 //#define CLAMP(x, y, z) (x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x)))
29 Preferences::Preferences()
34 preferences_lock = new Mutex;
35 sprintf(index_directory, BCASTDIR);
36 if(strlen(index_directory))
37 fs.complete_path(index_directory);
44 force_uniprocessor = 0;
45 renderfarm_port = DEAMON_PORT;
48 renderfarm_mountpoint[0] = 0;
50 renderfarm_job_count = 1;
51 processors = calculate_processors();
53 // Default brender asset
54 brender_asset = new Asset;
55 brender_asset->audio_data = 0;
56 brender_asset->video_data = 1;
57 sprintf(brender_asset->path, "/tmp/brender");
58 brender_asset->format = FILE_JPEG_LIST;
59 brender_asset->jpeg_quality = 80;
66 Preferences::~Preferences()
69 delete preferences_lock;
72 void Preferences::copy_rates_from(Preferences *preferences)
74 preferences_lock->lock();
75 // Need to match node titles in case the order changed and in case
76 // one of the nodes in the source is the master node.
77 local_rate = preferences->local_rate;
80 j < preferences->renderfarm_nodes.total;
83 double new_rate = preferences->renderfarm_rate.values[j];
84 // Put in the master node
85 if(preferences->renderfarm_nodes.values[j][0] == '/')
87 if(!EQUIV(new_rate, 0.0))
88 local_rate = new_rate;
91 // Search for local node and copy it to that node
92 if(!EQUIV(new_rate, 0.0))
94 for(int i = 0; i < renderfarm_nodes.total; i++)
96 if(!strcmp(preferences->renderfarm_nodes.values[j], renderfarm_nodes.values[i]) &&
97 preferences->renderfarm_ports.values[j] == renderfarm_ports.values[i])
99 renderfarm_rate.values[i] = new_rate;
106 //printf("Preferences::copy_rates_from 1 %f %f\n", local_rate, preferences->local_rate);
107 preferences_lock->unlock();
110 Preferences& Preferences::operator=(Preferences &that)
112 // ================================= Performance ================================
113 strcpy(index_directory, that.index_directory);
114 index_size = that.index_size;
115 index_count = that.index_count;
116 use_thumbnails = that.use_thumbnails;
117 strcpy(global_plugin_dir, that.global_plugin_dir);
118 strcpy(theme, that.theme);
120 cache_size = that.cache_size;
121 force_uniprocessor = that.force_uniprocessor;
122 processors = calculate_processors();
123 renderfarm_nodes.remove_all_objects();
124 renderfarm_ports.remove_all();
125 renderfarm_enabled.remove_all();
126 renderfarm_rate.remove_all();
127 local_rate = that.local_rate;
128 for(int i = 0; i < that.renderfarm_nodes.total; i++)
130 add_node(that.renderfarm_nodes.values[i],
131 that.renderfarm_ports.values[i],
132 that.renderfarm_enabled.values[i],
133 that.renderfarm_rate.values[i]);
135 use_renderfarm = that.use_renderfarm;
136 renderfarm_port = that.renderfarm_port;
137 render_preroll = that.render_preroll;
138 brender_preroll = that.brender_preroll;
139 renderfarm_job_count = that.renderfarm_job_count;
140 renderfarm_vfs = that.renderfarm_vfs;
141 strcpy(renderfarm_mountpoint, that.renderfarm_mountpoint);
142 renderfarm_consolidate = that.renderfarm_consolidate;
143 use_brender = that.use_brender;
144 brender_fragment = that.brender_fragment;
145 *brender_asset = *that.brender_asset;
150 if(strlen(index_directory))
152 fs.complete_path(index_directory);
153 fs.add_end_slash(index_directory);
156 if(strlen(global_plugin_dir))
158 fs.complete_path(global_plugin_dir);
159 fs.add_end_slash(global_plugin_dir);
162 renderfarm_job_count = MAX(renderfarm_job_count, 1);
163 CLAMP(cache_size, 1, 100);
168 int Preferences::load_defaults(Defaults *defaults)
170 char string[BCTEXTLEN];
172 defaults->get("INDEX_DIRECTORY", index_directory);
173 index_size = defaults->get("INDEX_SIZE", index_size);
174 index_count = defaults->get("INDEX_COUNT", index_count);
175 use_thumbnails = defaults->get("USE_THUMBNAILS", use_thumbnails);
177 sprintf(global_plugin_dir, "/usr/lib/cinelerra");
178 defaults->get("GLOBAL_PLUGIN_DIR", global_plugin_dir);
179 if(getenv("GLOBAL_PLUGIN_DIR"))
181 strcpy(global_plugin_dir, getenv("GLOBAL_PLUGIN_DIR"));
184 strcpy(theme, DEFAULT_THEME);
185 defaults->get("THEME", theme);
188 brender_asset->load_defaults(defaults,
198 force_uniprocessor = defaults->get("FORCE_UNIPROCESSOR", 0);
199 processors = calculate_processors();
200 use_brender = defaults->get("USE_BRENDER", use_brender);
201 brender_fragment = defaults->get("BRENDER_FRAGMENT", brender_fragment);
202 cache_size = defaults->get("CACHE_SIZE", cache_size);
203 local_rate = defaults->get("LOCAL_RATE", local_rate);
204 use_renderfarm = defaults->get("USE_RENDERFARM", use_renderfarm);
205 renderfarm_port = defaults->get("RENDERFARM_PORT", renderfarm_port);
206 render_preroll = defaults->get("RENDERFARM_PREROLL", render_preroll);
207 brender_preroll = defaults->get("BRENDER_PREROLL", brender_preroll);
208 renderfarm_job_count = defaults->get("RENDERFARM_JOBS_COUNT", renderfarm_job_count);
209 renderfarm_consolidate = defaults->get("RENDERFARM_CONSOLIDATE", renderfarm_consolidate);
210 renderfarm_vfs = defaults->get("RENDERFARM_VFS", renderfarm_vfs);
211 defaults->get("RENDERFARM_MOUNTPOINT", renderfarm_mountpoint);
212 int renderfarm_total = defaults->get("RENDERFARM_TOTAL", 0);
214 for(int i = 0; i < renderfarm_total; i++)
216 sprintf(string, "RENDERFARM_NODE%d", i);
217 char result[BCTEXTLEN];
219 int result_enabled = 0;
220 float result_rate = 0.0;
223 defaults->get(string, result);
225 sprintf(string, "RENDERFARM_PORT%d", i);
226 result_port = defaults->get(string, renderfarm_port);
228 sprintf(string, "RENDERFARM_ENABLED%d", i);
229 result_enabled = defaults->get(string, result_enabled);
231 sprintf(string, "RENDERFARM_RATE%d", i);
232 result_rate = defaults->get(string, result_rate);
236 add_node(result, result_port, result_enabled, result_rate);
243 int Preferences::save_defaults(Defaults *defaults)
245 char string[BCTEXTLEN];
246 defaults->update("CACHE_SIZE", cache_size);
247 defaults->update("INDEX_DIRECTORY", index_directory);
248 defaults->update("INDEX_SIZE", index_size);
249 defaults->update("INDEX_COUNT", index_count);
250 defaults->update("USE_THUMBNAILS", use_thumbnails);
251 defaults->update("GLOBAL_PLUGIN_DIR", global_plugin_dir);
252 defaults->update("THEME", theme);
256 defaults->update("FORCE_UNIPROCESSOR", force_uniprocessor);
257 brender_asset->save_defaults(defaults,
264 defaults->update("USE_BRENDER", use_brender);
265 defaults->update("BRENDER_FRAGMENT", brender_fragment);
266 defaults->update("USE_RENDERFARM", use_renderfarm);
267 defaults->update("LOCAL_RATE", local_rate);
268 defaults->update("RENDERFARM_PORT", renderfarm_port);
269 defaults->update("RENDERFARM_PREROLL", render_preroll);
270 defaults->update("BRENDER_PREROLL", brender_preroll);
271 defaults->update("RENDERFARM_VFS", renderfarm_vfs);
272 defaults->update("RENDERFARM_MOUNTPOINT", renderfarm_mountpoint);
273 defaults->update("RENDERFARM_JOBS_COUNT", renderfarm_job_count);
274 defaults->update("RENDERFARM_CONSOLIDATE", renderfarm_consolidate);
275 defaults->update("RENDERFARM_TOTAL", (int64_t)renderfarm_nodes.total);
276 for(int i = 0; i < renderfarm_nodes.total; i++)
278 sprintf(string, "RENDERFARM_NODE%d", i);
279 defaults->update(string, renderfarm_nodes.values[i]);
280 sprintf(string, "RENDERFARM_PORT%d", i);
281 defaults->update(string, renderfarm_ports.values[i]);
282 sprintf(string, "RENDERFARM_ENABLED%d", i);
283 defaults->update(string, renderfarm_enabled.values[i]);
284 sprintf(string, "RENDERFARM_RATE%d", i);
285 defaults->update(string, renderfarm_rate.values[i]);
291 void Preferences::add_node(char *text, int port, int enabled, float rate)
293 if(text[0] == 0) return;
295 preferences_lock->lock();
296 char *new_item = new char[strlen(text) + 1];
297 strcpy(new_item, text);
298 renderfarm_nodes.append(new_item);
299 renderfarm_ports.append(port);
300 renderfarm_enabled.append(enabled);
301 renderfarm_rate.append(rate);
302 preferences_lock->unlock();
305 void Preferences::delete_node(int number)
307 preferences_lock->lock();
308 if(number < renderfarm_nodes.total)
310 delete [] renderfarm_nodes.values[number];
311 renderfarm_nodes.remove_number(number);
312 renderfarm_ports.remove_number(number);
313 renderfarm_enabled.remove_number(number);
314 renderfarm_rate.remove_number(number);
316 preferences_lock->unlock();
319 void Preferences::delete_nodes()
321 preferences_lock->lock();
322 for(int i = 0; i < renderfarm_nodes.total; i++)
323 delete [] renderfarm_nodes.values[i];
324 renderfarm_nodes.remove_all();
325 renderfarm_ports.remove_all();
326 renderfarm_enabled.remove_all();
327 renderfarm_rate.remove_all();
328 preferences_lock->unlock();
331 void Preferences::reset_rates()
333 for(int i = 0; i < renderfarm_nodes.total; i++)
335 renderfarm_rate.values[i] = 0.0;
340 void Preferences::set_rate(float rate, int node)
342 //printf("Preferences::set_rate %f %d\n", rate, node);
350 for(int i = 0; i < renderfarm_nodes.total; i++)
352 if(renderfarm_enabled.values[i]) total++;
353 if(total == node + 1)
355 renderfarm_rate.values[i] = rate;
362 float Preferences::get_avg_rate(int use_master_node)
364 preferences_lock->lock();
366 if(renderfarm_rate.total)
371 if(EQUIV(local_rate, 0.0))
373 preferences_lock->unlock();
383 for(int i = 0; i < renderfarm_rate.total; i++)
385 if(renderfarm_enabled.values[i])
388 total += renderfarm_rate.values[i];
389 if(EQUIV(renderfarm_rate.values[i], 0.0))
391 preferences_lock->unlock();
402 preferences_lock->unlock();
407 void Preferences::sort_nodes()
414 for(int i = 0; i < renderfarm_nodes.total - 1; i++)
416 if(strcmp(renderfarm_nodes.values[i], renderfarm_nodes.values[i + 1]) > 0)
418 char *temp = renderfarm_nodes.values[i];
419 int temp_port = renderfarm_ports.values[i];
421 renderfarm_nodes.values[i] = renderfarm_nodes.values[i + 1];
422 renderfarm_nodes.values[i + 1] = temp;
424 renderfarm_ports.values[i] = renderfarm_ports.values[i + 1];
425 renderfarm_ports.values[i + 1] = temp_port;
427 renderfarm_enabled.values[i] = renderfarm_enabled.values[i + 1];
428 renderfarm_enabled.values[i + 1] = temp_port;
430 renderfarm_rate.values[i] = renderfarm_rate.values[i + 1];
431 renderfarm_rate.values[i + 1] = temp_port;
438 void Preferences::edit_node(int number,
443 char *new_item = new char[strlen(new_text) + 1];
444 strcpy(new_item, new_text);
446 delete [] renderfarm_nodes.values[number];
447 renderfarm_nodes.values[number] = new_item;
448 renderfarm_ports.values[number] = new_port;
449 renderfarm_enabled.values[number] = new_enabled;
452 int Preferences::get_enabled_nodes()
455 for(int i = 0; i < renderfarm_enabled.total; i++)
456 if(renderfarm_enabled.values[i]) result++;
460 char* Preferences::get_node_hostname(int number)
463 for(int i = 0; i < renderfarm_nodes.total; i++)
465 if(renderfarm_enabled.values[i])
468 return renderfarm_nodes.values[i];
476 int Preferences::get_node_port(int number)
479 for(int i = 0; i < renderfarm_ports.total; i++)
481 if(renderfarm_enabled.values[i])
484 return renderfarm_ports.values[i];
493 int Preferences::calculate_processors()
495 /* Get processor count */
499 if(force_uniprocessor) return 1;
501 if(proc = fopen("/proc/cpuinfo", "r"))
506 fgets(string, 1024, proc);
507 if(!strncasecmp(string, "processor", 9))
509 char *ptr = strchr(string, ':');
513 result = atol(ptr) + 1;
517 if(!strncasecmp(string, "cpus detected", 13))
519 char *ptr = strchr(string, ':');