• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*!
2  * \copy
3  *     Copyright (c)  2011-2013, Cisco Systems
4  *     All rights reserved.
5  *
6  *     Redistribution and use in source and binary forms, with or without
7  *     modification, are permitted provided that the following conditions
8  *     are met:
9  *
10  *        * Redistributions of source code must retain the above copyright
11  *          notice, this list of conditions and the following disclaimer.
12  *
13  *        * Redistributions in binary form must reproduce the above copyright
14  *          notice, this list of conditions and the following disclaimer in
15  *          the documentation and/or other materials provided with the
16  *          distribution.
17  *
18  *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  *     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  *     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  *     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  *     COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24  *     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  *     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  *     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28  *     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *     POSSIBILITY OF SUCH DAMAGE.
30  *
31  * \file        :  util.h
32  *
33  * \brief       :  utils for wels video processor class
34  *
35  * \date        :  2011/01/04
36  *
37  * \description :
38  *
39  *************************************************************************************
40  */
41 
42 #ifndef WELSVP_UTIL_H
43 #define WELSVP_UTIL_H
44 
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <string.h>
48 #include <stdarg.h>
49 #include <assert.h>
50 
51 #include "typedef.h"
52 #include "memory.h"
53 #include "IWelsVP.h"
54 
55 WELSVP_NAMESPACE_BEGIN
56 
57 #define MAX_MBS_PER_FRAME 36864 //in accordance with max level support in Rec
58 
59 #define MB_WIDTH_LUMA  (16)
60 #define PESN               (1e-6)       // desired float precision
61 #define AQ_INT_MULTIPLY                   10000000
62 #define AQ_TIME_INT_MULTIPLY                   10000
63 #define AQ_QSTEP_INT_MULTIPLY                   100
64 #define AQ_PESN 10 // (1e-6)*AQ_INT_MULTIPLY
65 
66 #define MB_TYPE_INTRA4x4                0x00000001
67 #define MB_TYPE_INTRA16x16              0x00000002
68 #define MB_TYPE_INTRA_PCM               0x00000004
69 #define MB_TYPE_INTRA                     (MB_TYPE_INTRA4x4 | MB_TYPE_INTRA16x16 | MB_TYPE_INTRA_PCM)
70 #define IS_INTRA(type) ((type)&MB_TYPE_INTRA)
71 
72 #define WELS_MAX(x, y) ((x) > (y) ? (x) : (y))
73 #define WELS_MIN(x, y) ((x) < (y) ? (x) : (y))
74 
75 #ifndef WELS_SIGN
76 #define WELS_SIGN(a) ((int32_t)(a) >> 31)
77 #endif
78 
79 #ifndef WELS_ABS
80 #define WELS_ABS(a) ((WELS_SIGN(a) ^ (int32_t)(a)) - WELS_SIGN(a))
81 #endif
82 
83 #define WELS_CLAMP(x, minv, maxv)  WELS_MIN(WELS_MAX(x, minv), maxv)
84 
85 #define ALIGNBYTES         (16)       /* Worst case is requiring alignment to an 16 byte boundary */
86 
87 #define WelsCastFromPointer(p)      (reinterpret_cast<intptr_t>(p))
88 #define WelsStaticCast(type, p)  (static_cast<type>(p))
89 #define WelsDynamicCast(type, p) (dynamic_cast<type>(p))
90 
91 #define GET_METHOD(x)  ((x) & 0xff)          // mask method as the lowest 8bits
92 #define GET_SPECIAL(x) (((x) >> 8) & 0xff)   // mask special flag as 8bits
93 
WelsVpGetValidMethod(int32_t a)94 inline EMethods WelsVpGetValidMethod (int32_t a) {
95   int32_t iMethod = GET_METHOD (a);
96   return WelsStaticCast (EMethods, WELS_CLAMP (iMethod, METHOD_NULL + 1, METHOD_MASK - 1));
97 }
98 
99 
100 
101 WELSVP_NAMESPACE_END
102 
103 #endif
104 
105 
106