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 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 // TODO(henrik.lundin): This condition should probably be | 753 // TODO(henrik.lundin): This condition should probably be |
754 // in_frame.num_channels_ > encoder_stack_->NumChannels() | 754 // in_frame.num_channels_ > encoder_stack_->NumChannels() |
755 const bool down_mix = | 755 const bool down_mix = |
756 in_frame.num_channels_ == 2 && encoder_stack_->NumChannels() == 1; | 756 in_frame.num_channels_ == 2 && encoder_stack_->NumChannels() == 1; |
757 | 757 |
758 if (!first_10ms_data_) { | 758 if (!first_10ms_data_) { |
759 expected_in_ts_ = in_frame.timestamp_; | 759 expected_in_ts_ = in_frame.timestamp_; |
760 expected_codec_ts_ = in_frame.timestamp_; | 760 expected_codec_ts_ = in_frame.timestamp_; |
761 first_10ms_data_ = true; | 761 first_10ms_data_ = true; |
762 } else if (in_frame.timestamp_ != expected_in_ts_) { | 762 } else if (in_frame.timestamp_ != expected_in_ts_) { |
763 LOG(LS_WARNING) << "Unexpected input timestamp: " << in_frame.timestamp_ | |
764 << ", expected: " << expected_in_ts_; | |
765 expected_codec_ts_ += | 763 expected_codec_ts_ += |
766 (in_frame.timestamp_ - expected_in_ts_) * | 764 (in_frame.timestamp_ - expected_in_ts_) * |
767 static_cast<uint32_t>( | 765 static_cast<uint32_t>( |
768 static_cast<double>(encoder_stack_->SampleRateHz()) / | 766 static_cast<double>(encoder_stack_->SampleRateHz()) / |
769 static_cast<double>(in_frame.sample_rate_hz_)); | 767 static_cast<double>(in_frame.sample_rate_hz_)); |
770 expected_in_ts_ = in_frame.timestamp_; | 768 expected_in_ts_ = in_frame.timestamp_; |
771 } | 769 } |
772 | 770 |
773 | 771 |
774 if (!down_mix && !resample) { | 772 if (!down_mix && !resample) { |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 receiver_.SetCodecs(codecs); | 970 receiver_.SetCodecs(codecs); |
973 } | 971 } |
974 | 972 |
975 bool AudioCodingModuleImpl::RegisterReceiveCodec( | 973 bool AudioCodingModuleImpl::RegisterReceiveCodec( |
976 int rtp_payload_type, | 974 int rtp_payload_type, |
977 const SdpAudioFormat& audio_format) { | 975 const SdpAudioFormat& audio_format) { |
978 rtc::CritScope lock(&acm_crit_sect_); | 976 rtc::CritScope lock(&acm_crit_sect_); |
979 RTC_DCHECK(receiver_initialized_); | 977 RTC_DCHECK(receiver_initialized_); |
980 | 978 |
981 if (!acm2::RentACodec::IsPayloadTypeValid(rtp_payload_type)) { | 979 if (!acm2::RentACodec::IsPayloadTypeValid(rtp_payload_type)) { |
982 LOG_F(LS_ERROR) << "Invalid payload-type " << rtp_payload_type | |
983 << " for decoder."; | |
984 return false; | 980 return false; |
985 } | 981 } |
986 | 982 |
987 return receiver_.AddCodec(rtp_payload_type, audio_format); | 983 return receiver_.AddCodec(rtp_payload_type, audio_format); |
988 } | 984 } |
989 | 985 |
990 int AudioCodingModuleImpl::RegisterReceiveCodec(const CodecInst& codec) { | 986 int AudioCodingModuleImpl::RegisterReceiveCodec(const CodecInst& codec) { |
991 rtc::CritScope lock(&acm_crit_sect_); | 987 rtc::CritScope lock(&acm_crit_sect_); |
992 auto* ef = encoder_factory_.get(); | 988 auto* ef = encoder_factory_.get(); |
993 return RegisterReceiveCodecUnlocked( | 989 return RegisterReceiveCodecUnlocked( |
994 codec, [&] { return ef->rent_a_codec.RentIsacDecoder(codec.plfreq); }); | 990 codec, [&] { return ef->rent_a_codec.RentIsacDecoder(codec.plfreq); }); |
995 } | 991 } |
996 | 992 |
997 int AudioCodingModuleImpl::RegisterReceiveCodec( | 993 int AudioCodingModuleImpl::RegisterReceiveCodec( |
998 const CodecInst& codec, | 994 const CodecInst& codec, |
999 rtc::FunctionView<std::unique_ptr<AudioDecoder>()> isac_factory) { | 995 rtc::FunctionView<std::unique_ptr<AudioDecoder>()> isac_factory) { |
1000 rtc::CritScope lock(&acm_crit_sect_); | 996 rtc::CritScope lock(&acm_crit_sect_); |
1001 return RegisterReceiveCodecUnlocked(codec, isac_factory); | 997 return RegisterReceiveCodecUnlocked(codec, isac_factory); |
1002 } | 998 } |
1003 | 999 |
1004 int AudioCodingModuleImpl::RegisterReceiveCodecUnlocked( | 1000 int AudioCodingModuleImpl::RegisterReceiveCodecUnlocked( |
1005 const CodecInst& codec, | 1001 const CodecInst& codec, |
1006 rtc::FunctionView<std::unique_ptr<AudioDecoder>()> isac_factory) { | 1002 rtc::FunctionView<std::unique_ptr<AudioDecoder>()> isac_factory) { |
1007 RTC_DCHECK(receiver_initialized_); | 1003 RTC_DCHECK(receiver_initialized_); |
1008 if (codec.channels > 2) { | 1004 if (codec.channels > 2) { |
1009 LOG_F(LS_ERROR) << "Unsupported number of channels: " << codec.channels; | |
1010 return -1; | 1005 return -1; |
1011 } | 1006 } |
1012 | 1007 |
1013 auto codec_id = acm2::RentACodec::CodecIdByParams(codec.plname, codec.plfreq, | 1008 auto codec_id = acm2::RentACodec::CodecIdByParams(codec.plname, codec.plfreq, |
1014 codec.channels); | 1009 codec.channels); |
1015 if (!codec_id) { | 1010 if (!codec_id) { |
1016 LOG_F(LS_ERROR) << "Wrong codec params to be registered as receive codec"; | |
1017 return -1; | 1011 return -1; |
1018 } | 1012 } |
1019 auto codec_index = acm2::RentACodec::CodecIndexFromId(*codec_id); | 1013 auto codec_index = acm2::RentACodec::CodecIndexFromId(*codec_id); |
1020 RTC_CHECK(codec_index) << "Invalid codec ID: " << static_cast<int>(*codec_id); | 1014 RTC_CHECK(codec_index) << "Invalid codec ID: " << static_cast<int>(*codec_id); |
1021 | 1015 |
1022 // Check if the payload-type is valid. | 1016 // Check if the payload-type is valid. |
1023 if (!acm2::RentACodec::IsPayloadTypeValid(codec.pltype)) { | 1017 if (!acm2::RentACodec::IsPayloadTypeValid(codec.pltype)) { |
1024 LOG_F(LS_ERROR) << "Invalid payload type " << codec.pltype << " for " | |
1025 << codec.plname; | |
1026 return -1; | 1018 return -1; |
1027 } | 1019 } |
1028 | 1020 |
1029 AudioDecoder* isac_decoder = nullptr; | 1021 AudioDecoder* isac_decoder = nullptr; |
1030 if (STR_CASE_CMP(codec.plname, "isac") == 0) { | 1022 if (STR_CASE_CMP(codec.plname, "isac") == 0) { |
1031 std::unique_ptr<AudioDecoder>& saved_isac_decoder = | 1023 std::unique_ptr<AudioDecoder>& saved_isac_decoder = |
1032 codec.plfreq == 16000 ? isac_decoder_16k_ : isac_decoder_32k_; | 1024 codec.plfreq == 16000 ? isac_decoder_16k_ : isac_decoder_32k_; |
1033 if (!saved_isac_decoder) { | 1025 if (!saved_isac_decoder) { |
1034 saved_isac_decoder = isac_factory(); | 1026 saved_isac_decoder = isac_factory(); |
1035 } | 1027 } |
1036 isac_decoder = saved_isac_decoder.get(); | 1028 isac_decoder = saved_isac_decoder.get(); |
1037 } | 1029 } |
1038 return receiver_.AddCodec(*codec_index, codec.pltype, codec.channels, | 1030 return receiver_.AddCodec(*codec_index, codec.pltype, codec.channels, |
1039 codec.plfreq, isac_decoder, codec.plname); | 1031 codec.plfreq, isac_decoder, codec.plname); |
1040 } | 1032 } |
1041 | 1033 |
1042 int AudioCodingModuleImpl::RegisterExternalReceiveCodec( | 1034 int AudioCodingModuleImpl::RegisterExternalReceiveCodec( |
1043 int rtp_payload_type, | 1035 int rtp_payload_type, |
1044 AudioDecoder* external_decoder, | 1036 AudioDecoder* external_decoder, |
1045 int sample_rate_hz, | 1037 int sample_rate_hz, |
1046 int num_channels, | 1038 int num_channels, |
1047 const std::string& name) { | 1039 const std::string& name) { |
1048 rtc::CritScope lock(&acm_crit_sect_); | 1040 rtc::CritScope lock(&acm_crit_sect_); |
1049 RTC_DCHECK(receiver_initialized_); | 1041 RTC_DCHECK(receiver_initialized_); |
1050 if (num_channels > 2 || num_channels < 0) { | 1042 if (num_channels > 2 || num_channels < 0) { |
1051 LOG_F(LS_ERROR) << "Unsupported number of channels: " << num_channels; | |
1052 return -1; | 1043 return -1; |
1053 } | 1044 } |
1054 | 1045 |
1055 // Check if the payload-type is valid. | 1046 // Check if the payload-type is valid. |
1056 if (!acm2::RentACodec::IsPayloadTypeValid(rtp_payload_type)) { | 1047 if (!acm2::RentACodec::IsPayloadTypeValid(rtp_payload_type)) { |
1057 LOG_F(LS_ERROR) << "Invalid payload-type " << rtp_payload_type | |
1058 << " for external decoder."; | |
1059 return -1; | 1048 return -1; |
1060 } | 1049 } |
1061 | 1050 |
1062 return receiver_.AddCodec(-1 /* external */, rtp_payload_type, num_channels, | 1051 return receiver_.AddCodec(-1 /* external */, rtp_payload_type, num_channels, |
1063 sample_rate_hz, external_decoder, name); | 1052 sample_rate_hz, external_decoder, name); |
1064 } | 1053 } |
1065 | 1054 |
1066 // Get current received codec. | 1055 // Get current received codec. |
1067 int AudioCodingModuleImpl::ReceiveCodec(CodecInst* current_codec) const { | 1056 int AudioCodingModuleImpl::ReceiveCodec(CodecInst* current_codec) const { |
1068 rtc::CritScope lock(&acm_crit_sect_); | 1057 rtc::CritScope lock(&acm_crit_sect_); |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1361 // Checks the validity of the parameters of the given codec | 1350 // Checks the validity of the parameters of the given codec |
1362 bool AudioCodingModule::IsCodecValid(const CodecInst& codec) { | 1351 bool AudioCodingModule::IsCodecValid(const CodecInst& codec) { |
1363 bool valid = acm2::RentACodec::IsCodecValid(codec); | 1352 bool valid = acm2::RentACodec::IsCodecValid(codec); |
1364 if (!valid) | 1353 if (!valid) |
1365 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, -1, | 1354 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, -1, |
1366 "Invalid codec setting"); | 1355 "Invalid codec setting"); |
1367 return valid; | 1356 return valid; |
1368 } | 1357 } |
1369 | 1358 |
1370 } // namespace webrtc | 1359 } // namespace webrtc |
OLD | NEW |