From 9bc6b35cb99864f4e656002f342394d8ce671abd Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Sat, 5 Dec 2026 19:10:35 +0000 Subject: [PATCH] sof-ucm: Align PCM and transducer columns to minimize edge crossings - graph_builder.py: Prevent fe_stream_to_pcm_nid from matching physical card transducer widgets, and add _demote_non_terminal_codec_endpoints() so intermediate codec pins (rt722 HP/SPK/MIC2, dmic-codec DMic) stay in the center Codec zone while only terminal physical transducers occupy the right Endpoint column. - layout.py: Group middle lanes sharing a downstream Endpoint, infer lane playback vs. capture from pipelines/PCMs/endpoints, add 2-pass barycenter column sorting plus ALAP pulling for root codec supply widgets (e.g. SDCA PDEs), and sort/pack both the left PCM column and right Endpoint column opposite their connected middle nodes. - tests/test_tplg_and_graph.py: Add unit test test_pcm_and_endpoint_columns_align_without_crossings covering codec-pin demotion, Deepbuffer/PCM31 grouping, and playback/capture vertical ordering. Signed-off-by: Liam Girdwood --- sof-ucm/sof_ucm/graph_builder.py | 27 ++- sof-ucm/sof_ucm/layout.py | 287 +++++++++++++++++++-------- sof-ucm/tests/test_tplg_and_graph.py | 89 +++++++++ 3 files changed, 324 insertions(+), 79 deletions(-) diff --git a/sof-ucm/sof_ucm/graph_builder.py b/sof-ucm/sof_ucm/graph_builder.py index 934a9b4..e97ea25 100644 --- a/sof-ucm/sof_ucm/graph_builder.py +++ b/sof-ucm/sof_ucm/graph_builder.py @@ -313,7 +313,7 @@ def build_end_to_end_graph( continue # Map FE DAI stream stubs on DSP component directly to their PCM node! - if dw.name in fe_stream_to_pcm_nid: + if dw.component != "card" and dw.name in fe_stream_to_pcm_nid: pcm_nid = fe_stream_to_pcm_nid[dw.name] dapm_node_by_key[key] = pcm_nid dapm_node_by_name.setdefault(dw.name, pcm_nid) @@ -377,6 +377,11 @@ def build_end_to_end_graph( # 5. Synthesize Hardware Endpoints only for remaining dangling DAI/PCM paths _synthesize_missing_endpoints(snap, vm, pcm_node_by_dev_dir) + # 5b. Demote intermediate codec pin widgets (e.g. rt722 HP/SPK/MIC2, dmic-codec DMic) + # that connect directly to a physical card transducer endpoint, so only true terminal + # transducers remain in the right-hand Endpoint column. + _demote_non_terminal_codec_endpoints(vm) + # 6. Attach Kcontrols to Edges and Owning Nodes _attach_kcontrols(snap, vm, pcm_node_by_dev_dir, tplg_node_by_wname, hda_ctl_to_nid, include_readonly_masks) @@ -694,6 +699,26 @@ def _add_edge( return edge +def _demote_non_terminal_codec_endpoints(vm: UcmGraphViewModel) -> None: + """Keep only terminal physical transducers as Endpoints; internal codec pins stay Codec.""" + to_demote: Set[str] = set() + for e in vm.edges: + u = vm.nodes.get(e.source_node) + v = vm.nodes.get(e.sink_node) + if not u or not v: + continue + if u.class_category == "Endpoint" and v.class_category == "Endpoint": + if u.component != "card" and (v.component == "card" or u.direction == "playback"): + to_demote.add(u.id) + elif v.component != "card" and (u.component == "card" or v.direction == "capture"): + to_demote.add(v.id) + for nid in to_demote: + n = vm.nodes.get(nid) + if n: + n.class_category = "Codec" + n.category = "codec" + + def _synthesize_missing_endpoints( snap: MachineAudioSnapshot, vm: UcmGraphViewModel, diff --git a/sof-ucm/sof_ucm/layout.py b/sof-ucm/sof_ucm/layout.py index 4d5a1fa..a9c48c0 100644 --- a/sof-ucm/sof_ucm/layout.py +++ b/sof-ucm/sof_ucm/layout.py @@ -260,8 +260,40 @@ def group_height(nid: str) -> float: return total_w, total_h +def _pack_column_near_targets( + ordered_ids: List[str], + dims: Dict[str, Tuple[float, float]], + target_centers: Dict[str, float], + min_y: float, + gap: float, +) -> Dict[str, float]: + """Place ordered vertical column blocks as close to neighbor target Y centers as possible without overlap.""" + ys: Dict[str, float] = {} + if not ordered_ids: + return ys + cursor = min_y + for nid in ordered_ids: + _bw, bh = dims[nid] + tc = target_centers.get(nid) + desired = (tc - bh * 0.5) if (tc is not None and tc < 1e8) else cursor + y = max(cursor, desired) + ys[nid] = y + cursor = y + bh + gap + for i in range(len(ordered_ids) - 2, -1, -1): + nid = ordered_ids[i] + nxt = ordered_ids[i + 1] + _bw, bh = dims[nid] + tc = target_centers.get(nid) + if tc is not None and tc < 1e8: + desired = tc - bh * 0.5 + max_allowed = ys[nxt] - gap - bh + if ys[nid] < desired: + ys[nid] = min(desired, max_allowed) + return ys + + def layout_end_to_end_graph(vm: UcmGraphViewModel, mirror_capture: bool = False) -> None: - """Layout end-to-end pipelines in 3 columnar zones: PCMs (left) -> Middle DSP/Codecs -> Endpoints (right).""" + """Layout end-to-end pipelines in 3 crossing-minimized columns: PCMs (left) -> DSP/Codecs -> Endpoints (right).""" if not vm.nodes: return @@ -300,15 +332,6 @@ def layout_end_to_end_graph(vm: UcmGraphViewModel, mirror_capture: bool = False) margin_x = 56.0 margin_y = 56.0 - # --- Zone 1 (Left Vertical Column): ALL PCM nodes --- - def pcm_sort_key(nid: str) -> Tuple[int, int, str, str]: - n = vm.nodes[nid] - dev = n.pcm_info.device_id if n.pcm_info is not None else 999 - d_ord = 0 if n.direction == "playback" else 1 - return (d_ord, dev, n.title, nid) - - pcm_ids.sort(key=pcm_sort_key) - single_dims: Dict[str, Tuple[float, float]] = {} orig_x: Dict[str, float] = {} for nid in pcm_ids + ep_ids: @@ -325,20 +348,11 @@ def shift_single_node(nid: str, dx: float, dy: float) -> None: pcm_left_overhang = max((orig_x[nid] for nid in pcm_ids), default=0.0) pcm_card_x = margin_x + pcm_left_overhang - cur_pcm_y = 0.0 left_col_right_edge = margin_x for nid in pcm_ids: - bw, bh = single_dims[nid] + bw, _bh = single_dims[nid] dx = pcm_card_x - orig_x[nid] - shift_single_node(nid, dx, cur_pcm_y) left_col_right_edge = max(left_col_right_edge, dx + bw) - cur_pcm_y += bh + SUPER_GAP_Y - pcm_total_h = max(0.0, cur_pcm_y - SUPER_GAP_Y) if pcm_ids else 0.0 - - # Preliminary PCM vertical rank / y for ordering middle lanes cleanly - pcm_center_y: Dict[str, float] = { - nid: vm.nodes[nid].y + vm.nodes[nid].height * 0.5 for nid in pcm_ids - } # --- Zone 2 (Middle Columns): PipelineContainers + DSP/Codec widgets --- def mid_super_id_of(nid: str) -> str: @@ -371,7 +385,6 @@ def mid_super_id_of(nid: str) -> str: bw, bh = _layout_dag_block(vm, [nid], ctrl_by_parent, [], mirror_capture=True) super_dims[sid] = (bw, bh) - # Full node adjacency to associate middle nodes/lanes with connected PCMs and Endpoints all_nbrs: Dict[str, Set[str]] = defaultdict(set) mid_undir: Dict[str, Set[str]] = defaultdict(set) super_edges: Set[Tuple[str, str]] = set() @@ -392,27 +405,31 @@ def mid_super_id_of(nid: str) -> str: else: super_edges.add((su, sv)) - # Find connected PCMs reachable from any node without crossing other PCMs/Endpoints - def connected_pcm_ys_for_member(nid: str) -> List[float]: - ys: List[float] = [] - seen_n: Set[str] = {nid} - dq = deque([nid]) + pcm_dev_of: Dict[str, int] = { + nid: (vm.nodes[nid].pcm_info.device_id if vm.nodes[nid].pcm_info is not None else 999) + for nid in pcm_ids + } + + def connected_pcm_devs_for_sid(sid: str) -> List[int]: + devs: List[int] = [] + seen_n: Set[str] = set(super_members[sid]) + dq = deque(super_members[sid]) while dq: u = dq.popleft() - if u in pcm_center_y: - ys.append(pcm_center_y[u]) + if u in pcm_dev_of: + devs.append(pcm_dev_of[u]) continue for v in all_nbrs[u]: if v not in seen_n and vm.nodes[v].class_category != "Endpoint": seen_n.add(v) dq.append(v) - return ys + return sorted(set(devs)) - def sid_pcm_bary(sid: str) -> float: - ys: List[float] = [] - for nid in super_members[sid]: - ys.extend(connected_pcm_ys_for_member(nid)) - return (sum(ys) / len(ys)) if ys else 1e9 + def sid_pcm_rank(sid: str) -> Tuple[int, float]: + devs = connected_pcm_devs_for_sid(sid) + if not devs: + return (9999, 1e9) + return (min(devs), sum(devs) / len(devs)) visited: Set[str] = set() mid_lanes: List[List[str]] = [] @@ -431,30 +448,86 @@ def sid_pcm_bary(sid: str) -> float: q.append(v) mid_lanes.append(lane) - def mid_lane_sort_key(lane: List[str]) -> Tuple[float, int, int, str]: + # Associate each middle lane with its connected Endpoints so lanes sharing an + # Endpoint (e.g. HDMI 1/2/3 -> Digital Out) stay grouped adjacently without crossings. + lane_eps: List[Set[str]] = [] + lane_min_dev: List[int] = [] + lane_has_pb: List[bool] = [] + ep_group_min_dev: Dict[str, int] = {} + for lane in mid_lanes: all_nodes = [vm.nodes[nid] for sid in lane for nid in super_members[sid]] - has_pb = any(n.direction == "playback" for n in all_nodes) - ys = [sid_pcm_bary(sid) for sid in lane] - finite_ys = [y for y in ys if y < 1e8] - avg_y = (sum(finite_ys) / len(finite_ys)) if finite_ys else 1e9 - pcm_devs = [n.pcm_info.device_id for n in all_nodes if n.pcm_info is not None] - return (avg_y, 0 if has_pb else 1, min(pcm_devs) if pcm_devs else 999, lane[0]) + pipe_or_dsp = [ + vm.nodes[nid] + for sid in lane + for nid in super_members[sid] + if sid.startswith("pipe:") or vm.nodes[nid].class_category == "Widget" + ] + devs: List[int] = [] + pb_devs: List[int] = [] + eps: Set[str] = set() + for sid in lane: + devs.extend(connected_pcm_devs_for_sid(sid)) + for nid in super_members[sid]: + for nb in all_nbrs[nid]: + if vm.nodes[nb].class_category == "Endpoint": + eps.add(nb) + elif vm.nodes[nb].class_category == "PCM" and vm.nodes[nb].direction == "playback": + pb_devs.append(pcm_dev_of[nb]) + if pb_devs: + has_pb = True + elif pipe_or_dsp: + has_pb = any(n.direction == "playback" for n in pipe_or_dsp) + elif eps: + has_pb = any(vm.nodes[eid].direction == "playback" for eid in eps) + else: + has_pb = any(n.direction == "playback" for n in all_nodes) + mdev = min(devs) if devs else 999 + lane_eps.append(eps) + lane_min_dev.append(mdev) + lane_has_pb.append(has_pb) + for ep_id in eps: + if ep_id not in ep_group_min_dev or mdev < ep_group_min_dev[ep_id]: + ep_group_min_dev[ep_id] = mdev + + lane_order = list(range(len(mid_lanes))) + + def lane_order_key(li: int) -> Tuple[int, int, str, int, str]: + eps = lane_eps[li] + mdev = lane_min_dev[li] + if eps: + # Prefer shared endpoint with smallest group min device id so shared-endpoint lanes cluster + best_ep = min(eps, key=lambda eid: (ep_group_min_dev.get(eid, 999), eid)) + grp_dev = ep_group_min_dev.get(best_ep, mdev) + else: + best_ep = "~" + grp_dev = mdev + return (0 if lane_has_pb[li] else 1, grp_dev, best_ep, mdev, mid_lanes[li][0]) - mid_lanes.sort(key=mid_lane_sort_key) + lane_order.sort(key=lane_order_key) + mid_lanes = [mid_lanes[li] for li in lane_order] def shift_super_node(sid: str, dx: float, dy: float) -> None: for nid in super_members[sid]: shift_single_node(nid, dx, dy) - cur_mid_y = 0.0 + def super_center_y(sid: str) -> float: + mem = super_members[sid] + y0 = min(vm.nodes[nid].y for nid in mem) + y1 = max(vm.nodes[nid].y + vm.nodes[nid].height for nid in mem) + return 0.5 * (y0 + y1) + + zone2_left_x = (left_col_right_edge + SUPER_GAP_X) if pcm_ids else margin_x + cur_mid_y = margin_y mid_total_w = 0.0 for lane in mid_lanes: lset = set(lane) - adj: Dict[str, List[str]] = defaultdict(list) + adj_fwd: Dict[str, List[str]] = defaultdict(list) + adj_rev: Dict[str, List[str]] = defaultdict(list) in_deg: Dict[str, int] = {sid: 0 for sid in lane} for su, sv in super_edges: if su in lset and sv in lset: - adj[su].append(sv) + adj_fwd[su].append(sv) + adj_rev[sv].append(su) in_deg[sv] += 1 col_of: Dict[str, int] = {sid: 0 for sid in lane} @@ -463,7 +536,7 @@ def shift_super_node(sid: str, dx: float, dy: float) -> None: while q: u = q.popleft() seen.add(u) - for v in adj[u]: + for v in adj_fwd[u]: col_of[v] = max(col_of[v], col_of[u] + 1) in_deg[v] -= 1 if in_deg[v] == 0: @@ -472,12 +545,30 @@ def shift_super_node(sid: str, dx: float, dy: float) -> None: if sid not in seen: col_of[sid] = max(col_of.values(), default=0) + 1 + # Pull root helper/supply codec nodes (e.g. SDCA PDEs not attached directly to PCMs) + # right next to their downstream consumer column (ALAP) instead of leaving them at col 0. + pcm_id_set = set(pcm_ids) + changed = True + while changed: + changed = False + for sid in lane: + if ( + not adj_rev[sid] + and adj_fwd[sid] + and not sid.startswith("pipe:") + and not any(all_nbrs[nid] & pcm_id_set for nid in super_members[sid]) + ): + target_c = max(0, min(col_of[v] for v in adj_fwd[sid]) - 1) + if target_c > col_of[sid]: + col_of[sid] = target_c + changed = True + cols: Dict[int, List[str]] = defaultdict(list) for sid in lane: cols[col_of[sid]].append(sid) sorted_cols = [cols[c] for c in sorted(cols.keys())] for col in sorted_cols: - col.sort(key=lambda s: (sid_pcm_bary(s), s)) + col.sort(key=lambda s: (*sid_pcm_rank(s), s)) col_heights = [ sum(super_dims[sid][1] for sid in col) + max(0, len(col) - 1) * SUPER_GAP_Y @@ -485,7 +576,32 @@ def shift_super_node(sid: str, dx: float, dy: float) -> None: ] lane_h = max(col_heights, default=120.0) - cur_x = 0.0 + if len(sorted_cols) > 1: + rank_y: Dict[str, float] = {} + for col in sorted_cols: + for idx_in_col, sid in enumerate(col): + rank_y[sid] = float(idx_in_col) + for _ in range(2): + for c_idx in range(1, len(sorted_cols)): + def _fwd_bary(s: str) -> Tuple[float, Tuple[int, float], str]: + preds = [u for u in adj_rev[s] if u in rank_y] + if preds: + return (sum(rank_y[u] for u in preds) / len(preds), sid_pcm_rank(s), s) + return (float(sid_pcm_rank(s)[0]), sid_pcm_rank(s), s) + sorted_cols[c_idx].sort(key=_fwd_bary) + for i, s in enumerate(sorted_cols[c_idx]): + rank_y[s] = float(i) + for c_idx in range(len(sorted_cols) - 2, -1, -1): + def _rev_bary(s: str) -> Tuple[float, Tuple[int, float], str]: + succs = [v for v in adj_fwd[s] if v in rank_y] + if succs: + return (sum(rank_y[v] for v in succs) / len(succs), sid_pcm_rank(s), s) + return (rank_y[s], sid_pcm_rank(s), s) + sorted_cols[c_idx].sort(key=_rev_bary) + for i, s in enumerate(sorted_cols[c_idx]): + rank_y[s] = float(i) + + cur_x = zone2_left_x for c_idx, col in enumerate(sorted_cols): col_w = max(super_dims[sid][0] for sid in col) cur_y = cur_mid_y + (lane_h - col_heights[c_idx]) / 2.0 @@ -497,36 +613,41 @@ def shift_super_node(sid: str, dx: float, dy: float) -> None: cur_y += sh + SUPER_GAP_Y cur_x += col_w + SUPER_GAP_X if sorted_cols: - mid_total_w = max(mid_total_w, cur_x - SUPER_GAP_X) + mid_total_w = max(mid_total_w, (cur_x - zone2_left_x) - SUPER_GAP_X) cur_mid_y += lane_h + LANE_GAP_Y - mid_total_h = max(0.0, cur_mid_y - LANE_GAP_Y) if mid_lanes else 0.0 - ep_total_h = ( - sum(single_dims[nid][1] for nid in ep_ids) + max(0, len(ep_ids) - 1) * SUPER_GAP_Y - if ep_ids - else 0.0 + mid_bottom_y = max(margin_y, cur_mid_y - LANE_GAP_Y) if mid_lanes else margin_y + zone2_right_edge = ( + (zone2_left_x + mid_total_w) + if mid_lanes + else (left_col_right_edge if pcm_ids else margin_x - SUPER_GAP_X) ) - max_zone_h = max(pcm_total_h, mid_total_h, ep_total_h, 120.0) + # --- Zone 1 (Left Vertical Column): Re-sort & align ALL PCMs to their middle pipelines --- + def pcm_bary_y(nid: str) -> float: + nbr_ys = [ + vm.nodes[nb].y + vm.nodes[nb].height * 0.5 + for nb in all_nbrs[nid] + if vm.nodes[nb].class_category != "PCM" + ] + return (sum(nbr_ys) / len(nbr_ys)) if nbr_ys else 1e9 - # Apply horizontal + vertical centering offsets to Zone 1 (PCMs) and Zone 2 (Middle) - pcm_y_off = margin_y + (max_zone_h - pcm_total_h) * 0.5 + pcm_targets = {nid: pcm_bary_y(nid) for nid in pcm_ids} + pcm_ids.sort( + key=lambda nid: ( + pcm_targets[nid], + 0 if vm.nodes[nid].direction == "playback" else 1, + pcm_dev_of[nid], + vm.nodes[nid].title, + nid, + ) + ) + pcm_ys = _pack_column_near_targets(pcm_ids, single_dims, pcm_targets, margin_y, SUPER_GAP_Y) for nid in pcm_ids: - shift_single_node(nid, 0.0, pcm_y_off) - - zone2_left_x = (left_col_right_edge + SUPER_GAP_X) if pcm_ids else margin_x - mid_y_off = margin_y + (max_zone_h - mid_total_h) * 0.5 - for sid in super_members: - shift_super_node(sid, zone2_left_x, mid_y_off) - - if mid_lanes: - zone2_right_edge = zone2_left_x + mid_total_w - elif pcm_ids: - zone2_right_edge = left_col_right_edge - else: - zone2_right_edge = margin_x - SUPER_GAP_X + dx = pcm_card_x - orig_x[nid] + shift_single_node(nid, dx, pcm_ys[nid]) - # --- Zone 3 (Right Vertical Column): ALL Endpoints (speakers, mics, jacks, line in/out, HDMI, etc.) --- + # --- Zone 3 (Right Vertical Column): Align ALL physical Endpoints directly to codec neighbors --- def ep_bary_y(nid: str) -> float: nbr_ys = [ vm.nodes[nb].y + vm.nodes[nb].height * 0.5 @@ -535,21 +656,31 @@ def ep_bary_y(nid: str) -> float: ] return (sum(nbr_ys) / len(nbr_ys)) if nbr_ys else 1e9 - ep_ids.sort(key=lambda nid: (ep_bary_y(nid), 0 if vm.nodes[nid].direction == "playback" else 1, vm.nodes[nid].title, nid)) - + ep_targets = {nid: ep_bary_y(nid) for nid in ep_ids} + ep_ids.sort( + key=lambda nid: ( + ep_targets[nid], + 0 if vm.nodes[nid].direction == "playback" else 1, + vm.nodes[nid].title, + nid, + ) + ) ep_left_overhang = max((orig_x[nid] for nid in ep_ids), default=0.0) ep_card_x = zone2_right_edge + SUPER_GAP_X + ep_left_overhang - cur_ep_y = margin_y + (max_zone_h - ep_total_h) * 0.5 + ep_ys = _pack_column_near_targets(ep_ids, single_dims, ep_targets, margin_y, SUPER_GAP_Y) for nid in ep_ids: - _bw, bh = single_dims[nid] dx = ep_card_x - orig_x[nid] - shift_single_node(nid, dx, cur_ep_y) - cur_ep_y += bh + SUPER_GAP_Y + shift_single_node(nid, dx, ep_ys[nid]) # Place any unparented orphan controls neatly along a bottom row + max_bottom = mid_bottom_y + if pcm_ids: + max_bottom = max(max_bottom, max(pcm_ys[nid] + single_dims[nid][1] for nid in pcm_ids)) + if ep_ids: + max_bottom = max(max_bottom, max(ep_ys[nid] + single_dims[nid][1] for nid in ep_ids)) if orphan_ctrl_ids: cur_ox = margin_x - oy = margin_y + max_zone_h + LANE_GAP_Y + oy = max_bottom + LANE_GAP_Y for cid in sorted(orphan_ctrl_ids): c = vm.nodes[cid] c.x = cur_ox diff --git a/sof-ucm/tests/test_tplg_and_graph.py b/sof-ucm/tests/test_tplg_and_graph.py index fef70e5..f58b1ed 100644 --- a/sof-ucm/tests/test_tplg_and_graph.py +++ b/sof-ucm/tests/test_tplg_and_graph.py @@ -32,9 +32,19 @@ SoundCardInfo, ) from sof_ucm.tplg_loader import ( + SND_SOC_TPLG_DAPM_AIF_IN, + SND_SOC_TPLG_DAPM_AIF_OUT, + SND_SOC_TPLG_DAPM_DAI_IN, + SND_SOC_TPLG_DAPM_DAI_OUT, + SND_SOC_TPLG_DAPM_MIXER, SND_SOC_TPLG_MAGIC, SND_SOC_TPLG_TYPE_DAI_LINK, SND_SOC_TPLG_TYPE_PCM, + TplgPcmDesc, + TplgPipelineDesc, + TplgRouteDesc, + TplgTopology, + TplgWidgetDesc, parse_tplg_bytes, parse_tplg_file, ) @@ -228,6 +238,85 @@ def test_columnar_layout_pcm_left_endpoints_right(self) -> None: for port in ep.in_ports + ep.out_ports: self.assertEqual(round(port.rel_x, 2), 0.0) + def test_pcm_and_endpoint_columns_align_without_crossings(self) -> None: + tplg = TplgTopology( + pipelines={pid: TplgPipelineDesc(pipeline_id=pid, name=f"pipeline.{pid}") for pid in (0, 1, 10, 15, 20, 50)}, + pcms=[ + TplgPcmDesc(pcm_id=0, name="Jack Out", playback_stream_name="Jack Out", playback_host_name="host-copier.0.playback"), + TplgPcmDesc(pcm_id=2, name="Speaker", playback_stream_name="Speaker", playback_host_name="host-copier.2.playback"), + TplgPcmDesc(pcm_id=5, name="HDMI1", playback_stream_name="HDMI1", playback_host_name="host-copier.5.playback"), + TplgPcmDesc(pcm_id=31, name="Deepbuffer", playback_stream_name="Deepbuffer", playback_host_name="host-copier.31.playback"), + TplgPcmDesc(pcm_id=1, name="Jack In", capture_stream_name="Jack In", capture_host_name="host-copier.1.capture"), + ], + widgets=[ + TplgWidgetDesc(comp_id=1, pipeline_id=0, dapm_type=SND_SOC_TPLG_DAPM_AIF_IN, name="host-copier.0.playback", stream_name="Jack Out"), + TplgWidgetDesc(comp_id=2, pipeline_id=15, dapm_type=SND_SOC_TPLG_DAPM_AIF_IN, name="host-copier.31.playback", stream_name="Deepbuffer"), + TplgWidgetDesc(comp_id=3, pipeline_id=1, dapm_type=SND_SOC_TPLG_DAPM_MIXER, name="mixer.1.1"), + TplgWidgetDesc(comp_id=4, pipeline_id=1, dapm_type=SND_SOC_TPLG_DAPM_DAI_IN, name="dai-copier.0"), + TplgWidgetDesc(comp_id=5, pipeline_id=20, dapm_type=SND_SOC_TPLG_DAPM_AIF_IN, name="host-copier.2.playback", stream_name="Speaker"), + TplgWidgetDesc(comp_id=6, pipeline_id=20, dapm_type=SND_SOC_TPLG_DAPM_DAI_IN, name="dai-copier.2"), + TplgWidgetDesc(comp_id=7, pipeline_id=50, dapm_type=SND_SOC_TPLG_DAPM_AIF_IN, name="host-copier.5.playback", stream_name="HDMI1"), + TplgWidgetDesc(comp_id=8, pipeline_id=50, dapm_type=SND_SOC_TPLG_DAPM_DAI_IN, name="dai-copier.5"), + TplgWidgetDesc(comp_id=9, pipeline_id=10, dapm_type=SND_SOC_TPLG_DAPM_AIF_OUT, name="host-copier.1.capture", stream_name="Jack In"), + TplgWidgetDesc(comp_id=10, pipeline_id=10, dapm_type=SND_SOC_TPLG_DAPM_DAI_OUT, name="dai-copier.1"), + ], + routes=[ + TplgRouteDesc(source_name="host-copier.0.playback", sink_name="mixer.1.1"), + TplgRouteDesc(source_name="host-copier.31.playback", sink_name="mixer.1.1"), + TplgRouteDesc(source_name="mixer.1.1", sink_name="dai-copier.0"), + TplgRouteDesc(source_name="host-copier.2.playback", sink_name="dai-copier.2"), + TplgRouteDesc(source_name="host-copier.5.playback", sink_name="dai-copier.5"), + TplgRouteDesc(source_name="dai-copier.1", sink_name="host-copier.1.capture"), + ], + ) + snap = MachineAudioSnapshot( + target_label="test-align", + card=SoundCardInfo(card_id=0, id="sofsdw", driver="sof-soundwire", name="sof-soundwire", longname="wcl", components=""), + pcms=[ + PcmDeviceInfo(card_id=0, device_id=0, direction="playback", id="Jack Out", name="Jack Out"), + PcmDeviceInfo(card_id=0, device_id=2, direction="playback", id="Speaker", name="Speaker"), + PcmDeviceInfo(card_id=0, device_id=5, direction="playback", id="HDMI1", name="HDMI1"), + PcmDeviceInfo(card_id=0, device_id=31, direction="playback", id="Deepbuffer", name="Deepbuffer"), + PcmDeviceInfo(card_id=0, device_id=1, direction="capture", id="Jack In", name="Jack In"), + ], + tplg=tplg, + tplg_available=True, + dapm_widgets=[ + DapmWidgetInfo(name="rt722 HP", component="sdw0", widget_type="hp"), + DapmWidgetInfo(name="rt722 SPK", component="sdw0", widget_type="spk"), + DapmWidgetInfo(name="rt722 MIC2", component="sdw0", widget_type="mic"), + DapmWidgetInfo(name="Headphone", component="card", widget_type="hp"), + DapmWidgetInfo(name="Speaker", component="card", widget_type="spk"), + DapmWidgetInfo(name="HDMI Out", component="ehdaudio0D2", widget_type="output"), + DapmWidgetInfo(name="Headset Mic", component="card", widget_type="mic"), + ], + dapm_edges=[ + DapmEdgeInfo(src_name="dai-copier.0", src_comp="0000:00:1f.3", dst_name="rt722 HP", dst_comp="sdw0"), + DapmEdgeInfo(src_name="rt722 HP", src_comp="sdw0", dst_name="Headphone", dst_comp="card"), + DapmEdgeInfo(src_name="dai-copier.2", src_comp="0000:00:1f.3", dst_name="rt722 SPK", dst_comp="sdw0"), + DapmEdgeInfo(src_name="rt722 SPK", src_comp="sdw0", dst_name="Speaker", dst_comp="card"), + DapmEdgeInfo(src_name="dai-copier.5", src_comp="0000:00:1f.3", dst_name="HDMI Out", dst_comp="ehdaudio0D2"), + DapmEdgeInfo(src_name="Headset Mic", src_comp="card", dst_name="rt722 MIC2", dst_comp="sdw0"), + DapmEdgeInfo(src_name="rt722 MIC2", src_comp="sdw0", dst_name="dai-copier.1", dst_comp="0000:00:1f.3"), + ], + dapm_available=True, + ) + vm = build_end_to_end_graph(snap) + layout_end_to_end_graph(vm) + # Codec pins feeding card transducers must be demoted to Codec, not Endpoint + self.assertEqual(vm.nodes["dapm:sdw0:rt722 HP"].class_category, "Codec") + self.assertEqual(vm.nodes["dapm:sdw0:rt722 SPK"].class_category, "Codec") + self.assertEqual(vm.nodes["dapm:sdw0:rt722 MIC2"].class_category, "Codec") + self.assertEqual(vm.nodes["dapm:card:Headphone"].class_category, "Endpoint") + self.assertEqual(vm.nodes["dapm:card:Speaker"].class_category, "Endpoint") + self.assertEqual(vm.nodes["dapm:card:Headset Mic"].class_category, "Endpoint") + # Playback Deepbuffer (PCM31) shares mixer.1.1 with PCM0, so it must stay adjacent above Speaker (PCM2) + self.assertLess(vm.nodes["pcm:playback:31"].y, vm.nodes["pcm:playback:2"].y) + self.assertLess(vm.nodes["pcm:playback:2"].y, vm.nodes["pcm:playback:5"].y) + # All playback endpoints precede capture Headset Mic vertically + self.assertLess(vm.nodes["dapm:card:Headphone"].y, vm.nodes["dapm:card:Speaker"].y) + self.assertLess(vm.nodes["dapm:card:Speaker"].y, vm.nodes["dapm:card:Headset Mic"].y) + def test_tplg_multi_link_and_bounds_safety(self) -> None: def make_hdr(hdr_type: int, payload: bytes, count: int = 1) -> bytes: return struct.pack("<9I", SND_SOC_TPLG_MAGIC, 5, 0, hdr_type, 36, 0, len(payload), 0, count) + payload