PSDK如何进行rtmp推流
已完成if (!rtmp_init) {
rtmp = RTMP_Alloc();
RTMP_Init(rtmp);
//rtmp://XXX 这个是我故意写错的
if (!RTMP_SetupURL(rtmp, "rtmp://XXX")) {
printf("Failed to set up RTMP connection\n");
}
// 设置连接超时时间
rtmp->Link.timeout = 5; // 设置为 5 秒
RTMP_EnableWrite(rtmp);
if (!RTMP_Connect(rtmp, NULL) || !RTMP_ConnectStream(rtmp, 0)) {
printf("Failed to connect to RTMP server\n");
}
rtmp_init = true;
printf("RTMP connection initialized\n");
}
timestamp = get_current_timestamp_in_milliseconds();
is_h264 = is_h264_iframe(buf, len);
//rtmp_buf = (char *) buf;
rtmp_buf = (char *)malloc(len * sizeof(char));
memcpy(rtmp_buf, buf, len);
if (RTMP_IsConnected(rtmp))
{
printf("RTMP connect\n");
if(run_cnt<=240 || true)
{
if(run_cnt >= 250)
{
printf("add break\n");
}
ret = RTMP_Write(rtmp, rtmp_buf, len);
free(rtmp_buf);
//printf("RTMP_write_bytes: %d\n", ret);
/*
int bytesSent = 0;
int bytesRemaining = len;
while (bytesRemaining > 0) {
int chunkSize = (bytesRemaining > MAX_CHUNK_SIZE) ? MAX_CHUNK_SIZE : bytesRemaining;
if (RTMP_IsConnected(rtmp)) {
printf("RTMP connect 2\n");
ret = RTMP_Write(rtmp, rtmp_buf + bytesSent, chunkSize);
printf("RTMP_write_bytes: %d\n", ret);
}
else{
printf("break\n");
}
bytesSent += ret;
bytesRemaining -= ret;
// 添加1毫秒延迟
usleep(10000);
}
*/
}
else{
printf("stop write\n");
}
}
else
{
printf("RTMP disconnect\n");
}
run_cnt++;
printf("cnt: %d\n", run_cnt);
各位大佬,谁用PSDK 实现过RTMP推流,我的用librtmp库。
在回调函数
DjiTest_FpvCameraStreamCallback()下进行修改的,我的运行252次就会报错退出,通过gdb打印没发现空指针,出错的函数为RTMP_Write()。
请先登录再写评论。
评论
0 条评论