mirror of
https://github.com/google/bumble.git
synced 2026-06-01 07:37:02 +00:00
AVDTP: Make local stream endpoint in_use dyanmic property
This commit is contained in:
+29
-26
@@ -17,6 +17,7 @@
|
|||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import abc
|
||||||
import asyncio
|
import asyncio
|
||||||
import enum
|
import enum
|
||||||
import logging
|
import logging
|
||||||
@@ -1946,9 +1947,6 @@ class Stream:
|
|||||||
await self.rtp_channel.disconnect()
|
await self.rtp_channel.disconnect()
|
||||||
self.rtp_channel = None
|
self.rtp_channel = None
|
||||||
|
|
||||||
# Release the endpoint
|
|
||||||
self.local_endpoint.in_use = 0
|
|
||||||
|
|
||||||
self.change_state(State.IDLE)
|
self.change_state(State.IDLE)
|
||||||
|
|
||||||
async def on_set_configuration_command(
|
async def on_set_configuration_command(
|
||||||
@@ -2039,7 +2037,6 @@ class Stream:
|
|||||||
|
|
||||||
if self.rtp_channel is None:
|
if self.rtp_channel is None:
|
||||||
# No channel to release, we're done
|
# No channel to release, we're done
|
||||||
self.local_endpoint.in_use = 0
|
|
||||||
self.change_state(State.IDLE)
|
self.change_state(State.IDLE)
|
||||||
else:
|
else:
|
||||||
# TODO: set a timer as we wait for the RTP channel to be closed
|
# TODO: set a timer as we wait for the RTP channel to be closed
|
||||||
@@ -2051,7 +2048,6 @@ class Stream:
|
|||||||
await self.local_endpoint.on_abort_command()
|
await self.local_endpoint.on_abort_command()
|
||||||
if self.rtp_channel is None:
|
if self.rtp_channel is None:
|
||||||
# No need to wait
|
# No need to wait
|
||||||
self.local_endpoint.in_use = 0
|
|
||||||
self.change_state(State.IDLE)
|
self.change_state(State.IDLE)
|
||||||
else:
|
else:
|
||||||
# Wait for the RTP channel to be closed
|
# Wait for the RTP channel to be closed
|
||||||
@@ -2074,7 +2070,6 @@ class Stream:
|
|||||||
def on_l2cap_channel_close(self) -> None:
|
def on_l2cap_channel_close(self) -> None:
|
||||||
logger.debug(color('<<< stream channel closed', 'magenta'))
|
logger.debug(color('<<< stream channel closed', 'magenta'))
|
||||||
self.local_endpoint.on_rtp_channel_close()
|
self.local_endpoint.on_rtp_channel_close()
|
||||||
self.local_endpoint.in_use = 0
|
|
||||||
self.rtp_channel = None
|
self.rtp_channel = None
|
||||||
|
|
||||||
if self.state in (State.CLOSING, State.ABORTING):
|
if self.state in (State.CLOSING, State.ABORTING):
|
||||||
@@ -2099,7 +2094,6 @@ class Stream:
|
|||||||
self.state = State.IDLE
|
self.state = State.IDLE
|
||||||
|
|
||||||
local_endpoint.stream = self
|
local_endpoint.stream = self
|
||||||
local_endpoint.in_use = 1
|
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return (
|
return (
|
||||||
@@ -2109,14 +2103,16 @@ class Stream:
|
|||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
@dataclass
|
class StreamEndPoint(abc.ABC):
|
||||||
class StreamEndPoint:
|
|
||||||
seid: int
|
seid: int
|
||||||
media_type: MediaType
|
media_type: MediaType
|
||||||
tsep: StreamEndPointType
|
tsep: StreamEndPointType
|
||||||
in_use: int
|
|
||||||
capabilities: Iterable[ServiceCapabilities]
|
capabilities: Iterable[ServiceCapabilities]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def in_use(self) -> int:
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
class StreamEndPointProxy:
|
class StreamEndPointProxy:
|
||||||
@@ -2156,21 +2152,30 @@ class DiscoveredStreamEndPoint(StreamEndPoint, StreamEndPointProxy):
|
|||||||
in_use: int,
|
in_use: int,
|
||||||
capabilities: Iterable[ServiceCapabilities],
|
capabilities: Iterable[ServiceCapabilities],
|
||||||
) -> None:
|
) -> None:
|
||||||
StreamEndPoint.__init__(
|
# StreamEndPoint attributes
|
||||||
self,
|
self.seid = seid
|
||||||
seid=seid,
|
self.media_type = media_type
|
||||||
media_type=media_type,
|
self.tsep = tsep
|
||||||
tsep=tsep,
|
self._in_use = in_use
|
||||||
in_use=in_use,
|
self.capabilities = capabilities
|
||||||
capabilities=capabilities,
|
|
||||||
)
|
|
||||||
StreamEndPointProxy.__init__(self, protocol=protocol, seid=seid)
|
StreamEndPointProxy.__init__(self, protocol=protocol, seid=seid)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def in_use(self) -> int:
|
||||||
|
return self._in_use
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
class LocalStreamEndPoint(StreamEndPoint, utils.EventEmitter):
|
class LocalStreamEndPoint(StreamEndPoint, utils.EventEmitter):
|
||||||
stream: Stream | None
|
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_CONFIGURATION = "configuration"
|
||||||
EVENT_OPEN = "open"
|
EVENT_OPEN = "open"
|
||||||
EVENT_START = "start"
|
EVENT_START = "start"
|
||||||
@@ -2193,15 +2198,13 @@ class LocalStreamEndPoint(StreamEndPoint, utils.EventEmitter):
|
|||||||
capabilities: Iterable[ServiceCapabilities],
|
capabilities: Iterable[ServiceCapabilities],
|
||||||
configuration: Iterable[ServiceCapabilities] | None = None,
|
configuration: Iterable[ServiceCapabilities] | None = None,
|
||||||
):
|
):
|
||||||
StreamEndPoint.__init__(
|
|
||||||
self,
|
|
||||||
seid=seid,
|
|
||||||
media_type=media_type,
|
|
||||||
tsep=tsep,
|
|
||||||
in_use=0,
|
|
||||||
capabilities=capabilities,
|
|
||||||
)
|
|
||||||
utils.EventEmitter.__init__(self)
|
utils.EventEmitter.__init__(self)
|
||||||
|
# StreamEndPoint attributes
|
||||||
|
self.seid = seid
|
||||||
|
self.media_type = media_type
|
||||||
|
self.tsep = tsep
|
||||||
|
self.capabilities = capabilities
|
||||||
|
|
||||||
self.protocol = protocol
|
self.protocol = protocol
|
||||||
self.configuration = configuration if configuration is not None else []
|
self.configuration = configuration if configuration is not None else []
|
||||||
self.stream = None
|
self.stream = None
|
||||||
|
|||||||
Reference in New Issue
Block a user