Commit 25754e7b authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Allow creating a factory specifying a plugins directory and setting the image...

Allow creating a factory specifying a plugins directory and setting the image resources directory (where to find the nowebcam image) through the factory.
parent d5440930
......@@ -46,6 +46,7 @@ struct _MSFactory{
bool_t statistics_enabled;
bool_t voip_initd;
MSDevicesInfo *devices_info;
char *image_resources_dir;
};
typedef struct _MSFactory MSFactory;
......@@ -61,7 +62,7 @@ extern "C" {
#define MS2_DEPRECATED __attribute__ ((deprecated))
#endif
#endif
/**
* Create a mediastreamer2 factory. This is the root object that will create everything else from mediastreamer2.
**/
......@@ -72,6 +73,12 @@ MS2_PUBLIC MSFactory *ms_factory_new(void);
**/
MS2_PUBLIC MSFactory* ms_factory_new_with_voip(void);
/**
* Create a mediastreamer2 factory, initialize all voip related filters, cards and webcam managers and load the plugins from the specified directory.
* @param[in] plugins_dir The path where to find the mediastreamer2 plugins to be loaded
*/
MS2_PUBLIC MSFactory *ms_factory_new_with_voip_and_plugins_dir(const char *plugins_dir);
/**
* Create the fallback factory (for compatibility with applications not using MSFactory to create ms2 object)
**/
......@@ -375,6 +382,20 @@ MS2_PUBLIC MSOfferAnswerContext * ms_factory_create_offer_answer_context(MSFacto
MS2_PUBLIC MSDevicesInfo* ms_factory_get_devices_info(MSFactory *f);
/**
* Get the path where the image resources (mainly the nowebcam image) are located.
* @param[in] f MSFactory object
* @return The path where the image resources are located
*/
MS2_PUBLIC char * ms_factory_get_image_resources_dir(const MSFactory *f);
/**
* Set the path where the image resources are located
* @param[in] f MSFactory object
* @param[in] path The path where the image resources are located
*/
MS2_PUBLIC void ms_factory_set_image_resources_dir(MSFactory *f, const char *path);
#ifdef __cplusplus
}
#endif
......
......@@ -246,6 +246,13 @@ extern "C"{
*/
MS2_PUBLIC MS2_DEPRECATED void ms_filter_register(MSFilterDesc *desc);
/**
* Get the factory that created a filter.
* @param[in] f MSFilter object
* @return The MSFactory that created the filter
*/
MS2_PUBLIC struct _MSFactory * ms_filter_get_factory(MSFilter *f);
/**
* Retrieve capture filter that supports encoding to codec name.
*
......
......@@ -155,7 +155,9 @@ MS2_PUBLIC const MSList * ms_web_cam_manager_get_list(MSWebCamManager *m);
*
*/
MS2_PUBLIC void ms_web_cam_manager_add_cam(MSWebCamManager *m, MSWebCam *c);
MS2_PUBLIC MSWebCam * ms_web_cam_manager_create_cam(MSWebCamManager *m, MSWebCamDesc *desc);
MS2_PUBLIC void ms_web_cam_set_manager(MSWebCamManager*m, MSWebCam *c);
/**
......
......@@ -51,6 +51,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#endif
#endif
#endif
#ifndef PACKAGE_DATA_DIR
#define PACKAGE_DATA_DIR "share"
#endif
#ifdef HAVE_DLOPEN
#include <dlfcn.h>
#endif
......@@ -850,6 +855,16 @@ MSDevicesInfo* ms_factory_get_devices_info(MSFactory *f) {
return f->devices_info;
}
char * ms_factory_get_image_resources_dir(const MSFactory *f) {
if (f->image_resources_dir) bctbx_strdup(f->image_resources_dir);
return bctbx_strdup_printf("%s/images", PACKAGE_DATA_DIR);
}
void ms_factory_set_image_resources_dir(MSFactory *f, const char *path) {
if (f->image_resources_dir) bctbx_free(f->image_resources_dir);
f->image_resources_dir = bctbx_strdup(path);
}
#ifdef ANDROID
#include "sys/system_properties.h"
#include <jni.h>
......
......@@ -82,6 +82,14 @@ void ms_web_cam_manager_add_cam(MSWebCamManager *m, MSWebCam *c){
m->cams=bctbx_list_append(m->cams,c);
}
MSWebCam * ms_web_cam_manager_create_cam(MSWebCamManager *m, MSWebCamDesc *desc) {
MSWebCam *obj = (MSWebCam *)ms_new0(MSWebCam, 1);
obj->desc = desc;
ms_web_cam_set_manager(m, obj);
if (desc->init!=NULL)
desc->init(obj);
return obj;
}
void ms_web_cam_manager_prepend_cam(MSWebCamManager *m, MSWebCam *c){
......
......@@ -75,6 +75,7 @@ typedef struct V4lState{
bool_t v4lv2; /*we interface with a V4Lv2 driver */
bool_t force_v1;
bool_t auto_started;
MSFactory *factory;
}V4lState;
static void *v4l_thread(void *s);
......@@ -292,6 +293,7 @@ static void v4l_init(MSFilter *f){
s->queued=0;
s->force_v1=FALSE;
s->auto_started=FALSE;
s->factory = ms_filter_get_factory(f);
f->data=s;
}
......@@ -772,7 +774,7 @@ static mblk_t * v4l_make_mire(V4lState *s){
static mblk_t * v4l_make_nowebcam(V4lState *s){
if (s->mire==NULL && s->frame_ind==0){
#if !defined(NO_FFMPEG)
s->mire=ms_load_nowebcam(&s->vsize, -1);
s->mire=ms_load_nowebcam(s->factory, &s->vsize, -1);
#endif
}
s->frame_ind++;
......
......@@ -177,26 +177,25 @@ mblk_t *ms_load_jpeg_as_yuv(const char *jpgpath, MSVideoSize *reqsize) {
}
#ifndef PACKAGE_DATA_DIR
#define PACKAGE_DATA_DIR "share"
#endif
#ifndef NOWEBCAM_JPG
#define NOWEBCAM_JPG "nowebcamCIF"
#endif
static char *def_image = NULL;
static const char *def_image_path = PACKAGE_DATA_DIR "/images/" NOWEBCAM_JPG ".jpg";
mblk_t *ms_load_nowebcam(MSVideoSize *reqsize, int idx) {
char tmp[256];
mblk_t *ms_load_nowebcam(MSFactory *factory, MSVideoSize *reqsize, int idx) {
mblk_t *m;
char *tmp;
char *image_resources_dir = ms_factory_get_image_resources_dir(factory);
if (idx < 0)
snprintf(tmp, sizeof(tmp), "%s/images/%s.jpg", PACKAGE_DATA_DIR, NOWEBCAM_JPG);
tmp = bctbx_strdup_printf("%s/%s.jpg", image_resources_dir, NOWEBCAM_JPG);
else
snprintf(tmp, sizeof(tmp), "%s/images/%s%i.jpg", PACKAGE_DATA_DIR, NOWEBCAM_JPG, idx);
return ms_load_jpeg_as_yuv(tmp, reqsize);
tmp = bctbx_strdup_printf("%s/%s%i.jpg", image_resources_dir, NOWEBCAM_JPG, idx);
m = ms_load_jpeg_as_yuv(tmp, reqsize);
bctbx_free(tmp);
bctbx_free(image_resources_dir);
return m;
}
typedef struct _SIData {
......@@ -352,9 +351,12 @@ static void static_image_detect(MSWebCamManager *obj);
static void static_image_cam_init(MSWebCam *cam) {
cam->name=ms_strdup("Static picture");
if (def_image == NULL)
def_image = ms_strdup(def_image_path);
if (def_image == NULL) {
MSFactory *factory = ms_web_cam_get_factory(cam);
char *image_resources_dir = ms_factory_get_image_resources_dir(factory);
def_image = ms_strdup_printf("%s/%s.jpg", image_resources_dir, NOWEBCAM_JPG);
bctbx_free(image_resources_dir);
}
}
......@@ -372,7 +374,7 @@ MSWebCamDesc static_image_desc={
};
static void static_image_detect(MSWebCamManager *obj){
MSWebCam *cam=ms_web_cam_new(&static_image_desc);
MSWebCam *cam = ms_web_cam_manager_create_cam(obj, &static_image_desc);
ms_web_cam_manager_add_cam(obj,cam);
}
......
......@@ -72,6 +72,7 @@ typedef struct V4wState{
int frame_count;
bool_t running;
bool_t startwith_yuv_bug; /* avoid bug with USB vimicro cards. */
MSFactory *factory;
}V4wState;
static V4wState *s_callback=NULL;
......@@ -624,6 +625,7 @@ static void v4w_init(MSFilter *f){
s->frame_count=-1;
s->fps=15;
s->factory = ms_filter_get_factory(f);
f->data=s;
}
......@@ -849,12 +851,12 @@ static mblk_t * v4w_make_nowebcam(V4wState *s){
/* load several images to fake a movie */
for (idx=0;idx<10;idx++)
{
s->mire[idx]=ms_load_nowebcam(&s->vsize, idx);
s->mire[idx]=ms_load_nowebcam(s->factory, &s->vsize, idx);
if (s->mire[idx]==NULL)
break;
}
if (idx==0)
s->mire[0]=ms_load_nowebcam(&s->vsize, -1);
s->mire[0]=ms_load_nowebcam(s->factory, &s->vsize, -1);
}
for (count=0;count<10;count++)
{
......
......@@ -59,6 +59,7 @@ typedef struct V4wState{
bool_t started;
bool_t autostarted;
bool_t invert_rgb;
MSFactory *factory;
}V4wState;
static void dummy(void*p){
......@@ -272,6 +273,7 @@ static void v4w_init(MSFilter *f){
s->thread_running = FALSE;
#endif
s->factory = ms_filter_get_factory(f);
f->data=s;
}
......@@ -451,12 +453,12 @@ static mblk_t * v4w_make_nowebcam(V4wState *s){
/* load several images to fake a movie */
for (idx=0;idx<10;idx++)
{
s->mire[idx]=ms_load_nowebcam(&s->vsize, idx);
s->mire[idx]=ms_load_nowebcam(s->factory, &s->vsize, idx);
if (s->mire[idx]==NULL)
break;
}
if (idx==0)
s->mire[0]=ms_load_nowebcam(&s->vsize, -1);
s->mire[0]=ms_load_nowebcam(s->factory, &s->vsize, -1);
}
for (count=0;count<10;count++)
{
......
......@@ -69,6 +69,7 @@ typedef struct V4wState{
float fps;
uint64_t start_time;
int frame_count;
MSFactory *factory;
}V4wState;
static V4wState *s_callback=NULL;
......@@ -1021,6 +1022,7 @@ static void v4w_init(MSFilter *f){
s->fps=15;
memset(s->dev, 0, sizeof(s->dev));
s->factory = ms_filter_get_factory(f);
f->data=s;
}
......@@ -1208,12 +1210,12 @@ static mblk_t * v4w_make_nowebcam(V4wState *s){
/* load several images to fake a movie */
for (idx=0;idx<10;idx++)
{
s->mire[idx]=ms_load_nowebcam(&s->vsize, idx);
s->mire[idx]=ms_load_nowebcam(s->factory, &s->vsize, idx);
if (s->mire[idx]==NULL)
break;
}
if (idx==0)
s->mire[0]=ms_load_nowebcam(&s->vsize, -1);
s->mire[0]=ms_load_nowebcam(s->factory, &s->vsize, -1);
}
for (count=0;count<10;count++)
{
......
......@@ -356,6 +356,13 @@ MSFactory *ms_factory_new_with_voip(void){
return f;
}
MSFactory *ms_factory_new_with_voip_and_plugins_dir(const char *plugins_dir) {
MSFactory *f = ms_factory_new();
ms_factory_set_plugins_dir(f, plugins_dir);
ms_factory_init_voip(f);
ms_factory_init_plugins(f);
return f;
}
PayloadType * ms_offer_answer_context_match_payload(MSOfferAnswerContext *context, const MSList *local_payloads, const PayloadType *remote_payload, const MSList *remote_payloads, bool_t is_reading){
......
......@@ -22,7 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define nowebcam_h
MS2_PUBLIC mblk_t *ms_load_jpeg_as_yuv(const char *path, MSVideoSize *reqsize);
MS2_PUBLIC mblk_t *ms_load_nowebcam(MSVideoSize *reqsize, int idx);
MS2_PUBLIC mblk_t *ms_load_nowebcam(MSFactory *factory, MSVideoSize *reqsize, int idx);
MS2_PUBLIC mblk_t *jpeg2yuv(uint8_t *jpgbuf, int bufsize, MSVideoSize *reqsize);
#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