mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00
Migrate some scripts to python3
python-modernize, format and some manual lint fixes No-Try: True Bug: None Change-Id: I89d9f97f238be887962c67e18cc6480a8f6f3ac4 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/264551 Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#37071}
This commit is contained in:
parent
563dfd1948
commit
83e34eed87
4 changed files with 336 additions and 346 deletions
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
|
||||
#
|
||||
# Use of this source code is governed by a BSD-style license
|
||||
|
@ -7,6 +7,7 @@
|
|||
# in the file PATENTS. All contributing project authors may
|
||||
# be found in the AUTHORS file in the root of the source tree.
|
||||
|
||||
from __future__ import absolute_import
|
||||
import os
|
||||
import unittest
|
||||
import sys
|
||||
|
@ -20,9 +21,8 @@ import low_bandwidth_audio_test
|
|||
class TestExtractTestRuns(unittest.TestCase):
|
||||
def _TestLog(self, log, *expected):
|
||||
self.assertEqual(
|
||||
tuple(
|
||||
low_bandwidth_audio_test.ExtractTestRuns(
|
||||
log.splitlines(True))), expected)
|
||||
tuple(low_bandwidth_audio_test.ExtractTestRuns(log.splitlines(True))),
|
||||
expected)
|
||||
|
||||
def testLinux(self):
|
||||
self._TestLog(
|
||||
|
@ -43,22 +43,20 @@ class TestExtractTestRuns(unittest.TestCase):
|
|||
'/webrtc/src/out/PCLowBandwidth_perf_48.json'))
|
||||
|
||||
def testAndroid(self):
|
||||
self._TestLog(ANDROID_LOG, (
|
||||
'ddfa6149', 'Mobile2GNetwork',
|
||||
self._TestLog(
|
||||
ANDROID_LOG,
|
||||
('ddfa6149', 'Mobile2GNetwork',
|
||||
'/sdcard/chromium_tests_root/resources/voice_engine/audio_tiny16.wav',
|
||||
'/sdcard/chromium_tests_root/LowBandwidth_Mobile2GNetwork.wav',
|
||||
None
|
||||
), (
|
||||
'TA99205CNO', 'GoodNetworkHighBitrate',
|
||||
'/sdcard/chromium_tests_root/LowBandwidth_Mobile2GNetwork.wav', None),
|
||||
('TA99205CNO', 'GoodNetworkHighBitrate',
|
||||
'/sdcard/chromium_tests_root/resources/voice_engine/audio_tiny16.wav',
|
||||
'/sdcard/chromium_tests_root/LowBandwidth_GoodNetworkHighBitrate.wav',
|
||||
None
|
||||
), (
|
||||
'ddfa6149', 'PCMobile2GNetwork',
|
||||
None),
|
||||
('ddfa6149', 'PCMobile2GNetwork',
|
||||
'/sdcard/chromium_tests_root/resources/voice_engine/audio_tiny16.wav',
|
||||
'/sdcard/chromium_tests_root/PCLowBandwidth_PCMobile2GNetwork.wav',
|
||||
'/sdcard/chromium_tests_root/PCLowBandwidth_perf_48.json'
|
||||
), ('TA99205CNO', 'PCGoodNetworkHighBitrate',
|
||||
'/sdcard/chromium_tests_root/PCLowBandwidth_perf_48.json'),
|
||||
('TA99205CNO', 'PCGoodNetworkHighBitrate',
|
||||
'/sdcard/chromium_tests_root/resources/voice_engine/audio_tiny16.wav',
|
||||
('/sdcard/chromium_tests_root/'
|
||||
'PCLowBandwidth_PCGoodNetworkHighBitrate.wav'),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
|
||||
#
|
||||
# Use of this source code is governed by a BSD-style license
|
||||
|
@ -14,12 +14,14 @@ or
|
|||
"""
|
||||
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
import random
|
||||
import unittest
|
||||
from six.moves import range
|
||||
from six.moves import zip
|
||||
|
||||
import misc
|
||||
|
||||
|
||||
class TestMisc(unittest.TestCase):
|
||||
def testUnwrapMod3(self):
|
||||
data = [0, 1, 2, 0, -1, -2, -3, -4]
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
|
||||
#
|
||||
# Use of this source code is governed by a BSD-style license
|
||||
|
@ -10,10 +11,13 @@
|
|||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
from __future__ import absolute_import
|
||||
import collections
|
||||
import optparse
|
||||
import os
|
||||
import sys
|
||||
from six.moves import range
|
||||
from six.moves import zip
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy
|
||||
|
@ -22,7 +26,7 @@ import misc
|
|||
import pb_parse
|
||||
|
||||
|
||||
class RTPStatistics(object):
|
||||
class RTPStatistics:
|
||||
"""Has methods for calculating and plotting RTP stream statistics."""
|
||||
|
||||
BANDWIDTH_SMOOTHING_WINDOW_SIZE = 10
|
||||
|
@ -53,9 +57,8 @@ class RTPStatistics(object):
|
|||
for point in self.data_points:
|
||||
print("{:>6}{:>14}{:>14}{:>6}{:>6}{:>3}{:>11}".format(
|
||||
point.sequence_number, point.timestamp,
|
||||
int(point.arrival_timestamp_ms), point.size,
|
||||
point.payload_type, point.marker_bit,
|
||||
"0x{:x}".format(point.ssrc)))
|
||||
int(point.arrival_timestamp_ms), point.size, point.payload_type,
|
||||
point.marker_bit, "0x{:x}".format(point.ssrc)))
|
||||
|
||||
def PrintSsrcInfo(self, ssrc_id, ssrc):
|
||||
"""Prints packet and size statistics for a given SSRC.
|
||||
|
@ -64,12 +67,9 @@ class RTPStatistics(object):
|
|||
ssrc_id: textual identifier of SSRC printed beside statistics for it.
|
||||
ssrc: SSRC by which to filter data and display statistics
|
||||
"""
|
||||
filtered_ssrc = [
|
||||
point for point in self.data_points if point.ssrc == ssrc
|
||||
]
|
||||
filtered_ssrc = [point for point in self.data_points if point.ssrc == ssrc]
|
||||
payloads = misc.NormalizeCounter(
|
||||
collections.Counter(
|
||||
[point.payload_type for point in filtered_ssrc]))
|
||||
collections.Counter([point.payload_type for point in filtered_ssrc]))
|
||||
|
||||
payload_info = "payload type(s): {}".format(", ".join(
|
||||
str(payload) for payload in payloads))
|
||||
|
@ -83,8 +83,7 @@ class RTPStatistics(object):
|
|||
density=False)
|
||||
bin_proportions = bin_counts / sum(bin_counts)
|
||||
print("\n".join([
|
||||
" {:.1f} - {:.1f}: {:.2f}%".format(bin_bounds[i],
|
||||
bin_bounds[i + 1],
|
||||
" {:.1f} - {:.1f}: {:.2f}%".format(bin_bounds[i], bin_bounds[i + 1],
|
||||
bin_proportions[i] * 100)
|
||||
for i in range(len(bin_proportions))
|
||||
]))
|
||||
|
@ -93,17 +92,13 @@ class RTPStatistics(object):
|
|||
"""Queries user for SSRC."""
|
||||
|
||||
if len(self.ssrc_frequencies) == 1:
|
||||
chosen_ssrc = self.ssrc_frequencies.keys()[0]
|
||||
chosen_ssrc = list(self.ssrc_frequencies.keys())[0]
|
||||
self.PrintSsrcInfo("", chosen_ssrc)
|
||||
return chosen_ssrc
|
||||
|
||||
ssrc_is_incoming = misc.SsrcDirections(self.data_points)
|
||||
incoming = [
|
||||
ssrc for ssrc in ssrc_is_incoming if ssrc_is_incoming[ssrc]
|
||||
]
|
||||
outgoing = [
|
||||
ssrc for ssrc in ssrc_is_incoming if not ssrc_is_incoming[ssrc]
|
||||
]
|
||||
incoming = [ssrc for ssrc in ssrc_is_incoming if ssrc_is_incoming[ssrc]]
|
||||
outgoing = [ssrc for ssrc in ssrc_is_incoming if not ssrc_is_incoming[ssrc]]
|
||||
|
||||
print("\nIncoming:\n")
|
||||
for (i, ssrc) in enumerate(incoming):
|
||||
|
@ -117,7 +112,6 @@ class RTPStatistics(object):
|
|||
chosen_index = int(misc.get_input("choose one> "))
|
||||
if 0 <= chosen_index < len(self.ssrc_frequencies):
|
||||
return (incoming + outgoing)[chosen_index]
|
||||
else:
|
||||
print("Invalid index!")
|
||||
|
||||
def FilterSsrc(self, chosen_ssrc):
|
||||
|
@ -138,8 +132,7 @@ class RTPStatistics(object):
|
|||
unwrapped_timestamps = misc.Unwrap(
|
||||
[point.timestamp for point in self.data_points], 2**32 - 1)
|
||||
|
||||
for (data_point, timestamp) in zip(self.data_points,
|
||||
unwrapped_timestamps):
|
||||
for (data_point, timestamp) in zip(self.data_points, unwrapped_timestamps):
|
||||
data_point.timestamp = timestamp
|
||||
|
||||
def PrintSequenceNumberStatistics(self):
|
||||
|
@ -165,8 +158,7 @@ class RTPStatistics(object):
|
|||
"""
|
||||
delta_timestamp = (self.data_points[-1].timestamp -
|
||||
self.data_points[0].timestamp)
|
||||
delta_arr_timestamp = float(
|
||||
(self.data_points[-1].arrival_timestamp_ms -
|
||||
delta_arr_timestamp = float((self.data_points[-1].arrival_timestamp_ms -
|
||||
self.data_points[0].arrival_timestamp_ms))
|
||||
freq_est = delta_timestamp / delta_arr_timestamp
|
||||
|
||||
|
@ -213,8 +205,8 @@ class RTPStatistics(object):
|
|||
100 * (stream_duration_receiver / stream_duration_sender - 1)))
|
||||
|
||||
total_size = sum(point.size for point in self.data_points) * 8 / 1000
|
||||
print("Send average bitrate: {:.2f} kbps".format(
|
||||
total_size / stream_duration_sender))
|
||||
print("Send average bitrate: {:.2f} kbps".format(total_size /
|
||||
stream_duration_sender))
|
||||
|
||||
print("Receive average bitrate: {:.2f} kbps".format(
|
||||
total_size / stream_duration_receiver))
|
||||
|
@ -240,8 +232,7 @@ class RTPStatistics(object):
|
|||
stop_ms = self.data_points[-1].real_send_time_ms
|
||||
(self.bandwidth_kbps, _) = numpy.histogram(
|
||||
[point.real_send_time_ms for point in self.data_points],
|
||||
bins=numpy.arange(start_ms, stop_ms,
|
||||
RTPStatistics.PLOT_RESOLUTION_MS),
|
||||
bins=numpy.arange(start_ms, stop_ms, RTPStatistics.PLOT_RESOLUTION_MS),
|
||||
weights=[
|
||||
point.size * 8 / RTPStatistics.PLOT_RESOLUTION_MS
|
||||
for point in self.data_points
|
||||
|
@ -249,8 +240,7 @@ class RTPStatistics(object):
|
|||
correlate_filter = (
|
||||
numpy.ones(RTPStatistics.BANDWIDTH_SMOOTHING_WINDOW_SIZE) /
|
||||
RTPStatistics.BANDWIDTH_SMOOTHING_WINDOW_SIZE)
|
||||
self.smooth_bw_kbps = numpy.correlate(self.bandwidth_kbps,
|
||||
correlate_filter)
|
||||
self.smooth_bw_kbps = numpy.correlate(self.bandwidth_kbps, correlate_filter)
|
||||
|
||||
def PlotStatistics(self):
|
||||
"""Plots changes in delay and average bandwidth."""
|
||||
|
@ -260,8 +250,7 @@ class RTPStatistics(object):
|
|||
time_axis = numpy.arange(start_ms / 1000, stop_ms / 1000,
|
||||
RTPStatistics.PLOT_RESOLUTION_MS / 1000)
|
||||
|
||||
delay = CalculateDelay(start_ms, stop_ms,
|
||||
RTPStatistics.PLOT_RESOLUTION_MS,
|
||||
delay = CalculateDelay(start_ms, stop_ms, RTPStatistics.PLOT_RESOLUTION_MS,
|
||||
self.data_points)
|
||||
|
||||
plt.figure(1)
|
||||
|
@ -300,8 +289,7 @@ def CalculateDelay(start, stop, step, points):
|
|||
def main():
|
||||
usage = "Usage: %prog [options] <filename of rtc event log>"
|
||||
parser = optparse.OptionParser(usage=usage)
|
||||
parser.add_option(
|
||||
"--dump_header_to_stdout",
|
||||
parser.add_option("--dump_header_to_stdout",
|
||||
default=False,
|
||||
action="store_true",
|
||||
help="print header info to stdout; similar to rtp_analyze")
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
|
||||
#
|
||||
# Use of this source code is governed by a BSD-style license
|
||||
|
@ -13,6 +13,8 @@ or
|
|||
python3 rtp_analyzer_test.py
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
import collections
|
||||
import unittest
|
||||
|
||||
|
@ -55,6 +57,6 @@ class TestDelay(unittest.TestCase):
|
|||
|
||||
if __name__ == "__main__":
|
||||
if MISSING_NUMPY:
|
||||
print "Missing numpy, skipping test."
|
||||
print("Missing numpy, skipping test.")
|
||||
else:
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in a new issue