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

Dynamically allocate adb/usb devices using a vector, to avoid a hardcoded limit #3035

Merged
merged 4 commits into from
Feb 20, 2022

Conversation

rom1v
Copy link
Collaborator

@rom1v rom1v commented Feb 18, 2022

The maximum number of adb devices (and usb devices for HID/OTG) was hardcoded to 16, which is too low.

The first commit (8d06944) adds a sc_vector data structure and API. It is adapted from vlc_vector that I initially wrote while implementing the VLC playlist.

It is then used for listing usb devices and adb devices to remove any hardcoded limitation (the vector grows dynamically as necessary).

There is still a limitation in the parsing of adb devices -l, which is implemented for simplicity in a single pass on the whole output. The output was limited to 4096 bytes (which represents ~40 devices). I changed to 65536 bytes, it should be sufficient in practice (~650 devices listed by adb devices should never happen).

This replaces #3029.

@DarkZeros I added you as co-author for the adb devices listing. Please test this PR and confirm that it works for your use case.

@DarkZeros
Copy link

I tested and managed to connect to the 17-20 devices with this patch, seems working from my side!
I didn't thoroughly review though.

rom1v and others added 4 commits February 20, 2022 23:59
Adapt vlc_vector [1], that I initially wrote while implementing the VLC
playlist [2].

Change the implementation to use "statement expressions" [3], which are
forbidden in VLC because "non-standard", but:
 - they are supported by gcc and clang;
 - they are already used in the scrcpy codebase;
 - they avoid implementation hacks (VLC_VECTOR_FAILFLAG_);
 - they allow a better API (sc_vector_index_of() may return the result
   without an output parameter).

PR #3035 <#3035>

[1]: https://code.videolan.org/videolan/vlc/-/blob/0857947abaed9c89810cd96353aaa1b7e6ba3b0d/include/vlc_vector.h
[2]: https://blog.rom1v.com/2019/05/a-new-core-playlist-for-vlc-4
[3]: https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
This avoids the hardcoded maximum number of USB devices detected (16).

Refs #3029 <#3029>
PR #3035 <#3035>
This avoids the hardcoded maximum number of ADB devices detected (16).

Refs #3029 <#3029>
PR #3035 <#3035>

Co-authored-by: Daniel Ansorregui <d.ansorregui@samsung.com>
For simplicity, the parsing of `adb devices -l` output is performed in a
single pass on the whole output.

This output was limited to 4096 bytes. Since there are about 100 chars
per device line, this limited the number of connected devices to ~40.

Increase to 65536 bytes to avoid a limitation in practice.

PR #3035 <#3035>
@rom1v
Copy link
Collaborator Author

rom1v commented Feb 20, 2022

Thank you for your tests 👍 Merged.

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

2 participants