SpoutMemoryShare.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. SpoutMemoryShare.h
  3. Spout memory map management for sharing images via shared memory
  4. Revised over original single reader/writer pair
  5. LJ - leadedge@adam.com.au
  6. Thanks and credit to Malcolm Bechard for the SpoutSharedMemory class
  7. https://github.com/mbechard
  8. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9. Copyright (c) 2014-2015, Lynn Jarvis. All rights reserved.
  10. Redistribution and use in source and binary forms, with or without modification,
  11. are permitted provided that the following conditions are met:
  12. 1. Redistributions of source code must retain the above copyright notice,
  13. this list of conditions and the following disclaimer.
  14. 2. Redistributions in binary form must reproduce the above copyright notice,
  15. this list of conditions and the following disclaimer in the documentation
  16. and/or other materials provided with the distribution.
  17. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
  18. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  23. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  25. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #pragma once
  28. #ifndef __spoutMemoryShare__
  29. #define __spoutMemoryShare__
  30. #include <windowsx.h>
  31. #include <string>
  32. #include "SpoutCommon.h"
  33. #include "SpoutSharedMemory.h"
  34. using namespace std;
  35. class SPOUT_DLLEXP spoutMemoryShare {
  36. public:
  37. spoutMemoryShare();
  38. ~spoutMemoryShare();
  39. // Create / Open, Update or Close a sender memory map
  40. bool CreateSenderMemory (const char *sendername, unsigned int width, unsigned int height);
  41. bool UpdateSenderMemorySize (const char* sendername, unsigned int width, unsigned int height);
  42. bool OpenSenderMemory (const char *sendername);
  43. void CloseSenderMemory ();
  44. // Retrieve global width and height
  45. bool GetSenderMemorySize(unsigned int &width, unsigned int &height);
  46. // Lock and unlock memory and retrieve buffer pointer
  47. unsigned char * LockSenderMemory();
  48. void UnlockSenderMemory();
  49. // TODO : Basic write and read ?
  50. // bool WriteSenderMemory(const char *buffer, int nBytes);
  51. // bool ReadSenderMemory (const char *buffer, int nBytes);
  52. // Close and release memory object
  53. void ReleaseSenderMemory ();
  54. protected:
  55. SpoutSharedMemory *senderMem;
  56. unsigned int m_Width;
  57. unsigned int m_Height;
  58. };
  59. #endif