[0.6.200] consider the audio offload supported format 14/209714/2 accepted/tizen/unified/20190715.111855 submit/tizen/20190712.083315
authorEunhye Choi <eunhae1.choi@samsung.com>
Wed, 10 Jul 2019 07:06:39 +0000 (16:06 +0900)
committerEunhye Choi <eunhae1.choi@samsung.com>
Thu, 11 Jul 2019 09:03:18 +0000 (18:03 +0900)
- get supported format type from ini for audio offload
- keep the format information in player attributes
  with media_format_mimetype_e type
- add function to return the offload activation status

Change-Id: I10daf07163346640968e2fe7feb0b6552c8ecec7

packaging/libmm-player.spec
src/include/mm_player.h
src/include/mm_player_attrs.h
src/include/mm_player_ini.h
src/include/mm_player_priv.h
src/mm_player.c
src/mm_player_attrs.c
src/mm_player_ini.c
src/mm_player_priv.c

index bfbe599..3efa2d8 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-player
 Summary:    Multimedia Framework Player Library
-Version:    0.6.199
+Version:    0.6.200
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index 768b034..48f91a8 100644 (file)
@@ -552,70 +552,22 @@ typedef struct _SubtitleStreamInfo {
 } mmplayer_subtitle_stream_info_t;
 
 /**
- * selected subtitle track number callback function type.
- *
- * @param      track_num       [in]    Track number of subtitle
- * @param      user_param      [in]    User defined parameter
- *
- *
- * @return     This callback function have to return MM_ERROR_NONE.
- */
-typedef bool (*mm_player_track_selected_subtitle_language_callback)(int track_num, void *user_param);
-
-/**
  * Called to notify the stream changed.
- *
- * @param user_data [in] The user data passed from the callback registration function
- *
- * @return     This callback function have to return MM_ERROR_NONE.
  */
 typedef bool (*mm_player_stream_changed_callback)(void *user_param);
 
 /**
  * Video decoded callback function type.
- *
- * @param      stream          [in]    Reference pointer to video frame data
- * @param      stream_size     [in]    Size of video frame data
- * @param      user_param      [in]    User defined parameter which is passed when set
- *                                                             video stream callback
- * @param      width           [in]    width of video frame
- * @param      height          [in]    height of video frame
- *
- * @return     This callback function have to return MM_ERROR_NONE.
  */
 typedef bool (*mm_player_video_decoded_callback)(void *stream, void *user_param);
 
 /**
  * Audio stream callback function type.
- *
- * @param      stream          [in]    Reference pointer to audio frame data
- * @param      stream_size     [in]    Size of audio frame data
- * @param      user_param      [in]    User defined parameter which is passed when set
- *                                                             audio stream callback
- *
- * @return     This callback function have to return MM_ERROR_NONE.
  */
 typedef bool (*mm_player_video_capture_callback)(void *stream, int stream_size, void *user_param);
 
 /**
- * Video frame render error callback function type.
- *
- * @param      error_id        [in]    cause of error
- * @param      user_param      [in]    User defined parameter which is passed when set
- *                                                             video frame render error callback
- *
- * @return     This callback function have to return MM_ERROR_NONE.
- */
-typedef bool (*mm_player_video_frame_render_error_callback)(void *error_id, void *user_param);
-
-/**
  * Audio stream callback function type.
- *
- * @param      stream          [in]    Reference pointer to audio frame data
- * @param      user_param      [in]    User defined parameter which is passed when set
- *                                                             audio stream callback
- *
- * @return     This callback function have to return MM_ERROR_NONE.
  */
 typedef bool (*mm_player_audio_decoded_callback)(void *stream, void *user_param);
 
@@ -1528,6 +1480,11 @@ int mm_player_change_videosink(MMHandleType player, MMDisplaySurfaceType display
 int mm_player_set_client_pid(MMHandleType player, int pid);
 
 /**
+ * This function gets the activation status of audio offload.
+ */
+int mm_player_audio_offload_is_activated(MMHandleType player, bool *activated);
+
+/**
        @}
  */
 
index da46c4c..113ffd6 100644 (file)
@@ -90,6 +90,7 @@ typedef enum {
        MMPLAYER_ATTRS_PITCH_CONTROL,
        MMPLAYER_ATTRS_PITCH_VALUE,             /* 60 */
        MMPLAYER_ATTRS_AUDIO_OFFLOAD,
+       MMPLAYER_ATTRS_AUDIO_OFFLOAD_FORMAT,
        MMPLAYER_ATTRS_NUM
 } mmplayer_attrs_id_e;
 
index f682052..a733613 100644 (file)
 #define MM_PLAYER_INI_DEFAULT_PATH     SYSCONFDIR"/multimedia/mmfw_player.ini" /* SYSCONFDIR is defined at .spec */
 #define MM_PLAYER_INI_DEFAULT_AUDIOEFFECT_PATH SYSCONFDIR"/multimedia/mmfw_player_audio_effect.ini" /* SYSCONFDIR is defined at .spec */
 
-#define PLAYER_INI_MAX_STRLEN  100
-#define PLAYER_INI_MAX_PARAM_STRLEN    256
+#define PLAYER_INI_MAX_STRLEN       100
+#define PLAYER_INI_MAX_PARAM_STRLEN 256
 
-#define PLAYER_INI_MAX_ELEMENT 10
+#define PLAYER_INI_MAX_ELEMENT      10
+#define PLAYER_INI_MAX_DEVICE_TYPE  10
+#define PLAYER_INI_MAX_SUPPORTED_MEDIA_FORMAT 10 /* @see MAX_SUPPORTED_MEDIA_FORMAT in player_private.h */
 
 /* NOTE : MMPlayer has no initalizing API for library itself
  * so we cannot decide when those ini values to be released.
@@ -57,7 +59,8 @@ enum keyword_type {
        KEYWORD_UNSUPPORTED_CODEC, // for un-supported codec
        KEYWORD_A_SW_CODEC, // for audio sw codec
        KEYWORD_V_SW_CODEC, // for video sw codec
-       KEYWORD_A_OFFLOAD,  // for audio device type which can support offload
+       KEYWORD_A_OFFLOAD_DEVICE_TYPE,  // for audio device type which can support offload
+       KEYWORD_A_OFFLOAD_MEDIA_FORMAT, // supported media format for audio offload
 };
 
 typedef struct {
@@ -72,7 +75,8 @@ typedef struct {
        gchar audioresampler_element[PLAYER_INI_MAX_STRLEN];
        gchar audiosink_element[PLAYER_INI_MAX_STRLEN];
        gchar audio_offload_sink_element[PLAYER_INI_MAX_STRLEN];
-       gchar audio_offload_device_type[PLAYER_INI_MAX_ELEMENT][PLAYER_INI_MAX_STRLEN];
+       gchar audio_offload_device_type[PLAYER_INI_MAX_DEVICE_TYPE][PLAYER_INI_MAX_STRLEN];
+       gchar audio_offload_media_format[PLAYER_INI_MAX_SUPPORTED_MEDIA_FORMAT][PLAYER_INI_MAX_STRLEN];
        gboolean skip_rescan;
        gboolean generate_dot;
        gboolean use_system_clock;
@@ -124,6 +128,7 @@ typedef struct {
 
 /* default values if each values are not specified in inifile */
 /* general */
+#define DEFAULT_EMPTY_VALUE                               ""
 #define DEFAULT_AUDIO_EFFECT_ELEMENT                      ""
 #define DEFAULT_USE_AUDIO_EFFECT_PRESET                   FALSE
 #define DEFAULT_AUDIO_EFFECT_PRESET_LIST                  ""
index cf2d2bc..fb64dca 100644 (file)
@@ -862,6 +862,7 @@ int _mmplayer_set_replaygain_enabled(MMHandleType hplayer, bool enabled);
 int _mmplayer_is_replaygain_enabled(MMHandleType hplayer, bool *enabled);
 int _mmplayer_set_video_roi_area(MMHandleType hplayer, double scale_x, double scale_y, double scale_width, double scale_height);
 int _mmplayer_get_video_roi_area(MMHandleType hplayer, double *scale_x, double *scale_y, double *scale_width, double *scale_height);
+int _mmplayer_audio_offload_is_activated(MMHandleType hplayer, bool *activated);
 
 /* internal */
 void _mmplayer_bus_msg_thread_destroy(MMHandleType hplayer);
index 4e54a02..b6b6d15 100644 (file)
@@ -1246,4 +1246,20 @@ int mm_player_set_client_pid(MMHandleType player, int pid)
        MMPLAYER_CMD_UNLOCK(player);
 
        return result;
-}
\ No newline at end of file
+}
+
+int mm_player_audio_offload_is_activated(MMHandleType player, bool *activated)
+{
+       int result = MM_ERROR_NONE;
+
+       MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+       MMPLAYER_RETURN_VAL_IF_FAIL(activated, MM_ERROR_INVALID_ARGUMENT);
+
+       MMPLAYER_CMD_LOCK(player);
+
+       result = _mmplayer_audio_offload_is_activated(player, activated);
+
+       MMPLAYER_CMD_UNLOCK(player);
+
+       return result;
+}
index 8502acc..b0fb693 100644 (file)
@@ -730,6 +730,17 @@ mmplayer_attrs_spec_t player_attrs[] = {
                {.int_max = TRUE},
                NULL,
        },
