nibi79 / synologysurveillancestation

Synology Surveillancestation Binding
45 stars 5 forks source link

refresh live feed URI (mjpeg over http) #26

Closed dmcwhinnie closed 6 years ago

dmcwhinnie commented 6 years ago

The Live feed URI can change over time, however it seems the value is only determined at binding startup. Would be nice to have the URI refresh similar to how the image snapshot does.

Pavion commented 6 years ago

Seems you've found a bug. You're right, the value is determined at startup (and could actually be refreshed with REFRESH command). Sadly, the only solution is to poll the station with yet another query.

Pavion commented 6 years ago

Please check newest release for a fix https://github.com/nibi79/synologysurveillancestation/releases

dmcwhinnie commented 6 years ago

Looks good. Have had a few times where the image is broken, and then later fixes itself with the new URL. It seems like it takes longer than it should, but haven't had the time to capture the exact timings, and how that correlates to the refresh rate.

Pavion commented 6 years ago

With my setup, the URIs are renewed every 35 minutes while the next-to-last URI remains valid too. The binding checks for a new URI with the event refresh rate (default: 3 seconds) and should thus have no down time at all. If you still encounter some problems, please provide some additional information. Otherwise please close this issue.

dmcwhinnie commented 6 years ago

Had this issue today and I was home so able to grab the log.

Event log has this: 2018-07-08 19:29:27.525 [vent.ItemStateChangedEvent] - ONVIF2_Common_LiveFeedURIMjpegOverHttp changed from http://192.168.1.9:5000/webapi/entry.cgi?api=SYNO.SurveillanceStation.Stream.VideoStreaming&version=1&method=Stream&format=mjpeg&cameraId=5&StmKey=b271cf62f2a0c9cf2dcda0bc67587c54 to http://192.168.1.9:5000/webapi/entry.cgi?api=SYNO.SurveillanceStation.Stream.VideoStreaming&version=1&method=Stream&format=mjpeg&cameraId=5&StmKey=0377e36f8a33dcd0a536d6be4e22a9ef

So the new URL (9ef) does not work, The old one (c54) still works.

When I go to the new URL I get this error: {"error":{"code":105},"success":false}

35 minutes later get a new URL again

2018-07-08 20:04:27.526 [vent.ItemStateChangedEvent] - ONVIF2_Common_LiveFeedURIMjpegOverHttp changed from http://192.168.1.9:5000/webapi/entry.cgi?api=SYNO.SurveillanceStation.Stream.VideoStreaming&version=1&method=Stream&format=mjpeg&cameraId=5&StmKey=0377e36f8a33dcd0a536d6be4e22a9ef to http://192.168.1.9:5000/webapi/entry.cgi?api=SYNO.SurveillanceStation.Stream.VideoStreaming&version=1&method=Stream&format=mjpeg&cameraId=5&StmKey=2d2d6ed45bda8344eda4bb3225adb2ff

And that new one (2ff) works. The intermediate one (9ef) still doesn't work and the initial (c54) still works too..

Pavion commented 6 years ago

It might be related to #25: Keys starting with 0 doesn't seem to work and should be escaped: &StmKey="0377e36f8a33dcd0a536d6be4e22a9ef" other StmKeys should still work as expected. Can you confirm this behavior?

dmcwhinnie commented 6 years ago

Had a case this evening where the Key didn't start with 0, but still had an error. Quoted it and it worked. This failed: http://192.168.1.9:5000/webapi/entry.cgi?api=SYNO.SurveillanceStation.Stream.VideoStreaming&version=1&method=Stream&format=mjpeg&cameraId=6&StmKey=26119e2b439e295f7291baece81b9bb5

This worked: http://192.168.1.9:5000/webapi/entry.cgi?api=SYNO.SurveillanceStation.Stream.VideoStreaming&version=1&method=Stream&format=mjpeg&cameraId=6&StmKey="26119e2b439e295f7291baece81b9bb5"

Not sure if it matters... I have 2 cameras. An ONVIF compatible camera that has the issues. A second camera that is just an MJPEG feed and doesn't seem to have issues.

Pavion commented 6 years ago

Thank you for your detailed description. Please check newest release for a fix: https://github.com/nibi79/synologysurveillancestation/releases

dmcwhinnie commented 6 years ago

All Looks good to me. Haven't had any issues the last 2 days.

utya1988 commented 6 years ago

Hi. Very useful bidings. But i have problem with mjpeg uri. This config doesnot work. Video item=Surveillance_Snapshot_Live_Uri_Mjpeg_Http url="[%s]" encoding="mjpeg"

But if add manualy string

url="http://192.168.234.101:5000/webapi/entry.cgi?api=SYNO.SurveillanceStation.Stream.VideoStreaming&version=1&method=Stream&format=mjpeg&cameraId=3&StmKey=e4aec36203cd040fd6cb9ffbf3df3173"

not

url="http://192.168.234.101:5000/webapi/entry.cgi?api=SYNO.SurveillanceStation.Stream.VideoStreaming&version=1&method=Stream&format=mjpeg&cameraId=3&StmKey="e4aec36203cd040fd6cb9ffbf3df3173""

So if i remove quotes in stmkey, work good. Good you help me. Thanks

Pavion commented 6 years ago

Hi!

As you've already seen above, there was also an issue with quotes being absent The quotes are not from within the binding but from Synology Surveillance Station and they have to be kept. On my system no URI without quotes works properly. As it is and because of the behavior above the quotes may not be removed.

You can check your URIs in a normal browser or an VLC player, in both cases quotes are accepted without complain.

The issue you encounter seems to come from BasicUI, which is unable to escape the quotes properly. Sadly, openHAB only allows using Transformations in sitemap labels, but not in the url="" part.

I've tried a simple Transformation using a .js file:

transform/url.js

(function(i) {    
    return i.replace(/"/g, """);    
})(input)

sitemaps/dummy.sitemap

sitemap Dummy label="Dummy" {
    Frame label="Test" {       
        // working with label=
        Text item=Surveillance_Snapshot_Live_Uri_Mjpeg_Http label="[JS(url.js):%s]" 
        // still not working with url=
        Image item=Surveillance_Snapshot_Live_Uri_Mjpeg_Http  url="[JS(url.js):%s]" refresh=10000       
    }
}

Right now I have no clue as to how to fix this issue. Your thoughts are welcome. If you wish, you can also PM me (also in Russian, if my guess is right :))

Best regards Pav