You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Decoder.h 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright 2014 Pierre Ossman for Cendio AB
  3. *
  4. * This is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This software is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this software; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  17. * USA.
  18. */
  19. #ifndef __RFB_DECODER_H__
  20. #define __RFB_DECODER_H__
  21. #include <stdint.h>
  22. namespace rdr {
  23. class InStream;
  24. class OutStream;
  25. }
  26. namespace rfb {
  27. class ServerParams;
  28. class ModifiablePixelBuffer;
  29. class Region;
  30. struct Rect;
  31. enum DecoderFlags {
  32. // A constant for decoders that don't need anything special
  33. DecoderPlain = 0,
  34. // All rects for this decoder must be handled in order
  35. DecoderOrdered = 1 << 0,
  36. // Only some of the rects must be handled in order,
  37. // see doesRectsConflict()
  38. DecoderPartiallyOrdered = 1 << 1,
  39. };
  40. class Decoder {
  41. public:
  42. Decoder(enum DecoderFlags flags);
  43. virtual ~Decoder();
  44. // These functions are the main interface to an individual decoder
  45. // readRect() transfers data for the given rectangle from the
  46. // InStream to the OutStream, possibly changing it along the way to
  47. // make it easier to decode. This function will always be called in
  48. // a serial manner on the main thread.
  49. virtual bool readRect(const Rect& r, rdr::InStream* is,
  50. const ServerParams& server, rdr::OutStream* os)=0;
  51. // These functions will be called from any of the worker threads.
  52. // A lock will be held whilst these are called so it is safe to
  53. // read and update internal state as necessary.
  54. // getAffectedRegion() returns the parts of the frame buffer will
  55. // be either read from or written do when decoding this rect. The
  56. // default implementation simply returns the given rectangle.
  57. virtual void getAffectedRegion(const Rect& rect, const uint8_t* buffer,
  58. size_t buflen, const ServerParams& server,
  59. Region* region);
  60. // doesRectsConflict() determines if two rectangles must be decoded
  61. // in the order they were received. This will only be called if the
  62. // DecoderPartiallyOrdered flag has been set.
  63. virtual bool doRectsConflict(const Rect& rectA,
  64. const uint8_t* bufferA,
  65. size_t buflenA,
  66. const Rect& rectB,
  67. const uint8_t* bufferB,
  68. size_t buflenB,
  69. const ServerParams& server);
  70. // decodeRect() decodes the given rectangle with data from the
  71. // given buffer, onto the ModifiablePixelBuffer. The PixelFormat of
  72. // the PixelBuffer might not match the ConnParams and it is up to
  73. // the decoder to do any necessary conversion.
  74. virtual void decodeRect(const Rect& r, const uint8_t* buffer,
  75. size_t buflen, const ServerParams& server,
  76. ModifiablePixelBuffer* pb)=0;
  77. public:
  78. static bool supported(int encoding);
  79. static Decoder* createDecoder(int encoding);
  80. public:
  81. const enum DecoderFlags flags;
  82. };
  83. }
  84. #endif