summaryrefslogtreecommitdiffstats
path: root/libvideoeditor/osal/inc/M4OSA_Time.h
blob: 984c243aa79870b0a10219ce39806b1f2b06ede5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
 * Copyright (C) 2004-2011 NXP Software
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 ************************************************************************
 * @file         M4OSA_Time.h
 * @ingroup      OSAL
 * @brief        Time macros
 * @note         This file defines time type and associated macros which must
 *               be used to manipulate time.
 ************************************************************************
*/

/* $Id: M4OSA_Time.h,v 1.2 2007/01/05 13:12:22 thenault Exp $ */

#ifndef M4OSA_TIME_H
#define M4OSA_TIME_H


#include "M4OSA_Types.h"


typedef M4OSA_Int64   M4OSA_Time;


/** This macro sets the unknown time value */
#ifdef M4OSA_64BITS_SUPPORTED
   #define M4OSA_TIME_SET_UNKNOWN(time) {time = 0x8000000000000000LL ;}
#endif /* M4OSA_64BITS_SUPPORTED */

#ifdef M4OSA_64BITS_COUPLE_INT
   #define M4OSA_TIME_SET_UNKNOWN(time) {\
      time.major = 0x80000000 ;\
      time.minor = 0x00000000 ;}
#endif /* M4OSA_64BITS_COUPLE_INT */

#ifdef M4OSA_64BITS_NOT_SUPPORTED
   #define M4OSA_TIME_SET_UNKNOWN(time) {time = 0x80000000;}
#endif   /* M4OSA_64BITS_NOT_SUPPORTED */


/** This macro returns 1 if the provided time is set to unknown time,
    and 0 else.*/
#ifdef M4OSA_64BITS_SUPPORTED

#define M4OSA_TIME_IS_UNKNOWN(time) (((M4OSA_UInt64)(time) == 0x8000000000000000LL) ? 1 : 0)

#elif defined M4OSA_64BITS_COUPLE_INT

#define M4OSA_TIME_IS_UNKNOWN(time)\
   (( (M4OSA_INT64_GET_HIGH32(time) == M4OSA_unknownTimeMajor)\
      &&(M4OSA_INT64_GET_LOW32(time) == M4OSA_unknownTimeMinor) ) ? 1:0)

#else /* M4OSA_64BITS_NOT_SUPPORTED */

#define M4OSA_TIME_IS_UNKNOWN(time) (((M4OSA_UInt32)(time) == 0x80000000) ? 1 : 0)

#endif


/** This macro affects time2 to time1.*/
#define M4OSA_TIME_SET(time1, time2)\
        M4OSA_INT64_SET(time1, time2)


/** This macro sets time from i32.*/
#define M4OSA_TIME_FROM_INT32(time, i32)\
        M4OSA_INT64_FROM_INT32(time, i32)


/** This macro sets time from i32 ui32.*/
#define M4OSA_TIME_FROM_INT32_UINT32(time, i32, ui32)\
        M4OSA_INT64_FROM_INT32_UINT32(time, i32, ui32)


/** This macro tests if time is positive*/
#define M4OSA_TIME_IS_POSITIVE(time)\
        M4OSA_INT64_IS_POSITIVE(time)


/** This macro sets time_out = -time_in*/
#define M4OSA_TIME_NEG(time_out, time_in)\
        M4OSA_INT64_NEG(time_out, time_in)


/** This macro sets time_out = |time_in|*/
#define M4OSA_TIME_ABS(time_out, time_in)\
        M4OSA_INT64_ABS(time_out, time_in)


/** This macro adds the 2 provided times (time1 and time2),
    and writes the result in result. Both times must have the same timescale.*/
#define M4OSA_TIME_ADD(result, time1, time2)\
        M4OSA_INT64_ADD(result, time1, time2)


/** This macro subs the 2 provided times (time1 and time2),
    and writes the result in result.*/
#define M4OSA_TIME_SUB(result, time1, time2)\
        M4OSA_INT64_SUB(result, time1, time2)


/** This macro does a scalar product (result = time*value),
    and writes the result in result.*/
#define M4OSA_TIME_SCALAR_PRODUCT(result, time, value)\
        M4OSA_INT64_SCALAR_PRODUCT(result, time, value)


/** This macro does a scalar division (result= time / value),
    and writes the result in result.*/
#define M4OSA_TIME_SCALAR_DIVISION(result, time, value)\
        M4OSA_INT64_SCALAR_DIVISION(result, time, value)


/** This macro updates the time to the oldTimeScale to the newTimeScale. The
    result (the nearest rounded to the min value) is stored in result value. */
#define M4OSA_TIME_CHANGE_TIMESCALE(result, time, oldTimeScale, newTimeScale)\
      { M4OSA_Time t_tempTime1, t_tempTime2, t_tempTime3;\
        M4OSA_Int32 i32_quotient = newTimeScale/oldTimeScale;\
        M4OSA_Int32 i32_rest = newTimeScale%oldTimeScale;\
        M4OSA_INT64_SCALAR_PRODUCT(t_tempTime1, time, i32_quotient);\
        M4OSA_INT64_SCALAR_PRODUCT(t_tempTime2, time, i32_rest);\
        M4OSA_INT64_SCALAR_DIVISION(t_tempTime3, t_tempTime2, oldTimeScale);\
        M4OSA_INT64_ADD(result, t_tempTime1, t_tempTime3); }


/** This macro tests the 2 provided times (time1 & time2).
    The result is either:
  * @arg  1: if time1 is bigger than time2
  * @arg  0: if time2 is equal to time2
  * @arg -1: if time1 is smaller than time2  */
#define M4OSA_TIME_COMPARE(time1, time2)\
        M4OSA_INT64_COMPARE(time1, time2)


/** This macro converts a time with a time scale to millisecond.
    The result is a M4OSA_Double*/
#define M4OSA_TIME_TO_MS(result, time, timescale)\
      { M4OSA_INT64_TO_DOUBLE(result, time);\
        result = (1000*result)/((M4OSA_Double)timescale); }


/** This macro converts a millisecond time to M4OSA_Time with the provided
    timescale. The result (the nearest rounded to the min value) is stored
    in time value.*/
#define M4OSA_MS_TO_TIME(time, timescale, ms)\
      {M4OSA_INT64_FROM_DOUBLE(time, (ms*((M4OSA_Double)(timescale))/1000.0));}


#endif /*M4OSA_TIME_H*/