~ubuntu-branches/debian/experimental/kopete/experimental

« back to all changes in this revision

Viewing changes to protocols/jabber/libjingle/talk/session/phone/codec.h

  • Committer: Package Import Robot
  • Author(s): Maximiliano Curia
  • Date: 2015-02-24 11:32:57 UTC
  • mfrom: (1.1.41 vivid)
  • Revision ID: package-import@ubuntu.com-20150224113257-gnupg4v7lzz18ij0
Tags: 4:14.12.2-1
* New upstream release (14.12.2).
* Bump Standards-Version to 3.9.6, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * libjingle
 
3
 * Copyright 2004--2007, Google Inc.
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions are met:
 
7
 *
 
8
 *  1. Redistributions of source code must retain the above copyright notice,
 
9
 *     this list of conditions and the following disclaimer.
 
10
 *  2. Redistributions in binary form must reproduce the above copyright notice,
 
11
 *     this list of conditions and the following disclaimer in the documentation
 
12
 *     and/or other materials provided with the distribution.
 
13
 *  3. The name of the author may not be used to endorse or promote products
 
14
 *     derived from this software without specific prior written permission.
 
15
 *
 
16
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 
17
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 
18
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
 
19
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
20
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
21
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 
22
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 
23
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 
24
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 
25
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
26
 */
 
27
 
 
28
#ifndef TALK_SESSION_PHONE_CODEC_H_
 
29
#define TALK_SESSION_PHONE_CODEC_H_
 
30
 
 
31
#include <map>
 
32
#include <string>
 
33
 
 
34
#include "talk/session/phone/constants.h"
 
