Make webrtc 50 KB smaller by not inlining Codec.

The Codec class is a big class and objects of the Codec class are passed
around by value. That means that inlined operations would be duplicated
at many places, in particular inside STL.

By not inlining Codec methods, webrtc shrinks by 50 KB in
a Linux x64 clang build.

Total change: -54147 bytes
==========================
 +2810 - Source: /home/bratell/src/chromium/src/third_party/libjingle/source/talk/media/base/codec.cc - (gained 2920, lost 110)
 -1003 - Source: /home/bratell/src/chromium/src/third_party/libjingle/source/talk/media/base/codec.h - (gained 0, lost 1003)
 -1129 - Source: /home/bratell/src/chromium/src/third_party/libjingle/source/talk/media/sctp/sctpdataengine.cc - (gained 1660, lost 2789)
 -1190 - Source: /home/bratell/src/chromium/src/third_party/libjingle/source/talk/media/base/rtpdataengine.cc - (gained 1408, lost 2598)
 -1747 - Source: /home/bratell/src/chromium/src/third_party/libjingle/source/talk/session/media/mediasession.cc - (gained 803, lost 2550)
 -2141 - Source: /home/bratell/src/chromium/src/third_party/libjingle/source/talk/media/webrtc/webrtcvideoengine.cc - (gained 1679, lost 3820)
 -2250 - Source: /home/bratell/src/chromium/src/third_party/libjingle/source/talk/app/webrtc/webrtcsdp.cc - (gained 1224, lost 3474)
 -2927 - Source: /usr/include/c++/4.8/bits/stl_vector.h - (gained 0, lost 2927)
 -3729 - Source: /home/bratell/src/chromium/src/third_party/libjingle/source/talk/media/webrtc/webrtcvideoengine2.cc - (gained 10925, lost 14654)
 -6369 - Source: /usr/include/c++/4.8/bits/vector.tcc - (gained 0, lost 6369)
 -10582 - Source: /usr/include/c++/4.8/bits/stl_heap.h - (gained 0, lost 10582)
 -19324 - Source: /usr/include/c++/4.8/bits/stl_algo.h - (gained 743, lost 20067)

BUG=
R=juberti@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/40729005

Cr-Commit-Position: refs/heads/master@{#8436}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8436 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
guoweis@webrtc.org 2015-02-19 17:55:18 +00:00
parent e07710cc91
commit bc6961fe32
2 changed files with 129 additions and 96 deletions

View File

@ -89,6 +89,39 @@ bool FeedbackParams::HasDuplicateEntries() const {
return false; 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 { bool Codec::Matches(const Codec& codec) const {
// Match the codec id/name based on the typical static/dynamic name rules. // Match the codec id/name based on the typical static/dynamic name rules.
// Matching is case-insensitive. // Matching is case-insensitive.
@ -135,6 +168,37 @@ void Codec::IntersectFeedbackParams(const Codec& other) {
feedback_params.Intersect(other.feedback_params); 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 { bool AudioCodec::Matches(const AudioCodec& codec) const {
// If a nonzero clockrate is specified, it must match the actual clockrate. // If a nonzero clockrate is specified, it must match the actual clockrate.
// If a nonzero bitrate is specified, it must match the actual bitrate, // If a nonzero bitrate is specified, it must match the actual bitrate,
@ -166,6 +230,37 @@ std::string VideoCodec::ToString() const {
return os.str(); 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, VideoCodec VideoCodec::CreateRtxCodec(int rtx_payload_type,
int associated_payload_type) { int associated_payload_type) {
VideoCodec rtx_codec(rtx_payload_type, kRtxCodecName, 0, 0, 0, 0); VideoCodec rtx_codec(rtx_payload_type, kRtxCodecName, 0, 0, 0, 0);
@ -215,6 +310,18 @@ bool VideoCodec::ValidateCodecFormat() const {
return true; 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::string DataCodec::ToString() const {
std::ostringstream os; std::ostringstream os;
os << "DataCodec[" << id << ":" << name << "]"; os << "DataCodec[" << id << ":" << name << "]";

View File

@ -86,15 +86,11 @@ struct Codec {
FeedbackParams feedback_params; FeedbackParams feedback_params;
// Creates a codec with the given parameters. // Creates a codec with the given parameters.
Codec(int id, const std::string& name, int clockrate, int preference) Codec(int id, const std::string& name, int clockrate, int preference);
: id(id),
name(name),
clockrate(clockrate),
preference(preference) {
}
// Creates an empty codec. // 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. // Indicates if this codec is compatible with the specified codec.
bool Matches(const Codec& codec) const; bool Matches(const Codec& codec) const;
@ -121,24 +117,9 @@ struct Codec {
// and |other| are kept. // and |other| are kept.
void IntersectFeedbackParams(const Codec& other); void IntersectFeedbackParams(const Codec& other);
Codec& operator=(const Codec& c) { 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 operator==(const Codec& c) const { 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); return !(*this == c);
@ -150,14 +131,11 @@ struct AudioCodec : public Codec {
int channels; int channels;
// Creates a codec with the given parameters. // Creates a codec with the given parameters.
AudioCodec(int pt, const std::string& nm, int cr, int br, int cs, int pr) AudioCodec(int pt, const std::string& nm, int cr, int br, int cs, int pr);
: Codec(pt, nm, cr, pr),
bitrate(br),
channels(cs) {
}
// Creates an empty codec. // 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. // Indicates if this codec is compatible with the specified codec.
bool Matches(const AudioCodec& codec) const; bool Matches(const AudioCodec& codec) const;
@ -168,28 +146,9 @@ struct AudioCodec : public Codec {
std::string ToString() const; std::string ToString() const;
AudioCodec& operator=(const AudioCodec& c) { 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;
}
bool operator==(const AudioCodec& c) const { 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); return !(*this == c);
@ -202,21 +161,11 @@ struct VideoCodec : public Codec {
int framerate; int framerate;
// Creates a codec with the given parameters. // Creates a codec with the given parameters.
VideoCodec(int pt, const std::string& nm, int w, int h, int fr, int pr) 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) {
}
// Creates an empty codec. // Creates an empty codec.
VideoCodec() VideoCodec();
: Codec(), VideoCodec(const VideoCodec& c);
width(0), ~VideoCodec() = default;
height(0),
framerate(0) {
clockrate = kVideoCodecClockrate;
}
static bool Preferable(const VideoCodec& first, const VideoCodec& other) { static bool Preferable(const VideoCodec& first, const VideoCodec& other) {
return first.preference > other.preference; return first.preference > other.preference;
@ -224,30 +173,9 @@ struct VideoCodec : public Codec {
std::string ToString() const; std::string ToString() const;
VideoCodec& operator=(const VideoCodec& c) { 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;
}
bool operator==(const VideoCodec& c) const { 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); return !(*this == c);
@ -271,13 +199,11 @@ struct VideoCodec : public Codec {
}; };
struct DataCodec : public Codec { struct DataCodec : public Codec {
DataCodec(int id, const std::string& name, int preference) DataCodec(int id, const std::string& name, int preference);
: Codec(id, name, kDataCodecClockrate, preference) { DataCodec();
} DataCodec(const DataCodec& c);
DataCodec() : Codec() { DataCodec& operator=(const DataCodec& c);
clockrate = kDataCodecClockrate;
}
std::string ToString() const; std::string ToString() const;
}; };