diff --git a/python/README.md b/python/README.md index 213014246..0c378a5a3 100644 --- a/python/README.md +++ b/python/README.md @@ -86,17 +86,15 @@ sudo pip3 install av Execute the `st20p_rx.py` to receive a ST2110 ST_FRAME_FMT_YUV422RFC4175PG2BE10 stream and display it. ```bash -# Customize the port, IP and display option in the code before using -python3 python/example/st20p_rx.py +python3 python/example/st20p_rx.py --p_port 0000:ac:01.1 --p_sip 192.168.108.102 --p_rx_ip 239.168.85.20 ``` ### 3.2 st20p_tx.py -Run the `st20p_tx.py`, which reads YUV video data from a file and transmits it over the network as a ST2110 ST_FRAME_FMT_YUV422RFC4175PG2BE10 stream. +Run the `st20p_tx.py`, which reads YUV video data from a file(default: yuv422p10le_1080p.yuv) and transmits it over the network as a ST2110 ST_FRAME_FMT_YUV422RFC4175PG2BE10 stream. ```bash -# Customize the port, IP and display option in the code before using -python3 python/example/st20p_tx.py +python3 python/example/st20p_tx.py --p_port 0000:ac:01.0 --p_sip 192.168.108.101 --p_tx_ip 239.168.85.20 ``` ### 3.3 st20p_rx_encode.py @@ -104,8 +102,7 @@ python3 python/example/st20p_tx.py Run the `st20p_rx_encode.py` to receive a ST2110 ST_FRAME_FMT_YUV422RFC4175PG2BE10 stream and encode it to a `.mp4` encoder file. ```bash -# Customize the port, IP and display option in the code before using -python3 python/example/st20p_rx_encode.py +python3 python/example/st20p_rx_encode.py --p_port 0000:ac:01.1 --p_sip 192.168.108.102 --p_rx_ip 239.168.85.20 ``` ### 3.4 st20p_tx_decode.py @@ -113,6 +110,5 @@ python3 python/example/st20p_rx_encode.py Use `st20p_tx_decode.py` to decode YUV video from an encoded file `jellyfish-3-mbps-hd-hevc-10bit.mkv` and transmit it as a ST2110 ST_FRAME_FMT_YUV422RFC4175PG2BE10 stream across the network. ```bash -# Customize the port, IP and display option in the code before using -python3 python/example/st20p_tx_decode.py +python3 python/example/st20p_tx_decode.py --p_port 0000:ac:01.0 --p_sip 192.168.108.101 --p_tx_ip 239.168.85.20 ``` diff --git a/python/example/arg_util.py b/python/example/arg_util.py new file mode 100644 index 000000000..20498b2d6 --- /dev/null +++ b/python/example/arg_util.py @@ -0,0 +1,38 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2023 Intel Corporation +# argparse utils + +import argparse + + +def parse_args(is_tx): + parser = argparse.ArgumentParser(description="Argument util for MTL example") + if is_tx: + p_port_default = "0000:af:01.1" + else: + p_port_default = "0000:af:01.0" + parser.add_argument( + "--p_port", type=str, default=p_port_default, help="primary port name" + ) + if is_tx: + p_sip_default = "192.168.108.101" + else: + p_sip_default = "192.168.108.102" + parser.add_argument( + "--p_sip", type=str, default=p_sip_default, help="primary local IP address" + ) + # p_tx_ip + parser.add_argument( + "--p_tx_ip", + type=str, + default="239.168.85.20", + help="primary TX dest IP address", + ) + # p_rx_ip + parser.add_argument( + "--p_rx_ip", + type=str, + default="239.168.85.20", + help="primary RX source IP address", + ) + return parser.parse_args() diff --git a/python/example/st20p_rx.py b/python/example/st20p_rx.py index f66b8a200..3a0a74ad4 100644 --- a/python/example/st20p_rx.py +++ b/python/example/st20p_rx.py @@ -3,6 +3,7 @@ import sys +import arg_util import cv2_util import pymtl as mtl @@ -65,11 +66,13 @@ def main(): output_fmt = mtl.ST_FRAME_FMT_YUV422PLANAR8 interlaced = False + args = arg_util.parse_args(True) + # Init para init_para = mtl.mtl_init_params() - mtl.mtl_para_port_set(init_para, mtl.MTL_PORT_P, "0000:af:01.0") + mtl.mtl_para_port_set(init_para, mtl.MTL_PORT_P, args.p_port) init_para.num_ports = 1 - mtl.mtl_para_sip_set(init_para, mtl.MTL_PORT_P, "192.168.108.102") + mtl.mtl_para_sip_set(init_para, mtl.MTL_PORT_P, args.p_sip) init_para.flags = mtl.MTL_FLAG_BIND_NUMA | mtl.MTL_FLAG_DEV_AUTO_START_STOP mtl.mtl_para_tx_queues_cnt_set(init_para, mtl.MTL_PORT_P, 0) mtl.mtl_para_rx_queues_cnt_set(init_para, mtl.MTL_PORT_P, 1) @@ -98,7 +101,7 @@ def main(): mtl.mtl_para_port_get(init_para, mtl.MTL_SESSION_PORT_P), ) rx_port.num_port = 1 - mtl.st_rxp_para_sip_set(rx_port, mtl.MTL_SESSION_PORT_P, "239.168.85.20") + mtl.st_rxp_para_sip_set(rx_port, mtl.MTL_SESSION_PORT_P, args.p_rx_ip) mtl.st_rxp_para_udp_port_set(rx_port, mtl.MTL_SESSION_PORT_P, 20000) rx_port.payload_type = 112 rx_para.port = rx_port diff --git a/python/example/st20p_rx_encode.py b/python/example/st20p_rx_encode.py index 062744f06..7026a182c 100644 --- a/python/example/st20p_rx_encode.py +++ b/python/example/st20p_rx_encode.py @@ -5,6 +5,7 @@ import sys from datetime import datetime +import arg_util import av import numpy as np import pymtl as mtl @@ -19,11 +20,13 @@ def main(): current_datetime = datetime.now() output_file = current_datetime.strftime("%Y_%m_%d_%H_%M_%S") + "_output.mp4" + args = arg_util.parse_args(True) + # Init para init_para = mtl.mtl_init_params() - mtl.mtl_para_port_set(init_para, mtl.MTL_PORT_P, "0000:af:01.0") + mtl.mtl_para_port_set(init_para, mtl.MTL_PORT_P, args.p_port) init_para.num_ports = 1 - mtl.mtl_para_sip_set(init_para, mtl.MTL_PORT_P, "192.168.108.102") + mtl.mtl_para_sip_set(init_para, mtl.MTL_PORT_P, args.p_sip) init_para.flags = mtl.MTL_FLAG_BIND_NUMA | mtl.MTL_FLAG_DEV_AUTO_START_STOP mtl.mtl_para_tx_queues_cnt_set(init_para, mtl.MTL_PORT_P, 0) mtl.mtl_para_rx_queues_cnt_set(init_para, mtl.MTL_PORT_P, 1) @@ -51,7 +54,7 @@ def main(): mtl.mtl_para_port_get(init_para, mtl.MTL_SESSION_PORT_P), ) rx_port.num_port = 1 - mtl.st_rxp_para_sip_set(rx_port, mtl.MTL_SESSION_PORT_P, "239.168.85.20") + mtl.st_rxp_para_sip_set(rx_port, mtl.MTL_SESSION_PORT_P, args.p_rx_ip) mtl.st_rxp_para_udp_port_set(rx_port, mtl.MTL_SESSION_PORT_P, 20000) rx_port.payload_type = 112 rx_para.port = rx_port diff --git a/python/example/st20p_tx.py b/python/example/st20p_tx.py index c138ca5e5..a59304606 100644 --- a/python/example/st20p_tx.py +++ b/python/example/st20p_tx.py @@ -4,6 +4,7 @@ import ctypes import sys +import arg_util import cv2_util import pymtl as mtl @@ -25,11 +26,13 @@ def main(): print(f"Open {yuv_file_path} fail") sys.exit(1) + args = arg_util.parse_args(True) + # Init para init_para = mtl.mtl_init_params() - mtl.mtl_para_port_set(init_para, mtl.MTL_PORT_P, "0000:af:01.1") + mtl.mtl_para_port_set(init_para, mtl.MTL_PORT_P, args.p_port) init_para.num_ports = 1 - mtl.mtl_para_sip_set(init_para, mtl.MTL_PORT_P, "192.168.108.101") + mtl.mtl_para_sip_set(init_para, mtl.MTL_PORT_P, args.p_sip) init_para.flags = ( mtl.MTL_FLAG_BIND_NUMA | mtl.MTL_FLAG_DEV_AUTO_START_STOP @@ -62,7 +65,7 @@ def main(): mtl.mtl_para_port_get(init_para, mtl.MTL_SESSION_PORT_P), ) tx_port.num_port = 1 - mtl.st_txp_para_dip_set(tx_port, mtl.MTL_SESSION_PORT_P, "239.168.85.20") + mtl.st_txp_para_dip_set(tx_port, mtl.MTL_SESSION_PORT_P, args.p_tx_ip) mtl.st_txp_para_udp_port_set(tx_port, mtl.MTL_SESSION_PORT_P, 20000) tx_port.payload_type = 112 tx_para.port = tx_port diff --git a/python/example/st20p_tx_decode.py b/python/example/st20p_tx_decode.py index a733801dc..6cadcf74a 100644 --- a/python/example/st20p_tx_decode.py +++ b/python/example/st20p_tx_decode.py @@ -4,6 +4,7 @@ import ctypes import sys +import arg_util import av import numpy as np import pymtl as mtl @@ -58,11 +59,13 @@ def main(): mtl_input_fmt = mtl.ST_FRAME_FMT_YUV422PLANAR10LE av_pixel_output_format = "yuv422p10le" + args = arg_util.parse_args(True) + # Init para init_para = mtl.mtl_init_params() - mtl.mtl_para_port_set(init_para, mtl.MTL_PORT_P, "0000:af:01.1") + mtl.mtl_para_port_set(init_para, mtl.MTL_PORT_P, args.p_port) init_para.num_ports = 1 - mtl.mtl_para_sip_set(init_para, mtl.MTL_PORT_P, "192.168.108.101") + mtl.mtl_para_sip_set(init_para, mtl.MTL_PORT_P, args.p_sip) init_para.flags = ( mtl.MTL_FLAG_BIND_NUMA | mtl.MTL_FLAG_DEV_AUTO_START_STOP @@ -94,7 +97,7 @@ def main(): mtl.mtl_para_port_get(init_para, mtl.MTL_SESSION_PORT_P), ) tx_port.num_port = 1 - mtl.st_txp_para_dip_set(tx_port, mtl.MTL_SESSION_PORT_P, "239.168.85.20") + mtl.st_txp_para_dip_set(tx_port, mtl.MTL_SESSION_PORT_P, args.p_tx_ip) mtl.st_txp_para_udp_port_set(tx_port, mtl.MTL_SESSION_PORT_P, 20000) tx_port.payload_type = 112 tx_para.port = tx_port