【问题标题】:Why can't the compiler convert to bool implicitly from sp<android::MetaData>?为什么编译器不能从 sp<android::MetaData> 隐式转换为 bool?
【发布时间】:2015-08-07 06:15:06
【问题描述】:

我正在尝试使用 NDK 编译带有 libstagefright 的 ffmpeg。我在编译 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

谁能指导一下为什么会发生这个错误,我做错了什么?

【问题讨论】:

    标签: android c++ ffmpeg android-ndk stagefright


    【解决方案1】:

    为了让编译器写代码

    if (!meta)
    

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

    if (meta != NULL)
    

    【讨论】:

    • 但是 libstagefright.cpp 是由专业开发人员编写的。当然,除了对其进行更改之外,还必须有另一种编译方式。它应该按原样工作。不应该吗?
    • 可能是用不同版本的android ndk写的?虽然我认为 android ndk 不会出于意识形态原因引入非向后兼容的更改......
    • 将其更改为if (meta != NULL) 后,该错误消失了,但出现了许多其他“未定义的对...的引用”错误。我认为存在某种链接问题。也许 lib 文件没有正确链接。无论如何,谢谢您的回复。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-17
    • 1970-01-01
    • 1970-01-01
    • 2016-10-23
    • 2021-06-01
    • 1970-01-01
    相关资源
    最近更新 更多