3
* Copyright 2004--2007, Google Inc.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
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.
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.
28
#ifndef TALK_SESSION_PHONE_CODEC_H_
29
#define TALK_SESSION_PHONE_CODEC_H_
34
#include "talk/session/phone/constants.h"
38
typedef std::map<std::string, std::string> CodecParameterMap;
46
// Creates a codec with the given parameters.
47
Codec(int id, const std::string& name, int clockrate, int preference)
51
preference(preference) {
54
// Creates an empty codec.
55
Codec() : id(0), clockrate(0), preference(0) {}
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;
61
static bool Preferable(const Codec& first, const Codec& other) {
62
return first.preference > other.preference;
65
Codec& operator=(const Codec& c) {
66
this->id = c.id; // id is reserved in objective-c
68
clockrate = c.clockrate;
69
preference = c.preference;
73
bool operator==(const Codec& c) const {
74
return this->id == c.id && // id is reserved in objective-c
76
clockrate == c.clockrate &&
77
preference == c.preference;
80
bool operator!=(const Codec& c) const {
85
struct AudioCodec : public Codec {
88
CodecParameterMap params;
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),
97
// Creates an empty codec.
98
AudioCodec() : Codec(), bitrate(0), channels(0) {}
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;
104
static bool Preferable(const AudioCodec& first, const AudioCodec& other) {
105
return first.preference > other.preference;
108
std::string ToString() const;
110
AudioCodec& operator=(const AudioCodec& c) {
111
this->id = c.id; // id is reserved in objective-c
113
clockrate = c.clockrate;
115
channels = c.channels;
116
preference = c.preference;
121
bool operator==(const AudioCodec& c) const {
122
return this->id == c.id && // id is reserved in objective-c
124
clockrate == c.clockrate &&
125
bitrate == c.bitrate &&
126
channels == c.channels &&
127
preference == c.preference &&
131
bool operator!=(const AudioCodec& c) const {
132
return !(*this == c);
136
struct VideoCodec : public Codec {
140
CodecParameterMap params;
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),
150
// Creates an empty codec.
156
clockrate = kVideoCodecClockrate;
159
static bool Preferable(const VideoCodec& first, const VideoCodec& other) {
160
return first.preference > other.preference;
163
std::string ToString() const;
165
VideoCodec& operator=(const VideoCodec& c) {
166
this->id = c.id; // id is reserved in objective-c
168
clockrate = c.clockrate;
171
framerate = c.framerate;
172
preference = c.preference;
177
bool operator==(const VideoCodec& c) const {
178
return this->id == c.id && // id is reserved in objective-c
180
clockrate == c.clockrate &&
182
height == c.height &&
183
framerate == c.framerate &&
184
preference == c.preference &&
188
bool operator!=(const VideoCodec& c) const {
189
return !(*this == c);
193
struct DataCodec : public Codec {
194
DataCodec(int id, const std::string& name, int preference)
195
: Codec(id, name, kDataCodecClockrate, preference) {
198
DataCodec() : Codec() {
199
clockrate = kDataCodecClockrate;
202
std::string ToString() const;
205
struct VideoEncoderConfig {
206
static const int kDefaultMaxThreads = -1;
207
static const int kDefaultCpuProfile = -1;
211
num_threads(kDefaultMaxThreads),
212
cpu_profile(kDefaultCpuProfile) {
215
VideoEncoderConfig(const VideoCodec& c)
217
num_threads(kDefaultMaxThreads),
218
cpu_profile(kDefaultCpuProfile) {
221
VideoEncoderConfig(const VideoCodec& c, int t, int p)
227
VideoEncoderConfig& operator=(const VideoEncoderConfig& config) {
228
max_codec = config.max_codec;
229
num_threads = config.num_threads;
230
cpu_profile = config.cpu_profile;
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;
240
bool operator!=(const VideoEncoderConfig& config) const {
241
return !(*this == config);
244
VideoCodec max_codec;
249
} // namespace cricket
251
#endif // TALK_SESSION_PHONE_CODEC_H_