VideoEditorUtils.h revision 32ed3f4dad00f8a65f7e6b38402c70d5341c57eb
1/*
2 * Copyright (C) 2011 NXP Software
3 * Copyright (C) 2011 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*************************************************************************
19* @file   VideoEditorUtils.cpp
20* @brief  StageFright shell Utilities
21*************************************************************************
22*/
23#ifndef ANDROID_UTILS_H_
24#define ANDROID_UTILS_H_
25
26/*******************
27 *     HEADERS     *
28 *******************/
29
30#include "M4OSA_Debug.h"
31
32#include "utils/Log.h"
33#include <utils/RefBase.h>
34#include <utils/threads.h>
35#include <media/stagefright/MediaSource.h>
36#include <media/stagefright/MetaData.h>
37
38/**
39 *************************************************************************
40 * VIDEOEDITOR_CHECK(test, errCode)
41 * @note This macro displays an error message and goes to function cleanUp label
42 *       if the test fails.
43 *************************************************************************
44 */
45#define VIDEOEDITOR_CHECK(test, errCode) \
46{ \
47    if( !(test) ) { \
48        LOGV("!!! %s (L%d) check failed : " #test ", yields error 0x%.8x", \
49            __FILE__, __LINE__, errCode); \
50        err = (errCode); \
51        goto cleanUp; \
52    } \
53}
54
55/**
56 *************************************************************************
57 * SAFE_FREE(p)
58 * @note This macro calls free and makes sure the pointer is set to NULL.
59 *************************************************************************
60 */
61#define SAFE_FREE(p) \
62{ \
63    if(M4OSA_NULL != (p)) { \
64        M4OSA_free((M4OSA_MemAddr32)(p)) ; \
65        (p) = M4OSA_NULL ; \
66    } \
67}
68
69/**
70 *************************************************************************
71 * SAFE_MALLOC(p, type, count, comment)
72 * @note This macro allocates a buffer, checks for success and fills the buffer
73 *       with 0.
74 *************************************************************************
75 */
76#define SAFE_MALLOC(p, type, count, comment) \
77{ \
78    (p) = (type*)M4OSA_malloc(sizeof(type)*(count), 0xFF,(M4OSA_Char*)comment);\
79    VIDEOEDITOR_CHECK(M4OSA_NULL != (p), M4ERR_ALLOC); \
80    memset((void *)(p), 0,sizeof(type)*(count)); \
81}
82
83
84    /********************
85     *    UTILITIES     *
86     ********************/
87
88
89namespace android {
90
91/*--------------------------*/
92/* DISPLAY METADATA CONTENT */
93/*--------------------------*/
94void displayMetaData(const sp<MetaData> meta);
95
96// Build the AVC codec spcific info from the StageFright encoders output
97status_t buildAVCCodecSpecificData(uint8_t **outputData, size_t *outputSize,
98        const uint8_t *data, size_t size, MetaData *param);
99
100}//namespace android
101
102
103#endif //ANDROID_UTILS_H_
104