* Rewrote LLImageManager to use a real priority queue and hold minimal state
* Rewrote the logic in J2KImage.RunUpdate() * Added a default avatar texture (I made it myself)prioritization
parent
44776fea72
commit
6e0c79b8fe
|
@ -38,44 +38,37 @@ using System.Reflection;
|
||||||
namespace OpenSim.Region.ClientStack.LindenUDP
|
namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// We use this class to store image data and associated request data and attributes
|
/// Stores information about a current texture download and a reference to the texture asset
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class J2KImage
|
public class J2KImage
|
||||||
{
|
{
|
||||||
|
private const int IMAGE_PACKET_SIZE = 1000;
|
||||||
|
private const int FIRST_PACKET_SIZE = 600;
|
||||||
|
|
||||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
public double m_designatedPriorityKey;
|
public uint m_lastSequence;
|
||||||
public double m_requestedPriority = 0.0d;
|
public float m_requestedPriority;
|
||||||
public uint m_lastSequence = 0;
|
|
||||||
public uint m_requestedPacketNumber;
|
public uint m_requestedPacketNumber;
|
||||||
public sbyte m_requestedDiscardLevel;
|
public sbyte m_requestedDiscardLevel;
|
||||||
public UUID m_requestedUUID;
|
public UUID m_requestedUUID;
|
||||||
public IJ2KDecoder m_j2kDecodeModule;
|
public IJ2KDecoder m_j2kDecodeModule;
|
||||||
public IAssetService m_assetCache;
|
public IAssetService m_assetCache;
|
||||||
public OpenJPEG.J2KLayerInfo[] Layers = new OpenJPEG.J2KLayerInfo[0];
|
public OpenJPEG.J2KLayerInfo[] m_layers;
|
||||||
public AssetBase m_MissingSubstitute = null;
|
public bool m_decoded;
|
||||||
public bool m_decoded = false;
|
public bool m_hasasset;
|
||||||
public bool m_completedSendAtCurrentDiscardLevel;
|
public C5.IPriorityQueueHandle<J2KImage> m_priorityQueueHandle;
|
||||||
|
|
||||||
private sbyte m_discardLevel=-1;
|
|
||||||
private uint m_packetNumber;
|
private uint m_packetNumber;
|
||||||
private bool m_decoderequested = false;
|
private bool m_decoderequested;
|
||||||
public bool m_hasasset = false;
|
private bool m_asset_requested;
|
||||||
private bool m_asset_requested = false;
|
private bool m_sentinfo;
|
||||||
private bool m_sentinfo = false;
|
private uint m_stopPacket;
|
||||||
private uint m_stopPacket = 0;
|
private AssetBase m_asset;
|
||||||
private const int cImagePacketSize = 1000;
|
private int m_assetDataLength;
|
||||||
private const int cFirstPacketSize = 600;
|
private LLImageManager m_imageManager;
|
||||||
|
|
||||||
private AssetBase m_asset = null;
|
#region Properties
|
||||||
private int m_assetDataLength = 0;
|
|
||||||
|
|
||||||
private LLImageManager m_image;
|
|
||||||
|
|
||||||
public J2KImage(LLImageManager image)
|
|
||||||
{
|
|
||||||
m_image = image;
|
|
||||||
}
|
|
||||||
|
|
||||||
public uint m_pPacketNumber
|
public uint m_pPacketNumber
|
||||||
{
|
{
|
||||||
|
@ -101,9 +94,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
{
|
{
|
||||||
if (!m_decoded)
|
if (!m_decoded)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return (ushort)(((m_assetDataLength - cFirstPacketSize + cImagePacketSize - 1) / cImagePacketSize) + 1);
|
return (ushort)(((m_assetDataLength - FIRST_PACKET_SIZE + IMAGE_PACKET_SIZE - 1) / IMAGE_PACKET_SIZE) + 1);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
@ -114,171 +108,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DropAsset()
|
#endregion Properties
|
||||||
|
|
||||||
|
public J2KImage(LLImageManager imageManager)
|
||||||
{
|
{
|
||||||
//m_log.WarnFormat("[LLIMAGE MANAGER]: Dropping texture asset {0}", m_requestedUUID);
|
m_imageManager = imageManager;
|
||||||
m_asset = null;
|
|
||||||
m_hasasset = false;
|
|
||||||
m_asset_requested = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void J2KDecodedCallback(UUID AssetId, OpenJPEG.J2KLayerInfo[] layers)
|
|
||||||
{
|
|
||||||
m_image.m_outstandingtextures++;
|
|
||||||
Layers = layers;
|
|
||||||
m_decoded = true;
|
|
||||||
RunUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AssetDataCallback(UUID AssetID, AssetBase asset)
|
|
||||||
{
|
|
||||||
m_hasasset = true;
|
|
||||||
if (asset == null || asset.Data == null)
|
|
||||||
{
|
|
||||||
m_asset = m_MissingSubstitute;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_asset = asset;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_assetDataLength = m_asset.Data.Length;
|
|
||||||
|
|
||||||
RunUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void AssetReceived(string id, Object sender, AssetBase asset)
|
|
||||||
{
|
|
||||||
UUID assetID = UUID.Zero;
|
|
||||||
if (asset != null)
|
|
||||||
assetID = asset.FullID;
|
|
||||||
|
|
||||||
AssetDataCallback(assetID, asset);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private int GetPacketForBytePosition(int bytePosition)
|
|
||||||
{
|
|
||||||
return ((bytePosition - cFirstPacketSize + cImagePacketSize - 1) / cImagePacketSize) + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int LastPacketSize()
|
|
||||||
{
|
|
||||||
if (m_packetNumber == 1)
|
|
||||||
return m_assetDataLength;
|
|
||||||
int lastsize = (m_assetDataLength - cFirstPacketSize) % cImagePacketSize;
|
|
||||||
//If the last packet size is zero, it's really cImagePacketSize, it sits on the boundary
|
|
||||||
if (lastsize == 0)
|
|
||||||
{
|
|
||||||
lastsize = cImagePacketSize;
|
|
||||||
}
|
|
||||||
return lastsize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int CurrentBytePosition()
|
|
||||||
{
|
|
||||||
if (m_packetNumber == 0)
|
|
||||||
return 0;
|
|
||||||
if (m_packetNumber == 1)
|
|
||||||
return cFirstPacketSize;
|
|
||||||
|
|
||||||
int result = cFirstPacketSize + ((int)m_packetNumber - 2) * cImagePacketSize;
|
|
||||||
if (result < 0)
|
|
||||||
{
|
|
||||||
result = cFirstPacketSize;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool SendFirstPacket(LLClientView client)
|
|
||||||
{
|
|
||||||
// this means we don't have
|
|
||||||
if (Data == null)
|
|
||||||
{
|
|
||||||
client.SendImageNotFound(m_requestedUUID);
|
|
||||||
m_log.WarnFormat("[TEXTURE]: Got null Data element on a asset {0}.. and the missing image Data property is al", m_requestedUUID);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// Do we have less then 1 packet's worth of data?
|
|
||||||
else if (m_assetDataLength <= cFirstPacketSize)
|
|
||||||
{
|
|
||||||
// Send only 1 packet
|
|
||||||
client.SendImageFirstPart(1, m_requestedUUID, (uint)m_assetDataLength, m_asset.Data, 2);
|
|
||||||
m_stopPacket = 0;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
byte[] firstImageData = new byte[cFirstPacketSize];
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Buffer.BlockCopy(m_asset.Data, 0, firstImageData, 0, (int)cFirstPacketSize);
|
|
||||||
client.SendImageFirstPart(TexturePacketCount(), m_requestedUUID, (uint)m_assetDataLength, firstImageData, 2);
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
m_log.Error("Texture block copy failed. Possibly out of memory?");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool SendPacket(LLClientView client)
|
|
||||||
{
|
|
||||||
bool complete = false;
|
|
||||||
int imagePacketSize = ((int)m_packetNumber == (TexturePacketCount())) ? LastPacketSize() : cImagePacketSize;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if ((CurrentBytePosition() + cImagePacketSize) > m_assetDataLength)
|
|
||||||
{
|
|
||||||
imagePacketSize = LastPacketSize();
|
|
||||||
complete=true;
|
|
||||||
if ((CurrentBytePosition() + imagePacketSize) > m_assetDataLength)
|
|
||||||
{
|
|
||||||
imagePacketSize = m_assetDataLength - CurrentBytePosition();
|
|
||||||
complete = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// It's concievable that the client might request packet one
|
|
||||||
// from a one packet image, which is really packet 0,
|
|
||||||
// which would leave us with a negative imagePacketSize..
|
|
||||||
if (imagePacketSize > 0)
|
|
||||||
{
|
|
||||||
byte[] imageData = new byte[imagePacketSize];
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Buffer.BlockCopy(m_asset.Data, CurrentBytePosition(), imageData, 0, imagePacketSize);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
m_log.Error("Error copying texture block. Out of memory? imagePacketSize was " + imagePacketSize.ToString() + " on packet " + m_packetNumber.ToString() + " out of " + m_stopPacket.ToString() + ". Exception: " + e.ToString());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Send the packet
|
|
||||||
client.SendImageNextPart((ushort)(m_packetNumber-1), m_requestedUUID, imageData);
|
|
||||||
}
|
|
||||||
if (complete)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public bool SendPackets(LLClientView client, int maxpack)
|
public bool SendPackets(LLClientView client, int maxpack)
|
||||||
{
|
|
||||||
|
|
||||||
if (!m_completedSendAtCurrentDiscardLevel)
|
|
||||||
{
|
{
|
||||||
if (m_packetNumber <= m_stopPacket)
|
if (m_packetNumber <= m_stopPacket)
|
||||||
{
|
{
|
||||||
|
@ -307,11 +144,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_packetNumber > m_stopPacket)
|
if (m_packetNumber > m_stopPacket)
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,19 +158,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
|
|
||||||
if (!m_hasasset)
|
if (!m_hasasset)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!m_asset_requested)
|
if (!m_asset_requested)
|
||||||
{
|
{
|
||||||
m_asset_requested = true;
|
m_asset_requested = true;
|
||||||
m_assetCache.Get(m_requestedUUID.ToString(), this, AssetReceived);
|
m_assetCache.Get(m_requestedUUID.ToString(), this, AssetReceived);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
if (!m_decoded)
|
if (!m_decoded)
|
||||||
{
|
{
|
||||||
//We need to decode the requested image first
|
//We need to decode the requested image first
|
||||||
|
@ -362,30 +192,32 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
J2KDecodedCallback(m_requestedUUID, new OpenJPEG.J2KLayerInfo[0]);
|
J2KDecodedCallback(m_requestedUUID, new OpenJPEG.J2KLayerInfo[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Check for missing image asset data
|
||||||
|
if (m_asset == null || m_asset.Data == null)
|
||||||
|
{
|
||||||
|
// FIXME:
|
||||||
|
m_packetNumber = m_stopPacket;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
if (m_requestedDiscardLevel >= 0 || m_stopPacket == 0)
|
||||||
else
|
|
||||||
{
|
{
|
||||||
//discardLevel of -1 means just update the priority
|
int maxDiscardLevel = Math.Max(0, m_layers.Length - 1);
|
||||||
if (m_requestedDiscardLevel != -1)
|
|
||||||
{
|
// Treat initial texture downloads with a DiscardLevel of -1 a request for the highest DiscardLevel
|
||||||
//Evaluate the discard level
|
if (m_requestedDiscardLevel < 0 && m_stopPacket == 0)
|
||||||
//First, is it positive?
|
m_requestedDiscardLevel = (sbyte)maxDiscardLevel;
|
||||||
if (m_requestedDiscardLevel >= 0)
|
|
||||||
{
|
// Clamp at the highest discard level
|
||||||
if (m_requestedDiscardLevel > Layers.Length - 1)
|
m_requestedDiscardLevel = (sbyte)Math.Min(m_requestedDiscardLevel, maxDiscardLevel);
|
||||||
{
|
|
||||||
m_discardLevel = (sbyte)(Layers.Length - 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_discardLevel = m_requestedDiscardLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Calculate the m_stopPacket
|
//Calculate the m_stopPacket
|
||||||
if (Layers.Length > 0)
|
if (m_layers.Length > 0)
|
||||||
{
|
{
|
||||||
m_stopPacket = (uint)GetPacketForBytePosition(Layers[(Layers.Length - 1) - m_discardLevel].End);
|
m_stopPacket = (uint)GetPacketForBytePosition(m_layers[(m_layers.Length - 1) - m_requestedDiscardLevel].End);
|
||||||
//I don't know why, but the viewer seems to expect the final packet if the file
|
//I don't know why, but the viewer seems to expect the final packet if the file
|
||||||
//is just one packet bigger.
|
//is just one packet bigger.
|
||||||
if (TexturePacketCount() == m_stopPacket + 1)
|
if (TexturePacketCount() == m_stopPacket + 1)
|
||||||
|
@ -397,24 +229,165 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
{
|
{
|
||||||
m_stopPacket = TexturePacketCount();
|
m_stopPacket = TexturePacketCount();
|
||||||
}
|
}
|
||||||
//Don't reset packet number unless we're waiting or it's ahead of us
|
|
||||||
if (m_completedSendAtCurrentDiscardLevel || m_requestedPacketNumber>m_packetNumber)
|
|
||||||
{
|
|
||||||
m_packetNumber = m_requestedPacketNumber;
|
m_packetNumber = m_requestedPacketNumber;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (m_packetNumber <= m_stopPacket)
|
private bool SendPacket(LLClientView client)
|
||||||
{
|
{
|
||||||
m_completedSendAtCurrentDiscardLevel = false;
|
bool complete = false;
|
||||||
|
int imagePacketSize = ((int)m_packetNumber == (TexturePacketCount())) ? LastPacketSize() : IMAGE_PACKET_SIZE;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if ((CurrentBytePosition() + IMAGE_PACKET_SIZE) > m_assetDataLength)
|
||||||
|
{
|
||||||
|
imagePacketSize = LastPacketSize();
|
||||||
|
complete = true;
|
||||||
|
if ((CurrentBytePosition() + imagePacketSize) > m_assetDataLength)
|
||||||
|
{
|
||||||
|
imagePacketSize = m_assetDataLength - CurrentBytePosition();
|
||||||
|
complete = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// It's concievable that the client might request packet one
|
||||||
|
// from a one packet image, which is really packet 0,
|
||||||
|
// which would leave us with a negative imagePacketSize..
|
||||||
|
if (imagePacketSize > 0)
|
||||||
|
{
|
||||||
|
byte[] imageData = new byte[imagePacketSize];
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Buffer.BlockCopy(m_asset.Data, CurrentBytePosition(), imageData, 0, imagePacketSize);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
m_log.Error("Error copying texture block. Out of memory? imagePacketSize was " + imagePacketSize.ToString() + " on packet " + m_packetNumber.ToString() + " out of " + m_stopPacket.ToString() + ". Exception: " + e.ToString());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Send the packet
|
||||||
|
client.SendImageNextPart((ushort)(m_packetNumber - 1), m_requestedUUID, imageData);
|
||||||
|
}
|
||||||
|
if (complete)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_packetNumber = m_stopPacket;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int GetPacketForBytePosition(int bytePosition)
|
||||||
|
{
|
||||||
|
return ((bytePosition - FIRST_PACKET_SIZE + IMAGE_PACKET_SIZE - 1) / IMAGE_PACKET_SIZE) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int LastPacketSize()
|
||||||
|
{
|
||||||
|
if (m_packetNumber == 1)
|
||||||
|
return m_assetDataLength;
|
||||||
|
int lastsize = (m_assetDataLength - FIRST_PACKET_SIZE) % IMAGE_PACKET_SIZE;
|
||||||
|
//If the last packet size is zero, it's really cImagePacketSize, it sits on the boundary
|
||||||
|
if (lastsize == 0)
|
||||||
|
{
|
||||||
|
lastsize = IMAGE_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
return lastsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int CurrentBytePosition()
|
||||||
|
{
|
||||||
|
if (m_packetNumber == 0)
|
||||||
|
return 0;
|
||||||
|
if (m_packetNumber == 1)
|
||||||
|
return FIRST_PACKET_SIZE;
|
||||||
|
|
||||||
|
int result = FIRST_PACKET_SIZE + ((int)m_packetNumber - 2) * IMAGE_PACKET_SIZE;
|
||||||
|
if (result < 0)
|
||||||
|
{
|
||||||
|
result = FIRST_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool SendFirstPacket(LLClientView client)
|
||||||
|
{
|
||||||
|
// this means we don't have
|
||||||
|
if (Data == null)
|
||||||
|
{
|
||||||
|
client.SendImageNotFound(m_requestedUUID);
|
||||||
|
m_log.WarnFormat("[TEXTURE]: Got null Data element on a asset {0}.. and the missing image Data property is al", m_requestedUUID);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Do we have less then 1 packet's worth of data?
|
||||||
|
else if (m_assetDataLength <= FIRST_PACKET_SIZE)
|
||||||
|
{
|
||||||
|
// Send only 1 packet
|
||||||
|
client.SendImageFirstPart(1, m_requestedUUID, (uint)m_assetDataLength, m_asset.Data, 2);
|
||||||
|
m_stopPacket = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
byte[] firstImageData = new byte[FIRST_PACKET_SIZE];
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Buffer.BlockCopy(m_asset.Data, 0, firstImageData, 0, (int)FIRST_PACKET_SIZE);
|
||||||
|
client.SendImageFirstPart(TexturePacketCount(), m_requestedUUID, (uint)m_assetDataLength, firstImageData, 2);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
m_log.Error("Texture block copy failed. Possibly out of memory?");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void J2KDecodedCallback(UUID AssetId, OpenJPEG.J2KLayerInfo[] layers)
|
||||||
|
{
|
||||||
|
m_layers = layers;
|
||||||
|
m_decoded = true;
|
||||||
|
RunUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AssetDataCallback(UUID AssetID, AssetBase asset)
|
||||||
|
{
|
||||||
|
m_hasasset = true;
|
||||||
|
|
||||||
|
if (asset == null || asset.Data == null)
|
||||||
|
{
|
||||||
|
m_asset = null;
|
||||||
|
m_decoded = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_asset = asset;
|
||||||
|
m_assetDataLength = m_asset.Data.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
RunUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AssetReceived(string id, Object sender, AssetBase asset)
|
||||||
|
{
|
||||||
|
UUID assetID = UUID.Zero;
|
||||||
|
if (asset != null)
|
||||||
|
assetID = asset.FullID;
|
||||||
|
|
||||||
|
AssetDataCallback(assetID, asset);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,26 +27,28 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
using OpenMetaverse;
|
using OpenMetaverse;
|
||||||
using OpenMetaverse.Imaging;
|
using OpenMetaverse.Imaging;
|
||||||
using OpenSim.Framework;
|
using OpenSim.Framework;
|
||||||
using OpenSim.Region.Framework.Interfaces;
|
using OpenSim.Region.Framework.Interfaces;
|
||||||
using OpenSim.Services.Interfaces;
|
using OpenSim.Services.Interfaces;
|
||||||
using log4net;
|
using log4net;
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace OpenSim.Region.ClientStack.LindenUDP
|
namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
{
|
{
|
||||||
|
|
||||||
public class LLImageManager
|
public class LLImageManager
|
||||||
{
|
{
|
||||||
|
private sealed class J2KImageComparer : IComparer<J2KImage>
|
||||||
|
{
|
||||||
|
public int Compare(J2KImage x, J2KImage y)
|
||||||
|
{
|
||||||
|
return x.m_requestedPriority.CompareTo(y.m_requestedPriority);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Public interfaces:
|
|
||||||
//Constructor - (LLClientView, IAssetCache, IJ2KDecoder);
|
|
||||||
//void EnqueueReq - (TextureRequestArgs)
|
|
||||||
//ProcessImageQueue
|
|
||||||
//Close
|
|
||||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
private bool m_shuttingdown = false;
|
private bool m_shuttingdown = false;
|
||||||
private long m_lastloopprocessed = 0;
|
private long m_lastloopprocessed = 0;
|
||||||
|
@ -54,28 +56,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
private LLClientView m_client; //Client we're assigned to
|
private LLClientView m_client; //Client we're assigned to
|
||||||
private IAssetService m_assetCache; //Asset Cache
|
private IAssetService m_assetCache; //Asset Cache
|
||||||
private IJ2KDecoder m_j2kDecodeModule; //Our J2K module
|
private IJ2KDecoder m_j2kDecodeModule; //Our J2K module
|
||||||
|
private C5.IntervalHeap<J2KImage> m_priorityQueue = new C5.IntervalHeap<J2KImage>(10, new J2KImageComparer());
|
||||||
|
|
||||||
private readonly AssetBase m_missingsubstitute; //Sustitute for bad decodes
|
|
||||||
private Dictionary<UUID,J2KImage> m_imagestore; // Our main image storage dictionary
|
|
||||||
private SortedList<double,UUID> m_priorities; // For fast image lookup based on priority
|
|
||||||
private Dictionary<int, int> m_priorityresolver; //Enabling super fast assignment of images with the same priorities
|
|
||||||
|
|
||||||
private const double doubleMinimum = .0000001;
|
|
||||||
|
|
||||||
public int m_outstandingtextures = 0;
|
|
||||||
//Constructor
|
|
||||||
public LLImageManager(LLClientView client, IAssetService pAssetCache, IJ2KDecoder pJ2kDecodeModule)
|
public LLImageManager(LLClientView client, IAssetService pAssetCache, IJ2KDecoder pJ2kDecodeModule)
|
||||||
{
|
{
|
||||||
|
|
||||||
m_imagestore = new Dictionary<UUID,J2KImage>();
|
|
||||||
m_priorities = new SortedList<double,UUID>();
|
|
||||||
m_priorityresolver = new Dictionary<int, int>();
|
|
||||||
m_client = client;
|
m_client = client;
|
||||||
m_assetCache = pAssetCache;
|
m_assetCache = pAssetCache;
|
||||||
if (pAssetCache != null)
|
|
||||||
m_missingsubstitute = pAssetCache.Get("5748decc-f629-461c-9a36-a35a221fe21f");
|
|
||||||
else
|
|
||||||
m_log.Error("[ClientView] - couldn't set missing image, all manner of things will probably break");
|
|
||||||
m_j2kDecodeModule = pJ2kDecodeModule;
|
m_j2kDecodeModule = pJ2kDecodeModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,59 +74,61 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
//Make sure we're not shutting down..
|
//Make sure we're not shutting down..
|
||||||
if (!m_shuttingdown)
|
if (!m_shuttingdown)
|
||||||
{
|
{
|
||||||
|
J2KImage imgrequest;
|
||||||
|
|
||||||
//Do we already know about this UUID?
|
// Do a linear search for this texture download
|
||||||
if (m_imagestore.ContainsKey(newRequest.RequestedAssetID))
|
m_priorityQueue.Find(delegate(J2KImage img) { return img.m_requestedUUID == newRequest.RequestedAssetID; }, out imgrequest);
|
||||||
|
|
||||||
|
if (imgrequest != null)
|
||||||
{
|
{
|
||||||
|
if (newRequest.DiscardLevel == -1 && newRequest.Priority == 0f)
|
||||||
|
{
|
||||||
|
m_log.Debug("[JPEG2000]: (CAN) ID=" + newRequest.RequestedAssetID);
|
||||||
|
|
||||||
|
try { m_priorityQueue.Delete(imgrequest.m_priorityQueueHandle); }
|
||||||
|
catch (Exception) { }
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[JPEG2000]: (UPD) ID={0}: D={1}, S={2}, P={3}",
|
||||||
|
newRequest.RequestedAssetID, newRequest.DiscardLevel, newRequest.PacketNumber, newRequest.Priority);
|
||||||
|
|
||||||
//Check the packet sequence to make sure this isn't older than
|
//Check the packet sequence to make sure this isn't older than
|
||||||
//one we've already received
|
//one we've already received
|
||||||
|
|
||||||
J2KImage imgrequest = m_imagestore[newRequest.RequestedAssetID];
|
|
||||||
|
|
||||||
// This is the inbound request sequence number. We can ignore
|
|
||||||
// "old" ones.
|
|
||||||
|
|
||||||
if (newRequest.requestSequence > imgrequest.m_lastSequence)
|
if (newRequest.requestSequence > imgrequest.m_lastSequence)
|
||||||
{
|
{
|
||||||
|
//Update the sequence number of the last RequestImage packet
|
||||||
imgrequest.m_lastSequence = newRequest.requestSequence;
|
imgrequest.m_lastSequence = newRequest.requestSequence;
|
||||||
|
|
||||||
//Check the priority
|
|
||||||
|
|
||||||
double priority = imgrequest.m_requestedPriority;
|
|
||||||
if (priority != newRequest.Priority)
|
|
||||||
{
|
|
||||||
//Remove the old priority
|
|
||||||
m_priorities.Remove(imgrequest.m_designatedPriorityKey);
|
|
||||||
//Assign a new unique priority
|
|
||||||
imgrequest.m_requestedPriority = newRequest.Priority;
|
|
||||||
imgrequest.m_designatedPriorityKey = AssignPriority(newRequest.RequestedAssetID, newRequest.Priority);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Update the requested discard level
|
//Update the requested discard level
|
||||||
imgrequest.m_requestedDiscardLevel = newRequest.DiscardLevel;
|
imgrequest.m_requestedDiscardLevel = newRequest.DiscardLevel;
|
||||||
|
|
||||||
//Update the requested packet number
|
//Update the requested packet number
|
||||||
imgrequest.m_requestedPacketNumber = newRequest.PacketNumber;
|
imgrequest.m_requestedPacketNumber = newRequest.PacketNumber;
|
||||||
|
|
||||||
//Check if this will create an outstanding texture request
|
//Update the requested priority
|
||||||
bool activated = imgrequest.m_completedSendAtCurrentDiscardLevel;
|
imgrequest.m_requestedPriority = newRequest.Priority;
|
||||||
|
try { m_priorityQueue.Replace(imgrequest.m_priorityQueueHandle, imgrequest); }
|
||||||
|
catch (Exception) { imgrequest.m_priorityQueueHandle = null; m_priorityQueue.Add(ref imgrequest.m_priorityQueueHandle, imgrequest); }
|
||||||
|
|
||||||
//Run an update
|
//Run an update
|
||||||
|
|
||||||
imgrequest.RunUpdate();
|
imgrequest.RunUpdate();
|
||||||
|
|
||||||
if (activated && !imgrequest.m_completedSendAtCurrentDiscardLevel && imgrequest.m_decoded)
|
|
||||||
{
|
|
||||||
Interlocked.Increment(ref m_outstandingtextures);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
J2KImage imgrequest = new J2KImage(this);
|
if (newRequest.DiscardLevel == -1 && newRequest.Priority == 0f)
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[JPEG2000]: (IGN) ID={0}: D={1}, S={2}, P={3}",
|
||||||
|
newRequest.RequestedAssetID, newRequest.DiscardLevel, newRequest.PacketNumber, newRequest.Priority);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[JPEG2000]: (NEW) ID={0}: D={1}, S={2}, P={3}",
|
||||||
|
newRequest.RequestedAssetID, newRequest.DiscardLevel, newRequest.PacketNumber, newRequest.Priority);
|
||||||
|
|
||||||
//Assign our missing substitute
|
imgrequest = new J2KImage(this);
|
||||||
imgrequest.m_MissingSubstitute = m_missingsubstitute;
|
|
||||||
|
|
||||||
//Assign our decoder module
|
//Assign our decoder module
|
||||||
imgrequest.m_j2kDecodeModule = m_j2kDecodeModule;
|
imgrequest.m_j2kDecodeModule = m_j2kDecodeModule;
|
||||||
|
@ -148,9 +136,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
//Assign our asset cache module
|
//Assign our asset cache module
|
||||||
imgrequest.m_assetCache = m_assetCache;
|
imgrequest.m_assetCache = m_assetCache;
|
||||||
|
|
||||||
//Assign a priority based on our request
|
|
||||||
imgrequest.m_designatedPriorityKey = AssignPriority(newRequest.RequestedAssetID, newRequest.Priority);
|
|
||||||
|
|
||||||
//Assign the requested discard level
|
//Assign the requested discard level
|
||||||
imgrequest.m_requestedDiscardLevel = newRequest.DiscardLevel;
|
imgrequest.m_requestedDiscardLevel = newRequest.DiscardLevel;
|
||||||
|
|
||||||
|
@ -163,49 +148,29 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
//Assign the asset uuid
|
//Assign the asset uuid
|
||||||
imgrequest.m_requestedUUID = newRequest.RequestedAssetID;
|
imgrequest.m_requestedUUID = newRequest.RequestedAssetID;
|
||||||
|
|
||||||
m_imagestore.Add(imgrequest.m_requestedUUID, imgrequest);
|
//Assign the requested priority
|
||||||
|
imgrequest.m_requestedPriority = newRequest.Priority;
|
||||||
|
|
||||||
|
//Add this download to the priority queue
|
||||||
|
m_priorityQueue.Add(ref imgrequest.m_priorityQueueHandle, imgrequest);
|
||||||
|
|
||||||
//Run an update
|
//Run an update
|
||||||
imgrequest.RunUpdate();
|
imgrequest.RunUpdate();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private double AssignPriority(UUID pAssetID, double pPriority)
|
|
||||||
{
|
|
||||||
|
|
||||||
//First, find out if we can just assign directly
|
|
||||||
if (m_priorityresolver.ContainsKey((int)pPriority) == false)
|
|
||||||
{
|
|
||||||
m_priorities.Add((double)((int)pPriority), pAssetID);
|
|
||||||
m_priorityresolver.Add((int)pPriority, 0);
|
|
||||||
return (double)((int)pPriority);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//Use the hash lookup goodness of a secondary dictionary to find a free slot
|
|
||||||
double mFreePriority = ((int)pPriority) + (doubleMinimum * (m_priorityresolver[(int)pPriority] + 1));
|
|
||||||
m_priorities[mFreePriority] = pAssetID;
|
|
||||||
m_priorityresolver[(int)pPriority]++;
|
|
||||||
return mFreePriority;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ProcessImageQueue(int count, int maxpack)
|
public bool ProcessImageQueue(int count, int maxpack)
|
||||||
{
|
{
|
||||||
|
//count is the number of textures we want to process in one go.
|
||||||
|
//As part of this class re-write, that number will probably rise
|
||||||
|
//since we're processing in a more efficient manner.
|
||||||
|
|
||||||
// this can happen during Close()
|
// this can happen during Close()
|
||||||
if (m_client == null)
|
if (m_client == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
//Count is the number of textures we want to process in one go.
|
|
||||||
//As part of this class re-write, that number will probably rise
|
|
||||||
//since we're processing in a more efficient manner.
|
|
||||||
|
|
||||||
int numCollected = 0;
|
int numCollected = 0;
|
||||||
|
|
||||||
//Calculate our threshold
|
//Calculate our threshold
|
||||||
|
@ -232,30 +197,24 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (threshold < 10)
|
|
||||||
{
|
|
||||||
threshold = 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_client.PacketHandler == null)
|
if (m_client.PacketHandler == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (m_client.PacketHandler.PacketQueue == null)
|
if (m_client.PacketHandler.PacketQueue == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
//First of all make sure our packet queue isn't above our threshold
|
if (threshold < 10)
|
||||||
|
threshold = 10;
|
||||||
|
|
||||||
//Uncomment this to see what the texture stack is doing
|
//Uncomment this to see what the texture stack is doing
|
||||||
//m_log.Debug("Queue: " + m_client.PacketHandler.PacketQueue.TextureOutgoingPacketQueueCount.ToString() + " Threshold: " + threshold.ToString() + " outstanding: " + m_outstandingtextures.ToString());
|
//m_log.Debug("Queue: " + m_client.PacketHandler.PacketQueue.TextureOutgoingPacketQueueCount.ToString() + " Threshold: " + threshold.ToString() + " outstanding: " + m_outstandingtextures.ToString());
|
||||||
if (m_client.PacketHandler.PacketQueue.TextureOutgoingPacketQueueCount < threshold && m_outstandingtextures > 0)
|
if (m_client.PacketHandler.PacketQueue.TextureOutgoingPacketQueueCount < threshold)
|
||||||
{
|
{
|
||||||
bool justreset = false;
|
while (m_priorityQueue.Count > 0)
|
||||||
|
|
||||||
for (int x = m_priorities.Count - 1; x > -1; x--)
|
|
||||||
{
|
{
|
||||||
|
J2KImage imagereq = m_priorityQueue.FindMax();
|
||||||
|
|
||||||
J2KImage imagereq = m_imagestore[m_priorities.Values[x]];
|
if (imagereq.m_decoded == true)
|
||||||
if (imagereq.m_decoded == true && !imagereq.m_completedSendAtCurrentDiscardLevel)
|
|
||||||
{
|
{
|
||||||
// we need to test this here now that we are dropping assets
|
// we need to test this here now that we are dropping assets
|
||||||
if (!imagereq.m_hasasset)
|
if (!imagereq.m_hasasset)
|
||||||
|
@ -265,72 +224,23 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
numCollected++;
|
++numCollected;
|
||||||
|
|
||||||
//SendPackets will send up to ten packets per cycle
|
//SendPackets will send up to ten packets per cycle
|
||||||
if (imagereq.SendPackets(m_client, maxpack))
|
if (imagereq.SendPackets(m_client, maxpack))
|
||||||
{
|
{
|
||||||
//Send complete
|
// Send complete. Destroy any knowledge of this transfer
|
||||||
if (!imagereq.m_completedSendAtCurrentDiscardLevel)
|
try { m_priorityQueue.Delete(imagereq.m_priorityQueueHandle); }
|
||||||
{
|
catch (Exception) { }
|
||||||
// I think this field imagereq.m_completedSendAtCurrentDiscardLevel
|
}
|
||||||
// is completely redundant
|
}
|
||||||
//imagereq.m_completedSendAtCurrentDiscardLevel = true;
|
|
||||||
|
|
||||||
Interlocked.Decrement(ref m_outstandingtextures);
|
|
||||||
|
|
||||||
// First and foremost, drop the reference to the asset
|
|
||||||
// so that the asset doesn't stay in memory forever.
|
|
||||||
// We'll Get it again from the asset service (usually cache)
|
|
||||||
// if/when the client requests it again.
|
|
||||||
// In order not to mess much with the current implementation
|
|
||||||
// of this management code, we drop only the asset reference
|
|
||||||
// but keep the image request itself.
|
|
||||||
imagereq.DropAsset();
|
|
||||||
|
|
||||||
//Re-assign priority to bottom
|
|
||||||
//Remove the old priority
|
|
||||||
m_priorities.Remove(imagereq.m_designatedPriorityKey);
|
|
||||||
int lowest;
|
|
||||||
if (m_priorities.Count > 0)
|
|
||||||
{
|
|
||||||
lowest = (int)m_priorities.Keys[0];
|
|
||||||
lowest--;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lowest = -10000;
|
|
||||||
}
|
|
||||||
m_priorities.Add((double)lowest, imagereq.m_requestedUUID);
|
|
||||||
imagereq.m_designatedPriorityKey = (double)lowest;
|
|
||||||
if (m_priorityresolver.ContainsKey((int)lowest))
|
|
||||||
{
|
|
||||||
m_priorityresolver[(int)lowest]++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_priorityresolver.Add((int)lowest, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (numCollected == count)
|
if (numCollected == count)
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (numCollected == count || m_outstandingtextures == 0)
|
|
||||||
break;
|
|
||||||
if (numCollected % m_outstandingtextures == 0 && !justreset)
|
|
||||||
{
|
|
||||||
//We've gotten as much as we can from the stack,
|
|
||||||
//reset to the top so that we can send MOAR DATA (nomnomnom)!
|
|
||||||
x = m_priorities.Count - 1;
|
|
||||||
|
|
||||||
justreset = true; //prevents us from getting stuck in a loop
|
return m_priorityQueue.Count > 0;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_outstandingtextures != 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Faux destructor
|
//Faux destructor
|
||||||
|
|
|
@ -161,7 +161,6 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
|
||||||
for (int i = 0; i < layerStarts.Count; i++)
|
for (int i = 0; i < layerStarts.Count; i++)
|
||||||
{
|
{
|
||||||
OpenJPEG.J2KLayerInfo layer = new OpenJPEG.J2KLayerInfo();
|
OpenJPEG.J2KLayerInfo layer = new OpenJPEG.J2KLayerInfo();
|
||||||
int start = layerStarts[i];
|
|
||||||
|
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
layer.Start = 0;
|
layer.Start = 0;
|
||||||
|
|
|
@ -401,4 +401,11 @@
|
||||||
<Key Name="assetType" Value="0" />
|
<Key Name="assetType" Value="0" />
|
||||||
<Key Name="fileName" Value="default_clear.jp2" />
|
<Key Name="fileName" Value="default_clear.jp2" />
|
||||||
</Section>
|
</Section>
|
||||||
|
|
||||||
|
<Section Name="Default Avatar">
|
||||||
|
<Key Name="assetID" Value="c228d1cf-4b5d-4ba8-84f4-899a0796aa97"/>
|
||||||
|
<Key Name="name" Value="Default Avatar"/>
|
||||||
|
<Key Name="assetType" Value="0" />
|
||||||
|
<Key Name="fileName" Value="default_avatar.jp2" />
|
||||||
|
</Section>
|
||||||
</Nini>
|
</Nini>
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue