1717# -----------------------------------------------------------------------------
1818from __future__ import annotations
1919
20+ import abc
2021import asyncio
2122import enum
2223import logging
@@ -1946,9 +1947,6 @@ async def close(self) -> None:
19461947 await self .rtp_channel .disconnect ()
19471948 self .rtp_channel = None
19481949
1949- # Release the endpoint
1950- self .local_endpoint .in_use = 0
1951-
19521950 self .change_state (State .IDLE )
19531951
19541952 async def on_set_configuration_command (
@@ -2039,7 +2037,6 @@ async def on_close_command(self) -> Message | None:
20392037
20402038 if self .rtp_channel is None :
20412039 # No channel to release, we're done
2042- self .local_endpoint .in_use = 0
20432040 self .change_state (State .IDLE )
20442041 else :
20452042 # TODO: set a timer as we wait for the RTP channel to be closed
@@ -2051,7 +2048,6 @@ async def on_abort_command(self) -> Message | None:
20512048 await self .local_endpoint .on_abort_command ()
20522049 if self .rtp_channel is None :
20532050 # No need to wait
2054- self .local_endpoint .in_use = 0
20552051 self .change_state (State .IDLE )
20562052 else :
20572053 # Wait for the RTP channel to be closed
@@ -2074,7 +2070,6 @@ def on_l2cap_channel_open(self) -> None:
20742070 def on_l2cap_channel_close (self ) -> None :
20752071 logger .debug (color ('<<< stream channel closed' , 'magenta' ))
20762072 self .local_endpoint .on_rtp_channel_close ()
2077- self .local_endpoint .in_use = 0
20782073 self .rtp_channel = None
20792074
20802075 if self .state in (State .CLOSING , State .ABORTING ):
@@ -2099,7 +2094,6 @@ def __init__(
20992094 self .state = State .IDLE
21002095
21012096 local_endpoint .stream = self
2102- local_endpoint .in_use = 1
21032097
21042098 def __str__ (self ) -> str :
21052099 return (
@@ -2109,14 +2103,16 @@ def __str__(self) -> str:
21092103
21102104
21112105# -----------------------------------------------------------------------------
2112- @dataclass
2113- class StreamEndPoint :
2106+ class StreamEndPoint (abc .ABC ):
21142107 seid : int
21152108 media_type : MediaType
21162109 tsep : StreamEndPointType
2117- in_use : int
21182110 capabilities : Iterable [ServiceCapabilities ]
21192111
2112+ @property
2113+ def in_use (self ) -> int :
2114+ raise NotImplementedError ()
2115+
21202116
21212117# -----------------------------------------------------------------------------
21222118class StreamEndPointProxy :
@@ -2156,14 +2152,30 @@ def __init__(
21562152 in_use : int ,
21572153 capabilities : Iterable [ServiceCapabilities ],
21582154 ) -> None :
2159- StreamEndPoint .__init__ (self , seid , media_type , tsep , in_use , capabilities )
2160- StreamEndPointProxy .__init__ (self , protocol , seid )
2155+ # StreamEndPoint attributes
2156+ self .seid = seid
2157+ self .media_type = media_type
2158+ self .tsep = tsep
2159+ self ._in_use = in_use
2160+ self .capabilities = capabilities
2161+
2162+ StreamEndPointProxy .__init__ (self , protocol = protocol , seid = seid )
2163+
2164+ @property
2165+ def in_use (self ) -> int :
2166+ return self ._in_use
21612167
21622168
21632169# -----------------------------------------------------------------------------
21642170class LocalStreamEndPoint (StreamEndPoint , utils .EventEmitter ):
21652171 stream : Stream | None
21662172
2173+ @property
2174+ def in_use (self ) -> int :
2175+ if self .stream and self .stream .state != State .IDLE :
2176+ return 1
2177+ return 0
2178+
21672179 EVENT_CONFIGURATION = "configuration"
21682180 EVENT_OPEN = "open"
21692181 EVENT_START = "start"
@@ -2186,8 +2198,13 @@ def __init__(
21862198 capabilities : Iterable [ServiceCapabilities ],
21872199 configuration : Iterable [ServiceCapabilities ] | None = None ,
21882200 ):
2189- StreamEndPoint .__init__ (self , seid , media_type , tsep , 0 , capabilities )
21902201 utils .EventEmitter .__init__ (self )
2202+ # StreamEndPoint attributes
2203+ self .seid = seid
2204+ self .media_type = media_type
2205+ self .tsep = tsep
2206+ self .capabilities = capabilities
2207+
21912208 self .protocol = protocol
21922209 self .configuration = configuration if configuration is not None else []
21932210 self .stream = None
@@ -2273,12 +2290,12 @@ def __init__(
22732290 codec_capabilities ,
22742291 ] + list (other_capabilities )
22752292 super ().__init__ (
2276- protocol ,
2277- seid ,
2278- codec_capabilities .media_type ,
2279- AVDTP_TSEP_SRC ,
2280- capabilities ,
2281- capabilities ,
2293+ protocol = protocol ,
2294+ seid = seid ,
2295+ media_type = codec_capabilities .media_type ,
2296+ tsep = AVDTP_TSEP_SRC ,
2297+ capabilities = capabilities ,
2298+ configuration = capabilities ,
22822299 )
22832300 self .packet_pump = packet_pump
22842301
@@ -2317,11 +2334,11 @@ def __init__(
23172334 codec_capabilities ,
23182335 ]
23192336 super ().__init__ (
2320- protocol ,
2321- seid ,
2322- codec_capabilities .media_type ,
2323- AVDTP_TSEP_SNK ,
2324- capabilities ,
2337+ protocol = protocol ,
2338+ seid = seid ,
2339+ media_type = codec_capabilities .media_type ,
2340+ tsep = AVDTP_TSEP_SNK ,
2341+ capabilities = capabilities ,
23252342 )
23262343
23272344 def on_rtp_channel_open (self ) -> None :
0 commit comments