Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / remote_bitrate_estimator / tools / bwe_rtp.cc
1 /*
2  *  Copyright (c) 2014 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 "webrtc/modules/remote_bitrate_estimator/tools/bwe_rtp.h"
12
13 #include <stdio.h>
14 #include <string>
15
16 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
17 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
18 #include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h"
19 #include "webrtc/test/rtp_file_reader.h"
20
21 const int kMinBitrateBps = 30000;
22
23 bool ParseArgsAndSetupEstimator(int argc,
24                                 char** argv,
25                                 webrtc::Clock* clock,
26                                 webrtc::RemoteBitrateObserver* observer,
27                                 webrtc::test::RtpFileReader** rtp_reader,
28                                 webrtc::RtpHeaderParser** parser,
29                                 webrtc::RemoteBitrateEstimator** estimator,
30                                 std::string* estimator_used) {
31   *rtp_reader = webrtc::test::RtpFileReader::Create(
32       webrtc::test::RtpFileReader::kRtpDump, argv[3]);
33   if (!*rtp_reader) {
34     fprintf(stderr, "Cannot open input file %s\n", argv[3]);
35     return false;
36   }
37   fprintf(stderr, "Input file: %s\n\n", argv[3]);
38   webrtc::RTPExtensionType extension = webrtc::kRtpExtensionAbsoluteSendTime;
39
40   if (strncmp("tsoffset", argv[1], 8) == 0) {
41     extension = webrtc::kRtpExtensionTransmissionTimeOffset;
42     fprintf(stderr, "Extension: toffset\n");
43   } else {
44     fprintf(stderr, "Extension: abs\n");
45   }
46   int id = atoi(argv[2]);
47
48   // Setup the RTP header parser and the bitrate estimator.
49   *parser = webrtc::RtpHeaderParser::Create();
50   (*parser)->RegisterRtpHeaderExtension(extension, id);
51   if (estimator) {
52     switch (extension) {
53       case webrtc::kRtpExtensionAbsoluteSendTime: {
54           webrtc::AbsoluteSendTimeRemoteBitrateEstimatorFactory factory;
55           *estimator = factory.Create(observer, clock, webrtc::kAimdControl,
56                                       kMinBitrateBps);
57           *estimator_used = "AbsoluteSendTimeRemoteBitrateEstimator";
58           break;
59         }
60       case webrtc::kRtpExtensionTransmissionTimeOffset: {
61           webrtc::RemoteBitrateEstimatorFactory factory;
62           *estimator = factory.Create(observer, clock, webrtc::kAimdControl,
63                                       kMinBitrateBps);
64           *estimator_used = "RemoteBitrateEstimator";
65           break;
66         }
67       default:
68         assert(false);
69     }
70   }
71   return true;
72 }