tmedia_producer.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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_producer.h
  23. * @brief Base producer object.
  24. *
  25. * @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
  26. *
  27. */
  28. #ifndef TINYMEDIA_PRODUCER_H
  29. #define TINYMEDIA_PRODUCER_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_PRODUCER_BITS_PER_SAMPLE_DEFAULT 16
  36. #define TMEDIA_PRODUCER_CHANNELS_DEFAULT 2
  37. #define TMEDIA_PRODUCER_RATE_DEFAULT 8000
  38. /**Max number of plugins (producer types) we can create */
  39. #define TMED_PRODUCER_MAX_PLUGINS 0x0F
  40. /** cast any pointer to @ref tmedia_producer_t* object */
  41. #define TMEDIA_PRODUCER(self) ((tmedia_producer_t*)(self))
  42. typedef int (*tmedia_producer_enc_cb_f)(const void* callback_data, const void* buffer, tsk_size_t size);
  43. typedef int (*tmedia_producer_raw_cb_f)(const tmedia_video_encode_result_xt* chunck);
  44. /** Default Video chroma */
  45. #define TMEDIA_PRODUCER_CHROMA_DEFAULT tmedia_chroma_yuv420p
  46. /** Base object for all Producers */
  47. typedef struct tmedia_producer_s {
  48. TSK_DECLARE_OBJECT;
  49. tmedia_type_t type;
  50. const char* desc;
  51. struct {
  52. tmedia_chroma_t chroma;
  53. int fps;
  54. int rotation;
  55. tsk_bool_t mirror;
  56. tsk_size_t width;
  57. tsk_size_t height;
  58. } video;
  59. struct {
  60. uint8_t bits_per_sample;
  61. uint8_t channels;
  62. uint32_t rate;
  63. uint8_t ptime;
  64. uint8_t gain;
  65. int32_t volume;
  66. } audio;
  67. const struct tmedia_producer_plugin_def_s* plugin;
  68. tsk_bool_t is_prepared;
  69. tsk_bool_t is_started;
  70. uint64_t session_id;
  71. struct {
  72. enum tmedia_codec_id_e codec_id;
  73. // other options to be added
  74. } encoder;
  75. struct {
  76. tmedia_producer_enc_cb_f callback;
  77. const void* callback_data;
  78. } enc_cb;
  79. struct {
  80. tmedia_producer_raw_cb_f callback;
  81. tmedia_video_encode_result_xt chunck_curr;
  82. } raw_cb;
  83. }
  84. tmedia_producer_t;
  85. /** Virtual table used to define a producer plugin */
  86. typedef struct tmedia_producer_plugin_def_s {
  87. //! object definition used to create an instance of the producer
  88. const tsk_object_def_t* objdef;
  89. //! the type of the producer
  90. tmedia_type_t type;
  91. //! full description (usefull for debugging)
  92. const char* desc;
  93. int (*set) (tmedia_producer_t* , const tmedia_param_t*);
  94. int (* prepare) (tmedia_producer_t* , const tmedia_codec_t*);
  95. int (* start) (tmedia_producer_t* );
  96. int (* pause) (tmedia_producer_t* );
  97. int (* stop) (tmedia_producer_t* );
  98. }
  99. tmedia_producer_plugin_def_t;
  100. #define TMEDIA_DECLARE_PRODUCER tmedia_producer_t __producer__
  101. TINYMEDIA_API tmedia_producer_t* tmedia_producer_create(tmedia_type_t type, uint64_t session_id);
  102. TINYMEDIA_API int tmedia_producer_init(tmedia_producer_t* self);
  103. TINYMEDIA_API int tmedia_producer_set_enc_callback(tmedia_producer_t *self, tmedia_producer_enc_cb_f callback, const void* callback_data);
  104. TINYMEDIA_API int tmedia_producer_set_raw_callback(tmedia_producer_t *self, tmedia_producer_raw_cb_f callback, const void* callback_data);
  105. TINYMEDIA_API int tmedia_producer_set(tmedia_producer_t* self, const tmedia_param_t* param);
  106. TINYMEDIA_API int tmedia_producer_prepare(tmedia_producer_t *self, const tmedia_codec_t* codec);
  107. TINYMEDIA_API int tmedia_producer_start(tmedia_producer_t *self);
  108. TINYMEDIA_API int tmedia_producer_pause(tmedia_producer_t *self);
  109. TINYMEDIA_API int tmedia_producer_stop(tmedia_producer_t *self);
  110. TINYMEDIA_API int tmedia_producer_deinit(tmedia_producer_t* self);
  111. TINYMEDIA_API int tmedia_producer_plugin_register(const tmedia_producer_plugin_def_t* plugin);
  112. TINYMEDIA_API int tmedia_producer_plugin_unregister(const tmedia_producer_plugin_def_t* plugin);
  113. TINYMEDIA_API int tmedia_producer_plugin_unregister_by_type(tmedia_type_t type);
  114. TMEDIA_END_DECLS
  115. #endif /* TINYMEDIA_PRODUCER_H */