From c04000a192a00f047ea6d04e131e42f0b72bc11b Mon Sep 17 00:00:00 2001 From: Liong Sauw Ming Date: Thu, 1 Dec 2011 10:49:07 +0000 Subject: Closed #1420: Add support for event manager git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3893 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip/include/pjsua-lib/pjsua_internal.h | 6 ++--- pjsip/src/pjsua-lib/pjsua_media.c | 13 +++------ pjsip/src/pjsua-lib/pjsua_vid.c | 46 +++++++++++++++++++++----------- 3 files changed, 36 insertions(+), 29 deletions(-) (limited to 'pjsip') diff --git a/pjsip/include/pjsua-lib/pjsua_internal.h b/pjsip/include/pjsua-lib/pjsua_internal.h index 31d303f0..5c16370a 100644 --- a/pjsip/include/pjsua-lib/pjsua_internal.h +++ b/pjsip/include/pjsua-lib/pjsua_internal.h @@ -85,9 +85,6 @@ struct pjsua_call_media address) */ pjmedia_srtp_use rem_srtp_use; /**< Remote's SRTP usage policy. */ - pjmedia_event_subscription esub_rend;/**< Subscribe renderer events. */ - pjmedia_event_subscription esub_cap;/**< Subscribe capture events. */ - pjsua_med_tp_state_cb med_init_cb;/**< Media transport initialization callback. */ @@ -565,6 +562,9 @@ pj_status_t video_channel_update(pjsua_call_media *call_med, void stop_video_stream(pjsua_call_media *call_med); void set_media_tp_state(pjsua_call_media *call_med, pjsua_med_tp_st tp_st); +/* Callback to receive media events */ +pj_status_t call_media_on_event(pjmedia_event *event, + void *user_data); /** * Init presence. diff --git a/pjsip/src/pjsua-lib/pjsua_media.c b/pjsip/src/pjsua-lib/pjsua_media.c index 3eb8cee6..e938247f 100644 --- a/pjsip/src/pjsua-lib/pjsua_media.c +++ b/pjsip/src/pjsua-lib/pjsua_media.c @@ -1253,14 +1253,13 @@ static void sort_media(const pjmedia_sdp_session *sdp, } /* Callback to receive media events */ -static pj_status_t call_media_on_event(pjmedia_event_subscription *esub, - pjmedia_event *event) +pj_status_t call_media_on_event(pjmedia_event *event, + void *user_data) { - pjsua_call_media *call_med = (pjsua_call_media*)esub->user_data; + pjsua_call_media *call_med = (pjsua_call_media*)user_data; pjsua_call *call = call_med->call; if (pjsua_var.ua_cfg.cb.on_call_media_event && call) { - ++event->proc_cnt; (*pjsua_var.ua_cfg.cb.on_call_media_event)(call->index, call_med->idx, event); } @@ -1424,12 +1423,6 @@ pj_status_t pjsua_call_media_init(pjsua_call_media *call_med, pjmedia_vid_dev_get_info(call_med->strm.v.cap_dev, &info); call_med->strm.v.cap_dev = info.id; } - - /* Init event subscribtion */ - pjmedia_event_subscription_init(&call_med->esub_rend, &call_media_on_event, - call_med); - pjmedia_event_subscription_init(&call_med->esub_cap, &call_media_on_event, - call_med); } #endif diff --git a/pjsip/src/pjsua-lib/pjsua_vid.c b/pjsip/src/pjsua-lib/pjsua_vid.c index 81b943e1..4e9017fa 100644 --- a/pjsip/src/pjsua-lib/pjsua_vid.c +++ b/pjsip/src/pjsua-lib/pjsua_vid.c @@ -57,6 +57,13 @@ pj_status_t pjsua_vid_subsys_init(void) goto on_error; } + status = pjmedia_event_mgr_create(pjsua_var.pool, 0, NULL); + if (status != PJ_SUCCESS) { + PJ_PERROR(1,(THIS_FILE, status, + "Error creating PJMEDIA event manager")); + goto on_error; + } + status = pjmedia_vid_codec_mgr_create(pjsua_var.pool, NULL); if (status != PJ_SUCCESS) { PJ_PERROR(1,(THIS_FILE, status, @@ -130,6 +137,9 @@ pj_status_t pjsua_vid_subsys_destroy(void) if (pjmedia_converter_mgr_instance()) pjmedia_converter_mgr_destroy(NULL); + if (pjmedia_event_mgr_instance()) + pjmedia_event_mgr_destroy(NULL); + if (pjmedia_video_format_mgr_instance()) pjmedia_video_format_mgr_destroy(NULL); @@ -613,11 +623,15 @@ static void free_vid_win(pjsua_vid_win_id wid) pj_log_push_indent(); if (w->vp_cap) { + pjmedia_event_unsubscribe(NULL, &call_media_on_event, NULL, + w->vp_cap); pjmedia_vid_port_stop(w->vp_cap); pjmedia_vid_port_disconnect(w->vp_cap); pjmedia_vid_port_destroy(w->vp_cap); } if (w->vp_rend) { + pjmedia_event_unsubscribe(NULL, &call_media_on_event, NULL, + w->vp_rend); pjmedia_vid_port_stop(w->vp_rend); pjmedia_vid_port_destroy(w->vp_rend); } @@ -815,9 +829,8 @@ pj_status_t video_channel_update(pjsua_call_media *call_med, #if ENABLE_EVENT /* Register to video events */ - pjmedia_event_subscribe( - pjmedia_vid_port_get_event_publisher(w->vp_rend), - &call_med->esub_rend); + pjmedia_event_subscribe(NULL, w->pool, &call_media_on_event, + call_med, w->vp_rend); #endif /* Connect renderer to stream */ @@ -886,9 +899,8 @@ pj_status_t video_channel_update(pjsua_call_media *call_med, w = &pjsua_var.win[wid]; #if ENABLE_EVENT - pjmedia_event_subscribe( - pjmedia_vid_port_get_event_publisher(w->vp_cap), - &call_med->esub_cap); + pjmedia_event_subscribe(NULL, w->pool, &call_media_on_event, + call_med, w->vp_cap); #endif /* Connect stream to capturer (via video window tee) */ @@ -1006,7 +1018,8 @@ void stop_video_stream(pjsua_call_media *call_med) } /* Unsubscribe event */ - pjmedia_event_unsubscribe(&call_med->esub_cap); + pjmedia_event_unsubscribe(NULL, &call_media_on_event, call_med, + w->vp_cap); /* Re-start capture again, if it is used by other stream */ if (w->ref_cnt > 1) @@ -1021,7 +1034,8 @@ void stop_video_stream(pjsua_call_media *call_med) /* Stop the render before unsubscribing event */ pjmedia_vid_port_stop(w->vp_rend); - pjmedia_event_unsubscribe(&call_med->esub_rend); + pjmedia_event_unsubscribe(NULL, &call_media_on_event, call_med, + w->vp_rend); dec_vid_win(call_med->strm.v.rdr_win_id); call_med->strm.v.rdr_win_id = PJSUA_INVALID_ID; @@ -1835,7 +1849,8 @@ static pj_status_t call_change_cap_dev(pjsua_call *call, if (status != PJ_SUCCESS) return status; - pjmedia_event_unsubscribe(&call_med->esub_cap); + pjmedia_event_unsubscribe(NULL, &call_media_on_event, call_med, + w->vp_cap); /* temporarily disconnect while we operate on the tee. */ pjmedia_vid_port_disconnect(w->vp_cap); @@ -1893,9 +1908,8 @@ static pj_status_t call_change_cap_dev(pjsua_call *call, } #if ENABLE_EVENT - pjmedia_event_subscribe( - pjmedia_vid_port_get_event_publisher(new_w->vp_cap), - &call_med->esub_cap); + pjmedia_event_subscribe(NULL, new_w->pool, &call_media_on_event, + call_med, new_w->vp_cap); #endif /* Start capturer */ @@ -1919,7 +1933,8 @@ on_error: if (new_w) { /* Unsubscribe, just in case */ - pjmedia_event_unsubscribe(&call_med->esub_cap); + pjmedia_event_unsubscribe(NULL, &call_media_on_event, call_med, + new_w->vp_cap); /* Disconnect media port from the new capturer */ pjmedia_vid_tee_remove_dst_port(new_w->tee, media_port); /* Release the new capturer */ @@ -1935,9 +1950,8 @@ on_error: #if ENABLE_EVENT /* Resubscribe */ - pjmedia_event_subscribe( - pjmedia_vid_port_get_event_publisher(w->vp_cap), - &call_med->esub_cap); + pjmedia_event_subscribe(NULL, w->pool, &call_media_on_event, + call_med, w->vp_cap); #endif return status; -- cgit v1.2.3