diff --git a/webrtc/modules/audio_coding/neteq/test/RTPtimeshift.cc b/webrtc/modules/audio_coding/neteq/test/RTPtimeshift.cc index dc7ff9fb7e..66a00bda03 100644 --- a/webrtc/modules/audio_coding/neteq/test/RTPtimeshift.cc +++ b/webrtc/modules/audio_coding/neteq/test/RTPtimeshift.cc @@ -22,76 +22,68 @@ #define FIRSTLINELEN 40 -int main(int argc, char* argv[]) -{ - if(argc < 4 || argc > 6) - { - printf("Usage: RTPtimeshift in.rtp out.rtp newStartTS [newStartSN [newStartArrTime]]\n"); - exit(1); +int main(int argc, char* argv[]) { + if (argc < 4 || argc > 6) { + printf( + "Usage: RTPtimeshift in.rtp out.rtp newStartTS " + "[newStartSN [newStartArrTime]]\n"); + exit(1); + } + + FILE *inFile = fopen(argv[1], "rb"); + if (!inFile) { + printf("Cannot open input file %s\n", argv[1]); + return (-1); + } + printf("Input RTP file: %s\n", argv[1]); + + FILE *outFile = fopen(argv[2], "wb"); + if (!outFile) { + printf("Cannot open output file %s\n", argv[2]); + return (-1); + } + printf("Output RTP file: %s\n\n", argv[2]); + + // read file header and write directly to output file + const unsigned int kRtpDumpHeaderSize = 4 + 4 + 4 + 2 + 2; + char firstline[FIRSTLINELEN]; + EXPECT_TRUE(fgets(firstline, FIRSTLINELEN, inFile) != NULL); + EXPECT_GT(fputs(firstline, outFile), 0); + EXPECT_EQ(kRtpDumpHeaderSize, + fread(firstline, 1, kRtpDumpHeaderSize, inFile)); + EXPECT_EQ(kRtpDumpHeaderSize, + fwrite(firstline, 1, kRtpDumpHeaderSize, outFile)); + NETEQTEST_RTPpacket packet; + int packLen = packet.readFromFile(inFile); + if (packLen < 0) { + exit(1); + } + + // get new start TS and start SeqNo from arguments + WebRtc_UWord32 TSdiff = atoi(argv[3]) - packet.timeStamp(); + WebRtc_UWord16 SNdiff = 0; + WebRtc_UWord32 ATdiff = 0; + if (argc > 4) { + SNdiff = atoi(argv[4]) - packet.sequenceNumber(); + if (argc > 5) { + ATdiff = atoi(argv[5]) - packet.time(); } + } - FILE *inFile=fopen(argv[1],"rb"); - if (!inFile) - { - printf("Cannot open input file %s\n", argv[1]); - return(-1); - } - printf("Input RTP file: %s\n",argv[1]); + while (packLen >= 0) { - FILE *outFile=fopen(argv[2],"wb"); - if (!outFile) - { - printf("Cannot open output file %s\n", argv[2]); - return(-1); - } - printf("Output RTP file: %s\n\n",argv[2]); + packet.setTimeStamp(packet.timeStamp() + TSdiff); + packet.setSequenceNumber(packet.sequenceNumber() + SNdiff); + packet.setTime(packet.time() + ATdiff); - // read file header and write directly to output file - const unsigned int kRtpDumpHeaderSize = 4 + 4 + 4 + 2 + 2; - char firstline[FIRSTLINELEN]; - EXPECT_TRUE(fgets(firstline, FIRSTLINELEN, inFile) != NULL); - EXPECT_GT(fputs(firstline, outFile), 0); - EXPECT_EQ(kRtpDumpHeaderSize, - fread(firstline, 1, kRtpDumpHeaderSize, inFile)); - EXPECT_EQ(kRtpDumpHeaderSize, - fwrite(firstline, 1, kRtpDumpHeaderSize, outFile)); - NETEQTEST_RTPpacket packet; - int packLen = packet.readFromFile(inFile); - if (packLen < 0) - { - exit(1); - } + packet.writeToFile(outFile); - // get new start TS and start SeqNo from arguments - WebRtc_UWord32 TSdiff = atoi(argv[3]) - packet.timeStamp(); - WebRtc_UWord16 SNdiff = 0; - WebRtc_UWord32 ATdiff = 0; - if (argc > 4) - { - if (argv[4] >= 0) - SNdiff = atoi(argv[4]) - packet.sequenceNumber(); - if (argc > 5) - { - if (argv[5] >= 0) - ATdiff = atoi(argv[5]) - packet.time(); - } - } + packLen = packet.readFromFile(inFile); - while (packLen >= 0) - { - - packet.setTimeStamp(packet.timeStamp() + TSdiff); - packet.setSequenceNumber(packet.sequenceNumber() + SNdiff); - packet.setTime(packet.time() + ATdiff); + } - packet.writeToFile(outFile); + fclose(inFile); + fclose(outFile); - packLen = packet.readFromFile(inFile); - - } - - fclose(inFile); - fclose(outFile); - - return 0; + return 0; }