static GstElement * kms_recorder_endpoint_get_sink_fallback (KmsRecorderEndpoint * self) { GstElement *sink = NULL; gchar *prot; prot = gst_uri_get_protocol (KMS_URI_ENDPOINT (self)->uri); if ((g_strcmp0 (prot, HTTP_PROTO) == 0) || (g_strcmp0 (prot, HTTPS_PROTO) == 0)) { if (kms_is_valid_uri (KMS_URI_ENDPOINT (self)->uri)) { /* We use souphttpclientsink */ sink = gst_element_factory_make ("curlhttpsink", NULL); g_object_set (sink, "blocksize", MEGA_BYTES (1), "qos", FALSE, "async", FALSE, NULL); } else { GST_ERROR ("URL not valid"); } } g_free (prot); /* Add more if required */ return sink; }
static GstElement * kms_recorder_endpoint_get_sink_fallback (KmsRecorderEndpoint * self) { GstElement *sink = NULL; gchar *prot; prot = gst_uri_get_protocol (KMS_URI_ENDPOINT (self)->uri); if ((g_strcmp0 (prot, HTTP_PROTO) == 0) || (g_strcmp0 (prot, HTTPS_PROTO) == 0)) { SoupSession *ss; if (kms_is_valid_uri (KMS_URI_ENDPOINT (self)->uri)) { /* We use souphttpclientsink */ sink = gst_element_factory_make ("souphttpclientsink", NULL); g_object_set (sink, "blocksize", MEGA_BYTES (1), NULL); ss = soup_session_new_with_options ("timeout", HTTP_TIMEOUT, "ssl-strict", FALSE, NULL); g_object_set (G_OBJECT (sink), "session", ss, NULL); } else { GST_ERROR ("URL not valid"); } } /* Add more if required */ return sink; }
static void kms_recorder_endpoint_create_base_media_muxer (KmsRecorderEndpoint * self) { KmsBaseMediaMuxer *mux; if (self->priv->profile == KMS_RECORDING_PROFILE_KSR) { mux = KMS_BASE_MEDIA_MUXER (kms_ksr_muxer_new (KMS_BASE_MEDIA_MUXER_PROFILE, self->priv->profile, KMS_BASE_MEDIA_MUXER_URI, KMS_URI_ENDPOINT (self)->uri, NULL)); } else { mux = KMS_BASE_MEDIA_MUXER (kms_av_muxer_new (KMS_BASE_MEDIA_MUXER_PROFILE, self->priv->profile, KMS_BASE_MEDIA_MUXER_URI, KMS_URI_ENDPOINT (self)->uri, NULL)); } self->priv->mux = mux; }
static void kms_recorder_endpoint_state_changed (KmsRecorderEndpoint * self, KmsUriEndpointState state) { KMS_ELEMENT_LOCK (KMS_ELEMENT (self)); if (!self->priv->stopping || state == KMS_URI_ENDPOINT_STATE_STOP) { KMS_URI_ENDPOINT_GET_CLASS (self)->change_state (KMS_URI_ENDPOINT (self), state); } KMS_ELEMENT_UNLOCK (KMS_ELEMENT (self)); }
static void kms_recorder_endpoint_state_changed (KmsRecorderEndpoint * self, KmsUriEndpointState state) { KMS_URI_ENDPOINT_GET_CLASS (self)->change_state (KMS_URI_ENDPOINT (self), state); KMS_ELEMENT_UNLOCK (KMS_ELEMENT (self)); g_mutex_lock (&self->priv->state_manager.mutex); self->priv->state_manager.changing = FALSE; if (self->priv->state_manager.locked > 0) g_cond_broadcast (&self->priv->state_manager.cond); g_mutex_unlock (&self->priv->state_manager.mutex); KMS_ELEMENT_LOCK (KMS_ELEMENT (self)); }
static void kms_recorder_endpoint_create_parent_directories (KmsRecorderEndpoint * self) { const gchar *uri = KMS_URI_ENDPOINT (self)->uri; gchar *protocol = gst_uri_get_protocol (uri); if (g_strcmp0 (protocol, "file") == 0) { gchar *file = gst_uri_get_location (uri); gchar *dir = g_path_get_dirname (file); // Try to create directory if (g_mkdir_with_parents (dir, ALLPERMS) != 0) { GST_WARNING_OBJECT (self, "Directory %s could not be created", dir); } g_free (file); g_free (dir); } g_free (protocol); }
static GstElement * kms_recorder_endpoint_get_sink (KmsRecorderEndpoint * self) { GObjectClass *sink_class; GstElement *sink = NULL; GParamSpec *pspec; GError *err = NULL; KMS_ELEMENT_LOCK (KMS_ELEMENT (self)); if (KMS_URI_ENDPOINT (self)->uri == NULL) goto no_uri; if (!gst_uri_is_valid (KMS_URI_ENDPOINT (self)->uri)) goto invalid_uri; sink = gst_element_make_from_uri (GST_URI_SINK, KMS_URI_ENDPOINT (self)->uri, NULL, &err); if (sink == NULL) { /* Some elements have no URI handling capabilities though they can */ /* handle them. We try to find such element before failing to attend */ /* this request */ sink = kms_recorder_endpoint_get_sink_fallback (self); if (sink == NULL) goto no_sink; g_clear_error (&err); } /* Try to configure the sink element */ sink_class = G_OBJECT_GET_CLASS (sink); pspec = g_object_class_find_property (sink_class, "location"); if (pspec != NULL && G_PARAM_SPEC_VALUE_TYPE (pspec) == G_TYPE_STRING) { if (g_strcmp0 (GST_OBJECT_NAME (gst_element_get_factory (sink)), "filesink") == 0) { /* Work around for filesink elements */ gchar *location = gst_uri_get_location (KMS_URI_ENDPOINT (self)->uri); GST_DEBUG_OBJECT (sink, "filesink location=%s", location); g_object_set (sink, "location", location, NULL); g_free (location); } else { GST_DEBUG_OBJECT (sink, "configuring location=%s", KMS_URI_ENDPOINT (self)->uri); g_object_set (sink, "location", KMS_URI_ENDPOINT (self)->uri, NULL); } } goto end; no_uri: { GST_ELEMENT_ERROR (self, RESOURCE, SETTINGS, ("No URI specified to record to."), GST_ERROR_SYSTEM); goto end; } invalid_uri: { GST_ELEMENT_ERROR (self, RESOURCE, SETTINGS, ("Invalid URI \"%s\".", KMS_URI_ENDPOINT (self)->uri), GST_ERROR_SYSTEM); g_clear_error (&err); goto end; } no_sink: { /* whoops, could not create the sink element, dig a little deeper to * figure out what might be wrong. */ if (err != NULL && err->code == GST_URI_ERROR_UNSUPPORTED_PROTOCOL) { gchar *prot; prot = gst_uri_get_protocol (KMS_URI_ENDPOINT (self)->uri); if (prot == NULL) goto invalid_uri; GST_ELEMENT_ERROR (self, RESOURCE, SETTINGS, ("No URI handler implemented for \"%s\".", prot), GST_ERROR_SYSTEM); g_free (prot); } else { GST_ELEMENT_ERROR (self, RESOURCE, SETTINGS, ("%s", (err) ? err->message : "URI was not accepted by any element"), GST_ERROR_SYSTEM); } g_clear_error (&err); goto end; } end: KMS_ELEMENT_UNLOCK (KMS_ELEMENT (self)); return sink; }