Attempting to improve the robustness of texture decoding by always ignoring LayerInfo.End values and creating guessed default layer boundaries on failed decodes Changed a noisy J2K decode log message from Info to Debug Replacing openjpeg-dotnet decoding with managed CSJ2K decoding. Should be much more reliable, faster, and use less memory

* Re-added openjpeg-dotnet files since they are used elsewhere in OpenSim * Updated prebuild.xml with a reference to CSJ2K

* Renamed IJ2KDecoder and J2KDecoder member names to follow standard naming conventions * Removed j2kDecodeCache cruft and replaced it with the OpenSim cache system * Rewrote the default layer boundary algorithm to use percentages instead of an exponent * Switched from an infinite in-memory cache to an expiring cache (10 minute timeout) * Slightly quieted logging errors for failed texture decodes
prioritization
John Hurliman 2009-09-30 12:18:22 -07:00 committed by Melanie
parent f908e32f62
commit f56dc5fcda
7 changed files with 174 additions and 542 deletions

View File

@ -351,7 +351,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
J2KDecodedCallback(m_requestedUUID, new OpenJPEG.J2KLayerInfo[0]);
}
// Send it off to the jpeg decoder
m_j2kDecodeModule.decode(m_requestedUUID, Data, J2KDecodedCallback);
m_j2kDecodeModule.BeginDecode(m_requestedUUID, Data, J2KDecodedCallback);
}
else

View File

@ -34,8 +34,8 @@ using System.Threading;
using log4net;
using Nini.Config;
using OpenMetaverse;
using OpenMetaverse.Assets;
using OpenMetaverse.Imaging;
using CSJ2K;
using OpenSim.Framework;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
@ -43,31 +43,25 @@ using OpenSim.Services.Interfaces;
namespace OpenSim.Region.CoreModules.Agent.TextureSender
{
public delegate void J2KDecodeDelegate(UUID AssetId);
public delegate void J2KDecodeDelegate(UUID assetID);
public class J2KDecoderModule : IRegionModule, IJ2KDecoder
{
#region IRegionModule Members
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static readonly ILog m_log
= LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// Cached Decoded Layers
/// </summary>
private readonly Dictionary<UUID, OpenJPEG.J2KLayerInfo[]> m_cacheddecode = new Dictionary<UUID, OpenJPEG.J2KLayerInfo[]>();
private bool OpenJpegFail = false;
private string CacheFolder = Util.dataDir() + "/j2kDecodeCache";
private int CacheTimeout = 720;
private J2KDecodeFileCache fCache = null;
private Thread CleanerThread = null;
private IAssetService AssetService = null;
private Scene m_Scene = null;
/// <summary>
/// List of client methods to notify of results of decode
/// </summary>
/// <summary>Temporarily holds deserialized layer data information in memory</summary>
private readonly ExpiringCache<UUID, OpenJPEG.J2KLayerInfo[]> m_decodedCache = new ExpiringCache<UUID,OpenJPEG.J2KLayerInfo[]>();
/// <summary>List of client methods to notify of results of decode</summary>
private readonly Dictionary<UUID, List<DecodedCallback>> m_notifyList = new Dictionary<UUID, List<DecodedCallback>>();
/// <summary>Cache that will store decoded JPEG2000 layer boundary data</summary>
private IImprovedAssetCache m_cache;
/// <summary>Reference to a scene (doesn't matter which one as long as it can load the cache module)</summary>
private Scene m_scene;
#region IRegionModule
public string Name { get { return "J2KDecoderModule"; } }
public bool IsSharedModule { get { return true; } }
public J2KDecoderModule()
{
@ -75,630 +69,268 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
public void Initialise(Scene scene, IConfigSource source)
{
if (m_Scene == null)
m_Scene = scene;
IConfig j2kConfig = source.Configs["J2KDecoder"];
if (j2kConfig != null)
{
CacheFolder = j2kConfig.GetString("CacheDir", CacheFolder);
CacheTimeout = j2kConfig.GetInt("CacheTimeout", CacheTimeout);
}
if (fCache == null)
fCache = new J2KDecodeFileCache(CacheFolder, CacheTimeout);
if (m_scene == null)
m_scene = scene;
scene.RegisterModuleInterface<IJ2KDecoder>(this);
if (CleanerThread == null && CacheTimeout != 0)
{
CleanerThread = new Thread(CleanCache);
CleanerThread.Name = "J2KCleanerThread";
CleanerThread.IsBackground = true;
CleanerThread.Start();
}
}
public void PostInitialise()
{
AssetService = m_Scene.AssetService;
m_cache = m_scene.RequestModuleInterface<IImprovedAssetCache>();
}
public void Close()
{
}
public string Name
#endregion IRegionModule
#region IJ2KDecoder
public void BeginDecode(UUID assetID, byte[] j2kData, DecodedCallback callback)
{
get { return "J2KDecoderModule"; }
}
public bool IsSharedModule
{
get { return true; }
}
#endregion
#region IJ2KDecoder Members
public void decode(UUID AssetId, byte[] assetData, DecodedCallback decodedReturn)
{
// Dummy for if decoding fails.
OpenJPEG.J2KLayerInfo[] result = new OpenJPEG.J2KLayerInfo[0];
// Check if it's cached
bool cached = false;
lock (m_cacheddecode)
{
if (m_cacheddecode.ContainsKey(AssetId))
{
cached = true;
result = m_cacheddecode[AssetId];
}
}
OpenJPEG.J2KLayerInfo[] result;
// If it's cached, return the cached results
if (cached)
if (m_decodedCache.TryGetValue(assetID, out result))
{
decodedReturn(AssetId, result);
callback(assetID, result);
}
else
{
// not cached, so we need to decode it
// Not cached, we need to decode it.
// Add to notify list and start decoding.
// Next request for this asset while it's decoding will only be added to the notify list
// once this is decoded, requests will be served from the cache and all clients in the notifylist will be updated
bool decode = false;
lock (m_notifyList)
{
if (m_notifyList.ContainsKey(AssetId))
if (m_notifyList.ContainsKey(assetID))
{
m_notifyList[AssetId].Add(decodedReturn);
m_notifyList[assetID].Add(callback);
}
else
{
List<DecodedCallback> notifylist = new List<DecodedCallback>();
notifylist.Add(decodedReturn);
m_notifyList.Add(AssetId, notifylist);
notifylist.Add(callback);
m_notifyList.Add(assetID, notifylist);
decode = true;
}
}
// Do Decode!
if (decode)
{
doJ2kDecode(AssetId, assetData);
}
DoJ2KDecode(assetID, j2kData);
}
}
/// <summary>
/// Provides a synchronous decode so that caller can be assured that this executes before the next line
/// </summary>
/// <param name="AssetId"></param>
/// <param name="j2kdata"></param>
public void syncdecode(UUID AssetId, byte[] j2kdata)
/// <param name="assetID"></param>
/// <param name="j2kData"></param>
public void Decode(UUID assetID, byte[] j2kData)
{
doJ2kDecode(AssetId, j2kdata);
DoJ2KDecode(assetID, j2kData);
}
#endregion
#endregion IJ2KDecoder
/// <summary>
/// Decode Jpeg2000 Asset Data
/// </summary>
/// <param name="AssetId">UUID of Asset</param>
/// <param name="j2kdata">Byte Array Asset Data </param>
private void doJ2kDecode(UUID AssetId, byte[] j2kdata)
/// <param name="assetID">UUID of Asset</param>
/// <param name="j2kData">JPEG2000 data</param>
private void DoJ2KDecode(UUID assetID, byte[] j2kData)
{
int DecodeTime = 0;
DecodeTime = Environment.TickCount;
OpenJPEG.J2KLayerInfo[] layers = new OpenJPEG.J2KLayerInfo[0]; // Dummy result for if it fails. Informs that there's only full quality
OpenJPEG.J2KLayerInfo[] layers;
if (!OpenJpegFail)
if (!TryLoadCacheForAsset(assetID, out layers))
{
if (!fCache.TryLoadCacheForAsset(AssetId, out layers))
try
{
try
{
List<int> layerStarts = CSJ2K.J2kImage.GetLayerBoundaries(new MemoryStream(j2kData));
AssetTexture texture = new AssetTexture(AssetId, j2kdata);
if (texture.DecodeLayerBoundaries())
if (layerStarts != null && layerStarts.Count > 0)
{
layers = new OpenJPEG.J2KLayerInfo[layerStarts.Count];
for (int i = 0; i < layerStarts.Count; i++)
{
bool sane = true;
OpenJPEG.J2KLayerInfo layer = new OpenJPEG.J2KLayerInfo();
int start = layerStarts[i];
// Sanity check all of the layers
for (int i = 0; i < texture.LayerInfo.Length; i++)
{
if (texture.LayerInfo[i].End > texture.AssetData.Length)
{
sane = false;
break;
}
}
if (sane)
{
layers = texture.LayerInfo;
fCache.SaveFileCacheForAsset(AssetId, layers);
// Write out decode time
m_log.InfoFormat("[J2KDecoderModule]: {0} Decode Time: {1}", Environment.TickCount - DecodeTime,
AssetId);
}
if (i == 0)
layer.Start = 0;
else
{
m_log.WarnFormat(
"[J2KDecoderModule]: JPEG2000 texture decoding succeeded, but sanity check failed for {0}",
AssetId);
}
}
layer.Start = layerStarts[i];
else
{
/*
Random rnd = new Random();
// scramble ends for test
for (int i = 0; i < texture.LayerInfo.Length; i++)
{
texture.LayerInfo[i].End = rnd.Next(999999);
}
*/
// Try to do some heuristics error correction! Yeah.
bool sane2Heuristics = true;
if (texture.Image == null)
sane2Heuristics = false;
if (texture.LayerInfo == null)
sane2Heuristics = false;
if (sane2Heuristics)
{
if (texture.LayerInfo.Length == 0)
sane2Heuristics = false;
}
if (sane2Heuristics)
{
// Last layer start is less then the end of the file and last layer start is greater then 0
if (texture.LayerInfo[texture.LayerInfo.Length - 1].Start < texture.AssetData.Length && texture.LayerInfo[texture.LayerInfo.Length - 1].Start > 0)
{
}
else
{
sane2Heuristics = false;
}
}
if (sane2Heuristics)
{
int start = 0;
// try to fix it by using consistant data in the start field
for (int i = 0; i < texture.LayerInfo.Length; i++)
{
if (i == 0)
start = 0;
if (i == texture.LayerInfo.Length - 1)
texture.LayerInfo[i].End = texture.AssetData.Length;
else
texture.LayerInfo[i].End = texture.LayerInfo[i + 1].Start - 1;
// in this case, the end of the next packet is less then the start of the last packet
// after we've attempted to fix it which means the start of the last packet is borked
// there's no recovery from this
if (texture.LayerInfo[i].End < start)
{
sane2Heuristics = false;
break;
}
if (texture.LayerInfo[i].End < 0 || texture.LayerInfo[i].End > texture.AssetData.Length)
{
sane2Heuristics = false;
break;
}
if (texture.LayerInfo[i].Start < 0 || texture.LayerInfo[i].Start > texture.AssetData.Length)
{
sane2Heuristics = false;
break;
}
start = texture.LayerInfo[i].Start;
}
}
if (sane2Heuristics)
{
layers = texture.LayerInfo;
fCache.SaveFileCacheForAsset(AssetId, layers);
// Write out decode time
m_log.InfoFormat("[J2KDecoderModule]: HEURISTICS SUCCEEDED {0} Decode Time: {1}", Environment.TickCount - DecodeTime,
AssetId);
}
if (i == layerStarts.Count - 1)
layer.End = j2kData.Length;
else
{
m_log.WarnFormat("[J2KDecoderModule]: JPEG2000 texture decoding failed for {0}. Is this a texture? is it J2K?", AssetId);
}
layer.End = layerStarts[i + 1] - 1;
layers[i] = layer;
}
texture = null; // dereference and dispose of ManagedImage
}
catch (DllNotFoundException)
{
m_log.Error(
"[J2KDecoderModule]: OpenJpeg is not installed properly. Decoding disabled! This will slow down texture performance! Often times this is because of an old version of GLIBC. You must have version 2.4 or above!");
OpenJpegFail = true;
}
catch (Exception ex)
{
m_log.WarnFormat(
"[J2KDecoderModule]: JPEG2000 texture decoding threw an exception for {0}, {1}",
AssetId, ex);
}
}
catch (Exception ex)
{
m_log.Warn("[J2KDecoderModule]: CSJ2K threw an exception decoding texture " + assetID + ": " + ex.Message);
}
if (layers == null || layers.Length == 0)
{
m_log.Warn("[J2KDecoderModule]: Failed to decode layer data for texture " + assetID + ", guessing sane defaults");
// Layer decoding completely failed. Guess at sane defaults for the layer boundaries
layers = CreateDefaultLayers(j2kData.Length);
}
// Cache Decoded layers
SaveFileCacheForAsset(assetID, layers);
}
// Cache Decoded layers
lock (m_cacheddecode)
{
if (m_cacheddecode.ContainsKey(AssetId))
m_cacheddecode.Remove(AssetId);
m_cacheddecode.Add(AssetId, layers);
}
// Notify Interested Parties
lock (m_notifyList)
{
if (m_notifyList.ContainsKey(AssetId))
if (m_notifyList.ContainsKey(assetID))
{
foreach (DecodedCallback d in m_notifyList[AssetId])
foreach (DecodedCallback d in m_notifyList[assetID])
{
if (d != null)
d.DynamicInvoke(AssetId, layers);
d.DynamicInvoke(assetID, layers);
}
m_notifyList.Remove(AssetId);
m_notifyList.Remove(assetID);
}
}
}
private void CleanCache()
private OpenJPEG.J2KLayerInfo[] CreateDefaultLayers(int j2kLength)
{
m_log.Info("[J2KDecoderModule]: Cleaner thread started");
OpenJPEG.J2KLayerInfo[] layers = new OpenJPEG.J2KLayerInfo[5];
while (true)
{
if (AssetService != null)
fCache.ScanCacheFiles(RedecodeTexture);
for (int i = 0; i < layers.Length; i++)
layers[i] = new OpenJPEG.J2KLayerInfo();
System.Threading.Thread.Sleep(600000);
}
// These default layer sizes are based on a small sampling of real-world texture data
// with extra padding thrown in for good measure. This is a worst case fallback plan
// and may not gracefully handle all real world data
layers[0].Start = 0;
layers[1].Start = (int)((float)j2kLength * 0.02f);
layers[2].Start = (int)((float)j2kLength * 0.05f);
layers[3].Start = (int)((float)j2kLength * 0.20f);
layers[4].Start = (int)((float)j2kLength * 0.50f);
layers[0].End = layers[1].Start - 1;
layers[1].End = layers[2].Start - 1;
layers[2].End = layers[3].Start - 1;
layers[3].End = layers[4].Start - 1;
layers[4].End = j2kLength;
return layers;
}
private void RedecodeTexture(UUID assetID)
private void SaveFileCacheForAsset(UUID AssetId, OpenJPEG.J2KLayerInfo[] Layers)
{
AssetBase texture = AssetService.Get(assetID.ToString());
if (texture == null)
return;
m_decodedCache.AddOrUpdate(AssetId, Layers, TimeSpan.FromMinutes(10));
doJ2kDecode(assetID, texture.Data);
}
}
public class J2KDecodeFileCache
{
private readonly string m_cacheDecodeFolder;
private readonly int m_cacheTimeout;
private bool enabled = true;
private static readonly ILog m_log
= LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// Creates a new instance of a file cache
/// </summary>
/// <param name="pFolder">base folder for the cache. Will be created if it doesn't exist</param>
public J2KDecodeFileCache(string pFolder, int timeout)
{
m_cacheDecodeFolder = pFolder;
m_cacheTimeout = timeout;
if (!Directory.Exists(pFolder))
if (m_cache != null)
{
Createj2KCacheFolder(pFolder);
}
}
AssetBase layerDecodeAsset = new AssetBase();
layerDecodeAsset.ID = "j2kCache_" + AssetId.ToString();
layerDecodeAsset.Local = true;
layerDecodeAsset.Name = layerDecodeAsset.ID;
layerDecodeAsset.Temporary = true;
layerDecodeAsset.Type = (sbyte)AssetType.Notecard;
#region Serialize Layer Data
/// <summary>
/// Save Layers to Disk Cache
/// </summary>
/// <param name="AssetId">Asset to Save the layers. Used int he file name by default</param>
/// <param name="Layers">The Layer Data from OpenJpeg</param>
/// <returns></returns>
public bool SaveFileCacheForAsset(UUID AssetId, OpenJPEG.J2KLayerInfo[] Layers)
{
if (Layers.Length > 0 && enabled)
{
FileStream fsCache =
new FileStream(String.Format("{0}/{1}", m_cacheDecodeFolder, FileNameFromAssetId(AssetId)),
FileMode.Create);
StreamWriter fsSWCache = new StreamWriter(fsCache);
StringBuilder stringResult = new StringBuilder();
string strEnd = "\n";
for (int i = 0; i < Layers.Length; i++)
{
if (i == (Layers.Length - 1))
strEnd = "";
if (i == Layers.Length - 1)
strEnd = String.Empty;
stringResult.AppendFormat("{0}|{1}|{2}{3}", Layers[i].Start, Layers[i].End, Layers[i].End - Layers[i].Start, strEnd);
}
fsSWCache.Write(stringResult.ToString());
fsSWCache.Close();
fsSWCache.Dispose();
fsCache.Dispose();
return true;
layerDecodeAsset.Data = Encoding.UTF8.GetBytes(stringResult.ToString());
#endregion Serialize Layer Data
m_cache.Cache(layerDecodeAsset);
}
return false;
}
/// <summary>
/// Loads the Layer data from the disk cache
/// Returns true if load succeeded
/// </summary>
/// <param name="AssetId">AssetId that we're checking the cache for</param>
/// <param name="Layers">out layers to save to</param>
/// <returns>true if load succeeded</returns>
public bool TryLoadCacheForAsset(UUID AssetId, out OpenJPEG.J2KLayerInfo[] Layers)
bool TryLoadCacheForAsset(UUID AssetId, out OpenJPEG.J2KLayerInfo[] Layers)
{
string filename = String.Format("{0}/{1}", m_cacheDecodeFolder, FileNameFromAssetId(AssetId));
Layers = new OpenJPEG.J2KLayerInfo[0];
if (!File.Exists(filename))
return false;
if (!enabled)
if (m_decodedCache.TryGetValue(AssetId, out Layers))
{
return false;
return true;
}
string readResult = string.Empty;
try
else if (m_cache != null)
{
FileStream fsCachefile =
new FileStream(filename,
FileMode.Open);
string assetName = "j2kCache_" + AssetId.ToString();
AssetBase layerDecodeAsset = m_cache.Get(assetName);
StreamReader sr = new StreamReader(fsCachefile);
readResult = sr.ReadToEnd();
sr.Close();
sr.Dispose();
fsCachefile.Dispose();
}
catch (IOException ioe)
{
if (ioe is PathTooLongException)
if (layerDecodeAsset != null)
{
m_log.Error(
"[J2KDecodeCache]: Cache Read failed. Path is too long.");
}
else if (ioe is DirectoryNotFoundException)
{
m_log.Error(
"[J2KDecodeCache]: Cache Read failed. Cache Directory does not exist!");
enabled = false;
}
else
{
m_log.Error(
"[J2KDecodeCache]: Cache Read failed. IO Exception.");
}
return false;
#region Deserialize Layer Data
}
catch (UnauthorizedAccessException)
{
m_log.Error(
"[J2KDecodeCache]: Cache Read failed. UnauthorizedAccessException Exception. Do you have the proper permissions on this file?");
return false;
}
catch (ArgumentException ae)
{
if (ae is ArgumentNullException)
{
m_log.Error(
"[J2KDecodeCache]: Cache Read failed. No Filename provided");
}
else
{
m_log.Error(
"[J2KDecodeCache]: Cache Read failed. Filname was invalid");
}
return false;
}
catch (NotSupportedException)
{
m_log.Error(
"[J2KDecodeCache]: Cache Read failed, not supported. Cache disabled!");
enabled = false;
string readResult = Encoding.UTF8.GetString(layerDecodeAsset.Data);
string[] lines = readResult.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
return false;
}
catch (Exception e)
{
m_log.ErrorFormat(
"[J2KDecodeCache]: Cache Read failed, unknown exception. Error: {0}",
e.ToString());
return false;
}
string[] lines = readResult.Split('\n');
if (lines.Length <= 0)
return false;
Layers = new OpenJPEG.J2KLayerInfo[lines.Length];
for (int i = 0; i < lines.Length; i++)
{
string[] elements = lines[i].Split('|');
if (elements.Length == 3)
{
int element1, element2;
try
if (lines.Length == 0)
{
element1 = Convert.ToInt32(elements[0]);
element2 = Convert.ToInt32(elements[1]);
}
catch (FormatException)
{
m_log.WarnFormat("[J2KDecodeCache]: Cache Read failed with ErrorConvert for {0}", AssetId);
Layers = new OpenJPEG.J2KLayerInfo[0];
m_log.Warn("[J2KDecodeCache]: Expiring corrupted layer data (empty) " + assetName);
m_cache.Expire(assetName);
return false;
}
Layers[i] = new OpenJPEG.J2KLayerInfo();
Layers[i].Start = element1;
Layers[i].End = element2;
Layers = new OpenJPEG.J2KLayerInfo[lines.Length];
}
else
{
// reading failed
m_log.WarnFormat("[J2KDecodeCache]: Cache Read failed for {0}", AssetId);
Layers = new OpenJPEG.J2KLayerInfo[0];
return false;
for (int i = 0; i < lines.Length; i++)
{
string[] elements = lines[i].Split('|');
if (elements.Length == 3)
{
int element1, element2;
try
{
element1 = Convert.ToInt32(elements[0]);
element2 = Convert.ToInt32(elements[1]);
}
catch (FormatException)
{
m_log.Warn("[J2KDecodeCache]: Expiring corrupted layer data (format) " + assetName);
m_cache.Expire(assetName);
return false;
}
Layers[i] = new OpenJPEG.J2KLayerInfo();
Layers[i].Start = element1;
Layers[i].End = element2;
}
else
{
m_log.Warn("[J2KDecodeCache]: Expiring corrupted layer data (layout) " + assetName);
m_cache.Expire(assetName);
return false;
}
}
#endregion Deserialize Layer Data
return true;
}
}
return true;
}
/// <summary>
/// Routine which converts assetid to file name
/// </summary>
/// <param name="AssetId">asset id of the image</param>
/// <returns>string filename</returns>
public string FileNameFromAssetId(UUID AssetId)
{
return String.Format("j2kCache_{0}.cache", AssetId);
}
public UUID AssetIdFromFileName(string fileName)
{
string rawId = fileName.Replace("j2kCache_", "").Replace(".cache", "");
UUID asset;
if (!UUID.TryParse(rawId, out asset))
return UUID.Zero;
return asset;
}
/// <summary>
/// Creates the Cache Folder
/// </summary>
/// <param name="pFolder">Folder to Create</param>
public void Createj2KCacheFolder(string pFolder)
{
try
{
Directory.CreateDirectory(pFolder);
}
catch (IOException ioe)
{
if (ioe is PathTooLongException)
{
m_log.Error(
"[J2KDecodeCache]: Cache Directory does not exist and create failed because the path to the cache folder is too long. Cache disabled!");
}
else if (ioe is DirectoryNotFoundException)
{
m_log.Error(
"[J2KDecodeCache]: Cache Directory does not exist and create failed because the supplied base of the directory folder does not exist. Cache disabled!");
}
else
{
m_log.Error(
"[J2KDecodeCache]: Cache Directory does not exist and create failed because of an IO Exception. Cache disabled!");
}
enabled = false;
}
catch (UnauthorizedAccessException)
{
m_log.Error(
"[J2KDecodeCache]: Cache Directory does not exist and create failed because of an UnauthorizedAccessException Exception. Cache disabled!");
enabled = false;
}
catch (ArgumentException ae)
{
if (ae is ArgumentNullException)
{
m_log.Error(
"[J2KDecodeCache]: Cache Directory does not exist and create failed because the folder provided is invalid! Cache disabled!");
}
else
{
m_log.Error(
"[J2KDecodeCache]: Cache Directory does not exist and create failed because no cache folder was provided! Cache disabled!");
}
enabled = false;
}
catch (NotSupportedException)
{
m_log.Error(
"[J2KDecodeCache]: Cache Directory does not exist and create failed because it's not supported. Cache disabled!");
enabled = false;
}
catch (Exception e)
{
m_log.ErrorFormat(
"[J2KDecodeCache]: Cache Directory does not exist and create failed because of an unknown exception. Cache disabled! Error: {0}",
e.ToString());
enabled = false;
}
}
public void ScanCacheFiles(J2KDecodeDelegate decode)
{
DirectoryInfo dir = new DirectoryInfo(m_cacheDecodeFolder);
FileInfo[] files = dir.GetFiles("j2kCache_*.cache");
foreach (FileInfo f in files)
{
TimeSpan fileAge = DateTime.Now - f.CreationTime;
if (m_cacheTimeout != 0 && fileAge >= TimeSpan.FromMinutes(m_cacheTimeout))
{
File.Delete(f.Name);
decode(AssetIdFromFileName(f.Name));
System.Threading.Thread.Sleep(5000);
}
}
return false;
}
}
}

View File

@ -325,7 +325,7 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture
IJ2KDecoder cacheLayerDecode = scene.RequestModuleInterface<IJ2KDecoder>();
if (cacheLayerDecode != null)
{
cacheLayerDecode.syncdecode(asset.FullID, asset.Data);
cacheLayerDecode.Decode(asset.FullID, asset.Data);
cacheLayerDecode = null;
LastAssetID = asset.FullID;
}

View File

@ -30,12 +30,11 @@ using OpenMetaverse.Imaging;
namespace OpenSim.Region.Framework.Interfaces
{
public delegate void DecodedCallback(UUID AssetId, OpenJPEG.J2KLayerInfo[] layers);
public interface IJ2KDecoder
{
void decode(UUID AssetId, byte[] assetData, DecodedCallback decodedReturn);
void syncdecode(UUID AssetId, byte[] j2kdata);
void BeginDecode(UUID assetID, byte[] j2kData, DecodedCallback callback);
void Decode(UUID assetID, byte[] j2kData);
}
}

View File

@ -652,7 +652,7 @@ namespace OpenSim.Region.Framework.Scenes
AssetBase ab = sn.AssetService.Get(arrassets[i].ToString());
if (ab != null && ab.Data != null)
{
j2kdecode.syncdecode(arrassets[i], ab.Data);
j2kdecode.Decode(arrassets[i], ab.Data);
}
}
ThreadTracker.Remove(thisthread);

BIN
bin/CSJ2K.dll Normal file

Binary file not shown.

View File

@ -1503,6 +1503,7 @@
<Reference name="OpenMetaverseTypes.dll"/>
<Reference name="OpenMetaverse.StructuredData.dll"/>
<Reference name="OpenMetaverse.dll"/>
<Reference name="CSJ2K.dll"/>
<Reference name="OpenSim.Framework"/>
<Reference name="OpenSim.Framework.Capabilities"/>
<Reference name="OpenSim.Framework.Communications"/>