UniMRCP  1.3.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
mpf_dtmf_detector.h
Go to the documentation of this file.
1 /*
2  * Copyright 2009-2010 Tomas Valenta, Arsen Chaloyan
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Id: mpf_dtmf_detector.h 1474 2010-02-07 20:51:47Z achaloyan $
17  */
18 
19 #ifndef MPF_DTMF_DETECTOR_H
20 #define MPF_DTMF_DETECTOR_H
21 
22 /**
23  * @file mpf_dtmf_detector.h
24  * @brief DTMF detector
25  *
26  * Detector of DTMF tones sent both out-of-band (RFC4733) and in-band (audio).
27  */
28 
29 #include "apr.h"
30 #include "apr_pools.h"
31 #include "apt.h"
32 #include "mpf_frame.h"
33 #include "mpf_stream.h"
34 
36 
37 /** DTMF detector band */
39  /** Detect tones in-band */
41  /** Detect named events out-of-band */
43  /** Detect both in-band and out-of-band digits */
46 
47 /** Opaque MPF DTMF detector structure definition */
49 
50 
51 /**
52  * Create MPF DTMF detector (advanced).
53  * @param stream A stream to get digits from.
54  * @param band One of:
55  * - MPF_DTMF_DETECTOR_INBAND: detect audible tones only
56  * - MPF_DTMF_DETECTOR_OUTBAND: detect out-of-band named-events only
57  * - MPF_DTMF_DETECTOR_BOTH: detect digits in both bands if supported by
58  * stream. When out-of-band digit arrives, in-band detection is turned off.
59  * @param pool Memory pool to allocate DTMF detector from.
60  * @return The object or NULL on error.
61  * @see mpf_dtmf_detector_create
62  */
64  const struct mpf_audio_stream_t *stream,
65  enum mpf_dtmf_detector_band_e band,
66  struct apr_pool_t *pool);
67 
68 /**
69  * Create MPF DTMF detector (simple). Calls mpf_dtmf_detector_create_ex
70  * with band = MPF_DTMF_DETECTOR_BOTH if out-of-band supported by the stream,
71  * MPF_DTMF_DETECTOR_INBAND otherwise.
72  * @param stream A stream to get digits from.
73  * @param pool Memory pool to allocate DTMF detector from.
74  * @return The object or NULL on error.
75  * @see mpf_dtmf_detector_create_ex
76  */
77 static APR_INLINE struct mpf_dtmf_detector_t *mpf_dtmf_detector_create(
78  const struct mpf_audio_stream_t *stream,
79  struct apr_pool_t *pool)
80 {
81  return mpf_dtmf_detector_create_ex(stream,
82  stream->tx_event_descriptor ? MPF_DTMF_DETECTOR_BOTH : MPF_DTMF_DETECTOR_INBAND,
83  pool);
84 }
85 
86 /**
87  * Get DTMF digit from buffer of digits detected so far and remove it.
88  * @param detector The detector.
89  * @return DTMF character [0-9*#A-D] or NUL if the buffer is empty.
90  */
92 
93 /**
94  * Retrieve how many digits was lost due to full buffer.
95  * @param detector The detector.
96  * @return Number of lost digits.
97  */
98 MPF_DECLARE(apr_size_t) mpf_dtmf_detector_digits_lost(const struct mpf_dtmf_detector_t *detector);
99 
100 /**
101  * Empty the buffer and reset detection states.
102  * @param detector The detector.
103  */
105 
106 /**
107  * Detect DTMF digits in the frame.
108  * @param detector The detector.
109  * @param frame Frame object passed in stream_write().
110  */
112  struct mpf_dtmf_detector_t *detector,
113  const struct mpf_frame_t *frame);
114 
115 /**
116  * Free all resources associated with the detector.
117  * @param detector The detector.
118  */
120 
122 
123 #endif /* MPF_DTMF_DETECTOR_H */