GstElement * _owr_payload_create_payload_packetizer(OwrPayload *payload) { GstElement * pay = NULL; gchar *element_name = NULL; OwrMediaType media_type; g_return_val_if_fail(payload, NULL); element_name = g_strdup_printf("pay_%s_%u", OwrCodecTypePayElementName[payload->priv->codec_type], get_unique_id()); pay = gst_element_factory_make(OwrCodecTypePayElementName[payload->priv->codec_type], element_name); g_free(element_name); g_object_bind_property(payload, "mtu", pay, "mtu", G_BINDING_SYNC_CREATE); g_object_get(payload, "media-type", &media_type, NULL); switch (media_type) { case OWR_MEDIA_TYPE_AUDIO: if (OWR_IS_AUDIO_PAYLOAD(payload)) { g_object_bind_property(OWR_AUDIO_PAYLOAD(payload), "ptime", pay, "min-ptime", G_BINDING_SYNC_CREATE); g_object_bind_property(OWR_AUDIO_PAYLOAD(payload), "ptime", pay, "max-ptime", G_BINDING_SYNC_CREATE); } break; case OWR_MEDIA_TYPE_VIDEO: if (payload->priv->codec_type == OWR_CODEC_TYPE_H264) g_object_set(pay, "config-interval", 1, NULL); break; default: g_warn_if_reached(); } return pay; }
GstCaps * _owr_payload_create_raw_caps(OwrPayload *payload) { OwrPayloadPrivate *priv; OwrMediaType media_type; GstCaps *caps = NULL; guint channels = 0; guint width = 0, height = 0; gdouble framerate = 0.0; gint fps_n = 0, fps_d = 1; g_return_val_if_fail(payload, NULL); priv = payload->priv; g_object_get(payload, "media-type", &media_type, NULL); switch (media_type) { case OWR_MEDIA_TYPE_AUDIO: if (OWR_IS_AUDIO_PAYLOAD(payload)) g_object_get(OWR_AUDIO_PAYLOAD(payload), "channels", &channels, NULL); caps = gst_caps_new_simple("audio/x-raw", "rate", G_TYPE_INT, priv->clock_rate, NULL); if (channels > 0) { gst_caps_set_simple(caps, "channels", G_TYPE_INT, channels, NULL); } break; case OWR_MEDIA_TYPE_VIDEO: if (OWR_IS_VIDEO_PAYLOAD(payload)) { g_object_get(OWR_VIDEO_PAYLOAD(payload), "width", &width, "height", &height, "framerate", &framerate, NULL); } caps = gst_caps_new_empty_simple(_owr_codec_type_to_caps_mime(media_type, priv->codec_type)); #ifdef __APPLE__ if (priv->codec_type == OWR_CODEC_TYPE_H264) gst_caps_set_features(caps, 0, gst_caps_features_new_any()); #endif gst_caps_set_simple(caps, "width", G_TYPE_INT, width > 0 ? width : LIMITED_WIDTH, NULL); gst_caps_set_simple(caps, "height", G_TYPE_INT, height > 0 ? height : LIMITED_HEIGHT, NULL); framerate = framerate > 0.0 ? framerate : LIMITED_FRAMERATE; gst_util_double_to_fraction(framerate, &fps_n, &fps_d); gst_caps_set_simple(caps, "framerate", GST_TYPE_FRACTION, fps_n, fps_d, NULL); break; default: g_return_val_if_reached(NULL); } return caps; }
GstCaps * _owr_payload_create_source_caps(OwrPayload *payload) { OwrPayloadPrivate *priv; OwrMediaType media_type; GstCaps *caps = NULL, *tmp; guint channels = 0; g_return_val_if_fail(payload, NULL); priv = payload->priv; g_object_get(payload, "media-type", &media_type, NULL); switch (media_type) { case OWR_MEDIA_TYPE_AUDIO: if (OWR_IS_AUDIO_PAYLOAD(payload)) g_object_get(OWR_AUDIO_PAYLOAD(payload), "channels", &channels, NULL); caps = gst_caps_new_simple("audio/x-raw", "rate", G_TYPE_INT, priv->clock_rate, NULL); if (channels > 0) { gst_caps_set_simple(caps, "channels", G_TYPE_INT, channels, NULL); } break; case OWR_MEDIA_TYPE_VIDEO: caps = gst_caps_new_empty(); /* For cameras that may be able to give us embedded video */ tmp = _owr_payload_create_encoded_caps(payload); if (tmp) { /* * Do not set video params here. * It means that we don't limit the video size in capsfilter and * we could stream any resolution of encoded video including dynamic video size change. */ //set_video_params(tmp, payload); gst_caps_append(caps, tmp); } // For raw video source caps tmp = gst_caps_new_empty_simple("video/x-raw"); set_video_params(tmp, payload); gst_caps_append(caps, tmp); break; default: g_return_val_if_reached(NULL); } return caps; }
GstCaps * _owr_payload_create_raw_caps(OwrPayload *payload) { OwrPayloadPrivate *priv; GstCaps *caps = NULL; guint channels = 0; guint width = 0, height = 0; gdouble framerate = 0.0; gint fps_n = 0, fps_d = 1; g_return_val_if_fail(payload, NULL); priv = payload->priv; switch (priv->media_type) { case OWR_MEDIA_TYPE_AUDIO: if (OWR_IS_AUDIO_PAYLOAD(payload)) g_object_get(OWR_AUDIO_PAYLOAD(payload), "channels", &channels, NULL); caps = gst_caps_new_simple("audio/x-raw", "format", G_TYPE_STRING, "S16LE", "layout", G_TYPE_STRING, "interleaved", "rate", G_TYPE_INT, priv->clock_rate, NULL); if (channels > 0) { gst_caps_set_simple(caps, "channels", G_TYPE_INT, channels, NULL); } break; case OWR_MEDIA_TYPE_VIDEO: if (OWR_IS_VIDEO_PAYLOAD(payload)) { g_object_get(OWR_VIDEO_PAYLOAD(payload), "width", &width, "height", &height, "framerate", &framerate, NULL); } caps = gst_caps_new_empty_simple("video/x-raw"); gst_caps_set_simple(caps, "width", G_TYPE_INT, width > 0 ? width : LIMITED_WIDTH, NULL); gst_caps_set_simple(caps, "height", G_TYPE_INT, height > 0 ? height : LIMITED_HEIGHT, NULL); framerate = framerate > 0.0 ? framerate : LIMITED_FRAMERATE; gst_util_double_to_fraction(framerate, &fps_n, &fps_d); gst_caps_set_simple(caps, "framerate", GST_TYPE_FRACTION, fps_n, fps_d, NULL); break; default: g_return_val_if_reached(NULL); } return caps; }
GstCaps * _owr_payload_create_rtp_caps(OwrPayload *payload) { OwrPayloadPrivate *priv; OwrMediaType media_type; GstCaps *caps = NULL; GEnumClass *enum_class; GEnumValue *enum_value; gchar *encoding_name; gboolean ccm_fir = FALSE, nack_pli = FALSE; g_return_val_if_fail(payload, NULL); priv = payload->priv; switch (priv->codec_type) { case OWR_CODEC_TYPE_PCMU: encoding_name = "PCMU"; break; case OWR_CODEC_TYPE_PCMA: encoding_name = "PCMA"; break; case OWR_CODEC_TYPE_OPUS: encoding_name = "X-GST-OPUS-DRAFT-SPITTKA-00"; break; case OWR_CODEC_TYPE_H264: encoding_name = "H264"; break; case OWR_CODEC_TYPE_VP8: encoding_name = "VP8-DRAFT-IETF-01"; break; default: g_return_val_if_reached(NULL); } caps = gst_caps_new_simple("application/x-rtp", "encoding-name", G_TYPE_STRING, encoding_name, "payload", G_TYPE_INT, priv->payload_type, "clock-rate", G_TYPE_INT, priv->clock_rate, NULL); g_object_get(payload, "media-type", &media_type, NULL); enum_class = G_ENUM_CLASS(g_type_class_ref(OWR_TYPE_MEDIA_TYPE)); enum_value = g_enum_get_value(enum_class, media_type); if (enum_value) gst_caps_set_simple(caps, "media", G_TYPE_STRING, enum_value->value_nick, NULL); g_type_class_unref(enum_class); if (OWR_IS_VIDEO_PAYLOAD(payload)) { g_object_get(OWR_VIDEO_PAYLOAD(payload), "ccm-fir", &ccm_fir, "nack-pli", &nack_pli, NULL); gst_caps_set_simple(caps, "rtcp-fb-ccm-fir", G_TYPE_BOOLEAN, ccm_fir, "rtcp-fb-nack-pli", G_TYPE_BOOLEAN, nack_pli, NULL); } else if (media_type == OWR_MEDIA_TYPE_AUDIO) { guint channels = 0; if (OWR_IS_AUDIO_PAYLOAD(payload)) g_object_get(OWR_AUDIO_PAYLOAD(payload), "channels", &channels, NULL); if (channels > 0) { gst_caps_set_simple(caps, "channels", G_TYPE_INT, channels, NULL); } } return caps; }