jack2 codebase
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.

145 lines
5.5KB

  1. /*
  2. Copyright (C) 2001-2003 Paul Davis
  3. Copyright (C) 2005-2012 Grame
  4. Copyright (C) 2013 Samsung Electronics
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU Lesser General Public License as published by
  7. the Free Software Foundation; either version 2.1 of the License, or
  8. (at your option) any later version.
  9. This program 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 Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. #ifndef __jack_shm_android_h__
  18. #define __jack_shm_android_h__
  19. #include <limits.h>
  20. #include <sys/types.h>
  21. #include "types.h"
  22. #include "JackCompilerDeps.h"
  23. #include <binder/MemoryHeapBase.h>
  24. #include <utils/RefBase.h>
  25. #ifdef __cplusplus
  26. extern "C"
  27. {
  28. #endif
  29. #define JACK_SHM_REGISTRY_FD -1
  30. #define JACK_SHM_HEAP_ENOUGH_COUNT 300
  31. void jack_instantiate();
  32. #ifdef __cplusplus
  33. }
  34. #endif
  35. namespace android {
  36. class IAndroidShm;
  37. class Shm {
  38. public:
  39. static Shm* Instantiate();
  40. virtual ~Shm();
  41. private:
  42. Shm();
  43. Shm( const Shm&);
  44. Shm& operator=(const Shm);
  45. private:
  46. void set_server_prefix (const char *server_name);
  47. int server_initialize_shm (int new_registry);
  48. int shm_lock_registry (void);
  49. void shm_unlock_registry (void);
  50. int access_registry (jack_shm_info_t *ri);
  51. void remove_shm (jack_shm_id_t *id);
  52. int create_registry (jack_shm_info_t *ri);
  53. int shm_validate_registry ();
  54. int GetUID();
  55. int GetPID();
  56. void shm_init_registry ();
  57. void release_shm_entry (jack_shm_registry_index_t index);
  58. jack_shm_registry_t * get_free_shm_info ();
  59. public:
  60. static void jack_shm_copy_from_registry (jack_shm_info_t*, jack_shm_registry_index_t);
  61. static void jack_shm_copy_to_registry (jack_shm_info_t*, jack_shm_registry_index_t*);
  62. static int jack_release_shm_info (jack_shm_registry_index_t);
  63. static char* jack_shm_addr (jack_shm_info_t* si);
  64. static int jack_register_server (const char *server_name, int new_registry);
  65. static int jack_unregister_server (const char *server_name);
  66. static int jack_initialize_shm (const char *server_name);
  67. static int jack_initialize_shm_server (void);
  68. static int jack_initialize_shm_client (void);
  69. static int jack_cleanup_shm (void);
  70. static int jack_shmalloc (const char *shm_name, jack_shmsize_t size, jack_shm_info_t* result);
  71. static void jack_release_shm (jack_shm_info_t*);
  72. static void jack_release_lib_shm (jack_shm_info_t*);
  73. static void jack_destroy_shm (jack_shm_info_t*);
  74. static int jack_attach_shm (jack_shm_info_t*);
  75. static int jack_attach_lib_shm (jack_shm_info_t*);
  76. static int jack_attach_shm_read (jack_shm_info_t*);
  77. static int jack_attach_lib_shm_read (jack_shm_info_t*);
  78. static int jack_resize_shm (jack_shm_info_t*, jack_shmsize_t size);
  79. public:
  80. void shm_copy_from_registry (jack_shm_info_t*, jack_shm_registry_index_t);
  81. void shm_copy_to_registry (jack_shm_info_t*, jack_shm_registry_index_t*);
  82. int release_shm_info (jack_shm_registry_index_t);
  83. char* shm_addr (unsigned int fd);
  84. // here begin the API
  85. int register_server (const char *server_name, int new_registry);
  86. int unregister_server (const char *server_name);
  87. int initialize_shm (const char *server_name);
  88. int initialize_shm_server (void);
  89. int initialize_shm_client (void);
  90. int cleanup_shm (void);
  91. int shmalloc (const char *shm_name, jack_shmsize_t size, jack_shm_info_t* result);
  92. void release_shm (jack_shm_info_t*);
  93. void release_lib_shm (jack_shm_info_t*);
  94. void destroy_shm (jack_shm_info_t*);
  95. int attach_shm (jack_shm_info_t*);
  96. int attach_lib_shm (jack_shm_info_t*);
  97. int attach_shm_read (jack_shm_info_t*);
  98. int attach_lib_shm_read (jack_shm_info_t*);
  99. int resize_shm (jack_shm_info_t*, jack_shmsize_t size);
  100. private:
  101. static jack_shmtype_t jack_shmtype;
  102. static jack_shm_id_t registry_id;
  103. static jack_shm_fd_t registry_fd;
  104. static jack_shm_info_t registry_info;
  105. static jack_shm_header_t *jack_shm_header;
  106. static jack_shm_registry_t *jack_shm_registry;
  107. static char jack_shm_server_prefix[JACK_SERVER_NAME_SIZE+1];
  108. static int semid;
  109. static pthread_mutex_t mutex;
  110. static Shm* ref;
  111. void jack_release_shm_entry (jack_shm_registry_index_t index);
  112. int jack_shm_lock_registry (void);
  113. void jack_shm_unlock_registry (void);
  114. //static sp<IAndroidShm> mShmService;
  115. static sp<IMemoryHeap> mShmMemBase[JACK_SHM_HEAP_ENOUGH_COUNT];
  116. public:
  117. static sp<IAndroidShm> getShmService();
  118. };
  119. };
  120. #endif /* __jack_shm_android_h__ */