Skip to content

Commit

Permalink
fix bugs #3.
Browse files Browse the repository at this point in the history
  • Loading branch information
hecomi committed Oct 28, 2021
1 parent 59eed08 commit d639257
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ sysinfo.txt
.vs
**/*.h264
*.log
.vsconfig

5 changes: 3 additions & 2 deletions Assets/uNvEncoder/Scripts/Encoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Encoder
[System.Serializable]
public class EncodedCallback : UnityEvent<System.IntPtr, int> {};
public EncodedCallback onEncoded = new EncodedCallback();
public bool outputError = false;

public int id { get; private set; } = -1;

Expand Down Expand Up @@ -99,7 +100,7 @@ public bool Encode(Texture texture, bool forceIdrFrame)
if (!Encode(ptr, forceIdrFrame))
{
var msg = error;
if (!string.IsNullOrEmpty(msg))
if (outputError && !string.IsNullOrEmpty(msg))
{
Debug.LogError(msg);
}
Expand All @@ -124,7 +125,7 @@ public bool Encode(System.IntPtr ptr, bool forceIdrFrame)
}

var result = Lib.Encode(id, ptr, forceIdrFrame);
if (!result)
if (outputError && !result)
{
Debug.LogError(error);
}
Expand Down
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions Assets/uRemoteDesktopDuplication/Scripts/DesktopSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public void OnEncoded(System.IntPtr data, int size)
for (uint i = 0; i < n; ++i)
{
var fragmentData = fragmenter_.GetFragmentData(i);
if (fragmentData == System.IntPtr.Zero) return;
var fragmentSize = (int)fragmenter_.GetFragmentSize(i);
byte[] buf = new byte[fragmentSize];
Marshal.Copy(fragmentData, buf, 0, fragmentSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace uPacketFragmentation
{


void Frame::AddFragmentData(const void *pData, uint32_t size)
void Frame::AddFragmentData(const void *pData, uint32_t)
{
const auto &header = *reinterpret_cast<const PacketHeader*>(pData);

Expand Down
6 changes: 3 additions & 3 deletions Plugins/uPacketFragmentation/uPacketFragmentation/Assembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ class PacketAssembler final

std::map<uint64_t, std::unique_ptr<Frame>> frames_;
std::deque<uint64_t> assembledFrameIndices_;
uint64_t oldestFrameIndex_ = -1;
uint64_t latestFrameIndex_ = -1;
uint64_t latestTimestamp_ = -1;
uint64_t oldestFrameIndex_ = UINT64_MAX;
uint64_t latestFrameIndex_ = UINT64_MAX;
uint64_t latestTimestamp_ = UINT64_MAX;
PacketEventType eventType_ = PacketEventType::None;
PacketLossType lossType_ = PacketLossType::None;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ void PacketFragmenter::FragmentData(const void *pData, uint32_t size)
const uint32_t fragmentSize = size / fragmentCount + 1;

PacketHeader header = { GetPacketHeaderVersion() };
header.type = static_cast<uint32_t>(PacketType::Fragment);
header.type = static_cast<uint8_t>(PacketType::Fragment);
header.totalSize = size;
header.timestamp = time_point_cast<milliseconds>(system_clock::now()).time_since_epoch().count();
header.frameIndex = frameIndex_++;
header.fragmentCount = fragmentCount;
header.fragmentCount = static_cast<uint16_t>(fragmentCount);

for (uint32_t i = 0; i < fragmentCount; ++i)
for (uint16_t i = 0; i < fragmentCount; ++i)
{
const auto bufSize = static_cast<size_t>(maxBufSize) + headerSize;
auto buf = std::make_unique<char[]>(bufSize);
Expand Down
2 changes: 1 addition & 1 deletion Plugins/uPacketFragmentation/uPacketFragmentation/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ UNITY_INTERFACE_EXPORT uint64_t UNITY_INTERFACE_API UpfAssemblerGetAssembledFram
{
return assembler->GetAssembledFrameIndex();
}
return -1;
return UINT64_MAX;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
<Optimization>Disabled</Optimization>
<SDLCheck>false</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -115,6 +116,7 @@
<Optimization>Disabled</Optimization>
<SDLCheck>false</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -133,6 +135,8 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>false</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -153,6 +157,8 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>false</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,14 @@
<Filter>Unity</Filter>
</ClInclude>
<ClInclude Include="Common.h" />
<ClInclude Include="Log.h" />
<ClInclude Include="Assembler.h" />
<ClInclude Include="Fragmenter.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Log.cpp" />
<ClCompile Include="Main.cpp" />
<ClCompile Include="Assembler.cpp" />
<ClCompile Include="Fragmenter.cpp" />
</ItemGroup>
</Project>

0 comments on commit d639257

Please sign in to comment.