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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. namespace rdr {
  22. class InStream;
  23. class OutStream;
  24. }
  25. namespace rfb {
  26. class ServerParams;
  27. class ModifiablePixelBuffer;
  28. class Region;
  29. struct Rect;
  30. enum DecoderFlags {
  31. // A constant for decoders that don't need anything special
  32. DecoderPlain = 0,
  33. // All rects for this decoder must be handled in order
  34. DecoderOrdered = 1 << 0,
  35. // Only some of the rects must be handled in order,
  36. // see doesRectsConflict()
  37. DecoderPartiallyOrdered = 1 << 1,
  38. };
  39. class Decoder {
  40. public:
  41. Decoder(enum DecoderFlags flags);
  42. virtual ~Decoder();
  43. // These functions are the main interface to an individual decoder
  44. // readRect() transfers data for the given rectangle from the
  45. // InStream to the OutStream, possibly changing it along the way to
  46. // make it easier to decode. This function will always be called in
  47. // a serial manner on the main thread.
  48. virtual void readRect(const Rect& r, rdr::InStream* is,
  49. const ServerParams& server, rdr::OutStream* os)=0;
  50. // These functions will be called from any of the worker threads.
  51. // A lock will be held whilst these are called so it is safe to
  52. // read and update internal state as necessary.
  53. // getAffectedRegion() returns the parts of the frame buffer will
  54. // be either read from or written do when decoding this rect. The
  55. // default implementation simply returns the given rectangle.
  56. virtual void getAffectedRegion(const Rect& rect, const void* buffer,
  57. size_t buflen, const ServerParams& server,
  58. Region* region);
  59. // doesRectsConflict() determines if two rectangles must be decoded
  60. // in the order they were received. This will only be called if the
  61. // DecoderPartiallyOrdered flag has been set.
  62. virtual bool doRectsConflict(const Rect& rectA,
  63. const void* bufferA,
  64. size_t buflenA,
  65. const Rect& rectB,
  66. const void* bufferB,
  67. size_t buflenB,
  68. const ServerParams& server);
  69. // decodeRect() decodes the given rectangle with data from the
  70. // given buffer, onto the ModifiablePixelBuffer. The PixelFormat of
  71. // the PixelBuffer might not match the ConnParams and it is up to
  72. // the decoder to do any necessary conversion.
  73. virtual void decodeRect(const Rect& r, const void* buffer,
  74. size_t buflen, const ServerParams& server,
  75. ModifiablePixelBuffer* pb)=0;
  76. public:
  77. static bool supported(int encoding);
  78. static Decoder* createDecoder(int encoding);
  79. public:
  80. const enum DecoderFlags flags;
  81. };
  82. }
  83. #endif