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
This commit is contained in:
parent
c6a8fde4aa
commit
b8cb2d5cf5
|
@ -473,14 +473,15 @@ int tdav_codec_set_priority(tdav_codec_id_t codec_id, int priority)
|
|||
{
|
||||
tsk_size_t i;
|
||||
|
||||
if(priority < 0) {
|
||||
if (priority < 0) {
|
||||
TSK_DEBUG_ERROR("Invalid parameter");
|
||||
return -1;
|
||||
}
|
||||
for(i = 0; i < __codec_plugins_all_count && __codec_plugins_all[i]; ++i) {
|
||||
for (i = 0; i < __codec_plugins_all_count && __codec_plugins_all[i]; ++i) {
|
||||
if(__codec_plugins_all[i]->codec_id == codec_id) {
|
||||
const struct tmedia_codec_plugin_def_s *codec_decl_1, *codec_decl_2;
|
||||
priority = TSK_MIN(priority, (int)__codec_plugins_all_count-1);
|
||||
tsk_size_t max = tmedia_codec_plugin_registered_count(__codec_plugins_all, __codec_plugins_all_count);
|
||||
priority = TSK_CLAMP(0, priority, (int)(max > 0 ? (max - 1) : 0));
|
||||
codec_decl_1 = __codec_plugins_all[priority];
|
||||
codec_decl_2 = __codec_plugins_all[i];
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
@ -398,6 +404,15 @@ const struct tmedia_codec_plugin_def_s* tmedia_codec_plugin_registered_get_const
|
|||
return tsk_null;
|
||||
}
|
||||
|
||||
/**@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.
|
||||
|
|
Loading…
Reference in New Issue