• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * rtp.h
3  *
4  * rtp interface for srtp reference implementation
5  *
6  * David A. McGrew
7  * Cisco Systems, Inc.
8  *
9  * data types:
10  *
11  * rtp_msg_t       an rtp message (the data that goes on the wire)
12  * rtp_sender_t    sender side socket and rtp info
13  * rtp_receiver_t  receiver side socket and rtp info
14  *
15  */
16 
17 /*
18  *
19  * Copyright (c) 2001-2017, Cisco Systems, Inc.
20  * All rights reserved.
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions
24  * are met:
25  *
26  *   Redistributions of source code must retain the above copyright
27  *   notice, this list of conditions and the following disclaimer.
28  *
29  *   Redistributions in binary form must reproduce the above
30  *   copyright notice, this list of conditions and the following
31  *   disclaimer in the documentation and/or other materials provided
32  *   with the distribution.
33  *
34  *   Neither the name of the Cisco Systems, Inc. nor the names of its
35  *   contributors may be used to endorse or promote products derived
36  *   from this software without specific prior written permission.
37  *
38  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
39  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
40  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
41  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
42  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
43  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
44  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
45  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49  * OF THE POSSIBILITY OF SUCH DAMAGE.
50  *
51  */
52 
53 #ifndef SRTP_RTP_H
54 #define SRTP_RTP_H
55 
56 #ifdef HAVE_NETINET_IN_H
57 #include <netinet/in.h>
58 #elif defined HAVE_WINSOCK2_H
59 #include <winsock2.h>
60 #endif
61 
62 #include "srtp_priv.h"
63 
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67 
68 /*
69  * RTP_HEADER_LEN indicates the size of an RTP header
70  */
71 #define RTP_HEADER_LEN 12
72 
73 /*
74  * RTP_MAX_BUF_LEN defines the largest RTP packet in the rtp.c implementation
75  */
76 #define RTP_MAX_BUF_LEN 16384
77 
78 typedef srtp_hdr_t rtp_hdr_t;
79 
80 typedef struct {
81     srtp_hdr_t header;
82     char body[RTP_MAX_BUF_LEN];
83 } rtp_msg_t;
84 
85 typedef struct rtp_sender_ctx_t {
86     rtp_msg_t message;
87     int socket;
88     srtp_ctx_t *srtp_ctx;
89     struct sockaddr_in addr; /* reciever's address */
90 } rtp_sender_ctx_t;
91 
92 typedef struct rtp_receiver_ctx_t {
93     rtp_msg_t message;
94     int socket;
95     srtp_ctx_t *srtp_ctx;
96     struct sockaddr_in addr; /* receiver's address */
97 } rtp_receiver_ctx_t;
98 
99 typedef struct rtp_sender_ctx_t *rtp_sender_t;
100 
101 typedef struct rtp_receiver_ctx_t *rtp_receiver_t;
102 
103 int rtp_sendto(rtp_sender_t sender, const void *msg, int len);
104 
105 int rtp_recvfrom(rtp_receiver_t receiver, void *msg, int *len);
106 
107 int rtp_receiver_init(rtp_receiver_t rcvr,
108                       int sock,
109                       struct sockaddr_in addr,
110                       unsigned int ssrc);
111 
112 int rtp_sender_init(rtp_sender_t sender,
113                     int sock,
114                     struct sockaddr_in addr,
115                     unsigned int ssrc);
116 
117 /*
118  * srtp_sender_init(...) initializes an rtp_sender_t
119  */
120 
121 int srtp_sender_init(
122     rtp_sender_t rtp_ctx,              /* structure to be init'ed */
123     struct sockaddr_in name,           /* socket name             */
124     srtp_sec_serv_t security_services, /* sec. servs. to be used  */
125     unsigned char *input_key           /* master key/salt in hex  */
126     );
127 
128 int srtp_receiver_init(
129     rtp_receiver_t rtp_ctx,            /* structure to be init'ed */
130     struct sockaddr_in name,           /* socket name             */
131     srtp_sec_serv_t security_services, /* sec. servs. to be used  */
132     unsigned char *input_key           /* master key/salt in hex  */
133     );
134 
135 int rtp_sender_init_srtp(rtp_sender_t sender, const srtp_policy_t *policy);
136 
137 int rtp_sender_deinit_srtp(rtp_sender_t sender);
138 
139 int rtp_receiver_init_srtp(rtp_receiver_t sender, const srtp_policy_t *policy);
140 
141 int rtp_receiver_deinit_srtp(rtp_receiver_t sender);
142 
143 rtp_sender_t rtp_sender_alloc(void);
144 
145 void rtp_sender_dealloc(rtp_sender_t rtp_ctx);
146 
147 rtp_receiver_t rtp_receiver_alloc(void);
148 
149 void rtp_receiver_dealloc(rtp_receiver_t rtp_ctx);
150 
151 #ifdef __cplusplus
152 }
153 #endif
154 
155 #endif /* SRTP_RTP_H */
156