Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 41 additions & 24 deletions bumble/avdtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# -----------------------------------------------------------------------------
from __future__ import annotations

import abc
import asyncio
import enum
import logging
Expand Down Expand Up @@ -1946,9 +1947,6 @@ async def close(self) -> None:
await self.rtp_channel.disconnect()
self.rtp_channel = None

# Release the endpoint
self.local_endpoint.in_use = 0

self.change_state(State.IDLE)

async def on_set_configuration_command(
Expand Down Expand Up @@ -2039,7 +2037,6 @@ async def on_close_command(self) -> Message | None:

if self.rtp_channel is None:
# No channel to release, we're done
self.local_endpoint.in_use = 0
self.change_state(State.IDLE)
else:
# TODO: set a timer as we wait for the RTP channel to be closed
Expand All @@ -2051,7 +2048,6 @@ async def on_abort_command(self) -> Message | None:
await self.local_endpoint.on_abort_command()
if self.rtp_channel is None:
# No need to wait
self.local_endpoint.in_use = 0
self.change_state(State.IDLE)
else:
# Wait for the RTP channel to be closed
Expand All @@ -2074,7 +2070,6 @@ def on_l2cap_channel_open(self) -> None:
def on_l2cap_channel_close(self) -> None:
logger.debug(color('<<< stream channel closed', 'magenta'))
self.local_endpoint.on_rtp_channel_close()
self.local_endpoint.in_use = 0
self.rtp_channel = None

if self.state in (State.CLOSING, State.ABORTING):
Expand All @@ -2099,7 +2094,6 @@ def __init__(
self.state = State.IDLE

local_endpoint.stream = self
local_endpoint.in_use = 1

def __str__(self) -> str:
return (
Expand All @@ -2109,14 +2103,16 @@ def __str__(self) -> str:


# -----------------------------------------------------------------------------
@dataclass
class StreamEndPoint:
class StreamEndPoint(abc.ABC):
seid: int
media_type: MediaType
tsep: StreamEndPointType
in_use: int
capabilities: Iterable[ServiceCapabilities]

@property
def in_use(self) -> int:
raise NotImplementedError()


# -----------------------------------------------------------------------------
class StreamEndPointProxy:
Expand Down Expand Up @@ -2156,14 +2152,30 @@ def __init__(
in_use: int,
capabilities: Iterable[ServiceCapabilities],
) -> None:
StreamEndPoint.__init__(self, seid, media_type, tsep, in_use, capabilities)
StreamEndPointProxy.__init__(self, protocol, seid)
# StreamEndPoint attributes
self.seid = seid
self.media_type = media_type
self.tsep = tsep
self._in_use = in_use
self.capabilities = capabilities

StreamEndPointProxy.__init__(self, protocol=protocol, seid=seid)

@property
def in_use(self) -> int:
return self._in_use


# -----------------------------------------------------------------------------
class LocalStreamEndPoint(StreamEndPoint, utils.EventEmitter):
stream: Stream | None

@property
def in_use(self) -> int:
if self.stream and self.stream.state != State.IDLE:
return 1
return 0

EVENT_CONFIGURATION = "configuration"
EVENT_OPEN = "open"
EVENT_START = "start"
Expand All @@ -2186,8 +2198,13 @@ def __init__(
capabilities: Iterable[ServiceCapabilities],
configuration: Iterable[ServiceCapabilities] | None = None,
):
StreamEndPoint.__init__(self, seid, media_type, tsep, 0, capabilities)
utils.EventEmitter.__init__(self)
# StreamEndPoint attributes
self.seid = seid
self.media_type = media_type
self.tsep = tsep
self.capabilities = capabilities

self.protocol = protocol
self.configuration = configuration if configuration is not None else []
self.stream = None
Expand Down Expand Up @@ -2273,12 +2290,12 @@ def __init__(
codec_capabilities,
] + list(other_capabilities)
super().__init__(
protocol,
seid,
codec_capabilities.media_type,
AVDTP_TSEP_SRC,
capabilities,
capabilities,
protocol=protocol,
seid=seid,
media_type=codec_capabilities.media_type,
tsep=AVDTP_TSEP_SRC,
capabilities=capabilities,
configuration=capabilities,
)
self.packet_pump = packet_pump

Expand Down Expand Up @@ -2317,11 +2334,11 @@ def __init__(
codec_capabilities,
]
super().__init__(
protocol,
seid,
codec_capabilities.media_type,
AVDTP_TSEP_SNK,
capabilities,
protocol=protocol,
seid=seid,
media_type=codec_capabilities.media_type,
tsep=AVDTP_TSEP_SNK,
capabilities=capabilities,
)

def on_rtp_channel_open(self) -> None:
Expand Down
Loading