char pointer(2): passing a pointer as argument

The library provides APIs:

xxx_set_property_p(ctx, int property, void *value);

xxx_get_property_p(ctx, int property, void **value);

In the library,

struct buf {

    int index;

    int pointer;

}

struct context {

    void ** buf_pointers;   // point to the start of the pointers, which point to the application-allocated buffers

    struct buf * xxx_bufs;   // point to start of

    int planar_offsets[3];

    const char *norm;

}

int xxx_set_property_p(ctx, int property, void *value)

{

    ctx->buf_pointers = (void **) value;

    memcpy(ctx->planar_offsets, (int *)value, sizeof(int) * 3);

    ctx->norm = (char *) value;

}

ctx->xxx_bufs = (struct buf *)calloc(num_bufs, sizeof(struct buf));

ctx->xxx_bufs[i].pointer = ctx->buf_pointers[i];

int xxx_get_property_p(ctx, int property, void **value)

{

    *value = ctx->planar_offsets; // ?????

    *value = ctx->buf_pointers;

    *value = ctx->norm;

}

 

In the application,

void ** pointers = NULL;

int planar_offsets[3];

char norm[100] = “”;

pointers = calloc (nbufs, sizeof(void *));

capture_set_property_p(ctx, PROP_BUFS, pointers);

capture_set_property_p(ctx, PROP_PLANAR, offsets);

capture_set_property_p(ctx, PROP_NORM, norm);

 

capture_get_property_p(ctx, PROP_BUFS, (void **)&pointers);

capture_get_property_p(ctx, PROP_NORM, (void **)&norm);

 

 

 

 

 

 

 

 

 

 

 

 

 

}

There are two ways to pass the norm to the library:

Char norm[128] = “ntsc_j”;  // note: use a large size, not leave the size blank, as you might have overbound issue after a later modification of the array

or

Char *norm= “nstc_j”;

(the change of #1 content can be done by strcpy(norm, “pal_m”), the change of #2 content can be done by redirecting the pointer “norm = “pal_m”;

If the norm will be taken from the input, the #1 declaration & initialization has to be used).

 

Capture_set_property_p(_PROPERTY_NORM, norm);

 

 

Capture_set_property_p(property, void *value), sometimes, we keep a copy of the array, as it is mandatory to keep capture driver running; if it is optional, we reply on the pointers supplied by the user, without keep our own copy.

 

In this function, we cast void *value to (char *)value, and validate it.

 

Char *norm = NULL;

Capture_get_property_p(PROPERTY_NORM, (void **)&norm);

 

In the library,

Capture_get_property_p(property, void ** value)

{

*(char **)value = “ntsc_j”;  // return a const string

}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s