00001 /* 00002 * Copyright 2008-2010 Arsen Chaloyan 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 * 00016 * $Id: mpf_rtp_defs.h 1833 2012-02-03 19:52:05Z achaloyan $ 00017 */ 00018 00019 #ifndef MPF_RTP_DEFS_H 00020 #define MPF_RTP_DEFS_H 00021 00022 /** 00023 * @file mpf_rtp_defs.h 00024 * @brief Internal RTP Definitions 00025 */ 00026 00027 #include "mpf_rtp_stat.h" 00028 #include "mpf_jitter_buffer.h" 00029 00030 APT_BEGIN_EXTERN_C 00031 00032 /** Used to calculate actual number of received packets (32bit) in 00033 * case seq number (16bit) wrapped around */ 00034 #define RTP_SEQ_MOD (1 << 16) 00035 /** Number of max dropout packets (seq numbers) is used to trigger 00036 * either a drift in the seq numbers or a misorder packet */ 00037 #define MAX_DROPOUT 3000 00038 /** Number of max misorder packets (seq numbers) is used to 00039 * differentiate a drift in the seq numbers from a misorder packet */ 00040 #define MAX_MISORDER 100 00041 /** Restart receiver if threshold is reached */ 00042 #define DISCARDED_TO_RECEIVED_RATIO_THRESHOLD 30 /* 30% */ 00043 /** Deviation threshold is used to trigger a drift in timestamps */ 00044 #define DEVIATION_THRESHOLD 4000 00045 /** This threshold is used to detect a new talkspurt */ 00046 #define INTER_TALKSPURT_GAP 1000 /* msec */ 00047 00048 /** RTP receiver history declaration */ 00049 typedef struct rtp_rx_history_t rtp_rx_history_t; 00050 /** RTP receiver periodic history declaration */ 00051 typedef struct rtp_rx_periodic_history_t rtp_rx_periodic_history_t; 00052 /** RTP receiver declaration */ 00053 typedef struct rtp_receiver_t rtp_receiver_t; 00054 /** RTP transmitter declaration */ 00055 typedef struct rtp_transmitter_t rtp_transmitter_t; 00056 00057 /** History of RTP receiver */ 00058 struct rtp_rx_history_t { 00059 /** Updated on every seq num wrap around */ 00060 apr_uint32_t seq_cycles; 00061 00062 /** First seq num received */ 00063 apr_uint16_t seq_num_base; 00064 /** Max seq num received */ 00065 apr_uint16_t seq_num_max; 00066 00067 /** Last timestamp received */ 00068 apr_uint32_t ts_last; 00069 /** Local time measured on last packet received */ 00070 apr_time_t time_last; 00071 00072 /** New ssrc, which is in probation */ 00073 apr_uint32_t ssrc_new; 00074 /** Period of ssrc probation */ 00075 apr_byte_t ssrc_probation; 00076 }; 00077 00078 /** Periodic history of RTP receiver (initialized after every N packets) */ 00079 struct rtp_rx_periodic_history_t { 00080 /** Number of packets received */ 00081 apr_uint32_t received_prior; 00082 /** Number of packets expected */ 00083 apr_uint32_t expected_prior; 00084 /** Number of packets discarded */ 00085 apr_uint32_t discarded_prior; 00086 00087 /** Min jitter */ 00088 apr_uint32_t jitter_min; 00089 /** Max jitter */ 00090 apr_uint32_t jitter_max; 00091 }; 00092 00093 /** Reset RTP receiver history */ 00094 static APR_INLINE void mpf_rtp_rx_history_reset(rtp_rx_history_t *rx_history) 00095 { 00096 memset(rx_history,0,sizeof(rtp_rx_history_t)); 00097 } 00098 00099 /** Reset RTP receiver periodic history */ 00100 static APR_INLINE void mpf_rtp_rx_periodic_history_reset(rtp_rx_periodic_history_t *rx_periodic_history) 00101 { 00102 memset(rx_periodic_history,0,sizeof(rtp_rx_periodic_history_t)); 00103 } 00104 00105 /** RTP receiver */ 00106 struct rtp_receiver_t { 00107 /** Jitter buffer */ 00108 mpf_jitter_buffer_t *jb; 00109 00110 /** RTCP statistics used in RR */ 00111 rtcp_rr_stat_t rr_stat; 00112 /** RTP receiver statistics */ 00113 rtp_rx_stat_t stat; 00114 /** RTP history */ 00115 rtp_rx_history_t history; 00116 /** RTP periodic history */ 00117 rtp_rx_periodic_history_t periodic_history; 00118 }; 00119 00120 00121 /** RTP transmitter */ 00122 struct rtp_transmitter_t { 00123 /** Packetization time in msec */ 00124 apr_uint16_t ptime; 00125 00126 /** Number of frames in a packet */ 00127 apr_uint16_t packet_frames; 00128 /** Current number of frames */ 00129 apr_uint16_t current_frames; 00130 /** Samples in frames in timestamp units */ 00131 apr_uint32_t samples_per_frame; 00132 00133 /** Indicate silence period among the talkspurts */ 00134 apr_byte_t inactivity; 00135 /** Last seq number sent */ 00136 apr_uint16_t last_seq_num; 00137 /** Current timestamp (samples processed) */ 00138 apr_uint32_t timestamp; 00139 /** Event timestamp base */ 00140 apr_uint32_t timestamp_base; 00141 00142 /** RTP packet payload */ 00143 char *packet_data; 00144 /** RTP packet payload size */ 00145 apr_size_t packet_size; 00146 00147 /** RTCP statistics used in SR */ 00148 rtcp_sr_stat_t sr_stat; 00149 }; 00150 00151 00152 /** Initialize RTP receiver */ 00153 static APR_INLINE void rtp_receiver_init(rtp_receiver_t *receiver) 00154 { 00155 receiver->jb = NULL; 00156 00157 mpf_rtcp_rr_stat_reset(&receiver->rr_stat); 00158 mpf_rtp_rx_stat_reset(&receiver->stat); 00159 mpf_rtp_rx_history_reset(&receiver->history); 00160 mpf_rtp_rx_periodic_history_reset(&receiver->periodic_history); 00161 } 00162 00163 /** Initialize RTP transmitter */ 00164 static APR_INLINE void rtp_transmitter_init(rtp_transmitter_t *transmitter) 00165 { 00166 transmitter->ptime = 0; 00167 00168 transmitter->packet_frames = 0; 00169 transmitter->current_frames = 0; 00170 transmitter->samples_per_frame = 0; 00171 00172 transmitter->inactivity = 0; 00173 transmitter->last_seq_num = 0; 00174 transmitter->timestamp = 0; 00175 transmitter->timestamp_base = 0; 00176 00177 transmitter->packet_data = NULL; 00178 transmitter->packet_size = 0; 00179 00180 mpf_rtcp_sr_stat_reset(&transmitter->sr_stat); 00181 } 00182 00183 APT_END_EXTERN_C 00184 00185 #endif /* MPF_RTP_DEFS_H */