diff options
author | Gilbok Lee <gilbok.lee@samsung.com> | 2018-10-31 18:04:43 +0900 |
---|---|---|
committer | Gilbok Lee <gilbok.lee@samsung.com> | 2018-11-05 14:37:05 +0900 |
commit | 7a2d9dc529b6ed8176f87a3b2d723ccddc85ef26 (patch) | |
tree | d2826306d67ba6531502025b8a11e58ef31753bd | |
parent | bf57cdf96cb5b1343b87717e6afd802072be88d4 (diff) | |
download | libmm-player-7a2d9dc529b6ed8176f87a3b2d723ccddc85ef26.tar.gz libmm-player-7a2d9dc529b6ed8176f87a3b2d723ccddc85ef26.tar.bz2 libmm-player-7a2d9dc529b6ed8176f87a3b2d723ccddc85ef26.zip |
[0.6.138] resolve complexity issue
- resolve the cyclomatic complexity issue of below function
__mmplayer_parse_profile
Change-Id: Ic80069144ffc531c3eb031ffe6c93b0aeeefbc83
-rw-r--r-- | packaging/libmm-player.spec | 2 | ||||
-rw-r--r-- | src/mm_player_priv.c | 300 |
2 files changed, 143 insertions, 159 deletions
diff --git a/packaging/libmm-player.spec b/packaging/libmm-player.spec index ca25fff..cf42747 100644 --- a/packaging/libmm-player.spec +++ b/packaging/libmm-player.spec @@ -1,6 +1,6 @@ Name: libmm-player Summary: Multimedia Framework Player Library -Version: 0.6.137 +Version: 0.6.138 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 diff --git a/src/mm_player_priv.c b/src/mm_player_priv.c index 6bbea38..c000d2d 100644 --- a/src/mm_player_priv.c +++ b/src/mm_player_priv.c @@ -197,6 +197,9 @@ static void __mmplayer_audio_stream_send_data(mm_player_t* player, mm_player_au static void __mmplayer_initialize_storage_info(mm_player_t* player, MMPlayerPathType path_type); static int __resource_release_cb(mm_resource_manager_h rm, mm_resource_manager_res_h res, void *user_data); +static void __mmplayer_copy_uri_and_set_type(MMPlayerParseProfile* data, const char *uri, int uri_type); +static int __mmplayer_set_mem_uri(MMPlayerParseProfile* data, char *path, void *param); +static int __mmplayer_set_file_uri(MMPlayerParseProfile* data, const char *uri); /*=========================================================================================== | | | FUNCTION DEFINITIONS | @@ -5028,7 +5031,7 @@ __mmplayer_gst_set_message_callback(mm_player_t* player, MMMessageCallback callb int __mmplayer_parse_profile(const char *uri, void *param, MMPlayerParseProfile* data) { - int ret = MM_ERROR_PLAYER_INVALID_URI; + int ret = MM_ERROR_NONE; char *path = NULL; MMPLAYER_FENTER(); @@ -5039,173 +5042,33 @@ int __mmplayer_parse_profile(const char *uri, void *param, MMPlayerParseProfile* memset(data, 0, sizeof(MMPlayerParseProfile)); - if ((path = strstr(uri, "es_buff://"))) { - if (strlen(path)) { - strncpy(data->uri, uri, MM_MAX_URL_LEN-1); - data->uri_type = MM_PLAYER_URI_TYPE_MS_BUFF; - ret = MM_ERROR_NONE; - } - } else if ((path = strstr(uri, "rtsp://")) || (path = strstr(uri, "rtsps://"))) { - if (strlen(path)) { - strncpy(data->uri, uri, MM_MAX_URL_LEN-1); - data->uri_type = MM_PLAYER_URI_TYPE_URL_RTSP; - ret = MM_ERROR_NONE; - } - } else if ((path = strstr(uri, "http://")) || (path = strstr(uri, "https://"))) { - if (strlen(path)) { - gchar *tmp = NULL; - strncpy(data->uri, uri, MM_MAX_URL_LEN-1); - tmp = g_ascii_strdown(uri, strlen(uri)); - - if (tmp && (g_str_has_suffix(tmp, ".ism/manifest") || g_str_has_suffix(tmp, ".isml/manifest"))) - data->uri_type = MM_PLAYER_URI_TYPE_SS; - else - data->uri_type = MM_PLAYER_URI_TYPE_URL_HTTP; - - ret = MM_ERROR_NONE; - g_free(tmp); - } - } else if ((path = strstr(uri, "rtspu://"))) { - if (strlen(path)) { - strncpy(data->uri, uri, MM_MAX_URL_LEN-1); - data->uri_type = MM_PLAYER_URI_TYPE_URL_RTSP; - ret = MM_ERROR_NONE; - } - } else if ((path = strstr(uri, "rtspr://"))) { - strncpy(data->uri, path, MM_MAX_URL_LEN-1); - char *separater = strstr(path, "*"); - - if (separater) { - int urgent_len = 0; - char *urgent = separater + strlen("*"); - - if ((urgent_len = strlen(urgent))) { - data->uri[strlen(path) - urgent_len - strlen("*")] = '\0'; - strncpy(data->urgent, urgent, MM_MAX_FILENAME_LEN-1); - data->uri_type = MM_PLAYER_URI_TYPE_URL_RTSP; - ret = MM_ERROR_NONE; - } - } - } else if ((path = strstr(uri, "mms://"))) { - if (strlen(path)) { - strncpy(data->uri, uri, MM_MAX_URL_LEN-1); - data->uri_type = MM_PLAYER_URI_TYPE_URL_MMS; - ret = MM_ERROR_NONE; - } + if (strstr(uri, "es_buff://")) { + __mmplayer_copy_uri_and_set_type(data, uri, MM_PLAYER_URI_TYPE_MS_BUFF); + } else if (strstr(uri, "rtsp://") || strstr(uri, "rtsps://") || strstr(uri, "rtspu://")) { + __mmplayer_copy_uri_and_set_type(data, uri, MM_PLAYER_URI_TYPE_URL_RTSP); + } else if (strstr(uri, "http://") || strstr(uri, "https://")) { + gchar *tmp = NULL; + tmp = g_ascii_strdown(uri, strlen(uri)); + if (tmp && (g_str_has_suffix(tmp, ".ism/manifest") || g_str_has_suffix(tmp, ".isml/manifest"))) + __mmplayer_copy_uri_and_set_type(data, uri, MM_PLAYER_URI_TYPE_SS); + else + __mmplayer_copy_uri_and_set_type(data, uri, MM_PLAYER_URI_TYPE_URL_HTTP); + g_free(tmp); + } else if (strstr(uri, "mms://")) { + __mmplayer_copy_uri_and_set_type(data, uri, MM_PLAYER_URI_TYPE_URL_MMS); } else if ((path = strstr(uri, "mem://"))) { - if (strlen(path)) { - int mem_size = 0; - char *buffer = NULL; - char *seperator = strchr(path, ','); - char ext[100] = {0,}, size[100] = {0,}; - - if (seperator) { - if ((buffer = strstr(path, "ext="))) { - buffer += strlen("ext="); - - if (strlen(buffer)) { - strncpy(ext, buffer, 99); - - if ((seperator = strchr(ext, ',')) - || (seperator = strchr(ext, ' ')) - || (seperator = strchr(ext, '\0'))) { - seperator[0] = '\0'; - } - } - } - - if ((buffer = strstr(path, "size="))) { - buffer += strlen("size="); - - if (strlen(buffer) > 0) { - strncpy(size, buffer, 99); - - if ((seperator = strchr(size, ',')) - || (seperator = strchr(size, ' ')) - || (seperator = strchr(size, '\0'))) { - seperator[0] = '\0'; - } - - mem_size = atoi(size); - } - } - } - - LOGD("ext: %s, mem_size: %d, mmap(param): %p\n", ext, mem_size, param); - if (mem_size && param) { - if (data->input_mem.buf) - free(data->input_mem.buf); - data->input_mem.buf = malloc(mem_size); - - if (data->input_mem.buf) { - memcpy(data->input_mem.buf, param, mem_size); - data->input_mem.len = mem_size; - ret = MM_ERROR_NONE; - } else { - LOGE("failed to alloc mem %d", mem_size); - ret = MM_ERROR_PLAYER_INTERNAL; - } - - data->input_mem.offset = 0; - data->uri_type = MM_PLAYER_URI_TYPE_MEM; - } - } + ret = __mmplayer_set_mem_uri(data, path, param); } else { - gchar *location = NULL; - GError *err = NULL; - - if ((path = strstr(uri, "file://"))) { - - location = g_filename_from_uri(uri, NULL, &err); - - if (!location || (err != NULL)) { - LOGE("Invalid URI '%s' for filesrc: %s", path, - (err != NULL) ? err->message : "unknown error"); - - if (err) g_error_free(err); - if (location) g_free(location); - - data->uri_type = MM_PLAYER_URI_TYPE_NONE; - goto exit; - } - - LOGD("path from uri: %s", location); - } - - path = (location != NULL) ? (location) : ((char*)uri); - int file_stat = MM_ERROR_NONE; - - file_stat = util_exist_file_path(path); - - /* if no protocol prefix exist. check file existence and then give file:// as it's prefix */ - if (file_stat == MM_ERROR_NONE) { - g_snprintf(data->uri, MM_MAX_URL_LEN, "file://%s", path); - - if (util_is_sdp_file(path)) { - LOGD("uri is actually a file but it's sdp file. giving it to rtspsrc\n"); - data->uri_type = MM_PLAYER_URI_TYPE_URL_RTSP; - } else { - data->uri_type = MM_PLAYER_URI_TYPE_FILE; - } - ret = MM_ERROR_NONE; - } else if (file_stat == MM_ERROR_PLAYER_PERMISSION_DENIED) { - data->uri_type = MM_PLAYER_URI_TYPE_NO_PERMISSION; - } else { - LOGE("invalid uri, could not play..\n"); - data->uri_type = MM_PLAYER_URI_TYPE_NONE; - } - - if (location) g_free(location); + ret = __mmplayer_set_file_uri(data, uri); } -exit: if (data->uri_type == MM_PLAYER_URI_TYPE_NONE) ret = MM_ERROR_PLAYER_FILE_NOT_FOUND; else if (data->uri_type == MM_PLAYER_URI_TYPE_NO_PERMISSION) ret = MM_ERROR_PLAYER_PERMISSION_DENIED; /* dump parse result */ - SECURE_LOGW("incomming uri : %s\n", uri); + SECURE_LOGW("incoming uri : %s\n", uri); LOGD("uri_type : %d, mem : %p, mem_size : %d, urgent : %s\n", data->uri_type, data->input_mem.buf, data->input_mem.len, data->urgent); @@ -10088,3 +9951,124 @@ _mmplayer_get_video_roi_area(MMHandleType hplayer, double *scale_x, double *scal return ret; } + +static void +__mmplayer_copy_uri_and_set_type(MMPlayerParseProfile* data, const char *uri, int uri_type) +{ + strncpy(data->uri, uri, MM_MAX_URL_LEN - 1); + data->uri_type = uri_type; +} +static int +__mmplayer_set_mem_uri(MMPlayerParseProfile* data, char *path, void *param) +{ + int ret = MM_ERROR_PLAYER_INVALID_URI; + int mem_size = 0; + char *buffer = NULL; + char *seperator = strchr(path, ','); + char ext[100] = {0,}, size[100] = {0,}; + + if (seperator) { + if ((buffer = strstr(path, "ext="))) { + buffer += strlen("ext="); + + if (strlen(buffer)) { + strncpy(ext, buffer, 99); + + if ((seperator = strchr(ext, ',')) + || (seperator = strchr(ext, ' ')) + || (seperator = strchr(ext, '\0'))) { + seperator[0] = '\0'; + } + } + } + + if ((buffer = strstr(path, "size="))) { + buffer += strlen("size="); + + if (strlen(buffer) > 0) { + strncpy(size, buffer, 99); + + if ((seperator = strchr(size, ',')) + || (seperator = strchr(size, ' ')) + || (seperator = strchr(size, '\0'))) { + seperator[0] = '\0'; + } + + mem_size = atoi(size); + } + } + } + + LOGD("ext: %s, mem_size: %d, mmap(param): %p\n", ext, mem_size, param); + + if (mem_size && param) { + if (data->input_mem.buf) + free(data->input_mem.buf); + data->input_mem.buf = malloc(mem_size); + + if (data->input_mem.buf) { + memcpy(data->input_mem.buf, param, mem_size); + data->input_mem.len = mem_size; + ret = MM_ERROR_NONE; + } else { + LOGE("failed to alloc mem %d", mem_size); + ret = MM_ERROR_PLAYER_INTERNAL; + } + + data->input_mem.offset = 0; + data->uri_type = MM_PLAYER_URI_TYPE_MEM; + } + + return ret; +} + +static int +__mmplayer_set_file_uri(MMPlayerParseProfile* data, const char *uri) +{ + gchar *location = NULL; + GError *err = NULL; + char *path = NULL; + int ret = MM_ERROR_NONE; + + if ((path = strstr(uri, "file://"))) { + location = g_filename_from_uri(uri, NULL, &err); + if (!location || (err != NULL)) { + LOGE("Invalid URI '%s' for filesrc: %s", path, + (err != NULL) ? err->message : "unknown error"); + if (err) + g_error_free(err); + if (location) + g_free(location); + + data->uri_type = MM_PLAYER_URI_TYPE_NONE; + return MM_ERROR_PLAYER_INVALID_URI; + } + LOGD("path from uri: %s", location); + } + + path = (location != NULL) ? (location) : ((char *)uri); + + + ret = util_exist_file_path(path); + + /* if no protocol prefix exist. check file existence and then give file:// as it's prefix */ + if (ret == MM_ERROR_NONE) { + g_snprintf(data->uri, MM_MAX_URL_LEN, "file://%s", path); + if (util_is_sdp_file(path)) { + LOGD("uri is actually a file but it's sdp file. giving it to rtspsrc\n"); + data->uri_type = MM_PLAYER_URI_TYPE_URL_RTSP; + } else { + data->uri_type = MM_PLAYER_URI_TYPE_FILE; + } + } else if (ret == MM_ERROR_PLAYER_PERMISSION_DENIED) { + data->uri_type = MM_PLAYER_URI_TYPE_NO_PERMISSION; + } else { + LOGE("invalid uri, could not play..\n"); + data->uri_type = MM_PLAYER_URI_TYPE_NONE; + } + + if (location) + g_free(location); + + return ret; +} |