From c2c09a4c97194b07dbd1eae82aa0226d9774f350 Mon Sep 17 00:00:00 2001 From: Good Guy Date: Tue, 16 Jan 2018 15:24:01 -0700 Subject: [PATCH] add 2pass ffmpeg cin_stats_file, renderfarm watchdog pref, fix brender hang, sort ffmpeg fmts --- cinelerra-5.1/cinelerra/ffmpeg.C | 122 ++++++++- cinelerra-5.1/cinelerra/ffmpeg.h | 10 + cinelerra-5.1/cinelerra/formatpopup.C | 1 + cinelerra-5.1/cinelerra/mwindow.C | 5 +- cinelerra-5.1/cinelerra/performanceprefs.C | 254 +++++-------------- cinelerra-5.1/cinelerra/performanceprefs.h | 46 ++-- cinelerra-5.1/cinelerra/performanceprefs.inc | 1 + cinelerra-5.1/cinelerra/preferences.C | 194 ++++++-------- cinelerra-5.1/cinelerra/preferences.h | 2 + cinelerra-5.1/cinelerra/renderfarm.C | 215 +++++++--------- cinelerra-5.1/cinelerra/renderfarm.h | 7 +- cinelerra-5.1/cinelerra/renderfarmclient.C | 12 +- cinelerra-5.1/cinelerra/renderfarmclient.h | 2 +- cinelerra-5.1/ffmpeg/video/pass1of2_vp9.webm | 13 + cinelerra-5.1/ffmpeg/video/pass2of2_vp9.webm | 13 + cinelerra-5.1/guicast/bclistboxitem.C | 11 + cinelerra-5.1/guicast/bclistboxitem.h | 3 + 17 files changed, 438 insertions(+), 473 deletions(-) create mode 100644 cinelerra-5.1/ffmpeg/video/pass1of2_vp9.webm create mode 100644 cinelerra-5.1/ffmpeg/video/pass2of2_vp9.webm diff --git a/cinelerra-5.1/cinelerra/ffmpeg.C b/cinelerra-5.1/cinelerra/ffmpeg.C index 75131dca..0d3fe73a 100644 --- a/cinelerra-5.1/cinelerra/ffmpeg.C +++ b/cinelerra-5.1/cinelerra/ffmpeg.C @@ -7,6 +7,8 @@ #include #include #include +#include + // work arounds (centos) #include #ifndef INT64_MAX @@ -251,6 +253,10 @@ FFStream::FFStream(FFMPEG *ffmpeg, AVStream *st, int fidx) need_packet = 1; frame = fframe = 0; bsfc = 0; + stats_fp = 0; + stats_filename = 0; + stats_in = 0; + pass = 0; } FFStream::~FFStream() @@ -264,6 +270,9 @@ FFStream::~FFStream() if( frame ) av_frame_free(&frame); if( fframe ) av_frame_free(&fframe); delete frm_lock; + if( stats_fp ) fclose(stats_fp); + if( stats_in ) av_freep(&stats_in); + delete [] stats_filename; } void FFStream::ff_lock(const char *cp) @@ -475,6 +484,10 @@ int FFStream::encode_frame(AVFrame *frame) ret = write_packet(opkt); if( ret < 0 ) break; ++pkts; + if( stats_fp ) { + ret = write_stats_file(); + if( ret < 0 ) break; + } } ff_err(ret, "FFStream::encode_frame: encode failed\n"); return -1; @@ -485,11 +498,75 @@ int FFStream::flush() if( writing < 0 ) return -1; int ret = encode_frame(0); + if( ret >= 0 && stats_fp ) { + ret = write_stats_file(); + close_stats_file(); + } if( ret < 0 ) ff_err(ret, "FFStream::flush"); return ret >= 0 ? 0 : 1; } + +int FFStream::open_stats_file() +{ + stats_fp = fopen(stats_filename,"w"); + return stats_fp ? 0 : AVERROR(errno); +} + +int FFStream::close_stats_file() +{ + if( stats_fp ) { + fclose(stats_fp); stats_fp = 0; + } + return 0; +} + +int FFStream::read_stats_file() +{ + int64_t len = 0; struct stat stats_st; + int fd = open(stats_filename, O_RDONLY); + int ret = fd >= 0 ? 0: ENOENT; + if( !ret && fstat(fd, &stats_st) ) + ret = EINVAL; + if( !ret ) { + len = stats_st.st_size; + stats_in = (char *)av_malloc(len+1); + if( !stats_in ) + ret = ENOMEM; + } + if( !ret && read(fd, stats_in, len+1) != len ) + ret = EIO; + if( !ret ) { + stats_in[len] = 0; + avctx->stats_in = stats_in; + } + if( fd >= 0 ) + close(fd); + return !ret ? 0 : AVERROR(ret); +} + +int FFStream::write_stats_file() +{ + int ret = 0; + if( avctx->stats_out && (ret=strlen(avctx->stats_out)) > 0 ) { + int len = fwrite(avctx->stats_out, 1, ret, stats_fp); + if( ret != len ) + ff_err(ret = AVERROR(errno), "FFStream::write_stats_file"); + } + return ret; +} + +int FFStream::init_stats_file() +{ + int ret = 0; + if( (pass & 2) && (ret = read_stats_file()) < 0 ) + ff_err(ret, "stat file read: %s", stats_filename); + if( (pass & 1) && (ret=open_stats_file()) < 0 ) + ff_err(ret, "stat file open: %s", stats_filename); + return ret >= 0 ? 0 : ret; +} + int FFStream::seek(int64_t no, double rate) { // default ffmpeg native seek @@ -2001,6 +2078,9 @@ int FFMPEG::open_encoder(const char *type, const char *spec) ret = 1; break; } + av_reduce(&frame_rate.num, &frame_rate.den, + frame_rate.num, frame_rate.den, INT_MAX); + ctx->framerate = (AVRational) { frame_rate.num, frame_rate.den }; ctx->time_base = (AVRational) { frame_rate.den, frame_rate.num }; st->avg_frame_rate = frame_rate; st->time_base = ctx->time_base; @@ -2013,11 +2093,44 @@ int FFMPEG::open_encoder(const char *type, const char *spec) eprintf(_("not audio/video, %s:%s\n"), codec_name, filename); ret = 1; } + + if( ctx ) { + AVDictionaryEntry *tag; + if( (tag=av_dict_get(sopts, "cin_stats_filename", NULL, 0)) != 0 ) { + char suffix[BCSTRLEN]; sprintf(suffix,"-%d.log",fst->fidx); + fst->stats_filename = cstrcat(2, tag->value, suffix); + } + if( (tag=av_dict_get(sopts, "flags", NULL, 0)) != 0 ) { + int pass = fst->pass; + char *cp = tag->value; + while( *cp ) { + int ch = *cp++, pfx = ch=='-' ? -1 : ch=='+' ? 1 : 0; + if( !isalnum(!pfx ? ch : (ch=*cp++)) ) continue; + char id[BCSTRLEN], *bp = id, *ep = bp+sizeof(id)-1; + for( *bp++=ch; isalnum(ch=*cp); ++cp ) + if( bp < ep ) *bp++ = ch; + *bp = 0; + if( !strcmp(id, "pass1") ) { + pass = pfx<0 ? (pass&~1) : pfx>0 ? (pass|1) : 1; + } + else if( !strcmp(id, "pass2") ) { + pass = pfx<0 ? (pass&~2) : pfx>0 ? (pass|2) : 2; + } + } + if( (fst->pass=pass) ) { + if( pass & 1 ) ctx->flags |= AV_CODEC_FLAG_PASS1; + if( pass & 2 ) ctx->flags |= AV_CODEC_FLAG_PASS2; + } + } + } } if( !ret ) { if( fmt_ctx->oformat->flags & AVFMT_GLOBALHEADER ) ctx->flags |= CODEC_FLAG_GLOBAL_HEADER; - + if( fst->stats_filename && (ret=fst->init_stats_file()) ) + eprintf(_("error: stats file = %s\n"), fst->stats_filename); + } + if( !ret ) { av_dict_set(&sopts, "cin_bitrate", 0, 0); av_dict_set(&sopts, "cin_quality", 0, 0); @@ -2029,6 +2142,13 @@ int FFMPEG::open_encoder(const char *type, const char *spec) if( ret < 0 ) fprintf(stderr, "Could not copy the stream parameters\n"); } + if( ret >= 0 ) { +_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") + ret = avcodec_copy_context(st->codec, ctx); +_Pragma("GCC diagnostic warning \"-Wdeprecated-declarations\"") + if( ret < 0 ) + fprintf(stderr, "Could not copy the stream context\n"); + } if( ret < 0 ) { ff_err(ret,"FFMPEG::open_encoder"); eprintf(_("open failed %s:%s\n"), codec_name, filename); diff --git a/cinelerra-5.1/cinelerra/ffmpeg.h b/cinelerra-5.1/cinelerra/ffmpeg.h index 9a9f8552..11194792 100644 --- a/cinelerra-5.1/cinelerra/ffmpeg.h +++ b/cinelerra-5.1/cinelerra/ffmpeg.h @@ -99,6 +99,11 @@ public: int load_filter(AVFrame *frame); int read_filter(AVFrame *frame); int read_frame(AVFrame *frame); + int open_stats_file(); + int close_stats_file(); + int read_stats_file(); + int write_stats_file(); + int init_stats_file(); FFMPEG *ffmpeg; AVStream *st; @@ -124,6 +129,11 @@ public: int reading, writing; int seeked, eof; + FILE *stats_fp; + char *stats_filename; + char *stats_in; + int pass; + int st_eof() { return eof; } void st_eof(int v) { eof = v; } }; diff --git a/cinelerra-5.1/cinelerra/formatpopup.C b/cinelerra-5.1/cinelerra/formatpopup.C index d6ff3363..03e94dd9 100644 --- a/cinelerra-5.1/cinelerra/formatpopup.C +++ b/cinelerra-5.1/cinelerra/formatpopup.C @@ -132,6 +132,7 @@ void FFMPEGPopup::create_objects() } } + BC_ListBoxItem::sort_items(ffmpeg_types); update(&ffmpeg_types, 0, 0, 1); } diff --git a/cinelerra-5.1/cinelerra/mwindow.C b/cinelerra-5.1/cinelerra/mwindow.C index 9ab96a9e..1f69fd50 100644 --- a/cinelerra-5.1/cinelerra/mwindow.C +++ b/cinelerra-5.1/cinelerra/mwindow.C @@ -1556,6 +1556,7 @@ void MWindow::restart_brender() void MWindow::stop_brender() { if( !brender ) return; +// cannot be holding mwindow->gui display lock brender->stop(); } @@ -1598,7 +1599,9 @@ void MWindow::set_brender_active(int v, int update) } else { edl->session->brender_start = edl->session->brender_end = 0; + gui->unlock_window(); stop_brender(); + gui->lock_window("MWindow::set_brender_active"); } if( update ) { gui->update_timebar(0); @@ -3237,7 +3240,6 @@ void MWindow::update_project(int load_mode) const int debug = 0; if(debug) PRINT_TRACE - init_brender(); edl->tracks->update_y_pixels(theme); if(debug) PRINT_TRACE @@ -3251,6 +3253,7 @@ void MWindow::update_project(int load_mode) gui->update(1, 1, 1, 1, 1, 1, 1); if(debug) PRINT_TRACE gui->unlock_window(); + init_brender(); cwindow->gui->lock_window("MWindow::update_project 1"); cwindow->update(0, 0, 1, 1, 1); diff --git a/cinelerra-5.1/cinelerra/performanceprefs.C b/cinelerra-5.1/cinelerra/performanceprefs.C index 7adb020b..5c35553f 100644 --- a/cinelerra-5.1/cinelerra/performanceprefs.C +++ b/cinelerra-5.1/cinelerra/performanceprefs.C @@ -70,16 +70,7 @@ void PerformancePrefs::create_objects() xmargin1 = x = mwindow->theme->preferencesoptions_x; y = mwindow->theme->preferencesoptions_y; -// add_subwindow(new BC_Title(x, -// y, -// _("Time Format"), -// LARGEFONT, -// resources->text_default)); -// -// y += get_text_height(LARGEFONT) + 5; - int y0 = y; - win = add_subwindow(new BC_Title(x, y + 5, _("Cache size (MB):"), MEDIUMFONT, resources->text_default)); maxw = win->get_w(); @@ -121,31 +112,23 @@ void PerformancePrefs::create_objects() y += win->get_h() + 10; win = add_subwindow(new BC_Title(x, y, _("Frames per background rendering job:"))); y += win->get_h() + 5; - PrefsBRenderFragment *brender_fragment = new PrefsBRenderFragment(pwindow, - this, - x + xmargin3, - y); + PrefsBRenderFragment *brender_fragment = new PrefsBRenderFragment(pwindow, this, + x + xmargin3, y); brender_fragment->create_objects(); y += brender_fragment->get_h() + 5; win = add_subwindow(new BC_Title(x, y, _("Frames to preroll background:"))); y += win->get_h() + 5; - PrefsBRenderPreroll *bpreroll = new PrefsBRenderPreroll(pwindow, - this, - x + xmargin3, - y + 5); + PrefsBRenderPreroll *bpreroll = new PrefsBRenderPreroll(pwindow, this, + x + xmargin3, y + 5); bpreroll->create_objects(); y += bpreroll->get_h() + 20; - x += xmargin4; add_subwindow(new BC_Title(x, y1, _("Output for background rendering:"))); y1 += 20; - brender_tools = - new FormatTools(mwindow, - this, + brender_tools = new FormatTools(mwindow, this, pwindow->thread->preferences->brender_asset); - brender_tools->create_objects(x, - y1, + brender_tools->create_objects(x, y1, 0, // Include tools for audio 1, // Include tools for video 0, // Include checkbox for audio @@ -163,84 +146,42 @@ void PerformancePrefs::create_objects() add_subwindow(new BC_Bar(5, y, get_w() - 10)); y += 5; add_subwindow(new BC_Title(x, y, _("Render Farm"), LARGEFONT, resources->text_default)); + x1 = get_w() - BC_GenericButton::calculate_w(this, _("Reset rates")) - x; + add_subwindow(new PrefsRenderFarmReset(pwindow, this, x1, y)); x1 = x + xmargin4; BC_Title *node_title = new BC_Title(x1, y, _("Nodes:")); add_subwindow(node_title); - x1 += node_title->get_w() + 25; + x1 += node_title->get_w() + 15; sprintf(string, _(MASTER_NODE_FRAMERATE_TEXT), pwindow->thread->preferences->local_rate); add_subwindow(master_rate = new BC_Title(x1, y, string)); - y += 25; - add_subwindow(node_list = new PrefsRenderFarmNodes(pwindow, - this, - x + xmargin4, - y)); - y += 5; - add_subwindow(new PrefsRenderFarm(pwindow, x, y)); - y += 30; - add_subwindow(new BC_Title(x, y, _("Hostname:"))); + add_subwindow(node_list = new PrefsRenderFarmNodes(pwindow, this, x + xmargin4, y+=25)); + add_subwindow(new PrefsRenderFarm(pwindow, x, y+=5)); + add_subwindow(new BC_Title(x, y+=30, _("Hostname:"))); add_subwindow(new BC_Title(x + xmargin3, y, _("Port:"))); - - y += 25; - add_subwindow(edit_node = new PrefsRenderFarmEditNode(pwindow, - this, - x, - y)); - edit_port = new PrefsRenderFarmPort(pwindow, - this, - x + xmargin3, - y); + add_subwindow(edit_node = new PrefsRenderFarmEditNode(pwindow, this, x, y+=25)); + edit_port = new PrefsRenderFarmPort(pwindow, this, x+xmargin3, y); edit_port->create_objects(); - y += 30; - - - add_subwindow(new PrefsRenderFarmReplaceNode(pwindow, - this, - x, - y)); - add_subwindow(new PrefsRenderFarmNewNode(pwindow, - this, - x + xmargin2, - y)); - y += 30; - add_subwindow(new PrefsRenderFarmDelNode(pwindow, - this, - x + xmargin2, - y)); - add_subwindow(new PrefsRenderFarmSortNodes(pwindow, - this, - x, - y)); - y += 30; - add_subwindow(new PrefsRenderFarmReset(pwindow, - this, - x, - y)); - y += 35; - add_subwindow(new BC_Title(x, - y, - _("Total jobs to create:"))); - add_subwindow(new BC_Title(x, - y + 30, - _("(overridden if new file at each label is checked)"))); - PrefsRenderFarmJobs *jobs = new PrefsRenderFarmJobs(pwindow, - this, - x + xmargin3, - y); + add_subwindow(new PrefsRenderFarmReplaceNode(pwindow, this, x, y+=30)); + add_subwindow(new PrefsRenderFarmNewNode(pwindow, this, x+xmargin2, y)); + add_subwindow(new PrefsRenderFarmSortNodes(pwindow, this, x, y+=30)); + add_subwindow(new PrefsRenderFarmDelNode(pwindow, this, x+xmargin2, y)); + add_subwindow(new BC_Title(x, y+=35, _("Client Watchdog Timeout:"))); + renderfarm_watchdog = new PrefsRenderFarmWatchdog(pwindow, this, x+xmargin3, y-5); + renderfarm_watchdog->create_objects(); + add_subwindow(new BC_Title(x, y+=35, _("Total jobs to create:"))); + PrefsRenderFarmJobs *jobs = new PrefsRenderFarmJobs(pwindow, this, + x + xmargin3, y-5); jobs->create_objects(); - y += 55; -// add_subwindow(new PrefsRenderFarmVFS(pwindow, -// this, -// x, -// y)); -// add_subwindow(new BC_Title(x, -// y, + y += jobs->get_h() + 5; + win = add_subwindow(new BC_Title(x, y, + _("(overridden if new file at each label is checked)"))); +// y += win->get_h() + 5; +// add_subwindow(new PrefsRenderFarmVFS(pwindow, this, x, y)); +// add_subwindow(new BC_Title(x, y, // _("Filesystem prefix on remote nodes:"))); -// add_subwindow(new PrefsRenderFarmMountpoint(pwindow, -// this, -// x + xmargin3, -// y)); +// add_subwindow(new PrefsRenderFarmMountpoint(pwindow, this, x + xmargin3, y)); // y += 30; } @@ -275,20 +216,13 @@ void PerformancePrefs::generate_node_list() } } -static const char *default_titles[] = -{ - N_("On"), - N_("Hostname"), - N_("Port"), - N_("Framerate") + +static const char *default_titles[] = { + N_("On"), N_("Hostname"), N_("Port"), N_("Framerate") }; -static int default_widths[] = -{ - 30, - 150, - 50, - 50 +static int default_widths[] = { + 30, 150, 50, 50 }; @@ -347,21 +281,11 @@ int PrefsUseBRender::handle_event() } - - - - PrefsBRenderFragment::PrefsBRenderFragment(PreferencesWindow *pwindow, - PerformancePrefs *subwindow, - int x, - int y) + PerformancePrefs *subwindow, int x, int y) : BC_TumbleTextBox(subwindow, (int64_t)pwindow->thread->preferences->brender_fragment, - (int64_t)1, - (int64_t)65535, - x, - y, - 100) + (int64_t)1, (int64_t)65535, x, y, 100) { this->pwindow = pwindow; } @@ -371,27 +295,13 @@ int PrefsBRenderFragment::handle_event() return 1; } - - - - - - - - - - -CICacheSize::CICacheSize(int x, - int y, - PreferencesWindow *pwindow, - PerformancePrefs *subwindow) +CICacheSize::CICacheSize(int x, int y, + PreferencesWindow *pwindow, PerformancePrefs *subwindow) : BC_TumbleTextBox(subwindow, (int64_t)pwindow->thread->preferences->cache_size / 0x100000, (int64_t)MIN_CACHE_SIZE / 0x100000, (int64_t)MAX_CACHE_SIZE / 0x100000, - x, - y, - 100) + x, y, 100) { this->pwindow = pwindow; set_increment(1); @@ -453,15 +363,6 @@ int PrefsBRenderPreroll::handle_event() } - - - - - - - - - PrefsRenderFarm::PrefsRenderFarm(PreferencesWindow *pwindow, int x, int y) : BC_CheckBox(x, y, @@ -480,8 +381,6 @@ int PrefsRenderFarm::handle_event() } - - PrefsForceUniprocessor::PrefsForceUniprocessor(PreferencesWindow *pwindow, int x, int y) : BC_CheckBox(x, y, @@ -603,11 +502,6 @@ int PrefsRenderFarmNodes::selection_changed() } - - - - - PrefsRenderFarmEditNode::PrefsRenderFarmEditNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y) : BC_TextBox(x, y, 240, 1, "") { @@ -625,10 +519,6 @@ int PrefsRenderFarmEditNode::handle_event() } - - - - PrefsRenderFarmNewNode::PrefsRenderFarmNewNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y) : BC_GenericButton(x, y, _("Add Nodes")) { @@ -659,11 +549,6 @@ int PrefsRenderFarmNewNode::handle_event() } - - - - - PrefsRenderFarmReplaceNode::PrefsRenderFarmReplaceNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y) : BC_GenericButton(x, y, _("Apply Changes")) { @@ -688,9 +573,6 @@ int PrefsRenderFarmReplaceNode::handle_event() } - - - PrefsRenderFarmDelNode::PrefsRenderFarmDelNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y) : BC_GenericButton(x, y, _("Delete Nodes")) { @@ -714,9 +596,6 @@ int PrefsRenderFarmDelNode::handle_event() } - - - PrefsRenderFarmSortNodes::PrefsRenderFarmSortNodes(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, @@ -741,13 +620,8 @@ int PrefsRenderFarmSortNodes::handle_event() } - - - PrefsRenderFarmReset::PrefsRenderFarmReset(PreferencesWindow *pwindow, - PerformancePrefs *subwindow, - int x, - int y) + PerformancePrefs *subwindow, int x, int y) : BC_GenericButton(x, y, _("Reset rates")) { this->pwindow = pwindow; @@ -762,7 +636,7 @@ int PrefsRenderFarmReset::handle_event() char string[BCTEXTLEN]; sprintf(string, - MASTER_NODE_FRAMERATE_TEXT, + _(MASTER_NODE_FRAMERATE_TEXT), pwindow->thread->preferences->local_rate); subwindow->master_rate->update(string); subwindow->hot_node = -1; @@ -770,9 +644,6 @@ int PrefsRenderFarmReset::handle_event() } - - - PrefsProjectSMP::PrefsProjectSMP(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y) : BC_TumbleTextBox(subwindow, @@ -791,20 +662,13 @@ int PrefsProjectSMP::handle_event() } - - - PrefsRenderFarmJobs::PrefsRenderFarmJobs(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y) : BC_TumbleTextBox(subwindow, (int64_t)pwindow->thread->preferences->renderfarm_job_count, - (int64_t)1, - (int64_t)100, - x, - y, - 100) + (int64_t)1, (int64_t)100, x, y, 100) { this->pwindow = pwindow; } @@ -818,15 +682,9 @@ int PrefsRenderFarmJobs::handle_event() } - PrefsRenderFarmMountpoint::PrefsRenderFarmMountpoint(PreferencesWindow *pwindow, - PerformancePrefs *subwindow, - int x, - int y) - : BC_TextBox(x, - y, - 100, - 1, + PerformancePrefs *subwindow, int x, int y) + : BC_TextBox(x, y, 100, 1, pwindow->thread->preferences->renderfarm_mountpoint) { this->pwindow = pwindow; @@ -842,8 +700,6 @@ int PrefsRenderFarmMountpoint::handle_event() } - - PrefsRenderFarmVFS::PrefsRenderFarmVFS(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y) : BC_CheckBox(x, y, pwindow->thread->preferences->renderfarm_vfs, @@ -859,3 +715,21 @@ int PrefsRenderFarmVFS::handle_event() return 1; } + +PrefsRenderFarmWatchdog::PrefsRenderFarmWatchdog(PreferencesWindow *pwindow, + PerformancePrefs *subwindow, int x, int y) + : BC_TumbleTextBox(subwindow, + (int64_t)pwindow->thread->preferences->renderfarm_watchdog_timeout, + (int64_t)0, (int64_t)1000, x, y, 100) +{ + this->pwindow = pwindow; + set_increment(15); +} + +int PrefsRenderFarmWatchdog::handle_event() +{ + pwindow->thread->preferences->renderfarm_watchdog_timeout = atol(get_text()); + return 1; +} + + diff --git a/cinelerra-5.1/cinelerra/performanceprefs.h b/cinelerra-5.1/cinelerra/performanceprefs.h index 6e1e99c8..61d43a5d 100644 --- a/cinelerra-5.1/cinelerra/performanceprefs.h +++ b/cinelerra-5.1/cinelerra/performanceprefs.h @@ -60,18 +60,17 @@ public: PrefsRenderFarmEditNode *edit_node; PrefsRenderFarmPort *edit_port; PrefsRenderFarmNodes *node_list; + PrefsRenderFarmWatchdog *renderfarm_watchdog; FormatTools *brender_tools; BC_Title *master_rate; }; - class PrefsUseBRender : public BC_CheckBox { public: PrefsUseBRender(PreferencesWindow *pwindow, - int x, - int y); + int x, int y); int handle_event(); PreferencesWindow *pwindow; }; @@ -81,14 +80,11 @@ class PrefsBRenderFragment : public BC_TumbleTextBox public: PrefsBRenderFragment(PreferencesWindow *pwindow, PerformancePrefs *subwindow, - int x, - int y); + int x, int y); int handle_event(); PreferencesWindow *pwindow; }; - - class PrefsRenderPreroll : public BC_TumbleTextBox { public: @@ -135,9 +131,6 @@ public: PerformancePrefs *perf_prefs; }; - - - class PrefsRenderFarm : public BC_CheckBox { public: @@ -146,7 +139,6 @@ public: int handle_event(); - PreferencesWindow *pwindow; }; @@ -158,7 +150,6 @@ public: int handle_event(); - PreferencesWindow *pwindow; }; @@ -168,8 +159,7 @@ class PrefsRenderFarmPort : public BC_TumbleTextBox public: PrefsRenderFarmPort(PreferencesWindow *pwindow, PerformancePrefs *subwindow, - int x, - int y); + int x, int y); ~PrefsRenderFarmPort(); int handle_event(); @@ -193,8 +183,7 @@ class PrefsRenderFarmJobs : public BC_TumbleTextBox public: PrefsRenderFarmJobs(PreferencesWindow *pwindow, PerformancePrefs *subwindow, - int x, - int y); + int x, int y); ~PrefsRenderFarmJobs(); int handle_event(); @@ -207,8 +196,7 @@ class PrefsRenderFarmMountpoint : public BC_TextBox public: PrefsRenderFarmMountpoint(PreferencesWindow *pwindow, PerformancePrefs *subwindow, - int x, - int y); + int x, int y); ~PrefsRenderFarmMountpoint(); int handle_event(); @@ -297,7 +285,6 @@ public: int handle_event(); PerformancePrefs *subwindow; - PreferencesWindow *pwindow; }; @@ -313,13 +300,23 @@ public: PreferencesWindow *pwindow; }; - class PrefsRenderFarmReset : public BC_GenericButton { public: PrefsRenderFarmReset(PreferencesWindow *pwindow, - PerformancePrefs *subwindow, - int x, int y); + PerformancePrefs *subwindow, int x, int y); + + int handle_event(); + + PerformancePrefs *subwindow; + PreferencesWindow *pwindow; +}; + +class PrefsRenderFarmWatchdog : public BC_TumbleTextBox +{ +public: + PrefsRenderFarmWatchdog(PreferencesWindow *pwindow, + PerformancePrefs *subwindow, int x, int y); int handle_event(); @@ -331,11 +328,12 @@ public: class CICacheSize : public BC_TumbleTextBox { public: - CICacheSize(int x, - int y, + CICacheSize(int x, int y, PreferencesWindow *pwindow, PerformancePrefs *subwindow); + int handle_event(); + PreferencesWindow *pwindow; }; diff --git a/cinelerra-5.1/cinelerra/performanceprefs.inc b/cinelerra-5.1/cinelerra/performanceprefs.inc index b8793fb1..db081535 100644 --- a/cinelerra-5.1/cinelerra/performanceprefs.inc +++ b/cinelerra-5.1/cinelerra/performanceprefs.inc @@ -42,6 +42,7 @@ class PrefsRenderFarmReplaceNode; class PrefsRenderFarmDelNode; class PrefsRenderFarmSortNodes; class PrefsRenderFarmReset; +class PrefsRenderFarmWatchdog; class CICacheSize; #endif diff --git a/cinelerra-5.1/cinelerra/preferences.C b/cinelerra-5.1/cinelerra/preferences.C index edeee836..b950b374 100644 --- a/cinelerra-5.1/cinelerra/preferences.C +++ b/cinelerra-5.1/cinelerra/preferences.C @@ -40,26 +40,23 @@ #include "videoconfig.h" #include "videodevice.inc" +#include #include #include #include #include -//#define CLAMP(x, y, z) (x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))) - Preferences::Preferences() { // Set defaults FileSystem fs; - preferences_lock = new Mutex("Preferences::preferences_lock"); - // initial plugin path from build -DPLUGIN_DIR="..." sprintf(plugin_dir, "%s/", File::get_plugin_path()); sprintf(index_directory, "%s/", File::get_config_path()); - if(strlen(index_directory)) + if( strlen(index_directory) ) fs.complete_path(index_directory); cache_size = 0x10000000; index_size = 0x400000; @@ -79,6 +76,7 @@ Preferences::Preferences() renderfarm_mountpoint[0] = 0; renderfarm_vfs = 0; renderfarm_job_count = 20; + renderfarm_watchdog_timeout = 60; project_smp = processors = calculate_processors(0); real_processors = calculate_processors(1); ffmpeg_marker_indexes = 1; @@ -91,8 +89,8 @@ Preferences::Preferences() forward_render_displacement = 0; dvd_yuv420p_interlace = 0; highlight_inverse = 0xffffff; - yuv_color_space = 0; // bt601 - yuv_color_range = 0; // jpeg + yuv_color_space = BC_COLORS_BT601; + yuv_color_range = BC_COLORS_JPEG; // Default brender asset brender_asset = new Asset; @@ -138,26 +136,19 @@ void Preferences::copy_rates_from(Preferences *preferences) // one of the nodes in the source is the master node. local_rate = preferences->local_rate; - for(int j = 0; - j < preferences->renderfarm_nodes.total; - j++) - { + for( int j=0; jrenderfarm_nodes.total; ++j ) { double new_rate = preferences->renderfarm_rate.values[j]; // Put in the master node - if(preferences->renderfarm_nodes.values[j][0] == '/') - { - if(!EQUIV(new_rate, 0.0)) + if( preferences->renderfarm_nodes.values[j][0] == '/' ) { + if( !EQUIV(new_rate, 0.0) ) local_rate = new_rate; } else // Search for local node and copy it to that node - if(!EQUIV(new_rate, 0.0)) - { - for(int i = 0; i < renderfarm_nodes.total; i++) - { - if(!strcmp(preferences->renderfarm_nodes.values[j], renderfarm_nodes.values[i]) && - preferences->renderfarm_ports.values[j] == renderfarm_ports.values[i]) - { + if( !EQUIV(new_rate, 0.0) ) { + for( int i=0; irenderfarm_nodes.values[j], renderfarm_nodes.values[i]) && + preferences->renderfarm_ports.values[j] == renderfarm_ports.values[i] ) { renderfarm_rate.values[i] = new_rate; break; } @@ -216,8 +207,7 @@ void Preferences::copy_from(Preferences *that) renderfarm_enabled.remove_all(); renderfarm_rate.remove_all(); local_rate = that->local_rate; - for(int i = 0; i < that->renderfarm_nodes.size(); i++) - { + for( int i=0; irenderfarm_nodes.size(); ++i ) { add_node(that->renderfarm_nodes.get(i), that->renderfarm_ports.get(i), that->renderfarm_enabled.get(i), @@ -228,6 +218,7 @@ void Preferences::copy_from(Preferences *that) render_preroll = that->render_preroll; brender_preroll = that->brender_preroll; renderfarm_job_count = that->renderfarm_job_count; + renderfarm_watchdog_timeout = that->renderfarm_watchdog_timeout; renderfarm_vfs = that->renderfarm_vfs; strcpy(renderfarm_mountpoint, that->renderfarm_mountpoint); renderfarm_consolidate = that->renderfarm_consolidate; @@ -238,13 +229,12 @@ void Preferences::copy_from(Preferences *that) // Check boundaries FileSystem fs; - if(strlen(index_directory)) - { + if( strlen(index_directory) ) { fs.complete_path(index_directory); fs.add_end_slash(index_directory); } -// if(strlen(global_plugin_dir)) +// if( strlen(global_plugin_dir) ) // { // fs.complete_path(global_plugin_dir); // fs.add_end_slash(global_plugin_dir); @@ -269,42 +259,31 @@ printf("Preferences::operator=\n"); return *this; } -void Preferences::print_channels(char *string, - int *channel_positions, - int channels) +void Preferences::print_channels(char *string, int *channel_positions, int channels) { - char string3[BCTEXTLEN]; - string[0] = 0; - for(int j = 0; j < channels; j++) - { - sprintf(string3, "%d", channel_positions[j]); - strcat(string, string3); - if(j < channels - 1) - strcat(string, ","); + char *cp = string, *ep = cp+BCTEXTLEN-1; + for( int i=0; i= channels) break; + for(;;) { + while( isspace(*cp) ) ++cp; + if( !cp ) break; + channel_positions[current_channel++] = strtol(cp, &cp, 0); + if( current_channel >= channels ) break; + while( isspace(*cp) ) ++cp; + if( *cp == ',' ) ++cp; + } + while( current_channel < channels ) { + int pos = default_audio_channel_position(current_channel, channels); + channel_positions[current_channel++] = pos; } } @@ -364,13 +343,13 @@ int Preferences::load_defaults(BC_Hash *defaults) render_preroll = defaults->get("RENDERFARM_PREROLL", render_preroll); brender_preroll = defaults->get("BRENDER_PREROLL", brender_preroll); renderfarm_job_count = defaults->get("RENDERFARM_JOBS_COUNT", renderfarm_job_count); + renderfarm_watchdog_timeout = defaults->get("RENDERFARM_WATCHDOG_TIMEOUT", renderfarm_watchdog_timeout); renderfarm_consolidate = defaults->get("RENDERFARM_CONSOLIDATE", renderfarm_consolidate); // renderfarm_vfs = defaults->get("RENDERFARM_VFS", renderfarm_vfs); defaults->get("RENDERFARM_MOUNTPOINT", renderfarm_mountpoint); int renderfarm_total = defaults->get("RENDERFARM_TOTAL", 0); - for(int i = 0; i < renderfarm_total; i++) - { + for( int i = 0; i < renderfarm_total; i++ ) { sprintf(string, "RENDERFARM_NODE%d", i); char result[BCTEXTLEN]; int result_port = 0; @@ -389,8 +368,7 @@ int Preferences::load_defaults(BC_Hash *defaults) sprintf(string, "RENDERFARM_RATE%d", i); result_rate = defaults->get(string, result_rate); - if(result[0] != 0) - { + if( result[0] != 0 ) { add_node(result, result_port, result_enabled, result_rate); } } @@ -468,8 +446,7 @@ int Preferences::save_defaults(BC_Hash *defaults) defaults->update("PLUGIN_ICONS", plugin_icons); defaults->update("SNAPSHOT_PATH", snapshot_path); - for(int i = 0; i < MAXCHANNELS; i++) - { + for( int i = 0; i < MAXCHANNELS; i++ ) { char string2[BCTEXTLEN]; sprintf(string, "CHANNEL_POSITIONS%d", i); print_channels(string2, &channel_positions[i][0], i + 1); @@ -501,10 +478,10 @@ int Preferences::save_defaults(BC_Hash *defaults) // defaults->update("RENDERFARM_VFS", renderfarm_vfs); defaults->update("RENDERFARM_MOUNTPOINT", renderfarm_mountpoint); defaults->update("RENDERFARM_JOBS_COUNT", renderfarm_job_count); + defaults->update("RENDERFARM_WATCHDOG_TIMEOUT", renderfarm_watchdog_timeout); defaults->update("RENDERFARM_CONSOLIDATE", renderfarm_consolidate); defaults->update("RENDERFARM_TOTAL", (int64_t)renderfarm_nodes.total); - for(int i = 0; i < renderfarm_nodes.total; i++) - { + for( int i = 0; i < renderfarm_nodes.total; i++ ) { sprintf(string, "RENDERFARM_NODE%d", i); defaults->update(string, renderfarm_nodes.values[i]); sprintf(string, "RENDERFARM_PORT%d", i); @@ -538,7 +515,7 @@ int Preferences::save_defaults(BC_Hash *defaults) void Preferences::add_node(const char *text, int port, int enabled, float rate) { - if(text[0] == 0) return; + if( text[0] == 0 ) return; preferences_lock->lock("Preferences::add_node"); char *new_item = new char[strlen(text) + 1]; @@ -554,8 +531,7 @@ void Preferences::add_node(const char *text, int port, int enabled, float rate) void Preferences::delete_node(int number) { preferences_lock->lock("Preferences::delete_node"); - if(number < renderfarm_nodes.total && number >= 0) - { + if( number < renderfarm_nodes.total && number >= 0 ) { delete [] renderfarm_nodes.values[number]; renderfarm_nodes.remove_number(number); renderfarm_ports.remove_number(number); @@ -568,7 +544,7 @@ void Preferences::delete_node(int number) void Preferences::delete_nodes() { preferences_lock->lock("Preferences::delete_nodes"); - for(int i = 0; i < renderfarm_nodes.total; i++) + for( int i = 0; i < renderfarm_nodes.total; i++ ) delete [] renderfarm_nodes.values[i]; renderfarm_nodes.remove_all(); renderfarm_ports.remove_all(); @@ -579,8 +555,7 @@ void Preferences::delete_nodes() void Preferences::reset_rates() { - for(int i = 0; i < renderfarm_nodes.total; i++) - { + for( int i = 0; i < renderfarm_nodes.total; i++ ) { renderfarm_rate.values[i] = 0.0; } local_rate = 0.0; @@ -588,18 +563,14 @@ void Preferences::reset_rates() float Preferences::get_rate(int node) { - if(node < 0) - { + if( node < 0 ) { return local_rate; } - else - { + else { int total = 0; - for(int i = 0; i < renderfarm_nodes.size(); i++) - { - if(renderfarm_enabled.get(i)) total++; - if(total == node + 1) - { + for( int i = 0; i < renderfarm_nodes.size(); i++ ) { + if( renderfarm_enabled.get(i) ) total++; + if( total == node + 1 ) { return renderfarm_rate.get(i); } } @@ -611,18 +582,14 @@ float Preferences::get_rate(int node) void Preferences::set_rate(float rate, int node) { //printf("Preferences::set_rate %f %d\n", rate, node); - if(node < 0) - { + if( node < 0 ) { local_rate = rate; } - else - { + else { int total = 0; - for(int i = 0; i < renderfarm_nodes.size(); i++) - { - if(renderfarm_enabled.get(i)) total++; - if(total == node + 1) - { + for( int i = 0; i < renderfarm_nodes.size(); i++ ) { + if( renderfarm_enabled.get(i) ) total++; + if( total == node + 1 ) { renderfarm_rate.set(i, rate); return; } @@ -634,38 +601,31 @@ float Preferences::get_avg_rate(int use_master_node) { preferences_lock->lock("Preferences::get_avg_rate"); float total = 0.0; - if(renderfarm_rate.total) - { + if( renderfarm_rate.total ) { int enabled = 0; - if(use_master_node) - { - if(EQUIV(local_rate, 0.0)) - { + if( use_master_node ) { + if( EQUIV(local_rate, 0.0) ) { preferences_lock->unlock(); return 0.0; } - else - { + else { enabled++; total += local_rate; } } - for(int i = 0; i < renderfarm_rate.total; i++) - { - if(renderfarm_enabled.values[i]) - { + for( int i = 0; i < renderfarm_rate.total; i++ ) { + if( renderfarm_enabled.values[i] ) { enabled++; total += renderfarm_rate.values[i]; - if(EQUIV(renderfarm_rate.values[i], 0.0)) - { + if( EQUIV(renderfarm_rate.values[i], 0.0) ) { preferences_lock->unlock(); return 0.0; } } } - if(enabled) + if( enabled ) total /= enabled; else total = 0.0; @@ -682,10 +642,8 @@ void Preferences::sort_nodes() while(!done) { done = 1; - for(int i = 0; i < renderfarm_nodes.total - 1; i++) - { - if(strcmp(renderfarm_nodes.values[i], renderfarm_nodes.values[i + 1]) > 0) - { + for( int i = 0; i < renderfarm_nodes.total - 1; i++ ) { + if( strcmp(renderfarm_nodes.values[i], renderfarm_nodes.values[i + 1]) > 0 ) { char *temp = renderfarm_nodes.values[i]; int temp_port = renderfarm_ports.values[i]; @@ -723,19 +681,17 @@ void Preferences::edit_node(int number, int Preferences::get_enabled_nodes() { int result = 0; - for(int i = 0; i < renderfarm_enabled.total; i++) - if(renderfarm_enabled.values[i]) result++; + for( int i = 0; i < renderfarm_enabled.total; i++ ) + if( renderfarm_enabled.values[i] ) result++; return result; } const char* Preferences::get_node_hostname(int number) { int total = 0; - for(int i = 0; i < renderfarm_nodes.total; i++) - { - if(renderfarm_enabled.values[i]) - { - if(total == number) + for( int i = 0; i < renderfarm_nodes.total; i++ ) { + if( renderfarm_enabled.values[i] ) { + if( total == number ) return renderfarm_nodes.values[i]; else total++; @@ -747,11 +703,9 @@ const char* Preferences::get_node_hostname(int number) int Preferences::get_node_port(int number) { int total = 0; - for(int i = 0; i < renderfarm_ports.total; i++) - { - if(renderfarm_enabled.values[i]) - { - if(total == number) + for( int i = 0; i < renderfarm_ports.total; i++ ) { + if( renderfarm_enabled.values[i] ) { + if( total == number ) return renderfarm_ports.values[i]; else total++; @@ -780,7 +734,7 @@ int Preferences::get_asset_file_path(Asset *asset, char *path) int Preferences::calculate_processors(int interactive) { - if(force_uniprocessor && !interactive) return 1; + if( force_uniprocessor && !interactive ) return 1; return BC_WindowBase::get_resources()->machine_cpus; } diff --git a/cinelerra-5.1/cinelerra/preferences.h b/cinelerra-5.1/cinelerra/preferences.h index 8b1bb3b4..d7f449ef 100644 --- a/cinelerra-5.1/cinelerra/preferences.h +++ b/cinelerra-5.1/cinelerra/preferences.h @@ -156,6 +156,8 @@ public: int renderfarm_job_count; // Consolidate output files int renderfarm_consolidate; +// watchdog timeout, zero disabled + int renderfarm_watchdog_timeout; // Tip of the day int use_tipwindow; diff --git a/cinelerra-5.1/cinelerra/renderfarm.C b/cinelerra-5.1/cinelerra/renderfarm.C index 9672b1af..cdfd18f0 100644 --- a/cinelerra-5.1/cinelerra/renderfarm.C +++ b/cinelerra-5.1/cinelerra/renderfarm.C @@ -92,11 +92,9 @@ int RenderFarmServer::start_clients() { int result = 0; - for(int i = 0; i < preferences->get_enabled_nodes() && !result; i++) - { + for( int i=0; iget_enabled_nodes() && !result; ++i ) { client_lock->lock("RenderFarmServer::start_clients"); - RenderFarmServerThread *client = new RenderFarmServerThread(this, - i); + RenderFarmServerThread *client = new RenderFarmServerThread(this, i); clients.append(client); result = client->start_loop(); @@ -143,14 +141,11 @@ RenderFarmServerThread::RenderFarmServerThread(RenderFarmServer *server, RenderFarmServerThread::~RenderFarmServerThread() { -//printf("RenderFarmServerThread::~RenderFarmServerThread 1 %p\n", this); Thread::join(); -//printf("RenderFarmServerThread::~RenderFarmServerThread 1\n"); - if(socket_fd >= 0) close(socket_fd); - if(watchdog) delete watchdog; - if(buffer) delete [] buffer; - if(datagram) delete [] datagram; -//printf("RenderFarmServerThread::~RenderFarmServerThread 2\n"); + if( socket_fd >= 0 ) close(socket_fd); + delete watchdog; + delete [] buffer; + delete [] datagram; } @@ -160,15 +155,12 @@ int RenderFarmServerThread::open_client(const char *hostname, int port) int result = 0; // Open file for master node - if(hostname[0] == '/') - { - if((socket_fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) - { - perror(_("RenderFarmServerThread::start_loop: socket\n")); + if( hostname[0] == '/' ) { + if( (socket_fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0 ) { + perror(_("RenderFarmServerThread::open_client: socket\n")); result = 1; } - else - { + else { struct sockaddr_un addr; addr.sun_family = AF_FILE; strcpy(addr.sun_path, hostname); @@ -183,11 +175,9 @@ int RenderFarmServerThread::open_client(const char *hostname, int port) do { - if(connect(socket_fd, (struct sockaddr*)&addr, size) < 0) - { + if( connect(socket_fd, (struct sockaddr*)&addr, size) < 0 ) { attempt++; - if(attempt > 30000000 / ATTEMPT_DELAY) - { + if( attempt > 30000000 / ATTEMPT_DELAY ) { fprintf(stderr, _("RenderFarmServerThread::open_client: %s: %s\n"), hostname, strerror(errno)); @@ -204,31 +194,26 @@ int RenderFarmServerThread::open_client(const char *hostname, int port) else // Open socket { - if((socket_fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) - { + if( (socket_fd = socket(PF_INET, SOCK_STREAM, 0)) < 0 ) { perror(_("RenderFarmServerThread::start_loop: socket")); result = 1; } - else - { + else { // Open port struct sockaddr_in addr; struct hostent *hostinfo; addr.sin_family = AF_INET; addr.sin_port = htons(port); hostinfo = gethostbyname(hostname); - if(hostinfo == NULL) - { + if( hostinfo == NULL ) { fprintf(stderr, _("RenderFarmServerThread::open_client: unknown host %s.\n"), hostname); result = 1; } - else - { + else { addr.sin_addr = *(struct in_addr *) hostinfo->h_addr; - if(connect(socket_fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) - { + if( connect(socket_fd, (struct sockaddr*)&addr, sizeof(addr)) < 0 ) { fprintf(stderr, _("RenderFarmServerThread::open_client: %s: %s\n"), hostname, strerror(errno)); @@ -238,7 +223,7 @@ int RenderFarmServerThread::open_client(const char *hostname, int port) } } - if(result) socket_fd = -1; + if( result ) socket_fd = -1; return socket_fd; } @@ -246,19 +231,19 @@ int RenderFarmServerThread::open_client(const char *hostname, int port) int RenderFarmServerThread::start_loop() { int result = 0; - socket_fd = open_client(server->preferences->get_node_hostname(number), server->preferences->get_node_port(number)); + if( socket_fd < 0 ) result = 1; - if(socket_fd < 0) result = 1; - - if(!result) - { - watchdog = new RenderFarmWatchdog(this, 0); - watchdog->start(); + if( !result ) { + int watchdog_timeout = server->preferences->renderfarm_watchdog_timeout; + if( watchdog_timeout > 0 ) { + watchdog = new RenderFarmWatchdog(watchdog_timeout, this, 0); + watchdog->start(); + } } - if(!result) Thread::start(); + if( !result ) Thread::start(); return result; } @@ -276,7 +261,7 @@ int RenderFarmServerThread::start_loop() int64_t RenderFarmServerThread::read_int64(int *error) { int temp = 0; - if(!error) error = &temp; + if( !error ) error = &temp; unsigned char data[sizeof(int64_t)]; *error = (read_socket((char*)data, sizeof(int64_t)) != @@ -285,8 +270,7 @@ int64_t RenderFarmServerThread::read_int64(int *error) // Make it return 1 if error so it can be used to read a result code from the // server. int64_t result = 1; - if(!*error) - { + if( !*error ) { result = (((int64_t)data[0]) << 56) | (((uint64_t)data[1]) << 48) | (((uint64_t)data[2]) << 40) | @@ -321,22 +305,23 @@ int RenderFarmServerThread::read_socket(char *data, int len) int bytes_read = 0; int offset = 0; //printf("RenderFarmServerThread::read_socket 1\n"); - watchdog->begin_request(); + if( watchdog ) + watchdog->begin_request(); while(len > 0 && bytes_read >= 0) { enable_cancel(); bytes_read = read(socket_fd, data + offset, len); disable_cancel(); - if(bytes_read > 0) - { + if( bytes_read > 0 ) { len -= bytes_read; offset += bytes_read; } else - if(bytes_read < 0) + if( bytes_read < 0 ) break; } - watchdog->end_request(); + if( watchdog ) + watchdog->end_request(); //printf("RenderFarmServerThread::read_socket 10\n"); return offset; @@ -353,14 +338,12 @@ int RenderFarmServerThread::write_socket(char *data, int len) void RenderFarmServerThread::reallocate_buffer(int size) { - if(buffer && buffer_allocated < size) - { + if( buffer && buffer_allocated < size ) { delete [] buffer; buffer = 0; } - if(!buffer && size) - { + if( !buffer && size ) { buffer = new unsigned char[size]; buffer_allocated = size; } @@ -385,25 +368,23 @@ void RenderFarmServerThread::run() - while(!done) - { + while(!done) { // Wait for requests. // Requests consist of request ID's and accompanying buffers. // Get request ID. bytes_read = read_socket((char*)header, 5); //printf("RenderFarmServerThread::run 1\n"); - if(bytes_read != 5) - { + if( bytes_read != 5 ) { done = 1; continue; } int request_id = header[0]; int64_t request_size = (((u_int32_t)header[1]) << 24) | - (((u_int32_t)header[2]) << 16) | - (((u_int32_t)header[3]) << 8) | - (u_int32_t)header[4]; + (((u_int32_t)header[2]) << 16) | + (((u_int32_t)header[3]) << 8) | + (u_int32_t)header[4]; reallocate_buffer(request_size); @@ -411,74 +392,64 @@ void RenderFarmServerThread::run() bytes_read = read_socket((char*)buffer, request_size); //printf("RenderFarmServerThread::run 2 %d %jd %d\n", request_id, request_size, bytes_read); - if(bytes_read != request_size) - { + if( bytes_read != request_size ) { done = 1; continue; } //printf("RenderFarmServerThread::run 3\n"); - switch(request_id) - { - case RENDERFARM_PREFERENCES: - send_preferences(); - break; + switch( request_id ) { + case RENDERFARM_PREFERENCES: + send_preferences(); + break; - case RENDERFARM_ASSET: - send_asset(); - break; + case RENDERFARM_ASSET: + send_asset(); + break; - case RENDERFARM_EDL: - send_edl(); - break; + case RENDERFARM_EDL: + send_edl(); + break; - case RENDERFARM_PACKAGE: - send_package(buffer); - break; + case RENDERFARM_PACKAGE: + send_package(buffer); + break; - case RENDERFARM_PROGRESS: - set_progress(buffer); - break; + case RENDERFARM_PROGRESS: + set_progress(buffer); + break; - case RENDERFARM_SET_RESULT: - set_result(buffer); - break; + case RENDERFARM_SET_RESULT: + set_result(buffer); + break; - case RENDERFARM_SET_VMAP: - set_video_map(buffer); - break; + case RENDERFARM_SET_VMAP: + set_video_map(buffer); + break; - case RENDERFARM_GET_RESULT: - get_result(); - break; + case RENDERFARM_GET_RESULT: + get_result(); + break; - case RENDERFARM_DONE: + case RENDERFARM_DONE: //printf("RenderFarmServerThread::run 10\n"); - done = 1; - break; + done = 1; + break; - case RENDERFARM_KEEPALIVE: - break; + case RENDERFARM_KEEPALIVE: + break; - default: -// if(!fs_server->handle_request(request_id, request_size, (unsigned char*)buffer)) - { - printf(_("RenderFarmServerThread::run: unknown request %02x\n"), request_id); - } - break; + default: +// if( fs_server->handle_request(request_id, request_size, (unsigned char*)buffer) ) break; + printf(_("RenderFarmServerThread::run: unknown request %02x\n"), request_id); + break; } //printf("RenderFarmServerThread::run 10 %d %jd\n", request_id, request_size); } - -// Don't let watchdog kill the entire renderfarm when a client finishes -// normally. - if(watchdog) - { //printf("RenderFarmServerThread::run 20\n"); - delete watchdog; - watchdog = 0; - } +// Don't let watchdog kill the entire renderfarm when a client finishes normally. + delete watchdog; watchdog = 0; // delete fs_server; } @@ -571,8 +542,7 @@ void RenderFarmServerThread::send_package(unsigned char *buffer) datagram = new char[BCTEXTLEN]; // No more packages - if(!package) - { + if( !package ) { //printf("RenderFarmServerThread::send_package 1\n"); datagram[0] = datagram[1] = datagram[2] = datagram[3] = 0; write_socket(datagram, 4); @@ -623,14 +593,13 @@ void RenderFarmServerThread::set_progress(unsigned char *buffer) server->preferences->set_rate(frames_per_second, number); // This locks the preferences - if(server->mwindow) server->mwindow->preferences->copy_rates_from( + if( server->mwindow ) server->mwindow->preferences->copy_rates_from( server->preferences); } int RenderFarmServerThread::set_video_map(unsigned char *buffer) { - if(server->brender) - { + if( server->brender ) { server->brender->set_video_map((int64_t)(((u_int32_t)buffer[0]) << 24) | (((u_int32_t)buffer[1]) << 16) | (((u_int32_t)buffer[2]) << 8) | @@ -651,7 +620,7 @@ int RenderFarmServerThread::set_video_map(unsigned char *buffer) void RenderFarmServerThread::set_result(unsigned char *buffer) { //printf("RenderFarmServerThread::set_result %p\n", buffer); - if(!*server->result_return) + if( !*server->result_return ) *server->result_return = buffer[0]; } @@ -676,11 +645,12 @@ void RenderFarmServerThread::get_result() -RenderFarmWatchdog::RenderFarmWatchdog( +RenderFarmWatchdog::RenderFarmWatchdog(int timeout_secs, RenderFarmServerThread *server, RenderFarmClientThread *client) : Thread(1, 0, 0) { + this->timeout_usecs = timeout_secs * 1000000; this->server = server; this->client = client; next_request = new Condition(0, "RenderFarmWatchdog::next_request", 0); @@ -710,24 +680,17 @@ void RenderFarmWatchdog::end_request() void RenderFarmWatchdog::run() { - while(!done) - { + while(!done) { next_request->lock("RenderFarmWatchdog::run"); - - int result = request_complete->timed_lock(RENDERFARM_TIMEOUT * 1000000, - "RenderFarmWatchdog::run"); + int result = request_complete->timed_lock(timeout_usecs, "RenderFarmWatchdog::run"); //printf("RenderFarmWatchdog::run 1 %d\n", result); - if(result) - { - if(client) - { + if( result ) { + if( client ) { printf("RenderFarmWatchdog::run 1 killing client pid %d\n", client->pid); kill(client->pid, SIGKILL); } - else - if(server) - { + else if( server ) { printf("RenderFarmWatchdog::run 1 killing server thread %p\n", server); server->cancel(); unsigned char buffer[4]; diff --git a/cinelerra-5.1/cinelerra/renderfarm.h b/cinelerra-5.1/cinelerra/renderfarm.h index 9418213a..1391351c 100644 --- a/cinelerra-5.1/cinelerra/renderfarm.h +++ b/cinelerra-5.1/cinelerra/renderfarm.h @@ -262,10 +262,8 @@ public: class RenderFarmWatchdog : public Thread { public: -// use_pid - causes it to kill the pid instead of cancel the thread -// Used for client. - RenderFarmWatchdog(RenderFarmServerThread *server, - RenderFarmClientThread *client); + RenderFarmWatchdog(int timeout_secs, + RenderFarmServerThread *server, RenderFarmClientThread *client); ~RenderFarmWatchdog(); // Called at the beginning of a socket read @@ -280,6 +278,7 @@ public: Condition *request_complete; int done; int pid; + int timeout_usecs; }; diff --git a/cinelerra-5.1/cinelerra/renderfarmclient.C b/cinelerra-5.1/cinelerra/renderfarmclient.C index f4eac0da..24eee2a6 100644 --- a/cinelerra-5.1/cinelerra/renderfarmclient.C +++ b/cinelerra-5.1/cinelerra/renderfarmclient.C @@ -555,8 +555,9 @@ void RenderFarmClientThread::run() TheList::reset(); int socket_fd = this->socket_fd; - - init_client_keepalive(); + int watchdog_timeout = client->boot_preferences->renderfarm_watchdog_timeout; + if( watchdog_timeout > 0 ) + init_client_keepalive(watchdog_timeout); // Get command to run int command; @@ -580,11 +581,11 @@ void RenderFarmClientThread::run() } -void RenderFarmClientThread::init_client_keepalive() +void RenderFarmClientThread::init_client_keepalive(int timeout_secs) { keep_alive = new RenderFarmKeepalive(this); keep_alive->start(); - watchdog = new RenderFarmWatchdog(0, this); + watchdog = new RenderFarmWatchdog(timeout_secs, 0, this); watchdog->start(); } @@ -712,8 +713,7 @@ void RenderFarmKeepalive::run() enable_cancel(); sleep(5); disable_cancel(); - if(!done) - { + if( !done ) { //printf("RenderFarmKeepalive::run 1\n"); // watchdog thread kills this if it gets stuck client_thread->ping_server(); diff --git a/cinelerra-5.1/cinelerra/renderfarmclient.h b/cinelerra-5.1/cinelerra/renderfarmclient.h index 1da3893f..5ee6d5ef 100644 --- a/cinelerra-5.1/cinelerra/renderfarmclient.h +++ b/cinelerra-5.1/cinelerra/renderfarmclient.h @@ -93,7 +93,7 @@ public: int read_package(int socket_fd, RenderPackage *package); int send_completion(int socket_fd); void ping_server(); - void init_client_keepalive(); + void init_client_keepalive(int timeout_secs); void main_loop(int socket_fd); void run(); diff --git a/cinelerra-5.1/ffmpeg/video/pass1of2_vp9.webm b/cinelerra-5.1/ffmpeg/video/pass1of2_vp9.webm new file mode 100644 index 00000000..74f7a4f9 --- /dev/null +++ b/cinelerra-5.1/ffmpeg/video/pass1of2_vp9.webm @@ -0,0 +1,13 @@ +webm libvpx-vp9 +# pass 1 of 2, you must render the 2nd pass using pass2of2... +cin_stats_filename /tmp/cin_video_vp9_webm +flags +pass1 +bitrate=1024k +minrate=512k +maxrate=1485k +tile-columns=2 +g=240 +threads=8 +quality=good +crf=32 +speed=4 diff --git a/cinelerra-5.1/ffmpeg/video/pass2of2_vp9.webm b/cinelerra-5.1/ffmpeg/video/pass2of2_vp9.webm new file mode 100644 index 00000000..9f5978b6 --- /dev/null +++ b/cinelerra-5.1/ffmpeg/video/pass2of2_vp9.webm @@ -0,0 +1,13 @@ +webm libvpx-vp9 +# Pass 2 of 2, you must first render using pass1of2... +cin_stats_filename /tmp/cin_video_vp9_webm +flags +pass2 +bitrate=1024k +minrate=512k +maxrate=1485k +tile-columns=2 +g=240 +threads=8 +quality=good +crf=32 +speed=4 diff --git a/cinelerra-5.1/guicast/bclistboxitem.C b/cinelerra-5.1/guicast/bclistboxitem.C index 2c112ebf..88ba5a2b 100644 --- a/cinelerra-5.1/guicast/bclistboxitem.C +++ b/cinelerra-5.1/guicast/bclistboxitem.C @@ -157,4 +157,15 @@ ArrayList* BC_ListBoxItem::new_sublist(int columns) return sublist; } +int BC_ListBoxItem::compare_item_text(const void *a, const void *b) +{ + BC_ListBoxItem *ap = *(BC_ListBoxItem**)a, *bp = *(BC_ListBoxItem**)b; + return strcmp(ap->text, bp->text); +} + +void BC_ListBoxItem::sort_items(ArrayList &items) +{ + qsort(&items[0], items.size(), sizeof(items[0]), compare_item_text); +} + diff --git a/cinelerra-5.1/guicast/bclistboxitem.h b/cinelerra-5.1/guicast/bclistboxitem.h index bb9bc126..a77519a9 100644 --- a/cinelerra-5.1/guicast/bclistboxitem.h +++ b/cinelerra-5.1/guicast/bclistboxitem.h @@ -99,10 +99,13 @@ public: // Return if it's expanded int get_expand() { return expand; } void set_expand(int value) { expand = value; } +// alpha sort on text + static void sort_items(ArrayList &items); private: int initialize(); void set_in_view(int v) { in_view = v; } + static int compare_item_text(const void *a, const void *b); BC_Pixmap *icon; VFrame *icon_vframe; -- 2.26.2