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 <string>
32
33namespace cricket {
34
35struct AudioCodec {
36  int id;
37  std::string name;
38  int clockrate;
39  int bitrate;
40  int channels;
41
42  int preference;
43
44  // Creates a codec with the given parameters.
45  AudioCodec(int pt, const std::string& nm, int cr, int br, int cs, int pr)
46      : id(pt), name(nm), clockrate(cr), bitrate(br),
47        channels(cs), preference(pr) {}
48
49  // Creates an empty codec.
50  AudioCodec() : id(0), clockrate(0), bitrate(0), channels(0), preference(0) {}
51
52  // Indicates if this codec is compatible with the specified codec.
53  bool Matches(int payload, const std::string& nm) const;
54  bool Matches(const AudioCodec& codec) const;
55
56  static bool Preferable(const AudioCodec& first, const AudioCodec& other) {
57    return first.preference > other.preference;
58  }
59
60  std::string ToString() const;
61
62  AudioCodec& operator=(const AudioCodec& c) {
63    this->id = c.id;  // id is reserved in objective-c
64    name = c.name;
65    clockrate = c.clockrate;
66    bitrate = c.bitrate;
67    channels = c.channels;
68    preference =  c.preference;
69    return *this;
70  }
71
72  bool operator==(const AudioCodec& c) const {
73    return this->id == c.id &&  // id is reserved in objective-c
74           name == c.name &&
75           clockrate == c.clockrate &&
76           bitrate == c.bitrate &&
77           channels == c.channels &&
78           preference == c.preference;
79  }
80
81  bool operator!=(const AudioCodec& c) const {
82    return !(*this == c);
83  }
84};
85
86struct VideoCodec {
87  int id;
88  std::string name;
89  int width;
90  int height;
91  int framerate;
92
93  int preference;
94
95  // Creates a codec with the given parameters.
96  VideoCodec(int pt, const std::string& nm, int w, int h, int fr, int pr)
97      : id(pt), name(nm), width(w), height(h), framerate(fr), preference(pr) {}
98
99  // Creates an empty codec.
100  VideoCodec()
101      : id(0), width(0), height(0), framerate(0), preference(0) {}
102
103  bool Matches(int payload, const std::string& nm) const;
104  bool Matches(const VideoCodec& codec) const;
105
106  static bool Preferable(const VideoCodec& first, const VideoCodec& other) {
107    return first.preference > other.preference;
108  }
109
110  std::string ToString() const;
111
112  VideoCodec& operator=(const VideoCodec& c) {
113    this->id = c.id;  // id is reserved in objective-c
114    name = c.name;
115    width = c.width;
116    height = c.height;
117    framerate = c.framerate;
118    preference =  c.preference;
119    return *this;
120  }
121
122  bool operator==(const VideoCodec& c) const {
123    return this->id == c.id &&  // id is reserved in objective-c
124           name == c.name &&
125           width == c.width &&
126           height == c.height &&
127           framerate == c.framerate &&
128           preference == c.preference;
129  }
130
131  bool operator!=(const VideoCodec& c) const {
132    return !(*this == c);
133  }
134};
135
136struct VideoEncoderConfig {
137  static const int kDefaultMaxThreads = -1;
138  static const int kDefaultCpuProfile = -1;
139
140  VideoEncoderConfig()
141      : max_codec(),
142        num_threads(kDefaultMaxThreads),
143        cpu_profile(kDefaultCpuProfile) {
144  }
145
146  VideoEncoderConfig(const VideoCodec& c)
147      : max_codec(c),
148        num_threads(kDefaultMaxThreads),
149        cpu_profile(kDefaultCpuProfile) {
150  }
151
152  VideoEncoderConfig(const VideoCodec& c, int t, int p)
153      : max_codec(c),
154        num_threads(t),
155        cpu_profile(p) {
156  }
157
158  VideoEncoderConfig& operator=(const VideoEncoderConfig& config) {
159    max_codec = config.max_codec;
160    num_threads = config.num_threads;
161    cpu_profile = config.cpu_profile;
162    return *this;
163  }
164
165  bool operator==(const VideoEncoderConfig& config) const {
166    return max_codec == config.max_codec &&
167           num_threads == config.num_threads &&
168           cpu_profile == config.cpu_profile;
169  }
170
171  bool operator!=(const VideoEncoderConfig& config) const {
172    return !(*this == config);
173  }
174
175  VideoCodec max_codec;
176  int num_threads;
177  int cpu_profile;
178};
179
180}  // namespace cricket
181
182#endif  // TALK_SESSION_PHONE_CODEC_H_
183