GithubHelp home page GithubHelp logo

Comments (2)

wangxiaochuTHU avatar wangxiaochuTHU commented on June 12, 2024

I'm sorry, but in my use case the streamed image frames which flow as slow as 5 fps can be lost/dropped, where actually only a 4 μs-duration-operation is spent on each arrival of frames. So I suspect that the bottleneck might be at your lib.

Since it is common for most drivers to obtain a captured image frame-by-frame ( rather than byte-by-byte or line-by-line), I think we should shorten the handling time after we got the frame and keep capturing as soon as possible. Here is the idea based on this rule, how do you think about it (the code pattern is given as below) ?

The lib API looks like

/// set stream on, and return `rx` to user for receiving `Buffer`
pub fn stream_on(&mut self)  -> mpsc::Receiver<Buffer> {
    /* 
        set the stream on 
    */
    
    let (tx, rx) = mpsc::channel();
    self.tx = Some(tx);
    rx
}

/// infinite loop for requesting the next samples, and use a thread to handle each sample.
pub fn frames(&mut self)  {
     loop {
            let imf_sample: Option<IMFSample> = match unsafe { MFCreateSample() } {
                Ok(sample) => {
                    Some(sample)
                }
                Err(why) => {
                    return Err(NokhwaError::ReadFrameError(why.to_string()));
                }
            };
            
            /* 
                  here, can we handle imf_sample in a background thread? 
                           e.g. handle_task.send(Wrapper<imf_sample>);
                  thus we can wait for the next frame as soon as possible
            */
     }
}

/// the handle thread
pub fn sample_handle_thread(tx : mpsc::Sender<Buffer>) {
      while let Ok(Wrapper<imf_sample>) = handle_task.recv(){
              /*
                    handle the imf_sample and get `Buffer`
              */
              tx.send(buffer);
      }
}
            

Thus users can obtain the Buffer by receiving from rx.

from nokhwa.

wangxiaochuTHU avatar wangxiaochuTHU commented on June 12, 2024

Hello, the frame drop problem in my case finally ends up with setting the priority of the capture thread to "Time Critical" (it's on Windows). By doing this, the drop ratio can decrease from about 500 out of 10000 to a relatively low number, which is about 25 out of 10000.

Actually, my use case was to capture video with resolution 5000x5000 at 5Hz and then display&handle&save the images. I found it hard to understand the process/winapi of Windows camera capturing. Thanks to your crate, it let me achieve this goal much more easier and don't need to turn to Linux. Thank you very much, it is really a great project.

from nokhwa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.