~ubuntu-branches/ubuntu/vivid/ekiga/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/engine/protocol/codec-description.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kilian Krause
  • Date: 2011-07-17 00:24:50 UTC
  • mfrom: (5.1.5 upstream) (7.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110717002450-ytg3wsrc1ptd3153
Tags: 3.3.1-1
* New upstream release.
 - Required libpt-dev 2.10 and libopal-dev 3.10
* Fix debian/watch to catch new version
* Remove libnotify0.7.patch - included upstream
* Add libboost-dev and libboost-signals-dev to Build-Depends
* debian/rules: Don't install *.la files for new internal shared libs
* Fix Vcs URIs to point to correct desktop/experimental/ekiga tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * Ekiga -- A VoIP and Video-Conferencing application
 
4
 * Copyright (C) 2000-2009 Damien Sandras <dsandras@seconix.com>
 
5
 
 
6
 * This program is free software; you can  redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or (at
 
9
 * your option) any later version. This program is distributed in the hope
 
10
 * that it will be useful, but WITHOUT ANY WARRANTY; without even the
 
11
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
12
 * See the GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License along
 
15
 * with this program; if not, write to the Free Software Foundation, Inc.,
 
16
 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
17
 *
 
18
 * Ekiga is licensed under the GPL license and as a special exception, you
 
19
 * have permission to link or otherwise combine this program with the
 
20
 * programs OPAL, OpenH323 and PWLIB, and distribute the combination, without
 
21
 * applying the requirements of the GNU GPL to the OPAL, OpenH323 and PWLIB
 
22
 * programs, as long as you do follow the requirements of the GNU GPL for all
 
23
 * the rest of the software thus combined.
 
24
 */
 
25
 
 
26
 
 
27
/*
 
28
 *                         codec-description.cpp  -  description
 
29
 *                         ------------------------------------------
 
30
 *   begin                : written in January 2008 by Damien Sandras
 
31
 *   copyright            : (c) 2008 by Damien Sandras
 
32
 *   description          : declaration of the interface of a codec description.
 
33
 *
 
34
 */
 
35
 
 
36
#include <cstdlib>
 
37
#include <cstring>
 
38
#include <iostream>
 
39
#include <sstream>
 
40
 
 
41
#include "codec-description.h"
 
42
 
 
43
 
 
44
using namespace Ekiga;
 
45
 
 
46
CodecDescription::CodecDescription ()
 
47
  : rate (0), active (true), audio (false)
 
48
{
 
49
}
 
50
 
 
51
 
 
52
CodecDescription::CodecDescription (std::string _name,
 
53
                                    unsigned _rate,
 
54
                                    bool _audio,
 
55
                                    std::string _protocols,
 
56
                                    bool _active)
 
57
  : name (_name), rate (_rate), active (_active), audio (_audio)
 
58
{
 
59
  gchar** prots = NULL;
 
60
 
 
61
  prots = g_strsplit (_protocols.c_str (), ", ", -1);
 
62
 
 
63
  for (gchar** ptr = prots;
 
64
       *ptr != NULL;
 
65
       ptr++) {
 
66
 
 
67
    if ((*ptr)[0] != '\0') { // not the empty string
 
68
 
 
69
      protocols.push_back (*ptr);
 
70
    }
 
71
  }
 
72
 
 
73
  g_strfreev (prots);
 
74
 
 
75
  protocols.unique ();
 
76
  protocols.sort ();
 
77
}
 
78
 
 
79
 
 
80
CodecDescription::CodecDescription (std::string codec)
 
81
{
 
82
  int i = 0;
 
83
  gchar** vect = NULL;
 
84
  std::string tmp [5];
 
85
 
 
86
  vect = g_strsplit (codec.c_str (), "*", -1);
 
87
 
 
88
  for (gchar** ptr = vect; *ptr != NULL; ptr++) {
 
89
 
 
90
    tmp[i] = *ptr;
 
91
    i++;
 
92
  }
 
93
 
 
94
  g_strfreev (vect);
 
95
 
 
96
  if (i < 4)
 
97
    return;
 
98
 
 
99
  vect = g_strsplit (tmp[3].c_str (), " ", -1);
 
100
  for (gchar** ptr = vect; *ptr != NULL; ptr++) {
 
101
 
 
102
    protocols.push_back (*ptr);
 
103
  }
 
104
 
 
105
  g_strfreev (vect);
 
106
 
 
107
  name = tmp [0];
 
108
  rate = atoi (tmp [1].c_str ());
 
109
  audio = atoi (tmp [2].c_str ());
 
110
  active = atoi (tmp [4].c_str ());
 
111
}
 
112
 
 
113
 
 
114
std::string
 
115
CodecDescription::str ()
 
116
{
 
117
  std::stringstream val;
 
118
  std::stringstream proto;
 
119
 
 
120
  val << name << "*" << rate << "*" << audio << "*";
 
121
  protocols.sort ();
 
122
  for (std::list<std::string>::iterator iter = protocols.begin ();
 
123
       iter != protocols.end ();
 
124
       iter++) {
 
125
 
 
126
    if (iter != protocols.begin ())
 
127
      proto << " ";
 
128
 
 
129
    proto << *iter;
 
130
  }
 
131
  val << proto.str () << "*" << (active ? "1" : "0");
 
132
 
 
133
  return val.str ();
 
134
}
 
135
 
 
136
 
 
137
bool
 
138
CodecDescription::operator== (const CodecDescription & c) const
 
139
{
 
140
  CodecDescription d = c;
 
141
  CodecDescription e = (*this);
 
142
 
 
143
  return (e.str () == d.str ());
 
144
}
 
145
 
 
146
 
 
147
bool
 
148
CodecDescription::operator!= (const CodecDescription & c) const
 
149
{
 
150
  return (!((*this) == c));
 
151
}
 
152
 
 
153
 
 
154
CodecList::CodecList (GSList *codecs_config)
 
155
{
 
156
  GSList *codecs_config_it = NULL;
 
157
 
 
158
  codecs_config_it = (GSList *) codecs_config;
 
159
  while (codecs_config_it) {
 
160
 
 
161
 
 
162
    Ekiga::CodecDescription d = Ekiga::CodecDescription ((char *) codecs_config_it->data);
 
163
    if (!d.name.empty ())
 
164
      codecs.push_back (d);
 
165
 
 
166
    codecs_config_it = g_slist_next (codecs_config_it);
 
167
  }
 
168
}
 
169
 
 
170
 
 
171
CodecList::iterator
 
172
CodecList::begin ()
 
173
{
 
174
  return codecs.begin ();
 
175
}
 
176
 
 
177
CodecList::const_iterator CodecList::begin () const
 
178
{
 
179
  return codecs.begin ();
 
180
}
 
181
 
 
182
CodecList::iterator
 
183
CodecList::end ()
 
184
{
 
185
  return codecs.end ();
 
186
}
 
187
 
 
188
CodecList::const_iterator
 
189
CodecList::end () const
 
190
{
 
191
  return codecs.end ();
 
192
}
 
193
 
 
194
void
 
195
CodecList::append (CodecList& other)
 
196
{
 
197
  codecs.insert (end (), other.begin (), other.end ());
 
198
}
 
199
 
 
200
void
 
201
CodecList::append (CodecDescription& descr)
 
202
{
 
203
  codecs.push_back (descr);
 
204
}
 
205
 
 
206
void
 
207
CodecList::remove (iterator it)
 
208
{
 
209
  codecs.erase (it);
 
210
}
 
211
 
 
212
CodecList
 
213
CodecList::get_audio_list ()
 
214
{
 
215
  CodecList result;
 
216
 
 
217
  for (iterator it = begin ();
 
218
       it != end ();
 
219
       it++) {
 
220
 
 
221
    if ((*it).audio)
 
222
      result.codecs.push_back (*it);
 
223
  }
 
224
 
 
225
  return result;
 
226
}
 
227
 
 
228
 
 
229
CodecList
 
230
CodecList::get_video_list ()
 
231
{
 
232
  CodecList result;
 
233
 
 
234
  for (iterator it = begin ();
 
235
       it != end ();
 
236
       it++) {
 
237
 
 
238
    if (!(*it).audio)
 
239
      result.codecs.push_back (*it);
 
240
  }
 
241
 
 
242
  return result;
 
243
}
 
244
 
 
245
 
 
246
GSList*
 
247
CodecList::gslist ()
 
248
{
 
249
  GSList* result = NULL;
 
250
 
 
251
  for (iterator it = begin ();
 
252
       it != end ();
 
253
       it++) {
 
254
 
 
255
    result = g_slist_append (result, g_strdup ((*it).str ().c_str ()));
 
256
  }
 
257
 
 
258
  return result;
 
259
}
 
260
 
 
261
 
 
262
bool
 
263
CodecList::operator== (const CodecList & c) const
 
264
{
 
265
  CodecList::const_iterator it2 = c.begin ();
 
266
 
 
267
  if (codecs.size () != c.codecs.size ())
 
268
    return false;
 
269
 
 
270
  for (const_iterator it = begin ();
 
271
       it != end ();
 
272
       it++) {
 
273
 
 
274
    if ((*it) != (*it2))
 
275
      return false;
 
276
 
 
277
    it2++;
 
278
  }
 
279
 
 
280
  return true;
 
281
}
 
282
 
 
283
 
 
284
bool
 
285
CodecList::operator!= (const CodecList & c) const
 
286
{
 
287
  return (!(*this == c));
 
288
}
 
289
 
 
290
 
 
291
std::ostream&
 
292
operator<< (std::ostream & os, const CodecList & c)
 
293
{
 
294
  std::stringstream str;
 
295
  for (CodecList::const_iterator it = c.begin ();
 
296
       it != c.end ();
 
297
       it++) {
 
298
 
 
299
    if (it != c.begin ())
 
300
      str << " ; ";
 
301
 
 
302
    str << (*it).name;
 
303
  }
 
304
 
 
305
  return os << str.str ();
 
306
}