• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright Samsung Electronics Co.,LTD.
3  * Copyright (C) 2015 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef __HWJPEG_INTERNAL_H__
19 #define __HWJPEG_INTERNAL_H__
20 
21 #ifndef LOG_TAG
22 #error "LOG_TAG is not defined!"
23 #endif
24 
25 #include <log/log.h>
26 #include <sys/ioctl.h>
27 #include <time.h>
28 #include <unistd.h>
29 
30 #include <cerrno>
31 #include <cstring>
32 
33 #ifdef __GNUC__
34 #define __UNUSED__ __attribute__((__unused__))
35 #else
36 #define __UNUSED__
37 #endif
38 
39 #ifndef ALOGERR
40 #define ALOGERR(fmt, args...) ((void)ALOG(LOG_ERROR, LOG_TAG, fmt " [%s]", ##args, strerror(errno)))
41 #endif
42 
43 #define V4L2_CID_JPEG_SEC_COMP_QUALITY (V4L2_CID_JPEG_CLASS_BASE + 20)
44 #define V4L2_CID_JPEG_QTABLES2 (V4L2_CID_JPEG_CLASS_BASE + 22)
45 #define V4L2_CID_JPEG_HWFC_ENABLE (V4L2_CID_JPEG_CLASS_BASE + 25)
46 #define V4L2_CID_JPEG_PADDING (V4L2_CID_JPEG_CLASS_BASE + 26)
47 #define V4L2_CID_JPEG_SEC_PADDING (V4L2_CID_JPEG_CLASS_BASE + 27)
48 
49 #define TO_MAIN_SIZE(val) ((val)&0xFFFF)
50 #define TO_THUMB_SIZE(val) (((val)&0xFFFF) << 16)
51 #define TO_IMAGE_SIZE(main, thumb) (TO_MAIN_SIZE(main) | TO_THUMB_SIZE(thumb))
52 
53 #define PTR_TO_ULONG(ptr) reinterpret_cast<unsigned long>(ptr)
54 #define PTR_DIFF(ptr1, ptr2) (reinterpret_cast<size_t>(ptr2) - reinterpret_cast<size_t>(ptr1))
55 
56 #define ARRSIZE(v) (sizeof(v) / sizeof(v[0]))
57 
58 #ifndef min
59 template <typename T>
min(T val1,T val2)60 static inline T min(T val1, T val2) {
61     return (val1 > val2) ? val2 : val1;
62 }
63 #endif
64 
65 #ifndef max
66 template <typename T>
max(T val1,T val2)67 static inline T max(T val1, T val2) {
68     return (val1 < val2) ? val2 : val1;
69 }
70 #endif
71 
72 // H/W requires 16-byte alignment
73 #define HW_BASE_ALIGN_BITS 4
74 #define HW_BASE_ALIGN_SIZE (1 << HW_BASE_ALIGN_BITS)
75 #define HW_BASE_ALIGN_MASK ~(HW_BASE_ALIGN_SIZE - 1)
76 
77 class CStopWatch {
78     timespec m_tBegin;
79 
80 public:
81     CStopWatch(bool start = false) {
82         if (start) Start();
83     }
84     bool Start();
85     unsigned long GetElapsed();
86     unsigned long GetElapsedUpdate();
87 };
88 
89 bool WriteToFile(const char *path, const char *data, size_t len);
90 bool WriteToFile(const char *path, int dmabuf, size_t len);
91 #endif //__HWJPEG_INTERNAL_H__
92