feat(sender): 支持把串流画面弹出为独立原生窗口

- 新增 windows/runner/video_window.{h,cpp}:Win32 顶层窗口,GDI 直接绘制解码后的 BGRA 帧,支持拖到任意显示器/最大化/双击或 F11 全屏/ESC 退出

- FrameStore 增加 Snapshot()(shared_ptr 保活),独立窗口与主窗口共享同一份帧,不重复解码、不抢 Rust 单消费者帧队列

- 独立窗口在播时跳过 MarkTextureFrameAvailable,省一次 BGRA 拷贝;主界面显示占位提示

- ttstd/video 通道新增 openWindow/closeWindow/windowOpen,stats 带 windowOpen

- VideoView 按真实码流宽高算显示比例,竖屏投屏不再被压成 16:9
This commit is contained in:
tongtong committed 2026-11-27 09:28:46 +08:00
1 parent f87ef59d98
commit 0cff2b011a
8 files changed
+419 -4

No files matched your search

@@ -1,5 +1,7 @@
#include "video_texture.h"
#include "video_window.h"
#include <flutter/encodable_value.h>
#include <flutter/method_channel.h>
#include <flutter/plugin_registrar_windows.h>
@@ -262,6 +264,18 @@ class FrameStore {
return frames_;
}
// 独立窗口使用:返回当前帧的共享所有权快照。
// 拿到 shared_ptr 后即使解码线程继续 Publish,绘制期间的帧也不会被回收。
std::shared_ptr<std::vector<uint8_t>> Snapshot(int* width, int* height) {
std::lock_guard<std::mutex> lock(mutex_);
if (!front_ || front_->empty() || width_ <= 0 || height_ <= 0) {
return nullptr;
}
*width = width_;
*height = height_;
return front_;
}
uint64_t pts() {
std::lock_guard<std::mutex> lock(mutex_);
return pts_;
@@ -860,6 +874,22 @@ class VideoTexturePlugin : public flutter::Plugin {
static_cast<int64_t>(texture_id_)));
return;
}
if (call.method_name() == "openWindow") {
auto store = frames_;
const bool opened = video_window_.Open(
[store](int* width, int* height) { return store->Snapshot(width, height); });
result->Success(flutter::EncodableValue(opened));
return;
}
if (call.method_name() == "closeWindow") {
video_window_.Close();
result->Success(flutter::EncodableValue(true));
return;
}
if (call.method_name() == "windowOpen") {
result->Success(flutter::EncodableValue(video_window_.IsOpen()));
return;
}
if (call.method_name() == "stats") {
flutter::EncodableMap map;
int width = 0;
@@ -886,6 +916,8 @@ class VideoTexturePlugin : public flutter::Plugin {
// 这里显式指出,避免和「还没等到关键帧」或「没收到码流」混为一谈。
error = "被控端码流缺少 SPS/PPS,请更新被控端 APK 后重连";
}
map[flutter::EncodableValue("windowOpen")] =
flutter::EncodableValue(video_window_.IsOpen());
map[flutter::EncodableValue("error")] = flutter::EncodableValue(error);
map[flutter::EncodableValue("format")] =
flutter::EncodableValue(static_cast<int64_t>(last_format_));
@@ -978,6 +1010,11 @@ class VideoTexturePlugin : public flutter::Plugin {
return [this, store](std::shared_ptr<std::vector<uint8_t>> frame, int width,
int height, uint64_t pts) {
store->Publish(std::move(frame), width, height, pts);
if (video_window_.IsOpen()) {
// 画面已经在独立窗口里,没必要再驱动 Flutter 纹理(省一次 BGRA 拷贝)。
video_window_.OnFrameAvailable();
return;
}
if (texture_registrar_ != nullptr && texture_id_ != 0) {
texture_registrar_->MarkTextureFrameAvailable(texture_id_);
}
@@ -990,6 +1027,8 @@ class VideoTexturePlugin : public flutter::Plugin {
std::unique_ptr<flutter::MethodChannel<flutter::EncodableValue>> channel_;
FlutterDesktopPixelBuffer descriptor_ = {};
std::shared_ptr<FrameStore> frames_;
// 与主窗口纹理共享同一份 FrameStore 的独立串流窗口。
VideoWindow video_window_;
RustVideoApi api_;
VideoDecoder decoder_;
std::atomic<bool> stop_{false};