blob: 3b7a53c4ab2a250f83e4a70fed06bccc572572b0 [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
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000011#include <stdio.h>
Ivo Creusen5a317802015-04-22 13:12:00 +020012#include <algorithm>
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000013#include <vector>
14
Ivo Creusen5a317802015-04-22 13:12:00 +020015#include "webrtc/modules/audio_coding/neteq/test/NETEQTEST_RTPpacket.h"
kwibergac9f8762016-09-30 22:29:43 -070016#include "webrtc/test/gtest.h"
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000017
18#define FIRSTLINELEN 40
19
Ivo Creusen5a317802015-04-22 13:12:00 +020020int 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:21 +000027
Ivo Creusen5a317802015-04-22 13:12:00 +020028 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:21 +000069 }
Ivo Creusen5a317802015-04-22 13:12:00 +020070 }
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000071
Ivo Creusen5a317802015-04-22 13:12:00 +020072 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:21 +000076
Ivo Creusen5a317802015-04-22 13:12:00 +020077 packet.writeToFile(outFile);
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000078
Ivo Creusen5a317802015-04-22 13:12:00 +020079 packLen = packet.readFromFile(inFile);
80 }
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000081
Ivo Creusen5a317802015-04-22 13:12:00 +020082 fclose(inFile);
83 fclose(outFile);
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000084
Ivo Creusen5a317802015-04-22 13:12:00 +020085 return 0;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000086}