blob: dc7ff9fb7ef31bdc2cbd3788ed686f60f85dbc82 [file] [log] [blame]
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +00001/*
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"
16#include "gtest/gtest.h"
17
18/*********************/
19/* Misc. definitions */
20/*********************/
21
22#define FIRSTLINELEN 40
23
24
25int main(int argc, char* argv[])
26{
27 if(argc < 4 || argc > 6)
28 {
29 printf("Usage: RTPtimeshift in.rtp out.rtp newStartTS [newStartSN [newStartArrTime]]\n");
30 exit(1);
31 }
32
33 FILE *inFile=fopen(argv[1],"rb");
34 if (!inFile)
35 {
36 printf("Cannot open input file %s\n", argv[1]);
37 return(-1);
38 }
39 printf("Input RTP file: %s\n",argv[1]);
40
41 FILE *outFile=fopen(argv[2],"wb");
42 if (!outFile)
43 {
44 printf("Cannot open output file %s\n", argv[2]);
45 return(-1);
46 }
47 printf("Output RTP file: %s\n\n",argv[2]);
48
49 // read file header and write directly to output file
50 const unsigned int kRtpDumpHeaderSize = 4 + 4 + 4 + 2 + 2;
51 char firstline[FIRSTLINELEN];
52 EXPECT_TRUE(fgets(firstline, FIRSTLINELEN, inFile) != NULL);
53 EXPECT_GT(fputs(firstline, outFile), 0);
54 EXPECT_EQ(kRtpDumpHeaderSize,
55 fread(firstline, 1, kRtpDumpHeaderSize, inFile));
56 EXPECT_EQ(kRtpDumpHeaderSize,
57 fwrite(firstline, 1, kRtpDumpHeaderSize, outFile));
58 NETEQTEST_RTPpacket packet;
59 int packLen = packet.readFromFile(inFile);
60 if (packLen < 0)
61 {
62 exit(1);
63 }
64
65 // get new start TS and start SeqNo from arguments
66 WebRtc_UWord32 TSdiff = atoi(argv[3]) - packet.timeStamp();
67 WebRtc_UWord16 SNdiff = 0;
68 WebRtc_UWord32 ATdiff = 0;
69 if (argc > 4)
70 {
71 if (argv[4] >= 0)
72 SNdiff = atoi(argv[4]) - packet.sequenceNumber();
73 if (argc > 5)
74 {
75 if (argv[5] >= 0)
76 ATdiff = atoi(argv[5]) - packet.time();
77 }
78 }
79
80 while (packLen >= 0)
81 {
82
83 packet.setTimeStamp(packet.timeStamp() + TSdiff);
84 packet.setSequenceNumber(packet.sequenceNumber() + SNdiff);
85 packet.setTime(packet.time() + ATdiff);
86
87 packet.writeToFile(outFile);
88
89 packLen = packet.readFromFile(inFile);
90
91 }
92
93 fclose(inFile);
94 fclose(outFile);
95
96 return 0;
97}