From 1172988c794d15706b4c951dcbaa57b11221d225 Mon Sep 17 00:00:00 2001 From: "kwiberg@webrtc.org" Date: Mon, 13 Oct 2014 10:53:42 +0000 Subject: [PATCH] Some WebRtcIsac_* and WebRtcIsacfix_* functions: type encoded stream as uint8[] The affected functions are WebRtcIsacfix_ReadFrameLen WebRtcIsacfix_GetNewBitStream WebRtcIsacfix_ReadBwIndex and WebRtcIsac_ReadFrameLen WebRtcIsac_GetNewBitStream WebRtcIsac_ReadBwIndex WebRtcIsac_GetRedPayload BUG=909 R=aluebs@webrtc.org, henrik.lundin@webrtc.org Review URL: https://webrtc-codereview.appspot.com/22979004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7429 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../codecs/isac/fix/interface/isacfix.h | 6 +-- .../codecs/isac/fix/source/isacfix.c | 17 ++++---- .../codecs/isac/fix/test/kenny.cc | 8 ++-- .../codecs/isac/main/interface/isac.h | 8 ++-- .../codecs/isac/main/source/isac.c | 40 +++++++++---------- .../test/ReleaseTest-API/ReleaseTest-API.cc | 33 ++++++++++----- .../SwitchingSampRate/SwitchingSampRate.cc | 6 ++- .../codecs/isac/main/test/simpleKenny.c | 3 +- .../audio_coding/main/acm2/acm_isac.cc | 8 ++-- .../audio_coding/neteq/test/RTPencode.cc | 5 ++- 10 files changed, 75 insertions(+), 59 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 c113b034c..70fff13d5 100644 --- a/webrtc/modules/audio_coding/codecs/isac/fix/interface/isacfix.h +++ b/webrtc/modules/audio_coding/codecs/isac/fix/interface/isacfix.h @@ -357,7 +357,7 @@ extern "C" { * */ - int16_t WebRtcIsacfix_ReadFrameLen(const int16_t* encoded, + int16_t WebRtcIsacfix_ReadFrameLen(const uint8_t* encoded, int encoded_len_bytes, int16_t* frameLength); @@ -557,7 +557,7 @@ extern "C" { int16_t WebRtcIsacfix_GetNewBitStream(ISACFIX_MainStruct *ISAC_main_inst, int16_t bweIndex, float scale, - int16_t *encoded); + uint8_t* encoded); /**************************************************************************** @@ -608,7 +608,7 @@ extern "C" { * */ - int16_t WebRtcIsacfix_ReadBwIndex(const int16_t* encoded, + int16_t WebRtcIsacfix_ReadBwIndex(const uint8_t* encoded, int encoded_len_bytes, int16_t* rateIndex); 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 44fff0e92..9f3bdb6e7 100644 --- a/webrtc/modules/audio_coding/codecs/isac/fix/source/isacfix.c +++ b/webrtc/modules/audio_coding/codecs/isac/fix/source/isacfix.c @@ -536,7 +536,7 @@ int16_t WebRtcIsacfix_EncodeNb(ISACFIX_MainStruct *ISAC_main_inst, int16_t WebRtcIsacfix_GetNewBitStream(ISACFIX_MainStruct *ISAC_main_inst, int16_t bweIndex, float scale, - int16_t *encoded) + uint8_t* encoded) { ISACFIX_SubStruct *ISAC_inst; int16_t stream_len; @@ -564,8 +564,9 @@ int16_t WebRtcIsacfix_GetNewBitStream(ISACFIX_MainStruct *ISAC_main_inst, #ifndef WEBRTC_ARCH_BIG_ENDIAN for (k=0;k<(stream_len+1)>>1;k++) { - encoded[k] = (int16_t)( ( (uint16_t)(ISAC_inst->ISACenc_obj.bitstr_obj).stream[k] >> 8 ) - | (((ISAC_inst->ISACenc_obj.bitstr_obj).stream[k] & 0x00FF) << 8)); + ((int16_t*)encoded)[k] = (int16_t)( + ((uint16_t)(ISAC_inst->ISACenc_obj.bitstr_obj).stream[k] >> 8) | + (((ISAC_inst->ISACenc_obj.bitstr_obj).stream[k] & 0x00FF) << 8)); } #else @@ -1315,7 +1316,7 @@ int16_t WebRtcIsacfix_UpdateUplinkBw(ISACFIX_MainStruct* ISAC_main_inst, * */ -int16_t WebRtcIsacfix_ReadFrameLen(const int16_t* encoded, +int16_t WebRtcIsacfix_ReadFrameLen(const uint8_t* encoded, int encoded_len_bytes, int16_t* frameLength) { @@ -1334,7 +1335,8 @@ int16_t WebRtcIsacfix_ReadFrameLen(const int16_t* encoded, #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 = ((uint16_t*)encoded)[k]; + streamdata.stream[k] = (uint16_t)((ek >> 8) | ((ek & 0xff) << 8)); } #else memcpy(streamdata.stream, encoded, kRequiredEncodedLenBytes); @@ -1363,7 +1365,7 @@ int16_t WebRtcIsacfix_ReadFrameLen(const int16_t* encoded, * */ -int16_t WebRtcIsacfix_ReadBwIndex(const int16_t* encoded, +int16_t WebRtcIsacfix_ReadBwIndex(const uint8_t* encoded, int encoded_len_bytes, int16_t* rateIndex) { @@ -1382,7 +1384,8 @@ int16_t WebRtcIsacfix_ReadBwIndex(const int16_t* encoded, #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 = ((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 39a413b6a..6b044f8c5 100644 --- a/webrtc/modules/audio_coding/codecs/isac/fix/test/kenny.cc +++ b/webrtc/modules/audio_coding/codecs/isac/fix/test/kenny.cc @@ -572,12 +572,14 @@ int main(int argc, char* argv[]) if (stream_len>0) { if (testCE == 1) { err = WebRtcIsacfix_ReadBwIndex( - (int16_t*)streamdata, stream_len, &bwe); + reinterpret_cast(streamdata), + stream_len, + &bwe); stream_len = WebRtcIsacfix_GetNewBitStream( ISAC_main_inst, bwe, scale, - (int16_t*)streamdata); + reinterpret_cast(streamdata)); } else if (testCE == 2) { /* transcode function not supported */ } else if (testCE == 3) { @@ -742,7 +744,7 @@ int main(int argc, char* argv[]) short FL; /* Call getFramelen, only used here for function test */ err = WebRtcIsacfix_ReadFrameLen( - (int16_t*)streamdata, stream_len, &FL); + reinterpret_cast(streamdata), stream_len, &FL); declen = WebRtcIsacfix_Decode( ISAC_main_inst, streamdata, stream_len, decoded, speechType ); /* Error check */ 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 406705802..a3786bf23 100644 --- a/webrtc/modules/audio_coding/codecs/isac/main/interface/isac.h +++ b/webrtc/modules/audio_coding/codecs/isac/main/interface/isac.h @@ -319,7 +319,7 @@ extern "C" { int16_t WebRtcIsac_ReadFrameLen( ISACStruct* ISAC_main_inst, - const int16_t* encoded, + const uint8_t* encoded, int16_t* frameLength); @@ -574,7 +574,7 @@ extern "C" { int16_t bweIndex, int16_t jitterInfo, int32_t rate, - int16_t* encoded, + uint8_t* encoded, int16_t isRCU); @@ -631,7 +631,7 @@ extern "C" { */ int16_t WebRtcIsac_ReadBwIndex( - const int16_t* encoded, + const uint8_t* encoded, int16_t* bweIndex); @@ -679,7 +679,7 @@ extern "C" { */ int16_t WebRtcIsac_GetRedPayload( ISACStruct* ISAC_main_inst, - int16_t* encoded); + uint8_t* encoded); /**************************************************************************** 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 13170a084..882712d37 100644 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/isac.c +++ b/webrtc/modules/audio_coding/codecs/isac/main/source/isac.c @@ -786,7 +786,7 @@ int16_t WebRtcIsac_GetNewBitStream(ISACStruct* ISAC_main_inst, int16_t bweIndex, int16_t jitterInfo, int32_t rate, - int16_t* encoded, + uint8_t* encoded, int16_t isRCU) { Bitstr iSACBitStreamInst; /* Local struct for bitstream handling */ int16_t streamLenLB; @@ -799,7 +799,6 @@ int16_t WebRtcIsac_GetNewBitStream(ISACStruct* ISAC_main_inst, double rateLB; double rateUB; int32_t currentBN; - uint8_t* encodedPtrUW8 = (uint8_t*)encoded; uint32_t crc; #ifndef WEBRTC_ARCH_BIG_ENDIAN int16_t k; @@ -885,20 +884,20 @@ int16_t WebRtcIsac_GetNewBitStream(ISACStruct* ISAC_main_inst, } totalStreamLen = streamLenLB + streamLenUB + 1 + LEN_CHECK_SUM_WORD8; - encodedPtrUW8[streamLenLB] = streamLenUB + 1 + LEN_CHECK_SUM_WORD8; + encoded[streamLenLB] = streamLenUB + 1 + LEN_CHECK_SUM_WORD8; - memcpy(&encodedPtrUW8[streamLenLB + 1], iSACBitStreamInst.stream, + memcpy(&encoded[streamLenLB + 1], iSACBitStreamInst.stream, streamLenUB); - WebRtcIsac_GetCrc((int16_t*)(&(encodedPtrUW8[streamLenLB + 1])), + WebRtcIsac_GetCrc((int16_t*)(&(encoded[streamLenLB + 1])), streamLenUB, &crc); #ifndef WEBRTC_ARCH_BIG_ENDIAN for (k = 0; k < LEN_CHECK_SUM_WORD8; k++) { - encodedPtrUW8[totalStreamLen - LEN_CHECK_SUM_WORD8 + k] = + encoded[totalStreamLen - LEN_CHECK_SUM_WORD8 + k] = (uint8_t)((crc >> (24 - k * 8)) & 0xFF); } #else - memcpy(&encodedPtrUW8[streamLenLB + streamLenUB + 1], &crc, + memcpy(&encoded[streamLenLB + streamLenUB + 1], &crc, LEN_CHECK_SUM_WORD8); #endif return totalStreamLen; @@ -1734,7 +1733,7 @@ int16_t WebRtcIsac_UpdateUplinkBw(ISACStruct* ISAC_main_inst, * - bweIndex : Bandwidth estimate in bit-stream * */ -int16_t WebRtcIsac_ReadBwIndex(const int16_t* encoded, +int16_t WebRtcIsac_ReadBwIndex(const uint8_t* encoded, int16_t* bweIndex) { Bitstr streamdata; #ifndef WEBRTC_ARCH_BIG_ENDIAN @@ -1746,8 +1745,8 @@ int16_t WebRtcIsac_ReadBwIndex(const int16_t* encoded, #ifndef WEBRTC_ARCH_BIG_ENDIAN for (k = 0; k < 10; k++) { - streamdata.stream[k] = (uint8_t)((encoded[k >> 1] >> - ((k & 1) << 3)) & 0xFF); + int16_t ek2 = ((const int16_t*)encoded)[k >> 1]; + streamdata.stream[k] = (uint8_t)((ek2 >> ((k & 1) << 3)) & 0xff); } #else memcpy(streamdata.stream, encoded, 10); @@ -1783,7 +1782,7 @@ int16_t WebRtcIsac_ReadBwIndex(const int16_t* encoded, * */ int16_t WebRtcIsac_ReadFrameLen(ISACStruct* ISAC_main_inst, - const int16_t* encoded, + const uint8_t* encoded, int16_t* frameLength) { Bitstr streamdata; #ifndef WEBRTC_ARCH_BIG_ENDIAN @@ -1796,8 +1795,8 @@ int16_t WebRtcIsac_ReadFrameLen(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); + int16_t ek2 = ((const int16_t*)encoded)[k >> 1]; + streamdata.stream[k] = (uint8_t)((ek2 >> ((k & 1) << 3)) & 0xff); } #else memcpy(streamdata.stream, encoded, 10); @@ -2096,13 +2095,12 @@ int16_t WebRtcIsac_SetMaxRate(ISACStruct* ISAC_main_inst, * : -1 - Error */ int16_t WebRtcIsac_GetRedPayload(ISACStruct* ISAC_main_inst, - int16_t* encoded) { + uint8_t* encoded) { Bitstr iSACBitStreamInst; int16_t streamLenLB; int16_t streamLenUB; int16_t streamLen; int16_t totalLenUB; - uint8_t* ptrEncodedUW8 = (uint8_t*)encoded; ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; #ifndef WEBRTC_ARCH_BIG_ENDIAN int k; @@ -2125,7 +2123,7 @@ int16_t WebRtcIsac_GetRedPayload(ISACStruct* ISAC_main_inst, } /* convert from bytes to int16_t. */ - memcpy(ptrEncodedUW8, iSACBitStreamInst.stream, streamLenLB); + memcpy(encoded, iSACBitStreamInst.stream, streamLenLB); streamLen = streamLenLB; if (instISAC->bandwidthKHz == isac8kHz) { return streamLenLB; @@ -2154,19 +2152,19 @@ int16_t WebRtcIsac_GetRedPayload(ISACStruct* ISAC_main_inst, (streamLenUB > 0)) { uint32_t crc; streamLen += totalLenUB; - ptrEncodedUW8[streamLenLB] = (uint8_t)totalLenUB; - memcpy(&ptrEncodedUW8[streamLenLB + 1], iSACBitStreamInst.stream, + encoded[streamLenLB] = (uint8_t)totalLenUB; + memcpy(&encoded[streamLenLB + 1], iSACBitStreamInst.stream, streamLenUB); - WebRtcIsac_GetCrc((int16_t*)(&(ptrEncodedUW8[streamLenLB + 1])), + WebRtcIsac_GetCrc((int16_t*)(&(encoded[streamLenLB + 1])), streamLenUB, &crc); #ifndef WEBRTC_ARCH_BIG_ENDIAN for (k = 0; k < LEN_CHECK_SUM_WORD8; k++) { - ptrEncodedUW8[streamLen - LEN_CHECK_SUM_WORD8 + k] = + encoded[streamLen - LEN_CHECK_SUM_WORD8 + k] = (uint8_t)((crc >> (24 - k * 8)) & 0xFF); } #else - memcpy(&ptrEncodedUW8[streamLenLB + streamLenUB + 1], &crc, + memcpy(&encoded[streamLenLB + streamLenUB + 1], &crc, LEN_CHECK_SUM_WORD8); #endif } 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 8af4e6f99..e4365492a 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 @@ -687,8 +687,12 @@ int main(int argc, char* argv[]) /************************* Main Transcoding stream *******************************/ WebRtcIsac_GetDownLinkBwIndex(ISAC_main_inst, &bnIdxTC, &jitterInfoTC); streamLenTransCoding = WebRtcIsac_GetNewBitStream( - ISAC_main_inst, bnIdxTC, jitterInfoTC, rateTransCoding, - (int16_t*)streamDataTransCoding, false); + ISAC_main_inst, + bnIdxTC, + jitterInfoTC, + rateTransCoding, + reinterpret_cast(streamDataTransCoding), + false); if(streamLenTransCoding < 0) { fprintf(stderr, "Error in trans-coding\n"); @@ -714,9 +718,10 @@ int main(int argc, char* argv[]) return -1; } - WebRtcIsac_ReadBwIndex((int16_t*)streamDataTransCoding, &indexStream); - if(indexStream != bnIdxTC) - { + WebRtcIsac_ReadBwIndex(reinterpret_cast( + streamDataTransCoding), + &indexStream); + if (indexStream != bnIdxTC) { fprintf(stderr, "Error in inserting Bandwidth index into transcoding stream.\n"); exit(0); } @@ -780,14 +785,18 @@ int main(int argc, char* argv[]) // RED. if(lostFrame) { - stream_len = WebRtcIsac_GetRedPayload(ISAC_main_inst, - (int16_t*)streamdata); + stream_len = WebRtcIsac_GetRedPayload( + ISAC_main_inst, reinterpret_cast(streamdata)); if(doTransCoding) { streamLenTransCoding = WebRtcIsac_GetNewBitStream( - ISAC_main_inst, bnIdxTC, jitterInfoTC, rateTransCoding, - (int16_t*)streamDataTransCoding, true); + ISAC_main_inst, + bnIdxTC, + jitterInfoTC, + rateTransCoding, + reinterpret_cast(streamDataTransCoding), + true); if(streamLenTransCoding < 0) { fprintf(stderr, "Error in RED trans-coding\n"); @@ -872,8 +881,10 @@ int main(int argc, char* argv[]) } /* Call getFramelen, only used here for function test */ - err = WebRtcIsac_ReadFrameLen(ISAC_main_inst, - (int16_t*)streamdata, &FL); + err = WebRtcIsac_ReadFrameLen( + ISAC_main_inst, + reinterpret_cast(streamdata), + &FL); if(err < 0) { /* exit if returned with error */ 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 72d3fe861..6253e0070 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 @@ -287,8 +287,10 @@ int main(int argc, char* argv[]) (uint8_t*)bitStream); int16_t ggg; if (streamLen > 0) { - if(( WebRtcIsac_ReadFrameLen(codecInstance[receiverIdx], - (short *) bitStream, &ggg))<0) + if ((WebRtcIsac_ReadFrameLen( + codecInstance[receiverIdx], + reinterpret_cast(bitStream), + &ggg)) < 0) printf("ERROR\n"); } 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 2df5a84e4..96aee1f13 100644 --- a/webrtc/modules/audio_coding/codecs/isac/main/test/simpleKenny.c +++ b/webrtc/modules/audio_coding/codecs/isac/main/test/simpleKenny.c @@ -395,7 +395,8 @@ valid values are 8 and 16.\n", sampFreqKHz); break; } - rcuStreamLen = WebRtcIsac_GetRedPayload(ISAC_main_inst, (int16_t*)payloadRCU); + rcuStreamLen = WebRtcIsac_GetRedPayload( + ISAC_main_inst, (uint8_t*)payloadRCU); get_arrival_time(cur_framesmpls, stream_len, bottleneck, &packetData, sampFreqKHz * 1000, sampFreqKHz * 1000); diff --git a/webrtc/modules/audio_coding/main/acm2/acm_isac.cc b/webrtc/modules/audio_coding/main/acm2/acm_isac.cc index f3682f1e3..e4f619599 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_isac.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_isac.cc @@ -211,7 +211,7 @@ static int16_t ACMISACFixGetNewBitstream(ACM_ISAC_STRUCT* inst, int16_t bwe_index, int16_t /* jitter_index */, int32_t rate, - int16_t* bitstream, + uint8_t* bitstream, bool is_red) { if (is_red) { // RED not supported with iSACFIX @@ -437,7 +437,7 @@ int16_t ACMISAC::Transcode(uint8_t* bitstream, *bitstream_len_byte = ACM_ISAC_GETNEWBITSTREAM( codec_inst_ptr_->inst, q_bwe, jitter_info, rate, - reinterpret_cast(bitstream), (is_red) ? 1 : 0); + bitstream, (is_red) ? 1 : 0); if (*bitstream_len_byte < 0) { // error happened @@ -591,9 +591,7 @@ int32_t ACMISAC::GetRedPayloadSafe( #else uint8_t* red_payload, int16_t* payload_bytes) { CriticalSectionScoped lock(codec_inst_crit_sect_.get()); - int16_t bytes = - WebRtcIsac_GetRedPayload( - codec_inst_ptr_->inst, reinterpret_cast(red_payload)); + int16_t bytes = WebRtcIsac_GetRedPayload(codec_inst_ptr_->inst, red_payload); if (bytes < 0) { return -1; } diff --git a/webrtc/modules/audio_coding/neteq/test/RTPencode.cc b/webrtc/modules/audio_coding/neteq/test/RTPencode.cc index 92bccee2f..ab338a73c 100644 --- a/webrtc/modules/audio_coding/neteq/test/RTPencode.cc +++ b/webrtc/modules/audio_coding/neteq/test/RTPencode.cc @@ -261,7 +261,7 @@ int main(int argc, char* argv[]) uint32_t red_TS[2] = {0}; uint16_t red_len[2] = {0}; int RTPheaderLen=12; - unsigned char red_data[8000]; + uint8_t red_data[8000]; #ifdef INSERT_OLD_PACKETS uint16_t old_length, old_plen; int old_enc_len; @@ -755,7 +755,8 @@ int main(int argc, char* argv[]) if(usedCodec==webrtc::kDecoderISAC) { assert(!usingStereo); // Cannot handle stereo yet - red_len[0] = WebRtcIsac_GetRedPayload(ISAC_inst[0], (int16_t*)red_data); + red_len[0] = + WebRtcIsac_GetRedPayload(ISAC_inst[0], red_data); } else {