c - librtmp 免费 () : invalid pointer

标签 c linux rtmp

我正在尝试使用 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 免费 () : invalid pointer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30068377/

相关文章:

c - 在调用 pthread_join 之前到达 pthread_exit()

c - 如何strtok保存在数组中的字符串并将其保存到c中的三个不同的数组中?

linux - 磁盘上的嵌入式 linux 根文件系统

php - C++ popen 运行 PHP

c++ - 为什么 Go 套接字比 C++ 套接字慢?

nginx - 流式网络摄像头实时缓冲区 [东芝网络摄像头] [视频输入] 太满或接近太满

nginx - nginx添加新模块时,配置组装出错

c - 在 C 中的结构中使用 "static"

c - 段错误数组在 ubuntu 中 float 但在 osx 中不 float

youtube - RTMP链接youtube