codecDescriptor.h 4.1 KB
Newer Older
1
/*
jpbl's avatar
jpbl committed
2
3
4
 *  Copyright (C) 2004-2005 Savoir-Faire Linux inc.
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
 *  Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com>
5
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
jpbl's avatar
jpbl committed
6
7
8
 *                                                                              
 *  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
9
 *  the Free Software Foundation; either version 3 of the License, or
jpbl's avatar
jpbl committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 *  (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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */


#ifndef __CODEC_DESCRIPTOR_H__
#define __CODEC_DESCRIPTOR_H__

#include <string>
#include <map>
28
#include <vector>
jpbl's avatar
jpbl committed
29

30
#include "../global.h"
jpbl's avatar
jpbl committed
31
32
33
34
35
36
37
38
39
40
41
typedef enum {
// http://www.iana.org/assignments/rtp-parameters
// http://www.gnu.org/software/ccrtp/doc/refman/html/formats_8h.html#a0
// 0 PCMU A 8000 1 [RFC3551]
  PAYLOAD_CODEC_ULAW = 0, 
// 3 GSM  A 8000 1 [RFC3551]
  PAYLOAD_CODEC_GSM = 3,
// 8 PCMA A 8000 1 [RFC3551]
  PAYLOAD_CODEC_ALAW = 8,
// http://www.ietf.org/rfc/rfc3952.txt
// 97 iLBC/8000
42
43
  PAYLOAD_CODEC_ILBC_20 = 97,
  PAYLOAD_CODEC_ILBC_30 = 98,
jpbl's avatar
jpbl committed
44
45
46
47
48
49
50
51
52
// http://www.speex.org/drafts/draft-herlein-speex-rtp-profile-00.txt
//  97 speex/8000
// http://support.xten.com/viewtopic.php?p=8684&sid=3367a83d01fdcad16c7459a79859b08e
// 100 speex/16000
  PAYLOAD_CODEC_SPEEX = 110
} CodecType;

#include "audiocodec.h"

53
54
/* A codec is identified by its payload. A payload is associated with a name. */ 
typedef std::map<CodecType, std::string> CodecMap;
55
typedef std::vector<CodecType> CodecOrder;
56
57

class CodecDescriptor {
jpbl's avatar
jpbl committed
58
59
60
61
public:
  /**
   * Initialize all codec 
   */
62
63
64
  CodecDescriptor();
  ~CodecDescriptor() {};
  CodecMap& getCodecMap() { return _codecMap; }
65
  CodecOrder& getActiveCodecs() { return _codecOrder; }
jpbl's avatar
jpbl committed
66
67
68
69
70

  /**
   * Get codec with is associated payload
   * @param payload the payload associated with the payload
   *                same as getPayload()
71
   * @return the name of the codec
jpbl's avatar
jpbl committed
72
   */
73
  std::string& getCodecName(CodecType payload);
jpbl's avatar
jpbl committed
74

Emmanuel Milou's avatar
Emmanuel Milou committed
75
76
  void init();

jpbl's avatar
jpbl committed
77
  /**
78
79
80
81
   * Check in the map codec if the specified codec is supported 
   * @param payload unique identifier of a codec (RFC)
   * @return true if the codec specified is supported
   * 	     false otherwise
jpbl's avatar
jpbl committed
82
   */
83
84
85
86
87
88
89
90
91
  bool isSupported(CodecType payload);

 /**
  * Remove the codec with payload payload from the list
  * @param payload the codec to erase
  */ 
  void removeCodec(CodecType payload);

 /**
92
  * Add a codec in the list.
93
94
95
96
  * @param payload the codec to add
  */
  void addCodec(CodecType payload);

97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
 /**
  * Get the bit rate of the specified codec.
  * @param payload The payload of the codec
  * @return double The bit rate 
  */  
  double getBitRate(CodecType payload);

 /**
  * Get the bandwidth for one call with the specified codec.
  * The value has been calculated with the further information:
  * RTp communication, SIP protocol (the value with IAX2 is very close), no RTCP, one simultaneous call, for one channel (the incoming one).
  * @param payload The payload of the codec 
  * @return double The bandwidth
  */
  double getBandwidthPerCall(CodecType payload);


 /**
  * Get the clock rate of the specified codec
  * @param payload The payload of the codec
  * @return int The clock rate of the specified codec
  */
  int getSampleRate(CodecType payload);
120
121
122
123
124
125
126

/**
 * Set the order of codecs by their payload
 * @param list The ordered list sent by DBus
 */
 void saveActiveCodecs(const std::vector<std::string>& list);
 
jpbl's avatar
jpbl committed
127
128
private:
  CodecMap _codecMap;
129
  CodecOrder _codecOrder;
jpbl's avatar
jpbl committed
130
131
132
};

#endif // __CODEC_DESCRIPTOR_H__