Author: titmuss
Date: Tue Nov  4 07:30:45 2008
New Revision: 3275

URL: http://svn.slimdevices.com?rev=3275&root=Jive&view=rev
Log:
Bug: 9876
Description:
Add support for power management on jive during audio playback.


Modified:
    7.3/trunk/squeezeplay/src/squeezeplay/share/jive/audio/Playback.lua
    7.3/trunk/squeezeplay/src/squeezeplay/share/jive/net/NetworkThread.lua
    7.3/trunk/squeezeplay/src/squeezeplay/share/jive/net/Socket.lua

Modified: 7.3/trunk/squeezeplay/src/squeezeplay/share/jive/audio/Playback.lua
URL: 
http://svn.slimdevices.com/7.3/trunk/squeezeplay/src/squeezeplay/share/jive/audio/Playback.lua?rev=3275&root=Jive&r1=3274&r2=3275&view=diff
==============================================================================
--- 7.3/trunk/squeezeplay/src/squeezeplay/share/jive/audio/Playback.lua 
(original)
+++ 7.3/trunk/squeezeplay/src/squeezeplay/share/jive/audio/Playback.lua Tue Nov 
 4 07:30:45 2008
@@ -115,6 +115,24 @@
 function _timerCallback(self)
        local status = Decode:status()
 
+       -- cpu power saving
+       local outputFullness = status.outputFull / status.outputSize * 100
+       if status.decodeSize > 0 then
+               if outputFullness < 80 then
+                       self.jnt:cpuActive(self)
+               elseif outputFullness > 99 then
+                       self.jnt:cpuInactive(self)
+               end
+       end
+
+       -- cpu power saving
+       -- note this won't enter power save for internet streams
+       local decodeFullness = status.decodeFull / status.decodeSize * 100
+       if self.stream and decodeFullness < 80 then
+               self.jnt:networkActive(self)
+       elseif not self.stream or decodeFullness > 99 then
+               self.jnt:networkInactive(self)
+       end
 
        -- enable stream reads when decode buffer is not full
        if status.decodeFull < status.decodeSize and self.stream then

Modified: 7.3/trunk/squeezeplay/src/squeezeplay/share/jive/net/NetworkThread.lua
URL: 
http://svn.slimdevices.com/7.3/trunk/squeezeplay/src/squeezeplay/share/jive/net/NetworkThread.lua?rev=3275&root=Jive&r1=3274&r2=3275&view=diff
==============================================================================
--- 7.3/trunk/squeezeplay/src/squeezeplay/share/jive/net/NetworkThread.lua 
(original)
+++ 7.3/trunk/squeezeplay/src/squeezeplay/share/jive/net/NetworkThread.lua Tue 
Nov  4 07:30:45 2008
@@ -29,7 +29,7 @@
 
 
 -- stuff we use
-local _assert, tostring, table, ipairs, pairs, pcall, select, setmetatable, 
type  = _assert, tostring, table, ipairs, pairs, pcall, select, setmetatable, 
type
+local _assert, next, tostring, table, ipairs, pairs, pcall, select, 
setmetatable, type  = _assert, next, tostring, table, ipairs, pairs, pcall, 
select, setmetatable, type
 
 local io                = require("io")
 local os                = require("os")
@@ -261,32 +261,80 @@
 
 
 -- Called by the network layer when the network is active
-function networkActive(self)
-       if self.activeCount == 0 then
-               if self.activeCallback then
-                       self.activeCallback(true)
-               end
-       end
-
-       self.activeCount = self.activeCount + 1
+function networkActive(self, obj)
+       self.networkActiveCount[obj] = 1
+
+       local isempty = next(self.networkActiveCount)
+
+       if isempty and not self.networkIsActive then
+               if self.networkActiveCallback then
+                       self.networkActiveCallback(true)
+               end
+
+               self.networkIsActive = true
+       end
 end
 
 
 -- Called by the network layer when the network is inactive
-function networkInactive(self)
-       self.activeCount = self.activeCount - 1
-
-       if self.activeCount == 0 then
-               if self.activeCallback then
-                       self.activeCallback(false)
-               end
+function networkInactive(self, obj)
+       self.networkActiveCount[obj] = nil
+
+       local isempty = next(self.networkActiveCount)
+
+       if not isempty and self.networkIsActive then
+               if self.networkActiveCallback then
+                       self.networkActiveCallback(false)
+               end
+
+               self.networkIsActive = false
        end
 end
 
 
 -- Register a network active callback for power management
 function registerNetworkActive(self, callback)
-       self.activeCallback = callback
+       self.networkActiveCallback = callback
+end
+
+
+-- Called by the network layer when the cpu is active (used for audio
+-- playback)
+function cpuActive(self, obj)
+       self.cpuActiveCount[obj] = 1
+
+       local isempty = next(self.cpuActiveCount)
+
+       if isempty and not self.cpuIsActive then
+               if self.cpuActiveCallback then
+                       self.cpuActiveCallback(true)
+               end
+
+               self.cpuIsActive = true
+       end
+end
+
+
+-- Called by the network layer when the cpu is inactive (used for audio
+-- playback)
+function cpuInactive(self, obj)
+       self.cpuActiveCount[obj] = nil
+
+       local isempty = next(self.cpuActiveCount)
+
+       if not isempty and self.cpuIsActive then
+               if self.cpuActiveCallback then
+                       self.cpuActiveCallback(false)
+               end
+
+               self.cpuIsActive = false
+       end
+end
+
+
+-- Register a cpu active callback for power management
+function registerCpuActive(self, callback)
+       self.cpuActiveCallback = callback
 end
 
 
@@ -386,7 +434,11 @@
                -- list of objects for notify
                subscribers = {},
 
-               activeCount = 0,
+               networkActiveCount = {},
+               networkIsActive = false,
+
+               cpuActiveCount = {},
+               cpuIsActive = false,
        })
 
        -- subscriptions are gc weak

Modified: 7.3/trunk/squeezeplay/src/squeezeplay/share/jive/net/Socket.lua
URL: 
http://svn.slimdevices.com/7.3/trunk/squeezeplay/src/squeezeplay/share/jive/net/Socket.lua?rev=3275&root=Jive&r1=3274&r2=3275&view=diff
==============================================================================
--- 7.3/trunk/squeezeplay/src/squeezeplay/share/jive/net/Socket.lua (original)
+++ 7.3/trunk/squeezeplay/src/squeezeplay/share/jive/net/Socket.lua Tue Nov  4 
07:30:45 2008
@@ -116,7 +116,7 @@
 function socketActive(self)
        if not self.active then
                self.active = true
-               self.jnt:networkActive()
+               self.jnt:networkActive(self)
        end
 end
 
@@ -124,7 +124,7 @@
 function socketInactive(self)
        if self.active then
                self.active = false
-               self.jnt:networkInactive()
+               self.jnt:networkInactive(self)
        end
 end
 

_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/cgi-bin/mailman/listinfo/jive-checkins

Reply via email to