From 1f78d86b5532943b2a3ea51f409a1fe5bd961e02 Mon Sep 17 00:00:00 2001 From: Good Guy Date: Sun, 15 May 2016 14:24:48 -0600 Subject: [PATCH] add threading to xfer --- cinelerra-5.1/cinelerra/atrack.C | 2 +- cinelerra-5.1/cinelerra/mediadb.C | 2 +- cinelerra-5.1/cinelerra/strack.C | 2 +- cinelerra-5.1/cinelerra/vtrack.C | 2 +- cinelerra-5.1/guicast/Makefile | 2 +- cinelerra-5.1/guicast/bcbitmap.C | 2 +- cinelerra-5.1/guicast/bccmdl.py | 125 ++++++++++++++++-------------- cinelerra-5.1/guicast/bccmodels.h | 1 + cinelerra-5.1/guicast/bcsignals.C | 5 ++ cinelerra-5.1/guicast/bcsignals.h | 1 + cinelerra-5.1/guicast/linklist.h | 18 ++--- cinelerra-5.1/guicast/xfer.C | 110 +++++++++++++++++++++++++- cinelerra-5.1/guicast/xfer.h | 44 +++++++++-- cinelerra-5.1/plugins/Makefile | 6 +- 14 files changed, 237 insertions(+), 85 deletions(-) diff --git a/cinelerra-5.1/cinelerra/atrack.C b/cinelerra-5.1/cinelerra/atrack.C index 1ef123da..9387ed9d 100644 --- a/cinelerra-5.1/cinelerra/atrack.C +++ b/cinelerra-5.1/cinelerra/atrack.C @@ -127,7 +127,7 @@ int ATrack::load_defaults(BC_Hash *defaults) void ATrack::set_default_title() { - Track *current = ListItem::owner->first; + Track *current = ListItem::list->first; int i; for(i = 0; current; current = NEXT) { diff --git a/cinelerra-5.1/cinelerra/mediadb.C b/cinelerra-5.1/cinelerra/mediadb.C index 2c057c09..bb2e826c 100644 --- a/cinelerra-5.1/cinelerra/mediadb.C +++ b/cinelerra-5.1/cinelerra/mediadb.C @@ -189,7 +189,7 @@ Clip(int clip_id, double start, double end, int index) Clip:: ~Clip() { - Clips *clips = (Clips *)owner; + Clips *clips = (Clips *)list; if( clips && clips->current == this ) clips->current = 0; } diff --git a/cinelerra-5.1/cinelerra/strack.C b/cinelerra-5.1/cinelerra/strack.C index 82435a2a..ffa6a5b1 100644 --- a/cinelerra-5.1/cinelerra/strack.C +++ b/cinelerra-5.1/cinelerra/strack.C @@ -45,7 +45,7 @@ int STrack::load_defaults(BC_Hash *defaults) void STrack::set_default_title() { - Track *current = ListItem::owner->first; + Track *current = ListItem::list->first; int i; for(i = 0; current; current = NEXT) { diff --git a/cinelerra-5.1/cinelerra/vtrack.C b/cinelerra-5.1/cinelerra/vtrack.C index c61ee3c3..580191ad 100644 --- a/cinelerra-5.1/cinelerra/vtrack.C +++ b/cinelerra-5.1/cinelerra/vtrack.C @@ -107,7 +107,7 @@ int VTrack::load_defaults(BC_Hash *defaults) void VTrack::set_default_title() { - Track *current = ListItem::owner->first; + Track *current = ListItem::list->first; int i; for(i = 0; current; current = NEXT) { diff --git a/cinelerra-5.1/guicast/Makefile b/cinelerra-5.1/guicast/Makefile index fbf609da..ba5e6cc3 100644 --- a/cinelerra-5.1/guicast/Makefile +++ b/cinelerra-5.1/guicast/Makefile @@ -115,7 +115,7 @@ $(shell echo $(OBJS) > $(OBJDIR)/objs) all: $(OUTPUT) $(UTILS) $(OBJDIR)/bcxfer.o: bcxfer.C xfer.C xfer.h - $(CXX) `cat $(OBJDIR)/c_flags` -c $< -o $@ + $(CXX) `cat $(OBJDIR)/c_flags` -O3 -c $< -o $@ bcxfer.C: bccmdl.py python < ./bccmdl.py > bcxfer.C diff --git a/cinelerra-5.1/guicast/bcbitmap.C b/cinelerra-5.1/guicast/bcbitmap.C index e9118da4..231ce559 100644 --- a/cinelerra-5.1/guicast/bcbitmap.C +++ b/cinelerra-5.1/guicast/bcbitmap.C @@ -56,7 +56,7 @@ BC_BitmapImage::~BC_BitmapImage() bool BC_BitmapImage::is_avail() { - return owner == &bitmap->avail; + return list == &bitmap->avail; } BC_BitmapImage *BC_Bitmap::cur_bfr() diff --git a/cinelerra-5.1/guicast/bccmdl.py b/cinelerra-5.1/guicast/bccmdl.py index 2850fe50..0c730de0 100755 --- a/cinelerra-5.1/guicast/bccmdl.py +++ b/cinelerra-5.1/guicast/bccmdl.py @@ -392,13 +392,17 @@ base = { } cmodels = [] +bcmodels = {} layout = {} -dtype = {} +dtype = { None: None } special = {} +mx_bcmdl = -1 -def add_cmodel(nm, typ=None, *args): - global cmodels, layout, dtype +def add_cmodel(n, nm, typ=None, *args): + global cmodels, bcmodels, layout, dtype, mx_bcmdl cmodels += [nm,] + bcmodels[n] = nm + if( n > mx_bcmdl ): mx_bcmdl = n dtype[nm] = typ layout[nm] = args @@ -406,44 +410,44 @@ def specialize(fr_cmdl, to_cmdl, fn): global special special[(fr_cmdl, to_cmdl)] = fn -add_cmodel("bc_transparency") -add_cmodel("bc_compressed") - -add_cmodel("bc_rgb8", "i8", "rgb8") -add_cmodel("bc_rgb565", "i8", "rgb565") -add_cmodel("bc_bgr565", "i8", "bgr565") -add_cmodel("bc_bgr888", "i8", "bgr888") -add_cmodel("bc_bgr8888", "i8", "bgr8888") - -add_cmodel("bc_rgb888", "i8", "rgb888") -add_cmodel("bc_rgba8888", "i8", "rgb888", "a8") -add_cmodel("bc_argb8888", "i8", "a8", "rgb888") -add_cmodel("bc_abgr8888", "i8", "a8", "bgr888") -add_cmodel("bc_rgb161616", "i16", "rgb161616") -add_cmodel("bc_rgba16161616", "i16", "rgb161616", "a16") -add_cmodel("bc_yuv888", "i8", "yuv888") -add_cmodel("bc_yuva8888", "i8", "yuv888", "a8") -add_cmodel("bc_yuv161616", "i16", "yuv161616") -add_cmodel("bc_yuva16161616", "i16", "yuv161616", "a16") - -add_cmodel("bc_yuv422", "i8", "yuyv8888") -add_cmodel("bc_uvy422", "i8", "uyvy8888") -add_cmodel("bc_a8") -add_cmodel("bc_a16") -add_cmodel("bc_a_float") -add_cmodel("bc_yuv101010", "i16", "yuv10101010") -add_cmodel("bc_vyu888", "i8", "vyu888") -add_cmodel("bc_uyva8888", "i8", "uyv888", "a8") -add_cmodel("bc_rgb_float", "fp", "rgbfloat") -add_cmodel("bc_rgba_float", "fp", "rgbfloat", "afp") - -add_cmodel("bc_yuv420p", "i8", "yuv420p") -add_cmodel("bc_yuv422p", "i8", "yuv422p") -add_cmodel("bc_yuv444p", "i8", "yuv444p") -add_cmodel("bc_yuv411p", "i8", "yuv411p") -add_cmodel("bc_yuv410p", "i8", "yuv410p") -add_cmodel("bc_rgb_floatp", "fp", "rgbfltp") -add_cmodel("bc_rgba_floatp", "fp", "rgbfltp", "afpp") +add_cmodel( 0, "bc_transparency") +add_cmodel( 1, "bc_compressed") + +add_cmodel( 2, "bc_rgb8", "i8", "rgb8") +add_cmodel( 3, "bc_rgb565", "i8", "rgb565") +add_cmodel( 4, "bc_bgr565", "i8", "bgr565") +add_cmodel( 5, "bc_bgr888", "i8", "bgr888") +add_cmodel( 6, "bc_bgr8888", "i8", "bgr8888") + +add_cmodel( 9, "bc_rgb888", "i8", "rgb888") +add_cmodel(10, "bc_rgba8888", "i8", "rgb888", "a8") +add_cmodel(20, "bc_argb8888", "i8", "a8", "rgb888") +add_cmodel(21, "bc_abgr8888", "i8", "a8", "bgr888") +add_cmodel(11, "bc_rgb161616", "i16", "rgb161616") +add_cmodel(12, "bc_rgba16161616", "i16", "rgb161616", "a16") +add_cmodel(13, "bc_yuv888", "i8", "yuv888") +add_cmodel(14, "bc_yuva8888", "i8", "yuv888", "a8") +add_cmodel(15, "bc_yuv161616", "i16", "yuv161616") +add_cmodel(16, "bc_yuva16161616", "i16", "yuv161616", "a16") + +add_cmodel(18, "bc_yuv422", "i8", "yuyv8888") +add_cmodel(19, "bc_uvy422", "i8", "uyvy8888") +add_cmodel(22, "bc_a8") +add_cmodel(23, "bc_a16") +add_cmodel(31, "bc_a_float") +add_cmodel(24, "bc_yuv101010", "i16", "yuv10101010") +add_cmodel(25, "bc_vyu888", "i8", "vyu888") +add_cmodel(26, "bc_uyva8888", "i8", "uyv888", "a8") +add_cmodel(29, "bc_rgb_float", "fp", "rgbfloat") +add_cmodel(30, "bc_rgba_float", "fp", "rgbfloat", "afp") + +add_cmodel( 7, "bc_yuv420p", "i8", "yuv420p") +add_cmodel( 8, "bc_yuv422p", "i8", "yuv422p") +add_cmodel(27, "bc_yuv444p", "i8", "yuv444p") +add_cmodel(17, "bc_yuv411p", "i8", "yuv411p") +add_cmodel(28, "bc_yuv410p", "i8", "yuv410p") +add_cmodel(32, "bc_rgb_floatp", "fp", "rgbfltp") +add_cmodel(33, "bc_rgba_floatp", "fp", "rgbfltp", "afpp") specialize("bc_rgba8888", "bc_transparency", "XFER_rgba8888_to_transparency") @@ -498,7 +502,7 @@ def gen_xfer_proto(pfx, cls, fr_cmdl, to_cmdl): print "%svoid %sxfer_%s_to_%s" % (pfx, cls, fr_cmdl[3:], to_cmdl[3:]), ityp = dtype[fr_cmdl]; fr_typ = ctype[ityp]; otyp = dtype[to_cmdl]; to_typ = ctype[otyp]; - print "()", + print "(unsigned y0, unsigned y1)", def gen_xfer_fn(fr_cmdl, to_cmdl): global layout, dtype, adata @@ -574,7 +578,7 @@ for fr_cmdl in cmodels: for to_cmdl in cmodels: otyp = dtype[to_cmdl] if( is_specialized(fr_cmdl, to_cmdl) ): - print " void %s();" % (special[(fr_cmdl, to_cmdl)]) + print " void %s(unsigned y0, unsigned y1);" % (special[(fr_cmdl, to_cmdl)]) continue if( ityp is None or otyp is None ): continue gen_xfer_proto(" ", "", fr_cmdl, to_cmdl); @@ -592,24 +596,27 @@ for fr_cmdl in cmodels: print "" print "void %sxfer()" % class_qual print "{" -print " switch(in_colormodel) {" -for fr_cmdl in cmodels: +mx_no = mx_bcmdl + 1 +print " static xfer_fn xfns[%d][%d] = {" % (mx_no, mx_no) +for fr_no in range(mx_no): + fr_cmdl = bcmodels.get(fr_no) ityp = dtype[fr_cmdl] - if( ityp is None ): - if( not fr_cmdl in [it[0] for it in special] ): continue - print " case %s:" % (fr_cmdl.upper()) - print " switch(out_colormodel) {" - for to_cmdl in cmodels: - if( is_specialized(fr_cmdl, to_cmdl) ): - print " case %s: %s(); break;" % (to_cmdl.upper(), special[(fr_cmdl, to_cmdl)]) - continue + print " { // %s" % (fr_cmdl.upper() if ityp else "None") + n = 0 + for to_no in range(mx_no): + to_cmdl = bcmodels.get(to_no) otyp = dtype[to_cmdl] - if( ityp is None or otyp is None ): continue - print " case %s:" % (to_cmdl.upper()), - print "xfer_%s_to_%s(); break;" % (fr_cmdl[3:], to_cmdl[3:]) - print " }" - print " break;" -print " }" + xfn = special[(fr_cmdl, to_cmdl)] if( is_specialized(fr_cmdl, to_cmdl) ) else \ + "xfer_%s_to_%s" % (fr_cmdl[3:], to_cmdl[3:]) if ( ityp and otyp ) else None + if( n > 72 ): print ""; n = 0 + if( n == 0 ): print " ",; n += 4 + fn = "&%s%s" % (class_qual, xfn) if( xfn ) else "0" + print "%s, " % (fn), + n += len(fn) + 3 + print "}, " +print " }; " +print " xfn = xfns[in_colormodel][out_colormodel];" +print " xfer_slices(out_w*out_h/0x80000+1);" print "}" print "" print "#include \"xfer.C\"" diff --git a/cinelerra-5.1/guicast/bccmodels.h b/cinelerra-5.1/guicast/bccmodels.h index b6c397b3..94a9bbcd 100644 --- a/cinelerra-5.1/guicast/bccmodels.h +++ b/cinelerra-5.1/guicast/bccmodels.h @@ -124,6 +124,7 @@ public: static void init_yuv(); static int bc_to_x(int color_model); + static void bcxfer_stop_slicers(); }; diff --git a/cinelerra-5.1/guicast/bcsignals.C b/cinelerra-5.1/guicast/bcsignals.C index 609ea1e2..3886cd64 100644 --- a/cinelerra-5.1/guicast/bcsignals.C +++ b/cinelerra-5.1/guicast/bcsignals.C @@ -21,6 +21,7 @@ #include "bcsignals.h" #include "bcwindowbase.h" +#include "bccmodels.h" #include "bckeyboard.h" #include "bcresources.h" @@ -419,6 +420,10 @@ void BC_Signals::set_sighup_exit(int enable) BC_Signals::BC_Signals() { } +BC_Signals::~BC_Signals() +{ + BC_CModels::bcxfer_stop_slicers(); +} void BC_Signals::dump_traces(FILE *fp) { diff --git a/cinelerra-5.1/guicast/bcsignals.h b/cinelerra-5.1/guicast/bcsignals.h index f5d4fa04..05d44f87 100644 --- a/cinelerra-5.1/guicast/bcsignals.h +++ b/cinelerra-5.1/guicast/bcsignals.h @@ -64,6 +64,7 @@ class BC_Signals static int x_error_handler(Display *display, XErrorEvent *event); public: BC_Signals(); + ~BC_Signals(); void initialize(); void initialize2(); void terminate(); diff --git a/cinelerra-5.1/guicast/linklist.h b/cinelerra-5.1/guicast/linklist.h index 284a0ebf..000f0f21 100644 --- a/cinelerra-5.1/guicast/linklist.h +++ b/cinelerra-5.1/guicast/linklist.h @@ -7,12 +7,12 @@ template class ListItem { public: TYPE *previous, *next; - List *owner; + List *list; - int get_item_number() { return !owner ? -1 : owner->number_of(this); } - ListItem() { owner = 0; previous = next = 0; } - ListItem(List &me) { owner = me; previous = next = 0; } - virtual ~ListItem() { if( owner ) owner->remove_pointer(this); } + int get_item_number() { return !list ? -1 : list->number_of(this); } + ListItem() { list = 0; previous = next = 0; } + ListItem(List &me) { list = me; previous = next = 0; } + virtual ~ListItem() { if( list ) list->remove_pointer(this); } }; template @@ -57,7 +57,7 @@ public: template TYPE* List::append(TYPE *item) { - item->owner = this; item->next = 0; + item->list = this; item->next = 0; if( !last ) { item->previous = 0; first = item; } else { item->previous = last; last->next = item; } return last = item; @@ -67,7 +67,7 @@ template TYPE* List::insert_before(TYPE *here, TYPE *item) { if( !here || !last ) return append(item); - item->owner = this; item->next = here; + item->list = this; item->next = here; *( !(item->previous=here->previous) ? &first : &here->previous->next ) = item; return here->previous = item; } @@ -76,7 +76,7 @@ template TYPE* List::insert_after(TYPE *here, TYPE *item) { if( !here || !last ) return append(item); - item->owner = this; item->previous = here; + item->list = this; item->previous = here; *( !(item->next=here->next) ? &last : &here->next->previous ) = item; return here->next = item; } @@ -89,7 +89,7 @@ void List::remove_pointer(ListItem *item) TYPE *previous = item->previous, *next = item->next; *( previous ? &previous->next : &first ) = next; *( next ? &next->previous : &last ) = previous; - item->owner = 0; + item->list = 0; } template diff --git a/cinelerra-5.1/guicast/xfer.C b/cinelerra-5.1/guicast/xfer.C index c689b6b6..87ad6bdd 100644 --- a/cinelerra-5.1/guicast/xfer.C +++ b/cinelerra-5.1/guicast/xfer.C @@ -245,9 +245,9 @@ void BC_CModels::transfer( // specialized functions // in bccmdl.py: specialize("bc_rgba8888", "bc_transparency", "XFER_rgba8888_to_transparency") -void BC_Xfer::XFER_rgba8888_to_transparency() +void BC_Xfer::XFER_rgba8888_to_transparency(unsigned y0, unsigned y1) { - for( unsigned i=0; ilock("BC_Xfer::SlicerList::get_slicer"); + } + Slicer *slicer = first; + remove_pointer(slicer); + return slicer; +} + +void BC_Xfer::xfer_slices(int slices) +{ + if( !xfn ) return; + int max_slices = BC_Resources::machine_cpus/2+1; + if( slices > max_slices ) slices = max_slices; + Slicer *active[slices]; + unsigned y0 = 0, y1 = out_h; + int slices1 = slices-1; + if( slices1 > 0 ) { + slicers.lock("BC_Xfer::xfer_slices"); + for( int i=0; islice(this, y0, y1); + } + slicers.unlock(); + } + (this->*xfn)(y0, out_h); + if( slices1 > 0 ) { + for( int i=0; icomplete->lock("BC_Xfer::xfer_slices"); + slicers.lock("BC_Xfer::xfer_slices"); + for( int i=0; iunlock(); + } +} + +BC_Xfer::Slicer::Slicer(BC_Xfer *xp) +{ + this->xp = xp; + init = new Condition(0, "BC_Xfer::Slicer::init", 0); + complete = new Condition(0, "BC_Xfer::Slicer::complete", 0); + done = 0; + start(); +} +BC_Xfer::Slicer::~Slicer() +{ + done = 1; + init->unlock(); + join(); +} + +void BC_Xfer::Slicer::slice(BC_Xfer *xp, unsigned y0, unsigned y1) +{ + this->xp = xp; + this->y0 = y0; + this->y1 = y1; + init->unlock(); +} + +void BC_Xfer::Slicer::run() +{ + while( !done ) { + init->lock("Slicer::run"); + if( done ) break; + xfer_fn xfn = xp->xfn; + (xp->*xfn)(y0, y1); + complete->unlock(); + } +} + +void BC_CModels::bcxfer_stop_slicers() +{ + BC_Xfer::slicers.reset(); +} + diff --git a/cinelerra-5.1/guicast/xfer.h b/cinelerra-5.1/guicast/xfer.h index ddbca7f0..bb69407f 100644 --- a/cinelerra-5.1/guicast/xfer.h +++ b/cinelerra-5.1/guicast/xfer.h @@ -1,4 +1,9 @@ #include "bccmodels.h" +#include "bcresources.h" +#include "condition.h" +#include "linklist.h" +#include "mutex.h" +#include "thread.h" #include "clip.h" static inline float clp(const int n, float v) { @@ -78,7 +83,7 @@ ZTYP(float); #define xfer_flat_row_out(oty_t) \ - for( unsigned i=0; i, public Thread { + public: + Condition *init, *complete; + Slicer(BC_Xfer *xp); + ~Slicer(); + void slice(BC_Xfer *xp, unsigned y0, unsigned y1); + void run(); + BC_Xfer *xp; + int done, y0, y1; + }; + + class SlicerList : public List, public Mutex { + public: + int count; + Condition *waiting; + Slicer *get_slicer(BC_Xfer *xp); + void reset(); + SlicerList(); + ~SlicerList(); + }; + static SlicerList slicers; static void init(); static class Tables { public: Tables() { init(); } } tables; diff --git a/cinelerra-5.1/plugins/Makefile b/cinelerra-5.1/plugins/Makefile index 2467e78d..c979a9c7 100644 --- a/cinelerra-5.1/plugins/Makefile +++ b/cinelerra-5.1/plugins/Makefile @@ -37,7 +37,6 @@ DIRS = \ delayvideo \ denoise \ denoisefft \ - denoisemjpeg \ denoiseseltempavg \ denoisevideo \ despike \ @@ -58,7 +57,6 @@ DIRS = \ gamma \ gradient \ graphic \ - greycstoration \ histogram \ histogram_bezier \ holo \ @@ -139,7 +137,11 @@ DIRS = \ theme_suv \ theme_unflat \ +# too costly # findobject \ +# greycstoration \ +# not finished +# denoisemjpeg \ DATA = $(PLUGIN_DIR)/fonts $(PLUGIN_DIR)/shapes LADSPA = $(BINDIR)/ladspa -- 2.26.2