/** * gst_rtsp_message_init_data: * @msg: a #GstRTSPMessage * @channel: a channel * * Initialize a new data #GstRTSPMessage for @channel. * * Returns: a #GstRTSPResult. */ GstRTSPResult gst_rtsp_message_init_data (GstRTSPMessage * msg, guint8 channel) { g_return_val_if_fail (msg != NULL, GST_RTSP_EINVAL); gst_rtsp_message_unset (msg); msg->type = GST_RTSP_MESSAGE_DATA; msg->type_data.data.channel = channel; return GST_RTSP_OK; }
/** * gst_rtsp_message_init: * @msg: a #GstRTSPMessage * * Initialize @msg. This function is mostly used when @msg is allocated on the * stack. The reverse operation of this is gst_rtsp_message_unset(). * * Returns: a #GstRTSPResult. */ GstRTSPResult gst_rtsp_message_init (GstRTSPMessage * msg) { g_return_val_if_fail (msg != NULL, GST_RTSP_EINVAL); gst_rtsp_message_unset (msg); msg->type = GST_RTSP_MESSAGE_INVALID; msg->hdr_fields = g_array_new (FALSE, FALSE, sizeof (RTSPKeyValue)); return GST_RTSP_OK; }
/** * gst_rtsp_message_init_response: * @msg: a #GstRTSPMessage * @code: the status code * @reason: (transfer none) (allow-none): the status reason or %NULL * @request: (transfer none) (allow-none): the request that triggered the response or %NULL * * Initialize @msg with @code and @reason. * * When @reason is #NULL, the default reason for @code will be used. * * When @request is not #NULL, the relevant headers will be copied to the new * response message. * * Returns: a #GstRTSPResult. */ GstRTSPResult gst_rtsp_message_init_response (GstRTSPMessage * msg, GstRTSPStatusCode code, const gchar * reason, const GstRTSPMessage * request) { g_return_val_if_fail (msg != NULL, GST_RTSP_EINVAL); gst_rtsp_message_unset (msg); if (reason == NULL) reason = gst_rtsp_status_as_text (code); msg->type = GST_RTSP_MESSAGE_RESPONSE; msg->type_data.response.code = code; msg->type_data.response.reason = g_strdup (reason); msg->type_data.response.version = GST_RTSP_VERSION_1_0; msg->hdr_fields = g_array_new (FALSE, FALSE, sizeof (RTSPKeyValue)); if (request) { if (request->type == GST_RTSP_MESSAGE_HTTP_REQUEST) { msg->type = GST_RTSP_MESSAGE_HTTP_RESPONSE; if (request->type_data.request.version != GST_RTSP_VERSION_INVALID) msg->type_data.response.version = request->type_data.request.version; else msg->type_data.response.version = GST_RTSP_VERSION_1_1; } else { gchar *header; /* copy CSEQ */ if (gst_rtsp_message_get_header (request, GST_RTSP_HDR_CSEQ, &header, 0) == GST_RTSP_OK) { gst_rtsp_message_add_header (msg, GST_RTSP_HDR_CSEQ, header); } /* copy session id */ if (gst_rtsp_message_get_header (request, GST_RTSP_HDR_SESSION, &header, 0) == GST_RTSP_OK) { char *pos; header = g_strdup (header); if ((pos = strchr (header, ';'))) { *pos = '\0'; } g_strchomp (header); gst_rtsp_message_take_header (msg, GST_RTSP_HDR_SESSION, header); } /* FIXME copy more headers? */ } } return GST_RTSP_OK; }
/** * gst_rtsp_message_free: * @msg: a #GstRTSPMessage * * Free the memory used by @msg. * * Returns: a #GstRTSPResult. */ GstRTSPResult gst_rtsp_message_free (GstRTSPMessage * msg) { GstRTSPResult res; g_return_val_if_fail (msg != NULL, GST_RTSP_EINVAL); res = gst_rtsp_message_unset (msg); if (res == GST_RTSP_OK) g_free (msg); return res; }
/** * gst_rtsp_message_init_request: * @msg: a #GstRTSPMessage * @method: the request method to use * @uri: the uri of the request * * Initialize @msg as a request message with @method and @uri. To clear @msg * again, use gst_rtsp_message_unset(). * * Returns: a #GstRTSPResult. */ GstRTSPResult gst_rtsp_message_init_request (GstRTSPMessage * msg, GstRTSPMethod method, const gchar * uri) { g_return_val_if_fail (msg != NULL, GST_RTSP_EINVAL); g_return_val_if_fail (uri != NULL, GST_RTSP_EINVAL); gst_rtsp_message_unset (msg); msg->type = GST_RTSP_MESSAGE_REQUEST; msg->type_data.request.method = method; msg->type_data.request.uri = g_strdup (uri); msg->type_data.request.version = GST_RTSP_VERSION_1_0; msg->hdr_fields = g_array_new (FALSE, FALSE, sizeof (RTSPKeyValue)); return GST_RTSP_OK; }
static void test_client_sdp (const gchar * launch_line, guint * bandwidth_val) { GstRTSPClient *client; GstRTSPMessage request = { 0, }; gchar *str; /* simple DESCRIBE for an existing url */ client = setup_client (launch_line); fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_DESCRIBE, "rtsp://localhost/test") == GST_RTSP_OK); str = g_strdup_printf ("%d", cseq); gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str); g_free (str); gst_rtsp_client_set_send_func (client, test_response_sdp, (gpointer) bandwidth_val, NULL); fail_unless (gst_rtsp_client_handle_message (client, &request) == GST_RTSP_OK); gst_rtsp_message_unset (&request); teardown_client (client); }