diff options
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Agent/TextureDownload')
3 files changed, 560 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs new file mode 100644 index 0000000..b8899d2 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs | |||
@@ -0,0 +1,215 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Threading; | ||
31 | using libsecondlife; | ||
32 | using Nini.Config; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Region.Environment.Interfaces; | ||
35 | using OpenSim.Region.Environment.Scenes; | ||
36 | |||
37 | namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload | ||
38 | { | ||
39 | public class TextureDownloadModule : IRegionModule | ||
40 | { | ||
41 | //private static readonly log4net.ILog m_log | ||
42 | // = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||
43 | |||
44 | private Scene m_scene; | ||
45 | private List<Scene> m_scenes = new List<Scene>(); | ||
46 | |||
47 | /// <summary> | ||
48 | /// There is one queue for all textures waiting to be sent, regardless of the requesting user. | ||
49 | /// </summary> | ||
50 | private readonly BlockingQueue<ITextureSender> m_queueSenders | ||
51 | = new BlockingQueue<ITextureSender>(); | ||
52 | |||
53 | /// <summary> | ||
54 | /// Each user has their own texture download service. | ||
55 | /// </summary> | ||
56 | private readonly Dictionary<LLUUID, UserTextureDownloadService> m_userTextureServices = | ||
57 | new Dictionary<LLUUID, UserTextureDownloadService>(); | ||
58 | |||
59 | private Thread m_thread; | ||
60 | |||
61 | public TextureDownloadModule() | ||
62 | { | ||
63 | } | ||
64 | |||
65 | public void Initialise(Scene scene, IConfigSource config) | ||
66 | { | ||
67 | if (m_scene == null) | ||
68 | { | ||
69 | //Console.WriteLine("Creating Texture download module"); | ||
70 | m_thread = new Thread(new ThreadStart(ProcessTextureSenders)); | ||
71 | m_thread.Name = "ProcessTextureSenderThread"; | ||
72 | m_thread.IsBackground = true; | ||
73 | m_thread.Start(); | ||
74 | ThreadTracker.Add(m_thread); | ||
75 | } | ||
76 | |||
77 | if (!m_scenes.Contains(scene)) | ||
78 | { | ||
79 | m_scenes.Add(scene); | ||
80 | m_scene = scene; | ||
81 | m_scene.EventManager.OnNewClient += NewClient; | ||
82 | m_scene.EventManager.OnRemovePresence += EventManager_OnRemovePresence; | ||
83 | } | ||
84 | } | ||
85 | |||
86 | /// <summary> | ||
87 | /// Cleanup the texture service related objects for the removed presence. | ||
88 | /// </summary> | ||
89 | /// <param name="agentId"> </param> | ||
90 | private void EventManager_OnRemovePresence(LLUUID agentId) | ||
91 | { | ||
92 | UserTextureDownloadService textureService; | ||
93 | |||
94 | lock (m_userTextureServices) | ||
95 | { | ||
96 | if (m_userTextureServices.TryGetValue(agentId, out textureService)) | ||
97 | { | ||
98 | textureService.Close(); | ||
99 | |||
100 | m_userTextureServices.Remove(agentId); | ||
101 | } | ||
102 | } | ||
103 | } | ||
104 | |||
105 | public void PostInitialise() | ||
106 | { | ||
107 | } | ||
108 | |||
109 | public void Close() | ||
110 | { | ||
111 | } | ||
112 | |||
113 | public string Name | ||
114 | { | ||
115 | get { return "TextureDownloadModule"; } | ||
116 | } | ||
117 | |||
118 | public bool IsSharedModule | ||
119 | { | ||
120 | get { return false; } | ||
121 | } | ||
122 | |||
123 | public void NewClient(IClientAPI client) | ||
124 | { | ||
125 | client.OnRequestTexture += TextureRequest; | ||
126 | } | ||
127 | |||
128 | /// <summary> | ||
129 | /// Does this user have a registered texture download service? | ||
130 | /// </summary> | ||
131 | /// <param name="userID"></param> | ||
132 | /// <param name="textureService"></param> | ||
133 | /// <returns>Always returns true, since a service is created if one does not already exist</returns> | ||
134 | private bool TryGetUserTextureService( | ||
135 | IClientAPI client, out UserTextureDownloadService textureService) | ||
136 | { | ||
137 | lock (m_userTextureServices) | ||
138 | { | ||
139 | if (m_userTextureServices.TryGetValue(client.AgentId, out textureService)) | ||
140 | { | ||
141 | return true; | ||
142 | } | ||
143 | |||
144 | textureService = new UserTextureDownloadService(client, m_scene, m_queueSenders); | ||
145 | m_userTextureServices.Add(client.AgentId, textureService); | ||
146 | |||
147 | return true; | ||
148 | } | ||
149 | } | ||
150 | |||
151 | /// <summary> | ||
152 | /// Start the process of requesting a given texture. | ||
153 | /// </summary> | ||
154 | /// <param name="sender"> </param> | ||
155 | /// <param name="e"></param> | ||
156 | public void TextureRequest(Object sender, TextureRequestArgs e) | ||
157 | { | ||
158 | IClientAPI client = (IClientAPI) sender; | ||
159 | UserTextureDownloadService textureService; | ||
160 | |||
161 | if (TryGetUserTextureService(client, out textureService)) | ||
162 | { | ||
163 | textureService.HandleTextureRequest(e); | ||
164 | } | ||
165 | } | ||
166 | |||
167 | /// <summary> | ||
168 | /// Entry point for the thread dedicated to processing the texture queue. | ||
169 | /// </summary> | ||
170 | public void ProcessTextureSenders() | ||
171 | { | ||
172 | ITextureSender sender = null; | ||
173 | |||
174 | while (true) | ||
175 | { | ||
176 | sender = m_queueSenders.Dequeue(); | ||
177 | |||
178 | if (sender.Cancel) | ||
179 | { | ||
180 | TextureSent(sender); | ||
181 | |||
182 | sender.Cancel = false; | ||
183 | } | ||
184 | else | ||
185 | { | ||
186 | bool finished = sender.SendTexturePacket(); | ||
187 | if (finished) | ||
188 | { | ||
189 | TextureSent(sender); | ||
190 | } | ||
191 | else | ||
192 | { | ||
193 | m_queueSenders.Enqueue(sender); | ||
194 | } | ||
195 | } | ||
196 | |||
197 | // Make sure that any sender we currently have can get garbage collected | ||
198 | sender = null; | ||
199 | |||
200 | //m_log.InfoFormat("[TEXTURE DOWNLOAD] Texture sender queue size: {0}", m_queueSenders.Count()); | ||
201 | } | ||
202 | } | ||
203 | |||
204 | /// <summary> | ||
205 | /// Called when the texture has finished sending. | ||
206 | /// </summary> | ||
207 | /// <param name="sender"></param> | ||
208 | private void TextureSent(ITextureSender sender) | ||
209 | { | ||
210 | sender.Sending = false; | ||
211 | //m_log.DebugFormat("[TEXTURE DOWNLOAD]: Removing download stat for {0}", sender.assetID); | ||
212 | m_scene.AddPendingDownloads(-1); | ||
213 | } | ||
214 | } | ||
215 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureNotFoundSender.cs b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureNotFoundSender.cs new file mode 100644 index 0000000..6f11f73 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureNotFoundSender.cs | |||
@@ -0,0 +1,93 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using libsecondlife; | ||
29 | using libsecondlife.Packets; | ||
30 | using OpenSim.Framework; | ||
31 | using OpenSim.Region.Environment.Interfaces; | ||
32 | |||
33 | namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// Sends a 'texture not found' packet back to the client | ||
37 | /// </summary> | ||
38 | public class TextureNotFoundSender : ITextureSender | ||
39 | { | ||
40 | //private static readonly log4net.ILog m_log | ||
41 | // = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||
42 | |||
43 | private LLUUID m_textureId; | ||
44 | private IClientAPI m_client; | ||
45 | |||
46 | // See ITextureSender | ||
47 | public bool Sending | ||
48 | { | ||
49 | get { return false; } | ||
50 | set { m_sending = value; } | ||
51 | } | ||
52 | |||
53 | private bool m_sending = false; | ||
54 | |||
55 | // See ITextureSender | ||
56 | public bool Cancel | ||
57 | { | ||
58 | get { return false; } | ||
59 | set { m_cancel = value; } | ||
60 | } | ||
61 | |||
62 | private bool m_cancel = false; | ||
63 | |||
64 | public TextureNotFoundSender(IClientAPI client, LLUUID textureID) | ||
65 | { | ||
66 | m_client = client; | ||
67 | m_textureId = textureID; | ||
68 | } | ||
69 | |||
70 | // See ITextureSender | ||
71 | public void UpdateRequest(int discardLevel, uint packetNumber) | ||
72 | { | ||
73 | // Not need to implement since priority changes don't affect this operation | ||
74 | } | ||
75 | |||
76 | // See ITextureSender | ||
77 | public bool SendTexturePacket() | ||
78 | { | ||
79 | //m_log.InfoFormat( | ||
80 | // "[TEXTURE NOT FOUND SENDER]: Informing the client that texture {0} cannot be found", | ||
81 | // m_textureId); | ||
82 | |||
83 | ImageNotInDatabasePacket notFound = new ImageNotInDatabasePacket(); | ||
84 | notFound.ImageID.ID = m_textureId; | ||
85 | |||
86 | // XXX Temporarily disabling as this appears to be causing client crashes on at least | ||
87 | // 1.19.0(5) of the Linden Second Life client. | ||
88 | // m_client.OutPacket(notFound, ThrottleOutPacketType.Texture); | ||
89 | |||
90 | return true; | ||
91 | } | ||
92 | } | ||
93 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs new file mode 100644 index 0000000..08a22d6 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs | |||
@@ -0,0 +1,252 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections.Generic; | ||
29 | using System.Reflection; | ||
30 | using libsecondlife; | ||
31 | using log4net; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Framework.Communications.Limit; | ||
34 | using OpenSim.Region.Environment.Interfaces; | ||
35 | using OpenSim.Region.Environment.Modules.Agent.TextureDownload; | ||
36 | using OpenSim.Region.Environment.Modules.Agent.TextureSender; | ||
37 | using OpenSim.Region.Environment.Scenes; | ||
38 | |||
39 | namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload | ||
40 | { | ||
41 | /// <summary> | ||
42 | /// This module sets up texture senders in response to client texture requests, and places them on a | ||
43 | /// processing queue once those senders have the appropriate data (i.e. a texture retrieved from the | ||
44 | /// asset cache). | ||
45 | /// </summary> | ||
46 | public class UserTextureDownloadService | ||
47 | { | ||
48 | private static readonly ILog m_log | ||
49 | = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | |||
51 | /// <summary> | ||
52 | /// We will allow the client to request the same texture n times before dropping further requests | ||
53 | /// | ||
54 | /// This number includes repeated requests for the same texture at different resolutions (which we don't | ||
55 | /// currently handle properly as far as I know). However, this situation should be handled in a more | ||
56 | /// sophisticated way. | ||
57 | /// </summary> | ||
58 | private static readonly int MAX_ALLOWED_TEXTURE_REQUESTS = 5; | ||
59 | |||
60 | /// <summary> | ||
61 | /// We're going to limit requests for the same missing texture. | ||
62 | /// XXX This is really a temporary solution to deal with the situation where a client continually requests | ||
63 | /// the same missing textures | ||
64 | /// </summary> | ||
65 | private readonly IRequestLimitStrategy<LLUUID> missingTextureLimitStrategy | ||
66 | = new RepeatLimitStrategy<LLUUID>(MAX_ALLOWED_TEXTURE_REQUESTS); | ||
67 | |||
68 | /// <summary> | ||
69 | /// XXX Also going to limit requests for found textures. | ||
70 | /// </summary> | ||
71 | private readonly IRequestLimitStrategy<LLUUID> foundTextureLimitStrategy | ||
72 | = new RepeatLimitStrategy<LLUUID>(MAX_ALLOWED_TEXTURE_REQUESTS); | ||
73 | |||
74 | /// <summary> | ||
75 | /// Holds texture senders before they have received the appropriate texture from the asset cache. | ||
76 | /// </summary> | ||
77 | private readonly Dictionary<LLUUID, TextureSender.TextureSender> m_textureSenders = new Dictionary<LLUUID, TextureSender.TextureSender>(); | ||
78 | |||
79 | /// <summary> | ||
80 | /// Texture Senders are placed in this queue once they have received their texture from the asset | ||
81 | /// cache. Another module actually invokes the send. | ||
82 | /// </summary> | ||
83 | private readonly BlockingQueue<ITextureSender> m_sharedSendersQueue; | ||
84 | |||
85 | private readonly Scene m_scene; | ||
86 | |||
87 | private readonly IClientAPI m_client; | ||
88 | |||
89 | public UserTextureDownloadService( | ||
90 | IClientAPI client, Scene scene, BlockingQueue<ITextureSender> sharedQueue) | ||
91 | { | ||
92 | m_client = client; | ||
93 | m_scene = scene; | ||
94 | m_sharedSendersQueue = sharedQueue; | ||
95 | } | ||
96 | |||
97 | /// <summary> | ||
98 | /// Handle a texture request. This involves creating a texture sender and placing it on the | ||
99 | /// previously passed in shared queue. | ||
100 | /// </summary> | ||
101 | /// <param name="e"></param> | ||
102 | public void HandleTextureRequest(TextureRequestArgs e) | ||
103 | { | ||
104 | TextureSender.TextureSender textureSender; | ||
105 | |||
106 | //TODO: should be working out the data size/ number of packets to be sent for each discard level | ||
107 | if ((e.DiscardLevel >= 0) || (e.Priority != 0)) | ||
108 | { | ||
109 | lock (m_textureSenders) | ||
110 | { | ||
111 | if (m_textureSenders.TryGetValue(e.RequestedAssetID, out textureSender)) | ||
112 | { | ||
113 | // If we've received new non UUID information for this request and it hasn't dispatched | ||
114 | // yet, then update the request accordingly. | ||
115 | textureSender.UpdateRequest(e.DiscardLevel, e.PacketNumber); | ||
116 | } | ||
117 | else | ||
118 | { | ||
119 | if (!foundTextureLimitStrategy.AllowRequest(e.RequestedAssetID)) | ||
120 | { | ||
121 | // m_log.DebugFormat( | ||
122 | // "[USER TEXTURE DOWNLOAD SERVICE]: Refusing request for {0} from client {1}", | ||
123 | // e.RequestedAssetID, m_client.AgentId); | ||
124 | |||
125 | return; | ||
126 | } | ||
127 | else if (!missingTextureLimitStrategy.AllowRequest(e.RequestedAssetID)) | ||
128 | { | ||
129 | if (missingTextureLimitStrategy.IsFirstRefusal(e.RequestedAssetID)) | ||
130 | { | ||
131 | // Commenting out this message for now as it causes too much noise with other | ||
132 | // debug messages. | ||
133 | // TODO: possibly record this as a statistic in the future | ||
134 | // | ||
135 | // m_log.DebugFormat( | ||
136 | // "[USER TEXTURE DOWNLOAD SERVICE]: Dropping requests for notified missing texture {0} for client {1} since we have received more than {2} requests", | ||
137 | // e.RequestedAssetID, m_client.AgentId, MAX_ALLOWED_TEXTURE_REQUESTS); | ||
138 | } | ||
139 | |||
140 | return; | ||
141 | } | ||
142 | |||
143 | m_scene.AddPendingDownloads(1); | ||
144 | |||
145 | TextureSender.TextureSender requestHandler = new TextureSender.TextureSender(m_client, e.DiscardLevel, e.PacketNumber); | ||
146 | m_textureSenders.Add(e.RequestedAssetID, requestHandler); | ||
147 | |||
148 | m_scene.AssetCache.GetAsset(e.RequestedAssetID, TextureCallback, true); | ||
149 | } | ||
150 | } | ||
151 | } | ||
152 | else | ||
153 | { | ||
154 | lock (m_textureSenders) | ||
155 | { | ||
156 | if (m_textureSenders.TryGetValue(e.RequestedAssetID, out textureSender)) | ||
157 | { | ||
158 | textureSender.Cancel = true; | ||
159 | } | ||
160 | } | ||
161 | } | ||
162 | } | ||
163 | |||
164 | /// <summary> | ||
165 | /// The callback for the asset cache when a texture has been retrieved. This method queues the | ||
166 | /// texture sender for processing. | ||
167 | /// </summary> | ||
168 | /// <param name="textureID"></param> | ||
169 | /// <param name="texture"></param> | ||
170 | public void TextureCallback(LLUUID textureID, AssetBase texture) | ||
171 | { | ||
172 | //m_log.DebugFormat("[USER TEXTURE DOWNLOAD SERVICE]: Calling TextureCallback with {0}, texture == null is {1}", textureID, (texture == null ? true : false)); | ||
173 | |||
174 | lock (m_textureSenders) | ||
175 | { | ||
176 | TextureSender.TextureSender textureSender; | ||
177 | |||
178 | if (m_textureSenders.TryGetValue(textureID, out textureSender)) | ||
179 | { | ||
180 | // XXX It may be perfectly valid for a texture to have no data... but if we pass | ||
181 | // this on to the TextureSender it will blow up, so just discard for now. | ||
182 | // Needs investigation. | ||
183 | if (texture == null || texture.Data == null) | ||
184 | { | ||
185 | if (!missingTextureLimitStrategy.IsMonitoringRequests(textureID)) | ||
186 | { | ||
187 | missingTextureLimitStrategy.MonitorRequests(textureID); | ||
188 | |||
189 | m_log.DebugFormat( | ||
190 | "[USER TEXTURE DOWNLOAD SERVICE]: Queueing first TextureNotFoundSender for {0}, client {1}", | ||
191 | textureID, m_client.AgentId); | ||
192 | } | ||
193 | |||
194 | ITextureSender textureNotFoundSender = new TextureNotFoundSender(m_client, textureID); | ||
195 | EnqueueTextureSender(textureNotFoundSender); | ||
196 | } | ||
197 | else | ||
198 | { | ||
199 | if (!textureSender.ImageLoaded) | ||
200 | { | ||
201 | textureSender.TextureReceived(texture); | ||
202 | EnqueueTextureSender(textureSender); | ||
203 | |||
204 | foundTextureLimitStrategy.MonitorRequests(textureID); | ||
205 | } | ||
206 | } | ||
207 | |||
208 | //m_log.InfoFormat("[TEXTURE SENDER] Removing texture sender with uuid {0}", textureID); | ||
209 | m_textureSenders.Remove(textureID); | ||
210 | //m_log.InfoFormat("[TEXTURE SENDER] Current texture senders in dictionary: {0}", m_textureSenders.Count); | ||
211 | } | ||
212 | else | ||
213 | { | ||
214 | m_log.WarnFormat( | ||
215 | "Got a texture uuid {0} with no sender object to handle it, this shouldn't happen", | ||
216 | textureID); | ||
217 | } | ||
218 | } | ||
219 | } | ||
220 | |||
221 | /// <summary> | ||
222 | /// Place a ready texture sender on the processing queue. | ||
223 | /// </summary> | ||
224 | /// <param name="textureSender"></param> | ||
225 | private void EnqueueTextureSender(ITextureSender textureSender) | ||
226 | { | ||
227 | textureSender.Cancel = false; | ||
228 | textureSender.Sending = true; | ||
229 | |||
230 | if (!m_sharedSendersQueue.Contains(textureSender)) | ||
231 | { | ||
232 | m_sharedSendersQueue.Enqueue(textureSender); | ||
233 | } | ||
234 | } | ||
235 | |||
236 | /// <summary> | ||
237 | /// Close this module. | ||
238 | /// </summary> | ||
239 | internal void Close() | ||
240 | { | ||
241 | lock (m_textureSenders) | ||
242 | { | ||
243 | foreach( TextureSender.TextureSender textureSender in m_textureSenders.Values ) | ||
244 | { | ||
245 | textureSender.Cancel = true; | ||
246 | } | ||
247 | |||
248 | m_textureSenders.Clear(); | ||
249 | } | ||
250 | } | ||
251 | } | ||
252 | } \ No newline at end of file | ||