forked from auracaster/bumble_mirror
Fix AVRCP errors
This commit is contained in:
@@ -50,19 +50,10 @@ from bumble.sdp import (
|
|||||||
ServiceAttribute,
|
ServiceAttribute,
|
||||||
)
|
)
|
||||||
from bumble import utils
|
from bumble import utils
|
||||||
from bumble.core import (
|
from bumble import core
|
||||||
InvalidArgumentError,
|
|
||||||
ProtocolError,
|
|
||||||
BT_L2CAP_PROTOCOL_ID,
|
|
||||||
BT_AVCTP_PROTOCOL_ID,
|
|
||||||
BT_AV_REMOTE_CONTROL_SERVICE,
|
|
||||||
BT_AV_REMOTE_CONTROL_CONTROLLER_SERVICE,
|
|
||||||
BT_AV_REMOTE_CONTROL_TARGET_SERVICE,
|
|
||||||
)
|
|
||||||
from bumble import l2cap
|
from bumble import l2cap
|
||||||
from bumble import avc
|
from bumble import avc
|
||||||
from bumble import avctp
|
from bumble import avctp
|
||||||
from bumble import utils
|
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
@@ -102,8 +93,8 @@ def make_controller_service_sdp_records(
|
|||||||
SDP_SERVICE_CLASS_ID_LIST_ATTRIBUTE_ID,
|
SDP_SERVICE_CLASS_ID_LIST_ATTRIBUTE_ID,
|
||||||
DataElement.sequence(
|
DataElement.sequence(
|
||||||
[
|
[
|
||||||
DataElement.uuid(BT_AV_REMOTE_CONTROL_SERVICE),
|
DataElement.uuid(core.BT_AV_REMOTE_CONTROL_SERVICE),
|
||||||
DataElement.uuid(BT_AV_REMOTE_CONTROL_CONTROLLER_SERVICE),
|
DataElement.uuid(core.BT_AV_REMOTE_CONTROL_CONTROLLER_SERVICE),
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -113,13 +104,13 @@ def make_controller_service_sdp_records(
|
|||||||
[
|
[
|
||||||
DataElement.sequence(
|
DataElement.sequence(
|
||||||
[
|
[
|
||||||
DataElement.uuid(BT_L2CAP_PROTOCOL_ID),
|
DataElement.uuid(core.BT_L2CAP_PROTOCOL_ID),
|
||||||
DataElement.unsigned_integer_16(avctp.AVCTP_PSM),
|
DataElement.unsigned_integer_16(avctp.AVCTP_PSM),
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
DataElement.sequence(
|
DataElement.sequence(
|
||||||
[
|
[
|
||||||
DataElement.uuid(BT_AVCTP_PROTOCOL_ID),
|
DataElement.uuid(core.BT_AVCTP_PROTOCOL_ID),
|
||||||
DataElement.unsigned_integer_16(avctp_version_int),
|
DataElement.unsigned_integer_16(avctp_version_int),
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
@@ -132,7 +123,7 @@ def make_controller_service_sdp_records(
|
|||||||
[
|
[
|
||||||
DataElement.sequence(
|
DataElement.sequence(
|
||||||
[
|
[
|
||||||
DataElement.uuid(BT_AV_REMOTE_CONTROL_SERVICE),
|
DataElement.uuid(core.BT_AV_REMOTE_CONTROL_SERVICE),
|
||||||
DataElement.unsigned_integer_16(avrcp_version_int),
|
DataElement.unsigned_integer_16(avrcp_version_int),
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
@@ -170,7 +161,7 @@ def make_target_service_sdp_records(
|
|||||||
SDP_SERVICE_CLASS_ID_LIST_ATTRIBUTE_ID,
|
SDP_SERVICE_CLASS_ID_LIST_ATTRIBUTE_ID,
|
||||||
DataElement.sequence(
|
DataElement.sequence(
|
||||||
[
|
[
|
||||||
DataElement.uuid(BT_AV_REMOTE_CONTROL_TARGET_SERVICE),
|
DataElement.uuid(core.BT_AV_REMOTE_CONTROL_TARGET_SERVICE),
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -180,13 +171,13 @@ def make_target_service_sdp_records(
|
|||||||
[
|
[
|
||||||
DataElement.sequence(
|
DataElement.sequence(
|
||||||
[
|
[
|
||||||
DataElement.uuid(BT_L2CAP_PROTOCOL_ID),
|
DataElement.uuid(core.BT_L2CAP_PROTOCOL_ID),
|
||||||
DataElement.unsigned_integer_16(avctp.AVCTP_PSM),
|
DataElement.unsigned_integer_16(avctp.AVCTP_PSM),
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
DataElement.sequence(
|
DataElement.sequence(
|
||||||
[
|
[
|
||||||
DataElement.uuid(BT_AVCTP_PROTOCOL_ID),
|
DataElement.uuid(core.BT_AVCTP_PROTOCOL_ID),
|
||||||
DataElement.unsigned_integer_16(avctp_version_int),
|
DataElement.unsigned_integer_16(avctp_version_int),
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
@@ -199,7 +190,7 @@ def make_target_service_sdp_records(
|
|||||||
[
|
[
|
||||||
DataElement.sequence(
|
DataElement.sequence(
|
||||||
[
|
[
|
||||||
DataElement.uuid(BT_AV_REMOTE_CONTROL_SERVICE),
|
DataElement.uuid(core.BT_AV_REMOTE_CONTROL_SERVICE),
|
||||||
DataElement.unsigned_integer_16(avrcp_version_int),
|
DataElement.unsigned_integer_16(avrcp_version_int),
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
@@ -1208,7 +1199,7 @@ class Protocol(utils.EventEmitter):
|
|||||||
def _delegate_command(
|
def _delegate_command(
|
||||||
self, transaction_label: int, command: Command, method: Awaitable
|
self, transaction_label: int, command: Command, method: Awaitable
|
||||||
) -> None:
|
) -> None:
|
||||||
async def call():
|
async def call() -> None:
|
||||||
try:
|
try:
|
||||||
await method
|
await method
|
||||||
except Delegate.Error as error:
|
except Delegate.Error as error:
|
||||||
@@ -1412,7 +1403,7 @@ class Protocol(utils.EventEmitter):
|
|||||||
def notify_track_changed(self, identifier: bytes) -> None:
|
def notify_track_changed(self, identifier: bytes) -> None:
|
||||||
"""Notify the connected peer of a Track change."""
|
"""Notify the connected peer of a Track change."""
|
||||||
if len(identifier) != 8:
|
if len(identifier) != 8:
|
||||||
raise InvalidArgumentError("identifier must be 8 bytes")
|
raise core.InvalidArgumentError("identifier must be 8 bytes")
|
||||||
self.notify_event(TrackChangedEvent(identifier))
|
self.notify_event(TrackChangedEvent(identifier))
|
||||||
|
|
||||||
def notify_playback_position_changed(self, position: int) -> None:
|
def notify_playback_position_changed(self, position: int) -> None:
|
||||||
@@ -1679,7 +1670,7 @@ class Protocol(utils.EventEmitter):
|
|||||||
else:
|
else:
|
||||||
logger.debug("unexpected PDU ID")
|
logger.debug("unexpected PDU ID")
|
||||||
pending_command.response.set_exception(
|
pending_command.response.set_exception(
|
||||||
ProtocolError(
|
core.ProtocolError(
|
||||||
error_code=None,
|
error_code=None,
|
||||||
error_namespace="avrcp",
|
error_namespace="avrcp",
|
||||||
details="unexpected PDU ID",
|
details="unexpected PDU ID",
|
||||||
@@ -1688,7 +1679,7 @@ class Protocol(utils.EventEmitter):
|
|||||||
else:
|
else:
|
||||||
logger.debug("unexpected response code")
|
logger.debug("unexpected response code")
|
||||||
pending_command.response.set_exception(
|
pending_command.response.set_exception(
|
||||||
ProtocolError(
|
core.ProtocolError(
|
||||||
error_code=None,
|
error_code=None,
|
||||||
error_namespace="avrcp",
|
error_namespace="avrcp",
|
||||||
details="unexpected response code",
|
details="unexpected response code",
|
||||||
@@ -1866,12 +1857,12 @@ class Protocol(utils.EventEmitter):
|
|||||||
) -> None:
|
) -> None:
|
||||||
logger.debug(f"<<< AVRCP command PDU: {command}")
|
logger.debug(f"<<< AVRCP command PDU: {command}")
|
||||||
|
|
||||||
async def get_supported_events():
|
async def get_supported_events() -> None:
|
||||||
if (
|
if (
|
||||||
command.capability_id
|
command.capability_id
|
||||||
!= GetCapabilitiesCommand.CapabilityId.EVENTS_SUPPORTED
|
!= GetCapabilitiesCommand.CapabilityId.EVENTS_SUPPORTED
|
||||||
):
|
):
|
||||||
raise Protocol.InvalidParameterError
|
raise core.InvalidArgumentError()
|
||||||
|
|
||||||
supported_events = await self.delegate.get_supported_events()
|
supported_events = await self.delegate.get_supported_events()
|
||||||
self.send_avrcp_response(
|
self.send_avrcp_response(
|
||||||
@@ -1887,7 +1878,7 @@ class Protocol(utils.EventEmitter):
|
|||||||
) -> None:
|
) -> None:
|
||||||
logger.debug(f"<<< AVRCP command PDU: {command}")
|
logger.debug(f"<<< AVRCP command PDU: {command}")
|
||||||
|
|
||||||
async def set_absolute_volume():
|
async def set_absolute_volume() -> None:
|
||||||
await self.delegate.set_absolute_volume(command.volume)
|
await self.delegate.set_absolute_volume(command.volume)
|
||||||
effective_volume = await self.delegate.get_absolute_volume()
|
effective_volume = await self.delegate.get_absolute_volume()
|
||||||
self.send_avrcp_response(
|
self.send_avrcp_response(
|
||||||
@@ -1903,7 +1894,7 @@ class Protocol(utils.EventEmitter):
|
|||||||
) -> None:
|
) -> None:
|
||||||
logger.debug(f"<<< AVRCP command PDU: {command}")
|
logger.debug(f"<<< AVRCP command PDU: {command}")
|
||||||
|
|
||||||
async def register_notification():
|
async def register_notification() -> None:
|
||||||
# Check if the event is supported.
|
# Check if the event is supported.
|
||||||
supported_events = await self.delegate.get_supported_events()
|
supported_events = await self.delegate.get_supported_events()
|
||||||
if command.event_id not in supported_events:
|
if command.event_id not in supported_events:
|
||||||
|
|||||||
Reference in New Issue
Block a user