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_descriptor.h 1841 2012-02-07 20:53:17Z achaloyan $ 00017 */ 00018 00019 #ifndef MPF_RTP_DESCRIPTOR_H 00020 #define MPF_RTP_DESCRIPTOR_H 00021 00022 /** 00023 * @file mpf_rtp_descriptor.h 00024 * @brief MPF RTP Stream Descriptor 00025 */ 00026 00027 #include <apr_network_io.h> 00028 #include "apt_string.h" 00029 #include "mpf_stream_descriptor.h" 00030 00031 APT_BEGIN_EXTERN_C 00032 00033 /** RTP media descriptor declaration */ 00034 typedef struct mpf_rtp_media_descriptor_t mpf_rtp_media_descriptor_t; 00035 /** RTP stream descriptor declaration */ 00036 typedef struct mpf_rtp_stream_descriptor_t mpf_rtp_stream_descriptor_t; 00037 /** RTP termination descriptor declaration */ 00038 typedef struct mpf_rtp_termination_descriptor_t mpf_rtp_termination_descriptor_t; 00039 /** RTP configuration declaration */ 00040 typedef struct mpf_rtp_config_t mpf_rtp_config_t; 00041 /** RTP settings declaration */ 00042 typedef struct mpf_rtp_settings_t mpf_rtp_settings_t; 00043 /** Jitter buffer configuration declaration */ 00044 typedef struct mpf_jb_config_t mpf_jb_config_t; 00045 00046 /** MPF media state */ 00047 typedef enum { 00048 MPF_MEDIA_DISABLED, /**< disabled media */ 00049 MPF_MEDIA_ENABLED /**< enabled media */ 00050 } mpf_media_state_e; 00051 00052 /** RTP media (local/remote) descriptor */ 00053 struct mpf_rtp_media_descriptor_t { 00054 /** Media state (disabled/enabled)*/ 00055 mpf_media_state_e state; 00056 /** Ip address */ 00057 apt_str_t ip; 00058 /** External (NAT) Ip address */ 00059 apt_str_t ext_ip; 00060 /** Port */ 00061 apr_port_t port; 00062 /** Stream mode (send/receive) */ 00063 mpf_stream_direction_e direction; 00064 /** Packetization time */ 00065 apr_uint16_t ptime; 00066 /** Codec list */ 00067 mpf_codec_list_t codec_list; 00068 /** Media identifier */ 00069 apr_size_t mid; 00070 /** Position, order in SDP message (0,1,...) */ 00071 apr_size_t id; 00072 }; 00073 00074 /** RTP stream descriptor */ 00075 struct mpf_rtp_stream_descriptor_t { 00076 /** Stream capabilities */ 00077 mpf_stream_capabilities_t *capabilities; 00078 /** Local media descriptor */ 00079 mpf_rtp_media_descriptor_t *local; 00080 /** Remote media descriptor */ 00081 mpf_rtp_media_descriptor_t *remote; 00082 /** Settings loaded from config */ 00083 mpf_rtp_settings_t *settings; 00084 }; 00085 00086 /** RTP termination descriptor */ 00087 struct mpf_rtp_termination_descriptor_t { 00088 /** Audio stream descriptor */ 00089 mpf_rtp_stream_descriptor_t audio; 00090 /** Video stream descriptor */ 00091 mpf_rtp_stream_descriptor_t video; 00092 }; 00093 00094 /** Jitter buffer configuration */ 00095 struct mpf_jb_config_t { 00096 /** Min playout delay in msec */ 00097 apr_uint32_t min_playout_delay; 00098 /** Initial playout delay in msec */ 00099 apr_uint32_t initial_playout_delay; 00100 /** Max playout delay in msec */ 00101 apr_uint32_t max_playout_delay; 00102 /** Mode of operation of the jitter buffer: static - 0, adaptive - 1 */ 00103 apr_byte_t adaptive; 00104 /** Enable/disable time skew detection */ 00105 apr_byte_t time_skew_detection; 00106 }; 00107 00108 /** RTCP BYE transmission policy */ 00109 typedef enum { 00110 RTCP_BYE_DISABLE, /**< disable RTCP BYE transmission */ 00111 RTCP_BYE_PER_SESSION, /**< transmit RTCP BYE at the end of session */ 00112 RTCP_BYE_PER_TALKSPURT /**< transmit RTCP BYE at the end of each talkspurt (input) */ 00113 } rtcp_bye_policy_e; 00114 00115 /** RTP factory config */ 00116 struct mpf_rtp_config_t { 00117 /** Local IP address to bind to */ 00118 apt_str_t ip; 00119 /** External (NAT) IP address */ 00120 apt_str_t ext_ip; 00121 /** Min RTP port */ 00122 apr_port_t rtp_port_min; 00123 /** Max RTP port */ 00124 apr_port_t rtp_port_max; 00125 /** Current RTP port */ 00126 apr_port_t rtp_port_cur; 00127 }; 00128 00129 /** RTP settings */ 00130 struct mpf_rtp_settings_t { 00131 /** Packetization time */ 00132 apr_uint16_t ptime; 00133 /** Codec list */ 00134 mpf_codec_list_t codec_list; 00135 /** Preference in offer/anwser: 1 - own(local) preference, 0 - remote preference */ 00136 apt_bool_t own_preferrence; 00137 /** Enable/disable RTCP support */ 00138 apt_bool_t rtcp; 00139 /** RTCP BYE policy */ 00140 rtcp_bye_policy_e rtcp_bye_policy; 00141 /** RTCP report transmission interval */ 00142 apr_uint16_t rtcp_tx_interval; 00143 /** RTCP rx resolution (timeout to check for a new RTCP message) */ 00144 apr_uint16_t rtcp_rx_resolution; 00145 /** Jitter buffer config */ 00146 mpf_jb_config_t jb_config; 00147 }; 00148 00149 /** Initialize media descriptor */ 00150 static APR_INLINE void mpf_rtp_media_descriptor_init(mpf_rtp_media_descriptor_t *media) 00151 { 00152 media->state = MPF_MEDIA_DISABLED; 00153 apt_string_reset(&media->ip); 00154 apt_string_reset(&media->ext_ip); 00155 media->port = 0; 00156 media->direction = STREAM_DIRECTION_NONE; 00157 media->ptime = 0; 00158 mpf_codec_list_reset(&media->codec_list); 00159 media->mid = 0; 00160 media->id = 0; 00161 } 00162 00163 /** Initialize stream descriptor */ 00164 static APR_INLINE void mpf_rtp_stream_descriptor_init(mpf_rtp_stream_descriptor_t *descriptor) 00165 { 00166 descriptor->capabilities = NULL; 00167 descriptor->local = NULL; 00168 descriptor->remote = NULL; 00169 descriptor->settings = NULL; 00170 } 00171 00172 /** Initialize RTP termination descriptor */ 00173 static APR_INLINE void mpf_rtp_termination_descriptor_init(mpf_rtp_termination_descriptor_t *rtp_descriptor) 00174 { 00175 mpf_rtp_stream_descriptor_init(&rtp_descriptor->audio); 00176 mpf_rtp_stream_descriptor_init(&rtp_descriptor->video); 00177 } 00178 00179 /** Initialize JB config */ 00180 static APR_INLINE void mpf_jb_config_init(mpf_jb_config_t *jb_config) 00181 { 00182 jb_config->adaptive = 0; 00183 jb_config->initial_playout_delay = 0; 00184 jb_config->min_playout_delay = 0; 00185 jb_config->max_playout_delay = 0; 00186 jb_config->time_skew_detection = 1; 00187 } 00188 00189 /** Allocate RTP config */ 00190 static APR_INLINE mpf_rtp_config_t* mpf_rtp_config_alloc(apr_pool_t *pool) 00191 { 00192 mpf_rtp_config_t *rtp_config = (mpf_rtp_config_t*)apr_palloc(pool,sizeof(mpf_rtp_config_t)); 00193 apt_string_reset(&rtp_config->ip); 00194 apt_string_reset(&rtp_config->ext_ip); 00195 rtp_config->rtp_port_cur = 0; 00196 rtp_config->rtp_port_min = 0; 00197 rtp_config->rtp_port_max = 0; 00198 return rtp_config; 00199 } 00200 00201 /** Allocate RTP settings */ 00202 static APR_INLINE mpf_rtp_settings_t* mpf_rtp_settings_alloc(apr_pool_t *pool) 00203 { 00204 mpf_rtp_settings_t *rtp_settings = (mpf_rtp_settings_t*)apr_palloc(pool,sizeof(mpf_rtp_settings_t)); 00205 rtp_settings->ptime = 0; 00206 mpf_codec_list_init(&rtp_settings->codec_list,0,pool); 00207 rtp_settings->own_preferrence = FALSE; 00208 rtp_settings->rtcp = FALSE; 00209 rtp_settings->rtcp_bye_policy = RTCP_BYE_DISABLE; 00210 rtp_settings->rtcp_tx_interval = 0; 00211 rtp_settings->rtcp_rx_resolution = 0; 00212 mpf_jb_config_init(&rtp_settings->jb_config); 00213 return rtp_settings; 00214 } 00215 00216 00217 APT_END_EXTERN_C 00218 00219 #endif /* MPF_RTP_DESCRIPTOR_H */