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.

DecodeManager.h 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* Copyright 2015 Pierre Ossman for Cendio AB
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. #ifndef __RFB_DECODEMANAGER_H__
  19. #define __RFB_DECODEMANAGER_H__
  20. #include <list>
  21. #include <os/Thread.h>
  22. #include <rfb/Region.h>
  23. #include <rfb/encodings.h>
  24. namespace os {
  25. class Condition;
  26. class Mutex;
  27. }
  28. namespace rdr {
  29. struct Exception;
  30. class MemOutStream;
  31. }
  32. namespace rfb {
  33. class CConnection;
  34. class Decoder;
  35. class ModifiablePixelBuffer;
  36. struct Rect;
  37. class DecodeManager {
  38. public:
  39. DecodeManager(CConnection *conn);
  40. ~DecodeManager();
  41. void decodeRect(const Rect& r, int encoding,
  42. ModifiablePixelBuffer* pb);
  43. void flush();
  44. private:
  45. void setThreadException(const rdr::Exception& e);
  46. void throwThreadException();
  47. private:
  48. CConnection *conn;
  49. Decoder *decoders[encodingMax+1];
  50. struct QueueEntry {
  51. bool active;
  52. Rect rect;
  53. int encoding;
  54. Decoder* decoder;
  55. const ServerParams* server;
  56. ModifiablePixelBuffer* pb;
  57. rdr::MemOutStream* bufferStream;
  58. Region affectedRegion;
  59. };
  60. std::list<rdr::MemOutStream*> freeBuffers;
  61. std::list<QueueEntry*> workQueue;
  62. os::Mutex* queueMutex;
  63. os::Condition* producerCond;
  64. os::Condition* consumerCond;
  65. private:
  66. class DecodeThread : public os::Thread {
  67. public:
  68. DecodeThread(DecodeManager* manager);
  69. ~DecodeThread();
  70. void stop();
  71. protected:
  72. void worker();
  73. DecodeManager::QueueEntry* findEntry();
  74. private:
  75. DecodeManager* manager;
  76. bool stopRequested;
  77. };
  78. std::list<DecodeThread*> threads;
  79. rdr::Exception *threadException;
  80. };
  81. }
  82. #endif