Correct way to map C #define to version
Sumit Raja
sumitraja at gmail.com
Mon Oct 22 04:05:23 PDT 2012
Hi,
My first post here as a new D user. I am trying to interface with
FFmpeg with D and need some guidance on how to replicate the
version semantics in a C header. I'd like to open source the D
modules files so I want to get this right.
FFMpeg defines a bunch of constants that are then used in the
headers to include/exclude fields from structs.
e.g.
struct AVFilterBufferRefAudioProps {
uint64_t channel_layout; ///< channel layout of audio
buffer
int nb_samples; ///< number of audio samples per
channel
int sample_rate; ///< audio buffer sample rate
#if FF_API_PACKING
int planar; ///< audio buffer - planar or
packed
#endif
} AVFilterBufferRefAudioProps;
where FF_API_PACKING is defines as:
#define LIBAVFILTER_VERSION_MAJOR 2
#define LIBAVFILTER_VERSION_MINOR 77
#define LIBAVFILTER_VERSION_MICRO 100
.
.
.
#ifndef FF_API_PACKING
#define FF_API_PACKING
(LIBAVFILTER_VERSION_MAJOR < 3)
#endif
I tried to do the following:
version (V54_23_100) {
version = FF_API_PACKING;
}
and then specify the version at the top of my D interface files:
version = V54_23_100
and define the struct as
struct AVFilterBufferRefAudioProps {
uint64_t channel_layout; ///< channel layout of audio
buffer
int nb_samples; ///< number of audio samples per
channel
int sample_rate; ///< audio buffer sample rate
version(FF_API_PACKING) {
int planar; ///< audio buffer - planar or
packed
}
}
but this resulted in the wrong size of struct when the C
functions were called - the struct did not container the planer
field.
Am I using version correctly? How is this done usually?
Thanks
Sumit
More information about the Digitalmars-d-learn
mailing list