1 /* 2 * Copyright (c) 2021 Rockchip Electronics Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef __MPP_TIME_H__ 17 #define __MPP_TIME_H__ 18 19 #include "rk_type.h" 20 #include "mpp_thread.h" 21 22 #if defined(_WIN32) && !defined(__MINGW32CE__) 23 #include <windows.h> 24 #define msleep Sleep 25 #define sleep(x) Sleep((x)*1000) 26 #else 27 #include <unistd.h> 28 #define msleep(x) usleep((x)*1000) 29 #endif 30 31 typedef void *MppClock; 32 typedef void *MppTimer; 33 typedef void *MppStopwatch; 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 RK_S64 mpp_time(void); 40 void mpp_time_diff(RK_S64 start, RK_S64 end, RK_S64 limit, const char *fmt); 41 MppClock mpp_clock_get(const char *name); 42 void mpp_clock_put(MppClock clock); 43 void mpp_clock_enable(MppClock clock, unsigned int enable); 44 RK_S64 mpp_clock_start(MppClock clock); 45 RK_S64 mpp_clock_pause(MppClock clock); 46 RK_S64 mpp_clock_reset(MppClock clock); 47 RK_S64 mpp_clock_get_sum(MppClock clock); 48 RK_S64 mpp_clock_get_count(MppClock clock); 49 const char *mpp_clock_get_name(MppClock clock); 50 MppTimer mpp_timer_get(const char *name); 51 void mpp_timer_set_callback(MppTimer timer, MppThreadFunc func, void *ctx); 52 void mpp_timer_set_timing(MppTimer timer, signed int initial, signed int interval); 53 void mpp_timer_set_enable(MppTimer timer, signed int enable); 54 void mpp_timer_put(MppTimer timer); 55 MppStopwatch mpp_stopwatch_get(const char *name); 56 void mpp_stopwatch_set_show_on_exit(MppStopwatch stopwatch, signed int show_on_exit); 57 void mpp_stopwatch_record(MppStopwatch stopwatch, const char *event); 58 void mpp_stopwatch_put(MppStopwatch timer); 59 RK_S64 mpp_stopwatch_elapsed_time(MppStopwatch stopwatch); 60 61 #ifdef __cplusplus 62 } 63 #endif 64 65 #ifdef __cplusplus 66 class MppTime { 67 public: 68 MppTime(const char *name = __FUNCTION__); 69 ~MppTime(); 70 71 private: 72 const char *mName; 73 RK_S64 mStart; 74 RK_S64 mEnd; 75 76 MppTime(const MppTime &); 77 MppTime &operator=(const MppTime &); 78 }; 79 80 #endif 81 82 #define AUTO_TIMER_STRING(name, cnt) name##cnt 83 #define AUTO_TIMER_NAME_STRING(name, cnt) AUTO_TIMER_STRING(name, cnt) 84 #define AUTO_TIMER_NAME(name) AUTO_TIMER_NAME_STRING(name, __COUNTER__) 85 #define AUTO_TIMING() MppTime AUTO_TIMER_NAME(auto_timing)(__FUNCTION__) 86 87 #endif 88