Unable to use util/libav.h from C++
It appears that libav.h (and libav_internal.h) are not compatible with C++, causing a lot of compile errors:
extern "C"
{
#include <libplacebo/utils/libav.h>
}
int main()
{
return 0;
}
$ g++ test.cpp -lplacebo
In file included from test.cpp:3:
/usr/include/libplacebo/utils/libav.h: In function ‘bool pl_map_avframe(pl_gpu, pl_frame*, const pl_tex_t**, const AVFrame*)’:
/usr/include/libplacebo/utils/libav.h:132:74: error: taking address of rvalue [-fpermissive]
132 | return pl_map_avframe_ex(gpu, out_frame, &(struct pl_avframe_params) {
| ^
133 | .frame = avframe,
| ~~~~~~~~~~~~~~~~~~
134 | .tex = tex,
| ~~~~~~~~~~~~~~
135 | });
| ~
In file included from /usr/include/libplacebo/utils/libav.h:234:
/usr/include/libplacebo/utils/libav_internal.h: In function ‘void pl_color_space_from_avframe(pl_color_space*, const AVFrame*)’:
/usr/include/libplacebo/utils/libav_internal.h:277:34: error: expected primary-expression before ‘struct’
277 | out_csp->hdr.prim = (struct pl_raw_primaries) {
| ^~~~~~
/usr/include/libplacebo/utils/libav_internal.h:277:34: error: expected ‘)’ before ‘struct’
277 | out_csp->hdr.prim = (struct pl_raw_primaries) {
| ~^~~~~~
| )
/usr/include/libplacebo/utils/libav_internal.h: In function ‘void pl_avframe_set_color(AVFrame*, pl_color_space)’:
/usr/include/libplacebo/utils/libav_internal.h:581:13: error: designator order for field ‘AVMasteringDisplayMetadata::min_luminance’ does not match declaration order in ‘AVMasteringDisplayMetadata’
581 | };
| ^
/usr/include/libplacebo/utils/libav_internal.h: In function ‘void pl_frame_from_avframe(pl_frame*, const AVFrame*)’:
/usr/include/libplacebo/utils/libav_internal.h:609:65: error: invalid conversion from ‘int’ to ‘AVPixelFormat’ [-fpermissive]
609 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
| ~~~~~~~^~~~~~
| |
| int
In file included from /usr/include/libavutil/imgutils.h:31,
from /usr/include/libplacebo/utils/libav_internal.h:26:
/usr/include/libavutil/pixdesc.h:213:66: note: initializing argument 1 of ‘const AVPixFmtDescriptor* av_pix_fmt_desc_get(AVPixelFormat)’
213 | const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt);
| ~~~~~~~~~~~~~~~~~~~^~~~~~~
/usr/include/libplacebo/utils/libav_internal.h:610:49: error: invalid conversion from ‘int’ to ‘AVPixelFormat’ [-fpermissive]
610 | int planes = av_pix_fmt_count_planes(frame->format);
| ~~~~~~~^~~~~~
| |
| int
/usr/include/libavutil/pixdesc.h:247:48: note: initializing argument 1 of ‘int av_pix_fmt_count_planes(AVPixelFormat)’
247 | int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt);
| ~~~~~~~~~~~~~~~~~~~^~~~~~~
/usr/include/libplacebo/utils/libav_internal.h:624:13: error: expected primary-expression before ‘struct’
624 | *out = (struct pl_frame) {
| ^~~~~~
/usr/include/libplacebo/utils/libav_internal.h:624:13: error: expected ‘)’ before ‘struct’
624 | *out = (struct pl_frame) {
| ~^~~~~~
| )
/usr/include/libplacebo/utils/libav_internal.h: In function ‘void pl_frame_copy_stream_props(pl_frame*, const AVStream*)’:
/usr/include/libplacebo/utils/libav_internal.h:736:36: error: expected primary-expression before ‘struct’
736 | out->color.hdr.prim = (struct pl_raw_primaries) {
| ^~~~~~
/usr/include/libplacebo/utils/libav_internal.h:736:36: error: expected ‘)’ before ‘struct’
736 | out->color.hdr.prim = (struct pl_raw_primaries) {
| ~^~~~~~
| )
/usr/include/libplacebo/utils/libav_internal.h: In function ‘bool pl_frame_recreate_from_avframe(pl_gpu, pl_frame*, const pl_tex_t**, const AVFrame*)’:
/usr/include/libplacebo/utils/libav_internal.h:815:65: error: invalid conversion from ‘int’ to ‘AVPixelFormat’ [-fpermissive]
815 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
| ~~~~~~~^~~~~~
| |
| int
/usr/include/libavutil/pixdesc.h:213:66: note: initializing argument 1 of ‘const AVPixFmtDescriptor* av_pix_fmt_desc_get(AVPixelFormat)’
213 | const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt);
| ~~~~~~~~~~~~~~~~~~~^~~~~~~
/usr/include/libplacebo/utils/libav_internal.h:816:37: error: invalid conversion from ‘int’ to ‘pl_fmt_type’ [-fpermissive]
816 | struct pl_plane_data data[4] = {0};
| ^
| |
| int
/usr/include/libplacebo/utils/libav_internal.h:820:70: error: invalid conversion from ‘int’ to ‘AVPixelFormat’ [-fpermissive]
820 | planes = pl_plane_data_from_pixfmt(data, &out->repr.bits, frame->format);
| ~~~~~~~^~~~~~
| |
| int
/usr/include/libplacebo/utils/libav_internal.h:384:64: note: initializing argument 3 of ‘int pl_plane_data_from_pixfmt(pl_plane_data*, pl_bit_encoding*, AVPixelFormat)’
384 | enum AVPixelFormat pix_fmt)
| ~~~~~~~~~~~~~~~~~~~^~~~~~~
/usr/include/libplacebo/utils/libav_internal.h: In function ‘void pl_avframe_free_cb(void*)’:
/usr/include/libplacebo/utils/libav_internal.h:838:22: error: invalid conversion from ‘void*’ to ‘AVFrame*’ [-fpermissive]
838 | AVFrame *frame = priv;
| ^~~~
| |
| void*
In file included from /usr/include/libplacebo/utils/libav.h:21:
/usr/include/libplacebo/utils/libav_internal.h: In function ‘bool pl_map_avframe_drm(pl_gpu, pl_frame*, const AVFrame*)’:
/usr/include/libplacebo/utils/libav_internal.h:887:53: error: expected primary-expression before ‘struct’
887 | out->planes[n].texture = pl_tex_create(gpu, pl_tex_params(
| ^~~~~~~~~~~~~
/usr/include/libplacebo/utils/libav_internal.h:887:53: error: expected ‘)’ before ‘struct’
887 | out->planes[n].texture = pl_tex_create(gpu, pl_tex_params(
| ^~~~~~~~~~~~~
/usr/include/libplacebo/utils/libav_internal.h: In function ‘bool pl_map_avframe_internal(pl_gpu, pl_frame*, const pl_avframe_params*, bool)’:
/usr/include/libplacebo/utils/libav_internal.h:1015:65: error: invalid conversion from ‘int’ to ‘AVPixelFormat’ [-fpermissive]
1015 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
| ~~~~~~~^~~~~~
| |
| int
/usr/include/libavutil/pixdesc.h:213:66: note: initializing argument 1 of ‘const AVPixFmtDescriptor* av_pix_fmt_desc_get(AVPixelFormat)’
213 | const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt);
| ~~~~~~~~~~~~~~~~~~~^~~~~~~
/usr/include/libplacebo/utils/libav_internal.h:1016:37: error: invalid conversion from ‘int’ to ‘pl_fmt_type’ [-fpermissive]
1016 | struct pl_plane_data data[4] = {0};
| ^
| |
| int
/usr/include/libplacebo/utils/libav_internal.h:1077:70: error: invalid conversion from ‘int’ to ‘AVPixelFormat’ [-fpermissive]
1077 | planes = pl_plane_data_from_pixfmt(data, &out->repr.bits, frame->format);
| ~~~~~~~^~~~~~
| |
| int
/usr/include/libplacebo/utils/libav_internal.h:384:64: note: initializing argument 3 of ‘int pl_plane_data_from_pixfmt(pl_plane_data*, pl_bit_encoding*, AVPixelFormat)’
384 | enum AVPixelFormat pix_fmt)
| ~~~~~~~~~~~~~~~~~~~^~~~~~~
/usr/include/libplacebo/utils/libav_internal.h:1095:31: error: invalid conversion from ‘void*’ to ‘pl_avalloc*’ [-fpermissive]
1095 | alloc = frame->buf[p] ? av_buffer_get_opaque(frame->buf[p]) : NULL;
| ^
| |
| void*
/usr/include/libplacebo/utils/libav_internal.h: In function ‘void pl_unmap_avframe(pl_gpu, pl_frame*)’:
/usr/include/libplacebo/utils/libav_internal.h:1129:31: error: invalid conversion from ‘void*’ to ‘AVFrame*’ [-fpermissive]
1129 | AVFrame *avframe = frame->user_data;
| ~~~~~~~^~~~~~~~~
| |
| void*
/usr/include/libplacebo/utils/libav_internal.h:1139:41: error: invalid conversion from ‘int’ to ‘AVPixelFormat’ [-fpermissive]
1139 | desc = av_pix_fmt_desc_get(avframe->format);
| ~~~~~~~~~^~~~~~
| |
| int
/usr/include/libavutil/pixdesc.h:213:66: note: initializing argument 1 of ‘const AVPixFmtDescriptor* av_pix_fmt_desc_get(AVPixelFormat)’
213 | const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt);
| ~~~~~~~~~~~~~~~~~~~^~~~~~~
/usr/include/libplacebo/utils/libav_internal.h: In function ‘bool pl_upload_avframe(pl_gpu, pl_frame*, const pl_tex_t**, const AVFrame*)’:
/usr/include/libplacebo/utils/libav_internal.h:1154:65: error: invalid conversion from ‘int’ to ‘AVPixelFormat’ [-fpermissive]
1154 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
| ~~~~~~~^~~~~~
| |
| int
/usr/include/libavutil/pixdesc.h:213:66: note: initializing argument 1 of ‘const AVPixFmtDescriptor* av_pix_fmt_desc_get(AVPixelFormat)’
213 | const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt);
| ~~~~~~~~~~~~~~~~~~~^~~~~~~
/usr/include/libplacebo/utils/libav_internal.h: In function ‘void pl_done_cb(void*)’:
/usr/include/libplacebo/utils/libav_internal.h:1171:20: error: invalid conversion from ‘void*’ to ‘bool*’ [-fpermissive]
1171 | bool *status = priv;
| ^~~~
| |
| void*
/usr/include/libplacebo/utils/libav_internal.h: In function ‘bool pl_download_avframe(pl_gpu, const pl_frame*, AVFrame*)’:
/usr/include/libplacebo/utils/libav_internal.h:1180:65: error: invalid conversion from ‘int’ to ‘AVPixelFormat’ [-fpermissive]
1180 | if (frame->num_planes != av_pix_fmt_count_planes(out_frame->format))
| ~~~~~~~~~~~^~~~~~
| |
| int
/usr/include/libavutil/pixdesc.h:247:48: note: initializing argument 1 of ‘int av_pix_fmt_count_planes(AVPixelFormat)’
247 | int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt);
| ~~~~~~~~~~~~~~~~~~~^~~~~~~
/usr/include/libplacebo/utils/libav_internal.h:1184:40: error: designator order for field ‘pl_tex_transfer_params::callback’ does not match declaration order in ‘pl_tex_transfer_params’
1184 | bool ok = pl_tex_download(gpu, pl_tex_transfer_params(
| ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/libplacebo/utils/libav_internal.h:1184:40: error: taking address of rvalue [-fpermissive]
1184 | bool ok = pl_tex_download(gpu, pl_tex_transfer_params(
| ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/libplacebo/utils/libav_internal.h: In function ‘void pl_avalloc_free(void*, uint8_t*)’:
/usr/include/libplacebo/utils/libav_internal.h:1210:32: error: invalid conversion from ‘void*’ to ‘pl_avalloc*’ [-fpermissive]
1210 | struct pl_avalloc *alloc = opaque;
| ^~~~~~
| |
| void*
/usr/include/libplacebo/utils/libav_internal.h: In function ‘int pl_get_buffer2(AVCodecContext*, AVFrame*, int)’:
/usr/include/libplacebo/utils/libav_internal.h:1226:27: error: invalid conversion from ‘void*’ to ‘const pl_gpu_t**’ [-fpermissive]
1226 | pl_gpu *pgpu = avctx->opaque;
| ~~~~~~~^~~~~~
| |
| void*
/usr/include/libplacebo/utils/libav_internal.h:1230:61: error: invalid conversion from ‘int’ to ‘AVPixelFormat’ [-fpermissive]
1230 | int planes = pl_plane_data_from_pixfmt(data, NULL, pic->format);
| ~~~~~^~~~~~
| |
| int
/usr/include/libplacebo/utils/libav_internal.h:384:64: note: initializing argument 3 of ‘int pl_plane_data_from_pixfmt(pl_plane_data*, pl_bit_encoding*, AVPixelFormat)’
384 | enum AVPixelFormat pix_fmt)
| ~~~~~~~~~~~~~~~~~~~^~~~~~~
/usr/include/libplacebo/utils/libav_internal.h:1245:60: error: invalid conversion from ‘int’ to ‘AVPixelFormat’ [-fpermissive]
1245 | if ((ret = av_image_fill_linesizes(pic->linesize, pic->format, width)))
| ~~~~~^~~~~~
| |
| int
/usr/include/libavutil/imgutils.h:68:66: note: initializing argument 2 of ‘int av_image_fill_linesizes(int*, AVPixelFormat, int)’
68 | int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width);
| ~~~~~~~~~~~~~~~~~~~^~~~~~~
/usr/include/libplacebo/utils/libav_internal.h:1255:53: error: invalid conversion from ‘int’ to ‘AVPixelFormat’ [-fpermissive]
1255 | ret = av_image_fill_plane_sizes(planesize, pic->format, height, (ptrdiff_t[4]) {
| ~~~~~^~~~~~
| |
| int
/usr/include/libavutil/imgutils.h:81:66: note: initializing argument 2 of ‘int av_image_fill_plane_sizes(size_t*, AVPixelFormat, int, const ptrdiff_t*)’
81 | int av_image_fill_plane_sizes(size_t size[4], enum AVPixelFormat pix_fmt,
| ~~~~~~~~~~~~~~~~~~~^~~~~~~
/usr/include/libplacebo/utils/libav_internal.h:1255:84: error: taking address of temporary array
1255 | ret = av_image_fill_plane_sizes(planesize, pic->format, height, (ptrdiff_t[4]) {
| ^
1256 | pic->linesize[0], pic->linesize[1], pic->linesize[2], pic->linesize[3],
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1257 | });
| ~
/usr/include/libplacebo/utils/libav_internal.h:1276:23: error: invalid conversion from ‘void*’ to ‘pl_avalloc*’ [-fpermissive]
1276 | alloc = malloc(sizeof(*alloc));
| ~~~~~~^~~~~~~~~~~~~~~~
| |
| void*
/usr/include/libplacebo/utils/libav_internal.h:1285:39: error: designator order for field ‘pl_buf_params::size’ does not match declaration order in ‘pl_buf_params’
1285 | .buf = pl_buf_create(gpu, pl_buf_params(
| ^~~~~~~~~~~~~
/usr/include/libplacebo/utils/libav_internal.h:1285:39: error: taking address of rvalue [-fpermissive]
1285 | .buf = pl_buf_create(gpu, pl_buf_params(
| ^~~~~~~~~~~~~