| OLD | NEW |
| (Empty) |
| 1 # Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
| 2 # | |
| 3 # Use of this source code is governed by a BSD-style license | |
| 4 # that can be found in the LICENSE file in the root of the source | |
| 5 # tree. An additional intellectual property rights grant can be found | |
| 6 # in the file PATENTS. All contributing project authors may | |
| 7 # be found in the AUTHORS file in the root of the source tree. | |
| 8 | |
| 9 """Parses protobuf RTC dumps.""" | |
| 10 | |
| 11 from __future__ import division | |
| 12 import struct | |
| 13 import pyproto.webrtc.logging.rtc_event_log.rtc_event_log_pb2 as rtc_pb | |
| 14 | |
| 15 | |
| 16 class DataPoint(object): | |
| 17 """Simple container class for RTP events.""" | |
| 18 | |
| 19 def __init__(self, rtp_header_str, packet_size, | |
| 20 arrival_timestamp_us, incoming): | |
| 21 """Builds a data point by parsing an RTP header, size and arrival time. | |
| 22 | |
| 23 RTP header structure is defined in RFC 3550 section 5.1. | |
| 24 """ | |
| 25 self.size = packet_size | |
| 26 self.arrival_timestamp_ms = arrival_timestamp_us / 1000 | |
| 27 self.incoming = incoming | |
| 28 header = struct.unpack_from("!HHII", rtp_header_str, 0) | |
| 29 (first2header_bytes, self.sequence_number, self.timestamp, | |
| 30 self.ssrc) = header | |
| 31 self.payload_type = first2header_bytes & 0b01111111 | |
| 32 self.marker_bit = (first2header_bytes & 0b10000000) >> 7 | |
| 33 | |
| 34 | |
| 35 def ParseProtobuf(file_path): | |
| 36 """Parses RTC event log from protobuf file. | |
| 37 | |
| 38 Args: | |
| 39 file_path: path to protobuf file of RTC event stream | |
| 40 | |
| 41 Returns: | |
| 42 all RTP packet events from the event stream as a list of DataPoints | |
| 43 """ | |
| 44 event_stream = rtc_pb.EventStream() | |
| 45 with open(file_path, "rb") as f: | |
| 46 event_stream.ParseFromString(f.read()) | |
| 47 | |
| 48 return [DataPoint(event.rtp_packet.header, | |
| 49 event.rtp_packet.packet_length, | |
| 50 event.timestamp_us, event.rtp_packet.incoming) | |
| 51 for event in event_stream.stream | |
| 52 if event.HasField("rtp_packet")] | |
| OLD | NEW |