diff --git a/talk/media/base/codec.cc b/talk/media/base/codec.cc index e4ab540a2..cd98b76a9 100644 --- a/talk/media/base/codec.cc +++ b/talk/media/base/codec.cc @@ -89,6 +89,39 @@ bool FeedbackParams::HasDuplicateEntries() const { return false; } +Codec::Codec(int id, const std::string& name, int clockrate, int preference) + : id(id), + name(name), + clockrate(clockrate), + preference(preference) { +} + +Codec::Codec() : id(0), clockrate(0), preference(0) { +} + +Codec::Codec(const Codec& c) = default; + +Codec::~Codec() = default; + +Codec& Codec::operator=(const Codec& c) { + this->id = c.id; // id is reserved in objective-c + name = c.name; + clockrate = c.clockrate; + preference = c.preference; + params = c.params; + feedback_params = c.feedback_params; + return *this; +} + +bool Codec::operator==(const Codec& c) const { + return this->id == c.id && // id is reserved in objective-c + name == c.name && + clockrate == c.clockrate && + preference == c.preference && + params == c.params && + feedback_params == c.feedback_params; +} + bool Codec::Matches(const Codec& codec) const { // Match the codec id/name based on the typical static/dynamic name rules. // Matching is case-insensitive. @@ -135,6 +168,37 @@ void Codec::IntersectFeedbackParams(const Codec& other) { feedback_params.Intersect(other.feedback_params); } +AudioCodec::AudioCodec(int pt, + const std::string& nm, + int cr, + int br, + int cs, + int pr) + : Codec(pt, nm, cr, pr), + bitrate(br), + channels(cs) { +} + +AudioCodec::AudioCodec() + : Codec(), + bitrate(0), + channels(0) { +} + +AudioCodec::AudioCodec(const AudioCodec& c) = default; + +AudioCodec& AudioCodec::operator=(const AudioCodec& c) { + Codec::operator=(c); + bitrate = c.bitrate; + channels = c.channels; + return *this; +} + +bool AudioCodec::operator==(const AudioCodec& c) const { + return clockrate == c.clockrate && bitrate == c.bitrate && + Codec::operator==(c); +} + bool AudioCodec::Matches(const AudioCodec& codec) const { // If a nonzero clockrate is specified, it must match the actual clockrate. // If a nonzero bitrate is specified, it must match the actual bitrate, @@ -166,6 +230,37 @@ std::string VideoCodec::ToString() const { return os.str(); } +VideoCodec::VideoCodec(int pt, + const std::string& nm, + int w, + int h, + int fr, + int pr) + : Codec(pt, nm, kVideoCodecClockrate, pr), + width(w), + height(h), + framerate(fr) { +} + +VideoCodec::VideoCodec() : Codec(), width(0), height(0), framerate(0) { + clockrate = kVideoCodecClockrate; +} + +VideoCodec::VideoCodec(const VideoCodec& c) = default; + +VideoCodec& VideoCodec::operator=(const VideoCodec& c) { + Codec::operator=(c); + width = c.width; + height = c.height; + framerate = c.framerate; + return *this; +} + +bool VideoCodec::operator==(const VideoCodec& c) const { + return width == c.width && height == c.height && framerate == c.framerate && + Codec::operator==(c); +} + VideoCodec VideoCodec::CreateRtxCodec(int rtx_payload_type, int associated_payload_type) { VideoCodec rtx_codec(rtx_payload_type, kRtxCodecName, 0, 0, 0, 0); @@ -215,6 +310,18 @@ bool VideoCodec::ValidateCodecFormat() const { return true; } +DataCodec::DataCodec(int id, const std::string& name, int preference) + : Codec(id, name, kDataCodecClockrate, preference) { +} + +DataCodec::DataCodec() : Codec() { + clockrate = kDataCodecClockrate; +} + +DataCodec::DataCodec(const DataCodec& c) = default; + +DataCodec& DataCodec::operator=(const DataCodec& c) = default; + std::string DataCodec::ToString() const { std::ostringstream os; os << "DataCodec[" << id << ":" << name << "]"; diff --git a/talk/media/base/codec.h b/talk/media/base/codec.h index 861962058..f30af15ce 100644 --- a/talk/media/base/codec.h +++ b/talk/media/base/codec.h @@ -86,15 +86,11 @@ struct Codec { FeedbackParams feedback_params; // Creates a codec with the given parameters. - Codec(int id, const std::string& name, int clockrate, int preference) - : id(id), - name(name), - clockrate(clockrate), - preference(preference) { - } - + Codec(int id, const std::string& name, int clockrate, int preference); // Creates an empty codec. - Codec() : id(0), clockrate(0), preference(0) {} + Codec(); + Codec(const Codec& c); + ~Codec(); // Indicates if this codec is compatible with the specified codec. bool Matches(const Codec& codec) const; @@ -121,24 +117,9 @@ struct Codec { // and |other| are kept. void IntersectFeedbackParams(const Codec& other); - Codec& operator=(const Codec& c) { - this->id = c.id; // id is reserved in objective-c - name = c.name; - clockrate = c.clockrate; - preference = c.preference; - params = c.params; - feedback_params = c.feedback_params; - return *this; - } + Codec& operator=(const Codec& c); - bool operator==(const Codec& c) const { - return this->id == c.id && // id is reserved in objective-c - name == c.name && - clockrate == c.clockrate && - preference == c.preference && - params == c.params && - feedback_params == c.feedback_params; - } + bool operator==(const Codec& c) const; bool operator!=(const Codec& c) const { return !(*this == c); @@ -150,14 +131,11 @@ struct AudioCodec : public Codec { int channels; // Creates a codec with the given parameters. - AudioCodec(int pt, const std::string& nm, int cr, int br, int cs, int pr) - : Codec(pt, nm, cr, pr), - bitrate(br), - channels(cs) { - } - + AudioCodec(int pt, const std::string& nm, int cr, int br, int cs, int pr); // Creates an empty codec. - AudioCodec() : Codec(), bitrate(0), channels(0) {} + AudioCodec(); + AudioCodec(const AudioCodec& c); + ~AudioCodec() = default; // Indicates if this codec is compatible with the specified codec. bool Matches(const AudioCodec& codec) const; @@ -168,28 +146,9 @@ struct AudioCodec : public Codec { std::string ToString() const; - AudioCodec& operator=(const AudioCodec& c) { - this->id = c.id; // id is reserved in objective-c - name = c.name; - clockrate = c.clockrate; - bitrate = c.bitrate; - channels = c.channels; - preference = c.preference; - params = c.params; - feedback_params = c.feedback_params; - return *this; - } + AudioCodec& operator=(const AudioCodec& c); - bool operator==(const AudioCodec& c) const { - return this->id == c.id && // id is reserved in objective-c - name == c.name && - clockrate == c.clockrate && - bitrate == c.bitrate && - channels == c.channels && - preference == c.preference && - params == c.params && - feedback_params == c.feedback_params; - } + bool operator==(const AudioCodec& c) const; bool operator!=(const AudioCodec& c) const { return !(*this == c); @@ -202,21 +161,11 @@ struct VideoCodec : public Codec { int framerate; // Creates a codec with the given parameters. - VideoCodec(int pt, const std::string& nm, int w, int h, int fr, int pr) - : Codec(pt, nm, kVideoCodecClockrate, pr), - width(w), - height(h), - framerate(fr) { - } - + VideoCodec(int pt, const std::string& nm, int w, int h, int fr, int pr); // Creates an empty codec. - VideoCodec() - : Codec(), - width(0), - height(0), - framerate(0) { - clockrate = kVideoCodecClockrate; - } + VideoCodec(); + VideoCodec(const VideoCodec& c); + ~VideoCodec() = default; static bool Preferable(const VideoCodec& first, const VideoCodec& other) { return first.preference > other.preference; @@ -224,30 +173,9 @@ struct VideoCodec : public Codec { std::string ToString() const; - VideoCodec& operator=(const VideoCodec& c) { - this->id = c.id; // id is reserved in objective-c - name = c.name; - clockrate = c.clockrate; - width = c.width; - height = c.height; - framerate = c.framerate; - preference = c.preference; - params = c.params; - feedback_params = c.feedback_params; - return *this; - } + VideoCodec& operator=(const VideoCodec& c); - bool operator==(const VideoCodec& c) const { - return this->id == c.id && // id is reserved in objective-c - name == c.name && - clockrate == c.clockrate && - width == c.width && - height == c.height && - framerate == c.framerate && - preference == c.preference && - params == c.params && - feedback_params == c.feedback_params; - } + bool operator==(const VideoCodec& c) const; bool operator!=(const VideoCodec& c) const { return !(*this == c); @@ -271,13 +199,11 @@ struct VideoCodec : public Codec { }; struct DataCodec : public Codec { - DataCodec(int id, const std::string& name, int preference) - : Codec(id, name, kDataCodecClockrate, preference) { - } + DataCodec(int id, const std::string& name, int preference); + DataCodec(); + DataCodec(const DataCodec& c); - DataCodec() : Codec() { - clockrate = kDataCodecClockrate; - } + DataCodec& operator=(const DataCodec& c); std::string ToString() const; };