FreeSWITCH API Documentation  1.7.0
switch_core_media.h
Go to the documentation of this file.
1 
2 /*
3  * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
4  * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
5  *
6  * Version: MPL 1.1
7  *
8  * The contents of this file are subject to the Mozilla Public License Version
9  * 1.1 (the "License"); you may not use this file except in compliance with
10  * the License. You may obtain a copy of the License at
11  * http://www.mozilla.org/MPL/
12  *
13  * Software distributed under the License is distributed on an "AS IS" basis,
14  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
15  * for the specific language governing rights and limitations under the
16  * License.
17  *
18  * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
19  *
20  * The Initial Developer of the Original Code is
21  * Anthony Minessale II <anthm@freeswitch.org>
22  * Portions created by the Initial Developer are Copyright (C)
23  * the Initial Developer. All Rights Reserved.
24  *
25  * Contributor(s):
26  *
27  * Anthony Minessale II <anthm@freeswitch.org>
28  *
29  * switch_core_media.c -- Core Media
30  *
31  */
32 
33 #ifndef SWITCH_CORE_MEDIA_H
34 #define SWITCH_CORE_MEDIA_H
35 
36 
37 #include <switch.h>
38 
40 
41 #define SWITCH_MAX_CAND_ACL 25
42 #define SWITCH_NO_CRYPTO_TAG -1
43 
44 typedef enum {
50 
51 typedef enum {
59 
60 typedef enum {
80 
82 
83 typedef enum {
84  STUN_FLAG_SET = (1 << 0),
85  STUN_FLAG_PING = (1 << 1),
86  STUN_FLAG_FUNNY = (1 << 2)
87 } STUNFLAGS;
88 
89 typedef enum {
90  VAD_IN = (1 << 0),
91  VAD_OUT = (1 << 1)
93 
95  uint32_t rtp_timeout_sec;
97  uint32_t dtmf_delay;
98  uint32_t codec_flags;
99 
102 
105 
106  char *timer_name;
107 
109  char *early_sdp;
115 
116  char *stun_ip;
118  uint32_t stun_flags;
119 
120  char *jb_msec;
121 
123 
126 
129 
130 
131  char *extrtpip;
132  char *rtpip;
133  char *rtpip4;
134  char *rtpip6;
135 
136 
137  char *remote_ip;
139 
140  char *extsipip;
142 
143  char *sipip;
144 
146 
149  unsigned long te_rate;
150  unsigned long cng_rate;
151 
153 
158 
159 
160  /* a core_video_thread will be started automatically
161  when uses rtp based media,
162  external_video_source should be set to SWITCH_TRUE and
163  switch_core_session_start_video_thread()
164  should be explicitly called to start the video thread
165  if uses the media handle for non-rtp based media
166  */
167 
169 
170  uint32_t video_key_freq;
171  uint32_t video_key_first;
172 
174 
176 
177 static inline const char *switch_media_type2str(switch_media_type_t type)
178 {
179  switch(type) {
181  return "audio";
183  return "video";
184  default:
185  return "!ERR";
186 
187  }
188 }
189 
190 
203  const char *varname,
204  switch_media_type_t type, const char *crypto, int crypto_tag, switch_sdp_type_t sdp_type);
205 
206 
209 
218 SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *session, const char *r_sdp, uint8_t *proceed, switch_sdp_type_t sdp_type);
220 SWITCH_DECLARE(switch_status_t) switch_core_media_set_codec(switch_core_session_t *session, int force, uint32_t codec_flags);
223  switch_io_flag_t flags, int stream_id, switch_media_type_t type);
225  switch_frame_t *frame, switch_io_flag_t flags, int stream_id, switch_media_type_t type);
226 SWITCH_DECLARE(int) switch_core_media_check_nat(switch_media_handle_t *smh, const char *network_ip);
227 
237  switch_core_session_t *other_session, switch_t38_options_t *t38_options);
239  const char *ip, switch_port_t port, const char *sr, int force);
248 
249 
250 
261 
266 
267 
284 
286  switch_media_type_t type,
287  const char *iananame,
288  uint32_t rate,
289  switch_payload_t *ptP,
290  switch_payload_t *recv_ptP,
291  char **fmtpP);
292 
294  switch_media_type_t type,
295  const char *name,
296  const char *modname,
297  const char *fmtp,
298  switch_sdp_type_t sdp_type,
299  uint32_t pt,
300  uint32_t rate,
301  uint32_t ptime,
302  uint32_t channels,
303  uint8_t negotiated);
304 
309 SWITCH_DECLARE(char *) switch_core_media_filter_sdp(const char *sdp, const char *cmd, const char *arg);
310 SWITCH_DECLARE(char *) switch_core_media_process_sdp_filter(const char *sdp, const char *cmd_buf, switch_core_session_t *session);
311 
312 
314  switch_media_type_t mtype,
315  switch_io_type_t iotype,
318  void *cmd_data,
320  void *cmd_arg,
322  void **ret_data);
323 
324 
325 #define switch_core_media_gen_key_frame(_session) switch_core_media_codec_control(_session, SWITCH_MEDIA_TYPE_VIDEO, SWITCH_IO_WRITE, \
326  SCC_VIDEO_GEN_KEYFRAME, SCCT_NONE, NULL, SCCT_NONE, NULL, NULL, NULL) \
327 
328 #define switch_core_media_write_bandwidth(_session, _val) switch_core_media_codec_control(_session, SWITCH_MEDIA_TYPE_VIDEO, SWITCH_IO_WRITE, \
329  SCC_VIDEO_BANDWIDTH, SCCT_STRING, _val, SCCT_NONE, NULL, NULL, NULL) \
330 
331 
339 
340 #define switch_core_media_read_lock(_s, _t) switch_core_media_read_lock_unlock(_s, _t, SWITCH_TRUE)
341 #define switch_core_media_read_unlock(_s, _t) switch_core_media_read_lock_unlock(_s, _t, SWITCH_FALSE)
342 
355 
357 #endif
358 /* For Emacs:
359  * Local Variables:
360  * mode:c
361  * indent-tabs-mode:t
362  * tab-width:4
363  * c-basic-offset:4
364  * End:
365  * For VIM:
366  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
367  */
368 
int32_t switch_media_handle_test_media_flag(switch_media_handle_t *smh, switch_core_media_flag_t flag)
switch_rtp_stats_t * switch_core_media_get_stats(switch_core_session_t *session, switch_media_type_t type, switch_memory_pool_t *pool)
void switch_core_session_check_outgoing_crypto(switch_core_session_t *session)
switch_status_t switch_core_media_choose_ports(switch_core_session_t *session, switch_bool_t audio, switch_bool_t video)
void switch_core_media_check_outgoing_proxy(switch_core_session_t *session, switch_core_session_t *o_session)
switch_rtp_crypto_key_type_t
void switch_media_handle_destroy(switch_core_session_t *session)
void(* switch_video_function_t)(switch_core_session_t *session, void *user_data)
void switch_core_session_set_ice(switch_core_session_t *session)
switch_status_t switch_core_media_set_video_codec(switch_core_session_t *session, int force)
uint32_t switch_io_flag_t
switch_status_t switch_core_media_proxy_remote_addr(switch_core_session_t *session, const char *sdp_str)
switch_core_media_params_t * switch_core_media_get_mparams(switch_media_handle_t *smh)
void switch_core_media_set_local_sdp(switch_core_session_t *session, const char *sdp_str, switch_bool_t dup)
struct switch_core_media_params_s switch_core_media_params_t
switch_core_media_vflag_t
#define SWITCH_END_EXTERN_C
Definition: switch.h:43
switch_rtp_crypto_key_type_t switch_core_media_crypto_str2type(const char *str)
switch_bool_t
Definition: switch_types.h:405
void switch_core_media_gen_local_sdp(switch_core_session_t *session, switch_sdp_type_t sdp_type, const char *ip, switch_port_t port, const char *sr, int force)
switch_memory_pool_t * pool
void switch_core_media_pass_zrtp_hash(switch_core_session_t *session)
switch_status_t switch_core_media_set_video_file(switch_core_session_t *session, switch_file_handle_t *fh, switch_rw_t rw)
uint8_t switch_core_media_ready(switch_core_session_t *session, switch_media_type_t type)
switch_core_media_vflag_t vflags
void switch_core_media_set_udptl_image_sdp(switch_core_session_t *session, switch_t38_options_t *t38_options, int insist)
void switch_core_media_prepare_codecs(switch_core_session_t *session, switch_bool_t force)
switch_status_t switch_core_media_queue_rfc2833_in(switch_core_session_t *session, switch_media_type_t type, const switch_dtmf_t *dtmf)
void switch_core_media_resume(switch_core_session_t *session)
int switch_core_media_crypto_keylen(switch_rtp_crypto_key_type_t type)
void switch_core_media_pause(switch_core_session_t *session)
void switch_core_media_reset_autofix(switch_core_session_t *session, switch_media_type_t type)
Abstract handler to a timer module.
switch_bool_t switch_core_media_check_dtls(switch_core_session_t *session, switch_media_type_t type)
void switch_core_media_deactivate_rtp(switch_core_session_t *session)
switch_status_t switch_core_media_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id, switch_media_type_t type)
A message object designed to allow unlike technologies to exchange data.
Definition: switch_core.h:177
switch_rtp_bug_flag_t manual_video_rtp_bugs
void switch_core_media_end_video_function(switch_core_session_t *session)
uint32_t switch_core_media_get_video_fps(switch_core_session_t *session)
void switch_core_session_clear_crypto(switch_core_session_t *session)
void switch_core_media_deinit(void)
switch_status_t switch_media_handle_create(switch_media_handle_t **smhp, switch_core_session_t *session, switch_core_media_params_t *params)
switch_codec_control_command_t
switch_status_t switch_core_media_check_autoadj(switch_core_session_t *session)
void switch_media_handle_set_media_flags(switch_media_handle_t *smh, switch_core_media_flag_t flags[])
void switch_core_media_set_rtp_session(switch_core_session_t *session, switch_media_type_t type, switch_rtp_t *rtp_session)
switch_rw_t
Definition: switch_types.h:565
switch_codec_control_type_t
static const char * switch_media_type2str(switch_media_type_t type)
int switch_core_media_check_nat(switch_media_handle_t *smh, const char *network_ip)
const char * switch_core_media_get_zrtp_hash(switch_core_session_t *session, switch_media_type_t type, switch_bool_t local)
switch_status_t switch_core_media_udptl_mode(switch_core_session_t *session, switch_media_type_t type)
const char * switch_core_media_get_codec_string(switch_core_session_t *session)
int switch_core_media_check_video_function(switch_core_session_t *session)
void switch_core_media_clear_rtp_flag(switch_core_session_t *session, switch_media_type_t type, switch_rtp_flag_t flag)
void switch_core_media_pass_zrtp_hash2(switch_core_session_t *aleg_session, switch_core_session_t *bleg_session)
switch_timer_t * switch_core_media_get_timer(switch_core_session_t *session, switch_media_type_t mtype)
switch_file_handle_t * switch_core_media_get_video_file(switch_core_session_t *session, switch_rw_t rw)
char * switch_core_media_process_sdp_filter(const char *sdp, const char *cmd_buf, switch_core_session_t *session)
switch_rtp_bug_flag_t
Definition: switch_types.h:771
void switch_core_media_sync_stats(switch_core_session_t *session)
void switch_core_media_set_telephony_event(switch_core_session_t *session, switch_media_type_t type, switch_payload_t te)
switch_status_t switch_core_media_codec_chosen(switch_core_session_t *session, switch_media_type_t media)
int switch_core_media_toggle_hold(switch_core_session_t *session, int sendonly)
switch_bool_t switch_core_session_in_video_thread(switch_core_session_t *session)
switch_media_handle_t * switch_core_session_get_media_handle(switch_core_session_t *session)
switch_t38_options_t * switch_core_media_extract_t38_options(switch_core_session_t *session, const char *r_sdp)
switch_core_media_dtmf_t dtmf_type
void switch_core_media_break(switch_core_session_t *session, switch_media_type_t type)
switch_core_media_flag_t
switch_status_t switch_core_media_process_t38_passthru(switch_core_session_t *session, switch_core_session_t *other_session, switch_t38_options_t *t38_options)
switch_status_t switch_core_media_add_ice_acl(switch_core_session_t *session, switch_media_type_t type, const char *acl_name)
An abstraction of a data frame.
Definition: switch_frame.h:43
void switch_core_media_absorb_sdp(switch_core_session_t *session)
switch_sdp_type_t
uint16_t switch_port_t
uint8_t switch_core_media_negotiate_sdp(switch_core_session_t *session, const char *r_sdp, uint8_t *proceed, switch_sdp_type_t sdp_type)
payload_map_t * switch_core_media_add_payload_map(switch_core_session_t *session, switch_media_type_t type, const char *name, const char *modname, const char *fmtp, switch_sdp_type_t sdp_type, uint32_t pt, uint32_t rate, uint32_t ptime, uint32_t channels, uint8_t negotiated)
void switch_core_media_hard_mute(switch_core_session_t *session, switch_bool_t on)
switch_status_t switch_core_media_ext_address_lookup(switch_core_session_t *session, char **ip, switch_port_t *port, const char *sourceip)
switch_bool_t switch_core_media_check_udptl_mode(switch_core_session_t *session, switch_media_type_t type)
void switch_core_media_kill_socket(switch_core_session_t *session, switch_media_type_t type)
void switch_core_media_start_udptl(switch_core_session_t *session, switch_t38_options_t *t38_options)
switch_status_t switch_core_session_media_handle_ready(switch_core_session_t *session)
switch_status_t switch_core_session_wait_for_video_input_params(switch_core_session_t *session, uint32_t timeout_ms)
const char * switch_core_media_crypto_type2str(switch_rtp_crypto_key_type_t type)
switch_thread_t * video_write_thread
switch_status_t switch_core_media_codec_control(switch_core_session_t *session, switch_media_type_t mtype, switch_io_type_t iotype, switch_codec_control_command_t cmd, switch_codec_control_type_t ctype, void *cmd_data, switch_codec_control_type_t atype, void *cmd_arg, switch_codec_control_type_t *rtype, void **ret_data)
switch_status_t switch_core_media_activate_rtp(switch_core_session_t *session)
switch_rtp_bug_flag_t manual_rtp_bugs
void switch_core_media_set_stats(switch_core_session_t *session)
void switch_core_media_copy_t38_options(switch_t38_options_t *t38_options, switch_core_session_t *session)
switch_media_flow_t switch_core_session_media_flow(switch_core_session_t *session, switch_media_type_t type)
switch_status_t switch_core_media_get_vid_params(switch_core_session_t *session, switch_vid_params_t *vid_params)
switch_status_t switch_core_media_reset_jb(switch_core_session_t *session, switch_media_type_t type)
switch_status_t switch_core_media_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg)
void switch_core_media_clear_ice(switch_core_session_t *session)
STUNFLAGS
switch_status_t switch_core_media_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id, switch_media_type_t type)
switch_status_t
Common return values.
void switch_core_session_wake_video_thread(switch_core_session_t *session)
void switch_core_media_set_rtp_flag(switch_core_session_t *session, switch_media_type_t type, switch_rtp_flag_t flag)
char * switch_core_media_filter_sdp(const char *sdp, const char *cmd, const char *arg)
switch_status_t switch_core_session_start_video_thread(switch_core_session_t *session)
struct apr_thread_t switch_thread_t
Definition: switch_apr.h:941
switch_rtp_flag_t
RTP Related Flags.
Definition: switch_types.h:723
Main Library Header.
void switch_core_session_video_reinit(switch_core_session_t *session)
switch_status_t switch_core_media_queue_rfc2833(switch_core_session_t *session, switch_media_type_t type, const switch_dtmf_t *dtmf)
#define SWITCH_DECLARE(type)
void switch_core_media_start_video_function(switch_core_session_t *session, switch_video_function_t video_function, void *user_data)
void switch_core_session_stop_media(switch_core_session_t *session)
switch_status_t switch_core_media_unlock_video_file(switch_core_session_t *session, switch_rw_t rw)
switch_status_t switch_core_media_set_codec(switch_core_session_t *session, int force, uint32_t codec_flags)
switch_rtp_bug_flag_t auto_rtp_bugs
switch_status_t switch_core_session_clear_media_handle(switch_core_session_t *session)
void switch_core_media_parse_rtp_bugs(switch_rtp_bug_flag_t *flag_pole, const char *str)
switch_core_media_NDLB_t ndlb
switch_media_flow_t
struct apr_pool_t switch_memory_pool_t
switch_status_t switch_core_media_set_outgoing_bitrate(switch_core_session_t *session, switch_media_type_t type, uint32_t bitrate)
switch_status_t switch_core_media_read_lock_unlock(switch_core_session_t *session, switch_media_type_t type, switch_bool_t lock)
switch_status_t switch_core_media_lock_video_file(switch_core_session_t *session, switch_rw_t rw)
switch_status_t switch_core_media_choose_port(switch_core_session_t *session, switch_media_type_t type, int force)
const char * switch_core_session_local_crypto_key(switch_core_session_t *session, switch_media_type_t type)
switch_rtp_stats_t * switch_core_media_stats(switch_core_session_t *session, switch_media_type_t type, switch_memory_pool_t *pool)
switch_io_type_t
void switch_core_media_set_sdp_codec_string(switch_core_session_t *session, const char *r_sdp, switch_sdp_type_t sdp_type)
void switch_media_handle_clear_media_flag(switch_media_handle_t *smh, switch_core_media_flag_t flag)
void switch_core_media_init(void)
switch_status_t switch_core_session_get_payload_code(switch_core_session_t *session, switch_media_type_t type, const char *iananame, uint32_t rate, switch_payload_t *ptP, switch_payload_t *recv_ptP, char **fmtpP)
void switch_core_media_check_video_codecs(switch_core_session_t *session)
void switch_core_media_check_dtmf_type(switch_core_session_t *session)
void switch_core_media_recover_session(switch_core_session_t *session)
switch_jb_t * switch_core_media_get_jb(switch_core_session_t *session, switch_media_type_t type)
void switch_core_media_patch_sdp(switch_core_session_t *session)
switch_core_media_NDLB_t
void switch_core_media_set_telephony_recv_event(switch_core_session_t *session, switch_media_type_t type, switch_payload_t te)
switch_core_media_dtmf_t
uint8_t switch_payload_t
int switch_core_session_check_incoming_crypto(switch_core_session_t *session, const char *varname, switch_media_type_t type, const char *crypto, int crypto_tag, switch_sdp_type_t sdp_type)
#define SWITCH_BEGIN_EXTERN_C
Definition: switch.h:42
switch_media_type_t
void switch_media_handle_set_media_flag(switch_media_handle_t *smh, switch_core_media_flag_t flag)