diff options
Diffstat (limited to 'tinyMEDIA')
-rwxr-xr-x | tinyMEDIA/include/tinymedia/tmedia_codec.h | 1 | ||||
-rwxr-xr-x | tinyMEDIA/src/tmedia_codec.c | 35 |
2 files changed, 26 insertions, 10 deletions
diff --git a/tinyMEDIA/include/tinymedia/tmedia_codec.h b/tinyMEDIA/include/tinymedia/tmedia_codec.h index 6dcd2be..63e6fc9 100755 --- a/tinyMEDIA/include/tinymedia/tmedia_codec.h +++ b/tinyMEDIA/include/tinymedia/tmedia_codec.h @@ -314,6 +314,7 @@ TINYMEDIA_API tsk_bool_t tmedia_codec_plugin_is_registered(const tmedia_codec_pl TINYMEDIA_API tsk_bool_t tmedia_codec_plugin_is_registered_2(tmedia_codec_id_t codec_id); TINYMEDIA_API int tmedia_codec_plugin_registered_get_all(const struct tmedia_codec_plugin_def_s*(** plugins)[TMED_CODEC_MAX_PLUGINS], tsk_size_t* count); TINYMEDIA_API const struct tmedia_codec_plugin_def_s* tmedia_codec_plugin_registered_get_const(tmedia_codec_id_t codec_id); +TINYMEDIA_API tsk_size_t tmedia_codec_plugin_registered_count(const struct tmedia_codec_plugin_def_s** plugins, tsk_size_t count); TINYMEDIA_API int tmedia_codec_plugin_unregister(const tmedia_codec_plugin_def_t* plugin); TINYMEDIA_API int tmedia_codec_plugin_unregister_all(); TINYMEDIA_API tmedia_codec_t* tmedia_codec_create(const char* format); diff --git a/tinyMEDIA/src/tmedia_codec.c b/tinyMEDIA/src/tmedia_codec.c index a5fb8e2..0470a04 100755 --- a/tinyMEDIA/src/tmedia_codec.c +++ b/tinyMEDIA/src/tmedia_codec.c @@ -302,37 +302,43 @@ int tmedia_codec_plugin_register(const tmedia_codec_plugin_def_t* plugin) int tmedia_codec_plugin_register_2(const tmedia_codec_plugin_def_t* plugin, int prio) { - tsk_size_t count = 0; + tsk_size_t index = 0, max; tsk_bool_t already_registered = tsk_false; const tmedia_codec_plugin_def_t* tmp; - if(!plugin || tsk_strnullORempty(plugin->name) || tsk_strnullORempty(plugin->format) || (prio + 1) >= TMED_CODEC_MAX_PLUGINS) { + if (!plugin || tsk_strnullORempty(plugin->name) || tsk_strnullORempty(plugin->format) || (prio + 1) >= TMED_CODEC_MAX_PLUGINS) { TSK_DEBUG_ERROR("Invalid parameter"); return -1; } // count codecs and found if already registered - while(__tmedia_codec_plugins[count]) { - if(__tmedia_codec_plugins[count] == plugin) { + while (__tmedia_codec_plugins[index]) { + if (__tmedia_codec_plugins[index] == plugin) { already_registered = tsk_true; } - ++count; + ++index; } - if(count >= TMED_CODEC_MAX_PLUGINS) { + if (index >= TMED_CODEC_MAX_PLUGINS) { TSK_DEBUG_ERROR("No room"); return -1; } + // clamp prio (must be done here before unregistering the plugin) + max = tmedia_codec_plugin_registered_count(__tmedia_codec_plugins, sizeof(__tmedia_codec_plugins)/sizeof(__tmedia_codec_plugins[0])); + prio = TSK_CLAMP(0, prio, (int)(max > 0 ? (max - 1) : 0)); + // unregister and compact - if(already_registered) { - if(tmedia_codec_plugin_unregister(plugin) == 0) { - --count; + if (already_registered) { + if (tmedia_codec_plugin_unregister(plugin) == 0) { + --index; } } + + // put current plugin at prio and old (which was at prio) at the end tmp = __tmedia_codec_plugins[prio]; - __tmedia_codec_plugins[count] = tmp;// put old codec add prio to the end of the list + __tmedia_codec_plugins[index] = tmp;// put old codec add prio to the end of the list __tmedia_codec_plugins[prio] = plugin; return 0; @@ -399,6 +405,15 @@ const struct tmedia_codec_plugin_def_s* tmedia_codec_plugin_registered_get_const } /**@ingroup tmedia_codec_group +*/ +tsk_size_t tmedia_codec_plugin_registered_count(const struct tmedia_codec_plugin_def_s** plugins, tsk_size_t count) +{ + tsk_size_t i; + for (i = 0; i < count && plugins[i]; ++i) ; + return i; +} + +/**@ingroup tmedia_codec_group * UnRegisters a codec plugin. * @param plugin the definition of the plugin. * @retval 0 if succeed and non-zero error code otherwise. |