Skip to content

Commit

Permalink
fake stream with video
Browse files Browse the repository at this point in the history
  • Loading branch information
XdoctorwhoZ committed Nov 24, 2023
1 parent 3b37a9b commit 0a8e58e
Show file tree
Hide file tree
Showing 6 changed files with 292 additions and 10 deletions.
12 changes: 7 additions & 5 deletions platform/panduza_platform/devices/panduza/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from .fake_dio_controller import DevicePanduzaFakeDioController
from .fake_bps.dev_fake_bps import DevicePanduzaFakeBps
from .fake_relay_controller import DevicePanduzaFakeRelayController
from .server.dev_server import DevicePanduzaServer
from .fake_dio_controller import DevicePanduzaFakeDioController
from .fake_bps.dev_fake_bps import DevicePanduzaFakeBps
from .fake_relay_controller import DevicePanduzaFakeRelayController
from .server.dev_server import DevicePanduzaServer
from .fake_webcam.dev_fake_webcam import DevicePanduzaFakeWebcam

PZA_DEVICES_LIST= [
DevicePanduzaFakeDioController,
DevicePanduzaFakeBps,
DevicePanduzaFakeRelayController,
DevicePanduzaServer
DevicePanduzaServer,
DevicePanduzaFakeWebcam
]

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from core.platform_device import PlatformDevice

from .itf_fake_video_stream import InterfacePanduzaFakeVideoStream

class DevicePanduzaFakeWebcam(PlatformDevice):
"""
"""

# ---

def _PZA_DEV_config(self):
"""
"""
return {
"family": "??",
"model": "FakeWebcam",
"manufacturer": "Panduza"
}

# ---

async def _PZA_DEV_mount_interfaces(self):
"""
"""

