DJI_lover
DJI_lover

Reputation: 61

RTMP_Init “Segmentation fault”

I am using librtmp to stream video.I install librtmp in ubuntu 16.04 with "sudo apt-get librtmp-dev".I successfully compiled the code,but I got a "Segmentation fault" in RTMP_Init().Here is my rtmp_test code:

main function:

int main(int argc,char *argv[]){
    printf("11111\n");
    if (RTMP264_Connect("rtmp://**********") == TRUE){
        printf("connect successful");
    }
    printf("22222222\n");
    return 0;
}

RTMP264_Connect function:

int RTMP264_Connect(const char * url){
    printf("~~~~~~~1\n");
    RTMP_Init(m_Rtmp);
    printf("~~~~~~~2\n");
    if(RTMP_SetupURL(m_Rtmp,(char*)url) == FALSE){
        RTMP_Free(m_Rtmp);
        return FALSE;
    }
    printf("~~~~~~~3\n");
    RTMP_EnableWrite(m_Rtmp);
    if(RTMP_Connect(m_Rtmp,NULL)==FALSE){
        RTMP_Free(m_Rtmp);
        return FALSE;
    }

When I run the code,I got this error:

11111
aaaa
~~~~~~~1
Segmentation fault

So I'm sure the problem is in RTMP_init function.I saw someone on the Internet saying that the reason may be that socket is not initialized. I found a socket initialization code:

int InitSockets()
{
#ifdef WIN32

    WORD version;
    WSADATA wsaData;
    version = MAKEWORD(1, 1);
    return (WSAStartup(version, &wsaData) == 0);
#endif
}

void CleanupSockets()
{
#ifdef WIN32
    WSACleanup();
#endif
}

But this is for Windows system. If I run on Ubuntu, I will report an error. And I don't know if my problem has something to do with socket not being initialized.Could someone tell me how to fix my problem,thanks!

Upvotes: 0

Views: 149

Answers (1)

Alan Birtles
Alan Birtles

Reputation: 36488

According to the documentation:

The basic interaction is as follows. A session handle is created using RTMP_Alloc() and initialized using RTMP_Init().

As you haven't called RTMP_Alloc this is presumably the cause of the segfault

Upvotes: 1

Related Questions