35
 
 
36
namespace cricket {
 
37
 
 
38
typedef std::map<std::string, std::string> CodecParameterMap;
 
39
 
 
40
struct Codec {
 
41
  int id;
 
42
  std::string name;
 
43
  int clockrate;
 
44
  int preference;
 
45
 
 
46
  // Creates a codec with the given parameters.
 
47
  Codec(int id, const std::string& name, int clockrate, int preference)
 
48
      : id(id),
 
49
        name(name),
 
50
        clockrate(clockrate),
 
51
        preference(preference) {
 
52
  }
 
53
 
 
54
  // Creates an empty codec.
 
55
  Codec() : id(0), clockrate(0), preference(0) {}
 
56
 
 
57
  // Indicates if this codec is compatible with the specified codec.
 
58
  bool Matches(int id, const std::string& name) const;
 
59
  bool Matches(const Codec& codec) const;
 
60
 
 
61
  static bool Preferable(const Codec& first, const Codec& other) {
 
62
    return first.preference > other.preference;
 
63
  }
 
64
 
 
65
  Codec& operator=(const Codec& c) {
 
66
    this->id = c.id;  // id is reserved in objective-c
 
67
    name = c.name;
 
68
    clockrate = c.clockrate;
 
69
    preference = c.preference;
 
70
    return *this;
 
71
  }
 
72
 
 
73
  bool operator==(const Codec& c) const {
 
74
    return this->id == c.id &&  // id is reserved in objective-c
 
75
        name == c.name &&
 
76
        clockrate == c.clockrate &&
 
77
        preference == c.preference;
 
78
  }
 
79
 
 
80
  bool operator!=(const Codec& c) const {
 
81
    return !(*this == c);
 
82
  }
 
83
};
 
84
 
 
85
struct AudioCodec : public Codec {
 
86
  int bitrate;
 
87
  int channels;
 
88
  CodecParameterMap params;
 
89
 
 
90
  // Creates a codec with the given parameters.
 
91
  AudioCodec(int pt, const std::string& nm, int cr, int br, int cs, int pr)
 
92
      : Codec(pt, nm, cr, pr),
 
93
        bitrate(br),
 
94
        channels(cs) {
 
95
  }
 
96
 
 
97
  // Creates an empty codec.
 
98
  AudioCodec() : Codec(), bitrate(0), channels(0) {}
 
99
 
 
100
  // Indicates if this codec is compatible with the specified codec.
 
101
  bool Matches(int payload, const std::string& nm) const;
 
102
  bool Matches(const AudioCodec& codec) const;
 
103
 
 
104
  static bool Preferable(const AudioCodec& first, const AudioCodec& other) {
 
105
    return first.preference > other.preference;
 
106
  }
 
107
 
 
108
  std::string ToString() const;
 
109
 
 
110
  AudioCodec& operator=(const AudioCodec& c) {
 
111
    this->id = c.id;  // id is reserved in objective-c
 
112
    name = c.name;
 
113
    clockrate = c.clockrate;
 
114
    bitrate = c.bitrate;
 
115
    channels = c.channels;
 
116
    preference =  c.preference;
 
117
    params = c.params;
 
118
    return *this;
 
119
  }
 
120
 
 
121
  bool operator==(const AudioCodec& c) const {
 
122
    return this->id == c.id &&  // id is reserved in objective-c
 
123
           name == c.name &&
 
124
           clockrate == c.clockrate &&
 
125
           bitrate == c.bitrate &&
 
126
           channels == c.channels &&
 
127
           preference == c.preference &&
 
128
           params == c.params;
 
129
  }
 
130
 
 
131
  bool operator!=(const AudioCodec& c) const {
 
132
    return !(*this == c);
 
133
  }
 
134
};
 
135
 
 
136
struct VideoCodec : public Codec {
 
137
  int width;
 
138
  int height;
 
139
  int framerate;
 
140
  CodecParameterMap params;
 
141
 
 
142
  // Creates a codec with the given parameters.
 
143
  VideoCodec(int pt, const std::string& nm, int w, int h, int fr, int pr)
 
144
      : Codec(pt, nm, kVideoCodecClockrate, pr),
 
145
        width(w),
 
146
        height(h),
 
147
        framerate(fr) {
 
148
  }
 
149
 
 
150
  // Creates an empty codec.
 
151
  VideoCodec()
 
152
      : Codec(),
 
153
        width(0),
 
154
        height(0),
 
155
        framerate(0) {
 
156
    clockrate = kVideoCodecClockrate;
 
157
  }
 
158
 
 
159
  static bool Preferable(const VideoCodec& first, const VideoCodec& other) {
 
160
    return first.preference > other.preference;
 
161
  }
 
162
 
 
163
  std::string ToString() const;
 
164
 
 
165
  VideoCodec& operator=(const VideoCodec& c) {
 
166
    this->id = c.id;  // id is reserved in objective-c
 
167
    name = c.name;
 
168
    clockrate = c.clockrate;
 
169
    width = c.width;
 
170
    height = c.height;
 
171
    framerate = c.framerate;
 
172
    preference =  c.preference;
 
173
    params = c.params;
 
174
    return *this;
 
175
  }
 
176
 
 
177
  bool operator==(const VideoCodec& c) const {
 
178
    return this->id == c.id &&  // id is reserved in objective-c
 
179
           name == c.name &&
 
180
           clockrate == c.clockrate &&
 
181
           width == c.width &&
 
182
           height == c.height &&
 
183
           framerate == c.framerate &&
 
184
           preference == c.preference &&
 
185
           params == c.params;
 
186
  }
 
187
 
 
188
  bool operator!=(const VideoCodec& c) const {
 
189
    return !(*this == c);
 
190
  }
 
191
};
 
192
 
 
193
struct DataCodec : public Codec {
 
194
  DataCodec(int id, const std::string& name, int preference)
 
195
      : Codec(id, name, kDataCodecClockrate, preference) {
 
196
  }
 
197
 
 
198
  DataCodec() : Codec() {
 
199
    clockrate = kDataCodecClockrate;
 
200
  }
 
201
 
 
202
  std::string ToString() const;
 
203
};
 
204
 
 
205
struct VideoEncoderConfig {
 
206
  static const int kDefaultMaxThreads = -1;
 
207
  static const int kDefaultCpuProfile = -1;
 
208
 
 
209
  VideoEncoderConfig()
 
210
      : max_codec(),
 
211
        num_threads(kDefaultMaxThreads),
 
212
        cpu_profile(kDefaultCpuProfile) {
 
213
  }
 
214
 
 
215
  VideoEncoderConfig(const VideoCodec& c)
 
216
      : max_codec(c),
 
217
        num_threads(kDefaultMaxThreads),
 
218
        cpu_profile(kDefaultCpuProfile) {
 
219
  }
 
220
 
 
221
  VideoEncoderConfig(const VideoCodec& c, int t, int p)
 
222
      : max_codec(c),
 
223
        num_threads(t),
 
224
        cpu_profile(p) {
 
225
  }
 
226
 
 
227
  VideoEncoderConfig& operator=(const VideoEncoderConfig& config) {
 
228
    max_codec = config.max_codec;
 
229
    num_threads = config.num_threads;
 
230
    cpu_profile = config.cpu_profile;
 
231
    return *this;
 
232
  }
 
233
 
 
234
  bool operator==(const VideoEncoderConfig& config) const {
 
235
    return max_codec == config.max_codec &&
 
236
           num_threads == config.num_threads &&
 
237
           cpu_profile == config.cpu_profile;
 
238
  }
 
239
 
 
240
  bool operator!=(const VideoEncoderConfig& config) const {
 
241
    return !(*this == config);
 
242
  }
 
243
 
 
244
  VideoCodec max_codec;
 
245
  int num_threads;
 
246
  int cpu_profile;
 
247
};
 
248
 
 
249
}  // namespace cricket
 
250
 
 
251
#endif  // TALK_SESSION_PHONE_CODEC_H_