Home | History | Annotate | Download | only in test
      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 
     11 #include <stdio.h>
     12 
     13 #include <algorithm>
     14 #include <vector>
     15 
     16 #include "testing/gtest/include/gtest/gtest.h"
     17 #include "webrtc/modules/audio_coding/neteq/test/NETEQTEST_RTPpacket.h"
     18 
     19 #define FIRSTLINELEN 40
     20 
     21 int main(int argc, char* argv[]) {
     22   if (argc < 3) {
     23     printf("Usage: RTPcat in1.rtp int2.rtp [...] out.rtp\n");
     24     exit(1);
     25   }
     26 
     27   FILE* in_file = fopen(argv[1], "rb");
     28   if (!in_file) {
     29     printf("Cannot open input file %s\n", argv[1]);
     30     return -1;
     31   }
     32 
     33   FILE* out_file = fopen(argv[argc - 1], "wb");  // Last parameter is out file.
     34   if (!out_file) {
     35     printf("Cannot open output file %s\n", argv[argc - 1]);
     36     return -1;
     37   }
     38   printf("Output RTP file: %s\n\n", argv[argc - 1]);
     39 
     40   // Read file header and write directly to output file.
     41   char firstline[FIRSTLINELEN];
     42   const unsigned int kRtpDumpHeaderSize = 4 + 4 + 4 + 2 + 2;
     43   EXPECT_TRUE(fgets(firstline, FIRSTLINELEN, in_file) != NULL);
     44   EXPECT_GT(fputs(firstline, out_file), 0);
     45   EXPECT_EQ(kRtpDumpHeaderSize, fread(firstline, 1, kRtpDumpHeaderSize,
     46                                       in_file));
     47   EXPECT_EQ(kRtpDumpHeaderSize, fwrite(firstline, 1, kRtpDumpHeaderSize,
     48                                        out_file));
     49 
     50   // Close input file and re-open it later (easier to write the loop below).
     51   fclose(in_file);
     52 
     53   for (int i = 1; i < argc - 1; i++) {
     54     in_file = fopen(argv[i], "rb");
     55     if (!in_file) {
     56       printf("Cannot open input file %s\n", argv[i]);
     57       return -1;
     58     }
     59     printf("Input RTP file: %s\n", argv[i]);
     60 
     61     NETEQTEST_RTPpacket::skipFileHeader(in_file);
     62     NETEQTEST_RTPpacket packet;
     63     int pack_len = packet.readFromFile(in_file);
     64     if (pack_len < 0) {
     65       exit(1);
     66     }
     67     while (pack_len >= 0) {
     68       packet.writeToFile(out_file);
     69       pack_len = packet.readFromFile(in_file);
     70     }
     71     fclose(in_file);
     72   }
     73   fclose(out_file);
     74   return 0;
     75 }
     76