更新:我能够通过关闭防火墙来解决这个问题。
但是现在我有另一个问题,大约有。视频播放延迟 1 秒。 有什么关于如何改善延迟的建议吗?
我正在尝试使用 Gstreamer 构建 RTSP 服务器来流式传输笔记本电脑上的内置摄像头。当我使用 VLC 作为客户端并在本地进行流传输时,此设置效果很好。
但是,当我尝试连接同一网络上的另一台笔记本电脑时,我获取服务器笔记本电脑的 IP 地址 (192.168.1.2) 并将此 URL (rtsp://192.168.1.2:8554/test) 提供给运行在客户端笔记本电脑。
不幸的是,它不起作用,我不确定问题的根源。
值得一提的是,我正在 Windows 10 上工作。
这是我的代码
#include <gst/gst.h>
#include <gst/rtsp-server/rtsp-server.h>
/* this timeout is periodically run to clean up the expired sessions from the
* pool. This needs to be run explicitly currently but might be done
* automatically as part of the mainloop. */
static gboolean
timeout(GstRTSPServer* server)
{
GstRTSPSessionPool* pool;
pool = gst_rtsp_server_get_session_pool(server);
gst_rtsp_session_pool_cleanup(pool);
g_object_unref(pool);
return TRUE;
}
int
main(int argc, char* argv[])
{
GMainLoop* loop;
GstRTSPServer* server;
GstRTSPMountPoints* mounts;
GstRTSPMediaFactory* factory;
gst_init(&argc, &argv);
loop = g_main_loop_new(NULL, FALSE);
/* create a server instance */
server = gst_rtsp_server_new();
gst_rtsp_server_set_address(server, "192.168.1.2");
gst_rtsp_server_set_service(server, "8554");
/* get the mount points for this server, every server has a default object
* that be used to map uri mount points to media factories */
mounts = gst_rtsp_server_get_mount_points(server);
/* make a media factory for a test stream. The default media factory can use
* gst-launch syntax to create pipelines.
* any launch line works as long as it contains elements named pay%d. Each
* element with pay%d names will be a stream */
factory = gst_rtsp_media_factory_new();
gst_rtsp_media_factory_set_launch(factory, "( "
"ksvideosrc do-stats=TRUE ! video/x-raw,width=640,height=480! "
"videoconvert ! x264enc ! rtph264pay name=pay0 pt=96 "
"audiotestsrc ! audio/x-raw,rate=8000 ! "
"alawenc ! rtppcmapay name=pay1 pt=97 " ")");
/* attach the test factory to the /test url */
gst_rtsp_mount_points_add_factory(mounts, "/test", factory);
/* don't need the ref to the mapper anymore */
g_object_unref(mounts);
/* attach the server to the default maincontext */
if (gst_rtsp_server_attach(server, NULL) == 0)
goto failed;
/* add a timeout for the session cleanup */
g_timeout_add_seconds(2, (GSourceFunc)timeout, server);
/* start serving, this never stops */
g_print("stream ready\n");
g_main_loop_run(loop);
return 0;
/* ERRORS */
failed:
{
g_print("failed to attach the server\n");
return -1;
}
}