Refactoring: Declare cricket::Codec constructors protected.
This makes it obvious that cricket::Codec should not be instantiated; only subclasses should be instantiated. BUG=none Review-Url: https://codereview.webrtc.org/2546363002 Cr-Commit-Position: refs/heads/master@{#15468}
This commit is contained in:
parent
06a6984935
commit
b39db841b6
@ -2385,8 +2385,7 @@ bool VerifyCodec(const cricket::Codec& codec) {
|
||||
// Codec has not been populated correctly unless the name has been set. This
|
||||
// can happen if an SDP has an fmtp or rtcp-fb with a payload type but doesn't
|
||||
// have a corresponding "rtpmap" line.
|
||||
cricket::Codec default_codec;
|
||||
return default_codec.name != codec.name;
|
||||
return !codec.name.empty();
|
||||
}
|
||||
|
||||
bool VerifyAudioCodecs(const AudioContentDescription* audio_desc) {
|
||||
|
||||
@ -67,12 +67,6 @@ struct Codec {
|
||||
CodecParameterMap params;
|
||||
FeedbackParams feedback_params;
|
||||
|
||||
// Creates a codec with the given parameters.
|
||||
Codec(int id, const std::string& name, int clockrate);
|
||||
// Creates an empty codec.
|
||||
Codec();
|
||||
Codec(const Codec& c);
|
||||
Codec(Codec&& c);
|
||||
virtual ~Codec();
|
||||
|
||||
// Indicates if this codec is compatible with the specified codec.
|
||||
@ -106,6 +100,15 @@ struct Codec {
|
||||
bool operator!=(const Codec& c) const {
|
||||
return !(*this == c);
|
||||
}
|
||||
|
||||
protected:
|
||||
// A Codec can't be created without a subclass.
|
||||
// Creates a codec with the given parameters.
|
||||
Codec(int id, const std::string& name, int clockrate);
|
||||
// Creates an empty codec.
|
||||
Codec();
|
||||
Codec(const Codec& c);
|
||||
Codec(Codec&& c);
|
||||
};
|
||||
|
||||
struct AudioCodec : public Codec {
|
||||
|
||||
@ -20,11 +20,19 @@ using cricket::kCodecParamAssociatedPayloadType;
|
||||
using cricket::kCodecParamMaxBitrate;
|
||||
using cricket::kCodecParamMinBitrate;
|
||||
|
||||
class TestCodec : public Codec {
|
||||
public:
|
||||
TestCodec(int id, const std::string name, int clockrate)
|
||||
: Codec(id, name, clockrate) {}
|
||||
TestCodec() : Codec() {}
|
||||
TestCodec(const TestCodec& c) : Codec(c) {}
|
||||
};
|
||||
|
||||
TEST(CodecTest, TestCodecOperators) {
|
||||
Codec c0(96, "D", 1000);
|
||||
TestCodec c0(96, "D", 1000);
|
||||
c0.SetParam("a", 1);
|
||||
|
||||
Codec c1 = c0;
|
||||
TestCodec c1 = c0;
|
||||
EXPECT_TRUE(c1 == c0);
|
||||
|
||||
int param_value0;
|
||||
@ -48,8 +56,8 @@ TEST(CodecTest, TestCodecOperators) {
|
||||
c1.SetParam("a", 2);
|
||||
EXPECT_TRUE(c0 != c1);
|
||||
|
||||
Codec c5;
|
||||
Codec c6(0, "", 0);
|
||||
TestCodec c5;
|
||||
TestCodec c6(0, "", 0);
|
||||
EXPECT_TRUE(c5 == c6);
|
||||
}
|
||||
|
||||
@ -220,11 +228,11 @@ TEST(CodecTest, TestIntersectFeedbackParams) {
|
||||
const FeedbackParam b2("b", "2");
|
||||
const FeedbackParam b3("b", "3");
|
||||
const FeedbackParam c3("c", "3");
|
||||
Codec c1;
|
||||
TestCodec c1;
|
||||
c1.AddFeedbackParam(a1); // Only match with c2.
|
||||
c1.AddFeedbackParam(b2); // Same param different values.
|
||||
c1.AddFeedbackParam(c3); // Not in c2.
|
||||
Codec c2;
|
||||
TestCodec c2;
|
||||
c2.AddFeedbackParam(a1);
|
||||
c2.AddFeedbackParam(b3);
|
||||
|
||||
|
||||
@ -971,9 +971,7 @@ static bool GetCodecIntParameter(const std::vector<DataCodec>& codecs,
|
||||
int id, const std::string& name,
|
||||
const std::string& param, int* dest) {
|
||||
std::string value;
|
||||
Codec match_pattern;
|
||||
match_pattern.id = id;
|
||||
match_pattern.name = name;
|
||||
DataCodec match_pattern(id, name);
|
||||
for (size_t i = 0; i < codecs.size(); ++i) {
|
||||
if (codecs[i].Matches(match_pattern)) {
|
||||
if (codecs[i].GetParam(param, &value)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user