diff options
author | Justin Clark-Casey (justincc) | 2012-01-05 22:40:49 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-01-05 22:40:49 +0000 |
commit | 5ea9740f1b2cc98601cfb15c19e190471c4c42ed (patch) | |
tree | 62c37ecf7740044fa01ebf99f0c3f36fef9be8a2 /OpenSim/Region | |
parent | Make "show asset" command available simulator side. Actually make the servic... (diff) | |
download | opensim-SC-5ea9740f1b2cc98601cfb15c19e190471c4c42ed.zip opensim-SC-5ea9740f1b2cc98601cfb15c19e190471c4c42ed.tar.gz opensim-SC-5ea9740f1b2cc98601cfb15c19e190471c4c42ed.tar.bz2 opensim-SC-5ea9740f1b2cc98601cfb15c19e190471c4c42ed.tar.xz |
Add a "j2k decode" region console command that allows a manual request for a JPEG2000 decode of an asset
For debugging purposes.
Diffstat (limited to '')
3 files changed, 163 insertions, 9 deletions
diff --git a/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs b/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs index 14dee84..349d3ac 100644 --- a/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs +++ b/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs | |||
@@ -137,14 +137,9 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender | |||
137 | } | 137 | } |
138 | } | 138 | } |
139 | 139 | ||
140 | /// <summary> | 140 | public bool Decode(UUID assetID, byte[] j2kData) |
141 | /// Provides a synchronous decode so that caller can be assured that this executes before the next line | ||
142 | /// </summary> | ||
143 | /// <param name="assetID"></param> | ||
144 | /// <param name="j2kData"></param> | ||
145 | public void Decode(UUID assetID, byte[] j2kData) | ||
146 | { | 141 | { |
147 | DoJ2KDecode(assetID, j2kData); | 142 | return DoJ2KDecode(assetID, j2kData); |
148 | } | 143 | } |
149 | 144 | ||
150 | #endregion IJ2KDecoder | 145 | #endregion IJ2KDecoder |
@@ -154,11 +149,13 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender | |||
154 | /// </summary> | 149 | /// </summary> |
155 | /// <param name="assetID">UUID of Asset</param> | 150 | /// <param name="assetID">UUID of Asset</param> |
156 | /// <param name="j2kData">JPEG2000 data</param> | 151 | /// <param name="j2kData">JPEG2000 data</param> |
157 | private void DoJ2KDecode(UUID assetID, byte[] j2kData) | 152 | private bool DoJ2KDecode(UUID assetID, byte[] j2kData) |
158 | { | 153 | { |
159 | // m_log.DebugFormat( | 154 | // m_log.DebugFormat( |
160 | // "[J2KDecoderModule]: Doing J2K decoding of {0} bytes for asset {1}", j2kData.Length, assetID); | 155 | // "[J2KDecoderModule]: Doing J2K decoding of {0} bytes for asset {1}", j2kData.Length, assetID); |
161 | 156 | ||
157 | bool decodedSuccessfully = true; | ||
158 | |||
162 | //int DecodeTime = 0; | 159 | //int DecodeTime = 0; |
163 | //DecodeTime = Environment.TickCount; | 160 | //DecodeTime = Environment.TickCount; |
164 | OpenJPEG.J2KLayerInfo[] layers; | 161 | OpenJPEG.J2KLayerInfo[] layers; |
@@ -196,6 +193,7 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender | |||
196 | catch (Exception ex) | 193 | catch (Exception ex) |
197 | { | 194 | { |
198 | m_log.Warn("[J2KDecoderModule]: CSJ2K threw an exception decoding texture " + assetID + ": " + ex.Message); | 195 | m_log.Warn("[J2KDecoderModule]: CSJ2K threw an exception decoding texture " + assetID + ": " + ex.Message); |
196 | decodedSuccessfully = false; | ||
199 | } | 197 | } |
200 | } | 198 | } |
201 | else | 199 | else |
@@ -204,6 +202,7 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender | |||
204 | if (!OpenJPEG.DecodeLayerBoundaries(j2kData, out layers, out components)) | 202 | if (!OpenJPEG.DecodeLayerBoundaries(j2kData, out layers, out components)) |
205 | { | 203 | { |
206 | m_log.Warn("[J2KDecoderModule]: OpenJPEG failed to decode texture " + assetID); | 204 | m_log.Warn("[J2KDecoderModule]: OpenJPEG failed to decode texture " + assetID); |
205 | decodedSuccessfully = false; | ||
207 | } | 206 | } |
208 | } | 207 | } |
209 | 208 | ||
@@ -212,6 +211,7 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender | |||
212 | m_log.Warn("[J2KDecoderModule]: Failed to decode layer data for texture " + assetID + ", guessing sane defaults"); | 211 | m_log.Warn("[J2KDecoderModule]: Failed to decode layer data for texture " + assetID + ", guessing sane defaults"); |
213 | // Layer decoding completely failed. Guess at sane defaults for the layer boundaries | 212 | // Layer decoding completely failed. Guess at sane defaults for the layer boundaries |
214 | layers = CreateDefaultLayers(j2kData.Length); | 213 | layers = CreateDefaultLayers(j2kData.Length); |
214 | decodedSuccessfully = false; | ||
215 | } | 215 | } |
216 | 216 | ||
217 | // Cache Decoded layers | 217 | // Cache Decoded layers |
@@ -231,6 +231,8 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender | |||
231 | m_notifyList.Remove(assetID); | 231 | m_notifyList.Remove(assetID); |
232 | } | 232 | } |
233 | } | 233 | } |
234 | |||
235 | return decodedSuccessfully; | ||
234 | } | 236 | } |
235 | 237 | ||
236 | private OpenJPEG.J2KLayerInfo[] CreateDefaultLayers(int j2kLength) | 238 | private OpenJPEG.J2KLayerInfo[] CreateDefaultLayers(int j2kLength) |
diff --git a/OpenSim/Region/Framework/Interfaces/IJ2KDecoder.cs b/OpenSim/Region/Framework/Interfaces/IJ2KDecoder.cs index 856eb11..0964276 100644 --- a/OpenSim/Region/Framework/Interfaces/IJ2KDecoder.cs +++ b/OpenSim/Region/Framework/Interfaces/IJ2KDecoder.cs | |||
@@ -35,6 +35,13 @@ namespace OpenSim.Region.Framework.Interfaces | |||
35 | public interface IJ2KDecoder | 35 | public interface IJ2KDecoder |
36 | { | 36 | { |
37 | void BeginDecode(UUID assetID, byte[] j2kData, DecodedCallback callback); | 37 | void BeginDecode(UUID assetID, byte[] j2kData, DecodedCallback callback); |
38 | void Decode(UUID assetID, byte[] j2kData); | 38 | |
39 | /// <summary> | ||
40 | /// Provides a synchronous decode so that caller can be assured that this executes before the next line | ||
41 | /// </summary> | ||
42 | /// <param name="assetID"></param> | ||
43 | /// <param name="j2kData"></param> | ||
44 | /// <returns>true if decode was successful. false otherwise.</returns> | ||
45 | bool Decode(UUID assetID, byte[] j2kData); | ||
39 | } | 46 | } |
40 | } | 47 | } |
diff --git a/OpenSim/Region/OptionalModules/Agent/TextureSender/J2KDecoderCommandModule.cs b/OpenSim/Region/OptionalModules/Agent/TextureSender/J2KDecoderCommandModule.cs new file mode 100644 index 0000000..b224132 --- /dev/null +++ b/OpenSim/Region/OptionalModules/Agent/TextureSender/J2KDecoderCommandModule.cs | |||
@@ -0,0 +1,145 @@ | |||
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.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Text; | ||
33 | using log4net; | ||
34 | using Mono.Addins; | ||
35 | using Nini.Config; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Console; | ||
39 | using OpenSim.Region.Framework.Interfaces; | ||
40 | using OpenSim.Region.Framework.Scenes; | ||
41 | |||
42 | namespace OpenSim.Region.OptionalModules.Agent.TextureSender | ||
43 | { | ||
44 | /// <summary> | ||
45 | /// Commands for the J2KDecoder module. For debugging purposes. | ||
46 | /// </summary> | ||
47 | /// <remarks> | ||
48 | /// Placed here so that they can be removed if not required and to keep the J2KDecoder module itself simple. | ||
49 | /// </remarks> | ||
50 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "J2KDecoderCommandModule")] | ||
51 | public class J2KDecoderCommandModule : ISharedRegionModule | ||
52 | { | ||
53 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
54 | |||
55 | private Scene m_scene; | ||
56 | |||
57 | public string Name { get { return "Asset Information Module"; } } | ||
58 | |||
59 | public Type ReplaceableInterface { get { return null; } } | ||
60 | |||
61 | public void Initialise(IConfigSource source) | ||
62 | { | ||
63 | // m_log.DebugFormat("[J2K DECODER COMMAND MODULE]: INITIALIZED MODULE"); | ||
64 | } | ||
65 | |||
66 | public void PostInitialise() | ||
67 | { | ||
68 | // m_log.DebugFormat("[J2K DECODER COMMAND MODULE]: POST INITIALIZED MODULE"); | ||
69 | } | ||
70 | |||
71 | public void Close() | ||
72 | { | ||
73 | // m_log.DebugFormat("[J2K DECODER COMMAND MODULE]: CLOSED MODULE"); | ||
74 | } | ||
75 | |||
76 | public void AddRegion(Scene scene) | ||
77 | { | ||
78 | // m_log.DebugFormat("[J2K DECODER COMMAND MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName); | ||
79 | } | ||
80 | |||
81 | public void RemoveRegion(Scene scene) | ||
82 | { | ||
83 | // m_log.DebugFormat("[J2K DECODER COMMAND MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName); | ||
84 | } | ||
85 | |||
86 | public void RegionLoaded(Scene scene) | ||
87 | { | ||
88 | // m_log.DebugFormat("[J2K DECODER COMMAND MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName); | ||
89 | |||
90 | if (m_scene == null) | ||
91 | m_scene = scene; | ||
92 | |||
93 | MainConsole.Instance.Commands.AddCommand( | ||
94 | "j2k", | ||
95 | false, | ||
96 | "j2k decode", | ||
97 | "j2k decode <ID>", | ||
98 | "Do JPEG2000 decoding of an asset.", | ||
99 | "This is for debugging purposes. The asset id given must contain JPEG2000 data.", | ||
100 | HandleDecode); | ||
101 | } | ||
102 | |||
103 | void HandleDecode(string module, string[] args) | ||
104 | { | ||
105 | if (args.Length < 3) | ||
106 | { | ||
107 | MainConsole.Instance.Output("Usage is j2k decode <ID>"); | ||
108 | return; | ||
109 | } | ||
110 | |||
111 | UUID assetId; | ||
112 | string rawAssetId = args[2]; | ||
113 | |||
114 | if (!UUID.TryParse(rawAssetId, out assetId)) | ||
115 | { | ||
116 | MainConsole.Instance.OutputFormat("ERROR: {0} is not a valid ID format", rawAssetId); | ||
117 | return; | ||
118 | } | ||
119 | |||
120 | AssetBase asset = m_scene.AssetService.Get(assetId.ToString()); | ||
121 | if (asset == null) | ||
122 | { | ||
123 | MainConsole.Instance.OutputFormat("ERROR: No asset found with ID {0}", assetId); | ||
124 | return; | ||
125 | } | ||
126 | |||
127 | if (asset.Type != (sbyte)AssetType.Texture) | ||
128 | { | ||
129 | MainConsole.Instance.OutputFormat("ERROR: Asset {0} is not a texture type", assetId); | ||
130 | return; | ||
131 | } | ||
132 | |||
133 | IJ2KDecoder decoder = m_scene.RequestModuleInterface<IJ2KDecoder>(); | ||
134 | if (decoder == null) | ||
135 | { | ||
136 | MainConsole.Instance.OutputFormat("ERROR: No IJ2KDecoder module available"); | ||
137 | return; | ||
138 | } | ||
139 | |||
140 | if (decoder.Decode(assetId, asset.Data)) | ||
141 | MainConsole.Instance.OutputFormat("Successfully decoded asset {0}", assetId); | ||
142 | else | ||
143 | MainConsole.Instance.OutputFormat("Decode of asset {0} failed", assetId); } | ||
144 | } | ||
145 | } \ No newline at end of file | ||