plugin_win_mf_consumer_audio.cxx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* Copyright (C) 2013 Mamadou DIOP
  2. * Copyright (C) 2013 Doubango Telecom <http://www.doubango.org>
  3. *
  4. * This file is part of Open Source Doubango Framework.
  5. *
  6. * DOUBANGO is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * DOUBANGO is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with DOUBANGO.
  18. */
  19. #include "plugin_win_mf_config.h"
  20. #include "internals/mf_utils.h"
  21. #include "tinydav/audio/tdav_consumer_audio.h"
  22. #include "tsk_debug.h"
  23. typedef struct plugin_win_mf_consumer_audio_s {
  24. TDAV_DECLARE_CONSUMER_AUDIO;
  25. bool bStarted;
  26. }
  27. plugin_win_mf_consumer_audio_t;
  28. /* ============ Consumer Interface ================= */
  29. static int plugin_win_mf_consumer_audio_set(tmedia_consumer_t* self, const tmedia_param_t* param)
  30. {
  31. plugin_win_mf_consumer_audio_t* pSelf = (plugin_win_mf_consumer_audio_t*)self;
  32. int ret = tdav_consumer_audio_set(TDAV_CONSUMER_AUDIO(self), param);
  33. if(ret == 0) {
  34. }
  35. return ret;
  36. }
  37. static int plugin_win_mf_consumer_audio_prepare(tmedia_consumer_t* self, const tmedia_codec_t* codec)
  38. {
  39. plugin_win_mf_consumer_audio_t* pSelf = (plugin_win_mf_consumer_audio_t*)self;
  40. if(!pSelf) {
  41. TSK_DEBUG_ERROR("Invalid parameter");
  42. return -1;
  43. }
  44. return 0;
  45. }
  46. static int plugin_win_mf_consumer_audio_start(tmedia_consumer_t* self)
  47. {
  48. plugin_win_mf_consumer_audio_t* pSelf = (plugin_win_mf_consumer_audio_t*)self;
  49. pSelf->bStarted = true;
  50. return 0;
  51. }
  52. static int plugin_win_mf_consumer_audio_consume(tmedia_consumer_t* self, const void* buffer, tsk_size_t size, const tsk_object_t* proto_hdr)
  53. {
  54. if(!self || !buffer || !size) {
  55. TSK_DEBUG_ERROR("Invalid parameter");
  56. return -1;
  57. }
  58. /* buffer is already decoded */
  59. return tdav_consumer_audio_put(TDAV_CONSUMER_AUDIO(self), buffer, size, proto_hdr);
  60. }
  61. static int plugin_win_mf_consumer_audio_pause(tmedia_consumer_t* self)
  62. {
  63. return 0;
  64. }
  65. static int plugin_win_mf_consumer_audio_stop(tmedia_consumer_t* self)
  66. {
  67. plugin_win_mf_consumer_audio_t* pSelf = (plugin_win_mf_consumer_audio_t*)self;
  68. if(!pSelf) {
  69. TSK_DEBUG_ERROR("Invalid parameter");
  70. return -1;
  71. }
  72. if(!pSelf->bStarted) {
  73. TSK_DEBUG_INFO("WinMF audio consumer not started");
  74. return 0;
  75. }
  76. /* should be done here */
  77. pSelf->bStarted = false;
  78. return 0;
  79. }
  80. //
  81. // WaveAPI consumer object definition
  82. //
  83. /* constructor */
  84. static tsk_object_t* plugin_win_mf_consumer_audio_ctor(tsk_object_t * self, va_list * app)
  85. {
  86. MFUtils::Startup();
  87. plugin_win_mf_consumer_audio_t *pSelf = (plugin_win_mf_consumer_audio_t *)self;
  88. if(pSelf) {
  89. /* init base */
  90. tdav_consumer_audio_init(TDAV_CONSUMER_AUDIO(pSelf));
  91. /* init self */
  92. }
  93. return self;
  94. }
  95. /* destructor */
  96. static tsk_object_t* plugin_win_mf_consumer_audio_dtor(tsk_object_t * self)
  97. {
  98. plugin_win_mf_consumer_audio_t *pSelf = (plugin_win_mf_consumer_audio_t *)self;
  99. if(pSelf) {
  100. /* stop */
  101. if(pSelf->bStarted) {
  102. plugin_win_mf_consumer_audio_stop(TMEDIA_CONSUMER(pSelf));
  103. }
  104. /* deinit base */
  105. tdav_consumer_audio_deinit(TDAV_CONSUMER_AUDIO(pSelf));
  106. /* deinit self */
  107. }
  108. return self;
  109. }
  110. /* object definition */
  111. static const tsk_object_def_t plugin_win_mf_consumer_audio_def_s = {
  112. sizeof(plugin_win_mf_consumer_audio_t),
  113. plugin_win_mf_consumer_audio_ctor,
  114. plugin_win_mf_consumer_audio_dtor,
  115. tdav_consumer_audio_cmp,
  116. };
  117. /* plugin definition*/
  118. static const tmedia_consumer_plugin_def_t plugin_win_mf_consumer_audio_plugin_def_s = {
  119. &plugin_win_mf_consumer_audio_def_s,
  120. tmedia_audio,
  121. "Windows Media Foundation audio consumer",
  122. plugin_win_mf_consumer_audio_set,
  123. plugin_win_mf_consumer_audio_prepare,
  124. plugin_win_mf_consumer_audio_start,
  125. plugin_win_mf_consumer_audio_consume,
  126. plugin_win_mf_consumer_audio_pause,
  127. plugin_win_mf_consumer_audio_stop
  128. };
  129. const tmedia_consumer_plugin_def_t *plugin_win_mf_consumer_audio_plugin_def_t = &plugin_win_mf_consumer_audio_plugin_def_s;