NewChromantics / PopH264

Low-level, minimal H264 decoder & encoder library for windows, hololens/uwp, ios/tvos/macos, linux, android/quest/magic leap. CAPI for use with c#, unreal, swift
http://poph264.com/
Mozilla Public License 2.0
84 stars 15 forks source link

Not compiling on .NET Framework 4.x (Unity) #79

Open Fenekhu opened 10 months ago

Fenekhu commented 10 months ago

I have a different plugin that was having issues compiling and the recommended change was to switch from .NET Standard 2.1 to .NET Framework (4.8 maybe?). Doing so caused a bunch of this:

Library\PackageCache\com.newchromantics.poph264@9c2efe8322\Runtime\PopH264.cs(719,5): error CS0021: Cannot apply indexing with [] to an expression of type 'ArraySegment<byte>'
Library\PackageCache\com.newchromantics.poph264@9c2efe8322\Runtime\PopH264.cs(720,5): error CS0021: Cannot apply indexing with [] to an expression of type 'ArraySegment<byte>'
Library\PackageCache\com.newchromantics.poph264@9c2efe8322\Runtime\PopH264.cs(721,5): error CS0021: Cannot apply indexing with [] to an expression of type 'ArraySegment<byte>'
Library\PackageCache\com.newchromantics.poph264@9c2efe8322\Runtime\PopH264.cs(754,5): error CS0021: Cannot apply indexing with [] to an expression of type 'ArraySegment<byte>'
Library\PackageCache\com.newchromantics.poph264@9c2efe8322\Runtime\PopH264.cs(755,5): error CS0021: Cannot apply indexing with [] to an expression of type 'ArraySegment<byte>'
Library\PackageCache\com.newchromantics.poph264@9c2efe8322\Runtime\PopH264.cs(756,5): error CS0021: Cannot apply indexing with [] to an expression of type 'ArraySegment<byte>'

I don't see anything about PopH264 not working with .NET Framework, am I doing something dumb?

Fenekhu commented 10 months ago

Update: MSDN says:

ArraySegment implements the IReadOnlyCollection interface starting with the .NET Framework 4.6; in previous versions of the .NET Framework, the ArraySegment structure did not implement this interface.

So I converted those lines to index into the YuvPixels array directly like so:

YuvPixels[i] = Luma;
YuvPixels[LumaSize+Chromai] = ChromaU;
YuvPixels[LumaSize+ChromaSize+Chromai] = ChromaV;

and

YuvPixels[i] = Luma;
YuvPixels[LumaSize+Chromai+0] = ChromaV;
YuvPixels[LumaSize+Chromai+1] = ChromaV;

And now it compiles. I would still feel better if I knew whether this is a proper fix though.

SoylentGraham commented 10 months ago

Using the array directly should be fine! I just split them into views for simplicity, but i guess they're not read only in 2.1.

Ive only used this with unity, which I believe complies only with .net 2.1 (which i guess is runtime apis) but language version 8 or so.

If you can submit a PR, I'll double check it in unity, but this is all good :)

Just for any future stuff, what are you building with? Just a c# app built in visual studio or something?

SoylentGraham commented 9 months ago

To clarify, this is when not using unity, right? (Is title wrong?)

Fenekhu commented 9 months ago

No, this is with Unity. I can’t remember exactly where, but I think it’s under Player settings, there’s an option to change between compiling with .NET Standard 2.1 or .NET Framework 4.8. It wasn’t working with Framework. Though, in the end, switching that didn’t fix the other problem anyway, so I set it back to Standard.

I’ll work on a PR later today or tonight.