Change ordering of webrtc_media_source_type_e enum 44/259844/4
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 16 Jun 2021 01:31:17 +0000 (10:31 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 16 Jun 2021 08:07:52 +0000 (17:07 +0900)
WEBRTC_MEDIA_SOURCE_TYPE_FILE is also added to support for media files.
The implementation will be updated in the near future.

typedef enum {
    WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST,    /**<  Audio test */
    WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST,    /**<  Video test */
    WEBRTC_MEDIA_SOURCE_TYPE_MIC,          /**<  Audio from microphone */
    WEBRTC_MEDIA_SOURCE_TYPE_CAMERA,       /**<  Camera preview */
    WEBRTC_MEDIA_SOURCE_TYPE_SCREEN,       /**<  Screen capture */
    WEBRTC_MEDIA_SOURCE_TYPE_FILE,         /**<  Media file */
    WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET  /**<  Media packet */
} webrtc_media_source_type_e;

Unnecessary structure is also removed.

[Version] 0.2.12
[Issue Type] API

Change-Id: I2d939c0aee848a44b3ea68445d31bc1696b08217
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
include/webrtc.h
packaging/capi-media-webrtc.spec
src/webrtc_ini.c
src/webrtc_source.c
test/webrtc_test.c

index 44f2df4af60343f9cca615f151dc8c37dba03854..e9e2208cfcfbc96fec366a0e8902bcab801ee95f 100644 (file)
@@ -134,12 +134,13 @@ typedef enum {
  * @since_tizen 6.5
  */
 typedef enum {
-       WEBRTC_MEDIA_SOURCE_TYPE_CAMERA,       /**<  Camera preview */
-       WEBRTC_MEDIA_SOURCE_TYPE_MIC,          /**<  Audio from microphone */
        WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST,    /**<  Audio test */
        WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST,    /**<  Video test */
-       WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET, /**<  Media packet */
-       WEBRTC_MEDIA_SOURCE_TYPE_SCREEN        /**<  Screen capture */
+       WEBRTC_MEDIA_SOURCE_TYPE_MIC,          /**<  Audio from microphone */
+       WEBRTC_MEDIA_SOURCE_TYPE_CAMERA,       /**<  Camera preview */
+       WEBRTC_MEDIA_SOURCE_TYPE_SCREEN,       /**<  Screen capture */
+       WEBRTC_MEDIA_SOURCE_TYPE_FILE,         /**<  Media file */
+       WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET  /**<  Media packet */
 } webrtc_media_source_type_e;
 
 /**
index cec6135e6b118d2034af07edb96a2e0fd1d28e25..7992092dd9cdb210a77287bda6c9cef7fa954712 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.2.11
+Version:    0.2.12
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index a070db42305f61d265f1d6b3283cb9f622f236ac..358c9daaa772ed3f4b316daf0133c78d7f1aca8b 100644 (file)
@@ -33,6 +33,7 @@
 #define INI_CATEGORY_SOURCE_VIDEOTEST     "source videotest"
 #define INI_CATEGORY_SOURCE_MEDIA_PACKET  "source media packet"
 #define INI_CATEGORY_SOURCE_SCREEN        "source screen"
+#define INI_CATEGORY_SOURCE_FILE          "source file"
 #define INI_CATEGORY_RENDERING_SINK       "rendering sink"
 #define INI_CATEGORY_VPXENC_PARAMS        "vpxenc params"
 
@@ -112,28 +113,15 @@ typedef enum {
        INI_ITEM_TYPE_STRINGS
 } ini_item_type_e;
 
-typedef enum {
-       MEDIA_SOURCE_TYPE_CAMERA,
-       MEDIA_SOURCE_TYPE_MIC,
-       MEDIA_SOURCE_TYPE_AUDIOTEST,
-       MEDIA_SOURCE_TYPE_VIDEOTEST,
-       MEDIA_SOURCE_TYPE_MEDIA_PACKET,
-       MEDIA_SOURCE_TYPE_SCREEN,
-       MEDIA_SOURCE_TYPE_MAX,
-} media_source_type_e;
-
-typedef struct {
-       const char *name;
-} ini_category_name_s;
-
-static ini_category_name_s category_source_names[] = {
-       [MEDIA_SOURCE_TYPE_CAMERA] = { INI_CATEGORY_SOURCE_CAMERA },
-       [MEDIA_SOURCE_TYPE_MIC] = { INI_CATEGORY_SOURCE_MIC },
-       [MEDIA_SOURCE_TYPE_AUDIOTEST] = { INI_CATEGORY_SOURCE_AUDIOTEST },
-       [MEDIA_SOURCE_TYPE_VIDEOTEST] = { INI_CATEGORY_SOURCE_VIDEOTEST },
-       [MEDIA_SOURCE_TYPE_MEDIA_PACKET] = { INI_CATEGORY_SOURCE_MEDIA_PACKET },
-       [MEDIA_SOURCE_TYPE_SCREEN] = { INI_CATEGORY_SOURCE_SCREEN },
-       [MEDIA_SOURCE_TYPE_MAX] = { NULL },
+static const char* category_source_names[] = {
+       [WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST] = INI_CATEGORY_SOURCE_AUDIOTEST,
+       [WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST] = INI_CATEGORY_SOURCE_VIDEOTEST,
+       [WEBRTC_MEDIA_SOURCE_TYPE_MIC] = INI_CATEGORY_SOURCE_MIC,
+       [WEBRTC_MEDIA_SOURCE_TYPE_CAMERA] = INI_CATEGORY_SOURCE_CAMERA,
+       [WEBRTC_MEDIA_SOURCE_TYPE_SCREEN] = INI_CATEGORY_SOURCE_SCREEN,
+       [WEBRTC_MEDIA_SOURCE_TYPE_FILE] = INI_CATEGORY_SOURCE_FILE,
+       [WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET] = INI_CATEGORY_SOURCE_MEDIA_PACKET,
+       [WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET + 1] = NULL,
 };
 
 static void __dump_item(const char *prefix_str, ini_item_type_e type, void *item)
@@ -193,7 +181,6 @@ static bool __is_vpx(const char *v_codec)
 static void __dump_ini(webrtc_ini_s *ini)
 {
        int i = 0;
-       const char *category_name;
 
        RET_IF(ini == NULL, "ini is NULL");
 
@@ -210,10 +197,10 @@ static void __dump_ini(webrtc_ini_s *ini)
        LOG_INFO("[%s]", INI_CATEGORY_MEDIA_SOURCE);
        __dump_items_of_source(&ini->media_source);
 
-       for (; (category_name = category_source_names[i].name) != NULL; i++) {
-               ini_item_media_source_s *source = g_hash_table_lookup(ini->sources, category_name);
+       for (; category_source_names[i] != NULL; i++) {
+               ini_item_media_source_s *source = g_hash_table_lookup(ini->sources, category_source_names[i]);
                if (source) {
-                       LOG_INFO("[%s]", category_name);
+                       LOG_INFO("[%s]", category_source_names[i]);
                        __dump_items_of_source(source);
                }
        }
@@ -401,7 +388,6 @@ static void __apply_media_source_setting(webrtc_ini_s *ini, ini_item_media_sourc
 int _load_ini(webrtc_s *webrtc)
 {
        webrtc_ini_s *ini;
-       const char *category_name;
        int i = 0;
 
        RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
@@ -433,12 +419,12 @@ int _load_ini(webrtc_s *webrtc)
        __apply_media_source_setting(ini, &ini->media_source, INI_CATEGORY_MEDIA_SOURCE);
 
        /* it overrides the default values above */
-       for (; (category_name = category_source_names[i].name) != NULL; i++) {
-               if (iniparser_getsecnkeys(ini->dict, category_name) > 0) {
+       for (; category_source_names[i] != NULL; i++) {
+               if (iniparser_getsecnkeys(ini->dict, category_source_names[i]) > 0) {
                        ini_item_media_source_s *source = g_new0(ini_item_media_source_s, 1);
-                       __apply_media_source_setting(ini, source, category_name);
-                       if (!g_hash_table_insert(ini->sources, g_strdup(category_name), (gpointer)source)) {
-                               LOG_WARNING("[%s] already exist", category_name);
+                       __apply_media_source_setting(ini, source, category_source_names[i]);
+                       if (!g_hash_table_insert(ini->sources, g_strdup(category_source_names[i]), (gpointer)source)) {
+                               LOG_WARNING("[%s] already exist", category_source_names[i]);
                                continue;
                        }
                }
@@ -463,7 +449,7 @@ ini_item_media_source_s* _ini_get_source_by_type(webrtc_ini_s *ini, webrtc_media
 {
        RET_VAL_IF(ini == NULL, NULL, "ini is NULL");
 
-       return (ini_item_media_source_s*)g_hash_table_lookup(ini->sources, category_source_names[type].name);
+       return (ini_item_media_source_s*)g_hash_table_lookup(ini->sources, category_source_names[type]);
 }
 
 void _unload_ini(webrtc_s *webrtc)
index 70203cb286a472e94406f414c96c14236afd3fdd..cbe3f6ce47c761b9c09fc35ad21d1a633f2ee7c5 100644 (file)
@@ -252,8 +252,8 @@ static GstCaps *__make_video_raw_caps_with_resolution(webrtc_gst_slot_s *source,
                ini_source = &ini->media_source;
 
        switch (source->type) {
-       case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA:
        case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST:
+       case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA:
        case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN:
                caps = gst_caps_new_simple(MEDIA_TYPE_VIDEO_RAW,
                                                "format", G_TYPE_STRING, ini_source->v_raw_format,
@@ -285,8 +285,8 @@ static GstCaps *__make_default_raw_caps(webrtc_gst_slot_s *source, webrtc_ini_s
                ini_source = &ini->media_source;
 
        switch (source->type) {
-       case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA:
        case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST:
+       case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA:
        case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN:
                caps = gst_caps_new_simple(MEDIA_TYPE_VIDEO_RAW,
                                                "format", G_TYPE_STRING, ini_source->v_raw_format,
@@ -298,8 +298,8 @@ static GstCaps *__make_default_raw_caps(webrtc_gst_slot_s *source, webrtc_ini_s
                source->video_info.height = ini_source->v_height;
                break;
 
-       case WEBRTC_MEDIA_SOURCE_TYPE_MIC:
        case WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST:
+       case WEBRTC_MEDIA_SOURCE_TYPE_MIC:
                caps = gst_caps_new_simple(MEDIA_TYPE_AUDIO_RAW,
                                                "format", G_TYPE_STRING, ini_source->a_raw_format,
                                                "channels", G_TYPE_INT, ini_source->a_channels,
@@ -416,8 +416,8 @@ static GstCaps *__make_default_encoded_caps(webrtc_gst_slot_s *source, webrtc_in
                ini_source = &ini->media_source;
 
        switch (source->type) {
-       case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA:
        case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST:
+       case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA:
        case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN:
                _media_type = __get_video_media_type(ini_source->v_codec);
                RET_VAL_IF(_media_type == NULL, NULL, "_media_type is NULL");
@@ -431,8 +431,8 @@ static GstCaps *__make_default_encoded_caps(webrtc_gst_slot_s *source, webrtc_in
                source->video_info.height = ini_source->v_height;
                break;
 
-       case WEBRTC_MEDIA_SOURCE_TYPE_MIC:
        case WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST:
+       case WEBRTC_MEDIA_SOURCE_TYPE_MIC:
                _media_type = __get_audio_media_type(ini_source->a_codec);
                RET_VAL_IF(_media_type == NULL, NULL, "_media_type is NULL");
 
@@ -778,18 +778,18 @@ static const char *__get_default_element(webrtc_media_source_type_e type)
 {
        const char *element = NULL;
 
-       if (type == WEBRTC_MEDIA_SOURCE_TYPE_CAMERA)
-               element = DEFAULT_ELEMENT_CAMERASRC;
-       else if (type == WEBRTC_MEDIA_SOURCE_TYPE_MIC)
-               element = DEFAULT_ELEMENT_AUDIOSRC;
-       else if (type == WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST)
+       if (type == WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST)
                element = DEFAULT_ELEMENT_AUDIOTESTSRC;
        else if (type == WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST)
                element = DEFAULT_ELEMENT_VIDEOTESTSRC;
-       else if (type == WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET)
-               element = DEFAULT_ELEMENT_APPSRC;
+       else if (type == WEBRTC_MEDIA_SOURCE_TYPE_MIC)
+               element = DEFAULT_ELEMENT_AUDIOSRC;
+       else if (type == WEBRTC_MEDIA_SOURCE_TYPE_CAMERA)
+               element = DEFAULT_ELEMENT_CAMERASRC;
        else if (type == WEBRTC_MEDIA_SOURCE_TYPE_SCREEN)
                element = DEFAULT_ELEMENT_SCREENSRC;
+       else if (type == WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET)
+               element = DEFAULT_ELEMENT_APPSRC;
        else
                LOG_ERROR_IF_REACHED("type(%d)", type);
 
@@ -1463,24 +1463,24 @@ static int __build_source_bin(webrtc_s *webrtc, webrtc_gst_slot_s *source)
        RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL");
 
        switch (source->type) {
-       case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA:
-               return __build_camerasrc(webrtc, source);
-
-       case WEBRTC_MEDIA_SOURCE_TYPE_MIC:
-               return __build_audiosrc(webrtc, source, true);
+       case WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST:
+               return __build_audiosrc(webrtc, source, false);
 
        case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST:
                return __build_videotestsrc(webrtc, source);
 
-       case WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST:
-               return __build_audiosrc(webrtc, source, false);
+       case WEBRTC_MEDIA_SOURCE_TYPE_MIC:
+               return __build_audiosrc(webrtc, source, true);
 
-       case WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET:
-               return __build_mediapacketsrc(webrtc, source);
+       case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA:
+               return __build_camerasrc(webrtc, source);
 
        case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN:
                return __build_screensrc(webrtc, source);
 
+       case WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET:
+               return __build_mediapacketsrc(webrtc, source);
+
        default:
                LOG_ERROR_IF_REACHED("type(%d)", source->type);
                return WEBRTC_ERROR_INVALID_PARAMETER;
@@ -1610,7 +1610,7 @@ int _add_media_source(webrtc_s *webrtc, webrtc_media_source_type_e type, unsigne
 
        RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
        RET_VAL_IF(source_id == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is NULL");
-       RET_VAL_IF(type > WEBRTC_MEDIA_SOURCE_TYPE_SCREEN, WEBRTC_ERROR_INVALID_PARAMETER, "invalid source type(%d)", type);
+       RET_VAL_IF(type > WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET, WEBRTC_ERROR_INVALID_PARAMETER, "invalid source type(%d)", type);
        RET_VAL_IF(webrtc->gst.source_slots == NULL, WEBRTC_ERROR_INVALID_OPERATION, "source_slots is NULL");
 
        /* bin_name/source will be freed by function which is set to g_hash_table_new_full() */
@@ -2306,6 +2306,10 @@ int _set_video_source_mute(webrtc_s *webrtc, unsigned int source_id, bool mute)
        LOG_DEBUG("source_id[%u] mute[%d]", source_id, mute);
 
        switch (source->type) {
+       case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST:
+               ret = __mute_videotestsrc(source, mute);
+               break;
+
        case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA:
                ret = __mute_camerasrc(source, mute);
                break;
@@ -2314,10 +2318,6 @@ int _set_video_source_mute(webrtc_s *webrtc, unsigned int source_id, bool mute)
                ret = __mute_videosrc(source, mute);
                break;
 
-       case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST:
-               ret = __mute_videotestsrc(source, mute);
-               break;
-
        default :
                LOG_ERROR_IF_REACHED("type(%d)", source->type);
                return WEBRTC_ERROR_INVALID_PARAMETER;
@@ -2344,8 +2344,8 @@ int _set_audio_source_mute(webrtc_s *webrtc, unsigned int source_id, bool mute)
        }
 
        switch (source->type) {
-       case WEBRTC_MEDIA_SOURCE_TYPE_MIC:
        case WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST:
+       case WEBRTC_MEDIA_SOURCE_TYPE_MIC:
                volume = gst_bin_get_by_name(source->bin, ELEMENT_NAME_VOLUME);
                RET_VAL_IF(volume == NULL, WEBRTC_ERROR_INVALID_OPERATION, "volume is NULL");
 
@@ -2381,9 +2381,9 @@ int _get_video_source_muted(webrtc_s *webrtc, unsigned int source_id, bool *mute
        }
 
        switch (source->type) {
+       case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST:
        case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA:
        case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN:
-       case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST:
                *muted = source->video_muted;
                break;
 
@@ -2412,8 +2412,8 @@ int _get_audio_source_muted(webrtc_s *webrtc, unsigned int source_id, bool *mute
        }
 
        switch (source->type) {
-       case WEBRTC_MEDIA_SOURCE_TYPE_MIC:
        case WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST:
+       case WEBRTC_MEDIA_SOURCE_TYPE_MIC:
                volume = gst_bin_get_by_name(source->bin, ELEMENT_NAME_VOLUME);
                RET_VAL_IF(volume == NULL, WEBRTC_ERROR_INVALID_OPERATION, "volume is NULL");
 
index 110045eca4df9618c4d8e5fb5eddfaad226be91b..1cf89f2fe713e9185a05b76443a8478e2642a83d 100644 (file)
@@ -3326,7 +3326,7 @@ static void displaymenu()
                display_sub_basic();
 
        } else if (g_conns[g_conn_index].menu_state == CURRENT_STATUS_ADD_MEDIA_SOURCE) {
-               g_print("*** input media source type.(1:camera, 2:mic, 3:audiotest, 4:videotest, 5:media packet, 6:screen)\n");
+               g_print("*** input media source type.(1:audiotest, 2:videotest, 3:mic, 4:camera, 5:screen, 6:file, 7:media packet)\n");
 
        } else if (g_conns[g_conn_index].menu_state == CURRENT_STATUS_REMOVE_MEDIA_SOURCE) {
                g_print("*** input media source id to remove.\n");