Any way to tell whether UMS is streaming?
Forum rules
Please make sure you follow the Problem Reporting Guidelines before posting if you want a reply
Please make sure you follow the Problem Reporting Guidelines before posting if you want a reply
Any way to tell whether UMS is streaming?
I am building a little utility that will prevent system from entering sleep mode only when UMS is streaming any content to a renderer. I was wondering if there is anything that I can monitor on the server machine to determine whether UMS is actively streaming or not? Thanks in advance!
Re: Any way to tell whether UMS is streaming?
You know UMS has a "Prevent Windows from sleeping" option on the "General configuration tab"?
Re: Any way to tell whether UMS is streaming?
Yes, but that option prevents the computer from going to sleep irrespective of whether it is streaming or not... essentially keep it awake all the time which is not what I want for energy conservation reasons. Please correct me if that is not how this option is supposed to work.squadjot wrote:You know UMS has a "Prevent Windows from sleeping" option on the "General configuration tab"?
In any case, I ended up creating a little utility that sends sleep prevention signals if the computer's outgoing network utilization is beyond a certain threshold. Seems to be working well so far.
Re: Any way to tell whether UMS is streaming?
I agree some kind of "intelligent sleep" option would be welcome (ie Sleep after X' of no streaming activity). UMS prevents the server to go to sleep even if not streaming, so when I disabled that and played with windows sleep setting, the machine went to sleep right after the streaming ended (so no chance for me to catch the remote and start another file!ishareit wrote:Yes, but that option prevents the computer from going to sleep irrespective of whether it is streaming or not... essentially keep it awake all the time which is not what I want for energy conservation reasons. Please correct me if that is not how this option is supposed to work.squadjot wrote:You know UMS has a "Prevent Windows from sleeping" option on the "General configuration tab"?
In any case, I ended up creating a little utility that sends sleep prevention signals if the computer's outgoing network utilization is beyond a certain threshold. Seems to be working well so far.

-- UMS serving PS3, WDTV, Samsung H6400 + J5500 and Kalemsoft renderers! (no video transcoding but remuxing accepted
)

Re: Any way to tell whether UMS is streaming?
Hi!, If i test by
1. Set sleepmode to 2 minutes
2. Have no active renderers/players on the network.
3. Start UMS but without doing any streaming/browsing.
Result: The computer sleeps after a couple of minutes, atleast it does on my win7.
If instead use UMS right away, the computer does not sleep.
If UMS has a minimum time before sleep, or if UMS keeps computer live aslong it can see the render/player.. i dont' know, but the times i've fell asleep with UMS running, the computer was sleeping when i woke up
If youre interested, there's also a "shutdown" plugin (manual/remote)
Its made for earlier version, but will still work with UMS:
http://www.ps3mediaserver.org/forum/vie ... =12&t=6117
Edit: Yea i guess it could be useful to have more detailed options.
1. Set sleepmode to 2 minutes
2. Have no active renderers/players on the network.
3. Start UMS but without doing any streaming/browsing.
Result: The computer sleeps after a couple of minutes, atleast it does on my win7.
If instead use UMS right away, the computer does not sleep.
If UMS has a minimum time before sleep, or if UMS keeps computer live aslong it can see the render/player.. i dont' know, but the times i've fell asleep with UMS running, the computer was sleeping when i woke up

If youre interested, there's also a "shutdown" plugin (manual/remote)
Its made for earlier version, but will still work with UMS:
http://www.ps3mediaserver.org/forum/vie ... =12&t=6117
Edit: Yea i guess it could be useful to have more detailed options.
Re: Any way to tell whether UMS is streaming?
That is an interesting prerequisite. I have several devices on my network that are considered renderers like my sound receiver, tv, amazon tv stick running kodi, etc. For me, having no active renderers/players is almost impossible.2. Have no active renderers/players on the network.
The inbuilt option needs to do this:
- If UMS is streaming actively any content, then ask Windows to keep prevent sleeping.
- When UMS stops streaming the content, the inbuilt Windows sleep timer starts. For example, if the sleep setting is 30 minutes, and I stopped playing a movie at 9:00 am, then the computer should sleep at 9:30 am.
- Should be independent of whether there are any active renderers/player on the network.
The above is what my little outbound n/w traffic monitor utility does essentially.
PS: If I check the "Prevent Windows from Sleeping" option and restart UMS, I can see that javaw.exe is requesting system to stay awake. If I uncheck that option, javaw.exe is no longer making that request. All without streaming anything from UMS (but with active renderers on the network). You can check this info by running "powercfg -requests" in Windows using admin command prompt.
Re: Any way to tell whether UMS is streaming?
Thanks for your input, i widely agree.
Re: Any way to tell whether UMS is streaming?
I may be wrong, but looking at the code at https://github.com/UniversalMediaServer ... Utils.java it seems the Prevent Sleep is implemented as a timeout of 40 seconds regardless the system is streaming or not.
Maybe some logic can be added for an "Sleep if no activity for X seconds/minutes"?
Maybe some logic can be added for an "Sleep if no activity for X seconds/minutes"?
-- UMS serving PS3, WDTV, Samsung H6400 + J5500 and Kalemsoft renderers! (no video transcoding but remuxing accepted
)

Re: Any way to tell whether UMS is streaming?
I'm no java programmer, but I think the 40 secs is to avoid too many calls to the function.
So if its more than 40 secs cince the function was last called...then the function is allowed to continue.
It seems UMS does not set any "sleeptime", it just uses whatever settings you've set in windows.
Looking at the code:
In RequestHandlerV2.java
This tells me that PMS.get().getRegistry().disableGoToSleep(); is called every time a message is received.
In RequestV2.java
This tells me that; if the operation is complete, we close the stream and call PMS.get().getRegistry().reenableGoToSleep(); (Using whatever power management scheme windows is using)
That makes sense to me.
So if its more than 40 secs cince the function was last called...then the function is allowed to continue.
It seems UMS does not set any "sleeptime", it just uses whatever settings you've set in windows.
Looking at the code:
In RequestHandlerV2.java
Code: Select all
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
79 throws Exception {
80 RequestV2 request = null;
81 RendererConfiguration renderer = null;
82 String userAgentString = null;
83 ArrayList<String> identifiers = new ArrayList<>();
84
85 HttpRequest nettyRequest = this.nettyRequest = (HttpRequest) e.getMessage();
86
87 InetSocketAddress remoteAddress = (InetSocketAddress) e.getChannel().getRemoteAddress();
88 InetAddress ia = remoteAddress.getAddress();
89
90 // Is the request from our own Cling service, i.e. self-originating?
91 boolean isSelf = ia.getHostAddress().equals(PMS.get().getServer().getHost()) &&
92 nettyRequest.headers().get(HttpHeaders.Names.USER_AGENT) != null &&
93 nettyRequest.headers().get(HttpHeaders.Names.USER_AGENT).contains("UMS/");
94
95 // Filter if required
96 if (isSelf || filterIp(ia)) {
97 e.getChannel().close();
98 LOGGER.trace(isSelf ?
99 ("Ignoring self-originating request from " + ia + ":" + remoteAddress.getPort()) :
100 ("Access denied for address " + ia + " based on IP filter"));
101 return;
102 }
103
104 LOGGER.trace("Opened request handler on socket " + remoteAddress);
105 PMS.get().getRegistry().disableGoToSleep();
In RequestV2.java
Code: Select all
public void operationComplete(ChannelFuture future) {
904 chunkWriteFuture.addListener(new ChannelFutureListener() {
905 @Override
906 public void operationComplete(ChannelFuture future) {
907 try {
908 PMS.get().getRegistry().reenableGoToSleep();
909 inputStream.close();
910 } catch (IOException e) {
911 LOGGER.debug("Caught exception", e);
912 }
913
914 // Always close the channel after the response is sent because of
915 // a freeze at the end of video when the channel is not closed.
916 future.getChannel().close();
917 startStopListenerDelegate.stop();
918 }
919 });
That makes sense to me.
Re: Any way to tell whether UMS is streaming?
I observed the same problem as ishareit: when I enable "Prevent Windows from sleeping" my computer does not go to sleep when finished streaming. The windows command
(call it as administartor!) tells that UMS prevents sleeping. When I disable "Prevent Windows from sleeping" this process disappears from the list.
I am sure that there is a logical bug in the WinUtils.java:
The "if" prevents calling SetThreadExecutionState faster than every 40 seconds. That's a good idea but there are situations where it has to be called more often! For instance:
You can also find examples where a needed disableGoToSleep is suppressed.
I would suggest to change the conditions in the "if" clauses:
Unfortunately I can not test the modifications. Maybe anyone of the developer team can do that? Thank you!
Code: Select all
powercfg -requests
I am sure that there is a logical bug in the WinUtils.java:
Code: Select all
@Override
public void disableGoToSleep() {
// Disable go to sleep (every 40s)
if (configuration.isPreventsSleep() && System.currentTimeMillis() - lastDontSleepCall > 40000) {
LOGGER.trace("Calling SetThreadExecutionState ES_SYSTEM_REQUIRED");
Kernel32.INSTANCE.SetThreadExecutionState(Kernel32.ES_SYSTEM_REQUIRED | Kernel32.ES_CONTINUOUS);
lastDontSleepCall = System.currentTimeMillis();
}
}
/* (non-Javadoc)
* @see net.pms.io.SystemUtils#reenableGoToSleep()
*/
@Override
public void reenableGoToSleep() {
// Reenable go to sleep
if (configuration.isPreventsSleep() && System.currentTimeMillis() - lastGoToSleepCall > 40000) {
LOGGER.trace("Calling SetThreadExecutionState ES_CONTINUOUS");
Kernel32.INSTANCE.SetThreadExecutionState(Kernel32.ES_CONTINUOUS);
lastGoToSleepCall = System.currentTimeMillis();
}
}
- disableGoToSleep is called (streaming started)
- after 1 minute reenableGoToSleep is called (streaming finished)
- a few seconds later disableGoToSleep is called (streaming is started again)
- a few seconds later reenableGoToSleep is called (streaming finished again)
You can also find examples where a needed disableGoToSleep is suppressed.
I would suggest to change the conditions in the "if" clauses:
Code: Select all
@Override
public void disableGoToSleep() {
// Disable go to sleep (every 40s)
if (configuration.isPreventsSleep() && (System.currentTimeMillis() - lastDontSleepCall > 40000) || (lastGoToSleepCall >= lastDontSleepCall)) {
LOGGER.trace("Calling SetThreadExecutionState ES_SYSTEM_REQUIRED");
Kernel32.INSTANCE.SetThreadExecutionState(Kernel32.ES_SYSTEM_REQUIRED | Kernel32.ES_CONTINUOUS);
lastDontSleepCall = System.currentTimeMillis();
}
}
@Override
public void reenableGoToSleep() {
// Reenable go to sleep
if (configuration.isPreventsSleep() && (System.currentTimeMillis() - lastGoToSleepCall > 40000) || (lastDontSleepCall >= lastGoToSleepCall)) {
LOGGER.trace("Calling SetThreadExecutionState ES_CONTINUOUS");
Kernel32.INSTANCE.SetThreadExecutionState(Kernel32.ES_CONTINUOUS);
lastGoToSleepCall = System.currentTimeMillis();
}
}