henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [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 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 11 | #include <stdio.h> |
Ivo Creusen | 5a31780 | 2015-04-22 11:12:00 | [diff] [blame] | 12 | #include <algorithm> |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 13 | #include <vector> |
| 14 | |
kjellander@webrtc.org | 3c0aae1 | 2014-09-04 09:55:40 | [diff] [blame] | 15 | #include "testing/gtest/include/gtest/gtest.h" |
Ivo Creusen | 5a31780 | 2015-04-22 11:12:00 | [diff] [blame] | 16 | #include "webrtc/modules/audio_coding/neteq/test/NETEQTEST_RTPpacket.h" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 17 | |
| 18 | #define FIRSTLINELEN 40 |
| 19 | |
Ivo Creusen | 5a31780 | 2015-04-22 11:12:00 | [diff] [blame] | 20 | int main(int argc, char* argv[]) { |
| 21 | if (argc < 4 || argc > 6) { |
| 22 | printf( |
| 23 | "Usage: RTPtimeshift in.rtp out.rtp newStartTS [newStartSN " |
| 24 | "[newStartArrTime]]\n"); |
| 25 | exit(1); |
| 26 | } |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 27 | |
Ivo Creusen | 5a31780 | 2015-04-22 11:12:00 | [diff] [blame] | 28 | FILE* inFile = fopen(argv[1], "rb"); |
| 29 | if (!inFile) { |
| 30 | printf("Cannot open input file %s\n", argv[1]); |
| 31 | return (-1); |
| 32 | } |
| 33 | printf("Input RTP file: %s\n", argv[1]); |
| 34 | |
| 35 | FILE* outFile = fopen(argv[2], "wb"); |
| 36 | if (!outFile) { |
| 37 | printf("Cannot open output file %s\n", argv[2]); |
| 38 | return (-1); |
| 39 | } |
| 40 | printf("Output RTP file: %s\n\n", argv[2]); |
| 41 | |
| 42 | // Read file header and write directly to output file. |
| 43 | const unsigned int kRtpDumpHeaderSize = 4 + 4 + 4 + 2 + 2; |
| 44 | char firstline[FIRSTLINELEN]; |
| 45 | EXPECT_TRUE(fgets(firstline, FIRSTLINELEN, inFile) != NULL); |
| 46 | EXPECT_GT(fputs(firstline, outFile), 0); |
| 47 | EXPECT_EQ(kRtpDumpHeaderSize, |
| 48 | fread(firstline, 1, kRtpDumpHeaderSize, inFile)); |
| 49 | EXPECT_EQ(kRtpDumpHeaderSize, |
| 50 | fwrite(firstline, 1, kRtpDumpHeaderSize, outFile)); |
| 51 | NETEQTEST_RTPpacket packet; |
| 52 | int packLen = packet.readFromFile(inFile); |
| 53 | if (packLen < 0) { |
| 54 | exit(1); |
| 55 | } |
| 56 | |
| 57 | // Get new start TS and start SeqNo from arguments. |
| 58 | uint32_t TSdiff = atoi(argv[3]) - packet.timeStamp(); |
| 59 | uint16_t SNdiff = 0; |
| 60 | uint32_t ATdiff = 0; |
| 61 | if (argc > 4) { |
| 62 | int startSN = atoi(argv[4]); |
| 63 | if (startSN >= 0) |
| 64 | SNdiff = startSN - packet.sequenceNumber(); |
| 65 | if (argc > 5) { |
| 66 | int startTS = atoi(argv[5]); |
| 67 | if (startTS >= 0) |
| 68 | ATdiff = startTS - packet.time(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 69 | } |
Ivo Creusen | 5a31780 | 2015-04-22 11:12:00 | [diff] [blame] | 70 | } |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 71 | |
Ivo Creusen | 5a31780 | 2015-04-22 11:12:00 | [diff] [blame] | 72 | while (packLen >= 0) { |
| 73 | packet.setTimeStamp(packet.timeStamp() + TSdiff); |
| 74 | packet.setSequenceNumber(packet.sequenceNumber() + SNdiff); |
| 75 | packet.setTime(packet.time() + ATdiff); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 76 | |
Ivo Creusen | 5a31780 | 2015-04-22 11:12:00 | [diff] [blame] | 77 | packet.writeToFile(outFile); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 78 | |
Ivo Creusen | 5a31780 | 2015-04-22 11:12:00 | [diff] [blame] | 79 | packLen = packet.readFromFile(inFile); |
| 80 | } |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 81 | |
Ivo Creusen | 5a31780 | 2015-04-22 11:12:00 | [diff] [blame] | 82 | fclose(inFile); |
| 83 | fclose(outFile); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 84 | |
Ivo Creusen | 5a31780 | 2015-04-22 11:12:00 | [diff] [blame] | 85 | return 0; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 86 | } |