#include "media_streamer_gst_webrtc.h"
#include "media_streamer_node.h"
+int ms_webrtcbin_set_pad_format(GstElement *webrtc_container, const char *pad_name, media_format_h fmt)
+{
+ int ret = MEDIA_STREAMER_ERROR_NONE;
+ media_format_mimetype_e mime;
+ GstCaps *caps = NULL;
+ GstPad *sinkpad = NULL;
+ gchar *media = NULL;
+ gchar *caps_str = NULL;
+ const gchar *encoding_name = NULL;
+ gint payload = 0;
+
+ ms_retvm_if(webrtc_container == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "webrtc_container is NULL");
+ ms_retvm_if(pad_name == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "pad_name is NULL");
+ ms_retvm_if(fmt == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "fmt is NULL");
+
+ ms_debug_fenter();
+
+ sinkpad = gst_element_get_static_pad(webrtc_container, pad_name);
+ if (!sinkpad) {
+ ms_error("[%s] doesn`t have valid pad [%s]", GST_ELEMENT_NAME(webrtc_container), pad_name);
+ return MEDIA_STREAMER_ERROR_INVALID_OPERATION;
+ }
+
+ if (!media_format_get_video_info(fmt, &mime, NULL, NULL, NULL, NULL) &&
+ g_strrstr(pad_name, MS_RTP_PAD_VIDEO_IN)) {
+ media = "video";
+ payload = 96;
+ } else if (!media_format_get_audio_info(fmt, &mime, NULL, NULL, NULL, NULL) &&
+ g_strrstr(pad_name, MS_RTP_PAD_AUDIO_IN)) {
+ media = "audio";
+ payload = 97;
+ } else {
+ ms_error("format is not video or audio format");
+ goto end;
+ }
+ encoding_name = ms_convert_mime_to_rtp_format(mime);
+
+ caps = gst_caps_new_simple("application/x-rtp",
+ "media", G_TYPE_STRING, media,
+ "encoding-name", G_TYPE_STRING, encoding_name,
+ "payload", G_TYPE_INT, payload, NULL);
+
+ if (!gst_pad_set_caps(sinkpad, caps)) {
+ ms_error("[%s]'s pad [%s] can't be set with the given format", GST_ELEMENT_NAME(webrtc_container), pad_name);
+ ret = MEDIA_STREAMER_ERROR_INVALID_OPERATION;
+ goto end;
+ }
+ caps_str = gst_caps_to_string(caps);
+ ms_info("[%s]'s pad [%s] is set with the given format[%s]", GST_ELEMENT_NAME(webrtc_container), pad_name, caps_str);
+ MS_SAFE_GFREE(caps_str);
+
+end:
+ MS_SAFE_UNREF(sinkpad);
+ MS_SAFE_UNREF(caps);
+
+ return ret;
+}
+
static gchar *__make_ice_candidate_message(guint mlineindex, gchar *candidate)
{
JsonObject *ice, *msg;
return ret;
}
+static int __ms_rtp_node_set_pad_format(media_streamer_node_s *node, const char *pad_name, media_format_h fmt)
+{
+ int ret = MEDIA_STREAMER_ERROR_NONE;
+ media_format_mimetype_e mime;
+ gchar *rtp_caps_str = NULL;
+
+ ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL");
+ ms_retvm_if(node->gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node's element is NULL");
+ ms_retvm_if(pad_name == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "pad_name is NULL");
+ ms_retvm_if(fmt == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "fmt is NULL");
+
+ ms_debug_fenter();
+
+ /* It is needed to set 'application/x-rtp' for audio and video udpsrc */
+ if (g_strrstr(pad_name, MS_RTP_PAD_VIDEO_IN)) {
+ ret = media_format_get_video_info(fmt, &mime, NULL, NULL, NULL, NULL);
+ if (MEDIA_FORMAT_ERROR_NONE == ret) {
+ rtp_caps_str = g_strdup_printf("application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=%s", ms_convert_mime_to_rtp_format(mime));
+ param_s param = {MEDIA_STREAMER_PARAM_VIDEO_IN_FORMAT, MEDIA_STREAMER_PARAM_VIDEO_IN_FORMAT};
+ ret = ms_node_set_param_value(node, ¶m, rtp_caps_str);
+ }
+ } else if (g_strrstr(pad_name, MS_RTP_PAD_AUDIO_IN)) {
+ int audio_channels, audio_samplerate;
+ ret = media_format_get_audio_info(fmt, &mime, &audio_channels, &audio_samplerate, NULL, NULL);
+ if (MEDIA_FORMAT_ERROR_NONE == ret) {
+ rtp_caps_str = g_strdup_printf("application/x-rtp,media=(string)audio,clock-rate=(int)8000,encoding-name=(string)AMR,encoding-params=(string)1,octet-align=(string)1");
+ param_s param = {MEDIA_STREAMER_PARAM_AUDIO_IN_FORMAT, MEDIA_STREAMER_PARAM_AUDIO_IN_FORMAT};
+ ret = ms_node_set_param_value(node, ¶m, rtp_caps_str);
+ }
+ } else {
+ ms_error("[%s]'s pad [%s] can't be set with the given format", GST_ELEMENT_NAME(node->gst_element), pad_name);
+ ret = MEDIA_STREAMER_ERROR_INVALID_OPERATION;
+ }
+ MS_SAFE_GFREE(rtp_caps_str);
+
+ return ret;
+}
+
int ms_node_set_pad_format(media_streamer_node_s *node, const char *pad_name, media_format_h fmt)
{
int ret = MEDIA_STREAMER_ERROR_NONE;
ms_debug_fenter();
ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL");
+ ms_retvm_if(node->gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node's element is NULL");
ms_retvm_if(pad_name == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "pad_name is NULL");
ms_retvm_if(fmt == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "fmt is NULL");
- if (node->type == MEDIA_STREAMER_NODE_TYPE_RTP) {
- media_format_mimetype_e mime;
- gchar *rtp_caps_str = NULL;
-
- /* It is needed to set 'application/x-rtp' for audio and video udpsrc */
- if (g_strrstr(pad_name, MS_RTP_PAD_VIDEO_IN)) {
- ret = media_format_get_video_info(fmt, &mime, NULL, NULL, NULL, NULL);
- if (MEDIA_FORMAT_ERROR_NONE == ret) {
- rtp_caps_str = g_strdup_printf("application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=%s", ms_convert_mime_to_rtp_format(mime));
- param_s param = {MEDIA_STREAMER_PARAM_VIDEO_IN_FORMAT, MEDIA_STREAMER_PARAM_VIDEO_IN_FORMAT};
- ret = ms_node_set_param_value(node, ¶m, rtp_caps_str);
- }
- } else if (g_strrstr(pad_name, MS_RTP_PAD_AUDIO_IN)) {
- int audio_channels, audio_samplerate;
- ret = media_format_get_audio_info(fmt, &mime, &audio_channels, &audio_samplerate, NULL, NULL);
- if (MEDIA_FORMAT_ERROR_NONE == ret) {
- rtp_caps_str = g_strdup_printf("application/x-rtp,media=(string)audio,clock-rate=(int)8000,encoding-name=(string)AMR,encoding-params=(string)1,octet-align=(string)1");
- param_s param = {MEDIA_STREAMER_PARAM_AUDIO_IN_FORMAT, MEDIA_STREAMER_PARAM_AUDIO_IN_FORMAT};
- ret = ms_node_set_param_value(node, ¶m, rtp_caps_str);
- }
- }
-
- MS_SAFE_GFREE(rtp_caps_str);
- } else {
+ if (node->type == MEDIA_STREAMER_NODE_TYPE_RTP)
+ ret = __ms_rtp_node_set_pad_format(node, pad_name, fmt);
+ else if (node->type == MEDIA_STREAMER_NODE_TYPE_WEBRTC)
+ ret = ms_webrtcbin_set_pad_format(node->gst_element, pad_name, fmt);
+ else
ret = ms_element_set_fmt(node->gst_element, pad_name, fmt);
- }
ms_debug_fleave();