Author: titmuss
Date: Mon Feb 4 06:33:44 2008
New Revision: 1780
URL: http://svn.slimdevices.com?rev=1780&root=Jive&view=rev
Log:
[EMAIL PROTECTED] (orig r1775): titmuss | 2008-02-04 13:43:36 +0000
Bug: 6576
Description:
Limit artwork cache to 20Mbytes using a lru cache.
Added:
trunk/jive/src/pkg/jive/share/jive/slim/ArtworkCache.lua
Removed:
trunk/jive/src/pkg/jive/share/jive/slim/RequestsCli.lua
Modified:
trunk/ (props changed)
trunk/jive/src/pkg/jive/Makefile.am
trunk/jive/src/pkg/jive/Makefile.in
trunk/jive/src/pkg/jive/share/jive/slim/SlimServer.lua
trunk/jive/src/pkg/jive/src/ui/jive.h
trunk/jive/src/pkg/jive/src/ui/jive_surface.c
trunk/jive/src/pkg/jive/src/ui/lua_jiveui.c
trunk/jive/src/pkg/jive/src/ui/lua_jiveui.pkg
trunk/jive/src/pkg/jive_squeezeboxjive/share/applets/SetupWireless/SetupWirelessApplet.lua
Propchange: trunk/
------------------------------------------------------------------------------
--- svk:merge (original)
+++ svk:merge Mon Feb 4 06:33:44 2008
@@ -1,3 +1,3 @@
-bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/branches/7.0:1773
+bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/branches/7.0:1775
bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/branches/SN:1083
bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/branches/scrolling:1378
Modified: trunk/jive/src/pkg/jive/Makefile.am
URL:
http://svn.slimdevices.com/trunk/jive/src/pkg/jive/Makefile.am?rev=1780&root=Jive&r1=1779&r2=1780&view=diff
==============================================================================
--- trunk/jive/src/pkg/jive/Makefile.am (original)
+++ trunk/jive/src/pkg/jive/Makefile.am Mon Feb 4 06:33:44 2008
@@ -150,7 +150,7 @@
share/jive/slim/Player.lua \
share/jive/slim/SlimServer.lua \
share/jive/slim/SlimServers.lua \
- share/jive/slim/RequestsCli.lua
+ share/jive/slim/ArtworkCache.lua
luautildir = $(pkgdatadir)/jive/utils
dist_luautil_DATA = \
Modified: trunk/jive/src/pkg/jive/Makefile.in
URL:
http://svn.slimdevices.com/trunk/jive/src/pkg/jive/Makefile.in?rev=1780&root=Jive&r1=1779&r2=1780&view=diff
==============================================================================
--- trunk/jive/src/pkg/jive/Makefile.in (original)
+++ trunk/jive/src/pkg/jive/Makefile.in Mon Feb 4 06:33:44 2008
@@ -433,7 +433,7 @@
share/jive/slim/Player.lua \
share/jive/slim/SlimServer.lua \
share/jive/slim/SlimServers.lua \
- share/jive/slim/RequestsCli.lua
+ share/jive/slim/ArtworkCache.lua
luautildir = $(pkgdatadir)/jive/utils
dist_luautil_DATA = \
Added: trunk/jive/src/pkg/jive/share/jive/slim/ArtworkCache.lua
URL:
http://svn.slimdevices.com/trunk/jive/src/pkg/jive/share/jive/slim/ArtworkCache.lua?rev=1780&root=Jive&view=auto
==============================================================================
--- trunk/jive/src/pkg/jive/share/jive/slim/ArtworkCache.lua (added)
+++ trunk/jive/src/pkg/jive/share/jive/slim/ArtworkCache.lua Mon Feb 4
06:33:44 2008
@@ -1,0 +1,179 @@
+
+--[[
+=head1 NAME
+
+jive.slim.ArtworkCache - Size bounded LRU cache for artwork
+
+--]]
+
+local pairs, setmetatable = pairs, setmetatable
+
+local os = require("os")
+local oo = require("loop.base")
+
+local debug = require("jive.utils.debug")
+local log = require("jive.utils.log").logger("slimserver.cache")
+
+
+-- ArtworkCache is a base class
+module(..., oo.class)
+
+
+-- Limit artwork cache to 20 Mbytes
+local ARTWORK_LIMIT = 20 * 1024 * 1024
+
+
+function __init(self)
+ local obj = oo.rawnew(self, {})
+
+ -- initialise state
+ obj:free()
+
+ return obj
+end
+
+
+function free(self)
+ -- artwork cache
+ self.cache = {}
+
+ -- most and least recently used links
+ self.mru = nil
+ self.lru = nil
+
+ -- total size in bytes
+ self.total = 0
+end
+
+
+function dump(self)
+ local citems = 0
+ for k, v in pairs(self.cache) do
+ citems = citems + 1
+ end
+
+ local items = 0
+ local v = self.lru
+ while v do
+ items = items + 1
+ --log:debug("\t", v.key, " next=", v.next and v.next.key)
+ v = v.prev
+ end
+
+ log:debug("artworkThumbCache items=", items, " citems=", citems, "
bytes=", self.total)
+end
+
+
+function set(self, key, value)
+ -- clear entry
+ if value == nil then
+ self.cache[key] = nil
+ return
+ end
+
+ -- mark as loading
+ if value == true then
+ self.cache[key] = {
+ value = true
+ }
+ return
+ end
+
+ -- loaded artwork
+ local bytes = value:getBytes()
+
+ self.total = self.total + bytes
+
+ local entry = {
+ key = key,
+ value = value,
+ bytes = bytes,
+ }
+
+ self.cache[key] = entry
+
+ -- link into mru list
+ entry.prev = nil
+ entry.next = self.mru
+
+ if self.mru then
+ self.mru.prev = entry
+ end
+ self.mru = entry
+
+ if not self.lru or entry.next == nil then
+ self.lru = entry
+ end
+
+ -- keep cache under artwork limit
+ while self.total > ARTWORK_LIMIT do
+ local entry = self.lru
+ log:debug("Free artwork entry=", entry.key, " total=",
self.total)
+
+ self.cache[entry.key] = nil
+
+ if entry.prev then
+ entry.prev.next = nil
+ end
+ self.lru = entry.prev
+
+ self.total = self.total - entry.value:getBytes()
+ end
+
+ if log:isDebug() then
+ self:dump()
+ end
+end
+
+
+function get(self, key)
+ local entry = self.cache[key]
+
+ if not entry then
+ return nil
+ end
+
+ -- loading or already most recently used entry?
+ if entry.value == true or self.mru == entry then
+ return entry.value
+ end
+
+ -- unlink from list
+ if entry.prev then
+ entry.prev.next = entry.next
+ end
+ if entry.next then
+ entry.next.prev = entry.prev
+ end
+
+ -- link to head
+ entry.prev = nil
+ entry.next = self.mru
+
+ if self.mru then
+ self.mru.prev = entry
+ end
+ self.mru = entry
+
+ if entry.next == nil then
+ self.lru = entry
+ end
+
+ if log:isDebug() then
+ self:dump()
+ end
+
+ return entry.value
+end
+
+
+--[[
+
+=head1 LICENSE
+
+Copyright 2007 Logitech. All Rights Reserved.
+
+This file is subject to the Logitech Public Source License Version 1.0. Please
see the LICENCE file for details.
+
+=cut
+--]]
Modified: trunk/jive/src/pkg/jive/share/jive/slim/SlimServer.lua
URL:
http://svn.slimdevices.com/trunk/jive/src/pkg/jive/share/jive/slim/SlimServer.lua?rev=1780&root=Jive&r1=1779&r2=1780&view=diff
==============================================================================
--- trunk/jive/src/pkg/jive/share/jive/slim/SlimServer.lua (original)
+++ trunk/jive/src/pkg/jive/share/jive/slim/SlimServer.lua Mon Feb 4 06:33:44
2008
@@ -49,6 +49,8 @@
local Task = require("jive.ui.Task")
local Framework = require("jive.ui.Framework")
+
+local ArtworkCache = require("jive.slim.ArtworkCache")
local log = require("jive.utils.log").logger("slimserver")
local logcache = require("jive.utils.log").logger("slimserver.cache")
@@ -231,7 +233,7 @@
artworkPool = HttpPool(jnt, name, ip, port, 2, 1,
Task.PRIORITY_LOW),
-- artwork cache: Weak table storing a surface by iconId
- artworkThumbCache = setmetatable({}, { __mode="k" }),
+ artworkCache = ArtworkCache(),
-- Icons waiting for the given iconId
artworkThumbIcons = {},
@@ -290,7 +292,7 @@
-- notify we're gone by caller in SlimServers
-- clear cache
- self.artworkThumbCache = {}
+ self.artworkCache:free()
self.artworkThumbIcons = {}
-- delete players
@@ -430,17 +432,6 @@
end
--- _dunpArtworkCache
--- returns statistical data about our cache
-local function _dumpArtworkThumbCache(self)
- local items = 0
- for k, v in pairs(self.artworkThumbCache) do
- items = items + 1
- end
- logcache:debug("artworkThumbCache contains ", items, " items")
-end
-
-
-- _getArworkThumbSink
-- returns a sink for artwork so we can cache it as Surface before sending it
forward
local function _getArtworkThumbSink(self, iconId, size)
@@ -449,7 +440,7 @@
size = 56
end
- local cacheKey = iconId .. size
+ local cacheKey = iconId .. "@" .. size
return function(chunk, err)
@@ -483,6 +474,10 @@
end
end
+
+ log:warn("ARTWORK BYTES=", artwork:getBytes())
+
+
-- don't display empty artwork
if w == 0 or h == 0 then
artwork = nil
@@ -498,11 +493,7 @@
end
-- store the artwork in the cache
- self.artworkThumbCache[cacheKey] = artwork
-
- if logcache:isDebug() then
- _dumpArtworkThumbCache(self)
- end
+ self.artworkCache:set(cacheKey, artwork)
end
end
end
@@ -559,8 +550,8 @@
--]]
function artworkThumbCached(self, iconId, size)
- local cacheKey = iconId .. (size or 56)
- if self.artworkThumbCache[cacheKey] then
+ local cacheKey = iconId .. "@" .. (size or 56)
+ if self.artworkCache:get(cacheKey) then
return true
else
return false
@@ -596,10 +587,10 @@
function cancelAllArtwork(self, icon)
for i, entry in ipairs(self.artworkFetchQueue) do
- local cacheKey = entry.key .. entry.size
+ local cacheKey = entry.key .. "@" .. entry.size
-- release cache marker
- self.artworkThumbCache[cacheKey] = nil
+ self.artworkCache:set(cacheKey, nil)
-- release icons
local icons = self.artworkThumbIcons
@@ -632,18 +623,14 @@
function fetchArtworkThumb(self, iconId, icon, uriGenerator, size, imgFormat)
logcache:debug(self, ":fetchArtworkThumb(", iconId, ")")
- if logcache:isDebug() then
- _dumpArtworkThumbCache(self)
- end
-
if not size then
size = 56
end
- local cacheKey = iconId .. size
+ local cacheKey = iconId .. "@" .. size
-- do we have the artwork in the cache
- local artwork = self.artworkThumbCache[cacheKey]
+ local artwork = self.artworkCache:get(cacheKey)
if artwork then
-- are we requesting it already?
if artwork == true then
@@ -664,7 +651,7 @@
end
-- no luck, generate a request for the artwork
- self.artworkThumbCache[cacheKey] = true
+ self.artworkCache:set(cacheKey, true)
if icon then
self.artworkThumbIcons[icon] = cacheKey
icon:setValue(nil)
@@ -693,18 +680,14 @@
function fetchArtworkURL(self, url, icon, size)
logcache:debug(self, ":fetchArtworkURL(", url, ")")
- if logcache:isDebug() then
- _dumpArtworkThumbCache(self)
- end
-
if not size then
size = 56
end
- local cacheKey = url .. size
+ local cacheKey = url .. "@" .. size
-- do we have the artwork in the cache
- local artwork = self.artworkThumbCache[cacheKey]
+ local artwork = self.artworkCache:get(cacheKey)
if artwork then
-- are we requesting it already?
if artwork == true then
@@ -725,7 +708,7 @@
end
-- no luck, generate a request for the artwork
- self.artworkThumbCache[cacheKey] = true
+ self.artworkCache:set(cacheKey, true)
if icon then
icon:setValue(nil)
self.artworkThumbIcons[icon] = cacheKey
Modified: trunk/jive/src/pkg/jive/src/ui/jive.h
URL:
http://svn.slimdevices.com/trunk/jive/src/pkg/jive/src/ui/jive.h?rev=1780&root=Jive&r1=1779&r2=1780&view=diff
==============================================================================
--- trunk/jive/src/pkg/jive/src/ui/jive.h (original)
+++ trunk/jive/src/pkg/jive/src/ui/jive.h Mon Feb 4 06:33:44 2008
@@ -291,6 +291,7 @@
JiveSurface* dst, Uint16 dx, Uint16 dy);
void jive_surface_blit_alpha(JiveSurface *src, JiveSurface *dst, Uint16 dx,
Uint16 dy, Uint8 alpha);
void jive_surface_get_size(JiveSurface *srf, Uint16 *w, Uint16 *h);
+int jive_surface_get_bytes(JiveSurface *srf);
void jive_surface_free(JiveSurface *srf);
/* Encapsulated SDL_gfx functions */
Modified: trunk/jive/src/pkg/jive/src/ui/jive_surface.c
URL:
http://svn.slimdevices.com/trunk/jive/src/pkg/jive/src/ui/jive_surface.c?rev=1780&root=Jive&r1=1779&r2=1780&view=diff
==============================================================================
--- trunk/jive/src/pkg/jive/src/ui/jive_surface.c (original)
+++ trunk/jive/src/pkg/jive/src/ui/jive_surface.c Mon Feb 4 06:33:44 2008
@@ -281,6 +281,19 @@
}
}
+
+int jive_surface_get_bytes(JiveSurface *srf) {
+ SDL_PixelFormat *format;
+
+ if (!srf->sdl) {
+ return 0;
+ }
+
+ format = srf->sdl->format;
+ return srf->sdl->w * srf->sdl->h * format->BytesPerPixel;
+}
+
+
void jive_surface_free(JiveSurface *srf) {
if (--srf->refcount > 0) {
return;
Modified: trunk/jive/src/pkg/jive/src/ui/lua_jiveui.c
URL:
http://svn.slimdevices.com/trunk/jive/src/pkg/jive/src/ui/lua_jiveui.c?rev=1780&root=Jive&r1=1779&r2=1780&view=diff
==============================================================================
--- trunk/jive/src/pkg/jive/src/ui/lua_jiveui.c (original)
+++ trunk/jive/src/pkg/jive/src/ui/lua_jiveui.c Mon Feb 4 06:33:44 2008
@@ -1,6 +1,6 @@
/*
** Lua binding: jive
-** Generated automatically by tolua++-1.0.92 on Tue Jan 22 12:52:24 2008.
+** Generated automatically by tolua++-1.0.92 on Wed Jan 30 21:18:12 2008.
*/
#ifndef __cplusplus
@@ -672,6 +672,38 @@
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'getSize'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: jive_surface_get_bytes of class Surface */
+#ifndef TOLUA_DISABLE_tolua_jive_jive_ui_Surface_getBytes00
+static int tolua_jive_jive_ui_Surface_getBytes00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"Surface",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,2,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ Surface* self = (Surface*) tolua_tousertype(tolua_S,1,0);
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function
'jive_surface_get_bytes'",NULL);
+#endif
+ {
+ tolua_outside int tolua_ret = (tolua_outside int)
jive_surface_get_bytes(self);
+ tolua_pushinteger(tolua_S,(lua_Integer)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'getBytes'.",&tolua_err);
return 0;
#endif
}
@@ -2169,6 +2201,7 @@
tolua_function(tolua_S,"blitClip",tolua_jive_jive_ui_Surface_blitClip00);
tolua_function(tolua_S,"blitAlpha",tolua_jive_jive_ui_Surface_blitAlpha00);
tolua_function(tolua_S,"getSize",tolua_jive_jive_ui_Surface_getSize00);
+ tolua_function(tolua_S,"getBytes",tolua_jive_jive_ui_Surface_getBytes00);
tolua_function(tolua_S,"rotozoom",tolua_jive_jive_ui_Surface_rotozoom00);
tolua_function(tolua_S,"zoom",tolua_jive_jive_ui_Surface_zoom00);
tolua_function(tolua_S,"shrink",tolua_jive_jive_ui_Surface_shrink00);
Modified: trunk/jive/src/pkg/jive/src/ui/lua_jiveui.pkg
URL:
http://svn.slimdevices.com/trunk/jive/src/pkg/jive/src/ui/lua_jiveui.pkg?rev=1780&root=Jive&r1=1779&r2=1780&view=diff
==============================================================================
--- trunk/jive/src/pkg/jive/src/ui/lua_jiveui.pkg (original)
+++ trunk/jive/src/pkg/jive/src/ui/lua_jiveui.pkg Mon Feb 4 06:33:44 2008
@@ -165,6 +165,7 @@
Surface* dst, Uint16 dx, Uint16 dy);
tolua_outside void jive_surface_blit_alpha @ blitAlpha(Surface *dst,
Sint16 dx, Sint16 dy, Uint8 alpha);
tolua_outside void jive_surface_get_size @ getSize(Uint16 *w=0, Uint16
*h=0);
+ tolua_outside int jive_surface_get_bytes @ getBytes();
tolua_create Surface *jive_surface_rotozoomSurface @ rotozoom(double
angle, double zoom, int smooth=1);
tolua_create Surface *jive_surface_zoomSurface @ zoom(double zoomx,
double zoomy, int smooth=1);
Modified:
trunk/jive/src/pkg/jive_squeezeboxjive/share/applets/SetupWireless/SetupWirelessApplet.lua
URL:
http://svn.slimdevices.com/trunk/jive/src/pkg/jive_squeezeboxjive/share/applets/SetupWireless/SetupWirelessApplet.lua?rev=1780&root=Jive&r1=1779&r2=1780&view=diff
==============================================================================
---
trunk/jive/src/pkg/jive_squeezeboxjive/share/applets/SetupWireless/SetupWirelessApplet.lua
(original)
+++
trunk/jive/src/pkg/jive_squeezeboxjive/share/applets/SetupWireless/SetupWirelessApplet.lua
Mon Feb 4 06:33:44 2008
@@ -328,7 +328,7 @@
local item = self.scanResults[ssid].item
- assert(type(entry.quality) == "number", "Eh?
quality is " .. tostring(entry.quality) .. " for " .. ssid)
+ --assert(type(entry.quality) == "number", "Eh?
quality is " .. tostring(entry.quality) .. " for " .. ssid)
item.icon:setStyle("wirelessLevel" ..
entry.quality)
self.scanMenu:updatedItem(item)
@@ -1413,6 +1413,14 @@
{ text = self:string("NETWORK_IP_ADDRESS"),
icon = values[5] },
{ text = self:string("NETWORK_SNR"), icon =
values[6] },
{ text = self:string("NETWORK_BITRATE"),
icon = values[7] },
+
+ {
+ text =
self:string("NETWORK_FORGET_NETWORK"), nil,
+ sound = "WINDOWSHOW",
+ callback = function()
+
deleteConfirm(self, ssid)
+ end
+ },
})
window:addWidget(menu)
_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/cgi-bin/mailman/listinfo/jive-checkins