Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(457)

Side by Side Diff: webrtc/modules/audio_coding/neteq/decoder_database.h

Issue 2276913002: DecoderDatabase: Made several methods nonvirtual to minimize mockable interface (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 23 matching lines...) Expand all
34 kCodecNotSupported = -2, 34 kCodecNotSupported = -2,
35 kInvalidSampleRate = -3, 35 kInvalidSampleRate = -3,
36 kDecoderExists = -4, 36 kDecoderExists = -4,
37 kDecoderNotFound = -5, 37 kDecoderNotFound = -5,
38 kInvalidPointer = -6 38 kInvalidPointer = -6
39 }; 39 };
40 40
41 // Class that stores decoder info in the database. 41 // Class that stores decoder info in the database.
42 class DecoderInfo { 42 class DecoderInfo {
43 public: 43 public:
44 DecoderInfo(NetEqDecoder ct, const std::string& nm); 44 DecoderInfo(NetEqDecoder ct, const std::string& nm,
45 rtc::scoped_refptr<AudioDecoderFactory> factory = nullptr);
45 DecoderInfo(NetEqDecoder ct, 46 DecoderInfo(NetEqDecoder ct,
46 const std::string& nm, 47 const std::string& nm,
47 AudioDecoder* ext_dec); 48 AudioDecoder* ext_dec);
48 DecoderInfo(DecoderInfo&&); 49 DecoderInfo(DecoderInfo&&);
49 ~DecoderInfo(); 50 ~DecoderInfo();
50 51
51 // Get the AudioDecoder object, creating it first if necessary. 52 // Get the AudioDecoder object, creating it first if necessary.
52 AudioDecoder* GetDecoder(AudioDecoderFactory* factory); 53 AudioDecoder* GetDecoder() const;
53 54
54 // Delete the AudioDecoder object, unless it's external. (This means we can 55 // Delete the AudioDecoder object, unless it's external. (This means we can
55 // always recreate it later if we need it.) 56 // always recreate it later if we need it.)
56 void DropDecoder() { decoder_.reset(); } 57 void DropDecoder() const { decoder_.reset(); }
kwiberg-webrtc 2016/08/24 22:28:49 Hmm. Why did you make these two const? It seems li
ossu 2016/08/25 10:23:47 My reasoning is as follows: - Some parts of NetEq
kwiberg-webrtc 2016/08/25 10:49:53 Acknowledged.
57 58
58 int SampleRateHz() const { 59 int SampleRateHz() const {
59 RTC_DCHECK_EQ(1, !!decoder_ + !!external_decoder_ + !!cng_decoder_); 60 RTC_DCHECK_EQ(1, !!decoder_ + !!external_decoder_ + !!cng_decoder_);
60 return decoder_ ? decoder_->SampleRateHz() 61 return decoder_ ? decoder_->SampleRateHz()
61 : external_decoder_ ? external_decoder_->SampleRateHz() 62 : external_decoder_ ? external_decoder_->SampleRateHz()
62 : cng_decoder_->sample_rate_hz; 63 : cng_decoder_->sample_rate_hz;
63 } 64 }
64 65
66 // Returns true if |code_type| is comfort noise.
kwiberg-webrtc 2016/08/24 22:28:49 Spelling.
ossu 2016/08/25 10:23:47 Ah! Now I see it! Thanks. :)
67 bool IsComfortNoise() const;
68
69 // Returns true if |code_type| is DTMF.
kwiberg-webrtc 2016/08/24 22:28:49 Spelling.
ossu 2016/08/25 10:23:47 Acknowledged.
70 bool IsDtmf() const;
71
72 // Returns true if |codec_type| is RED.
73 bool IsRed() const;
74
65 const NetEqDecoder codec_type; 75 const NetEqDecoder codec_type;
66 const std::string name; 76 const std::string name;
67 77
68 private: 78 private:
69 const rtc::Optional<SdpAudioFormat> audio_format_; 79 const rtc::Optional<SdpAudioFormat> audio_format_;
70 std::unique_ptr<AudioDecoder> decoder_; 80 rtc::scoped_refptr<AudioDecoderFactory> factory_;
ossu 2016/08/24 11:15:20 If we can rely on DecoderInfo not outliving the re
kwiberg-webrtc 2016/08/24 22:28:49 I think you can have it as a reference. Mutable re
ossu 2016/08/25 10:23:47 Yeah, but then I'd pass it as a pointer to the con
kwiberg-webrtc 2016/08/25 10:49:53 Passing a raw pointer clearly doesn't transfer own
ossu 2016/08/25 13:43:04 Agreed. But since it's not consistently like that
81 mutable std::unique_ptr<AudioDecoder> decoder_;
71 82
72 // Set iff this is an external decoder. 83 // Set iff this is an external decoder.
73 AudioDecoder* const external_decoder_; 84 AudioDecoder* const external_decoder_;
74 85
75 // Set iff this is a comfort noise decoder. 86 // Set iff this is a comfort noise decoder.
76 struct CngDecoder { 87 struct CngDecoder {
77 static rtc::Optional<CngDecoder> Create(NetEqDecoder ct); 88 static rtc::Optional<CngDecoder> Create(NetEqDecoder ct);
78 int sample_rate_hz; 89 int sample_rate_hz;
79 }; 90 };
80 const rtc::Optional<CngDecoder> cng_decoder_; 91 const rtc::Optional<CngDecoder> cng_decoder_;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 // Returns a pointer to the DecoderInfo struct for |rtp_payload_type|. If 133 // Returns a pointer to the DecoderInfo struct for |rtp_payload_type|. If
123 // no decoder is registered with that |rtp_payload_type|, NULL is returned. 134 // no decoder is registered with that |rtp_payload_type|, NULL is returned.
124 virtual const DecoderInfo* GetDecoderInfo(uint8_t rtp_payload_type) const; 135 virtual const DecoderInfo* GetDecoderInfo(uint8_t rtp_payload_type) const;
125 136
126 // Returns one RTP payload type associated with |codec_type|, or 137 // Returns one RTP payload type associated with |codec_type|, or
127 // kDecoderNotFound if no entry exists for that value. Note that one 138 // kDecoderNotFound if no entry exists for that value. Note that one
128 // |codec_type| may be registered with several RTP payload types, and the 139 // |codec_type| may be registered with several RTP payload types, and the
129 // method may return any of them. 140 // method may return any of them.
130 virtual uint8_t GetRtpPayloadType(NetEqDecoder codec_type) const; 141 virtual uint8_t GetRtpPayloadType(NetEqDecoder codec_type) const;
131 142
132 // Returns a pointer to the AudioDecoder object associated with
133 // |rtp_payload_type|, or NULL if none is registered. If the AudioDecoder
134 // object does not exist for that decoder, the object is created.
135 virtual AudioDecoder* GetDecoder(uint8_t rtp_payload_type);
136
137 // Returns true if |rtp_payload_type| is registered as a |codec_type|.
138 virtual bool IsType(uint8_t rtp_payload_type,
139 NetEqDecoder codec_type) const;
140
141 // Returns true if |rtp_payload_type| is registered as comfort noise.
142 virtual bool IsComfortNoise(uint8_t rtp_payload_type) const;
143
144 // Returns true if |rtp_payload_type| is registered as DTMF.
145 virtual bool IsDtmf(uint8_t rtp_payload_type) const;
146
147 // Returns true if |rtp_payload_type| is registered as RED.
148 virtual bool IsRed(uint8_t rtp_payload_type) const;
149
150 // Sets the active decoder to be |rtp_payload_type|. If this call results in a 143 // Sets the active decoder to be |rtp_payload_type|. If this call results in a
151 // change of active decoder, |new_decoder| is set to true. The previous active 144 // change of active decoder, |new_decoder| is set to true. The previous active
152 // decoder's AudioDecoder object is deleted. 145 // decoder's AudioDecoder object is deleted.
153 virtual int SetActiveDecoder(uint8_t rtp_payload_type, bool* new_decoder); 146 virtual int SetActiveDecoder(uint8_t rtp_payload_type, bool* new_decoder);
154 147
155 // Returns the current active decoder, or NULL if no active decoder exists. 148 // Returns the current active decoder, or NULL if no active decoder exists.
156 virtual AudioDecoder* GetActiveDecoder(); 149 virtual AudioDecoder* GetActiveDecoder();
157 150
158 // Sets the active comfort noise decoder to be |rtp_payload_type|. If this 151 // Sets the active comfort noise decoder to be |rtp_payload_type|. If this
159 // call results in a change of active comfort noise decoder, the previous 152 // call results in a change of active comfort noise decoder, the previous
160 // active decoder's AudioDecoder object is deleted. 153 // active decoder's AudioDecoder object is deleted.
161 virtual int SetActiveCngDecoder(uint8_t rtp_payload_type); 154 virtual int SetActiveCngDecoder(uint8_t rtp_payload_type);
162 155
163 // Returns the current active comfort noise decoder, or NULL if no active 156 // Returns the current active comfort noise decoder, or NULL if no active
164 // comfort noise decoder exists. 157 // comfort noise decoder exists.
165 virtual ComfortNoiseDecoder* GetActiveCngDecoder(); 158 virtual ComfortNoiseDecoder* GetActiveCngDecoder();
166 159
167 // Returns kOK if all packets in |packet_list| carry payload types that are 160 // Returns kOK if all packets in |packet_list| carry payload types that are
168 // registered in the database. Otherwise, returns kDecoderNotFound. 161 // registered in the database. Otherwise, returns kDecoderNotFound.
169 virtual int CheckPayloadTypes(const PacketList& packet_list) const; 162 virtual int CheckPayloadTypes(const PacketList& packet_list) const;
170 163
164 // The following are utility methods: they will look up DecoderInfo through
ossu 2016/08/24 11:15:20 I moved these down so that everything virtual is k
165 // GetDecoderInfo and call the respective method on that info object, if it
166 // exists.
167
168 // Returns a pointer to the AudioDecoder object associated with
169 // |rtp_payload_type|, or NULL if none is registered. If the AudioDecoder
170 // object does not exist for that decoder, the object is created.
171 AudioDecoder* GetDecoder(uint8_t rtp_payload_type);
172
173 // Returns true if |rtp_payload_type| is registered as a |codec_type|.
174 bool IsType(uint8_t rtp_payload_type, NetEqDecoder codec_type) const;
175
176 // Returns true if |rtp_payload_type| is registered as comfort noise.
177 bool IsComfortNoise(uint8_t rtp_payload_type) const;
178
179 // Returns true if |rtp_payload_type| is registered as DTMF.
180 bool IsDtmf(uint8_t rtp_payload_type) const;
181
182 // Returns true if |rtp_payload_type| is registered as RED.
183 bool IsRed(uint8_t rtp_payload_type) const;
184
171 private: 185 private:
172 typedef std::map<uint8_t, DecoderInfo> DecoderMap; 186 typedef std::map<uint8_t, DecoderInfo> DecoderMap;
173 187
174 DecoderMap decoders_; 188 DecoderMap decoders_;
175 int active_decoder_type_; 189 int active_decoder_type_;
176 int active_cng_decoder_type_; 190 int active_cng_decoder_type_;
177 std::unique_ptr<ComfortNoiseDecoder> active_cng_decoder_; 191 std::unique_ptr<ComfortNoiseDecoder> active_cng_decoder_;
178 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_; 192 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
179 193
180 RTC_DISALLOW_COPY_AND_ASSIGN(DecoderDatabase); 194 RTC_DISALLOW_COPY_AND_ASSIGN(DecoderDatabase);
181 }; 195 };
182 196
183 } // namespace webrtc 197 } // namespace webrtc
184 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_DECODER_DATABASE_H_ 198 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_DECODER_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698