Exemplo n.º 1
0
Arquivo: gb28181.c Projeto: LinLL/ipc
int gb28181_data_proc(pSipSession s)
{	
	char ip[32];
	int port,payloadtype;

	sip_parse_siphead(&s->recv_siphead,s->recvbuf);
	if(0 == strncmp(s->recv_siphead.sh_ReqLine.cmd,"MESSAGE",strlen("MESSAGE")))
	{
		TRACE("\033[32mGet a %s 2 parse\033[0m\n",s->recv_siphead.sh_ContentType.content_type);
		if(0 == strncmp(s->recv_siphead.sh_ContentType.content_type,"Application/MANSCDP+xml",strlen("Application/MANSCDP+xml")))
		{
			if( 0 ==  s->run_msg_loop)
			{
				char *data_ptr = strstr(s->recvbuf,"\r\n\r\n") + 4;
				s->xml_str = strdup(data_ptr);	
				char *cmdtype = s->get_tagvalue(s->xml_str,"CmdType");		
				if(NULL ==  s->get_tagvalue(s->xml_str,"PTZCmd")
						&& NULL == s->get_tagvalue(s->xml_str,"TeleBoot")
						&& 0 != strcmp("Alarm",cmdtype))
				{
					s->pack_msg(s,MSG_200,NULL);
					TRACE("echo 200;Message need 4 steps way\n");		
					sendto(s->sock,s->sendbuf,strlen(s->sendbuf),\
							0,(struct sockaddr*)&s->server,sizeof(s->server));
				}				
				pthread_t msg;
				pthread_create(&msg,NULL,&gb28181_msg_loop,s);
				pthread_detach(msg);
			}
		}
	}
	else if(0 == strncmp(s->recv_siphead.sh_EchoLine.msg_code,"401",3))
	{
		if(s->auth_status == AUTH_S_REG)
		{
			s->pack_msg(s,MSG_RE_AUTH,NULL);
			TRACE("401:::Re_auth\n");
			s->auth_status = AUTH_S_401;
		}
	}
	else if(0 == strncmp(s->recv_siphead.sh_EchoLine.msg_code,"200",3))
	{
		if((0 == s->online) && s->auth_status == AUTH_S_REG_AGAIN)
		{//this is auth success
			GB_NOTIFY("200:::AUTH success time:%d\n",(int)time(NULL));
			//FIXME the time on board is UTC time
			TRACE("ServerTime:%04d-%02d-%02d %02d:%02d:%02d.%03d\n",
					s->recv_siphead.sh_Date.YYYY,s->recv_siphead.sh_Date.MM,
					s->recv_siphead.sh_Date.DD,
					s->recv_siphead.sh_Date.hh,
					s->recv_siphead.sh_Date.mm,
					s->recv_siphead.sh_Date.ss,
					s->recv_siphead.sh_Date.mmm);
			char time_str[32];
			sprintf(time_str,"date -s \"%04d-%02d-%02d %02d:%02d:%02d\"",
					s->recv_siphead.sh_Date.YYYY,
					s->recv_siphead.sh_Date.MM,
					s->recv_siphead.sh_Date.DD,
					s->recv_siphead.sh_Date.hh,
					s->recv_siphead.sh_Date.mm,
					s->recv_siphead.sh_Date.ss);
			system(time_str);

			s->auth_status = AUTH_S_SUCCESS;
			s->online = 1;
			pthread_t hb;
			pthread_create(&hb,NULL,&gb28181_heartbeat_loop,s);
			pthread_detach(hb);
		}
		else if((0 != s->online) && s->auth_status == AUTH_S_REG_AGAIN)
		{
			GB_NOTIFY("200:::Login out success:%d\n",(int)time(NULL));
			s->auth_status = AUTH_S_SUCCESS;
			s->online = 0 ;
		}
		else if((0 != s->online) && s->auth_status == AUTH_S_SUCCESS)
		{// heartbeat or other msg echo 200
			if((strlen(s->heartbeat_callid) > 0)&&(0 == strncmp(s->recv_siphead.sh_CallID.call_id,s->heartbeat_callid,
							strlen(s->heartbeat_callid)))){
				TRACE("Get A HeartBeat callID:%s\n",s->heartbeat_callid);
			}else{
				s->run_msg_loop = 0;
			}
		}		
	}
	else if(0 == strncmp(s->recv_siphead.sh_ReqLine.cmd,"INVITE",6))
	{
		SessionDesc_t *sdp=NULL;
		SipRtpSession_t *srtp=NULL;
		TRACE("sdp ###%s\n",strstr(s->recvbuf,"\r\n\r\n") + 4);
		TRACE("Get a media request\n");
		if(SIPRTP_session_find(s->recv_siphead.sh_CallID.call_id)==NULL){
			sdp = (void *)SDP_decode(strstr(s->recvbuf,"\r\n\r\n") + 4);
			srtp=SIPRTP_session_add(s->recv_siphead.sh_CallID.call_id,g_SipRtpPort++,sdp,s);
			pthread_t invite;
			pthread_create(&invite,NULL,gb28181_invite_loop,srtp);
			pthread_detach(invite);
		}
	}
	else if(0 == strncmp(s->recv_siphead.sh_ReqLine.cmd,"ACK",3))
	{
		TRACE("Get a media ACK\n");
		SessionDesc_t *sdp=NULL;
		SipRtpSession_t *srtp=NULL;
		Rtp_t *rtp=NULL;
		if((srtp=SIPRTP_session_find(s->recv_siphead.sh_CallID.call_id))!=NULL){
			sdp = (SessionDesc_t *)srtp->data.context;
			TRACE("ssrc:%u",sdp->media[0].ssrc);
			SDP_get_h264_info(sdp,&payloadtype,ip,&port);
			TRACE("payloadtype:%d,ip:%s:%d\n",payloadtype,ip,port);
			int sock=SOCK_udp_init(srtp->data.port,3000);
			rtp = (void *)RTP_server_new(sdp->media[0].ssrc,payloadtype,RTP_TRANSPORT_UDP,FALSE,sock,ip,port);
			SIPRTP_session_set_context(srtp,rtp);
			SDP_cleanup(sdp);
#if 0
			pthread_t thread_rtp;
			pthread_create(&thread_rtp,NULL,gb28181_rtp_loop,srtp);
#endif
		}
	}
	else if(0 == strncmp(s->recv_siphead.sh_ReqLine.cmd,"BYE",3))
	{		
		SipRtpSession_t *srtp=NULL;
		s->pack_msg(s, MSG_200,NULL);
		TRACE("BYE:\n%s\n",s->sendbuf);
		sendto(s->sock,s->sendbuf,strlen(s->sendbuf),\
				0,(struct sockaddr*)&s->server,sizeof(s->server));		
		if((srtp=SIPRTP_session_find(s->recv_siphead.sh_CallID.call_id))!=NULL){
#if 1
			RTP_destroy((Rtp_t *)srtp->data.context);
			SIPRTP_session_del(srtp->data.id);
#else
			SIPRTP_session_toggle(srtp,FALSE);
#endif
		}
	}
	return 0;
}
Exemplo n.º 2
0
void TalkbackCore::deinitRtspInfo()
{
    //fix me
    if(m_pRtspInfo!=NULL){
        //close rtspSocket
        //delete sdp;
        //delete auth
        //delete pRtcp_video
        //delete pRtcp_audio
        //delete pRtp_video
        //delete pRtp_audio
        //close pSocketGroup
        //delete pSocketGroup
        //delete m_pRtspInfo
        if(m_pRtspInfo->rtspSocket!=-1){
            SOCK_close(m_pRtspInfo->rtspSocket);
            m_pRtspInfo->rtspSocket=-1;
        }
        if(m_pRtspInfo->sdp!=NULL){
            SDP_cleanup(m_pRtspInfo->sdp);
            m_pRtspInfo->sdp=NULL;
        }
        if(m_pRtspInfo->auth!=NULL){
            HTTP_AUTH_destroy(m_pRtspInfo->auth);
            m_pRtspInfo->auth=NULL;
        }
        if(m_pRtspInfo->pSocketGroup!=NULL){
            if(m_pRtspInfo->pSocketGroup->rtcp_socket!=-1){
                SOCK_close(m_pRtspInfo->pSocketGroup->rtcp_socket);
                m_pRtspInfo->pSocketGroup->rtcp_socket=-1;
            }
            if(m_pRtspInfo->pSocketGroup->rtp_socket!=-1){
                SOCK_close(m_pRtspInfo->pSocketGroup->rtp_socket);
                m_pRtspInfo->pSocketGroup->rtp_socket=-1;
            }
            delete m_pRtspInfo->pSocketGroup;
            m_pRtspInfo->pSocketGroup=NULL;
        }
        if(NULL!=m_pRtspInfo->pRtcp_audio){
            m_pRtspInfo->pRtcp_audio->deinit();
            delete m_pRtspInfo->pRtcp_audio;
            m_pRtspInfo->pRtcp_audio=NULL;
        }
        if(NULL!=m_pRtspInfo->pRtcp_video){
            m_pRtspInfo->pRtcp_video->deinit();
            delete m_pRtspInfo->pRtcp_video;
            m_pRtspInfo->pRtcp_video=NULL;
        }
        if(NULL!=m_pRtspInfo->pRtp_audio){
            m_pRtspInfo->pRtp_audio->deinit();
            delete m_pRtspInfo->pRtp_audio;
            m_pRtspInfo->pRtp_audio=NULL;
        }
        if(NULL!=m_pRtspInfo->pRtp_video){
            m_pRtspInfo->pRtp_video->deinit();
            delete m_pRtspInfo->pRtp_video;
            m_pRtspInfo->pRtp_video=NULL;
        }
        delete m_pRtspInfo;
        m_pRtspInfo=NULL;
    }
}