Commit c322c130 authored by jehan's avatar jehan

add functions to ms_factory for enabling/disabling a filter encoder/decoder at runtime

parent 265d7618
...@@ -123,7 +123,7 @@ MS2_PUBLIC MSFilterDesc * ms_factory_get_decoder(MSFactory *factory, const char ...@@ -123,7 +123,7 @@ MS2_PUBLIC MSFilterDesc * ms_factory_get_decoder(MSFactory *factory, const char
* *
* @param filter_name The filter name. * @param filter_name The filter name.
**/ **/
MS2_PUBLIC MSFilterDesc *ms_factory_lookup_filter_by_name(MSFactory *factory, const char *filter_name); MS2_PUBLIC MSFilterDesc *ms_factory_lookup_filter_by_name(const MSFactory *factory, const char *filter_name);
/** /**
* Lookup a mediastreamer2 filter using its id. * Lookup a mediastreamer2 filter using its id.
...@@ -261,6 +261,26 @@ MS2_PUBLIC const struct _MSFmtDescriptor * ms_factory_get_video_format(MSFactory ...@@ -261,6 +261,26 @@ MS2_PUBLIC const struct _MSFmtDescriptor * ms_factory_get_video_format(MSFactory
MS2_PUBLIC const MSFmtDescriptor *ms_factory_get_format(MSFactory *obj, const MSFmtDescriptor *ref); MS2_PUBLIC const MSFmtDescriptor *ms_factory_get_format(MSFactory *obj, const MSFmtDescriptor *ref);
/**
* Specifies if a filter is enabled or not. Only enabled filter are return by functions like ms_filter_get_encoder
* @param factory
* @param name A name for the filter.
* @param enable, true/false
* @return 0 in case of success
*
*/
MS2_PUBLIC int ms_factory_enable_filter_from_name(MSFactory *factory, const char *name, bool_t enable);
/**
* Specifies if a filter is enabled or not. Only enabled filter are return by functions like ms_filter_get_encoder
*
* @param factory
* @param name A name for the filter.
* @return true/false if enabled
*
*/
MS2_PUBLIC bool_t ms_factory_filter_from_name_enabled(const MSFactory *factory, const char *name);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -165,6 +165,7 @@ struct _MSFilterDesc{ ...@@ -165,6 +165,7 @@ struct _MSFilterDesc{
MSFilterFunc uninit; /**< Filter's uninit function, used to deallocate internal structures*/ MSFilterFunc uninit; /**< Filter's uninit function, used to deallocate internal structures*/
MSFilterMethod *methods; /**<Filter's method table*/ MSFilterMethod *methods; /**<Filter's method table*/
unsigned int flags; /**<Filter's special flags, from the MSFilterFlags enum.*/ unsigned int flags; /**<Filter's special flags, from the MSFilterFlags enum.*/
bool_t enabled; /*Flag to specify if a filter is enabled or not. Only enabled filter are return by function ms_filter_get_encoder */
}; };
/** /**
......
/*
MediastreamException.java
Copyright (C) 2015 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.linphone.mediastream;
@SuppressWarnings("serial")
public class MediastreamException extends Exception {
public MediastreamException() {
}
public MediastreamException(String detailMessage) {
super(detailMessage);
}
public MediastreamException(Throwable e) {
super(e);
}
public MediastreamException(String detailMessage,Throwable e) {
super(detailMessage,e);
}
}
...@@ -84,4 +84,24 @@ public class MediastreamerAndroidContext { ...@@ -84,4 +84,24 @@ public class MediastreamerAndroidContext {
} }
return returnedValue; return returnedValue;
} }
native private int enableFilterFromNameImpl(String name,boolean enable);
native private boolean filterFromNameEnabledImpl(String name);
/**
* Specifies if a filter is enabled or not.
* @param name A name for the filter. refer to ms2 internals to get list of filters
* @param enable, true/false
* @throw MediastreamException if filter name is unknown
* */
public static void enableFilterFromName(String name,boolean enable) throws MediastreamException {
if (getInstance().enableFilterFromNameImpl(name,enable) != 0)
throw new MediastreamException("Cannot "+(enable?"enable":"disable") + " filter name ["+name+"]");
}
/**
* Specifies if a filter is enabled or not.
* @param name A name for the filter. refer to ms2 internals to get list of filters
* @return enable, true/false
** */
public static boolean filterFromNameEnabled(String name) {
return getInstance().filterFromNameEnabledImpl(name);
}
} }
...@@ -262,6 +262,8 @@ void ms_factory_register_filter(MSFactory* factory, MSFilterDesc* desc ) { ...@@ -262,6 +262,8 @@ void ms_factory_register_filter(MSFactory* factory, MSFilterDesc* desc ) {
if (desc->id==MS_FILTER_NOT_SET_ID){ if (desc->id==MS_FILTER_NOT_SET_ID){
ms_fatal("MSFilterId for %s not set !",desc->name); ms_fatal("MSFilterId for %s not set !",desc->name);
} }
desc->enabled=TRUE; /*by default a registered filter is enabled*/
/*lastly registered encoder/decoders may replace older ones*/ /*lastly registered encoder/decoders may replace older ones*/
factory->desc_list=ms_list_prepend(factory->desc_list,desc); factory->desc_list=ms_list_prepend(factory->desc_list,desc);
} }
...@@ -328,8 +330,9 @@ MSFilterDesc * ms_factory_get_encoder(MSFactory* factory, const char *mime){ ...@@ -328,8 +330,9 @@ MSFilterDesc * ms_factory_get_encoder(MSFactory* factory, const char *mime){
MSList *elem; MSList *elem;
for (elem=factory->desc_list;elem!=NULL;elem=ms_list_next(elem)){ for (elem=factory->desc_list;elem!=NULL;elem=ms_list_next(elem)){
MSFilterDesc *desc=(MSFilterDesc*)elem->data; MSFilterDesc *desc=(MSFilterDesc*)elem->data;
if ((desc->category==MS_FILTER_ENCODER || desc->category==MS_FILTER_ENCODING_CAPTURER) && if (desc->enabled
strcasecmp(desc->enc_fmt,mime)==0){ && (desc->category==MS_FILTER_ENCODER || desc->category==MS_FILTER_ENCODING_CAPTURER)
&& strcasecmp(desc->enc_fmt,mime)==0){
return desc; return desc;
} }
} }
...@@ -340,8 +343,9 @@ MSFilterDesc * ms_factory_get_decoder(MSFactory* factory, const char *mime){ ...@@ -340,8 +343,9 @@ MSFilterDesc * ms_factory_get_decoder(MSFactory* factory, const char *mime){
MSList *elem; MSList *elem;
for (elem=factory->desc_list;elem!=NULL;elem=ms_list_next(elem)){ for (elem=factory->desc_list;elem!=NULL;elem=ms_list_next(elem)){
MSFilterDesc *desc=(MSFilterDesc*)elem->data; MSFilterDesc *desc=(MSFilterDesc*)elem->data;
if ((desc->category==MS_FILTER_DECODER || desc->category==MS_FILTER_DECODER_RENDERER) && if (desc->enabled
strcasecmp(desc->enc_fmt,mime)==0){ && (desc->category==MS_FILTER_DECODER || desc->category==MS_FILTER_DECODER_RENDERER)
&& strcasecmp(desc->enc_fmt,mime)==0){
return desc; return desc;
} }
} }
...@@ -389,7 +393,7 @@ MSFilter *ms_factory_create_filter(MSFactory* factory, MSFilterId id){ ...@@ -389,7 +393,7 @@ MSFilter *ms_factory_create_filter(MSFactory* factory, MSFilterId id){
return NULL; return NULL;
} }
MSFilterDesc *ms_factory_lookup_filter_by_name(MSFactory* factory, const char *filter_name){ MSFilterDesc *ms_factory_lookup_filter_by_name(const MSFactory* factory, const char *filter_name){
MSList *elem; MSList *elem;
for (elem=factory->desc_list;elem!=NULL;elem=ms_list_next(elem)){ for (elem=factory->desc_list;elem!=NULL;elem=ms_list_next(elem)){
MSFilterDesc *desc=(MSFilterDesc*)elem->data; MSFilterDesc *desc=(MSFilterDesc*)elem->data;
...@@ -803,3 +807,39 @@ const MSFmtDescriptor * ms_factory_get_video_format(MSFactory *obj, const char * ...@@ -803,3 +807,39 @@ const MSFmtDescriptor * ms_factory_get_video_format(MSFactory *obj, const char *
return ms_factory_get_format(obj,&tmp); return ms_factory_get_format(obj,&tmp);
} }
int ms_factory_enable_filter_from_name(MSFactory *factory, const char *name,bool_t enable) {
MSFilterDesc *desc=ms_factory_lookup_filter_by_name(factory,name);
if (!desc) {
ms_error("Cannot enable/disable unknown filter [%s] on factory [%p]",name,factory);
return -1;
}
desc->enabled=enable;
ms_message("Filter [%s] %s on factory [%p]",name,(enable?"enabled":"disabled"),factory);
return 0;
}
bool_t ms_factory_filter_from_name_enabled(const MSFactory *factory, const char *name) {
MSFilterDesc *desc=ms_factory_lookup_filter_by_name(factory,name);
if (!desc) {
ms_error("Cannot get enable/disable state for unknown filter [%s] on factory [%p]",name,factory);
return FALSE;
}
return desc->enabled;
}
#ifdef ANDROID
#include "sys/system_properties.h"
#include <jni.h>
JNIEXPORT jint JNICALL Java_org_linphone_mediastream_MediastreamerAndroidContext_enableFilterFromNameImpl(JNIEnv* env, jobject obj, jstring jname, jboolean enable) {
const char *mime = jname ? (*env)->GetStringUTFChars(env, jname, NULL) : NULL;
int result = ms_factory_enable_filter_from_name(ms_factory_get_fallback(),mime,enable);
(*env)->ReleaseStringUTFChars(env, jname, mime);
return result;
}
JNIEXPORT jboolean JNICALL Java_org_linphone_mediastream_MediastreamerAndroidContext_filterFromNameEnabledImpl(JNIEnv* env, jobject obj, jstring jname) {
const char *mime = jname ? (*env)->GetStringUTFChars(env, jname, NULL) : NULL;
jboolean result = ms_factory_filter_from_name_enabled(ms_factory_get_fallback(),mime);
(*env)->ReleaseStringUTFChars(env, jname, mime);
return result;
}
#endif
...@@ -141,11 +141,48 @@ static void test_is_multicast(void) { ...@@ -141,11 +141,48 @@ static void test_is_multicast(void) {
BC_ASSERT_FALSE(ms_is_multicast("::1")); BC_ASSERT_FALSE(ms_is_multicast("::1"));
} }
static void test_filterdesc_enable_disable_base(const char* mime, const char* filtername,bool_t is_enc) {
ms_init();
MSFilter *filter;
if (is_enc)
filter = ms_filter_create_encoder(mime);
else
filter = ms_filter_create_decoder(mime);
BC_ASSERT_PTR_NOT_NULL(filter);
ms_filter_destroy(filter);
BC_ASSERT_FALSE(ms_factory_enable_filter_from_name(ms_factory_get_fallback(),filtername,FALSE));
BC_ASSERT_FALSE(ms_factory_filter_from_name_enabled(ms_factory_get_fallback(),filtername));
if (is_enc)
filter = ms_filter_create_encoder(mime);
else
filter = ms_filter_create_decoder(mime);
BC_ASSERT_PTR_NULL(filter);
BC_ASSERT_FALSE(ms_factory_enable_filter_from_name(ms_factory_get_fallback(),filtername,TRUE));
BC_ASSERT_TRUE(ms_factory_filter_from_name_enabled(ms_factory_get_fallback(),filtername));
if (is_enc)
filter = ms_filter_create_encoder(mime);
else
filter = ms_filter_create_decoder(mime);
BC_ASSERT_PTR_NOT_NULL(filter);
ms_filter_destroy(filter);
ms_exit();
}
static void test_filterdesc_enable_disable() {
test_filterdesc_enable_disable_base("pcmu", "MSUlawDec", FALSE);
test_filterdesc_enable_disable_base("pcma", "MSAlawEnc", TRUE);
}
static test_t tests[] = { static test_t tests[] = {
{ "Multiple ms_voip_init", filter_register_tester } { "Multiple ms_voip_init", filter_register_tester },
, { "Is multicast", test_is_multicast} { "Is multicast", test_is_multicast},
{ "FilterDesc enabling/disabling", test_filterdesc_enable_disable},
#ifdef VIDEO_ENABLED #ifdef VIDEO_ENABLED
, { "Video processing function", test_video_processing} { "Video processing function", test_video_processing}
#endif #endif
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment