Giter Club home page Giter Club logo

Comments (6)

tsightler avatar tsightler commented on September 26, 2024

You screenshot indicates a classic example of UDP buffer overflow, specifically during an I-frame which normally requires a few dozen UDP packets to arrive in time. Assuming a reasonably fast system I would only expect to see that during startup.

The issue is relatively simple, ring-client-api relies on werift, a WebRTC implementation entirely in Typescript (Javascript). Javascript is fairly fast for an interpreted language, and the werift code path is fairly optimized, but it's still not ideal for real time streaming.

Even worse, when werift opens a UDP socket, it just uses the default socket receive buffer. You say above that are running on Windows, which I believe defaults to a 64K UDP receive buffer by default. That means that if node can't make it through the event loop in time to service the inbound packets, well, it's UDP, so older packets are just thrown away as newer packets arrive.

With such a small receive buffer, it can be quite difficult for werift to read data from the socket without buffer overflows, this is especially true during initial startup, usually it stables out after the first few seconds.

You see this problem on Linux as well, especially slower devices like RPi 3/4, as Linux only has a 100k default buffer (still larger than Windows). The solution on Linux is to use sysctl to increase the size of net.core.rmem_max and net.core.rmem_default. For Windows, I think you have to modify the registry and restart:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\AFD\Parameters]
"DefaultReceiveWindow"=dword:00200000
"DefaultSendWindow"=dword:00200000

If you set those values you should get a default 2MB buffer which should help quite a bit, although it may not completely get rid of the issue. I've played with values from 2-8MB, but 2MB usually seems to be enough and has the least impact on latency (may not matter if your are just recording, matters more for viewing a live stream).

from ring.

tsightler avatar tsightler commented on September 26, 2024

Regarding onMotionDetected, you didn't really provide much to go on so it's not clear if you are receiving motion events or not. This is unrelated to cameraStatusPollingSeconds since motion events use push notifications and are not updated by polling, and generally you should use a fairly infrequent polling time here (20 seconds is my recommendation as the Ring API does not update quickly anyway so polling more often is mostly wasting resources for no benefit).

At first glance it appears you are attempting to record the video to a file, so you should probably just use recordToFile() function instead. I'm not really sure what you are using -r for, as I believe that is setting the frame rate, but you can change the frame rate without transcoding which is not done by default.

Overall there are plenty of examples available.

from ring.

tsightler avatar tsightler commented on September 26, 2024

OK, I believe I know why onMotionDetected is not working for you. I'm guessing that you simply generated a new token with the CLI, stored this in an env file, and then are using that token each time you run the app, however, if you do this, notifications will work the first time, but will not continue to work on subsequent uses.

The reason why is that, on first use, the token is updated with additional information, such as the system ID and FCM token, which also must be persistent. If you keep connecting to the API with the CLI generated token, you'll get a new FCM token on each startup and notifications will stop working since Ring doesn't allow the FCM token to change after initial registration.

You should make sure you are moinotiring onRefreshTokenUpdated as documented in https://github.com/dgreif/ring/wiki/Refresh-Tokens#refresh-token-expiration.

from ring.

Zmer03 avatar Zmer03 commented on September 26, 2024

from ring.

tsightler avatar tsightler commented on September 26, 2024

What do you mean by "like how ring actually does it"?

The ring-client-api project includes everything that is needed to start a live stream exactly the way Ring does it (it uses the same API used by the Ring apps and Ring web dashbaord) and from there you can pretty much do anything you want with the stream.

The links I provided above include examples showing, for example, how to stream via HLS in a browser, and there are projects like homebridge-ring, which stream to Homekit, and ring-mqtt, which can stream to any RTSP capable client.

from ring.

Zmer03 avatar Zmer03 commented on September 26, 2024

I know that this closed a while ago but is there a chance you can link me where the HLS example is that you mentioned. I am currently trying to stream via HLS and I'm not sure how so it would be greatly appreciated. I apologize for causing any inconveniences, I know I've asked a lot of questions today.

from ring.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.