Use macro instead
[platform/core/multimedia/libmm-fileinfo.git] / mm_file.c
index 7bb7b5b..50d0be5 100644 (file)
--- a/mm_file.c
+++ b/mm_file.c
@@ -264,8 +264,11 @@ static int _load_dynamic_functions(MMFILE_FUNC_HANDLE *pHandle)
        return 1;
 
 exception:
-       if (formatFuncHandle) dlclose(formatFuncHandle);
-       if (codecFuncHandle)  dlclose(codecFuncHandle);
+       if (formatFuncHandle)
+               dlclose(formatFuncHandle);
+
+       if (codecFuncHandle)
+               dlclose(codecFuncHandle);
 
        return ret;
 }
@@ -274,24 +277,21 @@ static void _unload_dynamic_functions(MMFILE_FUNC_HANDLE *pHandle)
 {
        debug_fenter(RELEASE);
 
-       if (pHandle->formatFuncHandle) {
+       if (pHandle->formatFuncHandle)
                dlclose(pHandle->formatFuncHandle);
-       }
-       if (pHandle->codecFuncHandle) {
+
+       if (pHandle->codecFuncHandle)
                dlclose(pHandle->codecFuncHandle);
-       }
 
        debug_fleave(RELEASE);
 }
 
-
 #endif /* __MMFILE_DYN_LOADING__ */
 
 /**
  * local functions.
  */
-static int
-_is_file_readable(const char *filename)
+static int _is_file_readable(const char *filename)
 {
        mm_file_retvm_if_fails(DEBUG, filename, FILEINFO_ERROR_INVALID_ARGUMENT);
 
@@ -308,8 +308,7 @@ _is_file_readable(const char *filename)
        return FILEINFO_ERROR_NONE;
 }
 
-static int
-_info_set_attr_media(MMHandleType attrs, MMFileFormatContext *formatContext)
+static int _info_set_attr_media(MMHandleType attrs, MMFileFormatContext *formatContext)
 {
        int ret = 0;
 
@@ -449,17 +448,15 @@ _info_set_attr_media(MMHandleType attrs, MMFileFormatContext *formatContext)
  * @param      videoStream             [in]    information of video codec for frameContext.
  * @param      decodedFrame    [inout] frame after decoding frameContext.
  */
-static int
-__decode_contents_frame(MMFileFormatFrame *frameContext, MMFileFormatStream *videoStream, MMFileCodecFrame *decodedFrame)
+static int __decode_contents_frame(MMFileFormatFrame *frameContext, MMFileFormatStream *videoStream, MMFileCodecFrame *decodedFrame)
 {
        int ret = FILEINFO_ERROR_NONE;
        MMFileCodecContext *codecContext = NULL;
        MMFileCodecFrame codecFrame = {0, };
 
-       if (!frameContext || !videoStream || !decodedFrame) {
-               debug_error(DEBUG, "error: invalid parameters (%p %p %p)\n", frameContext, videoStream, decodedFrame);
-               return FILEINFO_ERROR_FILE_INTERNAL;
-       }
+       mm_file_retvm_if_fails(DEBUG, frameContext, FILEINFO_ERROR_FILE_INTERNAL);
+       mm_file_retvm_if_fails(DEBUG, videoStream, FILEINFO_ERROR_FILE_INTERNAL);
+       mm_file_retvm_if_fails(DEBUG, decodedFrame, FILEINFO_ERROR_FILE_INTERNAL);
 
        codecFrame.frameDataSize = frameContext->frameSize;
        codecFrame.width = frameContext->frameWidth;
@@ -493,10 +490,7 @@ __get_contents_thumbnail(MMFileFormatContext *formatContext)
        MMFileCodecFrame decodedFrame = {0, };
        MMFileFormatFrame *thumbnail = NULL;
 
-       if (!formatContext) {
-               debug_error(DEBUG, "error: invalid parameter (%p)\n", formatContext);
-               return FILEINFO_ERROR_FILE_INTERNAL;
-       }
+       mm_file_retvm_if_fails(DEBUG, formatContext, FILEINFO_ERROR_FILE_INTERNAL);
 
        if (MMFILE_FORMAT_FAIL == mmfile_format_read_frame(formatContext, _SEEK_POINT_, &frameContext)) {
                debug_error(DEBUG, "error: mmfile_format_read_frame\n");
@@ -565,10 +559,8 @@ _get_contents_info(MMHandleType attrs, MMFileSourceType *src, MMFILE_PARSE_INFO
        MMFileFormatContext *formatContext = NULL;
        int ret = 0;
 
-       if (!src || !parse) {
-               debug_error(DEBUG, "error: invalid parameters (%p, %p)\n", src, parse);
-               return FILEINFO_ERROR_FILE_INTERNAL;
-       }
+       mm_file_retvm_if_fails(DEBUG, src, FILEINFO_ERROR_FILE_INTERNAL);
+       mm_file_retvm_if_fails(DEBUG, parse, FILEINFO_ERROR_FILE_INTERNAL);
 
        if (MMFILE_FORMAT_FAIL == mmfile_format_open(&formatContext, src) || formatContext == NULL) {
                debug_error(DEBUG, "error: mmfile_format_open\n");
@@ -688,15 +680,8 @@ int mm_file_get_attrs(MMHandleType attrs, const char *first_attribute_name, ...)
        va_list var_args;
        char *err_attr_name = NULL;
 
-       if (!attrs) {
-               debug_error(DEBUG, "Invalid arguments [attrs 0]\n");
-               return FILEINFO_ERROR_INVALID_ARGUMENT;
-       }
-
-       if (first_attribute_name == NULL) {
-               debug_error(DEBUG, "Invalid arguments [first_attribute_name null]\n");
-               return FILEINFO_ERROR_INVALID_ARGUMENT;
-       }
+       mm_file_retvm_if_fails(DEBUG, attrs, FILEINFO_ERROR_INVALID_ARGUMENT);
+       mm_file_retvm_if_fails(DEBUG, first_attribute_name, FILEINFO_ERROR_INVALID_ARGUMENT);
 
        /* get requested attributes */
        va_start(var_args, first_attribute_name);
@@ -721,10 +706,7 @@ int mm_file_get_synclyrics_info(MMHandleType tag_attrs, int index, unsigned long
 
        debug_fenter(RELEASE);
 
-       if (tag_attrs == NULL) {
-               debug_error(DEBUG, "invalid handle");
-               return FILEINFO_ERROR_INVALID_ARGUMENT;
-       }
+       mm_file_retvm_if_fails(DEBUG, tag_attrs, FILEINFO_ERROR_INVALID_ARGUMENT);
 
        ret = mm_attrs_get_data_by_name(tag_attrs, MM_FILE_TAG_SYNCLYRICS, (void **)&synclyrics_list);
        if (ret != FILEINFO_ERROR_NONE) {
@@ -732,25 +714,16 @@ int mm_file_get_synclyrics_info(MMHandleType tag_attrs, int index, unsigned long
                return ret;
        }
 
-       if (synclyrics_list != NULL) {
-
-               sync_lyric_item = (AvSynclyricsInfo *)g_list_nth_data(synclyrics_list, index);
+       mm_file_retvm_if_fails(RELEASE, synclyrics_list, FILEINFO_ERROR_ATTR_NOT_EXIST);
 
-               if (sync_lyric_item == NULL) {
-                       debug_warning(RELEASE, "synclyric item is NULL");
-                       return FILEINFO_ERROR_ATTR_NOT_EXIST;
-               }
+       sync_lyric_item = (AvSynclyricsInfo *)g_list_nth_data(synclyrics_list, index);
 
-               *time_info = sync_lyric_item->time_info;
-               *lyrics = sync_lyric_item->lyric_info;
+       mm_file_retvm_if_fails(RELEASE, sync_lyric_item, FILEINFO_ERROR_ATTR_NOT_EXIST);
 
-       } else {
-               debug_warning(RELEASE, "synclyrics_list is NULL");
-               return FILEINFO_ERROR_ATTR_NOT_EXIST;
-       }
+       *time_info = sync_lyric_item->time_info;
+       *lyrics = sync_lyric_item->lyric_info;
 
        return ret;
-
 }
 
 int mm_file_create_tag_attrs(MMHandleType *tag_attrs, const char *filename)
@@ -761,11 +734,7 @@ int mm_file_create_tag_attrs(MMHandleType *tag_attrs, const char *filename)
 
        debug_fenter(RELEASE);
 
-       /* Check argument here */
-       if (tag_attrs == NULL) {
-               debug_error(DEBUG, "Invalid arguments [tag null]\n");
-               return FILEINFO_ERROR_INVALID_ARGUMENT;
-       }
+       mm_file_retvm_if_fails(DEBUG, tag_attrs, FILEINFO_ERROR_INVALID_ARGUMENT);
 
        ret = _is_file_readable(filename);
        if (ret != FILEINFO_ERROR_NONE)
@@ -821,10 +790,7 @@ int mm_file_destroy_tag_attrs(MMHandleType tag_attrs)
 
        debug_fenter(RELEASE);
 
-       if (tag_attrs == NULL) {
-               debug_error(DEBUG, "invalid handle.\n");
-               return FILEINFO_ERROR_INVALID_ARGUMENT;
-       }
+       mm_file_retvm_if_fails(DEBUG, tag_attrs, FILEINFO_ERROR_INVALID_ARGUMENT);
 
        ret = mm_attrs_get_data_by_name(tag_attrs, MM_FILE_TAG_ARTWORK, &artwork);
        mmfile_free(artwork);
@@ -847,11 +813,7 @@ static int __create_content_attrs(MMHandleType *contents_attrs, const char *file
 
        debug_fenter(RELEASE);
 
-       /* Check argument here */
-       if (contents_attrs == NULL) {
-               debug_error(DEBUG, "Invalid arguments [contents null]\n");
-               return FILEINFO_ERROR_INVALID_ARGUMENT;
-       }
+       mm_file_retvm_if_fails(DEBUG, contents_attrs, FILEINFO_ERROR_INVALID_ARGUMENT);
 
        ret = _is_file_readable(filename);
        if (ret != FILEINFO_ERROR_NONE)
@@ -936,11 +898,8 @@ int mm_file_create_tag_attrs_from_memory(MMHandleType *tag_attrs, const void *da
 
        debug_fenter(RELEASE);
 
-       /* Check argument here */
-       if (tag_attrs == NULL || data == NULL) {
-               debug_error(DEBUG, "Invalid arguments\n");
-               return FILEINFO_ERROR_INVALID_ARGUMENT;
-       }
+       mm_file_retvm_if_fails(DEBUG, tag_attrs, FILEINFO_ERROR_INVALID_ARGUMENT);
+       mm_file_retvm_if_fails(DEBUG, data, FILEINFO_ERROR_INVALID_ARGUMENT);
 
 #ifdef __MMFILE_DYN_LOADING__
        MMFILE_FUNC_HANDLE func_handle;
@@ -993,11 +952,8 @@ int mm_file_create_content_attrs_from_memory(MMHandleType *contents_attrs, const
 
        debug_fenter(RELEASE);
 
-       /* Check argument here */
-       if (contents_attrs == NULL || data == NULL) {
-               debug_error(DEBUG, "Invalid arguments\n");
-               return FILEINFO_ERROR_INVALID_ARGUMENT;
-       }
+       mm_file_retvm_if_fails(DEBUG, contents_attrs, FILEINFO_ERROR_INVALID_ARGUMENT);
+       mm_file_retvm_if_fails(DEBUG, data, FILEINFO_ERROR_INVALID_ARGUMENT);
 
 #ifdef __MMFILE_DYN_LOADING__
        MMFILE_FUNC_HANDLE func_handle;
@@ -1048,10 +1004,7 @@ int mm_file_destroy_content_attrs(MMHandleType contents_attrs)
 
        debug_fenter(RELEASE);
 
-       if (contents_attrs == NULL) {
-               debug_error(DEBUG, "invalid handle.\n");
-               return FILEINFO_ERROR_INVALID_ARGUMENT;
-       }
+       mm_file_retvm_if_fails(DEBUG, contents_attrs, FILEINFO_ERROR_INVALID_ARGUMENT);
 
        ret = mm_attrs_get_data_by_name(contents_attrs, MM_FILE_CONTENT_VIDEO_THUMBNAIL, &thumbnail);
        mmfile_free(thumbnail);
@@ -1074,10 +1027,8 @@ int mm_file_get_stream_info(const char *filename, int *audio_stream_num, int *vi
 
        debug_fenter(RELEASE);
 
-       if (audio_stream_num == NULL || video_stream_num == NULL) {
-               debug_error(DEBUG, "Invalid arguments\n");
-               return FILEINFO_ERROR_INVALID_ARGUMENT;
-       }
+       mm_file_retvm_if_fails(DEBUG, audio_stream_num, FILEINFO_ERROR_INVALID_ARGUMENT);
+       mm_file_retvm_if_fails(DEBUG, video_stream_num, FILEINFO_ERROR_INVALID_ARGUMENT);
 
        ret = _is_file_readable(filename);
        if (ret != FILEINFO_ERROR_NONE)
@@ -1140,10 +1091,7 @@ int mm_file_get_video_frame(const char *path, double timestamp, bool is_accurate
        int ret = 0;
        void *formatFuncHandle = NULL;
 
-       if (path == NULL) {
-               debug_error(DEBUG, "Invalid arguments [Path is Null]\n");
-               return FILEINFO_ERROR_INVALID_ARGUMENT;
-       }
+       mm_file_retvm_if_fails(DEBUG, path, FILEINFO_ERROR_INVALID_ARGUMENT);
 
 #ifdef __MMFILE_DYN_LOADING__
        /* Get from function argument */
@@ -1168,12 +1116,14 @@ int mm_file_get_video_frame(const char *path, double timestamp, bool is_accurate
                goto exception;
        }
 
-       if (formatFuncHandle) dlclose(formatFuncHandle);
+       if (formatFuncHandle)
+               dlclose(formatFuncHandle);
 
        return FILEINFO_ERROR_NONE;
 
 exception:
-       if (formatFuncHandle) dlclose(formatFuncHandle);
+       if (formatFuncHandle)
+               dlclose(formatFuncHandle);
 
        return FILEINFO_ERROR_FILE_INTERNAL;
 }
@@ -1184,15 +1134,8 @@ int mm_file_get_video_frame_from_memory(const void *data, unsigned int datasize,
        int ret = 0;
        void *formatFuncHandle = NULL;
 
-       if (data == NULL) {
-               debug_error(DEBUG, "Invalid arguments [data is Null]\n");
-               return FILEINFO_ERROR_INVALID_ARGUMENT;
-       }
-
-       if (datasize == 0) {
-               debug_error(DEBUG, "Invalid arguments [datasize is zero]\n");
-               return FILEINFO_ERROR_INVALID_ARGUMENT;
-       }
+       mm_file_retvm_if_fails(DEBUG, data, FILEINFO_ERROR_INVALID_ARGUMENT);
+       mm_file_retvm_if_fails(DEBUG, datasize != 0, FILEINFO_ERROR_INVALID_ARGUMENT);
 
 #ifdef __MMFILE_DYN_LOADING__
        /* Get from function argument */
@@ -1217,12 +1160,14 @@ int mm_file_get_video_frame_from_memory(const void *data, unsigned int datasize,
                goto exception;
        }
 
-       if (formatFuncHandle) dlclose(formatFuncHandle);
+       if (formatFuncHandle)
+               dlclose(formatFuncHandle);
 
        return FILEINFO_ERROR_NONE;
 
 exception:
-       if (formatFuncHandle) dlclose(formatFuncHandle);
+       if (formatFuncHandle)
+               dlclose(formatFuncHandle);
 
        return FILEINFO_ERROR_FILE_INTERNAL;
 }