Chromium Code Reviews| 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 | |
| 12 from __future__ import division | |
| 13 | |
| 14 import os | |
| 15 import struct | |
| 16 import sys | |
| 17 | |
| 18 | |
| 19 # makes sure to import correct protobuf | |
| 20 webrtc_root = "../../" | |
| 21 sys.path.append(os.path.join(webrtc_root, "out/Debug/pyproto/webrtc/call/")) | |
| 22 sys.path.append(os.path.join(webrtc_root, "out/Release/pyproto/webrtc/call/")) | |
| 23 sys.path.append(os.path.join(webrtc_root, "third_party/protobuf/python/")) | |
| 24 import rtc_event_log_pb2 as rtc_pb | |
| 25 | |
| 26 | |
| 27 class DataPoint(object): | |
| 28 """Simple container class for RTP events. | |
| 29 """ | |
| 30 | |
| 31 def __init__(self, rtp_header_str, packet_size, | |
| 32 arrival_timestamp_us): | |
| 33 """Builds a data point by parsing an RTP header. | |
| 34 | |
| 35 As defined in RFC 3550 section 5.1. | |
|
hlundin-webrtc
2016/05/25 12:54:23
Technically, the arrival timestamp is not part of
aleloi2
2016/05/30 14:57:55
Updated a little.
| |
| 36 """ | |
| 37 self.size = packet_size | |
| 38 self.arrival_timestamp_ms = arrival_timestamp_us / 1000 | |
| 39 unpacked = struct.unpack_from("!HHII", rtp_header_str, 0) | |
| 40 (first2header_bytes, self.sequence_number, | |
| 41 self.timestamp, self.ssrc | |
| 42 ) = unpacked | |
|
kwiberg-webrtc
2016/05/25 12:42:41
Eliminate "unpacked"?
(first2header_bytes, self.s
aleloi2
2016/05/30 14:57:55
Done.
| |
| 43 self.payload_type = first2header_bytes & 0b01111111 | |
| 44 | |
| 45 | |
| 46 def parse_protobuf(file_path): | |
| 47 """Parses rtc event log from protobuf file. | |
|
peah-webrtc
2016/05/26 06:44:18
I think the abbreviation rtc should be capitalized
aleloi2
2016/05/30 14:57:55
Done.
| |
| 48 | |
| 49 Args: | |
| 50 file_path: path to protobuf file of RTC event stream | |
| 51 | |
| 52 Returns: | |
| 53 all RtpPacket events from the event stream as a list of DataPoints | |
|
peah-webrtc
2016/05/26 06:44:18
Rtp should be capitalized according to how it is c
aleloi2
2016/05/30 14:57:55
Done.
| |
| 54 """ | |
| 55 event_stream = rtc_pb.EventStream() | |
| 56 with open(file_path, "rb") as f: | |
| 57 event_stream.ParseFromString(f.read()) | |
| 58 | |
| 59 return [DataPoint(event.rtp_packet.header, | |
| 60 event.rtp_packet.packet_length, | |
| 61 event.timestamp_us) | |
| 62 for event in event_stream.stream | |
| 63 if event.HasField("rtp_packet")] | |
| OLD | NEW |