From 2bf69dcae8e5a3ab01c48fb63518db7911da0747 Mon Sep 17 00:00:00 2001 From: Aline Gondim Santos Date: Thu, 8 Sep 2022 15:25:59 -0300 Subject: [PATCH] misc: fix ut_recorder GitLab: #761 Change-Id: Iebcb1dfed3ebd1919c99e00b9528f3e09a77683c --- src/media/media_recorder.cpp | 4 +++ src/sip/sipcall.cpp | 24 +++++++++--------- test/unitTest/call/recorder.cpp | 45 ++++++++++++++++++++++++++++----- 3 files changed, 55 insertions(+), 18 deletions(-) diff --git a/src/media/media_recorder.cpp b/src/media/media_recorder.cpp index 89a94d803..a92d55699 100644 --- a/src/media/media_recorder.cpp +++ b/src/media/media_recorder.cpp @@ -230,6 +230,10 @@ MediaRecorder::addStream(const MediaStream& ms) JAMI_ERR() << "Trying to add video stream to audio only recording"; return nullptr; } + if (ms.isVideo && ms.format < 0) { + JAMI_ERR() << "Trying to add invalid video stream to recording"; + return nullptr; + } auto ptr = std::make_unique(ms, [this, diff --git a/src/sip/sipcall.cpp b/src/sip/sipcall.cpp index 32fe89cdd..0aa586832 100644 --- a/src/sip/sipcall.cpp +++ b/src/sip/sipcall.cpp @@ -1274,10 +1274,9 @@ SIPCall::transfer(const std::string& to) return; } - if (Recordable::isRecording()) { - deinitRecorder(); + deinitRecorder(); + if (Call::isRecording()) stopRecording(); - } std::string toUri = account->getToUri(to); const pj_str_t dst(CONST_PJ_STR(toUri)); @@ -2219,10 +2218,10 @@ void SIPCall::stopAllMedia() { JAMI_DBG("[call:%s] Stopping all media", getCallId().c_str()); - if (Recordable::isRecording()) { - deinitRecorder(); + deinitRecorder(); + if (Call::isRecording()) stopRecording(); // if call stops, finish recording - } + #ifdef ENABLE_VIDEO { std::lock_guard lk(sinksMtx_); @@ -3161,7 +3160,6 @@ SIPCall::toggleRecording() // add streams to recorder before starting the record if (not Call::isRecording()) { - updateRecState(true); auto account = getSIPAccount(); if (!account) { JAMI_ERR("No account detected"); @@ -3178,15 +3176,17 @@ SIPCall::toggleRecording() deinitRecorder(); } pendingRecord_ = false; - return Call::toggleRecording(); + auto state = Call::toggleRecording(); + if (state) + updateRecState(state); + return state; } void SIPCall::deinitRecorder() { - if (Call::isRecording()) - for (const auto& rtpSession : getRtpSessionList()) - rtpSession->deinitRecorder(recorder_); + for (const auto& rtpSession : getRtpSessionList()) + rtpSession->deinitRecorder(recorder_); } void @@ -3482,7 +3482,7 @@ SIPCall::peerRecording(bool state) auto conference = conf_.lock(); const std::string& id = conference ? conference->getConfId() : getCallId(); if (state) { - JAMI_WARN("Peer is recording"); + JAMI_WARN("[call:%s] Peer is recording", getCallId().c_str()); emitSignal(id, getPeerNumber(), true); } else { JAMI_WARN("Peer stopped recording"); diff --git a/test/unitTest/call/recorder.cpp b/test/unitTest/call/recorder.cpp index 6ec837d2b..c605cf7b4 100644 --- a/test/unitTest/call/recorder.cpp +++ b/test/unitTest/call/recorder.cpp @@ -184,6 +184,18 @@ RecorderTest::testRecordCall() JAMI_INFO("Start call between Alice and Bob"); std::vector> mediaList; + std::map mediaAttributeA + = {{DRing::Media::MediaAttributeKey::MEDIA_TYPE, DRing::Media::MediaAttributeValue::AUDIO}, + {DRing::Media::MediaAttributeKey::ENABLED, TRUE_STR}, + {DRing::Media::MediaAttributeKey::MUTED, FALSE_STR}, + {DRing::Media::MediaAttributeKey::SOURCE, ""}}; + std::map mediaAttributeV + = {{DRing::Media::MediaAttributeKey::MEDIA_TYPE, DRing::Media::MediaAttributeValue::VIDEO}, + {DRing::Media::MediaAttributeKey::ENABLED, TRUE_STR}, + {DRing::Media::MediaAttributeKey::MUTED, FALSE_STR}, + {DRing::Media::MediaAttributeKey::SOURCE, ""}}; + mediaList.emplace_back(mediaAttributeA); + mediaList.emplace_back(mediaAttributeV); auto callId = DRing::placeCallWithMedia(aliceId, bobUri, mediaList); CPPUNIT_ASSERT(cv.wait_for(lk, 20s, [&] { return !bobCall.callId.empty(); })); Manager::instance().answerCall(bobId, bobCall.callId); @@ -191,15 +203,17 @@ RecorderTest::testRecordCall() return bobCall.mediaStatus == DRing::Media::MediaNegotiationStatusEvents::NEGOTIATION_SUCCESS; })); + // give time to start camera + std::this_thread::sleep_for(5s); // Start recorder + recordedFile.clear(); CPPUNIT_ASSERT(!DRing::getIsRecording(aliceId, callId)); DRing::toggleRecording(aliceId, callId); // Stop recorder after a few seconds std::this_thread::sleep_for(5s); CPPUNIT_ASSERT(DRing::getIsRecording(aliceId, callId)); - recordedFile.clear(); DRing::toggleRecording(aliceId, callId); CPPUNIT_ASSERT(!DRing::getIsRecording(aliceId, callId)); @@ -223,8 +237,7 @@ RecorderTest::testRecordAudioOnlyCall() = {{DRing::Media::MediaAttributeKey::MEDIA_TYPE, DRing::Media::MediaAttributeValue::AUDIO}, {DRing::Media::MediaAttributeKey::ENABLED, TRUE_STR}, {DRing::Media::MediaAttributeKey::MUTED, FALSE_STR}, - {DRing::Media::MediaAttributeKey::SOURCE, ""}, - {DRing::Media::MediaAttributeKey::LABEL, "audio_0"}}; + {DRing::Media::MediaAttributeKey::SOURCE, ""}}; mediaList.emplace_back(mediaAttribute); auto callId = DRing::placeCallWithMedia(aliceId, bobUri, mediaList); CPPUNIT_ASSERT(cv.wait_for(lk, 20s, [&] { return !bobCall.callId.empty(); })); @@ -235,12 +248,12 @@ RecorderTest::testRecordAudioOnlyCall() })); // Start recorder + recordedFile.clear(); DRing::toggleRecording(aliceId, callId); // Stop recorder std::this_thread::sleep_for(5s); CPPUNIT_ASSERT(DRing::getIsRecording(aliceId, callId)); - recordedFile.clear(); DRing::toggleRecording(aliceId, callId); CPPUNIT_ASSERT(!DRing::getIsRecording(aliceId, callId)); @@ -262,6 +275,18 @@ RecorderTest::testStopCallWhileRecording() JAMI_INFO("Start call between Alice and Bob"); std::vector> mediaList; + std::map mediaAttributeA + = {{DRing::Media::MediaAttributeKey::MEDIA_TYPE, DRing::Media::MediaAttributeValue::AUDIO}, + {DRing::Media::MediaAttributeKey::ENABLED, TRUE_STR}, + {DRing::Media::MediaAttributeKey::MUTED, FALSE_STR}, + {DRing::Media::MediaAttributeKey::SOURCE, ""}}; + std::map mediaAttributeV + = {{DRing::Media::MediaAttributeKey::MEDIA_TYPE, DRing::Media::MediaAttributeValue::VIDEO}, + {DRing::Media::MediaAttributeKey::ENABLED, TRUE_STR}, + {DRing::Media::MediaAttributeKey::MUTED, FALSE_STR}, + {DRing::Media::MediaAttributeKey::SOURCE, ""}}; + mediaList.emplace_back(mediaAttributeA); + mediaList.emplace_back(mediaAttributeV); auto callId = DRing::placeCallWithMedia(aliceId, bobUri, mediaList); CPPUNIT_ASSERT(cv.wait_for(lk, 20s, [&] { return !bobCall.callId.empty(); })); Manager::instance().answerCall(bobId, bobCall.callId); @@ -269,13 +294,15 @@ RecorderTest::testStopCallWhileRecording() return bobCall.mediaStatus == DRing::Media::MediaNegotiationStatusEvents::NEGOTIATION_SUCCESS; })); + // give time to start camera + std::this_thread::sleep_for(5s); // Start recorder + recordedFile.clear(); DRing::toggleRecording(aliceId, callId); // Hangup call std::this_thread::sleep_for(5s); - recordedFile.clear(); Manager::instance().hangupCall(aliceId, callId); CPPUNIT_ASSERT( cv.wait_for(lk, 20s, [&] { return bobCall.state == "OVER" && !recordedFile.empty(); })); @@ -290,9 +317,16 @@ RecorderTest::testDaemonPreference() auto bobUri = bobAccount->getUsername(); DRing::setIsAlwaysRecording(true); + recordedFile.clear(); JAMI_INFO("Start call between Alice and Bob"); std::vector> mediaList; + std::map mediaAttributeA + = {{DRing::Media::MediaAttributeKey::MEDIA_TYPE, DRing::Media::MediaAttributeValue::AUDIO}, + {DRing::Media::MediaAttributeKey::ENABLED, TRUE_STR}, + {DRing::Media::MediaAttributeKey::MUTED, FALSE_STR}, + {DRing::Media::MediaAttributeKey::SOURCE, ""}}; + mediaList.emplace_back(mediaAttributeA); auto callId = DRing::placeCallWithMedia(aliceId, bobUri, mediaList); CPPUNIT_ASSERT(cv.wait_for(lk, 20s, [&] { return !bobCall.callId.empty(); })); Manager::instance().answerCall(bobId, bobCall.callId); @@ -304,7 +338,6 @@ RecorderTest::testDaemonPreference() // Let record some seconds std::this_thread::sleep_for(5s); - recordedFile.clear(); Manager::instance().hangupCall(aliceId, callId); CPPUNIT_ASSERT( cv.wait_for(lk, 20s, [&] { return bobCall.state == "OVER" && !recordedFile.empty(); }));