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

Use TextureView instead of SurfaceView on Android. #459

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

nielsenko
Copy link

Compared to existing ZXingSurfaceView, ZXingTextureView fixes the following:

  • Ensure correct aspect ratio, no matter what the view size.
  • Use background handler for all camera manipulation.
  • Crop preview to match viewfinder, so that you only scan what you see.
  • Avoid byte[] marshalling between Java and .Net runtime (FastJavaByteArray).
  • Return buffer to java runtime with camera.AddCallbackBuffer.
  • Avoid traslating from YCrCb to Rgb and back to luminance data (FastJavaByteArrayYUVLuminanceSource)
  • Re-use buffers, to avoid memory pressure, when rotating.
  • Automatically request autofocus on devices that does not support continous auto focus mode.
  • Prefer continous mode
  • For Xamarin.Forms ZXingScannerView now uses ZXingTextureView in the renderer on Android.

@Redth
Copy link
Owner

Redth commented Nov 15, 2016

This looks great!!! going to take a bit to review, but thanks so much for doing this work. Will post follow up questions yet i'm sure.

using Android.Hardware;
using Android.Runtime;

namespace ApxLabs.FastAndroidCamera
Copy link
Owner

Choose a reason for hiding this comment

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

Could you please change the namespace here?

Copy link
Author

Choose a reason for hiding this comment

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

The reason I kept the APXLabs namespace in:

CameraExtensions.cs
FastJavaByteArray.cs
FastJavaByteArrayEnumerator.cs

is that these files stems from: https://github.com/APXLabs/FastAndroidCamera. APXLabs is not my company, and even if the license permits me to change the namespace I felt it was a bit rude.

I only modified the files to use the JniEnvironment class (introduced with Xamarin.Android 6.1, if I recall correctly)

However I see that James Athey (the original author - https://github.com/jamesathey) has done some simlar fixes this september, and even released a nuget: https://www.nuget.org/packages/FastAndroidCamera/ Perhaps it would be better to reference this, what do you think?

@Redth
Copy link
Owner

Redth commented Nov 15, 2016

As part of this, I think this has swayed me enough to completely drop support for < 4.0.3 (TextureView is only available on 4.0+).

@nielsenko
Copy link
Author

Can't really grok what fails on the build servers..

@@ -41,6 +42,9 @@
<HintPath>..\..\packages\Xamarin.Android.Support.v4.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.v4.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="FastAndroidCamera">
<HintPath>..\..\Samples\Forms\packages\FastAndroidCamera.2.0.0\lib\MonoAndroid403\FastAndroidCamera.dll</HintPath>
Copy link
Contributor

@f1nzer f1nzer Nov 16, 2016

Choose a reason for hiding this comment

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

Change hint path from Samples folder to ..\..\packages\....

@@ -94,6 +95,9 @@
<HintPath>..\..\packages\Xamarin.Forms.2.3.0.107\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="FastAndroidCamera">
<HintPath>..\..\Samples\Forms\packages\FastAndroidCamera.2.0.0\lib\MonoAndroid403\FastAndroidCamera.dll</HintPath>
Copy link
Contributor

Choose a reason for hiding this comment

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

also here

@Redth
Copy link
Owner

Redth commented Nov 16, 2016

Ahh I didn't realize this wasn't your code. Definitely in that case I wouldn't want to remove the namespace but I like the switch to a nuget dependency anyway.

@Redth
Copy link
Owner

Redth commented Nov 16, 2016

I'm going to take a shot at manually merging this tomorrow since I've just merged a big refactor of these related classes into master. Thanks for doing this work!

Also, you inspired me to do the same type of work for iOS which saw some huge performance gains from the work I did on it this morning.

Cheers!

@nielsenko
Copy link
Author

nielsenko commented Nov 17, 2016

Sounds great. I will merge with master for you. Looking forward for your changes on the iOS side!

@nielsenko
Copy link
Author

All systems are go!

@nielsenko
Copy link
Author

@Redth, don't hesitate to contact me, if you have any questions/comments

@Redth
Copy link
Owner

Redth commented Nov 22, 2016

Thanks, I'm going to bring in the changes to ZXingSurfaceView first. We'll have to revisit some of the refactoring @f1nzer did around the android camera (it's coupled to SurfaceView) so that we can follow the same pattern with the TextureView implementation.

@nielsenko
Copy link
Author

nielsenko commented Nov 30, 2016

Hi @Redth,
Could you share the status on this? Perhaps I can help out?

@adusak
Copy link

adusak commented Mar 27, 2017

Any news regarding this pull request? It is extensive fixes alot of issues, it would be a shame for it to go to waste.

@nielsenko
Copy link
Author

No; I haven't heard more from @Redth. I think he is busy with other stuff. I have created nugets for Android here: https://www.myget.org/F/custom-zxing-mobile/. I wasn't sure what to do with the version number, so it has the odd version 2.1.11 where 2.1 is taken from the original source, and 11 is my bitrise build number.

@Redth
Copy link
Owner

Redth commented Apr 12, 2017

@nielsenko sorry i dropped the ball on this one. I've finally got some of the android fast camera stuff into master and released.

If you are open to it, I'd love this to be rebased on current master. If you're not able to get to that, I can always have a look...

@nielsenko
Copy link
Author

I'm a bit pressed for time right now, but I will give it a try, once I get around to it.

…n FastJavaByteArrayYUVLuminanceSource and simplify CameraAnalyzer
Compared to existing ZXingSurfaceView, ZXingTextureView fixes the following:

- Ensure correct aspect ratio, no matter what the view size.
- Use background handler for all camera manipulation.
- Crop preview to match viewfinder, so that you only scan what you see.
- Avoid byte[] marshalling between Java and .Net runtime (FastJavaByteArray).
- Return buffer to java runtime with camera.AddCallbackBuffer.
- Avoid traslating from YCrCb to Rgb and back to luminance data (FastJavaByteArrayYUVLuminanceSource)
- Re-use buffers, to avoid memory pressure, when rotating.
- Automatically request autofocus on devices that does not support continous auto focus mode.
- Prefer continous mode
- For Xamarin.Forms ZXingScannerView now uses ZXingTextureView in the renderer on Android.
…d a FastJavaArrayEx.BlockCopyTo method to compensate for missing funtionality.
…ep a ringbuffer of recent barcodes, and honor DelayBetweenContinuousScans (of same barcode)
@rstcrypto
Copy link

any update on this?

@GiampaoloGabba
Copy link

I suppose we will never get this merged :(
Maybe after the new dev branch will be released, i will fork everything and try to rebase & merge this pull request. Its very promising and i think it can improve a lot this beautiful project

@Softtinn
Copy link

Softtinn commented May 8, 2020

What's the hold up on this?
It's a great fix! A shame if all the work from the author goes to waste...

@nielsenko
Copy link
Author

@Softtinn My PR was an offshoot from a contract back in 2016 for a scandinavian postal service. I'm no longer involved with this project, so my personal interest has faded. I think @Redth was just busy with other stuff, and hence it never got merged. I'm not sure how many of these improvements has made it into master through other PRs. There has been quite a lot of releases since then. Today, I would probably use Google Vision instead (https://developers.google.com/vision/android/barcodes-overview) and Camera X (https://developer.android.com/training/camerax)

@Redth
Copy link
Owner

Redth commented May 9, 2020

I do plan on incorporating this in the future. Right now I’m too tied up with other pandemic related work so it may be a few weeks before I get back to this project yet.

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

Successfully merging this pull request may close these issues.

None yet

7 participants