修改Janus,支持datachannel通过rtp通道传输

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/twoconk/article/details/82390399

Janus的datachannel支持的协议主要是:“DTLS/SCTP”、"UDP/DTLS/SCTP",而RTP通道使用的是"UDP/TLS/RTP/SAVPF",修改的思路包括SDP返回的修改,RTP数据包中提取datachannel包对应SSRC的包。

1、给janus_ice_stream结构体添加data的ssrc字段和初始化:

    guint32 data_ssrc_peer;//lyz@xdja.com
    guint32 data_ssrc, sequence_data;

    int janus_sdp_process(void *ice_handle, janus_sdp *remote_sdp, gboolean update) 方法中增加如下逻辑:
                    if(!strcasecmp(m->proto, "UDP/DTLS/SCTP")  || !strcasecmp(m->proto, "UDP/TLS/RTP/SAVPF")) {
                        stream->data_ssrc = janus_random_uint32();    /* FIXME Should we look for conflicts? */
                        stream->sequence_data = janus_random_uint32();    
                        janus_flags_set(&handle->webrtc_flags, JANUS_ICE_HANDLE_WEBRTC_NEW_DATACHAN_SDP);
                        janus_flags_clear(&handle->webrtc_flags, JANUS_ICE_HANDLE_WEBRTC_DATA_CHANNELS);//lyz@xdja.com add
                    } else {
                        janus_flags_clear(&handle->webrtc_flags, JANUS_ICE_HANDLE_WEBRTC_NEW_DATACHAN_SDP);
                    }

2、SDP返回数据:

m->fmts = g_list_append(m->fmts, g_strdup("109"));
            janus_sdp_attribute *aa = janus_sdp_attribute_create("rtpmap", "109 google-data/90000");
            m->attributes = g_list_append(m->attributes, aa);        
            m->ptypes = g_list_append(m->ptypes, GINT_TO_POINTER(109));  

          

3、接收RTP数据函数janus_ice_cb_nice_recv中,增加对datachannel的数据处理的逻辑:

if (header->type == 109 || stream->data_ssrc_peer == packet_ssrc){ 
                        /* Pass the data to the responsible plugin */ 
                        janus_plugin *plugin = (janus_plugin *)handle->app;
                        
                        if(plugin && plugin->incoming_data &&
                                !g_atomic_int_get(&handle->app_handle->stopped) &&
                                !g_atomic_int_get(&handle->destroyed)){
                                
                            plugin->incoming_data(handle->app_handle, (char *)buf + RTP_HEADER_SIZE, buflen - RTP_HEADER_SIZE);
                        }
                        return;
                    }

4、发送RTP数据时,使用RTP通道发送datachannel的数据:

void janus_plugin_relay_data(janus_plugin_session *plugin_session, char *buf, int len) {
    if((plugin_session < (janus_plugin_session *)0x1000) || g_atomic_int_get(&plugin_session->stopped) || buf == NULL || len < 1)
        return;
    janus_ice_handle *handle = (janus_ice_handle *)plugin_session->gateway_handle;
    if(!handle || janus_flags_is_set(&handle->webrtc_flags, JANUS_ICE_HANDLE_WEBRTC_STOP)
            || janus_flags_is_set(&handle->webrtc_flags, JANUS_ICE_HANDLE_WEBRTC_ALERT)){
        return;
    }
#ifdef HAVE_SCTP
    if (janus_flags_is_set(&handle->webrtc_flags, JANUS_ICE_HANDLE_WEBRTC_NEW_DATACHAN_SDP)){
        janus_ice_relay_data_withrtp(handle, buf, len);//relay daa with rtp only.
    }else{
        janus_ice_relay_data(handle, buf, len);
    }
#else
    JANUS_LOG(LOG_WARN, "Asked to relay data, but Data Channels support has not been compiled...\n");
#endif
}


