Fix formatting for some NetEQ test tools

Format and lint for RTPchange.cc, RTPcat.cc and RTPanalyze.cc.

Review URL: http://webrtc-codereview.appspot.com/329024

git-svn-id: http://webrtc.googlecode.com/svn/trunk@1313 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
henrik.lundin@webrtc.org 2012-01-03 10:03:19 +00:00
parent 60c9bbd976
commit 6c877363f7
6 changed files with 201 additions and 247 deletions

View File

@ -8,6 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
//TODO(hlundin): Reformat file to meet style guide.
/* header includes */
#include "typedefs.h"
#include "stdio.h"
@ -127,8 +129,6 @@ bool changeStereoMode(NETEQTEST_RTPpacket & rtp, std::map<WebRtc_UWord8, decoder
WebRtc_Word16 NetEqPacketBuffer[MAX_NETEQ_BUFFERSIZE>>1];
WebRtc_Word16 NetEqPacketBufferSlave[MAX_NETEQ_BUFFERSIZE>>1];
FILE *in_file;
FILE *out_file;
#ifdef NETEQ_DELAY_LOGGING
extern "C" {
@ -240,7 +240,7 @@ int main(int argc, char* argv[])
return(ok);
}
in_file=fopen(argv[1],"rb");
FILE* in_file=fopen(argv[1],"rb");
CHECK_NOT_NULL(in_file);
printf("Input file: %s\n",argv[1]);
@ -258,7 +258,7 @@ int main(int argc, char* argv[])
return(-1);
#endif
}
out_file=fopen(outfilename,"wb");
FILE* out_file=fopen(outfilename,"wb");
if (out_file==NULL) {
fprintf(stderr,"Could not open file %s for writing\n", outfilename);
return(-1);

View File

@ -12,62 +12,54 @@
#include <stdio.h>
#include <vector>
#include "NETEQTEST_RTPpacket.h"
#include "modules/audio_coding/neteq/test/NETEQTEST_RTPpacket.h"
enum {
kRedPayloadType = 127
};
/*********************/
/* Misc. definitions */
/*********************/
int main(int argc, char* argv[]) {
FILE* in_file = fopen(argv[1], "rb");
if (!in_file) {
printf("Cannot open input file %s\n", argv[1]);
return -1;
}
printf("Input file: %s\n", argv[1]);
enum {kRedPayloadType = 127};
FILE* out_file = fopen(argv[2], "wt");
if (!out_file) {
printf("Cannot open output file %s\n", argv[2]);
return -1;
}
printf("Output file: %s\n\n", argv[2]);
int main(int argc, char* argv[])
{
FILE *inFile=fopen(argv[1],"rb");
if (!inFile)
{
printf("Cannot open input file %s\n", argv[1]);
return(-1);
}
printf("Input file: %s\n",argv[1]);
// Print file header.
fprintf(out_file, "SeqNo TimeStamp SendTime Size PT M\n");
FILE *outFile=fopen(argv[2],"wt");
if (!outFile)
{
printf("Cannot open output file %s\n", argv[2]);
return(-1);
}
printf("Output file: %s\n\n",argv[2]);
// Read file header.
NETEQTEST_RTPpacket::skipFileHeader(in_file);
NETEQTEST_RTPpacket packet;
// print file header
fprintf(outFile, "SeqNo TimeStamp SendTime Size PT M\n");
// read file header
NETEQTEST_RTPpacket::skipFileHeader(inFile);
NETEQTEST_RTPpacket packet;
while (packet.readFromFile(inFile) >= 0)
{
// write packet data to file
fprintf(outFile, "%5u %10u %10u %5i %5i %2i\n",
while (packet.readFromFile(in_file) >= 0) {
// Write packet data to file.
fprintf(out_file, "%5u %10u %10u %5i %5i %2i\n",
packet.sequenceNumber(), packet.timeStamp(), packet.time(),
packet.dataLen(), packet.payloadType(), packet.markerBit());
if (packet.payloadType() == kRedPayloadType) {
WebRtcNetEQ_RTPInfo redHdr;
int len;
int redIndex = 0;
while ((len = packet.extractRED(redIndex++, redHdr)) >= 0)
{
fprintf(outFile, "* %5u %10u %10u %5i %5i\n",
redHdr.sequenceNumber, redHdr.timeStamp, packet.time(),
len, redHdr.payloadType);
}
assert(redIndex > 1); // We must get at least one payload.
}
if (packet.payloadType() == kRedPayloadType) {
WebRtcNetEQ_RTPInfo red_header;
int len;
int red_index = 0;
while ((len = packet.extractRED(red_index++, red_header)) >= 0) {
fprintf(out_file, "* %5u %10u %10u %5i %5i\n",
red_header.sequenceNumber, red_header.timeStamp,
packet.time(), len, red_header.payloadType);
}
assert(red_index > 1); // We must get at least one payload.
}
}
fclose(inFile);
fclose(outFile);
fclose(in_file);
fclose(out_file);
return 0;
return 0;
}

View File

@ -8,73 +8,68 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include <algorithm>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include "NETEQTEST_RTPpacket.h"
#include "gtest/gtest.h"
/*********************/
/* Misc. definitions */
/*********************/
#include "modules/audio_coding/neteq/test/NETEQTEST_RTPpacket.h"
#define FIRSTLINELEN 40
int main(int argc, char* argv[])
{
if (argc < 3) {
printf("Usage: RTPcat in1.rtp int2.rtp [...] out.rtp\n");
exit(1);
int main(int argc, char* argv[]) {
if (argc < 3) {
printf("Usage: RTPcat in1.rtp int2.rtp [...] out.rtp\n");
exit(1);
}
FILE* in_file = fopen(argv[1], "rb");
if (!in_file) {
printf("Cannot open input file %s\n", argv[1]);
return -1;
}
FILE* out_file = fopen(argv[argc - 1], "wb"); // Last parameter is out file.
if (!out_file) {
printf("Cannot open output file %s\n", argv[argc - 1]);
return -1;
}
printf("Output RTP file: %s\n\n", argv[argc - 1]);
// Read file header and write directly to output file.
char firstline[FIRSTLINELEN];
const unsigned int kRtpDumpHeaderSize = 4 + 4 + 4 + 2 + 2;
EXPECT_TRUE(fgets(firstline, FIRSTLINELEN, in_file) != NULL);
EXPECT_GT(fputs(firstline, out_file), 0);
EXPECT_EQ(kRtpDumpHeaderSize, fread(firstline, 1, kRtpDumpHeaderSize,
in_file));
EXPECT_EQ(kRtpDumpHeaderSize, fwrite(firstline, 1, kRtpDumpHeaderSize,
out_file));
// Close input file and re-open it later (easier to write the loop below).
fclose(in_file);
for (int i = 1; i < argc - 1; i++) {
in_file = fopen(argv[i], "rb");
if (!in_file) {
printf("Cannot open input file %s\n", argv[i]);
return -1;
}
printf("Input RTP file: %s\n", argv[i]);
FILE *inFile = fopen(argv[1], "rb");
if (!inFile) {
printf("Cannot open input file %s\n", argv[1]);
return (-1);
NETEQTEST_RTPpacket::skipFileHeader(in_file);
NETEQTEST_RTPpacket packet;
int pack_len = packet.readFromFile(in_file);
if (pack_len < 0) {
exit(1);
}
FILE *outFile = fopen(argv[argc - 1], "wb"); // last parameter is output file
if (!outFile) {
printf("Cannot open output file %s\n", argv[argc - 1]);
return (-1);
while (pack_len >= 0) {
packet.writeToFile(out_file);
pack_len = packet.readFromFile(in_file);
}
printf("Output RTP file: %s\n\n", argv[argc - 1]);
// read file header and write directly to output file
char firstline[FIRSTLINELEN];
const unsigned int kRtpDumpHeaderSize = 4 + 4 + 4 + 2 + 2;
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));
// close input file and re-open it later (easier to write the loop below)
fclose(inFile);
for (int i = 1; i < argc - 1; i++) {
inFile = fopen(argv[i], "rb");
if (!inFile) {
printf("Cannot open input file %s\n", argv[i]);
return (-1);
}
printf("Input RTP file: %s\n", argv[i]);
// skip file header
NETEQTEST_RTPpacket::skipFileHeader(inFile);
NETEQTEST_RTPpacket packet;
int packLen = packet.readFromFile(inFile);
if (packLen < 0) {
exit(1);
}
while (packLen >= 0) {
packet.writeToFile(outFile);
packLen = packet.readFromFile(inFile);
}
fclose(inFile);
}
fclose(outFile);
return 0;
fclose(in_file);
}
fclose(out_file);
return 0;
}

View File

@ -8,138 +8,121 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include <algorithm>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include "NETEQTEST_RTPpacket.h"
#include "gtest/gtest.h"
/*********************/
/* Misc. definitions */
/*********************/
#include "modules/audio_coding/neteq/test/NETEQTEST_RTPpacket.h"
#define FIRSTLINELEN 40
bool pktCmp (NETEQTEST_RTPpacket *a, NETEQTEST_RTPpacket *b)
{
return (a->time() < b->time());
static bool pktCmp(NETEQTEST_RTPpacket *a, NETEQTEST_RTPpacket *b) {
return (a->time() < b->time());
}
int main(int argc, char* argv[]) {
FILE* in_file = fopen(argv[1], "rb");
if (!in_file) {
printf("Cannot open input file %s\n", argv[1]);
return -1;
}
printf("Input RTP file: %s\n", argv[1]);
int main(int argc, char* argv[])
{
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* stat_file = fopen(argv[2], "rt");
if (!stat_file) {
printf("Cannot open timing file %s\n", argv[2]);
return -1;
}
printf("Timing file: %s\n", argv[2]);
FILE *statFile=fopen(argv[2],"rt");
if (!statFile)
{
printf("Cannot open timing file %s\n", argv[2]);
return(-1);
}
printf("Timing file: %s\n",argv[2]);
FILE* out_file = fopen(argv[3], "wb");
if (!out_file) {
printf("Cannot open output file %s\n", argv[3]);
return -1;
}
printf("Output RTP file: %s\n\n", argv[3]);
FILE *outFile=fopen(argv[3],"wb");
if (!outFile)
{
printf("Cannot open output file %s\n", argv[3]);
return(-1);
}
printf("Output RTP file: %s\n\n",argv[3]);
// Read all statistics and insert into map.
// Read first line.
char temp_str[100];
if (fgets(temp_str, 100, stat_file) == NULL) {
printf("Failed to read timing file %s\n", argv[2]);
return -1;
}
// Define map.
std::map<std::pair<uint16_t, uint32_t>, uint32_t> packet_stats;
uint16_t seq_no;
uint32_t ts;
uint32_t send_time;
// read all statistics and insert into map
// read first line
char tempStr[100];
if (fgets(tempStr, 100, statFile) == NULL)
{
printf("Failed to read timing file %s\n", argv[2]);
return (-1);
}
// define map
std::map<std::pair<WebRtc_UWord16, WebRtc_UWord32>, WebRtc_UWord32>
packetStats;
WebRtc_UWord16 seqNo;
WebRtc_UWord32 ts;
WebRtc_UWord32 sendTime;
while (fscanf(stat_file,
"%hu %u %u %*i %*i\n", &seq_no, &ts, &send_time) == 3) {
std::pair<uint16_t, uint32_t>
temp_pair = std::pair<uint16_t, uint32_t>(seq_no, ts);
while(fscanf(statFile, "%hu %u %u %*i %*i\n", &seqNo, &ts, &sendTime) == 3)
{
std::pair<WebRtc_UWord16, WebRtc_UWord32> tempPair =
std::pair<WebRtc_UWord16, WebRtc_UWord32>(seqNo, ts);
packet_stats[temp_pair] = send_time;
}
packetStats[tempPair] = sendTime;
fclose(stat_file);
// Read file header and write directly to output file.
char first_line[FIRSTLINELEN];
if (fgets(first_line, FIRSTLINELEN, in_file) == NULL) {
printf("Failed to read first line of input file %s\n", argv[1]);
return -1;
}
fputs(first_line, out_file);
// start_sec + start_usec + source + port + padding
const unsigned int kRtpDumpHeaderSize = 4 + 4 + 4 + 2 + 2;
if (fread(first_line, 1, kRtpDumpHeaderSize, in_file)
!= kRtpDumpHeaderSize) {
printf("Failed to read RTP dump header from input file %s\n", argv[1]);
return -1;
}
if (fwrite(first_line, 1, kRtpDumpHeaderSize, out_file)
!= kRtpDumpHeaderSize) {
printf("Failed to write RTP dump header to output file %s\n", argv[3]);
return -1;
}
std::vector<NETEQTEST_RTPpacket *> packet_vec;
while (1) {
// Insert in vector.
NETEQTEST_RTPpacket *new_packet = new NETEQTEST_RTPpacket();
if (new_packet->readFromFile(in_file) < 0) {
// End of file.
break;
}
fclose(statFile);
// Look for new send time in statistics vector.
std::pair<uint16_t, uint32_t> temp_pair =
std::pair<uint16_t, uint32_t>(new_packet->sequenceNumber(),
new_packet->timeStamp());
// read file header and write directly to output file
char firstline[FIRSTLINELEN];
if (fgets(firstline, FIRSTLINELEN, inFile) == NULL)
{
printf("Failed to read first line of input file %s\n", argv[1]);
return (-1);
}
fputs(firstline, outFile);
// start_sec + start_usec + source + port + padding
const unsigned int kRtpDumpHeaderSize = 4 + 4 + 4 + 2 + 2;
if (fread(firstline, 1, kRtpDumpHeaderSize, inFile) != kRtpDumpHeaderSize)
{
printf("Failed to read RTP dump header from input file %s\n", argv[1]);
return (-1);
}
if (fwrite(firstline, 1, kRtpDumpHeaderSize, outFile) != kRtpDumpHeaderSize)
{
printf("Failed to write RTP dump header to output file %s\n", argv[3]);
return (-1);
uint32_t new_send_time = packet_stats[temp_pair];
new_packet->setTime(new_send_time); // Set new send time.
packet_vec.push_back(new_packet); // Insert in vector.
}
// Sort the vector according to send times.
std::sort(packet_vec.begin(), packet_vec.end(), pktCmp);
std::vector<NETEQTEST_RTPpacket *>::iterator it;
for (it = packet_vec.begin(); it != packet_vec.end(); it++) {
// Write to out file.
if ((*it)->writeToFile(out_file) < 0) {
printf("Error writing to file\n");
return -1;
}
// Delete packet.
delete *it;
}
std::vector<NETEQTEST_RTPpacket *> packetVec;
fclose(in_file);
fclose(out_file);
while (1)
{
// insert in vector
NETEQTEST_RTPpacket *newPacket = new NETEQTEST_RTPpacket();
if (newPacket->readFromFile(inFile) < 0)
{
// end of file
break;
}
// look for new send time in statistics vector
std::pair<WebRtc_UWord16, WebRtc_UWord32> tempPair =
std::pair<WebRtc_UWord16, WebRtc_UWord32>(newPacket->sequenceNumber(), newPacket->timeStamp());
WebRtc_UWord32 newSendTime = packetStats[tempPair];
newPacket->setTime(newSendTime); // set new send time
packetVec.push_back(newPacket); // insert in vector
}
// sort the vector according to send times
std::sort(packetVec.begin(), packetVec.end(), pktCmp);
std::vector<NETEQTEST_RTPpacket *>::iterator it;
for (it = packetVec.begin(); it != packetVec.end(); it++)
{
// write to out file
if ((*it)->writeToFile(outFile) < 0)
{
printf("Error writing to file\n");
return(-1);
}
// delete packet
delete *it;
}
fclose(inFile);
fclose(outFile);
return 0;
return 0;
}

View File

@ -8,6 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
//TODO(hlundin): Reformat file to meet style guide.
/* header includes */
#include "typedefs.h"
#include "stdio.h"
@ -79,17 +81,6 @@ int makeDTMFpayload(unsigned char* payload_data, int Event, int End, int Volume,
void stereoDeInterleave(WebRtc_Word16* audioSamples, int numSamples);
void stereoInterleave(unsigned char* data, int dataLen, int stride);
/********************/
/* Global variables */
/********************/
FILE *in_file;
FILE *out_file;
FILE *dat_file;
/*********************/
/* Codec definitions */
/*********************/
@ -399,10 +390,10 @@ int main(int argc, char* argv[])
return(0);
}
in_file=fopen(argv[1],"rb");
FILE* in_file=fopen(argv[1],"rb");
CHECK_NOT_NULL(in_file);
printf("Input file: %s\n",argv[1]);
out_file=fopen(argv[2],"wb");
FILE* out_file=fopen(argv[2],"wb");
CHECK_NOT_NULL(out_file);
printf("Output file: %s\n\n",argv[2]);
packet_size=atoi(argv[3]);

View File

@ -8,6 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
//TODO(hlundin): Reformat file to meet style guide.
/* header includes */
#include "typedefs.h"
#include <stdio.h>
@ -32,15 +34,6 @@
#define CHECK_ZERO(a) {int errCode = a; if((errCode)!=0){fprintf(stderr,"\n %s \n line: %d \n error at %s\n Error Code = %d\n",__FILE__,__LINE__,#a, WebRtcNetEQ_GetErrorCode(inst)); exit(0);}}
#define CHECK_NOT_NULL(a) if((a)==NULL){fprintf(stderr,"\n %s \n line: %d \nerror at %s\n",__FILE__,__LINE__,#a );return(-1);}
/********************/
/* Global variables */
/********************/
FILE *in_file;
FILE *out_file;
FILE *dat_file;
struct arr_time {
float time;
WebRtc_UWord32 ix;
@ -97,13 +90,13 @@ int main(int argc, char* argv[])
return(0);
}
in_file=fopen(argv[1],"rb");
FILE* in_file=fopen(argv[1],"rb");
CHECK_NOT_NULL(in_file);
printf("Input file: %s\n",argv[1]);
dat_file=fopen(argv[2],"rb");
FILE* dat_file=fopen(argv[2],"rb");
CHECK_NOT_NULL(dat_file);
printf("Dat-file: %s\n",argv[2]);
out_file=fopen(argv[3],"wb");
FILE* out_file=fopen(argv[3],"wb");
CHECK_NOT_NULL(out_file);
printf("Output file: %s\n\n",argv[3]);