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

Streaming With SRTP Question #472

Open
Greg0109 opened this issue Jul 8, 2024 · 0 comments
Open

Streaming With SRTP Question #472

Greg0109 opened this issue Jul 8, 2024 · 0 comments

Comments

@Greg0109
Copy link

Greg0109 commented Jul 8, 2024

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant