add lv2 plugin interface
[goodguy/history.git] / cinelerra-5.1 / cinelerra / pluginfclient.C
index 2a35e96c7539c2039e2914471d1926502f9e484e..114d64e547d4559280abfa246c7936ae6da6306b 100644 (file)
@@ -532,7 +532,7 @@ PluginFClient::~PluginFClient()
        delete ffilt;
 }
 
-bool PluginFClient::is_audio(AVFilter *fp)
+bool PluginFClient::is_audio(const AVFilter *fp)
 {
        if( !fp->outputs ) return 0;
        if( avfilter_pad_count(fp->outputs) > 1 ) return 0;
@@ -544,7 +544,7 @@ bool PluginFClient::is_audio(AVFilter *fp)
        if( avfilter_pad_get_type(fp->inputs, 0) != AVMEDIA_TYPE_AUDIO ) return 0;
        return 1;
 }
-bool PluginFClient::is_video(AVFilter *fp)
+bool PluginFClient::is_video(const AVFilter *fp)
 {
        if( !fp->outputs ) return 0;
        if( avfilter_pad_count(fp->outputs) > 1 ) return 0;
@@ -805,14 +805,14 @@ int PluginFAClient::get_inchannels()
 {
        AVFilterContext *fctx = ffilt->fctx;
        AVFilterLink **links = !fctx->nb_inputs ? 0 : fctx->inputs;
-       return !links ? 0 : avfilter_link_get_channels(links[0]);
+       return !links ? 0 : links[0]->channels;
 }
 
 int PluginFAClient::get_outchannels()
 {
        AVFilterContext *fctx = ffilt->fctx;
        AVFilterLink **links = !fctx->nb_outputs ? 0 : fctx->outputs;
-       return !links ? 0 : avfilter_link_get_channels(links[0]);
+       return !links ? 0 : links[0]->channels;
 }
 
 int PluginFAClient::process_buffer(int64_t size, Samples **buffer, int64_t start_position, int sample_rate)
@@ -939,7 +939,7 @@ int PluginFVClient::process_buffer(VFrame **frames, int64_t position, double fra
                ret = av_buffersink_get_frame(fsink, frame);
                if( ret >= 0 || ret != AVERROR(EAGAIN) ) break;
                if( !fsrc ) { ret = AVERROR(EIO);  break; }
-               read_frame(vframe, 0, filter_position++, frame_rate, get_use_opengl());
+               read_frame(vframe, 0, filter_position++, frame_rate, 0);
                frame->format = pix_fmt;
                frame->width  = width;
                frame->height = height;
@@ -1098,15 +1098,24 @@ int PluginFFilter::init(const char *name, PluginFClientConfig *conf)
                graph->nb_threads  = 0;
        }
        fctx = avfilter_graph_alloc_filter(graph, filter, inst_name);
-       fctx->thread_type = graph->thread_type; // bug in avfilter
        if( !fctx ) return AVERROR(ENOMEM);
+       fctx->thread_type = graph->thread_type; // bug in avfilter
        if( conf ) {
                AVDictionary *opts = 0;
                for( int i=0; i<conf->size(); ++i ) {
                        PluginFClient_Opt *op = conf->get(i);
                        const char *name = op->opt->name;
                        char val[BCTEXTLEN], *vp = op->get(val, sizeof(val));
-                       if( vp ) av_dict_set(&opts, name, vp, 0);
+                       if( !vp ) continue;
+                       uint8_t *bp = 0;
+// unspecified opts cause a special behavior in some filters (lut3d)
+// so... if opt value is the default, skip it or no special behavior
+                       if( av_opt_get(filter_config(), name, 0, &bp) >= 0 ) {
+                               int result = strcmp((const char *)bp, vp);
+                               av_freep(&bp);
+                               if( !result ) continue;
+                       }
+                       av_dict_set(&opts, name, vp, 0);
                }
                ret = avfilter_init_dict(fctx, &opts);
                av_dict_free(&opts);
@@ -1142,7 +1151,7 @@ PluginFFilter *PluginFFilter::new_ffilter(const char *name, PluginFClientConfig
 
 PluginClient *PluginServer::new_ffmpeg_plugin()
 {
-       AVFilter *filter = avfilter_get_by_name(ff_name);
+       const AVFilter *filter = avfilter_get_by_name(ff_name);
        if( !filter ) return 0;
        PluginFClient *ffmpeg =
                PluginFClient::is_audio(filter) ?
@@ -1160,14 +1169,15 @@ PluginServer* MWindow::new_ffmpeg_server(MWindow *mwindow, const char *name)
        PluginFFilter *ffilt = PluginFFilter::new_ffilter(name);
        if( !ffilt ) return 0;
        delete ffilt;
-       return new PluginServer(mwindow, (char*)name, PLUGIN_TYPE_FFMPEG);
+       return new PluginServer(mwindow, name, PLUGIN_TYPE_FFMPEG);
 }
 
 void MWindow::init_ffmpeg_index(MWindow *mwindow, Preferences *preferences, FILE *fp)
 {
        PluginFLogLevel errs(AV_LOG_ERROR);
-       const AVFilter *filter = 0;
-       while( (filter=avfilter_next(filter)) != 0 ) {
+       const AVFilter *filter = 0;  void *idx = 0;
+       while( (filter=av_filter_iterate(&idx)) != 0 ) {
+//printf("%s\n",filter->name);
                PluginServer *server = new_ffmpeg_server(mwindow, filter->name);
                if( server ) {
                        int result = server->open_plugin(1, preferences, 0, 0);
@@ -1183,7 +1193,5 @@ void MWindow::init_ffmpeg_index(MWindow *mwindow, Preferences *preferences, FILE
 
 void MWindow::init_ffmpeg()
 {
-       av_register_all();
-       avfilter_register_all();
 }