Revert "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"
This reverts commit 22cc31135e
.
prioritization
parent
8d35cd9061
commit
f908e32f62
|
@ -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;
|
||||
|
@ -195,47 +195,163 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
|
|||
{
|
||||
int DecodeTime = 0;
|
||||
DecodeTime = Environment.TickCount;
|
||||
OpenJPEG.J2KLayerInfo[] layers = null;
|
||||
OpenJPEG.J2KLayerInfo[] layers = new OpenJPEG.J2KLayerInfo[0]; // Dummy result for if it fails. Informs that there's only full quality
|
||||
|
||||
if (!OpenJpegFail)
|
||||
{
|
||||
if (!fCache.TryLoadCacheForAsset(AssetId, out layers))
|
||||
{
|
||||
try
|
||||
{
|
||||
List<int> layerStarts = CSJ2K.J2kImage.GetLayerBoundaries(new MemoryStream(j2kdata));
|
||||
|
||||
if (layerStarts != null && layerStarts.Count > 0)
|
||||
AssetTexture texture = new AssetTexture(AssetId, j2kdata);
|
||||
if (texture.DecodeLayerBoundaries())
|
||||
{
|
||||
layers = new OpenJPEG.J2KLayerInfo[layerStarts.Count];
|
||||
bool sane = true;
|
||||
|
||||
for (int i = 0; i < layerStarts.Count; i++)
|
||||
// Sanity check all of the layers
|
||||
for (int i = 0; i < texture.LayerInfo.Length; i++)
|
||||
{
|
||||
OpenJPEG.J2KLayerInfo layer = new OpenJPEG.J2KLayerInfo();
|
||||
int start = layerStarts[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);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.WarnFormat(
|
||||
"[J2KDecoderModule]: JPEG2000 texture decoding succeeded, but sanity check failed for {0}",
|
||||
AssetId);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
layer.Start = 0;
|
||||
else
|
||||
layer.Start = layerStarts[i];
|
||||
start = 0;
|
||||
|
||||
if (i == layerStarts.Count - 1)
|
||||
layer.End = j2kdata.Length;
|
||||
if (i == texture.LayerInfo.Length - 1)
|
||||
texture.LayerInfo[i].End = texture.AssetData.Length;
|
||||
else
|
||||
layer.End = layerStarts[i + 1] - 1;
|
||||
texture.LayerInfo[i].End = texture.LayerInfo[i + 1].Start - 1;
|
||||
|
||||
layers[i] = layer;
|
||||
// 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);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.WarnFormat("[J2KDecoderModule]: JPEG2000 texture decoding failed for {0}. Is this a texture? is it J2K?", AssetId);
|
||||
}
|
||||
}
|
||||
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.Warn("[J2KDecoderModule]: CSJ2K threw an exception decoding texture " + AssetId + ": " + ex.ToString());
|
||||
m_log.WarnFormat(
|
||||
"[J2KDecoderModule]: JPEG2000 texture decoding threw an exception for {0}, {1}",
|
||||
AssetId, ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (layers.Length == 0)
|
||||
{
|
||||
m_log.Warn("[J2KDecoderModule]: OpenJPEG failed to decode any 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
|
||||
|
@ -244,7 +360,7 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
|
|||
if (m_cacheddecode.ContainsKey(AssetId))
|
||||
m_cacheddecode.Remove(AssetId);
|
||||
m_cacheddecode.Add(AssetId, layers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Notify Interested Parties
|
||||
|
@ -262,31 +378,6 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
|
|||
}
|
||||
}
|
||||
|
||||
private OpenJPEG.J2KLayerInfo[] CreateDefaultLayers(int j2kLength)
|
||||
{
|
||||
OpenJPEG.J2KLayerInfo[] layers = new OpenJPEG.J2KLayerInfo[5];
|
||||
layers[0] = new OpenJPEG.J2KLayerInfo();
|
||||
|
||||
for (int i = 0; i < layers.Length; i++)
|
||||
{
|
||||
OpenJPEG.J2KLayerInfo layer = new OpenJPEG.J2KLayerInfo();
|
||||
|
||||
if (i == 0)
|
||||
layer.Start = 0;
|
||||
else
|
||||
layer.Start = layers[i - 1].End + 1;
|
||||
|
||||
// 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 will probably not gracefully handle all real world data
|
||||
layer.End = (int)(160d * Math.Exp(1.3d * (double)(i + 1)));
|
||||
|
||||
layers[i] = layer;
|
||||
}
|
||||
|
||||
return layers;
|
||||
}
|
||||
|
||||
private void CleanCache()
|
||||
{
|
||||
m_log.Info("[J2KDecoderModule]: Cleaner thread started");
|
||||
|
@ -327,10 +418,11 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
|
|||
{
|
||||
m_cacheDecodeFolder = pFolder;
|
||||
m_cacheTimeout = timeout;
|
||||
|
||||
if (!Directory.Exists(pFolder))
|
||||
{
|
||||
Createj2KCacheFolder(pFolder);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save Layers to Disk Cache
|
||||
|
@ -355,15 +447,14 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -384,9 +475,11 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
|
|||
return false;
|
||||
|
||||
if (!enabled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string readResult = String.Empty;
|
||||
string readResult = string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -400,6 +493,7 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
|
|||
sr.Close();
|
||||
sr.Dispose();
|
||||
fsCachefile.Dispose();
|
||||
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
|
@ -420,6 +514,7 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
|
|||
"[J2KDecodeCache]: Cache Read failed. IO Exception.");
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
|
@ -446,6 +541,7 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
|
|||
m_log.Error(
|
||||
"[J2KDecodeCache]: Cache Read failed, not supported. Cache disabled!");
|
||||
enabled = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -485,6 +581,7 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
|
|||
Layers[i] = new OpenJPEG.J2KLayerInfo();
|
||||
Layers[i].Start = element1;
|
||||
Layers[i].End = element2;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -495,6 +592,9 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
BIN
bin/CSJ2K.dll
BIN
bin/CSJ2K.dll
Binary file not shown.
|
@ -1503,7 +1503,6 @@
|
|||
<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"/>
|
||||
|
|
Loading…
Reference in New Issue