diff options
author | Charlie Boutier <charliebout@google.com> | 2021-11-03 13:53:18 +0000 |
---|---|---|
committer | Charlie Boutier <charliebout@google.com> | 2021-11-09 16:13:32 +0000 |
commit | b18f8bfb854667b3c11a2b4a3f771b78fa01119a (patch) | |
tree | 5b6e663411c771bb8e7210caa9ecd38040a00e57 | |
parent | 6e7447ca74ccd2fc2b716c2619f3fe91475581c7 (diff) | |
download | mmi2grpc-b18f8bfb854667b3c11a2b4a3f771b78fa01119a.tar.gz |
a2dp: add mmi
Change-Id: I015fd6f7a9da6ac67a7ce583021d1e5074f54d8c
-rw-r--r-- | mmi2grpc/a2dp.py | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/mmi2grpc/a2dp.py b/mmi2grpc/a2dp.py index 45c62c0..60a55fd 100644 --- a/mmi2grpc/a2dp.py +++ b/mmi2grpc/a2dp.py @@ -17,6 +17,18 @@ def _ensure_connection(host, addr): if not _connection: _connection = host.GetConnection(address=addr).connection +def _ensure_sink_open(host, a2dp, addr): + global _connection, _sink, _source + _ensure_connection(host, addr) + if not _sink: + _sink = a2dp.OpenSink(connection=_connection).sink + +def _ensure_source_open(host, a2dp, addr): + global _connection, _source + _ensure_connection(host, addr) + if not _source: + _source = a2dp.OpenSource(connection=_connection).source + def interact(channel: Channel, interaction_id: str, test: str, pts_addr: bytes): global _connection, _sink, _source a2dp = A2DP(channel) @@ -24,9 +36,13 @@ def interact(channel: Channel, interaction_id: str, test: str, pts_addr: bytes): if interaction_id == "TSC_AVDTP_mmi_iut_accept_connect": host.SetConnectable(connectable=True) elif interaction_id == "TSC_AVDTP_mmi_iut_initiate_start": - _connection = host.Connect(address=pts_addr).connection + _ensure_connection(host, pts_addr) if "SNK" in test: - _sink = a2dp.OpenSink(connection=_connection).sink + _ensure_sink_open(host, a2dp, pts_addr) + a2dp.Start(sink=_sink) + if "SRC" in test: + _ensure_source_open(host, a2dp, pts_addr) + a2dp.Close(source=_source) elif interaction_id == "TSC_AVDTP_mmi_iut_initiate_out_of_range": _ensure_connection(host, pts_addr) host.Disconnect(connection=_connection) @@ -39,6 +55,32 @@ def interact(channel: Channel, interaction_id: str, test: str, pts_addr: bytes): _connection = host.Connect(address=pts_addr).connection if "SRC" in test: _source = a2dp.OpenSource(connection=_connection).source + if "SNK" in test: + _sink = a2dp.OpenSink(connection=_connection).sink + elif interaction_id == "TSC_AVDTP_mmi_iut_initiate_open_stream": + _ensure_connection(host, pts_addr) + if "SNK" in test: + _sink = a2dp.OpenSink(connection=_connection).sink + if "SRC" in test: + _source = a2dp.OpenSource(connection=_connection).source + elif interaction_id == "TSC_AVDTP_mmi_iut_initiate_close_stream": + _ensure_connection(host, pts_addr) + if "SNK" in test: + _ensure_sink_open(host, a2dp, pts_addr) + a2dp.Close(sink=_sink) + _sink = None + if "SRC" in test: + _ensure_source_open(host, a2dp, pts_addr) + a2dp.Close(source=_source) + _source = None + elif interaction_id == "TSC_AVDTP_mmi_iut_initiate_suspend": + _ensure_connection(host, pts_addr) + if "SNK" in test: + _ensure_sink_open(host, a2dp, pts_addr) + a2dp.Suspend(sink=_sink) + if "SRC" in test: + _ensure_source_open(host, a2dp, pts_addr) + a2dp.suspend(source=_source) elif interaction_id == "TSC_AVDTP_mmi_iut_accept_close_stream": pass elif interaction_id == "TSC_AVDTP_mmi_iut_accept_get_capabilities": @@ -53,5 +95,7 @@ def interact(channel: Channel, interaction_id: str, test: str, pts_addr: bytes): pass elif interaction_id == "TSC_AVDTP_mmi_iut_accept_reconnect": pass + elif interaction_id == "TSC_AVDTP_mmi_iut_accept_suspend": + pass else: print(f'MMI NOT IMPLEMENTED: {interaction_id}') |