pupil-labs / libuvc

a cross-platform library for USB video devices
https://int80k.com/libuvc/
Other
51 stars 30 forks source link

Windows, error: Integer division by zero #42

Closed PeterPeterPan closed 4 years ago

PeterPeterPan commented 4 years ago

Hi, anyone still here~

When I use the device with UVC 1.0, it's good.

When I use the device with UVC 1.1, the first time call function get_dev_time_us( ), the parameter "strmh->corrected_clock_freq" is zero, that cause "Integer division by zero".

Any idea for this question? why be zero? how to fix?

thanks

PeterPeterPan commented 4 years ago

Oh, actually dwClockFrequency is obsolete in UVC 1.1 right?

PeterPeterPan commented 4 years ago

OK, it's work now 🤣

inline int64_t get_dev_time_us(uvc_stream_handle_t *strmh, int64_t dev_ticks)
{
    int64_t time_us;
    if (strmh->corrected_clock_freq != 0)
        time_us = ((int64_t)dev_ticks * MILLION + (strmh->corrected_clock_freq >> 1)) / strmh->corrected_clock_freq;
    else // UVC 1.1, swClockFrequency is obsolete.
        time_us = 0;

    return time_us;
}