diff options
author | John Hurliman | 2009-10-20 10:33:23 -0700 |
---|---|---|
committer | John Hurliman | 2009-10-20 10:33:23 -0700 |
commit | 9a5e7222cef7e81fee0c992c4557ac56e9665808 (patch) | |
tree | 2167b485454b513387fe239630038e83642613e6 /OpenSim/Region/CoreModules/Agent/TextureSender | |
parent | * Optimized sending of terrain data (diff) | |
download | opensim-SC_OLD-9a5e7222cef7e81fee0c992c4557ac56e9665808.zip opensim-SC_OLD-9a5e7222cef7e81fee0c992c4557ac56e9665808.tar.gz opensim-SC_OLD-9a5e7222cef7e81fee0c992c4557ac56e9665808.tar.bz2 opensim-SC_OLD-9a5e7222cef7e81fee0c992c4557ac56e9665808.tar.xz |
* Removing cruft left over from the conversion to the new texture sending and UDP code
* Changing the cache modules to only initialize the caches if they are actually enabled. Should save a bit of resources from unused cache systems
Diffstat (limited to 'OpenSim/Region/CoreModules/Agent/TextureSender')
-rw-r--r-- | OpenSim/Region/CoreModules/Agent/TextureSender/Tests/TextureSenderTests.cs | 180 | ||||
-rw-r--r-- | OpenSim/Region/CoreModules/Agent/TextureSender/TextureSender.cs | 212 |
2 files changed, 0 insertions, 392 deletions
diff --git a/OpenSim/Region/CoreModules/Agent/TextureSender/Tests/TextureSenderTests.cs b/OpenSim/Region/CoreModules/Agent/TextureSender/Tests/TextureSenderTests.cs deleted file mode 100644 index efa275c..0000000 --- a/OpenSim/Region/CoreModules/Agent/TextureSender/Tests/TextureSenderTests.cs +++ /dev/null | |||
@@ -1,180 +0,0 @@ | |||
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 OpenSimulator 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 NUnit.Framework; | ||
30 | using NUnit.Framework.SyntaxHelpers; | ||
31 | using OpenMetaverse; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Tests.Common; | ||
34 | using OpenSim.Tests.Common.Mock; | ||
35 | |||
36 | namespace OpenSim.Region.CoreModules.Agent.TextureSender | ||
37 | { | ||
38 | [TestFixture] | ||
39 | public class UserTextureSenderTests | ||
40 | { | ||
41 | public UUID uuid1; | ||
42 | public UUID uuid2; | ||
43 | public UUID uuid3; | ||
44 | public UUID uuid4; | ||
45 | public int npackets, testsize; | ||
46 | public TestClient client; | ||
47 | public TextureSender ts; | ||
48 | public static Random random = new Random(); | ||
49 | |||
50 | [TestFixtureSetUp] | ||
51 | public void Init() | ||
52 | { | ||
53 | AgentCircuitData agent = new AgentCircuitData(); | ||
54 | agent.AgentID = UUID.Random(); | ||
55 | agent.firstname = "testfirstname"; | ||
56 | agent.lastname = "testlastname"; | ||
57 | agent.SessionID = UUID.Zero; | ||
58 | agent.SecureSessionID = UUID.Zero; | ||
59 | agent.circuitcode = 123; | ||
60 | agent.BaseFolder = UUID.Zero; | ||
61 | agent.InventoryFolder = UUID.Zero; | ||
62 | agent.startpos = Vector3.Zero; | ||
63 | agent.CapsPath = "http://wibble.com"; | ||
64 | client = new TestClient(agent, null); | ||
65 | ts = new TextureSender(client, 0, 0); | ||
66 | testsize = random.Next(5000,15000); | ||
67 | npackets = CalculateNumPackets(testsize); | ||
68 | uuid1 = UUID.Random(); | ||
69 | uuid2 = UUID.Random(); | ||
70 | uuid3 = UUID.Random(); | ||
71 | uuid4 = UUID.Random(); | ||
72 | } | ||
73 | |||
74 | /// <summary> | ||
75 | /// Test sending package | ||
76 | /// </summary> | ||
77 | [Test] | ||
78 | public void T010_SendPkg() | ||
79 | { | ||
80 | TestHelper.InMethod(); | ||
81 | // Normal sending | ||
82 | AssetBase abase = new AssetBase(uuid1, "asset one"); | ||
83 | byte[] abdata = new byte[testsize]; | ||
84 | random.NextBytes(abdata); | ||
85 | abase.Data = abdata; | ||
86 | bool isdone = false; | ||
87 | ts.TextureReceived(abase); | ||
88 | for (int i = 0; i < npackets; i++) { | ||
89 | isdone = ts.SendTexturePacket(); | ||
90 | } | ||
91 | |||
92 | Assert.That(isdone,Is.False); | ||
93 | isdone = ts.SendTexturePacket(); | ||
94 | Assert.That(isdone,Is.True); | ||
95 | } | ||
96 | |||
97 | [Test] | ||
98 | public void T011_UpdateReq() | ||
99 | { | ||
100 | TestHelper.InMethod(); | ||
101 | // Test packet number start | ||
102 | AssetBase abase = new AssetBase(uuid2, "asset two"); | ||
103 | byte[] abdata = new byte[testsize]; | ||
104 | random.NextBytes(abdata); | ||
105 | abase.Data = abdata; | ||
106 | |||
107 | bool isdone = false; | ||
108 | ts.TextureReceived(abase); | ||
109 | ts.UpdateRequest(0,3); | ||
110 | |||
111 | for (int i = 0; i < npackets-3; i++) { | ||
112 | isdone = ts.SendTexturePacket(); | ||
113 | } | ||
114 | |||
115 | Assert.That(isdone,Is.False); | ||
116 | isdone = ts.SendTexturePacket(); | ||
117 | Assert.That(isdone,Is.True); | ||
118 | |||
119 | // Test discard level | ||
120 | abase = new AssetBase(uuid3, "asset three"); | ||
121 | abdata = new byte[testsize]; | ||
122 | random.NextBytes(abdata); | ||
123 | abase.Data = abdata; | ||
124 | isdone = false; | ||
125 | ts.TextureReceived(abase); | ||
126 | ts.UpdateRequest(-1,0); | ||
127 | |||
128 | Assert.That(ts.SendTexturePacket(),Is.True); | ||
129 | |||
130 | abase = new AssetBase(uuid4, "asset four"); | ||
131 | abdata = new byte[testsize]; | ||
132 | random.NextBytes(abdata); | ||
133 | abase.Data = abdata; | ||
134 | isdone = false; | ||
135 | ts.TextureReceived(abase); | ||
136 | ts.UpdateRequest(0,5); | ||
137 | |||
138 | for (int i = 0; i < npackets-5; i++) { | ||
139 | isdone = ts.SendTexturePacket(); | ||
140 | } | ||
141 | Assert.That(isdone,Is.False); | ||
142 | isdone = ts.SendTexturePacket(); | ||
143 | Assert.That(isdone,Is.True); | ||
144 | } | ||
145 | |||
146 | [Test] | ||
147 | public void T999_FinishStatus() | ||
148 | { | ||
149 | TestHelper.InMethod(); | ||
150 | // Of the 4 assets "sent", only 2 sent the first part. | ||
151 | Assert.That(client.sentdatapkt.Count,Is.EqualTo(2)); | ||
152 | |||
153 | // Sum of all packets sent: | ||
154 | int totalpkts = (npackets) + (npackets - 2) + (npackets - 4); | ||
155 | Assert.That(client.sentpktpkt.Count,Is.EqualTo(totalpkts)); | ||
156 | } | ||
157 | |||
158 | /// <summary> | ||
159 | /// Calculate the number of packets that will be required to send the texture loaded into this sender | ||
160 | /// This is actually the number of 1000 byte packets not including an initial 600 byte packet... | ||
161 | /// Borrowed from TextureSender.cs | ||
162 | /// </summary> | ||
163 | /// <param name="length"></param> | ||
164 | /// <returns></returns> | ||
165 | private int CalculateNumPackets(int length) | ||
166 | { | ||
167 | int numPackets = 0; | ||
168 | |||
169 | if (length > 600) | ||
170 | { | ||
171 | //over 600 bytes so split up file | ||
172 | int restData = (length - 600); | ||
173 | int restPackets = ((restData + 999) / 1000); | ||
174 | numPackets = restPackets; | ||
175 | } | ||
176 | |||
177 | return numPackets; | ||
178 | } | ||
179 | } | ||
180 | } | ||
diff --git a/OpenSim/Region/CoreModules/Agent/TextureSender/TextureSender.cs b/OpenSim/Region/CoreModules/Agent/TextureSender/TextureSender.cs deleted file mode 100644 index 62c5a32..0000000 --- a/OpenSim/Region/CoreModules/Agent/TextureSender/TextureSender.cs +++ /dev/null | |||
@@ -1,212 +0,0 @@ | |||
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 OpenSimulator 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.Reflection; | ||
30 | using log4net; | ||
31 | using OpenSim.Framework; | ||
32 | using OpenSim.Region.Framework.Interfaces; | ||
33 | |||
34 | namespace OpenSim.Region.CoreModules.Agent.TextureSender | ||
35 | { | ||
36 | /// <summary> | ||
37 | /// A TextureSender handles the process of receiving a texture requested by the client from the | ||
38 | /// AssetCache, and then sending that texture back to the client. | ||
39 | /// </summary> | ||
40 | public class TextureSender : ITextureSender | ||
41 | { | ||
42 | private static readonly ILog m_log | ||
43 | = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
44 | |||
45 | /// <summary> | ||
46 | /// Records the number of times texture send has been called. | ||
47 | /// </summary> | ||
48 | public int counter = 0; | ||
49 | |||
50 | public bool ImageLoaded = false; | ||
51 | |||
52 | /// <summary> | ||
53 | /// Holds the texture asset to send. | ||
54 | /// </summary> | ||
55 | private AssetBase m_asset; | ||
56 | |||
57 | //public UUID assetID { get { return m_asset.FullID; } } | ||
58 | |||
59 | // private bool m_cancel = false; | ||
60 | |||
61 | // See ITextureSender | ||
62 | |||
63 | // private bool m_sending = false; | ||
64 | |||
65 | /// <summary> | ||
66 | /// This is actually the number of extra packets required to send the texture data! We always assume | ||
67 | /// at least one is required. | ||
68 | /// </summary> | ||
69 | private int NumPackets = 0; | ||
70 | |||
71 | /// <summary> | ||
72 | /// Holds the packet number to send next. In this case, each packet is 1000 bytes long and starts | ||
73 | /// at the 600th byte (0th indexed). | ||
74 | /// </summary> | ||
75 | private int PacketCounter = 0; | ||
76 | |||
77 | private int RequestedDiscardLevel = -1; | ||
78 | private IClientAPI RequestUser; | ||
79 | private uint StartPacketNumber = 0; | ||
80 | |||
81 | public TextureSender(IClientAPI client, int discardLevel, uint packetNumber) | ||
82 | { | ||
83 | RequestUser = client; | ||
84 | RequestedDiscardLevel = discardLevel; | ||
85 | StartPacketNumber = packetNumber; | ||
86 | } | ||
87 | |||
88 | #region ITextureSender Members | ||
89 | |||
90 | public bool Cancel | ||
91 | { | ||
92 | get { return false; } | ||
93 | set | ||
94 | { | ||
95 | // m_cancel = value; | ||
96 | } | ||
97 | } | ||
98 | |||
99 | public bool Sending | ||
100 | { | ||
101 | get { return false; } | ||
102 | set | ||
103 | { | ||
104 | // m_sending = value; | ||
105 | } | ||
106 | } | ||
107 | |||
108 | // See ITextureSender | ||
109 | public void UpdateRequest(int discardLevel, uint packetNumber) | ||
110 | { | ||
111 | RequestedDiscardLevel = discardLevel; | ||
112 | StartPacketNumber = packetNumber; | ||
113 | PacketCounter = (int)StartPacketNumber; | ||
114 | } | ||
115 | |||
116 | // See ITextureSender | ||
117 | public bool SendTexturePacket() | ||
118 | { | ||
119 | //m_log.DebugFormat("[TEXTURE SENDER]: Sending packet for {0}", m_asset.FullID); | ||
120 | |||
121 | SendPacket(); | ||
122 | counter++; | ||
123 | if ((NumPackets == 0) || (RequestedDiscardLevel == -1) || (PacketCounter > NumPackets) || | ||
124 | ((RequestedDiscardLevel > 0) && (counter > 50 + (NumPackets / (RequestedDiscardLevel + 1))))) | ||
125 | { | ||
126 | return true; | ||
127 | } | ||
128 | return false; | ||
129 | } | ||
130 | |||
131 | #endregion | ||
132 | |||
133 | /// <summary> | ||
134 | /// Load up the texture data to send. | ||
135 | /// </summary> | ||
136 | /// <param name="asset"></param> | ||
137 | public void TextureReceived(AssetBase asset) | ||
138 | { | ||
139 | m_asset = asset; | ||
140 | NumPackets = CalculateNumPackets(asset.Data.Length); | ||
141 | PacketCounter = (int)StartPacketNumber; | ||
142 | ImageLoaded = true; | ||
143 | } | ||
144 | |||
145 | /// <summary> | ||
146 | /// Sends a texture packet to the client. | ||
147 | /// </summary> | ||
148 | private void SendPacket() | ||
149 | { | ||
150 | if (PacketCounter <= NumPackets) | ||
151 | { | ||
152 | if (PacketCounter == 0) | ||
153 | { | ||
154 | if (NumPackets == 0) | ||
155 | { | ||
156 | RequestUser.SendImageFirstPart(1, m_asset.FullID, (uint)m_asset.Data.Length, m_asset.Data, 2); | ||
157 | PacketCounter++; | ||
158 | } | ||
159 | else | ||
160 | { | ||
161 | byte[] ImageData1 = new byte[600]; | ||
162 | Array.Copy(m_asset.Data, 0, ImageData1, 0, 600); | ||
163 | |||
164 | RequestUser.SendImageFirstPart( | ||
165 | (ushort)(NumPackets), m_asset.FullID, (uint)m_asset.Data.Length, ImageData1, 2); | ||
166 | PacketCounter++; | ||
167 | } | ||
168 | } | ||
169 | else | ||
170 | { | ||
171 | int size = m_asset.Data.Length - 600 - (1000 * (PacketCounter - 1)); | ||
172 | if (size > 1000) size = 1000; | ||
173 | byte[] imageData = new byte[size]; | ||
174 | try | ||
175 | { | ||
176 | Array.Copy(m_asset.Data, 600 + (1000 * (PacketCounter - 1)), imageData, 0, size); | ||
177 | } | ||
178 | catch (ArgumentOutOfRangeException) | ||
179 | { | ||
180 | m_log.Error("[TEXTURE SENDER]: Unable to separate texture into multiple packets: Array bounds failure on asset:" + | ||
181 | m_asset.ID); | ||
182 | return; | ||
183 | } | ||
184 | |||
185 | RequestUser.SendImageNextPart((ushort)PacketCounter, m_asset.FullID, imageData); | ||
186 | PacketCounter++; | ||
187 | } | ||
188 | } | ||
189 | } | ||
190 | |||
191 | /// <summary> | ||
192 | /// Calculate the number of packets that will be required to send the texture loaded into this sender | ||
193 | /// This is actually the number of 1000 byte packets not including an initial 600 byte packet... | ||
194 | /// </summary> | ||
195 | /// <param name="length"></param> | ||
196 | /// <returns></returns> | ||
197 | private int CalculateNumPackets(int length) | ||
198 | { | ||
199 | int numPackets = 0; | ||
200 | |||
201 | if (length > 600) | ||
202 | { | ||
203 | //over 600 bytes so split up file | ||
204 | int restData = (length - 600); | ||
205 | int restPackets = ((restData + 999) / 1000); | ||
206 | numPackets = restPackets; | ||
207 | } | ||
208 | |||
209 | return numPackets; | ||
210 | } | ||
211 | } | ||
212 | } | ||