summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
authorRoxie Linden <roxie@lindenlab.com>2023-09-19 10:14:29 -0700
committerRoxie Linden <roxie@lindenlab.com>2024-02-08 18:34:01 -0800
commitfd8119c550bea19bbcf26e5426f259010f54c43e (patch)
tree1a7e9fb0c7fa67a5ff7f16831cbffef86ec5ae24 /indra
parent976a75ed24f11e3211a98120b1ac57126e625d6c (diff)
add datachannel support
Diffstat (limited to 'indra')
-rw-r--r--indra/llwebrtc/llwebrtc.cpp50
-rw-r--r--indra/llwebrtc/llwebrtc.h16
-rw-r--r--indra/llwebrtc/llwebrtc_impl.h20
-rw-r--r--indra/newview/llvoicewebrtc.cpp9
-rw-r--r--indra/newview/llvoicewebrtc.h13
5 files changed, 104 insertions, 4 deletions
diff --git a/indra/llwebrtc/llwebrtc.cpp b/indra/llwebrtc/llwebrtc.cpp
index 96be2c1f0b..ac5870eab3 100644
--- a/indra/llwebrtc/llwebrtc.cpp
+++ b/indra/llwebrtc/llwebrtc.cpp
@@ -314,7 +314,22 @@ bool LLWebRTCImpl::initializeConnectionThreaded()
RTC_LOG(LS_INFO) << __FUNCTION__ << " " << mPeerConnection->signaling_state();
- return mPeerConnection != nullptr;
+ webrtc::DataChannelInit init;
+ init.ordered = true;
+ init.reliable = true;
+ auto data_channel_or_error = mPeerConnection->CreateDataChannelOrError("SLData", &init);
+ if (data_channel_or_error.ok())
+ {
+ mDataChannel = std::move(data_channel_or_error.value());
+ }
+ else
+ {
+ shutdownConnection();
+ return false;
+ }
+ mDataChannel->RegisterObserver(this);
+
+ return true;
}
void LLWebRTCImpl::shutdownConnection()
@@ -574,9 +589,42 @@ void LLWebRTCImpl::OnSetLocalDescriptionComplete(webrtc::RTCError error)
}
}
+//
+// DataChannelObserver implementation
+//
+void LLWebRTCImpl::OnMessage(const webrtc::DataBuffer& buffer)
+{
+ std::string data((const char*)buffer.data.cdata(), buffer.size());
+ for (auto &observer : mDataObserverList)
+ {
+ observer->OnDataReceived(data, buffer.binary);
+ }
+}
+
+void LLWebRTCImpl::sendData(const std::string& data, bool binary)
+{
+ rtc::CopyOnWriteBuffer cowBuffer(data.data(), data.length());
+ webrtc::DataBuffer buffer(cowBuffer, binary);
+ mDataChannel->Send(buffer);
+}
+
+void LLWebRTCImpl::setDataObserver(LLWebRTCDataObserver* observer) { mDataObserverList.emplace_back(observer); }
+
+void LLWebRTCImpl::unsetDataObserver(LLWebRTCDataObserver* observer)
+{
+ std::vector<LLWebRTCDataObserver *>::iterator it =
+ std::find(mDataObserverList.begin(), mDataObserverList.end(), observer);
+ if (it != mDataObserverList.end())
+ {
+ mDataObserverList.erase(it);
+ }
+}
+
rtc::RefCountedObject<LLWebRTCImpl> *gWebRTCImpl = nullptr;
LLWebRTCDeviceInterface *getDeviceInterface() { return gWebRTCImpl; }
LLWebRTCSignalInterface *getSignalingInterface() { return gWebRTCImpl; }
+LLWebRTCDataInterface *getDataInterface() { return gWebRTCImpl; }
+
void init()
{
diff --git a/indra/llwebrtc/llwebrtc.h b/indra/llwebrtc/llwebrtc.h
index ca558add01..a6e754684e 100644
--- a/indra/llwebrtc/llwebrtc.h
+++ b/indra/llwebrtc/llwebrtc.h
@@ -96,6 +96,21 @@ class LLWebRTCAudioInterface
virtual void setSpeakerVolume(float volume) = 0; // volume between 0.0 and 1.0
};
+class LLWebRTCDataObserver
+{
+public:
+ virtual void OnDataReceived(const std::string& data, bool binary) = 0;
+};
+
+class LLWebRTCDataInterface
+{
+public:
+ virtual void sendData(const std::string& data, bool binary=false) = 0;
+
+ virtual void setDataObserver(LLWebRTCDataObserver *observer) = 0;
+ virtual void unsetDataObserver(LLWebRTCDataObserver *observer) = 0;
+};
+
class LLWebRTCSignalingObserver
{
public:
@@ -124,6 +139,7 @@ class LLWebRTCSignalInterface
LLSYMEXPORT LLWebRTCDeviceInterface* getDeviceInterface();
LLSYMEXPORT LLWebRTCSignalInterface* getSignalingInterface();
+LLSYMEXPORT LLWebRTCDataInterface* getDataInterface();
}
#endif // LLWEBRTC_H
diff --git a/indra/llwebrtc/llwebrtc_impl.h b/indra/llwebrtc/llwebrtc_impl.h
index 3f9b06cae7..1ad117c7f3 100644
--- a/indra/llwebrtc/llwebrtc_impl.h
+++ b/indra/llwebrtc/llwebrtc_impl.h
@@ -66,11 +66,13 @@ namespace llwebrtc
class LLWebRTCImpl : public LLWebRTCDeviceInterface,
public LLWebRTCSignalInterface,
public LLWebRTCAudioInterface,
+ public LLWebRTCDataInterface,
public webrtc::AudioDeviceDataObserver,
public webrtc::PeerConnectionObserver,
public webrtc::CreateSessionDescriptionObserver,
public webrtc::SetRemoteDescriptionObserverInterface,
- public webrtc::SetLocalDescriptionObserverInterface
+ public webrtc::SetLocalDescriptionObserverInterface,
+ public webrtc::DataChannelObserver
{
public:
@@ -126,6 +128,13 @@ class LLWebRTCImpl : public LLWebRTCDeviceInterface,
//
void setMute(bool mute) override;
void setSpeakerVolume(float folume) override; // range 0.0-1.0
+
+ //
+ // LLWebRTCDataInterface
+ //
+ void sendData(const std::string& data, bool binary=false) override;
+ void setDataObserver(LLWebRTCDataObserver *observer) override;
+ void unsetDataObserver(LLWebRTCDataObserver *observer) override;
//
// PeerConnectionObserver implementation.
@@ -158,6 +167,12 @@ class LLWebRTCImpl : public LLWebRTCDeviceInterface,
// SetLocalDescriptionObserverInterface implementation.
//
void OnSetLocalDescriptionComplete(webrtc::RTCError error) override;
+
+ //
+ // DataChannelObserver implementation.
+ //
+ void OnStateChange() override {}
+ void OnMessage(const webrtc::DataBuffer& buffer) override;
protected:
@@ -184,6 +199,9 @@ class LLWebRTCImpl : public LLWebRTCDeviceInterface,
bool mAnswerReceived;
rtc::scoped_refptr<webrtc::PeerConnectionInterface> mPeerConnection;
+
+ std::vector<LLWebRTCDataObserver *> mDataObserverList;
+ rtc::scoped_refptr<webrtc::DataChannelInterface> mDataChannel;
};
}
diff --git a/indra/newview/llvoicewebrtc.cpp b/indra/newview/llvoicewebrtc.cpp
index 66bed5f0b5..9013de67f5 100644
--- a/indra/newview/llvoicewebrtc.cpp
+++ b/indra/newview/llvoicewebrtc.cpp
@@ -361,6 +361,9 @@ void LLWebRTCVoiceClient::init(LLPumpIO *pump)
mWebRTCSignalingInterface = llwebrtc::getSignalingInterface();
mWebRTCSignalingInterface->setSignalingObserver(this);
+
+ mWebRTCDataInterface = llwebrtc::getDataInterface();
+ mWebRTCDataInterface->setDataObserver(this);
}
void LLWebRTCVoiceClient::terminate()
@@ -2707,6 +2710,12 @@ void LLWebRTCVoiceClient::OnAudioEstablished(llwebrtc::LLWebRTCAudioInterface *
setVoiceControlStateUnless(VOICE_STATE_SESSION_ESTABLISHED, VOICE_STATE_SESSION_RETRY);
}
+void LLWebRTCVoiceClient::OnDataReceived(const std::string& data, bool binary)
+{
+
+}
+
+
void LLWebRTCVoiceClient::OnRenegotiationNeeded()
{
LL_INFOS("Voice") << "On Renegotiation Needed." << LL_ENDL;
diff --git a/indra/newview/llvoicewebrtc.h b/indra/newview/llvoicewebrtc.h
index eb3893fe2b..0d6988e1ef 100644
--- a/indra/newview/llvoicewebrtc.h
+++ b/indra/newview/llvoicewebrtc.h
@@ -59,7 +59,8 @@ class LLWebRTCVoiceClient : public LLSingleton<LLWebRTCVoiceClient>,
virtual public LLVoiceModuleInterface,
virtual public LLVoiceEffectInterface,
public llwebrtc::LLWebRTCDevicesObserver,
- public llwebrtc::LLWebRTCSignalingObserver
+ public llwebrtc::LLWebRTCSignalingObserver,
+ public llwebrtc::LLWebRTCDataObserver
{
LLSINGLETON_C11(LLWebRTCVoiceClient);
LOG_CLASS(LLWebRTCVoiceClient);
@@ -255,6 +256,13 @@ public:
void OnRenegotiationNeeded() override;
void OnAudioEstablished(llwebrtc::LLWebRTCAudioInterface *audio_interface) override;
//@}
+
+ /////////////////////////
+ /// @name Data Notification
+ /// LLWebRTCDataObserver
+ //@{
+ void OnDataReceived(const std::string& data, bool binary) override;
+ //@}
void processIceUpdates();
void onIceUpdateComplete(const LLSD& result);
@@ -761,7 +769,8 @@ private:
llwebrtc::LLWebRTCDeviceInterface *mWebRTCDeviceInterface;
llwebrtc::LLWebRTCSignalInterface *mWebRTCSignalingInterface;
- llwebrtc::LLWebRTCAudioInterface *mWebRTCAudioInterface;
+ llwebrtc::LLWebRTCAudioInterface *mWebRTCAudioInterface;
+ llwebrtc::LLWebRTCDataInterface *mWebRTCDataInterface;
LLVoiceDeviceList mCaptureDevices;
LLVoiceDeviceList mRenderDevices;