为什么编译器不能从 sp<android::MetaData> 隐式转换为 bool?
Why can't the compiler convert to bool implicitly from sp<android::MetaData>?
我正在尝试使用 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-bit)
和 Ubuntu 14 64 bit
有人可以指导为什么会出现此错误,我做错了什么吗?
为了让编译器为
编写代码
if (!meta)
android::sp
class 必须定义 operator!()
,或者必须有一种方法可以将此 class 转换为 bool,即 operator bool()
.由于您无法更改 android::sp
实现,因此您需要找到另一种方式来编写它。我认为这应该有效:
if (meta != NULL)
我正在尝试使用 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-bit)
和 Ubuntu 14 64 bit
有人可以指导为什么会出现此错误,我做错了什么吗?
为了让编译器为
编写代码if (!meta)
android::sp
class 必须定义 operator!()
,或者必须有一种方法可以将此 class 转换为 bool,即 operator bool()
.由于您无法更改 android::sp
实现,因此您需要找到另一种方式来编写它。我认为这应该有效:
if (meta != NULL)