2009-02-12 09:53:12 +00:00
|
|
|
/*
|
2009-01-19 18:33:25 +00:00
|
|
|
* Copyright (c) Contributors, http://opensimulator.org/
|
|
|
|
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2009-06-01 06:37:14 +00:00
|
|
|
* * Neither the name of the OpenSimulator Project nor the
|
2009-01-19 18:33:25 +00:00
|
|
|
* names of its contributors may be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
using System;
|
2009-06-25 07:42:06 +00:00
|
|
|
using System.Threading;
|
2009-10-02 00:42:13 +00:00
|
|
|
using System.Collections;
|
2009-01-19 18:33:25 +00:00
|
|
|
using System.Collections.Generic;
|
2009-10-02 00:42:13 +00:00
|
|
|
using System.Reflection;
|
2009-01-19 18:33:25 +00:00
|
|
|
using OpenMetaverse;
|
2009-02-12 09:53:12 +00:00
|
|
|
using OpenMetaverse.Imaging;
|
2009-01-19 18:33:25 +00:00
|
|
|
using OpenSim.Framework;
|
2009-02-06 16:55:34 +00:00
|
|
|
using OpenSim.Region.Framework.Interfaces;
|
2009-05-15 05:00:25 +00:00
|
|
|
using OpenSim.Services.Interfaces;
|
2009-02-22 20:52:55 +00:00
|
|
|
using log4net;
|
2009-01-19 18:33:25 +00:00
|
|
|
|
|
|
|
namespace OpenSim.Region.ClientStack.LindenUDP
|
|
|
|
{
|
2012-01-02 19:46:30 +00:00
|
|
|
/// <summary>
|
|
|
|
/// This class handles UDP texture requests.
|
|
|
|
/// </summary>
|
2009-01-19 18:33:25 +00:00
|
|
|
public class LLImageManager
|
|
|
|
{
|
2009-10-02 00:42:13 +00:00
|
|
|
private sealed class J2KImageComparer : IComparer<J2KImage>
|
|
|
|
{
|
|
|
|
public int Compare(J2KImage x, J2KImage y)
|
|
|
|
{
|
2009-10-02 20:08:15 +00:00
|
|
|
return x.Priority.CompareTo(y.Priority);
|
2009-10-02 00:42:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-10 08:30:21 +00:00
|
|
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
2009-10-02 23:53:35 +00:00
|
|
|
private bool m_shuttingdown;
|
|
|
|
private AssetBase m_missingImage;
|
2012-01-19 21:57:12 +00:00
|
|
|
private IAssetService m_assetCache;
|
|
|
|
private IJ2KDecoder m_j2kDecodeModule;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Priority queue for determining which image to send first.
|
|
|
|
/// </summary>
|
2009-10-02 00:42:13 +00:00
|
|
|
private C5.IntervalHeap<J2KImage> m_priorityQueue = new C5.IntervalHeap<J2KImage>(10, new J2KImageComparer());
|
2012-01-19 21:57:12 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Used to control thread access to the priority queue.
|
|
|
|
/// </summary>
|
2009-10-02 23:53:35 +00:00
|
|
|
private object m_syncRoot = new object();
|
|
|
|
|
2012-01-19 21:57:12 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Client served by this image manager
|
|
|
|
/// </summary>
|
|
|
|
public IClientAPI Client { get; private set; }
|
|
|
|
|
2009-10-02 23:53:35 +00:00
|
|
|
public AssetBase MissingImage { get { return m_missingImage; } }
|
2009-02-22 20:52:55 +00:00
|
|
|
|
2012-01-19 19:00:11 +00:00
|
|
|
public LLImageManager(IClientAPI client, IAssetService pAssetCache, IJ2KDecoder pJ2kDecodeModule)
|
2009-01-19 18:33:25 +00:00
|
|
|
{
|
2012-01-19 21:57:12 +00:00
|
|
|
Client = client;
|
2009-01-19 18:33:25 +00:00
|
|
|
m_assetCache = pAssetCache;
|
2009-10-02 23:53:35 +00:00
|
|
|
|
2009-10-02 04:49:27 +00:00
|
|
|
if (pAssetCache != null)
|
|
|
|
m_missingImage = pAssetCache.Get("5748decc-f629-461c-9a36-a35a221fe21f");
|
2009-10-02 23:53:35 +00:00
|
|
|
|
|
|
|
if (m_missingImage == null)
|
|
|
|
m_log.Error("[ClientView] - Couldn't set missing image asset, falling back to missing image packet. This is known to crash the client");
|
2009-10-02 04:49:27 +00:00
|
|
|
|
2009-01-19 18:33:25 +00:00
|
|
|
m_j2kDecodeModule = pJ2kDecodeModule;
|
|
|
|
}
|
|
|
|
|
2009-10-02 23:53:35 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Handles an incoming texture request or update to an existing texture request
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="newRequest"></param>
|
2009-04-10 08:30:21 +00:00
|
|
|
public void EnqueueReq(TextureRequestArgs newRequest)
|
2009-01-19 18:33:25 +00:00
|
|
|
{
|
2009-04-10 08:30:21 +00:00
|
|
|
if (!m_shuttingdown)
|
|
|
|
{
|
2009-10-02 00:42:13 +00:00
|
|
|
J2KImage imgrequest;
|
2009-02-04 00:01:36 +00:00
|
|
|
|
2009-10-02 00:42:13 +00:00
|
|
|
// Do a linear search for this texture download
|
2009-10-05 18:01:45 +00:00
|
|
|
lock (m_syncRoot)
|
2009-10-02 20:08:15 +00:00
|
|
|
m_priorityQueue.Find(delegate(J2KImage img) { return img.TextureID == newRequest.RequestedAssetID; }, out imgrequest);
|
2009-02-04 00:01:36 +00:00
|
|
|
|
2009-10-02 00:42:13 +00:00
|
|
|
if (imgrequest != null)
|
|
|
|
{
|
|
|
|
if (newRequest.DiscardLevel == -1 && newRequest.Priority == 0f)
|
Thank you kindly, RemedyTomm for a patch that:
Following feedback from 0003440, i've made some changes to the new texture pipeline to optimise
performance. The changes are:
- Fixed a math issue where a small percentage of images with a certain size (on the packet boundary) would not have their final data delivered. This issue has been present since pre- 0003440
- It was suggested that a discardlevel of -1 and a prioriy of 0 meant to abandon the transfer, this is incorrect and caused some textures to clog.
- The texture throttle blocking queue is now only filled in relation to the actual throttle amount.. i.e, on a connection throttled to 300k, only twenty packets will be placed in the queue at a time, on a larger connection it will be much more. This is to balance responsiveness to requests and speed, and to minimise wasted packets.
- The engine now keeps track of the number of pending textures, and the stack will not be walked if there's no textures pending, saving CPU. Textures are only considered "pending" when they've already been decoded.
- As part of the above, some textures may receive twice as much data per cycle if the number of pending textures is below the cycle threshold, this should prevent loading from slowing down when there are fewer textures in the queue.
2009-04-18 18:35:03 +00:00
|
|
|
{
|
2009-10-02 01:12:13 +00:00
|
|
|
//m_log.Debug("[TEX]: (CAN) ID=" + newRequest.RequestedAssetID);
|
2009-06-25 07:42:06 +00:00
|
|
|
|
2012-01-04 21:40:15 +00:00
|
|
|
try
|
2009-10-02 03:32:22 +00:00
|
|
|
{
|
2009-10-05 18:01:45 +00:00
|
|
|
lock (m_syncRoot)
|
2012-01-04 21:40:15 +00:00
|
|
|
m_priorityQueue.Delete(imgrequest.PriorityQueueHandle);
|
2009-10-02 03:32:22 +00:00
|
|
|
}
|
2009-10-02 00:42:13 +00:00
|
|
|
catch (Exception) { }
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-05 19:44:06 +00:00
|
|
|
// m_log.DebugFormat(
|
|
|
|
// "[LL IMAGE MANAGER]: Received duplicate of existing request for {0}, start packet {1} from {2}",
|
|
|
|
// newRequest.RequestedAssetID, newRequest.PacketNumber, m_client.Name);
|
2012-01-04 21:40:15 +00:00
|
|
|
|
2012-01-19 23:09:16 +00:00
|
|
|
// m_log.DebugFormat("[TEX]: (UPD) ID={0}: D={1}, S={2}, P={3}",
|
|
|
|
// newRequest.RequestedAssetID, newRequest.DiscardLevel, newRequest.PacketNumber, newRequest.Priority);
|
2009-01-19 18:33:25 +00:00
|
|
|
|
2012-01-04 21:40:15 +00:00
|
|
|
//Check the packet sequence to make sure this isn't older than
|
2009-10-02 00:42:13 +00:00
|
|
|
//one we've already received
|
2009-10-02 20:08:15 +00:00
|
|
|
if (newRequest.requestSequence > imgrequest.LastSequence)
|
2009-06-25 07:42:06 +00:00
|
|
|
{
|
2009-10-02 00:42:13 +00:00
|
|
|
//Update the sequence number of the last RequestImage packet
|
2009-10-02 20:08:15 +00:00
|
|
|
imgrequest.LastSequence = newRequest.requestSequence;
|
2009-01-19 18:33:25 +00:00
|
|
|
|
2009-10-02 00:42:13 +00:00
|
|
|
//Update the requested discard level
|
2009-10-02 20:08:15 +00:00
|
|
|
imgrequest.DiscardLevel = newRequest.DiscardLevel;
|
2009-02-04 00:01:36 +00:00
|
|
|
|
2009-10-02 00:42:13 +00:00
|
|
|
//Update the requested packet number
|
2009-10-02 23:53:35 +00:00
|
|
|
imgrequest.StartPacket = Math.Max(1, newRequest.PacketNumber);
|
2009-04-10 08:30:21 +00:00
|
|
|
|
2009-10-02 00:42:13 +00:00
|
|
|
//Update the requested priority
|
2009-10-02 20:08:15 +00:00
|
|
|
imgrequest.Priority = newRequest.Priority;
|
2012-01-04 21:40:15 +00:00
|
|
|
|
2009-10-02 23:53:35 +00:00
|
|
|
UpdateImageInQueue(imgrequest);
|
Thank you kindly, RemedyTomm for a patch that:
Following feedback from 0003440, i've made some changes to the new texture pipeline to optimise
performance. The changes are:
- Fixed a math issue where a small percentage of images with a certain size (on the packet boundary) would not have their final data delivered. This issue has been present since pre- 0003440
- It was suggested that a discardlevel of -1 and a prioriy of 0 meant to abandon the transfer, this is incorrect and caused some textures to clog.
- The texture throttle blocking queue is now only filled in relation to the actual throttle amount.. i.e, on a connection throttled to 300k, only twenty packets will be placed in the queue at a time, on a larger connection it will be much more. This is to balance responsiveness to requests and speed, and to minimise wasted packets.
- The engine now keeps track of the number of pending textures, and the stack will not be walked if there's no textures pending, saving CPU. Textures are only considered "pending" when they've already been decoded.
- As part of the above, some textures may receive twice as much data per cycle if the number of pending textures is below the cycle threshold, this should prevent loading from slowing down when there are fewer textures in the queue.
2009-04-18 18:35:03 +00:00
|
|
|
|
2009-10-02 00:42:13 +00:00
|
|
|
imgrequest.RunUpdate();
|
2012-01-04 21:40:15 +00:00
|
|
|
|
|
|
|
// J2KImage imgrequest2 = new J2KImage(this);
|
|
|
|
// imgrequest2.J2KDecoder = m_j2kDecodeModule;
|
|
|
|
// imgrequest2.AssetService = m_assetCache;
|
|
|
|
// imgrequest2.AgentID = m_client.AgentId;
|
|
|
|
// imgrequest2.InventoryAccessModule = m_client.Scene.RequestModuleInterface<IInventoryAccessModule>();
|
|
|
|
// imgrequest2.DiscardLevel = newRequest.DiscardLevel;
|
|
|
|
// imgrequest2.StartPacket = Math.Max(1, newRequest.PacketNumber);
|
|
|
|
// imgrequest2.Priority = newRequest.Priority;
|
|
|
|
// imgrequest2.TextureID = newRequest.RequestedAssetID;
|
|
|
|
// imgrequest2.Priority = newRequest.Priority;
|
|
|
|
//
|
|
|
|
// //Add this download to the priority queue
|
|
|
|
// AddImageToQueue(imgrequest2);
|
|
|
|
//
|
|
|
|
// imgrequest2.RunUpdate();
|
|
|
|
|
2009-06-25 07:42:06 +00:00
|
|
|
}
|
2012-01-04 21:40:15 +00:00
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// m_log.DebugFormat(
|
|
|
|
// "[LL IMAGE MANAGER]: Ignoring duplicate of existing request for {0} (sequence {1}) from {2} as its request sequence {3} is not greater",
|
|
|
|
// newRequest.RequestedAssetID, imgrequest.LastSequence, m_client.Name, newRequest.requestSequence);
|
|
|
|
// }
|
Thank you kindly, RemedyTomm for a patch that:
Following feedback from 0003440, i've made some changes to the new texture pipeline to optimise
performance. The changes are:
- Fixed a math issue where a small percentage of images with a certain size (on the packet boundary) would not have their final data delivered. This issue has been present since pre- 0003440
- It was suggested that a discardlevel of -1 and a prioriy of 0 meant to abandon the transfer, this is incorrect and caused some textures to clog.
- The texture throttle blocking queue is now only filled in relation to the actual throttle amount.. i.e, on a connection throttled to 300k, only twenty packets will be placed in the queue at a time, on a larger connection it will be much more. This is to balance responsiveness to requests and speed, and to minimise wasted packets.
- The engine now keeps track of the number of pending textures, and the stack will not be walked if there's no textures pending, saving CPU. Textures are only considered "pending" when they've already been decoded.
- As part of the above, some textures may receive twice as much data per cycle if the number of pending textures is below the cycle threshold, this should prevent loading from slowing down when there are fewer textures in the queue.
2009-04-18 18:35:03 +00:00
|
|
|
}
|
2009-01-19 18:33:25 +00:00
|
|
|
}
|
2009-04-10 08:30:21 +00:00
|
|
|
else
|
|
|
|
{
|
2009-10-02 00:42:13 +00:00
|
|
|
if (newRequest.DiscardLevel == -1 && newRequest.Priority == 0f)
|
|
|
|
{
|
2009-10-02 01:12:13 +00:00
|
|
|
//m_log.DebugFormat("[TEX]: (IGN) ID={0}: D={1}, S={2}, P={3}",
|
|
|
|
// newRequest.RequestedAssetID, newRequest.DiscardLevel, newRequest.PacketNumber, newRequest.Priority);
|
2009-10-02 00:42:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-05 19:44:06 +00:00
|
|
|
// m_log.DebugFormat(
|
|
|
|
// "[LL IMAGE MANAGER]: Received request for {0}, start packet {1} from {2}",
|
|
|
|
// newRequest.RequestedAssetID, newRequest.PacketNumber, m_client.Name);
|
2012-01-04 21:40:15 +00:00
|
|
|
|
2009-10-02 01:12:13 +00:00
|
|
|
//m_log.DebugFormat("[TEX]: (NEW) ID={0}: D={1}, S={2}, P={3}",
|
|
|
|
// newRequest.RequestedAssetID, newRequest.DiscardLevel, newRequest.PacketNumber, newRequest.Priority);
|
2009-02-04 00:01:36 +00:00
|
|
|
|
2009-10-02 00:42:13 +00:00
|
|
|
imgrequest = new J2KImage(this);
|
2009-10-02 20:08:15 +00:00
|
|
|
imgrequest.J2KDecoder = m_j2kDecodeModule;
|
|
|
|
imgrequest.AssetService = m_assetCache;
|
2012-01-19 21:57:12 +00:00
|
|
|
imgrequest.AgentID = Client.AgentId;
|
|
|
|
imgrequest.InventoryAccessModule = Client.Scene.RequestModuleInterface<IInventoryAccessModule>();
|
2009-10-02 20:08:15 +00:00
|
|
|
imgrequest.DiscardLevel = newRequest.DiscardLevel;
|
2009-10-02 23:53:35 +00:00
|
|
|
imgrequest.StartPacket = Math.Max(1, newRequest.PacketNumber);
|
2009-10-02 20:08:15 +00:00
|
|
|
imgrequest.Priority = newRequest.Priority;
|
|
|
|
imgrequest.TextureID = newRequest.RequestedAssetID;
|
|
|
|
imgrequest.Priority = newRequest.Priority;
|
2009-04-10 08:30:21 +00:00
|
|
|
|
2009-10-02 00:42:13 +00:00
|
|
|
//Add this download to the priority queue
|
2009-10-02 23:53:35 +00:00
|
|
|
AddImageToQueue(imgrequest);
|
2009-02-04 00:01:36 +00:00
|
|
|
|
2009-10-02 00:42:13 +00:00
|
|
|
imgrequest.RunUpdate();
|
|
|
|
}
|
2009-01-19 18:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-18 20:28:36 +00:00
|
|
|
public bool HasUpdates()
|
|
|
|
{
|
|
|
|
J2KImage image = GetHighestPriorityImage();
|
|
|
|
|
|
|
|
return image != null && image.IsDecoded;
|
|
|
|
}
|
|
|
|
|
2009-10-14 18:43:31 +00:00
|
|
|
public bool ProcessImageQueue(int packetsToSend)
|
2009-01-19 18:33:25 +00:00
|
|
|
{
|
2009-10-14 18:43:31 +00:00
|
|
|
int packetsSent = 0;
|
2009-10-13 23:53:19 +00:00
|
|
|
|
2009-10-14 18:43:31 +00:00
|
|
|
while (packetsSent < packetsToSend)
|
2009-10-13 23:53:19 +00:00
|
|
|
{
|
2009-10-14 18:43:31 +00:00
|
|
|
J2KImage image = GetHighestPriorityImage();
|
|
|
|
|
|
|
|
// If null was returned, the texture priority queue is currently empty
|
|
|
|
if (image == null)
|
2012-01-04 21:40:15 +00:00
|
|
|
break;
|
2009-10-14 18:43:31 +00:00
|
|
|
|
|
|
|
if (image.IsDecoded)
|
2009-10-02 04:49:27 +00:00
|
|
|
{
|
2009-10-14 18:43:31 +00:00
|
|
|
int sent;
|
2012-01-19 21:57:12 +00:00
|
|
|
bool imageDone = image.SendPackets(Client, packetsToSend - packetsSent, out sent);
|
2009-10-14 18:43:31 +00:00
|
|
|
packetsSent += sent;
|
2009-10-13 23:53:19 +00:00
|
|
|
|
2009-10-14 18:43:31 +00:00
|
|
|
// If the send is complete, destroy any knowledge of this transfer
|
|
|
|
if (imageDone)
|
|
|
|
RemoveImageFromQueue(image);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// TODO: This is a limitation of how LLImageManager is currently
|
|
|
|
// written. Undecoded textures should not be going into the priority
|
|
|
|
// queue, because a high priority undecoded texture will clog up the
|
|
|
|
// pipeline for a client
|
2012-01-04 21:40:15 +00:00
|
|
|
// m_log.DebugFormat(
|
|
|
|
// "[LL IMAGE MANAGER]: Exiting image queue processing early on encountering undecoded image {0}",
|
|
|
|
// image.TextureID);
|
|
|
|
|
|
|
|
break;
|
2009-10-14 18:43:31 +00:00
|
|
|
}
|
2009-10-13 23:53:19 +00:00
|
|
|
}
|
2009-10-02 23:53:35 +00:00
|
|
|
|
2012-01-04 21:40:15 +00:00
|
|
|
// if (packetsSent != 0)
|
|
|
|
// m_log.DebugFormat("[LL IMAGE MANAGER]: Processed {0} packets from image queue", packetsSent);
|
|
|
|
|
2009-10-02 23:53:35 +00:00
|
|
|
return m_priorityQueue.Count > 0;
|
2009-01-19 18:33:25 +00:00
|
|
|
}
|
|
|
|
|
2009-10-13 23:53:19 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Faux destructor
|
|
|
|
/// </summary>
|
2009-01-19 18:33:25 +00:00
|
|
|
public void Close()
|
|
|
|
{
|
|
|
|
m_shuttingdown = true;
|
|
|
|
}
|
2009-04-10 08:30:21 +00:00
|
|
|
|
2012-01-19 19:49:06 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Clear the image queue.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The number of requests cleared.</returns>
|
|
|
|
public int ClearImageQueue()
|
|
|
|
{
|
|
|
|
int requestsDeleted;
|
|
|
|
|
|
|
|
lock (m_priorityQueue)
|
|
|
|
{
|
|
|
|
requestsDeleted = m_priorityQueue.Count;
|
|
|
|
|
|
|
|
// Surprisingly, there doesn't seem to be a clear method at this time.
|
|
|
|
while (!m_priorityQueue.IsEmpty)
|
|
|
|
m_priorityQueue.DeleteMax();
|
|
|
|
}
|
|
|
|
|
|
|
|
return requestsDeleted;
|
|
|
|
}
|
|
|
|
|
2012-01-10 21:30:12 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Returns an array containing all the images in the queue.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public J2KImage[] GetImages()
|
|
|
|
{
|
|
|
|
lock (m_priorityQueue)
|
|
|
|
return m_priorityQueue.ToArray();
|
|
|
|
}
|
|
|
|
|
2009-10-02 23:53:35 +00:00
|
|
|
#region Priority Queue Helpers
|
|
|
|
|
2012-01-02 21:31:42 +00:00
|
|
|
private J2KImage GetHighestPriorityImage()
|
2009-10-02 23:53:35 +00:00
|
|
|
{
|
|
|
|
J2KImage image = null;
|
|
|
|
|
2009-10-05 18:01:45 +00:00
|
|
|
lock (m_syncRoot)
|
2009-10-02 23:53:35 +00:00
|
|
|
{
|
2009-10-04 21:05:58 +00:00
|
|
|
if (m_priorityQueue.Count > 0)
|
2009-10-02 23:53:35 +00:00
|
|
|
{
|
2012-01-04 21:40:15 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
image = m_priorityQueue.FindMax();
|
|
|
|
}
|
2009-10-04 21:05:58 +00:00
|
|
|
catch (Exception) { }
|
2009-10-02 23:53:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
2012-01-02 21:31:42 +00:00
|
|
|
private void AddImageToQueue(J2KImage image)
|
2009-10-02 23:53:35 +00:00
|
|
|
{
|
|
|
|
image.PriorityQueueHandle = null;
|
|
|
|
|
2009-10-05 18:01:45 +00:00
|
|
|
lock (m_syncRoot)
|
2012-01-02 19:46:30 +00:00
|
|
|
{
|
2012-01-04 21:40:15 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
m_priorityQueue.Add(ref image.PriorityQueueHandle, image);
|
|
|
|
}
|
2009-10-05 18:01:45 +00:00
|
|
|
catch (Exception) { }
|
2012-01-02 19:46:30 +00:00
|
|
|
}
|
2009-10-02 23:53:35 +00:00
|
|
|
}
|
|
|
|
|
2012-01-02 21:31:42 +00:00
|
|
|
private void RemoveImageFromQueue(J2KImage image)
|
2009-10-02 23:53:35 +00:00
|
|
|
{
|
2009-10-05 18:01:45 +00:00
|
|
|
lock (m_syncRoot)
|
2012-01-02 19:46:30 +00:00
|
|
|
{
|
2012-01-04 21:40:15 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
m_priorityQueue.Delete(image.PriorityQueueHandle);
|
|
|
|
}
|
2009-10-05 18:01:45 +00:00
|
|
|
catch (Exception) { }
|
2012-01-02 19:46:30 +00:00
|
|
|
}
|
2009-10-02 23:53:35 +00:00
|
|
|
}
|
|
|
|
|
2012-01-02 21:31:42 +00:00
|
|
|
private void UpdateImageInQueue(J2KImage image)
|
2009-10-02 23:53:35 +00:00
|
|
|
{
|
2009-10-05 18:01:45 +00:00
|
|
|
lock (m_syncRoot)
|
2009-10-02 23:53:35 +00:00
|
|
|
{
|
2012-01-04 21:40:15 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
m_priorityQueue.Replace(image.PriorityQueueHandle, image);
|
|
|
|
}
|
2009-10-02 23:53:35 +00:00
|
|
|
catch (Exception)
|
|
|
|
{
|
|
|
|
image.PriorityQueueHandle = null;
|
|
|
|
m_priorityQueue.Add(ref image.PriorityQueueHandle, image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-04-10 08:30:21 +00:00
|
|
|
|
2009-10-02 23:53:35 +00:00
|
|
|
#endregion Priority Queue Helpers
|
2009-01-19 18:33:25 +00:00
|
|
|
}
|
2012-01-02 19:46:30 +00:00
|
|
|
}
|