Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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( |
| 45 NetEqDecoder ct, | |
| 46 const std::string& nm, | |
| 47 const rtc::scoped_refptr<AudioDecoderFactory>& factory = nullptr); | |
| 45 DecoderInfo(NetEqDecoder ct, | 48 DecoderInfo(NetEqDecoder ct, |
| 46 const std::string& nm, | 49 const std::string& nm, |
| 47 AudioDecoder* ext_dec); | 50 AudioDecoder* ext_dec); |
| 48 DecoderInfo(DecoderInfo&&); | 51 DecoderInfo(DecoderInfo&&); |
| 49 ~DecoderInfo(); | 52 ~DecoderInfo(); |
| 50 | 53 |
| 51 // Get the AudioDecoder object, creating it first if necessary. | 54 // Get the AudioDecoder object, creating it first if necessary. |
| 52 AudioDecoder* GetDecoder(AudioDecoderFactory* factory); | 55 AudioDecoder* GetDecoder() const; |
| 53 | 56 |
| 54 // 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 |
| 55 // always recreate it later if we need it.) | 58 // always recreate it later if we need it.) |
| 56 void DropDecoder() { decoder_.reset(); } | 59 void DropDecoder() const { decoder_.reset(); } |
| 57 | 60 |
| 58 int SampleRateHz() const { | 61 int SampleRateHz() const { |
| 59 RTC_DCHECK_EQ(1, !!decoder_ + !!external_decoder_ + !!cng_decoder_); | 62 RTC_DCHECK_EQ(1, !!decoder_ + !!external_decoder_ + !!cng_decoder_); |
| 60 return decoder_ ? decoder_->SampleRateHz() | 63 return decoder_ ? decoder_->SampleRateHz() |
| 61 : external_decoder_ ? external_decoder_->SampleRateHz() | 64 : external_decoder_ ? external_decoder_->SampleRateHz() |
| 62 : cng_decoder_->sample_rate_hz; | 65 : cng_decoder_->sample_rate_hz; |
| 63 } | 66 } |
| 64 | 67 |
| 68 // Returns true if |codec_type| is comfort noise. | |
| 69 bool IsComfortNoise() const; | |
| 70 | |
| 71 // Returns true if |codec_type| is DTMF. | |
| 72 bool IsDtmf() const; | |
| 73 | |
| 74 // Returns true if |codec_type| is RED. | |
| 75 bool IsRed() const; | |
| 76 | |
| 65 const NetEqDecoder codec_type; | 77 const NetEqDecoder codec_type; |
| 66 const std::string name; | 78 const std::string name; |
| 67 | 79 |
| 68 private: | 80 private: |
| 69 const rtc::Optional<SdpAudioFormat> audio_format_; | 81 const rtc::Optional<SdpAudioFormat> audio_format_; |
| 70 std::unique_ptr<AudioDecoder> decoder_; | 82 rtc::scoped_refptr<AudioDecoderFactory> factory_; |
| 83 mutable std::unique_ptr<AudioDecoder> decoder_; | |
| 71 | 84 |
| 72 // Set iff this is an external decoder. | 85 // Set iff this is an external decoder. |
| 73 AudioDecoder* const external_decoder_; | 86 AudioDecoder* const external_decoder_; |
| 74 | 87 |
| 75 // Set iff this is a comfort noise decoder. | 88 // Set iff this is a comfort noise decoder. |
| 76 struct CngDecoder { | 89 struct CngDecoder { |
| 77 static rtc::Optional<CngDecoder> Create(NetEqDecoder ct); | 90 static rtc::Optional<CngDecoder> Create(NetEqDecoder ct); |
| 78 int sample_rate_hz; | 91 int sample_rate_hz; |
| 79 }; | 92 }; |
| 80 const rtc::Optional<CngDecoder> cng_decoder_; | 93 const rtc::Optional<CngDecoder> cng_decoder_; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 // Returns a pointer to the DecoderInfo struct for |rtp_payload_type|. If | 135 // 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. | 136 // no decoder is registered with that |rtp_payload_type|, NULL is returned. |
| 124 virtual const DecoderInfo* GetDecoderInfo(uint8_t rtp_payload_type) const; | 137 virtual const DecoderInfo* GetDecoderInfo(uint8_t rtp_payload_type) const; |
| 125 | 138 |
| 126 // Returns one RTP payload type associated with |codec_type|, or | 139 // Returns one RTP payload type associated with |codec_type|, or |
| 127 // kDecoderNotFound if no entry exists for that value. Note that one | 140 // kDecoderNotFound if no entry exists for that value. Note that one |
| 128 // |codec_type| may be registered with several RTP payload types, and the | 141 // |codec_type| may be registered with several RTP payload types, and the |
| 129 // method may return any of them. | 142 // method may return any of them. |
| 130 virtual uint8_t GetRtpPayloadType(NetEqDecoder codec_type) const; | 143 virtual uint8_t GetRtpPayloadType(NetEqDecoder codec_type) const; |
| 131 | 144 |
| 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 | 145 // 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 | 146 // change of active decoder, |new_decoder| is set to true. The previous active |
| 152 // decoder's AudioDecoder object is deleted. | 147 // decoder's AudioDecoder object is deleted. |
| 153 virtual int SetActiveDecoder(uint8_t rtp_payload_type, bool* new_decoder); | 148 virtual int SetActiveDecoder(uint8_t rtp_payload_type, bool* new_decoder); |
| 154 | 149 |
| 155 // Returns the current active decoder, or NULL if no active decoder exists. | 150 // Returns the current active decoder, or NULL if no active decoder exists. |
| 156 virtual AudioDecoder* GetActiveDecoder(); | 151 virtual AudioDecoder* GetActiveDecoder() const; |
|
ossu
2016/08/25 10:23:47
Considering my reasoning on what const DecoderData
| |
| 157 | 152 |
| 158 // Sets the active comfort noise decoder to be |rtp_payload_type|. If this | 153 // 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 | 154 // call results in a change of active comfort noise decoder, the previous |
| 160 // active decoder's AudioDecoder object is deleted. | 155 // active decoder's AudioDecoder object is deleted. |
| 161 virtual int SetActiveCngDecoder(uint8_t rtp_payload_type); | 156 virtual int SetActiveCngDecoder(uint8_t rtp_payload_type); |
| 162 | 157 |
| 163 // Returns the current active comfort noise decoder, or NULL if no active | 158 // Returns the current active comfort noise decoder, or NULL if no active |
| 164 // comfort noise decoder exists. | 159 // comfort noise decoder exists. |
| 165 virtual ComfortNoiseDecoder* GetActiveCngDecoder(); | 160 virtual ComfortNoiseDecoder* GetActiveCngDecoder() const; |
| 161 | |
| 162 // The following are utility methods: they will look up DecoderInfo through | |
| 163 // GetDecoderInfo and call the respective method on that info object, if it | |
| 164 // exists. | |
| 165 | |
| 166 // Returns a pointer to the AudioDecoder object associated with | |
| 167 // |rtp_payload_type|, or NULL if none is registered. If the AudioDecoder | |
| 168 // object does not exist for that decoder, the object is created. | |
| 169 AudioDecoder* GetDecoder(uint8_t rtp_payload_type) const; | |
| 170 | |
| 171 // Returns true if |rtp_payload_type| is registered as a |codec_type|. | |
| 172 bool IsType(uint8_t rtp_payload_type, NetEqDecoder codec_type) const; | |
| 173 | |
| 174 // Returns true if |rtp_payload_type| is registered as comfort noise. | |
| 175 bool IsComfortNoise(uint8_t rtp_payload_type) const; | |
| 176 | |
| 177 // Returns true if |rtp_payload_type| is registered as DTMF. | |
| 178 bool IsDtmf(uint8_t rtp_payload_type) const; | |
| 179 | |
| 180 // Returns true if |rtp_payload_type| is registered as RED. | |
| 181 bool IsRed(uint8_t rtp_payload_type) const; | |
| 166 | 182 |
| 167 // Returns kOK if all packets in |packet_list| carry payload types that are | 183 // Returns kOK if all packets in |packet_list| carry payload types that are |
| 168 // registered in the database. Otherwise, returns kDecoderNotFound. | 184 // registered in the database. Otherwise, returns kDecoderNotFound. |
| 169 virtual int CheckPayloadTypes(const PacketList& packet_list) const; | 185 int CheckPayloadTypes(const PacketList& packet_list) const; |
| 170 | 186 |
| 171 private: | 187 private: |
| 172 typedef std::map<uint8_t, DecoderInfo> DecoderMap; | 188 typedef std::map<uint8_t, DecoderInfo> DecoderMap; |
| 173 | 189 |
| 174 DecoderMap decoders_; | 190 DecoderMap decoders_; |
| 175 int active_decoder_type_; | 191 int active_decoder_type_; |
| 176 int active_cng_decoder_type_; | 192 int active_cng_decoder_type_; |
| 177 std::unique_ptr<ComfortNoiseDecoder> active_cng_decoder_; | 193 mutable std::unique_ptr<ComfortNoiseDecoder> active_cng_decoder_; |
| 178 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_; | 194 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_; |
| 179 | 195 |
| 180 RTC_DISALLOW_COPY_AND_ASSIGN(DecoderDatabase); | 196 RTC_DISALLOW_COPY_AND_ASSIGN(DecoderDatabase); |
| 181 }; | 197 }; |
| 182 | 198 |
| 183 } // namespace webrtc | 199 } // namespace webrtc |
| 184 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_DECODER_DATABASE_H_ | 200 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_DECODER_DATABASE_H_ |
| OLD | NEW |