Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / audio_coding / neteq / test / RTPanalyze.cc
1 /*
2  *  Copyright (c) 2012 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 <assert.h>
12 #include <stdio.h>
13 #include <vector>
14
15 #include "modules/audio_coding/neteq/test/NETEQTEST_RTPpacket.h"
16 #include "modules/audio_coding/neteq/test/NETEQTEST_DummyRTPpacket.h"
17
18 //#define WEBRTC_DUMMY_RTP
19
20 enum {
21   kRedPayloadType = 127
22 };
23
24 int main(int argc, char* argv[]) {
25   FILE* in_file = fopen(argv[1], "rb");
26   if (!in_file) {
27     printf("Cannot open input file %s\n", argv[1]);
28     return -1;
29   }
30   printf("Input file: %s\n", argv[1]);
31
32   FILE* out_file = fopen(argv[2], "wt");
33   if (!out_file) {
34     printf("Cannot open output file %s\n", argv[2]);
35     return -1;
36   }
37   printf("Output file: %s\n\n", argv[2]);
38
39   // Print file header.
40   fprintf(out_file, "SeqNo  TimeStamp   SendTime  Size    PT  M       SSRC\n");
41
42   // Read file header.
43   NETEQTEST_RTPpacket::skipFileHeader(in_file);
44 #ifdef WEBRTC_DUMMY_RTP
45   NETEQTEST_DummyRTPpacket packet;
46 #else
47   NETEQTEST_RTPpacket packet;
48 #endif
49
50   while (packet.readFromFile(in_file) >= 0) {
51     // Write packet data to file.
52     fprintf(out_file, "%5u %10u %10u %5i %5i %2i %#08X\n",
53             packet.sequenceNumber(), packet.timeStamp(), packet.time(),
54             packet.dataLen(), packet.payloadType(), packet.markerBit(),
55             packet.SSRC());
56     if (packet.payloadType() == kRedPayloadType) {
57       WebRtcNetEQ_RTPInfo red_header;
58       int len;
59       int red_index = 0;
60       while ((len = packet.extractRED(red_index++, red_header)) >= 0) {
61         fprintf(out_file, "* %5u %10u %10u %5i %5i\n",
62                 red_header.sequenceNumber, red_header.timeStamp,
63                 packet.time(), len, red_header.payloadType);
64       }
65       assert(red_index > 1);  // We must get at least one payload.
66     }
67   }
68
69   fclose(in_file);
70   fclose(out_file);
71
72   return 0;
73 }