From: Sangchul Lee Date: Fri, 23 Oct 2020 12:02:07 +0000 (+0900) Subject: Apply values of newly added items in ini configuration file X-Git-Tag: submit/tizen/20210729.023123~198 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5a15b3c1d70772bf9f84c8f12ad8f63e41d2484f;p=platform%2Fcore%2Fapi%2Fwebrtc.git Apply values of newly added items in ini configuration file Items regarding media source and codec are added in ini structure. These values are now applied when creating a media source. The new items are as below. [general] gstreamer excluded elements = [media source] video format = video width = video height = video framerate = audio format = audio samplerate = audio channels = [codec] audio codec = video codec = [Version] 0.1.44 [Issue Type] Improvement Change-Id: I8a1a3570f5cf3001a25c529e63d0bdef900a44b9 Signed-off-by: Sangchul Lee --- diff --git a/include/webrtc_private.h b/include/webrtc_private.h index 9ab77cfd..e36b7c59 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -137,7 +137,7 @@ do { \ #define GENERATE_DOT(x_webrtc, x_fmt, x_arg...) \ do { \ gchar *dot_name; \ - if (!x_webrtc->ini.generate_dot) \ + if (!x_webrtc->ini.general.generate_dot) \ break; \ dot_name = g_strdup_printf(""x_fmt"", x_arg); \ _generate_dot(x_webrtc, dot_name); \ @@ -159,9 +159,25 @@ typedef enum { typedef struct _webrtc_ini_s { dictionary *dict; - gboolean generate_dot; - gchar **gst_args; - gchar **gst_excluded_elements; + struct { + gboolean generate_dot; + const char *dot_path; + gchar **gst_args; + gchar **gst_excluded_elements; + } general; + struct { + const char *v_format; + int v_width; + int v_height; + int v_framerate; + const char *a_format; + int a_samplerate; + int a_channels; + } media_source; + struct { + const char *video; + const char *audio; + } codec; } webrtc_ini_s; typedef struct _webrtc_gst_slot_s { diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 0acf6df8..8879347d 100644 --- a/packaging/capi-media-webrtc.spec +++ b/packaging/capi-media-webrtc.spec @@ -1,6 +1,6 @@ Name: capi-media-webrtc Summary: A WebRTC library in Tizen Native API -Version: 0.1.43 +Version: 0.1.44 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_ini.c b/src/webrtc_ini.c index 15515aab..c09e63ed 100644 --- a/src/webrtc_ini.c +++ b/src/webrtc_ini.c @@ -25,6 +25,86 @@ #define INI_ITEM_GENERAL_DOT_GENERATE "general:generate dot" #define INI_ITEM_GENERAL_GST_ARGS "general:gstreamer arguments" #define INI_ITEM_GENERAL_GST_EXCLUDED_ELEMENTS "general:gstreamer excluded elements" +#define INI_ITEM_MEDIA_SOURCE_V_FORMAT "media source:video format" +#define INI_ITEM_MEDIA_SOURCE_V_WIDTH "media source:video width" +#define INI_ITEM_MEDIA_SOURCE_V_HEIGHT "media source:video height" +#define INI_ITEM_MEDIA_SOURCE_V_FRAMERATE "media source:video framerate" +#define INI_ITEM_MEDIA_SOURCE_A_FORMAT "media source:audio format" +#define INI_ITEM_MEDIA_SOURCE_A_SAMPLERATE "media source:audio samplerate" +#define INI_ITEM_MEDIA_SOURCE_A_CHANNELS "media source:audio channels" +#define INI_ITEM_CODEC_VIDEO "codec:video codec" +#define INI_ITEM_CODEC_AUDIO "codec:audio codec" + +#define DEFAULT_VIDEO_RAW_FORMAT "I420" +#define DEFAULT_VIDEO_WIDTH 320 +#define DEFAULT_VIDEO_HEIGHT 240 +#define DEFAULT_VIDEO_FRAMERATE 30 +#define DEFAULT_AUDIO_RAW_FORMAT "S16LE" +#define DEFAULT_AUDIO_SAMPLERATE 8000 +#define DEFAULT_AUDIO_CHANNELS 1 + +#define DEFAULT_VIDEO_CODEC "vp8" +#define DEFAULT_AUDIO_CODEC "opus" + +typedef enum { + INI_ITEM_TYPE_BOOL, + INI_ITEM_TYPE_INT, + INI_ITEM_TYPE_STRING, + INI_ITEM_TYPE_STRINGS +} ini_item_type_e; + +static void __dump_item(const char *prefix_str, ini_item_type_e type, void *item) +{ + RET_IF(prefix_str == NULL, "prefix_str is NULL"); + + if (item == NULL) + return; + + switch (type) { + case INI_ITEM_TYPE_BOOL: + LOG_INFO("- %-19s = %s", prefix_str, *(gboolean*)item ? "yes" : "no"); + break; + case INI_ITEM_TYPE_INT: + LOG_INFO("- %-19s = %d", prefix_str, *(int*)item); + break; + case INI_ITEM_TYPE_STRING: + LOG_INFO("- %-19s = %s", prefix_str, (const char *)item); + break; + case INI_ITEM_TYPE_STRINGS: { + gchar *joined_str = g_strjoinv(" ", item); + LOG_INFO("- %-19s = %s", prefix_str, joined_str); + g_free(joined_str); + break; + } + default: + LOG_ERROR("not supported type[%d]", type); + break; + } +} + +static void __dump_ini(webrtc_ini_s *ini) +{ + RET_IF(ini == NULL, "ini is NULL"); + + LOG_INFO("[general]"); + __dump_item("generate dot", INI_ITEM_TYPE_BOOL, &ini->general.generate_dot); + __dump_item("dot path", INI_ITEM_TYPE_STRING, (void *)ini->general.dot_path); + __dump_item("gstreamer arguments", INI_ITEM_TYPE_STRINGS, ini->general.gst_args); + __dump_item("gstreamer excluded elements", INI_ITEM_TYPE_STRINGS, ini->general.gst_excluded_elements); + + LOG_INFO("[media source]"); + __dump_item("video format", INI_ITEM_TYPE_STRING, (void *)ini->media_source.v_format); + __dump_item("video width", INI_ITEM_TYPE_INT, &ini->media_source.v_width); + __dump_item("video height", INI_ITEM_TYPE_INT, &ini->media_source.v_height); + __dump_item("video framerate", INI_ITEM_TYPE_INT, &ini->media_source.v_framerate); + __dump_item("audio format", INI_ITEM_TYPE_STRING, (void *)ini->media_source.a_format); + __dump_item("audio samplerate", INI_ITEM_TYPE_INT, &ini->media_source.a_samplerate); + __dump_item("audio channels", INI_ITEM_TYPE_INT, &ini->media_source.a_channels); + + LOG_INFO("[codec]"); + __dump_item("video codec", INI_ITEM_TYPE_STRING, (void *)ini->codec.video); + __dump_item("audio codec", INI_ITEM_TYPE_STRING, (void *)ini->codec.audio); +} static const char* __get_delimiter(const char *ini_path) { @@ -59,27 +139,41 @@ static void __ini_read_list(dictionary *dict, const char *ini_path, gchar ***lis int _load_ini(webrtc_s *webrtc) { - const char *dot_path; + webrtc_ini_s *ini; RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); memset(&webrtc->ini, 0, sizeof(webrtc_ini_s)); + ini = &webrtc->ini; - webrtc->ini.dict = iniparser_load(WEBRTC_INI_PATH); - if (!webrtc->ini.dict) + ini->dict = iniparser_load(WEBRTC_INI_PATH); + if (!ini->dict) LOG_WARNING("could not open ini[%s], use default values", WEBRTC_INI_PATH); - webrtc->ini.generate_dot = iniparser_getboolean(webrtc->ini.dict, INI_ITEM_GENERAL_DOT_GENERATE, DEFAULT_GENERATE_DOT); - - dot_path = iniparser_getstring(webrtc->ini.dict, INI_ITEM_GENERAL_DOT_PATH, DEFAULT_DOT_PATH); - if (webrtc->ini.generate_dot) { - LOG_INFO("dot file will be stored in [%s]", dot_path); - g_setenv("GST_DEBUG_DUMP_DOT_DIR", dot_path, FALSE); + /* general */ + ini->general.generate_dot = iniparser_getboolean(ini->dict, INI_ITEM_GENERAL_DOT_GENERATE, DEFAULT_GENERATE_DOT); + ini->general.dot_path = iniparser_getstring(ini->dict, INI_ITEM_GENERAL_DOT_PATH, DEFAULT_DOT_PATH); + if (ini->general.generate_dot) { + LOG_INFO("dot file will be stored in [%s]", ini->general.dot_path); + g_setenv("GST_DEBUG_DUMP_DOT_DIR", ini->general.dot_path, FALSE); } + __ini_read_list(ini->dict, INI_ITEM_GENERAL_GST_ARGS, &ini->general.gst_args); + __ini_read_list(ini->dict, INI_ITEM_GENERAL_GST_EXCLUDED_ELEMENTS, &ini->general.gst_excluded_elements); + + /* media source */ + ini->media_source.v_format = iniparser_getstring(ini->dict, INI_ITEM_MEDIA_SOURCE_V_FORMAT, DEFAULT_VIDEO_RAW_FORMAT); + ini->media_source.v_width = iniparser_getint(ini->dict, INI_ITEM_MEDIA_SOURCE_V_WIDTH, DEFAULT_VIDEO_WIDTH); + ini->media_source.v_height = iniparser_getint(ini->dict, INI_ITEM_MEDIA_SOURCE_V_HEIGHT, DEFAULT_VIDEO_HEIGHT); + ini->media_source.v_framerate = iniparser_getint(ini->dict, INI_ITEM_MEDIA_SOURCE_V_FRAMERATE, DEFAULT_VIDEO_FRAMERATE); + ini->media_source.a_format = iniparser_getstring(ini->dict, INI_ITEM_MEDIA_SOURCE_A_FORMAT, DEFAULT_AUDIO_RAW_FORMAT); + ini->media_source.a_samplerate = iniparser_getint(ini->dict, INI_ITEM_MEDIA_SOURCE_A_SAMPLERATE, DEFAULT_AUDIO_SAMPLERATE); + ini->media_source.a_channels = iniparser_getint(ini->dict, INI_ITEM_MEDIA_SOURCE_A_CHANNELS, DEFAULT_AUDIO_CHANNELS); - __ini_read_list(webrtc->ini.dict, INI_ITEM_GENERAL_GST_ARGS, &webrtc->ini.gst_args); + /* codec */ + ini->codec.video = iniparser_getstring(ini->dict, INI_ITEM_CODEC_VIDEO, DEFAULT_VIDEO_CODEC); + ini->codec.audio = iniparser_getstring(ini->dict, INI_ITEM_CODEC_AUDIO, DEFAULT_AUDIO_CODEC); - __ini_read_list(webrtc->ini.dict, INI_ITEM_GENERAL_GST_EXCLUDED_ELEMENTS, &webrtc->ini.gst_excluded_elements); + __dump_ini(ini); return WEBRTC_ERROR_NONE; } @@ -89,11 +183,11 @@ void _unload_ini(webrtc_s *webrtc) RET_IF(webrtc == NULL, "webrtc is NULL"); RET_IF(webrtc->ini.dict == NULL, "ini.dict is NULL"); - g_strfreev(webrtc->ini.gst_args); - webrtc->ini.gst_args = NULL; + g_strfreev(webrtc->ini.general.gst_args); + webrtc->ini.general.gst_args = NULL; - g_strfreev(webrtc->ini.gst_excluded_elements); - webrtc->ini.gst_excluded_elements = NULL; + g_strfreev(webrtc->ini.general.gst_excluded_elements); + webrtc->ini.general.gst_excluded_elements = NULL; iniparser_freedict(webrtc->ini.dict); LOG_DEBUG("ini instance[%p] is freed", webrtc->ini.dict); diff --git a/src/webrtc_private.c b/src/webrtc_private.c index 4e5406d2..86cc748c 100644 --- a/src/webrtc_private.c +++ b/src/webrtc_private.c @@ -383,27 +383,28 @@ int _gst_init(webrtc_s *webrtc) char **argv = NULL; GError *err = NULL; gboolean gst_ret = 0; + gchar **gst_args; RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + gst_args = webrtc->ini.general.gst_args; + /* get argc(number of command line option), argc is always one without option */ - if (webrtc->ini.gst_args) - argc += g_strv_length(webrtc->ini.gst_args); + if (gst_args) + argc += g_strv_length(gst_args); argv = (char **)calloc(argc, sizeof(char*)); RET_VAL_IF(argv == NULL, WEBRTC_ERROR_INVALID_OPERATION, "failed to calloc()"); argv[0] = g_strdup("capi-media-webrtc"); - if (webrtc->ini.gst_args) { - for ( ; webrtc->ini.gst_args[i]; ++i) { - if (argc <= i+1) { - LOG_ERROR("need to check, prevent overrun"); - break; - } - argv[i+1] = webrtc->ini.gst_args[i]; - LOG_DEBUG("add [%s] gstreamer parameter", argv[i+1]); + for ( ; gst_args && gst_args[i]; ++i) { + if (argc <= i+1) { + LOG_ERROR("need to check, prevent overrun"); + break; } + argv[i+1] = gst_args[i]; + LOG_DEBUG("[%s] is added", argv[i+1]); } gst_ret = gst_init_check(&argc, &argv, &err); diff --git a/src/webrtc_source.c b/src/webrtc_source.c index aae7ecda..fd8bb9b4 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -33,17 +33,16 @@ #define DEFAULT_ELEMENT_CAPSFILTER "capsfilter" #define DEFAULT_ELEMENT_QUEUE "queue" -#define DEFAULT_VIDEO_ENCODED_MEDIA_TYPE "video/x-vp8" -#define DEFAULT_VIDEO_RAW_MEDIA_TYPE "video/x-raw" -#define DEFAULT_VIDEO_RAW_FORMAT "I420" -#define DEFAULT_VIDEO_WIDTH 352 -#define DEFAULT_VIDEO_HEIGHT 288 - -#define DEFAULT_AUDIO_ENCODED_MEDIA_TYPE "audio/x-opus" -#define DEFAULT_AUDIO_RAW_MEDIA_TYPE "audio/x-raw" -#define DEFAULT_AUDIO_RAW_FORMAT "S16LE" -#define DEFAULT_AUDIO_CHANNELS 1 -#define DEFAULT_AUDIO_SAMPLERATE 8000 +#define MEDIA_TYPE_AUDIO_RAW "audio/x-raw" +#define MEDIA_TYPE_AUDIO_OPUS "audio/x-opus" +#define MEDIA_TYPE_AUDIO_VORBIS "audio/x-vorbis" +#define MEDIA_TYPE_VIDEO_RAW "video/x-raw" +#define MEDIA_TYPE_VIDEO_VP8 "video/x-vp8" +#define MEDIA_TYPE_VIDEO_VP9 "video/x-vp9" +#define MEDIA_TYPE_VIDEO_THEORA "video/x-theora" +#define MEDIA_TYPE_VIDEO_H263 "video/x-h263" +#define MEDIA_TYPE_VIDEO_H264 "video/x-h264" +#define MEDIA_TYPE_VIDEO_H265 "video/x-h265" typedef enum { CODEC_TYPE_OPUS, @@ -75,28 +74,93 @@ static payload_type_s payload_types[] = { [CODEC_TYPE_H265] = { "H265", 90000 }, }; -static GstCaps *__make_default_raw_caps(webrtc_media_source_type_e type) +static const char * __get_audio_media_type(const char *codec_name) +{ + RET_VAL_IF(codec_name == NULL, NULL, "codec_name is NULL"); + + if (!strcmp(codec_name, "opus") || !strcmp(codec_name, "OPUS")) + return MEDIA_TYPE_AUDIO_OPUS; + else if (!strcmp(codec_name, "vorbis") || !strcmp(codec_name, "VORBIS")) + return MEDIA_TYPE_AUDIO_VORBIS; + + LOG_ERROR("not supported audio codec_name[%s]", codec_name); + + return NULL; +} + +static const char * __get_video_media_type(const char *codec_name) +{ + RET_VAL_IF(codec_name == NULL, NULL, "codec_name is NULL"); + + if (!strcmp(codec_name, "vp8") || !strcmp(codec_name, "VP8")) + return MEDIA_TYPE_VIDEO_VP8; + else if (!strcmp(codec_name, "vp9") || !strcmp(codec_name, "VP9")) + return MEDIA_TYPE_VIDEO_VP9; + else if (!strcmp(codec_name, "theora") || !strcmp(codec_name, "THEORA")) + return MEDIA_TYPE_VIDEO_THEORA; + else if (!strcmp(codec_name, "h263") || !strcmp(codec_name, "H263")) + return MEDIA_TYPE_VIDEO_H263; + else if (!strcmp(codec_name, "h264") || !strcmp(codec_name, "H264")) + return MEDIA_TYPE_VIDEO_H264; + else if (!strcmp(codec_name, "h265") || !strcmp(codec_name, "H265")) + return MEDIA_TYPE_VIDEO_H265; + + LOG_ERROR("not supported video codec_name[%s]", codec_name); + + return NULL; +} + +static codec_type_e __get_audio_codec_type(const gchar *media_type) +{ + if (!g_strcmp0(media_type, MEDIA_TYPE_AUDIO_OPUS)) + return CODEC_TYPE_OPUS; + else if (!g_strcmp0(media_type, MEDIA_TYPE_AUDIO_VORBIS)) + return CODEC_TYPE_VORBIS; + + return CODEC_TYPE_NOT_SUPPORTED; +} + +static codec_type_e __get_video_codec_type(const gchar *media_type) +{ + if (!g_strcmp0(media_type, MEDIA_TYPE_VIDEO_VP8)) + return CODEC_TYPE_VP8; + else if (!g_strcmp0(media_type, MEDIA_TYPE_VIDEO_VP9)) + return CODEC_TYPE_VP9; + else if (!g_strcmp0(media_type, MEDIA_TYPE_VIDEO_THEORA)) + return CODEC_TYPE_THEORA; + else if (!g_strcmp0(media_type, MEDIA_TYPE_VIDEO_H263)) + return CODEC_TYPE_H263; + else if (!g_strcmp0(media_type, MEDIA_TYPE_VIDEO_H264)) + return CODEC_TYPE_H264; + else if (!g_strcmp0(media_type, MEDIA_TYPE_VIDEO_H265)) + return CODEC_TYPE_H265; + + return CODEC_TYPE_NOT_SUPPORTED; +} + +static GstCaps *__make_default_raw_caps(webrtc_media_source_type_e type, webrtc_ini_s *ini) { GstCaps *caps = NULL; + RET_VAL_IF(ini == NULL, NULL, "ini is NULL"); + switch (type) { case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA: case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST: - /* FIXME: get default value from ini */ - caps = gst_caps_new_simple(DEFAULT_VIDEO_RAW_MEDIA_TYPE, - "format", G_TYPE_STRING, DEFAULT_VIDEO_RAW_FORMAT, - "width", G_TYPE_INT, DEFAULT_VIDEO_WIDTH, - "height", G_TYPE_INT, DEFAULT_VIDEO_HEIGHT, + caps = gst_caps_new_simple(MEDIA_TYPE_VIDEO_RAW, + "format", G_TYPE_STRING, ini->media_source.v_format, + "framerate", GST_TYPE_FRACTION, ini->media_source.v_framerate, 1, + "width", G_TYPE_INT, ini->media_source.v_width, + "height", G_TYPE_INT, ini->media_source.v_height, NULL); break; case WEBRTC_MEDIA_SOURCE_TYPE_MIC: case WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST: - /* FIXME: get default value from ini */ - caps = gst_caps_new_simple(DEFAULT_AUDIO_RAW_MEDIA_TYPE, - "format", G_TYPE_STRING, DEFAULT_AUDIO_RAW_FORMAT, - "channels", G_TYPE_INT, DEFAULT_AUDIO_CHANNELS, - "rate", G_TYPE_INT, DEFAULT_AUDIO_SAMPLERATE, + caps = gst_caps_new_simple(MEDIA_TYPE_AUDIO_RAW, + "format", G_TYPE_STRING, ini->media_source.a_format, + "channels", G_TYPE_INT, ini->media_source.a_channels, + "rate", G_TYPE_INT, ini->media_source.a_samplerate, NULL); break; @@ -109,29 +173,30 @@ static GstCaps *__make_default_raw_caps(webrtc_media_source_type_e type) } /* Use g_free() to free the media_type parameter. */ -static GstCaps *__make_default_encoded_caps(webrtc_media_source_type_e type, gchar **media_type) +static GstCaps *__make_default_encoded_caps(webrtc_media_source_type_e type, webrtc_ini_s *ini, gchar **media_type) { GstCaps *caps; const char *_media_type; + RET_VAL_IF(ini == NULL, NULL, "ini is NULL"); + switch (type) { case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA: case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST: - /* FIXME: get default value from ini */ - _media_type = DEFAULT_VIDEO_ENCODED_MEDIA_TYPE; + _media_type = __get_video_media_type(ini->codec.video); caps = gst_caps_new_simple(_media_type, - "width", G_TYPE_INT, DEFAULT_VIDEO_WIDTH, - "height", G_TYPE_INT, DEFAULT_VIDEO_HEIGHT, + "framerate", GST_TYPE_FRACTION, ini->media_source.v_framerate, 1, + "width", G_TYPE_INT, ini->media_source.v_width, + "height", G_TYPE_INT, ini->media_source.v_height, NULL); break; case WEBRTC_MEDIA_SOURCE_TYPE_MIC: case WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST: - /* FIXME: get default value from ini */ - _media_type = DEFAULT_AUDIO_ENCODED_MEDIA_TYPE; - caps = gst_caps_new_simple(DEFAULT_AUDIO_ENCODED_MEDIA_TYPE, - "channels", G_TYPE_INT, DEFAULT_AUDIO_CHANNELS, - "rate", G_TYPE_INT, DEFAULT_AUDIO_SAMPLERATE, + _media_type = __get_audio_media_type(ini->codec.audio); + caps = gst_caps_new_simple(_media_type, + "channels", G_TYPE_INT, ini->media_source.a_channels, + "rate", G_TYPE_INT, ini->media_source.a_samplerate, NULL); break; @@ -146,57 +211,43 @@ static GstCaps *__make_default_encoded_caps(webrtc_media_source_type_e type, gch return caps; } -static codec_type_e __get_codec_type(const gchar *media_type) -{ - if (!g_strcmp0(media_type, "audio/x-opus")) - return CODEC_TYPE_OPUS; - else if (!g_strcmp0(media_type, "audio/x-vorbis")) - return CODEC_TYPE_VORBIS; - else if (!g_strcmp0(media_type, "video/x-vp8")) - return CODEC_TYPE_VP8; - else if (!g_strcmp0(media_type, "video/x-vp9")) - return CODEC_TYPE_VP9; - else if (!g_strcmp0(media_type, "video/x-theora")) - return CODEC_TYPE_THEORA; - else if (!g_strcmp0(media_type, "video/x-h263")) - return CODEC_TYPE_H263; - else if (!g_strcmp0(media_type, "video/x-h264")) - return CODEC_TYPE_H264; - else if (!g_strcmp0(media_type, "video/x-h265")) - return CODEC_TYPE_H265; - else - return CODEC_TYPE_NOT_SUPPORTED; -} - static GstCaps *__make_rtp_caps(const gchar *media_type, unsigned int id) { gchar *caps_str; GstCaps *caps; - codec_type_e codec_type = __get_codec_type(media_type); + gboolean is_video; + codec_type_e codec_type; + + RET_VAL_IF(media_type == NULL, NULL, "media_type is NULL"); + + is_video = g_strrstr(media_type, "video") ? TRUE : FALSE; + codec_type = is_video ? __get_video_codec_type(media_type) : __get_audio_codec_type(media_type); RET_VAL_IF(codec_type == CODEC_TYPE_NOT_SUPPORTED, NULL, "media_type[%s] is not supported", media_type); caps = gst_caps_new_simple("application/x-rtp", - "media", G_TYPE_STRING, g_strrstr(media_type, "video") ? "video" : "audio", + "media", G_TYPE_STRING, is_video ? "video" : "audio", "clock-rate", G_TYPE_INT, payload_types[codec_type].clock_rate, /* FIXME: support various clock-rate */ "encoding-name", G_TYPE_STRING, payload_types[codec_type].encoding_name, "payload", G_TYPE_INT, id + 95, NULL); caps_str = gst_caps_to_string(caps); - LOG_DEBUG("RTP caps is created [%s]", caps_str); + LOG_INFO("RTP caps is created [%s]", caps_str); g_free(caps_str); return caps; } -static int __create_rest_of_elements(webrtc_gst_slot_s *source, webrtc_media_source_type_e type, GstElement **capsfilter, GstElement **encoder, GstElement **payloader, GstElement **queue, GstElement **capsfilter2) +static int __create_rest_of_elements(webrtc_s *webrtc, webrtc_gst_slot_s *source, webrtc_media_source_type_e type, + GstElement **capsfilter, GstElement **encoder, GstElement **payloader, GstElement **queue, GstElement **capsfilter2) { GstCaps *sink_caps; element_info_s elem_info; const gchar *encoder_klass_name; gchar *media_type; + RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); RET_VAL_IF(capsfilter == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "capsfilter is NULL"); RET_VAL_IF(encoder == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "encoder is NULL"); @@ -208,7 +259,7 @@ static int __create_rest_of_elements(webrtc_gst_slot_s *source, webrtc_media_sou LOG_ERROR("failed to create capsfilter"); return WEBRTC_ERROR_INVALID_OPERATION; } - if ((sink_caps = __make_default_raw_caps(type))) { + if ((sink_caps = __make_default_raw_caps(type, &webrtc->ini))) { g_object_set(G_OBJECT(*capsfilter), "caps", sink_caps, NULL); gst_caps_unref(sink_caps); } @@ -219,12 +270,12 @@ static int __create_rest_of_elements(webrtc_gst_slot_s *source, webrtc_media_sou encoder_klass_name = GST_KLASS_NAME_ENCODER_AUDIO; CREATE_ELEMENT_FROM_REGISTRY(elem_info, encoder_klass_name, - __make_default_raw_caps(type), - __make_default_encoded_caps(type, NULL), + __make_default_raw_caps(type, &webrtc->ini), + __make_default_encoded_caps(type, &webrtc->ini, NULL), *encoder); CREATE_ELEMENT_FROM_REGISTRY(elem_info, GST_KLASS_NAME_PAYLOADER_RTP, - __make_default_encoded_caps(type, &media_type), + __make_default_encoded_caps(type, &webrtc->ini, &media_type), NULL, *payloader); @@ -249,7 +300,7 @@ static int __create_rest_of_elements(webrtc_gst_slot_s *source, webrtc_media_sou return WEBRTC_ERROR_NONE; } -static int __build_camerasrc(webrtc_gst_slot_s *source, GstPad *ghost_src_pad) +static int __build_camerasrc(webrtc_s *webrtc, webrtc_gst_slot_s *source, GstPad *ghost_src_pad) { int ret = WEBRTC_ERROR_NONE; GstElement *camerasrc; @@ -259,6 +310,7 @@ static int __build_camerasrc(webrtc_gst_slot_s *source, GstPad *ghost_src_pad) GstElement *queue; GstElement *capsfilter2; + RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); RET_VAL_IF(ghost_src_pad == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "ghost_src_pad is NULL"); RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL"); @@ -272,7 +324,7 @@ static int __build_camerasrc(webrtc_gst_slot_s *source, GstPad *ghost_src_pad) } /* FIXME: set camera default setting from ini */ - if ((ret = __create_rest_of_elements(source, WEBRTC_MEDIA_SOURCE_TYPE_CAMERA, &capsfilter, &videoenc, &videopay, &queue, &capsfilter2)) != WEBRTC_ERROR_NONE) + if ((ret = __create_rest_of_elements(webrtc, source, WEBRTC_MEDIA_SOURCE_TYPE_CAMERA, &capsfilter, &videoenc, &videopay, &queue, &capsfilter2)) != WEBRTC_ERROR_NONE) return ret; gst_bin_add_many(GST_BIN(source->bin), camerasrc, capsfilter, videoenc, videopay, queue, capsfilter2, NULL); @@ -284,7 +336,7 @@ static int __build_camerasrc(webrtc_gst_slot_s *source, GstPad *ghost_src_pad) return _set_ghost_pad_target(ghost_src_pad, capsfilter2, TRUE); } -static int __build_audiosrc(webrtc_gst_slot_s *source, GstPad *ghost_src_pad) +static int __build_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source, GstPad *ghost_src_pad) { int ret = WEBRTC_ERROR_NONE; GstElement *audiosrc; @@ -294,6 +346,7 @@ static int __build_audiosrc(webrtc_gst_slot_s *source, GstPad *ghost_src_pad) GstElement *queue; GstElement *capsfilter2; + RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); RET_VAL_IF(ghost_src_pad == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "ghost_src_pad is NULL"); RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL"); @@ -305,7 +358,7 @@ static int __build_audiosrc(webrtc_gst_slot_s *source, GstPad *ghost_src_pad) return WEBRTC_ERROR_INVALID_OPERATION; } - if ((ret = __create_rest_of_elements(source, WEBRTC_MEDIA_SOURCE_TYPE_MIC, &capsfilter, &audioenc, &audiopay, &queue, &capsfilter2)) != WEBRTC_ERROR_NONE) + if ((ret = __create_rest_of_elements(webrtc, source, WEBRTC_MEDIA_SOURCE_TYPE_MIC, &capsfilter, &audioenc, &audiopay, &queue, &capsfilter2)) != WEBRTC_ERROR_NONE) return ret; gst_bin_add_many(GST_BIN(source->bin), audiosrc, capsfilter, audioenc, audiopay, queue, capsfilter2, NULL); @@ -317,7 +370,7 @@ static int __build_audiosrc(webrtc_gst_slot_s *source, GstPad *ghost_src_pad) return _set_ghost_pad_target(ghost_src_pad, capsfilter2, TRUE); } -static int __build_videotestsrc(webrtc_gst_slot_s *source, GstPad *ghost_src_pad) +static int __build_videotestsrc(webrtc_s *webrtc, webrtc_gst_slot_s *source, GstPad *ghost_src_pad) { int ret = WEBRTC_ERROR_NONE; GstElement *videotestsrc; @@ -327,6 +380,7 @@ static int __build_videotestsrc(webrtc_gst_slot_s *source, GstPad *ghost_src_pad GstElement *queue; GstElement *capsfilter2; + RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); RET_VAL_IF(ghost_src_pad == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "ghost_src_pad is NULL"); RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL"); @@ -339,7 +393,7 @@ static int __build_videotestsrc(webrtc_gst_slot_s *source, GstPad *ghost_src_pad } g_object_set(G_OBJECT(videotestsrc), "is-live", TRUE, NULL); - if ((ret = __create_rest_of_elements(source, WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST, &capsfilter, &videoenc, &videopay, &queue, &capsfilter2)) != WEBRTC_ERROR_NONE) + if ((ret = __create_rest_of_elements(webrtc, source, WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST, &capsfilter, &videoenc, &videopay, &queue, &capsfilter2)) != WEBRTC_ERROR_NONE) return ret; gst_bin_add_many(GST_BIN(source->bin), videotestsrc, capsfilter, videoenc, videopay, queue, capsfilter2, NULL); @@ -351,7 +405,7 @@ static int __build_videotestsrc(webrtc_gst_slot_s *source, GstPad *ghost_src_pad return _set_ghost_pad_target(ghost_src_pad, capsfilter2, TRUE); } -static int __build_audiotestsrc(webrtc_gst_slot_s *source, GstPad *ghost_src_pad) +static int __build_audiotestsrc(webrtc_s *webrtc, webrtc_gst_slot_s *source, GstPad *ghost_src_pad) { int ret = WEBRTC_ERROR_NONE; GstElement *audiotestsrc; @@ -361,6 +415,7 @@ static int __build_audiotestsrc(webrtc_gst_slot_s *source, GstPad *ghost_src_pad GstElement *queue; GstElement *capsfilter2; + RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); RET_VAL_IF(ghost_src_pad == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "ghost_src_pad is NULL"); RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL"); @@ -373,7 +428,7 @@ static int __build_audiotestsrc(webrtc_gst_slot_s *source, GstPad *ghost_src_pad } g_object_set(G_OBJECT(audiotestsrc), "is-live", TRUE, NULL); - if ((ret = __create_rest_of_elements(source, WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST, &capsfilter, &audioenc, &audiopay, &queue, &capsfilter2)) != WEBRTC_ERROR_NONE) + if ((ret = __create_rest_of_elements(webrtc, source, WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST, &capsfilter, &audioenc, &audiopay, &queue, &capsfilter2)) != WEBRTC_ERROR_NONE) return ret; gst_bin_add_many(GST_BIN(source->bin), audiotestsrc, capsfilter, audioenc, audiopay, queue, capsfilter2, NULL); @@ -385,11 +440,12 @@ static int __build_audiotestsrc(webrtc_gst_slot_s *source, GstPad *ghost_src_pad return _set_ghost_pad_target(ghost_src_pad, capsfilter2, TRUE); } -static int __build_source_bin(webrtc_gst_slot_s *source, webrtc_media_source_type_e type) +static int __build_source_bin(webrtc_s *webrtc, webrtc_gst_slot_s *source, webrtc_media_source_type_e type) { int ret = WEBRTC_ERROR_NONE; GstPad *src_pad; + RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL"); @@ -398,16 +454,16 @@ static int __build_source_bin(webrtc_gst_slot_s *source, webrtc_media_source_typ switch (type) { case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA: - return __build_camerasrc(source, src_pad); + return __build_camerasrc(webrtc, source, src_pad); case WEBRTC_MEDIA_SOURCE_TYPE_MIC: - return __build_audiosrc(source, src_pad); + return __build_audiosrc(webrtc, source, src_pad); case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST: - return __build_videotestsrc(source, src_pad); + return __build_videotestsrc(webrtc, source, src_pad); case WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST: - return __build_audiotestsrc(source, src_pad); + return __build_audiotestsrc(webrtc, source, src_pad); default: LOG_ERROR_IF_REACHED("type(%d)", type); @@ -498,7 +554,7 @@ int _add_media_source(webrtc_s *webrtc, webrtc_media_source_type_e type, unsigne MALLOC_AND_INIT_SLOT(source, id, bin_name, webrtc->gst.webrtcbin); - ret = __build_source_bin(source, type); + ret = __build_source_bin(webrtc, source, type); if (ret != WEBRTC_ERROR_NONE) { LOG_ERROR("failed to __build_source_bin()"); goto error;