aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs')
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs316
1 files changed, 0 insertions, 316 deletions
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs b/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs
index 6bfab90..af359b3 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs
@@ -263,320 +263,4 @@ namespace OpenSim.Region.ClientStack.LindenUDP
263 263
264 264
265 } 265 }
266
267 /*
268 *
269 * J2KImage
270 *
271 * We use this class to store image data and associated request data and attributes
272 *
273 *
274 *
275 */
276
277 public class J2KImage
278 {
279 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
280 public double m_designatedPriorityKey;
281 public double m_requestedPriority = 0.0d;
282 public uint m_lastSequence = 0;
283 public uint m_requestedPacketNumber;
284 public sbyte m_requestedDiscardLevel;
285 public UUID m_requestedUUID;
286 public IJ2KDecoder m_j2kDecodeModule;
287 public IAssetCache m_assetCache;
288 public OpenJPEG.J2KLayerInfo[] Layers = new OpenJPEG.J2KLayerInfo[0];
289 public AssetBase m_MissingSubstitute = null;
290 public bool m_decoded = false;
291 public bool m_completedSendAtCurrentDiscardLevel;
292
293 private sbyte m_discardLevel=-1;
294 private uint m_packetNumber;
295 private bool m_decoderequested = false;
296 private bool m_hasasset = false;
297 private bool m_asset_requested = false;
298 private bool m_sentinfo = false;
299 private uint m_stopPacket = 0;
300 private const int cImagePacketSize = 1000;
301 private const int cFirstPacketSize = 600;
302 private AssetBase m_asset = null;
303
304
305 public uint m_pPacketNumber
306 {
307 get { return m_packetNumber; }
308 }
309 public uint m_pStopPacketNumber
310 {
311 get { return m_stopPacket; }
312 }
313
314 public byte[] Data
315 {
316 get { return m_asset.Data; }
317 }
318
319 public ushort TexturePacketCount()
320 {
321 if (!m_decoded)
322 return 0;
323 return (ushort)(((m_asset.Data.Length - cFirstPacketSize + cImagePacketSize - 1) / cImagePacketSize) + 1);
324 }
325
326 public void J2KDecodedCallback(UUID AssetId, OpenJPEG.J2KLayerInfo[] layers)
327 {
328 Layers = layers;
329 m_decoded = true;
330 RunUpdate();
331 }
332
333 public void AssetDataCallback(UUID AssetID, AssetBase asset)
334 {
335 m_hasasset = true;
336 if (asset == null || asset.Data == null)
337 {
338 m_asset = m_MissingSubstitute;
339 }
340 else
341 {
342 m_asset = asset;
343 }
344 RunUpdate();
345 }
346
347 private int GetPacketForBytePosition(int bytePosition)
348 {
349 return ((bytePosition - cFirstPacketSize + cImagePacketSize - 1) / cImagePacketSize) + 1;
350 }
351 public int LastPacketSize()
352 {
353 if (m_packetNumber == 1)
354 return m_asset.Data.Length;
355 return (m_asset.Data.Length - cFirstPacketSize) % cImagePacketSize;
356 }
357
358 public int CurrentBytePosition()
359 {
360 if (m_packetNumber == 0)
361 return 0;
362 if (m_packetNumber == 1)
363 return cFirstPacketSize;
364
365 int result = cFirstPacketSize + ((int)m_packetNumber - 2) * cImagePacketSize;
366 if (result < 0)
367 {
368 result = cFirstPacketSize;
369 }
370 return result;
371 }
372 public bool SendFirstPacket(LLClientView client)
373 {
374
375 // Do we have less then 1 packet's worth of data?
376 if (m_asset.Data.Length <= cFirstPacketSize)
377 {
378 // Send only 1 packet
379 client.SendImageFirstPart(1, m_requestedUUID, (uint)m_asset.Data.Length, m_asset.Data, 2);
380 m_stopPacket = 0;
381 return true;
382 }
383 else
384 {
385 byte[] firstImageData = new byte[cFirstPacketSize];
386 try
387 {
388 Buffer.BlockCopy(m_asset.Data, 0, firstImageData, 0, (int)cFirstPacketSize);
389 client.SendImageFirstPart(TexturePacketCount(), m_requestedUUID, (uint)m_asset.Data.Length, firstImageData, 2);
390 }
391 catch (Exception)
392 {
393 m_log.Error("Texture block copy failed. Possibly out of memory?");
394 return true;
395 }
396 }
397 return false;
398
399 }
400 private bool SendPacket(LLClientView client)
401 {
402 bool complete = false;
403 int imagePacketSize = ((int)m_packetNumber == (TexturePacketCount())) ? LastPacketSize() : cImagePacketSize;
404
405 if ((CurrentBytePosition() + cImagePacketSize) > m_asset.Data.Length)
406 {
407 imagePacketSize = LastPacketSize();
408 complete=true;
409 if ((CurrentBytePosition() + imagePacketSize) > m_asset.Data.Length)
410 {
411 imagePacketSize = m_asset.Data.Length - CurrentBytePosition();
412 complete = true;
413 }
414 }
415
416 //It's concievable that the client might request packet one
417 //from a one packet image, which is really packet 0,
418 //which would leave us with a negative imagePacketSize..
419 if (imagePacketSize > 0)
420 {
421 byte[] imageData = new byte[imagePacketSize];
422 try
423 {
424 Buffer.BlockCopy(m_asset.Data, CurrentBytePosition(), imageData, 0, imagePacketSize);
425 }
426 catch (Exception e)
427 {
428 m_log.Error("Error copying texture block. Out of memory? imagePacketSize was " + imagePacketSize.ToString() + " on packet " + m_packetNumber.ToString() + " out of " + m_stopPacket.ToString() + ". Exception: " + e.ToString());
429 return false;
430 }
431
432 //Send the packet
433 client.SendImageNextPart((ushort)(m_packetNumber-1), m_requestedUUID, imageData);
434
435 }
436 if (complete)
437 {
438 return false;
439 }
440 else
441 {
442 return true;
443 }
444
445
446 }
447 public bool SendPackets(LLClientView client)
448 {
449
450 if (!m_completedSendAtCurrentDiscardLevel)
451 {
452 if (m_packetNumber <= m_stopPacket)
453 {
454
455 bool SendMore = true;
456 if (!m_sentinfo || (m_packetNumber == 0))
457 {
458 if (SendFirstPacket(client))
459 {
460 SendMore = false;
461 }
462 m_sentinfo = true;
463 m_packetNumber++;
464 }
465
466 if (m_packetNumber < 2)
467 {
468 m_packetNumber = 2;
469 }
470
471 int count=0;
472 while (SendMore && count < 5 && m_packetNumber <= m_stopPacket)
473 {
474 count++;
475 SendMore = SendPacket(client);
476 m_packetNumber++;
477 }
478 if (m_packetNumber > m_stopPacket)
479 {
480
481 return true;
482
483 }
484
485 }
486
487 }
488 return false;
489 }
490
491 public void RunUpdate()
492 {
493 //This is where we decide what we need to update
494 //and assign the real discardLevel and packetNumber
495 //assuming of course that the connected client might be bonkers
496
497 if (!m_hasasset)
498 {
499
500 if (!m_asset_requested)
501 {
502 m_asset_requested = true;
503 m_assetCache.GetAsset(m_requestedUUID, AssetDataCallback, true);
504
505 }
506
507 }
508 else
509 {
510
511
512 if (!m_decoded)
513 {
514 //We need to decode the requested image first
515 if (!m_decoderequested)
516 {
517 //Request decode
518 m_decoderequested = true;
519 // Do we have a jpeg decoder?
520 if (m_j2kDecodeModule != null)
521 {
522 // Send it off to the jpeg decoder
523 m_j2kDecodeModule.decode(m_requestedUUID, Data, J2KDecodedCallback);
524
525 }
526 else
527 {
528 J2KDecodedCallback(m_requestedUUID, new OpenJPEG.J2KLayerInfo[0]);
529 }
530 }
531
532 }
533 else
534 {
535
536
537 //discardLevel of -1 means just update the priority
538 if (m_requestedDiscardLevel != -1)
539 {
540
541 //Evaluate the discard level
542 //First, is it positive?
543 if (m_requestedDiscardLevel >= 0)
544 {
545 if (m_requestedDiscardLevel > Layers.Length - 1)
546 {
547 m_discardLevel = (sbyte)(Layers.Length - 1);
548 }
549 else
550 {
551 m_discardLevel = m_requestedDiscardLevel;
552 }
553
554 //Calculate the m_stopPacket
555 if (Layers.Length > 0)
556 {
557 m_stopPacket = (uint)GetPacketForBytePosition(Layers[(Layers.Length - 1) - m_discardLevel].End);
558 }
559 else
560 {
561 m_stopPacket = TexturePacketCount();
562 }
563 //Don't reset packet number unless we're waiting or it's ahead of us
564 if (m_completedSendAtCurrentDiscardLevel || m_requestedPacketNumber>m_packetNumber)
565 {
566 m_packetNumber = m_requestedPacketNumber;
567 }
568
569 if (m_packetNumber <= m_stopPacket)
570 {
571 m_completedSendAtCurrentDiscardLevel = false;
572 }
573
574 }
575
576 }
577 }
578 }
579 }
580
581 }
582} 266}