tmedia_consumer.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Copyright (C) 2010-2011 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango[dot]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 tmedia_consumer.h
  23. * @brief Base consumer object.
  24. *
  25. * @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
  26. *
  27. */
  28. #ifndef TINYMEDIA_CONSUMER_H
  29. #define TINYMEDIA_CONSUMER_H
  30. #include "tinymedia_config.h"
  31. #include "tinymedia/tmedia_codec.h"
  32. #include "tinymedia/tmedia_params.h"
  33. #include "tmedia_common.h"
  34. TMEDIA_BEGIN_DECLS
  35. #define TMEDIA_CONSUMER_BITS_PER_SAMPLE_DEFAULT 16
  36. #define TMEDIA_CONSUMER_CHANNELS_DEFAULT 2
  37. #define TMEDIA_CONSUMER_RATE_DEFAULT 8000
  38. /**Max number of plugins (consumer types) we can create */
  39. #if !defined(TMED_CONSUMER_MAX_PLUGINS)
  40. # define TMED_CONSUMER_MAX_PLUGINS 0x0F
  41. #endif
  42. /** cast any pointer to @ref tmedia_consumer_t* object */
  43. #define TMEDIA_CONSUMER(self) ((tmedia_consumer_t*)(self))
  44. /** Default Video chroma */
  45. #if !defined(TMEDIA_CONSUMER_CHROMA_DEFAULT)
  46. # define TMEDIA_CONSUMER_CHROMA_DEFAULT tmedia_chroma_yuv420p
  47. #endif
  48. /** Base object for all Consumers */
  49. typedef struct tmedia_consumer_s {
  50. TSK_DECLARE_OBJECT;
  51. tmedia_type_t type;
  52. const char* desc;
  53. struct {
  54. int fps;
  55. struct {
  56. tmedia_chroma_t chroma;
  57. tsk_size_t width;
  58. tsk_size_t height;
  59. } in;
  60. struct {
  61. tmedia_chroma_t chroma;
  62. tsk_size_t width;
  63. tsk_size_t height;
  64. tsk_bool_t auto_resize; // auto_resize to "in.width, in.height"
  65. } display;
  66. } video;
  67. struct {
  68. uint8_t bits_per_sample;
  69. uint8_t ptime;
  70. uint8_t gain;
  71. struct {
  72. uint8_t channels;
  73. uint32_t rate;
  74. } in;
  75. struct {
  76. uint8_t channels;
  77. uint32_t rate;
  78. } out;
  79. int32_t volume;
  80. } audio;
  81. tsk_bool_t is_started;
  82. tsk_bool_t is_prepared;
  83. uint64_t session_id;
  84. struct {
  85. enum tmedia_codec_id_e codec_id;
  86. // other options to be added
  87. } decoder;
  88. const struct tmedia_consumer_plugin_def_s* plugin;
  89. }
  90. tmedia_consumer_t;
  91. /** Virtual table used to define a consumer plugin */
  92. typedef struct tmedia_consumer_plugin_def_s {
  93. //! object definition used to create an instance of the consumer
  94. const tsk_object_def_t* objdef;
  95. //! the type of the consumer
  96. tmedia_type_t type;
  97. //! full description (usefull for debugging)
  98. const char* desc;
  99. int (*set) (tmedia_consumer_t* , const tmedia_param_t*);
  100. int (* prepare) (tmedia_consumer_t*, const tmedia_codec_t* );
  101. int (* start) (tmedia_consumer_t* );
  102. int (* consume) (tmedia_consumer_t*, const void* buffer, tsk_size_t size, const tsk_object_t* proto_hdr);
  103. int (* pause) (tmedia_consumer_t* );
  104. int (* stop) (tmedia_consumer_t* );
  105. }
  106. tmedia_consumer_plugin_def_t;
  107. #define TMEDIA_DECLARE_CONSUMER tmedia_consumer_t __consumer__
  108. TINYMEDIA_API tmedia_consumer_t* tmedia_consumer_create(tmedia_type_t type, uint64_t session_id);
  109. TINYMEDIA_API int tmedia_consumer_init(tmedia_consumer_t* self);
  110. TINYMEDIA_API int tmedia_consumer_set(tmedia_consumer_t *self, const tmedia_param_t* param);
  111. TINYMEDIA_API int tmedia_consumer_prepare(tmedia_consumer_t *self, const tmedia_codec_t* codec);
  112. TINYMEDIA_API int tmedia_consumer_start(tmedia_consumer_t *self);
  113. TINYMEDIA_API int tmedia_consumer_consume(tmedia_consumer_t* self, const void* buffer, tsk_size_t size, const tsk_object_t* proto_hdr);
  114. TINYMEDIA_API int tmedia_consumer_pause(tmedia_consumer_t *self);
  115. TINYMEDIA_API int tmedia_consumer_stop(tmedia_consumer_t *self);
  116. TINYMEDIA_API int tmedia_consumer_deinit(tmedia_consumer_t* self);
  117. TINYMEDIA_API int tmedia_consumer_plugin_register(const tmedia_consumer_plugin_def_t* plugin);
  118. TINYMEDIA_API int tmedia_consumer_plugin_unregister(const tmedia_consumer_plugin_def_t* plugin);
  119. TINYMEDIA_API int tmedia_consumer_plugin_unregister_by_type(tmedia_type_t type);
  120. TMEDIA_END_DECLS
  121. #endif /* TINYMEDIA_CONSUMER_H */