diff --git a/src/modules/audio_coding/codecs/cng/test/CNG.cc b/src/modules/audio_coding/codecs/cng/test/CNG.cc index b24783191..e3cabbb5c 100644 --- a/src/modules/audio_coding/codecs/cng/test/CNG.cc +++ b/src/modules/audio_coding/codecs/cng/test/CNG.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -38,12 +38,12 @@ int main(int argc, char* argv[]) short size; int samps=0; - + if (argc < 5){ printf("Usage:\n CNG.exe infile outfile samplingfreq(Hz) interval(ms) order\n\n"); return(0); } - + infile=fopen(argv[1],"rb"); if (infile==NULL){ printf("file %s does not exist\n",argv[1]); @@ -53,12 +53,12 @@ int main(int argc, char* argv[]) statefile=fopen("CNGVAD.d","wb"); if (outfile==NULL){ printf("file %s could not be created\n",argv[2]); - return(0); + return(0); } - + unsigned int fs=16000; short frameLen=fs/50; - + #ifndef ASSIGN res=WebRtcCng_CreateEnc(&e_inst); if (res < 0) { @@ -74,18 +74,18 @@ int main(int argc, char* argv[]) fprintf(stderr,"\n\n Error in initialization: %d.\n\n", errtype); exit(EXIT_FAILURE); } - + #else - + // Test the Assign-functions - int Esize, Dsize; + int Esize, Dsize; void *Eaddr, *Daddr; - + res=WebRtcCng_AssignSizeEnc(&Esize); res=WebRtcCng_AssignSizeDec(&Dsize); Eaddr=malloc(Esize); Daddr=malloc(Dsize); - + res=WebRtcCng_AssignEnc(&e_inst, Eaddr); if (res < 0) { /* exit if returned with error */ @@ -93,7 +93,7 @@ int main(int argc, char* argv[]) fprintf(stderr,"\n\n Error in initialization: %d.\n\n", errtype); exit(EXIT_FAILURE); } - + res=WebRtcCng_AssignDec(&d_inst, Daddr); if (res < 0) { /* exit if returned with error */ @@ -101,35 +101,34 @@ int main(int argc, char* argv[]) fprintf(stderr,"\n\n Error in initialization: %d.\n\n", errtype); exit(EXIT_FAILURE); } - + #endif - - res=WebRtcCng_InitEnc(e_inst,atoi(argv[3]),atoi(argv[4]),atoi(argv[5])); + + res=WebRtcCng_InitEnc(e_inst,atoi(argv[3]),atoi(argv[4]),atoi(argv[5])); if (res < 0) { /* exit if returned with error */ errtype=WebRtcCng_GetErrorCodeEnc(e_inst); fprintf(stderr,"\n\n Error in initialization: %d.\n\n", errtype); exit(EXIT_FAILURE); } - - res=WebRtcCng_InitDec(d_inst); + + res=WebRtcCng_InitDec(d_inst); if (res < 0) { /* exit if returned with error */ errtype=WebRtcCng_GetErrorCodeDec(d_inst); fprintf(stderr,"\n\n Error in initialization: %d.\n\n", errtype); exit(EXIT_FAILURE); } - - + static bool firstSilent=true; - + int numSamp=0; int speech=0; int silent=0; long cnt=0; - + while(fread(anaSpeech,2,frameLen,infile)==frameLen){ - + cnt++; if (cnt==60){ cnt=60; @@ -139,9 +138,9 @@ int main(int argc, char* argv[]) float temp[640]; for(unsigned int j=0;j0){ res=WebRtcCng_UpdateSid(d_inst,SIDpkt, size); if (res < 0) { @@ -205,21 +203,22 @@ int main(int argc, char* argv[]) else{ firstSilent=true; memcpy(genSpeech,anaSpeech,2*frameLen); - + memset(anaSpeech,0,frameLen*2); memset(state,0,frameLen*2); - + + } + if (fwrite(genSpeech, 2, frameLen, + outfile) != static_cast(frameLen)) { + return -1; + } + if (fwrite(state, 2, frameLen, + statefile) != static_cast(frameLen)) { + return -1; } - fwrite(genSpeech,2,frameLen,outfile); - fwrite(state,2,frameLen,statefile); - } - fclose(infile); fclose(outfile); fclose(statefile); return 0; -} - - - +} diff --git a/src/modules/audio_coding/codecs/g711/test/testG711.cc b/src/modules/audio_coding/codecs/g711/test/testG711.cc index 747f9229e..fd5452237 100644 --- a/src/modules/audio_coding/codecs/g711/test/testG711.cc +++ b/src/modules/audio_coding/codecs/g711/test/testG711.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -129,16 +129,22 @@ int main(int argc, char* argv[]) /* A-law encoding */ stream_len = WebRtcG711_EncodeA(NULL, shortdata, framelength, streamdata); if (argc==6){ - /* Write bits to file */ - fwrite(streamdata,sizeof(unsigned char),stream_len,bitp); + /* Write bits to file */ + if (fwrite(streamdata, sizeof(unsigned char), stream_len, + bitp) != static_cast(stream_len)) { + return -1; + } } err = WebRtcG711_DecodeA(NULL, streamdata, stream_len, decoded, speechType); } else if (!strcmp(law,"u")){ /* u-law encoding */ stream_len = WebRtcG711_EncodeU(NULL, shortdata, framelength, streamdata); if (argc==6){ - /* Write bits to file */ - fwrite(streamdata,sizeof(unsigned char),stream_len,bitp); + /* Write bits to file */ + if (fwrite(streamdata, sizeof(unsigned char), stream_len, + bitp) != static_cast(stream_len)) { + return -1; + } } err = WebRtcG711_DecodeU(NULL, streamdata, stream_len, decoded, speechType); } else { @@ -149,8 +155,11 @@ int main(int argc, char* argv[]) /* exit if returned with error */ printf("Error in encoder/decoder\n"); } else { - /* Write coded speech to file */ - fwrite(decoded,sizeof(short),framelength,outp); + /* Write coded speech to file */ + if (fwrite(decoded, sizeof(short), framelength, + outp) != static_cast(framelength)) { + return -1; + } } } diff --git a/src/modules/audio_coding/codecs/g722/test/testG722.cc b/src/modules/audio_coding/codecs/g722/test/testG722.cc index 9ef8f2d91..d2fdca3a8 100644 --- a/src/modules/audio_coding/codecs/g722/test/testG722.cc +++ b/src/modules/audio_coding/codecs/g722/test/testG722.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -133,10 +133,16 @@ int main(int argc, char* argv[]) /* exit if returned with error */ printf("Error in encoder/decoder\n"); } else { - /* Write coded bits to file */ - fwrite(streamdata,sizeof(short),stream_len/2,outbitp); - /* Write coded speech to file */ - fwrite(decoded,sizeof(short),framelength,outp); + /* Write coded bits to file */ + if (fwrite(streamdata, sizeof(short), stream_len/2, + outbitp) != static_cast(stream_len/2)) { + return -1; + } + /* Write coded speech to file */ + if (fwrite(decoded, sizeof(short), framelength, + outp) != static_cast(framelength)) { + return -1; + } } } @@ -154,4 +160,3 @@ int main(int argc, char* argv[]) return 0; } - diff --git a/src/modules/audio_coding/codecs/iSAC/fix/test/kenny.c b/src/modules/audio_coding/codecs/iSAC/fix/test/kenny.c index 1b9c44ca2..8b04c98ec 100644 --- a/src/modules/audio_coding/codecs/iSAC/fix/test/kenny.c +++ b/src/modules/audio_coding/codecs/iSAC/fix/test/kenny.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -628,7 +628,10 @@ int main(int argc, char* argv[]) errtype=WebRtcIsacfix_GetErrorCode(ISAC_main_inst); printf("\nError in encoder: %d.\n", errtype); } else { - fwrite(streamdata, sizeof(char), stream_len, outbits); + if (fwrite(streamdata, sizeof(char), + stream_len, outbits) != (size_t)stream_len) { + return -1; + } } cur_framesmpls += FRAMESAMPLES_10ms; @@ -777,7 +780,10 @@ int main(int argc, char* argv[]) } /* Write decoded speech frame to file */ - fwrite(decoded, sizeof(WebRtc_Word16), declen, outp); + if (fwrite(decoded, sizeof(WebRtc_Word16), + declen, outp) != (size_t)declen) { + return -1; + } // fprintf( ratefile, "%f \n", stream_len / ( ((double)declen)/ // ((double)FS) ) * 8 ); } else { diff --git a/src/modules/audio_coding/codecs/iSAC/main/test/ReleaseTest-API/ReleaseTest-API.cc b/src/modules/audio_coding/codecs/iSAC/main/test/ReleaseTest-API/ReleaseTest-API.cc index 19cff9ee0..04c5367f4 100644 --- a/src/modules/audio_coding/codecs/iSAC/main/test/ReleaseTest-API/ReleaseTest-API.cc +++ b/src/modules/audio_coding/codecs/iSAC/main/test/ReleaseTest-API/ReleaseTest-API.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -692,15 +692,24 @@ int main(int argc, char* argv[]) exit(0); } auxUW8 = (WebRtc_UWord8)(((streamLenTransCoding & 0xFF00) >> 8) & 0x00FF); - fwrite(&auxUW8, sizeof(WebRtc_UWord8), - 1, transcodingBitstream); + if (fwrite(&auxUW8, sizeof(WebRtc_UWord8), 1, + transcodingBitstream) != 1) { + return -1; + } auxUW8 = (WebRtc_UWord8)(streamLenTransCoding & 0x00FF); - fwrite(&auxUW8, sizeof(WebRtc_UWord8), - 1, transcodingBitstream); + if (fwrite(&auxUW8, sizeof(WebRtc_UWord8), + 1, transcodingBitstream) != 1) { + return -1; + } - fwrite((WebRtc_UWord8*)streamDataTransCoding, sizeof(WebRtc_UWord8), - streamLenTransCoding, transcodingBitstream); + if (fwrite((WebRtc_UWord8*)streamDataTransCoding, + sizeof(WebRtc_UWord8), + streamLenTransCoding, + transcodingBitstream) != + static_cast(streamLenTransCoding)) { + return -1; + } WebRtcIsac_ReadBwIndex((WebRtc_Word16*)streamDataTransCoding, &indexStream); if(indexStream != bnIdxTC) @@ -939,12 +948,18 @@ int main(int argc, char* argv[]) /* Write decoded speech frame to file */ if((declen > 0) && (numFileLoop == 0)) { - fwrite(decoded, sizeof(WebRtc_Word16), declen, outp); + if (fwrite(decoded, sizeof(WebRtc_Word16), declen, + outp) != static_cast(declen)) { + return -1; + } } if((declenTC > 0) && (numFileLoop == 0)) { - fwrite(decodedTC, sizeof(WebRtc_Word16), declen, transCodingFile); + if (fwrite(decodedTC, sizeof(WebRtc_Word16), declen, + transCodingFile) != static_cast(declen)) { + return -1; + } } diff --git a/src/modules/audio_coding/codecs/iSAC/main/test/SwitchingSampRate/SwitchingSampRate.cc b/src/modules/audio_coding/codecs/iSAC/main/test/SwitchingSampRate/SwitchingSampRate.cc index e0eed127c..cccae28a6 100644 --- a/src/modules/audio_coding/codecs/iSAC/main/test/SwitchingSampRate/SwitchingSampRate.cc +++ b/src/modules/audio_coding/codecs/iSAC/main/test/SwitchingSampRate/SwitchingSampRate.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -392,13 +392,19 @@ int main(int argc, char* argv[]) // Write the arrival time. if(senderIdx == 0) { - fwrite(&(packetData[senderIdx]->arrival_time), sizeof(unsigned int), 1, - arrivalTimeFile1); + if (fwrite(&(packetData[senderIdx]->arrival_time), + sizeof(unsigned int), + 1, arrivalTimeFile1) != 1) { + return -1; + } } else { - fwrite(&(packetData[senderIdx]->arrival_time), sizeof(unsigned int), 1, - arrivalTimeFile2); + if (fwrite(&(packetData[senderIdx]->arrival_time), + sizeof(unsigned int), + 1, arrivalTimeFile2) != 1) { + return -1; + } } // BWE @@ -426,13 +432,19 @@ int main(int argc, char* argv[]) { WebRtcSpl_UpsampleBy2(audioBuff60ms, lenDecodedAudio, resampledAudio60ms, resamplerState[receiverIdx]); - fwrite(resampledAudio60ms, sizeof(short), lenDecodedAudio << 1, - outFile[receiverIdx]); + if (fwrite(resampledAudio60ms, sizeof(short), lenDecodedAudio << 1, + outFile[receiverIdx]) != + static_cast(lenDecodedAudio << 1)) { + return -1; + } } else { - fwrite(audioBuff60ms, sizeof(short), lenDecodedAudio, - outFile[receiverIdx]); + if (fwrite(audioBuff60ms, sizeof(short), lenDecodedAudio, + outFile[receiverIdx]) != + static_cast(lenDecodedAudio)) { + return -1; + } } num10ms[senderIdx] = 0; } diff --git a/src/modules/audio_coding/codecs/iSAC/main/test/simpleKenny.c b/src/modules/audio_coding/codecs/iSAC/main/test/simpleKenny.c index d92ab89f2..be1588c64 100644 --- a/src/modules/audio_coding/codecs/iSAC/main/test/simpleKenny.c +++ b/src/modules/audio_coding/codecs/iSAC/main/test/simpleKenny.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -429,13 +429,20 @@ valid values are 8 and 16.\n", sampFreqKHz); if(onlyEncode) { - WebRtc_UWord8 auxUW8; - auxUW8 = (WebRtc_UWord8)(((stream_len & 0x7F00) >> 8) & 0xFF); - fwrite(&auxUW8, sizeof(WebRtc_UWord8), 1, outp); + WebRtc_UWord8 auxUW8; + auxUW8 = (WebRtc_UWord8)(((stream_len & 0x7F00) >> 8) & 0xFF); + if (fwrite(&auxUW8, sizeof(WebRtc_UWord8), 1, outp) != 1) { + return -1; + } - auxUW8 = (WebRtc_UWord8)(stream_len & 0xFF); - fwrite(&auxUW8, sizeof(WebRtc_UWord8), 1, outp); - fwrite(payload, 1, stream_len, outp); + auxUW8 = (WebRtc_UWord8)(stream_len & 0xFF); + if (fwrite(&auxUW8, sizeof(WebRtc_UWord8), 1, outp) != 1) { + return -1; + } + if (fwrite(payload, 1, stream_len, + outp) != (size_t)stream_len) { + return -1; + } } else { @@ -462,7 +469,10 @@ valid values are 8 and 16.\n", sampFreqKHz); } // Write decoded speech frame to file - fwrite(decoded, sizeof(WebRtc_Word16), declen, outp); + if (fwrite(decoded, sizeof(WebRtc_Word16), + declen, outp) != (size_t)declen) { + return -1; + } cur_framesmpls = declen; } // Update Statistics diff --git a/src/modules/audio_coding/codecs/ilbc/test/iLBC_test.c b/src/modules/audio_coding/codecs/ilbc/test/iLBC_test.c index d2c9ba53c..19569acbd 100644 --- a/src/modules/audio_coding/codecs/ilbc/test/iLBC_test.c +++ b/src/modules/audio_coding/codecs/ilbc/test/iLBC_test.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -168,7 +168,11 @@ int main(int argc, char* argv[]) /* write byte file */ - fwrite(encoded_data, sizeof(WebRtc_Word16), ((len+1)/sizeof(WebRtc_Word16)), efileid); + if (fwrite(encoded_data, sizeof(WebRtc_Word16), + ((len+1)/sizeof(WebRtc_Word16)), efileid) != + (size_t)(((len+1)/sizeof(WebRtc_Word16)))) { + return -1; + } /* get channel data if provided */ if (argc==6) { @@ -204,7 +208,10 @@ int main(int argc, char* argv[]) /* write output file */ - fwrite(decoded_data,sizeof(WebRtc_Word16),len,ofileid); + if (fwrite(decoded_data, sizeof(WebRtc_Word16), len, + ofileid) != (size_t)len) { + return -1; + } } /* close files */ diff --git a/src/modules/audio_coding/main/source/audio_coding_module_impl.cc b/src/modules/audio_coding/main/source/audio_coding_module_impl.cc index 917122196..eeeecd898 100644 --- a/src/modules/audio_coding/main/source/audio_coding_module_impl.cc +++ b/src/modules/audio_coding/main/source/audio_coding_module_impl.cc @@ -431,9 +431,16 @@ WebRtc_Word32 AudioCodingModuleImpl::Process() { CriticalSectionScoped lock(*_callbackCritSect); #ifdef ACM_QA_TEST if(_outgoingPL != NULL) { - fwrite(&rtp_timestamp, sizeof(WebRtc_UWord32), 1, _outgoingPL); - fwrite(¤t_payload_type, sizeof(WebRtc_UWord8), 1, _outgoingPL); - fwrite(&length_bytes, sizeof(WebRtc_Word16), 1, _outgoingPL); + if (fwrite(&rtp_timestamp, sizeof(WebRtc_UWord32), 1, _outgoingPL) != 1) { + return -1; + } + if (fwrite(¤t_payload_type, sizeof(WebRtc_UWord8), + 1, _outgoingPL) != 1) { + return -1; + } + if (fwrite(&length_bytes, sizeof(WebRtc_Word16), 1, _outgoingPL) != 1) { + return -1; + } } #endif @@ -1489,11 +1496,18 @@ WebRtc_Word32 AudioCodingModuleImpl::IncomingPacket( CriticalSectionScoped lock(*_acmCritSect); #ifdef ACM_QA_TEST if(_incomingPL != NULL) { - fwrite(&rtp_info.header.timestamp, sizeof(WebRtc_UWord32), 1, - _incomingPL); - fwrite(&rtp_info.header.payloadType, sizeof(WebRtc_UWord8), 1, - _incomingPL); - fwrite(&payload_length, sizeof(WebRtc_Word16), 1, _incomingPL); + if (fwrite(&rtp_info.header.timestamp, sizeof(WebRtc_UWord32), + 1, _incomingPL) != 1) { + return -1; + } + if (fwrite(&rtp_info.header.payloadType, sizeof(WebRtc_UWord8), + 1, _incomingPL) != 1) { + return -1; + } + if (fwrite(&payload_length, sizeof(WebRtc_Word16), + 1, _incomingPL) != 1) { + return -1; + } } #endif diff --git a/src/modules/audio_coding/main/test/PCMFile.cc b/src/modules/audio_coding/main/test/PCMFile.cc index bf231f085..40a3675a5 100644 --- a/src/modules/audio_coding/main/test/PCMFile.cc +++ b/src/modules/audio_coding/main/test/PCMFile.cc @@ -181,8 +181,11 @@ WebRtc_Word32 PCMFile::Read10MsData(AudioFrame& audio_frame) { void PCMFile::Write10MsData(AudioFrame& audio_frame) { if (audio_frame.num_channels_ == 1) { if (!save_stereo_) { - fwrite(audio_frame.data_, sizeof(WebRtc_UWord16), - audio_frame.samples_per_channel_, pcm_file_); + if (fwrite(audio_frame.data_, sizeof(WebRtc_UWord16), + audio_frame.samples_per_channel_, pcm_file_) != + static_cast(audio_frame.samples_per_channel_)) { + return; + } } else { WebRtc_Word16* stereo_audio = new WebRtc_Word16[2 * audio_frame.samples_per_channel_]; @@ -191,20 +194,29 @@ void PCMFile::Write10MsData(AudioFrame& audio_frame) { stereo_audio[k << 1] = audio_frame.data_[k]; stereo_audio[(k << 1) + 1] = audio_frame.data_[k]; } - fwrite(stereo_audio, sizeof(WebRtc_Word16), - 2 * audio_frame.samples_per_channel_, pcm_file_); + if (fwrite(stereo_audio, sizeof(WebRtc_Word16), + 2 * audio_frame.samples_per_channel_, pcm_file_) != + static_cast(2 * audio_frame.samples_per_channel_)) { + return; + } delete[] stereo_audio; } } else { - fwrite(audio_frame.data_, sizeof(WebRtc_Word16), - audio_frame.num_channels_ * audio_frame.samples_per_channel_, - pcm_file_); + if (fwrite(audio_frame.data_, sizeof(WebRtc_Word16), + audio_frame.num_channels_ * audio_frame.samples_per_channel_, + pcm_file_) != static_cast( + audio_frame.num_channels_ * audio_frame.samples_per_channel_)) { + return; + } } } void PCMFile::Write10MsData(WebRtc_Word16* playout_buffer, WebRtc_UWord16 length_smpls) { - fwrite(playout_buffer, sizeof(WebRtc_UWord16), length_smpls, pcm_file_); + if (fwrite(playout_buffer, sizeof(WebRtc_UWord16), + length_smpls, pcm_file_) != length_smpls) { + return; + } } void PCMFile::Close() { diff --git a/src/modules/audio_coding/main/test/RTPFile.cc b/src/modules/audio_coding/main/test/RTPFile.cc index 91ba94695..37f9d3ce2 100644 --- a/src/modules/audio_coding/main/test/RTPFile.cc +++ b/src/modules/audio_coding/main/test/RTPFile.cc @@ -165,12 +165,23 @@ void RTPFile::WriteHeader() { // Write data in a format that NetEQ and RTP Play can parse fprintf(_rtpFile, "#!RTPencode%s\n", "1.0"); - WebRtc_UWord32 dummy_variable = 0; // should be converted to network endian format, but does not matter when 0 - fwrite(&dummy_variable, 4, 1, _rtpFile); - fwrite(&dummy_variable, 4, 1, _rtpFile); - fwrite(&dummy_variable, 4, 1, _rtpFile); - fwrite(&dummy_variable, 2, 1, _rtpFile); - fwrite(&dummy_variable, 2, 1, _rtpFile); + WebRtc_UWord32 dummy_variable = 0; + // should be converted to network endian format, but does not matter when 0 + if (fwrite(&dummy_variable, 4, 1, _rtpFile) != 1) { + return; + } + if (fwrite(&dummy_variable, 4, 1, _rtpFile) != 1) { + return; + } + if (fwrite(&dummy_variable, 4, 1, _rtpFile) != 1) { + return; + } + if (fwrite(&dummy_variable, 2, 1, _rtpFile) != 1) { + return; + } + if (fwrite(&dummy_variable, 2, 1, _rtpFile) != 1) { + return; + } fflush(_rtpFile); } @@ -205,11 +216,21 @@ void RTPFile::Write(const WebRtc_UWord8 payloadType, const WebRtc_UWord32 timeSt offsetMs = (timeStamp/(frequency/1000)); offsetMs = htonl(offsetMs); - fwrite(&lengthBytes, 2, 1, _rtpFile); - fwrite(&plen, 2, 1, _rtpFile); - fwrite(&offsetMs, 4, 1, _rtpFile); - fwrite(rtpHeader, 12, 1, _rtpFile); - fwrite(payloadData, 1, payloadSize, _rtpFile); + if (fwrite(&lengthBytes, 2, 1, _rtpFile) != 1) { + return; + } + if (fwrite(&plen, 2, 1, _rtpFile) != 1) { + return; + } + if (fwrite(&offsetMs, 4, 1, _rtpFile) != 1) { + return; + } + if (fwrite(rtpHeader, 12, 1, _rtpFile) != 1) { + return; + } + if (fwrite(payloadData, 1, payloadSize, _rtpFile) != payloadSize) { + return; + } } WebRtc_UWord16 RTPFile::Read(WebRtcRTPHeader* rtpInfo, diff --git a/src/modules/audio_coding/neteq/automode.c b/src/modules/audio_coding/neteq/automode.c index 815739e5d..d8d56c692 100644 --- a/src/modules/audio_coding/neteq/automode.c +++ b/src/modules/audio_coding/neteq/automode.c @@ -378,7 +378,9 @@ WebRtc_Word16 WebRtcNetEQ_CalcOptimalBufLvl(AutomodeInst_t *inst, WebRtc_Word32 #ifdef NETEQ_DELAY_LOGGING /* special code for offline delay logging */ temp_var = NETEQ_DELAY_LOGGING_SIGNAL_OPTBUF; - fwrite( &temp_var, sizeof(int), 1, delay_fid2 ); + if (fwrite( &temp_var, sizeof(int), 1, delay_fid2 ) != 1) { + return -1; + } temp_var = (int) (Bopt * inst->packetSpeechLenSamp); #endif @@ -518,7 +520,9 @@ WebRtc_Word16 WebRtcNetEQ_CalcOptimalBufLvl(AutomodeInst_t *inst, WebRtc_Word32 #ifdef NETEQ_DELAY_LOGGING /* special code for offline delay logging */ - fwrite( &temp_var, sizeof(int), 1, delay_fid2 ); + if (fwrite( &temp_var, sizeof(int), 1, delay_fid2 ) != 1) { + return -1; + } #endif /* Sanity check: Bopt must be strictly positive */ diff --git a/src/modules/audio_coding/neteq/packet_buffer.c b/src/modules/audio_coding/neteq/packet_buffer.c index 2a94c8a13..8f09b0726 100644 --- a/src/modules/audio_coding/neteq/packet_buffer.c +++ b/src/modules/audio_coding/neteq/packet_buffer.c @@ -317,14 +317,23 @@ int WebRtcNetEQ_PacketBufferInsert(PacketBuf_t *bufferInst, const RTPPacket_t *R if (*flushed) { temp_var = NETEQ_DELAY_LOGGING_SIGNAL_FLUSH; - fwrite( &temp_var, sizeof(int), 1, delay_fid2 ); + if (fwrite(&temp_var, sizeof(int), 1, delay_fid2) != 1) { + return -1; + } } temp_var = NETEQ_DELAY_LOGGING_SIGNAL_RECIN; - fwrite( &temp_var, sizeof(int), 1, delay_fid2 ); - fwrite( &RTPpacket->timeStamp, sizeof(WebRtc_UWord32), 1, delay_fid2 ); - fwrite( &RTPpacket->seqNumber, sizeof(WebRtc_UWord16), 1, delay_fid2 ); - fwrite( &RTPpacket->payloadType, sizeof(int), 1, delay_fid2 ); - fwrite( &RTPpacket->payloadLen, sizeof(WebRtc_Word16), 1, delay_fid2 ); + if ((fwrite(&temp_var, sizeof(int), + 1, delay_fid2) != 1) || + (fwrite(&RTPpacket->timeStamp, sizeof(WebRtc_UWord32), + 1, delay_fid2) != 1) || + (fwrite(&RTPpacket->seqNumber, sizeof(WebRtc_UWord16), + 1, delay_fid2) != 1) || + (fwrite(&RTPpacket->payloadType, sizeof(int), + 1, delay_fid2) != 1) || + (fwrite(&RTPpacket->payloadLen, sizeof(WebRtc_Word16), + 1, delay_fid2) != 1)) { + return -1; + } tot_received_packets++; #endif /* NETEQ_DELAY_LOGGING */ diff --git a/src/modules/audio_coding/neteq/recout.c b/src/modules/audio_coding/neteq/recout.c index f021f455b..896a4b8dd 100644 --- a/src/modules/audio_coding/neteq/recout.c +++ b/src/modules/audio_coding/neteq/recout.c @@ -318,8 +318,12 @@ int WebRtcNetEQ_RecOutInternal(DSPInst_t *inst, WebRtc_Word16 *pw16_outData, } #ifdef NETEQ_DELAY_LOGGING temp_var = NETEQ_DELAY_LOGGING_SIGNAL_CHANGE_FS; - fwrite(&temp_var, sizeof(int), 1, delay_fid2); - fwrite(&inst->fs, sizeof(WebRtc_UWord16), 1, delay_fid2); + if ((fwrite(&temp_var, sizeof(int), + 1, delay_fid2) != 1) || + (fwrite(&inst->fs, sizeof(WebRtc_UWord16), + 1, delay_fid2) != 1)) { + return -1; + } #endif } @@ -508,9 +512,17 @@ int WebRtcNetEQ_RecOutInternal(DSPInst_t *inst, WebRtc_Word16 *pw16_outData, pw16_decoded_buffer, &speechType); #ifdef NETEQ_DELAY_LOGGING temp_var = NETEQ_DELAY_LOGGING_SIGNAL_DECODE_ONE_DESC; - fwrite(&temp_var, sizeof(int), 1, delay_fid2); - fwrite(&inst->endTimestamp, sizeof(WebRtc_UWord32), 1, delay_fid2); - fwrite(&dspInfo->samplesLeft, sizeof(WebRtc_UWord16), 1, delay_fid2); + if (fwrite(&temp_var, sizeof(int), 1, delay_fid2) != 1) { + return -1; + } + if (fwrite(&inst->endTimestamp, sizeof(WebRtc_UWord32), + 1, delay_fid2) != 1) { + return -1; + } + if (fwrite(&dspInfo->samplesLeft, sizeof(WebRtc_UWord16), + 1, delay_fid2) != 1) { + return -1; + } tot_received_packets++; #endif } @@ -692,7 +704,9 @@ int WebRtcNetEQ_RecOutInternal(DSPInst_t *inst, WebRtc_Word16 *pw16_outData, case DSP_INSTR_MERGE: #ifdef NETEQ_DELAY_LOGGING temp_var = NETEQ_DELAY_LOGGING_SIGNAL_MERGE_INFO; - fwrite(&temp_var, sizeof(int), 1, delay_fid2); + if (fwrite(&temp_var, sizeof(int), 1, delay_fid2) != 1) { + return -1; + } temp_var = -len; #endif /* Call Merge with history*/ @@ -710,7 +724,9 @@ int WebRtcNetEQ_RecOutInternal(DSPInst_t *inst, WebRtc_Word16 *pw16_outData, #ifdef NETEQ_DELAY_LOGGING temp_var += len; - fwrite(&temp_var, sizeof(int), 1, delay_fid2); + if (fwrite(&temp_var, sizeof(int), 1, delay_fid2) != 1) { + return -1; + } #endif /* If last packet was decoded as a inband CNG set mode to CNG instead */ if (speechType == TYPE_CNG) inst->w16_mode = MODE_CODEC_INTERNAL_CNG; @@ -756,9 +772,13 @@ int WebRtcNetEQ_RecOutInternal(DSPInst_t *inst, WebRtc_Word16 *pw16_outData, inst->w16_concealedTS += len; #ifdef NETEQ_DELAY_LOGGING temp_var = NETEQ_DELAY_LOGGING_SIGNAL_EXPAND_INFO; - fwrite(&temp_var, sizeof(int), 1, delay_fid2); + if (fwrite(&temp_var, sizeof(int), 1, delay_fid2) != 1) { + return -1; + } temp_var = len; - fwrite(&temp_var, sizeof(int), 1, delay_fid2); + if (fwrite(&temp_var, sizeof(int), 1, delay_fid2) != 1) { + return -1; + } #endif len = 0; /* already written the data, so do not write it again further down. */ } @@ -812,9 +832,13 @@ int WebRtcNetEQ_RecOutInternal(DSPInst_t *inst, WebRtc_Word16 *pw16_outData, inst->curPosition += (borrowedSamples - len); #ifdef NETEQ_DELAY_LOGGING temp_var = NETEQ_DELAY_LOGGING_SIGNAL_ACCELERATE_INFO; - fwrite(&temp_var, sizeof(int), 1, delay_fid2); + if (fwrite(&temp_var, sizeof(int), 1, delay_fid2) != 1) { + return -1; + } temp_var = 3 * inst->timestampsPerCall - len; - fwrite(&temp_var, sizeof(int), 1, delay_fid2); + if (fwrite(&temp_var, sizeof(int), 1, delay_fid2) != 1) { + return -1; + } #endif len = 0; } @@ -827,9 +851,13 @@ int WebRtcNetEQ_RecOutInternal(DSPInst_t *inst, WebRtc_Word16 *pw16_outData, (len-borrowedSamples)); #ifdef NETEQ_DELAY_LOGGING temp_var = NETEQ_DELAY_LOGGING_SIGNAL_ACCELERATE_INFO; - fwrite(&temp_var, sizeof(int), 1, delay_fid2); + if (fwrite(&temp_var, sizeof(int), 1, delay_fid2) != 1) { + return -1; + } temp_var = 3 * inst->timestampsPerCall - len; - fwrite(&temp_var, sizeof(int), 1, delay_fid2); + if (fwrite(&temp_var, sizeof(int), 1, delay_fid2) != 1) { + return -1; + } #endif len = len - borrowedSamples; } @@ -839,7 +867,9 @@ int WebRtcNetEQ_RecOutInternal(DSPInst_t *inst, WebRtc_Word16 *pw16_outData, { #ifdef NETEQ_DELAY_LOGGING temp_var = NETEQ_DELAY_LOGGING_SIGNAL_ACCELERATE_INFO; - fwrite(&temp_var, sizeof(int), 1, delay_fid2); + if (fwrite(&temp_var, sizeof(int), 1, delay_fid2) != 1) { + return -1; + } temp_var = len; #endif return_value = WebRtcNetEQ_Accelerate(inst, @@ -856,7 +886,9 @@ int WebRtcNetEQ_RecOutInternal(DSPInst_t *inst, WebRtc_Word16 *pw16_outData, #ifdef NETEQ_DELAY_LOGGING temp_var -= len; - fwrite(&temp_var, sizeof(int), 1, delay_fid2); + if (fwrite(&temp_var, sizeof(int), 1, delay_fid2) != 1) { + return -1; + } #endif } /* If last packet was decoded as a inband CNG set mode to CNG instead */ @@ -1147,9 +1179,13 @@ int WebRtcNetEQ_RecOutInternal(DSPInst_t *inst, WebRtc_Word16 *pw16_outData, #ifdef NETEQ_DELAY_LOGGING temp_var = NETEQ_DELAY_LOGGING_SIGNAL_PREEMPTIVE_INFO; - fwrite(&temp_var, sizeof(int), 1, delay_fid2); + if (fwrite(&temp_var, sizeof(int), 1, delay_fid2) != 1) { + return -1; + } temp_var = len - w16_tmp1; /* number of samples added */ - fwrite(&temp_var, sizeof(int), 1, delay_fid2); + if (fwrite(&temp_var, sizeof(int), 1, delay_fid2) != 1) { + return -1; + } #endif /* If last packet was decoded as inband CNG, set mode to CNG instead */ if (speechType == TYPE_CNG) inst->w16_mode = MODE_CODEC_INTERNAL_CNG; @@ -1256,9 +1292,13 @@ int WebRtcNetEQ_RecOutInternal(DSPInst_t *inst, WebRtc_Word16 *pw16_outData, inst->w16_mode = MODE_FADE_TO_BGN; #ifdef NETEQ_DELAY_LOGGING temp_var = NETEQ_DELAY_LOGGING_SIGNAL_EXPAND_INFO; - fwrite(&temp_var, sizeof(int), 1, delay_fid2); + if (fwrite(&temp_var, sizeof(int), 1, delay_fid2) != 1) { + return -1; + } temp_var = len; - fwrite(&temp_var, sizeof(int), 1, delay_fid2); + if (fwrite(&temp_var, sizeof(int), 1, delay_fid2) != 1) { + return -1; + } #endif break; diff --git a/src/modules/audio_coding/neteq/signal_mcu.c b/src/modules/audio_coding/neteq/signal_mcu.c index 28dcf00db..b28f39c3d 100644 --- a/src/modules/audio_coding/neteq/signal_mcu.c +++ b/src/modules/audio_coding/neteq/signal_mcu.c @@ -646,9 +646,14 @@ int WebRtcNetEQ_SignalMcu(MCUInst_t *inst) #ifdef NETEQ_DELAY_LOGGING temp_var = NETEQ_DELAY_LOGGING_SIGNAL_DECODE; - fwrite(&temp_var,sizeof(int),1,delay_fid2); - fwrite(&temp_pkt.timeStamp,sizeof(WebRtc_UWord32),1,delay_fid2); - fwrite(&dspInfo.samplesLeft, sizeof(WebRtc_UWord16), 1, delay_fid2); + if ((fwrite(&temp_var, sizeof(int), + 1, delay_fid2) != 1) || + (fwrite(&temp_pkt.timeStamp, sizeof(WebRtc_UWord32), + 1, delay_fid2) != 1) || + (fwrite(&dspInfo.samplesLeft, sizeof(WebRtc_UWord16), + 1, delay_fid2) != 1)) { + return -1; + } #endif *blockPtr = temp_pkt.payloadLen; @@ -762,4 +767,3 @@ int WebRtcNetEQ_SignalMcu(MCUInst_t *inst) return 0; } - diff --git a/src/modules/audio_coding/neteq/test/NetEqRTPplay.cc b/src/modules/audio_coding/neteq/test/NetEqRTPplay.cc index 7525a40d7..1d6d80d5b 100644 --- a/src/modules/audio_coding/neteq/test/NetEqRTPplay.cc +++ b/src/modules/audio_coding/neteq/test/NetEqRTPplay.cc @@ -561,8 +561,12 @@ int main(int argc, char* argv[]) #ifdef NETEQ_DELAY_LOGGING temp_var = NETEQ_DELAY_LOGGING_SIGNAL_CLOCK; clock_float = (float) simClock; - fwrite(&temp_var,sizeof(int),1,delay_fid2); - fwrite(&clock_float, sizeof(float),1,delay_fid2); + if (fwrite(&temp_var, sizeof(int), 1, delay_fid2) != 1) { + return -1; + } + if (fwrite(&clock_float, sizeof(float), 1, delay_fid2) != 1) { + return -1; + } #endif /* time to set extra delay */ if (extraDelay > -1 && simClock >= nextExtraDelayTime) { @@ -657,7 +661,9 @@ int main(int argc, char* argv[]) } // write to file - fwrite(out_data,writeLen,2,out_file); + if (fwrite(out_data, writeLen, 2, out_file) != 2) { + return -1; + } writtenSamples += writeLen; @@ -678,8 +684,13 @@ int main(int argc, char* argv[]) #ifdef NETEQ_DELAY_LOGGING temp_var = NETEQ_DELAY_LOGGING_SIGNAL_EOF; - fwrite(&temp_var,sizeof(int),1,delay_fid2); - fwrite(&tot_received_packets,sizeof(WebRtc_UWord32),1,delay_fid2); + if (fwrite(&temp_var, sizeof(int), 1, delay_fid2) != 1) { + return -1; + } + if (fwrite(&tot_received_packets, sizeof(WebRtc_UWord32), + 1, delay_fid2) != 1) { + return -1; + } fprintf(delay_fid2,"End of file\n"); fclose(delay_fid2); #endif diff --git a/src/modules/audio_coding/neteq/test/RTPencode.cc b/src/modules/audio_coding/neteq/test/RTPencode.cc index f32879435..3aaaf6ca7 100644 --- a/src/modules/audio_coding/neteq/test/RTPencode.cc +++ b/src/modules/audio_coding/neteq/test/RTPencode.cc @@ -252,7 +252,7 @@ int main(int argc, char* argv[]) WebRtc_Word16 seqNo=0xFFF; WebRtc_UWord32 ssrc=1235412312; WebRtc_UWord32 timestamp=0xAC1245; - WebRtc_UWord16 length, plen; + WebRtc_UWord16 length, plen; WebRtc_UWord32 offset; double sendtime = 0; int red_PT[2] = {0}; @@ -547,11 +547,21 @@ int main(int argc, char* argv[]) //fprintf(out_file, "#!RTPencode%s\n", "1.0"); fprintf(out_file, "#!rtpplay%s \n", "1.0"); // this is the string that rtpplay needs WebRtc_UWord32 dummy_variable = 0; // should be converted to network endian format, but does not matter when 0 - fwrite(&dummy_variable, 4, 1, out_file); - fwrite(&dummy_variable, 4, 1, out_file); - fwrite(&dummy_variable, 4, 1, out_file); - fwrite(&dummy_variable, 2, 1, out_file); - fwrite(&dummy_variable, 2, 1, out_file); + if (fwrite(&dummy_variable, 4, 1, out_file) != 1) { + return -1; + } + if (fwrite(&dummy_variable, 4, 1, out_file) != 1) { + return -1; + } + if (fwrite(&dummy_variable, 4, 1, out_file) != 1) { + return -1; + } + if (fwrite(&dummy_variable, 2, 1, out_file) != 1) { + return -1; + } + if (fwrite(&dummy_variable, 2, 1, out_file) != 1) { + return -1; + } #ifdef TIMESTAMP_WRAPAROUND timestamp = 0xFFFFFFFF - fs*10; /* should give wrap-around in 10 seconds */ @@ -600,10 +610,18 @@ int main(int argc, char* argv[]) plen = htons(12 + enc_len); offset = (WebRtc_UWord32) sendtime; //(timestamp/(fs/1000)); offset = htonl(offset); - fwrite(&length, 2, 1, out_file); - fwrite(&plen, 2, 1, out_file); - fwrite(&offset, 4, 1, out_file); - fwrite(rtp_data, 12 + enc_len, 1, out_file); + if (fwrite(&length, 2, 1, out_file) != 1) { + return -1; + } + if (fwrite(&plen, 2, 1, out_file) != 1) { + return -1; + } + if (fwrite(&offset, 4, 1, out_file) != 1) { + return -1; + } + if (fwrite(rtp_data, 12 + enc_len, 1, out_file) != 1) { + return -1; + } dtmfSent = true; } @@ -683,13 +701,20 @@ int main(int argc, char* argv[]) do { #endif //MULTIPLE_SAME_TIMESTAMP /* write RTP packet to file */ - length = htons(12 + enc_len + 8); - plen = htons(12 + enc_len); - offset = (WebRtc_UWord32) sendtime; //(timestamp/(fs/1000)); - offset = htonl(offset); - fwrite(&length, 2, 1, out_file); - fwrite(&plen, 2, 1, out_file); - fwrite(&offset, 4, 1, out_file); + length = htons(12 + enc_len + 8); + plen = htons(12 + enc_len); + offset = (WebRtc_UWord32) sendtime; + //(timestamp/(fs/1000)); + offset = htonl(offset); + if (fwrite(&length, 2, 1, out_file) != 1) { + return -1; + } + if (fwrite(&plen, 2, 1, out_file) != 1) { + return -1; + } + if (fwrite(&offset, 4, 1, out_file) != 1) { + return -1; + } #ifdef RANDOM_DATA for (int k=0; k<12+enc_len; k++) { rtp_data[k] = rand() + rand(); @@ -700,7 +725,9 @@ int main(int argc, char* argv[]) rtp_data[k] = rand() + rand(); } #endif - fwrite(rtp_data, 12 + enc_len, 1, out_file); + if (fwrite(rtp_data, 12 + enc_len, 1, out_file) != 1) { + return -1; + } #ifdef MULTIPLE_SAME_TIMESTAMP } while ( (seqNo%REPEAT_PACKET_DISTANCE == 0) && (mult_pack++ < REPEAT_PACKET_COUNT) ); #endif //MULTIPLE_SAME_TIMESTAMP @@ -708,11 +735,23 @@ int main(int argc, char* argv[]) #ifdef INSERT_OLD_PACKETS if (packet_age >= OLD_PACKET*fs) { if (!first_old_packet) { - // send the old packet - fwrite(&old_length, 2, 1, out_file); - fwrite(&old_plen, 2, 1, out_file); - fwrite(&offset, 4, 1, out_file); - fwrite(old_rtp_data, 12 + old_enc_len, 1, out_file); + // send the old packet + if (fwrite(&old_length, 2, 1, + out_file) != 1) { + return -1; + } + if (fwrite(&old_plen, 2, 1, + out_file) != 1) { + return -1; + } + if (fwrite(&offset, 4, 1, + out_file) != 1) { + return -1; + } + if (fwrite(old_rtp_data, 12 + old_enc_len, + 1, out_file) != 1) { + return -1; + } } // store current packet as old old_length=length; diff --git a/src/modules/audio_coding/neteq/test/RTPjitter.cc b/src/modules/audio_coding/neteq/test/RTPjitter.cc index ef390911e..e3270be6b 100644 --- a/src/modules/audio_coding/neteq/test/RTPjitter.cc +++ b/src/modules/audio_coding/neteq/test/RTPjitter.cc @@ -167,7 +167,12 @@ int main(int argc, char* argv[]) } // write packet to file - fwrite(temp_packet, sizeof(unsigned char), ntohs(*((WebRtc_UWord16*) temp_packet)), out_file); + if (fwrite(temp_packet, sizeof(unsigned char), + ntohs(*((WebRtc_UWord16*) temp_packet)), + out_file) != + ntohs(*((WebRtc_UWord16*) temp_packet))) { + return -1; + } } }