1 /*
2  * Copyright (C) 2010 Stefan Sayer
3  * Copyright (C) 2011 Raphael Coeffic
4  *
5  * This file is part of SEMS, a free SIP media server.
6  *
7  * SEMS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version. This program is released under
11  * the GPL with the additional exemption that compiling, linking,
12  * and/or using OpenSSL is allowed.
13  *
14  * For a license to use the SEMS software under conditions
15  * other than those described here, or to purchase support for this
16  * software, please contact iptel.org by e-mail at the following addresses:
17  *    info@iptel.org
18  *
19  * SEMS is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27  */
28 
29 #ifndef _AmDtmfSender_h_
30 #define _AmDtmfSender_h_
31 
32 #include "AmThread.h"
33 
34 #include <queue>
35 using std::queue;
36 using std::pair;
37 
38 class AmRtpStream;
39 
40 class AmDtmfSender
41 {
42   // event, duration
43   typedef pair<int, unsigned int> Dtmf;
44 
45   enum sending_state_t {
46     DTMF_SEND_NONE,      // not sending event
47     DTMF_SEND_SENDING,   // sending event
48     DTMF_SEND_ENDING     // sending end of event
49   } sending_state;
50 
51   queue<Dtmf> send_queue;
52   AmMutex     send_queue_mut;
53 
54   Dtmf         current_send_dtmf;
55   unsigned int current_send_dtmf_ts;
56   int          send_dtmf_end_repeat;
57 
58 public:
59   AmDtmfSender();
60 
61   /** Add a DTMF event to the send queue */
62   void queueEvent(int event, unsigned int duration_ms, unsigned int sample_rate);
63 
64   /** Processes the send queue according to the timestamp */
65   void sendPacket(unsigned int ts, unsigned int remote_pt, AmRtpStream* stream);
66 };
67 
68 #endif
69