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

ASCS Source Implementation #372

Merged
merged 1 commit into from
May 29, 2024
Merged

ASCS Source Implementation #372

merged 1 commit into from
May 29, 2024

Conversation

zxzxwu
Copy link
Collaborator

@zxzxwu zxzxwu commented Dec 13, 2023

  • Implement ASE state transition for source
  • Make ASE emit state changed events
  • Replace pdu event with sink which is more reasonable and have a better type annotation
  • Implement a LEA app
  • Improve CIS handling in device and host

@zxzxwu
Copy link
Collaborator Author

zxzxwu commented Dec 13, 2023

SCO has the same issue. I think one solution could be - again, using microphone input from a web frontend.

@zxzxwu zxzxwu marked this pull request as draft December 13, 2023 16:11
@barbibulle
Copy link
Collaborator

SCO has the same issue. I think one solution could be - again, using microphone input from a web frontend.

You could read the input from an LC3 encoded audio file, like for the A2DP source example.

@zxzxwu
Copy link
Collaborator Author

zxzxwu commented May 3, 2024

Consider the difficulty of audio prcessing and state synchronization between Python and Web Frontend, I think it's better to host codec in Python instead of JS.

The liblc3.wasm file is built from liblc3 source. With wasmtime, it could be executed on all platforms (with CPython only?). Not sure whether there is a better way to pack liblc3?

@zxzxwu zxzxwu marked this pull request as ready for review May 3, 2024 12:40
@zxzxwu zxzxwu marked this pull request as draft May 3, 2024 12:40
@zxzxwu zxzxwu closed this May 3, 2024
@zxzxwu zxzxwu reopened this May 3, 2024
@zxzxwu
Copy link
Collaborator Author

zxzxwu commented May 3, 2024

Not sure how to solve this...

thread 'tokio-runtime-worker' panicked at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-asyncio-0.18.0/src/testing.rs:285:39:
called `Result::unwrap()` on an `Err` value: PyErr { type: <class 'ModuleNotFoundError'>, value: ModuleNotFoundError("No module named 'cryptography'"), traceback: Some(<traceback object at 0x7bb4710b75c0>) }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
pyo3_asyncio.RustPanic: rust future panicked
thread 'main' panicked at pytests/pytests.rs:15:1:
called `Result::unwrap()` on an `Err` value: ()
error: test failed, to rerun pass `--test pytests`

@zxzxwu zxzxwu force-pushed the source branch 3 times, most recently from 0115f92 to 47fb7f8 Compare May 3, 2024 16:27
setup.cfg Outdated Show resolved Hide resolved
@barbibulle
Copy link
Collaborator

Not sure how to solve this...

thread 'tokio-runtime-worker' panicked at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-asyncio-0.18.0/src/testing.rs:285:39:
called `Result::unwrap()` on an `Err` value: PyErr { type: <class 'ModuleNotFoundError'>, value: ModuleNotFoundError("No module named 'cryptography'"), traceback: Some(<traceback object at 0x7bb4710b75c0>) }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
pyo3_asyncio.RustPanic: rust future panicked
thread 'main' panicked at pytests/pytests.rs:15:1:
called `Result::unwrap()` on an `Err` value: ()
error: test failed, to rerun pass `--test pytests`

When do you get this error?

@zxzxwu
Copy link
Collaborator Author

zxzxwu commented May 6, 2024

It looks like an issue on my local machine. I tried again with GH workflow and then get

thread 'tokio-runtime-worker' panicked at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-asyncio-0.18.0/src/testing.rs:285:39:
called `Result::unwrap()` on an `Err` value: PyErr { type: <class 'RuntimeError'>, value: RuntimeError("There is no current event loop in thread 'Dummy-1'."), traceback: Some(<traceback object at 0x7f421426b6c0>) }
stack backtrace:
   0: rust_begin_unwind
             at /rustc/07dca489ac2d933c78d3c51[58](https://github.com/zxzxwu/bumble/actions/runs/8964830670/job/24617243180?pr=5#step:10:59)e3f43beefeb02ce/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:72:14
   2: core::result::unwrap_failed
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/result.rs:1[64](https://github.com/zxzxwu/bumble/actions/runs/8964830670/job/24617243180?pr=5#step:10:65)9:5
   3: core::result::Result<T,E>::unwrap
   4: pyo3_asyncio::testing::test_harness::{{closure}}::{{closure}}::{{closure}}
   5: <futures_util::stream::futures_unordered::FuturesUnordered<Fut> as futures_core::stream::Stream>::poll_next
   6: futures_util::stream::stream::StreamExt::poll_next_unpin
   7: <futures_util::stream::stream::for_each_concurrent::ForEachConcurrent<St,Fut,F> as core::future::future::Future>::poll
   8: pyo3_asyncio::testing::test_harness::{{closure}}
   9: pyo3_asyncio::testing::main::{{closure}}

After some investigation, the root cause of this seems to be async lock?

@zxzxwu zxzxwu force-pushed the source branch 4 times, most recently from 07286dd to 7a5f059 Compare May 6, 2024 07:58
@zxzxwu zxzxwu marked this pull request as ready for review May 6, 2024 17:17
@zxzxwu zxzxwu changed the title [WIP] ASCS Source ASCS Source Implementation May 6, 2024
@zxzxwu zxzxwu force-pushed the source branch 3 times, most recently from 2fe8e17 to ee2776e Compare May 15, 2024 19:47
@zxzxwu zxzxwu requested a review from barbibulle May 21, 2024 05:58
@zxzxwu
Copy link
Collaborator Author

zxzxwu commented May 21, 2024

Since we started working on Broadcast, we may merge this PR first to avoid conflict.

@barbibulle
Copy link
Collaborator

Since we started working on Broadcast, we may merge this PR first to avoid conflict.

Yes. I wasn't sure if you were ready with this one yet or not. I'll do a quick re-review today.

@zxzxwu
Copy link
Collaborator Author

zxzxwu commented May 24, 2024

Yes, I think it's ready.

apps/lea_unicast/app.py Outdated Show resolved Hide resolved
bumble/profiles/bap.py Outdated Show resolved Hide resolved
bumble/profiles/bap.py Outdated Show resolved Hide resolved
self._state = new_state
self.emit('state_change', new_state)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I recommend not sending the state in the event. The normal pattern is that if you notify of a change for a value that's already part of an object's properties, you don't need to repeat the value that changed, because the listener can access it from the object itself. For example, in device.py, when the encryption of the connection changes, we emit connection.emit('connection_encryption_change'). The listener can then look at connection.encryption to see what the new value is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds reasonable. It is really a pain point to use eventemitter - Despite it benefits Bumble a lot, the missing of type hint is something unstable.

examples/run_unicast_server.py Outdated Show resolved Hide resolved
@zxzxwu zxzxwu merged commit 0903093 into google:main May 29, 2024
57 checks passed
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.

2 participants