public void BeginDecode(UUID assetID, byte[] j2kData, DecodedCallback callback)
        {
            OpenJPEG.J2KLayerInfo[] result;

            // If it's cached, return the cached results
            if (m_decodedCache.TryGetValue(assetID, out result))
            {
                callback(assetID, result);
            }
            else
            {
                // Not cached, we need to decode it.
                // Add to notify list and start decoding.
                // Next request for this asset while it's decoding will only be added to the notify list
                // once this is decoded, requests will be served from the cache and all clients in the notifylist will be updated
                bool decode = false;
                lock (m_notifyList)
                {
                    if (m_notifyList.ContainsKey(assetID))
                    {
                        m_notifyList[assetID].Add(callback);
                    }
                    else
                    {
                        List<DecodedCallback> notifylist = new List<DecodedCallback> {callback};
                        m_notifyList.Add(assetID, notifylist);
                        decode = true;
                    }
                }

                // Do Decode!
                if (decode)
                    DoJ2KDecode(assetID, j2kData);
            }
        }
Exemple #2
0
        public void decode(UUID AssetId, byte[] assetData, DecodedCallback decodedReturn)
        {
            // Dummy for if decoding fails.
            OpenJPEG.J2KLayerInfo[] result = new OpenJPEG.J2KLayerInfo[0];

            // Check if it's cached
            bool cached = false;

            lock (m_cacheddecode)
            {
                if (m_cacheddecode.ContainsKey(AssetId))
                {
                    cached = true;
                    result = m_cacheddecode[AssetId];
                }
            }

            // If it's cached, return the cached results
            if (cached)
            {
                decodedReturn(AssetId, result);
            }
            else
            {
                // not cached, so we need to decode it
                // Add to notify list and start decoding.
                // Next request for this asset while it's decoding will only be added to the notify list
                // once this is decoded, requests will be served from the cache and all clients in the notifylist will be updated
                bool decode = false;
                lock (m_notifyList)
                {
                    if (m_notifyList.ContainsKey(AssetId))
                    {
                        m_notifyList[AssetId].Add(decodedReturn);
                    }
                    else
                    {
                        List <DecodedCallback> notifylist = new List <DecodedCallback>();
                        notifylist.Add(decodedReturn);
                        m_notifyList.Add(AssetId, notifylist);
                        decode = true;
                    }
                }
                // Do Decode!
                if (decode)
                {
                    doJ2kDecode(AssetId, assetData);
                }
            }
        }
        public void BeginDecode(UUID assetID, byte[] j2kData, DecodedCallback callback)
        {
            OpenJPEG.J2KLayerInfo[] result;
            bool decodedSuccessfully = false;

            lock (fCache)
            {
                decodedSuccessfully = fCache.TryLoadCacheForAsset(assetID, out result);
            }

            if (decodedSuccessfully)
            {
                callback(assetID, result);
                return;
            }

            // Not cached, we need to decode it.
            // Add to notify list and start decoding.
            // Next request for this asset while it's decoding will only be added to the notify list
            // once this is decoded, requests will be served from the cache and all clients in the notifylist will be updated
            bool decode = false;

            lock (m_notifyList)
            {
                if (m_notifyList.ContainsKey(assetID))
                {
                    m_notifyList[assetID].Add(callback);
                }
                else
                {
                    List <DecodedCallback> notifylist = new List <DecodedCallback>();
                    notifylist.Add(callback);
                    m_notifyList.Add(assetID, notifylist);
                    decode = true;
                }
            }

            // Do Decode!
            if (decode)
            {
                Decode(assetID, j2kData);
            }
        }
        public void BeginDecode(UUID assetID, byte[] j2kData, DecodedCallback callback)
        {
            OpenJPEG.J2KLayerInfo[] result;

            // If it's cached, return the cached results
            if (m_decodedCache.TryGetValue(assetID, out result))
            {
//                m_log.DebugFormat(
//                    "[J2KDecoderModule]: Returning existing cached {0} layers j2k decode for {1}",
//                    result.Length, assetID);

                callback(assetID, result);
            }
            else
            {
                // Not cached, we need to decode it.
                // Add to notify list and start decoding.
                // Next request for this asset while it's decoding will only be added to the notify list
                // once this is decoded, requests will be served from the cache and all clients in the notifylist will be updated
                bool decode = false;
                lock (m_notifyList)
                {
                    if (m_notifyList.ContainsKey(assetID))
                    {
                        m_notifyList[assetID].Add(callback);
                    }
                    else
                    {
                        List <DecodedCallback> notifylist = new List <DecodedCallback>();
                        notifylist.Add(callback);
                        m_notifyList.Add(assetID, notifylist);
                        decode = true;
                    }
                }

                // Do Decode!
                if (decode)
                {
                    Util.FireAndForget(delegate { Decode(assetID, j2kData); });
                }
            }
        }
