其他分享
首页 > 其他分享> > 配置RtmpSever

配置RtmpSever

作者:互联网

前面已经构建好了RtmpPacket然后使用librtmp进行包的上传代码如下

给定链接创建rtmp结构体

- (BOOL)config_ctx_with_filepath:(NSString *)filepath{
    BOOL is_success = NO;
    char *file_name = (char*) [filepath cStringUsingEncoding:NSUTF8StringEncoding];
    sever_rtmp = connect_rtmp_sever(file_name);
    if (sever_rtmp) {
        is_success = YES;
    }
    is_set = is_success;
    return is_success;
}

构建函数

static RTMP * connect_rtmp_sever(char *rtmpaddress){
    char *url = (char *)malloc(strlen(rtmpaddress)+1);
    memcpy(url, rtmpaddress, strlen(rtmpaddress)+1);
    RTMP *rtmp = NULL;
    rtmp = RTMP_Alloc();
    RTMP_Init(rtmp);
    rtmp->Link.timeout = 20;
    RTMP_SetupURL(rtmp, url);
    RTMP_EnableWrite(rtmp);
    RTMP_Connect(rtmp, 0);
    RTMP_SetBufferMS(rtmp, 3 * 1000);
    RTMP_ConnectStream(rtmp, 0);
    return rtmp;
}

rtmp包的发送函数

- (BOOL)send_packet_rtmp:(XCQueueObj *)srcobj{
    BOOL is_success = NO;
    if (!RTMP_IsConnected(sever_rtmp)) {
        return is_success;
    }
    srcobj->rtmp_packet->m_nInfoField2 = sever_rtmp->m_stream_id;
    int ret = RTMP_SendPacket(sever_rtmp, srcobj->rtmp_packet, 1);
    if (!ret) {
        NSLog(@"发送数据失败");
    }
    RTMPPacket_Free(srcobj->rtmp_packet);
    srcobj->rtmp_packet = 0;
    return ret;
}

单独推送音频或者视频都是没有问题的比较困扰我的是两个一起推送就会出现关于延迟编码的崩溃问题这个问题一直没有解决

我也一直在寻找相关的方案

 

标签:success,配置,packet,char,RtmpSever,rtmp,sever,RTMP
来源: https://blog.csdn.net/qq_24656927/article/details/110903142