-1

I want to mutate some data in the pad.

I see an example of working with pads here https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/blob/0.18.8/examples/src/bin/pad_probes.rs#L40

It seems like I can only use callbacks that don't modify anything they capture since the callback type is func: F . I tried to simply use one of my variables inside the closure and got this:

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

How I'm supposed to change anything in pads?

ckorzhik
  • 758
  • 2
  • 7
  • 21

1 Answers1

0

My bad. I should use something like Cannot borrow captured outer variable in an `Fn` closure as mutable

I tried the following to check this approach

        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);
            });        

and it seems like it works.

ckorzhik
  • 758
  • 2
  • 7
  • 21