+       {
+               MMPLAYER_ATTRS_AUDIO_OFFLOAD_FORMAT,
+               (char *)"audio_offload_format", /* MM_PLAYER_AUDIO_OFFLOAD_FORMAT, array of media_format_mimetype_e */
+               MM_ATTRS_TYPE_INT,
+               MM_ATTRS_FLAG_RW,
+               {(void *)NULL},
+               MM_ATTRS_VALID_TYPE_INT_ARRAY,
+               {.int_array = NULL},
+               {.count = 0},
+               NULL,
+       },
 };
 
 /*===========================================================================================
@@ -813,6 +824,110 @@ static bool __mmplayer_commit_audio_pitch_value(MMHandleType handle, int attr_id
        return true;
 }
 
+static int __mmplayer_get_array_count(MMHandleType handle, int type)
+{
+       mmplayer_t *player = (mmplayer_t *)handle;
+
+       int count = 0;
+       int i = 0;
+
+       if (type == KEYWORD_A_OFFLOAD_MEDIA_FORMAT) {
+               while (player->ini.audio_offload_media_format[i++][0])
+                       count++;
+       }
+       return count;
+}
+
+static media_format_mimetype_e __mmplayer_get_supported_format_mimetype(MMHandleType handle, int type, int i)
+{
+       char *name = NULL;
+       media_format_mimetype_e format = MEDIA_FORMAT_MAX;
+
+       mmplayer_t *player = (mmplayer_t *)handle;
+
+       if (type == KEYWORD_A_OFFLOAD_MEDIA_FORMAT) {
+               name = player->ini.audio_offload_media_format[i];
+       } else {
+               LOGE("invalid ini type");
+               goto EXIT;
+       }
+
+       if (!strcmp(name, "MP3"))
+               format = MEDIA_FORMAT_MP3;
+       else
+               LOGE("FIXME: need to modify function to support more format");
+
+EXIT:
+       LOGD("[%d type] supported format 0x%X(%s)", type, format, name);
+
+       return format;
+}
+
+static int __mmplayer_get_available_format(MMHandleType handle, int type, int **format)
+{
+       int *arr = NULL;
+       int total_count = 0;
+       int count = 0;
+       int i = 0;
+       int fmt = 0;
+
+       MMPLAYER_RETURN_VAL_IF_FAIL(handle, -1);
+
+       count = __mmplayer_get_array_count(handle, type);
+
+       if (count <= 0)
+               return -1;
+
+       arr = (int *) g_malloc0(count * sizeof(int));
+       if (arr == NULL) {
+               LOGE("malloc failed : %zu", count * sizeof(int));
+               return -1;
+       }
+
+       for (i = 0 ; i < count ; i++) {
+               fmt = __mmplayer_get_supported_format_mimetype(handle, type, i);
+               if (fmt != MEDIA_FORMAT_MAX)
+                       arr[total_count++] = fmt;
+       }
+
+       LOGD("[%d type] num of supported codec %d", type, total_count);
+
+       *format = arr;
+       return total_count;
+}
+
+static int __mmplayer_set_ini_to_valid_info(MMHandleType handle)
+{
+       int *format = NULL;
+       int total_count = 0;
+
+       /* supported format of audio offload */
+       total_count = __mmplayer_get_available_format(handle, KEYWORD_A_OFFLOAD_MEDIA_FORMAT, &format);
+       if (format && total_count > 0) {
+               player_attrs[MMPLAYER_ATTRS_AUDIO_OFFLOAD_FORMAT].validity_value_1.int_array = format;
+               player_attrs[MMPLAYER_ATTRS_AUDIO_OFFLOAD_FORMAT].validity_value_2.count = total_count;
+       }
+
+       return MM_ERROR_NONE;
+}
+
+static int __mmplayer_release_ini_info(void)
+{
+       int *mem = NULL;
+
+       MMPLAYER_FENTER();
+
+       mem = (int *)(player_attrs[MMPLAYER_ATTRS_AUDIO_OFFLOAD_FORMAT].validity_value_1.int_array);
+       if (mem) {
+               free(mem);
+               player_attrs[MMPLAYER_ATTRS_AUDIO_OFFLOAD_FORMAT].validity_value_1.int_array = NULL;
+               player_attrs[MMPLAYER_ATTRS_AUDIO_OFFLOAD_FORMAT].validity_value_2.count = 0;
+       }
+
+       MMPLAYER_FLEAVE();
+       return MM_ERROR_NONE;
+}
+
 static void __mmplayer_print_attrs(const char *attr_name, const MMAttrsValue * value, const char *prefix)
 {
        switch (value->type) {
@@ -1024,6 +1139,8 @@ MMHandleType _mmplayer_construct_attribute(MMHandleType handle)
                return NULL;
        }
 
+       __mmplayer_set_ini_to_valid_info(handle);
+
        /* set validity type and range */
        for (idx = 0; idx < num_of_attrs; idx++) {
                mm_attrs_set_valid_type(attrs, idx, player_attrs[idx].valid_type);
@@ -1064,6 +1181,8 @@ MMHandleType _mmplayer_construct_attribute(MMHandleType handle)
                return NULL;
        }
 
+       __mmplayer_release_ini_info();
+
        return attrs;
 }
 
index efad473..588c732 100644 (file)
@@ -173,7 +173,10 @@ mm_player_ini_load(mmplayer_ini_t *ini)
                        iniparser_getstring(dict, "general:element exclude keyword", DEFAULT_EXCLUDE_KEYWORD), KEYWORD_EXCLUDE);
 
                __get_element_list(ini,
-                       iniparser_getstring(dict, "general:audio offload device type", DEFAULT_A_OFFLOAD_DEVICE_TYPE), KEYWORD_A_OFFLOAD);
+                       iniparser_getstring(dict, "general:audio offload device type", DEFAULT_A_OFFLOAD_DEVICE_TYPE), KEYWORD_A_OFFLOAD_DEVICE_TYPE);
+
+               __get_element_list(ini,
+                       iniparser_getstring(dict, "general:audio offload media format", DEFAULT_EMPTY_VALUE), KEYWORD_A_OFFLOAD_MEDIA_FORMAT);
 
                __get_element_list(ini,
                        iniparser_getstring(dict, "general:unsupported codec keyword", DEFAULT_UNSUPPORTED_CODEC_KEYWORD), KEYWORD_UNSUPPORTED_CODEC);
@@ -224,7 +227,8 @@ mm_player_ini_load(mmplayer_ini_t *ini)
 
                __get_element_list(ini, DEFAULT_CODEC_SW, KEYWORD_A_SW_CODEC);
                __get_element_list(ini, DEFAULT_CODEC_SW, KEYWORD_V_SW_CODEC);
-               __get_element_list(ini, DEFAULT_A_OFFLOAD_DEVICE_TYPE, KEYWORD_A_OFFLOAD);
+               __get_element_list(ini, DEFAULT_A_OFFLOAD_DEVICE_TYPE, KEYWORD_A_OFFLOAD_DEVICE_TYPE);
+               __get_element_list(ini, DEFAULT_EMPTY_VALUE, KEYWORD_A_OFFLOAD_MEDIA_FORMAT);
                __get_element_list(ini, DEFAULT_EXCLUDE_KEYWORD, KEYWORD_EXCLUDE);
                __get_element_list(ini, DEFAULT_UNSUPPORTED_CODEC_KEYWORD, KEYWORD_UNSUPPORTED_CODEC);
 
@@ -267,6 +271,8 @@ mm_player_ini_load(mmplayer_ini_t *ini)
        LOGD("audio offload sink element : %s", ini->audio_offload_sink_element);
        for (idx = 0; ini->audio_offload_device_type[idx][0] != '\0'; idx++)
                LOGD("audio_offload_device_type [%d] : %s", idx, ini->audio_offload_device_type[idx]);
+       for (idx = 0; ini->audio_offload_media_format[idx][0] != '\0'; idx++)
+               LOGD("audio_offload_media_format [%d] : %s", idx, ini->audio_offload_media_format[idx]);
        LOGD("generate dot : %d", ini->generate_dot);
        LOGD("use system clock(video only) : %d", ini->use_system_clock);
        LOGD("live state change timeout(sec) : %d", ini->live_state_change_timeout);
@@ -490,9 +496,12 @@ __get_element_list(mmplayer_ini_t *ini, gchar *str, int keyword_type)
        case KEYWORD_A_SW_CODEC:
                ini_keyword = ini->audiocodec_element_sw;
                break;
-       case KEYWORD_A_OFFLOAD:
+       case KEYWORD_A_OFFLOAD_DEVICE_TYPE:
                ini_keyword = ini->audio_offload_device_type;
                break;
+       case KEYWORD_A_OFFLOAD_MEDIA_FORMAT:
+               ini_keyword = ini->audio_offload_media_format;
+               break;
        default:
                goto EXIT;
                break;
index b4d944a..543cd2f 100644 (file)
@@ -6877,6 +6877,37 @@ __mmplayer_add_audio_device_connected_cb(mmplayer_t *player)
        return TRUE;
 }
 
+int _mmplayer_audio_offload_is_activated(MMHandleType hplayer, bool *activated)
+{
+       mmplayer_t *player = (mmplayer_t *)hplayer;
+
+       MMPLAYER_FENTER();
+       MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+       MMPLAYER_RETURN_VAL_IF_FAIL(activated, MM_ERROR_INVALID_ARGUMENT);
+
+       *activated = player->build_audio_offload;
+
+       LOGD("offload activated : %d", (int)*activated);
+
+       MMPLAYER_FLEAVE();
+       return MM_ERROR_NONE;
+}
+
+static gboolean
+__mmplayer_is_offload_supported_type(mmplayer_t *player)
+{
+       /* NOTE :
+          this function need to be updated according to the supported media format
+          @see player->ini.audio_offload_media_format */
+
+       if (__mmplayer_is_only_mp3_type(player->type)) {
+               LOGD("offload supportable media format type");
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
 static gboolean
 __mmplayer_can_build_audio_offload_path(mmplayer_t *player)
 {
@@ -6887,7 +6918,7 @@ __mmplayer_can_build_audio_offload_path(mmplayer_t *player)
        MMPLAYER_RETURN_VAL_IF_FAIL(player && player->attrs, FALSE);
 
        LOGD("current stream : %s, sink: %s", player->type, player->ini.audio_offload_sink_element);
-       if (!__mmplayer_is_only_mp3_type(player->type))
+       if (!__mmplayer_is_offload_supported_type(player))
                goto DONE;
 
        if (!strcmp(player->ini.audio_offload_sink_element, "")) {