声明无效'AVPacket'

时间:2013-10-24 20:30:32

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

我正在使用android NDK和FFmpeg本机库开发一个解码器。我使用Android Tools为项目提供了原生支持,我在videodecoder.cpp文件中有C代码。在文件中,以下函数给我这个问题

JNIEXPORT jint Java_ssrp_android_ffmpegdecoder_H264Decoder_consumeNalUnitsFromDirectBuffer(
        JNIEnv* env, jobject thiz, jobject nal_units, jint num_bytes,
        jlong pkt_pts) {
    DecoderContext *ctx = get_ctx(env, thiz);

    void *buf = NULL;
    if (nal_units == NULL) {
        D("Received null buffer, sending empty packet to decoder");
    } else {
        buf = env->GetDirectBufferAddress(nal_units);
        if (buf == NULL) {
            D("Error getting direct buffer address");
            return -1;
        }
    }

    AVPacket packet = {.data = (uint8_t*) buf, .size = num_bytes, .pts = pkt_pts };

    int frameFinished = 0;
    int res = avcodec_decode_video2(ctx->codec_ctx, ctx->src_frame,&frameFinished, &packet);

    if (frameFinished)
        ctx->frame_ready = 1;

    return res;
}

AVPacket packet = {.data = (uint8_t*) buf, .size = num_bytes, .pts = pkt_pts };

它说'声明无效“AVPAcket”和

int res = avcodec_decode_video2(ctx->codec_ctx, ctx->src_frame,&frameFinished, &packet);

它说Invalid arguments ' Candidates are: int avcodec_decode_video2(AVCodecContext *, AVFrame *, int *, const AVPacket *)'

1 个答案:

答案 0 :(得分:3)

问题是

AVPacket packet = {.data = (uint8_t*) buf, .size = num_bytes, .pts = pkt_pts }

因为编译器不理解类型/初始化。 这会导致无效的参数错误。 也许把这一行分成:

AVPacket packet;
packet.data = (uint8_t*) buf;
packet.size = num_bytes;
packet.pts = pkt_pts;

这应该会得到更明确的错误输出。