1 /* 2 * Copyright (C) 2002-2003 Fhg Fokus 3 * 4 * This file is part of SEMS, a free SIP media server. 5 * 6 * SEMS is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. This program is released under 10 * the GPL with the additional exemption that compiling, linking, 11 * and/or using OpenSSL is allowed. 12 * 13 * For a license to use the SEMS software under conditions 14 * other than those described here, or to purchase support for this 15 * software, please contact iptel.org by e-mail at the following addresses: 16 * info@iptel.org 17 * 18 * SEMS is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 * GNU General Public License for more details. 22 * 23 * You should have received a copy of the GNU General Public License 24 * along with this program; if not, write to the Free Software 25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 */ 27 /** @file AmRtpPacket.h */ 28 #ifndef _AmRtpPacket_h_ 29 #define _AmRtpPacket_h_ 30 31 #include <sys/time.h> 32 #include <sys/types.h> 33 #include <sys/socket.h> 34 #include <netinet/in.h> 35 36 #include <string> 37 38 class AmRtpPacketTracer; 39 class msg_logger; 40 41 /** \brief RTP packet implementation */ 42 class AmRtpPacket { 43 44 unsigned char buffer[4096]; 45 unsigned int b_size; 46 47 unsigned int data_offset; 48 unsigned int d_size; 49 AmRtpPacket()50 int sendto(int sd); 51 int sendmsg(int sd, unsigned int sys_if_idx); 52 53 public: 54 unsigned char payload; 55 bool marker; 56 unsigned short sequence; 57 unsigned int timestamp; ~AmRtpPacket()58 unsigned int ssrc; 59 unsigned char version; 60 61 struct timeval recv_time; setAddr(struct sockaddr_storage * a)62 struct sockaddr_storage addr; 63 64 AmRtpPacket(); 65 ~AmRtpPacket(); 66 getAddr(struct sockaddr_storage * a)67 void setAddr(struct sockaddr_storage* a); 68 void getAddr(struct sockaddr_storage* a); 69 70 // returns -1 if error, else 0 71 int compile(unsigned char* data_buf, unsigned int size); parse()72 // returns -1 if error, else 0 73 int compile_raw(unsigned char* data_buf, unsigned int size); 74 75 int send(int sd, unsigned int sys_if_idx, sockaddr_storage* l_saddr, 76 const std::string& rtp_mux_remote_ip = "", unsigned int rtp_mux_remote_port=0); 77 int recv(int sd); 78 // copy from already received packet 79 int recv(unsigned char* pkt, size_t len); 80 81 int parse(); 82 83 unsigned int getDataSize() const { return d_size; } 84 unsigned char* getData(); 85 86 unsigned int getBufferSize() const { return b_size; } 87 unsigned char* getBuffer(); 88 void setBufferSize(unsigned int b) { b_size = b; } 89 90 void logReceived(msg_logger *logger, struct sockaddr_storage *laddr); 91 void logSent(msg_logger *logger, struct sockaddr_storage *laddr); 92 }; 93 94 #endif 95 96 97