1/* @(#) interface to RTP-protocol parsing functions for udpxy 2 * 3 * Copyright 2008-2011 Pavel V. Cherenkov (pcherenkov@gmail.com) 4 * 5 * This file is part of udpxy. 6 * 7 * udpxy is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * udpxy is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with udpxy. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21#ifndef RTPH_UDPXY_021308 22#define RTPH_UDPXY_021308 23 24#include <sys/types.h> 25 26static const int MPEG_TS_SIG = 0x47; 27static const size_t RTP_MIN_SIZE = 4; 28static const size_t RTP_HDR_SIZE = 12; /* RFC 3550 */ 29static const int RTP_VER2 = 0x02; 30 31/* offset to header extension and extension length, 32 * as per RFC 3550 5.3.1 */ 33static const size_t XTLEN_OFFSET = 14; 34static const size_t XTSIZE = 4; 35 36/* minimum length to determine size of an extended RTP header 37 */ 38#define RTP_XTHDRLEN (XTLEN_OFFSET + XTSIZE) 39 40static const size_t CSRC_SIZE = 4; 41 42/* MPEG payload-type constants - adopted from VLC 0.8.6 */ 43#define P_MPGA 0x0E /* MPEG audio */ 44#define P_MPGV 0x20 /* MPEG video */ 45#define P_MPGTS 0x21 /* MPEG TS */ 46 47#ifdef __cplusplus 48extern "C" { 49#endif 50 51 52/* check if the buffer is an RTP packet 53 * 54 * @param buf buffer to analyze 55 * @param len size of the buffer 56 * @param is_rtp variable to set to 1 if data is an RTP packet 57 * @param log log file 58 * 59 * @return 0 if there was no error, -1 otherwise 60 */ 61int RTP_check( const char* buf, const size_t len, int* is_rtp, FILE* log ); 62 63 64/* process RTP package to retrieve the payload: set 65 * pbuf to the start of the payload area; set len to 66 * be equal payload's length 67 * 68 * @param pbuf address of pointer to beginning of RTP packet 69 * @param len pointer to RTP packet's length 70 * @param verify verify that it is an RTP packet if != 0 71 * @param log log file 72 * 73 * @return 0 if there was no error, -1 otherwise; 74 * set pbuf to point to beginning of payload and len 75 * be payload size in bytes 76 */ 77int RTP_process( void** pbuf, size_t* len, int verify, FILE* log ); 78 79 80/* verify if buffer contains an RTP packet, 0 otherwise 81 * 82 * @param buf buffer to analyze 83 * @param len size of the buffer 84 * @param log error log 85 * 86 * @return 1 if buffer contains an RTP packet, 0 otherwise 87 */ 88int RTP_verify( const char* buf, const size_t len, FILE* log ); 89 90 91/* calculate length of an RTP header 92 * 93 * @param buf buffer to analyze 94 * @param len size of the buffer 95 * @param hdrlen pointer to header length variable 96 * @param log error log 97 * 98 * @return 0 if header length has been calculated, 99 * ENOMEM if buffer is not big enough 100 */ 101int RTP_hdrlen( const char* buf, const size_t len, size_t* hdrlen, 102 FILE* log ); 103 104#ifdef __cplusplus 105} 106#endif 107 108#endif /* RTPH_UDPXY_021308 */ 109 110 111/* __EOF__ */ 112 113