• singintime

    Hi everybody,

    I'm trying to write a pdp external using the libavcodec library, to expand the video decoding capabilities of the system. I'm following Stephen Dranger's tutorial (available at http://www.dranger.com/ffmpeg/) cause it's very well organized and clear. Still I'm not able to open video files inside pd, while the same piece of code works perfectly in the sample standalone program.

    This is the code of my external:

    #include <stdlib.h>
    #include <stdio.h>
    #include <libavcodec/avcodec.h>
    #include <libavformat/avformat.h>
    #include <libswscale/swscale.h>
    #include "pdp.h"
    
    typedef struct pdp_in_struct {
        t_object x_obj;
        t_outlet *x_outlet0;
        int x_packet0, x_queue_id;
        u32 x_width, x_height;
    } t_pdp_in;
    
    static void pdp_in_sendpacket(t_pdp_in *x)
    {
        /* unregister and propagate if valid dest packet */
        pdp_packet_pass_if_valid(x->x_outlet0, &x->x_packet0);
    }
    
    static void pdp_in_process(t_pdp_in *x)
    {
    
    }
    
    int pdp_in_open(t_pdp_in *x, t_symbol *s)
    {
        const char *filename = s->s_name;
        AVFormatContext *pFormatCtx;
    
        av_register_all();
    
        // Open video file
        if(av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL)!=0)
        {
            post("Can't open file");
            return -1; // Couldn't open file
        }
    
        // Retrieve stream information
        if(av_find_stream_info(pFormatCtx)<0)
            return -1; // Couldn't find stream information
    
        // Dump information about file onto standard error
        dump_format(pFormatCtx, 0, filename, 0);
        return 0;
    }
    
    t_class *pdp_in_class;
    
    void pdp_in_free(t_pdp_in *x)
    {
        t_pdp_procqueue *q = pdp_queue_get_queue();
        pdp_procqueue_finish(q, x->x_queue_id);
        pdp_packet_mark_unused(x->x_packet0);
    }
    
    void *pdp_in_new(void)
    {
        t_pdp_in *x = (t_pdp_in *)pd_new(pdp_in_class);
    
        x->x_outlet0 = outlet_new(&x->x_obj, &s_anything);
    
        x->x_packet0 = -1;
        x->x_queue_id = -1;
        x->x_width = -1;
        x->x_height = -1;
    
        return (void *)x;
    }
    
    #ifdef __cplusplus
    extern "C"
    {
    #endif
    
    void pdp_in_setup(void)
    {
        pdp_in_class = class_new(gensym("pdp_in"), (t_newmethod)pdp_in_new,
            (t_method)pdp_in_free, sizeof(t_pdp_in), 0, A_DEFFLOAT, A_DEFFLOAT, A_NULL);
    
        class_addmethod(pdp_in_class, (t_method)pdp_in_open, gensym("open"), A_SYMBOL, A_NULL);
    }
    
    #ifdef __cplusplus
    }
    #endif
    

    Am I missing something?
    Thanks

    Stefano

    posted in pixel# read more
Internal error.

Oops! Looks like something went wrong!