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

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

Issue 2355503002: Stopped using the NetEqDecoder enum internally in NetEq. (Closed)
Patch Set: Created 4 years, 3 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( 44 explicit DecoderInfo(
45 const SdpAudioFormat& audio_format,
46 AudioDecoderFactory* factory = nullptr);
47 explicit DecoderInfo(
45 NetEqDecoder ct, 48 NetEqDecoder ct,
46 const std::string& nm,
47 AudioDecoderFactory* factory = nullptr); 49 AudioDecoderFactory* factory = nullptr);
48 DecoderInfo(NetEqDecoder ct, 50 DecoderInfo(const SdpAudioFormat& audio_format, AudioDecoder* ext_dec);
49 const std::string& nm,
50 AudioDecoder* ext_dec);
51 DecoderInfo(DecoderInfo&&); 51 DecoderInfo(DecoderInfo&&);
52 ~DecoderInfo(); 52 ~DecoderInfo();
53 53
54 // Get the AudioDecoder object, creating it first if necessary. 54 // Get the AudioDecoder object, creating it first if necessary.
55 AudioDecoder* GetDecoder() const; 55 AudioDecoder* GetDecoder() const;
56 56
57 // Delete the AudioDecoder object, unless it's external. (This means we can 57 // Delete the AudioDecoder object, unless it's external. (This means we can
58 // always recreate it later if we need it.) 58 // always recreate it later if we need it.)
59 void DropDecoder() const { decoder_.reset(); } 59 void DropDecoder() const { decoder_.reset(); }
60 60
61 int SampleRateHz() const { 61 int SampleRateHz() const {
62 const AudioDecoder* decoder = GetDecoder(); 62 const AudioDecoder* decoder = GetDecoder();
63 RTC_DCHECK_EQ(1, !!decoder + !!cng_decoder_); 63 RTC_DCHECK_EQ(1, !!decoder + !!cng_decoder_);
64 return decoder ? decoder->SampleRateHz() : cng_decoder_->sample_rate_hz; 64 return decoder ? decoder->SampleRateHz() : cng_decoder_->sample_rate_hz;
65 } 65 }
66 66
67 const SdpAudioFormat& GetFormat() const { 67 const SdpAudioFormat& GetFormat() const { return audio_format_; }
68 RTC_DCHECK(audio_format_);
69 return *audio_format_;
70 }
71 68
72 // Returns true if |codec_type| is comfort noise. 69 // Returns true if the decoder's format is comfort noise.
73 bool IsComfortNoise() const; 70 bool IsComfortNoise() const;
74 71
75 // Returns true if |codec_type| is DTMF. 72 // Returns true if the decoder's format is DTMF.
76 bool IsDtmf() const; 73 bool IsDtmf() const;
77 74
78 // Returns true if |codec_type| is RED. 75 // Returns true if the decoder's format is RED.
79 bool IsRed() const; 76 bool IsRed() const;
80 77
81 const NetEqDecoder codec_type; 78 // Returns if the decoder's format is named |name|.
82 const std::string name; 79 bool IsType(const char *name) const;
80 // Returns if the decoder's format is named |name|.
81 bool IsType(const std::string& name) const;
82
83 // TODO(ossu): |name| is kept here while we retain the old external decoder
84 // interface. Remove this once using an AudioDecoderFactory has
85 // supplanted the old functionality.
86 std::string name;
kwiberg-webrtc 2016/09/20 16:05:43 Why can't we just use the name field in audio_form
ossu 2016/09/21 09:10:56 I tried that, but there were some ambiguities for
kwiberg-webrtc 2016/09/21 09:21:19 Acknowledged.
83 87
84 private: 88 private:
85 const rtc::Optional<SdpAudioFormat> audio_format_; 89 const SdpAudioFormat audio_format_;
86 AudioDecoderFactory* factory_; 90 AudioDecoderFactory* factory_;
kwiberg-webrtc 2016/09/20 16:05:43 Consider making this const; I think you forget to
ossu 2016/09/21 09:10:55 Acknowledged.
87 mutable std::unique_ptr<AudioDecoder> decoder_; 91 mutable std::unique_ptr<AudioDecoder> decoder_;
88 92
89 // Set iff this is an external decoder. 93 // Set iff this is an external decoder.
90 AudioDecoder* const external_decoder_; 94 AudioDecoder* const external_decoder_;
91 95
92 // Set iff this is a comfort noise decoder. 96 // Set iff this is a comfort noise decoder.
93 struct CngDecoder { 97 struct CngDecoder {
94 static rtc::Optional<CngDecoder> Create(NetEqDecoder ct); 98 static rtc::Optional<CngDecoder> Create(const SdpAudioFormat& format);
95 int sample_rate_hz; 99 int sample_rate_hz;
96 }; 100 };
97 const rtc::Optional<CngDecoder> cng_decoder_; 101 const rtc::Optional<CngDecoder> cng_decoder_;
98 }; 102 };
99 103
100 // Maximum value for 8 bits, and an invalid RTP payload type (since it is 104 // Maximum value for 8 bits, and an invalid RTP payload type (since it is
101 // only 7 bits). 105 // only 7 bits).
102 static const uint8_t kRtpPayloadTypeError = 0xFF; 106 static const uint8_t kRtpPayloadTypeError = 0xFF;
103 107
104 DecoderDatabase( 108 DecoderDatabase(
(...skipping 28 matching lines...) Expand all
133 AudioDecoder* decoder); 137 AudioDecoder* decoder);
134 138
135 // Removes the entry for |rtp_payload_type| from the database. 139 // Removes the entry for |rtp_payload_type| from the database.
136 // Returns kDecoderNotFound or kOK depending on the outcome of the operation. 140 // Returns kDecoderNotFound or kOK depending on the outcome of the operation.
137 virtual int Remove(uint8_t rtp_payload_type); 141 virtual int Remove(uint8_t rtp_payload_type);
138 142
139 // Returns a pointer to the DecoderInfo struct for |rtp_payload_type|. If 143 // Returns a pointer to the DecoderInfo struct for |rtp_payload_type|. If
140 // no decoder is registered with that |rtp_payload_type|, NULL is returned. 144 // no decoder is registered with that |rtp_payload_type|, NULL is returned.
141 virtual const DecoderInfo* GetDecoderInfo(uint8_t rtp_payload_type) const; 145 virtual const DecoderInfo* GetDecoderInfo(uint8_t rtp_payload_type) const;
142 146
143 // Returns one RTP payload type associated with |codec_type|, or
144 // kDecoderNotFound if no entry exists for that value. Note that one
145 // |codec_type| may be registered with several RTP payload types, and the
146 // method may return any of them.
147 virtual uint8_t GetRtpPayloadType(NetEqDecoder codec_type) const;
148
149 // Sets the active decoder to be |rtp_payload_type|. If this call results in a 147 // Sets the active decoder to be |rtp_payload_type|. If this call results in a
150 // change of active decoder, |new_decoder| is set to true. The previous active 148 // change of active decoder, |new_decoder| is set to true. The previous active
151 // decoder's AudioDecoder object is deleted. 149 // decoder's AudioDecoder object is deleted.
152 virtual int SetActiveDecoder(uint8_t rtp_payload_type, bool* new_decoder); 150 virtual int SetActiveDecoder(uint8_t rtp_payload_type, bool* new_decoder);
153 151
154 // Returns the current active decoder, or NULL if no active decoder exists. 152 // Returns the current active decoder, or NULL if no active decoder exists.
155 virtual AudioDecoder* GetActiveDecoder() const; 153 virtual AudioDecoder* GetActiveDecoder() const;
156 154
157 // Sets the active comfort noise decoder to be |rtp_payload_type|. If this 155 // Sets the active comfort noise decoder to be |rtp_payload_type|. If this
158 // call results in a change of active comfort noise decoder, the previous 156 // call results in a change of active comfort noise decoder, the previous
159 // active decoder's AudioDecoder object is deleted. 157 // active decoder's AudioDecoder object is deleted.
160 virtual int SetActiveCngDecoder(uint8_t rtp_payload_type); 158 virtual int SetActiveCngDecoder(uint8_t rtp_payload_type);
161 159
162 // Returns the current active comfort noise decoder, or NULL if no active 160 // Returns the current active comfort noise decoder, or NULL if no active
163 // comfort noise decoder exists. 161 // comfort noise decoder exists.
164 virtual ComfortNoiseDecoder* GetActiveCngDecoder() const; 162 virtual ComfortNoiseDecoder* GetActiveCngDecoder() const;
165 163
166 // The following are utility methods: they will look up DecoderInfo through 164 // The following are utility methods: they will look up DecoderInfo through
167 // GetDecoderInfo and call the respective method on that info object, if it 165 // GetDecoderInfo and call the respective method on that info object, if it
168 // exists. 166 // exists.
169 167
170 // Returns a pointer to the AudioDecoder object associated with 168 // Returns a pointer to the AudioDecoder object associated with
171 // |rtp_payload_type|, or NULL if none is registered. If the AudioDecoder 169 // |rtp_payload_type|, or NULL if none is registered. If the AudioDecoder
172 // object does not exist for that decoder, the object is created. 170 // object does not exist for that decoder, the object is created.
173 AudioDecoder* GetDecoder(uint8_t rtp_payload_type) const; 171 AudioDecoder* GetDecoder(uint8_t rtp_payload_type) const;
174 172
175 // Returns true if |rtp_payload_type| is registered as a |codec_type|. 173 // Returns if |rtp_payload_type| is registered with a format named |name|.
176 bool IsType(uint8_t rtp_payload_type, NetEqDecoder codec_type) const; 174 bool IsType(uint8_t rtp_payload_type, const char *name) const;
175
176 // Returns if |rtp_payload_type| is registered with a format named |name|.
177 bool IsType(uint8_t rtp_payload_type, const std::string& name) const;
177 178
178 // Returns true if |rtp_payload_type| is registered as comfort noise. 179 // Returns true if |rtp_payload_type| is registered as comfort noise.
179 bool IsComfortNoise(uint8_t rtp_payload_type) const; 180 bool IsComfortNoise(uint8_t rtp_payload_type) const;
180 181
181 // Returns true if |rtp_payload_type| is registered as DTMF. 182 // Returns true if |rtp_payload_type| is registered as DTMF.
182 bool IsDtmf(uint8_t rtp_payload_type) const; 183 bool IsDtmf(uint8_t rtp_payload_type) const;
183 184
184 // Returns true if |rtp_payload_type| is registered as RED. 185 // Returns true if |rtp_payload_type| is registered as RED.
185 bool IsRed(uint8_t rtp_payload_type) const; 186 bool IsRed(uint8_t rtp_payload_type) const;
186 187
187 // Returns kOK if all packets in |packet_list| carry payload types that are 188 // Returns kOK if all packets in |packet_list| carry payload types that are
188 // registered in the database. Otherwise, returns kDecoderNotFound. 189 // registered in the database. Otherwise, returns kDecoderNotFound.
189 int CheckPayloadTypes(const PacketList& packet_list) const; 190 int CheckPayloadTypes(const PacketList& packet_list) const;
190 191
191 private: 192 private:
192 typedef std::map<uint8_t, DecoderInfo> DecoderMap; 193 typedef std::map<uint8_t, DecoderInfo> DecoderMap;
193 194
194 DecoderMap decoders_; 195 DecoderMap decoders_;
195 int active_decoder_type_; 196 int active_decoder_type_;
196 int active_cng_decoder_type_; 197 int active_cng_decoder_type_;
197 mutable std::unique_ptr<ComfortNoiseDecoder> active_cng_decoder_; 198 mutable std::unique_ptr<ComfortNoiseDecoder> active_cng_decoder_;
198 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_; 199 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
199 200
200 RTC_DISALLOW_COPY_AND_ASSIGN(DecoderDatabase); 201 RTC_DISALLOW_COPY_AND_ASSIGN(DecoderDatabase);
201 }; 202 };
202 203
203 } // namespace webrtc 204 } // namespace webrtc
204 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_DECODER_DATABASE_H_ 205 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_DECODER_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698