[Libav-user] A question about sws_scale and pointer types

Alex Cohn alexcohn at netvision.net.il
Sun Oct 2 13:35:12 CEST 2011


On Wed, Sep 28, 2011 at 04:06, James Felix Black <jfb at homonculus.net> wrote:
> All,
>
> I have a chunk of code that creates an AVPicture from a raw stream of YUV420P, and rescales it.  Easy-peasy, but I'm getting the error:
>
> zc_libav.c:29: error: passing argument 2 of ‘sws_scale’ from incompatible pointer type
>
> (I run -pedantic-errors when building test builds.)

For ffmpeg sources, -pedantic-errors report numerous complaints for me
(regarding C++ style comments, etc). But the "incompatible pointer
type" is reported with default warnings, too (my ver is 4.5.3). This
is the explanation: expected `const uint8_t * const*' but argument is
of type `uint8_t **'.

> Looking at libswscale/swscale.h, I see that the function signature is:
>
> int sws_scale(struct SwsContext *c, const uint8_t* const srcSlice[],
>              const int srcStride[], int srcSliceY, int srcSliceH,
>              uint8_t* const dst[], const int dstStride[]);
>
> My code (assume that in_pic and out_pic are properly generated AVPictures):
>
>  sws_scale(sws_ctx,
>            in_pic->data,
>            in_pic->linesize,
>            0,
>            in->y,
>            out_pic->data,
>            out_pic->linesize);
>
> I'm happy to cast that 'in_pic->data' to get the compiler to shut up, but I don't know how.

The fix is to cast this way:
    (const uint8_t **)in_pic->data,

> If I turn off errors (-pedantic), it compiles and runs fine.  So this is really about my neurotic need not to see warnings, I guess.  But I'm still curious as to how someone with more C experience would handle this.

There is a breathtaking discussion of the subject here:
http://stackoverflow.com/questions/78125/why-cant-i-convert-char-to-a-const-char-const-in-c.
The bottom line is: it's just a problem in the C standard.

Sincerely,
Alex


> Am I doomed to special-casing this makefile rule to turn off -pedantic-errors?  That would make me sad, but then again, there is much that makes me sad.
>
> TIA,
> ~ jfb
>
> --
> James Felix Black <jfb at homonculus.net>
> "Some strangey that!"
> Words: http://homonculus.net
>
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
>
>


More information about the Libav-user mailing list