ProxyProducer.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 ProxyProducer.h
  23. * @brief Audio/Video proxy consumers.
  24. *
  25. * @author Mamadou Diop <diopmamadou(at)doubango.org>
  26. *
  27. */
  28. #ifndef TINYWRAP_PRODUCER_PROXY_H
  29. #define TINYWRAP_PRODUCER_PROXY_H
  30. #include "tinyWRAP_config.h"
  31. #include "ProxyPluginMgr.h"
  32. #include "tinymedia/tmedia_common.h"
  33. #include "tinymedia/tmedia_producer.h"
  34. /* ============ ProxyAudioProducerCallback Class ================= */
  35. class ProxyAudioProducerCallback
  36. {
  37. public:
  38. ProxyAudioProducerCallback() { }
  39. virtual ~ProxyAudioProducerCallback() { }
  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. // this function is called to signal that it's time to copy push data
  53. virtual int fillPushBuffer() {
  54. return -1;
  55. }
  56. };
  57. /* ============ ProxyAudioProducer Class ================= */
  58. class ProxyAudioProducer : public ProxyPlugin
  59. {
  60. public:
  61. #if !defined(SWIG)
  62. ProxyAudioProducer(struct twrap_producer_proxy_audio_s* pProducer);
  63. #endif
  64. virtual ~ProxyAudioProducer();
  65. bool setActualSndCardRecordParams(int nPtime, int nRate, int nChannels);
  66. bool setPushBuffer(const void* pPushBufferPtr, unsigned nPushBufferSize, bool bUsePushCallback=false);
  67. int push(const void* pBuffer=tsk_null, unsigned nSize=0);
  68. bool setGain(unsigned nGain);
  69. unsigned getGain();
  70. void setCallback(ProxyAudioProducerCallback* pCallback) {
  71. m_pCallback = pCallback;
  72. }
  73. #if !defined(SWIG)
  74. inline bool usePushCallback() {
  75. return m_bUsePushCallback;
  76. }
  77. inline ProxyAudioProducerCallback* getCallback()const {
  78. return m_pCallback;
  79. }
  80. virtual inline bool isWrapping(tsk_object_t* pWrappedPlugin) {
  81. return m_pWrappedPlugin == pWrappedPlugin;
  82. }
  83. #endif
  84. virtual inline uint64_t getMediaSessionId() {
  85. return m_pWrappedPlugin ? TMEDIA_PRODUCER(m_pWrappedPlugin)->session_id : 0;
  86. }
  87. #if !defined(SWIG)
  88. public:
  89. bool startPushCallback();
  90. bool stopPushCallback();
  91. private:
  92. static int pushTimerCallback(const void* arg, tsk_timer_id_t timer_id);
  93. #endif
  94. public:
  95. static bool registerPlugin();
  96. private:
  97. struct twrap_producer_proxy_audio_s* m_pWrappedPlugin;
  98. ProxyAudioProducerCallback* m_pCallback;
  99. struct {
  100. const void* pPushBufferPtr;
  101. unsigned nPushBufferSize;
  102. } m_PushBuffer;
  103. bool m_bUsePushCallback;
  104. void* m_hPushTimerMgr;
  105. uint64_t m_uPushTimer;
  106. };
  107. /* ============ ProxyVideoProducerCallback Class ================= */
  108. class ProxyVideoProducerCallback
  109. {
  110. public:
  111. ProxyVideoProducerCallback() { }
  112. virtual ~ProxyVideoProducerCallback() { }
  113. virtual int prepare(int width, int height, int fps) {
  114. return -1;
  115. }
  116. virtual int start() {
  117. return -1;
  118. }
  119. virtual int pause() {
  120. return -1;
  121. }
  122. virtual int stop() {
  123. return -1;
  124. }
  125. };
  126. /* ============ ProxyVideoProducer Class ================= */
  127. class ProxyVideoProducer : public ProxyPlugin
  128. {
  129. public:
  130. #if !defined(SWIG)
  131. ProxyVideoProducer(tmedia_chroma_t eChroma, struct twrap_producer_proxy_video_s* pProducer);
  132. #endif
  133. virtual ~ProxyVideoProducer();
  134. int getRotation()const;
  135. bool setRotation(int nRot);
  136. bool getMirror()const;
  137. bool setMirror(bool bMirror);
  138. bool setActualCameraOutputSize(unsigned nWidth, unsigned nHeight);
  139. int push(const void* pBuffer, unsigned nSize);
  140. void setCallback(ProxyVideoProducerCallback* pCallback) {
  141. m_pCallback = pCallback;
  142. }
  143. #if !defined(SWIG)
  144. int sendRaw(const void* pBuffer, unsigned nSize, unsigned nDuration, bool bMarker);
  145. int sendRaw(const void* pBuffer, unsigned nSize, const void* proto_hdr);
  146. inline ProxyVideoProducerCallback* getCallback()const {
  147. return m_pCallback;
  148. }
  149. virtual inline bool isWrapping(tsk_object_t* wrapped_plugin) {
  150. return m_pWrappedPlugin == wrapped_plugin;
  151. }
  152. virtual inline const tmedia_producer_t* getWrappedPlugin()const {
  153. return (tmedia_producer_t*)m_pWrappedPlugin;
  154. }
  155. #endif
  156. virtual inline uint64_t getMediaSessionId() {
  157. return m_pWrappedPlugin ? TMEDIA_PRODUCER(m_pWrappedPlugin)->session_id : 0;
  158. }
  159. public:
  160. static bool registerPlugin();
  161. static void setDefaultChroma(tmedia_chroma_t eChroma) {
  162. s_eDefaultChroma = eChroma;
  163. }
  164. #if !defined(SWIG)
  165. tmedia_chroma_t getChroma()const;
  166. static tmedia_chroma_t getDefaultChroma() {
  167. return s_eDefaultChroma;
  168. }
  169. #endif
  170. private:
  171. struct twrap_producer_proxy_video_s* m_pWrappedPlugin;
  172. ProxyVideoProducerCallback* m_pCallback;
  173. tmedia_chroma_t m_eChroma;
  174. int m_nRotation;
  175. bool m_bMirror;
  176. static tmedia_chroma_t s_eDefaultChroma;
  177. };
  178. #endif /* TINYWRAP_PRODUCER_PROXY_H */