ProxyConsumer.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /*
  2. * Copyright (C) 2010-2011 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango.org>
  5. *
  6. * This file is part of Open Source Doubango Framework.
  7. *
  8. * DOUBANGO is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * DOUBANGO is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with DOUBANGO.
  20. *
  21. */
  22. /**@file ProxyConsumer.h
  23. * @brief Audio/Video proxy consumers.
  24. *
  25. * @author Mamadou Diop <diopmamadou(at)doubango.org>
  26. */
  27. #ifndef TINYWRAP_CONSUMER_PROXY_H
  28. #define TINYWRAP_CONSUMER_PROXY_H
  29. #include "tinyWRAP_config.h"
  30. #include "ProxyPluginMgr.h"
  31. #include "tinymedia/tmedia_common.h"
  32. #include "tinymedia/tmedia_consumer.h"
  33. class AudioResampler;
  34. /* ============ ProxyAudioConsumerCallback Class ================= */
  35. class ProxyAudioConsumerCallback
  36. {
  37. public:
  38. ProxyAudioConsumerCallback() { }
  39. virtual ~ProxyAudioConsumerCallback() { }
  40. virtual int prepare(int ptime, int rate, int channels) {
  41. return -1;
  42. }
  43. virtual int start() {
  44. return -1;
  45. }
  46. virtual int pause() {
  47. return -1;
  48. }
  49. virtual int stop() {
  50. return -1;
  51. }
  52. #if !defined(SWIG)
  53. // whether the audio buffer have to be stored in the JB then pulled using "ProxyAudioConsumer::pull()" or not
  54. virtual bool putInJitterBuffer() {
  55. return true;
  56. }
  57. // whether we are using the "telepresence" system (PIVOT audio settings must not be changed)
  58. virtual bool isPivotSettings() {
  59. return false;
  60. }
  61. // only called if "putInJitterBuffer()" return "true"
  62. virtual int consume(const void* buffer_ptr, tsk_size_t buffer_size, const tsk_object_t* proto_hdr) {
  63. return -1;
  64. }
  65. #endif
  66. };
  67. /* ============ ProxyAudioConsumer Class ================= */
  68. class ProxyAudioConsumer : public ProxyPlugin
  69. {
  70. public:
  71. #if !defined(SWIG)
  72. ProxyAudioConsumer(struct twrap_consumer_proxy_audio_s* pConsumer);
  73. #endif
  74. virtual ~ProxyAudioConsumer();
  75. bool setActualSndCardPlaybackParams(int nPtime, int nRate, int nChannels);
  76. bool queryForResampler(uint16_t nInFreq, uint16_t nOutFreq, uint16_t nFrameDuration, uint16_t nChannels, uint16_t nResamplerQuality);
  77. bool setPullBuffer(const void* pPullBufferPtr, unsigned nPullBufferSize);
  78. unsigned pull(void* pOutput=tsk_null, unsigned nSize=0);
  79. bool setGain(unsigned nGain);
  80. unsigned getGain();
  81. bool reset();
  82. void setCallback(ProxyAudioConsumerCallback* pCallback) {
  83. m_pCallback = pCallback;
  84. }
  85. #if !defined(SWIG)
  86. inline ProxyAudioConsumerCallback* getCallback()const {
  87. return m_pCallback;
  88. }
  89. virtual inline bool isWrapping(tsk_object_t* pWrappedPlugin) {
  90. return m_pWrappedPlugin == pWrappedPlugin;
  91. }
  92. #endif
  93. virtual inline uint64_t getMediaSessionId() {
  94. return m_pWrappedPlugin ? TMEDIA_CONSUMER(m_pWrappedPlugin)->session_id : 0;
  95. }
  96. public:
  97. static bool registerPlugin();
  98. private:
  99. struct twrap_consumer_proxy_audio_s* m_pWrappedPlugin;
  100. ProxyAudioConsumerCallback* m_pCallback;
  101. struct {
  102. const void* pPullBufferPtr;
  103. unsigned nPullBufferSize;
  104. } m_PullBuffer;
  105. struct {
  106. void* pInBufferPtr;
  107. unsigned nInBufferSizeInByte;
  108. AudioResampler* pResampler;
  109. } m_Resampler;
  110. };
  111. class ProxyVideoFrame;
  112. /* ============ ProxyVideoConsumerCallback Class ================= */
  113. class ProxyVideoConsumerCallback
  114. {
  115. public:
  116. ProxyVideoConsumerCallback() {}
  117. virtual ~ProxyVideoConsumerCallback() {}
  118. virtual int prepare(int nWidth, int nHeight, int nFps) {
  119. return -1;
  120. }
  121. virtual int consume(const ProxyVideoFrame* frame) {
  122. return -1;
  123. }
  124. // only called if a buffer is registered using setPullBuffer(). Otherwise, consume() will be called
  125. virtual int bufferCopied(unsigned nCopiedSize, unsigned nAvailableSize) {
  126. return -1;
  127. }
  128. virtual int start() {
  129. return -1;
  130. }
  131. virtual int pause() {
  132. return -1;
  133. }
  134. virtual int stop() {
  135. return -1;
  136. }
  137. };
  138. /* ============ ProxyVideoConsumer Class ================= */
  139. class ProxyVideoConsumer : public ProxyPlugin
  140. {
  141. public:
  142. #if !defined(SWIG)
  143. ProxyVideoConsumer(tmedia_chroma_t eChroma, struct twrap_consumer_proxy_video_s* pConsumer);
  144. #endif
  145. virtual ~ProxyVideoConsumer();
  146. bool setDisplaySize(unsigned nWidth, unsigned nHeight);
  147. unsigned getDisplayWidth();
  148. unsigned getDisplayHeight();
  149. unsigned getDecodedWidth();
  150. unsigned getDecodedHeight();
  151. void setCallback(ProxyVideoConsumerCallback* pCallback) {
  152. m_pCallback = pCallback;
  153. }
  154. bool setAutoResizeDisplay(bool bAutoResizeDisplay);
  155. bool getAutoResizeDisplay()const;
  156. bool setConsumeBuffer(const void* pConsumeBufferPtr, unsigned nConsumeBufferSize);
  157. unsigned pull(void* pOutput, unsigned nSize);
  158. bool reset();
  159. #if !defined(SWIG)
  160. bool hasConsumeBuffer()const {
  161. return m_ConsumeBuffer.pConsumeBufferPtr && m_ConsumeBuffer.nConsumeBufferSize;
  162. }
  163. unsigned copyBuffer(const void* pBuffer, unsigned nSize)const;
  164. inline ProxyVideoConsumerCallback* getCallback()const {
  165. return m_pCallback;
  166. }
  167. virtual inline bool isWrapping(tsk_object_t* wrapped_plugin) {
  168. return m_pWrappedPlugin == wrapped_plugin;
  169. }
  170. #endif
  171. virtual inline uint64_t getMediaSessionId() {
  172. return m_pWrappedPlugin ? TMEDIA_CONSUMER(m_pWrappedPlugin)->session_id : 0;
  173. }
  174. public:
  175. static bool registerPlugin();
  176. static void setDefaultChroma(tmedia_chroma_t eChroma) {
  177. s_eDefaultChroma = eChroma;
  178. }
  179. static void setDefaultAutoResizeDisplay(bool bAutoResizeDisplay) {
  180. s_bAutoResizeDisplay = bAutoResizeDisplay;
  181. }
  182. #if !defined(SWIG)
  183. tmedia_chroma_t getChroma()const;
  184. static tmedia_chroma_t getDefaultChroma() {
  185. return s_eDefaultChroma;
  186. }
  187. static bool getDefaultAutoResizeDisplay() {
  188. return s_bAutoResizeDisplay;
  189. }
  190. #endif
  191. private:
  192. struct twrap_consumer_proxy_video_s* m_pWrappedPlugin;
  193. tmedia_chroma_t m_eChroma;
  194. ProxyVideoConsumerCallback* m_pCallback;
  195. struct {
  196. const void* pConsumeBufferPtr;
  197. unsigned nConsumeBufferSize;
  198. } m_ConsumeBuffer;
  199. bool m_bAutoResizeDisplay;
  200. static tmedia_chroma_t s_eDefaultChroma;
  201. static bool s_bAutoResizeDisplay;
  202. };
  203. /* ============ ProxyVideoFrame Class ================= */
  204. class ProxyVideoFrame
  205. {
  206. public:
  207. #if !defined(SWIG)
  208. ProxyVideoFrame(const void* pBufferPtr, unsigned nBufferSize, unsigned nFrameWidth, unsigned nFrameHeight, const tsk_object_t* pProtoHdr);
  209. #endif
  210. virtual ~ProxyVideoFrame();
  211. public: /* For Java/C# applications */
  212. unsigned getSize();
  213. unsigned getContent(void* pOutput, unsigned nMaxsize);
  214. inline unsigned getFrameWidth()const {
  215. return m_nFrameWidth;
  216. }
  217. inline unsigned getFrameHeight()const {
  218. return m_nFrameHeight;
  219. }
  220. #if !defined(SWIG) /* For C/C++ applications */
  221. public:
  222. inline unsigned getBufferSize()const {
  223. return m_nBufferSize;
  224. }
  225. inline const void* getBufferPtr()const {
  226. return m_pBufferPtr;
  227. }
  228. inline const tsk_object_t* getProtoHdr()const {
  229. return m_pProtoHdr;
  230. }
  231. #endif
  232. private:
  233. const void* m_pBufferPtr;
  234. unsigned m_nBufferSize, m_nFrameWidth, m_nFrameHeight;
  235. const tsk_object_t* m_pProtoHdr;
  236. };
  237. #endif /* TINYWRAP_CONSUMER_PROXY_H */