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

Side by Side Diff: webrtc/modules/audio_coding/acm2/audio_coding_module.cc

Issue 2686043006: WebRtcVoiceMediaChannel::AddRecvStream: Don't call SetRecPayloadType (Closed)
Patch Set: rebase Created 3 years, 9 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 114
115 // Initialize receiver, resets codec database etc. 115 // Initialize receiver, resets codec database etc.
116 int InitializeReceiver() override; 116 int InitializeReceiver() override;
117 117
118 // Get current receive frequency. 118 // Get current receive frequency.
119 int ReceiveFrequency() const override; 119 int ReceiveFrequency() const override;
120 120
121 // Get current playout frequency. 121 // Get current playout frequency.
122 int PlayoutFrequency() const override; 122 int PlayoutFrequency() const override;
123 123
124 void SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs) override;
125
124 bool RegisterReceiveCodec(int rtp_payload_type, 126 bool RegisterReceiveCodec(int rtp_payload_type,
125 const SdpAudioFormat& audio_format) override; 127 const SdpAudioFormat& audio_format) override;
126 128
127 int RegisterReceiveCodec(const CodecInst& receive_codec) override; 129 int RegisterReceiveCodec(const CodecInst& receive_codec) override;
128 int RegisterReceiveCodec( 130 int RegisterReceiveCodec(
129 const CodecInst& receive_codec, 131 const CodecInst& receive_codec,
130 rtc::FunctionView<std::unique_ptr<AudioDecoder>()> isac_factory) override; 132 rtc::FunctionView<std::unique_ptr<AudioDecoder>()> isac_factory) override;
131 133
132 int RegisterExternalReceiveCodec(int rtp_payload_type, 134 int RegisterExternalReceiveCodec(int rtp_payload_type,
133 AudioDecoder* external_decoder, 135 AudioDecoder* external_decoder,
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 }; 313 };
312 314
313 // Adds a codec usage sample to the histogram. 315 // Adds a codec usage sample to the histogram.
314 void UpdateCodecTypeHistogram(size_t codec_type) { 316 void UpdateCodecTypeHistogram(size_t codec_type) {
315 RTC_HISTOGRAM_ENUMERATION( 317 RTC_HISTOGRAM_ENUMERATION(
316 "WebRTC.Audio.Encoder.CodecType", static_cast<int>(codec_type), 318 "WebRTC.Audio.Encoder.CodecType", static_cast<int>(codec_type),
317 static_cast<int>( 319 static_cast<int>(
318 webrtc::AudioEncoder::CodecType::kMaxLoggedAudioCodecTypes)); 320 webrtc::AudioEncoder::CodecType::kMaxLoggedAudioCodecTypes));
319 } 321 }
320 322
321 // TODO(turajs): the same functionality is used in NetEq. If both classes
322 // need them, make it a static function in ACMCodecDB.
323 bool IsCodecRED(const CodecInst& codec) {
324 return (STR_CASE_CMP(codec.plname, "RED") == 0);
325 }
326
327 bool IsCodecCN(const CodecInst& codec) {
328 return (STR_CASE_CMP(codec.plname, "CN") == 0);
329 }
330
331 // Stereo-to-mono can be used as in-place. 323 // Stereo-to-mono can be used as in-place.
332 int DownMix(const AudioFrame& frame, 324 int DownMix(const AudioFrame& frame,
333 size_t length_out_buff, 325 size_t length_out_buff,
334 int16_t* out_buff) { 326 int16_t* out_buff) {
335 if (length_out_buff < frame.samples_per_channel_) { 327 if (length_out_buff < frame.samples_per_channel_) {
336 return -1; 328 return -1;
337 } 329 }
338 for (size_t n = 0; n < frame.samples_per_channel_; ++n) 330 for (size_t n = 0; n < frame.samples_per_channel_; ++n)
339 out_buff[n] = (frame.data_[2 * n] + frame.data_[2 * n + 1]) >> 1; 331 out_buff[n] = (frame.data_[2 * n] + frame.data_[2 * n + 1]) >> 1;
340 return 0; 332 return 0;
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 // If the receiver is already initialized then we want to destroy any 941 // If the receiver is already initialized then we want to destroy any
950 // existing decoders. After a call to this function, we should have a clean 942 // existing decoders. After a call to this function, we should have a clean
951 // start-up. 943 // start-up.
952 if (receiver_initialized_) 944 if (receiver_initialized_)
953 receiver_.RemoveAllCodecs(); 945 receiver_.RemoveAllCodecs();
954 receiver_.ResetInitialDelay(); 946 receiver_.ResetInitialDelay();
955 receiver_.SetMinimumDelay(0); 947 receiver_.SetMinimumDelay(0);
956 receiver_.SetMaximumDelay(0); 948 receiver_.SetMaximumDelay(0);
957 receiver_.FlushBuffers(); 949 receiver_.FlushBuffers();
958 950
959 // Register RED and CN.
960 auto db = acm2::RentACodec::Database();
961 for (size_t i = 0; i < db.size(); i++) {
962 if (IsCodecRED(db[i]) || IsCodecCN(db[i])) {
963 if (receiver_.AddCodec(static_cast<int>(i),
964 static_cast<uint8_t>(db[i].pltype), 1,
965 db[i].plfreq, nullptr, db[i].plname) < 0) {
966 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_,
967 "Cannot register master codec.");
968 return -1;
969 }
970 }
971 }
972 receiver_initialized_ = true; 951 receiver_initialized_ = true;
973 return 0; 952 return 0;
974 } 953 }
975 954
976 // Get current receive frequency. 955 // Get current receive frequency.
977 int AudioCodingModuleImpl::ReceiveFrequency() const { 956 int AudioCodingModuleImpl::ReceiveFrequency() const {
978 const auto last_packet_sample_rate = receiver_.last_packet_sample_rate_hz(); 957 const auto last_packet_sample_rate = receiver_.last_packet_sample_rate_hz();
979 return last_packet_sample_rate ? *last_packet_sample_rate 958 return last_packet_sample_rate ? *last_packet_sample_rate
980 : receiver_.last_output_sample_rate_hz(); 959 : receiver_.last_output_sample_rate_hz();
981 } 960 }
982 961
983 // Get current playout frequency. 962 // Get current playout frequency.
984 int AudioCodingModuleImpl::PlayoutFrequency() const { 963 int AudioCodingModuleImpl::PlayoutFrequency() const {
985 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_, 964 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_,
986 "PlayoutFrequency()"); 965 "PlayoutFrequency()");
987 return receiver_.last_output_sample_rate_hz(); 966 return receiver_.last_output_sample_rate_hz();
988 } 967 }
989 968
969 void AudioCodingModuleImpl::SetReceiveCodecs(
970 const std::map<int, SdpAudioFormat>& codecs) {
971 rtc::CritScope lock(&acm_crit_sect_);
972 receiver_.SetCodecs(codecs);
973 }
974
990 bool AudioCodingModuleImpl::RegisterReceiveCodec( 975 bool AudioCodingModuleImpl::RegisterReceiveCodec(
991 int rtp_payload_type, 976 int rtp_payload_type,
992 const SdpAudioFormat& audio_format) { 977 const SdpAudioFormat& audio_format) {
993 rtc::CritScope lock(&acm_crit_sect_); 978 rtc::CritScope lock(&acm_crit_sect_);
994 RTC_DCHECK(receiver_initialized_); 979 RTC_DCHECK(receiver_initialized_);
995 980
996 if (!acm2::RentACodec::IsPayloadTypeValid(rtp_payload_type)) { 981 if (!acm2::RentACodec::IsPayloadTypeValid(rtp_payload_type)) {
997 LOG_F(LS_ERROR) << "Invalid payload-type " << rtp_payload_type 982 LOG_F(LS_ERROR) << "Invalid payload-type " << rtp_payload_type
998 << " for decoder."; 983 << " for decoder.";
999 return false; 984 return false;
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 // Checks the validity of the parameters of the given codec 1361 // Checks the validity of the parameters of the given codec
1377 bool AudioCodingModule::IsCodecValid(const CodecInst& codec) { 1362 bool AudioCodingModule::IsCodecValid(const CodecInst& codec) {
1378 bool valid = acm2::RentACodec::IsCodecValid(codec); 1363 bool valid = acm2::RentACodec::IsCodecValid(codec);
1379 if (!valid) 1364 if (!valid)
1380 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, -1, 1365 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, -1,
1381 "Invalid codec setting"); 1366 "Invalid codec setting");
1382 return valid; 1367 return valid;
1383 } 1368 }
1384 1369
1385 } // namespace webrtc 1370 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/acm2/acm_receiver.cc ('k') | webrtc/modules/audio_coding/include/audio_coding_module.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698