-
Notifications
You must be signed in to change notification settings - Fork 38
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
feat: ipcamera support #93
base: main
Are you sure you want to change the base?
Conversation
…basic ipcamera support ewilken#47
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm impressed! This is some great work! I've tried to get started with this feature a few different times and got discouraged because it felt like a large mountain to climb.
Just a heads up, I think ewilken might not have a lot of extra time to maintain features.
I added some comments in places I think are useful. I wrote a simple examples/ip_camera.rs
to help me review this. What do you think about adding one?
I tried to test this against an rtsp stream (I think this should be supported?) but was unsuccessful. It's unclear how to craft the video/audio options, pipeline
ro to specify rtsp/port for the ip camera.
camera-gstreamer18 = ["dep:gstreamer18"] | ||
camera-gstreamer = ["dep:gstreamer"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I don't know much about gstreamer. Any particular reason why gstreamer 18 support specifically?
gstreamer18 support is needed to build it for raspberrypi (glib dependency).
Gotcha.
// todo: consider types to be more restricted | ||
#[derive(Clone, Default, Debug)] | ||
pub struct StreamOptions { | ||
pub video: Value, | ||
pub audio: Value, | ||
pub srtp: bool, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was about to suggest changing this from a serde_json::Value
to more struct/enumerated types because I wasn't sure what to use for the video/audio fields without looking at the tests.
/// setup_endpoints to create proper handshake with iOS device | ||
/// Current accessory contract doesnt allow to self modify Characteristic and locks | ||
/// are created when adding accessory to the server | ||
pub async fn build<S>(self, server: S) -> Result<StreamManager<MP>, StreamManagerError> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. How does one start do server.run_handle()
after passing the server into the builder? I did a bit of debugging and was able to start it by using a reference to the server (server: &S
) and stream_builder.build(&server)
but it's unclear what the intended use is.
Wow, thank you so much for this huge contribution and @simlay thank you so much for helping with the review! 🙏 Super happy to merge and publish this once you guys are on the same page about it. @kstasik do you think it makes sense to check in a version of your code actually using this as an example, or would that be too complicated? Having a basic example of using it with GStreamer right in here might be pretty valuable to users. |
Any help is very appreciated - the project for one evening turned out to be project for a week of evening. I didn't find any good documentation of TLV contract for ipcamera accessory. I used https://github.com/ikalchev/HAP-python/blob/dev/pyhap/camera.py as a reference (i think we should add it to a block comment) + i did run some ipcamera nodejs homebridge integration to get some data for unit tests. I have a little bit complicated setup, i have a garden plot and ipsec tunnel on a microtik routers between garden (LTE) and home - i wanted to have a remote camera and sprinklers accessible using homekit. In home i have raspberrypi with hap-rs running on it.
Cross.toml (another thing i wasted few hours on, raspberrypi, maybe someone will save some time thanks to this information):
Current solution is sufficient for my use case but i think it may have some bugs - i have low quality connection to the camera - it may be caused by tunnel over LTE with cheap internet - IOS sometimes sends premature signal to close the connection - or i did something wrong with audio stream (my camera doesn't have a microphone - and i wasn't able to extend gstreamer pipeline with audio support). Im also complaining about quality of video but it may be caused by my lack of knowledge about gstreamer/rtspsrc. The reason why i had to introduce some builder pattern and accept One more thing about the library is that it has some pairing issues. I have multiple apple devices in home and very often it's very difficult to pair a hap-rs server. I'm not sure if it's a race condition but i know it has some troubles with ids, |
Oneliner to test gstreamer + rtspc:
The pipeline is built this way (it's generated/regenerated on a request from ios device):
RUST_LOG="info,hap=debug" should display generated gstreamer pipeline as well. As you may notice it doesnt have udpsink + srtpenc for audio - i wanted to add it but my hikvision camera doesn't have a mic. |
It looks like audio configuration is required and device capabilities characteristics are only fetched during pairing. So,
has to be enabled. Without it a video stream won't be requested by ios device. |
@kstasik here is my example/ip_camera.rs. I changed the ip address in the pipeline but otherwise it's the same. I'm not sure why I'm not seeing any logs from the |
I'd love to see a solution for the UUID mismatch. I tried the temporary solution outlined in another issue but it didn't work. Are you able to run the lightbulb example using your branch? |
IMO during pairing and from time to time Remember that device will negotiate the resolution of the streaming needed with accessory. Gstreamer creates dynamic video/audio conversion pipeline which will convert your video camera stream to proper format/framerate/resolution. So please list there all resolutions which fit your device probably caring only about aspect ratio starting from the best one. |
I needed this crate to setup some home automation and got tired of homebridge. Few things changed:
In case of ipcamera I have created trait which can be implemented for ffmpeg if needed.
I decided to use gstreamer bindings. It worked well with my hikvision ip camera. IMO the code is not perfect but better than nothing.
gstreamer18 support is needed to build it for raspberrypi (glib dependency).