29 using System.Threading;
30 using System.Collections;
31 using System.Collections.Generic;
32 using System.Reflection;
34 using OpenMetaverse.Imaging;
35 using OpenSim.Framework;
36 using OpenSim.Region.Framework.Interfaces;
37 using OpenSim.Services.Interfaces;
40 namespace OpenSim.
Region.ClientStack.LindenUDP
47 private sealed
class J2KImageComparer : IComparer<J2KImage>
51 return x.Priority.CompareTo(y.Priority);
55 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
56 private bool m_shuttingdown;
64 private C5.IntervalHeap<
J2KImage> m_priorityQueue =
new C5.IntervalHeap<
J2KImage>(10,
new J2KImageComparer());
69 private object m_syncRoot =
new object();
76 public AssetBase MissingImage {
get {
return m_missingImage; } }
81 m_assetCache = pAssetCache;
83 if (pAssetCache != null)
84 m_missingImage = pAssetCache.Get(
"5748decc-f629-461c-9a36-a35a221fe21f");
86 if (m_missingImage == null)
87 m_log.Error(
"[ClientView] - Couldn't set missing image asset, falling back to missing image packet. This is known to crash the client");
89 m_j2kDecodeModule = pJ2kDecodeModule;
104 m_priorityQueue.Find(delegate(
J2KImage img) {
return img.TextureID == newRequest.RequestedAssetID; }, out imgrequest);
106 if (imgrequest != null)
115 m_priorityQueue.Delete(imgrequest.PriorityQueueHandle);
117 catch (Exception) { }
133 imgrequest.LastSequence = newRequest.requestSequence;
136 imgrequest.DiscardLevel = newRequest.DiscardLevel;
139 imgrequest.StartPacket = Math.Max(1, newRequest.PacketNumber);
142 imgrequest.Priority = newRequest.Priority;
144 UpdateImageInQueue(imgrequest);
146 imgrequest.RunUpdate();
190 imgrequest.J2KDecoder = m_j2kDecodeModule;
191 imgrequest.AssetService = m_assetCache;
192 imgrequest.AgentID = Client.AgentId;
194 imgrequest.DiscardLevel = newRequest.DiscardLevel;
195 imgrequest.StartPacket = Math.Max(1, newRequest.PacketNumber);
196 imgrequest.Priority = newRequest.Priority;
197 imgrequest.TextureID = newRequest.RequestedAssetID;
198 imgrequest.Priority = newRequest.Priority;
201 AddImageToQueue(imgrequest);
203 imgrequest.RunUpdate();
211 J2KImage image = GetHighestPriorityImage();
213 return image != null && image.IsDecoded;
220 while (packetsSent < packetsToSend)
222 J2KImage image = GetHighestPriorityImage();
231 bool imageDone = image.SendPackets(Client, packetsToSend - packetsSent, out sent);
236 RemoveImageFromQueue(image);
255 return m_priorityQueue.Count > 0;
263 m_shuttingdown =
true;
274 lock (m_priorityQueue)
276 requestsDeleted = m_priorityQueue.Count;
279 while (!m_priorityQueue.IsEmpty)
280 m_priorityQueue.DeleteMax();
283 return requestsDeleted;
292 lock (m_priorityQueue)
293 return m_priorityQueue.ToArray();
296 #region Priority Queue Helpers
298 private J2KImage GetHighestPriorityImage()
304 if (m_priorityQueue.Count > 0)
308 image = m_priorityQueue.FindMax();
310 catch (Exception) { }
316 private void AddImageToQueue(J2KImage image)
318 image.PriorityQueueHandle = null;
324 m_priorityQueue.Add(ref image.PriorityQueueHandle, image);
326 catch (Exception) { }
330 private void RemoveImageFromQueue(J2KImage image)
336 m_priorityQueue.Delete(image.PriorityQueueHandle);
338 catch (Exception) { }
342 private void UpdateImageInQueue(J2KImage image)
348 m_priorityQueue.Replace(image.PriorityQueueHandle, image);
352 image.PriorityQueueHandle = null;
353 m_priorityQueue.Add(ref image.PriorityQueueHandle, image);
358 #endregion Priority Queue Helpers
int ClearImageQueue()
Clear the image queue.
bool ProcessImageQueue(int packetsToSend)
Asset class. All Assets are reference by this class or a class derived from this class ...
Stores information about a current texture download and a reference to the texture asset ...
void EnqueueReq(TextureRequestArgs newRequest)
Handles an incoming texture request or update to an existing texture request
bool IsDecoded
Has this request decoded the asset data?
LLImageManager(IClientAPI client, IAssetService pAssetCache, IJ2KDecoder pJ2kDecodeModule)
This class handles UDP texture requests.
J2KImage[] GetImages()
Returns an array containing all the images in the queue.
void Close()
Faux destructor