Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python/example: add args to customize p_port, p_sip, p_tx_ip/p_rx_ip #679

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,33 +86,29 @@ 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

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

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
```
38 changes: 38 additions & 0 deletions python/example/arg_util.py
Original file line number Diff line number Diff line change
@@ -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()
9 changes: 6 additions & 3 deletions python/example/st20p_rx.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import sys

import arg_util
import cv2_util
import pymtl as mtl

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions python/example/st20p_rx_encode.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys
from datetime import datetime

import arg_util
import av
import numpy as np
import pymtl as mtl
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions python/example/st20p_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ctypes
import sys

import arg_util
import cv2_util
import pymtl as mtl

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions python/example/st20p_tx_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ctypes
import sys

import arg_util
import av
import numpy as np
import pymtl as mtl
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down