rust 是否将数据作为可变数据传递到add_probe?

jecbmhm3  于 2023-01-09  发布在  其他
关注(0)|答案(1)|浏览(101)

我想修改笔记本里的一些数据。
我在www.example.com上看到了使用衬垫的示例https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/blob/0.18.8/examples/src/bin/pad_probes.rs#L40
因为回调类型是func: F,所以我只能使用不修改任何捕获内容的回调。我尝试简单地在闭包中使用我的一个变量,得到了以下结果:

error[E0594]: cannot assign to `self.frame_id`, as `Fn` closures cannot mutate their captured variables
   --> src/decoding_branch.rs:161:13
    |
161 |             self.frame_id += 1;
    |             ^^^^^^^^^^^^^^^^^^ cannot assign

我该怎么改变卫生纸上的东西?

hmae6n7t

hmae6n7t1#

我的错。我应该使用Cannot borrow captured outer variable in an Fn closure as mutable之类的东西
我尝试了以下方法来检查此方法

let frame_id = Arc::new(Mutex::new(0));
        
        nvv4l2dec_src.add_probe(gst::PadProbeType::BUFFER, move |_, probe_info| {
            let mut frame_id = frame_id.lock().unwrap();
            *frame_id += 1;
            println!("{:?}", frame_id);
            });

而且看起来很有效。

相关问题