self.mount_interface(
InterfacePanduzaFakeVideoStream(name="stream")
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
import asyncio
import subprocess

from core.platform_driver import PlatformDriver

class InterfacePanduzaFakeVideoStream(PlatformDriver):
"""
"""

# ---

def _PZA_DRV_config(self):
"""From PlatformDriver
"""
return {
"info": {
"type": "video_stream",
"version": "0.0.0"
}
}

# ---

async def _PZA_DRV_loop_init(self):
"""From PlatformDriver
"""

# docker run -d -p 1935:1935 -p 8080:8080 alqutami/rtmp-hls:latest-alpine


# ffmpeg -re \
# \
# -i TearsOfSteel.mp4 \
# -c:v copy \
# -r 24 -g 24 \
# -preset superfast \
# -tune zerolatency \
# -f flv rtmp://127.0.0.1:1935/live/test


# test video
# ffmpeg -f lavfi -i testsrc=duration=120:size=1280x720:rate=30 testsrc.mp4

ffmpeg_command = [
'ffmpeg', '-re', '-stream_loop', '-1',
'-i', '/etc/panduza/data/video_test.mpg',
'-c:v' , 'copy',
'-r', '24', '-g', '24',
'-preset', 'superfast',
'-tune', 'zerolatency',
'-f', 'flv', 'rtmp://127.0.0.1:1935/live/test'
]

ffmpeg_cmd_string = ''
for part in ffmpeg_command:
ffmpeg_cmd_string += f"{part} "
self.log.info(ffmpeg_cmd_string)

self.process = subprocess.Popen(ffmpeg_command, stdout=None, stderr=None)

# # Continue executing your script while the FFmpeg command runs in the background
# print("Running FFmpeg command in the background...")

# # Check the process status to ensure it's finished
# while process.poll() is None:
# time.sleep(0.1)

# if process.returncode != 0:
# print("FFmpeg command failed with error code:", process.returncode)
# else:
# print("FFmpeg command completed successfully")



# self.hunting = False

# # Set command handlers
# self.__cmd_handlers = {
# "dtree": self.__handle_cmds_set_dtree,
# "devices": self.__handle_cmds_set_devices,
# }

# # Append a task to refresh platform data
# self.load_worker_task(self.__refresh_platform_data_task())


# # status
# # state => string
# # report => json

# await self._update_attribute("info", "dying_gasp", False)


# devices

# Tell the platform that the init state end sucessfuly
self._PZA_DRV_init_success()

# ---

# async def _PZA_DRV_cmds_set(self, payload):
# """From MetaDriver
# """
# cmds = self.payload_to_dict(payload)
# for att in self.__cmd_handlers:
# if att in cmds:
# await self.__cmd_handlers[att](cmds[att])

# # ---

# async def _PZA_DRV_dying_gasp(self):
# # [REQ_ITF_PLATFORM_0020_00] - Info 'dying_gasp' field
# await self._update_attribute("info", "dying_gasp", True)

# # ---

# async def __refresh_platform_data_task(self):
# """Refresh important data count
# """
# while self.alive:
# await asyncio.sleep(1)

# await self._update_attribute("info", "interfaces", self.platform.get_number_of_interfaces())

# await self._update_attributes_from_dict({
# "info": {
# "number_of_devices": self.platform.get_number_of_device(),
# }
# })

# await self._update_attributes_from_dict({
# "dtree": {
# "name": "tree.json",
# "saved": True,
# "list": [],
# "content": self.platform.dtree,
# }
# })

# await self._update_attributes_from_dict({
# "devices": {
# "hunting": False,
# "max": 0,
# "hunted": 0,
# "store": self.platform.device_factory.get_devices_store(),
# }
# })

# # ---

# async def __handle_cmds_set_dtree(self, cmd_att):
# """
# """
# update_obj = {}
# self.log.info(cmd_att)

# await self._prepare_update(update_obj,
# "dtree", cmd_att,
# "content", [dict]
# , self.__set_config_content
# , self.__get_config_content)

# # await self._prepare_update(update_obj,
# # "enable", cmd_att,
# # "polling_cycle", [float, int]
# # , self.__set_poll_cycle_enable
# # , self.__get_poll_cycle_enable)
# await self._update_attributes_from_dict(update_obj)

# # ---

# async def __set_config_content(self, value):
# self.log.info(value)
# await self.platform.load_config_content_task(value)

# # ---

# async def __get_config_content(self):
# return self.platform.dtree

# # ---

# async def __handle_cmds_set_devices(self, cmd_att):
# """
# """
# update_obj = {}
# self.log.info(cmd_att)

# await self._prepare_update(update_obj,
# "devices", cmd_att,
# "hunting", [bool]
# , self.__set_device_hunting
# , self.__get_device_hunting)

# # await self._prepare_update(update_obj,
# # "enable", cmd_att,
# # "polling_cycle", [float, int]
# # , self.__set_poll_cycle_enable
# # , self.__get_poll_cycle_enable)



# await self._update_attributes_from_dict(update_obj)

# # ---

# async def __set_device_hunting(self, value):
# self.log.info(value)

# if value == True:
# if self.hunting:
# pass
# # already hunting
# else:
# self.hunting = True
# self.platform.load_task(self.hunt_task())
# else:
# # stop hunting
# self.log.warning("stop huntin not implemented")

# # ---

# async def __get_device_hunting(self):
# return self.hunting

# # ---

# async def hunt_task(self):
# print("!!!!!!!!!!!!!! HUNT !!!!!!!!!!!!!!!")
# await self.platform.device_factory.hunt_start()
# while True:
# has_next = await self.platform.device_factory.hunt_next()
# if not has_next:
# break
# self.hunting = False
# await self._update_attribute("devices", "hunting", self.hunting)
# print(f"!!!!!!!!!!!!!! HUNT !!!!!!!!!!!!!!!")


Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ async def _PZA_DRV_loop_init(self):
# docker run -d -p 1935:1935 -p 8080:8080 alqutami/rtmp-hls:latest-alpine


# ffmpeg -re \
# -stream_loop -1 \
# -i TearsOfSteel.mp4 \
# -c:v copy \
# -r 24 -g 24 \
# -preset superfast \
# -tune zerolatency \
# -f flv rtmp://127.0.0.1:1935/live/test


# ffmpeg_command = ['ffmpeg', '-i', 'input.mp4', '-o', 'output.mp3']
Expand Down
14 changes: 9 additions & 5 deletions platform/tests/manual/load_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@
# ]
# })

# plat.dtree.content.set({
# "devices": [
# {'ref': 'Korad.KA3005P', 'settings': {'usb_serial_short': '0034A5A10458'}},
# {'ref': 'Hanmatek.Hm310t', 'settings': {}},
# {'ref': 'Tenma.72-2710', 'settings': {'usb_serial_short': '003222D50454'}}
# ]
# })

plat.dtree.content.set({
"devices": [
{'ref': 'Korad.KA3005P', 'settings': {'usb_serial_short': '0034A5A10458'}},
{'ref': 'Hanmatek.Hm310t', 'settings': {}},
{'ref': 'Tenma.72-2710', 'settings': {'usb_serial_short': '003222D50454'}}
{'ref': 'Panduza.FakeWebcam', 'settings': {}}
]
})



0 comments on commit 0a8e58e

Please sign in to comment.