How would you wrap a complicated C struct (pointers to functions, ** pointers)?

Asked by Billy Chang

Hi, I'm quite new to PyBindGen, and maybe I'm crazy but I'm trying to wrap parts of ffmpeg.
There are a few quite complicated structs which I'm not certain how to wrap:

typedef struct AVOutputFormat {
    const char *name;

    enum CodecID audio_codec;

    int (*write_header)(struct AVFormatContext *);
    int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);

    int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
    int (*interleave_packet)(struct AVFormatContext *, AVPacket *out, AVPacket *in, int flush);

    const struct AVCodecTag **codec_tag;

    /* private fields */
    struct AVOutputFormat *next;
} AVOutputFormat;

How would you wrap this struct?

Question information

Language:
English Edit question
Status:
Answered
For:
PyBindGen Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Gustavo Carneiro (gjc) said :
#1

Erm.. I don't think you can wrap most of it with pybindgen, or at least not automatically, sorry :P

First you start with wrapping the structure:
 AVOutputFormat = module.add_struct('AVOutputFormat')

Then you add the fields:

  AVOutputFormat.add_instance_attribute('name', retval('char*', 'name', is_const=True))
  AVOutputFormat.add_instance_attribute('audio_codec', retval('CodecID', 'audio_codec'))

The rest are function pointers, and ** pointers to structs (array?), which are not directly supported by pybindgen.

If it was me, I would simply code the AVOutputFormat python type manually and integrate it with pybindgen through type handlers.

Can you help with this problem?

Provide an answer of your own, or ask Billy Chang for more information if necessary.

To post a message you must log in.