aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Region/Environment/Modules/TextureSender.cs270
-rw-r--r--OpenSim/Region/Environment/Modules/UserTextureDownloadService.cs194
2 files changed, 232 insertions, 232 deletions
diff --git a/OpenSim/Region/Environment/Modules/TextureSender.cs b/OpenSim/Region/Environment/Modules/TextureSender.cs
index aba0126..c8807f7 100644
--- a/OpenSim/Region/Environment/Modules/TextureSender.cs
+++ b/OpenSim/Region/Environment/Modules/TextureSender.cs
@@ -1,136 +1,136 @@
1using System; 1using System;
2using libsecondlife; 2using libsecondlife;
3using libsecondlife.Packets; 3using libsecondlife.Packets;
4using OpenSim.Framework; 4using OpenSim.Framework;
5using OpenSim.Framework.Console; 5using OpenSim.Framework.Console;
6 6
7namespace OpenSim.Region.Environment.Modules 7namespace OpenSim.Region.Environment.Modules
8{ 8{
9 public class TextureSender 9 public class TextureSender
10 { 10 {
11 public int counter = 0; 11 public int counter = 0;
12 private AssetBase m_asset; 12 private AssetBase m_asset;
13 public long DataPointer = 0; 13 public long DataPointer = 0;
14 public int NumPackets = 0; 14 public int NumPackets = 0;
15 public int PacketCounter = 0; 15 public int PacketCounter = 0;
16 public bool Cancel = false; 16 public bool Cancel = false;
17 public bool ImageLoaded = false; 17 public bool ImageLoaded = false;
18 18
19 public bool Sending = false; 19 public bool Sending = false;
20 20
21 public IClientAPI RequestUser; 21 public IClientAPI RequestUser;
22 public LLUUID RequestedAssetID; 22 public LLUUID RequestedAssetID;
23 public int RequestedDiscardLevel = -1; 23 public int RequestedDiscardLevel = -1;
24 public uint StartPacketNumber = 0; 24 public uint StartPacketNumber = 0;
25 25
26 // private int m_sentDiscardLevel = -1; 26 // private int m_sentDiscardLevel = -1;
27 27
28 public TextureSender(IClientAPI client, LLUUID textureID, int discardLevel, uint packetNumber) 28 public TextureSender(IClientAPI client, LLUUID textureID, int discardLevel, uint packetNumber)
29 { 29 {
30 RequestUser = client; 30 RequestUser = client;
31 RequestedAssetID = textureID; 31 RequestedAssetID = textureID;
32 RequestedDiscardLevel = discardLevel; 32 RequestedDiscardLevel = discardLevel;
33 StartPacketNumber = packetNumber; 33 StartPacketNumber = packetNumber;
34 } 34 }
35 35
36 public void TextureReceived(AssetBase asset) 36 public void TextureReceived(AssetBase asset)
37 { 37 {
38 m_asset = asset; 38 m_asset = asset;
39 NumPackets = CalculateNumPackets(asset.Data.Length); 39 NumPackets = CalculateNumPackets(asset.Data.Length);
40 PacketCounter = (int) StartPacketNumber; 40 PacketCounter = (int) StartPacketNumber;
41 ImageLoaded = true; 41 ImageLoaded = true;
42 } 42 }
43 43
44 public void UpdateRequest(int discardLevel, uint packetNumber) 44 public void UpdateRequest(int discardLevel, uint packetNumber)
45 { 45 {
46 RequestedDiscardLevel = discardLevel; 46 RequestedDiscardLevel = discardLevel;
47 StartPacketNumber = packetNumber; 47 StartPacketNumber = packetNumber;
48 PacketCounter = (int) StartPacketNumber; 48 PacketCounter = (int) StartPacketNumber;
49 } 49 }
50 50
51 public bool SendTexturePacket() 51 public bool SendTexturePacket()
52 { 52 {
53 SendPacket(); 53 SendPacket();
54 counter++; 54 counter++;
55 if ((NumPackets == 0) || (RequestedDiscardLevel == -1) || (PacketCounter > NumPackets) || 55 if ((NumPackets == 0) || (RequestedDiscardLevel == -1) || (PacketCounter > NumPackets) ||
56 ((RequestedDiscardLevel > 0) && (counter > 50 + (NumPackets/(RequestedDiscardLevel + 1))))) 56 ((RequestedDiscardLevel > 0) && (counter > 50 + (NumPackets/(RequestedDiscardLevel + 1)))))
57 { 57 {
58 return true; 58 return true;
59 } 59 }
60 return false; 60 return false;
61 } 61 }
62 62
63 private void SendPacket() 63 private void SendPacket()
64 { 64 {
65 if (PacketCounter <= NumPackets) 65 if (PacketCounter <= NumPackets)
66 { 66 {
67 if (PacketCounter == 0) 67 if (PacketCounter == 0)
68 { 68 {
69 if (NumPackets == 0) 69 if (NumPackets == 0)
70 { 70 {
71 ImageDataPacket im = new ImageDataPacket(); 71 ImageDataPacket im = new ImageDataPacket();
72 im.Header.Reliable = false; 72 im.Header.Reliable = false;
73 im.ImageID.Packets = 1; 73 im.ImageID.Packets = 1;
74 im.ImageID.ID = m_asset.FullID; 74 im.ImageID.ID = m_asset.FullID;
75 im.ImageID.Size = (uint) m_asset.Data.Length; 75 im.ImageID.Size = (uint) m_asset.Data.Length;
76 im.ImageData.Data = m_asset.Data; 76 im.ImageData.Data = m_asset.Data;
77 im.ImageID.Codec = 2; 77 im.ImageID.Codec = 2;
78 RequestUser.OutPacket(im, ThrottleOutPacketType.Texture); 78 RequestUser.OutPacket(im, ThrottleOutPacketType.Texture);
79 PacketCounter++; 79 PacketCounter++;
80 } 80 }
81 else 81 else
82 { 82 {
83 ImageDataPacket im = new ImageDataPacket(); 83 ImageDataPacket im = new ImageDataPacket();
84 im.Header.Reliable = false; 84 im.Header.Reliable = false;
85 im.ImageID.Packets = (ushort) (NumPackets); 85 im.ImageID.Packets = (ushort) (NumPackets);
86 im.ImageID.ID = m_asset.FullID; 86 im.ImageID.ID = m_asset.FullID;
87 im.ImageID.Size = (uint) m_asset.Data.Length; 87 im.ImageID.Size = (uint) m_asset.Data.Length;
88 im.ImageData.Data = new byte[600]; 88 im.ImageData.Data = new byte[600];
89 Array.Copy(m_asset.Data, 0, im.ImageData.Data, 0, 600); 89 Array.Copy(m_asset.Data, 0, im.ImageData.Data, 0, 600);
90 im.ImageID.Codec = 2; 90 im.ImageID.Codec = 2;
91 RequestUser.OutPacket(im, ThrottleOutPacketType.Texture); 91 RequestUser.OutPacket(im, ThrottleOutPacketType.Texture);
92 PacketCounter++; 92 PacketCounter++;
93 } 93 }
94 } 94 }
95 else 95 else
96 { 96 {
97 ImagePacketPacket im = new ImagePacketPacket(); 97 ImagePacketPacket im = new ImagePacketPacket();
98 im.Header.Reliable = false; 98 im.Header.Reliable = false;
99 im.ImageID.Packet = (ushort) (PacketCounter); 99 im.ImageID.Packet = (ushort) (PacketCounter);
100 im.ImageID.ID = m_asset.FullID; 100 im.ImageID.ID = m_asset.FullID;
101 int size = m_asset.Data.Length - 600 - (1000*(PacketCounter - 1)); 101 int size = m_asset.Data.Length - 600 - (1000*(PacketCounter - 1));
102 if (size > 1000) size = 1000; 102 if (size > 1000) size = 1000;
103 im.ImageData.Data = new byte[size]; 103 im.ImageData.Data = new byte[size];
104 try 104 try
105 { 105 {
106 Array.Copy(m_asset.Data, 600 + (1000*(PacketCounter - 1)), im.ImageData.Data, 0, size); 106 Array.Copy(m_asset.Data, 600 + (1000*(PacketCounter - 1)), im.ImageData.Data, 0, size);
107 } 107 }
108 catch (ArgumentOutOfRangeException) 108 catch (ArgumentOutOfRangeException)
109 { 109 {
110 MainLog.Instance.Error("TEXTURE", 110 MainLog.Instance.Error("TEXTURE",
111 "Unable to separate texture into multiple packets: Array bounds failure on asset:" + 111 "Unable to separate texture into multiple packets: Array bounds failure on asset:" +
112 m_asset.FullID.ToString() ); 112 m_asset.FullID.ToString() );
113 return; 113 return;
114 } 114 }
115 RequestUser.OutPacket(im, ThrottleOutPacketType.Texture); 115 RequestUser.OutPacket(im, ThrottleOutPacketType.Texture);
116 PacketCounter++; 116 PacketCounter++;
117 } 117 }
118 } 118 }
119 } 119 }
120 120
121 private int CalculateNumPackets(int length) 121 private int CalculateNumPackets(int length)
122 { 122 {
123 int numPackets = 0; 123 int numPackets = 0;
124 124
125 if (length > 600) 125 if (length > 600)
126 { 126 {
127 //over 600 bytes so split up file 127 //over 600 bytes so split up file
128 int restData = (length - 600); 128 int restData = (length - 600);
129 int restPackets = ((restData + 999)/1000); 129 int restPackets = ((restData + 999)/1000);
130 numPackets = restPackets; 130 numPackets = restPackets;
131 } 131 }
132 132
133 return numPackets; 133 return numPackets;
134 } 134 }
135 } 135 }
136} \ No newline at end of file 136} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/UserTextureDownloadService.cs b/OpenSim/Region/Environment/Modules/UserTextureDownloadService.cs
index 6ee43e2..9a5b362 100644
--- a/OpenSim/Region/Environment/Modules/UserTextureDownloadService.cs
+++ b/OpenSim/Region/Environment/Modules/UserTextureDownloadService.cs
@@ -1,98 +1,98 @@
1using System; 1using System;
2using System.Collections.Generic; 2using System.Collections.Generic;
3using libsecondlife; 3using libsecondlife;
4using OpenSim.Framework; 4using OpenSim.Framework;
5using OpenSim.Framework.Console; 5using OpenSim.Framework.Console;
6using OpenSim.Region.Environment.Scenes; 6using OpenSim.Region.Environment.Scenes;
7 7
8namespace OpenSim.Region.Environment.Modules 8namespace OpenSim.Region.Environment.Modules
9{ 9{
10 public class UserTextureDownloadService 10 public class UserTextureDownloadService
11 { 11 {
12 private readonly Dictionary<LLUUID, TextureSender> m_textureSenders = new Dictionary<LLUUID, TextureSender>(); 12 private readonly Dictionary<LLUUID, TextureSender> m_textureSenders = new Dictionary<LLUUID, TextureSender>();
13 private readonly BlockingQueue<TextureSender> m_sharedSendersQueue; 13 private readonly BlockingQueue<TextureSender> m_sharedSendersQueue;
14 private readonly Scene m_scene; 14 private readonly Scene m_scene;
15 15
16 public UserTextureDownloadService(Scene scene, BlockingQueue<TextureSender> sharedQueue) 16 public UserTextureDownloadService(Scene scene, BlockingQueue<TextureSender> sharedQueue)
17 { 17 {
18 m_scene = scene; 18 m_scene = scene;
19 m_sharedSendersQueue = sharedQueue; 19 m_sharedSendersQueue = sharedQueue;
20 } 20 }
21 21
22 public void HandleTextureRequest(IClientAPI client, TextureRequestArgs e) 22 public void HandleTextureRequest(IClientAPI client, TextureRequestArgs e)
23 { 23 {
24 TextureSender textureSender; 24 TextureSender textureSender;
25 25
26 //TODO: should be working out the data size/ number of packets to be sent for each discard level 26 //TODO: should be working out the data size/ number of packets to be sent for each discard level
27 if ((e.DiscardLevel >= 0) || (e.Priority != 0)) 27 if ((e.DiscardLevel >= 0) || (e.Priority != 0))
28 { 28 {
29 lock (m_textureSenders) 29 lock (m_textureSenders)
30 { 30 {
31 if (m_textureSenders.TryGetValue(e.RequestedAssetID, out textureSender)) 31 if (m_textureSenders.TryGetValue(e.RequestedAssetID, out textureSender))
32 { 32 {
33 textureSender.UpdateRequest(e.DiscardLevel, e.PacketNumber); 33 textureSender.UpdateRequest(e.DiscardLevel, e.PacketNumber);
34 34
35 if ((textureSender.ImageLoaded) && 35 if ((textureSender.ImageLoaded) &&
36 (textureSender.Sending == false)) 36 (textureSender.Sending == false))
37 { 37 {
38 EnqueueTextureSender(textureSender); 38 EnqueueTextureSender(textureSender);
39 } 39 }
40 } 40 }
41 else 41 else
42 { 42 {
43 TextureSender requestHandler = 43 TextureSender requestHandler =
44 new TextureSender(client, e.RequestedAssetID, e.DiscardLevel, e.PacketNumber); 44 new TextureSender(client, e.RequestedAssetID, e.DiscardLevel, e.PacketNumber);
45 m_textureSenders.Add(e.RequestedAssetID, requestHandler); 45 m_textureSenders.Add(e.RequestedAssetID, requestHandler);
46 m_scene.AssetCache.GetAsset(e.RequestedAssetID, TextureCallback); 46 m_scene.AssetCache.GetAsset(e.RequestedAssetID, TextureCallback);
47 } 47 }
48 } 48 }
49 } 49 }
50 else 50 else
51 { 51 {
52 lock (m_textureSenders) 52 lock (m_textureSenders)
53 { 53 {
54 if (m_textureSenders.TryGetValue(e.RequestedAssetID, out textureSender)) 54 if (m_textureSenders.TryGetValue(e.RequestedAssetID, out textureSender))
55 { 55 {
56 textureSender.Cancel = true; 56 textureSender.Cancel = true;
57 } 57 }
58 } 58 }
59 } 59 }
60 } 60 }
61 61
62 public void TextureCallback(LLUUID textureID, AssetBase asset) 62 public void TextureCallback(LLUUID textureID, AssetBase asset)
63 { 63 {
64 lock (m_textureSenders) 64 lock (m_textureSenders)
65 { 65 {
66 TextureSender textureSender; 66 TextureSender textureSender;
67 67
68 if (m_textureSenders.TryGetValue(textureID, out textureSender)) 68 if (m_textureSenders.TryGetValue(textureID, out textureSender))
69 { 69 {
70 if (!textureSender.ImageLoaded) 70 if (!textureSender.ImageLoaded)
71 { 71 {
72 textureSender.TextureReceived(asset); 72 textureSender.TextureReceived(asset);
73 73
74 EnqueueTextureSender(textureSender); 74 EnqueueTextureSender(textureSender);
75 } 75 }
76 } 76 }
77 else 77 else
78 { 78 {
79 throw new Exception("Got a texture with no sender object to handle it, this shouldn't happen"); 79 throw new Exception("Got a texture with no sender object to handle it, this shouldn't happen");
80 } 80 }
81 } 81 }
82 } 82 }
83 83
84 private void EnqueueTextureSender(TextureSender textureSender) 84 private void EnqueueTextureSender(TextureSender textureSender)
85 { 85 {
86 MainLog.Instance.Debug( "TEXTUREDOWNLOAD", "Start: ["+textureSender.RequestedAssetID+"] to ["+textureSender.RequestUser.Name+"]"); 86 MainLog.Instance.Debug( "TEXTUREDOWNLOAD", "Start: ["+textureSender.RequestedAssetID+"] to ["+textureSender.RequestUser.Name+"]");
87 87
88 textureSender.Cancel = false; 88 textureSender.Cancel = false;
89 textureSender.Sending = true; 89 textureSender.Sending = true;
90 textureSender.counter = 0; 90 textureSender.counter = 0;
91 91
92 if (!m_sharedSendersQueue.Contains(textureSender)) 92 if (!m_sharedSendersQueue.Contains(textureSender))
93 { 93 {
94 m_sharedSendersQueue.Enqueue(textureSender); 94 m_sharedSendersQueue.Enqueue(textureSender);
95 } 95 }
96 } 96 }
97 } 97 }
98} \ No newline at end of file 98} \ No newline at end of file