UniMRCP  1.7.0
mpf_rtp_defs.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2015 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 
17 #ifndef MPF_RTP_DEFS_H
18 #define MPF_RTP_DEFS_H
19 
20 /**
21  * @file mpf_rtp_defs.h
22  * @brief Internal RTP Definitions
23  */
24 
25 #include "mpf_rtp_stat.h"
26 #include "mpf_jitter_buffer.h"
27 
29 
30 /** Used to calculate actual number of received packets (32bit) in
31  * case seq number (16bit) wrapped around */
32 #define RTP_SEQ_MOD (1 << 16)
33 /** Number of max dropout packets (seq numbers) is used to trigger
34  * either a drift in the seq numbers or a misorder packet */
35 #define MAX_DROPOUT 3000
36 /** Number of max misorder packets (seq numbers) is used to
37  * differentiate a drift in the seq numbers from a misorder packet */
38 #define MAX_MISORDER 100
39 /** Restart receiver if threshold is reached */
40 #define DISCARDED_TO_RECEIVED_RATIO_THRESHOLD 30 /* 30% */
41 /** Deviation threshold is used to trigger a drift in timestamps */
42 #define DEVIATION_THRESHOLD 4000
43 /** This threshold is used to detect a new talkspurt */
44 #define INTER_TALKSPURT_GAP 1000 /* msec */
45 
46 /** RTP receiver history declaration */
48 /** RTP receiver periodic history declaration */
50 /** RTP receiver declaration */
52 /** RTP transmitter declaration */
54 
55 /** History of RTP receiver */
57  /** Updated on every seq num wrap around */
58  apr_uint32_t seq_cycles;
59 
60  /** First seq num received */
61  apr_uint16_t seq_num_base;
62  /** Max seq num received */
63  apr_uint16_t seq_num_max;
64 
65  /** Last timestamp received */
66  apr_uint32_t ts_last;
67  /** Local time measured on last packet received */
68  apr_time_t time_last;
69 
70  /** New ssrc, which is in probation */
71  apr_uint32_t ssrc_new;
72  /** Period of ssrc probation */
73  apr_byte_t ssrc_probation;
74 };
75 
76 /** Periodic history of RTP receiver (initialized after every N packets) */
78  /** Number of packets received */
79  apr_uint32_t received_prior;
80  /** Number of packets expected */
81  apr_uint32_t expected_prior;
82  /** Number of packets discarded */
83  apr_uint32_t discarded_prior;
84 
85  /** Min jitter */
86  apr_uint32_t jitter_min;
87  /** Max jitter */
88  apr_uint32_t jitter_max;
89 };
90 
91 /** Reset RTP receiver history */
92 static APR_INLINE void mpf_rtp_rx_history_reset(rtp_rx_history_t *rx_history)
93 {
94  memset(rx_history,0,sizeof(rtp_rx_history_t));
95 }
96 
97 /** Reset RTP receiver periodic history */
98 static APR_INLINE void mpf_rtp_rx_periodic_history_reset(rtp_rx_periodic_history_t *rx_periodic_history)
99 {
100  memset(rx_periodic_history,0,sizeof(rtp_rx_periodic_history_t));
101 }
102 
103 /** RTP receiver */
105  /** Jitter buffer */
107 
108  /** RTCP statistics used in RR */
110  /** RTP receiver statistics */
112  /** RTP history */
114  /** RTP periodic history */
116 };
117 
118 
119 /** RTP transmitter */
121  /** Packetization time in msec */
122  apr_uint16_t ptime;
123 
124  /** Number of frames in a packet */
125  apr_uint16_t packet_frames;
126  /** Current number of frames */
127  apr_uint16_t current_frames;
128  /** Samples in frames in timestamp units */
129  apr_uint32_t samples_per_frame;
130 
131  /** Indicate silence period among the talkspurts */
132  apr_byte_t inactivity;
133  /** Last seq number sent */
134  apr_uint16_t last_seq_num;
135  /** Current timestamp (samples processed) */
136  apr_uint32_t timestamp;
137  /** Event timestamp base */
138  apr_uint32_t timestamp_base;
139 
140  /** RTP packet payload */
141  char *packet_data;
142  /** RTP packet payload size */
143  apr_size_t packet_size;
144 
145  /** RTCP statistics used in SR */
147 };
148 
149 
150 /** Initialize RTP receiver */
151 static APR_INLINE void rtp_receiver_init(rtp_receiver_t *receiver)
152 {
153  receiver->jb = NULL;
154 
155  mpf_rtcp_rr_stat_reset(&receiver->rr_stat);
156  mpf_rtp_rx_stat_reset(&receiver->stat);
157  mpf_rtp_rx_history_reset(&receiver->history);
158  mpf_rtp_rx_periodic_history_reset(&receiver->periodic_history);
159 }
160 
161 /** Initialize RTP transmitter */
162 static APR_INLINE void rtp_transmitter_init(rtp_transmitter_t *transmitter)
163 {
164  transmitter->ptime = 0;
165 
166  transmitter->packet_frames = 0;
167  transmitter->current_frames = 0;
168  transmitter->samples_per_frame = 0;
169 
170  transmitter->inactivity = 0;
171  transmitter->last_seq_num = 0;
172  transmitter->timestamp = 0;
173  transmitter->timestamp_base = 0;
174 
175  transmitter->packet_data = NULL;
176  transmitter->packet_size = 0;
177 
178  mpf_rtcp_sr_stat_reset(&transmitter->sr_stat);
179 }
180 
182 
183 #endif /* MPF_RTP_DEFS_H */
apr_uint16_t seq_num_max
Definition: mpf_rtp_defs.h:63
Definition: mpf_rtp_stat.h:58
apr_uint32_t ssrc_new
Definition: mpf_rtp_defs.h:71
apr_uint16_t packet_frames
Definition: mpf_rtp_defs.h:125
rtcp_sr_stat_t sr_stat
Definition: mpf_rtp_defs.h:146
apr_time_t time_last
Definition: mpf_rtp_defs.h:68
apr_uint16_t ptime
Definition: mpf_rtp_defs.h:122
#define APT_END_EXTERN_C
Definition: apt.h:38
apr_uint32_t ts_last
Definition: mpf_rtp_defs.h:66
apr_uint32_t seq_cycles
Definition: mpf_rtp_defs.h:58
Definition: mpf_rtp_defs.h:56
mpf_jitter_buffer_t * jb
Definition: mpf_rtp_defs.h:106
Definition: mpf_rtp_defs.h:104
apr_uint32_t discarded_prior
Definition: mpf_rtp_defs.h:83
apr_byte_t ssrc_probation
Definition: mpf_rtp_defs.h:73
apr_uint32_t timestamp_base
Definition: mpf_rtp_defs.h:138
apr_size_t packet_size
Definition: mpf_rtp_defs.h:143
#define APT_BEGIN_EXTERN_C
Definition: apt.h:36
apr_uint32_t samples_per_frame
Definition: mpf_rtp_defs.h:129
apr_uint16_t last_seq_num
Definition: mpf_rtp_defs.h:134
apr_uint32_t jitter_max
Definition: mpf_rtp_defs.h:88
apr_uint32_t jitter_min
Definition: mpf_rtp_defs.h:86
apr_byte_t inactivity
Definition: mpf_rtp_defs.h:132
rtp_rx_history_t history
Definition: mpf_rtp_defs.h:113
apr_uint32_t received_prior
Definition: mpf_rtp_defs.h:79
struct mpf_jitter_buffer_t mpf_jitter_buffer_t
Definition: mpf_jitter_buffer.h:40
Definition: mpf_rtp_stat.h:39
rtp_rx_periodic_history_t periodic_history
Definition: mpf_rtp_defs.h:115
apr_uint32_t expected_prior
Definition: mpf_rtp_defs.h:81
RTP/RTCP Statistics.
Definition: mpf_rtp_stat.h:74
rtcp_rr_stat_t rr_stat
Definition: mpf_rtp_defs.h:109
Definition: mpf_rtp_defs.h:77
Definition: mpf_rtp_defs.h:120
apr_uint32_t timestamp
Definition: mpf_rtp_defs.h:136
apr_uint16_t current_frames
Definition: mpf_rtp_defs.h:127
rtp_rx_stat_t stat
Definition: mpf_rtp_defs.h:111
Jitter Buffer.
char * packet_data
Definition: mpf_rtp_defs.h:141
apr_uint16_t seq_num_base
Definition: mpf_rtp_defs.h:61