From 0f6ffcacc1616dcd9340dec8c89226f5aac4dfb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Sat, 1 Jun 2019 19:13:05 -0400 Subject: [PATCH] dring/call: send video codec to client Change-Id: I919aa2607b1d0dcc33b7b02f90b97b1b8fd1ef98 --- src/call.h | 7 +++++-- src/client/configurationmanager.cpp | 2 +- src/dring/call_const.h | 2 ++ src/media/audio/audio_sender.cpp | 2 +- src/media/media_encoder.cpp | 18 ------------------ src/media/media_encoder.h | 4 ++-- src/media/rtp_session.h | 2 ++ src/media/video/video_rtp_session.cpp | 7 ------- src/media/video/video_rtp_session.h | 8 +------- src/media/video/video_sender.cpp | 8 +------- src/media/video/video_sender.h | 7 +------ src/sip/sipcall.cpp | 17 ++++++++++++----- src/sip/sipcall.h | 4 +++- 13 files changed, 31 insertions(+), 57 deletions(-) diff --git a/src/call.h b/src/call.h index 9f16a0bc4a..37d85eea52 100644 --- a/src/call.h +++ b/src/call.h @@ -298,8 +298,11 @@ class Call : public Recordable, public std::enable_shared_from_this<Call> { void onTextMessage(std::map<std::string, std::string>&& messages); - virtual bool useVideoCodec(const AccountVideoCodecInfo* /*codec*/) const { - return false; + virtual std::shared_ptr<AccountCodecInfo> getAudioCodec() const { + return {}; + } + virtual std::shared_ptr<AccountCodecInfo> getVideoCodec() const { + return {}; } virtual void restartMediaSender() = 0; diff --git a/src/client/configurationmanager.cpp b/src/client/configurationmanager.cpp index 12d6f3b330..559fa7c7ad 100644 --- a/src/client/configurationmanager.cpp +++ b/src/client/configurationmanager.cpp @@ -505,7 +505,7 @@ setCodecDetails(const std::string& accountID, JAMI_WARN("parameters for %s changed ", foundCodec->systemCodecInfo.name.c_str()); if (auto call = jami::Manager::instance().getCurrentCall()) { - if (call->useVideoCodec(foundCodec.get())) { + if (call->getVideoCodec() == foundCodec) { JAMI_WARN("%s running. Need to restart encoding", foundCodec->systemCodecInfo.name.c_str()); call->restartMediaSender(); diff --git a/src/dring/call_const.h b/src/dring/call_const.h index d2a7c4987b..e0e08fa348 100644 --- a/src/dring/call_const.h +++ b/src/dring/call_const.h @@ -58,6 +58,8 @@ constexpr static char AUDIO_MUTED [] = "AUDIO_MUTED" ; constexpr static char VIDEO_MUTED [] = "VIDEO_MUTED" ; constexpr static char VIDEO_SOURCE [] = "VIDEO_SOURCE" ; constexpr static char AUDIO_ONLY [] = "AUDIO_ONLY" ; +constexpr static char AUDIO_CODEC [] = "AUDIO_CODEC" ; +constexpr static char VIDEO_CODEC [] = "VIDEO_CODEC" ; } diff --git a/src/media/audio/audio_sender.cpp b/src/media/audio/audio_sender.cpp index ff0ff1f002..eb361640c5 100644 --- a/src/media/audio/audio_sender.cpp +++ b/src/media/audio/audio_sender.cpp @@ -83,7 +83,7 @@ AudioSender::setup(SocketPair& socketPair) return false; } - Smartools::getInstance().setLocalAudioCodec(audioEncoder_->getEncoderName()); + Smartools::getInstance().setLocalAudioCodec(audioEncoder_->getAudioCodec()); #ifdef DEBUG_SDP audioEncoder_->print_sdp(); diff --git a/src/media/media_encoder.cpp b/src/media/media_encoder.cpp index 8da58dae68..ca49952c97 100644 --- a/src/media/media_encoder.cpp +++ b/src/media/media_encoder.cpp @@ -134,15 +134,6 @@ MediaEncoder::getLastSeqValue() return 0; } -std::string -MediaEncoder::getEncoderName() const -{ - if (videoOpts_.isValid()) - return videoCodec_; - else - return audioCodec_; -} - void MediaEncoder::openOutput(const std::string& filename, const std::string& format) { @@ -700,15 +691,6 @@ MediaEncoder::extractProfileLevelID(const std::string ¶meters, JAMI_DBG("Using profile %x and level %d", ctx->profile, ctx->level); } -bool -MediaEncoder::useCodec(const jami::AccountCodecInfo* codec) const noexcept -{ - if (codec->systemCodecInfo.mediaType == MEDIA_VIDEO) - return videoCodec_ == codec->systemCodecInfo.name; - else - return audioCodec_ == codec->systemCodecInfo.name; -} - #ifdef RING_ACCEL void MediaEncoder::enableAccel(bool enableAccel) diff --git a/src/media/media_encoder.h b/src/media/media_encoder.h index 7cbc7f68c7..cb9f2f1c02 100644 --- a/src/media/media_encoder.h +++ b/src/media/media_encoder.h @@ -96,9 +96,9 @@ public: void setInitSeqVal(uint16_t seqVal); uint16_t getLastSeqValue(); - std::string getEncoderName() const; - bool useCodec(const AccountCodecInfo* codec) const noexcept; + const std::string& getAudioCodec() const { return audioCodec_; } + const std::string& getVideoCodec() const { return videoCodec_; } #ifdef RING_ACCEL void enableAccel(bool enableAccel); diff --git a/src/media/rtp_session.h b/src/media/rtp_session.h index 66f2d64af3..5cf24a5721 100644 --- a/src/media/rtp_session.h +++ b/src/media/rtp_session.h @@ -58,6 +58,8 @@ public: virtual void initRecorder(std::shared_ptr<MediaRecorder>& rec) = 0; virtual void deinitRecorder(std::shared_ptr<MediaRecorder>& rec) = 0; + std::shared_ptr<AccountCodecInfo> getCodec() const { return send_.codec; } + protected: std::recursive_mutex mutex_; std::unique_ptr<SocketPair> socketPair_; diff --git a/src/media/video/video_rtp_session.cpp b/src/media/video/video_rtp_session.cpp index 355f877e20..d0f362a9b2 100644 --- a/src/media/video/video_rtp_session.cpp +++ b/src/media/video/video_rtp_session.cpp @@ -336,13 +336,6 @@ void VideoRtpSession::exitConference() conference_ = nullptr; } -bool -VideoRtpSession::useCodec(const jami::AccountVideoCodecInfo* codec) const -{ - return sender_->useCodec(codec); -} - - float VideoRtpSession::checkPeerPacketLoss() { diff --git a/src/media/video/video_rtp_session.h b/src/media/video/video_rtp_session.h index b5a4310530..2e589331f7 100644 --- a/src/media/video/video_rtp_session.h +++ b/src/media/video/video_rtp_session.h @@ -19,8 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef __VIDEO_RTP_SESSION_H__ -#define __VIDEO_RTP_SESSION_H__ +#pragma once #include "media/rtp_session.h" #include "media/media_device.h" @@ -92,9 +91,6 @@ public: } void setChangeOrientationCallback(std::function<void(int)> cb); - - bool useCodec(const AccountVideoCodecInfo* codec) const; - void initRecorder(std::shared_ptr<MediaRecorder>& rec) override; void deinitRecorder(std::shared_ptr<MediaRecorder>& rec) override; @@ -158,5 +154,3 @@ private: }; }} // namespace jami::video - -#endif // __VIDEO_RTP_SESSION_H__ diff --git a/src/media/video/video_sender.cpp b/src/media/video/video_sender.cpp index 25fd9c9769..ef64ff8518 100644 --- a/src/media/video/video_sender.cpp +++ b/src/media/video/video_sender.cpp @@ -60,7 +60,7 @@ VideoSender::VideoSender(const std::string& dest, const DeviceParams& dev, videoEncoder_->setIOContext(muxContext_->getContext()); // Send local video codec in SmartInfo - Smartools::getInstance().setLocalVideoCodec(videoEncoder_->getEncoderName()); + Smartools::getInstance().setLocalVideoCodec(videoEncoder_->getVideoCodec()); // Send the resolution in smartInfo Smartools::getInstance().setResolution("local", dev.width, dev.height); @@ -135,12 +135,6 @@ VideoSender::getLastSeqValue() return videoEncoder_->getLastSeqValue(); } -bool -VideoSender::useCodec(const jami::AccountVideoCodecInfo* codec) const -{ - return videoEncoder_->useCodec(codec); -} - void VideoSender::setChangeOrientationCallback(std::function<void(int)> cb) { diff --git a/src/media/video/video_sender.h b/src/media/video/video_sender.h index e54fe4231a..2b86ad8f30 100644 --- a/src/media/video/video_sender.h +++ b/src/media/video/video_sender.h @@ -19,8 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef __VIDEO_SENDER_H__ -#define __VIDEO_SENDER_H__ +#pragma once #include "noncopyable.h" #include "media_encoder.h" @@ -60,8 +59,6 @@ public: uint16_t getLastSeqValue(); - bool useCodec(const AccountVideoCodecInfo* codec) const; - void setChangeOrientationCallback(std::function<void(int)> cb); private: @@ -85,5 +82,3 @@ private: std::function<void(int)> changeOrientationCallback_; }; }} // namespace jami::video - -#endif // __VIDEO_SENDER_H__ diff --git a/src/sip/sipcall.cpp b/src/sip/sipcall.cpp index 30467d0205..d719ae44e0 100644 --- a/src/sip/sipcall.cpp +++ b/src/sip/sipcall.cpp @@ -873,14 +873,19 @@ SIPCall::getAllRemoteCandidates() return rem_candidates; } -bool -SIPCall::useVideoCodec(const AccountVideoCodecInfo* codec) const +std::shared_ptr<AccountCodecInfo> +SIPCall::getVideoCodec() const { #ifdef ENABLE_VIDEO - if (videortp_->isSending()) - return videortp_->useCodec(codec); + return videortp_->getCodec(); #endif - return false; + return {}; +} + +std::shared_ptr<AccountCodecInfo> +SIPCall::getAudioCodec() const +{ + return avformatrtp_->getCodec(); } void @@ -1210,6 +1215,8 @@ SIPCall::getDetails() const #ifdef ENABLE_VIDEO // If Video is not enabled return an empty string details.emplace(DRing::Call::Details::VIDEO_SOURCE, acc.isVideoEnabled() ? mediaInput_ : ""); + if (auto codec = videortp_->getCodec()) + details.emplace(DRing::Call::Details::VIDEO_CODEC, codec->systemCodecInfo.name); #endif #if HAVE_RINGNS diff --git a/src/sip/sipcall.h b/src/sip/sipcall.h index 39df1f8fb1..aebb254b40 100644 --- a/src/sip/sipcall.h +++ b/src/sip/sipcall.h @@ -109,7 +109,9 @@ public: // overridden void removeCall() override; void muteMedia(const std::string& mediaType, bool isMuted) override; void restartMediaSender() override; - bool useVideoCodec(const AccountVideoCodecInfo* codec) const override; + std::shared_ptr<AccountCodecInfo> getAudioCodec() const override; + std::shared_ptr<AccountCodecInfo> getVideoCodec() const override; + void sendKeyframe() override; std::map<std::string, std::string> getDetails() const override; -- GitLab