datap 0.1.2__tar.gz → 0.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {datap-0.1.2 → datap-0.1.3}/PKG-INFO +10 -4
- {datap-0.1.2 → datap-0.1.3}/README.md +6 -3
- {datap-0.1.2 → datap-0.1.3}/pyproject.toml +3 -2
- {datap-0.1.2 → datap-0.1.3}/src/btsh/cli.py +10 -0
- {datap-0.1.2 → datap-0.1.3}/src/btsh/codec.py +86 -2
- {datap-0.1.2 → datap-0.1.3}/src/datap.egg-info/PKG-INFO +10 -4
- {datap-0.1.2 → datap-0.1.3}/src/datap.egg-info/requires.txt +4 -0
- {datap-0.1.2 → datap-0.1.3}/setup.cfg +0 -0
- {datap-0.1.2 → datap-0.1.3}/src/btsh/__init__.py +0 -0
- {datap-0.1.2 → datap-0.1.3}/src/btsh/__main__.py +0 -0
- {datap-0.1.2 → datap-0.1.3}/src/btsh/audio.py +0 -0
- {datap-0.1.2 → datap-0.1.3}/src/btsh/ble.py +0 -0
- {datap-0.1.2 → datap-0.1.3}/src/btsh/bt.py +0 -0
- {datap-0.1.2 → datap-0.1.3}/src/btsh/channel.py +0 -0
- {datap-0.1.2 → datap-0.1.3}/src/btsh/channels.py +0 -0
- {datap-0.1.2 → datap-0.1.3}/src/btsh/client.py +0 -0
- {datap-0.1.2 → datap-0.1.3}/src/btsh/crypto.py +0 -0
- {datap-0.1.2 → datap-0.1.3}/src/btsh/framing.py +0 -0
- {datap-0.1.2 → datap-0.1.3}/src/btsh/hub.py +0 -0
- {datap-0.1.2 → datap-0.1.3}/src/btsh/mcp.py +0 -0
- {datap-0.1.2 → datap-0.1.3}/src/btsh/modem.py +0 -0
- {datap-0.1.2 → datap-0.1.3}/src/btsh/node.py +0 -0
- {datap-0.1.2 → datap-0.1.3}/src/btsh/py.typed +0 -0
- {datap-0.1.2 → datap-0.1.3}/src/btsh/server.py +0 -0
- {datap-0.1.2 → datap-0.1.3}/src/btsh/session.py +0 -0
- {datap-0.1.2 → datap-0.1.3}/src/btsh/tcp.py +0 -0
- {datap-0.1.2 → datap-0.1.3}/src/btsh/transport.py +0 -0
- {datap-0.1.2 → datap-0.1.3}/src/datap.egg-info/SOURCES.txt +0 -0
- {datap-0.1.2 → datap-0.1.3}/src/datap.egg-info/dependency_links.txt +0 -0
- {datap-0.1.2 → datap-0.1.3}/src/datap.egg-info/entry_points.txt +0 -0
- {datap-0.1.2 → datap-0.1.3}/src/datap.egg-info/top_level.txt +0 -0
- {datap-0.1.2 → datap-0.1.3}/tests/test_channels.py +0 -0
- {datap-0.1.2 → datap-0.1.3}/tests/test_crypto.py +0 -0
- {datap-0.1.2 → datap-0.1.3}/tests/test_e2e.py +0 -0
- {datap-0.1.2 → datap-0.1.3}/tests/test_framing.py +0 -0
- {datap-0.1.2 → datap-0.1.3}/tests/test_mesh.py +0 -0
- {datap-0.1.2 → datap-0.1.3}/tests/test_modem.py +0 -0
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: datap
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: Shell over a Bluetooth speaker's audio codec: run commands without an SSH server
|
|
5
5
|
Author: Marc Partensky
|
|
6
6
|
License-Expression: MIT
|
|
7
7
|
Keywords: bluetooth,a2dp,sbc,modem,shell,ssh
|
|
8
8
|
Requires-Python: >=3.10
|
|
9
9
|
Description-Content-Type: text/markdown
|
|
10
|
+
Requires-Dist: av>=12
|
|
11
|
+
Provides-Extra: sbc
|
|
12
|
+
Requires-Dist: av>=12; extra == "sbc"
|
|
10
13
|
Provides-Extra: portaudio
|
|
11
14
|
Requires-Dist: sounddevice>=0.4; extra == "portaudio"
|
|
12
15
|
Provides-Extra: ble
|
|
@@ -55,12 +58,15 @@ what makes "the speaker's codec carries your shell" literal.
|
|
|
55
58
|
## Install
|
|
56
59
|
|
|
57
60
|
```bash
|
|
58
|
-
pip install datap # core,
|
|
61
|
+
pip install datap # core, SBC included
|
|
59
62
|
pip install "datap[all]" # + sounddevice (PortAudio) and bleak (BLE)
|
|
60
63
|
```
|
|
61
64
|
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
No system package is needed: the SBC transform walks through `av` (PyAV), which
|
|
66
|
+
carries FFmpeg inside its own wheel, on Windows, macOS and Linux alike. If an
|
|
67
|
+
`ffmpeg` binary happens to be on `PATH` it is used first, and `BTSH_FFMPEG` can
|
|
68
|
+
point at another one. Neither is required, and `btsh doctor` tells you which
|
|
69
|
+
backend is live. `--codec none` skips the transform entirely.
|
|
64
70
|
|
|
65
71
|
## Quick start
|
|
66
72
|
|
|
@@ -38,12 +38,15 @@ what makes "the speaker's codec carries your shell" literal.
|
|
|
38
38
|
## Install
|
|
39
39
|
|
|
40
40
|
```bash
|
|
41
|
-
pip install datap # core,
|
|
41
|
+
pip install datap # core, SBC included
|
|
42
42
|
pip install "datap[all]" # + sounddevice (PortAudio) and bleak (BLE)
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
No system package is needed: the SBC transform walks through `av` (PyAV), which
|
|
46
|
+
carries FFmpeg inside its own wheel, on Windows, macOS and Linux alike. If an
|
|
47
|
+
`ffmpeg` binary happens to be on `PATH` it is used first, and `BTSH_FFMPEG` can
|
|
48
|
+
point at another one. Neither is required, and `btsh doctor` tells you which
|
|
49
|
+
backend is live. `--codec none` skips the transform entirely.
|
|
47
50
|
|
|
48
51
|
## Quick start
|
|
49
52
|
|
|
@@ -4,16 +4,17 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "datap"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.3"
|
|
8
8
|
description = "Shell over a Bluetooth speaker's audio codec: run commands without an SSH server"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
11
11
|
license = "MIT"
|
|
12
12
|
authors = [{ name = "Marc Partensky" }]
|
|
13
13
|
keywords = ["bluetooth", "a2dp", "sbc", "modem", "shell", "ssh"]
|
|
14
|
-
dependencies = []
|
|
14
|
+
dependencies = ["av>=12"]
|
|
15
15
|
|
|
16
16
|
[project.optional-dependencies]
|
|
17
|
+
sbc = ["av>=12"]
|
|
17
18
|
portaudio = ["sounddevice>=0.4"]
|
|
18
19
|
ble = ["bleak>=0.21"]
|
|
19
20
|
all = ["sounddevice>=0.4", "bleak>=0.21"]
|
|
@@ -146,6 +146,7 @@ def cmd_doctor(args) -> int:
|
|
|
146
146
|
report: dict = {
|
|
147
147
|
"version": __version__,
|
|
148
148
|
"ffmpeg": shutil.which(codec.FFMPEG),
|
|
149
|
+
"sbc": codec.sbc_backend(),
|
|
149
150
|
"pw-play": shutil.which("pw-play"),
|
|
150
151
|
}
|
|
151
152
|
try:
|
|
@@ -165,6 +166,15 @@ def cmd_doctor(args) -> int:
|
|
|
165
166
|
return 0
|
|
166
167
|
print(f"btsh {report['version']}")
|
|
167
168
|
print(f"ffmpeg: {report['ffmpeg'] or 'missing'} pw-play: {report['pw-play'] or 'missing'}")
|
|
169
|
+
sbc = report.get("sbc", "none")
|
|
170
|
+
if sbc == "ffmpeg":
|
|
171
|
+
print("sbc: ffmpeg binary")
|
|
172
|
+
elif sbc == "av":
|
|
173
|
+
import av # noqa: PLC0415
|
|
174
|
+
|
|
175
|
+
print(f"sbc: PyAV {av.__version__} (FFmpeg {av.ffmpeg_version_info} inside the wheel)")
|
|
176
|
+
else:
|
|
177
|
+
print("sbc: none, install `datap[sbc]` or put ffmpeg on PATH (--codec none works without either)")
|
|
168
178
|
devices = report.get("devices") or []
|
|
169
179
|
if devices:
|
|
170
180
|
print("\nBluetooth devices:")
|
|
@@ -24,20 +24,104 @@ def ffmpeg_available() -> bool:
|
|
|
24
24
|
return shutil.which(FFMPEG) is not None
|
|
25
25
|
|
|
26
26
|
|
|
27
|
+
def _av_module():
|
|
28
|
+
"""Return the ``av`` module, or None when it is missing or unusable.
|
|
29
|
+
|
|
30
|
+
The import is lazy and failure tolerant on purpose: PyAV ships the FFmpeg
|
|
31
|
+
libraries inside its wheel, but on NixOS those prebuilt libs can fail to
|
|
32
|
+
load (``libz.so.1``, ``libstdc++.so.6`` not found), and that must degrade to
|
|
33
|
+
the ffmpeg CLI rather than break ``import btsh``.
|
|
34
|
+
"""
|
|
35
|
+
try:
|
|
36
|
+
import av # noqa: PLC0415
|
|
37
|
+
except Exception: # noqa: BLE001 - ImportError, OSError, AttributeError
|
|
38
|
+
return None
|
|
39
|
+
return av
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def sbc_backend() -> str:
|
|
43
|
+
"""Which SBC implementation is usable here: ``ffmpeg``, ``av`` or ``none``."""
|
|
44
|
+
if ffmpeg_available():
|
|
45
|
+
return "ffmpeg"
|
|
46
|
+
if _av_module() is not None:
|
|
47
|
+
return "av"
|
|
48
|
+
return "none"
|
|
49
|
+
|
|
50
|
+
|
|
27
51
|
_CODEC_ARGS = {
|
|
28
52
|
"sbc": ["-c:a", "sbc"],
|
|
29
53
|
"none": None,
|
|
30
54
|
}
|
|
31
55
|
|
|
32
56
|
|
|
57
|
+
def _apply_sbc_av(pcm: bytes, bitrate: int, sample_rate: int) -> bytes:
|
|
58
|
+
"""SBC round trip through PyAV, which carries FFmpeg inside the wheel.
|
|
59
|
+
|
|
60
|
+
This is the path for machines with no ffmpeg binary (Windows, a bare macOS
|
|
61
|
+
profile). ``av`` needs no system package: the codec comes with the wheel.
|
|
62
|
+
"""
|
|
63
|
+
av = _av_module()
|
|
64
|
+
if av is None: # pragma: no cover - guarded by the caller
|
|
65
|
+
raise CodecError("PyAV unavailable")
|
|
66
|
+
|
|
67
|
+
channels, layout = 1, "mono"
|
|
68
|
+
enc = av.CodecContext.create("sbc", "w")
|
|
69
|
+
enc.sample_rate = sample_rate
|
|
70
|
+
enc.format = "s16"
|
|
71
|
+
enc.layout = layout
|
|
72
|
+
enc.bit_rate = bitrate
|
|
73
|
+
enc.open()
|
|
74
|
+
frame_size = enc.frame_size or 128
|
|
75
|
+
width = frame_size * 2 * channels
|
|
76
|
+
|
|
77
|
+
padded = pcm + b"\x00" * (-len(pcm) % width)
|
|
78
|
+
packets: list[bytes] = []
|
|
79
|
+
for offset in range(0, len(padded), width):
|
|
80
|
+
frame = av.AudioFrame(format="s16", layout=layout, samples=frame_size)
|
|
81
|
+
frame.sample_rate = sample_rate
|
|
82
|
+
frame.planes[0].update(padded[offset:offset + width])
|
|
83
|
+
for packet in enc.encode(frame):
|
|
84
|
+
packets.append(bytes(packet))
|
|
85
|
+
# flushes any held frame
|
|
86
|
+
for packet in enc.encode(None):
|
|
87
|
+
packets.append(bytes(packet))
|
|
88
|
+
|
|
89
|
+
dec = av.CodecContext.create("sbc", "r")
|
|
90
|
+
# the decoder needs the stream shape before open(), else avcodec_receive_frame
|
|
91
|
+
# blows up with AVERROR_BUG
|
|
92
|
+
dec.sample_rate = sample_rate
|
|
93
|
+
dec.layout = layout
|
|
94
|
+
dec.open()
|
|
95
|
+
out = bytearray()
|
|
96
|
+
for payload in packets:
|
|
97
|
+
for frame in dec.decode(av.Packet(payload)):
|
|
98
|
+
for plane in frame.planes:
|
|
99
|
+
out += bytes(plane)
|
|
100
|
+
if len(out) < len(pcm):
|
|
101
|
+
out += b"\x00" * (len(pcm) - len(out))
|
|
102
|
+
return bytes(out[: len(pcm)])
|
|
103
|
+
|
|
104
|
+
|
|
33
105
|
def apply_codec(pcm: bytes, codec: str = "sbc", bitrate: int = 200_000, sample_rate: int = 48000) -> bytes:
|
|
34
106
|
"""Push PCM through ``codec`` and return PCM of the same length."""
|
|
35
107
|
if codec in ("", "none", None):
|
|
36
108
|
return pcm
|
|
37
109
|
if codec not in _CODEC_ARGS:
|
|
38
110
|
raise CodecError(f"unsupported codec: {codec}")
|
|
39
|
-
|
|
40
|
-
|
|
111
|
+
backend = sbc_backend()
|
|
112
|
+
if backend == "none":
|
|
113
|
+
raise CodecError(
|
|
114
|
+
"no SBC backend: reinstall with `pip install 'datap[sbc]'` (FFmpeg "
|
|
115
|
+
"libraries come with the wheel) or put an ffmpeg binary on PATH "
|
|
116
|
+
"(or point BTSH_FFMPEG at one); `--codec none` needs neither"
|
|
117
|
+
)
|
|
118
|
+
if backend == "av":
|
|
119
|
+
try:
|
|
120
|
+
return _apply_sbc_av(pcm, bitrate, sample_rate)
|
|
121
|
+
except CodecError:
|
|
122
|
+
raise
|
|
123
|
+
except Exception as exc: # noqa: BLE001 - PyAV raises many shapes
|
|
124
|
+
raise CodecError(f"SBC via PyAV failed: {exc}") from exc
|
|
41
125
|
with tempfile.TemporaryDirectory(prefix="btsh-codec-") as workdir:
|
|
42
126
|
source = os.path.join(workdir, "in.raw")
|
|
43
127
|
encoded = os.path.join(workdir, "out.sbc")
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: datap
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: Shell over a Bluetooth speaker's audio codec: run commands without an SSH server
|
|
5
5
|
Author: Marc Partensky
|
|
6
6
|
License-Expression: MIT
|
|
7
7
|
Keywords: bluetooth,a2dp,sbc,modem,shell,ssh
|
|
8
8
|
Requires-Python: >=3.10
|
|
9
9
|
Description-Content-Type: text/markdown
|
|
10
|
+
Requires-Dist: av>=12
|
|
11
|
+
Provides-Extra: sbc
|
|
12
|
+
Requires-Dist: av>=12; extra == "sbc"
|
|
10
13
|
Provides-Extra: portaudio
|
|
11
14
|
Requires-Dist: sounddevice>=0.4; extra == "portaudio"
|
|
12
15
|
Provides-Extra: ble
|
|
@@ -55,12 +58,15 @@ what makes "the speaker's codec carries your shell" literal.
|
|
|
55
58
|
## Install
|
|
56
59
|
|
|
57
60
|
```bash
|
|
58
|
-
pip install datap # core,
|
|
61
|
+
pip install datap # core, SBC included
|
|
59
62
|
pip install "datap[all]" # + sounddevice (PortAudio) and bleak (BLE)
|
|
60
63
|
```
|
|
61
64
|
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
No system package is needed: the SBC transform walks through `av` (PyAV), which
|
|
66
|
+
carries FFmpeg inside its own wheel, on Windows, macOS and Linux alike. If an
|
|
67
|
+
`ffmpeg` binary happens to be on `PATH` it is used first, and `BTSH_FFMPEG` can
|
|
68
|
+
point at another one. Neither is required, and `btsh doctor` tells you which
|
|
69
|
+
backend is live. `--codec none` skips the transform entirely.
|
|
64
70
|
|
|
65
71
|
## Quick start
|
|
66
72
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|