> For the complete documentation index, see [llms.txt](https://docs.convai.com/api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/unity-plugin-beta-overview/features/vision/publishing-and-policies.md).

# 发布与策略

## 控制视觉帧的发布方式

`ConvaiVisionPublisher` 是连接帧源和 Convai 后端的组件。它管理 WebRTC 视频轨道的生命周期——在房间连接事件发生时启动、保持和停止流——并提供一组策略和覆盖项，用于调优传输特性。本页解释每个 Inspector 字段，描述每种发布策略，并展示如何通过脚本手动控制发布。

### ConvaiVisionPublisher 检查器参考

#### 帧源

<table><thead><tr><th width="142.5">字段</th><th width="138.50006103515625">类型</th><th width="142">默认值</th><th>说明</th></tr></thead><tbody><tr><td><strong>帧源组件</strong></td><td><code>MonoBehaviour</code></td><td><em>（自动解析）</em></td><td>该 <code>IVisionFrameSource</code> 实现以进行发布。留空可自动发现场景中第一个可用的帧源。如果存在多个帧源，请在此明确指定。</td></tr></tbody></table>

#### 发布策略

<table><thead><tr><th width="139.5">字段</th><th width="189.00006103515625">类型</th><th width="147">默认值</th><th>说明</th></tr></thead><tbody><tr><td><strong>发布策略</strong></td><td><code>VisionPublishPolicy</code></td><td><code>AutoCompatible</code></td><td>控制客户端帧率和比特率。请参见下方策略表。</td></tr></tbody></table>

#### 视频设置

<table><thead><tr><th width="245.99993896484375">字段</th><th width="108.50006103515625">类型</th><th width="145">默认值</th><th>说明</th></tr></thead><tbody><tr><td><strong>视频轨道名称</strong></td><td><code>string</code></td><td><code>"unity-scene"</code></td><td>发布到房间的 WebRTC 视频轨道名称。Convai 后端使用此名称将视频流与会话关联起来。仅当你有特定的多轨道配置时才更改它。</td></tr><tr><td><strong>发布帧率覆盖</strong></td><td><code>int</code> （0–30）</td><td><code>0</code></td><td>覆盖发布策略中指定的帧率。 <code>0</code> 表示“使用策略默认值”。</td></tr><tr><td><strong>发布比特率覆盖</strong></td><td><code>int</code></td><td><code>0</code></td><td>覆盖发布策略中指定的最大比特率（每秒比特数）。 <code>0</code> 表示“使用策略默认值”。</td></tr></tbody></table>

***

### 发布策略对比

`VisionPublishPolicy` 是客户端传输设置。它控制帧采样的激进程度以及分配多少带宽。它不会 **不是** 决定后端由哪个 AI 模型或视觉提供方处理该流。

<table><thead><tr><th width="182.5">策略</th><th width="84.99993896484375">值</th><th width="90.00006103515625">帧率</th><th width="134.5">最大比特率</th><th>推荐用途</th></tr></thead><tbody><tr><td><code>AutoCompatible</code></td><td><code>0</code></td><td>10 fps</td><td>750 000 bps</td><td>通用用途——一个平衡的默认值，适用于大多数后端配置</td></tr><tr><td><code>高响应</code></td><td><code>1</code></td><td>15 fps</td><td>1 000 000 bps</td><td>实时多模态交互，角色需要快速响应视觉变化</td></tr><tr><td><code>低开销</code></td><td><code>2</code></td><td>5 fps</td><td>350 000 bps</td><td>大规模部署、对成本敏感的会话，或快照比运动更重要的场景</td></tr><tr><td><code>Manual</code></td><td><code>3</code></td><td>—</td><td>—</td><td>对何时开始和停止发布进行显式控制；在启用时使用 <code>AutoCompatible</code> 速率</td></tr></tbody></table>

{% hint style="warning" %}
`VisionPublishPolicy` 仅描述 **客户端传输** ——即通过网络发送的帧率和比特率。它不会暴露或控制后端 AI 模型、视觉提供方或处理延迟。不要将其用作后端行为的代理指标。
{% endhint %}

***

### 帧率和比特率覆盖

当你需要一个介于各策略之间的特定值时，请使用覆盖字段：

* **发布帧率覆盖** 接受从 `1` 到 `30`的值。设置 `0` 可恢复策略默认值。
* **发布比特率覆盖** 接受任意正整数，单位为每秒比特数。设置 `0` 可恢复策略默认值。

例如： `AutoCompatible` 采用 12 fps 覆盖的策略会以 750 000 bps 输出 12 fps。

{% hint style="info" %}
在 WebGL 上，帧率会被限制为最高 **15 fps** ，无论策略或覆盖值为何。这是由 `canvas.captureStream()`.
{% endhint %}

***

### 自动发布生命周期

默认情况下（除 `Manual`之外的任何策略），发布会遵循房间连接：

1. 房间连接并且 `连接类型 = 视频` → 自动开始发布。
2. 房间断开连接或模块停止 → 发布停止，视频轨道取消发布。
3. 组件被禁用 → 发布停止。
4. 当房间已连接时，组件重新启用 → 发布恢复。

你无需调用任何方法来触发此行为。

***

### 手动策略

设置 **发布策略** 到 `Manual` 当你需要显式控制时使用——例如，仅在用户执行某个操作时开始发布，或在训练模块之间暂停流。

#### 手动开始和停止

```csharp
using Convai.Modules.Vision;

ConvaiVisionPublisher publisher = GetComponent<ConvaiVisionPublisher>();

// 开始发布（使用 AutoCompatible 速率）
publisher.EnablePublishing(true);

// 停止发布，但不断开房间连接
publisher.EnablePublishing(false);
```

#### 在运行时切换策略

```csharp
// 在会话中途切换到 HighResponsiveness
publisher.SetPublishPolicy(VisionPublishPolicy.HighResponsiveness);
```

`SetPublishPolicy` 会立即生效。如果发布处于活动状态，当前轨道会取消发布，并使用更新后的配置启动新轨道。

***

### WebGL 平台说明

{% hint style="info" %}
在 WebGL 上， `ConvaiVisionPublisher` 通过 `canvas.captureStream()` 捕获可见的 Unity 浏览器画布，而不是从帧源组件读取。对于 WebGL 构建，你无需在场景中添加帧源组件。

发布策略选择仍然适用——对于注重性能的 WebGL 部署，请使用 `低开销` 。无论策略或覆盖值如何，WebGL 构建的帧率都被限制为 15 fps。
{% endhint %}

***

## 结论

`ConvaiVisionPublisher` 管理完整的视频轨道生命周期——它会在房间连接时开始发布，在断开时停止，并提供用于控制帧率和带宽的策略系统。配置好发布后，添加 [调试预览](/api-docs/zh/cha-jian-yu-ji-cheng/unity-plugin-beta-overview/features/vision/debug-preview.md) 以在部署前直观验证流。完整脚本 API 请参见 [高级主题](/api-docs/zh/cha-jian-yu-ji-cheng/unity-plugin-beta-overview/features/vision/advanced-topics.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/unity-plugin-beta-overview/features/vision/publishing-and-policies.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
