fix: 修正投屏授权状态与窗口生命周期,避免串流状态错乱

This commit is contained in:
tongtong committed 2026-11-28 02:59:49 +08:00
1 parent a0b77a3e7a
commit 4c9d006d11
6 files changed
+134 -90

No files matched your search

@@ -267,9 +267,11 @@ class FrameStore {
// 独立窗口使用:返回当前帧的共享所有权快照。
// 拿到 shared_ptr 后即使解码线程继续 Publish,绘制期间的帧也不会被回收。
std::shared_ptr<std::vector<uint8_t>> Snapshot(int* width, int* height) {
std::shared_ptr<std::vector<uint8_t>> Snapshot(int* width, int* height,
uint64_t after_frame) {
std::lock_guard<std::mutex> lock(mutex_);
if (!front_ || front_->empty() || width_ <= 0 || height_ <= 0) {
if (frames_ <= after_frame || !front_ || front_->empty() || width_ <= 0 ||
height_ <= 0) {
return nullptr;
}
*width = width_;
@@ -988,8 +990,13 @@ class VideoTexturePlugin : public flutter::Plugin {
hint_width = read_int("width");
hint_height = read_int("height");
}
if (!video_window_.IsOpen()) {
window_start_frame_ = store->frames();
}
const bool opened = video_window_.Open(
[store](int* width, int* height) { return store->Snapshot(width, height); },
[store, start = window_start_frame_](int* width, int* height) {
return store->Snapshot(width, height, start);
},
hint_width, hint_height);
result->Success(flutter::EncodableValue(opened));
return;
@@ -1013,8 +1020,13 @@ class VideoTexturePlugin : public flutter::Plugin {
frames_->size(&width, &height);
map[flutter::EncodableValue("textureId")] =
flutter::EncodableValue(static_cast<int64_t>(texture_id_));
const uint64_t decoded = frames_->frames();
map[flutter::EncodableValue("decoded")] =
flutter::EncodableValue(static_cast<int64_t>(frames_->frames()));
flutter::EncodableValue(static_cast<int64_t>(decoded));
map[flutter::EncodableValue("windowFrames")] = flutter::EncodableValue(
static_cast<int64_t>(video_window_.IsOpen()
? decoded - window_start_frame_
: 0));
map[flutter::EncodableValue("pending")] =
flutter::EncodableValue(static_cast<int64_t>(api_.Pending()));
map[flutter::EncodableValue("received")] =
@@ -1143,6 +1155,7 @@ class VideoTexturePlugin : public flutter::Plugin {
std::unique_ptr<flutter::MethodChannel<flutter::EncodableValue>> channel_;
FlutterDesktopPixelBuffer descriptor_ = {};
std::shared_ptr<FrameStore> frames_;
uint64_t window_start_frame_ = 0;
// 与主窗口纹理共享同一份 FrameStore 的独立串流窗口。
VideoWindow video_window_;
// 本次关闭是由 Flutter 主动发起的(不需要再回调 windowClosed)。