niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
andrew@webrtc.org | f589dfe | 2012-03-27 17:05:44 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 11 | #include <stdio.h> |
henrik.lundin@webrtc.org | 6c87736 | 2012-01-03 10:03:19 +0000 | [diff] [blame] | 12 | |
| 13 | #include <algorithm> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 14 | #include <vector> |
| 15 | |
henrik.lundin@webrtc.org | 6c87736 | 2012-01-03 10:03:19 +0000 | [diff] [blame] | 16 | #include "modules/audio_coding/neteq/test/NETEQTEST_RTPpacket.h" |
andrew@webrtc.org | 61b1b4b | 2012-03-27 17:33:29 +0000 | [diff] [blame^] | 17 | #include "modules/audio_coding/neteq/test/NETEQTEST_DummyRTPpacket.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | |
| 19 | #define FIRSTLINELEN 40 |
andrew@webrtc.org | f589dfe | 2012-03-27 17:05:44 +0000 | [diff] [blame] | 20 | //#define WEBRTC_DUMMY_RTP |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | |
henrik.lundin@webrtc.org | 6c87736 | 2012-01-03 10:03:19 +0000 | [diff] [blame] | 22 | static bool pktCmp(NETEQTEST_RTPpacket *a, NETEQTEST_RTPpacket *b) { |
| 23 | return (a->time() < b->time()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | } |
| 25 | |
henrik.lundin@webrtc.org | 6c87736 | 2012-01-03 10:03:19 +0000 | [diff] [blame] | 26 | int main(int argc, char* argv[]) { |
| 27 | FILE* in_file = fopen(argv[1], "rb"); |
| 28 | if (!in_file) { |
| 29 | printf("Cannot open input file %s\n", argv[1]); |
| 30 | return -1; |
| 31 | } |
| 32 | printf("Input RTP file: %s\n", argv[1]); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | |
henrik.lundin@webrtc.org | 6c87736 | 2012-01-03 10:03:19 +0000 | [diff] [blame] | 34 | FILE* stat_file = fopen(argv[2], "rt"); |
| 35 | if (!stat_file) { |
| 36 | printf("Cannot open timing file %s\n", argv[2]); |
| 37 | return -1; |
| 38 | } |
| 39 | printf("Timing file: %s\n", argv[2]); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | |
henrik.lundin@webrtc.org | 6c87736 | 2012-01-03 10:03:19 +0000 | [diff] [blame] | 41 | FILE* out_file = fopen(argv[3], "wb"); |
| 42 | if (!out_file) { |
| 43 | printf("Cannot open output file %s\n", argv[3]); |
| 44 | return -1; |
| 45 | } |
| 46 | printf("Output RTP file: %s\n\n", argv[3]); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | |
henrik.lundin@webrtc.org | 6c87736 | 2012-01-03 10:03:19 +0000 | [diff] [blame] | 48 | // Read all statistics and insert into map. |
| 49 | // Read first line. |
| 50 | char temp_str[100]; |
| 51 | if (fgets(temp_str, 100, stat_file) == NULL) { |
| 52 | printf("Failed to read timing file %s\n", argv[2]); |
| 53 | return -1; |
| 54 | } |
| 55 | // Define map. |
| 56 | std::map<std::pair<uint16_t, uint32_t>, uint32_t> packet_stats; |
| 57 | uint16_t seq_no; |
| 58 | uint32_t ts; |
| 59 | uint32_t send_time; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 60 | |
henrik.lundin@webrtc.org | 6c87736 | 2012-01-03 10:03:19 +0000 | [diff] [blame] | 61 | while (fscanf(stat_file, |
| 62 | "%hu %u %u %*i %*i\n", &seq_no, &ts, &send_time) == 3) { |
| 63 | std::pair<uint16_t, uint32_t> |
| 64 | temp_pair = std::pair<uint16_t, uint32_t>(seq_no, ts); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 65 | |
henrik.lundin@webrtc.org | 6c87736 | 2012-01-03 10:03:19 +0000 | [diff] [blame] | 66 | packet_stats[temp_pair] = send_time; |
| 67 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 68 | |
henrik.lundin@webrtc.org | 6c87736 | 2012-01-03 10:03:19 +0000 | [diff] [blame] | 69 | fclose(stat_file); |
| 70 | |
| 71 | // Read file header and write directly to output file. |
| 72 | char first_line[FIRSTLINELEN]; |
| 73 | if (fgets(first_line, FIRSTLINELEN, in_file) == NULL) { |
| 74 | printf("Failed to read first line of input file %s\n", argv[1]); |
| 75 | return -1; |
| 76 | } |
| 77 | fputs(first_line, out_file); |
| 78 | // start_sec + start_usec + source + port + padding |
| 79 | const unsigned int kRtpDumpHeaderSize = 4 + 4 + 4 + 2 + 2; |
| 80 | if (fread(first_line, 1, kRtpDumpHeaderSize, in_file) |
| 81 | != kRtpDumpHeaderSize) { |
| 82 | printf("Failed to read RTP dump header from input file %s\n", argv[1]); |
| 83 | return -1; |
| 84 | } |
| 85 | if (fwrite(first_line, 1, kRtpDumpHeaderSize, out_file) |
| 86 | != kRtpDumpHeaderSize) { |
| 87 | printf("Failed to write RTP dump header to output file %s\n", argv[3]); |
| 88 | return -1; |
| 89 | } |
| 90 | |
| 91 | std::vector<NETEQTEST_RTPpacket *> packet_vec; |
| 92 | |
| 93 | while (1) { |
| 94 | // Insert in vector. |
andrew@webrtc.org | f589dfe | 2012-03-27 17:05:44 +0000 | [diff] [blame] | 95 | #ifdef WEBRTC_DUMMY_RTP |
| 96 | NETEQTEST_RTPpacket *new_packet = new NETEQTEST_DummyRTPpacket(); |
| 97 | #else |
henrik.lundin@webrtc.org | 6c87736 | 2012-01-03 10:03:19 +0000 | [diff] [blame] | 98 | NETEQTEST_RTPpacket *new_packet = new NETEQTEST_RTPpacket(); |
andrew@webrtc.org | f589dfe | 2012-03-27 17:05:44 +0000 | [diff] [blame] | 99 | #endif |
henrik.lundin@webrtc.org | 6c87736 | 2012-01-03 10:03:19 +0000 | [diff] [blame] | 100 | if (new_packet->readFromFile(in_file) < 0) { |
| 101 | // End of file. |
| 102 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | } |
| 104 | |
henrik.lundin@webrtc.org | 6c87736 | 2012-01-03 10:03:19 +0000 | [diff] [blame] | 105 | // Look for new send time in statistics vector. |
| 106 | std::pair<uint16_t, uint32_t> temp_pair = |
| 107 | std::pair<uint16_t, uint32_t>(new_packet->sequenceNumber(), |
| 108 | new_packet->timeStamp()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 109 | |
henrik.lundin@webrtc.org | 6c87736 | 2012-01-03 10:03:19 +0000 | [diff] [blame] | 110 | uint32_t new_send_time = packet_stats[temp_pair]; |
| 111 | new_packet->setTime(new_send_time); // Set new send time. |
| 112 | packet_vec.push_back(new_packet); // Insert in vector. |
| 113 | } |
| 114 | |
| 115 | // Sort the vector according to send times. |
| 116 | std::sort(packet_vec.begin(), packet_vec.end(), pktCmp); |
| 117 | |
| 118 | std::vector<NETEQTEST_RTPpacket *>::iterator it; |
| 119 | for (it = packet_vec.begin(); it != packet_vec.end(); it++) { |
| 120 | // Write to out file. |
| 121 | if ((*it)->writeToFile(out_file) < 0) { |
| 122 | printf("Error writing to file\n"); |
| 123 | return -1; |
kjellander@webrtc.org | 543c3ea | 2011-11-23 12:20:35 +0000 | [diff] [blame] | 124 | } |
henrik.lundin@webrtc.org | 6c87736 | 2012-01-03 10:03:19 +0000 | [diff] [blame] | 125 | // Delete packet. |
| 126 | delete *it; |
| 127 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 128 | |
henrik.lundin@webrtc.org | 6c87736 | 2012-01-03 10:03:19 +0000 | [diff] [blame] | 129 | fclose(in_file); |
| 130 | fclose(out_file); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 131 | |
henrik.lundin@webrtc.org | 6c87736 | 2012-01-03 10:03:19 +0000 | [diff] [blame] | 132 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 133 | } |