Skip to content

Commit

Permalink
refactor: replace Solution with LegacySolutionRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
homuler committed Aug 13, 2024
1 parent a1e94fb commit 308150a
Show file tree
Hide file tree
Showing 15 changed files with 256 additions and 356 deletions.
6 changes: 3 additions & 3 deletions Assets/MediaPipeUnity/Samples/Common/Scripts/GraphRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ protected void AddPacketToInputStream<T>(string streamName, Packet<T> packet)
calculatorGraph.AddPacketToInputStream(streamName, packet);
}

protected void AddTextureFrameToInputStream(string streamName, TextureFrame textureFrame)
protected void AddTextureFrameToInputStream(string streamName, Experimental.TextureFrame textureFrame, GlContext glContext = null)
{
latestTimestamp = GetCurrentTimestampMicrosec();

if (configType == ConfigType.OpenGLES)
if (glContext != null)
{
var gpuBuffer = textureFrame.BuildGpuBuffer(GpuManager.GlCalculatorHelper.GetGlContext());
var gpuBuffer = textureFrame.BuildGpuBuffer(glContext);
AddPacketToInputStream(streamName, Packet.CreateGpuBufferAt(gpuBuffer, latestTimestamp));
return;
}
Expand Down
131 changes: 0 additions & 131 deletions Assets/MediaPipeUnity/Samples/Common/Scripts/ImageSourceSolution.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) 2023 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

using System.Collections;
using UnityEngine;

namespace Mediapipe.Unity.Sample
{
public abstract class LegacySolutionRunner<TGraphRunner> : TaskApiRunner where TGraphRunner : GraphRunner
{
[SerializeField] protected Screen screen;
[SerializeField] protected TGraphRunner graphRunner;

private Coroutine _coroutine;

public RunningMode runningMode;

public long timeoutMillisec
{
get => graphRunner.timeoutMillisec;
set => graphRunner.timeoutMillisec = value;
}

public override void Play()
{
if (_coroutine != null)
{
Stop();
}
base.Play();
_coroutine = StartCoroutine(Run());
}

public override void Pause()
{
base.Pause();
ImageSourceProvider.ImageSource.Pause();
}

public override void Resume()
{
base.Resume();
var _ = StartCoroutine(ImageSourceProvider.ImageSource.Resume());
}

public override void Stop()
{
base.Stop();
StopCoroutine(_coroutine);
ImageSourceProvider.ImageSource.Stop();
graphRunner.Stop();
}

protected abstract IEnumerator Run();

protected static void SetupAnnotationController<T>(AnnotationController<T> annotationController, ImageSource imageSource, bool expectedToBeMirrored = false) where T : HierarchicalAnnotation
{
annotationController.isMirrored = expectedToBeMirrored ^ imageSource.isHorizontallyFlipped ^ imageSource.isFrontFacing;
annotationController.rotationAngle = imageSource.rotation.Reverse();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Assets/MediaPipeUnity/Samples/Common/Scripts/Screen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void Rotate(RotationAngle rotationAngle)
_screen.rectTransform.localEulerAngles = rotationAngle.GetEulerAngles();
}

public void ReadSync(TextureFrame textureFrame)
public void ReadSync(Experimental.TextureFrame textureFrame)
{
if (!(texture is Texture2D))
{
Expand Down
110 changes: 0 additions & 110 deletions Assets/MediaPipeUnity/Samples/Common/Scripts/Solution.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Assets/MediaPipeUnity/Samples/Common/Scripts/Solution.cs.meta

This file was deleted.

Loading

0 comments on commit 308150a

Please sign in to comment.