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 1474 2010-02-07 20:51:47Z 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 drift 00036 * in seq number or misorder packets */ 00037 #define MAX_DROPOUT 3000 00038 /** Number of max misorder packets (seq numbers) to differentiate 00039 * seq drift from misorder packets */ 00040 #define MAX_MISORDER 100 00041 /** Restart receiver if threshold is fired */ 00042 #define DISCARDED_TO_RECEIVED_RATIO_THRESHOLD 30 /* 30% */ 00043 /** Deviation threshold is used to trigger drift in timestamps */ 00044 #define DEVIATION_THRESHOLD 4000 00045 00046 /** RTP receiver history declaration */ 00047 typedef struct rtp_rx_history_t rtp_rx_history_t; 00048 /** RTP receiver periodic history declaration */ 00049 typedef struct rtp_rx_periodic_history_t rtp_rx_periodic_history_t; 00050 /** RTP receiver declaration */ 00051 typedef struct rtp_receiver_t rtp_receiver_t; 00052 /** RTP transmitter declaration */ 00053 typedef struct rtp_transmitter_t rtp_transmitter_t; 00054 00055 /** History of RTP receiver */ 00056 struct rtp_rx_history_t { 00057 /** Updated on every seq num wrap around */ 00058 apr_uint32_t seq_cycles; 00059 00060 /** First seq num received */ 00061 apr_uint16_t seq_num_base; 00062 /** Max seq num received */ 00063 apr_uint16_t seq_num_max; 00064 00065 /** Last timestamp received */ 00066 apr_uint32_t ts_last; 00067 /** Local time measured on last packet received */ 00068 apr_time_t time_last; 00069 00070 /** New ssrc, which is in probation */ 00071 apr_uint32_t ssrc_new; 00072 /** Period of ssrc probation */ 00073 apr_byte_t ssrc_probation; 00074 }; 00075 00076 /** Periodic history of RTP receiver (initialized after every N packets) */ 00077 struct rtp_rx_periodic_history_t { 00078 /** Number of packets received */ 00079 apr_uint32_t received_prior; 00080 /** Number of packets expected */ 00081 apr_uint32_t expected_prior; 00082 /** Number of packets discarded */ 00083 apr_uint32_t discarded_prior; 00084 00085 /** Min jitter */ 00086 apr_uint32_t jitter_min; 00087 /** Max jitter */ 00088 apr_uint32_t jitter_max; 00089 }; 00090 00091 /** Reset RTP receiver history */ 00092 static APR_INLINE void mpf_rtp_rx_history_reset(rtp_rx_history_t *rx_history) 00093 { 00094 memset(rx_history,0,sizeof(rtp_rx_history_t)); 00095 } 00096 00097 /** Reset RTP receiver periodic history */ 00098 static APR_INLINE void mpf_rtp_rx_periodic_history_reset(rtp_rx_periodic_history_t *rx_periodic_history) 00099 { 00100 memset(rx_periodic_history,0,sizeof(rtp_rx_periodic_history_t)); 00101 } 00102 00103 /** RTP receiver */ 00104 struct rtp_receiver_t { 00105 /** Jitter buffer */ 00106 mpf_jitter_buffer_t *jb; 00107 00108 /** RTCP statistics used in RR */ 00109 rtcp_rr_stat_t rr_stat; 00110 /** RTP receiver statistics */ 00111 rtp_rx_stat_t stat; 00112 /** RTP history */ 00113 rtp_rx_history_t history; 00114 /** RTP periodic history */ 00115 rtp_rx_periodic_history_t periodic_history; 00116 }; 00117 00118 00119 /** RTP transmitter */ 00120 struct rtp_transmitter_t { 00121 /** Packetization time in msec */ 00122 apr_uint16_t ptime; 00123 00124 /** Number of frames in a packet */ 00125 apr_uint16_t packet_frames; 00126 /** Current number of frames */ 00127 apr_uint16_t current_frames; 00128 /** Samples in frames in timestamp units */ 00129 apr_uint32_t samples_per_frame; 00130 00131 /** Indicate silence period among the talkspurts */ 00132 apr_byte_t inactivity; 00133 /** Last seq number sent */ 00134 apr_uint16_t last_seq_num; 00135 /** Current timestamp (samples processed) */ 00136 apr_uint32_t timestamp; 00137 /** Event timestamp base */ 00138 apr_uint32_t timestamp_base; 00139 00140 /** RTP packet payload */ 00141 char *packet_data; 00142 /** RTP packet payload size */ 00143 apr_size_t packet_size; 00144 00145 /** RTCP statistics used in SR */ 00146 rtcp_sr_stat_t sr_stat; 00147 }; 00148 00149 00150 /** Initialize RTP receiver */ 00151 static APR_INLINE void rtp_receiver_init(rtp_receiver_t *receiver) 00152 { 00153 receiver->jb = NULL; 00154 00155 mpf_rtcp_rr_stat_reset(&receiver->rr_stat); 00156 mpf_rtp_rx_stat_reset(&receiver->stat); 00157 mpf_rtp_rx_history_reset(&receiver->history); 00158 mpf_rtp_rx_periodic_history_reset(&receiver->periodic_history); 00159 } 00160 00161 /** Initialize RTP transmitter */ 00162 static APR_INLINE void rtp_transmitter_init(rtp_transmitter_t *transmitter) 00163 { 00164 transmitter->ptime = 0; 00165 00166 transmitter->packet_frames = 0; 00167 transmitter->current_frames = 0; 00168 transmitter->samples_per_frame = 0; 00169 00170 transmitter->inactivity = 0; 00171 transmitter->last_seq_num = 0; 00172 transmitter->timestamp = 0; 00173 transmitter->timestamp_base = 0; 00174 00175 transmitter->packet_data = NULL; 00176 transmitter->packet_size = 0; 00177 00178 mpf_rtcp_sr_stat_reset(&transmitter->sr_stat); 00179 } 00180 00181 APT_END_EXTERN_C 00182 00183 #endif /* MPF_RTP_DEFS_H */
1.6.2