📄 rtp_send_packet.c
字号:
/* * * $Id: RTP_send_packet.c 143 2005-05-16 17:38:49Z federico $ * * This file is part of Fenice * * Fenice -- Open Media Server * * Copyright (C) 2004 by * * - Giampaolo Mancini <giampaolo.mancini@polito.it> * - Francesco Varano <francesco.varano@polito.it> * - Marco Penno <marco.penno@polito.it> * - Federico Ridolfo <federico.ridolfo@polito.it> * - Eugenio Menegatti <m.eu@libero.it> * - Stefano Cau * - Giuliano Emma * - Stefano Oldrini * * Fenice is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Fenice is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Fenice; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * */#include <config.h>#if HAVE_ALLOCA_H#include <alloca.h>#endif#include <string.h>#include <stdlib.h>#include <stdio.h>#include <netinet/in.h>#include <fenice/rtp.h>#include <fenice/utils.h>#include <fenice/bufferpool.h>#include <fenice/fnc_log.h>#if ENABLE_DUMP#include <fenice/debug.h>#endifint RTP_send_packet(RTP_session *session){ unsigned char *packet=NULL; unsigned int hdr_size=0; RTP_header r; // 12 bytes int res=ERR_GENERIC; double s_time; double nextts; OMSSlot *slot=NULL; ssize_t psize_sent=0; if(!(slot = OMSbuff_getreader(session->cons))){ //This operation runs only if producer writes the slot //session->current_media->mtime += session->current_media->description.delta_mtime; //emma //session->current_media->mtime+=session->current_media->description.pkt_len; // old scheduler s_time = session->current_media->mtime - session->current_media->mstart + session->current_media->mstart_offset; if ( (res=get_frame(session->current_media,&s_time))!=ERR_NOERROR ){ //fprintf(stderr,"Some errors occurred\n"); return res; } session->current_media->mtime += session->current_media->description.delta_mtime; //emma session->cons->frames++; slot=OMSbuff_getreader(session->cons); } else /*This runs if the consumer reads slot written in another RTP session*/ s_time=slot->timestamp; while (slot) { /*if (strcmp(session->current_media->description.encoding_name,"MP2T")!=0) { //session->current_media->mtime = slot->timestamp + session->current_media->mstart - session->current_media->mstart_offset; }*/ hdr_size=sizeof(r); r.version = 2; r.padding = 0; r.extension = 0; r.csrc_len = 0; r.marker=slot->marker; r.payload = session->current_media->description.payload_type; r.seq_no = htons(session->seq++ + session->start_seq); r.timestamp=htonl(session->start_rtptime+msec2tick(slot->timestamp,session->current_media)); r.ssrc = htonl(session->ssrc);#if HAVE_ALLOCA packet=(unsigned char*)alloca(slot->data_size+hdr_size);#else packet=(unsigned char*)calloc(1,slot->data_size+hdr_size);#endif if (packet==NULL) { return ERR_ALLOC; } memcpy(packet,&r,hdr_size); memcpy(packet+hdr_size,slot->data,slot->data_size); if ((psize_sent=sendto(session->rtp_fd,packet,slot->data_size+hdr_size,0,&(session->rtp_peer),sizeof(session->rtp_peer)))<0){ fnc_log(FNC_LOG_DEBUG,"RTP Packet Lost\n"); } else {#if ENABLE_DUMP char fname[255]; char crtp[255]; memset(fname,0,sizeof(fname)); strcpy(fname,"dump_fenice."); strcat(fname,session->current_media->description.encoding_name); strcat(fname,"."); sprintf(crtp,"%d",session->rtp_fd); strcat(fname,crtp); if(strcmp(session->current_media->description.encoding_name,"MPV")==0 || strcmp(session->current_media->description.encoding_name,"MPA")==0) dump_payload(packet+16,psize_sent-16,fname); else dump_payload(packet+12,psize_sent-12,fname);#endif session->rtcp_stats[i_server].pkt_count++; session->rtcp_stats[i_server].octet_count+=slot->data_size; }#if !HAVE_ALLOCA free(packet);#endif OMSbuff_gotreader(session->cons); if ( ((nextts=OMSbuff_nextts(session->cons)) == -1) || (nextts != s_time) ) { slot = NULL; session->cons->frames--; } else slot = OMSbuff_getreader(session->cons); } return ERR_NOERROR;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -