[0.2.122] check display type range 40/211940/3 accepted/tizen/unified/20190814.065136 submit/tizen/20190813.062516
authorEunhye Choi <eunhae1.choi@samsung.com>
Mon, 12 Aug 2019 08:49:33 +0000 (17:49 +0900)
committerEunhye Choi <eunhae1.choi@samsung.com>
Tue, 13 Aug 2019 04:27:46 +0000 (13:27 +0900)
- check type range according to the ASAN guide.
- change return type of the offload checking function
  and renaming it to simplify the usage which is additional
  patch of this commit :
  f5d99a565cc47a8be46fbd596aa9068431479902

Change-Id: I481b172a7e2ba239bddbe12ab60c6c0892227328

legacy/include/legacy_player_private.h
legacy/src/legacy_player.c

index ba7911f..81347e1 100644 (file)
@@ -45,6 +45,12 @@ extern "C" {
 #define PLAYER_NULL_ARG_CHECK(arg)      \
        PLAYER_CHECK_CONDITION((arg), PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER")
 
+#define PLAYER_RANGE_ARG_CHECK(arg, min, max)      \
+       do {    \
+               PLAYER_CHECK_CONDITION(((arg) >= (min)), PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");     \
+               PLAYER_CHECK_CONDITION(((arg) <= (max)), PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");     \
+       } while (0)
+
 #ifdef TIZEN_TTRACE
 #include <ttrace.h>
 #define PLAYER_TRACE_BEGIN(NAME) traceBegin(TTRACE_TAG_VIDEO, NAME)
index 74fe859..1a171a5 100644 (file)
@@ -646,19 +646,20 @@ __lplayer_convert_audio_pcm_mime_to_str(media_format_mimetype_e mime)
        return NULL;
 }
 
-static int __lplayer_audio_offload_is_enabled(legacy_player_h player, int *enabled)
+static bool __lplayer_is_offload_precondition_valid(legacy_player_h player)
 {
        int ret = MM_ERROR_NONE;
+       int enabled = 0;
        legacy_player_t *handle = (legacy_player_t *)player;
 
-       ret = mm_player_get_attribute(handle->mm_handle, NULL, MM_PLAYER_AUDIO_OFFLOAD, enabled, (char *)NULL);
+       ret = mm_player_get_attribute(handle->mm_handle, NULL, MM_PLAYER_AUDIO_OFFLOAD, &enabled, (char *)NULL);
        if (ret != MM_ERROR_NONE) {
-               LOGE("failed to get offload status");
-               return _lplayer_convert_error_code(ret, (char *)__FUNCTION__);
+               LOGE("failed to get offload status 0x%X", ret);
+               return false;
        }
 
-       LOGD("offload enabled : %d", *enabled);
-       return PLAYER_ERROR_NONE;
+       LOGD("offload status %d", enabled);
+       return (enabled) ? (false) : (true);
 }
 
 /*
@@ -1104,12 +1105,10 @@ int legacy_player_set_audio_latency_mode(legacy_player_h player, audio_latency_m
 {
        legacy_player_t *handle = (legacy_player_t *)player;
        int ret = MM_ERROR_NONE;
-       int enabled = 0;
 
        PLAYER_INSTANCE_CHECK(player);
 
-       if ((__lplayer_audio_offload_is_enabled(player, &enabled) != PLAYER_ERROR_NONE)
-               || (enabled))
+       if (!__lplayer_is_offload_precondition_valid(player))
                return PLAYER_ERROR_INVALID_OPERATION;
 
        ret = mm_player_set_attribute(handle->mm_handle, NULL, "sound_latency_mode", latency_mode, (char *)NULL);
@@ -1123,13 +1122,11 @@ int legacy_player_get_audio_latency_mode(legacy_player_h player, audio_latency_m
 {
        legacy_player_t *handle = (legacy_player_t *)player;
        int ret = MM_ERROR_NONE;
-       int enabled = 0;
 
        PLAYER_INSTANCE_CHECK(player);
        PLAYER_NULL_ARG_CHECK(latency_mode);
 
-       if ((__lplayer_audio_offload_is_enabled(player, &enabled) != PLAYER_ERROR_NONE)
-               || (enabled))
+       if (!__lplayer_is_offload_precondition_valid(player))
                return PLAYER_ERROR_INVALID_OPERATION;
 
        ret = mm_player_get_attribute(handle->mm_handle, NULL, "sound_latency_mode", latency_mode, (char *)NULL);
@@ -1417,14 +1414,12 @@ int legacy_player_set_playback_rate(legacy_player_h player, float rate)
 {
        legacy_player_t *handle = (legacy_player_t *)player;
        int ret = MM_ERROR_NONE;
-       int enabled = 0;
 
        LOGI("<ENTER: rate %0.1f>", rate);
        PLAYER_INSTANCE_CHECK(player);
        PLAYER_CHECK_CONDITION(rate >= -5.0 && rate <= 5.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
 
-       if ((__lplayer_audio_offload_is_enabled(player, &enabled) != PLAYER_ERROR_NONE)
-               || (enabled))
+       if (!__lplayer_is_offload_precondition_valid(player))
                return PLAYER_ERROR_INVALID_OPERATION;
 
        if (!_lplayer_state_validate(handle, PLAYER_STATE_READY)) {
@@ -1689,13 +1684,11 @@ int legacy_player_audio_effect_get_equalizer_bands_count(legacy_player_h player,
 {
        legacy_player_t *handle = (legacy_player_t *)player;
        int ret = MM_ERROR_NONE;
-       int enabled = 0;
 
        PLAYER_INSTANCE_CHECK(player);
        PLAYER_NULL_ARG_CHECK(count);
 
-       if ((__lplayer_audio_offload_is_enabled(player, &enabled) != PLAYER_ERROR_NONE)
-               || (enabled))
+       if (!__lplayer_is_offload_precondition_valid(player))
                return PLAYER_ERROR_INVALID_OPERATION;
 
        ret = mm_player_audio_effect_custom_get_eq_bands_number(handle->mm_handle, count);
@@ -1709,13 +1702,11 @@ int legacy_player_audio_effect_set_equalizer_all_bands(legacy_player_h player, i
 {
        legacy_player_t *handle = (legacy_player_t *)player;
        int ret = MM_ERROR_NONE;
-       int enabled = 0;
 
        PLAYER_INSTANCE_CHECK(player);
        PLAYER_NULL_ARG_CHECK(band_levels);
 
-       if ((__lplayer_audio_offload_is_enabled(player, &enabled) != PLAYER_ERROR_NONE)
-               || (enabled))
+       if (!__lplayer_is_offload_precondition_valid(player))
                return PLAYER_ERROR_INVALID_OPERATION;
 
        ret = mm_player_audio_effect_custom_set_level_eq_from_list(handle->mm_handle, band_levels, length);
@@ -1730,12 +1721,10 @@ int legacy_player_audio_effect_set_equalizer_band_level(legacy_player_h player,
 {
        legacy_player_t *handle = (legacy_player_t *)player;
        int ret = MM_ERROR_NONE;
-       int enabled = 0;
 
        PLAYER_INSTANCE_CHECK(player);
 
-       if ((__lplayer_audio_offload_is_enabled(player, &enabled) != PLAYER_ERROR_NONE)
-               || (enabled))
+       if (!__lplayer_is_offload_precondition_valid(player))
                return PLAYER_ERROR_INVALID_OPERATION;
 
        ret = mm_player_audio_effect_custom_set_level(handle->mm_handle, MM_AUDIO_EFFECT_CUSTOM_EQ, index, level);
@@ -1753,13 +1742,11 @@ int legacy_player_audio_effect_get_equalizer_band_level(legacy_player_h player,
 {
        legacy_player_t *handle = (legacy_player_t *)player;
        int ret = MM_ERROR_NONE;
-       int enabled = 0;
 
        PLAYER_INSTANCE_CHECK(player);
        PLAYER_NULL_ARG_CHECK(level);
 
-       if ((__lplayer_audio_offload_is_enabled(player, &enabled) != PLAYER_ERROR_NONE)
-               || (enabled))
+       if (!__lplayer_is_offload_precondition_valid(player))
                return PLAYER_ERROR_INVALID_OPERATION;
 
        ret = mm_player_audio_effect_custom_get_level(handle->mm_handle, MM_AUDIO_EFFECT_CUSTOM_EQ, index, level);
@@ -1773,13 +1760,11 @@ int legacy_player_audio_effect_get_equalizer_level_range(legacy_player_h player,
 {
        legacy_player_t *handle = (legacy_player_t *)player;
        int ret = MM_ERROR_NONE;
-       int enabled = 0;
 
        PLAYER_INSTANCE_CHECK(player);
        PLAYER_NULL_ARG_CHECK(min && max);
 
-       if ((__lplayer_audio_offload_is_enabled(player, &enabled) != PLAYER_ERROR_NONE)
-               || (enabled))
+       if (!__lplayer_is_offload_precondition_valid(player))
                return PLAYER_ERROR_INVALID_OPERATION;
 
        ret = mm_player_audio_effect_custom_get_level_range(handle->mm_handle, MM_AUDIO_EFFECT_CUSTOM_EQ, min, max);
@@ -1793,13 +1778,11 @@ int legacy_player_audio_effect_get_equalizer_band_frequency(legacy_player_h play
 {
        legacy_player_t *handle = (legacy_player_t *)player;
        int ret = MM_ERROR_NONE;
-       int enabled = 0;
 
        PLAYER_INSTANCE_CHECK(player);
        PLAYER_NULL_ARG_CHECK(frequency);
 
-       if ((__lplayer_audio_offload_is_enabled(player, &enabled) != PLAYER_ERROR_NONE)
-               || (enabled))
+       if (!__lplayer_is_offload_precondition_valid(player))
                return PLAYER_ERROR_INVALID_OPERATION;
 
        ret = mm_player_audio_effect_custom_get_eq_bands_freq(handle->mm_handle, index, frequency);
@@ -1813,13 +1796,11 @@ int legacy_player_audio_effect_get_equalizer_band_frequency_range(legacy_player_
 {
        legacy_player_t *handle = (legacy_player_t *)player;
        int ret = MM_ERROR_NONE;
-       int enabled = 0;
 
        PLAYER_INSTANCE_CHECK(player);
        PLAYER_NULL_ARG_CHECK(range);
 
-       if ((__lplayer_audio_offload_is_enabled(player, &enabled) != PLAYER_ERROR_NONE)
-               || (enabled))
+       if (!__lplayer_is_offload_precondition_valid(player))
                return PLAYER_ERROR_INVALID_OPERATION;
 
        ret = mm_player_audio_effect_custom_get_eq_bands_width(handle->mm_handle, index, range);
@@ -1833,12 +1814,10 @@ int legacy_player_audio_effect_equalizer_clear(legacy_player_h player)
 {
        legacy_player_t *handle = (legacy_player_t *)player;
        int ret = MM_ERROR_NONE;
-       int enabled = 0;
 
        PLAYER_INSTANCE_CHECK(player);
 
-       if ((__lplayer_audio_offload_is_enabled(player, &enabled) != PLAYER_ERROR_NONE)
-               || (enabled))
+       if (!__lplayer_is_offload_precondition_valid(player))
                return PLAYER_ERROR_INVALID_OPERATION;
 
        ret = mm_player_audio_effect_custom_clear_eq_all(handle->mm_handle);
@@ -1856,13 +1835,11 @@ int legacy_player_audio_effect_equalizer_is_available(legacy_player_h player, bo
 {
        legacy_player_t *handle = (legacy_player_t *)player;
        int ret = MM_ERROR_NONE;
-       int enabled = 0;
 
        PLAYER_INSTANCE_CHECK(player);
        PLAYER_NULL_ARG_CHECK(available);
 
-       if ((__lplayer_audio_offload_is_enabled(player, &enabled) != PLAYER_ERROR_NONE)
-               || (enabled))
+       if (!__lplayer_is_offload_precondition_valid(player))
                return PLAYER_ERROR_INVALID_OPERATION;
 
        if (!_lplayer_state_validate(handle, PLAYER_STATE_IDLE)) {
@@ -2076,13 +2053,11 @@ int legacy_player_set_media_packet_audio_frame_decoded_cb(legacy_player_h player
        legacy_player_t *handle = (legacy_player_t *)player;
        int ret = MM_ERROR_NONE;
        const char *audio_pcm_format = __lplayer_convert_audio_pcm_mime_to_str(mimetype);
-       int enabled = 0;
 
        PLAYER_INSTANCE_CHECK(player);
        PLAYER_NULL_ARG_CHECK(callback);
 
-       if ((__lplayer_audio_offload_is_enabled(player, &enabled) != PLAYER_ERROR_NONE)
-               || (enabled))
+       if (!__lplayer_is_offload_precondition_valid(player))
                return PLAYER_ERROR_INVALID_OPERATION;
 
        PLAYER_STATE_CHECK(handle, PLAYER_STATE_IDLE);
@@ -2298,13 +2273,11 @@ int legacy_player_get_track_count(legacy_player_h player, player_stream_type_e t
        legacy_player_t *handle = (legacy_player_t *)player;
        int ret = MM_ERROR_NONE;
        mmplayer_track_type_e track_type = 0;
-       int enabled = 0;
 
        PLAYER_INSTANCE_CHECK(player);
        PLAYER_NULL_ARG_CHECK(count);
 
-       if ((__lplayer_audio_offload_is_enabled(player, &enabled) != PLAYER_ERROR_NONE)
-               || (enabled))
+       if (!__lplayer_is_offload_precondition_valid(player))
                return PLAYER_ERROR_INVALID_OPERATION;
 
        if (!_lplayer_state_validate(handle, PLAYER_STATE_READY)) {
@@ -2336,13 +2309,11 @@ int legacy_player_get_current_track(legacy_player_h player, player_stream_type_e
        legacy_player_t *handle = (legacy_player_t *)player;
        int ret = MM_ERROR_NONE;
        mmplayer_track_type_e track_type = 0;
-       int enabled = 0;
 
        PLAYER_INSTANCE_CHECK(player);
        PLAYER_NULL_ARG_CHECK(index);
 
-       if ((__lplayer_audio_offload_is_enabled(player, &enabled) != PLAYER_ERROR_NONE)
-               || (enabled))
+       if (!__lplayer_is_offload_precondition_valid(player))
                return PLAYER_ERROR_INVALID_OPERATION;
 
        if (!_lplayer_state_validate(handle, PLAYER_STATE_READY)) {
@@ -2374,14 +2345,12 @@ int legacy_player_select_track(legacy_player_h player, player_stream_type_e type
        legacy_player_t *handle = (legacy_player_t *)player;
        int ret = MM_ERROR_NONE;
        mmplayer_track_type_e track_type = 0;
-       int enabled = 0;
 
        LPLAYER_FENTER();
        PLAYER_INSTANCE_CHECK(player);
        PLAYER_CHECK_CONDITION(index >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
 
-       if ((__lplayer_audio_offload_is_enabled(player, &enabled) != PLAYER_ERROR_NONE)
-               || (enabled))
+       if (!__lplayer_is_offload_precondition_valid(player))
                return PLAYER_ERROR_INVALID_OPERATION;
 
        if (!_lplayer_state_validate(handle, PLAYER_STATE_READY)) {
@@ -2414,13 +2383,11 @@ int legacy_player_get_track_language_code(legacy_player_h player, player_stream_
        legacy_player_t *handle = (legacy_player_t *)player;
        int ret = MM_ERROR_NONE;
        mmplayer_track_type_e track_type = 0;
-       int enabled = 0;
 
        PLAYER_INSTANCE_CHECK(player);
        PLAYER_NULL_ARG_CHECK(code && len);
 
-       if ((__lplayer_audio_offload_is_enabled(player, &enabled) != PLAYER_ERROR_NONE)
-               || (enabled))
+       if (!__lplayer_is_offload_precondition_valid(player))
                return PLAYER_ERROR_INVALID_OPERATION;
 
        if (!_lplayer_state_validate(handle, PLAYER_STATE_READY)) {
@@ -2518,6 +2485,8 @@ int legacy_player_set_display(legacy_player_h player, player_display_type_e type
        MMDisplaySurfaceType surface_type = __lplayer_convert_display_type(type);
 
        PLAYER_INSTANCE_CHECK(player);
+       PLAYER_RANGE_ARG_CHECK(type, PLAYER_DISPLAY_TYPE_OVERLAY, PLAYER_DISPLAY_TYPE_NONE);
+
        if (!_lplayer_state_validate(handle, PLAYER_STATE_IDLE)) {
                LOGE("PLAYER_ERROR_INVALID_STATE : current state - %d", handle->state);
                return PLAYER_ERROR_INVALID_STATE;
@@ -2561,8 +2530,9 @@ int legacy_player_set_sound_stream_info_for_mused(legacy_player_h player, char *
        if (strncmp(stream_type, "media", strlen("media"))) {
                int enabled = 0;
 
-               if (__lplayer_audio_offload_is_enabled(player, &enabled) != PLAYER_ERROR_NONE)
-                       return PLAYER_ERROR_INVALID_OPERATION;
+               ret = mm_player_get_attribute(handle->mm_handle, NULL, MM_PLAYER_AUDIO_OFFLOAD, &enabled, (char *)NULL);
+               if (ret != MM_ERROR_NONE)
+                       return _lplayer_convert_error_code(ret, (char *)__FUNCTION__);
 
                if (enabled) {
                        LOGW("audio offload will be disabled to support sound stream type: %s", stream_type);
@@ -2946,12 +2916,10 @@ int legacy_player_set_replaygain_enabled(legacy_player_h player, bool enabled)
 {
        legacy_player_t *handle = (legacy_player_t *)player;
        int ret = MM_ERROR_NONE;
-       int offload_enabled = 0;
 
        PLAYER_INSTANCE_CHECK(player);
 
-       if ((__lplayer_audio_offload_is_enabled(player, &offload_enabled) != PLAYER_ERROR_NONE)
-               || (offload_enabled))
+       if (!__lplayer_is_offload_precondition_valid(player))
                return PLAYER_ERROR_INVALID_OPERATION;
 
        if (!_lplayer_state_validate(handle, PLAYER_STATE_IDLE)) {
@@ -2971,13 +2939,11 @@ int legacy_player_is_replaygain_enabled(legacy_player_h player, bool *enabled)
        legacy_player_t *handle = (legacy_player_t *)player;
        int ret = MM_ERROR_NONE;
        bool replaygain_enabled = false;
-       int offload_enabled = 0;
 
        PLAYER_INSTANCE_CHECK(player);
        PLAYER_NULL_ARG_CHECK(enabled);
 
-       if ((__lplayer_audio_offload_is_enabled(player, &offload_enabled) != PLAYER_ERROR_NONE)
-               || (offload_enabled))
+       if (!__lplayer_is_offload_precondition_valid(player))
                return PLAYER_ERROR_INVALID_OPERATION;
 
        if (!_lplayer_state_validate(handle, PLAYER_STATE_IDLE)) {
@@ -3091,12 +3057,10 @@ int legacy_player_pitch_set_enabled(legacy_player_h player, bool enabled)
 {
        legacy_player_t *handle = (legacy_player_t *)player;
        int ret = MM_ERROR_NONE;
-       int offload_enabled = 0;
 
        PLAYER_INSTANCE_CHECK(player);
 
-       if ((__lplayer_audio_offload_is_enabled(player, &offload_enabled) != PLAYER_ERROR_NONE)
-               || (offload_enabled))
+       if (!__lplayer_is_offload_precondition_valid(player))
                return PLAYER_ERROR_INVALID_OPERATION;
 
        PLAYER_STATE_CHECK(handle, PLAYER_STATE_IDLE);
@@ -3115,13 +3079,11 @@ int legacy_player_pitch_is_enabled(legacy_player_h player, bool *enabled)
        legacy_player_t *handle = (legacy_player_t *)player;
        int ret = MM_ERROR_NONE;
        int val = 0;
-       int offload_enabled = 0;
 
        PLAYER_INSTANCE_CHECK(player);
        PLAYER_NULL_ARG_CHECK(enabled);
 
-       if ((__lplayer_audio_offload_is_enabled(player, &offload_enabled) != PLAYER_ERROR_NONE)
-               || (offload_enabled))
+       if (!__lplayer_is_offload_precondition_valid(player))
                return PLAYER_ERROR_INVALID_OPERATION;
 
        if (!_lplayer_state_validate(handle, PLAYER_STATE_IDLE)) {
@@ -3143,12 +3105,10 @@ int legacy_player_pitch_set_value(legacy_player_h player, float pitch)
        legacy_player_t *handle = (legacy_player_t *)player;
        int ret = MM_ERROR_NONE;
        int pitch_enabled = 0;
-       int offload_enabled = 0;
 
        PLAYER_INSTANCE_CHECK(player);
 
-       if ((__lplayer_audio_offload_is_enabled(player, &offload_enabled) != PLAYER_ERROR_NONE)
-               || (offload_enabled))
+       if (!__lplayer_is_offload_precondition_valid(player))
                return PLAYER_ERROR_INVALID_OPERATION;
 
        if (!_lplayer_state_validate(handle, PLAYER_STATE_IDLE)) {
@@ -3178,13 +3138,11 @@ int legacy_player_pitch_get_value(legacy_player_h player, float *pitch)
        legacy_player_t *handle = (legacy_player_t *)player;
        int ret = MM_ERROR_NONE;
        double value = 0.0;
-       int enabled = 0;
 
        PLAYER_INSTANCE_CHECK(player);
        PLAYER_NULL_ARG_CHECK(pitch);
 
-       if ((__lplayer_audio_offload_is_enabled(player, &enabled) != PLAYER_ERROR_NONE)
-               || (enabled))
+       if (!__lplayer_is_offload_precondition_valid(player))
                return PLAYER_ERROR_INVALID_OPERATION;
 
        if (!_lplayer_state_validate(handle, PLAYER_STATE_IDLE)) {