niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
| 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 | |
| 11 | #include <algorithm> |
| 12 | #include <stdio.h> |
| 13 | #include <vector> |
| 14 | |
| 15 | #include "NETEQTEST_RTPpacket.h" |
kjellander@webrtc.org | 543c3ea | 2011-11-23 12:20:35 +0000 | [diff] [blame] | 16 | #include "gtest/gtest.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 17 | |
| 18 | /*********************/ |
| 19 | /* Misc. definitions */ |
| 20 | /*********************/ |
| 21 | |
| 22 | #define FIRSTLINELEN 40 |
| 23 | |
| 24 | |
tina.legrand@webrtc.org | d0acdf6 | 2012-11-16 15:34:32 +0000 | [diff] [blame^] | 25 | int main(int argc, char* argv[]) { |
| 26 | if (argc < 4 || argc > 6) { |
| 27 | printf( |
| 28 | "Usage: RTPtimeshift in.rtp out.rtp newStartTS " |
| 29 | "[newStartSN [newStartArrTime]]\n"); |
| 30 | exit(1); |
| 31 | } |
| 32 | |
| 33 | FILE *inFile = fopen(argv[1], "rb"); |
| 34 | if (!inFile) { |
| 35 | printf("Cannot open input file %s\n", argv[1]); |
| 36 | return (-1); |
| 37 | } |
| 38 | printf("Input RTP file: %s\n", argv[1]); |
| 39 | |
| 40 | FILE *outFile = fopen(argv[2], "wb"); |
| 41 | if (!outFile) { |
| 42 | printf("Cannot open output file %s\n", argv[2]); |
| 43 | return (-1); |
| 44 | } |
| 45 | printf("Output RTP file: %s\n\n", argv[2]); |
| 46 | |
| 47 | // read file header and write directly to output file |
| 48 | const unsigned int kRtpDumpHeaderSize = 4 + 4 + 4 + 2 + 2; |
| 49 | char firstline[FIRSTLINELEN]; |
| 50 | EXPECT_TRUE(fgets(firstline, FIRSTLINELEN, inFile) != NULL); |
| 51 | EXPECT_GT(fputs(firstline, outFile), 0); |
| 52 | EXPECT_EQ(kRtpDumpHeaderSize, |
| 53 | fread(firstline, 1, kRtpDumpHeaderSize, inFile)); |
| 54 | EXPECT_EQ(kRtpDumpHeaderSize, |
| 55 | fwrite(firstline, 1, kRtpDumpHeaderSize, outFile)); |
| 56 | NETEQTEST_RTPpacket packet; |
| 57 | int packLen = packet.readFromFile(inFile); |
| 58 | if (packLen < 0) { |
| 59 | exit(1); |
| 60 | } |
| 61 | |
| 62 | // get new start TS and start SeqNo from arguments |
| 63 | WebRtc_UWord32 TSdiff = atoi(argv[3]) - packet.timeStamp(); |
| 64 | WebRtc_UWord16 SNdiff = 0; |
| 65 | WebRtc_UWord32 ATdiff = 0; |
| 66 | if (argc > 4) { |
| 67 | SNdiff = atoi(argv[4]) - packet.sequenceNumber(); |
| 68 | if (argc > 5) { |
| 69 | ATdiff = atoi(argv[5]) - packet.time(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | } |
tina.legrand@webrtc.org | d0acdf6 | 2012-11-16 15:34:32 +0000 | [diff] [blame^] | 71 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 72 | |
tina.legrand@webrtc.org | d0acdf6 | 2012-11-16 15:34:32 +0000 | [diff] [blame^] | 73 | while (packLen >= 0) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 74 | |
tina.legrand@webrtc.org | d0acdf6 | 2012-11-16 15:34:32 +0000 | [diff] [blame^] | 75 | packet.setTimeStamp(packet.timeStamp() + TSdiff); |
| 76 | packet.setSequenceNumber(packet.sequenceNumber() + SNdiff); |
| 77 | packet.setTime(packet.time() + ATdiff); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 78 | |
tina.legrand@webrtc.org | d0acdf6 | 2012-11-16 15:34:32 +0000 | [diff] [blame^] | 79 | packet.writeToFile(outFile); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | |
tina.legrand@webrtc.org | d0acdf6 | 2012-11-16 15:34:32 +0000 | [diff] [blame^] | 81 | packLen = packet.readFromFile(inFile); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 82 | |
tina.legrand@webrtc.org | d0acdf6 | 2012-11-16 15:34:32 +0000 | [diff] [blame^] | 83 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 84 | |
tina.legrand@webrtc.org | d0acdf6 | 2012-11-16 15:34:32 +0000 | [diff] [blame^] | 85 | fclose(inFile); |
| 86 | fclose(outFile); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | |
tina.legrand@webrtc.org | d0acdf6 | 2012-11-16 15:34:32 +0000 | [diff] [blame^] | 88 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | } |