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}
diff --git a/webrtc/media/base/codec.h b/webrtc/media/base/codec.h
index 2280082..ac85d1f 100644
--- a/webrtc/media/base/codec.h
+++ b/webrtc/media/base/codec.h
@@ -67,12 +67,6 @@
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 @@
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 {
diff --git a/webrtc/media/base/codec_unittest.cc b/webrtc/media/base/codec_unittest.cc
index 8dd2e44..77c1fd0 100644
--- a/webrtc/media/base/codec_unittest.cc
+++ b/webrtc/media/base/codec_unittest.cc
@@ -20,11 +20,19 @@
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 @@
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 @@
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);
diff --git a/webrtc/media/sctp/sctpdataengine.cc b/webrtc/media/sctp/sctpdataengine.cc
index 45dfad9..103aebd 100644
--- a/webrtc/media/sctp/sctpdataengine.cc
+++ b/webrtc/media/sctp/sctpdataengine.cc
@@ -971,9 +971,7 @@
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)) {