Skip to content

Commit

Permalink
added new test data scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
carTloyal123 committed Jul 11, 2024
1 parent 7edb179 commit d8702cb
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 378 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ google-services.json
# Docker details
emulator/
.venv/
tools/testing/*.txt
tools/testing/*.log
tools/testing/*.bin
87 changes: 87 additions & 0 deletions tools/testing/deffcode_h264.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import os
import cv2
import asyncio
import websockets
import numpy as np
import json
import deffcode

# WebSocket URL
websocket_url = "ws://localhost:3030"

# OpenCV window name
window_name = "Decoded Frames"

# Named pipe for H264 data
h264_pipe = "local_pipe.h264"

# Function to handle WebSocket messages
async def on_message(message):
# Write H264 data to the pipe
with open(h264_pipe, 'ab+') as f:
f.write(message)

print("Decoding H264 data!")
try:
# initialize and formulate the decoder for GRAYSCALE output
decoder = deffcode.FFdecoder(h264_pipe, source_demuxer="yuv4mpegpipe", frame_format="yuv420p", verbose=True).formulate()

print("Generating frames!")
# grab the GRAYSCALE frames from the decoder
for gray in decoder.generateFrame():

# check if frame is None
if gray is None:
break

# {do something with the gray frame here}

# Show output window
cv2.imshow("Gray Output", gray)

# check for 'q' key if pressed
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
break
except Exception as e:
print("Error decoding frame: " + str(e))
return

# Function to decode H264 data into frames
def decode_h264():
cap = cv2.VideoCapture(h264_pipe)

ret, frame = cap.read()

if not ret:
print("Error reading frame from pipe")
return None

return frame

# Function to start a WebSocket connection
async def start_websocket():
ffmpeg_path = deffcode.ffhelper.get_valid_ffmpeg_path(is_windows=True)
if ffmpeg_path == False:
print("FFmpeg not found in the system!")
return
print("FFmpeg path: " + ffmpeg_path)
supported_demuxers = deffcode.ffhelper.get_supported_demuxers(ffmpeg_path)
print("Supported demuxers: " + str(supported_demuxers))
async with websockets.connect(websocket_url) as ws:
# Subscribe to the video stream
await ws.send(json.dumps({"type": "Subscribe", "topic": "video-stream"}))

async for message in ws:
print("Received message of length " + str(len(message)))
if isinstance(message, bytes):
# Handle H264 data
print("Handling binary message!")
await on_message(message)
else:
# Handle control messages
data = json.loads(message)
print(data["message"])

# Start the WebSocket connection
asyncio.get_event_loop().run_until_complete(start_websocket())
17 changes: 10 additions & 7 deletions tools/testing/device_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@
# p2pUrl = '|wyze-test-list.cloudlinks.cn|42.194.219.201'
# wyzeP2pUrl = '|wyze-mars-asrv.wyzecam.com'
# mars_url = 'https://wyze-mars-service.wyzecam.com/plugin/mars/v2/regist_gw_user/GW_BE1_7C78B2A2AD34'
# mars_path_url = '/plugin/mars/v2/regist_gw_user/GW_BE1_7C78B2A2AD34'
mars_path_url = '/plugin/mars/v2/regist_gw_user/GW_BE1_7C78B2A2AD34'

wyze_sdk.set_file_logger('wyze_sdk', filepath='wyze_out.txt', level=wyze_sdk.logging.DEBUG)
mars_base_url = 'https://wyze-mars-service.wyzecam.com'
email = '[email protected]'
psswd = '@Lacylulu123!!!'
key_id = '94458b0d-2e6a-4e9e-b438-5914f735461b'
api_key='4yWuIM9jaSRvDQJ9aIEwqlNYSe0GHDx0LJvudthmiiy1Ju3OAHiMvmiZmBju'
psswd = 'YSHR*U*GVgn$*@u*@eT7EQ9e9r4w@bc5jGKdui&*^U84DW2o&Hcpitz@k$^F'
key_id = '8b47866c-fbf4-4cd4-894f-694836da9887'
api_key='AGzyRnvy4ysoicTwOlJxxNJgq9toGXEZaJDfor8k5rSvnGdUJjvkyncKV03r'
deviceId = "GW_BE1_7C78B2A2AD34"


last_token_fetch_time = 0
current_response = None

Expand All @@ -38,9 +37,12 @@ async def getLoginInfo():
email=email,
password=psswd,
key_id=key_id,
api_key=api_key
api_key=api_key,
totp_key='734700'
)

print(response.data)

wpk = WpkNetServiceClient(token=client._token, base_url=mars_base_url)
nonce = wpk.request_verifier.clock.nonce()
json_dict = {"ttl_minutes" : 10080, 'nonce' : str(nonce), 'unique_id' : wpk.phone_id }
Expand All @@ -55,6 +57,7 @@ async def getLoginInfo():
except requests.HTTPError as e:
print(f'HTTP Request Error')
print(e.response)
print(str(e))
except wyze_sdk.errors.WyzeApiError as e:
print(f'Wyze API Error:')
print(e.response)
Expand Down Expand Up @@ -109,7 +112,7 @@ async def websocket_client():
try:
async with websockets.connect(uri, ping_timeout=None) as websocket: # disable the library's automatic pinging
websocket.ping_interval = None # disable the library's automatic pinging
keyboard.on_press_key('right option', spacebar_event)
keyboard.on_press_key('backslash', spacebar_event)
await subscribeToLoginInfo(websocket)
while True:
try:
Expand Down
61 changes: 61 additions & 0 deletions tools/testing/ffmpeg_decode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import os
import cv2
import asyncio
import websockets
import numpy as np
import json
import subprocess

# WebSocket URL
websocket_url = "ws://localhost:3030"

# OpenCV window name
window_name = "Decoded Frames"

# Named pipe for H264 data
h264_pipe = "local_pipe"

# Function to handle WebSocket messages
async def on_message(message):
# Write H264 data to the pipe
with open(h264_pipe, 'ab+') as f:
print("writing to pipe")
f.write(message)

# process.stdin.write(message)
# print("waiting for frame to return")
# ret, decoded_frame = process.stdout.read()
# if decoded_frame is not None:
# cv2.imshow('Video', decoded_frame)
# if cv2.waitKey(1) & 0xFF == ord('q'):
# return

# Function to start a WebSocket connection
async def start_websocket():
async with websockets.connect(websocket_url) as ws:
# Subscribe to the video stream
await ws.send(json.dumps({"type": "Subscribe", "topic": "video-stream"}))

async for message in ws:
print("Received message of length " + str(len(message)))
if isinstance(message, bytes):
# Handle H264 data
await on_message(message)
else:
# Handle control messages
data = json.loads(message)
print(data["message"])

# Start the WebSocket connection
# Set up the ffmpeg command with GPU acceleration
ffmpeg_command = [
'C:\\ffmpeg\\bin\\ffmpeg.exe',
'-i', 'pipe:0',
'-f', 'rawvideo',
'-pix_fmt', 'yuv420p',
'pipe:1'
]

# Open the ffmpeg process
process = subprocess.Popen(ffmpeg_command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
asyncio.get_event_loop().run_until_complete(start_websocket())
Binary file removed tools/testing/local_pipe
Binary file not shown.
51 changes: 0 additions & 51 deletions tools/testing/video_client.py

This file was deleted.

47 changes: 0 additions & 47 deletions tools/testing/video_client_full_yuv.py

This file was deleted.

63 changes: 0 additions & 63 deletions tools/testing/video_client_v2.py

This file was deleted.

Loading

0 comments on commit d8702cb

Please sign in to comment.