return ret;
}
-static GObject *__ms_get_property_owner(GstElement *element, const gchar *key, GValue *value)
-{
- GParamSpec *param = NULL;
- GObject *obj = NULL;
-
- if (GST_IS_CHILD_PROXY(element)) {
- int i;
- const int childs_count = gst_child_proxy_get_children_count(GST_CHILD_PROXY(element));
-
- for (i = 0; (i < childs_count) && (param == NULL); ++i) {
- obj = gst_child_proxy_get_child_by_index(GST_CHILD_PROXY(element), i);
- param = g_object_class_find_property(G_OBJECT_GET_CLASS(obj), key);
- }
- ms_retvm_if(param == NULL || obj == NULL, NULL, "Error: Bin object does not have property [%s].", key);
- } else {
- obj = G_OBJECT(element);
- param = g_object_class_find_property(G_OBJECT_GET_CLASS(obj), key);
- }
-
- g_value_init(value, param->value_type);
-
- if (!(param->flags & G_PARAM_WRITABLE)) {
- /* Skip properties which user can not change. */
- ms_error("Error: node param [%s] is not writable!", key);
- return NULL;
- }
- ms_info("%-20s: %s\n", g_param_spec_get_name(param), g_param_spec_get_blurb(param));
-
- return obj;
-}
-
/* This unlinks from its peer and ghostpads on its way */
static gboolean __ms_pad_peer_unlink(GstPad *pad)
{
static GstCaps *__ms_create_caps_from_fmt(media_format_h fmt)
{
GstCaps *caps = NULL;
+ gchar *caps_name = NULL;
media_format_mimetype_e mime;
- gchar *format_name = NULL;
- int width;
- int height;
- int avg_bps;
- int max_bps;
- int channel;
- int samplerate;
- int bit;
-
- if (media_format_get_video_info(fmt, &mime, &width, &height, &avg_bps, &max_bps) == MEDIA_PACKET_ERROR_NONE) {
-
- ms_info("Creating video Caps from media format [width=%d, height=%d, bps=%d, mime=%d]", width, height, avg_bps, mime);
-
- if (mime & MEDIA_FORMAT_RAW) {
- format_name = g_strdup(__ms_convert_mime_to_string(mime));
- caps = gst_caps_new_simple("video/x-raw", "framerate", GST_TYPE_FRACTION, max_bps, avg_bps, "format", G_TYPE_STRING, format_name, "width", G_TYPE_INT, width, "height", G_TYPE_INT, height, NULL);
- } else {
- /*mime & MEDIA_FORMAT_ENCODED */
- format_name = g_strdup_printf("video/x-%s", __ms_convert_mime_to_string(mime));
- caps = gst_caps_new_simple(format_name, "framerate", GST_TYPE_FRACTION, max_bps, avg_bps, "width", G_TYPE_INT, width, "height", G_TYPE_INT, height, NULL);
- }
-
- } else if (media_format_get_audio_info(fmt, &mime, &channel, &samplerate, &bit, &avg_bps) == MEDIA_PACKET_ERROR_NONE) {
- ms_info("Creating audio Caps from media format [channel=%d, samplerate=%d, bit=%d, avg_bps=%d, mime=%d]", channel, samplerate, bit, avg_bps, mime);
-
- if (mime & MEDIA_FORMAT_RAW) {
- format_name = g_strdup(__ms_convert_mime_to_string(mime));
- caps = gst_caps_new_simple("audio/x-raw", "channels", G_TYPE_INT, channel, "format", G_TYPE_STRING, format_name, "rate", G_TYPE_INT, samplerate, NULL);
- } else {
- ms_error("Encoded audio formats does not supported yet.");
- }
- } else {
- ms_error("Failed getting media info from fmt.");
- }
- MS_SAFE_GFREE(format_name);
-
+ int width, height, avg_bps, max_bps, channel, samplerate, bit;
+
+ if (!media_format_get_audio_info(fmt, &mime, &channel, &samplerate, &bit, &avg_bps)) {
+ if (MEDIA_FORMAT_RAW == (mime & MEDIA_FORMAT_RAW))
+ caps = gst_caps_new_simple("audio/x-raw", "channels", G_TYPE_INT, channel, "format",
+ G_TYPE_STRING, __ms_convert_mime_to_string_format(mime), "rate", G_TYPE_INT, samplerate, NULL);
+ else if (MEDIA_FORMAT_ENCODED == (mime & MEDIA_FORMAT_ENCODED))
+ caps = gst_caps_new_simple(__ms_convert_mime_to_string_format(mime), "channels",G_TYPE_INT, channel, "rate", G_TYPE_INT, samplerate, NULL);
+ caps_name = gst_caps_to_string(caps);
+ ms_info("Creating Audio Caps from media format [%s]", caps_name);
+
+ } else if (!media_format_get_video_info(fmt, &mime, &width, &height, &avg_bps, &max_bps)) {
+ if (MEDIA_FORMAT_RAW == (mime & MEDIA_FORMAT_RAW))
+ caps = gst_caps_new_simple("video/x-raw", "framerate", GST_TYPE_FRACTION, max_bps,
+ avg_bps, "format", G_TYPE_STRING, __ms_convert_mime_to_string_format(mime), "width", G_TYPE_INT, width, "height", G_TYPE_INT, height, NULL);
+ else if (MEDIA_FORMAT_ENCODED == (mime & MEDIA_FORMAT_ENCODED))
+ caps = gst_caps_new_simple(__ms_convert_mime_to_string_format(mime), "framerate", GST_TYPE_FRACTION, max_bps,
+ avg_bps, "width", G_TYPE_INT, width, "height", G_TYPE_INT, height, NULL);
+ caps_name = gst_caps_to_string(caps);
+ ms_info("Creating Video Caps from media format [%s]", caps_name);
+
+ } else
+ ms_error("Error getting media format information");
+
+ MS_SAFE_GFREE(caps_name);
return caps;
}
gst_structure_get_fraction(pad_struct, "framerate", &max_bps, &avg_bps);
gst_structure_get_int(pad_struct, "height", &height);
- media_format_set_video_mime(fmt, __ms_convert_string_format_to_mime(pad_format));
+ media_format_set_video_mime(fmt, __ms_convert_string_format_to_media_format(pad_format));
media_format_set_video_width(fmt, width);
media_format_set_video_height(fmt, height);
media_format_set_video_avg_bps(fmt, avg_bps);
media_format_set_video_max_bps(fmt, max_bps);
} else if (MS_ELEMENT_IS_AUDIO(pad_type)) {
int channels, bps;
- media_format_set_audio_mime(fmt, __ms_convert_string_format_to_mime(pad_format));
+ media_format_set_audio_mime(fmt, __ms_convert_string_format_to_media_format(pad_format));
gst_structure_get_int(pad_struct, "channels", &channels);
media_format_set_audio_channel(fmt, channels);
gst_structure_get_int(pad_struct, "rate", &bps);
int __ms_element_get_pad_fmt(GstElement *gst_element, const char *pad_name, media_format_h *fmt)
{
GstCaps *allowed_caps = NULL;
- GstCaps *property_caps = NULL;
- GValue value = G_VALUE_INIT;
+ GstCaps *format_caps = NULL;
ms_retvm_if(gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Element handle is NULL");
GstPad *pad = gst_element_get_static_pad(gst_element, pad_name);
ms_retvm_if(pad == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Fail to get pad [%s] from element [%s].", pad_name, GST_ELEMENT_NAME(gst_element));
- GParamSpec *param = g_object_class_find_property(G_OBJECT_GET_CLASS(gst_element), "caps");
- if (param) {
- g_value_init(&value, param->value_type);
- if (param->flags & G_PARAM_READWRITE) {
- g_object_get_property(G_OBJECT(gst_element), "caps", &value);
- property_caps = GST_CAPS(gst_value_get_caps(&value));
- }
- g_value_unset(&value);
- }
+ GValue *value = (GValue *) g_object_get_data(G_OBJECT(gst_element), pad_name);
+ if (value)
+ format_caps = GST_CAPS(gst_value_get_caps(value));
+ else
+ ms_info(" No any format is set for pad [%s]", pad_name);
int ret = MEDIA_STREAMER_ERROR_NONE;
allowed_caps = gst_pad_get_allowed_caps(pad);
if (allowed_caps) {
if (gst_caps_is_empty(allowed_caps) || gst_caps_is_any(allowed_caps)) {
- if (property_caps)
- *fmt = __ms_create_fmt_from_caps(property_caps);
+ if (format_caps)
+ *fmt = __ms_create_fmt_from_caps(format_caps);
else
ret = MEDIA_STREAMER_ERROR_INVALID_OPERATION;
} else {
*fmt = __ms_create_fmt_from_caps(allowed_caps);
}
} else {
- if (property_caps)
- *fmt = __ms_create_fmt_from_caps(property_caps);
+ if (format_caps)
+ *fmt = __ms_create_fmt_from_caps(format_caps);
else
ret = MEDIA_STREAMER_ERROR_INVALID_OPERATION;
}
int __ms_element_set_fmt(media_streamer_node_s *node, const char *pad_name, media_format_h fmt)
{
- ms_retvm_if(!node || !pad_name || !fmt, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL");
+ ms_retvm_if(!node || !pad_name || !fmt, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL");
+ gboolean can_accept = FALSE;
- GValue value = G_VALUE_INIT;
- GObject *obj = __ms_get_property_owner(node->gst_element, "caps", &value);
- ms_retvm_if(!obj, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Can't find object");
+ GstCaps *fmt_caps = __ms_create_caps_from_fmt(fmt);
+ ms_retvm_if(!fmt_caps, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Can't convert fmt into Caps");
- GstCaps *caps = __ms_create_caps_from_fmt(fmt);
- ms_retvm_if(!caps, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Can't convert fmt into Caps");
+ GstElementFactory *factory = gst_element_get_factory(node->gst_element);
+ GstPad *node_pad = gst_element_get_static_pad(node->gst_element, pad_name);
+
+ if (GST_PAD_IS_SRC(node_pad))
+ can_accept = gst_element_factory_can_src_any_caps(factory, fmt_caps);
+ else if (GST_PAD_IS_SINK(node_pad))
+ can_accept = gst_element_factory_can_sink_any_caps(factory, fmt_caps);
+ else
+ ms_error(" Node [%s] doesn`t have valid pad [%s]", node->name, pad_name);
- gst_value_set_caps(&value, caps);
- g_object_set_property(obj, "caps", &value);
- g_value_unset(&value);
- gst_caps_unref(caps);
+ if (!can_accept) {
+ if (fmt_caps)
+ gst_caps_unref(fmt_caps);
+ ms_error("Node`s pad [%s] can`t be set with the given format", pad_name);
+ return MEDIA_STREAMER_ERROR_INVALID_OPERATION;
+ } else {
+ MS_SET_INT_CAPS_PARAM(node->gst_element, pad_name, fmt_caps);
+ ms_info("Pad [%s] of node [%s] was set with given format", pad_name, node->name);
+ }
return MEDIA_STREAMER_ERROR_NONE;
}
#include <media_streamer.h>
#include <media_streamer_util.h>
+format_s format_table[] = {
+ /* Audio - ENCODED */
+ {MEDIA_FORMAT_L16, "audio/x-raw"},
+ {MEDIA_FORMAT_ALAW, "audio/x-alaw"},
+ {MEDIA_FORMAT_ULAW, "audio/x-mulaw"},
+ {MEDIA_FORMAT_AMR, "audio/AMR"},
+ {MEDIA_FORMAT_AMR_NB, "audio/AMR"},
+ {MEDIA_FORMAT_AMR_WB, "audio/AMR-WB"},
+ {MEDIA_FORMAT_G729, "audio/G729"},
+ {MEDIA_FORMAT_AAC, "audio/mpeg"},
+ {MEDIA_FORMAT_AAC_LC, "audio/mpeg"},
+ {MEDIA_FORMAT_AAC_HE, "audio/mpeg"},
+ {MEDIA_FORMAT_AAC_HE_PS, "audio/mpeg"},
+ {MEDIA_FORMAT_MP3, "audio/mpeg"},
+ /* Audio - RAW */
+ {MEDIA_FORMAT_PCM, "S16LE"},
+ /* {MEDIA_FORMAT_PCMA, "audio/x-alaw"}, */
+ /* {MEDIA_FORMAT_PCMU, "audio/x-mulaw"}, */
+ /* Video - ENCODED */
+ {MEDIA_FORMAT_H261, "video/x-h261"},
+ {MEDIA_FORMAT_H263, "video/x-h263"},
+ {MEDIA_FORMAT_H263P, "video/x-h263"},
+ {MEDIA_FORMAT_H264_SP, "video/x-h264"},
+ {MEDIA_FORMAT_H264_MP, "video/x-h264"},
+ {MEDIA_FORMAT_H264_HP, "video/x-h264"},
+ {MEDIA_FORMAT_MJPEG, "image/jpeg"},
+ {MEDIA_FORMAT_MPEG1, "video/mpeg"},
+ {MEDIA_FORMAT_MPEG2_SP, "video/mpeg"},
+ {MEDIA_FORMAT_MPEG2_MP, "video/mpeg"},
+ {MEDIA_FORMAT_MPEG2_HP, "video/mpeg"},
+ {MEDIA_FORMAT_MPEG4_SP, "video/mpeg"},
+ {MEDIA_FORMAT_MPEG4_ASP, "video/mpeg"},
+ {MEDIA_FORMAT_HEVC, "video/x-h265"},
+ {MEDIA_FORMAT_VP8, "video/x-vp8"},
+ {MEDIA_FORMAT_VP9, "video/x-vp9"},
+ {MEDIA_FORMAT_VC1, "video/x-wmv"},
+ /* Video - RAW */
+ {MEDIA_FORMAT_I420, "I420"},
+ {MEDIA_FORMAT_NV12, "NV12"},
+ {MEDIA_FORMAT_NV12T, "NV12T"},
+ {MEDIA_FORMAT_YV12, "YV12"},
+ {MEDIA_FORMAT_NV21, "NV21"},
+ {MEDIA_FORMAT_NV16, "NV16"},
+ {MEDIA_FORMAT_YUYV, "YUYV"},
+ {MEDIA_FORMAT_UYVY, "UYVY"},
+ {MEDIA_FORMAT_422P, "422P"},
+ {MEDIA_FORMAT_RGB565, "RGB565"},
+ {MEDIA_FORMAT_RGB888, "RGB888"},
+ {MEDIA_FORMAT_RGBA, "RGBA"},
+ {MEDIA_FORMAT_ARGB, "ARGB"},
+ {MEDIA_FORMAT_NATIVE_VIDEO, "NATIVE_VIDEO"},
+ {MEDIA_FORMAT_MAX, NULL}
+};
+
static void __ms_check_ini_status(void);
gchar *__ms_ini_get_string(dictionary *dict, const char *ini_path, char *default_str)
}
}
+const gchar *__ms_convert_mime_to_string_format(media_format_mimetype_e mime)
+{
+ gchar *format_name = NULL;
+ int it_format;
+ for (it_format = 0; format_table[it_format].format != MEDIA_FORMAT_MAX; it_format++) {
+ if (mime == format_table[it_format].format) {
+ format_name = format_table[it_format].format_name;
+ break;
+ }
+ }
+
+ return format_name;
+}
+
const gchar *__ms_convert_mime_to_string(media_format_mimetype_e mime)
{
switch (mime) {
}
}
-media_format_mimetype_e __ms_convert_string_format_to_mime(const char *format_type)
+media_format_mimetype_e __ms_convert_string_format_to_media_format(const char *format_type)
{
- if (g_strrstr(format_type, "I420")) {
- return MEDIA_FORMAT_I420;
- } else if (g_strrstr(format_type, "YV12")) {
- return MEDIA_FORMAT_YV12;
- } else if (g_strrstr(format_type, "h263")) {
- return MEDIA_FORMAT_H263;
- } else if (g_strrstr(format_type, "h264")) {
- return MEDIA_FORMAT_H264_SP;
- } else if (g_strrstr(format_type, DEFAULT_AUDIO)) {
- return MEDIA_FORMAT_PCM;
- } else {
- ms_error("Invalid or Unsupported media format [%s].", format_type);
- return MEDIA_FORMAT_NONE;
+ media_format_mimetype_e mime = 0;
+ int it_format;
+ for (it_format = 0; format_table[it_format].format != MEDIA_FORMAT_MAX; it_format++) {
+ if (g_strrstr(format_type, format_table[it_format].format_name)) {
+ mime = format_table[it_format].format;
+ break;
+ }
}
+
+ return mime;
}
void __ms_signal_create(GList **sig_list, GstElement *obj, const char *sig_name, GCallback cb, gpointer user_data)