Skip to content

Commit

Permalink
replace Peerconnection header by forward declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaldassi committed Nov 13, 2023
1 parent cfa1345 commit e978214
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ UMillicastPublisherComponent::UMillicastPublisherComponent(const FObjectInitiali
EventBroadcaster.Emplace("inactive", [this](TSharedPtr<FJsonObject> Msg) { ParseInactiveEvent(Msg); });
EventBroadcaster.Emplace("viewercount", [this](TSharedPtr<FJsonObject> Msg) { ParseViewerCountEvent(Msg); });

PeerConnectionConfig = Millicast::Publisher::FWebRTCPeerConnection::GetDefaultConfig();

PeerConnectionConfig =
MakeUnique<Millicast::Publisher::FWebRTCPeerConnectionConfig>(
Millicast::Publisher::FWebRTCPeerConnection::GetDefaultConfig());

MaximumBitrate = 4'000'000;
StartingBitrate = 2'000'000;
Expand Down Expand Up @@ -94,7 +97,7 @@ void UMillicastPublisherComponent::SetupIceServersFromJson(TArray<TSharedPtr<FJs
{
using namespace Millicast::Publisher;

PeerConnectionConfig.servers.clear();
(*PeerConnectionConfig)->servers.clear();
for (const auto& Server : IceServersField)
{
// Grab Ice Server Details
Expand Down Expand Up @@ -137,7 +140,7 @@ void UMillicastPublisherComponent::SetupIceServersFromJson(TArray<TSharedPtr<FJs
}
}

PeerConnectionConfig.servers.push_back(IceServer);
(*PeerConnectionConfig)->servers.push_back(IceServer);
}
}

Expand Down Expand Up @@ -372,7 +375,7 @@ bool UMillicastPublisherComponent::PublishToMillicast()

using namespace Millicast::Publisher;

PeerConnection.Reset(FWebRTCPeerConnection::Create(PeerConnectionConfig));
PeerConnection.Reset(FWebRTCPeerConnection::Create(*(*PeerConnectionConfig)));

// Starts the capture first and add track to the peerconnection
// TODO: add a boolean to let choose autoplay or not
Expand Down
19 changes: 19 additions & 0 deletions Source/MillicastPublisher/Private/WebRTC/PeerConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,25 @@ class TaskQueueFactory;

namespace Millicast::Publisher
{
class FWebRTCPeerConnectionConfig
{
public:
webrtc::PeerConnectionInterface::RTCConfiguration Config;

explicit FWebRTCPeerConnectionConfig(const webrtc::PeerConnectionInterface::RTCConfiguration& Other)
: Config(Other) {}

webrtc::PeerConnectionInterface::RTCConfiguration* operator->()
{
return &Config;
}

webrtc::PeerConnectionInterface::RTCConfiguration& operator*()
{
return Config;
}
};

/*
* Small wrapper for the WebRTC peerconnection
*/
Expand Down
10 changes: 8 additions & 2 deletions Source/MillicastPublisher/Public/MillicastPublisherComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "RtcCodecsConstants.h"

#include "Components/ActorComponent.h"
#include "WebRTC/PeerConnection.h"
// #include "WebRTC/PeerConnection.h"

#include "MillicastPublisherComponent.generated.h"

Expand All @@ -20,6 +20,12 @@ namespace webrtc
struct RtpTransceiverInit;
}

namespace Millicast::Publisher
{
class FWebRTCPeerConnection;
class FWebRTCPeerConnectionConfig;
}

enum class EMillicastPublisherState : uint8
{
Disconnected,
Expand Down Expand Up @@ -257,7 +263,7 @@ class MILLICASTPUBLISHER_API UMillicastPublisherComponent : public UActorCompone

/** WebRTC */
TUniquePtr<Millicast::Publisher::FWebRTCPeerConnection> PeerConnection;
webrtc::PeerConnectionInterface::RTCConfiguration PeerConnectionConfig;
TUniquePtr<Millicast::Publisher::FWebRTCPeerConnectionConfig> PeerConnectionConfig;

/** Publisher */
TAtomic<EMillicastPublisherState> State = EMillicastPublisherState::Disconnected;
Expand Down

0 comments on commit e978214

Please sign in to comment.