steam-server/app/services/stream_manager.py

25 lines
698 B
Python
Raw Normal View History

2024-12-13 18:21:25 +08:00
from app.utils.logger import get_logger
2024-12-12 20:04:36 +08:00
import time
stream_manager = {}
2024-12-13 18:21:25 +08:00
logger = get_logger(__name__)
2024-12-17 20:07:29 +08:00
def reset_stream_time(stream_id: str) -> bool:
2024-12-12 20:04:36 +08:00
if stream_id in stream_manager:
2024-12-16 14:31:28 +08:00
new_time = int(time.time() * 1000)
logger.info(f"Stream {stream_id} reset time to {new_time}")
stream_manager[stream_id]["create_time"] = new_time
2024-12-17 20:07:29 +08:00
return True
return False
2024-12-12 20:04:36 +08:00
def stop_stream(stream_id: str):
2024-12-13 18:21:25 +08:00
if stream_id in stream_manager:
process = stream_manager[stream_id]["process"]
2024-12-12 20:04:36 +08:00
process.terminate()
2024-12-13 18:21:25 +08:00
process.wait() # 确保进程已经完全终止
logger.info(f"Stream {stream_id} stopped.")
del stream_manager[stream_id]
2024-12-17 20:07:29 +08:00