不兼容的指针类型错误、sws_scale、ffmpeg
我的代码非常简单;它使用 YUV420P 数据,调整其大小,并生成 PNG 或 JPEG 图像(OS X Lion、Apple 的 gcc 4.2.1)。效果很好;我正在使用 ffmpeg (HEAD,从几天前开始),但是当在 -pedantic-errors 模式下运行时(我喜欢时不时地这样做):
zc_libav.c:30: error: passing argument 2 of ‘sws_scale’ from incompatible pointer type
哎呀!好吧,我的代码是什么样的?
sws_scale(sws_ctx,
in_pic->data,
in_pic->linesize,
0,
in->y,
out_pic->data,
out_pic->linesize);
(为了论证,您可以假设 in_pic 和 out_pic AVPicture 结构已正确初始化,正如代码工作一样)。
那么,有问题的数据类型是什么?
来自 libswscale/swscale.h:
int sws_scale(struct SwsContext *c, const uint8_t* const srcSlice[], …
来自 libavcodec/avcodec.h
typedef struct AVPicture {
uint8_t *data[4];
int linesize[4]; ///< number of bytes per line
} AVPicture;
正如我上面提到的,当我将 -pedantic-errors 更改为 -pedantic 时,我得到了同样的抱怨,但代码编译并正确运行。为了我自己神经质的理智,有什么方法可以利用 -pedantic-errors 的优势,并且编译这段代码吗?
My code is very straightforward; it consumes YUV420P data, resizes it, and produces a PNG or JPEG image (OS X Lion, Apple's gcc 4.2.1). It works fine; I'm using ffmpeg (HEAD, as of mumble days ago), but when running in -pedantic-errors mode (which I like to do from time to time):
zc_libav.c:30: error: passing argument 2 of ‘sws_scale’ from incompatible pointer type
Ouch! Well, what's my code look like?
sws_scale(sws_ctx,
in_pic->data,
in_pic->linesize,
0,
in->y,
out_pic->data,
out_pic->linesize);
(You can assume for the sake of argument that the in_pic and out_pic AVPicture structures have been properly initialized, as the code works).
Well, what're the offending data types?
from libswscale/swscale.h:
int sws_scale(struct SwsContext *c, const uint8_t* const srcSlice[], …
from libavcodec/avcodec.h
typedef struct AVPicture {
uint8_t *data[4];
int linesize[4]; ///< number of bytes per line
} AVPicture;
As I noted above, when I change -pedantic-errors to -pedantic, I get the same complaint, but the code compiles and runs correctly. For my own neurotic sanity, is there any way to get the advantages of -pedantic-errors and, you know, compile this code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这在 C++ 中没问题,但 C 对于 const 没有相同的规则。它不喜欢将非常量 uint8_t ** 传递给采用 const uint8_t *const * 的函数。
在 C 中,您可以将 X * 转换为 const X *,但它仅适用于一级指针。下一个指针级别必须完全匹配。
This would be ok in C++, but C doesn't have the same rules regarding const. It doesn't like that you are passing a non-const uint8_t ** to a function that takes a const uint8_t *const *.
In C, you can convert an X * to a const X *, but it only works for one pointer level. The next pointer level has to match exactly.