Exemple #5
0
        public void BeginDecode(UUID assetID, byte [] j2kData, DecodedCallback callback)
        {
            OpenJPEG.J2KLayerInfo [] result;

            // If it's cached, return the cached results
            if (m_decodedCache.TryGetValue(assetID, out result))
            {
                callback(assetID, result);
            }
            else
            {
                // Not cached, we need to decode it.
                // Add to notify list and start decoding.
                // Next request for this asset while it's decoding will only be added to the notify list
                // once this is decoded, requests will be served from the cache and all clients in the notifylist will be updated
                bool decode = false;
                lock (m_notifyList) {
                    if (m_notifyList.ContainsKey(assetID))
                    {
                        m_notifyList [assetID].Add(callback);
                    }
                    else
                    {
                        var notifylist = new List <DecodedCallback> {
                            callback
                        };
                        m_notifyList.Add(assetID, notifylist);
                        decode = true;
                    }
                }

                // Do Decode!
                if (decode)
                {
                    DoJ2KDecode(assetID, j2kData);
                }
            }
        }
        public void BeginDecode(UUID assetID, byte[] j2kData, DecodedCallback callback)
        {
            OpenJPEG.J2KLayerInfo[] result;

            // If it's cached, return the cached results
            if (m_decodedCache.TryGetValue(assetID, out result))
            {
//                m_log.DebugFormat(
//                    "[J2KDecoderModule]: Returning existing cached {0} layers j2k decode for {1}",
//                    result.Length, assetID);

                callback(assetID, result);
            }
            else
            {
                // Not cached, we need to decode it.
                // Add to notify list and start decoding.
                // Next request for this asset while it's decoding will only be added to the notify list
                // once this is decoded, requests will be served from the cache and all clients in the notifylist will be updated
                bool decode = false;
                lock (m_notifyList)
                {
                    if (m_notifyList.ContainsKey(assetID))
                    {
                        m_notifyList[assetID].Add(callback);
                    }
                    else
                    {
                        List<DecodedCallback> notifylist = new List<DecodedCallback>();
                        notifylist.Add(callback);
                        m_notifyList.Add(assetID, notifylist);
                        decode = true;
                    }
                }

                // Do Decode!
                if (decode)
                    Util.FireAndForget(delegate { Decode(assetID, j2kData); });
            }
        }
        public void decode(UUID AssetId, byte[] assetData, DecodedCallback decodedReturn)
        {
            // Dummy for if decoding fails.
            OpenJPEG.J2KLayerInfo[] result = new OpenJPEG.J2KLayerInfo[0];

            // Check if it's cached
            bool cached = false;
            lock (m_cacheddecode)
            {
                if (m_cacheddecode.ContainsKey(AssetId))
                {
                    cached = true;
                    result = m_cacheddecode[AssetId];
                }
            }

            // If it's cached, return the cached results
            if (cached)
            {
                decodedReturn(AssetId, result);
            }
            else
            {
                // not cached, so we need to decode it
                // Add to notify list and start decoding.
                // Next request for this asset while it's decoding will only be added to the notify list
                // once this is decoded, requests will be served from the cache and all clients in the notifylist will be updated
                bool decode = false;
                lock (m_notifyList)
                {
                    if (m_notifyList.ContainsKey(AssetId))
                    {
                        m_notifyList[AssetId].Add(decodedReturn);
                    }
                    else
                    {
                        List<DecodedCallback> notifylist = new List<DecodedCallback>();
                        notifylist.Add(decodedReturn);
                        m_notifyList.Add(AssetId, notifylist);
                        decode = true;
                    }
                }
                // Do Decode!
                if (decode)
                {
                    doJ2kDecode(AssetId, assetData);
                }
            }
        }