From b6badebe891fee43277a4d0db0362f45a1ae4218 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Wed, 17 Jan 2018 13:49:32 +0100 Subject: [PATCH] Fixed linphone_call_unref called as many times snapshot was taken --- coreapi/linphonecall.c | 2 ++ tester/call_video_tester.c | 56 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index 2efde998a..7bee0b0c7 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -2384,6 +2384,7 @@ static void snapshot_taken(void *userdata, struct _MSFilter *f, unsigned int id, LinphoneStatus linphone_call_take_video_snapshot(LinphoneCall *call, const char *file) { #ifdef VIDEO_ENABLED if (call->videostream!=NULL && call->videostream->jpegwriter!=NULL){ + ms_filter_clear_notify_callback(call->videostream->jpegwriter); ms_filter_add_notify_callback(call->videostream->jpegwriter, snapshot_taken, linphone_call_ref(call), TRUE); return ms_filter_call_method(call->videostream->jpegwriter,MS_JPEG_WRITER_TAKE_SNAPSHOT,(void*)file); } @@ -2395,6 +2396,7 @@ LinphoneStatus linphone_call_take_video_snapshot(LinphoneCall *call, const char LinphoneStatus linphone_call_take_preview_snapshot(LinphoneCall *call, const char *file) { #ifdef VIDEO_ENABLED if (call->videostream!=NULL && call->videostream->local_jpegwriter!=NULL){ + ms_filter_clear_notify_callback(call->videostream->local_jpegwriter); ms_filter_add_notify_callback(call->videostream->local_jpegwriter, snapshot_taken, linphone_call_ref(call), TRUE); return ms_filter_call_method(call->videostream->local_jpegwriter,MS_JPEG_WRITER_TAKE_SNAPSHOT,(void*)file); } diff --git a/tester/call_video_tester.c b/tester/call_video_tester.c index 22fd9d356..eb20ed143 100644 --- a/tester/call_video_tester.c +++ b/tester/call_video_tester.c @@ -1737,6 +1737,61 @@ static void video_call_snapshot(void) { linphone_core_manager_destroy(pauline); } +static void video_call_snapshots(void) { + LinphoneCoreManager *marie = linphone_core_manager_new("marie_rc"); + LinphoneCoreManager* pauline = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc"); + LinphoneCallParams *marieParams = linphone_core_create_call_params(marie->lc, NULL); + LinphoneCallParams *paulineParams = linphone_core_create_call_params(pauline->lc, NULL); + LinphoneCall *callInst = NULL; + char *filename = bc_tester_file("snapshot.jpeg"); + bool_t call_succeeded = FALSE; + int dummy = 0; + + linphone_core_enable_video_capture(marie->lc, TRUE); + linphone_core_enable_video_display(marie->lc, TRUE); + linphone_core_enable_video_capture(pauline->lc, TRUE); + linphone_core_enable_video_display(pauline->lc, FALSE); + linphone_call_params_enable_video(marieParams, TRUE); + linphone_call_params_enable_video(paulineParams, TRUE); + + BC_ASSERT_TRUE(call_succeeded = call_with_params(marie, pauline, marieParams, paulineParams)); + BC_ASSERT_PTR_NOT_NULL(callInst = linphone_core_get_current_call(marie->lc)); + if (call_succeeded == TRUE && callInst != NULL) { + LinphoneCall *marie_call = linphone_core_get_current_call(marie->lc); + LinphoneCallCbs *marie_call_cbs = linphone_factory_create_call_cbs(linphone_factory_get()); + BC_ASSERT_PTR_NOT_NULL(marie_call); + linphone_call_cbs_set_snapshot_taken(marie_call_cbs, snapshot_taken); + linphone_call_add_callbacks(marie_call, marie_call_cbs); + linphone_call_cbs_unref(marie_call_cbs); + int jpeg_support = linphone_call_take_video_snapshot(callInst, filename); + if (jpeg_support < 0) { + ms_warning("No jpegwriter support!"); + } else { + BC_ASSERT_TRUE(wait_for(marie->lc,pauline->lc,&marie->stat.number_of_snapshot_taken,1)); + BC_ASSERT_EQUAL(ortp_file_exist(filename), 0, int, "%d"); + remove(filename); + + wait_for_until(marie->lc, pauline->lc, &dummy, 1, 1000); + linphone_call_take_video_snapshot(callInst, filename); + BC_ASSERT_TRUE(wait_for(marie->lc,pauline->lc,&marie->stat.number_of_snapshot_taken,2)); + BC_ASSERT_EQUAL(ortp_file_exist(filename), 0, int, "%d"); + remove(filename); + + wait_for_until(marie->lc, pauline->lc, &dummy, 1, 1000); + linphone_call_take_video_snapshot(callInst, filename); + BC_ASSERT_TRUE(wait_for(marie->lc,pauline->lc,&marie->stat.number_of_snapshot_taken,3)); + BC_ASSERT_EQUAL(ortp_file_exist(filename), 0, int, "%d"); + remove(filename); + } + end_call(marie, pauline); + } + ms_free(filename); + linphone_call_params_unref(marieParams); + linphone_call_params_unref(paulineParams); + linphone_core_manager_destroy(marie); + linphone_core_manager_destroy(pauline); +} + static void video_call_with_re_invite_inactive_followed_by_re_invite_base(LinphoneMediaEncryption mode, bool_t no_sdp) { LinphoneCoreManager* marie; LinphoneCoreManager* pauline; @@ -2220,6 +2275,7 @@ test_t call_video_tests[] = { TEST_NO_TAG("Video call recording (H264)", video_call_recording_h264_test), TEST_NO_TAG("Video call recording (VP8)", video_call_recording_vp8_test), TEST_NO_TAG("Snapshot", video_call_snapshot), + TEST_NO_TAG("Snapshots", video_call_snapshots), TEST_NO_TAG("Video call with early media and no matching audio codecs", video_call_with_early_media_no_matching_audio_codecs), TEST_NO_TAG("DTLS SRTP video call", dtls_srtp_video_call), TEST_ONE_TAG("DTLS SRTP ice video call", dtls_srtp_ice_video_call, "ICE"),