• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * @copyright
3  *
4  *   Copyright (c) 2015, The Linux Foundation. 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 are met:
8  *
9  *   * Redistributions of source code must retain the above copyright notice,
10  *     this list of conditions and the following disclaimer.
11  *   * Redistributions in binary form must reproduce the above copyright notice,
12  *     this list of conditions and the following disclaimer in the documentation
13  *     and/or other materials provided with the distribution.
14  *   * Neither the name of The Linux Foundation nor the names of its
15  *     contributors may be used to endorse or promote products derived from
16  *     this software without specific prior written permission.
17  *
18  *   THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
19  *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
20  *   FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE DISCLAIMED.
21  *   IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
22  *   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  *   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  *   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25  *   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  *   LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  *   OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
28  *   DAMAGE.
29  *
30  * @file
31  *
32  *   omx_swvdec_utils.h
33  *
34  * @brief
35  *
36  *   OMX software video decoder utility functions header.
37  */
38 
39 #ifndef _OMX_SWVDEC_UTILS_H_
40 #define _OMX_SWVDEC_UTILS_H_
41 
42 #include <pthread.h>
43 
44 #include <cutils/log.h>
45 
46 extern unsigned int g_omx_swvdec_logmask;
47                       ///< global OMX SwVdec logmask variable extern declaration
48 
49 void omx_swvdec_log_init();
50 
51 #define OMX_SWVDEC_LOGMASK_LOW   4 ///< 100: logmask for low priority logs
52 #define OMX_SWVDEC_LOGMASK_HIGH  2 ///< 010: logmask for high priority logs
53 #define OMX_SWVDEC_LOGMASK_ERROR 1 ///< 001: logmask for error priority logs
54 
55 #ifdef LOG_TAG
56 #undef LOG_TAG
57 #endif
58 #define LOG_TAG "OMX_SWVDEC" ///< OMX SwVdec log tag
59 
60 /// low priority log message
61 #define OMX_SWVDEC_LOG_LOW(string, ...)                              \
62     do {                                                             \
63         if (g_omx_swvdec_logmask & OMX_SWVDEC_LOGMASK_LOW)           \
64             ALOGD("--- %s(): " string, __FUNCTION__, ##__VA_ARGS__); \
65     } while (0)
66 
67 /// high priority log message
68 #define OMX_SWVDEC_LOG_HIGH(string, ...)                             \
69     do {                                                             \
70         if (g_omx_swvdec_logmask & OMX_SWVDEC_LOGMASK_HIGH)          \
71             ALOGI("--- %s(): " string, __FUNCTION__, ##__VA_ARGS__); \
72     } while (0)
73 
74 /// error priority log message
75 #define OMX_SWVDEC_LOG_ERROR(string, ...)                            \
76     do {                                                             \
77         if (g_omx_swvdec_logmask & OMX_SWVDEC_LOGMASK_ERROR)         \
78             ALOGE("!!! %s(): " string, __FUNCTION__, ##__VA_ARGS__); \
79     } while (0)
80 
81 /// high priority log message for OMX SwVdec API calls
82 #define OMX_SWVDEC_LOG_API(string, ...)                              \
83     do {                                                             \
84         if (g_omx_swvdec_logmask & OMX_SWVDEC_LOGMASK_HIGH)          \
85             ALOGI(">>> %s(): " string, __FUNCTION__, ##__VA_ARGS__); \
86     } while (0)
87 
88 /// high priority log message for OMX SwVdec callbacks
89 #define OMX_SWVDEC_LOG_CALLBACK(string, ...)                         \
90     do {                                                             \
91         if (g_omx_swvdec_logmask & OMX_SWVDEC_LOGMASK_HIGH)          \
92             ALOGI("<<< %s(): " string, __FUNCTION__, ##__VA_ARGS__); \
93     } while (0)
94 
95 #define OMX_SWVDEC_QUEUE_ELEMENTS 100 ///< number of elements in queue
96 
97 /// OMX SwVdec event information structure
98 typedef struct {
99     unsigned long event_id;     ///< event ID
100     unsigned long event_param1; ///< event parameter 1
101     unsigned long event_param2; ///< event parameter 2
102 } OMX_SWVDEC_EVENT_INFO;
103 
104 /// OMX SwVdec queue class
105 class omx_swvdec_queue
106 {
107 public:
108     omx_swvdec_queue();
109     ~omx_swvdec_queue();
110 
111     bool push(OMX_SWVDEC_EVENT_INFO *p_event_info);
112     bool pop(OMX_SWVDEC_EVENT_INFO *p_event_info);
113 
114 private:
115     OMX_SWVDEC_EVENT_INFO m_queue[OMX_SWVDEC_QUEUE_ELEMENTS];
116                                           ///< event queue
117     unsigned int          m_count_total;  ///< count of total elements
118     unsigned int          m_count_filled; ///< count of filled elements
119     unsigned int          m_index_write;  ///< queue index for writing
120     unsigned int          m_index_read;   ///< queue index for reading
121     pthread_mutex_t       m_mutex;        ///< mutex for queue access
122 };
123 
124 #define OMX_SWVDEC_TS_LIST_ELEMENTS 100
125                                        ///< number of elements in timestamp list
126 
127 /// OMX SwVdec timestamp element structure.
128 typedef struct {
129     bool      filled;    ///< element filled?
130     long long timestamp; ///< timestamp
131 } OMX_SWVDEC_TS_ELEMENT;
132 
133 /// OMX SwVdec timestamp list class
134 class omx_swvdec_ts_list
135 {
136 public:
137     omx_swvdec_ts_list();
138     ~omx_swvdec_ts_list();
139 
140     void reset();
141     bool push(long long timestamp);
142     bool pop(long long *p_timestamp);
143 
144 private:
145     OMX_SWVDEC_TS_ELEMENT m_list[OMX_SWVDEC_TS_LIST_ELEMENTS];
146                                           ///< list of timestamp elements
147     int                   m_count_filled; ///< count of filled elements
148     pthread_mutex_t       m_mutex;        ///< mutex for list access
149 };
150 
151 #define DIAG_FILENAME_IP "/data/misc/media/input.bin"  ///<  input filename
152 #define DIAG_FILENAME_OP "/data/misc/media/output.yuv" ///< output filename
153 
154 /// OMX SwVdec diagnostics class
155 class omx_swvdec_diag
156 {
157 public:
158     omx_swvdec_diag();
159     ~omx_swvdec_diag();
160 
161     void dump_ip(unsigned char *p_buffer, unsigned int   filled_length);
162     void dump_op(unsigned char *p_buffer,
163                  unsigned int   width,
164                  unsigned int   height,
165                  unsigned int   stride,
166                  unsigned int   scanlines);
167 
168 private:
169     unsigned int m_dump_ip; ///< dump input bitstream
170     unsigned int m_dump_op; ///< dump output YUV
171 
172     char *m_filename_ip; ///<  input filename string
173     char *m_filename_op; ///< output filename string
174 
175     FILE *m_file_ip; ///<  input file handle
176     FILE *m_file_op; ///< output file handle
177 };
178 
179 #endif // #ifndef _OMX_SWVDEC_UTILS_H_
180