UniMRCP  1.3.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
mpf_rtp_defs.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2014 Arsen Chaloyan
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Id: mpf_rtp_defs.h 2136 2014-07-04 06:33:36Z achaloyan@gmail.com $
17  */
18 
19 #ifndef MPF_RTP_DEFS_H
20 #define MPF_RTP_DEFS_H
21 
22 /**
23  * @file mpf_rtp_defs.h
24  * @brief Internal RTP Definitions
25  */
26 
27 #include "mpf_rtp_stat.h"
28 #include "mpf_jitter_buffer.h"
29 
31 
32 /** Used to calculate actual number of received packets (32bit) in
33  * case seq number (16bit) wrapped around */
34 #define RTP_SEQ_MOD (1 << 16)
35 /** Number of max dropout packets (seq numbers) is used to trigger
36  * either a drift in the seq numbers or a misorder packet */
37 #define MAX_DROPOUT 3000
38 /** Number of max misorder packets (seq numbers) is used to
39  * differentiate a drift in the seq numbers from a misorder packet */
40 #define MAX_MISORDER 100
41 /** Restart receiver if threshold is reached */
42 #define DISCARDED_TO_RECEIVED_RATIO_THRESHOLD 30 /* 30% */
43 /** Deviation threshold is used to trigger a drift in timestamps */
44 #define DEVIATION_THRESHOLD 4000
45 /** This threshold is used to detect a new talkspurt */
46 #define INTER_TALKSPURT_GAP 1000 /* msec */
47 
48 /** RTP receiver history declaration */
50 /** RTP receiver periodic history declaration */
52 /** RTP receiver declaration */
54 /** RTP transmitter declaration */
56 
57 /** History of RTP receiver */
59  /** Updated on every seq num wrap around */
60  apr_uint32_t seq_cycles;
61 
62  /** First seq num received */
63  apr_uint16_t seq_num_base;
64  /** Max seq num received */
65  apr_uint16_t seq_num_max;
66 
67  /** Last timestamp received */
68  apr_uint32_t ts_last;
69  /** Local time measured on last packet received */
70  apr_time_t time_last;
71 
72  /** New ssrc, which is in probation */
73  apr_uint32_t ssrc_new;
74  /** Period of ssrc probation */
75  apr_byte_t ssrc_probation;
76 };
77 
78 /** Periodic history of RTP receiver (initialized after every N packets) */
80  /** Number of packets received */
81  apr_uint32_t received_prior;
82  /** Number of packets expected */
83  apr_uint32_t expected_prior;
84  /** Number of packets discarded */
85  apr_uint32_t discarded_prior;
86 
87  /** Min jitter */
88  apr_uint32_t jitter_min;
89  /** Max jitter */
90  apr_uint32_t jitter_max;
91 };
92 
93 /** Reset RTP receiver history */
94 static APR_INLINE void mpf_rtp_rx_history_reset(rtp_rx_history_t *rx_history)
95 {
96  memset(rx_history,0,sizeof(rtp_rx_history_t));
97 }
98 
99 /** Reset RTP receiver periodic history */
100 static APR_INLINE void mpf_rtp_rx_periodic_history_reset(rtp_rx_periodic_history_t *rx_periodic_history)
101 {
102  memset(rx_periodic_history,0,sizeof(rtp_rx_periodic_history_t));
103 }
104 
105 /** RTP receiver */
107  /** Jitter buffer */
109 
110  /** RTCP statistics used in RR */
112  /** RTP receiver statistics */
114  /** RTP history */
116  /** RTP periodic history */
118 };
119 
120 
121 /** RTP transmitter */
123  /** Packetization time in msec */
124  apr_uint16_t ptime;
125 
126  /** Number of frames in a packet */
127  apr_uint16_t packet_frames;
128  /** Current number of frames */
129  apr_uint16_t current_frames;
130  /** Samples in frames in timestamp units */
131  apr_uint32_t samples_per_frame;
132 
133  /** Indicate silence period among the talkspurts */
134  apr_byte_t inactivity;
135  /** Last seq number sent */
136  apr_uint16_t last_seq_num;
137  /** Current timestamp (samples processed) */
138  apr_uint32_t timestamp;
139  /** Event timestamp base */
140  apr_uint32_t timestamp_base;
141 
142  /** RTP packet payload */
143  char *packet_data;
144  /** RTP packet payload size */
145  apr_size_t packet_size;
146 
147  /** RTCP statistics used in SR */
149 };
150 
151 
152 /** Initialize RTP receiver */
153 static APR_INLINE void rtp_receiver_init(rtp_receiver_t *receiver)
154 {
155  receiver->jb = NULL;
156 
157  mpf_rtcp_rr_stat_reset(&receiver->rr_stat);
158  mpf_rtp_rx_stat_reset(&receiver->stat);
159  mpf_rtp_rx_history_reset(&receiver->history);
160  mpf_rtp_rx_periodic_history_reset(&receiver->periodic_history);
161 }
162 
163 /** Initialize RTP transmitter */
164 static APR_INLINE void rtp_transmitter_init(rtp_transmitter_t *transmitter)
165 {
166  transmitter->ptime = 0;
167 
168  transmitter->packet_frames = 0;
169  transmitter->current_frames = 0;
170  transmitter->samples_per_frame = 0;
171 
172  transmitter->inactivity = 0;
173  transmitter->last_seq_num = 0;
174  transmitter->timestamp = 0;
175  transmitter->timestamp_base = 0;
176 
177  transmitter->packet_data = NULL;
178  transmitter->packet_size = 0;
179 
180  mpf_rtcp_sr_stat_reset(&transmitter->sr_stat);
181 }
182 
184 
185 #endif /* MPF_RTP_DEFS_H */