| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include <assert.h> | 26 #include <assert.h> |
| 27 | 27 |
| 28 #include "webrtc/test/gtest.h" | 28 #include "webrtc/test/gtest.h" |
| 29 #include "webrtc/typedefs.h" | 29 #include "webrtc/typedefs.h" |
| 30 | 30 |
| 31 /*********************/ | 31 /*********************/ |
| 32 /* Misc. definitions */ | 32 /* Misc. definitions */ |
| 33 /*********************/ | 33 /*********************/ |
| 34 | 34 |
| 35 #define FIRSTLINELEN 40 | 35 #define FIRSTLINELEN 40 |
| 36 #define CHECK_NOT_NULL(a) if((a)==NULL){ \ | 36 #define CHECK_NOT_NULL(a) \ |
| 37 fprintf(stderr,"\n %s \n line: %d \nerror at %s\n",__FILE__,__LINE__,#a ); \ | 37 if ((a) == nullptr) { \ |
| 38 return(-1);} | 38 fprintf(stderr, "\n %s \n line: %d \nerror at %s\n", __FILE__, __LINE__, \ |
| 39 #a); \ |
| 40 return (-1); \ |
| 41 } |
| 39 | 42 |
| 40 struct arr_time { | 43 struct arr_time { |
| 41 float time; | 44 float time; |
| 42 uint32_t ix; | 45 uint32_t ix; |
| 43 }; | 46 }; |
| 44 | 47 |
| 45 int filelen(FILE *fid) | 48 int filelen(FILE *fid) |
| 46 { | 49 { |
| 47 fpos_t cur_pos; | 50 fpos_t cur_pos; |
| 48 int len; | 51 int len; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 59 return (len); | 62 return (len); |
| 60 } | 63 } |
| 61 | 64 |
| 62 int compare_arr_time(const void *x, const void *y); | 65 int compare_arr_time(const void *x, const void *y); |
| 63 | 66 |
| 64 int main(int argc, char* argv[]) | 67 int main(int argc, char* argv[]) |
| 65 { | 68 { |
| 66 unsigned int dat_len, rtp_len, Npack, k; | 69 unsigned int dat_len, rtp_len, Npack, k; |
| 67 arr_time *time_vec; | 70 arr_time *time_vec; |
| 68 char firstline[FIRSTLINELEN]; | 71 char firstline[FIRSTLINELEN]; |
| 69 unsigned char* rtp_vec = NULL; | 72 unsigned char* rtp_vec = nullptr; |
| 70 unsigned char** packet_ptr = NULL; | 73 unsigned char** packet_ptr = nullptr; |
| 71 unsigned char* temp_packet = NULL; | 74 unsigned char* temp_packet = nullptr; |
| 72 const unsigned int kRtpDumpHeaderSize = 4 + 4 + 4 + 2 + 2; | 75 const unsigned int kRtpDumpHeaderSize = 4 + 4 + 4 + 2 + 2; |
| 73 uint16_t len; | 76 uint16_t len; |
| 74 uint32_t *offset; | 77 uint32_t *offset; |
| 75 | 78 |
| 76 /* check number of parameters */ | 79 /* check number of parameters */ |
| 77 if (argc != 4) { | 80 if (argc != 4) { |
| 78 /* print help text and exit */ | 81 /* print help text and exit */ |
| 79 printf("Apply jitter on RTP stream.\n"); | 82 printf("Apply jitter on RTP stream.\n"); |
| 80 printf("Reads an RTP stream and packet timing from two files.\n"); | 83 printf("Reads an RTP stream and packet timing from two files.\n"); |
| 81 printf("The RTP stream is modified to have the same jitter as described in " | 84 printf("The RTP stream is modified to have the same jitter as described in " |
| (...skipping 21 matching lines...) Expand all Loading... |
| 103 FILE* dat_file=fopen(argv[2],"rb"); | 106 FILE* dat_file=fopen(argv[2],"rb"); |
| 104 CHECK_NOT_NULL(dat_file); | 107 CHECK_NOT_NULL(dat_file); |
| 105 printf("Dat-file: %s\n",argv[2]); | 108 printf("Dat-file: %s\n",argv[2]); |
| 106 FILE* out_file=fopen(argv[3],"wb"); | 109 FILE* out_file=fopen(argv[3],"wb"); |
| 107 CHECK_NOT_NULL(out_file); | 110 CHECK_NOT_NULL(out_file); |
| 108 printf("Output file: %s\n\n",argv[3]); | 111 printf("Output file: %s\n\n",argv[3]); |
| 109 | 112 |
| 110 // add 1000 bytes to avoid (rare) strange error. | 113 // add 1000 bytes to avoid (rare) strange error. |
| 111 time_vec = (arr_time *) malloc(sizeof(arr_time) | 114 time_vec = (arr_time *) malloc(sizeof(arr_time) |
| 112 *(filelen(dat_file)/sizeof(float)) + 1000); | 115 *(filelen(dat_file)/sizeof(float)) + 1000); |
| 113 if (time_vec==NULL) { | 116 if (time_vec == nullptr) { |
| 114 fprintf(stderr, "Error: could not allocate memory for reading dat file\n"); | 117 fprintf(stderr, "Error: could not allocate memory for reading dat file\n"); |
| 115 goto closing; | 118 goto closing; |
| 116 } | 119 } |
| 117 | 120 |
| 118 dat_len=0; | 121 dat_len=0; |
| 119 while(fread(&(time_vec[dat_len].time),sizeof(float),1,dat_file)>0) { | 122 while(fread(&(time_vec[dat_len].time),sizeof(float),1,dat_file)>0) { |
| 120 time_vec[dat_len].ix=dat_len; | 123 time_vec[dat_len].ix=dat_len; |
| 121 dat_len++; | 124 dat_len++; |
| 122 } | 125 } |
| 123 | 126 |
| 124 if (dat_len == 0) { | 127 if (dat_len == 0) { |
| 125 fprintf(stderr, "Error: dat_file is empty, no arrival time is given.\n"); | 128 fprintf(stderr, "Error: dat_file is empty, no arrival time is given.\n"); |
| 126 goto closing; | 129 goto closing; |
| 127 } | 130 } |
| 128 | 131 |
| 129 qsort(time_vec,dat_len,sizeof(arr_time),compare_arr_time); | 132 qsort(time_vec,dat_len,sizeof(arr_time),compare_arr_time); |
| 130 | 133 |
| 131 | 134 |
| 132 rtp_vec = (unsigned char *) malloc(sizeof(unsigned char)*filelen(in_file)); | 135 rtp_vec = (unsigned char *) malloc(sizeof(unsigned char)*filelen(in_file)); |
| 133 if (rtp_vec==NULL) { | 136 if (rtp_vec == nullptr) { |
| 134 fprintf(stderr,"Error: could not allocate memory for reading rtp file\n"); | 137 fprintf(stderr,"Error: could not allocate memory for reading rtp file\n"); |
| 135 goto closing; | 138 goto closing; |
| 136 } | 139 } |
| 137 | 140 |
| 138 // read file header and write directly to output file | 141 // read file header and write directly to output file |
| 139 EXPECT_TRUE(fgets(firstline, FIRSTLINELEN, in_file) != NULL); | 142 EXPECT_TRUE(fgets(firstline, FIRSTLINELEN, in_file) != nullptr); |
| 140 EXPECT_GT(fputs(firstline, out_file), 0); | 143 EXPECT_GT(fputs(firstline, out_file), 0); |
| 141 EXPECT_EQ(kRtpDumpHeaderSize, fread(firstline, 1, kRtpDumpHeaderSize, | 144 EXPECT_EQ(kRtpDumpHeaderSize, fread(firstline, 1, kRtpDumpHeaderSize, |
| 142 in_file)); | 145 in_file)); |
| 143 EXPECT_EQ(kRtpDumpHeaderSize, fwrite(firstline, 1, kRtpDumpHeaderSize, | 146 EXPECT_EQ(kRtpDumpHeaderSize, fwrite(firstline, 1, kRtpDumpHeaderSize, |
| 144 out_file)); | 147 out_file)); |
| 145 | 148 |
| 146 // read all RTP packets into vector | 149 // read all RTP packets into vector |
| 147 rtp_len=0; | 150 rtp_len=0; |
| 148 Npack=0; | 151 Npack=0; |
| 149 | 152 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 ntohs(*((uint16_t*) temp_packet))) { | 202 ntohs(*((uint16_t*) temp_packet))) { |
| 200 return -1; | 203 return -1; |
| 201 } | 204 } |
| 202 } | 205 } |
| 203 } | 206 } |
| 204 | 207 |
| 205 | 208 |
| 206 closing: | 209 closing: |
| 207 free(time_vec); | 210 free(time_vec); |
| 208 free(rtp_vec); | 211 free(rtp_vec); |
| 209 if (packet_ptr != NULL) { | 212 if (packet_ptr != nullptr) { |
| 210 free(packet_ptr); | 213 free(packet_ptr); |
| 211 } | 214 } |
| 212 fclose(in_file); | 215 fclose(in_file); |
| 213 fclose(dat_file); | 216 fclose(dat_file); |
| 214 fclose(out_file); | 217 fclose(out_file); |
| 215 | 218 |
| 216 return(0); | 219 return(0); |
| 217 } | 220 } |
| 218 | 221 |
| 219 | 222 |
| 220 | 223 |
| 221 int compare_arr_time(const void *xp, const void *yp) { | 224 int compare_arr_time(const void *xp, const void *yp) { |
| 222 | 225 |
| 223 if(((arr_time *)xp)->time == ((arr_time *)yp)->time) | 226 if(((arr_time *)xp)->time == ((arr_time *)yp)->time) |
| 224 return(0); | 227 return(0); |
| 225 else if(((arr_time *)xp)->time > ((arr_time *)yp)->time) | 228 else if(((arr_time *)xp)->time > ((arr_time *)yp)->time) |
| 226 return(1); | 229 return(1); |
| 227 | 230 |
| 228 return(-1); | 231 return(-1); |
| 229 } | 232 } |
| OLD | NEW |