From 3f7f899a15c2685a8e45484f7b2c540771d28d90 Mon Sep 17 00:00:00 2001 From: "kwiberg@webrtc.org" Date: Mon, 13 Oct 2014 11:07:06 +0000 Subject: [PATCH] WebRtcIsac_UpdateBwEstimate et al.: Type byte streams as uint8, not uint16 This patch changes the signature of WebRtcIsac_UpdateBwEstimate, WebRtcIsacfix_UpdateBwEstimate, and WebRtcIsacfix_UpdateBwEstimate1 so that they expect the encoded data to be uint8 arrays, not uint16, which is more natural. The implementations of the functions are left unchanged for now. BUG=909 R=aluebs@webrtc.org, bjornv@webrtc.org, henrik.lundin@webrtc.org, turaj@webrtc.org Review URL: https://webrtc-codereview.appspot.com/25729004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7430 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../codecs/isac/fix/interface/isacfix.h | 4 ++-- .../audio_coding/codecs/isac/fix/source/isacfix.c | 10 ++++++---- .../audio_coding/codecs/isac/fix/test/kenny.cc | 13 +++++++------ .../audio_coding/codecs/isac/main/interface/isac.h | 2 +- .../audio_coding/codecs/isac/main/source/isac.c | 6 +++--- .../codecs/isac/main/source/isac_unittest.cc | 9 +++------ .../main/test/ReleaseTest-API/ReleaseTest-API.cc | 10 +++++++--- .../test/SwitchingSampRate/SwitchingSampRate.cc | 12 +++++++----- .../codecs/isac/main/test/simpleKenny.c | 9 ++++++--- webrtc/modules/audio_coding/main/acm2/acm_isac.cc | 2 +- .../audio_coding/neteq/audio_decoder_impl.cc | 4 ++-- 11 files changed, 45 insertions(+), 36 deletions(-) diff --git a/webrtc/modules/audio_coding/codecs/isac/fix/interface/isacfix.h b/webrtc/modules/audio_coding/codecs/isac/fix/interface/isacfix.h index 70fff13d5..4959d57ac 100644 --- a/webrtc/modules/audio_coding/codecs/isac/fix/interface/isacfix.h +++ b/webrtc/modules/audio_coding/codecs/isac/fix/interface/isacfix.h @@ -201,7 +201,7 @@ extern "C" { */ int16_t WebRtcIsacfix_UpdateBwEstimate1(ISACFIX_MainStruct *ISAC_main_inst, - const uint16_t *encoded, + const uint8_t* encoded, int32_t packet_size, uint16_t rtp_seq_number, uint32_t arr_ts); @@ -226,7 +226,7 @@ extern "C" { */ int16_t WebRtcIsacfix_UpdateBwEstimate(ISACFIX_MainStruct *ISAC_main_inst, - const uint16_t *encoded, + const uint8_t* encoded, int32_t packet_size, uint16_t rtp_seq_number, uint32_t send_ts, diff --git a/webrtc/modules/audio_coding/codecs/isac/fix/source/isacfix.c b/webrtc/modules/audio_coding/codecs/isac/fix/source/isacfix.c index 9f3bdb6e7..33bf373f3 100644 --- a/webrtc/modules/audio_coding/codecs/isac/fix/source/isacfix.c +++ b/webrtc/modules/audio_coding/codecs/isac/fix/source/isacfix.c @@ -636,7 +636,7 @@ int16_t WebRtcIsacfix_DecoderInit(ISACFIX_MainStruct *ISAC_main_inst) */ int16_t WebRtcIsacfix_UpdateBwEstimate1(ISACFIX_MainStruct *ISAC_main_inst, - const uint16_t *encoded, + const uint8_t* encoded, int32_t packet_size, uint16_t rtp_seq_number, uint32_t arr_ts) @@ -673,7 +673,8 @@ int16_t WebRtcIsacfix_UpdateBwEstimate1(ISACFIX_MainStruct *ISAC_main_inst, #ifndef WEBRTC_ARCH_BIG_ENDIAN for (k = 0; k < kRequiredEncodedLenBytes / 2; k++) { - streamdata.stream[k] = (uint16_t) (((uint16_t)encoded[k] >> 8)|((encoded[k] & 0xFF)<<8)); + uint16_t ek = ((const uint16_t*)encoded)[k]; + streamdata.stream[k] = (uint16_t) ((ek >> 8)|((ek & 0xff) << 8)); } #else memcpy(streamdata.stream, encoded, kRequiredEncodedLenBytes); @@ -717,7 +718,7 @@ int16_t WebRtcIsacfix_UpdateBwEstimate1(ISACFIX_MainStruct *ISAC_main_inst, */ int16_t WebRtcIsacfix_UpdateBwEstimate(ISACFIX_MainStruct *ISAC_main_inst, - const uint16_t *encoded, + const uint8_t* encoded, int32_t packet_size, uint16_t rtp_seq_number, uint32_t send_ts, @@ -758,7 +759,8 @@ int16_t WebRtcIsacfix_UpdateBwEstimate(ISACFIX_MainStruct *ISAC_main_inst, #ifndef WEBRTC_ARCH_BIG_ENDIAN for (k = 0; k < kRequiredEncodedLenBytes / 2; k++) { - streamdata.stream[k] = (uint16_t) ((encoded[k] >> 8)|((encoded[k] & 0xFF)<<8)); + uint16_t ek = ((const uint16_t*)encoded)[k]; + streamdata.stream[k] = (uint16_t) ((ek >> 8)|((ek & 0xff) <<8 )); } #else memcpy(streamdata.stream, encoded, kRequiredEncodedLenBytes); diff --git a/webrtc/modules/audio_coding/codecs/isac/fix/test/kenny.cc b/webrtc/modules/audio_coding/codecs/isac/fix/test/kenny.cc index 6b044f8c5..8e379c6a8 100644 --- a/webrtc/modules/audio_coding/codecs/isac/fix/test/kenny.cc +++ b/webrtc/modules/audio_coding/codecs/isac/fix/test/kenny.cc @@ -700,12 +700,13 @@ int main(int argc, char* argv[]) } if (testNum != 9) { - err = WebRtcIsacfix_UpdateBwEstimate(ISAC_main_inst, - streamdata, - stream_len, - BN_data.rtp_number, - BN_data.send_time, - BN_data.arrival_time); + err = WebRtcIsacfix_UpdateBwEstimate( + ISAC_main_inst, + reinterpret_cast(streamdata), + stream_len, + BN_data.rtp_number, + BN_data.send_time, + BN_data.arrival_time); if (err < 0) { /* exit if returned with error */ diff --git a/webrtc/modules/audio_coding/codecs/isac/main/interface/isac.h b/webrtc/modules/audio_coding/codecs/isac/main/interface/isac.h index a3786bf23..81b257c43 100644 --- a/webrtc/modules/audio_coding/codecs/isac/main/interface/isac.h +++ b/webrtc/modules/audio_coding/codecs/isac/main/interface/isac.h @@ -187,7 +187,7 @@ extern "C" { int16_t WebRtcIsac_UpdateBwEstimate( ISACStruct* ISAC_main_inst, - const uint16_t* encoded, + const uint8_t* encoded, int32_t packet_size, uint16_t rtp_seq_number, uint32_t send_ts, diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/isac.c b/webrtc/modules/audio_coding/codecs/isac/main/source/isac.c index 882712d37..05bdf2ac0 100644 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/isac.c +++ b/webrtc/modules/audio_coding/codecs/isac/main/source/isac.c @@ -996,7 +996,7 @@ int16_t WebRtcIsac_DecoderInit(ISACStruct* ISAC_main_inst) { * -1 - Error */ int16_t WebRtcIsac_UpdateBwEstimate(ISACStruct* ISAC_main_inst, - const uint16_t* encoded, + const uint8_t* encoded, int32_t packet_size, uint16_t rtp_seq_number, uint32_t send_ts, @@ -1026,8 +1026,8 @@ int16_t WebRtcIsac_UpdateBwEstimate(ISACStruct* ISAC_main_inst, #ifndef WEBRTC_ARCH_BIG_ENDIAN for (k = 0; k < 10; k++) { - streamdata.stream[k] = (uint8_t)((encoded[k >> 1] >> - ((k & 1) << 3)) & 0xFF); + uint16_t ek = ((const uint16_t*)encoded)[k >> 1]; + streamdata.stream[k] = (uint8_t)((ek >> ((k & 1) << 3)) & 0xff); } #else memcpy(streamdata.stream, encoded, 10); diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/isac_unittest.cc b/webrtc/modules/audio_coding/codecs/isac/main/source/isac_unittest.cc index 1d653731a..8b93e65ba 100644 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/isac_unittest.cc +++ b/webrtc/modules/audio_coding/codecs/isac/main/source/isac_unittest.cc @@ -79,13 +79,10 @@ TEST_F(IsacTest, IsacUpdateBWE) { WebRtcIsac_EncoderInit(isac_codec_, 0); WebRtcIsac_DecoderInit(isac_codec_); - // Encode & decode. int16_t encoded_bytes; - uint16_t* coded = reinterpret_cast(bitstream_); - uint16_t* coded_small = reinterpret_cast(bitstream_small_); // Test with call with a small packet (sync packet). - EXPECT_EQ(-1, WebRtcIsac_UpdateBwEstimate(isac_codec_, coded_small, 7, 1, + EXPECT_EQ(-1, WebRtcIsac_UpdateBwEstimate(isac_codec_, bitstream_small_, 7, 1, 12345, 56789)); // Encode 60 ms of data (needed to create a first packet). @@ -102,8 +99,8 @@ TEST_F(IsacTest, IsacUpdateBWE) { encoded_bytes = WebRtcIsac_Encode(isac_codec_, speech_data_, bitstream_); // Call to update bandwidth estimator with real data. - EXPECT_EQ(0, WebRtcIsac_UpdateBwEstimate(isac_codec_, coded, encoded_bytes, 1, - 12345, 56789)); + EXPECT_EQ(0, WebRtcIsac_UpdateBwEstimate(isac_codec_, bitstream_, + encoded_bytes, 1, 12345, 56789)); // Free memory. EXPECT_EQ(0, WebRtcIsac_Free(isac_codec_)); diff --git a/webrtc/modules/audio_coding/codecs/isac/main/test/ReleaseTest-API/ReleaseTest-API.cc b/webrtc/modules/audio_coding/codecs/isac/main/test/ReleaseTest-API/ReleaseTest-API.cc index e4365492a..e7e729ee6 100644 --- a/webrtc/modules/audio_coding/codecs/isac/main/test/ReleaseTest-API/ReleaseTest-API.cc +++ b/webrtc/modules/audio_coding/codecs/isac/main/test/ReleaseTest-API/ReleaseTest-API.cc @@ -857,9 +857,13 @@ int main(int argc, char* argv[]) if(testNum != 9) { - err = WebRtcIsac_UpdateBwEstimate(ISAC_main_inst, streamdata, - stream_len, BN_data.rtp_number, BN_data.sample_count, - BN_data.arrival_time); + err = WebRtcIsac_UpdateBwEstimate( + ISAC_main_inst, + reinterpret_cast(streamdata), + stream_len, + BN_data.rtp_number, + BN_data.sample_count, + BN_data.arrival_time); if(err < 0) { diff --git a/webrtc/modules/audio_coding/codecs/isac/main/test/SwitchingSampRate/SwitchingSampRate.cc b/webrtc/modules/audio_coding/codecs/isac/main/test/SwitchingSampRate/SwitchingSampRate.cc index 6253e0070..88b0944bf 100644 --- a/webrtc/modules/audio_coding/codecs/isac/main/test/SwitchingSampRate/SwitchingSampRate.cc +++ b/webrtc/modules/audio_coding/codecs/isac/main/test/SwitchingSampRate/SwitchingSampRate.cc @@ -411,11 +411,13 @@ int main(int argc, char* argv[]) } // BWE - if(WebRtcIsac_UpdateBwEstimate(codecInstance[receiverIdx], - bitStream, streamLen, packetData[senderIdx]->rtp_number, - packetData[senderIdx]->sample_count, - packetData[senderIdx]->arrival_time) < 0) - { + if (WebRtcIsac_UpdateBwEstimate( + codecInstance[receiverIdx], + reinterpret_cast(bitStream), + streamLen, + packetData[senderIdx]->rtp_number, + packetData[senderIdx]->sample_count, + packetData[senderIdx]->arrival_time) < 0) { printf(" BWE Error at client %d \n", receiverIdx + 1); return -1; } diff --git a/webrtc/modules/audio_coding/codecs/isac/main/test/simpleKenny.c b/webrtc/modules/audio_coding/codecs/isac/main/test/simpleKenny.c index 96aee1f13..e63e1e090 100644 --- a/webrtc/modules/audio_coding/codecs/isac/main/test/simpleKenny.c +++ b/webrtc/modules/audio_coding/codecs/isac/main/test/simpleKenny.c @@ -401,9 +401,12 @@ valid values are 8 and 16.\n", sampFreqKHz); get_arrival_time(cur_framesmpls, stream_len, bottleneck, &packetData, sampFreqKHz * 1000, sampFreqKHz * 1000); if(WebRtcIsac_UpdateBwEstimate(ISAC_main_inst, - payload, stream_len, packetData.rtp_number, - packetData.sample_count, - packetData.arrival_time) < 0) + (const uint8_t*)payload, + stream_len, + packetData.rtp_number, + packetData.sample_count, + packetData.arrival_time) + < 0) { printf(" BWE Error at client\n"); return -1; diff --git a/webrtc/modules/audio_coding/main/acm2/acm_isac.cc b/webrtc/modules/audio_coding/main/acm2/acm_isac.cc index e4f619599..89e52f4b0 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_isac.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_isac.cc @@ -754,7 +754,7 @@ int ACMISAC::IncomingPacket(const uint8_t* payload, CriticalSectionScoped lock(codec_inst_crit_sect_.get()); return ACM_ISAC_DECODE_BWE( static_cast(codec_inst_ptr_->inst), - reinterpret_cast(payload), + payload, static_cast(payload_len), rtp_sequence_number, rtp_timestamp, diff --git a/webrtc/modules/audio_coding/neteq/audio_decoder_impl.cc b/webrtc/modules/audio_coding/neteq/audio_decoder_impl.cc index 6c7269a35..028320a24 100644 --- a/webrtc/modules/audio_coding/neteq/audio_decoder_impl.cc +++ b/webrtc/modules/audio_coding/neteq/audio_decoder_impl.cc @@ -199,7 +199,7 @@ int AudioDecoderIsac::IncomingPacket(const uint8_t* payload, uint32_t rtp_timestamp, uint32_t arrival_timestamp) { return WebRtcIsac_UpdateBwEstimate(static_cast(state_), - reinterpret_cast(payload), + payload, static_cast(payload_len), rtp_sequence_number, rtp_timestamp, @@ -254,7 +254,7 @@ int AudioDecoderIsacFix::IncomingPacket(const uint8_t* payload, uint32_t arrival_timestamp) { return WebRtcIsacfix_UpdateBwEstimate( static_cast(state_), - reinterpret_cast(payload), + payload, static_cast(payload_len), rtp_sequence_number, rtp_timestamp, arrival_timestamp); }