codecDescriptor.cpp 4.16 KB
Newer Older
1
/*
2
 *  Copyright (C) 2004-2007 Savoir-Faire Linux inc.
jpbl's avatar
jpbl committed
3
4
 *  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
 *  (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.
 */

#include <iostream>
23
#include <cstdlib>
jpbl's avatar
jpbl committed
24
25
26

#include "audiocodec.h"
#include "codecDescriptor.h"
27
/*#ifdef HAVE_SPEEX
jpbl's avatar
jpbl committed
28
 #include "CodecSpeex.h"
29
#endif*/
jpbl's avatar
jpbl committed
30

31
CodecDescriptor::CodecDescriptor() 
jpbl's avatar
jpbl committed
32
{
33
34
35
36
  init();
//#ifdef HAVE_SPEEX
  //_codecMap[PAYLOAD_CODEC_SPEEX] = new CodecSpeex(PAYLOAD_CODEC_SPEEX); // TODO: this is a variable payload!
//#endif
jpbl's avatar
jpbl committed
37
38
}

Emmanuel Milou's avatar
Emmanuel Milou committed
39
40
41
void
CodecDescriptor::init()
{
42
43
44
45
46
47
48
  // init list of all codecs supported codecs
  _codecMap[PAYLOAD_CODEC_ULAW] = "PCMU";
  _codecMap[PAYLOAD_CODEC_GSM] = "GSM";
  _codecMap[PAYLOAD_CODEC_ALAW] = "PCMA";
  _codecMap[PAYLOAD_CODEC_ILBC_20] = "iLBC";


Emmanuel Milou's avatar
Emmanuel Milou committed
49
50
}

51

52
53
std::string&
CodecDescriptor::getCodecName(CodecType payload)
jpbl's avatar
jpbl committed
54
55
56
57
58
{
  CodecMap::iterator iter = _codecMap.find(payload);
  if (iter!=_codecMap.end()) {
    return (iter->second);
  }
59
  //return std::string("");
jpbl's avatar
jpbl committed
60
61
}

62
bool 
63
CodecDescriptor::isSupported(CodecType payload) 
jpbl's avatar
jpbl committed
64
65
66
{
  CodecMap::iterator iter = _codecMap.begin();
  while(iter!=_codecMap.end()) {
67
68
69
70
71
      if (iter->first == payload) {
	// codec is already in the map --> nothing to do
	_debug("Codec with payload %i already in the map\n", payload);
        //break;
        return true;
jpbl's avatar
jpbl committed
72
73
74
      }
    iter++;
  }
75
   return false;
jpbl's avatar
jpbl committed
76
}
77
78

void 
79
CodecDescriptor::removeCodec(CodecType payload)
80
81
82
{
  CodecMap::iterator iter = _codecMap.begin();
  while(iter!=_codecMap.end()) {
83
      if (iter->first == payload) {
84
85
	_debug("Codec %s removed from the list", getCodecName(payload).data());
	_codecMap.erase(iter);
86
87
88
89
90
91
92
        break;
      }
    iter++;
  }
	
}

93
94
95
96
97
void
CodecDescriptor::addCodec(CodecType payload)
{
}

98
99
100
101
double 
CodecDescriptor::getBitRate(CodecType payload)
{
  switch(payload){
102
103
104
    case PAYLOAD_CODEC_ULAW: 
      return 64;
    case PAYLOAD_CODEC_ALAW: 
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
      return 64;
    case PAYLOAD_CODEC_GSM:
      return 13.3;
    case PAYLOAD_CODEC_ILBC_20:
      return 15.2;
    case PAYLOAD_CODEC_ILBC_30:
      return 15.2;

  }
  return -1;
}

double 
CodecDescriptor::getBandwidthPerCall(CodecType payload)
{
  switch(payload){
121
122
123
    case PAYLOAD_CODEC_ULAW:
      return 80;
    case PAYLOAD_CODEC_ALAW:
124
125
126
127
128
129
130
131
132
133
134
135
136
137
      return 80;
    case PAYLOAD_CODEC_GSM:
      return 28.6;
    case PAYLOAD_CODEC_ILBC_20:
      return 30.8;
  }
  return -1;

}

int
CodecDescriptor::getSampleRate(CodecType payload)
{
  switch(payload){
138
139
140
141
142
143
144
145
    case PAYLOAD_CODEC_ULAW:
      printf("PAYLOAD = %i\n", payload);
      return 8000;
    case PAYLOAD_CODEC_ALAW:
      printf("PAYLOAD = %i\n", payload);
      return 8000;
    case PAYLOAD_CODEC_GSM:
      printf("PAYLOAD = %i\n", payload);
146
      return 8000;
147
148
149
150
151
    case PAYLOAD_CODEC_ILBC_20:
      printf("PAYLOAD = %i\n", payload);
      return 8000;
    default:
      return -1;
152
  }
153
 return -1;
154
}
155
156
157

void
CodecDescriptor::saveActiveCodecs(const std::vector<std::string>& list)
158
{
159
160
161
162
163
164
165
166
167
168
169
170
  _codecOrder.clear();
  // list contains the ordered payload of active codecs picked by the user
  // we used the CodecOrder vector to save the order.
  int i=0;
  int payload;
  size_t size = list.size();
  while(i<size)
  {
    payload = std::atoi(list[i].data());
    _codecOrder.push_back((CodecType)payload);
    i++;
  }
171
}
172

173