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

Side by Side Diff: webrtc/voice_engine/channel.cc

Issue 1316523002: Convert channel counts to size_t. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Rebase onto cleanup change Created 4 years, 12 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 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 void Channel::OnIncomingCSRCChanged(uint32_t CSRC, bool added) { 412 void Channel::OnIncomingCSRCChanged(uint32_t CSRC, bool added) {
413 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), 413 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId),
414 "Channel::OnIncomingCSRCChanged(CSRC=%d, added=%d)", CSRC, 414 "Channel::OnIncomingCSRCChanged(CSRC=%d, added=%d)", CSRC,
415 added); 415 added);
416 } 416 }
417 417
418 int32_t Channel::OnInitializeDecoder( 418 int32_t Channel::OnInitializeDecoder(
419 int8_t payloadType, 419 int8_t payloadType,
420 const char payloadName[RTP_PAYLOAD_NAME_SIZE], 420 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
421 int frequency, 421 int frequency,
422 uint8_t channels, 422 size_t channels,
423 uint32_t rate) { 423 uint32_t rate) {
424 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), 424 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId),
425 "Channel::OnInitializeDecoder(payloadType=%d, " 425 "Channel::OnInitializeDecoder(payloadType=%d, "
426 "payloadName=%s, frequency=%u, channels=%u, rate=%u)", 426 "payloadName=%s, frequency=%u, channels=%" PRIuS ", rate=%u)",
427 payloadType, payloadName, frequency, channels, rate); 427 payloadType, payloadName, frequency, channels, rate);
428 428
429 CodecInst receiveCodec = {0}; 429 CodecInst receiveCodec = {0};
430 CodecInst dummyCodec = {0}; 430 CodecInst dummyCodec = {0};
431 431
432 receiveCodec.pltype = payloadType; 432 receiveCodec.pltype = payloadType;
433 receiveCodec.plfreq = frequency; 433 receiveCodec.plfreq = frequency;
434 receiveCodec.channels = channels; 434 receiveCodec.channels = channels;
435 receiveCodec.rate = rate; 435 receiveCodec.rate = rate;
436 strncpy(receiveCodec.plname, payloadName, RTP_PAYLOAD_NAME_SIZE - 1); 436 strncpy(receiveCodec.plname, payloadName, RTP_PAYLOAD_NAME_SIZE - 1);
(...skipping 15 matching lines...) Expand all
452 return 0; 452 return 0;
453 } 453 }
454 454
455 int32_t 455 int32_t
456 Channel::OnReceivedPayloadData(const uint8_t* payloadData, 456 Channel::OnReceivedPayloadData(const uint8_t* payloadData,
457 size_t payloadSize, 457 size_t payloadSize,
458 const WebRtcRTPHeader* rtpHeader) 458 const WebRtcRTPHeader* rtpHeader)
459 { 459 {
460 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId), 460 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId),
461 "Channel::OnReceivedPayloadData(payloadSize=%" PRIuS "," 461 "Channel::OnReceivedPayloadData(payloadSize=%" PRIuS ","
462 " payloadType=%u, audioChannel=%u)", 462 " payloadType=%u, audioChannel=%" PRIuS ")",
463 payloadSize, 463 payloadSize,
464 rtpHeader->header.payloadType, 464 rtpHeader->header.payloadType,
465 rtpHeader->type.Audio.channel); 465 rtpHeader->type.Audio.channel);
466 466
467 if (!channel_state_.Get().playing) 467 if (!channel_state_.Get().playing)
468 { 468 {
469 // Avoid inserting into NetEQ when we are not playing. Count the 469 // Avoid inserting into NetEQ when we are not playing. Count the
470 // packet as discarded. 470 // packet as discarded.
471 WEBRTC_TRACE(kTraceStream, kTraceVoice, 471 WEBRTC_TRACE(kTraceStream, kTraceVoice,
472 VoEId(_instanceId, _channelId), 472 VoEId(_instanceId, _channelId),
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 if ((audio_coding_->Codec(idx, &codec) == -1) || 1072 if ((audio_coding_->Codec(idx, &codec) == -1) ||
1073 (rtp_receiver_->RegisterReceivePayload( 1073 (rtp_receiver_->RegisterReceivePayload(
1074 codec.plname, 1074 codec.plname,
1075 codec.pltype, 1075 codec.pltype,
1076 codec.plfreq, 1076 codec.plfreq,
1077 codec.channels, 1077 codec.channels,
1078 (codec.rate < 0) ? 0 : codec.rate) == -1)) 1078 (codec.rate < 0) ? 0 : codec.rate) == -1))
1079 { 1079 {
1080 WEBRTC_TRACE(kTraceWarning, kTraceVoice, 1080 WEBRTC_TRACE(kTraceWarning, kTraceVoice,
1081 VoEId(_instanceId,_channelId), 1081 VoEId(_instanceId,_channelId),
1082 "Channel::Init() unable to register %s (%d/%d/%d/%d) " 1082 "Channel::Init() unable to register %s "
1083 "to RTP/RTCP receiver", 1083 "(%d/%d/%" PRIuS "/%d) to RTP/RTCP receiver",
1084 codec.plname, codec.pltype, codec.plfreq, 1084 codec.plname, codec.pltype, codec.plfreq,
1085 codec.channels, codec.rate); 1085 codec.channels, codec.rate);
1086 } 1086 }
1087 else 1087 else
1088 { 1088 {
1089 WEBRTC_TRACE(kTraceInfo, kTraceVoice, 1089 WEBRTC_TRACE(kTraceInfo, kTraceVoice,
1090 VoEId(_instanceId,_channelId), 1090 VoEId(_instanceId,_channelId),
1091 "Channel::Init() %s (%d/%d/%d/%d) has been added to " 1091 "Channel::Init() %s (%d/%d/%" PRIuS "/%d) has been "
1092 "the RTP/RTCP receiver", 1092 "added to the RTP/RTCP receiver",
1093 codec.plname, codec.pltype, codec.plfreq, 1093 codec.plname, codec.pltype, codec.plfreq,
1094 codec.channels, codec.rate); 1094 codec.channels, codec.rate);
1095 } 1095 }
1096 1096
1097 // Ensure that PCMU is used as default codec on the sending side 1097 // Ensure that PCMU is used as default codec on the sending side
1098 if (!STR_CASE_CMP(codec.plname, "PCMU") && (codec.channels == 1)) 1098 if (!STR_CASE_CMP(codec.plname, "PCMU") && (codec.channels == 1))
1099 { 1099 {
1100 SetSendCodec(codec); 1100 SetSendCodec(codec);
1101 } 1101 }
1102 1102
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
1584 } 1584 }
1585 1585
1586 int32_t 1586 int32_t
1587 Channel::SetSendCNPayloadType(int type, PayloadFrequencies frequency) 1587 Channel::SetSendCNPayloadType(int type, PayloadFrequencies frequency)
1588 { 1588 {
1589 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), 1589 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId),
1590 "Channel::SetSendCNPayloadType()"); 1590 "Channel::SetSendCNPayloadType()");
1591 1591
1592 CodecInst codec; 1592 CodecInst codec;
1593 int32_t samplingFreqHz(-1); 1593 int32_t samplingFreqHz(-1);
1594 const int kMono = 1; 1594 const size_t kMono = 1;
1595 if (frequency == kFreq32000Hz) 1595 if (frequency == kFreq32000Hz)
1596 samplingFreqHz = 32000; 1596 samplingFreqHz = 32000;
1597 else if (frequency == kFreq16000Hz) 1597 else if (frequency == kFreq16000Hz)
1598 samplingFreqHz = 16000; 1598 samplingFreqHz = 16000;
1599 1599
1600 if (audio_coding_->Codec("CN", &codec, samplingFreqHz, kMono) == -1) 1600 if (audio_coding_->Codec("CN", &codec, samplingFreqHz, kMono) == -1)
1601 { 1601 {
1602 _engineStatisticsPtr->SetLastError( 1602 _engineStatisticsPtr->SetLastError(
1603 VE_AUDIO_CODING_MODULE_ERROR, kTraceError, 1603 VE_AUDIO_CODING_MODULE_ERROR, kTraceError,
1604 "SetSendCNPayloadType() failed to retrieve default CN codec " 1604 "SetSendCNPayloadType() failed to retrieve default CN codec "
(...skipping 1738 matching lines...) Expand 10 before | Expand all | Expand 10 after
3343 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId), 3343 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId),
3344 "Channel::Demultiplex()"); 3344 "Channel::Demultiplex()");
3345 _audioFrame.CopyFrom(audioFrame); 3345 _audioFrame.CopyFrom(audioFrame);
3346 _audioFrame.id_ = _channelId; 3346 _audioFrame.id_ = _channelId;
3347 return 0; 3347 return 0;
3348 } 3348 }
3349 3349
3350 void Channel::Demultiplex(const int16_t* audio_data, 3350 void Channel::Demultiplex(const int16_t* audio_data,
3351 int sample_rate, 3351 int sample_rate,
3352 size_t number_of_frames, 3352 size_t number_of_frames,
3353 int number_of_channels) { 3353 size_t number_of_channels) {
3354 CodecInst codec; 3354 CodecInst codec;
3355 GetSendCodec(codec); 3355 GetSendCodec(codec);
3356 3356
3357 // Never upsample or upmix the capture signal here. This should be done at the 3357 // Never upsample or upmix the capture signal here. This should be done at the
3358 // end of the send chain. 3358 // end of the send chain.
3359 _audioFrame.sample_rate_hz_ = std::min(codec.plfreq, sample_rate); 3359 _audioFrame.sample_rate_hz_ = std::min(codec.plfreq, sample_rate);
3360 _audioFrame.num_channels_ = std::min(number_of_channels, codec.channels); 3360 _audioFrame.num_channels_ = std::min(number_of_channels, codec.channels);
3361 RemixAndResample(audio_data, number_of_frames, number_of_channels, 3361 RemixAndResample(audio_data, number_of_frames, number_of_channels,
3362 sample_rate, &input_resampler_, &_audioFrame); 3362 sample_rate, &input_resampler_, &_audioFrame);
3363 } 3363 }
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
3830 VoEId(_instanceId, _channelId), 3830 VoEId(_instanceId, _channelId),
3831 "Channel::EncodeAndSend() inserting Dtmf failed"); 3831 "Channel::EncodeAndSend() inserting Dtmf failed");
3832 return -1; 3832 return -1;
3833 } 3833 }
3834 3834
3835 // Replace mixed audio with DTMF tone. 3835 // Replace mixed audio with DTMF tone.
3836 for (size_t sample = 0; 3836 for (size_t sample = 0;
3837 sample < _audioFrame.samples_per_channel_; 3837 sample < _audioFrame.samples_per_channel_;
3838 sample++) 3838 sample++)
3839 { 3839 {
3840 for (int channel = 0; 3840 for (size_t channel = 0;
3841 channel < _audioFrame.num_channels_; 3841 channel < _audioFrame.num_channels_;
3842 channel++) 3842 channel++)
3843 { 3843 {
3844 const size_t index = 3844 const size_t index =
3845 sample * _audioFrame.num_channels_ + channel; 3845 sample * _audioFrame.num_channels_ + channel;
3846 _audioFrame.data_[index] = toneBuffer[sample]; 3846 _audioFrame.data_[index] = toneBuffer[sample];
3847 } 3847 }
3848 } 3848 }
3849 3849
3850 assert(_audioFrame.samples_per_channel_ == toneSamples); 3850 assert(_audioFrame.samples_per_channel_ == toneSamples);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
3964 codec.plname, 3964 codec.plname,
3965 codec.pltype, 3965 codec.pltype,
3966 codec.plfreq, 3966 codec.plfreq,
3967 codec.channels, 3967 codec.channels,
3968 (codec.rate < 0) ? 0 : codec.rate) == -1)) 3968 (codec.rate < 0) ? 0 : codec.rate) == -1))
3969 { 3969 {
3970 WEBRTC_TRACE(kTraceWarning, 3970 WEBRTC_TRACE(kTraceWarning,
3971 kTraceVoice, 3971 kTraceVoice,
3972 VoEId(_instanceId, _channelId), 3972 VoEId(_instanceId, _channelId),
3973 "Channel::RegisterReceiveCodecsToRTPModule() unable" 3973 "Channel::RegisterReceiveCodecsToRTPModule() unable"
3974 " to register %s (%d/%d/%d/%d) to RTP/RTCP receiver", 3974 " to register %s (%d/%d/%" PRIuS "/%d) to RTP/RTCP "
3975 "receiver",
3975 codec.plname, codec.pltype, codec.plfreq, 3976 codec.plname, codec.pltype, codec.plfreq,
3976 codec.channels, codec.rate); 3977 codec.channels, codec.rate);
3977 } 3978 }
3978 else 3979 else
3979 { 3980 {
3980 WEBRTC_TRACE(kTraceInfo, 3981 WEBRTC_TRACE(kTraceInfo,
3981 kTraceVoice, 3982 kTraceVoice,
3982 VoEId(_instanceId, _channelId), 3983 VoEId(_instanceId, _channelId),
3983 "Channel::RegisterReceiveCodecsToRTPModule() %s " 3984 "Channel::RegisterReceiveCodecsToRTPModule() %s "
3984 "(%d/%d/%d/%d) has been added to the RTP/RTCP " 3985 "(%d/%d/%" PRIuS "/%d) has been added to the RTP/RTCP "
3985 "receiver", 3986 "receiver",
3986 codec.plname, codec.pltype, codec.plfreq, 3987 codec.plname, codec.pltype, codec.plfreq,
3987 codec.channels, codec.rate); 3988 codec.channels, codec.rate);
3988 } 3989 }
3989 } 3990 }
3990 } 3991 }
3991 3992
3992 // Assuming this method is called with valid payload type. 3993 // Assuming this method is called with valid payload type.
3993 int Channel::SetRedPayloadType(int red_payload_type) { 3994 int Channel::SetRedPayloadType(int red_payload_type) {
3994 CodecInst codec; 3995 CodecInst codec;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
4103 int64_t min_rtt = 0; 4104 int64_t min_rtt = 0;
4104 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) 4105 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt)
4105 != 0) { 4106 != 0) {
4106 return 0; 4107 return 0;
4107 } 4108 }
4108 return rtt; 4109 return rtt;
4109 } 4110 }
4110 4111
4111 } // namespace voe 4112 } // namespace voe
4112 } // namespace webrtc 4113 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698