void janus_ice_relay_data_withrtp(janus_ice_handle *handle, char *buf, int len) {
    struct timeval now;
    if(!handle || handle->queued_packets == NULL || buf == NULL || len < 1){
        return;
    }
    /* Queue this packet */
    janus_ice_queued_packet *pkt = g_malloc(sizeof(janus_ice_queued_packet));
    pkt->data = g_malloc(RTP_HEADER_SIZE+len+SRTP_MAX_TAG_LEN+4);
    janus_rtp_header *header = (janus_rtp_header *)pkt->data;
    header->ssrc = (handle->stream->data_ssrc);
    header->type = 109;
    header->version = 2;
    header->markerbit = 1;
    header->extension = 0; 
    handle->stream->sequence_data++;
    header->seq_number = (handle->stream->sequence_data + 100);
    gettimeofday(&now,0);
    header->timestamp = htonl(now.tv_sec);
    
    memcpy((char *)pkt->data + RTP_HEADER_SIZE, buf, len);
    pkt->length = RTP_HEADER_SIZE + len;
    pkt->type = JANUS_ICE_PACKET_DATA_WITH_RTP;
    pkt->control = FALSE;
    pkt->encrypted = FALSE;
    pkt->retransmission = FALSE;
    pkt->added = janus_get_monotonic_time();
    janus_ice_queue_packet(handle, pkt);
}
发送函数static gboolean janus_ice_outgoing_traffic_handle的逻辑中,对ssrc的处理需要修改为:
     header->ssrc = htonl(video ? stream->video_ssrc : ((pkt->type == JANUS_ICE_PACKET_DATA_WITH_RTP)?stream->data_ssrc : stream->audio_ssrc));

 

展开阅读全文

RTP传输mpeg4

05-09

