tmedia_content.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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_content.h
  23. * @brief Base content object.
  24. *
  25. * @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
  26. *
  27. */
  28. #ifndef TINYMEDIA_CONTENT_H
  29. #define TINYMEDIA_CONTENT_H
  30. #include "tinymedia_config.h"
  31. #include "tsk_buffer.h"
  32. #include "tsk_list.h"
  33. #include "tsk_params.h"
  34. TMEDIA_BEGIN_DECLS
  35. /**Max number of plugins (content types) we can create */
  36. #define TMEDIA_CONTENT_MAX_PLUGINS 0x0F
  37. /** cast any pointer to @ref tmedia_content_t* object */
  38. #define TMEDIA_CONTENT(self) ((tmedia_content_t*)(self))
  39. /** Base object for all contents */
  40. typedef struct tmedia_content_s {
  41. TSK_DECLARE_OBJECT;
  42. const char* type;
  43. //! plugin used to create the codec
  44. const struct tmedia_content_plugin_def_s* plugin;
  45. }
  46. tmedia_content_t;
  47. /** Virtual table used to define a content plugin */
  48. typedef struct tmedia_content_plugin_def_s {
  49. //! object definition used to create an instance of the codec
  50. const tsk_object_def_t* objdef;
  51. //! e.g. 'message/CPIM'
  52. const char* type;
  53. int (*parse) (tmedia_content_t*, const void* in_data, tsk_size_t in_size);
  54. tsk_buffer_t* (*get_data) (tmedia_content_t*);
  55. }
  56. tmedia_content_plugin_def_t;
  57. /** List of @ref tmedia_codec_t elements */
  58. typedef tsk_list_t tmedia_contents_L_t;
  59. /**< Declare base class as content */
  60. #define TMEDIA_DECLARE_CONTENT tmedia_content_t __content__
  61. TINYMEDIA_API int tmedia_content_plugin_register(const char* type, const tmedia_content_plugin_def_t* plugin);
  62. TINYMEDIA_API int tmedia_content_plugin_unregister(const char* type, const tmedia_content_plugin_def_t* plugin);
  63. TINYMEDIA_API int tmedia_content_plugin_unregister_all();
  64. TINYMEDIA_API tmedia_content_t* tmedia_content_create(const char* type);
  65. TINYMEDIA_API tmedia_content_t* tmedia_content_parse(const void* data, tsk_size_t size, const char* type);
  66. TINYMEDIA_API int tmedia_content_init(tmedia_content_t* self);
  67. TINYMEDIA_API int tmedia_content_deinit(tmedia_content_t* self);
  68. TINYMEDIA_API tsk_buffer_t* tmedia_content_get_data(tmedia_content_t* self);
  69. /** dummy content */
  70. typedef struct tmedia_content_dummy_s {
  71. TMEDIA_DECLARE_CONTENT;
  72. tsk_buffer_t* data;
  73. }
  74. tmedia_content_dummy_t;
  75. #define TMEDIA_CONTENT_DUMMY(self) ((tmedia_content_dummy_t*)(self))
  76. #define TMEDIA_CONTENT_IS_DUMMY(self) ( (self) && (TMEDIA_CONTENT((self))->plugin==tmedia_content_dummy_plugin_def_t) )
  77. TINYMEDIA_GEXTERN const tmedia_content_plugin_def_t *tmedia_content_dummy_plugin_def_t;
  78. /** content header */
  79. typedef struct tmedia_content_header_s {
  80. TSK_DECLARE_OBJECT;
  81. char* name;
  82. char* value;
  83. tsk_params_L_t* params;
  84. }
  85. tmedia_content_header_t;
  86. tmedia_content_header_t* tmedia_content_header_create(const char* name, const char* value);
  87. int tmedia_content_header_deinit(tmedia_content_header_t* self);
  88. char* tmedia_content_header_tostring(const tmedia_content_header_t* self);
  89. #define TMEDIA_CONTENT_HEADER(self) ((tmedia_content_header_t*)(self))
  90. #define TMEDIA_DECLARE_CONTENT_HEADER tmedia_content_header_t __content_header__
  91. typedef tsk_list_t tmedia_content_headers_L_t;
  92. TINYMEDIA_GEXTERN const tsk_object_def_t *tmedia_content_header_def_t;
  93. TMEDIA_END_DECLS
  94. #endif /* TINYMEDIA_CONTENT_H */