我试图用librtmp处理数据包,但得到一个“free():invalid pointer”错误。

#include <stdio.h>
#include <stdlib.h>
#include <librtmp/rtmp.h>
#include <librtmp/log.h>

int main(){
    RTMP *r;
    RTMPPacket packet;

    char uri[] = "rtmp://167.114.171.21:1936/tinyconf app=tinyconf timeout=180000 live=1 conn=S:ROOMNAME swfurl=http://tinychat.com/embed/Tinychat-11.1-1.0.0.0602.swf";

    RTMP_LogLevel loglvl=RTMP_LOGDEBUG2;
    RTMP_LogSetLevel(loglvl);

    r = RTMP_Alloc();
    RTMP_Init(r);
    RTMP_SetupURL(r, (char*)uri);
    RTMP_Connect(r, NULL);

    while (RTMP_IsConnected(r)) {
        RTMP_ReadPacket(r, &packet);
        if (!RTMPPacket_IsReady(&packet))
            continue;
        RTMP_ClientPacket(r, &packet);
        RTMPPacket_Free(&packet);
    }

    RTMP_Close(r);
    RTMP_Free(r);

    return 1;
}

Here's a link to the log/backtrace。(因为它很长)
我不确定为什么会发生这种情况,这是我的代码或librtmp本身的问题吗?

最佳答案

使用RTMPPacket_Alloc(packet, size);是可行的,尽管我看到其他代码没有使用它(我想)。无论如何,这里有一个有效的例子。

#include <stdio.h>
#include <stdlib.h>
#include <librtmp/rtmp.h>
#include <librtmp/log.h>

int main(){
    RTMP *r;
    RTMPPacket packet;
    RTMPPacket_Alloc(&packet, 4096);

    char uri[] = "rtmp://167.114.171.21:1936/tinyconf app=tinyconf timeout=180000 live=1 conn=S:ROOMNAME swfurl=http://tinychat.com/embed/Tinychat-11.1-1.0.0.0602.swf";

    RTMP_LogLevel loglvl=RTMP_LOGDEBUG2;
    RTMP_LogSetLevel(loglvl);

    r = RTMP_Alloc();
    RTMP_Init(r);
    RTMP_SetupURL(r, (char*)uri);
    RTMP_Connect(r, NULL);

    while (RTMP_IsConnected(r)) {
        RTMP_ReadPacket(r, &packet);
        if (!RTMPPacket_IsReady(&packet))
            continue;
        RTMP_ClientPacket(r, &packet);
        RTMPPacket_Free(&packet);
    }

    RTMP_Close(r);
    RTMP_Free(r);

    return 1;
}

关于c - librtmp free():无效的指针,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30068377/

10-11 15:12