summaryrefslogtreecommitdiffstats
path: root/tinyMEDIA
diff options
context:
space:
mode:
authorMamadou DIOP <bossiel@yahoo.fr>2016-02-26 01:38:27 +0100
committerMamadou DIOP <bossiel@yahoo.fr>2016-02-26 01:38:27 +0100
commitb8cb2d5cf5c2beb5de175a0b6a95502a54d3e936 (patch)
tree3cd30efa859d8c4a7168260c77dbc3d2f642a75a /tinyMEDIA
parentc6a8fde4aaf6fd5185814525fcee3193fedef67d (diff)
downloaddoubango-b8cb2d5cf5c2beb5de175a0b6a95502a54d3e936.zip
doubango-b8cb2d5cf5c2beb5de175a0b6a95502a54d3e936.tar.gz
Fix codec priority setting issue. The codec is removed when the priority value is > the total number of registered codecs. This happens when few codecs are registered
Diffstat (limited to 'tinyMEDIA')
-rwxr-xr-xtinyMEDIA/include/tinymedia/tmedia_codec.h1
-rwxr-xr-xtinyMEDIA/src/tmedia_codec.c35
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.
OpenPOWER on IntegriCloud