def f():

                    # Wait longer if not already recording so that things that don't need to detect as much give up faster.
                    # prioritize reliable start of record!

                    #Cannot wait too long thogh because we nee to quickly fail back to motion only.

                    # This calculates our length in terms of how much loop recorded footage we have
                    # We have to detect within this window or it will dissapear before we capture it.

                    #Note
                    n = max(1, int((float(self.config.get('device.loop_record_length', 5))+2.5)/5))*5


                    # If we have not seen any objects lately, better check more often because
                    # We might be about to stop the recording even if there is still motion, so it must be accurate.
                    if self.lastObjectDetectionHit > (time.monotonic()-15):
                        t = 3 if self.datapoints['record'] else (n*0.75)
                    else:
                        t = n*0.75

                    if object_detection_lock.acquire(True, t+(random.random()*0.1)):
                        try:
                            # We have to make sure an older detection does not wait on a newer detection. 
                            # Only the latest should get through, or we would queue up a problem.
                            if self.obj_rec_wait_timestamp > obj_rec_wait:
                                return
                            o=recognize_tflite(self.request_data_point("bmp_snapshot"), self)
                            self.lastDidObjectRecognition=time.monotonic()
                            self.lastObjectSet=o