Home | History | Annotate | Download | only in mediaeditor
      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 #include <VideoEditorJava.h>
     18 #include <VideoEditorLogging.h>
     19 #include <VideoEditorOsal.h>
     20 
     21 extern "C" {
     22 #include <M4OSA_Clock.h>
     23 #include <M4OSA_CharStar.h>
     24 #include <M4OSA_FileCommon.h>
     25 #include <M4OSA_FileReader.h>
     26 #include <M4OSA_FileWriter.h>
     27 #include <M4OSA_Memory.h>
     28 #include <M4OSA_Thread.h>
     29 #include <M4xVSS_API.h>
     30 #include <M4VSS3GPP_ErrorCodes.h>
     31 #include <M4MCS_ErrorCodes.h>
     32 #include <M4READER_Common.h>
     33 #include <M4WRITER_common.h>
     34 #include <M4VSS3GPP_API.h>
     35 #include <M4DECODER_Common.h>
     36 };
     37 
     38 
     39 #define VIDEOEDIT_OSAL_RESULT_STRING_MAX     (32)
     40 
     41 #define VIDEOEDIT_OSAL_RESULT_INIT(m_result) { m_result, #m_result }
     42 
     43 
     44 typedef struct
     45 {
     46     M4OSA_ERR   result;
     47     const char* pName;
     48 } VideoEdit_Osal_Result;
     49 
     50 static const VideoEdit_Osal_Result gkRESULTS[] =
     51 {
     52     // M4OSA_Clock.h
     53     VIDEOEDIT_OSAL_RESULT_INIT(M4WAR_TIMESCALE_TOO_BIG                                ),
     54     VIDEOEDIT_OSAL_RESULT_INIT(M4ERR_CLOCK_BAD_REF_YEAR                               ),
     55 
     56     // M4OSA_Error.h
     57     VIDEOEDIT_OSAL_RESULT_INIT(M4NO_ERROR                                             ),
     58     VIDEOEDIT_OSAL_RESULT_INIT(M4ERR_PARAMETER                                        ),
     59     VIDEOEDIT_OSAL_RESULT_INIT(M4ERR_STATE                                            ),
     60     VIDEOEDIT_OSAL_RESULT_INIT(M4ERR_ALLOC                                            ),
     61     VIDEOEDIT_OSAL_RESULT_INIT(M4ERR_BAD_CONTEXT                                      ),
     62     VIDEOEDIT_OSAL_RESULT_INIT(M4ERR_CONTEXT_FAILED                                   ),
     63     VIDEOEDIT_OSAL_RESULT_INIT(M4ERR_BAD_STREAM_ID                                    ),
     64     VIDEOEDIT_OSAL_RESULT_INIT(M4ERR_BAD_OPTION_ID                                    ),
     65     VIDEOEDIT_OSAL_RESULT_INIT(M4ERR_WRITE_ONLY                                       ),
     66     VIDEOEDIT_OSAL_RESULT_INIT(M4ERR_READ_ONLY                                        ),
     67     VIDEOEDIT_OSAL_RESULT_INIT(M4ERR_NOT_IMPLEMENTED                                  ),
     68     VIDEOEDIT_OSAL_RESULT_INIT(M4ERR_UNSUPPORTED_MEDIA_TYPE                           ),
     69     VIDEOEDIT_OSAL_RESULT_INIT(M4WAR_NO_DATA_YET                                      ),
     70     VIDEOEDIT_OSAL_RESULT_INIT(M4WAR_NO_MORE_STREAM                                   ),
     71     VIDEOEDIT_OSAL_RESULT_INIT(M4WAR_INVALID_TIME                                     ),
     72     VIDEOEDIT_OSAL_RESULT_INIT(M4WAR_NO_MORE_AU                                       ),
     73     VIDEOEDIT_OSAL_RESULT_INIT(M4WAR_TIME_OUT                                         ),
     74     VIDEOEDIT_OSAL_RESULT_INIT(M4WAR_BUFFER_FULL                                      ),
     75     VIDEOEDIT_OSAL_RESULT_INIT(M4WAR_REDIRECT                                         ),
     76     VIDEOEDIT_OSAL_RESULT_INIT(M4WAR_TOO_MUCH_STREAMS                                 ),
     77 
     78     // M4OSA_FileCommon.h
     79     VIDEOEDIT_OSAL_RESULT_INIT(M4ERR_FILE_NOT_FOUND                                   ),
     80     VIDEOEDIT_OSAL_RESULT_INIT(M4ERR_FILE_LOCKED                                      ),
     81     VIDEOEDIT_OSAL_RESULT_INIT(M4ERR_FILE_BAD_MODE_ACCESS                             ),
     82     VIDEOEDIT_OSAL_RESULT_INIT(M4ERR_FILE_INVALID_POSITION                            ),
     83 
     84     // M4OSA_Thread.h
     85     VIDEOEDIT_OSAL_RESULT_INIT(M4ERR_THREAD_NOT_STARTED                               ),
     86 
     87     // M4xVSS_API.h
     88     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_WAR_ANALYZING_DONE                           ),
     89     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_WAR_PREVIEW_READY                            ),
     90     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_WAR_SAVING_DONE                              ),
     91     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_WAR_TRANSCODING_NECESSARY                    ),
     92     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_WAR_OUTPUTFILESIZE_EXCEED                    ),
     93     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_JPG_TOO_BIG                              ),
     94     VIDEOEDIT_OSAL_RESULT_INIT(M4xVSSWAR_BUFFER_OUT_TOO_SMALL                         ),
     95     VIDEOEDIT_OSAL_RESULT_INIT(M4xVSSERR_NO_MORE_SPACE                                ),
     96 
     97     // M4VSS3GPP_ErrorCodes.h
     98     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_INVALID_FILE_TYPE                        ),
     99     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_INVALID_EFFECT_KIND                      ),
    100     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_INVALID_VIDEO_EFFECT_TYPE                ),
    101     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_INVALID_AUDIO_EFFECT_TYPE                ),
    102     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_INVALID_VIDEO_TRANSITION_TYPE            ),
    103     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_INVALID_AUDIO_TRANSITION_TYPE            ),
    104     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_INVALID_VIDEO_ENCODING_FRAME_RATE        ),
    105     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_EXTERNAL_EFFECT_NULL                     ),
    106     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_EXTERNAL_TRANSITION_NULL                 ),
    107     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_BEGIN_CUT_LARGER_THAN_DURATION           ),
    108     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_BEGIN_CUT_LARGER_THAN_END_CUT            ),
    109     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_OVERLAPPING_TRANSITIONS                  ),
    110 #ifdef M4VSS3GPP_ERR_ANALYSIS_DATA_SIZE_TOO_SMALL
    111     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_ANALYSIS_DATA_SIZE_TOO_SMALL             ),
    112 #endif
    113     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_INVALID_3GPP_FILE                        ),
    114     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_UNSUPPORTED_INPUT_VIDEO_FORMAT           ),
    115     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_UNSUPPORTED_INPUT_AUDIO_FORMAT           ),
    116     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_AMR_EDITING_UNSUPPORTED                  ),
    117     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_INPUT_VIDEO_AU_TOO_LARGE                 ),
    118     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_INPUT_AUDIO_AU_TOO_LARGE                 ),
    119     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_INPUT_AUDIO_CORRUPTED_AU                 ),
    120 #ifdef M4VSS3GPP_ERR_INPUT_AUDIO_CORRUPTED_AMR_AU
    121     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_INPUT_AUDIO_CORRUPTED_AMR_AU             ),
    122 #endif
    123     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_ENCODER_ACCES_UNIT_ERROR                 ),
    124     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_EDITING_UNSUPPORTED_VIDEO_FORMAT         ),
    125     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_EDITING_UNSUPPORTED_H263_PROFILE         ),
    126     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_EDITING_UNSUPPORTED_MPEG4_PROFILE        ),
    127     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_EDITING_UNSUPPORTED_MPEG4_RVLC           ),
    128     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_EDITING_UNSUPPORTED_AUDIO_FORMAT         ),
    129     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_EDITING_NO_SUPPORTED_STREAM_IN_FILE      ),
    130     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_EDITING_NO_SUPPORTED_VIDEO_STREAM_IN_FILE),
    131     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_INVALID_CLIP_ANALYSIS_VERSION            ),
    132 #ifdef M4VSS3GPP_ERR_INVALID_CLIP_ANALYSIS_PLATFORM
    133     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_INVALID_CLIP_ANALYSIS_PLATFORM           ),
    134 #endif
    135     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_INCOMPATIBLE_VIDEO_FORMAT                ),
    136     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_INCOMPATIBLE_VIDEO_FRAME_SIZE            ),
    137     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_INCOMPATIBLE_VIDEO_TIME_SCALE            ),
    138     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_INCOMPATIBLE_VIDEO_DATA_PARTITIONING     ),
    139     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_UNSUPPORTED_MP3_ASSEMBLY                 ),
    140     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_WAR_INCOMPATIBLE_AUDIO_STREAM_TYPE           ),
    141     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_WAR_INCOMPATIBLE_AUDIO_NB_OF_CHANNELS        ),
    142     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_WAR_INCOMPATIBLE_AUDIO_SAMPLING_FREQUENCY    ),
    143     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_NO_SUPPORTED_STREAM_IN_FILE              ),
    144     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_ADDVOLUME_EQUALS_ZERO                    ),
    145     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_ADDCTS_HIGHER_THAN_VIDEO_DURATION        ),
    146     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_UNDEFINED_AUDIO_TRACK_FILE_FORMAT        ),
    147     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_UNSUPPORTED_ADDED_AUDIO_STREAM           ),
    148     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_AUDIO_MIXING_UNSUPPORTED                 ),
    149     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_FEATURE_UNSUPPORTED_WITH_AUDIO_TRACK     ),
    150     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_AUDIO_CANNOT_BE_MIXED                    ),
    151     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_INPUT_CLIP_IS_NOT_A_3GPP                 ),
    152     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_BEGINLOOP_HIGHER_ENDLOOP                 ),
    153 #ifdef M4VSS3GPP_ERR_AUDIO_MIXING_MP3_UNSUPPORTED
    154     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_AUDIO_MIXING_MP3_UNSUPPORTED             ),
    155 #endif
    156 #ifdef M4VSS3GPP_ERR_FEATURE_UNSUPPORTED_WITH_AAC
    157     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_FEATURE_UNSUPPORTED_WITH_AAC             ),
    158 #endif
    159 #ifdef M4VSS3GPP_ERR_ONLY_AMRNB_INPUT_CAN_BE_MIXED
    160     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_ONLY_AMRNB_INPUT_CAN_BE_MIXED            ),
    161 #endif
    162 #ifdef M4VSS3GPP_ERR_FEATURE_UNSUPPORTED_WITH_EVRC
    163     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_FEATURE_UNSUPPORTED_WITH_EVRC            ),
    164 #endif
    165     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_H263_PROFILE_NOT_SUPPORTED               ),
    166     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_NO_SUPPORTED_VIDEO_STREAM_IN_FILE        ),
    167     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_INTERNAL_STATE                           ),
    168     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_LUMA_FILTER_ERROR                        ),
    169     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_TRANSITION_FILTER_ERROR                  ),
    170     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_AUDIO_DECODER_INIT_FAILED                ),
    171     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_AUDIO_DECODED_PCM_SIZE_ISSUE             ),
    172     VIDEOEDIT_OSAL_RESULT_INIT(M4VSS3GPP_ERR_OUTPUT_FILE_TYPE_ERROR                   ),
    173 
    174     // M4MCS_ErrorCodes.h
    175     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_WAR_TRANSCODING_DONE                             ),
    176     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED                      ),
    177     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_ERR_INPUT_FILE_CONTAINS_NO_SUPPORTED_STREAM      ),
    178     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_ERR_INVALID_INPUT_FILE                           ),
    179     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_ERR_UNDEFINED_OUTPUT_VIDEO_FORMAT                ),
    180     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_ERR_UNDEFINED_OUTPUT_VIDEO_FRAME_SIZE            ),
    181     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_ERR_UNDEFINED_OUTPUT_VIDEO_FRAME_RATE            ),
    182     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_ERR_UNDEFINED_OUTPUT_AUDIO_FORMAT                ),
    183     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_ERR_INVALID_VIDEO_FRAME_SIZE_FOR_H263            ),
    184     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_ERR_INVALID_VIDEO_FRAME_RATE_FOR_H263            ),
    185     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_ERR_DURATION_IS_NULL                             ),
    186     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_ERR_H263_FORBIDDEN_IN_MP4_FILE                   ),
    187     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_ERR_H263_PROFILE_NOT_SUPPORTED                   ),
    188     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_ERR_INVALID_AAC_SAMPLING_FREQUENCY               ),
    189     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_ERR_AUDIO_CONVERSION_FAILED                      ),
    190     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_ERR_BEGIN_CUT_LARGER_THAN_DURATION               ),
    191     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_ERR_BEGIN_CUT_EQUALS_END_CUT                     ),
    192     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_ERR_END_CUT_SMALLER_THAN_BEGIN_CUT               ),
    193     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_ERR_MAXFILESIZE_TOO_SMALL                        ),
    194     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_ERR_VIDEOBITRATE_TOO_LOW                         ),
    195     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_ERR_AUDIOBITRATE_TOO_LOW                         ),
    196     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_ERR_VIDEOBITRATE_TOO_HIGH                        ),
    197     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_ERR_AUDIOBITRATE_TOO_HIGH                        ),
    198     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_ERR_OUTPUT_FILE_SIZE_TOO_SMALL                   ),
    199     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_ERR_NOMORE_SPACE                                 ),
    200     VIDEOEDIT_OSAL_RESULT_INIT(M4MCS_ERR_FILE_DRM_PROTECTED                           ),
    201 
    202     // M4READER_Common.h
    203     VIDEOEDIT_OSAL_RESULT_INIT(M4ERR_READER_UNKNOWN_STREAM_TYPE                       ),
    204     VIDEOEDIT_OSAL_RESULT_INIT(M4WAR_READER_NO_METADATA                               ),
    205     VIDEOEDIT_OSAL_RESULT_INIT(M4WAR_READER_INFORMATION_NOT_PRESENT                   ),
    206 
    207     // M4WRITER_Common.h
    208     VIDEOEDIT_OSAL_RESULT_INIT(M4WAR_WRITER_STOP_REQ                                  ),
    209     // M4DECODER_Common.h
    210     VIDEOEDIT_OSAL_RESULT_INIT(M4WAR_VIDEORENDERER_NO_NEW_FRAME                       ),
    211     VIDEOEDIT_OSAL_RESULT_INIT(M4WAR_DEBLOCKING_FILTER_NOT_IMPLEMENTED                ),
    212     VIDEOEDIT_OSAL_RESULT_INIT(M4ERR_DECODER_H263_PROFILE_NOT_SUPPORTED               ),
    213     VIDEOEDIT_OSAL_RESULT_INIT(M4ERR_DECODER_H263_NOT_BASELINE                        )
    214 };
    215 
    216 static const int gkRESULTS_COUNT = (sizeof(gkRESULTS) / sizeof(VideoEdit_Osal_Result));
    217 
    218 #ifdef OSAL_MEM_LEAK_DEBUG
    219 static int gAllocatedBlockCount = 0;
    220 #endif
    221 
    222 const char*
    223 videoEditOsal_getResultString(
    224                 M4OSA_ERR                           result)
    225 {
    226     static char string[VIDEOEDIT_OSAL_RESULT_STRING_MAX] = "";
    227     const char* pString                         = M4OSA_NULL;
    228     int         index                           = 0;
    229 
    230     // Loop over the list with constants.
    231     for (index = 0;
    232          ((M4OSA_NULL == pString) && (index < gkRESULTS_COUNT));
    233          index++)
    234     {
    235         // Check if the specified result matches.
    236         if (result == gkRESULTS[index].result)
    237         {
    238             // Set the description.
    239             pString = gkRESULTS[index].pName;
    240         }
    241     }
    242 
    243     // Check if no result was found.
    244     if (M4OSA_NULL == pString)
    245     {
    246         // Set the description to a default value.
    247         M4OSA_chrSPrintf((M4OSA_Char *)string, sizeof(string) - 1,
    248          (M4OSA_Char*)"<unknown(0x%08X)>", result);
    249         pString = string;
    250     }
    251 
    252     // Return the result.
    253     return(pString);
    254 }
    255 
    256 void *
    257 videoEditOsal_alloc(
    258                 bool*                               pResult,
    259                 JNIEnv*                             pEnv,
    260                 size_t                              size,
    261                 const char*                         pDescription)
    262 {
    263     void *pData = M4OSA_NULL;
    264 
    265     // Check if the previous action succeeded.
    266     if (*pResult)
    267     {
    268         // Allocate memory for the settings.
    269         pData = (M4VSS3GPP_EditSettings*)M4OSA_32bitAlignedMalloc(size, 0, (M4OSA_Char*)pDescription);
    270         if (M4OSA_NULL != pData)
    271         {
    272             // Reset the allocated memory.
    273             memset((void *)pData, 0,size);
    274 #ifdef OSAL_MEM_LEAK_DEBUG
    275             // Update the allocated block count.
    276             gAllocatedBlockCount++;
    277 #endif
    278         }
    279         else
    280         {
    281             // Reset the result flag.
    282             (*pResult) = false;
    283 
    284             // Log the error.
    285             VIDEOEDIT_LOG_ERROR(ANDROID_LOG_ERROR, "VIDEO_EDITOR_OSAL", "videoEditOsal_alloc,\
    286              error: unable to allocate memory for %s", pDescription);
    287 
    288             // Throw an exception.
    289             jniThrowException(pEnv, "java/lang/OutOfMemoryError", "unable to allocate memory");
    290         }
    291     }
    292 
    293     // Return the allocated memory.
    294     return(pData);
    295 }
    296 
    297 void
    298 videoEditOsal_free(
    299                 void*                               pData)
    300 {
    301     // Check if memory was allocated.
    302     if (M4OSA_NULL != pData)
    303     {
    304         VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_OSAL", "videoEditOsal_free()");
    305 
    306         // Log the API call.
    307         VIDEOEDIT_LOG_API(ANDROID_LOG_INFO, "VIDEO_EDITOR_OSAL", "free");
    308 
    309         // Free the memory.
    310         free(pData);
    311 #ifdef OSAL_MEM_LEAK_DEBUG
    312         // Update the allocated block count.
    313         gAllocatedBlockCount--;
    314 
    315         // Log the number of allocated blocks.
    316         VIDEOEDIT_LOG_ALLOCATION(ANDROID_LOG_ERROR, "VIDEO_EDITOR_OSAL", "allocated, %d blocks",\
    317          gAllocatedBlockCount);
    318 #endif
    319     }
    320 }
    321 
    322 
    323 void
    324 videoEditOsal_getFilePointers ( M4OSA_FileReadPointer *pOsaFileReadPtr,
    325                                 M4OSA_FileWriterPointer *pOsaFileWritePtr)
    326 {
    327     if (pOsaFileReadPtr != M4OSA_NULL)
    328     {
    329         // Initialize the filereader function pointers.
    330         pOsaFileReadPtr->openRead  = M4OSA_fileReadOpen;
    331         pOsaFileReadPtr->readData  = M4OSA_fileReadData;
    332         pOsaFileReadPtr->seek      = M4OSA_fileReadSeek;
    333         pOsaFileReadPtr->closeRead = M4OSA_fileReadClose;
    334         pOsaFileReadPtr->setOption = M4OSA_fileReadSetOption;
    335         pOsaFileReadPtr->getOption = M4OSA_fileReadGetOption;
    336     }
    337 
    338     if (pOsaFileWritePtr != M4OSA_NULL)
    339     {
    340         // Initialize the filewriter function pointers.
    341         pOsaFileWritePtr->openWrite  = M4OSA_fileWriteOpen;
    342         pOsaFileWritePtr->writeData  = M4OSA_fileWriteData;
    343         pOsaFileWritePtr->seek       = M4OSA_fileWriteSeek;
    344         pOsaFileWritePtr->Flush      = M4OSA_fileWriteFlush;
    345         pOsaFileWritePtr->closeWrite = M4OSA_fileWriteClose;
    346         pOsaFileWritePtr->setOption  = M4OSA_fileWriteSetOption;
    347         pOsaFileWritePtr->getOption  = M4OSA_fileWriteGetOption;
    348     }
    349 }
    350 
    351