 Chromium Code Reviews
 Chromium Code Reviews Issue 1999113002:
  New rtc dump analyzing tool in Python  (Closed) 
  Base URL: https://chromium.googlesource.com/external/webrtc.git@master
    
  
    Issue 1999113002:
  New rtc dump analyzing tool in Python  (Closed) 
  Base URL: https://chromium.googlesource.com/external/webrtc.git@master| 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 import enum | |
| 18 | |
| 19 | |
| 20 # makes sure to import correct protobuf | |
| 21 webrtc_root = "../../" | |
| 22 sys.path.append(os.path.join(webrtc_root, "out/Debug/pyproto/webrtc/call/")) | |
| 23 sys.path.append(os.path.join(webrtc_root, "out/Release/pyproto/webrtc/call/")) | |
| 24 sys.path.append(os.path.join(webrtc_root, "third_party/protobuf/python/")) | |
| 
kwiberg-webrtc
2016/05/24 12:09:51
sys.path += [os.path.join(webrtc_root, path) for p
 
aleloi
2016/05/24 15:54:41
The point is to make it import the correct generat
 
kwiberg-webrtc
2016/05/25 12:42:41
Sorry, I didn't mean to ask why you did this; I ju
 
aleloi2
2016/05/30 14:57:55
Thank you! This is better. Ignore the latest comme
 | |
| 25 import rtc_event_log_pb2 as rtc_pb | |
| 26 | |
| 27 | |
| 28 DIR = enum.Enum("Direction", "incoming outgoing") | |
| 
ivoc
2016/05/24 11:50:18
I would prefer a less fancy solution that does not
 
kwiberg-webrtc
2016/05/24 12:09:51
Why is this in all caps?
 
aleloi
2016/05/24 15:54:40
Got convinced by Ivo and removed. Directions are n
 | |
| 29 | |
| 30 | |
| 31 class DataPoint(object): | |
| 32 """Simple container class for RTP events. | |
| 33 """ | |
| 34 | |
| 35 def __init__(self, rtp_header_str, packet_size, | |
| 36 arrival_timestamp_us, direction): | |
| 37 """Builds a data point by parsing an RTP header. | |
| 38 | |
| 39 As defined in RFC 3550 section 5.1. | |
| 40 """ | |
| 41 self.size = packet_size | |
| 42 self.arrival_timestamp_ms = arrival_timestamp_us / 1000 | |
| 43 unpacked = struct.unpack_from("!HHII", rtp_header_str, 0) | |
| 44 first2header_bytes, self.seq_no, self.timestamp, self.ssrc = unpacked | |
| 
ivoc
2016/05/24 11:50:18
The temporary 'unpacked' variable can be removed h
 
kwiberg-webrtc
2016/05/24 12:09:51
I find it's good for readability to surround tuple
 
aleloi
2016/05/24 15:54:40
Acknowledged.
 | |
| 45 | |
| 46 def bit_unpack(bit_offsets, number): | |
| 47 """unpacks a big-endian number into blocks of bits.""" | |
| 
kwiberg-webrtc
2016/05/24 12:09:51
This doesn't sound right. Python integers are alwa
 
aleloi
2016/05/24 15:54:40
Yes, thank you. Anyway, I removed it completely by
 | |
| 48 res = [] | |
| 49 for offset in reversed(bit_offsets): | |
| 50 mask = ((1<<offset) - 1) | |
| 51 res.append(number & mask) | |
| 52 number >>= offset | |
| 53 return reversed(res) | |
| 54 | |
| 55 # fields V, P, X, CC, and M of the header are ignored | |
| 56 _, _, _, _, _, self.pt = bit_unpack([2, 1, 1, 4, 1, 7], first2header_bytes) | |
| 
ivoc
2016/05/24 11:50:18
I think something like this would be simpler (I di
 
kwiberg-webrtc
2016/05/24 12:09:51
It's probably much easier to just shift and mask m
 
aleloi
2016/05/24 15:54:40
Thank you! Changed to "& 0b01111111". I think it's
 | |
| 57 self.direction = direction | |
| 
ivoc
2016/05/24 11:50:18
Move to line 42 please.
 
aleloi
2016/05/24 15:54:40
completely removed because not used.
 | |
| 58 | |
| 59 | |
| 60 def parse_protobuf(file_path): | |
| 61 """Parses rtc event log from protobuf file. | |
| 62 | |
| 63 Args: | |
| 64 file_path: path to protobuf file of RTC event stream | |
| 65 | |
| 66 Returns: | |
| 67 all RtpPacket events from the event stream as a list of DataPoint:s | |
| 
ivoc
2016/05/24 11:50:18
Remove the : please.
 
aleloi
2016/05/24 15:54:40
Done.
 | |
| 68 """ | |
| 69 event_stream = rtc_pb.EventStream() | |
| 70 with open(file_path, "rb") as f: | |
| 71 event_stream.ParseFromString(f.read()) | |
| 72 result = [] | |
| 73 | |
| 74 for event in event_stream.stream: | |
| 75 if event.HasField("rtp_packet"): | |
| 76 rtp_packet = event.rtp_packet | |
| 77 header = rtp_packet.header | |
| 78 direction = DIR.incoming if rtp_packet.incoming else DIR.outgoing | |
| 79 result.append(DataPoint(header, rtp_packet.packet_length, | |
| 80 event.timestamp_us, | |
| 81 direction)) | |
| 
kwiberg-webrtc
2016/05/24 12:09:51
Consider using a comprehension:
  return [DataPoi
 
aleloi
2016/05/24 15:54:40
Thank you, that's nicer!
 | |
| 82 | |
| 83 return result | |
| OLD | NEW |