2
* Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc.
3
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 3 of the License, or
8
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
* Additional permission under GNU GPL version 3 section 7:
20
* If you modify this program, or any covered work, by linking or
21
* combining it with the OpenSSL project's OpenSSL library (or a
22
* modified version of that library), containing parts covered by the
23
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
24
* grants you additional permission to convey the resulting work.
25
* Corresponding Source for a non-source form of such a combination
26
* shall include the source code for the parts of OpenSSL used as well
27
* as that of the covered work.
30
#ifndef AUDIORTPRECORDHANDLER_H_
31
#define AUDIORTPRECORDHANDLER_H_
33
#include "sip/sipcall.h"
34
#include "audio/codecs/audiocodec.h"
35
#include "audio/samplerateconverter.h"
36
#include "audio/audioprocessing.h"
37
#include "audio/noisesuppress.h"
38
#include "managerimpl.h"
39
#include <ccrtp/rtp.h>
44
// Frequency (in packet number)
45
#define RTP_TIMESTAMP_RESET_FREQ 100
47
// Factor use to increase volume in fade in
48
#define FADEIN_STEP_SIZE 4;
50
static const int schedulingTimeout = 10000;
51
static const int expireTimeout = 100000;
53
// G.722 VoIP is typically carried in RTP payload type 9.[2] Note that IANA records the clock rate for type 9 G.722 as 8 kHz
54
// (instead of 16 kHz), RFC3551[3] clarifies that this is due to a historical error and is retained in order to maintain backward
55
// compatibility. Consequently correct implementations represent the value 8,000 where required but encode and decode audio at 16 kHz.
56
static const int g722PayloadType = 9;
57
static const int g722RtpClockRate = 8000;
58
static const int g722RtpTimeincrement = 160;
61
timeval2microtimeout (const timeval& t)
63
return ( (t.tv_sec * 1000000ul) + t.tv_usec);
66
class AudioRtpSessionException: public std::exception
68
virtual const char* what() const throw() {
69
return "AudioRtpSessionException occured";
73
typedef struct DtmfEvent {
74
ost::RTPPacket::RFC2833Payload payload;
79
typedef list<DtmfEvent *> EventQueue;
82
* Class meant to store internal data in order to encode/decode,
83
* resample, process, and packetize audio streams. This class should not be
84
* handled directly. Use AudioRtpRecorrdHandeler
92
AudioCodec *_audioCodec;
93
int _codecPayloadType;
94
bool _hasDynamicPayloadType;
95
SFLDataFormat *_micData;
96
SFLDataFormat *_micDataConverted;
97
unsigned char *_micDataEncoded;
98
SFLDataFormat *_spkrDataDecoded;
99
SFLDataFormat *_spkrDataConverted;
100
SamplerateConverter *_converter;
101
int _audioLayerSampleRate;
102
int _codecSampleRate;
103
int _audioLayerFrameSize;
105
int _converterSamplingRate;
106
EventQueue _eventQueue;
107
bool _micFadeInComplete;
108
bool _spkrFadeInComplete;
109
SFLDataFormat _micAmplFactor;
110
SFLDataFormat _spkrAmplFactor;
111
AudioProcessing *_audioProcess;
112
NoiseSuppress *_noiseSuppress;
117
class AudioRtpRecordHandler
120
AudioRtpRecordHandler (ManagerImpl *manager, SIPCall *ca);
121
~AudioRtpRecordHandler();
124
* Set rtp media for this session
127
void setRtpMedia (AudioCodec* audioCodec);
130
AudioCodec *getAudioCodec (void) {
131
return _audioRtpRecord._audioCodec;
134
int getCodecPayloadType (void) {
135
return _audioRtpRecord._codecPayloadType;
138
int getCodecSampleRate (void) {
139
return _audioRtpRecord._codecSampleRate;
142
int getCodecFrameSize (void) {
143
return _audioRtpRecord._codecFrameSize;
146
int getHasDynamicPayload (void) {
147
return _audioRtpRecord._hasDynamicPayloadType;
150
int getAudioLayerFrameSize (void) {
151
return _audioRtpRecord._audioLayerFrameSize;
154
int getAudioLayerSampleRate (void) {
155
return _audioRtpRecord._audioLayerSampleRate;
158
EventQueue *getEventQueue (void) {
159
return &_audioRtpRecord._eventQueue;
162
int getEventQueueSize (void) {
163
return _audioRtpRecord._eventQueue.size();
166
SFLDataFormat *getMicData (void) {
167
return _audioRtpRecord._micData;
170
SFLDataFormat *getMicDataConverted (void) {
171
return _audioRtpRecord._micDataConverted;
174
unsigned char *getMicDataEncoded (void) {
175
return _audioRtpRecord._micDataEncoded;
179
inline float computeCodecFrameSize (int codecSamplePerFrame, int codecClockRate) {
180
return ( (float) codecSamplePerFrame * 1000.0) / (float) codecClockRate;
183
int computeNbByteAudioLayer (float codecFrameSize) {
184
return (int) ( ( (float) _audioRtpRecord._codecSampleRate * codecFrameSize * sizeof (SFLDataFormat)) / 1000.0);
190
* Allocate memory for RTP buffers and fill them with zeros
191
* @prereq Session codec needs to be initialized prior calling this method
193
void initBuffers (void);
195
void initNoiseSuppress (void);
198
* Encode audio data from mainbuffer
200
int processDataEncode (void);
203
* Decode audio data received from peer
205
void processDataDecode (unsigned char * spkrData, unsigned int size);
208
* Ramp In audio data to avoid audio click from peer
210
bool fadeIn (SFLDataFormat *audio, int size, SFLDataFormat *factor);
212
void putDtmfEvent (int digit);
216
AudioRtpRecord _audioRtpRecord;
224
#endif /* AUDIORTPRECORD_H_ */