Skip to content

Streaming With SRTP Question #472

@Greg0109

Description

@Greg0109

I have a Raspberry pi with a Pi camera attached. I created a class called CameraSensor that controls the camera, allowing it to take pictures and start or stop streaming at will using RSTP. I have tested and everything works in that camera class, and in the HAP-Python class, while I do get the snapshots without any issue, I cannot get the stream working at all. I can check in VLC the stream is running, but in the home app I have no luck. Here's my homekit code

import logging
import os
from pyhap.accessory_driver import AccessoryDriver
from pyhap import camera
from sam.camera.sensor import CameraSensor
from sam.constants import USER, PASSWORD, SRTP_KEY

# Configuration parameters
FILE_PERSISTENT = './camera.state'
IP_ADDRESS = os.environ.get('IP_ADDRESS', '0.0.0.0')
SRTP_KEY = os.environ.get('SRTP_KEY', SRTP_KEY)
PORT = 51827

# Logging configuration
logging.basicConfig(level=logging.INFO, format="[%(module)s] %(message)s")
logger = logging.getLogger(__name__)

options = {
    "video": {
        "codec": {
            "profiles": [
                camera.VIDEO_CODEC_PARAM_PROFILE_ID_TYPES["BASELINE"],
                camera.VIDEO_CODEC_PARAM_PROFILE_ID_TYPES["MAIN"],
                camera.VIDEO_CODEC_PARAM_PROFILE_ID_TYPES["HIGH"]
            ],
            "levels": [
                camera.VIDEO_CODEC_PARAM_LEVEL_TYPES['TYPE3_1'],
                camera.VIDEO_CODEC_PARAM_LEVEL_TYPES['TYPE3_2'],
                camera.VIDEO_CODEC_PARAM_LEVEL_TYPES['TYPE4_0'],
            ],
        },
        "resolutions": [
            [320, 240, 15],  # Required for Apple Watch
            [1920, 1080, 30],
        ],
    },
    "audio": {
        "codecs": [
            {
                'type': 'OPUS',
                'samplerate': 24,
            },
            {
                'type': 'AAC-eld',
                'samplerate': 16
            }
        ],
    },
    "srtp": True,
    "address": IP_ADDRESS,
}

class HAPCamera(camera.Camera):
    def __init__(self, options, driver, name):
        super().__init__(options, driver, name)
        self._management = super()._create_stream_management(0, options)
        self.picam = CameraSensor()
        self.picam.stream()

    def get_snapshot(self, image_size):
        try:
            return self.picam.take_temp_photo()
        except Exception as e:
            logger.error(f"Error capturing snapshot: {e}")


def main():
    driver = AccessoryDriver(
        address=IP_ADDRESS,
        port=PORT,
        persist_file=FILE_PERSISTENT
    )
    acc = HAPCamera(options, driver, "Camera")
    driver.add_accessory(accessory=acc)
    driver.start()


if __name__ == "__main__":
    main()

Any ideas are very appreciated! Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions