Home | History | Annotate | Download | only in inc
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 /**
     17 *************************************************************************
     18 * @file   VideoEditorUtils.cpp
     19 * @brief  StageFright shell Utilities
     20 *************************************************************************
     21 */
     22 #ifndef ANDROID_UTILS_H_
     23 #define ANDROID_UTILS_H_
     24 
     25 /*******************
     26  *     HEADERS     *
     27  *******************/
     28 
     29 #include "M4OSA_Debug.h"
     30 
     31 #include "utils/Log.h"
     32 #include <utils/RefBase.h>
     33 #include <utils/threads.h>
     34 #include <media/stagefright/MediaSource.h>
     35 #include <media/stagefright/MetaData.h>
     36 
     37 /**
     38  *************************************************************************
     39  * VIDEOEDITOR_CHECK(test, errCode)
     40  * @note This macro displays an error message and goes to function cleanUp label
     41  *       if the test fails.
     42  *************************************************************************
     43  */
     44 #define VIDEOEDITOR_CHECK(test, errCode) \
     45 { \
     46     if( !(test) ) { \
     47         ALOGV("!!! %s (L%d) check failed : " #test ", yields error 0x%.8x", \
     48             __FILE__, __LINE__, errCode); \
     49         err = (errCode); \
     50         goto cleanUp; \
     51     } \
     52 }
     53 
     54 /**
     55  *************************************************************************
     56  * SAFE_FREE(p)
     57  * @note This macro calls free and makes sure the pointer is set to NULL.
     58  *************************************************************************
     59  */
     60 #define SAFE_FREE(p) \
     61 { \
     62     if(M4OSA_NULL != (p)) { \
     63         free((p)) ; \
     64         (p) = M4OSA_NULL ; \
     65     } \
     66 }
     67 
     68 /**
     69  *************************************************************************
     70  * SAFE_MALLOC(p, type, count, comment)
     71  * @note This macro allocates a buffer, checks for success and fills the buffer
     72  *       with 0.
     73  *************************************************************************
     74  */
     75 #define SAFE_MALLOC(p, type, count, comment) \
     76 { \
     77     (p) = (type*)M4OSA_32bitAlignedMalloc(sizeof(type)*(count), 0xFF,(M4OSA_Char*)comment);\
     78     VIDEOEDITOR_CHECK(M4OSA_NULL != (p), M4ERR_ALLOC); \
     79     memset((void *)(p), 0,sizeof(type)*(count)); \
     80 }
     81 
     82 
     83     /********************
     84      *    UTILITIES     *
     85      ********************/
     86 
     87 
     88 namespace android {
     89 
     90 /*--------------------------*/
     91 /* DISPLAY METADATA CONTENT */
     92 /*--------------------------*/
     93 void displayMetaData(const sp<MetaData> meta);
     94 
     95 // Build the AVC codec spcific info from the StageFright encoders output
     96 status_t buildAVCCodecSpecificData(uint8_t **outputData, size_t *outputSize,
     97         const uint8_t *data, size_t size, MetaData *param);
     98 
     99 }//namespace android
    100 
    101 
    102 #endif //ANDROID_UTILS_H_
    103