示例#1
0
RTP_session *RTP_session_destroy(RTP_session *session)
{
	RTP_session *next = session->next;
	OMSBuffer *buff = session->current_media->pkt_buffer;
	//struct stat fdstat;

	// shawill: close socket. To be moved in a specific function (RTP_transport_close)
	//Release SD_flag using in multicast and unjoing the multicast group
	// if(session->sd_descr->flags & SD_FL_MULTICAST){
	if( (session->transport.type==RTP_rtp_avp) && session->transport.u.udp.is_multicast) {
		struct ip_mreq mreq;
		mreq.imr_multiaddr.s_addr = inet_addr(session->sd_descr->multicast);
		mreq.imr_interface.s_addr = INADDR_ANY;
		setsockopt(session->transport.rtp_fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq));
		session->sd_descr->flags &= ~SD_FL_MULTICAST_PORT; /*Release SD_FL_MULTICAST_PORT*/
	}
	
	switch (session->transport.type) {
		case RTP_rtp_avp:
			// we must close socket only if we use udp, because for interleaved tcp
			// we use rtsp that must not be closed here.
			close(session->transport.rtp_fd);
			close(session->transport.rtcp_fd_in);
			close(session->transport.rtcp_fd_out);
			// release ports
			RTP_release_port_pair(&(session->transport.u.udp.ser_ports));
			break;
		case RTP_rtp_avp_tcp:
			session->transport.rtp_fd = session->transport.rtcp_fd_out = -1;
			break;
		default:
			break;
	}
	
	// destroy consumer
	OMSbuff_unref(session->cons);
	if (session->current_media->pkt_buffer->control->refs==0) {
			session->current_media->pkt_buffer=NULL;
			OMSbuff_free(buff);
			// close file if it's not a pipe
			//fstat(session->current_media->fd, &fdstat);
			//if ( !S_ISFIFO(fdstat.st_mode) )
				mediaclose(session->current_media);
	}
	// Deallocate memory
	free(session);

	return next;
}
示例#2
0
文件: rtp.c 项目: phully/feng_build
/**
 * Closes a transport linked to a session
 * @param session the RTP session for which to close the transport
 */
static void rtp_transport_close(RTP_session * session)
{
    port_pair pair;
    pair.RTP = get_local_port(session->transport.rtp_sock);
    pair.RTCP = get_local_port(session->transport.rtcp_sock);

    ev_periodic_stop(session->srv->loop, &session->transport.rtp_writer);
    ev_io_stop(session->srv->loop, &session->transport.rtcp_reader);

    switch (session->transport.rtp_sock->socktype) {
    case UDP:
        RTP_release_port_pair(session->srv, &pair);
    default:
        break;
    }
    Sock_close(session->transport.rtp_sock);
    Sock_close(session->transport.rtcp_sock);
}