Commit 60691866 authored by Mohamed Chibani's avatar Mohamed Chibani Committed by Sébastien Blin

sipcall: answer with audio only to empty offers

Currently, when an empty offer is received, a media offer is
generated with audio, and video if enabled in the account.
Now, the generated offer will include only audio. Both
participants can add video to the call if they wish.
Also some code clean-up

Gitlab: #556

Change-Id: Id51bf44b2b84fd9341de4b67bf53963614088ef8
parent 7ed35a6e
......@@ -151,7 +151,7 @@ SIPCall::SIPCall(const std::shared_ptr<SIPAccountBase>& account,
"[call:%s] No media offered in the incoming invite. An offer will be provided in "
"the answer",
getCallId().c_str());
mediaAttrList = getSIPAccount()->createDefaultMediaList(getSIPAccount()->isVideoEnabled(),
mediaAttrList = getSIPAccount()->createDefaultMediaList(false,
getState() == CallState::HOLD);
} else {
JAMI_WARN("[call:%s] Creating an outgoing call with empty offer", getCallId().c_str());
......@@ -2487,7 +2487,7 @@ SIPCall::onReceiveOffer(const pjmedia_sdp_session* offer, const pjsip_rx_data* r
}
void
SIPCall::onReceiveOfferIn200OK(const pjmedia_sdp_session* offer, pjsip_rx_data* rdata)
SIPCall::onReceiveOfferIn200OK(const pjmedia_sdp_session* offer)
{
if (not rtpStreams_.empty()) {
JAMI_ERR("[call:%s] Unexpected offer in '200 OK' answer", getCallId().c_str());
......@@ -2541,7 +2541,6 @@ SIPCall::onReceiveOfferIn200OK(const pjmedia_sdp_session* offer, pjsip_rx_data*
sdp_->startNegotiation();
pjsip_tx_data* tdata = nullptr;
if (pjsip_inv_set_sdp_answer(inviteSession_.get(), sdp_->getLocalSdpSession()) != PJ_SUCCESS) {
JAMI_ERR("[call:%s] Could not start media negotiation for a re-invite request",
getCallId().c_str());
......
......@@ -206,7 +206,7 @@ public:
const pjmedia_sdp_session* offer, const pjsip_rx_data* rdata);
pj_status_t onReceiveReinvite(const pjmedia_sdp_session* offer, pjsip_rx_data* rdata);
void onReceiveOfferIn200OK(const pjmedia_sdp_session* offer, pjsip_rx_data* rdata);
void onReceiveOfferIn200OK(const pjmedia_sdp_session* offer);
/**
* Called when the media negotiation (SDP offer/answer) has
* completed.
......@@ -394,8 +394,6 @@ private:
// Vector holding the current RTP sessions.
std::vector<RtpStream> rtpStreams_;
bool srtpEnabled_ {false};
/**
* Hold the transport used for SIP communication.
* Will be different from the account registration transport for
......@@ -426,6 +424,7 @@ private:
unsigned int localVideoPort_ {0};
bool enableIce_ {true};
bool srtpEnabled_ {false};
///< Transport used for media streams
std::shared_ptr<IceTransport> mediaTransport_;
......
......@@ -1001,7 +1001,7 @@ on_rx_offer2(pjsip_inv_session* inv, struct pjsip_inv_on_rx_offer_cb_param* para
if (auto call = getCallFromInvite(inv)) {
if (auto const& account = call->getAccount().lock()) {
call->onReceiveOfferIn200OK(param->offer, const_cast<pjsip_rx_data*>(param->rdata));
call->onReceiveOfferIn200OK(param->offer);
}
}
}
......
......@@ -83,12 +83,10 @@ public:
private:
// Test cases.
void audio_only_test();
void audio_video_test();
void send_and_handle_empty_offer();
CPPUNIT_TEST_SUITE(SipEmptyOfferTest);
CPPUNIT_TEST(audio_only_test);
CPPUNIT_TEST(audio_video_test);
CPPUNIT_TEST(send_and_handle_empty_offer);
CPPUNIT_TEST_SUITE_END();
// Event/Signal handlers
......@@ -466,24 +464,18 @@ SipEmptyOfferTest::audio_video_call(std::vector<MediaAttribute> offer,
{
auto activeMediaList = Manager::instance().getMediaAttributeList(aliceData_.callId_);
CPPUNIT_ASSERT_EQUAL(answer.size(), activeMediaList.size());
// Audio
CPPUNIT_ASSERT_EQUAL(MediaType::MEDIA_AUDIO, activeMediaList[0].type_);
CPPUNIT_ASSERT_EQUAL(answer[0].enabled_, activeMediaList[0].enabled_);
// Video
CPPUNIT_ASSERT_EQUAL(MediaType::MEDIA_VIDEO, activeMediaList[1].type_);
CPPUNIT_ASSERT_EQUAL(answer[1].enabled_, activeMediaList[1].enabled_);
}
// Validate Bob's media
{
auto activeMediaList = Manager::instance().getMediaAttributeList(bobData_.callId_);
CPPUNIT_ASSERT_EQUAL(offer.size(), activeMediaList.size());
// Audio
CPPUNIT_ASSERT_EQUAL(MediaType::MEDIA_AUDIO, activeMediaList[0].type_);
CPPUNIT_ASSERT_EQUAL(offer[0].enabled_, activeMediaList[0].enabled_);
// Video
CPPUNIT_ASSERT_EQUAL(MediaType::MEDIA_VIDEO, activeMediaList[1].type_);
CPPUNIT_ASSERT_EQUAL(offer[1].enabled_, activeMediaList[1].enabled_);
}
// Give some time to media to start and flow
......@@ -500,47 +492,13 @@ SipEmptyOfferTest::audio_video_call(std::vector<MediaAttribute> offer,
}
void
SipEmptyOfferTest::audio_only_test()
SipEmptyOfferTest::send_and_handle_empty_offer()
{
// Test with video enabled on Bob's side and disabled
// on Alice's side.
auto const aliceAcc = Manager::instance().getAccount<SIPAccount>(aliceData_.accountId_);
auto const bobAcc = Manager::instance().getAccount<SIPAccount>(bobData_.accountId_);
std::vector<MediaAttribute> offer;
MediaAttribute audio(MediaType::MEDIA_AUDIO);
audio.enabled_ = true;
audio.label_ = "audio_0";
audio.secure_ = bobAcc->isSrtpEnabled();
offer.emplace_back(audio);
MediaAttribute video(MediaType::MEDIA_VIDEO);
video.enabled_ = true;
video.label_ = "video_0";
video.secure_ = bobAcc->isSrtpEnabled();
bobAcc->enableVideo(true);
offer.emplace_back(video);
// Current implementation, when an empty offer is received, the
// local UA will provide a media offer (SDP) in "200 OK" answer
// that includes audio media only. Each call participant can add
// the video is he/she wishes.
std::vector<MediaAttribute> answer;
audio.enabled_ = true;
audio.label_ = "audio_0";
audio.secure_ = bobAcc->isSrtpEnabled();
answer.emplace_back(audio);
video.enabled_ = false;
video.label_ = "video_0";
video.secure_ = aliceAcc->isSrtpEnabled();
aliceAcc->enableVideo(false);
answer.emplace_back(video);
audio_video_call(offer, answer);
}
void
SipEmptyOfferTest::audio_video_test()
{
auto const aliceAcc = Manager::instance().getAccount<SIPAccount>(aliceData_.accountId_);
auto const bobAcc = Manager::instance().getAccount<SIPAccount>(bobData_.accountId_);
......@@ -552,25 +510,12 @@ SipEmptyOfferTest::audio_video_test()
audio.secure_ = bobAcc->isSrtpEnabled();
offer.emplace_back(audio);
MediaAttribute video(MediaType::MEDIA_VIDEO);
video.enabled_ = true;
video.label_ = "video_0";
video.secure_ = bobAcc->isSrtpEnabled();
bobAcc->enableVideo(true);
offer.emplace_back(video);
std::vector<MediaAttribute> answer;
audio.enabled_ = true;
audio.label_ = "audio_0";
audio.secure_ = bobAcc->isSrtpEnabled();
answer.emplace_back(audio);
video.enabled_ = true;
video.label_ = "video_0";
video.secure_ = aliceAcc->isSrtpEnabled();
aliceAcc->enableVideo(true);
answer.emplace_back(video);
audio_video_call(offer, answer);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment