1
2/*
3 * Copyright (C) Texas Instruments - http://www.ti.com/
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Lesser General Public License for more details.
15 *
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21/* =============================================================================
22*             Texas Instruments OMAP(TM) Platform Software
23*  (c) Copyright Texas Instruments, Incorporated.  All Rights Reserved.
24*
25*  Use of this software is controlled by the terms and conditions found
26*  in the license agreement under which this software has been supplied.
27* =========================================================================== */
28/**
29* @file OMX_TI_Debug.h
30*
31* This file implements the TI-specific OMX Debug interface
32*
33* @path  $(CSLPATH)\inc
34*
35* @rev  0.1
36*/
37/* -------------------------------------------------------------------------- */
38/* =============================================================================
39*!
40*! Revision History
41*! ================================================================
42*!
43*! 10-Mar-2009 lm: Revisions appear in reverse chronological order;
44*! that is, newest first.  The date format is dd-Mon-yyyy.
45* =========================================================================== */
46
47#ifndef OMX_TI_DEBUG__H
48#define OMX_TI_DEBUG__H
49
50#include <ctype.h>
51#include <utils/Log.h>
52/*
53    The OMX TI Debug interface allows debug messages to be classified by
54    domain and importance.  There are no preset classifications required, but
55    rather these are arbitrary.  Nonetheless, all modules using this interface
56    must adhere to these domain and level conventions.
57
58    While it would make sense that errors should be printed at the highest
59    level, we separated errors into their own domain, as even error printing
60    could have additional details that are not always desirable to print.
61
62    In order to facilitate using the debug interface, a set of macros are
63    defined for the common domains and levels.
64
65    Features of the TI Debug interface:
66
67    - debug messages are maskable: only messages for domains marked, and that
68      have levels at least of the mask's level will be printed
69    - there are two output files supported.  Error domain output is going to
70      the error file, whereas other outputs usually go into the other output
71      file.  This also allows only printing error messages.
72    - colors can be specified for each domain - through this file or the
73      macros
74    - line number information can be added (via a compile time option)
75
76    Compile time flags:
77
78    __OMX_DEBUG__      - enable OMX Debug print calls
79    __OMX_DBG_COLOR__  - enable color output
80    __OMX_DBG_FN__     - print function
81    __OMX_DBG_FILE__   - print file
82    __OMX_DBG_LINE__   - print line number
83    __OMX_DBG_LEVEL__  - print level
84    __OMX_DBG_DOMAIN__ - print domain
85    __OMX_DBG_4ISERROR__ - print level 4 messages into the error file
86
87    __OMX_DBG_ANDROID__ - always outputs to Android log.  Otherwise, Android
88                          log is only used if output is stderr or stdout.
89
90    Output format is:
91    file:function():line domain<level> message
92
93*/
94
95/*  You can change this file here to globally set the debug configurations
96
97 */
98#define __OMX_DEBUG__
99#undef  __OMX_DBG_COLOR__
100#undef  __OMX_DBG_FILE__
101#define __OMX_DBG_FN__
102#define __OMX_DBG_LINE__
103#undef  __OMX_DBG_DOMAIN__
104#undef  __OMX_DBG_LEVEL__
105#undef  __OMX_DBG_4ISERROR__
106#undef  __OMX_DBG_ANDROID__
107
108/*
109 *  OMX Debug levels specify the importance of the debug print
110 *
111 *  0 - very verbose      -- any details, such as system return values, etc.
112 *  1 - quite verbose     -- details
113 *  2 - verbose           -- main details
114 *  3 - normal            -- what an average user would want to see
115 *  4 - quiet             -- only important messages -- this would not be
116 *                           normally used by OMX components except for error
117 *                           messages as they don't output anything normally.
118 *                           This could be used by applications and tests.
119 *  5 - very quiet        -- crucial/error messages - goes to error file
120 */
121
122/* this is used as a bitmask currently, so must be 2^n-1 */
123#define OMX_DBG_MAX_LEVEL 0x0F
124
125/*
126 *  OMX Debug domains specify the system that the messages relate to
127 */
128#define OMX_DBG_DOM_ERROR  0x1ul         /* an error */
129#define OMX_DBG_DOM_PRINT  0x10ul        /* generic prints */
130#define OMX_DBG_DOM_SYSTEM 0x100ul       /* generic OS systems: memory, etc. */
131#define OMX_DBG_DOM_STATE  0x1000ul      /* state transitions */
132#define OMX_DBG_DOM_BUFFER 0x10000ul     /* buffer transfer between */
133#define OMX_DBG_DOM_DSP    0x100000ul    /* DSP communication/transfer */
134#define OMX_DBG_DOM_COMM   0x1000000ul   /* communication */
135#define OMX_DBG_DOM_MGR    0x10000000ul  /* communication with managers */
136
137#define OMX_DBG_BASEMASK   0x33333333ul  /* all domains at normal verbosity */
138
139/*
140 *  Generic DEBUG Settings
141 */
142struct OMX_TI_Debug
143{
144    FILE *out;    /* standard output file */
145    FILE *err;    /* error output file - used for the error domain
146                     and crucial messages */
147    FILE *out_opened;  /* opened output file */
148    FILE *err_opened;  /* opened error file */
149    OMX_U32 mask; /* debug mask */
150};
151
152/*
153 *  :TRICKY: do { } while (0) makes this behave like any other C function call
154 *           even though it contains several statements
155 */
156
157/* This macro sets the debug mask in the debug structure based on a mask
158   string */
159#define OMX_DBG_SET_MASK(dbg, mask_str) \
160    do { \
161        if (mask_str) { \
162            sscanf((mask_str), "%lx", &(dbg).mask); \
163            if (strlen(mask_str) < 8) { \
164                (dbg).mask &= ~0ul >> (32 - 4 * strlen(mask_str)); \
165                (dbg).mask |= OMX_DBG_BASEMASK << (4 * strlen(mask_str)); \
166            } \
167        } else { \
168            (dbg).mask = OMX_DBG_BASEMASK; \
169        } \
170    } while (0)
171
172/* This macro initializes the debug structure.  Default configuration is
173   stdout/stderr output and base mask. */
174#define OMX_DBG_INIT_BASE(dbg) \
175    do { \
176        (dbg).err = stderr; \
177        (dbg).out = stdout; \
178        (dbg).out_opened = (dbg).err_opened = NULL; \
179        (dbg).mask = OMX_DBG_BASEMASK; \
180    } while (0)
181
182/* This macro initializes the debug structure.  Default configuration is
183   stdout/stderr output and base mask.  If the OMX_DBG_CONFIG environment
184   variable is defined, the file given by this variable is opened and each line
185   is compared to the tag string followed by _OUT, _ERR or _LEVEL to specify
186   the output and error file names, or the debug level.  If the debug level
187   string is less than 8 hexadecimal digits, the remaining domain mask levels
188   are set to the base mask (3). */
189#define OMX_DBG_INITALL(dbg, tag_str, file) \
190    do { \
191        (dbg).err = stderr; \
192        (dbg).out = stdout; \
193        (dbg).out_opened = (dbg).err_opened = NULL; \
194        (dbg).mask = OMX_DBG_BASEMASK; \
195        char *config_file = getenv("OMX_DBG_CONFIG"); \
196        FILE *config = (config_file && *config_file) ? fopen(config_file, "rt") : NULL; \
197        if (config) { \
198            char line[80], *ptr, *end, out[75], err[75]; \
199            out[0] = err[0] = '\0'; \
200            while (fgets(line, sizeof(line), config)) { \
201                for (ptr = line; isspace(*ptr); ptr++); \
202                if (!strncmp(ptr, tag_str, strlen(tag_str))) { \
203                    ptr += strlen(tag_str); \
204                    end = ptr + strlen(ptr); \
205                    while (end > ptr && isspace(end[-1])) *--end = '\0'; \
206                    if (file && !strncmp(ptr, "_ERR", 4) && isspace(ptr[4])) { \
207                        ptr += 4; \
208                        while (isspace(*ptr)) ptr++; \
209                        strcpy(err, ptr); \
210                    } else if (file && !strncmp(ptr, "_OUT", 4) && isspace(ptr[4])) { \
211                        ptr += 4; \
212                        while (isspace(*ptr)) ptr++; \
213                        strcpy(out, ptr); \
214                    } else if (!strncmp(ptr, "_LEVEL", 6) && isspace(ptr[6])) { \
215                        ptr += 6; \
216                        while (isspace(*ptr)) ptr++; \
217                        OMX_DBG_SET_MASK(dbg, ptr); \
218                    } \
219                } \
220            } \
221            if (file) { \
222                if (!strcmp(out, "stdout")) {} \
223                else if (!strcmp(out, "stderr")) (dbg).out = stderr; \
224                else if (!strcmp(out, "null")) (dbg).out = NULL; \
225                else if (*out) (dbg).out_opened = (dbg).out = fopen(out, "w"); \
226                if (!strcmp(err, "stderr")) {} \
227                else if (!strcmp(err, "stdout")) (dbg).err = stdout; \
228                else if (!strcmp(err, "null")) (dbg).err = NULL; \
229                else if (!strcmp(err, out)) (dbg).err = (dbg).out; \
230                else if (*err) (dbg).err_opened = (dbg).err = fopen(err, "w"); \
231            } \
232            fclose(config); \
233        } \
234    } while (0)
235
236
237#define OMX_DBG_INIT(dbg, tag_str)      OMX_DBG_INITALL(dbg, tag_str, 1)
238#define OMX_DBG_INIT_MASK(dbg, tag_str) OMX_DBG_INITALL(dbg, tag_str, 0)
239
240
241/* Use this macro to copy a OMX_TI_Debug config received. */
242#define OMX_DBG_SETCONFIG(dbg, pConfig) \
243    do { \
244        struct OMX_TI_Debug *pConfDbg = (struct OMX_TI_Debug *) pConfig; \
245        (dbg).mask = pConfDbg->mask; \
246        (dbg).out = pConfDbg->out; \
247        (dbg).err = pConfDbg->err; \
248    } while (0)
249
250/* Use this macro to copy a OMX_TI_Debug config to be sent. */
251#define OMX_DBG_GETCONFIG(dbg, pConfig) \
252    do { \
253        struct OMX_TI_Debug *pConfDbg = (struct OMX_TI_Debug *) pConfig; \
254        pConfDbg->mask = dbg.mask; \
255        pConfDbg->out = dbg.out; \
256        pConfDbg->err = dbg.err; \
257        pConfDbg->err_opened = pConfDbg->out_opened = NULL; \
258    } while (0)
259
260/* Use this macro to close any opened file that was opened by OMX_DBG. */
261#define OMX_DBG_CLOSE(dbg) \
262    do { \
263        if ((dbg).err_opened) { \
264            if ((dbg).err == (dbg).err_opened) (dbg).err = stderr; \
265            fclose((dbg).err_opened); \
266        } \
267        if ((dbg).out_opened) { \
268            if ((dbg).out == (dbg).out_opened) (dbg).out = stdout; \
269            if ((dbg).err == (dbg).out_opened) (dbg).err = stderr; \
270            fclose((dbg).out_opened); \
271        } \
272        (dbg).err_opened = (dbg).out_opened = NULL; \
273    } while (0)
274
275#ifdef __OMX_DEBUG__
276
277/*
278 *  GENERIC OMX TI DEBUG STATEMENT
279 *
280 *  file   - output of the debug message
281 *  level  - level of the debug message
282 *  domain - domain of the debug message
283 *  mask   - debug print mask, only messages for domains marked, and that have
284 *           levels at least of the mask's level will be printed
285 *  format, list - debug message
286 */
287
288#ifdef ANDROID
289#ifdef __OMX_DEBUG_ANDROID__
290    #define OMX_DBG_PRINT(file, domain, level, mask, format, list...) \
291        do {\
292            if ((file) && (OMX_U32) (level * domain) >= (OMX_U32) ((mask) & (domain * OMX_DBG_MAX_LEVEL))) \
293                ALOGD(OMX_DBG_FN_FMT OMX_DBG_LINE_FMT OMX_DBG_FMT \
294                    format OMX_DBG_FN OMX_DBG_LINE, ##list); \
295        } while (0)
296#else
297    #define OMX_DBG_PRINT(file, domain, level, mask, format, list...) \
298        do {\
299            if ((file) && (OMX_U32) (level * domain) >= (OMX_U32) ((mask) & (domain * OMX_DBG_MAX_LEVEL))) { \
300                if (file == stderr || file == stdout) { \
301                    ALOGD(OMX_DBG_FN_FMT OMX_DBG_LINE_FMT OMX_DBG_FMT \
302                        format OMX_DBG_FN OMX_DBG_LINE, ##list); \
303                } else { \
304                fprintf((file), \
305                        OMX_DBG_FILE OMX_DBG_FN_FMT OMX_DBG_LINE_FMT OMX_DBG_FMT \
306                        format OMX_DBG_FN OMX_DBG_LINE, ##list); \
307                } \
308            } \
309        } while (0)
310#endif
311#else
312    #define OMX_DBG_PRINT(file, domain, level, mask, format, list...) \
313        do {\
314            if ((file) && (OMX_U32) (level * domain) >= (OMX_U32) ((mask) & (domain * OMX_DBG_MAX_LEVEL))) \
315                fprintf((file), \
316                        OMX_DBG_FILE OMX_DBG_FN_FMT OMX_DBG_LINE_FMT OMX_DBG_FMT \
317                        format OMX_DBG_FN OMX_DBG_LINE, ##list); \
318        } while (0)
319#endif
320
321/*  Alternate mask understanding implementation.  Use this if we cannot specify a
322    level for each domain */
323/*
324    #define OMX_DBG_PRINT(file, domain, level, mask, format, list...) \
325        do {\
326            if (file && (mask & domain) && level >= (mask & OMX_MASK_LEVEL)) \
327                fprintf(file, \
328                        OMX_DBG_FILE OMX_DBG_FN_FMT OMX_DBG_LINE_FMT OMX_DBG_FMT \
329                        format, OMX_DBG_FN OMX_DBG_LINE ##list); \
330        } while (0)
331*/
332
333#else
334/* empty definitions */
335    #define OMX_DBG_PRINT(file, domain, level, mask, format, list...)
336#endif
337
338/*
339 *  OMX BAIL Shortcut macros
340 */
341#define OMX_DBG_BAIL_IF_ERROR(_eError, dbg, cmd, format, list...) \
342    do { \
343        if (_eError) { \
344            cmd(dbg, format, ##list); \
345            OMX_CONF_BAIL_IF_ERROR(_eError); \
346        } \
347    } while (0)
348
349#define OMX_DBG_SET_ERROR_BAIL(_eError, _eErrorValue, dbg, cmd, format, list...) \
350    do { \
351        cmd(dbg, format, ##list); \
352        OMX_CONF_SET_ERROR_BAIL(_eError, _eErrorValue); \
353    } while (0)
354
355#define OMX_DBG_CHECK_CMD(dbg, _ptr1, _ptr2, _ptr3) \
356    do { \
357        if(!_ptr1) OMX_ERROR4(dbg, "NULL parameter (" #_ptr1 ").\n"); \
358        else if(!_ptr2) OMX_ERROR4(dbg, "NULL parameter (" #_ptr2 ").\n"); \
359        else if(!_ptr3) OMX_ERROR4(dbg, "NULL parameter (" #_ptr3 ").\n"); \
360        OMX_CONF_CHECK_CMD(_ptr1, _ptr2, _ptr3); \
361    } while (0)
362
363
364/*
365 *  GENERIC OMX TI DEBUG Shortcut macros
366 */
367
368/* This variant uses a shortcut for the domain notation, but is not traceable
369   by source understanders.  It also adds the color to the format string. */
370#define OMXDBG_PRINT(file, domain, level, mask, format, list...) \
371   OMX_DBG_PRINT(file, OMX_DBG_DOM_##domain, level, mask, \
372                 OMX_DBG_COL_##domain OMX_DBG_DOM_##domain##_STR OMX_DBG_LEVEL(level) format OMX_DBG_COL_WHITE, ##list)
373
374/* Shortcuts */
375#define OMX_ERROR0(dbg, format, list...) OMXDBG_PRINT((dbg).err, ERROR, 0, (dbg).mask, format, ##list)
376#define OMX_ERROR1(dbg, format, list...) OMXDBG_PRINT((dbg).err, ERROR, 1, (dbg).mask, format, ##list)
377#define OMX_ERROR2(dbg, format, list...) OMXDBG_PRINT((dbg).err, ERROR, 2, (dbg).mask, format, ##list)
378#define OMX_ERROR3(dbg, format, list...) OMXDBG_PRINT((dbg).err, ERROR, 3, (dbg).mask, format, ##list)
379#define OMX_ERROR4(dbg, format, list...) OMXDBG_PRINT((dbg).err, ERROR, 4, (dbg).mask, format, ##list)
380#define OMX_ERROR5(dbg, format, list...) OMXDBG_PRINT((dbg).err, ERROR, 5, (dbg).mask, format, ##list)
381#define OMX_TRACE0(dbg, format, list...) OMXDBG_PRINT((dbg).out, SYSTEM, 0, (dbg).mask, format, ##list)
382#define OMX_TRACE1(dbg, format, list...) OMXDBG_PRINT((dbg).out, SYSTEM, 1, (dbg).mask, format, ##list)
383#define OMX_TRACE2(dbg, format, list...) OMXDBG_PRINT((dbg).out, SYSTEM, 2, (dbg).mask, format, ##list)
384#define OMX_TRACE3(dbg, format, list...) OMXDBG_PRINT((dbg).out, SYSTEM, 3, (dbg).mask, format, ##list)
385#define OMX_TRACE4(dbg, format, list...) OMXDBG_PRINT((dbg).OMX_DBG_LEVEL4, SYSTEM, 4, (dbg).mask, format, ##list)
386#define OMX_TRACE5(dbg, format, list...) OMXDBG_PRINT((dbg).err, SYSTEM, 5, (dbg).mask, format, ##list)
387#define OMX_PRINT0(dbg, format, list...) OMXDBG_PRINT((dbg).out, PRINT, 0, (dbg).mask, format, ##list)
388#define OMX_PRINT1(dbg, format, list...) OMXDBG_PRINT((dbg).out, PRINT, 1, (dbg).mask, format, ##list)
389#define OMX_PRINT2(dbg, format, list...) OMXDBG_PRINT((dbg).out, PRINT, 2, (dbg).mask, format, ##list)
390#define OMX_PRINT3(dbg, format, list...) OMXDBG_PRINT((dbg).out, PRINT, 3, (dbg).mask, format, ##list)
391#define OMX_PRINT4(dbg, format, list...) OMXDBG_PRINT((dbg).OMX_DBG_LEVEL4, PRINT, 4, (dbg).mask, format, ##list)
392#define OMX_PRINT5(dbg, format, list...) OMXDBG_PRINT((dbg).err, PRINT, 5, (dbg).mask, format, ##list)
393#define OMX_PRBUFFER0(dbg, format, list...) OMXDBG_PRINT((dbg).out, BUFFER, 0, (dbg).mask, format, ##list)
394#define OMX_PRBUFFER1(dbg, format, list...) OMXDBG_PRINT((dbg).out, BUFFER, 1, (dbg).mask, format, ##list)
395#define OMX_PRBUFFER2(dbg, format, list...) OMXDBG_PRINT((dbg).out, BUFFER, 2, (dbg).mask, format, ##list)
396#define OMX_PRBUFFER3(dbg, format, list...) OMXDBG_PRINT((dbg).out, BUFFER, 3, (dbg).mask, format, ##list)
397#define OMX_PRBUFFER4(dbg, format, list...) OMXDBG_PRINT((dbg).OMX_DBG_LEVEL4, BUFFER, 4, (dbg).mask, format, ##list)
398#define OMX_PRBUFFER5(dbg, format, list...) OMXDBG_PRINT((dbg).err, BUFFER, 5, (dbg).mask, format, ##list)
399#define OMX_PRMGR0(dbg, format, list...) OMXDBG_PRINT((dbg).out, MGR, 0, (dbg).mask, format, ##list)
400#define OMX_PRMGR1(dbg, format, list...) OMXDBG_PRINT((dbg).out, MGR, 1, (dbg).mask, format, ##list)
401#define OMX_PRMGR2(dbg, format, list...) OMXDBG_PRINT((dbg).out, MGR, 2, (dbg).mask, format, ##list)
402#define OMX_PRMGR3(dbg, format, list...) OMXDBG_PRINT((dbg).out, MGR, 3, (dbg).mask, format, ##list)
403#define OMX_PRMGR4(dbg, format, list...) OMXDBG_PRINT((dbg).OMX_DBG_LEVEL4, MGR, 4, (dbg).mask, format, ##list)
404#define OMX_PRMGR5(dbg, format, list...) OMXDBG_PRINT((dbg).err, MGR, 5, (dbg).mask, format, ##list)
405#define OMX_PRDSP0(dbg, format, list...) OMXDBG_PRINT((dbg).out, DSP, 0, (dbg).mask, format, ##list)
406#define OMX_PRDSP1(dbg, format, list...) OMXDBG_PRINT((dbg).out, DSP, 1, (dbg).mask, format, ##list)
407#define OMX_PRDSP2(dbg, format, list...) OMXDBG_PRINT((dbg).out, DSP, 2, (dbg).mask, format, ##list)
408#define OMX_PRDSP3(dbg, format, list...) OMXDBG_PRINT((dbg).out, DSP, 3, (dbg).mask, format, ##list)
409#define OMX_PRDSP4(dbg, format, list...) OMXDBG_PRINT((dbg).OMX_DBG_LEVEL4, DSP, 4, (dbg).mask, format, ##list)
410#define OMX_PRDSP5(dbg, format, list...) OMXDBG_PRINT((dbg).err, DSP, 5, (dbg).mask, format, ##list)
411#define OMX_PRCOMM0(dbg, format, list...) OMXDBG_PRINT((dbg).out, COMM, 0, (dbg).mask, format, ##list)
412#define OMX_PRCOMM1(dbg, format, list...) OMXDBG_PRINT((dbg).out, COMM, 1, (dbg).mask, format, ##list)
413#define OMX_PRCOMM2(dbg, format, list...) OMXDBG_PRINT((dbg).out, COMM, 2, (dbg).mask, format, ##list)
414#define OMX_PRCOMM3(dbg, format, list...) OMXDBG_PRINT((dbg).out, COMM, 3, (dbg).mask, format, ##list)
415#define OMX_PRCOMM4(dbg, format, list...) OMXDBG_PRINT((dbg).OMX_DBG_LEVEL4, COMM, 4, (dbg).mask, format, ##list)
416#define OMX_PRCOMM5(dbg, format, list...) OMXDBG_PRINT((dbg).err, COMM, 5, (dbg).mask, format, ##list)
417#define OMX_PRSTATE0(dbg, format, list...) OMXDBG_PRINT((dbg).out, STATE, 0, (dbg).mask, format, ##list)
418#define OMX_PRSTATE1(dbg, format, list...) OMXDBG_PRINT((dbg).out, STATE, 1, (dbg).mask, format, ##list)
419#define OMX_PRSTATE2(dbg, format, list...) OMXDBG_PRINT((dbg).out, STATE, 2, (dbg).mask, format, ##list)
420#define OMX_PRSTATE3(dbg, format, list...) OMXDBG_PRINT((dbg).out, STATE, 3, (dbg).mask, format, ##list)
421#define OMX_PRSTATE4(dbg, format, list...) OMXDBG_PRINT((dbg).OMX_DBG_LEVEL4, STATE, 4, (dbg).mask, format, ##list)
422#define OMX_PRSTATE5(dbg, format, list...) OMXDBG_PRINT((dbg).err, STATE, 5, (dbg).mask, format, ##list)
423
424/*
425 *  Compile Time Customizations
426 */
427
428/*
429 *  Context
430 */
431#ifdef __OMX_DBG_FN__
432    #define OMX_DBG_FN_FMT "%s()"
433    #define OMX_DBG_FN , __FUNCTION__
434#else
435    #define OMX_DBG_FN_FMT
436    #define OMX_DBG_FN
437#endif
438
439#ifdef __OMX_DBG_LINE__
440    #define OMX_DBG_LINE_FMT ":%d"
441    #define OMX_DBG_LINE , __LINE__
442#else
443    #define OMX_DBG_LINE_FMT
444    #define OMX_DBG_LINE
445#endif
446
447#ifdef __OMX_DBG_FILE__
448    #ifdef __OMX_DBG_FN__
449        #define OMX_DBG_FILE __FILE__ ":"
450    #else
451        #define OMX_DBG_FILE __FILE__
452    #endif
453#else
454    #define OMX_DBG_FILE
455#endif
456
457#if defined(__OMX_DBG_LEVEL__)
458    #define OMX_DBG_LEVEL(level) "<" #level "> "
459#elif defined(__OMX_DBG_DOMAIN__)
460    #define OMX_DBG_LEVEL(level) " "
461#else
462    #define OMX_DBG_LEVEL(level)
463#endif
464
465#ifdef __OMX_DBG_DOMAIN__
466    #define OMX_DBG_DOM_ERROR_STR  "ERR"
467    #define OMX_DBG_DOM_BUFFER_STR "BUF"
468    #define OMX_DBG_DOM_COMM_STR   "COM"
469    #define OMX_DBG_DOM_DSP_STR    "DSP"
470    #define OMX_DBG_DOM_SYSTEM_STR "SYS"
471    #define OMX_DBG_DOM_MGR_STR    "MGR"
472    #define OMX_DBG_DOM_STATE_STR  "STA"
473    #define OMX_DBG_DOM_PRINT_STR  "GEN"
474#else
475    #define OMX_DBG_DOM_ERROR_STR
476    #define OMX_DBG_DOM_BUFFER_STR
477    #define OMX_DBG_DOM_COMM_STR
478    #define OMX_DBG_DOM_DSP_STR
479    #define OMX_DBG_DOM_SYSTEM_STR
480    #define OMX_DBG_DOM_MGR_STR
481    #define OMX_DBG_DOM_STATE_STR
482    #define OMX_DBG_DOM_PRINT_STR
483#endif
484
485#ifdef __OMX_DBG_4ISERROR__
486    #define OMX_DBG_LEVEL4 err
487#else
488    #define OMX_DBG_LEVEL4 out
489#endif
490
491#if defined(__OMX_DBG_LINE__) || defined(__OMX_DBG_FN__) || defined(__OMX_DBG_FILE__)
492    #define OMX_DBG_FMT " "
493#else
494    #define OMX_DBG_FMT
495#endif
496
497/*
498 *  Color (ANSI escape sequences)
499 */
500#ifdef __OMX_DBG_COLOR__
501    #define OMX_DBG_COL_RED     "\x1b[1;31;40m"
502    #define OMX_DBG_COL_GREEN   "\x1b[1;32;40m"
503    #define OMX_DBG_COL_YELLOW  "\x1b[1;33;40m"
504    #define OMX_DBG_COL_BLUE    "\x1b[1;34;40m"
505    #define OMX_DBG_COL_MAGENTA "\x1b[1;35;40m"
506    #define OMX_DBG_COL_CYAN    "\x1b[1;36;40m"
507    #define OMX_DBG_COL_WHITE   "\x1b[1;37;40m"
508#else
509    #define OMX_DBG_COL_BLUE
510    #define OMX_DBG_COL_CYAN
511    #define OMX_DBG_COL_GREEN
512    #define OMX_DBG_COL_MAGENTA
513    #define OMX_DBG_COL_RED
514    #define OMX_DBG_COL_WHITE
515    #define OMX_DBG_COL_YELLOW
516#endif
517
518/*
519 *  Domain colors - these can be predefined differently
520 */
521
522#ifndef OMX_DBG_COL_ERROR
523#define OMX_DBG_COL_ERROR OMX_DBG_COL_RED
524#endif
525#ifndef OMX_DBG_COL_SYSTEM
526#define OMX_DBG_COL_SYSTEM OMX_DBG_COL_WHITE
527#endif
528#ifndef OMX_DBG_COL_PRINT
529#define OMX_DBG_COL_PRINT OMX_DBG_COL_WHITE
530#endif
531#ifndef OMX_DBG_COL_BUFFER
532#define OMX_DBG_COL_BUFFER OMX_DBG_COL_GREEN
533#endif
534#ifndef OMX_DBG_COL_MGR
535#define OMX_DBG_COL_MGR OMX_DBG_COL_MAGENTA
536#endif
537#ifndef OMX_DBG_COL_DSP
538#define OMX_DBG_COL_DSP OMX_DBG_COL_CYAN
539#endif
540#ifndef OMX_DBG_COL_COMM
541#define OMX_DBG_COL_COMM OMX_DBG_COL_YELLOW
542#endif
543#ifndef OMX_DBG_COL_STATE
544#define OMX_DBG_COL_STATE OMX_DBG_COL_BLUE
545#endif
546
547#ifdef OMX_MEMDEBUG
548#define mem_array_size=500;
549
550void *arr[mem_array_size];
551int lines[mem_array_size];
552int bytes[mem_array_size];
553char file[mem_array_size][50];
554
555#define newmalloc(x) mymalloc(__LINE__,__FILE__,x)
556#define newfree(z) myfree(z,__LINE__,__FILE__)
557
558void * mymalloc(int line, char *s, int size);
559int myfree(void *dp, int line, char *s);
560
561void * mymalloc(int line, char *s, int size)
562{
563   void *p;
564   int e=0;
565   p = malloc(size);
566   if(p==NULL){
567       OMXDBG_PRINT(stderr, ERROR, 4, 0, "Memory not available\n");
568       /* ddexit(1); */
569       }
570   else{
571         while((lines[e]!=0)&& (e<(mem_array_size - 1)) ){
572              e++;
573         }
574         arr[e]=p;
575         lines[e]=line;
576         bytes[e]=size;
577         strcpy(file[e],s);
578         OMXDBG_PRINT(stderr, BUFFER, 2, 0,
579            "Allocating %d bytes on address %p, line %d file %s pos %d\n", size, p, line, s, e);
580   }
581   return p;
582}
583
584int myfree(void *dp, int line, char *s){
585    int q;
586    for(q=0;q<mem_array_size;q++){
587        if(arr[q]==dp){
588           OMXDBG_PRINT(stderr, PRINT, 2, 0, "Deleting %d bytes on address %p, line %d file %s\n",
589                   bytes[q],dp, line, s);
590           free(dp);
591           dp = NULL;
592           lines[q]=0;
593           strcpy(file[q],"");
594           break;
595        }
596     }
597     if(mem_array_size==q){
598         OMXDBG_PRINT(stderr, PRINT, 2, 0, "\n\nPointer not found. Line:%d    File%s!!\n\n",line, s);
599     }
600}
601
602#else
603
604#define newmalloc(x) malloc(x)
605#define newfree(z) free(z)
606
607#endif
608
609
610#endif
611