Skip to content

Commit

Permalink
fix: the sync mode fails when trying to get the ImageFrame result (#1142
Browse files Browse the repository at this point in the history
)

* fix: failed to get ImageFrame

* refactor: remove the fallback Packet.Get method
  • Loading branch information
homuler committed Jan 30, 2024
1 parent 3753fdf commit b6961e5
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 12 deletions.
5 changes: 0 additions & 5 deletions Assets/MediaPipeUnity/Samples/Common/Scripts/GraphRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,6 @@ protected void AddTextureFrameToInputStream(string streamName, TextureFrame text
AddPacketToInputStream(streamName, Packet.CreateImageFrameAt(imageFrame, latestTimestamp));
}

protected bool TryGetValue<T>(Packet<T> packet, out T value)
{
return TryGetValue(packet, out value, (packet) => packet.Get());
}

protected bool TryGetValue<T>(Packet<T> packet, out T value, Func<Packet<T>, T> getter)
{
if (packet == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ public async Task<ImageFrame> WaitNext()
var result = await _hairMaskStream.WaitNextAsync();
AssertResult(result);

_ = TryGetValue(result.packet, out var hairMask);
_ = TryGetValue(result.packet, out var hairMask, (packet) =>
{
return packet.Get();
});
return hairMask;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ public async Task<HolisticTrackingResult> WaitNextAsync()
{
return packet.Get(LandmarkList.Parser);
});
_ = TryGetValue(results.Item7.packet, out var segmentationMask);
_ = TryGetValue(results.Item7.packet, out var segmentationMask, (packet) =>
{
return packet.Get();
});
_ = TryGetValue(results.Item8.packet, out var poseRoi, (packet) =>
{
return packet.Get(NormalizedRect.Parser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ public async Task<ImageFrame> WaitNextAsync()
var result = await _outputVideoStream.WaitNextAsync();
AssertResult(result);

_ = TryGetValue(result.packet, out var outputVideo);
_ = TryGetValue(result.packet, out var outputVideo, (packet) =>
{
return packet.Get();
});
return outputVideo;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ public async Task<PoseTrackingResult> WaitNextAsync()
{
return packet.Get(LandmarkList.Parser);
});
_ = TryGetValue(results.Item4.packet, out var segmentationMask);
_ = TryGetValue(results.Item4.packet, out var segmentationMask, (packet) =>
{
return packet.Get();
});
_ = TryGetValue(results.Item5.packet, out var roiFromLandmarks, (packet) =>
{
return packet.Get(NormalizedRect.Parser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ public async Task<ImageFrame> WaitNextAsync()
var result = await _segmentationMaskStream.WaitNextAsync();
AssertResult(result);

_ = TryGetValue(result.packet, out var segmentationMask);
_ = TryGetValue(result.packet, out var segmentationMask, (packet) =>
{
return packet.Get();
});
return segmentationMask;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,5 @@ public static string Get(this Packet<string> packet)

[Obsolete("Use Get instead")]
public static string GetString(this Packet<string> packet) => Get(packet);

public static T Get<T>(this Packet<T> packet) => throw new NotImplementedException();
}
}

0 comments on commit b6961e5

Please sign in to comment.