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

C# Record and Playback APIs #822

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from

Conversation

Brent-A
Copy link
Contributor

@Brent-A Brent-A commented Oct 8, 2019

Fixes #573

Description of the changes:

  • Added wrapper for Record and Playback APIs
  • Added a unit test to loop back a synthetic recording
  • Added native debug message hook to Record and Playback

Before submitting a Pull Request:

I tested changes on:

  • Windows
  • Linux

wes-b
wes-b previously approved these changes Oct 9, 2019
Copy link
Contributor

@wes-b wes-b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow that is a lot of exception handling. There is a ton of code here. You might also have Derek take a peek

Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure the best way to deal with this. The "Any CPU" in the solution can get confusing, but Visual Studio really likes adding it back in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure here either. Not supporting Any CPU in the nuget package is also pretty rough since downstream projects tend to have it by default.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we did have an issue tracking Any CPU support but I can't find it at this moment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.NET Core can actually do AnyCPU here. It's able to handle multiple native libraries with different architectures by deploying the native libs in the \runtimes\win-x64\ and \runtimes\win-x86\ sub folders.

@@ -0,0 +1,102 @@
using System;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright header.

}

/// <summary>
/// Gets get the camera calibration for Azure Kinect device used during recording. The output struct is used as input to all transformation functions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many places in the file where you have "Gets get", you can remove the duplicate "get".

UIntPtr size = new UIntPtr(0);
if (NativeMethods.k4a_playback_get_raw_calibration(this.handle, null, ref size) != NativeMethods.k4a_buffer_result_t.K4A_BUFFER_RESULT_TOO_SMALL)
{
throw new AzureKinectGetRawCalibrationException($"Unexpected result calling {nameof(NativeMethods.k4a_playback_get_raw_calibration)}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand the code correctly, this will throw if there is no calibration, however the exception will just say unexpected result. Can we add logging in here? Or somehow return a better result for when the calibration doesn't exist?

case NativeMethods.k4a_stream_result_t.K4A_STREAM_RESULT_EOF:
return null;
case NativeMethods.k4a_stream_result_t.K4A_STREAM_RESULT_FAILED:
throw new AzureKinectGetCaptureException();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice to get the log here for this expcetion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the other similar functions, GetPreviousCapture, GetNextImuSample, GetPreviousImuSample, etc

/// Azure Kinect objects.
///
/// When using this handle value, the caller is responsible for ensuring that the
/// Device object does not become disposed.</remarks>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you want to add that locking on this object will gaurentee that it isn't disposed while you are using the handle?

/// <returns>The native handle that is wrapped by this device.</returns>
/// <remarks>The function is dangerous because there is no guarantee that the
/// handle will not be disposed once it is retrieved. This should only be called
/// by code that can ensure that the Capture object will not be disposed on another
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// by code that can ensure that the Capture object will not be disposed on another
/// by code that can ensure that the Device object will not be disposed on another

@@ -47,6 +48,19 @@ public static class Logger
}
}

private static event Action<LogMessage> LogMessageHandlers;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did StyleCop not require this to be before the public one?

}
}

private static event Action<LogMessage> LogMessageHandlers;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did StyleCop not require this to be before the Public one?

@@ -373,7 +380,10 @@ k4a_result_t k4a_record_add_tag(const k4a_record_t recording_handle, const char
return K4A_RESULT_FAILED;
}

add_tag(context, name, value);
if (NULL == add_tag(context, name, value))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope for this review, but do we need to care about the return value from any of the other add_tag calls?

@@ -0,0 +1,216 @@
using System;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright header.

record.AddTag("MYTAG1", "one");
record.AddTag("MYTAG2", "two");

record.WriteHeader();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have a comment that WriteHeader must be called before any data is written, but does it need to be called after all tracks and tags are added?


// Not captured in recording
// Assert.AreEqual(100, c.Color.ISOSpeed);
Assert.AreEqual(0, c.Color.SystemTimestampNsec);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this 0? Didn't you write the timestamp in above?

@natelowry
Copy link

any updates on this? would be greatly appreciated 😺

@sagarpatel
Copy link

really hoping this makes it in the v.1.4.0 release, waiting on this to develop some new features in my Unity3D project

@UnaNancyOwen UnaNancyOwen mentioned this pull request Mar 6, 2020
@UnaNancyOwen
Copy link
Contributor

What is the reason this pull request is stopped? Thanks,

@natelowry
Copy link

@UnaNancyOwen:

They mentioned in a comment on #1093 that they're working through some technical issues. I'm guessing they're probably working through any minor bugs on the 1.4 release as that was a pretty big one. They haven't forgotten about it 🙃

You can always build this branch or copy in the needed code to you project if you really need.

@natelowry
Copy link

bumping. i know it won't get missed, mainly wondering if it has a tentative date. didn't know if there was a normal release cadence or it's just as things get merged. if it'll be a while i'll just roll my own, wrapper - now with less quality!™️ :)

anything i can do to help on this?

@sagarpatel
Copy link

Re-bumping this.
Is the technical issue mentioned before still blocking the progress on this or is just that this feature is low priority/dropped?
Anything we can do to help?

@jwvanderbeck-Unity
Copy link

Hi,
Based on comments it sounds like this is just held back for logistical reasons? The code in this branch is actually complete and useable? I need to work with pre-recorded files in a project.

@jwvanderbeck-Unity
Copy link

I know this is sort of stalled, but I just wanted to comment that I have been using this branch now for a while to implement playback and recording inside of a Unity project I am working on and everything has been working like a charm. Thanks for this work!

@jwvanderbeck
Copy link

According to the C++ code here: https://github.com/microsoft/Azure-Kinect-Sensor-SDK/blob/develop/src/record/sdk/record.cpp#L85

The ColorFormat BGRA32 should be supported for recording, yet when attempting to use that format with the C# recording layer, I get an unsupported color format error.

@jwvanderbeck
Copy link

According to the C++ code here: https://github.com/microsoft/Azure-Kinect-Sensor-SDK/blob/develop/src/record/sdk/record.cpp#L85

The ColorFormat BGRA32 should be supported for recording, yet when attempting to use that format with the C# recording layer, I get an unsupported color format error.

I see my error here. This branch is actually using older C++ code that doesn't support that color format.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose the playback and record APIs through C#
9 participants