diff --git a/webrtc/api/webrtcsdp.cc b/webrtc/api/webrtcsdp.cc index d78112c168..69a1af28ad 100644 --- a/webrtc/api/webrtcsdp.cc +++ b/webrtc/api/webrtcsdp.cc @@ -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) { diff --git a/webrtc/media/base/codec.h b/webrtc/media/base/codec.h index 2280082c22..ac85d1fef4 100644 --- a/webrtc/media/base/codec.h +++ b/webrtc/media/base/codec.h @@ -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 { diff --git a/webrtc/media/base/codec_unittest.cc b/webrtc/media/base/codec_unittest.cc index 8dd2e44f00..77c1fd015f 100644 --- a/webrtc/media/base/codec_unittest.cc +++ b/webrtc/media/base/codec_unittest.cc @@ -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); diff --git a/webrtc/media/sctp/sctpdataengine.cc b/webrtc/media/sctp/sctpdataengine.cc index 45dfad9e05..103aebdd9b 100644 --- a/webrtc/media/sctp/sctpdataengine.cc +++ b/webrtc/media/sctp/sctpdataengine.cc @@ -971,9 +971,7 @@ static bool GetCodecIntParameter(const std::vector& 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)) {