Commit 22778d62 authored by Sandrine Avakian's avatar Sandrine Avakian

Adding MSSndCardManager* sndcardmanager in MSSndCard structure and MSFactory structure.

Using getter ms_factory_get_snd_manager to get MSSndCardManager from the MSFactory.
Using ms_snd_card_factory_get to get MSFactory from MSSndCard.
Removing static MSSndCardManager* scm.

.
parent 2bbda962
......@@ -43,6 +43,7 @@ struct _MSFactory{
bool_t statistics_enabled;
bool_t voip_initd;
int ref_count;
struct _MSSndCardManager* sndcardmanager;
};
typedef struct _MSFactory MSFactory;
......@@ -86,6 +87,9 @@ MS2_PUBLIC void ms_factory_destroy(MSFactory *factory);
* Ensures it can be destroyed before destroying all objects created by the factory.
**/
MS2_PUBLIC MSFactory* ms_factory_exit(MSFactory* factory);
MS2_PUBLIC struct _MSSndCardManager* ms_factory_get_snd_manager(MSFactory *f);
MS2_PUBLIC void ms_factory_register_filter(MSFactory *factory, MSFilterDesc *desc);
......
......@@ -131,7 +131,7 @@ typedef struct _MSSndCardDesc MSSndCardDesc;
struct _MSSndCard{
MSSndCardDesc *desc;
MSSndCardManager* scm;
MSSndCardManager* sndcardmanager;
char *name;
char *id;
unsigned int capabilities;
......@@ -161,13 +161,15 @@ extern "C"{
*
* Returns: MSSndCardManager if successfull, NULL otherwise.
*/
MS2_PUBLIC MSSndCardManager * ms_snd_card_manager_get(void);
MS2_PUBLIC MSSndCardManager * ms_snd_card_manager_get(MSSndCardManager* scm);
MS2_PUBLIC MSFactory * ms_snd_card_factory_get(MSSndCard * c);
/**
* Destroy a sound card manager object.
*
*/
MS2_PUBLIC void ms_snd_card_manager_destroy(void);
MS2_PUBLIC void ms_snd_card_manager_destroy(void* sndcardmanager);
/**
* Retreive a sound card object based on its name.
......
......@@ -794,7 +794,7 @@ static void set_audio_device_id(AuCard *wc,AUCommon* d, bool_t is_read) {
CFRelease(devUid);
}
MSFilter *ms_au_read_new(MSSndCard *card){
MSFilter *f = ms_factory_create_filter_from_desc((ms_snd_card_manager_get()->factory), &ms_au_read_desc);
MSFilter *f = ms_factory_create_filter_from_desc(ms_snd_card_factory_get(card), &ms_au_read_desc);
AuCard *wc = (AuCard *) card->data;
AURead *d = (AURead *) f->data;
/*d->common.dev = wc->dev;*/
......@@ -805,8 +805,7 @@ MSFilter *ms_au_read_new(MSSndCard *card){
MSFilter *ms_au_write_new(MSSndCard *card){
MSFactory* factory=(ms_snd_card_manager_get())->factory;
MSFilter *f=ms_factory_create_filter_from_desc(factory, &ms_au_write_desc);
MSFilter *f=ms_factory_create_filter_from_desc(ms_snd_card_factory_get(card), &ms_au_write_desc);
AuCard *wc = (AuCard *) card->data;
AUWrite *d = (AUWrite *) f->data;
/*d->common.dev = wc->dev;*/
......
......@@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "mediastreamer2/mssndcard.h"
static MSSndCardManager *scm=NULL;
//static MSSndCardManager *scm=NULL;
static MSSndCardManager * create_manager(void){
MSSndCardManager *obj=(MSSndCardManager *)ms_new0(MSSndCardManager,1);
......@@ -33,7 +33,8 @@ static MSSndCardManager * create_manager(void){
return obj;
}
void ms_snd_card_manager_destroy(void){
void ms_snd_card_manager_destroy(void* sndcardmanager){
MSSndCardManager* scm = (MSSndCardManager*) sndcardmanager;
if (scm!=NULL){
MSList *elem;
for(elem=scm->descs;elem!=NULL;elem=elem->next){
......@@ -49,11 +50,20 @@ void ms_snd_card_manager_destroy(void){
scm=NULL;
}
MSSndCardManager * ms_snd_card_manager_get(void){
MSSndCardManager * ms_snd_card_manager_get(MSSndCardManager *scm){
if (scm==NULL) scm=create_manager();
return scm;
}
MSFactory * ms_snd_card_factory_get(MSSndCard * c){
return (ms_snd_card_manager_get(c->sndcardmanager))->factory;
}
MSSndCardManager* ms_factory_get_snd_manager(MSFactory* f){
if(f == NULL) return create_manager();
return ms_snd_card_manager_get(f->sndcardmanager);
}
MSSndCard * ms_snd_card_manager_get_card(MSSndCardManager *m, const char *id){
MSList *elem;
for (elem=m->cards;elem!=NULL;elem=elem->next){
......@@ -107,7 +117,7 @@ void ms_snd_card_manager_add_card(MSSndCardManager *m, MSSndCard *c){
}
void ms_snd_card_set_manager(MSSndCardManager*m, MSSndCard *c){
c->scm = m;
c->sndcardmanager = m;
}
void ms_snd_card_manager_prepend_cards(MSSndCardManager *m, MSList *l) {
......@@ -153,7 +163,7 @@ MSSndCard * ms_snd_card_new(MSSndCardDesc *desc){
MSSndCard * ms_snd_card_new_with_name(MSSndCardDesc *desc,const char* name) {
MSSndCard *obj=(MSSndCard *)ms_new0(MSSndCard,1);
obj->scm = NULL;
obj->sndcardmanager = NULL;
obj->desc=desc;
obj->name=name?ms_strdup(name):NULL;
obj->data=NULL;
......
......@@ -1224,8 +1224,8 @@ AudioStream *audio_stream_start(RtpProfile *prof,int locport,const char *remip,i
MSSndCard *sndcard_playback;
MSSndCard *sndcard_capture;
AudioStream *stream;
sndcard_capture=ms_snd_card_manager_get_default_capture_card(ms_snd_card_manager_get());
sndcard_playback=ms_snd_card_manager_get_default_playback_card(ms_snd_card_manager_get());
sndcard_capture=ms_snd_card_manager_get_default_capture_card(ms_factory_get_snd_manager(factory));
sndcard_playback=ms_snd_card_manager_get_default_playback_card(ms_factory_get_snd_manager(factory));
if (sndcard_capture==NULL || sndcard_playback==NULL)
return NULL;
stream=audio_stream_new(locport, locport+1, ms_is_ipv6(remip),factory);
......
......@@ -272,10 +272,11 @@ void ms_factory_init_voip(MSFactory *obj){
}
if (managers_ref == 0){
cm=ms_snd_card_manager_get();
cm=ms_snd_card_manager_get(obj->sndcardmanager);
if (cm->descs==NULL){
ms_message("Registering all soundcard handlers");
cm->factory=obj;
obj->sndcardmanager = cm;
for (i=0;ms_snd_card_descs[i]!=NULL;i++){
ms_snd_card_manager_register_desc(cm,ms_snd_card_descs[i]);
}
......@@ -325,7 +326,7 @@ void ms_factory_uninit_voip(MSFactory *obj){
ms_srtp_shutdown();
managers_ref--;
if (managers_ref==0){
ms_snd_card_manager_destroy();
ms_snd_card_manager_destroy(obj->sndcardmanager);
#ifdef VIDEO_ENABLED
ms_web_cam_manager_destroy();
#endif
......
......@@ -97,7 +97,7 @@ static void dtmfgen_enc_dec_tonedet(char *mime, int sample_rate, int nchannels)
| FILTER_MASK_DECODER | FILTER_MASK_TONEDET | FILTER_MASK_VOIDSINK;
bool_t send_silence = TRUE;
MSSndCardManager *scm = ms_snd_card_manager_get();
MSSndCardManager *scm = ms_factory_get_snd_manager(factory);
ms_factory_reset_statistics(scm->factory);
//ms_filter_reset_statistics();
......@@ -152,8 +152,7 @@ static void dtmfgen_enc_dec_tonedet_pcmu(void) {
}
static void dtmfgen_enc_dec_tonedet_isac(void) {
MSSndCardManager *scm = ms_snd_card_manager_get();
bool_t supported = ms_factory_codec_supported(scm->factory, "iSAC");
bool_t supported = ms_factory_codec_supported(factory, "iSAC");
// bool_t supported = ms_filter_codec_supported("iSAC");
if( supported ) {
dtmfgen_enc_dec_tonedet("iSAC", 16000, 1);
......@@ -172,13 +171,13 @@ static void dtmfgen_enc_rtp_dec_tonedet(void) {
unsigned int filter_mask = FILTER_MASK_VOIDSOURCE | FILTER_MASK_DTMFGEN | FILTER_MASK_ENCODER
| FILTER_MASK_RTPSEND | FILTER_MASK_RTPRECV | FILTER_MASK_DECODER | FILTER_MASK_TONEDET | FILTER_MASK_VOIDSINK;
bool_t send_silence = TRUE;
MSSndCardManager *scm = ms_snd_card_manager_get();
ms_factory_reset_statistics(scm->factory);
MSSndCardManager *scm = ms_factory_get_snd_manager(factory);
ms_factory_reset_statistics(factory);
//ms_filter_reset_statistics();
ms_tester_create_ticker();
ms_tester_codec_mime = "pcmu";
ms_tester_create_filters(filter_mask, scm->factory);
ms_tester_create_filters(filter_mask, factory);
ms_filter_add_notify_callback(ms_tester_tonedet, (MSFilterNotifyFunc)tone_detected_cb, NULL,TRUE);
rtps = ms_create_duplex_rtp_session("0.0.0.0", 50060, 0);
rtp_session_set_remote_addr_full(rtps, "127.0.0.1", 50060, "127.0.0.1", 50061);
......
......@@ -70,7 +70,7 @@ static void play_file(const char *filepath, bool_t unsupported_format, bool_t se
bool_t succeed;
Eof eof;
MSMediaPlayer *file_player = NULL;
MSSndCard *snd_card = ms_snd_card_manager_get_default_playback_card(ms_snd_card_manager_get());
MSSndCard *snd_card = ms_snd_card_manager_get_default_playback_card(ms_factory_get_snd_manager(factory));
const char *display_name = video_stream_get_default_video_renderer();
int duration, timeout;
const int seek_time = 6100;
......@@ -86,7 +86,7 @@ static void play_file(const char *filepath, bool_t unsupported_format, bool_t se
BC_ASSERT_EQUAL(ms_media_player_get_state(file_player), MSPlayerClosed, int, "%d");
ms_media_player_set_eof_callback(file_player, eof_callback, &eof);
succeed = ms_media_player_open(file_player, filepath, snd_card->scm->factory);
succeed = ms_media_player_open(file_player, filepath,factory);
if(unsupported_format) {
BC_ASSERT_FALSE(succeed);
BC_ASSERT_EQUAL(ms_media_player_get_state(file_player), MSPlayerClosed, int, "%d");
......@@ -130,7 +130,7 @@ static void play_file(const char *filepath, bool_t unsupported_format, bool_t se
if(play_twice) {
eof_init(&eof);
BC_ASSERT_TRUE(ms_media_player_open(file_player, filepath,snd_card->scm->factory));
BC_ASSERT_TRUE(ms_media_player_open(file_player, filepath, factory));
BC_ASSERT_TRUE(ms_media_player_start(file_player));
wait_for_eof(&eof, 100, timeout);
ms_media_player_close(file_player);
......
......@@ -126,7 +126,7 @@ void ms_tester_create_filters(unsigned int filter_mask, MSFactory * f) {
CREATE_FILTER(FILTER_MASK_RESAMPLER, ms_tester_resampler, f, MS_RESAMPLE_ID);
if (filter_mask & FILTER_MASK_SOUNDWRITE) {
BC_ASSERT_PTR_NULL(ms_tester_soundwrite);
snd_manager = ms_snd_card_manager_get();
snd_manager = ms_factory_get_snd_manager(f);
playcard = ms_snd_card_manager_get_default_playback_card(snd_manager);
BC_ASSERT_PTR_NOT_NULL_FATAL(playcard);
ms_tester_soundwrite = ms_snd_card_create_writer(playcard);
......@@ -134,7 +134,7 @@ void ms_tester_create_filters(unsigned int filter_mask, MSFactory * f) {
}
if (filter_mask & FILTER_MASK_SOUNDREAD) {
BC_ASSERT_PTR_NULL(ms_tester_soundread);
snd_manager = ms_snd_card_manager_get();
snd_manager = ms_factory_get_snd_manager(f);
captcard = ms_snd_card_manager_get_default_capture_card(snd_manager);
BC_ASSERT_PTR_NOT_NULL_FATAL(captcard);
ms_tester_soundread = ms_snd_card_create_reader(captcard);
......
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