pluginclient delete window bug/segv + cleanups/improvements
authorGood Guy <good1.2guy@gmail.com>
Sat, 23 Apr 2016 22:19:37 +0000 (16:19 -0600)
committerGood Guy <good1.2guy@gmail.com>
Sat, 23 Apr 2016 22:19:37 +0000 (16:19 -0600)
cinelerra-5.1/cinelerra/Makefile
cinelerra-5.1/cinelerra/mwindow.C
cinelerra-5.1/cinelerra/pluginclient.C
cinelerra-5.1/cinelerra/pluginclient.h
cinelerra-5.1/cinelerra/pluginfclient.C
cinelerra-5.1/cinelerra/pluginfclient.h
cinelerra-5.1/cinelerra/sha1.C
cinelerra-5.1/guicast/thread.C
cinelerra-5.1/plugins/denoise/denoise.C

index 84cbb72938b998dc9ab1f725a402bd1991da2531..11af09329c0fc2377b4d9047d9b7d1e32afff406 100644 (file)
@@ -470,6 +470,9 @@ tags:
 $(OBJDIR)/%.o:         %.C
        $(CXX) `cat $(OBJDIR)/c_flags` -c $< -o $@
 
+$(OBJDIR)/sha1.o:      sha1.C sha1.h
+       $(CXX) `cat $(OBJDIR)/c_flags` -O3 -c $< -o $@
+
 $(DCRAW): dcraw.c
        $(GCC) `cat $(OBJDIR)/c_flags` dcraw.c -o $*.o
 
index b9615c1f7073f76de53edd2d48cd033a4be7f169..98736302e6e28a3188dc0f21bbb40fb560fff6be 100644 (file)
 #include "defaultformats.h"
 #include "ntsczones.h"
 
-#include <sys/types.h>
-#include <sys/stat.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
 #include <fcntl.h>
 #include <string.h>
+#include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/mman.h>
+#include <limits.h>
+#include <errno.h>
 
 
 extern "C"
