blob: f45a97af2f883304e9fc0d0766a9ea94ba50d32b [file] [log] [blame]
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:211/*
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.orgd94659d2013-01-29 12:09:2111#include <stdio.h>
Ivo Creusen5a317802015-04-22 11:12:0012#include <algorithm>
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:2113#include <vector>
14
kjellander@webrtc.org3c0aae12014-09-04 09:55:4015#include "testing/gtest/include/gtest/gtest.h"
Ivo Creusen5a317802015-04-22 11:12:0016#include "webrtc/modules/audio_coding/neteq/test/NETEQTEST_RTPpacket.h"
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:2117
18#define FIRSTLINELEN 40
19
Ivo Creusen5a317802015-04-22 11:12:0020int 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.orgd94659d2013-01-29 12:09:2127
Ivo Creusen5a317802015-04-22 11:12:0028 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.orgd94659d2013-01-29 12:09:2169 }
Ivo Creusen5a317802015-04-22 11:12:0070 }
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:2171
Ivo Creusen5a317802015-04-22 11:12:0072 while (packLen >= 0) {
73 packet.setTimeStamp(packet.timeStamp() + TSdiff);
74 packet.setSequenceNumber(packet.sequenceNumber() + SNdiff);
75 packet.setTime(packet.time() + ATdiff);
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:2176
Ivo Creusen5a317802015-04-22 11:12:0077 packet.writeToFile(outFile);
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:2178
Ivo Creusen5a317802015-04-22 11:12:0079 packLen = packet.readFromFile(inFile);
80 }
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:2181
Ivo Creusen5a317802015-04-22 11:12:0082 fclose(inFile);
83 fclose(outFile);
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:2184
Ivo Creusen5a317802015-04-22 11:12:0085 return 0;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:2186}