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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. bool decodeRect(const Rect& r, int encoding,
  42. ModifiablePixelBuffer* pb);
  43. void flush();
  44. private:
  45. void logStats();
  46. void setThreadException(const rdr::Exception& e);
  47. void throwThreadException();
  48. private:
  49. CConnection *conn;
  50. Decoder *decoders[encodingMax+1];
  51. struct DecoderStats {
  52. unsigned rects;
  53. unsigned long long bytes;
  54. unsigned long long pixels;
  55. unsigned long long equivalent;
  56. };
  57. DecoderStats stats[encodingMax+1];
  58. struct QueueEntry {
  59. bool active;
  60. Rect rect;
  61. int encoding;
  62. Decoder* decoder;
  63. const ServerParams* server;
  64. ModifiablePixelBuffer* pb;
  65. rdr::MemOutStream* bufferStream;
  66. Region affectedRegion;
  67. };
  68. std::list<rdr::MemOutStream*> freeBuffers;
  69. std::list<QueueEntry*> workQueue;
  70. os::Mutex* queueMutex;
  71. os::Condition* producerCond;
  72. os::Condition* consumerCond;
  73. private:
  74. class DecodeThread : public os::Thread {
  75. public:
  76. DecodeThread(DecodeManager* manager);
  77. ~DecodeThread();
  78. void stop();
  79. protected:
  80. void worker();
  81. DecodeManager::QueueEntry* findEntry();
  82. private:
  83. DecodeManager* manager;
  84. bool stopRequested;
  85. };
  86. std::list<DecodeThread*> threads;
  87. rdr::Exception *threadException;
  88. };
  89. }
  90. #endif