1 /* 2 mediastreamer2 library - modular sound and video processing and streaming 3 Copyright (C) 2014 Belledonne Communications SARL 4 5 This program is free software; you can redistribute it and/or 6 modify it under the terms of the GNU General Public License 7 as published by the Free Software Foundation; either version 2 8 of the License, or (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 */ 19 20 #ifndef msfactory_h 21 #define msfactory_h 22 23 24 #include "mediastreamer2/msfilter.h" 25 #include "mediastreamer2/devices.h" 26 27 /*do not use these fields directly*/ 28 struct _MSFactory{ 29 MSList *desc_list; 30 MSList *stats_list; 31 MSList *offer_answer_provider_list; 32 #ifdef _WIN32 33 MSList *ms_plugins_loaded_list; 34 #endif 35 MSList *formats; 36 MSList *platform_tags; 37 char *plugins_dir; 38 struct _MSVideoPresetsManager *video_presets_manager; 39 int cpu_count; 40 struct _MSEventQueue *evq; 41 int max_payload_size; 42 int mtu; 43 struct _MSSndCardManager* sndcardmanager; 44 struct _MSWebCamManager* wbcmanager; 45 void (*voip_uninit_func)(struct _MSFactory*); 46 bool_t statistics_enabled; 47 bool_t voip_initd; 48 MSDevicesInfo *devices_info; 49 char *image_resources_dir; 50 char *echo_canceller_filtername; 51 int expected_video_bandwidth; 52 }; 53 54 typedef struct _MSFactory MSFactory; 55 56 #ifdef __cplusplus 57 extern "C" { 58 #endif 59 60 #ifndef MS2_DEPRECATED 61 #if defined(_MSC_VER) 62 #define MS2_DEPRECATED __declspec(deprecated) 63 #else 64 #define MS2_DEPRECATED __attribute__ ((deprecated)) 65 #endif 66 #endif 67 68 /** 69 * Create a mediastreamer2 factory. This is the root object that will create everything else from mediastreamer2. 70 **/ 71 MS2_PUBLIC MSFactory *ms_factory_new(void); 72 73 /** 74 * Create a mediastreamer2 factory and initialize all voip related filter, card and webcam managers. 75 **/ 76 MS2_PUBLIC MSFactory* ms_factory_new_with_voip(void); 77 78 /** 79 * Create a mediastreamer2 factory, initialize all voip related filters, cards and webcam managers and load the plugins from the specified directory. 80 * @param[in] plugins_dir The path where to find the mediastreamer2 plugins to be loaded 81 * @param[in] images_dir The path where to find the images 82 */ 83 MS2_PUBLIC MSFactory *ms_factory_new_with_voip_and_directories(const char *plugins_dir, const char *images_dir); 84 85 /** 86 * Create the fallback factory (for compatibility with applications not using MSFactory to create ms2 object) 87 **/ 88 MS2_DEPRECATED MS2_PUBLIC MSFactory *ms_factory_create_fallback(void); 89 90 /** 91 * Used by the legacy functions before MSFactory was added. 92 * Do not use in an application. 93 **/ 94 MS2_DEPRECATED MS2_PUBLIC MSFactory *ms_factory_get_fallback(void); 95 96 /** 97 * Destroy the factory. 98 * This should be done after destroying all objects created by the factory. 99 **/ 100 MS2_PUBLIC void ms_factory_destroy(MSFactory *factory); 101 102 /* 103 * Obtain the soundcard manager. 104 **/ 105 MS2_PUBLIC struct _MSSndCardManager* ms_factory_get_snd_card_manager(MSFactory *f); 106 107 /** 108 * Obtain the webcam manager. 109 */ 110 MS2_PUBLIC struct _MSWebCamManager* ms_factory_get_web_cam_manager(MSFactory* f); 111 112 113 /** 114 * Register a filter descriptor (MSFilterDesc) into the factory. 115 **/ 116 MS2_PUBLIC void ms_factory_register_filter(MSFactory *factory, MSFilterDesc *desc); 117 118 /** 119 * Retrieve capture filter that supports encoding to codec name. 120 * 121 * @param mime A string indicating the codec. 122 * 123 * @return a MSFilterDesc if successfull, NULL otherwise. 124 */ 125 MS2_PUBLIC MSFilterDesc * ms_factory_get_encoding_capturer(MSFactory *factory, const char *mime); 126 127 /** 128 * Retrieve render filter that supports decoding to codec name. 129 * 130 * @param mime A string indicating the codec. 131 * 132 * @return a MSFilterDesc if successfull, NULL otherwise. 133 */ 134 MS2_PUBLIC MSFilterDesc * ms_factory_get_decoding_renderer(MSFactory *factory, const char *mime); 135 136 /** 137 * Retrieve encoders according to codec name. 138 * 139 * @param mime A string indicating the codec. 140 * 141 * @return a MSFilterDesc if successfull, NULL otherwise. 142 */ 143 MS2_PUBLIC MSFilterDesc * ms_factory_get_encoder(MSFactory *factory, const char *mime); 144 145 /** 146 * Retrieve decoders according to codec name. 147 * 148 * @param mime A string indicating the codec. 149 * 150 * @return a MSFilterDesc if successfull, NULL otherwise. 151 */ 152 MS2_PUBLIC MSFilterDesc * ms_factory_get_decoder(MSFactory *factory, const char *mime); 153 154 /** 155 * Lookup a mediastreamer2 filter using its name. 156 * If found, the descriptor (MSFilterDesc) is returned. 157 * This descriptor can be used to instanciate the filter using ms_filter_new_from_desc() 158 * This function can be useful to query the presence of a filter loaded as a plugin, for example. 159 * 160 * @param filter_name The filter name. 161 **/ 162 MS2_PUBLIC MSFilterDesc *ms_factory_lookup_filter_by_name(const MSFactory *factory, const char *filter_name); 163 164 /** 165 * Lookup a mediastreamer2 filter using its id. 166 * If found, the descriptor (MSFilterDesc) is returned. 167 * This descriptor can be used to instanciate the filter using ms_filter_new_from_desc() 168 * This function can be useful to query the presence of a filter loaded as a plugin, for example. 169 * 170 * @param id The filter id. 171 **/ 172 MS2_PUBLIC MSFilterDesc* ms_factory_lookup_filter_by_id( MSFactory* factory, MSFilterId id); 173 174 /** 175 * Returns a list of filter descriptions implementing a given interface. 176 * The list itself must be freed by the caller of this function, but not the MSFilterDesc pointed by the list elements. 177 * @param id a filter interface id 178 * @return a newly allocated MSList of #MSFilterDesc. 179 **/ 180 MS2_PUBLIC MSList *ms_factory_lookup_filter_by_interface(MSFactory *factory, MSFilterInterfaceId id); 181 182 /** 183 * Create encoder filter according to codec name. 184 * 185 * @param mime A string indicating the codec. 186 * 187 * @return a MSFilter if successfull, NULL otherwise. 188 */ 189 MS2_PUBLIC MSFilter * ms_factory_create_encoder(MSFactory *factory, const char *mime); 190 191 /** 192 * Create decoder filter according to codec name. 193 * 194 * @param mime A string indicating the codec. 195 * 196 * @return a MSFilter if successfull, NULL otherwise. 197 */ 198 MS2_PUBLIC MSFilter * ms_factory_create_decoder(MSFactory *factory, const char *mime); 199 200 /** 201 * Check if a encode or decode filter exists for a codec name. 202 * 203 * @param mime A string indicating the codec. 204 * 205 * @return TRUE if successfull, FALSE otherwise. 206 */ 207 MS2_PUBLIC bool_t ms_factory_codec_supported(MSFactory *factory, const char *mime); 208 209 /** 210 * Create decoder filter according to a filter's MSFilterId. 211 * 212 * @param id A MSFilterId identifier for the filter. 213 * 214 * @return a MSFilter if successfull, NULL otherwise. 215 */ 216 MS2_PUBLIC MSFilter *ms_factory_create_filter(MSFactory *factory, MSFilterId id); 217 218 /** 219 * Create decoder filter according to a filter's name. 220 * 221 * @param name A name for the filter. 222 * 223 * @return a MSFilter if successfull, NULL otherwise. 224 */ 225 MS2_PUBLIC MSFilter *ms_factory_create_filter_from_name(MSFactory *factory, const char *name); 226 227 /** 228 * Create decoder filter according to a filter's description. 229 * 230 * The primary use is to create your own filter's in your 231 * application and avoid registration inside mediastreamer2. 232 * 233 * @param desc A MSFilterDesc for the filter. 234 * 235 * @return a MSFilter if successfull, NULL otherwise. 236 */ 237 MS2_PUBLIC MSFilter *ms_factory_create_filter_from_desc(MSFactory *factory, MSFilterDesc *desc); 238 239 /** 240 * Enable filter statistics measurement at run time. 241 **/ 242 MS2_PUBLIC void ms_factory_enable_statistics(MSFactory* obj, bool_t enabled); 243 244 /** 245 * Obtain a list of MSFilterStats. 246 **/ 247 MS2_PUBLIC const MSList * ms_factory_get_statistics(MSFactory* obj); 248 249 /** 250 * Reset filter's statistics. 251 **/ 252 MS2_PUBLIC void ms_factory_reset_statistics(MSFactory *obj); 253 254 /** 255 * Output statistics to logs. 256 **/ 257 MS2_PUBLIC void ms_factory_log_statistics(MSFactory *obj); 258 259 /** 260 * Get number of available cpus for processing. 261 * The factory initializes this value to the number of logicial processors 262 * available on the machine where it runs. 263 **/ 264 MS2_PUBLIC unsigned int ms_factory_get_cpu_count(MSFactory *obj); 265 266 /** 267 * Set the number of available cpus for processing. 268 **/ 269 MS2_PUBLIC void ms_factory_set_cpu_count(MSFactory *obj, unsigned int c); 270 271 MS2_PUBLIC void ms_factory_add_platform_tag(MSFactory *obj, const char *tag); 272 273 MS2_PUBLIC MSList * ms_factory_get_platform_tags(MSFactory *obj); 274 275 MS2_PUBLIC char * ms_factory_get_platform_tags_as_string(MSFactory *obj); 276 277 MS2_PUBLIC struct _MSVideoPresetsManager * ms_factory_get_video_presets_manager(MSFactory *factory); 278 279 MS2_PUBLIC void ms_factory_init_plugins(MSFactory *obj); 280 281 /** 282 * Set directory where plugins are to be loaded. 283 **/ 284 MS2_PUBLIC void ms_factory_set_plugins_dir(MSFactory *obj, const char *path); 285 286 MS2_PUBLIC int ms_factory_load_plugins(MSFactory *factory, const char *dir); 287 288 MS2_PUBLIC void ms_factory_uninit_plugins(MSFactory *obj); 289 290 /** 291 * Init VOIP features (registration of codecs, sound card and webcam managers). 292 **/ 293 MS2_PUBLIC void ms_factory_init_voip(MSFactory *obj); 294 295 MS2_PUBLIC void ms_factory_uninit_voip(MSFactory *obj); 296 297 /** 298 * Creates an event queue. 299 * Only one can exist so if it has already been created the same one will be returned. 300 * @param[in] obj MSFactory object. 301 * @return The created event queue. 302 */ 303 MS2_PUBLIC struct _MSEventQueue * ms_factory_create_event_queue(MSFactory *obj); 304 305 MS2_PUBLIC void ms_factory_destroy_event_queue(MSFactory *obj); 306 307 /** 308 * Gets the event queue associated with the factory. 309 * Can be NULL if no event queue has been created. 310 * @param[in] obj MSFactory object. 311 * @return The event queue associated with the factory. 312 */ 313 MS2_PUBLIC struct _MSEventQueue * ms_factory_get_event_queue(MSFactory *obj); 314 315 MS2_PUBLIC void ms_factory_set_event_queue(MSFactory *obj,struct _MSEventQueue *q); 316 317 MS2_PUBLIC int ms_factory_get_payload_max_size(MSFactory *factory); 318 319 MS2_PUBLIC void ms_factory_set_payload_max_size(MSFactory *obj, int size); 320 321 MS2_PUBLIC void ms_factory_set_mtu(MSFactory *obj, int mtu); 322 323 MS2_PUBLIC int ms_factory_get_mtu(MSFactory *obj); 324 325 /** 326 * Set the name of the echo canceller filter to use. 327 * @param[in] obj MSFactory object 328 * @param[in] filtername The name of the echo canceller filter to use 329 */ 330 MS2_PUBLIC void ms_factory_set_echo_canceller_filter_name(MSFactory *obj, const char *filtername); 331 332 /** 333 * Get the name of the echo canceller filter being used. 334 * @param[in] obj MSFactory object 335 * @return The name of the echo canceller filter being used 336 */ 337 MS2_PUBLIC const char * ms_factory_get_echo_canceller_filter_name(const MSFactory *obj); 338 339 MS2_PUBLIC const struct _MSFmtDescriptor * ms_factory_get_audio_format(MSFactory *obj, const char *mime, int rate, int channels, const char *fmtp); 340 341 MS2_PUBLIC const struct _MSFmtDescriptor * ms_factory_get_video_format(MSFactory *obj, const char *mime, MSVideoSize size, float fps, const char *fmtp); 342 343 MS2_PUBLIC const MSFmtDescriptor *ms_factory_get_format(MSFactory *obj, const MSFmtDescriptor *ref); 344 345 /** 346 * Specifies if a filter is enabled or not. Only enabled filter are return by functions like ms_filter_get_encoder 347 * @param factory 348 * @param name A name for the filter. 349 * @param enable, true/false 350 * @return 0 in case of success 351 * 352 */ 353 MS2_PUBLIC int ms_factory_enable_filter_from_name(MSFactory *factory, const char *name, bool_t enable); 354 355 /** 356 * Specifies if a filter is enabled or not. Only enabled filter are return by functions like ms_filter_get_encoder 357 * 358 * @param factory 359 * @param name A name for the filter. 360 * @return true/false if enabled 361 * 362 */ 363 MS2_PUBLIC bool_t ms_factory_filter_from_name_enabled(const MSFactory *factory, const char *name); 364 365 366 #ifndef MS_OFFER_ANSWER_CONTEXT_DEFINED 367 #define MS_OFFER_ANSWER_CONTEXT_DEFINED 368 typedef struct _MSOfferAnswerContext MSOfferAnswerContext; 369 #endif 370 typedef struct _MSOfferAnswerProvider MSOfferAnswerProvider; 371 372 /** 373 * Registers an offer-answer provider. An offer answer provider is a kind of factory that creates 374 * context objects able to execute the particular offer/answer logic for a given codec. 375 * Indeed, several codecs have complex parameter handling specified in their RFC, and hence cannot be 376 * treated in a generic way by the global SDP offer answer logic. 377 * Mediastreamer2 plugins can then register with this method their offer/answer logic together with the encoder 378 * and decoder filters, so that it can be used by the signaling layer of the application. 379 * @param factory 380 * @param offer_answer_prov the offer answer provider descriptor. 381 **/ 382 MS2_PUBLIC void ms_factory_register_offer_answer_provider(MSFactory *f, MSOfferAnswerProvider *offer_answer_prov); 383 384 /** 385 * Retrieve an offer answer provider previously registered, giving the codec name. 386 * @param f the factory 387 * @param mime_type the codec mime type. 388 * @return an MSOfferAnswerProvider or NULL if none was registered for this codec. 389 **/ 390 MS2_PUBLIC MSOfferAnswerProvider * ms_factory_get_offer_answer_provider(MSFactory *f, const char *mime_type); 391 392 /** 393 * Directly creates an offer-answer context giving the codec mime-type. 394 * @param f the factory 395 * @param the mime-type of the codec. 396 * @return an MSOfferAnswerContext or NULL if none was registered for this codec. 397 **/ 398 MS2_PUBLIC MSOfferAnswerContext * ms_factory_create_offer_answer_context(MSFactory *f, const char *mime_type); 399 400 MS2_PUBLIC MSDevicesInfo* ms_factory_get_devices_info(MSFactory *f); 401 402 /** 403 * Get the path where the image resources (mainly the nowebcam image) are located. 404 * @param[in] f MSFactory object 405 * @return The path where the image resources are located 406 */ 407 MS2_PUBLIC const char * ms_factory_get_image_resources_dir(const MSFactory *f); 408 409 /** 410 * Set the path where the image resources are located 411 * @param[in] f MSFactory object 412 * @param[in] path The path where the image resources are located 413 */ 414 MS2_PUBLIC void ms_factory_set_image_resources_dir(MSFactory *f, const char *path); 415 416 MS2_PUBLIC void ms_factory_set_expected_bandwidth(MSFactory *f, int bitrate); 417 418 MS2_PUBLIC int ms_factory_get_expected_bandwidth(MSFactory *f); 419 420 #ifdef __cplusplus 421 } 422 #endif 423 424 #endif 425