diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Environment/Modules/TextureSender.cs | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/TextureSender.cs b/OpenSim/Region/Environment/Modules/TextureSender.cs new file mode 100644 index 0000000..aba0126 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/TextureSender.cs | |||
@@ -0,0 +1,136 @@ | |||
1 | using System; | ||
2 | using libsecondlife; | ||
3 | using libsecondlife.Packets; | ||
4 | using OpenSim.Framework; | ||
5 | using OpenSim.Framework.Console; | ||
6 | |||
7 | namespace OpenSim.Region.Environment.Modules | ||
8 | { | ||
9 | public class TextureSender | ||
10 | { | ||
11 | public int counter = 0; | ||
12 | private AssetBase m_asset; | ||
13 | public long DataPointer = 0; | ||
14 | public int NumPackets = 0; | ||
15 | public int PacketCounter = 0; | ||
16 | public bool Cancel = false; | ||
17 | public bool ImageLoaded = false; | ||
18 | |||
19 | public bool Sending = false; | ||
20 | |||
21 | public IClientAPI RequestUser; | ||
22 | public LLUUID RequestedAssetID; | ||
23 | public int RequestedDiscardLevel = -1; | ||
24 | public uint StartPacketNumber = 0; | ||
25 | |||
26 | // private int m_sentDiscardLevel = -1; | ||
27 | |||
28 | public TextureSender(IClientAPI client, LLUUID textureID, int discardLevel, uint packetNumber) | ||
29 | { | ||
30 | RequestUser = client; | ||
31 | RequestedAssetID = textureID; | ||
32 | RequestedDiscardLevel = discardLevel; | ||
33 | StartPacketNumber = packetNumber; | ||
34 | } | ||
35 | |||
36 | public void TextureReceived(AssetBase asset) | ||
37 | { | ||
38 | m_asset = asset; | ||
39 | NumPackets = CalculateNumPackets(asset.Data.Length); | ||
40 | PacketCounter = (int) StartPacketNumber; | ||
41 | ImageLoaded = true; | ||
42 | } | ||
43 | |||
44 | public void UpdateRequest(int discardLevel, uint packetNumber) | ||
45 | { | ||
46 | RequestedDiscardLevel = discardLevel; | ||
47 | StartPacketNumber = packetNumber; | ||
48 | PacketCounter = (int) StartPacketNumber; | ||
49 | } | ||
50 | |||
51 | public bool SendTexturePacket() | ||
52 | { | ||
53 | SendPacket(); | ||
54 | counter++; | ||
55 | if ((NumPackets == 0) || (RequestedDiscardLevel == -1) || (PacketCounter > NumPackets) || | ||
56 | ((RequestedDiscardLevel > 0) && (counter > 50 + (NumPackets/(RequestedDiscardLevel + 1))))) | ||
57 | { | ||
58 | return true; | ||
59 | } | ||
60 | return false; | ||
61 | } | ||
62 | |||
63 | private void SendPacket() | ||
64 | { | ||
65 | if (PacketCounter <= NumPackets) | ||
66 | { | ||
67 | if (PacketCounter == 0) | ||
68 | { | ||
69 | if (NumPackets == 0) | ||
70 | { | ||
71 | ImageDataPacket im = new ImageDataPacket(); | ||
72 | im.Header.Reliable = false; | ||
73 | im.ImageID.Packets = 1; | ||
74 | im.ImageID.ID = m_asset.FullID; | ||
75 | im.ImageID.Size = (uint) m_asset.Data.Length; | ||
76 | im.ImageData.Data = m_asset.Data; | ||
77 | im.ImageID.Codec = 2; | ||
78 | RequestUser.OutPacket(im, ThrottleOutPacketType.Texture); | ||
79 | PacketCounter++; | ||
80 | } | ||
81 | else | ||
82 | { | ||
83 | ImageDataPacket im = new ImageDataPacket(); | ||
84 | im.Header.Reliable = false; | ||
85 | im.ImageID.Packets = (ushort) (NumPackets); | ||
86 | im.ImageID.ID = m_asset.FullID; | ||
87 | im.ImageID.Size = (uint) m_asset.Data.Length; | ||
88 | im.ImageData.Data = new byte[600]; | ||
89 | Array.Copy(m_asset.Data, 0, im.ImageData.Data, 0, 600); | ||
90 | im.ImageID.Codec = 2; | ||
91 | RequestUser.OutPacket(im, ThrottleOutPacketType.Texture); | ||
92 | PacketCounter++; | ||
93 | } | ||
94 | } | ||
95 | else | ||
96 | { | ||
97 | ImagePacketPacket im = new ImagePacketPacket(); | ||
98 | im.Header.Reliable = false; | ||
99 | im.ImageID.Packet = (ushort) (PacketCounter); | ||
100 | im.ImageID.ID = m_asset.FullID; | ||
101 | int size = m_asset.Data.Length - 600 - (1000*(PacketCounter - 1)); | ||
102 | if (size > 1000) size = 1000; | ||
103 | im.ImageData.Data = new byte[size]; | ||
104 | try | ||
105 | { | ||
106 | Array.Copy(m_asset.Data, 600 + (1000*(PacketCounter - 1)), im.ImageData.Data, 0, size); | ||
107 | } | ||
108 | catch (ArgumentOutOfRangeException) | ||
109 | { | ||
110 | MainLog.Instance.Error("TEXTURE", | ||
111 | "Unable to separate texture into multiple packets: Array bounds failure on asset:" + | ||
112 | m_asset.FullID.ToString() ); | ||
113 | return; | ||
114 | } | ||
115 | RequestUser.OutPacket(im, ThrottleOutPacketType.Texture); | ||
116 | PacketCounter++; | ||
117 | } | ||
118 | } | ||
119 | } | ||
120 | |||
121 | private int CalculateNumPackets(int length) | ||
122 | { | ||
123 | int numPackets = 0; | ||
124 | |||
125 | if (length > 600) | ||
126 | { | ||
127 | //over 600 bytes so split up file | ||
128 | int restData = (length - 600); | ||
129 | int restPackets = ((restData + 999)/1000); | ||
130 | numPackets = restPackets; | ||
131 | } | ||
132 | |||
133 | return numPackets; | ||
134 | } | ||
135 | } | ||
136 | } \ No newline at end of file | ||