RTS API Documentation  1.10.11
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 #include <switch_msrp.h>
39 
41 
42 #define SWITCH_MAX_CAND_ACL 25
43 #define SWITCH_NO_CRYPTO_TAG -1
44 
45 typedef enum {
51 
52 typedef enum {
57 
58 typedef enum {
66 
67 typedef enum {
85 
87 
88 typedef enum {
89  STUN_FLAG_SET = (1 << 0),
90  STUN_FLAG_PING = (1 << 1),
91  STUN_FLAG_FUNNY = (1 << 2)
92 } STUNFLAGS;
93 
94 typedef enum {
95  VAD_IN = (1 << 0),
96  VAD_OUT = (1 << 1)
98 
100  uint32_t rtp_timeout_sec;
102  uint32_t dtmf_delay;
103  uint32_t codec_flags;
104 
107 
110 
111  char *timer_name;
112 
114  char *early_sdp;
120 
121  char *stun_ip;
123  uint32_t stun_flags;
124 
125  char *jb_msec;
126 
128 
132 
136 
137 
138  char *extrtpip;
139  char *rtpip;
140  char *rtpip4;
141  char *rtpip6;
142 
143 
144  char *remote_ip;
146 
147  char *extsipip;
149 
150  char *sipip;
151 
153 
156  unsigned long te_rate;
157  unsigned long cng_rate;
158 
160 
165 
166 
167  /* a core_video_thread will be started automatically
168  when uses rtp based media,
169  external_video_source should be set to SWITCH_TRUE and
170  switch_core_session_start_video_thread()
171  should be explicitly called to start the video thread
172  if uses the media handle for non-rtp based media
173  */
174 
176 
177  uint32_t video_key_freq;
178  uint32_t video_key_first;
179 
181 
183 
184 static inline const char *switch_media_type2str(switch_media_type_t type)
185 {
186  switch(type) {
188  return "audio";
190  return "video";
191  default:
192  return "!ERR";
193 
194  }
195 }
196 
197 
205 SWITCH_DECLARE(void) switch_media_handle_set_media_flag(switch_media_handle_t *smh, switch_core_media_flag_t flag);
206 SWITCH_DECLARE(void) switch_media_handle_clear_media_flag(switch_media_handle_t *smh, switch_core_media_flag_t flag);
207 SWITCH_DECLARE(int32_t) switch_media_handle_test_media_flag(switch_media_handle_t *smh, switch_core_media_flag_t flag);
208 SWITCH_DECLARE(void) switch_media_handle_set_media_flags(switch_media_handle_t *smh, switch_core_media_flag_t flags[SCMF_MAX]);
212  const char *varname,
213  switch_media_type_t type, const char *crypto, int crypto_tag, switch_sdp_type_t sdp_type);
214 
215 
219 
227 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);
232  switch_io_flag_t flags, int stream_id, switch_media_type_t type);
234  switch_frame_t *frame, switch_io_flag_t flags, int stream_id, switch_media_type_t type);
235 SWITCH_DECLARE(int) switch_core_media_check_nat(switch_media_handle_t *smh, const char *network_ip);
236 
247  switch_core_session_t *other_session, switch_t38_options_t *t38_options);
249  const char *ip, switch_port_t port, const char *sr, int force);
257 SWITCH_DECLARE(cJSON *) switch_core_media_gen_json_constraint(float min, float ideal, float max);
260 
261 
262 
273 
278 
279 
282  switch_sdp_type_t sdp_type, const char *codec_string);
283 
284 
300 
302  switch_media_type_t type,
303  const char *iananame,
304  uint32_t rate,
305  const char *fmtp_in,
306  switch_payload_t *ptP,
307  switch_payload_t *recv_ptP,
308  char **fmtpP);
309 
311  switch_media_type_t type,
312  const char *name,
313  const char *modname,
314  const char *fmtp,
315  switch_sdp_type_t sdp_type,
316  uint32_t pt,
317  uint32_t rate,
318  uint32_t ptime,
319  uint32_t channels,
320  uint8_t negotiated);
321 
327 SWITCH_DECLARE(char *) switch_core_media_filter_sdp(const char *sdp, const char *cmd, const char *arg);
328 SWITCH_DECLARE(char *) switch_core_media_process_sdp_filter(const char *sdp, const char *cmd_buf, switch_core_session_t *session);
329 
330 
332  switch_media_type_t mtype,
333  switch_io_type_t iotype,
336  void *cmd_data,
338  void *cmd_arg,
340  void **ret_data);
341 
343  switch_media_type_t mtype,
344  switch_codec_flag_t flag);
345 
346 
347 #define switch_core_media_gen_key_frame(_session) switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(_session), SWITCH_LOG_DEBUG1, "%s Send KeyFrame\n", switch_core_session_get_name(_session)); \
348  switch_core_media_codec_control(_session, SWITCH_MEDIA_TYPE_VIDEO, SWITCH_IO_WRITE, SCC_VIDEO_GEN_KEYFRAME, SCCT_NONE, NULL, SCCT_NONE, NULL, NULL, NULL)
349 
350 #define switch_core_media_write_bandwidth(_session, _val) switch_core_media_codec_control(_session, SWITCH_MEDIA_TYPE_VIDEO, SWITCH_IO_WRITE, \
351  SCC_VIDEO_BANDWIDTH, SCCT_STRING, _val, SCCT_NONE, NULL, NULL, NULL)
352 
353 
361 
362 #define switch_core_media_read_lock(_s, _t) switch_core_media_read_lock_unlock(_s, _t, SWITCH_TRUE)
363 #define switch_core_media_read_unlock(_s, _t) switch_core_media_read_lock_unlock(_s, _t, SWITCH_FALSE)
364 
381 
382 
384  switch_core_text_thread_callback_func_t func, void *user_data);
387  int stream_id);
388 
390  int stream_id);
391 
394 
397 
400 
403 
407 
409 #endif
410 /* For Emacs:
411  * Local Variables:
412  * mode:c
413  * indent-tabs-mode:t
414  * tab-width:4
415  * c-basic-offset:4
416  * End:
417  * For VIM:
418  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
419  */
420 
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)
float switch_core_media_get_media_bw_mult(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_core_media_reset_t38(switch_core_session_t *session)
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
void switch_core_media_set_smode(switch_core_session_t *session, switch_media_type_t type, switch_media_flow_t smode, switch_sdp_type_t sdp_type)
switch_rtp_crypto_key_type_t switch_core_media_crypto_str2type(const char *str)
switch_status_t switch_core_media_prepare_codecs(switch_core_session_t *session, switch_bool_t force)
switch_bool_t
Definition: switch_types.h:437
switch_status_t switch_core_session_print(switch_core_session_t *session, const char *data)
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
switch_status_t switch_core_media_set_video_file(switch_core_session_t *session, switch_file_handle_t *fh, switch_rw_t rw)
switch_rtp_crypto_direction_t
Definition: switch_rtp.h:62
switch_core_media_avp_secure_t
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)
switch_status_t switch_core_session_printf(switch_core_session_t *session, const char *fmt,...)
switch_rtp_t * switch_core_media_get_rtp_session(switch_core_session_t *session, switch_media_type_t type)
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)
switch_status_t switch_core_session_write_text_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id)
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:179
switch_rtp_bug_flag_t manual_video_rtp_bugs
uint32_t switch_core_media_get_video_fps(switch_core_session_t *session)
int cJSON_bool fmt
Definition: switch_cJSON.h:150
switch_status_t switch_core_session_text_read_callback(switch_core_session_t *session, switch_frame_t *frame)
void switch_core_session_clear_crypto(switch_core_session_t *session)
uint32_t switch_codec_flag_t
switch_bool_t switch_core_media_codec_get_cap(switch_core_session_t *session, switch_media_type_t mtype, switch_codec_flag_t flag)
switch_rtp_t * switch_core_session_get_rtp_session(switch_core_session_t *session, switch_media_type_t type)
int switch_core_media_crypto_keysalt_len(switch_rtp_crypto_key_type_t type)
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_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:598
switch_codec_control_type_t
static const char * switch_media_type2str(switch_media_type_t type)
void(* switch_engine_function_t)(switch_core_session_t *session, void *user_data)
int switch_core_media_check_nat(switch_media_handle_t *smh, const char *network_ip)
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)
void switch_core_media_clear_rtp_flag(switch_core_session_t *session, switch_media_type_t type, switch_rtp_flag_t flag)
switch_status_t switch_rtp_text_factory_create(switch_rtp_text_factory_t **tfP, switch_memory_pool_t *pool)
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:848
uint8_t switch_core_session_get_rtp_pt(switch_core_session_t *session, switch_media_type_t type)
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:54
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
int switch_core_media_check_engine_function(switch_core_session_t *session, switch_media_type_t type)
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)
void switch_core_media_set_resolveice(switch_bool_t resolve_ice)
switch_status_t switch_core_media_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg)
char * ip
Definition: switch_msrp.c:60
void switch_core_media_merge_sdp_codec_string(switch_core_session_t *session, const char *r_sdp, switch_sdp_type_t sdp_type, const char *codec_string)
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_end_engine_function(switch_core_session_t *session, switch_media_type_t type)
int switch_core_media_crypto_salt_len(switch_rtp_crypto_key_type_t type)
switch_status_t switch_core_session_set_text_read_callback(switch_core_session_t *session, switch_core_text_thread_callback_func_t func, void *user_data)
void switch_core_media_set_rtp_flag(switch_core_session_t *session, switch_media_type_t type, switch_rtp_flag_t flag)
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, const char *fmtp_in, switch_payload_t *ptP, switch_payload_t *recv_ptP, char **fmtpP)
char * switch_core_media_filter_sdp(const char *sdp, const char *cmd, const char *arg)
switch_codec_t * switch_core_media_get_codec(switch_core_session_t *session, switch_media_type_t type)
switch_status_t switch_core_session_start_video_thread(switch_core_session_t *session)
switch_rtp_flag_t
RTP Related Flags.
Definition: switch_types.h:793
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)
switch_status_t switch_core_media_media_params(switch_core_session_t *session, const char *json)
#define SWITCH_DECLARE(type)
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)
void switch_core_media_start_engine_function(switch_core_session_t *session, switch_media_type_t type, switch_engine_function_t engine_function, void *user_data)
void switch_core_media_parse_media_flags(switch_core_session_t *session)
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)
switch_status_t(* switch_core_text_thread_callback_func_t)(switch_core_session_t *session, switch_frame_t *frame, void *user_data)
void switch_media_handle_set_media_flags(switch_media_handle_t *smh, switch_core_media_flag_t flags[SCMF_MAX])
void switch_core_media_parse_rtp_bugs(switch_rtp_bug_flag_t *flag_pole, const char *str)
switch_bool_t switch_core_media_has_resolveice(void)
switch_core_media_NDLB_t ndlb
switch_media_flow_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_msrp_session_t * switch_core_media_get_msrp_session(switch_core_session_t *session)
switch_rtp_bug_flag_t manual_text_rtp_bugs
switch_status_t switch_core_media_lock_video_file(switch_core_session_t *session, switch_rw_t rw)
switch_status_t switch_rtp_text_factory_destroy(switch_rtp_text_factory_t **tfP)
switch_status_t switch_core_media_choose_port(switch_core_session_t *session, switch_media_type_t type, int force)
struct fspr_pool_t switch_memory_pool_t
const char *const name
Definition: switch_cJSON.h:250
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_session_write_blank_video(switch_core_session_t *session, uint32_t ms)
void switch_core_media_init(void)
struct fspr_thread_t switch_thread_t
Definition: switch_apr.h:941
void switch_core_media_check_video_codecs(switch_core_session_t *session)
uint32_t switch_core_media_get_orig_bitrate(switch_core_session_t *session, switch_media_type_t type)
switch_rtp_engine_t * switch_core_media_get_engine(switch_core_session_t *session, int media_type)
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_status_t switch_core_session_read_text_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id)
switch_core_media_NDLB_t
switch_status_t switch_core_media_add_crypto(switch_core_session_t *session, switch_secure_settings_t *ssec, switch_rtp_crypto_direction_t direction)
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)
cJSON * switch_core_media_gen_json_constraint(float min, float ideal, float max)
void switch_core_media_set_media_bw_mult(switch_core_session_t *session, float mult)
#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)