Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #402 from DolbyIO/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Kuba Audykowicz authored Sep 12, 2023
2 parents b845cb8 + 2ba62ec commit bf95173
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 89 deletions.
32 changes: 22 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ env:
CPP_SDK_URL: "https://github.com/DolbyIO/comms-sdk-cpp/releases/download"
PLUGIN_SOURCE_DIR: "DolbyIO"
PLUGIN_BUILD_DIR: "Build/DolbyIO"
BUILD_ARGS_COMMON: "BuildPlugin -Rocket -StrictIncludes -Plugin=\"$(pwd)/DolbyIO/DolbyIO.uplugin\" -Package=\"$(pwd)/Build/DolbyIO\""
GH_TOKEN: ${{ github.token }}
RETENTION: 7

Expand Down Expand Up @@ -41,10 +42,17 @@ jobs:

- name: Build plugin
env:
BUILD_ARGS: "BuildPlugin -Rocket -StrictIncludes -Plugin=\"$(pwd)\\DolbyIO\\DolbyIO.uplugin\" -Package=\"$(pwd)\\Build\\DolbyIO\" -TargetPlatforms=Win64 -VS2019"
BUILD_COMMAND: "C:/Program` Files/Epic` Games/UE_${{ matrix.version }}/Engine/Build/BatchFiles/RunUAT.bat"
BUILD_ARGS_PLATFORM: "-TargetPlatforms=Win64"
run: |
$UAT = "C:\\Program Files\\Epic Games\\UE_${{ matrix.version }}\\Engine\\Build\\BatchFiles\\RunUAT.bat"
& $UAT ${{ env.BUILD_ARGS }}
if (${{ matrix.version }} -eq "4.27")
{
${{ env.BUILD_COMMAND }} ${{ env.BUILD_ARGS_COMMON }} ${{ env.BUILD_ARGS_PLATFORM }} -VS2019
}
else
{
${{ env.BUILD_COMMAND }} ${{ env.BUILD_ARGS_COMMON }} ${{ env.BUILD_ARGS_PLATFORM }}
}
- name: Sign plugin
env:
Expand Down Expand Up @@ -100,9 +108,10 @@ jobs:
- name: Build plugin
env:
BUILD_ARGS: "BuildPlugin -Rocket -StrictIncludes -Plugin=\"$(pwd)/DolbyIO/DolbyIO.uplugin\" -Package=$(pwd)/Build/DolbyIO -TargetPlatforms=Mac -Architecture_Mac=x64+arm64"
BUILD_COMMAND: "/Users/Shared/Epic\\ Games/UE_${{ matrix.version }}/Engine/Build/BatchFiles/RunUAT.sh"
BUILD_ARGS_PLATFORM: "-TargetPlatforms=Mac -Architecture_Mac=x64+arm64"
run: |
/Users/Shared/Epic\ Games/UE_${{ matrix.version }}/Engine/Build/BatchFiles/RunUAT.sh ${{ env.BUILD_ARGS }}
${{ env.BUILD_COMMAND }} ${{ env.BUILD_ARGS_COMMON }} ${{ env.BUILD_ARGS_PLATFORM }}
- name: Sign plugin
env:
Expand Down Expand Up @@ -170,15 +179,18 @@ jobs:
- name: Build plugin
env:
BUILD_ARGS: "BuildPlugin -Rocket -StrictIncludes -Plugin=\"$(pwd)\\DolbyIO\\DolbyIO.uplugin\" -Package=\"$(pwd)\\Build\\DolbyIO\" -TargetPlatforms=Linux -NoHostPlatform"
BUILD_COMMAND: "C:/Program` Files/Epic` Games/UE_${{ matrix.version }}/Engine/Build/BatchFiles/RunUAT.bat"
BUILD_ARGS_PLATFORM: "-TargetPlatforms=Linux -NoHostPlatform"
run: |
if(${{ matrix.version }} -eq "4.27"){
if (${{ matrix.version }} -eq "4.27")
{
$env:LINUX_MULTIARCH_ROOT="C:\\UnrealToolchains\\v19_clang-11.0.1-centos7"
} else {
}
else
{
$env:LINUX_MULTIARCH_ROOT="C:\\UnrealToolchains\\v21_clang-15.0.1-centos7"
}
$UAT = "C:\\Program Files\\Epic Games\\UE_${{ matrix.version }}\\Engine\\Build\\BatchFiles\\RunUAT.bat"
& $UAT ${{ env.BUILD_ARGS }}
${{ env.BUILD_COMMAND }} ${{ env.BUILD_ARGS_COMMON }} ${{ env.BUILD_ARGS_PLATFORM }}
- name: Zip plugin
working-directory: ${{ env.PLUGIN_BUILD_DIR }}
Expand Down
Binary file modified DolbyIO/Content/BP_DolbyIOStarter.uasset
Binary file not shown.
2 changes: 1 addition & 1 deletion DolbyIO/Source/DolbyIO.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class DolbyIO : ModuleRules
{
public DolbyIO(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

CppStandard = CppStandardVersion.Cpp17;
bEnableExceptions = true;
Expand Down
15 changes: 10 additions & 5 deletions DolbyIO/Source/Private/Subsystem/DolbyIOInitialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ void UDolbyIOSubsystem::Initialize(FSubsystemCollectionBase& Collection)

ConferenceStatus = conference_status::destroyed;

VideoSinks.Emplace(LocalCameraTrackID, std::make_shared<FVideoSink>(LocalCameraTrackID));
VideoSinks.Emplace(LocalScreenshareTrackID, std::make_shared<FVideoSink>(LocalScreenshareTrackID));
LocalCameraFrameHandler = std::make_shared<FVideoFrameHandler>(VideoSinks[LocalCameraTrackID]);
LocalScreenshareFrameHandler = std::make_shared<FVideoFrameHandler>(VideoSinks[LocalScreenshareTrackID]);
{
FScopeLock Lock{&VideoSinksLock};
VideoSinks.Emplace(LocalCameraTrackID, std::make_shared<FVideoSink>(LocalCameraTrackID));
VideoSinks.Emplace(LocalScreenshareTrackID, std::make_shared<FVideoSink>(LocalScreenshareTrackID));
LocalCameraFrameHandler = std::make_shared<FVideoFrameHandler>(VideoSinks[LocalCameraTrackID]);
LocalScreenshareFrameHandler = std::make_shared<FVideoFrameHandler>(VideoSinks[LocalScreenshareTrackID]);
}

FTimerManager& TimerManager = GetGameInstance()->GetTimerManager();
TimerManager.SetTimer(LocationTimerHandle, this, &UDolbyIOSubsystem::SetLocationUsingFirstPlayer, 0.1, true);
Expand All @@ -42,6 +45,8 @@ void UDolbyIOSubsystem::Initialize(FSubsystemCollectionBase& Collection)
void UDolbyIOSubsystem::Deinitialize()
{
DLB_UE_LOG("Deinitializing");

FScopeLock Lock{&VideoSinksLock};
for (auto& Sink : VideoSinks)
{
Sink.Value->Disable(); // ignore new frames now on
Expand Down Expand Up @@ -121,7 +126,7 @@ void UDolbyIOSubsystem::SetToken(const FString& Token)
{
DLB_ERROR_HANDLER(OnSetTokenError).HandleError();
}
RefreshTokenCb.Reset(); // RefreshToken callback can be called only once
RefreshTokenCb.Reset(); // RefreshToken callback can only be called once
}
}

Expand Down
65 changes: 46 additions & 19 deletions DolbyIO/Source/Private/Subsystem/DolbyIOVideoTracks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ using namespace DolbyIO;

void UDolbyIOSubsystem::BindMaterial(UMaterialInstanceDynamic* Material, const FString& VideoTrackID)
{
FScopeLock Lock{&VideoSinksLock};
for (auto& Sink : VideoSinks)
{
if (Sink.Key != VideoTrackID)
Expand All @@ -29,6 +30,7 @@ void UDolbyIOSubsystem::BindMaterial(UMaterialInstanceDynamic* Material, const F

void UDolbyIOSubsystem::UnbindMaterial(UMaterialInstanceDynamic* Material, const FString& VideoTrackID)
{
FScopeLock Lock{&VideoSinksLock};
if (const std::shared_ptr<DolbyIO::FVideoSink>* Sink = VideoSinks.Find(VideoTrackID))
{
(*Sink)->UnbindMaterial(Material);
Expand All @@ -37,6 +39,7 @@ void UDolbyIOSubsystem::UnbindMaterial(UMaterialInstanceDynamic* Material, const

UTexture2D* UDolbyIOSubsystem::GetTexture(const FString& VideoTrackID)
{
FScopeLock Lock{&VideoSinksLock};
if (const std::shared_ptr<FVideoSink>* Sink = VideoSinks.Find(VideoTrackID))
{
return (*Sink)->GetTexture();
Expand All @@ -47,9 +50,18 @@ UTexture2D* UDolbyIOSubsystem::GetTexture(const FString& VideoTrackID)
void UDolbyIOSubsystem::BroadcastVideoTrackAdded(const FDolbyIOVideoTrack& VideoTrack)
{
DLB_UE_LOG("Video track added: TrackID=%s ParticipantID=%s", *VideoTrack.TrackID, *VideoTrack.ParticipantID);
WarnIfVideoTrackSuspicious(VideoTrack.TrackID);
BroadcastEvent(OnVideoTrackAdded, VideoTrack);
}

void UDolbyIOSubsystem::WarnIfVideoTrackSuspicious(const FString& VideoTrackID)
{
if (VideoTrackID == "{-}")
{
DLB_UE_LOG_BASE(Warning, "Suspicious video track ID added, things may not work as expected");
}
}

void UDolbyIOSubsystem::BroadcastVideoTrackEnabled(const FDolbyIOVideoTrack& VideoTrack)
{
DLB_UE_LOG("Video track enabled: TrackID=%s ParticipantID=%s", *VideoTrack.TrackID, *VideoTrack.ParticipantID);
Expand All @@ -60,31 +72,35 @@ void UDolbyIOSubsystem::ProcessBufferedVideoTracks(const FString& ParticipantID)
{
if (TArray<FDolbyIOVideoTrack>* AddedTracks = BufferedAddedVideoTracks.Find(ParticipantID))
{
FScopeLock Lock{&VideoSinksLock};
for (const FDolbyIOVideoTrack& AddedTrack : *AddedTracks)
{
VideoSinks[AddedTrack.TrackID]->OnTextureCreated(
[=]
{
BroadcastVideoTrackAdded(AddedTrack);

if (TArray<FDolbyIOVideoTrack>* EnabledTracks = BufferedEnabledVideoTracks.Find(ParticipantID))
if (std::shared_ptr<DolbyIO::FVideoSink>* Sink = VideoSinks.Find(AddedTrack.TrackID))
{
(*Sink)->OnTextureCreated(
[=]
{
TArray<FDolbyIOVideoTrack>& EnabledTracksRef = *EnabledTracks;
for (int i = 0; i < EnabledTracksRef.Num(); ++i)
BroadcastVideoTrackAdded(AddedTrack);

if (TArray<FDolbyIOVideoTrack>* EnabledTracks = BufferedEnabledVideoTracks.Find(ParticipantID))
{
if (EnabledTracksRef[i].TrackID == AddedTrack.TrackID)
TArray<FDolbyIOVideoTrack>& EnabledTracksRef = *EnabledTracks;
for (int i = 0; i < EnabledTracksRef.Num(); ++i)
{
BroadcastVideoTrackEnabled(EnabledTracksRef[i]);
EnabledTracksRef.RemoveAt(i);
if (!EnabledTracksRef.Num())
if (EnabledTracksRef[i].TrackID == AddedTrack.TrackID)
{
BufferedEnabledVideoTracks.Remove(ParticipantID);
BroadcastVideoTrackEnabled(EnabledTracksRef[i]);
EnabledTracksRef.RemoveAt(i);
if (!EnabledTracksRef.Num())
{
BufferedEnabledVideoTracks.Remove(ParticipantID);
}
return;
}
return;
}
}
}
});
});
}
}
BufferedAddedVideoTracks.Remove(ParticipantID);
}
Expand All @@ -94,13 +110,14 @@ void UDolbyIOSubsystem::Handle(const remote_video_track_added& Event)
{
const FDolbyIOVideoTrack VideoTrack = ToFDolbyIOVideoTrack(Event.track);

FScopeLock Lock1{&VideoSinksLock};
VideoSinks.Emplace(VideoTrack.TrackID, std::make_shared<FVideoSink>(VideoTrack.TrackID));
Sdk->video()
.remote()
.set_video_sink(Event.track, VideoSinks[VideoTrack.TrackID])
.on_error(DLB_ERROR_HANDLER_NO_DELEGATE);

FScopeLock Lock{&RemoteParticipantsLock};
FScopeLock Lock2{&RemoteParticipantsLock};
if (RemoteParticipants.Contains(VideoTrack.ParticipantID))
{
VideoSinks[VideoTrack.TrackID]->OnTextureCreated([this, VideoTrack] { BroadcastVideoTrackAdded(VideoTrack); });
Expand All @@ -117,9 +134,19 @@ void UDolbyIOSubsystem::Handle(const remote_video_track_removed& Event)
{
const FDolbyIOVideoTrack VideoTrack = ToFDolbyIOVideoTrack(Event.track);
DLB_UE_LOG("Video track removed: TrackID=%s ParticipantID=%s", *VideoTrack.TrackID, *VideoTrack.ParticipantID);
WarnIfVideoTrackSuspicious(VideoTrack.TrackID);

FScopeLock Lock{&VideoSinksLock};
if (std::shared_ptr<DolbyIO::FVideoSink>* Sink = VideoSinks.Find(VideoTrack.TrackID))
{
(*Sink)->UnbindAllMaterials();
VideoSinks.Remove(VideoTrack.TrackID);
}
else
{
DLB_UE_LOG_BASE(Warning, "Non-existent video track removed");
}

VideoSinks[VideoTrack.TrackID]->UnbindAllMaterials();
VideoSinks.Remove(VideoTrack.TrackID);
BroadcastEvent(OnVideoTrackRemoved, VideoTrack);
}

Expand Down
Loading

0 comments on commit bf95173

Please sign in to comment.