Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.5)
project(gstreamer-rtsp-ssl-example LANGUAGES C)
project(rtsp_server LANGUAGES C)

find_package(PkgConfig REQUIRED)
pkg_check_modules(GSTLIBS REQUIRED
Expand All @@ -15,7 +15,7 @@ pkg_check_modules(GSTREAMER REQUIRED
gstreamer-rtsp-server-1.0)

include_directories(${GSTREAMER_INCLUDE_DIRS})
link_directories(${GSTREAMER_LIBRARIES})
link_directories(${GSTREAMER_LIBRARY_DIRS})

# Update the source file path
add_executable(rtsp_server src/rtsp_server.c)
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# RTSP Server

A lightweight **RTSP (Real Time Streaming Protocol) server** written in **C** using **GStreamer** and **libgstrtspserver**.
This project demonstrates how to set up a simple video streaming service that clients like VLC or FFplay can connect for redering the video.
This project demonstrates how to set up a simple video streaming service that clients like VLC or FFplay can connect to for rendering video.
**Note** The pipeline currently supports video file only but can easily be updated to add audio plugin elements.

---
Expand Down Expand Up @@ -108,13 +108,14 @@ cmake -DCMAKE_INSTALL_PREFIX=/opt/rtsp ..

### 🧰 Option 2: Build Using Makefile

For a simple build using the provided `Makefile`, run:
For a simple build using the provided `src/Makefile`, run:

```bash
cd src
make
```

This generates the `rtsp_server` binary in the same directory.
This generates the `rtsp_server` binary in the `src/` directory.

To clean up:
```bash
Expand Down
13 changes: 10 additions & 3 deletions src/rtsp_server.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdio.h>
#include <string.h>
#include <gst/gst.h>
#include <gst/rtsp-server/rtsp-server.h>
#include <arpa/inet.h>
Expand Down Expand Up @@ -44,6 +45,11 @@ int main(int argc, char *argv[]) {
return -1;
}

if (!g_file_test(argv[1], G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Require regular file when validating input path

g_file_test() treats combined GFileTest flags as an OR, so G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR succeeds for any existing path, including directories. In this case a directory argument bypasses the new guard and the server continues until GStreamer fails at runtime when filesrc tries to open it as a file, which defeats the intended fail-fast validation. Use G_FILE_TEST_IS_REGULAR alone (or separate checks) to enforce a real file.

Useful? React with 👍 / 👎.

g_printerr("Error: '%s' is not a readable file.\n", argv[1]);
return -1;
}

GMainLoop *loop;
GstRTSPServer *server;
GstRTSPMountPoints *mounts;
Expand All @@ -59,11 +65,13 @@ int main(int argc, char *argv[]) {
mounts = gst_rtsp_server_get_mount_points(server);
factory = gst_rtsp_media_factory_new();

gchar *escaped_filepath = g_strescape(filepath, NULL);
gchar *pipeline_str = g_strdup_printf(
"( filesrc location=%s ! qtdemux name=demux "
"( filesrc location=\"%s\" ! qtdemux name=demux "
"demux.video_0 ! queue ! avdec_h264 ! x264enc tune=zerolatency ! rtph264pay name=pay0 pt=96 )",
filepath);
escaped_filepath);
gst_rtsp_media_factory_set_launch(factory, pipeline_str);
g_free(escaped_filepath);
g_free(pipeline_str);

gst_rtsp_media_factory_set_shared(factory, TRUE);
Expand All @@ -78,4 +86,3 @@ int main(int argc, char *argv[]) {
g_main_loop_run(loop);
return 0;
}