From 9b1c82edc4f3d022df3630042b9a212f48c507f5 Mon Sep 17 00:00:00 2001 From: marian Date: Tue, 24 Mar 2009 16:40:00 +0000 Subject: [PATCH] The client channel can now be (un)muted (set/reset data source only). git-svn-id: http://yate.null.ro/svn/yate/trunk@2538 acf43c95-373e-0410-b603-e72c3f656dc1 --- engine/Client.cpp | 35 ++++++++++++++++++++++++++++++----- yatecbase.h | 17 +++++++++++++++++ 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/engine/Client.cpp b/engine/Client.cpp index b7194a95..64907b43 100644 --- a/engine/Client.cpp +++ b/engine/Client.cpp @@ -2361,7 +2361,7 @@ ClientChannel::ClientChannel(const Message& msg, const String& peerid) : Channel(ClientDriver::self(),0,true), m_party(msg.getValue("caller")), m_noticed(false), m_line(0), m_active(false), m_silence(false), m_conference(false), - m_clientData(0), m_utility(false) + m_muted(false), m_clientData(0), m_utility(false) { Debug(this,DebugCall,"Created incoming from=%s peer=%s [%p]", m_party.c_str(),peerid.c_str(),this); @@ -2382,7 +2382,8 @@ ClientChannel::ClientChannel(const Message& msg, const String& peerid) ClientChannel::ClientChannel(const String& target, const NamedList& params) : Channel(ClientDriver::self(),0,false), m_party(target), m_noticed(true), m_line(0), m_active(false), - m_silence(true), m_conference(false), m_clientData(0), m_utility(false) + m_silence(true), m_conference(false), m_muted(false), m_clientData(0), + m_utility(false) { Debug(this,DebugCall,"Created outgoing to=%s [%p]", m_party.c_str(),this); @@ -2544,15 +2545,16 @@ bool ClientChannel::setMedia(bool open, bool replace) complete(m,true); m.userData(this); m.setParam("consumer",dev); - m.setParam("source",dev); + if (!m_muted) + m.setParam("source",dev); Engine::dispatch(m); if (getConsumer()) checkSilence(); else Debug(this,DebugNote,"Failed to set data consumer [%p]",this); - if (!getSource()) + if (!(getSource() || m_muted)) Debug(this,DebugNote,"Failed to set data source [%p]",this); - bool ok = (getSource() && getConsumer()); + bool ok = ((m_muted || getSource()) && getConsumer()); if (!ok && Client::self()) { String tmp = "Failed to open media channel(s)"; Client::self()->setStatusLocked(tmp); @@ -2570,6 +2572,9 @@ bool ClientChannel::setActive(bool active, bool upd) noticed(); if (active && m_transferId && !m_conference) return false; + // Reset data source to make sure we remove any MOH + if (active) + setSource(); if (isAnswered()) setMedia(active); // Don't notify if nothing changed @@ -2584,6 +2589,26 @@ bool ClientChannel::setActive(bool active, bool upd) return true; } +// Set/reset this channel's muted flag. Set media if on +bool ClientChannel::setMuted(bool on, bool upd) +{ + Lock lock(m_mutex); + if (m_muted == on) + return true; + + Debug(this,DebugInfo,"Set muted=%s [%p]",String::boolText(on),this); + m_muted = on; + if (m_active) { + if (m_muted) + setSource(); + else + setMedia(true); + } + if (upd) + update(Mute); + return true; +} + // Set/reset the transferred peer's id. Enqueue clientchan.update if changed void ClientChannel::setTransfer(const String& target) { diff --git a/yatecbase.h b/yatecbase.h index 73e7a16b..bc191286 100644 --- a/yatecbase.h +++ b/yatecbase.h @@ -1399,6 +1399,7 @@ public: Destroyed, Active, OnHold, + Mute, Noticed, AddrChanged, Routed, @@ -1502,6 +1503,14 @@ public: */ bool setActive(bool active, bool update = true); + /** + * Set/reset this channel's muted flag. Set media if 'on' is false and the channel is active + * @param on True to reset outgoing media, false to set outgoing media + * @param update True to enqueue an update message + * @return True on success + */ + bool setMuted(bool on, bool update = true); + /** * Set/reset the transferred peer's id. Enqueue clientchan.update if changed. * Open media when reset if the channel is active and answered @@ -1537,6 +1546,13 @@ public: inline bool active() const { return m_active; } + /** + * Check if this channel is muted + * @return True if this channel is muted + */ + inline bool muted() const + { return m_muted; } + /** * Check if this channel was noticed * @return True if this channel was noticed @@ -1624,6 +1640,7 @@ protected: bool m_active; // Channel active flag bool m_silence; // True if the peer did't sent us any audio data bool m_conference; // True if this channel is in conference + bool m_muted; // True if this channel is muted (no data source)) String m_transferId; // Transferred id or empty if not transferred RefObject* m_clientData; // Obscure data used by client logics bool m_utility; // Regular client channel flag