| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2012, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: $ |
|---|
| 11 | * $brcm_Revision: $ |
|---|
| 12 | * $brcm_Date: $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: $ |
|---|
| 19 | * |
|---|
| 20 | ***************************************************************************/ |
|---|
| 21 | |
|---|
| 22 | #ifndef _RTP_H |
|---|
| 23 | #define _RTP_H |
|---|
| 24 | |
|---|
| 25 | #if defined(NEXUS_LINUXUSER) |
|---|
| 26 | #include <sys/types.h> |
|---|
| 27 | #include <sys/socket.h> |
|---|
| 28 | #include <sys/un.h> |
|---|
| 29 | #include <resolv.h> |
|---|
| 30 | #include <unistd.h> |
|---|
| 31 | #elif defined(CONFIG_LWIP) |
|---|
| 32 | #include "lwip/sockets.h" |
|---|
| 33 | #endif |
|---|
| 34 | |
|---|
| 35 | #define RTP_TS_UNIT 188 |
|---|
| 36 | #ifdef CONFIG_LWIP |
|---|
| 37 | #define RTP_MAX_TS_PER_MTU 7 |
|---|
| 38 | #else |
|---|
| 39 | #define RTP_MAX_TS_PER_MTU 28 /* TODO:: to make packet size under network layer's MTU. Need to verify Packet size on lwip */ |
|---|
| 40 | #endif |
|---|
| 41 | #define RTP_PAYLOAD_SIZE (RTP_TS_UNIT*RTP_MAX_TS_PER_MTU) |
|---|
| 42 | #define RTP_HEADER_SIZE 12 |
|---|
| 43 | #define RTP_PACKET_SIZE (RTP_PAYLOAD_SIZE+RTP_HEADER_SIZE) |
|---|
| 44 | #define RTP_MP2T 33 |
|---|
| 45 | |
|---|
| 46 | enum |
|---|
| 47 | { |
|---|
| 48 | RTP_OK = 0, |
|---|
| 49 | RTP_RECV_ERR = 1, |
|---|
| 50 | RTP_SOCKET_ERR = 2, |
|---|
| 51 | RTP_MEM_ERR = 3, |
|---|
| 52 | }; |
|---|
| 53 | |
|---|
| 54 | /* this is for gcc little endian */ |
|---|
| 55 | typedef struct rtp_bits_t |
|---|
| 56 | { |
|---|
| 57 | unsigned int cc:4; /* CSRC identifiers */ |
|---|
| 58 | unsigned int x:1; /* extension headers */ |
|---|
| 59 | unsigned int p:1; /* padding */ |
|---|
| 60 | unsigned int v:2; /* version */ |
|---|
| 61 | unsigned int pt:7; /* payload type, see RFC 1890 */ |
|---|
| 62 | unsigned int m:1; /* marker */ |
|---|
| 63 | unsigned int seq:16; /* sequence number */ |
|---|
| 64 | }rtp_bits_t; |
|---|
| 65 | |
|---|
| 66 | typedef struct rtp_header_t |
|---|
| 67 | { |
|---|
| 68 | rtp_bits_t b; |
|---|
| 69 | int timestamp; |
|---|
| 70 | int csrc; |
|---|
| 71 | }rtp_header_t; |
|---|
| 72 | |
|---|
| 73 | typedef struct rtp_t |
|---|
| 74 | { |
|---|
| 75 | rtp_header_t rtph; /* default RTP header */ |
|---|
| 76 | #if defined(NEXUS_LINUXUSER)||defined(CONFIG_LWIP) |
|---|
| 77 | struct sockaddr_in saddr; |
|---|
| 78 | #endif |
|---|
| 79 | int s_fd; /* socket descriptor */ |
|---|
| 80 | unsigned char *buf; /* datagram buffer */ |
|---|
| 81 | unsigned int buf_len; /* length of the buffer */ |
|---|
| 82 | unsigned char *data_buf; /* pointer to payload buffer */ |
|---|
| 83 | int h_len; /* header length */ |
|---|
| 84 | }rtp_t; |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | #ifdef __cplusplus |
|---|
| 88 | extern "C" { |
|---|
| 89 | #endif |
|---|
| 90 | |
|---|
| 91 | int init_rtp( |
|---|
| 92 | rtp_t *p_rtp, /* uninitialized RTP structure */ |
|---|
| 93 | unsigned int buf_len, /* buffer length in bytes */ |
|---|
| 94 | int payload_type /* payload type of default RTP header (to use for sending) */ |
|---|
| 95 | ); |
|---|
| 96 | void free_rtp( |
|---|
| 97 | rtp_t *p_rtp /* initialized RTP structure */ |
|---|
| 98 | ); |
|---|
| 99 | |
|---|
| 100 | int get_rtp( |
|---|
| 101 | rtp_t *p_rtp, /* initialized RTP structure */ |
|---|
| 102 | unsigned int *len /* output payload size in bytes */ |
|---|
| 103 | ); |
|---|
| 104 | |
|---|
| 105 | int send_rtp( |
|---|
| 106 | rtp_t *p_rtp, /* initialized RTP structure */ |
|---|
| 107 | unsigned char *buf, |
|---|
| 108 | unsigned int len /* number of bytes in payload */ |
|---|
| 109 | ); |
|---|
| 110 | |
|---|
| 111 | int makesocket_rtp( |
|---|
| 112 | rtp_t *p_rtp, /* initialized RTP structure */ |
|---|
| 113 | char *addr_str, /* address string */ |
|---|
| 114 | unsigned short port, /* create socket for port */ |
|---|
| 115 | int ttl /* TTL */ |
|---|
| 116 | ); |
|---|
| 117 | |
|---|
| 118 | int makeclientsocket_rtp( |
|---|
| 119 | rtp_t *p_rtp, /* initialized RTP structure */ |
|---|
| 120 | char *addr_str, /* address string */ |
|---|
| 121 | unsigned short port, /* create socket for port */ |
|---|
| 122 | int ttl /* TTL */ |
|---|
| 123 | ); |
|---|
| 124 | |
|---|
| 125 | #ifdef __cplusplus |
|---|
| 126 | } |
|---|
| 127 | #endif |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | #endif |
|---|