mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-13 09:36:46 +00:00
add basics for analog (wip)
git-svn-id: http://svn.openzap.org/svn/openzap/trunk@130 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
@@ -74,6 +74,11 @@
|
||||
#pragma warning(disable:4706)
|
||||
#endif
|
||||
|
||||
#ifndef WIN32
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -91,6 +96,8 @@
|
||||
#include "Q931.h"
|
||||
#include "Q921.h"
|
||||
|
||||
#define XX if (0)
|
||||
|
||||
#ifdef NDEBUG
|
||||
#undef assert
|
||||
#define assert(_Expression) ((void)(_Expression))
|
||||
@@ -131,6 +138,11 @@
|
||||
*/
|
||||
#define zap_set_flag(obj, flag) (obj)->flags |= (flag)
|
||||
|
||||
#define zap_set_flag_locked(obj, flag) assert(obj->mutex != NULL);\
|
||||
zap_mutex_lock(obj->mutex);\
|
||||
(obj)->flags |= (flag);\
|
||||
zap_mutex_unlock(obj->mutex);
|
||||
|
||||
/*!
|
||||
\brief Clear a flag on an arbitrary object while locked
|
||||
\command obj the object to test
|
||||
@@ -138,6 +150,12 @@
|
||||
*/
|
||||
#define zap_clear_flag(obj, flag) (obj)->flags &= ~(flag)
|
||||
|
||||
#define zap_clear_flag_locked(obj, flag) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); (obj)->flags &= ~(flag); zap_mutex_unlock(obj->mutex);
|
||||
|
||||
#define zap_set_state_locked(obj, s) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); obj->state = s; zap_mutex_unlock(obj->mutex);
|
||||
|
||||
#define zap_is_dtmf(key) ((key > 47 && key < 58) || (key > 64 && key < 69) || (key > 96 && key < 101) || key == 35 || key == 42 || key == 87 || key == 119)
|
||||
|
||||
/*!
|
||||
\brief Copy flags from one arbitrary object to another
|
||||
\command dest the object to copy the flags to
|
||||
@@ -157,6 +175,8 @@
|
||||
|
||||
struct zap_event {
|
||||
zap_event_type_t e_type;
|
||||
uint32_t enum_id;
|
||||
zap_channel_t *channel;
|
||||
void *data;
|
||||
};
|
||||
|
||||
@@ -172,6 +192,8 @@ struct zap_channel {
|
||||
uint32_t effective_interval;
|
||||
uint32_t native_interval;
|
||||
uint32_t packet_len;
|
||||
zap_channel_state_t state;
|
||||
zap_mutex_t *mutex;
|
||||
teletone_dtmf_detect_state_t dtmf_detect;
|
||||
zap_event_t event_header;
|
||||
char last_error[256];
|
||||
@@ -179,9 +201,11 @@ struct zap_channel {
|
||||
void *mod_data;
|
||||
uint32_t skip_read_frames;
|
||||
zap_buffer_t *dtmf_buffer;
|
||||
zap_buffer_t *digit_buffer;
|
||||
uint32_t dtmf_on;
|
||||
uint32_t dtmf_off;
|
||||
teletone_generation_session_t tone_session;
|
||||
zap_time_t last_event_time;
|
||||
struct zap_span *span;
|
||||
struct zap_io_interface *zio;
|
||||
};
|
||||
@@ -207,6 +231,10 @@ struct zap_isdn_data {
|
||||
uint32_t flags;
|
||||
};
|
||||
|
||||
struct zap_analog_data {
|
||||
uint32_t flags;
|
||||
};
|
||||
|
||||
struct zap_span {
|
||||
uint32_t span_id;
|
||||
uint32_t chan_count;
|
||||
@@ -217,6 +245,8 @@ struct zap_span {
|
||||
zap_trunk_type_t trunk_type;
|
||||
zap_signal_type_t signal_type;
|
||||
struct zap_isdn_data *isdn_data;
|
||||
struct zap_analog_data *analog_data;
|
||||
zap_event_t event_header;
|
||||
char last_error[256];
|
||||
zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN];
|
||||
};
|
||||
@@ -233,12 +263,21 @@ struct zap_io_interface {
|
||||
zio_wait_t wait;
|
||||
zio_read_t read;
|
||||
zio_write_t write;
|
||||
zio_span_poll_event_t poll_event;
|
||||
zio_span_next_event_t next_event;
|
||||
uint32_t span_index;
|
||||
struct zap_span spans[ZAP_MAX_SPANS_INTERFACE];
|
||||
};
|
||||
|
||||
zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len);
|
||||
zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf);
|
||||
zap_time_t zap_current_time_in_ms(void);
|
||||
zap_oob_event_t str2zap_oob_signal(char *name);
|
||||
char *zap_oob_signal2str(zap_oob_event_t type);
|
||||
zap_trunk_type_t str2zap_trunk_type(char *name);
|
||||
char *zap_trunk_type2str(zap_trunk_type_t type);
|
||||
zap_status_t zap_span_poll_event(zap_span_t *span, uint32_t ms);
|
||||
zap_status_t zap_span_next_event(zap_span_t *span, zap_event_t **event);
|
||||
zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span);
|
||||
zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span);
|
||||
zap_status_t zap_span_close_all(zap_io_interface_t *zio);
|
||||
@@ -246,6 +285,7 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha
|
||||
zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback);
|
||||
zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback);
|
||||
zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan);
|
||||
zap_status_t zap_channel_open_chan(zap_channel_t *zchan);
|
||||
zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan);
|
||||
zap_status_t zap_channel_close(zap_channel_t **zchan);
|
||||
zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj);
|
||||
|
48
libs/freetdm/src/include/zap_analog.h
Normal file
48
libs/freetdm/src/include/zap_analog.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2007, Anthony Minessale II
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef ZAP_ANALOG_H
|
||||
#define ZAP_ANALOG_H
|
||||
#include "openzap.h"
|
||||
|
||||
typedef enum {
|
||||
ZAP_ANALOG_RUNNING = (1 << 0)
|
||||
} zap_analog_flag_t;
|
||||
|
||||
|
||||
typedef struct zap_analog_data zap_analog_data_t;
|
||||
|
||||
zap_status_t zap_analog_start(zap_span_t *span);
|
||||
zap_status_t zap_analog_configure_span(zap_span_t *span, zio_signal_cb_t sig_cb);
|
||||
|
||||
#endif
|
@@ -50,6 +50,8 @@ struct zap_io_interface;
|
||||
#define ZAP_COMMAND_OBJ_INT *((int *)obj)
|
||||
#define ZAP_COMMAND_OBJ_CHAR_P (char *)obj
|
||||
|
||||
typedef uint64_t zap_time_t;
|
||||
|
||||
typedef enum {
|
||||
ZAP_TRUNK_E1,
|
||||
ZAP_TRUNK_T1,
|
||||
@@ -79,6 +81,7 @@ typedef enum {
|
||||
typedef enum {
|
||||
ZAP_EVENT_NONE,
|
||||
ZAP_EVENT_DTMF,
|
||||
ZAP_EVENT_OOB,
|
||||
ZAP_EVENT_COUNT
|
||||
} zap_event_type_t;
|
||||
|
||||
@@ -143,7 +146,6 @@ typedef enum {
|
||||
ZAP_CHAN_TYPE_DQ931,
|
||||
ZAP_CHAN_TYPE_FXS,
|
||||
ZAP_CHAN_TYPE_FXO,
|
||||
|
||||
ZAP_CHAN_TYPE_COUNT
|
||||
} zap_chan_type_t;
|
||||
|
||||
@@ -153,6 +155,13 @@ typedef enum {
|
||||
ZAP_CHANNEL_FEATURE_INTERVAL = (1 << 2)
|
||||
} zap_channel_feature_t;
|
||||
|
||||
typedef enum {
|
||||
ZAP_CHANNEL_STATE_DOWN,
|
||||
ZAP_CHANNEL_STATE_UP,
|
||||
ZAP_CHANNEL_STATE_DIALTONE,
|
||||
ZAP_CHANNEL_STATE_COLLECT
|
||||
} zap_channel_state_t;
|
||||
|
||||
typedef enum {
|
||||
ZAP_CHANNEL_CONFIGURED = (1 << 0),
|
||||
ZAP_CHANNEL_READY = (1 << 1),
|
||||
@@ -160,14 +169,31 @@ typedef enum {
|
||||
ZAP_CHANNEL_DTMF_DETECT = (1 << 3),
|
||||
ZAP_CHANNEL_SUPRESS_DTMF = (1 << 4),
|
||||
ZAP_CHANNEL_TRANSCODE = (1 << 5),
|
||||
ZAP_CHANNEL_BUFFER = (1 << 6)
|
||||
ZAP_CHANNEL_BUFFER = (1 << 6),
|
||||
ZAP_CHANNEL_EVENT = (1 << 7),
|
||||
ZAP_CHANNEL_INTHREAD = (1 << 8),
|
||||
ZAP_CHANNEL_WINK = (1 << 9),
|
||||
ZAP_CHANNEL_FLASH = (1 << 10)
|
||||
} zap_channel_flag_t;
|
||||
|
||||
typedef enum {
|
||||
ZAP_OOB_DTMF,
|
||||
ZAP_OOB_ONHOOK,
|
||||
ZAP_OOB_OFFHOOK,
|
||||
ZAP_OOB_WINK,
|
||||
ZAP_OOB_FLASH,
|
||||
ZAP_OOB_RING_START,
|
||||
ZAP_OOB_RING_STOP,
|
||||
ZAP_OOB_INVALID
|
||||
} zap_oob_event_t;
|
||||
|
||||
typedef struct zap_channel zap_channel_t;
|
||||
typedef struct zap_event zap_event_t;
|
||||
typedef struct zap_sigmsg zap_sigmsg_t;
|
||||
typedef struct zap_span zap_span_t;
|
||||
|
||||
#define ZIO_SPAN_POLL_EVENT_ARGS (zap_span_t *span, uint32_t ms)
|
||||
#define ZIO_SPAN_NEXT_EVENT_ARGS (zap_span_t *span, zap_event_t **event)
|
||||
#define ZIO_SIGNAL_CB_ARGS (zap_span_t *span, zap_sigmsg_t *sigmsg, void *raw_data, uint32_t raw_data_len)
|
||||
#define ZIO_EVENT_CB_ARGS (zap_channel_t *zchan, zap_event_t *event)
|
||||
#define ZIO_CODEC_ARGS (void *data, zap_size_t max, zap_size_t *datalen)
|
||||
@@ -179,6 +205,8 @@ typedef struct zap_span zap_span_t;
|
||||
#define ZIO_READ_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen)
|
||||
#define ZIO_WRITE_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen)
|
||||
|
||||
typedef zap_status_t (*zio_span_poll_event_t) ZIO_SPAN_POLL_EVENT_ARGS ;
|
||||
typedef zap_status_t (*zio_span_next_event_t) ZIO_SPAN_NEXT_EVENT_ARGS ;
|
||||
typedef zap_status_t (*zio_signal_cb_t) ZIO_SIGNAL_CB_ARGS ;
|
||||
typedef zap_status_t (*zio_event_cb_t) ZIO_EVENT_CB_ARGS ;
|
||||
typedef zap_status_t (*zio_codec_t) ZIO_CODEC_ARGS ;
|
||||
@@ -190,6 +218,8 @@ typedef zap_status_t (*zio_wait_t) ZIO_WAIT_ARGS ;
|
||||
typedef zap_status_t (*zio_read_t) ZIO_READ_ARGS ;
|
||||
typedef zap_status_t (*zio_write_t) ZIO_WRITE_ARGS ;
|
||||
|
||||
#define ZIO_SPAN_POLL_EVENT_FUNCTION(name) zap_status_t name ZIO_SPAN_POLL_EVENT_ARGS
|
||||
#define ZIO_SPAN_NEXT_EVENT_FUNCTION(name) zap_status_t name ZIO_SPAN_NEXT_EVENT_ARGS
|
||||
#define ZIO_SIGNAL_CB_FUNCTION(name) zap_status_t name ZIO_SIGNAL_CB_ARGS
|
||||
#define ZIO_EVENT_CB_FUNCTION(name) zap_status_t name ZIO_EVENT_CB_ARGS
|
||||
#define ZIO_CODEC_FUNCTION(name) zap_status_t name ZIO_CODEC_ARGS
|
||||
|
Reference in New Issue
Block a user