Skip to content
Snippets Groups Projects
Commit 2bf69dca authored by Aline Gondim Santos's avatar Aline Gondim Santos Committed by Sébastien Blin
Browse files

misc: fix ut_recorder

GitLab: #761

Change-Id: Iebcb1dfed3ebd1919c99e00b9528f3e09a77683c
parent 1cc1af80
No related branches found
No related tags found
No related merge requests found
......@@ -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<StreamObserver>(ms,
[this,
......
......@@ -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<std::mutex> 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<DRing::CallSignal::RemoteRecordingChanged>(id, getPeerNumber(), true);
} else {
JAMI_WARN("Peer stopped recording");
......
......@@ -184,6 +184,18 @@ RecorderTest::testRecordCall()
JAMI_INFO("Start call between Alice and Bob");
std::vector<std::map<std::string, std::string>> mediaList;
std::map<std::string, std::string> 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<std::string, std::string> 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<std::map<std::string, std::string>> mediaList;
std::map<std::string, std::string> 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<std::string, std::string> 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<std::map<std::string, std::string>> mediaList;
std::map<std::string, std::string> 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(); }));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment