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