00001 /* 00002 * Copyright 2009-2010 Tomas Valenta, 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_dtmf_detector.h 1474 2010-02-07 20:51:47Z achaloyan $ 00017 */ 00018 00019 #ifndef MPF_DTMF_DETECTOR_H 00020 #define MPF_DTMF_DETECTOR_H 00021 00022 /** 00023 * @file mpf_dtmf_detector.h 00024 * @brief DTMF detector 00025 * 00026 * Detector of DTMF tones sent both out-of-band (RFC4733) and in-band (audio). 00027 */ 00028 00029 #include "apr.h" 00030 #include "apr_pools.h" 00031 #include "apt.h" 00032 #include "mpf_frame.h" 00033 #include "mpf_stream.h" 00034 00035 APT_BEGIN_EXTERN_C 00036 00037 /** DTMF detector band */ 00038 typedef enum mpf_dtmf_detector_band_e { 00039 /** Detect tones in-band */ 00040 MPF_DTMF_DETECTOR_INBAND = 0x1, 00041 /** Detect named events out-of-band */ 00042 MPF_DTMF_DETECTOR_OUTBAND = 0x2, 00043 /** Detect both in-band and out-of-band digits */ 00044 MPF_DTMF_DETECTOR_BOTH = MPF_DTMF_DETECTOR_INBAND | MPF_DTMF_DETECTOR_OUTBAND 00045 } mpf_dtmf_detector_band_e; 00046 00047 /** Opaque MPF DTMF detector structure definition */ 00048 typedef struct mpf_dtmf_detector_t mpf_dtmf_detector_t; 00049 00050 00051 /** 00052 * Create MPF DTMF detector (advanced). 00053 * @param stream A stream to get digits from. 00054 * @param band One of: 00055 * - MPF_DTMF_DETECTOR_INBAND: detect audible tones only 00056 * - MPF_DTMF_DETECTOR_OUTBAND: detect out-of-band named-events only 00057 * - MPF_DTMF_DETECTOR_BOTH: detect digits in both bands if supported by 00058 * stream. When out-of-band digit arrives, in-band detection is turned off. 00059 * @param pool Memory pool to allocate DTMF detector from. 00060 * @return The object or NULL on error. 00061 * @see mpf_dtmf_detector_create 00062 */ 00063 MPF_DECLARE(struct mpf_dtmf_detector_t *) mpf_dtmf_detector_create_ex( 00064 const struct mpf_audio_stream_t *stream, 00065 enum mpf_dtmf_detector_band_e band, 00066 struct apr_pool_t *pool); 00067 00068 /** 00069 * Create MPF DTMF detector (simple). Calls mpf_dtmf_detector_create_ex 00070 * with band = MPF_DTMF_DETECTOR_BOTH if out-of-band supported by the stream, 00071 * MPF_DTMF_DETECTOR_INBAND otherwise. 00072 * @param stream A stream to get digits from. 00073 * @param pool Memory pool to allocate DTMF detector from. 00074 * @return The object or NULL on error. 00075 * @see mpf_dtmf_detector_create_ex 00076 */ 00077 static APR_INLINE struct mpf_dtmf_detector_t *mpf_dtmf_detector_create( 00078 const struct mpf_audio_stream_t *stream, 00079 struct apr_pool_t *pool) 00080 { 00081 return mpf_dtmf_detector_create_ex(stream, 00082 stream->tx_event_descriptor ? MPF_DTMF_DETECTOR_BOTH : MPF_DTMF_DETECTOR_INBAND, 00083 pool); 00084 } 00085 00086 /** 00087 * Get DTMF digit from buffer of digits detected so far and remove it. 00088 * @param detector The detector. 00089 * @return DTMF character [0-9*#A-D] or NUL if the buffer is empty. 00090 */ 00091 MPF_DECLARE(char) mpf_dtmf_detector_digit_get(struct mpf_dtmf_detector_t *detector); 00092 00093 /** 00094 * Retrieve how many digits was lost due to full buffer. 00095 * @param detector The detector. 00096 * @return Number of lost digits. 00097 */ 00098 MPF_DECLARE(apr_size_t) mpf_dtmf_detector_digits_lost(const struct mpf_dtmf_detector_t *detector); 00099 00100 /** 00101 * Empty the buffer and reset detection states. 00102 * @param detector The detector. 00103 */ 00104 MPF_DECLARE(void) mpf_dtmf_detector_reset(struct mpf_dtmf_detector_t *detector); 00105 00106 /** 00107 * Detect DTMF digits in the frame. 00108 * @param detector The detector. 00109 * @param frame Frame object passed in stream_write(). 00110 */ 00111 MPF_DECLARE(void) mpf_dtmf_detector_get_frame( 00112 struct mpf_dtmf_detector_t *detector, 00113 const struct mpf_frame_t *frame); 00114 00115 /** 00116 * Free all resources associated with the detector. 00117 * @param detector The detector. 00118 */ 00119 MPF_DECLARE(void) mpf_dtmf_detector_destroy(struct mpf_dtmf_detector_t *detector); 00120 00121 APT_END_EXTERN_C 00122 00123 #endif /* MPF_DTMF_DETECTOR_H */