From 9316b09835ab906de9cc4b464d915bf7b272053d Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Fri, 19 Jan 2018 09:22:24 +0100 Subject: [PATCH] Added next video frame decoded callback to LinphoneCall --- coreapi/linphonecall.c | 12 ++++++++++++ coreapi/private.h | 2 ++ include/linphone/call.h | 14 ++++++++++++++ include/linphone/callbacks.h | 6 ++++++ tester/call_multicast_tester.c | 6 +++--- tester/call_single_tester.c | 21 +++++++++++++++------ tester/call_video_tester.c | 18 ++++++++---------- tester/liblinphone_tester.h | 2 +- 8 files changed, 61 insertions(+), 20 deletions(-) diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index 7bee0b0c7..3eadd09dd 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -160,6 +160,13 @@ void linphone_call_cbs_set_snapshot_taken(LinphoneCallCbs *cbs, LinphoneCallCbsS cbs->snapshot_taken_cb = cb; } +LinphoneCallCbsNextVideoFrameDecodedCb linphone_call_cbs_get_next_video_frame_decoded(LinphoneCallCbs *cbs) { + return cbs->next_video_frame_decoded_cb; +} + +void linphone_call_cbs_set_next_video_frame_decoded(LinphoneCallCbs *cbs, LinphoneCallCbsNextVideoFrameDecodedCb cb) { + cbs->next_video_frame_decoded_cb = cb; +} bool_t linphone_call_state_is_early(LinphoneCallState state){ switch (state){ @@ -2459,6 +2466,7 @@ static void video_stream_event_cb(void *user_pointer, const MSFilter *f, const u call->nextVideoFrameDecoded._func = NULL; call->nextVideoFrameDecoded._user_data = NULL; } + linphone_call_notify_next_video_frame_decoded(call); break; case MS_VIDEO_DECODER_SEND_PLI: case MS_VIDEO_DECODER_SEND_SLI: @@ -6304,3 +6312,7 @@ void linphone_call_notify_tmmbr_received(LinphoneCall *call, int stream_index, i void linphone_call_notify_snapshot_taken(LinphoneCall *call, const char *file_path) { NOTIFY_IF_EXIST(snapshot_taken_cb, call, file_path) } + +void linphone_call_notify_next_video_frame_decoded(LinphoneCall *call) { + NOTIFY_IF_EXIST(next_video_frame_decoded_cb, call) +} diff --git a/coreapi/private.h b/coreapi/private.h index 3b2894fd6..1c2af376c 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -315,6 +315,7 @@ struct _LinphoneCallCbs { LinphoneCallCbsAckProcessingCb ack_processing; LinphoneCallCbsTmmbrReceivedCb tmmbr_received_cb; LinphoneCallCbsSnapshotTakenCb snapshot_taken_cb; + LinphoneCallCbsNextVideoFrameDecodedCb next_video_frame_decoded_cb; }; LinphoneCallCbs * _linphone_call_cbs_new(void); @@ -429,6 +430,7 @@ void linphone_call_notify_info_message_received(LinphoneCall *call, const Linpho void linphone_call_notify_ack_processing(LinphoneCall *call, LinphoneHeaders *msg, bool_t is_received); void linphone_call_notify_tmmbr_received(LinphoneCall *call, int stream_index, int tmmbr); void linphone_call_notify_snapshot_taken(LinphoneCall *call, const char *file_path); +void linphone_call_notify_next_video_frame_decoded(LinphoneCall *call); LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to, const LinphoneCallParams *params, LinphoneProxyConfig *cfg); LinphoneCall * linphone_call_new_incoming(struct _LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to, SalOp *op); diff --git a/include/linphone/call.h b/include/linphone/call.h index 3a7188ed8..bbc19929a 100644 --- a/include/linphone/call.h +++ b/include/linphone/call.h @@ -712,6 +712,20 @@ LINPHONE_PUBLIC LinphoneCallCbsSnapshotTakenCb linphone_call_cbs_get_snapshot_ta */ LINPHONE_PUBLIC void linphone_call_cbs_set_snapshot_taken(LinphoneCallCbs *cbs, LinphoneCallCbsSnapshotTakenCb cb); +/** + * Get the next video frame decoded callback. + * @param[in] cbs LinphoneCallCbs object. + * @return The current next video frame decoded callback. + */ +LINPHONE_PUBLIC LinphoneCallCbsNextVideoFrameDecodedCb linphone_call_cbs_get_next_video_frame_decoded(LinphoneCallCbs *cbs); + +/** + * Set the next video frame decoded callback. + * @param[in] cbs LinphoneCallCbs object. + * @param[in] cb The next video frame decoded callback to be used. + */ +LINPHONE_PUBLIC void linphone_call_cbs_set_next_video_frame_decoded(LinphoneCallCbs *cbs, LinphoneCallCbsNextVideoFrameDecodedCb cb); + /** * @} */ diff --git a/include/linphone/callbacks.h b/include/linphone/callbacks.h index 6a6738dbe..c5fe71136 100644 --- a/include/linphone/callbacks.h +++ b/include/linphone/callbacks.h @@ -149,6 +149,12 @@ typedef void (*LinphoneCallCbsTmmbrReceivedCb)(LinphoneCall *call, int stream_in */ typedef void (*LinphoneCallCbsSnapshotTakenCb)(LinphoneCall *call, const char *filepath); +/** + * Callback to notify a next video frame has been decoded + * @param call LinphoneCall for which the next video frame has been decoded + */ +typedef void (*LinphoneCallCbsNextVideoFrameDecodedCb)(LinphoneCall *call); + /** * @} **/ diff --git a/tester/call_multicast_tester.c b/tester/call_multicast_tester.c index cf1758705..99116b5da 100644 --- a/tester/call_multicast_tester.c +++ b/tester/call_multicast_tester.c @@ -54,7 +54,7 @@ static void call_multicast_base(bool_t video) { BC_ASSERT_GREATER(linphone_core_manager_get_max_audio_down_bw(marie),70,int,"%d"); if (video) { /*check video path*/ - linphone_call_set_next_video_frame_decoded_callback(linphone_core_get_current_call(marie->lc),linphone_call_iframe_decoded_cb,marie->lc); + linphone_call_set_first_video_frame_decoded_cb(linphone_core_get_current_call(marie->lc)); linphone_call_send_vfu_request(linphone_core_get_current_call(marie->lc)); BC_ASSERT_TRUE( wait_for(marie->lc,pauline->lc,&marie->stat.number_of_IframeDecoded,1)); } @@ -148,7 +148,7 @@ static void early_media_with_multicast_base(bool_t video) { /* send a 183 to initiate the early media */ if (video) { /*check video path*/ - linphone_call_set_next_video_frame_decoded_callback(linphone_core_get_current_call(pauline->lc),linphone_call_iframe_decoded_cb,pauline->lc); + linphone_call_set_first_video_frame_decoded_cb(linphone_core_get_current_call(pauline->lc)); } linphone_call_accept_early_media(linphone_core_get_current_call(pauline->lc)); @@ -159,7 +159,7 @@ static void early_media_with_multicast_base(bool_t video) { /* send a 183 to initiate the early media */ if (video) { /*check video path*/ - linphone_call_set_next_video_frame_decoded_callback(linphone_core_get_current_call(pauline2->lc),linphone_call_iframe_decoded_cb,pauline2->lc); + linphone_call_set_first_video_frame_decoded_cb(linphone_core_get_current_call(pauline2->lc)); } linphone_call_accept_early_media(linphone_core_get_current_call(pauline2->lc)); diff --git a/tester/call_single_tester.c b/tester/call_single_tester.c index 32e4d0024..c6ede11e8 100644 --- a/tester/call_single_tester.c +++ b/tester/call_single_tester.c @@ -169,12 +169,11 @@ void linphone_transfer_state_changed(LinphoneCore *lc, LinphoneCall *transfered, } } - -void linphone_call_iframe_decoded_cb(LinphoneCall *call,void * user_data) { - char* to=linphone_address_as_string(linphone_call_get_call_log(call)->to); - char* from=linphone_address_as_string(linphone_call_get_call_log(call)->from); +static void linphone_call_next_video_frame_decoded_cb(LinphoneCall *call) { + char* to = linphone_address_as_string(linphone_call_get_call_log(call)->to); + char* from = linphone_address_as_string(linphone_call_get_call_log(call)->from); stats* counters; - LinphoneCore* lc=(LinphoneCore*)user_data; + LinphoneCore* lc = linphone_call_get_core(call); ms_message("call from [%s] to [%s] receive iFrame",from,to); ms_free(to); ms_free(from); @@ -182,6 +181,13 @@ void linphone_call_iframe_decoded_cb(LinphoneCall *call,void * user_data) { counters->number_of_IframeDecoded++; } +void linphone_call_set_first_video_frame_decoded_cb(LinphoneCall *call) { + LinphoneCallCbs *call_cbs = linphone_factory_create_call_cbs(linphone_factory_get()); + linphone_call_cbs_set_next_video_frame_decoded(call_cbs, linphone_call_next_video_frame_decoded_cb); + linphone_call_add_callbacks(call, call_cbs); + linphone_call_cbs_unref(call_cbs); +} + void liblinphone_tester_check_rtcp(LinphoneCoreManager* caller, LinphoneCoreManager* callee) { LinphoneCall *c1,*c2; MSTimeSpec ts; @@ -3606,9 +3612,12 @@ void check_media_direction(LinphoneCoreManager* mgr, LinphoneCall *call, bctbx_l LinphoneCallStats *stats = linphone_call_get_video_stats(call); if (video_dir != LinphoneMediaDirectionInactive){ + LinphoneCallCbs *call_cbs = linphone_factory_create_call_cbs(linphone_factory_get()); BC_ASSERT_TRUE(linphone_call_params_video_enabled(params)); BC_ASSERT_EQUAL(linphone_call_params_get_video_direction(params), video_dir, int, "%d"); - linphone_call_set_next_video_frame_decoded_callback(call,linphone_call_iframe_decoded_cb,mgr->lc); + linphone_call_cbs_set_next_video_frame_decoded(call_cbs, linphone_call_next_video_frame_decoded_cb); + linphone_call_add_callbacks(call, call_cbs); + linphone_call_cbs_unref(call_cbs); linphone_call_send_vfu_request(call); } switch (video_dir) { diff --git a/tester/call_video_tester.c b/tester/call_video_tester.c index eb20ed143..e5339bd2d 100644 --- a/tester/call_video_tester.c +++ b/tester/call_video_tester.c @@ -276,7 +276,7 @@ bool_t request_video(LinphoneCoreManager* caller,LinphoneCoreManager* callee, bo } if (video_added) { - linphone_call_set_next_video_frame_decoded_callback(call_obj,linphone_call_iframe_decoded_cb,callee->lc); + linphone_call_set_first_video_frame_decoded_cb(call_obj); /*send vfu*/ linphone_call_send_vfu_request(call_obj); BC_ASSERT_TRUE(wait_for(caller->lc,callee->lc,&callee->stat.number_of_IframeDecoded,initial_callee_stat.number_of_IframeDecoded+1)); @@ -600,7 +600,7 @@ void video_call_base_2(LinphoneCoreManager* caller,LinphoneCoreManager* callee, BC_ASSERT_TRUE(linphone_call_log_video_enabled(linphone_call_get_call_log(caller_call))); /*check video path*/ - linphone_call_set_next_video_frame_decoded_callback(callee_call,linphone_call_iframe_decoded_cb,callee->lc); + linphone_call_set_first_video_frame_decoded_cb(callee_call); linphone_call_send_vfu_request(callee_call); BC_ASSERT_TRUE( wait_for(callee->lc,caller->lc,&callee->stat.number_of_IframeDecoded,1)); } else { @@ -621,8 +621,8 @@ static void check_fir(LinphoneCoreManager* caller,LinphoneCoreManager* callee ){ /*check video path is established in both directions. Indeed, FIR are ignored until the first RTP packet is received, because SSRC is not known.*/ - linphone_call_set_next_video_frame_decoded_callback(callee_call,linphone_call_iframe_decoded_cb,callee->lc); - linphone_call_set_next_video_frame_decoded_callback(caller_call,linphone_call_iframe_decoded_cb,caller->lc); + linphone_call_set_first_video_frame_decoded_cb(callee_call); + linphone_call_set_first_video_frame_decoded_cb(caller_call); BC_ASSERT_TRUE( wait_for(callee->lc,caller->lc,&callee->stat.number_of_IframeDecoded,1)); BC_ASSERT_TRUE( wait_for(callee->lc,caller->lc,&caller->stat.number_of_IframeDecoded,1)); @@ -637,7 +637,7 @@ static void check_fir(LinphoneCoreManager* caller,LinphoneCoreManager* callee ){ ms_message ("check_fir : [%p] received %d FIR ",&caller_call ,caller_call->videostream->ms_video_stat.counter_rcvd_fir); ms_message ("check_fir : [%p] stat number of iframe decoded %d ",&callee_call, callee->stat.number_of_IframeDecoded); - linphone_call_set_next_video_frame_decoded_callback(caller_call,linphone_call_iframe_decoded_cb,caller->lc); + linphone_call_set_first_video_frame_decoded_cb(caller_call); linphone_call_send_vfu_request(caller_call); BC_ASSERT_TRUE( wait_for(callee->lc,caller->lc,&caller->stat.number_of_IframeDecoded,1)); @@ -876,8 +876,8 @@ static void video_call_established_by_reinvite_with_implicit_avpf(void) { BC_ASSERT_TRUE(linphone_call_params_video_enabled(linphone_call_get_current_params(callee_call))); BC_ASSERT_TRUE(linphone_call_params_video_enabled(linphone_call_get_current_params(caller_call))); - linphone_call_set_next_video_frame_decoded_callback(caller_call,linphone_call_iframe_decoded_cb,caller->lc); - linphone_call_set_next_video_frame_decoded_callback(callee_call,linphone_call_iframe_decoded_cb,callee->lc); + linphone_call_set_first_video_frame_decoded_cb(caller_call); + linphone_call_set_first_video_frame_decoded_cb(callee_call); BC_ASSERT_TRUE( wait_for(callee->lc,caller->lc,&callee->stat.number_of_IframeDecoded,1)); BC_ASSERT_TRUE( wait_for(callee->lc,caller->lc,&caller->stat.number_of_IframeDecoded,1)); @@ -1322,9 +1322,7 @@ static void accept_call_in_send_only_base(LinphoneCoreManager* pauline, Linphone /*The send-only client shall set rtp symmetric in absence of media relay for this test.*/ lp_config_set_int(marie->lc->config,"rtp","symmetric",1); - linphone_call_set_next_video_frame_decoded_callback(linphone_core_invite_address(pauline->lc,marie->identity) - ,linphone_call_iframe_decoded_cb - ,pauline->lc); + linphone_call_set_first_video_frame_decoded_cb(linphone_core_invite_address(pauline->lc,marie->identity)); BC_ASSERT_TRUE(wait_for_list(lcs, &marie->stat.number_of_LinphoneCallIncomingReceived,1,DEFAULT_WAIT_FOR)); diff --git a/tester/liblinphone_tester.h b/tester/liblinphone_tester.h index 3336de02c..330803458 100644 --- a/tester/liblinphone_tester.h +++ b/tester/liblinphone_tester.h @@ -375,7 +375,7 @@ void linphone_core_manager_check_accounts(LinphoneCoreManager *m); void account_manager_destroy(void); LinphoneCore* configure_lc_from(LinphoneCoreVTable* v_table, const char* path, const char* file, void* user_data); -void linphone_call_iframe_decoded_cb(LinphoneCall *call,void * user_data); +void linphone_call_set_first_video_frame_decoded_cb(LinphoneCall *call); void call_paused_resumed_base(bool_t multicast,bool_t with_losses); void simple_call_base(bool_t enable_multicast_recv_side); void call_base_with_configfile(LinphoneMediaEncryption mode, bool_t enable_video,bool_t enable_relay,LinphoneFirewallPolicy policy,bool_t enable_tunnel, const char *marie_rc, const char *pauline_rc);