1 /*
2  * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
3  * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
4  *
5  * Version: MPL 1.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
18  *
19  * The Initial Developer of the Original Code is
20  * Anthony Minessale II <anthm@freeswitch.org>
21  * Portions created by the Initial Developer are Copyright (C)
22  * the Initial Developer. All Rights Reserved.
23  *
24  * Contributor(s):
25  *
26  * Anthony Minessale II <anthm@freeswitch.org>
27  * Luke Dashjr <luke@openmethods.com> (OpenMethods, LLC)
28  * Andrey Volk <andywolk@gmail.com>
29  *
30  *
31  * switch_module_interfaces.h -- Module Interface Definitions
32  *
33  */
34 /*! \file switch_module_interfaces.h
35   \brief Module Interface Definitions
36 
37   This module holds the definition of data abstractions used to implement various pluggable
38   interfaces and pluggable event handlers.
39 
40 */
41 #ifndef SWITCH_MODULE_INTERFACES_H
42 #define SWITCH_MODULE_INTERFACES_H
43 
44 #include <switch.h>
45 #include "switch_resample.h"
46 
47 SWITCH_BEGIN_EXTERN_C
48 /*! \brief A table of functions to execute at various states
49  */
50 	typedef enum {
51 	SWITCH_SHN_ON_INIT,
52 	SWITCH_SHN_ON_ROUTING,
53 	SWITCH_SHN_ON_EXECUTE,
54 	SWITCH_SHN_ON_HANGUP,
55 	SWITCH_SHN_ON_EXCHANGE_MEDIA,
56 	SWITCH_SHN_ON_SOFT_EXECUTE,
57 	SWITCH_SHN_ON_CONSUME_MEDIA,
58 	SWITCH_SHN_ON_HIBERNATE,
59 	SWITCH_SHN_ON_RESET,
60 	SWITCH_SHN_ON_PARK,
61 	SWITCH_SHN_ON_REPORTING,
62 	SWITCH_SHN_ON_DESTROY
63 } switch_state_handler_name_t;
64 
65 struct switch_state_handler_table {
66 	/*! executed when the state changes to init */
67 	switch_state_handler_t on_init;
68 	/*! executed when the state changes to routing */
69 	switch_state_handler_t on_routing;
70 	/*! executed when the state changes to execute */
71 	switch_state_handler_t on_execute;
72 	/*! executed when the state changes to hangup */
73 	switch_state_handler_t on_hangup;
74 	/*! executed when the state changes to exchange_media */
75 	switch_state_handler_t on_exchange_media;
76 	/*! executed when the state changes to soft_execute */
77 	switch_state_handler_t on_soft_execute;
78 	/*! executed when the state changes to consume_media */
79 	switch_state_handler_t on_consume_media;
80 	/*! executed when the state changes to hibernate */
81 	switch_state_handler_t on_hibernate;
82 	/*! executed when the state changes to reset */
83 	switch_state_handler_t on_reset;
84 	/*! executed when the state changes to park */
85 	switch_state_handler_t on_park;
86 	/*! executed when the state changes to reporting */
87 	switch_state_handler_t on_reporting;
88 	/*! executed when the state changes to destroy */
89 	switch_state_handler_t on_destroy;
90 	int flags;
91 	void *padding[10];
92 };
93 
94 struct switch_stream_handle {
95 	switch_stream_handle_read_function_t read_function;
96 	switch_stream_handle_write_function_t write_function;
97 	switch_stream_handle_raw_write_function_t raw_write_function;
98 	void *data;
99 	void *end;
100 	switch_size_t data_size;
101 	switch_size_t data_len;
102 	switch_size_t alloc_len;
103 	switch_size_t alloc_chunk;
104 	switch_event_t *param_event;
105 };
106 
107 struct switch_io_event_hooks;
108 struct switch_say_file_handle;
109 
110 typedef switch_call_cause_t (*switch_io_outgoing_channel_t)
111 	(switch_core_session_t *, switch_event_t *, switch_caller_profile_t *, switch_core_session_t **, switch_memory_pool_t **, switch_originate_flag_t,
112 	 switch_call_cause_t *);
113 typedef switch_status_t (*switch_io_read_frame_t) (switch_core_session_t *, switch_frame_t **, switch_io_flag_t, int);
114 typedef switch_status_t (*switch_io_write_frame_t) (switch_core_session_t *, switch_frame_t *, switch_io_flag_t, int);
115 typedef switch_status_t (*switch_io_kill_channel_t) (switch_core_session_t *, int);
116 typedef switch_status_t (*switch_io_send_dtmf_t) (switch_core_session_t *, const switch_dtmf_t *);
117 typedef switch_status_t (*switch_io_receive_message_t) (switch_core_session_t *, switch_core_session_message_t *);
118 typedef switch_status_t (*switch_io_receive_event_t) (switch_core_session_t *, switch_event_t *);
119 typedef switch_status_t (*switch_io_state_change_t) (switch_core_session_t *);
120 typedef switch_status_t (*switch_io_state_run_t) (switch_core_session_t *);
121 typedef switch_status_t (*switch_io_read_video_frame_t) (switch_core_session_t *, switch_frame_t **, switch_io_flag_t, int);
122 typedef switch_status_t (*switch_io_write_video_frame_t) (switch_core_session_t *, switch_frame_t *, switch_io_flag_t, int);
123 typedef switch_status_t (*switch_io_read_text_frame_t) (switch_core_session_t *, switch_frame_t **, switch_io_flag_t, int);
124 typedef switch_status_t (*switch_io_write_text_frame_t) (switch_core_session_t *, switch_frame_t *, switch_io_flag_t, int);
125 typedef switch_jb_t *(*switch_io_get_jb_t) (switch_core_session_t *, switch_media_type_t);
126 
127 typedef enum {
128 	SWITCH_IO_OUTGOING_CHANNEL,
129 	SWITCH_IO_READ_FRAME,
130 	SWITCH_IO_WRITE_FRAME,
131 	SWITCH_IO_KILL_CHANNEL,
132 	SWITCH_IO_SEND_DTMF,
133 	SWITCH_IO_RECEIVE_MESSAGE,
134 	SWITCH_IO_RECEIVE_EVENT,
135 	SWITCH_IO_STATE_CHANGE,
136 	SWITCH_IO_READ_VIDEO_FRAME,
137 	SWITCH_IO_WRITE_VIDEO_FRAME,
138 	SWITCH_IO_READ_TEXT_FRAME,
139 	SWITCH_IO_WRITE_TEXT_FRAME,
140 	SWITCH_IO_GET_JB,
141 } switch_io_routine_name_t;
142 
143 /*! \brief A table of i/o routines that an endpoint interface can implement */
144 struct switch_io_routines {
145 	/*! creates an outgoing session from given session, caller profile */
146 	switch_io_outgoing_channel_t outgoing_channel;
147 	/*! read a frame from a session */
148 	switch_io_read_frame_t read_frame;
149 	/*! write a frame to a session */
150 	switch_io_write_frame_t write_frame;
151 	/*! send a kill signal to the session's channel */
152 	switch_io_kill_channel_t kill_channel;
153 	/*! send a string of DTMF digits to a session's channel */
154 	switch_io_send_dtmf_t send_dtmf;
155 	/*! receive a message from another session */
156 	switch_io_receive_message_t receive_message;
157 	/*! queue a message for another session */
158 	switch_io_receive_event_t receive_event;
159 	/*! change a sessions channel state */
160 	switch_io_state_change_t state_change;
161 	/*! read a video frame from a session */
162 	switch_io_read_video_frame_t read_video_frame;
163 	/*! write a video frame to a session */
164 	switch_io_write_video_frame_t write_video_frame;
165 	/*! read a video frame from a session */
166 	switch_io_read_text_frame_t read_text_frame;
167 	/*! write a video frame to a session */
168 	switch_io_write_text_frame_t write_text_frame;
169 	/*! change a sessions channel run state */
170 	switch_io_state_run_t state_run;
171 	/*! get sessions jitterbuffer */
172 	switch_io_get_jb_t get_jb;
173 	void *padding[10];
174 };
175 
176 /*! \brief Abstraction of an module endpoint interface
177   This is the glue between the abstract idea of a "channel" and what is really going on under the
178   hood.	 Each endpoint module fills out one of these tables and makes it available when a channel
179   is created of it's paticular type.
180 */
181 
182 struct switch_endpoint_interface {
183 	/*! the interface's name */
184 	const char *interface_name;
185 
186 	/*! channel abstraction methods */
187 	switch_io_routines_t *io_routines;
188 
189 	/*! state machine methods */
190 	switch_state_handler_table_t *state_handler;
191 
192 	/*! private information */
193 	void *private_info;
194 
195 	switch_thread_rwlock_t *rwlock;
196 	int refs;
197 	switch_mutex_t *reflock;
198 
199 	/* parent */
200 	switch_loadable_module_interface_t *parent;
201 
202 	/* to facilitate linking */
203 	struct switch_endpoint_interface *next;
204 
205 	switch_core_recover_callback_t recover_callback;
206 
207 };
208 
209 /*! \brief Abstract handler to a timer module */
210 struct switch_timer {
211 	/*! time interval expressed in milliseconds */
212 	int interval;
213 	/*! flags to control behaviour */
214 	uint32_t flags;
215 	/*! sample count to increment by on each cycle */
216 	unsigned int samples;
217 	/*! current sample count based on samples parameter */
218 	uint32_t samplecount;
219 	uint32_t last_samplecount;
220 	/*! the timer interface provided from a loadable module */
221 	switch_timer_interface_t *timer_interface;
222 	/*! the timer's memory pool */
223 	switch_memory_pool_t *memory_pool;
224 	/*! private data for loadable modules to store information */
225 	void *private_info;
226 	/*! remaining time from last call to _check() */
227 	switch_size_t diff;
228 	switch_time_t start;
229 	uint64_t tick;
230 
231 };
232 
233 typedef enum {
234 	SWITCH_TIMER_FUNC_TIMER_INIT,
235 	SWITCH_TIMER_FUNC_TIMER_NEXT,
236 	SWITCH_TIMER_FUNC_TIMER_STEP,
237 	SWITCH_TIMER_FUNC_TIMER_SYNC,
238 	SWITCH_TIMER_FUNC_TIMER_CHECK,
239 	SWITCH_TIMER_FUNC_TIMER_DESTROY
240 } switch_timer_func_name_t;
241 
242 /*! \brief A table of functions that a timer module implements */
243 struct switch_timer_interface {
244 	/*! the name of the interface */
245 	const char *interface_name;
246 	/*! function to allocate the timer */
247 	switch_status_t (*timer_init) (switch_timer_t *);
248 	/*! function to wait for one cycle to pass */
249 	switch_status_t (*timer_next) (switch_timer_t *);
250 	/*! function to step the timer one step */
251 	switch_status_t (*timer_step) (switch_timer_t *);
252 	/*! function to reset the timer  */
253 	switch_status_t (*timer_sync) (switch_timer_t *);
254 	/*! function to check if the current step has expired */
255 	switch_status_t (*timer_check) (switch_timer_t *, switch_bool_t);
256 	/*! function to deallocate the timer */
257 	switch_status_t (*timer_destroy) (switch_timer_t *);
258 	switch_thread_rwlock_t *rwlock;
259 	int refs;
260 	switch_mutex_t *reflock;
261 	switch_loadable_module_interface_t *parent;
262 	struct switch_timer_interface *next;
263 };
264 
265 /*! \brief Abstract interface to a dialplan module */
266 struct switch_dialplan_interface {
267 	/*! the name of the interface */
268 	const char *interface_name;
269 	/*! the function to read an extension and set a channels dialpan */
270 	switch_dialplan_hunt_function_t hunt_function;
271 	switch_thread_rwlock_t *rwlock;
272 	int refs;
273 	switch_mutex_t *reflock;
274 	switch_loadable_module_interface_t *parent;
275 	struct switch_dialplan_interface *next;
276 };
277 
278 /*! \brief Abstract interface to a file format module */
279 struct switch_file_interface {
280 	/*! the name of the interface */
281 	const char *interface_name;
282 	/*! function to open the file */
283 	switch_status_t (*file_open) (switch_file_handle_t *, const char *file_path);
284 	/*! function to close the file */
285 	switch_status_t (*file_close) (switch_file_handle_t *);
286 	/*! function to close the file */
287 	switch_status_t (*file_truncate) (switch_file_handle_t *, int64_t offset);
288 	/*! function to read from the file */
289 	switch_status_t (*file_read) (switch_file_handle_t *, void *data, switch_size_t *len);
290 	/*! function to write from the file */
291 	switch_status_t (*file_write) (switch_file_handle_t *, void *data, switch_size_t *len);
292 	/*! function to seek to a certian position in the file */
293 	switch_status_t (*file_read_video) (switch_file_handle_t *, switch_frame_t *frame, switch_video_read_flag_t flags);
294 	/*! function to write from the file */
295 	switch_status_t (*file_write_video) (switch_file_handle_t *, switch_frame_t *frame);
296 	/*! function to seek to a certian position in the file */
297 	switch_status_t (*file_seek) (switch_file_handle_t *, unsigned int *cur_pos, int64_t samples, int whence);
298 	/*! function to set meta data */
299 	switch_status_t (*file_set_string) (switch_file_handle_t *fh, switch_audio_col_t col, const char *string);
300 	/*! function to get meta data */
301 	switch_status_t (*file_get_string) (switch_file_handle_t *fh, switch_audio_col_t col, const char **string);
302 	/*! function to pre close the file to read params */
303 	switch_status_t (*file_pre_close) (switch_file_handle_t *fh);
304 	/*! function to control the underlying tech of the file  */
305 	switch_status_t (*file_command) (switch_file_handle_t *fh, switch_file_command_t command);
306 	/*! list of supported file extensions */
307 	char **extens;
308 	switch_thread_rwlock_t *rwlock;
309 	int refs;
310 	switch_mutex_t *reflock;
311 	switch_loadable_module_interface_t *parent;
312 	struct switch_file_interface *next;
313 };
314 
315 /*! an abstract representation of a file handle (some parameters based on compat with libsndfile) */
316 struct switch_file_handle {
317 	/*! the interface of the module that implemented the current file type */
318 	switch_file_interface_t *file_interface;
319 	/*! flags to control behaviour */
320 	uint32_t flags;
321 	/*! a file descriptor if neceessary */
322 	switch_file_t *fd;
323 	/*! samples position of the handle */
324 	unsigned int samples;
325 	/*! the current samplerate */
326 	uint32_t samplerate;
327 	/*! the current native samplerate */
328 	uint32_t native_rate;
329 	/*! the number of channels */
330 	uint32_t channels;
331 	uint32_t real_channels;
332 	/*! integer representation of the format */
333 	unsigned int format;
334 	/*! integer representation of the sections */
335 	unsigned int sections;
336 	/*! is the file seekable */
337 	int seekable;
338 	/*! the sample count of the file */
339 	switch_size_t sample_count;
340 	/*! the speed of the file playback */
341 	int speed;
342 	/*! the handle's memory pool */
343 	switch_memory_pool_t *memory_pool;
344 	/*! pre-buffer x bytes for streams */
345 	uint32_t prebuf;
346 	/*! private data for the format module to store handle specific info */
347 	uint32_t interval;
348 	void *private_info;
349 	char *handler;
350 	int64_t pos;
351 	switch_buffer_t *audio_buffer;
352 	switch_buffer_t *sp_audio_buffer;
353 	uint32_t thresh;
354 	uint32_t silence_hits;
355 	uint32_t offset_pos;
356 	switch_size_t samples_in;
357 	switch_size_t samples_out;
358 	int32_t vol;
359 	switch_audio_resampler_t *resampler;
360 	switch_buffer_t *buffer;
361 	switch_byte_t *dbuf;
362 	switch_size_t dbuflen;
363 	switch_buffer_t *pre_buffer;
364 	unsigned char *pre_buffer_data;
365 	switch_size_t pre_buffer_datalen;
366 	const char *file;
367 	const char *func;
368 	int line;
369 	char *file_path;
370 	char *spool_path;
371 	const char *prefix;
372 	int max_samples;
373 	switch_event_t *params;
374 	uint32_t cur_channels;
375 	uint32_t cur_samplerate;
376 	char *stream_name;
377 	char *modname;
378 	switch_mm_t mm;
379 	switch_mutex_t *flag_mutex;
380 	/*! total video duration, or total page in pdf*/
381 	int64_t duration;
382 	/*! current video position, or current page in pdf */
383 	int64_t vpos;
384 	void *muxbuf;
385 	switch_size_t muxlen;
386 };
387 
388 /*! \brief Abstract interface to an asr module */
389 struct switch_asr_interface {
390 	/*! the name of the interface */
391 	const char *interface_name;
392 	/*! function to open the asr interface */
393 	switch_status_t (*asr_open) (switch_asr_handle_t *ah, const char *codec, int rate, const char *dest, switch_asr_flag_t *flags);
394 	/*! function to load a grammar to the asr interface */
395 	switch_status_t (*asr_load_grammar) (switch_asr_handle_t *ah, const char *grammar, const char *name);
396 	/*! function to unload a grammar to the asr interface */
397 	switch_status_t (*asr_unload_grammar) (switch_asr_handle_t *ah, const char *name);
398 	/*! function to close the asr interface */
399 	switch_status_t (*asr_close) (switch_asr_handle_t *ah, switch_asr_flag_t *flags);
400 	/*! function to feed audio to the ASR */
401 	switch_status_t (*asr_feed) (switch_asr_handle_t *ah, void *data, unsigned int len, switch_asr_flag_t *flags);
402 	/*! function to resume the ASR */
403 	switch_status_t (*asr_resume) (switch_asr_handle_t *ah);
404 	/*! function to pause the ASR */
405 	switch_status_t (*asr_pause) (switch_asr_handle_t *ah);
406 	/*! function to read results from the ASR */
407 	switch_status_t (*asr_check_results) (switch_asr_handle_t *ah, switch_asr_flag_t *flags);
408 	/*! function to read results from the ASR */
409 	switch_status_t (*asr_get_results) (switch_asr_handle_t *ah, char **xmlstr, switch_asr_flag_t *flags);
410 	/*! function to read result headers from the ASR */
411 	switch_status_t (*asr_get_result_headers) (switch_asr_handle_t *ah, switch_event_t **headers, switch_asr_flag_t *flags);
412 	/*! function to start ASR input timers */
413 	switch_status_t (*asr_start_input_timers) (switch_asr_handle_t *ah);
414 	void (*asr_text_param) (switch_asr_handle_t *ah, char *param, const char *val);
415 	void (*asr_numeric_param) (switch_asr_handle_t *ah, char *param, int val);
416 	void (*asr_float_param) (switch_asr_handle_t *ah, char *param, double val);
417 	switch_thread_rwlock_t *rwlock;
418 	int refs;
419 	switch_mutex_t *reflock;
420 	switch_loadable_module_interface_t *parent;
421 	struct switch_asr_interface *next;
422 	/*! function to enable a grammar to the asr interface */
423 	switch_status_t (*asr_enable_grammar) (switch_asr_handle_t *ah, const char *name);
424 	/*! function to disable a grammar to the asr interface */
425 	switch_status_t (*asr_disable_grammar) (switch_asr_handle_t *ah, const char *name);
426 	/*! function to disable all grammars to the asr interface */
427 	switch_status_t (*asr_disable_all_grammars) (switch_asr_handle_t *ah);
428 	/*! function to feed DTMF to the ASR */
429 	switch_status_t (*asr_feed_dtmf) (switch_asr_handle_t *ah, const switch_dtmf_t *dtmf, switch_asr_flag_t *flags);
430 };
431 
432 /*! an abstract representation of an asr speech interface. */
433 struct switch_asr_handle {
434 	/*! the interface of the module that implemented the current speech interface */
435 	switch_asr_interface_t *asr_interface;
436 	/*! flags to control behaviour */
437 	uint32_t flags;
438 	/*! The Name */
439 	char *name;
440 	/*! The Codec */
441 	char *codec;
442 	/*! The Rate */
443 	uint32_t rate;
444 	char *grammar;
445 	/*! module specific param */
446 	char *param;
447 	/*! the handle's memory pool */
448 	switch_memory_pool_t *memory_pool;
449 	switch_buffer_t *buffer;
450 	switch_byte_t *dbuf;
451 	switch_size_t dbuflen;
452 	switch_audio_resampler_t *resampler;
453 	/*! the current samplerate */
454 	uint32_t samplerate;
455 	/*! the current native samplerate */
456 	uint32_t native_rate;
457 	/*! private data for the format module to store handle specific info */
458 	void *private_info;
459 };
460 
461 /*! \brief Abstract interface to a speech module */
462 struct switch_speech_interface {
463 	/*! the name of the interface */
464 	const char *interface_name;
465 	/*! function to open the speech interface */
466 	switch_status_t (*speech_open) (switch_speech_handle_t *sh, const char *voice_name, int rate, int channels, switch_speech_flag_t *flags);
467 	/*! function to close the speech interface */
468 	switch_status_t (*speech_close) (switch_speech_handle_t *, switch_speech_flag_t *flags);
469 	/*! function to feed audio to the ASR */
470 	switch_status_t (*speech_feed_tts) (switch_speech_handle_t *sh, char *text, switch_speech_flag_t *flags);
471 	/*! function to read audio from the TTS */
472 	switch_status_t (*speech_read_tts) (switch_speech_handle_t *sh, void *data, switch_size_t *datalen, switch_speech_flag_t *flags);
473 	void (*speech_flush_tts) (switch_speech_handle_t *sh);
474 	void (*speech_text_param_tts) (switch_speech_handle_t *sh, char *param, const char *val);
475 	void (*speech_numeric_param_tts) (switch_speech_handle_t *sh, char *param, int val);
476 	void (*speech_float_param_tts) (switch_speech_handle_t *sh, char *param, double val);
477 	switch_thread_rwlock_t *rwlock;
478 	int refs;
479 	switch_mutex_t *reflock;
480 	switch_loadable_module_interface_t *parent;
481 	struct switch_speech_interface *next;
482 };
483 
484 
485 /*! an abstract representation of a tts speech interface. */
486 struct switch_speech_handle {
487 	/*! the interface of the module that implemented the current speech interface */
488 	switch_speech_interface_t *speech_interface;
489 	/*! flags to control behaviour */
490 	uint32_t flags;
491 	/*! The Name */
492 	char *name;
493 	/*! The Rate */
494 	uint32_t rate;
495 	uint32_t speed;
496 	uint32_t samples;
497 	uint32_t channels;
498 	uint32_t real_channels;
499 	char voice[80];
500 	char *engine;
501 	/*! module specific param */
502 	char *param;
503 	/*! the handle's memory pool */
504 	switch_memory_pool_t *memory_pool;
505 	switch_audio_resampler_t *resampler;
506 	switch_buffer_t *buffer;
507 	switch_byte_t *dbuf;
508 	switch_size_t dbuflen;
509 	/*! the current samplerate */
510 	uint32_t samplerate;
511 	/*! the current native samplerate */
512 	uint32_t native_rate;
513 	/*! the number of channels */
514 
515 	/*! private data for the format module to store handle specific info */
516 	void *private_info;
517 };
518 
519 /*! \brief Abstract interface to a say module */
520 struct switch_say_interface {
521 	/*! the name of the interface */
522 	const char *interface_name;
523 	/*! function to pass down to the module */
524 	switch_say_callback_t say_function;
525 	switch_say_string_callback_t say_string_function;
526 	switch_thread_rwlock_t *rwlock;
527 	int refs;
528 	switch_mutex_t *reflock;
529 	switch_loadable_module_interface_t *parent;
530 	struct switch_say_interface *next;
531 };
532 
533 /*! \brief Abstract interface to a chat module */
534 struct switch_chat_interface {
535 	/*! the name of the interface */
536 	const char *interface_name;
537 	/*! function to open the directory interface */
538 	switch_status_t (*chat_send) (switch_event_t *message_event);
539 
540 	switch_thread_rwlock_t *rwlock;
541 	int refs;
542 	switch_mutex_t *reflock;
543 	switch_loadable_module_interface_t *parent;
544 	struct switch_chat_interface *next;
545 };
546 
547 /*! \brief Abstract interface to a management module */
548 struct switch_management_interface {
549 	/*! the name of the interface */
550 	const char *relative_oid;
551 	/*! function to open the directory interface */
552 	switch_status_t (*management_function) (char *relative_oid, switch_management_action_t action, char *data, switch_size_t datalen);
553 	switch_thread_rwlock_t *rwlock;
554 	int refs;
555 	switch_mutex_t *reflock;
556 	switch_loadable_module_interface_t *parent;
557 	struct switch_management_interface *next;
558 };
559 
560 /*! \brief Abstract interface to a limit module */
561 struct switch_limit_interface {
562 	/*! name of the interface */
563 	const char *interface_name;
564 	/*! increment */
565 	switch_status_t (*incr) (switch_core_session_t *session, const char *realm, const char *resource, const int max, const int interval);
566 	/*! release */
567 	switch_status_t (*release) (switch_core_session_t *session, const char *realm, const char *resource);
568 	/*! usage for resource */
569 	int (*usage) (const char *realm, const char *resource, uint32_t *rcount);
570 	/*! reset counters */
571 	switch_status_t (*reset) (void);
572 	/*! freform status */
573 	char * (*status) (void);
574 	/*! reset interval counter */
575 	switch_status_t (*interval_reset) (const char *realm, const char *resource);
576 	/* internal */
577 	switch_thread_rwlock_t *rwlock;
578 	int refs;
579 	switch_mutex_t *reflock;
580 	switch_loadable_module_interface_t *parent;
581 	struct switch_limit_interface *next;
582 };
583 
584 /*! \brief Abstract interface to a directory module */
585 struct switch_directory_interface {
586 	/*! the name of the interface */
587 	const char *interface_name;
588 	/*! function to open the directory interface */
589 	switch_status_t (*directory_open) (switch_directory_handle_t *dh, char *source, char *dsn, char *passwd);
590 	/*! function to close the directory interface */
591 	switch_status_t (*directory_close) (switch_directory_handle_t *dh);
592 	/*! function to query the directory interface */
593 	switch_status_t (*directory_query) (switch_directory_handle_t *dh, char *base, char *query);
594 	/*! function to advance to the next record */
595 	switch_status_t (*directory_next) (switch_directory_handle_t *dh);
596 	/*! function to advance to the next name/value pair in the current record */
597 	switch_status_t (*directory_next_pair) (switch_directory_handle_t *dh, char **var, char **val);
598 	switch_thread_rwlock_t *rwlock;
599 	int refs;
600 	switch_mutex_t *reflock;
601 	switch_loadable_module_interface_t *parent;
602 	struct switch_directory_interface *next;
603 };
604 
605 /*! an abstract representation of a directory interface. */
606 struct switch_directory_handle {
607 	/*! the interface of the module that implemented the current directory interface */
608 	switch_directory_interface_t *directory_interface;
609 	/*! flags to control behaviour */
610 	uint32_t flags;
611 
612 	/*! the handle's memory pool */
613 	switch_memory_pool_t *memory_pool;
614 	/*! private data for the format module to store handle specific info */
615 	void *private_info;
616 };
617 
618 /*! \brief Abstract interface to a database module */
619 struct switch_database_interface {
620 	/*! the name of the interface */
621 	const char *interface_name;
622 	/*! flags indicating database specifics, see switch_database_flag_t */
623 	uint32_t flags;
624 	switch_status_t(*handle_new)(switch_cache_db_database_interface_options_t database_interface_options, switch_database_interface_handle_t **dih);
625 	switch_status_t(*handle_destroy)(switch_database_interface_handle_t **dih);
626 	switch_status_t(*flush)(switch_database_interface_handle_t *dih);
627 	switch_status_t(*exec_detailed)(const char *file, const char *func, int line,
628 		switch_database_interface_handle_t *dih, const char *sql, char **err);
629 	switch_status_t(*exec_string)(switch_database_interface_handle_t *dih, const char *sql, char *resbuf, size_t len, char **err);
630 	switch_status_t(*sql_set_auto_commit_attr)(switch_database_interface_handle_t *dih, switch_bool_t on);
631 	switch_status_t(*commit)(switch_database_interface_handle_t *dih);
632 	switch_status_t(*rollback)(switch_database_interface_handle_t *dih);
633 	switch_status_t(*callback_exec_detailed)(const char *file, const char *func, int line,
634 		switch_database_interface_handle_t *dih, const char *sql, switch_core_db_callback_func_t callback, void *pdata, char **err);
635 	switch_status_t(*affected_rows)(switch_database_interface_handle_t *dih, int *affected_rows);
636 
637 	/*! list of supported dsn prefixes */
638 	char **prefixes;
639 	switch_thread_rwlock_t *rwlock;
640 	int refs;
641 	switch_mutex_t *reflock;
642 	switch_loadable_module_interface_t *parent;
643 	struct switch_database_interface *next;
644 };
645 
646 /*! an abstract representation of a database interface. */
647 struct switch_database_interface_handle {
648 	switch_cache_db_database_interface_options_t connection_options;
649 	void *handle;
650 };
651 
652 struct switch_audio_codec_settings {
653 	int unused;
654 };
655 
656 struct switch_video_codec_settings {
657 	uint32_t bandwidth;
658 	int32_t width;
659 	int32_t height;
660 	uint8_t try_hardware_encoder;
661 	uint8_t fps;
662 	char config_profile_name[64];
663 };
664 
665 union switch_codec_settings {
666 	struct switch_audio_codec_settings audio;
667 	struct switch_video_codec_settings video;
668 };
669 
670 /*! an abstract handle of a fmtp parsed by codec */
671 struct switch_codec_fmtp {
672 	/*! actual samples transferred per second for those who are not moron g722 RFC writers */
673 	uint32_t actual_samples_per_second;
674 	/*! bits transferred per second */
675 	int bits_per_second;
676 	/*! number of microseconds of media in one packet (ptime * 1000) */
677 	int microseconds_per_packet;
678 	/*! stereo  */
679 	int stereo;
680 	/*! private data for the codec module to store handle specific info */
681 	void *private_info;
682 
683 };
684 
685 struct switch_picture {
686 	uint32_t width;      /* the picture width */
687 	uint32_t height;     /* the picture height */
688 	uint8_t *planes[4];  /* pointer to the top left pixel for each plane */
689 	uint32_t stride[4];  /* stride between rows for each plane */
690 };
691 
692 /*! an abstract handle to a codec module */
693 struct switch_codec {
694 	/*! the codec interface table this handle uses */
695 	switch_codec_interface_t *codec_interface;
696 	/*! the specific implementation of the above codec */
697 	const switch_codec_implementation_t *implementation;
698 	/*! fmtp line from remote sdp */
699 	char *fmtp_in;
700 	/*! fmtp line for local sdp */
701 	char *fmtp_out;
702 	/*! flags to modify behaviour */
703 	uint32_t flags;
704 	/*! the handle's memory pool */
705 	switch_memory_pool_t *memory_pool;
706 	/*! private data for the codec module to store handle specific info */
707 	void *private_info;
708 	switch_payload_t agreed_pt;
709 	switch_mutex_t *mutex;
710 	struct switch_codec *next;
711 	switch_core_session_t *session;
712 	switch_frame_t *cur_frame;
713 };
714 
715 /*! \brief A table of settings and callbacks that define a paticular implementation of a codec */
716 struct switch_codec_implementation {
717 	/*! enumeration defining the type of the codec */
718 	switch_codec_type_t codec_type;
719 	/*! the IANA code number */
720 	switch_payload_t ianacode;
721 	/*! the IANA code name */
722 	char *iananame;
723 	/*! default fmtp to send (can be overridden by the init function) */
724 	char *fmtp;
725 	/*! samples transferred per second */
726 	uint32_t samples_per_second;
727 	/*! actual samples transferred per second for those who are not moron g722 RFC writers */
728 	uint32_t actual_samples_per_second;
729 	/*! bits transferred per second */
730 	int bits_per_second;
731 	/*! number of microseconds of media in one packet (ptime * 1000) */
732 	int microseconds_per_packet;
733 	/*! number of samples in one packet */
734 	uint32_t samples_per_packet;
735 	/*! number of bytes one packet will decompress to */
736 	uint32_t decoded_bytes_per_packet;
737 	/*! number of encoded bytes in the RTP payload */
738 	uint32_t encoded_bytes_per_packet;
739 	/*! number of channels represented */
740 	uint8_t number_of_channels;
741 	/*! number of codec frames packetized into one packet */
742 	int codec_frames_per_packet;
743 	/*! function to initialize a codec handle using this implementation */
744 	switch_core_codec_init_func_t init;
745 	/*! function to encode raw data into encoded data */
746 	switch_core_codec_encode_func_t encode;
747 	/*! function to decode encoded data into raw data */
748 	switch_core_codec_decode_func_t decode;
749 	/*! function to encode video raw data into encoded data */
750 	switch_core_codec_video_encode_func_t encode_video;
751 	/*! function to decode video encoded data into raw data */
752 	switch_core_codec_video_decode_func_t decode_video;
753 	/*! function to send control messages to the codec */
754 	switch_core_codec_control_func_t codec_control;
755 	/*! deinitalize a codec handle using this implementation */
756 	switch_core_codec_destroy_func_t destroy;
757 	uint32_t codec_id;
758 	uint32_t impl_id;
759 	char *modname;
760 	struct switch_codec_implementation *next;
761 };
762 
763 /*! \brief Top level module interface to implement a series of codec implementations */
764 struct switch_codec_interface {
765 	/*! the name of the interface */
766 	const char *interface_name;
767 	/*! a list of codec implementations related to the codec */
768 	switch_codec_implementation_t *implementations;
769 	/*! function to decode a codec fmtp parameters */
770 	switch_core_codec_fmtp_parse_func_t parse_fmtp;
771 	uint32_t codec_id;
772 	switch_thread_rwlock_t *rwlock;
773 	int refs;
774 	switch_mutex_t *reflock;
775 	char *modname;
776 	switch_loadable_module_interface_t *parent;
777 	struct switch_codec_interface *next;
778 };
779 
780 /*! \brief A module interface to implement an application */
781 struct switch_application_interface {
782 	/*! the name of the interface */
783 	const char *interface_name;
784 	/*! function the application implements */
785 	switch_application_function_t application_function;
786 	/*! the long winded description of the application */
787 	const char *long_desc;
788 	/*! the short and sweet description of the application */
789 	const char *short_desc;
790 	/*! an example of the application syntax */
791 	const char *syntax;
792 	/*! flags to control behaviour */
793 	uint32_t flags;
794 	switch_thread_rwlock_t *rwlock;
795 	int refs;
796 	switch_mutex_t *reflock;
797 	switch_loadable_module_interface_t *parent;
798 	struct switch_application_interface *next;
799 };
800 
801 /*! \brief A module interface to implement a chat application */
802 struct switch_chat_application_interface {
803 	/*! the name of the interface */
804 	const char *interface_name;
805 	/*! function the application implements */
806 	switch_chat_application_function_t chat_application_function;
807 	/*! the long winded description of the application */
808 	const char *long_desc;
809 	/*! the short and sweet description of the application */
810 	const char *short_desc;
811 	/*! an example of the application syntax */
812 	const char *syntax;
813 	/*! flags to control behaviour */
814 	uint32_t flags;
815 	switch_thread_rwlock_t *rwlock;
816 	int refs;
817 	switch_mutex_t *reflock;
818 	switch_loadable_module_interface_t *parent;
819 	struct switch_chat_application_interface *next;
820 };
821 
822 /*! \brief A module interface to implement an api function */
823 struct switch_api_interface {
824 	/*! the name of the interface */
825 	const char *interface_name;
826 	/*! a description of the api function */
827 	const char *desc;
828 	/*! function the api call uses */
829 	switch_api_function_t function;
830 	/*! an example of the api syntax */
831 	const char *syntax;
832 	switch_thread_rwlock_t *rwlock;
833 	int refs;
834 	switch_mutex_t *reflock;
835 	switch_loadable_module_interface_t *parent;
836 	struct switch_api_interface *next;
837 };
838 
839 
840 /*! \brief A module interface to implement a json api function */
841 struct switch_json_api_interface {
842 	/*! the name of the interface */
843 	const char *interface_name;
844 	/*! a description of the api function */
845 	const char *desc;
846 	/*! function the api call uses */
847 	switch_json_api_function_t function;
848 	/*! an example of the api syntax */
849 	const char *syntax;
850 	switch_thread_rwlock_t *rwlock;
851 	int refs;
852 	switch_mutex_t *reflock;
853 	switch_loadable_module_interface_t *parent;
854 	struct switch_json_api_interface *next;
855 };
856 
857 #define PROTECT_INTERFACE(_it) if (_it) {switch_mutex_lock(_it->reflock); switch_thread_rwlock_rdlock(_it->parent->rwlock); switch_thread_rwlock_rdlock(_it->rwlock); _it->refs++; _it->parent->refs++; switch_mutex_unlock(_it->reflock);}	//if (!strcmp(_it->interface_name, "user")) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "+++++++++++LOCK %s %d/%d\n", _it->interface_name, _it->refs, _it->parent->refs);
858 #define UNPROTECT_INTERFACE(_it) if (_it) {switch_mutex_lock(_it->reflock); switch_thread_rwlock_unlock(_it->rwlock); switch_thread_rwlock_unlock(_it->parent->rwlock); _it->refs--; _it->parent->refs--; switch_mutex_unlock(_it->reflock);}	//if (!strcmp(_it->interface_name, "user")) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "---------UNLOCK %s %d/%d\n", _it->interface_name, _it->refs, _it->parent->refs);
859 
860 #include "switch_frame.h"
861 
862 struct switch_slin_data {
863 	switch_core_session_t *session;
864 	switch_frame_t write_frame;
865 	switch_codec_t codec;
866 	char frame_data[SWITCH_RECOMMENDED_BUFFER_SIZE];
867 };
868 
869 SWITCH_END_EXTERN_C
870 #endif
871 /* For Emacs:
872  * Local Variables:
873  * mode:c
874  * indent-tabs-mode:t
875  * tab-width:4
876  * c-basic-offset:4
877  * End:
878  * For VIM:
879  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
880  */
881