2013-07-10 00:45:36 +00:00
|
|
|
/*
|
|
|
|
* libjingle
|
|
|
|
* Copyright 2004 Google Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
|
|
|
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "talk/media/base/codec.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <sstream>
|
|
|
|
|
2014-07-29 17:36:52 +00:00
|
|
|
#include "webrtc/base/common.h"
|
|
|
|
#include "webrtc/base/logging.h"
|
|
|
|
#include "webrtc/base/stringencode.h"
|
|
|
|
#include "webrtc/base/stringutils.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
namespace cricket {
|
|
|
|
|
2014-06-20 20:57:42 +00:00
|
|
|
const int kMaxPayloadId = 127;
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
bool FeedbackParam::operator==(const FeedbackParam& other) const {
|
|
|
|
return _stricmp(other.id().c_str(), id().c_str()) == 0 &&
|
|
|
|
_stricmp(other.param().c_str(), param().c_str()) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FeedbackParams::operator==(const FeedbackParams& other) const {
|
|
|
|
return params_ == other.params_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FeedbackParams::Has(const FeedbackParam& param) const {
|
|
|
|
return std::find(params_.begin(), params_.end(), param) != params_.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FeedbackParams::Add(const FeedbackParam& param) {
|
|
|
|
if (param.id().empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Has(param)) {
|
|
|
|
// Param already in |this|.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
params_.push_back(param);
|
|
|
|
ASSERT(!HasDuplicateEntries());
|
|
|
|
}
|
|
|
|
|
|
|
|
void FeedbackParams::Intersect(const FeedbackParams& from) {
|
|
|
|
std::vector<FeedbackParam>::iterator iter_to = params_.begin();
|
|
|
|
while (iter_to != params_.end()) {
|
|
|
|
if (!from.Has(*iter_to)) {
|
|
|
|
iter_to = params_.erase(iter_to);
|
|
|
|
} else {
|
|
|
|
++iter_to;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FeedbackParams::HasDuplicateEntries() const {
|
|
|
|
for (std::vector<FeedbackParam>::const_iterator iter = params_.begin();
|
|
|
|
iter != params_.end(); ++iter) {
|
|
|
|
for (std::vector<FeedbackParam>::const_iterator found = iter + 1;
|
|
|
|
found != params_.end(); ++found) {
|
|
|
|
if (*found == *iter) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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
2015-02-19 17:55:18 +00:00
|
|
|
Codec::Codec(int id, const std::string& name, int clockrate, int preference)
|
2015-02-19 18:14:36 +00:00
|
|
|
: id(id), name(name), clockrate(clockrate), preference(preference) {
|
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
2015-02-19 17:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2015-02-19 18:14:36 +00:00
|
|
|
name == c.name && clockrate == c.clockrate &&
|
|
|
|
preference == c.preference && params == c.params &&
|
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
2015-02-19 17:55:18 +00:00
|
|
|
feedback_params == c.feedback_params;
|
|
|
|
}
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
bool Codec::Matches(const Codec& codec) const {
|
|
|
|
// Match the codec id/name based on the typical static/dynamic name rules.
|
|
|
|
// Matching is case-insensitive.
|
2015-02-23 21:28:22 +00:00
|
|
|
const int kMaxStaticPayloadId = 95;
|
2013-07-10 00:45:36 +00:00
|
|
|
return (codec.id <= kMaxStaticPayloadId) ?
|
|
|
|
(id == codec.id) : (_stricmp(name.c_str(), codec.name.c_str()) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Codec::GetParam(const std::string& name, std::string* out) const {
|
|
|
|
CodecParameterMap::const_iterator iter = params.find(name);
|
|
|
|
if (iter == params.end())
|
|
|
|
return false;
|
|
|
|
*out = iter->second;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Codec::GetParam(const std::string& name, int* out) const {
|
|
|
|
CodecParameterMap::const_iterator iter = params.find(name);
|
|
|
|
if (iter == params.end())
|
|
|
|
return false;
|
2014-07-29 17:36:52 +00:00
|
|
|
return rtc::FromString(iter->second, out);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Codec::SetParam(const std::string& name, const std::string& value) {
|
|
|
|
params[name] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Codec::SetParam(const std::string& name, int value) {
|
2014-07-29 17:36:52 +00:00
|
|
|
params[name] = rtc::ToString(value);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
2014-06-19 19:50:55 +00:00
|
|
|
bool Codec::RemoveParam(const std::string& name) {
|
|
|
|
return params.erase(name) == 1;
|
|
|
|
}
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
void Codec::AddFeedbackParam(const FeedbackParam& param) {
|
|
|
|
feedback_params.Add(param);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Codec::HasFeedbackParam(const FeedbackParam& param) const {
|
|
|
|
return feedback_params.Has(param);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Codec::IntersectFeedbackParams(const Codec& other) {
|
|
|
|
feedback_params.Intersect(other.feedback_params);
|
|
|
|
}
|
|
|
|
|
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
2015-02-19 17:55:18 +00:00
|
|
|
AudioCodec::AudioCodec(int pt,
|
|
|
|
const std::string& nm,
|
|
|
|
int cr,
|
|
|
|
int br,
|
|
|
|
int cs,
|
|
|
|
int pr)
|
2015-02-19 18:14:36 +00:00
|
|
|
: Codec(pt, nm, cr, pr), bitrate(br), channels(cs) {
|
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
2015-02-19 17:55:18 +00:00
|
|
|
}
|
|
|
|
|
2015-02-19 18:14:36 +00:00
|
|
|
AudioCodec::AudioCodec() : Codec(), bitrate(0), channels(0) {
|
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
2015-02-19 17:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2015-02-19 18:14:36 +00:00
|
|
|
return bitrate == c.bitrate && channels == c.channels && Codec::operator==(c);
|
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
2015-02-19 17:55:18 +00:00
|
|
|
}
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
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,
|
|
|
|
// unless the codec is VBR (0), where we just force the supplied value.
|
|
|
|
// The number of channels must match exactly, with the exception
|
|
|
|
// that channels=0 is treated synonymously as channels=1, per RFC
|
|
|
|
// 4566 section 6: " [The channels] parameter is OPTIONAL and may be
|
|
|
|
// omitted if the number of channels is one."
|
|
|
|
// Preference is ignored.
|
|
|
|
// TODO(juberti): Treat a zero clockrate as 8000Hz, the RTP default clockrate.
|
|
|
|
return Codec::Matches(codec) &&
|
|
|
|
((codec.clockrate == 0 /*&& clockrate == 8000*/) ||
|
|
|
|
clockrate == codec.clockrate) &&
|
|
|
|
(codec.bitrate == 0 || bitrate <= 0 || bitrate == codec.bitrate) &&
|
|
|
|
((codec.channels < 2 && channels < 2) || channels == codec.channels);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AudioCodec::ToString() const {
|
|
|
|
std::ostringstream os;
|
|
|
|
os << "AudioCodec[" << id << ":" << name << ":" << clockrate << ":" << bitrate
|
|
|
|
<< ":" << channels << ":" << preference << "]";
|
|
|
|
return os.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string VideoCodec::ToString() const {
|
|
|
|
std::ostringstream os;
|
|
|
|
os << "VideoCodec[" << id << ":" << name << ":" << width << ":" << height
|
|
|
|
<< ":" << framerate << ":" << preference << "]";
|
|
|
|
return os.str();
|
|
|
|
}
|
|
|
|
|
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
2015-02-19 17:55:18 +00:00
|
|
|
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) {
|
|
|
|
}
|
|
|
|
|
2015-04-21 20:24:50 +08:00
|
|
|
VideoCodec::VideoCodec(int pt, const std::string& nm)
|
|
|
|
: Codec(pt, nm, kVideoCodecClockrate, 0),
|
|
|
|
width(0),
|
|
|
|
height(0),
|
|
|
|
framerate(0) {
|
|
|
|
}
|
|
|
|
|
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
2015-02-19 17:55:18 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-05-13 11:07:01 +00:00
|
|
|
VideoCodec VideoCodec::CreateRtxCodec(int rtx_payload_type,
|
|
|
|
int associated_payload_type) {
|
|
|
|
VideoCodec rtx_codec(rtx_payload_type, kRtxCodecName, 0, 0, 0, 0);
|
|
|
|
rtx_codec.SetParam(kCodecParamAssociatedPayloadType, associated_payload_type);
|
|
|
|
return rtx_codec;
|
|
|
|
}
|
|
|
|
|
|
|
|
VideoCodec::CodecType VideoCodec::GetCodecType() const {
|
|
|
|
const char* payload_name = name.c_str();
|
|
|
|
if (_stricmp(payload_name, kRedCodecName) == 0) {
|
|
|
|
return CODEC_RED;
|
|
|
|
}
|
|
|
|
if (_stricmp(payload_name, kUlpfecCodecName) == 0) {
|
|
|
|
return CODEC_ULPFEC;
|
|
|
|
}
|
|
|
|
if (_stricmp(payload_name, kRtxCodecName) == 0) {
|
|
|
|
return CODEC_RTX;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CODEC_VIDEO;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VideoCodec::ValidateCodecFormat() const {
|
|
|
|
if (id < 0 || id > 127) {
|
|
|
|
LOG(LS_ERROR) << "Codec with invalid payload type: " << ToString();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (GetCodecType() != CODEC_VIDEO) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Video validation from here on.
|
|
|
|
|
|
|
|
if (width <= 0 || height <= 0) {
|
|
|
|
LOG(LS_ERROR) << "Codec with invalid dimensions: " << ToString();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
int min_bitrate = -1;
|
|
|
|
int max_bitrate = -1;
|
|
|
|
if (GetParam(kCodecParamMinBitrate, &min_bitrate) &&
|
|
|
|
GetParam(kCodecParamMaxBitrate, &max_bitrate)) {
|
|
|
|
if (max_bitrate < min_bitrate) {
|
|
|
|
LOG(LS_ERROR) << "Codec with max < min bitrate: " << ToString();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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
2015-02-19 17:55:18 +00:00
|
|
|
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;
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
std::string DataCodec::ToString() const {
|
|
|
|
std::ostringstream os;
|
|
|
|
os << "DataCodec[" << id << ":" << name << "]";
|
|
|
|
return os.str();
|
|
|
|
}
|
|
|
|
|
2015-04-21 20:24:50 +08:00
|
|
|
bool HasNack(const VideoCodec& codec) {
|
|
|
|
return codec.HasFeedbackParam(
|
|
|
|
FeedbackParam(kRtcpFbParamNack, kParamValueEmpty));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasRemb(const VideoCodec& codec) {
|
|
|
|
return codec.HasFeedbackParam(
|
|
|
|
FeedbackParam(kRtcpFbParamRemb, kParamValueEmpty));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CodecNamesEq(const std::string& name1, const std::string& name2) {
|
|
|
|
return _stricmp(name1.c_str(), name2.c_str()) == 0;
|
|
|
|
}
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
} // namespace cricket
|