@@ -3107,37 +3113,50 @@ void MWindow::dump_exe(FILE *fp)
 {
         char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
         sprintf(proc_path, "/proc/%d/exe", (int)getpid());
-        int len = readlink(proc_path, exe_path, sizeof(exe_path));
-       if( len < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
-       exe_path[len] = 0;
+        int ret = readlink(proc_path, exe_path, sizeof(exe_path));
+       if( ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
+       exe_path[ret] = 0;
        struct stat st;
        if( stat(exe_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
        fprintf(fp, "path: %s = %9jd bytes\n",exe_path,st.st_size);
-       int fd = open(exe_path,O_RDONLY);
+       int fd = open(exe_path,O_RDONLY+O_NONBLOCK);
        if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
-       uint8_t buf[65536];  SHA1 sha1;
-       while( (len=read(fd,buf,sizeof(buf))) > 0 ) {
-               sha1.addBytes(buf, len);
+       uint8_t *bfr = 0;
+       int64_t bfrsz = 0;
+       int64_t pagsz = sysconf(_SC_PAGE_SIZE);
+       int64_t maxsz = 1024*pagsz;
+       int64_t size = st.st_size, pos = 0;
+       SHA1 sha1;
+       while( (bfrsz = size-pos) > 0 ) {
+               if( bfrsz > maxsz ) bfrsz = maxsz;
+               bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
+                       MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
+               if( bfr == MAP_FAILED ) break;
+               sha1.addBytes(bfr, bfrsz);
+               munmap(bfr, bfrsz);
+               pos += bfrsz;
        }
        close(fd);
+       ret = pos < size ? EIO : 0;
        fprintf(fp, "SHA1: ");
        uint8_t digest[20];  sha1.computeHash(digest);
        for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
+       if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
+       if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
        fprintf(fp, "\n");
 }
 
-
 void MWindow::trap_hook(FILE *fp, void *vp)
 {
        MWindow *mwindow = (MWindow *)vp;
-       fprintf(fp, "\nEXE:\n");
-       mwindow->dump_exe(fp);
-       fprintf(fp, "\nPLUGINS:\n");
-       mwindow->dump_plugins(fp);
+//     fprintf(fp, "\nPLUGINS:\n");
+//     mwindow->dump_plugins(fp);
        fprintf(fp, "\nEDL:\n");
        mwindow->dump_edl(fp);
        fprintf(fp, "\nUNDO:\n");
        mwindow->dump_undo(fp);
+       fprintf(fp, "\nEXE:\n");
+       mwindow->dump_exe(fp);
 }
 
 
@@ -3400,7 +3419,7 @@ int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tra
        int result = file->open_file(preferences, asset, 1, 0);
        if( !result && delete_tracks > 0 )
                undo->update_undo_before();
-       if( !result && asset->get_video_layers() > 0 ) {
+       if( !result && asset->video_data && asset->get_video_layers() > 0 ) {
                // try to get asset up to date, may fail
                file->select_video_stream(asset, vstream);
                // either way use what was/is there.
@@ -3452,14 +3471,16 @@ int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tra
                }
                edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
        }
-       if( !result && asset->channels > 0 ) {
+       if( !result && asset->audio_data && asset->channels > 0 ) {
                session->sample_rate = asset->get_sample_rate();
                int64_t channel_mask = 0;
-               int astrm = file->get_audio_for_video(vstream, astream, channel_mask);
+               int astrm = !asset->video_data ? -1 :
+                       file->get_audio_for_video(vstream, astream, channel_mask);
                if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
                if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
                int channels = 0;
                for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
+               if( channels < 1 ) channels = 1;
                if( channels > 6 ) channels = 6;
                session->audio_tracks = session->audio_channels = channels;
                switch( channels ) {
@@ -3475,6 +3496,15 @@ int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tra
                        session->achannel_positions[0] = 180;
                        session->achannel_positions[1] = 0;
                        break;
+               case 1:
+                       session->achannel_positions[1] = 90;
+                       break;
+               default: {
+                       if( !channels ) break;
+                       double t = 0, dt = 360./channels;
+                       for( int i=channels; --i>=0; t+=dt )
+                               session->achannel_positions[i] = int(t+0.5);
+                       break; }
                }
                remap_audio(MWindow::AUDIO_1_TO_1);
 
@@ -3510,6 +3540,8 @@ int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tra
 int MWindow::select_asset(int vtrack, int delete_tracks)
 {
        Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
+       if( !track )
+               track = edl->tracks->get(vtrack, TRACK_AUDIO);
        if( !track ) return 1;
        Edit *edit = track->edits->first;
        if( !edit ) return 1;
index cccdcde077d8bc6bfefe9c021b2b1b9f99a4dc02..096d03e32664ccaee8163e8efc5d597d2ac293c4 100644 (file)
@@ -55,8 +55,9 @@ PluginClientThread::PluginClientThread(PluginClient *client)
 
 PluginClientThread::~PluginClientThread()
 {
-//printf("PluginClientThread::~PluginClientThread %p %d\n", this, __LINE__);
        join();
+//printf("PluginClientThread::~PluginClientThread %p %d\n", this, __LINE__);
+       delete window;  window = 0;
 //printf("PluginClientThread::~PluginClientThread %p %d\n", this, __LINE__);
        delete init_complete;
 }
@@ -67,10 +68,10 @@ void PluginClientThread::run()
        int result = 0;
        if(client->window_x < 0) client->window_x = info.get_abs_cursor_x();
        if(client->window_y < 0) client->window_y = info.get_abs_cursor_y();
-       window = client->new_window();
+       if(!window)
+               window = client->new_window();
 
-       if(window)
-       {
+       if(window) {
                window->lock_window("PluginClientThread::run");
                window->create_objects();
                window->unlock_window();
@@ -84,7 +85,6 @@ void PluginClientThread::run()
 //printf("PluginClientThread::run %p %d\n", this, __LINE__);
                window->hide_window(1);
                window->unlock_window();
-               delete window;  window = 0;
 // Can't save defaults in the destructor because it's not called immediately
 // after closing.
                /* if(client->defaults) */ client->save_defaults_xml();
@@ -658,12 +658,6 @@ int PluginClient::get_gui_status()
        return server->get_gui_status();
 }
 
-int PluginClient::start_plugin()
-{
-       printf(_("No processing defined for this plugin.\n"));
-       return 0;
-}
-
 // close event from client side
 void PluginClient::client_side_close()
 {
index da684b4fb257b6914f6256f6cfd4c778a7423cf7..9f5b10c20dfb78f3e6065bf0b84de5d55fa70fcf 100644 (file)
@@ -241,7 +241,6 @@ public:
 // For realtime plugins give the requested framerate.
        virtual double get_framerate();
        virtual int delete_nonrealtime_parameters();
-       virtual int start_plugin();         // run a non realtime plugin
        virtual int get_parameters();     // get information from user before non realtime processing
        virtual int64_t get_in_buffers(int64_t recommended_size);  // return desired size for input buffers
        virtual int64_t get_out_buffers(int64_t recommended_size);     // return desired size for output buffers
index 1bea7dd04ba1564c7fbbdfd748409e9c15f604c6..fdafc29e72f3860076214daab44f3a415c32ec38 100644 (file)
@@ -76,6 +76,7 @@ void PluginFClientConfig::interpolate(PluginFClientConfig &prev, PluginFClientCo
 
 void PluginFClientConfig::initialize(const char *name)
 {
+       delete ffilt;
        ffilt = PluginFFilter::new_ffilter(name);
        const AVOption *opt = 0;
        void *obj = ffilt->filter_config();
@@ -154,7 +155,7 @@ PluginFClientReset::
 
 int PluginFClientReset::handle_event()
 {
-       av_opt_set_defaults(fwin->ffmpeg->config.filter_config());
+       fwin->ffmpeg->config.initialize(fwin->ffmpeg->name);
        if( fwin->ffmpeg->config.update() > 0 )
                fwin->draw();
        fwin->ffmpeg->plugin->send_configure_change();
index 781e2523a2e69327b9d1f1dd0cec723960b20659..4d112568add51a6ec4b87a1a96fd2ce708caaceb 100644 (file)
@@ -232,7 +232,7 @@ public:
        int activate();
        void reactivate();
 
-        PluginFClientConfig curr_config, av_config;
+        PluginFClientConfig curr_config;
         PLUGIN_CLASS_MEMBERS(PluginFClientConfig)
 };
 
index ad5becf899edc142b129c13658b6741a0a9a6be8..17471f94588e528a43499688372c17d7193f6e05 100644 (file)
@@ -3,10 +3,24 @@
 
 void SHA1::addBytes(const uint8_t* input, size_t length)
 {
-       while (length--) {
-               m_buffer[m_cursor++] = *input++;
-               ++m_totalBytes;
-               if (m_cursor == 64) processBlock();
+       m_totalBytes += length;
+       while (length > 0) {
+#if 1
+// allow unaliged access
+               uint64_t *buf = (uint64_t*)&m_buffer[m_cursor];
+               const uint64_t *inp = (const uint64_t*)input;
+               while (length >= sizeof(uint64_t) && m_cursor < 64) {
+                       *buf++ = *inp++;
+                       m_cursor += sizeof(uint64_t);
+                       length -= sizeof(uint64_t);
+               }
+               input = (const uint8_t *)inp;
+#endif
+               while (length > 0 && m_cursor < 64) {
+                       m_buffer[m_cursor++] = *input++;
+                       --length;
+               }
+               if( m_cursor >= 64 ) processBlock();
        }
 }
 
index 3d817272221f3049dba6e633d3ba72f9c256dab4..355d23d551561cb0dd236fa7b508597cad1556b3 100644 (file)
@@ -316,7 +316,7 @@ void Thread::dump_threads(FILE *fp)
 {
        int i = thread_list.size();
        while( --i >= 0 ) {
-               fprintf(fp, "thread %016lx, owner %016lx, %s\n",
+               fprintf(fp, "thread 0x%012lx, owner 0x%012lx, %s\n",
                        (unsigned long)thread_list[i]->tid, (unsigned long)thread_list[i]->owner,
                        thread_list[i]->name);
        }
index 8aa7ed7d8769baf94ec3fd911b079f3ea649fd1a..063a23f429067e8c150f37911e931bdab8f48968 100644 (file)
@@ -618,7 +618,7 @@ Tree::~Tree()
        int i;
 
        for (i = 2 * levels - 1; i >= 0; i--)
-               delete values[i];
+               delete [] values[i];
 
        delete values;
 }