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

calls: improve requestmediachange usage

In order to allow file/screen sharing from a audio only call, we must use requestmediachange to add this new stream.
deprecates setinputfile() and setDisplay(). Those functions should be replaced by requestmediachange().

GitLab: client-qt#499
Change-Id: I504789696fe050e360c775692c08ca86b47dd06a
parent 27f1117e
Branches
Tags
No related merge requests found
...@@ -251,7 +251,7 @@ public: ...@@ -251,7 +251,7 @@ public:
*/ */
const video::Renderer& getRenderer(const QString& id) const; const video::Renderer& getRenderer(const QString& id) const;
/** /**
* Render a file to the call id specified * @deprecated Render a file to the call id specified
* @param uri the path of the file * @param uri the path of the file
* @param callId * @param callId
* @note callId can be omitted to switch the input of the local recorder * @note callId can be omitted to switch the input of the local recorder
...@@ -266,7 +266,7 @@ public: ...@@ -266,7 +266,7 @@ public:
*/ */
void switchInputTo(const QString& id, const QString& callId = {}); void switchInputTo(const QString& id, const QString& callId = {});
/** /**
* Render the current display to the call id specified * @deprecated Render the current display to the call id specified
* @param idx of the display * @param idx of the display
* @param x top left of the area * @param x top left of the area
* @param y top up of the area * @param y top up of the area
...@@ -276,6 +276,15 @@ public: ...@@ -276,6 +276,15 @@ public:
* @note callId can be omitted to switch the input of the local recorder * @note callId can be omitted to switch the input of the local recorder
*/ */
void setDisplay(int idx, int x, int y, int w, int h, const QString& callId = {}); void setDisplay(int idx, int x, int y, int w, int h, const QString& callId = {});
/**
* Get the current display resource string
* @param idx of the display
* @param x top left of the area
* @param y top up of the area
* @param w width of the area
* @param h height of the area
*/
QString getDisplay(int idx, int x, int y, int w, int h);
/** /**
* Get informations on the rendered device * Get informations on the rendered device
* @param call_id linked call to the renderer * @param call_id linked call to the renderer
......
...@@ -67,6 +67,7 @@ public: ...@@ -67,6 +67,7 @@ public:
const account::Info& owner; const account::Info& owner;
enum class Media { NONE, AUDIO, VIDEO }; enum class Media { NONE, AUDIO, VIDEO };
enum class MediaRequestType { FILESHARING, SCREENSHARING, CAMERA };
NewCallModel(const account::Info& owner, NewCallModel(const account::Info& owner,
const CallbacksHandler& callbacksHandler, const CallbacksHandler& callbacksHandler,
...@@ -85,8 +86,15 @@ public: ...@@ -85,8 +86,15 @@ public:
* Request a media change in a ongoing call. * Request a media change in a ongoing call.
* @param callId * @param callId
* @param mediaLabel label of media to be changed * @param mediaLabel label of media to be changed
*/ * @param source
void requestMediaChange(const QString& callId, const QString& mediaLabel); * @param type
* @param mute
*/
void requestMediaChange(const QString& callId,
const QString& mediaLabel,
const QString& source,
MediaRequestType type,
bool mute);
/** /**
* Get the call from its call id * Get the call from its call id
......
...@@ -555,9 +555,20 @@ AVModel::setInputFile(const QString& uri, const QString& callId) ...@@ -555,9 +555,20 @@ AVModel::setInputFile(const QString& uri, const QString& callId)
void void
AVModel::setDisplay(int idx, int x, int y, int w, int h, const QString& callId) AVModel::setDisplay(int idx, int x, int y, int w, int h, const QString& callId)
{
auto resource = getDisplay(idx, x, y, w, h);
if (callId.isEmpty()) {
VideoManager::instance().switchInput(resource);
} else {
CallManager::instance().switchInput(callId, resource);
}
}
QString
AVModel::getDisplay(int idx, int x, int y, int w, int h)
{ {
QString sep = DRing::Media::VideoProtocolPrefix::SEPARATOR; QString sep = DRing::Media::VideoProtocolPrefix::SEPARATOR;
auto resource = QString("%1%2:%3+%4,%5 %6x%7") return QString("%1%2:%3+%4,%5 %6x%7")
.arg(DRing::Media::VideoProtocolPrefix::DISPLAY) .arg(DRing::Media::VideoProtocolPrefix::DISPLAY)
.arg(sep) .arg(sep)
.arg(idx) .arg(idx)
...@@ -565,11 +576,6 @@ AVModel::setDisplay(int idx, int x, int y, int w, int h, const QString& callId) ...@@ -565,11 +576,6 @@ AVModel::setDisplay(int idx, int x, int y, int w, int h, const QString& callId)
.arg(y) .arg(y)
.arg(w) .arg(w)
.arg(h); .arg(h);
if (callId.isEmpty()) {
VideoManager::instance().switchInput(resource);
} else {
CallManager::instance().switchInput(callId, resource);
}
} }
void void
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
// Qt // Qt
#include <QObject> #include <QObject>
#include <QString> #include <QString>
#include <QUrl>
// std // std
#include <chrono> #include <chrono>
...@@ -357,7 +358,7 @@ NewCallModel::createCall(const QString& uri, bool isAudioOnly, VectorMapStringSt ...@@ -357,7 +358,7 @@ NewCallModel::createCall(const QString& uri, bool isAudioOnly, VectorMapStringSt
} }
void void
NewCallModel::requestMediaChange(const QString& callId, const QString& mediaLabel) NewCallModel::requestMediaChange(const QString& callId, const QString& mediaLabel, const QString& uri, MediaRequestType type, bool mute)
{ {
// Main audio: audio_0 // Main audio: audio_0
// Main video: video_0 // Main video: video_0
...@@ -366,57 +367,102 @@ NewCallModel::requestMediaChange(const QString& callId, const QString& mediaLabe ...@@ -366,57 +367,102 @@ NewCallModel::requestMediaChange(const QString& callId, const QString& mediaLabe
if (!callInfo) if (!callInfo)
return; return;
QString sep = DRing::Media::VideoProtocolPrefix::SEPARATOR;
QString resource = "";
int found = 0;
QString srctype = MediaAttributeValue::SRC_TYPE_CAPTURE_DEVICE;
switch (type) {
case MediaRequestType::FILESHARING: {
// File sharing
resource = !uri.isEmpty() ? QString("%1%2%3")
.arg(DRing::Media::VideoProtocolPrefix::FILE)
.arg(sep)
.arg(QUrl(uri).toLocalFile())
: DRing::Media::VideoProtocolPrefix::NONE;
if (callInfo->type == call::Type::CONFERENCE) {
CallManager::instance().switchInput(callId, resource);
return;
}
if (!resource.isEmpty())
srctype = MediaAttributeValue::SRC_TYPE_FILE;
break;
}
case MediaRequestType::SCREENSHARING: {
// Screen/window sharing
resource = uri;
if (callInfo->type == call::Type::CONFERENCE) {
CallManager::instance().switchInput(callId, resource);
return;
}
srctype = MediaAttributeValue::SRC_TYPE_DISPLAY;
break;
}
case MediaRequestType::CAMERA: {
// Camera device
resource = !uri.isEmpty() ? QString("%1%2%3")
.arg(DRing::Media::VideoProtocolPrefix::CAMERA)
.arg(sep)
.arg(uri)
: DRing::Media::VideoProtocolPrefix::NONE;
if (callInfo->type == call::Type::CONFERENCE) { if (callInfo->type == call::Type::CONFERENCE) {
if (mediaLabel.contains("audio_0")) { if (mediaLabel.contains("audio_0")) {
CallManager::instance().muteLocalMedia(callId, CallManager::instance().muteLocalMedia(callId,
DRing::Media::Details::MEDIA_TYPE_AUDIO, DRing::Media::Details::MEDIA_TYPE_AUDIO,
!callInfo->audioMuted); !callInfo->audioMuted && mute);
callInfo->audioMuted = !callInfo->audioMuted;
} else if (mediaLabel.contains("video_0")) { } else if (mediaLabel.contains("video_0")) {
CallManager::instance().muteLocalMedia(callId, CallManager::instance().muteLocalMedia(callId,
DRing::Media::Details::MEDIA_TYPE_VIDEO, DRing::Media::Details::MEDIA_TYPE_VIDEO,
!callInfo->videoMuted); !callInfo->videoMuted && mute);
callInfo->videoMuted = !callInfo->videoMuted;
} }
if (callInfo->status == call::Status::IN_PROGRESS)
emit callInfosChanged(owner.id, callId);
return; return;
} }
auto proposedList = callInfo->mediaList; srctype = MediaAttributeValue::SRC_TYPE_CAPTURE_DEVICE;
break;
}
default:
return;
}
int found = 0; auto proposedList = callInfo->mediaList;
for (auto& item : proposedList) { for (auto& item : proposedList) {
if (item[MediaAttributeKey::LABEL] == mediaLabel) { if (item[MediaAttributeKey::LABEL] == mediaLabel) {
mute = resource.isEmpty() ? item[MediaAttributeKey::MUTED] == "false" : mute;
item[MediaAttributeKey::ENABLED] = "true"; item[MediaAttributeKey::ENABLED] = "true";
item[MediaAttributeKey::MUTED] = item[MediaAttributeKey::MUTED] == "true" ? "false" item[MediaAttributeKey::MUTED] = mute ? "true" : "false";
: "true"; item[MediaAttributeKey::SOURCE_TYPE] = srctype;
item[MediaAttributeKey::SOURCE] = resource.isEmpty() ? item[MediaAttributeKey::SOURCE] : resource;
break; break;
} }
found++; found++;
} }
if (found == proposedList.size() && mediaLabel == "video_0") { if (found == proposedList.size() && mediaLabel == "video_0") {
mute &= !resource.isEmpty();
MapStringString mediaAttribute = {{MediaAttributeKey::MEDIA_TYPE, MapStringString mediaAttribute = {{MediaAttributeKey::MEDIA_TYPE,
MediaAttributeValue::VIDEO}, MediaAttributeValue::VIDEO},
{MediaAttributeKey::ENABLED, "true"}, {MediaAttributeKey::ENABLED, "true"},
{MediaAttributeKey::MUTED, "false"}, {MediaAttributeKey::MUTED,
{MediaAttributeKey::SOURCE, ""}, mute ? "true" : "false"},
{MediaAttributeKey::LABEL, "video_0"}}; {MediaAttributeKey::SOURCE_TYPE, srctype},
{MediaAttributeKey::SOURCE, resource},
{MediaAttributeKey::LABEL, mediaLabel}};
proposedList.push_back(mediaAttribute); proposedList.push_back(mediaAttribute);
// We should prepare it here for adding file and screen sharing
// for now it supports only adding main video to an audio only call
} }
CallManager::instance().requestMediaChange(callId, proposedList); CallManager::instance().requestMediaChange(callId, proposedList);
// If media existed and its mute state was changed here, then we should // If media existed and its mute state was changed here, then we should
// update the mediaList because we will not receive signal // update the mediaList because we will not receive signal
// mediaNegotiationStatus // mediaNegotiationStatus
if (found < callInfo->mediaList.size()) { if (found < callInfo->mediaList.size()) {
callInfo->mediaList[found][MediaAttributeKey::MUTED] callInfo->mediaList = proposedList;
= callInfo->mediaList[found][MediaAttributeKey::MUTED] == "true" ? "false" : "true";
if (mediaLabel.contains("audio_0")) { if (mediaLabel.contains("audio_0")) {
callInfo->audioMuted = !callInfo->audioMuted; callInfo->audioMuted = mute;
} else if (mediaLabel.contains("video_0")) { } else if (mediaLabel.contains("video_0")) {
callInfo->videoMuted = !callInfo->videoMuted; callInfo->videoMuted = mute;
} }
if (callInfo->status == call::Status::IN_PROGRESS) if (callInfo->status == call::Status::IN_PROGRESS)
emit callInfosChanged(owner.id, callId); emit callInfosChanged(owner.id, callId);
...@@ -516,7 +562,7 @@ NewCallModel::toggleMedia(const QString& callId, const NewCallModel::Media media ...@@ -516,7 +562,7 @@ NewCallModel::toggleMedia(const QString& callId, const NewCallModel::Media media
if (!hasCall(callId)) if (!hasCall(callId))
return; return;
auto mediaLabel = media == NewCallModel::Media::VIDEO ? "video_0" : "audio_0"; auto mediaLabel = media == NewCallModel::Media::VIDEO ? "video_0" : "audio_0";
requestMediaChange(callId, mediaLabel); requestMediaChange(callId, mediaLabel, "", MediaRequestType::CAMERA, true);
} }
void void
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment