diff options
author | Michal Kubecek <mkubecek@suse.cz> | 2016-05-20 09:48:18 +0200 |
---|---|---|
committer | Michal Kubecek <mkubecek@suse.cz> | 2016-05-20 09:48:18 +0200 |
commit | 77eeffe564e5a82b2b419ed8129e6d151d139086 (patch) | |
tree | c6dccee5b5e5902490bb228835bc4c8c862a7911 /src/audio | |
parent | 4627d49d5e2d75030c0200c7770ea258cdb42a69 (diff) | |
download | twinkle-77eeffe564e5a82b2b419ed8129e6d151d139086.tar twinkle-77eeffe564e5a82b2b419ed8129e6d151d139086.tar.gz twinkle-77eeffe564e5a82b2b419ed8129e6d151d139086.tar.lz twinkle-77eeffe564e5a82b2b419ed8129e6d151d139086.tar.xz twinkle-77eeffe564e5a82b2b419ed8129e6d151d139086.zip |
DTMF event type cleanup
DTMF event constants handling is a bit messy as three different types
are used in different source files, triggering various compiler
warnings. Introduce t_dtmf_ev type and use it everywhere, also replace
helper macros by inline functions.
Diffstat (limited to 'src/audio')
-rw-r--r-- | src/audio/audio_rx.cpp | 2 | ||||
-rw-r--r-- | src/audio/audio_rx.h | 4 | ||||
-rw-r--r-- | src/audio/dtmf_player.cpp | 6 | ||||
-rw-r--r-- | src/audio/dtmf_player.h | 8 | ||||
-rw-r--r-- | src/audio/freq_gen.cpp | 3 | ||||
-rw-r--r-- | src/audio/freq_gen.h | 4 | ||||
-rw-r--r-- | src/audio/rtp_telephone_event.cpp | 8 | ||||
-rw-r--r-- | src/audio/rtp_telephone_event.h | 25 |
8 files changed, 41 insertions, 19 deletions
diff --git a/src/audio/audio_rx.cpp b/src/audio/audio_rx.cpp index 9435ac4..e605fcf 100644 --- a/src/audio/audio_rx.cpp +++ b/src/audio/audio_rx.cpp @@ -657,7 +657,7 @@ void t_audio_rx::set_pt_telephone_event(int pt) { void t_audio_rx::push_dtmf(char digit, bool inband) { // Ignore invalid DTMF digits - if (!VALID_DTMF_SYM(digit)) return; + if (!is_valid_dtmf_sym(digit)) return; // Ignore DTMF tones in a 3-way conference if (is_3way) return; diff --git a/src/audio/audio_rx.h b/src/audio/audio_rx.h index 5db8762..88d8884 100644 --- a/src/audio/audio_rx.h +++ b/src/audio/audio_rx.h @@ -109,8 +109,8 @@ private: // Queue of DTMF tones to be sent struct t_dtmf_event { - uint8 dtmf_tone; - bool inband; + t_dtmf_ev dtmf_tone; + bool inband; }; queue<t_dtmf_event> dtmf_queue; diff --git a/src/audio/dtmf_player.cpp b/src/audio/dtmf_player.cpp index d3d5909..54c2580 100644 --- a/src/audio/dtmf_player.cpp +++ b/src/audio/dtmf_player.cpp @@ -30,7 +30,7 @@ ///////////////////////////////////////// t_dtmf_player::t_dtmf_player(t_audio_rx *audio_rx, t_audio_encoder *audio_encoder, - t_user *user_config, uint8 dtmf_tone, uint32 dtmf_timestamp, + t_user *user_config, t_dtmf_ev dtmf_tone, uint32 dtmf_timestamp, uint16 nsamples) : _audio_rx(audio_rx), _user_config(user_config), @@ -57,7 +57,7 @@ bool t_dtmf_player::finished(void) { t_rtp_event_dtmf_player::t_rtp_event_dtmf_player(t_audio_rx *audio_rx, t_audio_encoder *audio_encoder, t_user *user_config, - uint8 dtmf_tone, uint32 dtmf_timestamp, + t_dtmf_ev dtmf_tone, uint32 dtmf_timestamp, uint16 nsamples) : t_dtmf_player(audio_rx, audio_encoder, user_config, dtmf_tone, dtmf_timestamp, nsamples) @@ -125,7 +125,7 @@ uint16 t_rtp_event_dtmf_player::get_payload(uint8 *payload, t_inband_dtmf_player::t_inband_dtmf_player(t_audio_rx *audio_rx, t_audio_encoder *audio_encoder, t_user *user_config, - uint8 dtmf_tone, uint32 dtmf_timestamp, + t_dtmf_ev dtmf_tone, uint32 dtmf_timestamp, uint16 nsamples) : t_dtmf_player(audio_rx, audio_encoder, user_config, dtmf_tone, dtmf_timestamp, nsamples), diff --git a/src/audio/dtmf_player.h b/src/audio/dtmf_player.h index 0145289..de10bb1 100644 --- a/src/audio/dtmf_player.h +++ b/src/audio/dtmf_player.h @@ -41,14 +41,14 @@ protected: // Settings for current DTMF tone bool _dtmf_pause; // indicates if playing is in the pause phase bool _dtmf_stop; // indicates if DTMF should be stopped - uint8 _dtmf_current; // Currently played DTMF tone + t_dtmf_ev _dtmf_current; // Currently played DTMF tone uint32 _dtmf_timestamp; // RTP timestamp (start of tone) uint16 _dtmf_duration; // Duration of the tone currently played uint16 _nsamples; // number of samples taken per packet public: t_dtmf_player(t_audio_rx *audio_rx, t_audio_encoder *audio_encoder, - t_user *user_config, uint8 dtmf_tone, uint32 dtmf_timestamp, + t_user *user_config, t_dtmf_ev dtmf_tone, uint32 dtmf_timestamp, uint16 nsamples); virtual ~t_dtmf_player() {}; @@ -71,7 +71,7 @@ public: class t_rtp_event_dtmf_player : public t_dtmf_player { public: t_rtp_event_dtmf_player(t_audio_rx *audio_rx, t_audio_encoder *audio_encoder, - t_user *user_config, uint8 dtmf_tone, uint32 dtmf_timestamp, + t_user *user_config, t_dtmf_ev dtmf_tone, uint32 dtmf_timestamp, uint16 nsamples); virtual uint16 get_payload(uint8 *payload, uint16 payload_size, @@ -87,7 +87,7 @@ private: public: t_inband_dtmf_player(t_audio_rx *audio_rx, t_audio_encoder *audio_encoder, - t_user *user_config, uint8 dtmf_tone, uint32 dtmf_timestamp, + t_user *user_config, t_dtmf_ev dtmf_tone, uint32 dtmf_timestamp, uint16 nsamples); virtual uint16 get_payload(uint8 *payload, uint16 payload_size, diff --git a/src/audio/freq_gen.cpp b/src/audio/freq_gen.cpp index 5aad228..0ba669e 100644 --- a/src/audio/freq_gen.cpp +++ b/src/audio/freq_gen.cpp @@ -35,7 +35,7 @@ t_freq_gen::t_freq_gen(vector<uint16> frequencies, int8 db_level) { _amplitude = int16(pow(10.0, db_level / 20.0) * 32767 / _frequencies.size()); } -t_freq_gen::t_freq_gen(uint8 dtmf, int8 db_level) : _frequencies(2) +t_freq_gen::t_freq_gen(t_dtmf_ev dtmf, int8 db_level) : _frequencies(2) { assert(db_level <= 0); @@ -106,6 +106,7 @@ t_freq_gen::t_freq_gen(uint8 dtmf, int8 db_level) : _frequencies(2) break; default: assert(false); + _frequencies.clear(); } // dB = 20 * log(amplitude / 32768) diff --git a/src/audio/freq_gen.h b/src/audio/freq_gen.h index 6817baa..40818fa 100644 --- a/src/audio/freq_gen.h +++ b/src/audio/freq_gen.h @@ -28,6 +28,8 @@ #include <vector> #include <commoncpp/config.h> +#include "rtp_telephone_event.h" + using namespace std; class t_freq_gen { @@ -37,7 +39,7 @@ private: public: t_freq_gen(vector<uint16> frequencies, int8 db_level); - t_freq_gen(uint8 dtmf, int8 db_level); + t_freq_gen(t_dtmf_ev dtmf, int8 db_level); // Get sound sample on a particular timestamp in us. int16 get_sample(uint32 ts_usec) const; diff --git a/src/audio/rtp_telephone_event.cpp b/src/audio/rtp_telephone_event.cpp index a076531..b4f4c00 100644 --- a/src/audio/rtp_telephone_event.cpp +++ b/src/audio/rtp_telephone_event.cpp @@ -60,16 +60,18 @@ unsigned short t_rtp_telephone_event::get_duration(void) const { return ntohs(duration); } -unsigned char char2dtmf_ev(char sym) { +t_dtmf_ev char2dtmf_ev(char sym) { if (sym >= '0' && sym <= '9') return (sym - '0' + TEL_EV_DTMF_0); if (sym >= 'A' && sym <= 'D') return (sym - 'A' + TEL_EV_DTMF_A); if (sym >= 'a' && sym <= 'd') return (sym- 'a' + TEL_EV_DTMF_A); if (sym == '*') return TEL_EV_DTMF_STAR; if (sym == '#') return TEL_EV_DTMF_POUND; + assert(false); + return TEL_EV_DTMF_INVALID; } -char dtmf_ev2char(unsigned char ev) { +char dtmf_ev2char(t_dtmf_ev ev) { if (ev <= TEL_EV_DTMF_9) { return ev + '0' - TEL_EV_DTMF_0; } @@ -78,6 +80,8 @@ char dtmf_ev2char(unsigned char ev) { } if (ev == TEL_EV_DTMF_STAR) return '*'; if (ev == TEL_EV_DTMF_POUND) return '#'; + assert(false); + return '?'; } diff --git a/src/audio/rtp_telephone_event.h b/src/audio/rtp_telephone_event.h index 372504c..5f8d005 100644 --- a/src/audio/rtp_telephone_event.h +++ b/src/audio/rtp_telephone_event.h @@ -25,6 +25,8 @@ // RFC 2833 3.10 // DTMF events +typedef unsigned char t_dtmf_ev; + #define TEL_EV_DTMF_0 0 #define TEL_EV_DTMF_1 1 #define TEL_EV_DTMF_2 2 @@ -41,12 +43,25 @@ #define TEL_EV_DTMF_B 13 #define TEL_EV_DTMF_C 14 #define TEL_EV_DTMF_D 15 +#define TEL_EV_DTMF_INVALID ((t_dtmf_ev) 0xff) + +static inline bool is_valid_dtmf_ev(t_dtmf_ev ev) +{ + return (ev <= TEL_EV_DTMF_D); +} -#define VALID_DTMF_EV(ev) ( (ev) <= TEL_EV_DTMF_D ) -#define VALID_DTMF_SYM(s) ( ((s) >= '0' && (s) <= '9') || \ - ((s) >= 'a' && (s) <= 'd') || \ - ((s) >= 'A' && (s) <= 'D') || \ - (s) == '*' || (s) == '#' ) +static inline bool is_valid_dtmf_sym(char s) +{ + if (s >= '0' && s <= '9') + return true; + if (s >= 'a' && s <= 'd') + return true; + if (s >= 'A' && s <= 'D') + return true; + if (s == '*' || s == '#') + return true; + return false; +} // RFC 2833 3.5 // Payload format (in network order!!) |