static gint create_and_send_OPTION_message(GstRTSPsink* sink, GTimeVal *timeout) { GstRTSPResult res; const gchar *url_server_str = g_strdup_printf("rtsp://%s", sink->host); //"rtsp://192.168.2.108"; // TODO: get ip and port from parameters. const gchar *url_server_ip_str = sink->host;// "192.168.2.108"; //GstRTSPConnection *conn = sink->conn ; int port = sink->port; GstRTSPUrl * url; GstRTSPMessage msg = { 0 }; // set parameters res = gst_rtsp_url_parse((const guint8*)url_server_str, &url); res = gst_rtsp_url_set_port(url, port); // create connection res = gst_rtsp_connection_create(url, &sink->conn); res = gst_rtsp_connection_connect(sink->conn, timeout); if (res != GST_RTSP_OK) goto beach; GstRTSPMethod method = GST_RTSP_OPTIONS; res = gst_rtsp_message_init_request(&msg, method, url_server_str); if (res < 0) return res; /* set user-agent */ if (sink->user_agent) gst_rtsp_message_add_header(&msg, GST_RTSP_HDR_USER_AGENT, sink->user_agent); // Send our packet receive server answer and check some basic checks. if ((res = sendReceiveAndCheck(sink->conn, timeout, &msg, sink->debug)) != GST_RTSP_OK) { return res; } // check if server supports RECORD. if (isServerSupportStreamPush(&msg) != GST_RTSP_OK) { return -ERR_CANNOT_PUSH_STREAM; } beach: return GST_RTSP_OK; }
static void test_prepare_reusable (GstRTSPThreadPool * pool, const gchar * launch_line) { GstRTSPMediaFactory *factory; GstRTSPMedia *media; GstRTSPUrl *url; GstRTSPThread *thread; factory = gst_rtsp_media_factory_new (); fail_if (gst_rtsp_media_factory_is_shared (factory)); fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test", &url) == GST_RTSP_OK); gst_rtsp_media_factory_set_launch (factory, launch_line); media = gst_rtsp_media_factory_construct (factory, url); fail_unless (GST_IS_RTSP_MEDIA (media)); fail_unless (gst_rtsp_media_n_streams (media) == 1); g_object_set (G_OBJECT (media), "reusable", TRUE, NULL); thread = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_MEDIA, NULL); fail_unless (gst_rtsp_media_prepare (media, thread)); fail_unless (gst_rtsp_media_unprepare (media)); fail_unless (gst_rtsp_media_n_streams (media) == 1); thread = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_MEDIA, NULL); fail_unless (gst_rtsp_media_prepare (media, thread)); fail_unless (gst_rtsp_media_unprepare (media)); g_object_unref (media); gst_rtsp_url_free (url); g_object_unref (factory); }
int main(int argc, char **argv) { GMainLoop *loop; GstRTSPServer *server; GstRTSPMediaMapping *mapping; GstRTSPCamMediaFactory *factory; GstRTSPUrl *local_url; GOptionContext *ctx; GOptionGroup *gst_group; gboolean res; GError *error = NULL; g_type_init (); g_thread_init (NULL); ctx = g_option_context_new ("rtsp://host:port/path"); g_option_context_add_main_entries (ctx, option_entries, NULL); gst_group = gst_init_get_option_group (); g_option_context_add_group (ctx, gst_group); res = g_option_context_parse (ctx, &argc, &argv, &error); g_option_context_free (ctx); gst_init (&argc, &argv); if (!res) { g_printerr ("command line error: %s\n", error->message); g_error_free (error); return 1; } if (gst_rtsp_url_parse (argc != 2 ? "rtsp://127.0.0.1:8554/test" : argv[1], &local_url) != GST_RTSP_OK) { g_printerr ("invalid rtsp url\n"); return 1; } loop = g_main_loop_new (NULL, FALSE); server = gst_rtsp_server_new (); factory = gst_rtsp_cam_media_factory_new (); g_object_set (factory, "video-device", video_device, "video", !no_video, "video-width", video_width, "video-height", video_height, "video-codec", video_codec, "video-framerate", fps_n, fps_d, "audio", !no_audio, "audio-device", audio_device, "audio-codec", audio_codec, NULL); gst_rtsp_media_factory_set_shared (GST_RTSP_MEDIA_FACTORY (factory), TRUE); mapping = gst_rtsp_server_get_media_mapping (server); gst_rtsp_media_mapping_add_factory (mapping, local_url->abspath, GST_RTSP_MEDIA_FACTORY (factory)); g_object_unref (mapping); gst_rtsp_url_free (local_url); gst_rtsp_server_attach (server, NULL); g_timeout_add_seconds (5, (GSourceFunc) timeout, server); /* start serving */ g_main_loop_run (loop); return 0; }
static GstRTSPStatusCode nmp_rtsp_handle_request(NmpMediaDevice *device, GstRTSPMessage *request) { GstRTSPMethod method; GstRTSPVersion version; const gchar *url_str; GstRTSPUrl *url; NmpRtspState state = { NULL }; GstRTSPMessage response = { 0 }; GstRTSPStatusCode rtsp_code = GST_RTSP_STS_OK; state.request = request; state.response = &response; gst_rtsp_message_parse_request(request, &method, &url_str, &version); if (version != GST_RTSP_VERSION_1_0) { /* we can only handle 1.0 requests */ nmp_rtsp_device_send_generic_response(device, GST_RTSP_STS_RTSP_VERSION_NOT_SUPPORTED, &state); return GST_RTSP_STS_RTSP_VERSION_NOT_SUPPORTED; } state.method = method; if (gst_rtsp_url_parse(url_str, &url) != GST_RTSP_OK) { nmp_rtsp_device_send_generic_response(device, GST_RTSP_STS_BAD_REQUEST, &state); return GST_RTSP_STS_BAD_REQUEST; } state.url = url; switch (method) { case GST_RTSP_OPTIONS: rtsp_code = nmp_rtsp_handle_options_request(device, &state); break; case GST_RTSP_TEARDOWN: // nmp_rtsp_handle_teardown_request(device, &state); break; case GST_RTSP_DESCRIBE: case GST_RTSP_SETUP: case GST_RTSP_PLAY: case GST_RTSP_PAUSE: case GST_RTSP_SET_PARAMETER: case GST_RTSP_GET_PARAMETER: case GST_RTSP_ANNOUNCE: case GST_RTSP_RECORD: case GST_RTSP_REDIRECT: nmp_rtsp_device_send_generic_response(device, GST_RTSP_STS_NOT_IMPLEMENTED, &state); break; case GST_RTSP_INVALID: default: nmp_rtsp_device_send_generic_response(device, GST_RTSP_STS_BAD_REQUEST, &state); break; } gst_rtsp_url_free(url); return rtsp_code; }