aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Agent
diff options
context:
space:
mode:
authorDahlia Trimble2009-01-10 09:15:23 +0000
committerDahlia Trimble2009-01-10 09:15:23 +0000
commit630ce5b26446883043aa5e6541a4550d0e918659 (patch)
tree5128485b0d8e94c96593b352a421623cbd053acb /OpenSim/Region/Environment/Modules/Agent
parentInclude the changes from StrawBerryFride's patch to (diff)
downloadopensim-SC_OLD-630ce5b26446883043aa5e6541a4550d0e918659.zip
opensim-SC_OLD-630ce5b26446883043aa5e6541a4550d0e918659.tar.gz
opensim-SC_OLD-630ce5b26446883043aa5e6541a4550d0e918659.tar.bz2
opensim-SC_OLD-630ce5b26446883043aa5e6541a4550d0e918659.tar.xz
Revert progressive texture patch from r8001 until issues can be addressed
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Agent')
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs62
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureNotFoundSender.cs21
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs31
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/TextureSender/Tests/TextureSenderTests.cs2
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/TextureSender/TextureSender.cs307
5 files changed, 155 insertions, 268 deletions
diff --git a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs
index 2f5ea23..6bb61e2 100644
--- a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs
+++ b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs
@@ -204,14 +204,14 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload
204 /// <param name="e"></param> 204 /// <param name="e"></param>
205 public void TextureRequest(Object sender, TextureRequestArgs e) 205 public void TextureRequest(Object sender, TextureRequestArgs e)
206 { 206 {
207 IClientAPI client = (IClientAPI) sender; 207 IClientAPI client = (IClientAPI)sender;
208 208
209 if (e.Priority == 1016001f) // Preview 209 if (e.Priority == 1016001f) // Preview
210 { 210 {
211 if (client.Scene is Scene) 211 if (client.Scene is Scene)
212 { 212 {
213 Scene scene = (Scene)client.Scene; 213 Scene scene = (Scene)client.Scene;
214 214
215 CachedUserInfo profile = scene.CommsManager.UserProfileCacheService.GetUserDetails(client.AgentId); 215 CachedUserInfo profile = scene.CommsManager.UserProfileCacheService.GetUserDetails(client.AgentId);
216 if (profile == null) // Deny unknown user 216 if (profile == null) // Deny unknown user
217 return; 217 return;
@@ -241,52 +241,44 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload
241 { 241 {
242 ITextureSender sender = null; 242 ITextureSender sender = null;
243 243
244// try 244 try
245// { 245 {
246 while (true) 246 while (true)
247 { 247 {
248 try 248 sender = m_queueSenders.Dequeue();
249
250 if (sender.Cancel)
249 { 251 {
250 sender = m_queueSenders.Dequeue(); 252 TextureSent(sender);
251 253
252 if (sender.Cancel) 254 sender.Cancel = false;
255 }
256 else
257 {
258 bool finished = sender.SendTexturePacket();
259 if (finished)
253 { 260 {
254 TextureSent(sender); 261 TextureSent(sender);
255
256 sender.Cancel = false;
257 } 262 }
258 else 263 else
259 { 264 {
260 bool finished = sender.SendTexturePacket(); 265 m_queueSenders.Enqueue(sender);
261 if (finished)
262 {
263 TextureSent(sender);
264 }
265 else
266 {
267 m_queueSenders.Enqueue(sender);
268 }
269 } 266 }
267 }
270 268
271 // Make sure that any sender we currently have can get garbage collected 269 // Make sure that any sender we currently have can get garbage collected
272 sender = null; 270 sender = null;
273 271
274 //m_log.InfoFormat("[TEXTURE] Texture sender queue size: {0}", m_queueSenders.Count()); 272 //m_log.InfoFormat("[TEXTURE] Texture sender queue size: {0}", m_queueSenders.Count());
275 }
276 catch(Exception e)
277 {
278 m_log.ErrorFormat(
279 "[TEXTURE]: Texture send thread caught exception. The texture send was aborted. Exception is {0}", e);
280 }
281 } 273 }
282// } 274 }
283// catch (Exception e) 275 catch (Exception e)
284// { 276 {
285// // TODO: Let users in the sim and those entering it and possibly an external watchdog know what has happened 277 // TODO: Let users in the sim and those entering it and possibly an external watchdog know what has happened
286// m_log.ErrorFormat( 278 m_log.ErrorFormat(
287// "[TEXTURE]: Texture send thread terminating with exception. PLEASE REBOOT YOUR SIM - TEXTURES WILL NOT BE AVAILABLE UNTIL YOU DO. Exception is {0}", 279 "[TEXTURE]: Texture send thread terminating with exception. PLEASE REBOOT YOUR SIM - TEXTURES WILL NOT BE AVAILABLE UNTIL YOU DO. Exception is {0}",
288// e); 280 e);
289// } 281 }
290 } 282 }
291 283
292 /// <summary> 284 /// <summary>
diff --git a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureNotFoundSender.cs b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureNotFoundSender.cs
index 044ee76..34ddee6 100644
--- a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureNotFoundSender.cs
+++ b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureNotFoundSender.cs
@@ -28,6 +28,7 @@
28using System.Reflection; 28using System.Reflection;
29using log4net; 29using log4net;
30using OpenMetaverse; 30using OpenMetaverse;
31using OpenMetaverse.Packets;
31using OpenSim.Framework; 32using OpenSim.Framework;
32using OpenSim.Region.Environment.Interfaces; 33using OpenSim.Region.Environment.Interfaces;
33 34
@@ -38,11 +39,11 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload
38 /// </summary> 39 /// </summary>
39 public class TextureNotFoundSender : ITextureSender 40 public class TextureNotFoundSender : ITextureSender
40 { 41 {
41// private static readonly log4net.ILog m_log 42 // private static readonly log4net.ILog m_log
42// = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 43 // = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
43 44
44// private IClientAPI m_client; 45 // private IClientAPI m_client;
45// private UUID m_textureId; 46 // private UUID m_textureId;
46 47
47 public TextureNotFoundSender(IClientAPI client, UUID textureID) 48 public TextureNotFoundSender(IClientAPI client, UUID textureID)
48 { 49 {
@@ -55,13 +56,13 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload
55 public bool Sending 56 public bool Sending
56 { 57 {
57 get { return false; } 58 get { return false; }
58 set {} 59 set { }
59 } 60 }
60 61
61 public bool Cancel 62 public bool Cancel
62 { 63 {
63 get { return false; } 64 get { return false; }
64 set {} 65 set { }
65 } 66 }
66 67
67 // See ITextureSender 68 // See ITextureSender
@@ -73,13 +74,13 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload
73 // See ITextureSender 74 // See ITextureSender
74 public bool SendTexturePacket() 75 public bool SendTexturePacket()
75 { 76 {
76// m_log.DebugFormat( 77 // m_log.DebugFormat(
77// "[TEXTURE NOT FOUND SENDER]: Informing the client that texture {0} cannot be found", 78 // "[TEXTURE NOT FOUND SENDER]: Informing the client that texture {0} cannot be found",
78// m_textureId); 79 // m_textureId);
79 80
80 // XXX Temporarily disabling as this appears to be causing client crashes on at least 81 // XXX Temporarily disabling as this appears to be causing client crashes on at least
81 // 1.19.0(5) of the Linden Second Life client. 82 // 1.19.0(5) of the Linden Second Life client.
82// m_client.SendImageNotFound(m_textureId); 83 // m_client.SendImageNotFound(m_textureId);
83 84
84 return true; 85 return true;
85 } 86 }
diff --git a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs
index aab4ad0..e0790a2 100644
--- a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs
+++ b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs
@@ -56,10 +56,11 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload
56 /// <summary> 56 /// <summary>
57 /// We will allow the client to request the same texture n times before dropping further requests 57 /// We will allow the client to request the same texture n times before dropping further requests
58 /// 58 ///
59 /// This number contains repeated requests for the same texture at different resolutions (which 59 /// This number includes repeated requests for the same texture at different resolutions (which we don't
60 /// are handled since r7368). However, this situation should be handled in a more sophisticated way. 60 /// currently handle properly as far as I know). However, this situation should be handled in a more
61 /// sophisticated way.
61 /// </summary> 62 /// </summary>
62 private static readonly int MAX_ALLOWED_TEXTURE_REQUESTS = 15; 63 private static readonly int MAX_ALLOWED_TEXTURE_REQUESTS = 5;
63 64
64 /// <summary> 65 /// <summary>
65 /// XXX Also going to limit requests for found textures. 66 /// XXX Also going to limit requests for found textures.
@@ -119,13 +120,13 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload
119 } 120 }
120 else 121 else
121 { 122 {
122// m_log.DebugFormat("[TEXTURE]: Received a request for texture {0}", e.RequestedAssetID); 123 // m_log.DebugFormat("[TEXTURE]: Received a request for texture {0}", e.RequestedAssetID);
123 124
124 if (!foundTextureLimitStrategy.AllowRequest(e.RequestedAssetID)) 125 if (!foundTextureLimitStrategy.AllowRequest(e.RequestedAssetID))
125 { 126 {
126// m_log.DebugFormat( 127 // m_log.DebugFormat(
127// "[TEXTURE]: Refusing request for {0} from client {1}", 128 // "[TEXTURE]: Refusing request for {0} from client {1}",
128// e.RequestedAssetID, m_client.AgentId); 129 // e.RequestedAssetID, m_client.AgentId);
129 130
130 return; 131 return;
131 } 132 }
@@ -138,9 +139,9 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload
138 139
139 // Commenting out this message for now as it causes too much noise with other 140 // Commenting out this message for now as it causes too much noise with other
140 // debug messages. 141 // debug messages.
141// m_log.DebugFormat( 142 // m_log.DebugFormat(
142// "[TEXTURE]: Dropping requests for notified missing texture {0} for client {1} since we have received more than {2} requests", 143 // "[TEXTURE]: Dropping requests for notified missing texture {0} for client {1} since we have received more than {2} requests",
143// e.RequestedAssetID, m_client.AgentId, MAX_ALLOWED_TEXTURE_REQUESTS); 144 // e.RequestedAssetID, m_client.AgentId, MAX_ALLOWED_TEXTURE_REQUESTS);
144 } 145 }
145 146
146 return; 147 return;
@@ -148,7 +149,7 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload
148 149
149 m_scene.AddPendingDownloads(1); 150 m_scene.AddPendingDownloads(1);
150 151
151 TextureSender.TextureSender requestHandler = new TextureSender.TextureSender(m_client, e.DiscardLevel, e.PacketNumber, e.Priority); 152 TextureSender.TextureSender requestHandler = new TextureSender.TextureSender(m_client, e.DiscardLevel, e.PacketNumber);
152 m_textureSenders.Add(e.RequestedAssetID, requestHandler); 153 m_textureSenders.Add(e.RequestedAssetID, requestHandler);
153 154
154 m_scene.AssetCache.GetAsset(e.RequestedAssetID, TextureCallback, true); 155 m_scene.AssetCache.GetAsset(e.RequestedAssetID, TextureCallback, true);
@@ -195,9 +196,9 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload
195 { 196 {
196 missingTextureLimitStrategy.MonitorRequests(textureID); 197 missingTextureLimitStrategy.MonitorRequests(textureID);
197 198
198// m_log.DebugFormat( 199 // m_log.DebugFormat(
199// "[TEXTURE]: Queueing first TextureNotFoundSender for {0}, client {1}", 200 // "[TEXTURE]: Queueing first TextureNotFoundSender for {0}, client {1}",
200// textureID, m_client.AgentId); 201 // textureID, m_client.AgentId);
201 } 202 }
202 203
203 ITextureSender textureNotFoundSender = new TextureNotFoundSender(m_client, textureID); 204 ITextureSender textureNotFoundSender = new TextureNotFoundSender(m_client, textureID);
diff --git a/OpenSim/Region/Environment/Modules/Agent/TextureSender/Tests/TextureSenderTests.cs b/OpenSim/Region/Environment/Modules/Agent/TextureSender/Tests/TextureSenderTests.cs
index cff215b..4049dfc 100644
--- a/OpenSim/Region/Environment/Modules/Agent/TextureSender/Tests/TextureSenderTests.cs
+++ b/OpenSim/Region/Environment/Modules/Agent/TextureSender/Tests/TextureSenderTests.cs
@@ -53,7 +53,7 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureSender
53 agent.startpos = Vector3.Zero; 53 agent.startpos = Vector3.Zero;
54 agent.CapsPath = "http://wibble.com"; 54 agent.CapsPath = "http://wibble.com";
55 55
56 new TextureSender(new TestClient(agent), 0, 0, 1.0f); 56 new TextureSender(new TestClient(agent), 0, 0);
57 } 57 }
58 } 58 }
59} \ No newline at end of file 59} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Agent/TextureSender/TextureSender.cs b/OpenSim/Region/Environment/Modules/Agent/TextureSender/TextureSender.cs
index 0e34271..a6901b6 100644
--- a/OpenSim/Region/Environment/Modules/Agent/TextureSender/TextureSender.cs
+++ b/OpenSim/Region/Environment/Modules/Agent/TextureSender/TextureSender.cs
@@ -27,188 +27,106 @@
27 27
28using System; 28using System;
29using System.Reflection; 29using System.Reflection;
30using OpenMetaverse.Packets;
30using log4net; 31using log4net;
31using OpenSim.Framework; 32using OpenSim.Framework;
32using OpenSim.Region.Environment.Interfaces; 33using OpenSim.Region.Environment.Interfaces;
33 34
34namespace OpenSim.Region.Environment.Modules.Agent.TextureSender 35namespace OpenSim.Region.Environment.Modules.Agent.TextureSender
35{ 36{
36 public class ImageDownload 37 /// <summary>
38 /// A TextureSender handles the process of receiving a texture requested by the client from the
39 /// AssetCache, and then sending that texture back to the client.
40 /// </summary>
41 public class TextureSender : ITextureSender
37 { 42 {
38 public const int FIRST_IMAGE_PACKET_SIZE = 600; 43 private static readonly ILog m_log
39 public const int IMAGE_PACKET_SIZE = 1000; 44 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
40
41 public OpenMetaverse.AssetTexture Texture;
42 public int DiscardLevel;
43 public float Priority;
44 public int CurrentPacket;
45 public int StopPacket;
46
47 public ImageDownload(OpenMetaverse.AssetTexture texture, int discardLevel, float priority, int packet)
48 {
49 Texture = texture;
50 Update(discardLevel, priority, packet);
51 }
52
53 /// <summary>
54 /// Updates an image transfer with new information and recalculates
55 /// offsets
56 /// </summary>
57 /// <param name="discardLevel">New requested discard level</param>
58 /// <param name="priority">New requested priority</param>
59 /// <param name="packet">New requested packet offset</param>
60 public void Update(int discardLevel, float priority, int packet)
61 {
62 Priority = priority;
63 DiscardLevel = Clamp(discardLevel, 0, Texture.LayerInfo.Length - 1);
64 StopPacket = GetPacketForBytePosition(Texture.LayerInfo[(Texture.LayerInfo.Length - 1) - DiscardLevel].End);
65 CurrentPacket = Clamp(packet, 1, TexturePacketCount());
66 }
67 45
68 /// <summary> 46 /// <summary>
69 /// Returns the total number of packets needed to transfer this texture, 47 /// Records the number of times texture send has been called.
70 /// including the first packet of size FIRST_IMAGE_PACKET_SIZE
71 /// </summary> 48 /// </summary>
72 /// <returns>Total number of packets needed to transfer this texture</returns> 49 public int counter = 0;
73 public int TexturePacketCount()
74 {
75 return ((Texture.AssetData.Length - FIRST_IMAGE_PACKET_SIZE + IMAGE_PACKET_SIZE - 1) / IMAGE_PACKET_SIZE) + 1;
76 }
77 50
78 /// <summary> 51 public bool ImageLoaded = false;
79 /// Returns the current byte offset for this transfer, calculated from
80 /// the CurrentPacket
81 /// </summary>
82 /// <returns>Current byte offset for this transfer</returns>
83 public int CurrentBytePosition()
84 {
85 return FIRST_IMAGE_PACKET_SIZE + (CurrentPacket - 1) * IMAGE_PACKET_SIZE;
86 }
87
88 /// <summary>
89 /// Returns the size, in bytes, of the last packet. This will be somewhere
90 /// between 1 and IMAGE_PACKET_SIZE bytes
91 /// </summary>
92 /// <returns>Size of the last packet in the transfer</returns>
93 public int LastPacketSize()
94 {
95 return Texture.AssetData.Length - (FIRST_IMAGE_PACKET_SIZE + ((TexturePacketCount() - 2) * IMAGE_PACKET_SIZE));
96 }
97 52
98 /// <summary> 53 /// <summary>
99 /// Find the packet number that contains a given byte position 54 /// Holds the texture asset to send.
100 /// </summary> 55 /// </summary>
101 /// <param name="bytePosition">Byte position</param> 56 private AssetBase m_asset;
102 /// <returns>Packet number that contains the given byte position</returns>
103 int GetPacketForBytePosition(int bytePosition)
104 {
105 return ((bytePosition - FIRST_IMAGE_PACKET_SIZE + IMAGE_PACKET_SIZE - 1) / IMAGE_PACKET_SIZE);
106 }
107 57
108 /// <summary> 58 //public UUID assetID { get { return m_asset.FullID; } }
109 /// Clamp a given value between a range
110 /// </summary>
111 /// <param name="value">Value to clamp</param>
112 /// <param name="min">Minimum allowable value</param>
113 /// <param name="max">Maximum allowable value</param>
114 /// <returns>A value inclusively between lower and upper</returns>
115 static int Clamp(int value, int min, int max)
116 {
117 // First we check to see if we're greater than the max
118 value = (value > max) ? max : value;
119 59
120 // Then we check to see if we're less than the min. 60 // private bool m_cancel = false;
121 value = (value < min) ? min : value;
122 61
123 // There's no check to see if min > max. 62 // See ITextureSender
124 return value;
125 }
126 }
127 63
128 /// <summary> 64 // private bool m_sending = false;
129 /// A TextureSender handles the process of receiving a texture requested by the client from the
130 /// AssetCache, and then sending that texture back to the client.
131 /// </summary>
132 public class TextureSender : ITextureSender
133 {
134 private static readonly ILog m_log
135 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
136 65
137 public bool ImageLoaded = false; 66 /// <summary>
67 /// This is actually the number of extra packets required to send the texture data! We always assume
68 /// at least one is required.
69 /// </summary>
70 private int NumPackets = 0;
138 71
139 /// <summary> 72 /// <summary>
140 /// Holds the texture asset to send. 73 /// Holds the packet number to send next. In this case, each packet is 1000 bytes long and starts
74 /// at the 600th byte (0th indexed).
141 /// </summary> 75 /// </summary>
142 private AssetBase m_asset; 76 private int PacketCounter = 0;
143 private bool m_cancel = false;
144 private bool m_sending = false;
145 private bool sendFirstPacket = false;
146 private int initialDiscardLevel = 0;
147 private int initialPacketNum = 0;
148 private float initialPriority = 0.0f;
149 77
150 private ImageDownload download; 78 private int RequestedDiscardLevel = -1;
151 private IClientAPI RequestUser; 79 private IClientAPI RequestUser;
80 private uint StartPacketNumber = 0;
152 81
153 public TextureSender(IClientAPI client, int discardLevel, uint packetNumber, float priority) 82 public TextureSender(IClientAPI client, int discardLevel, uint packetNumber)
154 { 83 {
155 RequestUser = client; 84 RequestUser = client;
156 initialDiscardLevel = discardLevel; 85 RequestedDiscardLevel = discardLevel;
157 initialPacketNum = (int)packetNumber; 86 StartPacketNumber = packetNumber;
158 initialPriority = priority;
159 } 87 }
160 88
161 #region ITextureSender Members 89 #region ITextureSender Members
162 90
163 public bool Cancel 91 public bool Cancel
164 { 92 {
165 get { return m_cancel; } 93 get { return false; }
166 set { m_cancel = value; } 94 set
95 {
96 // m_cancel = value;
97 }
167 } 98 }
168 99
169 public bool Sending 100 public bool Sending
170 { 101 {
171 get { return m_sending; } 102 get { return false; }
172 set { m_sending = value; } 103 set
104 {
105 // m_sending = value;
106 }
173 } 107 }
174 108
175 // See ITextureSender 109 // See ITextureSender
176 public void UpdateRequest(int discardLevel, uint packetNumber) 110 public void UpdateRequest(int discardLevel, uint packetNumber)
177 { 111 {
178 if (download == null) 112 RequestedDiscardLevel = discardLevel;
179 return; 113 StartPacketNumber = packetNumber;
180 114 PacketCounter = (int)StartPacketNumber;
181 lock (download)
182 {
183 if (discardLevel < download.DiscardLevel)
184 m_log.DebugFormat("Image download {0} is changing from DiscardLevel {1} to {2}",
185 m_asset.FullID, download.DiscardLevel, discardLevel);
186
187 if (packetNumber != download.CurrentPacket)
188 m_log.DebugFormat("Image download {0} is changing from Packet {1} to {2}",
189 m_asset.FullID, download.CurrentPacket, packetNumber);
190
191 download.Update(discardLevel, download.Priority, (int)packetNumber);
192
193 sendFirstPacket = true;
194 }
195 } 115 }
196 116
197 // See ITextureSender 117 // See ITextureSender
198 public bool SendTexturePacket() 118 public bool SendTexturePacket()
199 { 119 {
200 if (download != null && !m_cancel && (sendFirstPacket || download.CurrentPacket <= download.StopPacket)) 120 //m_log.DebugFormat("[TEXTURE SENDER]: Sending packet for {0}", m_asset.FullID);
201 { 121
202 SendPacket(); 122 SendPacket();
203 return false; 123 counter++;
204 } 124 if ((NumPackets == 0) || (RequestedDiscardLevel == -1) || (PacketCounter > NumPackets) ||
205 else 125 ((RequestedDiscardLevel > 0) && (counter > 50 + (NumPackets / (RequestedDiscardLevel + 1)))))
206 { 126 {
207 m_sending = false;
208 m_cancel = true;
209 sendFirstPacket = false;
210 return true; 127 return true;
211 } 128 }
129 return false;
212 } 130 }
213 131
214 #endregion 132 #endregion
@@ -220,52 +138,9 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureSender
220 public void TextureReceived(AssetBase asset) 138 public void TextureReceived(AssetBase asset)
221 { 139 {
222 m_asset = asset; 140 m_asset = asset;
223 141 NumPackets = CalculateNumPackets(asset.Data.Length);
224 try 142 PacketCounter = (int)StartPacketNumber;
225 { 143 ImageLoaded = true;
226 OpenMetaverse.AssetTexture texture = new OpenMetaverse.AssetTexture(m_asset.FullID, m_asset.Data);
227 if (texture.DecodeLayerBoundaries())
228 {
229 bool sane = true;
230
231 // Sanity check all of the layers
232 for (int i = 0; i < texture.LayerInfo.Length; i++)
233 {
234 if (texture.LayerInfo[i].End > texture.AssetData.Length)
235 {
236 sane = false;
237 break;
238 }
239 }
240
241 if (sane)
242 {
243 download = new ImageDownload(texture, initialDiscardLevel, initialPriority, initialPacketNum);
244 ImageLoaded = true;
245 m_sending = true;
246 m_cancel = false;
247 sendFirstPacket = true;
248 return;
249 }
250 else
251 {
252 m_log.Error("JPEG2000 texture decoding succeeded, but sanity check failed for " +
253 m_asset.FullID.ToString());
254 }
255 }
256 else
257 {
258 m_log.Error("JPEG2000 texture decoding failed for " + m_asset.FullID.ToString());
259 }
260 }
261 catch (Exception ex)
262 {
263 m_log.Error("JPEG2000 texture decoding threw an exception for " + m_asset.FullID.ToString(), ex);
264 }
265
266 ImageLoaded = false;
267 m_sending = false;
268 m_cancel = true;
269 } 144 }
270 145
271 /// <summary> 146 /// <summary>
@@ -273,48 +148,66 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureSender
273 /// </summary> 148 /// </summary>
274 private void SendPacket() 149 private void SendPacket()
275 { 150 {
276 lock (download) 151 if (PacketCounter <= NumPackets)
277 { 152 {
278 if (sendFirstPacket) 153 if (PacketCounter == 0)
279 { 154 {
280 sendFirstPacket = false; 155 if (NumPackets == 0)
281
282 if (m_asset.Data.Length <= ImageDownload.FIRST_IMAGE_PACKET_SIZE)
283 { 156 {
284 RequestUser.SendImageFirstPart(1, m_asset.FullID, (uint)m_asset.Data.Length, m_asset.Data, 2); 157 RequestUser.SendImageFirstPart(1, m_asset.FullID, (uint)m_asset.Data.Length, m_asset.Data, 2);
285 return; 158 PacketCounter++;
286 } 159 }
287 else 160 else
288 { 161 {
289 byte[] firstImageData = new byte[ImageDownload.FIRST_IMAGE_PACKET_SIZE]; 162 byte[] ImageData1 = new byte[600];
290 try { Buffer.BlockCopy(m_asset.Data, 0, firstImageData, 0, ImageDownload.FIRST_IMAGE_PACKET_SIZE); } 163 Array.Copy(m_asset.Data, 0, ImageData1, 0, 600);
291 catch (Exception) 164
292 { 165 RequestUser.SendImageFirstPart(
293 m_log.Error("Texture data copy failed on first packet for " + m_asset.FullID.ToString()); 166 (ushort)(NumPackets), m_asset.FullID, (uint)m_asset.Data.Length, ImageData1, 2);
294 m_cancel = true; 167 PacketCounter++;
295 m_sending = false;
296 return;
297 }
298 RequestUser.SendImageFirstPart((ushort)download.TexturePacketCount(), m_asset.FullID, (uint)m_asset.Data.Length, firstImageData, 2);
299 } 168 }
300 } 169 }
301 170 else
302 int imagePacketSize = (download.CurrentPacket == download.TexturePacketCount() - 1) ?
303 download.LastPacketSize() : ImageDownload.IMAGE_PACKET_SIZE;
304
305 byte[] imageData = new byte[imagePacketSize];
306 try { Buffer.BlockCopy(m_asset.Data, download.CurrentBytePosition(), imageData, 0, imagePacketSize); }
307 catch (Exception)
308 { 171 {
309 m_log.Error("Texture data copy failed for " + m_asset.FullID.ToString()); 172 int size = m_asset.Data.Length - 600 - (1000 * (PacketCounter - 1));
310 m_cancel = true; 173 if (size > 1000) size = 1000;
311 m_sending = false; 174 byte[] imageData = new byte[size];
312 return; 175 try
176 {
177 Array.Copy(m_asset.Data, 600 + (1000 * (PacketCounter - 1)), imageData, 0, size);
178 }
179 catch (ArgumentOutOfRangeException)
180 {
181 m_log.Error("[TEXTURE SENDER]: Unable to separate texture into multiple packets: Array bounds failure on asset:" +
182 m_asset.FullID.ToString());
183 return;
184 }
185
186 RequestUser.SendImageNextPart((ushort)PacketCounter, m_asset.FullID, imageData);
187 PacketCounter++;
313 } 188 }
189 }
190 }
314 191
315 RequestUser.SendImageNextPart((ushort)download.CurrentPacket, m_asset.FullID, imageData); 192 /// <summary>
316 ++download.CurrentPacket; 193 /// Calculate the number of packets that will be required to send the texture loaded into this sender
194 /// This is actually the number of 1000 byte packets not including an initial 600 byte packet...
195 /// </summary>
196 /// <param name="length"></param>
197 /// <returns></returns>
198 private int CalculateNumPackets(int length)
199 {
200 int numPackets = 0;
201
202 if (length > 600)
203 {
204 //over 600 bytes so split up file
205 int restData = (length - 600);
206 int restPackets = ((restData + 999) / 1000);
207 numPackets = restPackets;
317 } 208 }
209
210 return numPackets;
318 } 211 }
319 } 212 }
320} 213}