blob: 66a00bda03851cd1bb2e9ddf4519aaad04d13a54 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +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"
kjellander@webrtc.org543c3ea2011-11-23 12:20:35 +000016#include "gtest/gtest.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000017
18/*********************/
19/* Misc. definitions */
20/*********************/
21
22#define FIRSTLINELEN 40
23
24
tina.legrand@webrtc.orgd0acdf62012-11-16 15:34:32 +000025int 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.com470e71d2011-07-07 08:21:25 +000070 }
tina.legrand@webrtc.orgd0acdf62012-11-16 15:34:32 +000071 }
niklase@google.com470e71d2011-07-07 08:21:25 +000072
tina.legrand@webrtc.orgd0acdf62012-11-16 15:34:32 +000073 while (packLen >= 0) {
niklase@google.com470e71d2011-07-07 08:21:25 +000074
tina.legrand@webrtc.orgd0acdf62012-11-16 15:34:32 +000075 packet.setTimeStamp(packet.timeStamp() + TSdiff);
76 packet.setSequenceNumber(packet.sequenceNumber() + SNdiff);
77 packet.setTime(packet.time() + ATdiff);
niklase@google.com470e71d2011-07-07 08:21:25 +000078
tina.legrand@webrtc.orgd0acdf62012-11-16 15:34:32 +000079 packet.writeToFile(outFile);
niklase@google.com470e71d2011-07-07 08:21:25 +000080
tina.legrand@webrtc.orgd0acdf62012-11-16 15:34:32 +000081 packLen = packet.readFromFile(inFile);
niklase@google.com470e71d2011-07-07 08:21:25 +000082
tina.legrand@webrtc.orgd0acdf62012-11-16 15:34:32 +000083 }
niklase@google.com470e71d2011-07-07 08:21:25 +000084
tina.legrand@webrtc.orgd0acdf62012-11-16 15:34:32 +000085 fclose(inFile);
86 fclose(outFile);
niklase@google.com470e71d2011-07-07 08:21:25 +000087
tina.legrand@webrtc.orgd0acdf62012-11-16 15:34:32 +000088 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000089}