Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to just get the dll for using in Unity? #10

Closed
milos12345 opened this issue Aug 24, 2019 · 5 comments
Closed

Is it possible to just get the dll for using in Unity? #10

milos12345 opened this issue Aug 24, 2019 · 5 comments
Labels
question Further information is requested

Comments

@milos12345
Copy link

I don't see a way to build it on Windows and VS

@bmegli
Copy link
Owner

bmegli commented Aug 24, 2019

Building on Windows

There should be nothing stopping you.

The dependencies are standard library and ffmpeg.

If you don't know how to use cmake or don't want to use it:

  • make sure ffmpeg is available for compiler and linker
  • add hvd.c, hvd.h to VS
  • link with ffmpeg
  • build a dll as you would usually

In theory, it has been some time since I used Windows for development.

Using directly from Unity:

In theory it is possible but:

  • the library makes heavy use of pointers (you generally don't want to copy any data when working with 60 video frames per second, you always aim for zero copy or as close as possible)
  • using pointers from Unity is possible but clumsy
  • you generally would not want to make any managed copies of image data (at 1080p, single decoded frame is around 8 MB, at 60 fps this gives around 0,5 GB/s which doesn't play nice with Garbage Collector)

@milos12345
Copy link
Author

Thank you, I'll have to figure out how to do the first part. Your unity pointers make sense, I did not think of that so maybe it would not work as I expected

@bmegli
Copy link
Owner

bmegli commented Aug 26, 2019

@milos12345

For the second part (using directly from Unity) - I am trying to say that it will not be easy, and may not be the way to go. Still it is possible.

Using native code from managed code (Unity), with complex pointer logic, needs more experience and care than is required for writing native only or managed only code.

There are also other things to consider:

  • HVD will block for the duration of decoding
  • you should not wait for the duration of blocking code in Unity Update
  • so decoding should probably happen in separate thread
  • this thread will probably need synchronization with main Unity thread (mutex, semaphor, etc).

You may see example (but Linux only) of similar logic in unity-network-hardware-video-decoder

  • all network and decoding logic moved to native side (no managed memory)
  • the heavy stuff (network and decoding) runs in unmanaged thread
  • there is synchronization (mutex) when updating the texture data
  • a double buffer like mechanism was used (for decoded frames)
  • a smart pointer like reference counting for frame data was used (ffmpeg frame referencing, for avoiding copies of decoded video data)
  • the only thing left in Unity is texture update (with IntPtr, left in Unity for portability)
  • the network protocol used is custom (this would be bad choice, the reason is that those are also my experiments with the protocol)

There was also recently somebody trying to port nhvd code to Windows (for unhvd)

@bmegli bmegli reopened this Aug 26, 2019
@bmegli bmegli closed this as completed Aug 26, 2019
@bmegli bmegli reopened this Aug 30, 2019
@bmegli
Copy link
Owner

bmegli commented Aug 30, 2019

Hi @milos12345,

Have a look at ViveMediaDecoder by HTC

It is a Windows Unity video decoder.
From looking at code it is software decoder with hardware accelerated rendering (shaders).
Also, it seems to be working with RTSP over TCP/IP if you need to stream video.
There are a few examples in their repository.

Kind regards

@bmegli bmegli closed this as completed Sep 3, 2019
@milos12345
Copy link
Author

Hi @bmegli,
I have tried following your steps but it still exceeds my knowledge so I was unsuccessful. I have tried ViveMediaDecoder you suggested and seems to be fitting my needs.
Thank you!

@bmegli bmegli added the question Further information is requested label Sep 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants