summaryrefslogtreecommitdiffstats
path: root/src/audio/rtp_telephone_event.cpp
blob: a076531701d706be603734d9f519b030ccb72991 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
    Copyright (C) 2005-2009  Michel de Boer <michel@twinklephone.com>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include "cassert"
#include "rtp_telephone_event.h"
#include <netinet/in.h>

void t_rtp_telephone_event::set_event(unsigned char _event) {
	event = _event;
}

void t_rtp_telephone_event::set_volume(unsigned char _volume) {
	volume = _volume;
}

void t_rtp_telephone_event::set_reserved(bool _reserved) {
	reserved = _reserved;
}

void t_rtp_telephone_event::set_end(bool _end) {
	end = _end;
}

void t_rtp_telephone_event::set_duration(unsigned short _duration) {
	duration = htons(_duration);
}

unsigned char t_rtp_telephone_event::get_event(void) const {
	return event;
}

unsigned char t_rtp_telephone_event::get_volume(void) const {
	return volume;
}

bool t_rtp_telephone_event::get_reserved(void) const {
	return reserved;
}

bool t_rtp_telephone_event::get_end(void) const {
	return end;
}

unsigned short t_rtp_telephone_event::get_duration(void) const {
	return ntohs(duration);
}

unsigned char 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);
}

char dtmf_ev2char(unsigned char ev) {
	if (ev <= TEL_EV_DTMF_9) {
		return ev + '0' - TEL_EV_DTMF_0;
	}
	if (ev >= TEL_EV_DTMF_A && ev <= TEL_EV_DTMF_D) {
	  	return ev + 'A' - TEL_EV_DTMF_A;
	}
	if (ev == TEL_EV_DTMF_STAR) return '*';
	if (ev == TEL_EV_DTMF_POUND) return '#';
	assert(false);
}