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 <stdio.h> 12 13 #include "webrtc/base/format_macros.h" 14 #include "webrtc/base/scoped_ptr.h" 15 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h" 16 #include "webrtc/modules/remote_bitrate_estimator/tools/bwe_rtp.h" 17 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" 18 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" 19 #include "webrtc/test/rtp_file_reader.h" 20 21 class Observer : public webrtc::RemoteBitrateObserver { 22 public: 23 explicit Observer(webrtc::Clock* clock) : clock_(clock) {} 24 25 // Called when a receive channel group has a new bitrate estimate for the 26 // incoming streams. 27 virtual void OnReceiveBitrateChanged(const std::vector<unsigned int>& ssrcs, 28 unsigned int bitrate) { 29 printf("[%u] Num SSRCs: %d, bitrate: %u\n", 30 static_cast<uint32_t>(clock_->TimeInMilliseconds()), 31 static_cast<int>(ssrcs.size()), bitrate); 32 } 33 34 virtual ~Observer() {} 35 36 private: 37 webrtc::Clock* clock_; 38 }; 39 40 int main(int argc, char** argv) { 41 webrtc::test::RtpFileReader* reader; 42 webrtc::RemoteBitrateEstimator* estimator; 43 webrtc::RtpHeaderParser* parser; 44 std::string estimator_used; 45 webrtc::SimulatedClock clock(0); 46 Observer observer(&clock); 47 if (!ParseArgsAndSetupEstimator(argc, argv, &clock, &observer, &reader, 48 &parser, &estimator, &estimator_used)) { 49 return -1; 50 } 51 rtc::scoped_ptr<webrtc::test::RtpFileReader> rtp_reader(reader); 52 rtc::scoped_ptr<webrtc::RtpHeaderParser> rtp_parser(parser); 53 rtc::scoped_ptr<webrtc::RemoteBitrateEstimator> rbe(estimator); 54 55 // Process the file. 56 int packet_counter = 0; 57 int64_t next_rtp_time_ms = 0; 58 int64_t first_rtp_time_ms = -1; 59 int abs_send_time_count = 0; 60 int ts_offset_count = 0; 61 webrtc::test::RtpPacket packet; 62 if (!rtp_reader->NextPacket(&packet)) { 63 printf("No RTP packet found\n"); 64 return 0; 65 } 66 first_rtp_time_ms = packet.time_ms; 67 packet.time_ms = packet.time_ms - first_rtp_time_ms; 68 while (true) { 69 if (next_rtp_time_ms <= clock.TimeInMilliseconds()) { 70 if (!parser->IsRtcp(packet.data, packet.length)) { 71 webrtc::RTPHeader header; 72 parser->Parse(packet.data, packet.length, &header); 73 if (header.extension.hasAbsoluteSendTime) 74 ++abs_send_time_count; 75 if (header.extension.hasTransmissionTimeOffset) 76 ++ts_offset_count; 77 size_t packet_length = packet.length; 78 // Some RTP dumps only include the header, in which case packet.length 79 // is equal to the header length. In those cases packet.original_length 80 // usually contains the original packet length. 81 if (packet.original_length > 0) { 82 packet_length = packet.original_length; 83 } 84 rbe->IncomingPacket(clock.TimeInMilliseconds(), 85 packet_length - header.headerLength, header, true); 86 ++packet_counter; 87 } 88 if (!rtp_reader->NextPacket(&packet)) { 89 break; 90 } 91 packet.time_ms = packet.time_ms - first_rtp_time_ms; 92 next_rtp_time_ms = packet.time_ms; 93 } 94 int64_t time_until_process_ms = rbe->TimeUntilNextProcess(); 95 if (time_until_process_ms <= 0) { 96 rbe->Process(); 97 } 98 int64_t time_until_next_event = 99 std::min(rbe->TimeUntilNextProcess(), 100 next_rtp_time_ms - clock.TimeInMilliseconds()); 101 clock.AdvanceTimeMilliseconds(std::max<int64_t>(time_until_next_event, 0)); 102 } 103 printf("Parsed %d packets\nTime passed: %" PRId64 " ms\n", packet_counter, 104 clock.TimeInMilliseconds()); 105 printf("Estimator used: %s\n", estimator_used.c_str()); 106 printf("Packets with absolute send time: %d\n", 107 abs_send_time_count); 108 printf("Packets with timestamp offset: %d\n", 109 ts_offset_count); 110 printf("Packets with no extension: %d\n", 111 packet_counter - ts_offset_count - abs_send_time_count); 112 return 0; 113 } 114