gpt4 book ai didi

android - 为什么编译器不能从 sp 隐式转换为 bool?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:49:24 25 4
gpt4 key购买 nike

我正在尝试使用 NDK 将 ffmpeg 与 libstagefright 一起编译。我在编译 libstagefright.cpp 时遇到以下错误:

libavcodec/libstagefright.cpp: In function 'int Stagefright_init(AVCodecContext*)':
libavcodec/libstagefright.cpp:283:9: error: no match for 'operator!' (operand type is 'android::sp<android::MetaData>')
if (!meta) {
^
libavcodec/libstagefright.cpp:283:9: note: candidate is:
libavcodec/libstagefright.cpp:283:9: note: operator!(bool) <built-in>
libavcodec/libstagefright.cpp:283:9: note: no known conversion for argument 1 from 'android::sp<android::MetaData>' to 'bool'
make: *** [libavcodec/libstagefright.o] Error 1

libstagefright.cpp 相关部分的代码是:

meta = new MetaData;
if (!meta) {
ret = AVERROR(ENOMEM);
goto fail;
}
meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC);
meta->setInt32(kKeyWidth, avctx->width);
meta->setInt32(kKeyHeight, avctx->height);
meta->setData(kKeyAVCC, kTypeAVCC, avctx->extradata, avctx->extradata_size);

我正在使用 NDK r10e-rc4(64 位)Ubuntu 14 64 位

有人可以指导为什么会出现此错误,我做错了什么吗?

最佳答案

为了让编译器编写代码

if (!meta)

android::sp 类必须定义 operator!(),或者必须有一种方法可以将此类转换为 bool,即 运算符 bool ()。由于您无法更改 android::sp 实现,因此您需要找到另一种方式来编写它。我认为这应该有效:

if (meta != NULL)

关于android - 为什么编译器不能从 sp<android::MetaData> 隐式转换为 bool?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31870887/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com