我现在嵌入式环境下开发mpeg4 over RTP的视频服务器。用VLC解码的时候,只有上半部分图象而且有方块效应,下边是花的。编码用的是MPEG4,但VLC显示的解码器为什么是DIVX而不是mp4v呢?rnrn下面是VLC调试信息 丢帧率比较低 怀疑是不是buffer不够,新的帧把缓冲帧冲掉了rnmain error: cannot pre fill bufferrnffmpeg warning: I cbpy damaged at 15 7rn (mpeg4@00D07190)rnffmpeg warning: Error at MB: 337rn (mpeg4@00D07190)rnffmpeg debug: concealing 1069 DC, 1069 AC, 1069 MV errorsrn (mpeg4@00D07190)rnffmpeg warning: header damagedrn (mpeg4@00D07190)rnffmpeg warning: cannot decode one frame (12 bytes)rnffmpeg warning: illegal dc vlcrn (mpeg4@00D07190)rnffmpeg warning: Error at MB: 327rn (mpeg4@00D07190)rnffmpeg warning: marker does not match f_codern (mpeg4@00D07190)rnffmpeg warning: marker does not match f_codern (mpeg4@00D07190)rnffmpeg warning: ac-tex damaged at 6 3rn (mpeg4@00D07190)rnffmpeg warning: Error at MB: 144rn (mpeg4@00D07190)rnffmpeg debug: concealing 1350 DC, 1350 AC, 1350 MV errorsrn (mpeg4@00D07190)rnffmpeg warning: illegal dc vlcrn (mpeg4@00D07190)rnmain warning: late picture skipped (1110267)rnffmpeg debug: concealing 1078 DC, 1078 AC, 1078 MV errorsrn (mpeg4@00D07190)rnffmpeg warning: Error at MB: 336rn (mpeg4@00D07190)rnffmpeg debug: concealing 1070 DC, 1070 AC, 1070 MV errorsrn (mpeg4@00D07190)rnmain warning: late picture skipped (1250678)rnffmpeg warning: I cbpc damaged at 14 7rn (mpeg4@00D07190)rnffmpeg warning: Error at MB: 336rn (mpeg4@00D07190)rnffmpeg debug: concealing 1070 DC, 1070 AC, 1070 MV errorsrn (mpeg4@00D07190)rnmain warning: late picture skipped (1304678)rnffmpeg warning: Error at MB: 538rn (mpeg4@00D07190)rnffmpeg debug: concealing 872 DC, 872 AC, 872 MV errorsrn (mpeg4@00D07190)rnffmpeg warning: header damagedrn (mpeg4@00D07190)rnffmpeg warning: cannot decode one frame (2084 bytes)rnmain warning: late picture skipped (1342678)rnmain warning: late picture skipped (1302678)rnffmpeg warning: Error at MB: 476rn (mpeg4@00D07190)rnffmpeg debug: concealing 933 DC, 933 AC, 933 MV errorsrn (mpeg4@00D07190)rnffmpeg warning: I cbpy damaged at 8 7rn (mpeg4@00D07190)rnffmpeg warning: Error at MB: 330rn (mpeg4@00D07190)rnffmpeg debug: concealing 1076 DC, 1076 AC, 1076 MV errorsrn (mpeg4@00D07190)rnmain warning: late picture skipped (1332678)rnffmpeg warning: illegal dc vlcrn (mpeg4@00D07190)rnffmpeg warning: Error at MB: 337rn (mpeg4@00D07190)rnffmpeg debug: concealing 1069 DC, 1069 AC, 1069 MV errorsrn (mpeg4@00D07190)rnffmpeg warning: Error at MB: 329rn (mpeg4@00D07190)rnffmpeg warning: ac-tex damaged at 1 3rn (mpeg4@00D07190)rnffmpeg warning: Error at MB: 139rn (mpeg4@00D07190)rnffmpeg debug: concealing 1069 DC, 1069 AC, 1069 MV errorsrn (mpeg4@00D07190)rnmain warning: late picture skipped (1107345)rnffmpeg warning: Error at MB: 540rn (mpeg4@00D07190)rnffmpeg warning: Error at MB: 1253rn (mpeg4@00D07190)rnffmpeg warning: cannot decode one frame (2084 bytes)rnffmpeg warning: I cbpc damaged at 14 7rn (mpeg4@00D07190)rnffmpeg warning: Error at MB: 336rn (mpeg4@00D07190)rnffmpeg debug: concealing 1070 DC, 1070 AC, 1070 MV errorsrn (mpeg4@00D07190)rnmain warning: late picture skipped (1026089)rnffmpeg warning: Error at MB: 329rn (mpeg4@00D07190)rnffmpeg debug: concealing 1077 DC, 1077 AC, 1077 MV errorsrn (mpeg4@00D07190)rnffmpeg warning: header damagedrn (mpeg4@00D07190)rnffmpeg warning: cannot decode one frame (2084 bytes)rnffmpeg warning: Error at MB: 329rn (mpeg4@00D07190)rnffmpeg debug: concealing 1080 DC, 1080 AC, 1080 MV errorsrn (mpeg4@00D07190)rnffmpeg debug: concealing 1069 DC, 1069 AC, 1069 MV errorsrn (mpeg4@00D07190)rnmain warning: late picture skipped (132178)rnffmpeg warning: I cbpy damaged at 12 7rn (mpeg4@00D07190)rnffmpeg warning: Error at MB: 334rn (mpeg4@00D07190)rnffmpeg warning: header damagedrn (mpeg4@00D07190)rnffmpeg warning: cannot decode one frame (12 bytes)rnmain debug: closing inputrnmain debug: removing module "ffmpeg"rnmain warning: late picture skipped (362000)rnmain debug: removing module "access_udp"rnmain debug: removing module "packetizer_mpeg4video"rnmain debug: thread times: real 0m55.781250s, kernel 0m0.125000s, user 0m0.140625srnmain debug: thread 4128 joined (input/decoder.c:191)rnmain debug: killing decoder fourcc `DIVX', 0 PES in FIFOrnmain debug: removing an inputrnffmpeg debug: ffmpeg codec (MPEG-4 Video) stoppedrnmain debug: removing module "ffmpeg"rnmain debug: thread times: real 0m55.625000s, kernel 0m0.078125s, user 0m26.062500srnmain debug: thread 4156 joined (input/decoder.c:191)rnmain debug: killing decoder fourcc `mp4v', 92 PES in FIFOrnmain debug: destroying soutrnmain debug: destroying chain... (name=duplicate)rnstream_out_duplicate debug: closing a duplicationrnmain debug: destroying chain... (name=display)rnmain debug: removing module "stream_out_display"rnmain debug: destroying chain donernmain debug: removing module "stream_out_duplicate"rnmain debug: destroying chain donernmain debug: thread times: real 0m56.406250s, kernel 0m1.062500s, user 0m0.500000srnmain debug: thread 3964 joined (input/input.c:412)rnmain debug: garbage collector destroys 1 voutrnvout_directx debug: DirectXCloseSurfacernvout_directx debug: DirectXCloseDisplayrnvout_directx debug: DirectXCloseDisplay clipperrnvout_directx debug: DirectXCloseDisplay displayrnvout_directx debug: DirectXCloseDDrawrnvout_directx debug: CloseVideornvout_directx debug: DirectXEventThread terminatingrnvout_directx debug: DirectXCloseWindowrnvout_directx debug: WinProc WM_DESTROYrnmain debug: thread times: real 0m55.843750s, kernel 0m0.109375s, user 0m0.000000srnmain debug: thread 4212 joined (directx.c:509)rnmain debug: removing module "vout_directx"rnmain debug: thread times: real 0m55.750000s, kernel 0m0.093750s, user 0m0.843750srnmain debug: thread 4244 joined (video_output/video_output.c:461)rn 论坛

没有更多推荐了,返回首页