├── docs ├── sitemap.txt ├── plugin-sitemap.txt ├── index.md ├── plugin-index.md ├── sitemap.md ├── design │ └── gst-rtp-server-design └── meson.build ├── .gitignore ├── AUTHORS ├── TODO ├── tests ├── files │ └── test.avi ├── meson.build ├── test-cleanup.c ├── check │ ├── meson.build │ └── gst │ │ ├── token.c │ │ ├── mountpoints.c │ │ ├── permissions.c │ │ └── sessionpool.c └── test-reuse.c ├── .gitlab-ci.yml ├── REQUIREMENTS ├── gst ├── meson.build ├── rtsp-sink │ ├── meson.build │ └── plugin.c └── rtsp-server │ ├── rtsp-params.h │ ├── rtsp-sdp.h │ ├── rtsp-server-prelude.h │ ├── rtsp-server.h │ ├── rtsp-params.c │ ├── rtsp-latency-bin.h │ ├── rtsp-onvif-client.h │ ├── rtsp-context.c │ ├── rtsp-onvif-server.h │ ├── rtsp-onvif-media.h │ ├── meson.build │ ├── rtsp-context.h │ ├── rtsp-server-internal.h │ ├── rtsp-media-factory-uri.h │ ├── rtsp-onvif-server.c │ ├── rtsp-token.h │ ├── rtsp-onvif-media-factory.h │ ├── rtsp-mount-points.h │ ├── rtsp-permissions.h │ ├── rtsp-session-media.h │ ├── rtsp-session-pool.h │ ├── rtsp-thread-pool.h │ ├── rtsp-onvif-client.c │ └── rtsp-session.h ├── README ├── examples ├── meson.build ├── test-onvif-server.h ├── test-replay-server.h ├── test-readme.c ├── test-onvif-backchannel.c ├── test-sdp.c ├── test-ogg.c ├── test-launch.c ├── test-video-rtx.c ├── test-multicast.c ├── test-record.c ├── test-multicast2.c ├── test-netclock.c ├── test-netclock-client.c ├── test-appsrc.c ├── test-uri.c ├── test-mp4.c ├── test-video.c ├── test-auth.c └── test-record-auth.c ├── meson_options.txt ├── scripts └── extract-release-date-from-doap-file.py ├── hooks └── pre-commit.hook └── RELEASE /docs/sitemap.txt: -------------------------------------------------------------------------------- 1 | gi-index 2 | -------------------------------------------------------------------------------- /docs/plugin-sitemap.txt: -------------------------------------------------------------------------------- 1 | gst-index 2 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # GStreamer RTSP Server 2 | -------------------------------------------------------------------------------- /docs/plugin-index.md: -------------------------------------------------------------------------------- 1 | # rtspclientsink 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | /build 3 | /_build 4 | /b/ 5 | -------------------------------------------------------------------------------- /docs/sitemap.md: -------------------------------------------------------------------------------- 1 | gi-index 2 | gst-index 3 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Wim Taymans 2 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | 2 | - use a config file to configure the server 3 | - error recovery 4 | -------------------------------------------------------------------------------- /tests/files/test.avi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GStreamer/gst-rtsp-server/HEAD/tests/files/test.avi -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | include: "https://gitlab.freedesktop.org/gstreamer/gst-ci/raw/master/gitlab/ci_template.yml" 2 | -------------------------------------------------------------------------------- /REQUIREMENTS: -------------------------------------------------------------------------------- 1 | You need to have GStreamer. You can use an installed version of 2 | GStreamer or from its build dir. 3 | 4 | -------------------------------------------------------------------------------- /gst/meson.build: -------------------------------------------------------------------------------- 1 | subdir('rtsp-server') 2 | 3 | if not get_option('rtspclientsink').disabled() 4 | subdir('rtsp-sink') 5 | endif 6 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | gst-rtsp-server is a library on top of GStreamer for building an RTSP server 2 | 3 | There are some examples in the examples/ directory and more comprehensive 4 | documentation in docs/README. 5 | -------------------------------------------------------------------------------- /tests/meson.build: -------------------------------------------------------------------------------- 1 | # FIXME: make check work on windows 2 | if host_machine.system() != 'windows' and gstcheck_dep.found() 3 | subdir('check') 4 | endif 5 | 6 | test_cleanup_exe = executable('test-cleanup', 'test-cleanup.c', 7 | dependencies: gst_rtsp_server_dep) 8 | 9 | test_reuse_exe = executable('test-reuse', 'test-reuse.c', 10 | dependencies: gst_rtsp_server_dep) 11 | 12 | test('test-cleanup', test_cleanup_exe) 13 | test('test-reuse', test_reuse_exe) 14 | -------------------------------------------------------------------------------- /gst/rtsp-sink/meson.build: -------------------------------------------------------------------------------- 1 | rtspsink_sources = [ 2 | 'gstrtspclientsink.c', 3 | 'plugin.c', 4 | ] 5 | 6 | rtspsink = library('gstrtspclientsink', 7 | rtspsink_sources, 8 | c_args : rtspserver_args, 9 | include_directories : rtspserver_incs, 10 | dependencies : [gstrtsp_dep, gstsdp_dep, gst_rtsp_server_dep], 11 | install : true, 12 | install_dir : plugins_install_dir) 13 | pkgconfig.generate(rtspsink, install_dir : plugins_pkgconfig_install_dir) 14 | plugins += [rtspsink] 15 | -------------------------------------------------------------------------------- /gst/rtsp-sink/plugin.c: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | #include "config.h" 3 | #endif 4 | 5 | #include "gstrtspclientsink.h" 6 | 7 | static gboolean 8 | plugin_init (GstPlugin * plugin) 9 | { 10 | #ifdef ENABLE_NLS 11 | bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); 12 | bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); 13 | #endif /* ENABLE_NLS */ 14 | 15 | if (!gst_element_register (plugin, "rtspclientsink", GST_RANK_NONE, 16 | GST_TYPE_RTSP_CLIENT_SINK)) 17 | return FALSE; 18 | 19 | return TRUE; 20 | } 21 | 22 | GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, 23 | GST_VERSION_MINOR, 24 | rtspclientsink, 25 | "RTSP client sink element", 26 | plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN) 27 | -------------------------------------------------------------------------------- /examples/meson.build: -------------------------------------------------------------------------------- 1 | examples = [ 2 | 'test-appsrc', 3 | 'test-appsrc2', 4 | 'test-auth', 5 | 'test-auth-digest', 6 | 'test-launch', 7 | 'test-mp4', 8 | 'test-multicast2', 9 | 'test-multicast', 10 | 'test-netclock', 11 | 'test-netclock-client', 12 | 'test-ogg', 13 | 'test-onvif-client', 14 | 'test-onvif-server', 15 | 'test-readme', 16 | 'test-record-auth', 17 | 'test-record', 18 | 'test-replay-server', 19 | 'test-sdp', 20 | 'test-uri', 21 | 'test-video', 22 | 'test-video-rtx', 23 | ] 24 | 25 | foreach example : examples 26 | executable(example, '@0@.c'.format(example), 27 | c_args : rtspserver_args, 28 | include_directories : rtspserver_incs, 29 | dependencies : [glib_dep, gst_dep, gstapp_dep, gstnet_dep, gst_rtsp_server_dep], 30 | install: false) 31 | endforeach 32 | 33 | cgroup_dep = dependency('libcgroup', version : '>= 0.26', required : false) 34 | if cgroup_dep.found() 35 | executable('test-cgroups', 'test-cgroups.c', 36 | c_args : rtspserver_args, 37 | include_directories : rtspserver_incs, 38 | dependencies : [glib_dep, gst_dep, gstnet_dep, gst_rtsp_server_dep, cgroup_dep], 39 | install: false) 40 | endif 41 | -------------------------------------------------------------------------------- /examples/test-onvif-server.h: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2019 Mathieu Duponchelle 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | #include 22 | 23 | #include 24 | 25 | G_BEGIN_DECLS 26 | 27 | G_DECLARE_FINAL_TYPE (ReplayBin, replay_bin, REPLAY, BIN, GstBin); 28 | 29 | G_DECLARE_FINAL_TYPE (OnvifFactory, onvif_factory, ONVIF, FACTORY, 30 | GstRTSPOnvifMediaFactory); 31 | 32 | G_END_DECLS 33 | -------------------------------------------------------------------------------- /gst/rtsp-server/rtsp-params.h: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | #ifndef __GST_RTSP_PARAMS_H__ 26 | #define __GST_RTSP_PARAMS_H__ 27 | 28 | #include "rtsp-client.h" 29 | #include "rtsp-session.h" 30 | 31 | G_BEGIN_DECLS 32 | 33 | GST_RTSP_SERVER_API 34 | GstRTSPResult gst_rtsp_params_set (GstRTSPClient * client, GstRTSPContext * ctx); 35 | 36 | GST_RTSP_SERVER_API 37 | GstRTSPResult gst_rtsp_params_get (GstRTSPClient * client, GstRTSPContext * ctx); 38 | 39 | G_END_DECLS 40 | 41 | #endif /* __GST_RTSP_PARAMS_H__ */ 42 | -------------------------------------------------------------------------------- /examples/test-replay-server.h: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2019 Mathieu Duponchelle 3 | * Copyright (C) 2020 Seungha Yang 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Library General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Library General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Library General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 18 | * Boston, MA 02110-1301, USA. 19 | */ 20 | 21 | 22 | #include 23 | 24 | #include 25 | 26 | G_BEGIN_DECLS 27 | 28 | #define GST_TYPE_REPLAY_BIN (gst_replay_bin_get_type ()) 29 | G_DECLARE_FINAL_TYPE (GstReplayBin, gst_replay_bin, GST, REPLAY_BIN, GstBin); 30 | 31 | #define GST_TYPE_RTSP_MEDIA_FACTORY_REPLAY (gst_rtsp_media_factory_replay_get_type ()) 32 | G_DECLARE_FINAL_TYPE (GstRTSPMediaFactoryReplay, 33 | gst_rtsp_media_factory_replay, GST, RTSP_MEDIA_FACTORY_REPLAY, 34 | GstRTSPMediaFactory); 35 | 36 | G_END_DECLS 37 | -------------------------------------------------------------------------------- /meson_options.txt: -------------------------------------------------------------------------------- 1 | # Feature options for plugins with no external deps 2 | option('rtspclientsink', type : 'feature', value : 'auto') 3 | 4 | # Common feature options 5 | option('examples', type : 'feature', value : 'auto', yield : true, 6 | description : 'Build the examples') 7 | option('tests', type : 'feature', value : 'auto', yield : true, 8 | description : 'Build and enable unit tests') 9 | option('introspection', type : 'feature', value : 'auto', yield : true, 10 | description : 'Generate gobject-introspection bindings') 11 | option('gobject-cast-checks', type : 'feature', value : 'auto', yield : true, 12 | description: 'Enable run-time GObject cast checks (auto = enabled for development, disabled for stable releases)') 13 | option('glib-asserts', type : 'feature', value : 'enabled', yield : true, 14 | description: 'Enable GLib assertion (auto = enabled for development, disabled for stable releases)') 15 | option('glib-checks', type : 'feature', value : 'enabled', yield : true, 16 | description: 'Enable GLib checks such as API guards (auto = enabled for development, disabled for stable releases)') 17 | 18 | # Common options 19 | option('package-name', type : 'string', yield : true, 20 | description : 'package name to use in plugins') 21 | option('package-origin', type : 'string', 22 | value : 'Unknown package origin', yield : true, 23 | description : 'package origin URL to use in plugins') 24 | option('doc', type : 'feature', value : 'auto', yield: true, 25 | description: 'Enable documentation.') 26 | -------------------------------------------------------------------------------- /docs/design/gst-rtp-server-design: -------------------------------------------------------------------------------- 1 | RTSP server 2 | ----------- 3 | 4 | This directory contains an example RTSP server built with various GStreamer 5 | components and libraries. It also uses GStreamer for all of the multimedia 6 | procesing and RTP bits. The following features are implemented: 7 | 8 | - 9 | 10 | Server Design 11 | ------------- 12 | 13 | The toplevel component of the server is a GstRTSPServer object. This object 14 | creates and binds on the server socket and attaches into the mainloop. 15 | 16 | For each request a new GstRTSPClient object is created that will accept the 17 | request and a thread is started to handle further communication with the 18 | client until the connection is closed. 19 | 20 | When a client issues a SETUP request we create a GstRTSPSession object, 21 | identified with a sessionid, that will keep track of the state of a client. 22 | The object is destroyed when a TEARDOWN request is made for that sessionid. 23 | 24 | We also maintain a pool of URL to media pipeline mappings. Each url is mapped to 25 | an object that is able to provide a pipeline for that media. We provide 26 | pipelines to stream live captured data, on-demand file streaming or on-demand 27 | transcoding of a file or stream. 28 | 29 | A pool of currently active pipelines is also maintained. Usually the active 30 | pipelines are in use by one or more GstRTSPSession objects. An active pipeline 31 | becomes inactive when no more sessions refer to it. 32 | 33 | A client can choose to start a new pipeline or join a currently active pipeline. 34 | Some active pipeline cannot be joined (such as on-demand streams) but a new 35 | instance of that pipeline can be created. 36 | -------------------------------------------------------------------------------- /gst/rtsp-server/rtsp-sdp.h: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include "rtsp-media.h" 24 | 25 | #ifndef __GST_RTSP_SDP_H__ 26 | #define __GST_RTSP_SDP_H__ 27 | 28 | G_BEGIN_DECLS 29 | 30 | typedef struct { 31 | gboolean is_ipv6; 32 | const gchar *server_ip; 33 | } GstSDPInfo; 34 | 35 | /* creating SDP */ 36 | 37 | GST_RTSP_SERVER_API 38 | gboolean gst_rtsp_sdp_from_media (GstSDPMessage *sdp, GstSDPInfo *info, GstRTSPMedia * media); 39 | 40 | GST_RTSP_SERVER_API 41 | gboolean gst_rtsp_sdp_from_stream (GstSDPMessage * sdp, GstSDPInfo * info, GstRTSPStream *stream); 42 | 43 | GST_RTSP_SERVER_API 44 | gboolean 45 | gst_rtsp_sdp_make_media (GstSDPMessage * sdp, GstSDPInfo * info, GstRTSPStream * stream, GstCaps * caps, GstRTSPProfile profile); 46 | 47 | G_END_DECLS 48 | 49 | #endif /* __GST_RTSP_SDP_H__ */ 50 | -------------------------------------------------------------------------------- /scripts/extract-release-date-from-doap-file.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # extract-release-date-from-doap-file.py VERSION DOAP-FILE 4 | # 5 | # Extract release date for the given release version from a DOAP file 6 | # 7 | # Copyright (C) 2020 Tim-Philipp Müller 8 | # 9 | # This library is free software; you can redistribute it and/or 10 | # modify it under the terms of the GNU Library General Public 11 | # License as published by the Free Software Foundation; either 12 | # version 2 of the License, or (at your option) any later version. 13 | # 14 | # This library is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | # Library General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU Library General Public 20 | # License along with this library; if not, write to the 21 | # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 22 | # Boston, MA 02110-1301, USA. 23 | 24 | import sys 25 | import xml.etree.ElementTree as ET 26 | 27 | if len(sys.argv) != 3: 28 | sys.exit('Usage: {} VERSION DOAP-FILE'.format(sys.argv[0])) 29 | 30 | release_version = sys.argv[1] 31 | doap_fn = sys.argv[2] 32 | 33 | tree = ET.parse(doap_fn) 34 | root = tree.getroot() 35 | 36 | namespaces = {'doap': 'http://usefulinc.com/ns/doap#'} 37 | 38 | for v in root.findall('doap:release/doap:Version', namespaces=namespaces): 39 | if v.findtext('doap:revision', namespaces=namespaces) == release_version: 40 | release_date = v.findtext('doap:created', namespaces=namespaces) 41 | if release_date: 42 | print(release_date) 43 | sys.exit(0) 44 | 45 | sys.exit('Could not find a release with version {} in {}'.format(release_version, doap_fn)) 46 | -------------------------------------------------------------------------------- /gst/rtsp-server/rtsp-server-prelude.h: -------------------------------------------------------------------------------- 1 | /* GStreamer RtspServer Library 2 | * Copyright (C) 2018 GStreamer developers 3 | * 4 | * rtspserver-prelude.h: prelude include header for gst-rtspserver library 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 19 | * Boston, MA 02110-1301, USA. 20 | */ 21 | 22 | #ifndef __GST_RTSP_SERVER_PRELUDE_H__ 23 | #define __GST_RTSP_SERVER_PRELUDE_H__ 24 | 25 | #include 26 | 27 | #ifndef GST_RTSP_SERVER_API 28 | # ifdef BUILDING_GST_RTSP_SERVER 29 | # define GST_RTSP_SERVER_API GST_API_EXPORT /* from config.h */ 30 | # else 31 | # define GST_RTSP_SERVER_API GST_API_IMPORT 32 | # endif 33 | #endif 34 | 35 | /* Do *not* use these defines outside of rtsp-server. Use G_DEPRECATED instead. */ 36 | #ifdef GST_DISABLE_DEPRECATED 37 | #define GST_RTSP_SERVER_DEPRECATED GST_RTSP_SERVER_API 38 | #define GST_RTSP_SERVER_DEPRECATED_FOR(f) GST_RTSP_SERVER_API 39 | #else 40 | #define GST_RTSP_SERVER_DEPRECATED G_DEPRECATED GST_RTSP_SERVER_API 41 | #define GST_RTSP_SERVER_DEPRECATED_FOR(f) G_DEPRECATED_FOR(f) GST_RTSP_SERVER_API 42 | #endif 43 | 44 | #endif /* __GST_RTSP_SERVER_PRELUDE_H__ */ 45 | -------------------------------------------------------------------------------- /gst/rtsp-server/rtsp-server.h: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef __GST_RTSP_SERVER_H__ 21 | #define __GST_RTSP_SERVER_H__ 22 | 23 | #include 24 | 25 | G_BEGIN_DECLS 26 | 27 | #include "rtsp-server-prelude.h" 28 | #include "rtsp-server-object.h" 29 | #include "rtsp-session-pool.h" 30 | #include "rtsp-session.h" 31 | #include "rtsp-media.h" 32 | #include "rtsp-stream.h" 33 | #include "rtsp-stream-transport.h" 34 | #include "rtsp-address-pool.h" 35 | #include "rtsp-thread-pool.h" 36 | #include "rtsp-client.h" 37 | #include "rtsp-context.h" 38 | #include "rtsp-server.h" 39 | #include "rtsp-mount-points.h" 40 | #include "rtsp-media-factory.h" 41 | #include "rtsp-permissions.h" 42 | #include "rtsp-auth.h" 43 | #include "rtsp-token.h" 44 | #include "rtsp-session-media.h" 45 | #include "rtsp-sdp.h" 46 | #include "rtsp-media-factory-uri.h" 47 | #include "rtsp-params.h" 48 | 49 | #include "rtsp-onvif-client.h" 50 | #include "rtsp-onvif-media-factory.h" 51 | #include "rtsp-onvif-media.h" 52 | #include "rtsp-onvif-server.h" 53 | 54 | G_END_DECLS 55 | 56 | #endif /* __GST_RTSP_SERVER_H__ */ 57 | -------------------------------------------------------------------------------- /tests/test-cleanup.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | 24 | static gboolean 25 | timeout (GMainLoop * loop) 26 | { 27 | g_main_loop_quit (loop); 28 | return FALSE; 29 | } 30 | 31 | 32 | int 33 | main (int argc, char *argv[]) 34 | { 35 | GMainLoop *loop; 36 | GstRTSPServer *server; 37 | guint id; 38 | 39 | gst_init (&argc, &argv); 40 | 41 | loop = g_main_loop_new (NULL, FALSE); 42 | 43 | /* create a server instance */ 44 | server = gst_rtsp_server_new (); 45 | 46 | /* We just want to bind any port here, so that tests can run in parallel */ 47 | gst_rtsp_server_set_service (server, "0"); 48 | 49 | /* attach the server to the default maincontext */ 50 | if ((id = gst_rtsp_server_attach (server, NULL)) == 0) 51 | goto failed; 52 | 53 | g_timeout_add_seconds (2, (GSourceFunc) timeout, loop); 54 | 55 | /* start serving */ 56 | g_main_loop_run (loop); 57 | 58 | /* cleanup */ 59 | g_source_remove (id); 60 | g_object_unref (server); 61 | g_main_loop_unref (loop); 62 | 63 | return 0; 64 | 65 | /* ERRORS */ 66 | failed: 67 | { 68 | g_print ("failed to attach the server\n"); 69 | return -1; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /tests/check/meson.build: -------------------------------------------------------------------------------- 1 | pluginsdirs = [] 2 | if gst_dep.type_name() == 'pkgconfig' 3 | pbase = dependency('gstreamer-plugins-base-' + api_version, required: true) 4 | pbad = dependency('gstreamer-plugins-bad-' + api_version, required: true) 5 | 6 | pluginsdirs = [gst_dep.get_pkgconfig_variable('pluginsdir'), 7 | pbase.get_pkgconfig_variable('pluginsdir'), 8 | pbad.get_pkgconfig_variable('pluginsdir')] 9 | 10 | gst_plugin_scanner_dir = gst_dep.get_pkgconfig_variable('pluginscannerdir') 11 | else 12 | gst_plugin_scanner_dir = subproject('gstreamer').get_variable('gst_scanner_dir') 13 | endif 14 | gst_plugin_scanner_path = join_paths(gst_plugin_scanner_dir, 'gst-plugin-scanner') 15 | 16 | test_c_args = [ 17 | '-UG_DISABLE_ASSERT', 18 | '-UG_DISABLE_CAST_CHECKS', 19 | '-DGST_CHECK_TEST_ENVIRONMENT_BEACON="GST_PLUGIN_LOADING_WHITELIST"', 20 | '-DGST_TEST_FILES_PATH="' + meson.current_source_dir() + '/../files"', 21 | ] 22 | 23 | rtsp_server_tests = [ 24 | 'gst/addresspool', 25 | 'gst/client', 26 | 'gst/mountpoints', 27 | 'gst/mediafactory', 28 | 'gst/media', 29 | 'gst/permissions', 30 | 'gst/rtspserver', 31 | 'gst/sessionmedia', 32 | 'gst/sessionpool', 33 | 'gst/stream', 34 | 'gst/threadpool', 35 | 'gst/token', 36 | 'gst/onvif', 37 | ] 38 | 39 | if not get_option('rtspclientsink').disabled() 40 | rtsp_server_tests += ['gst/rtspclientsink'] 41 | endif 42 | 43 | foreach test_name : rtsp_server_tests 44 | fname = '@0@.c'.format(test_name) 45 | test_name = test_name.underscorify() 46 | 47 | env = environment() 48 | env.set('GST_PLUGIN_SYSTEM_PATH_1_0', '') 49 | env.set('GST_STATE_IGNORE_ELEMENTS', '') 50 | env.set('GST_PLUGIN_LOADING_WHITELIST', 'gstreamer:gst-plugins-base:gst-plugins-good:gst-plugins-bad:gst-rtsp-server@' + meson.build_root()) 51 | env.set('CK_DEFAULT_TIMEOUT', '120') 52 | env.set('GST_REGISTRY', join_paths(meson.current_build_dir(), '@0@.registry'.format(test_name))) 53 | env.set('GST_PLUGIN_PATH_1_0', [meson.build_root()] + pluginsdirs) 54 | env.set('GST_PLUGIN_SCANNER_1_0', gst_plugin_scanner_path) 55 | 56 | exe = executable(test_name, fname, 57 | include_directories : rtspserver_incs, 58 | c_args : rtspserver_args + test_c_args, 59 | dependencies : [gstcheck_dep, gstrtsp_dep, gstrtp_dep, gst_rtsp_server_dep] 60 | ) 61 | test(test_name, exe, 62 | env : env, 63 | timeout : 120, 64 | is_parallel: false 65 | ) 66 | endforeach 67 | -------------------------------------------------------------------------------- /examples/test-readme.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | 24 | int 25 | main (int argc, char *argv[]) 26 | { 27 | GMainLoop *loop; 28 | GstRTSPServer *server; 29 | GstRTSPMountPoints *mounts; 30 | GstRTSPMediaFactory *factory; 31 | 32 | gst_init (&argc, &argv); 33 | 34 | loop = g_main_loop_new (NULL, FALSE); 35 | 36 | /* create a server instance */ 37 | server = gst_rtsp_server_new (); 38 | 39 | /* get the mount points for this server, every server has a default object 40 | * that be used to map uri mount points to media factories */ 41 | mounts = gst_rtsp_server_get_mount_points (server); 42 | 43 | /* make a media factory for a test stream. The default media factory can use 44 | * gst-launch syntax to create pipelines. 45 | * any launch line works as long as it contains elements named pay%d. Each 46 | * element with pay%d names will be a stream */ 47 | factory = gst_rtsp_media_factory_new (); 48 | gst_rtsp_media_factory_set_launch (factory, 49 | "( videotestsrc is-live=1 ! x264enc ! rtph264pay name=pay0 pt=96 )"); 50 | 51 | gst_rtsp_media_factory_set_shared (factory, TRUE); 52 | 53 | /* attach the test factory to the /test url */ 54 | gst_rtsp_mount_points_add_factory (mounts, "/test", factory); 55 | 56 | /* don't need the ref to the mapper anymore */ 57 | g_object_unref (mounts); 58 | 59 | /* attach the server to the default maincontext */ 60 | gst_rtsp_server_attach (server, NULL); 61 | 62 | /* start serving */ 63 | g_print ("stream ready at rtsp://127.0.0.1:8554/test\n"); 64 | g_main_loop_run (loop); 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /tests/test-reuse.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | 24 | #define TIMEOUT 2 25 | 26 | static gboolean timeout_1 (GMainLoop * loop); 27 | 28 | static guint id; 29 | static gint rounds = 3; 30 | static GstRTSPServer *server; 31 | 32 | static gboolean 33 | timeout_2 (GMainLoop * loop) 34 | { 35 | rounds--; 36 | if (rounds > 0) { 37 | id = gst_rtsp_server_attach (server, NULL); 38 | g_print ("have attached\n"); 39 | g_timeout_add_seconds (TIMEOUT, (GSourceFunc) timeout_1, loop); 40 | } else { 41 | g_main_loop_quit (loop); 42 | } 43 | return FALSE; 44 | } 45 | 46 | static gboolean 47 | timeout_1 (GMainLoop * loop) 48 | { 49 | g_source_remove (id); 50 | g_print ("have removed\n"); 51 | g_timeout_add_seconds (TIMEOUT, (GSourceFunc) timeout_2, loop); 52 | return FALSE; 53 | } 54 | 55 | int 56 | main (int argc, char *argv[]) 57 | { 58 | GMainLoop *loop; 59 | 60 | gst_init (&argc, &argv); 61 | 62 | loop = g_main_loop_new (NULL, FALSE); 63 | 64 | /* create a server instance */ 65 | server = gst_rtsp_server_new (); 66 | 67 | /* attach the server to the default maincontext */ 68 | if ((id = gst_rtsp_server_attach (server, NULL)) == 0) 69 | goto failed; 70 | g_print ("have attached\n"); 71 | 72 | g_timeout_add_seconds (TIMEOUT, (GSourceFunc) timeout_1, loop); 73 | 74 | /* start serving */ 75 | g_main_loop_run (loop); 76 | 77 | /* cleanup */ 78 | g_object_unref (server); 79 | g_main_loop_unref (loop); 80 | 81 | g_print ("quit\n"); 82 | return 0; 83 | 84 | /* ERRORS */ 85 | failed: 86 | { 87 | g_print ("failed to attach the server\n"); 88 | return -1; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /gst/rtsp-server/rtsp-params.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | /** 20 | * SECTION:rtsp-params 21 | * @short_description: Param get and set implementation 22 | * @see_also: #GstRTSPClient 23 | * 24 | * Last reviewed on 2013-07-11 (1.0.0) 25 | */ 26 | #ifdef HAVE_CONFIG_H 27 | #include "config.h" 28 | #endif 29 | 30 | #include 31 | 32 | #include "rtsp-params.h" 33 | 34 | /** 35 | * gst_rtsp_params_set: 36 | * @client: a #GstRTSPClient 37 | * @ctx: (transfer none): a #GstRTSPContext 38 | * 39 | * Set parameters (not implemented yet) 40 | * 41 | * Returns: a #GstRTSPResult 42 | */ 43 | GstRTSPResult 44 | gst_rtsp_params_set (GstRTSPClient * client, GstRTSPContext * ctx) 45 | { 46 | GstRTSPStatusCode code; 47 | 48 | /* FIXME, actually parse the request based on the mime type and try to repond 49 | * with a list of the parameters */ 50 | code = GST_RTSP_STS_PARAMETER_NOT_UNDERSTOOD; 51 | 52 | gst_rtsp_message_init_response (ctx->response, code, 53 | gst_rtsp_status_as_text (code), ctx->request); 54 | 55 | return GST_RTSP_OK; 56 | } 57 | 58 | /** 59 | * gst_rtsp_params_get: 60 | * @client: a #GstRTSPClient 61 | * @ctx: (transfer none): a #GstRTSPContext 62 | * 63 | * Get parameters (not implemented yet) 64 | * 65 | * Returns: a #GstRTSPResult 66 | */ 67 | GstRTSPResult 68 | gst_rtsp_params_get (GstRTSPClient * client, GstRTSPContext * ctx) 69 | { 70 | GstRTSPStatusCode code; 71 | 72 | /* FIXME, actually parse the request based on the mime type and try to repond 73 | * with a list of the parameters */ 74 | code = GST_RTSP_STS_PARAMETER_NOT_UNDERSTOOD; 75 | 76 | gst_rtsp_message_init_response (ctx->response, code, 77 | gst_rtsp_status_as_text (code), ctx->request); 78 | 79 | return GST_RTSP_OK; 80 | } 81 | -------------------------------------------------------------------------------- /gst/rtsp-server/rtsp-latency-bin.h: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2018 Ognyan Tonchev 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef __GST_RTSP_LATENCY_BIN_H__ 21 | #define __GST_RTSP_LATENCY_BIN_H__ 22 | 23 | #include 24 | #include "rtsp-server-prelude.h" 25 | 26 | G_BEGIN_DECLS 27 | 28 | typedef struct _GstRTSPLatencyBin GstRTSPLatencyBin; 29 | typedef struct _GstRTSPLatencyBinClass GstRTSPLatencyBinClass; 30 | typedef struct _GstRTSPLatencyBinPrivate GstRTSPLatencyBinPrivate; 31 | 32 | #define GST_RTSP_LATENCY_BIN_TYPE (gst_rtsp_latency_bin_get_type ()) 33 | #define IS_GST_RTSP_LATENCY_BIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_RTSP_LATENCY_BIN_TYPE)) 34 | #define IS_GST_RTSP_LATENCY_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_RTSP_LATENCY_BIN_TYPE)) 35 | #define GST_RTSP_LATENCY_BIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_RTSP_LATENCY_BIN_TYPE, GstRTSPLatencyBinClass)) 36 | #define GST_RTSP_LATENCY_BIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_RTSP_LATENCY_BIN_TYPE, GstRTSPLatencyBin)) 37 | #define GST_RTSP_LATENCY_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_RTSP_LATENCY_BIN_TYPE, GstRTSPLatencyBinClass)) 38 | #define GST_RTSP_LATENCY_BIN_CAST(obj) ((GstRTSPLatencyBin*)(obj)) 39 | #define GST_RTSP_LATENCY_BIN_CLASS_CAST(klass) ((GstRTSPLatencyBinClass*)(klass)) 40 | 41 | struct _GstRTSPLatencyBin { 42 | GstBin parent; 43 | 44 | GstRTSPLatencyBinPrivate *priv; 45 | }; 46 | 47 | struct _GstRTSPLatencyBinClass { 48 | GstBinClass parent_class; 49 | }; 50 | 51 | GST_RTSP_SERVER_API 52 | GType gst_rtsp_latency_bin_get_type (void); 53 | 54 | GST_RTSP_SERVER_API 55 | GstElement * gst_rtsp_latency_bin_new (GstElement * element); 56 | 57 | G_END_DECLS 58 | 59 | #endif /* __GST_RTSP_LATENCY_BIN_H__ */ 60 | -------------------------------------------------------------------------------- /gst/rtsp-server/rtsp-onvif-client.h: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2017 Sebastian Dröge 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef __GST_RTSP_ONVIF_CLIENT_H__ 21 | #define __GST_RTSP_ONVIF_CLIENT_H__ 22 | 23 | #include 24 | #include "rtsp-client.h" 25 | 26 | #define GST_TYPE_RTSP_ONVIF_CLIENT (gst_rtsp_onvif_client_get_type ()) 27 | #define GST_IS_RTSP_ONVIF_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_RTSP_ONVIF_CLIENT)) 28 | #define GST_IS_RTSP_ONVIF_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_RTSP_ONVIF_CLIENT)) 29 | #define GST_RTSP_ONVIF_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RTSP_ONVIF_CLIENT, GstRTSPOnvifClientClass)) 30 | #define GST_RTSP_ONVIF_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_RTSP_ONVIF_CLIENT, GstRTSPOnvifClient)) 31 | #define GST_RTSP_ONVIF_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_RTSP_ONVIF_CLIENT, GstRTSPOnvifClientClass)) 32 | #define GST_RTSP_ONVIF_CLIENT_CAST(obj) ((GstRTSPOnvifClient*)(obj)) 33 | #define GST_RTSP_ONVIF_CLIENT_CLASS_CAST(klass) ((GstRTSPOnvifClientClass*)(klass)) 34 | 35 | typedef struct GstRTSPOnvifClientClass GstRTSPOnvifClientClass; 36 | typedef struct GstRTSPOnvifClient GstRTSPOnvifClient; 37 | 38 | /** 39 | * GstRTSPOnvifClient: 40 | * 41 | * Since: 1.14 42 | */ 43 | struct GstRTSPOnvifClientClass 44 | { 45 | GstRTSPClientClass parent; 46 | 47 | /*< private >*/ 48 | gpointer _gst_reserved[GST_PADDING_LARGE]; 49 | }; 50 | 51 | struct GstRTSPOnvifClient 52 | { 53 | GstRTSPClient parent; 54 | 55 | /*< private >*/ 56 | gpointer _gst_reserved[GST_PADDING]; 57 | }; 58 | 59 | GST_RTSP_SERVER_API 60 | GType gst_rtsp_onvif_client_get_type (void); 61 | 62 | GST_RTSP_SERVER_API 63 | GstRTSPClient * gst_rtsp_onvif_client_new (void); 64 | 65 | #endif /* __GST_RTSP_ONVIF_CLIENT_H__ */ 66 | -------------------------------------------------------------------------------- /gst/rtsp-server/rtsp-context.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2013 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | /** 20 | * SECTION:rtsp-context 21 | * @short_description: A client request context 22 | * @see_also: #GstRTSPServer, #GstRTSPClient 23 | * 24 | * Last reviewed on 2013-07-11 (1.0.0) 25 | */ 26 | #ifdef HAVE_CONFIG_H 27 | #include "config.h" 28 | #endif 29 | 30 | #include "rtsp-context.h" 31 | 32 | G_DEFINE_POINTER_TYPE (GstRTSPContext, gst_rtsp_context); 33 | 34 | static GPrivate current_context; 35 | 36 | /** 37 | * gst_rtsp_context_get_current: (skip): 38 | * 39 | * Get the current #GstRTSPContext. This object is retrieved from the 40 | * current thread that is handling the request for a client. 41 | * 42 | * Returns: a #GstRTSPContext 43 | */ 44 | GstRTSPContext * 45 | gst_rtsp_context_get_current (void) 46 | { 47 | GSList *l; 48 | 49 | l = g_private_get (¤t_context); 50 | if (l == NULL) 51 | return NULL; 52 | 53 | return (GstRTSPContext *) (l->data); 54 | 55 | } 56 | 57 | /** 58 | * gst_rtsp_context_push_current: 59 | * @ctx: a #GstRTSPContext 60 | * 61 | * Pushes @ctx onto the context stack. The current 62 | * context can then be received using gst_rtsp_context_get_current(). 63 | **/ 64 | void 65 | gst_rtsp_context_push_current (GstRTSPContext * ctx) 66 | { 67 | GSList *l; 68 | 69 | g_return_if_fail (ctx != NULL); 70 | 71 | l = g_private_get (¤t_context); 72 | l = g_slist_prepend (l, ctx); 73 | g_private_set (¤t_context, l); 74 | } 75 | 76 | /** 77 | * gst_rtsp_context_pop_current: 78 | * @ctx: a #GstRTSPContext 79 | * 80 | * Pops @ctx off the context stack (verifying that @ctx 81 | * is on the top of the stack). 82 | **/ 83 | void 84 | gst_rtsp_context_pop_current (GstRTSPContext * ctx) 85 | { 86 | GSList *l; 87 | 88 | l = g_private_get (¤t_context); 89 | 90 | g_return_if_fail (l != NULL); 91 | g_return_if_fail (l->data == ctx); 92 | 93 | l = g_slist_delete_link (l, l); 94 | g_private_set (¤t_context, l); 95 | } 96 | -------------------------------------------------------------------------------- /gst/rtsp-server/rtsp-onvif-server.h: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2017 Sebastian Dröge 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef __GST_RTSP_ONVIF_SERVER_H__ 21 | #define __GST_RTSP_ONVIF_SERVER_H__ 22 | 23 | #include 24 | #include "rtsp-server-object.h" 25 | 26 | #define GST_TYPE_RTSP_ONVIF_SERVER (gst_rtsp_onvif_server_get_type ()) 27 | #define GST_IS_RTSP_ONVIF_SERVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_RTSP_ONVIF_SERVER)) 28 | #define GST_IS_RTSP_ONVIF_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_RTSP_ONVIF_SERVER)) 29 | #define GST_RTSP_ONVIF_SERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RTSP_ONVIF_SERVER, GstRTSPOnvifServerClass)) 30 | #define GST_RTSP_ONVIF_SERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_RTSP_ONVIF_SERVER, GstRTSPOnvifServer)) 31 | #define GST_RTSP_ONVIF_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_RTSP_ONVIF_SERVER, GstRTSPOnvifServerClass)) 32 | #define GST_RTSP_ONVIF_SERVER_CAST(obj) ((GstRTSPOnvifServer*)(obj)) 33 | #define GST_RTSP_ONVIF_SERVER_CLASS_CAST(klass) ((GstRTSPOnvifServerClass*)(klass)) 34 | 35 | typedef struct GstRTSPOnvifServerClass GstRTSPOnvifServerClass; 36 | typedef struct GstRTSPOnvifServer GstRTSPOnvifServer; 37 | 38 | /** 39 | * GstRTSPOnvifServer: 40 | * 41 | * Since: 1.14 42 | */ 43 | struct GstRTSPOnvifServerClass 44 | { 45 | GstRTSPServerClass parent; 46 | 47 | /*< private >*/ 48 | gpointer _gst_reserved[GST_PADDING_LARGE]; 49 | }; 50 | 51 | struct GstRTSPOnvifServer 52 | { 53 | GstRTSPServer parent; 54 | 55 | /*< private >*/ 56 | gpointer _gst_reserved[GST_PADDING]; 57 | }; 58 | 59 | GST_RTSP_SERVER_API 60 | GType gst_rtsp_onvif_server_get_type (void); 61 | GST_RTSP_SERVER_API 62 | GstRTSPServer *gst_rtsp_onvif_server_new (void); 63 | 64 | #define GST_RTSP_ONVIF_BACKCHANNEL_REQUIREMENT "www.onvif.org/ver20/backchannel" 65 | #define GST_RTSP_ONVIF_REPLAY_REQUIREMENT "onvif-replay" 66 | 67 | #include "rtsp-onvif-client.h" 68 | #include "rtsp-onvif-media-factory.h" 69 | #include "rtsp-onvif-media.h" 70 | 71 | #endif /* __GST_RTSP_ONVIF_SERVER_H__ */ 72 | -------------------------------------------------------------------------------- /examples/test-onvif-backchannel.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2017 Sebastian Dröge 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | int 26 | main (int argc, char *argv[]) 27 | { 28 | GMainLoop *loop; 29 | GstRTSPServer *server; 30 | GstRTSPMountPoints *mounts; 31 | GstRTSPMediaFactory *factory; 32 | 33 | gst_init (&argc, &argv); 34 | 35 | loop = g_main_loop_new (NULL, FALSE); 36 | 37 | /* create a server instance */ 38 | server = gst_rtsp_onvif_server_new (); 39 | 40 | /* get the mount points for this server, every server has a default object 41 | * that be used to map uri mount points to media factories */ 42 | mounts = gst_rtsp_server_get_mount_points (server); 43 | 44 | /* make a media factory for a test stream. The default media factory can use 45 | * gst-launch syntax to create pipelines. 46 | * any launch line works as long as it contains elements named pay%d. Each 47 | * element with pay%d names will be a stream */ 48 | factory = gst_rtsp_onvif_media_factory_new (); 49 | gst_rtsp_media_factory_set_launch (factory, 50 | "( videotestsrc is-live=true ! x264enc ! rtph264pay name=pay0 pt=96 audiotestsrc is-live=true ! mulawenc ! rtppcmupay name=pay1 )"); 51 | gst_rtsp_onvif_media_factory_set_backchannel_launch 52 | (GST_RTSP_ONVIF_MEDIA_FACTORY (factory), 53 | "( capsfilter caps=\"application/x-rtp, media=audio, payload=0, clock-rate=8000, encoding-name=PCMU\" name=depay_backchannel ! rtppcmudepay ! fakesink async=false )"); 54 | gst_rtsp_media_factory_set_shared (factory, FALSE); 55 | gst_rtsp_media_factory_set_media_gtype (factory, GST_TYPE_RTSP_ONVIF_MEDIA); 56 | 57 | /* attach the test factory to the /test url */ 58 | gst_rtsp_mount_points_add_factory (mounts, "/test", factory); 59 | 60 | /* don't need the ref to the mapper anymore */ 61 | g_object_unref (mounts); 62 | 63 | /* attach the server to the default maincontext */ 64 | gst_rtsp_server_attach (server, NULL); 65 | 66 | /* start serving */ 67 | g_print ("stream ready at rtsp://127.0.0.1:8554/test\n"); 68 | g_main_loop_run (loop); 69 | 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /gst/rtsp-server/rtsp-onvif-media.h: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2017 Sebastian Dröge 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef __GST_RTSP_ONVIF_MEDIA_H__ 21 | #define __GST_RTSP_ONVIF_MEDIA_H__ 22 | 23 | #include 24 | #include "rtsp-media.h" 25 | 26 | #define GST_TYPE_RTSP_ONVIF_MEDIA (gst_rtsp_onvif_media_get_type ()) 27 | #define GST_IS_RTSP_ONVIF_MEDIA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_RTSP_ONVIF_MEDIA)) 28 | #define GST_IS_RTSP_ONVIF_MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_RTSP_ONVIF_MEDIA)) 29 | #define GST_RTSP_ONVIF_MEDIA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RTSP_ONVIF_MEDIA, GstRTSPOnvifMediaClass)) 30 | #define GST_RTSP_ONVIF_MEDIA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_RTSP_ONVIF_MEDIA, GstRTSPOnvifMedia)) 31 | #define GST_RTSP_ONVIF_MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_RTSP_ONVIF_MEDIA, GstRTSPOnvifMediaClass)) 32 | #define GST_RTSP_ONVIF_MEDIA_CAST(obj) ((GstRTSPOnvifMedia*)(obj)) 33 | #define GST_RTSP_ONVIF_MEDIA_CLASS_CAST(klass) ((GstRTSPOnvifMediaClass*)(klass)) 34 | 35 | typedef struct GstRTSPOnvifMediaClass GstRTSPOnvifMediaClass; 36 | typedef struct GstRTSPOnvifMedia GstRTSPOnvifMedia; 37 | typedef struct GstRTSPOnvifMediaPrivate GstRTSPOnvifMediaPrivate; 38 | 39 | /** 40 | * GstRTSPOnvifMedia: 41 | * 42 | * Since: 1.14 43 | */ 44 | struct GstRTSPOnvifMediaClass 45 | { 46 | GstRTSPMediaClass parent; 47 | 48 | /*< private >*/ 49 | gpointer _gst_reserved[GST_PADDING_LARGE]; 50 | }; 51 | 52 | struct GstRTSPOnvifMedia 53 | { 54 | GstRTSPMedia parent; 55 | GstRTSPOnvifMediaPrivate *priv; 56 | 57 | /*< private >*/ 58 | gpointer _gst_reserved[GST_PADDING]; 59 | }; 60 | 61 | GST_RTSP_SERVER_API 62 | GType gst_rtsp_onvif_media_get_type (void); 63 | GST_RTSP_SERVER_API 64 | gboolean gst_rtsp_onvif_media_collect_backchannel (GstRTSPOnvifMedia * media); 65 | 66 | GST_RTSP_SERVER_API 67 | void gst_rtsp_onvif_media_set_backchannel_bandwidth (GstRTSPOnvifMedia * media, guint bandwidth); 68 | GST_RTSP_SERVER_API 69 | guint gst_rtsp_onvif_media_get_backchannel_bandwidth (GstRTSPOnvifMedia * media); 70 | 71 | #endif /* __GST_RTSP_ONVIF_MEDIA_H__ */ 72 | -------------------------------------------------------------------------------- /examples/test-sdp.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2009 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | 24 | 25 | static gboolean 26 | timeout (GstRTSPServer * server) 27 | { 28 | GstRTSPSessionPool *pool; 29 | 30 | pool = gst_rtsp_server_get_session_pool (server); 31 | gst_rtsp_session_pool_cleanup (pool); 32 | g_object_unref (pool); 33 | 34 | return TRUE; 35 | } 36 | 37 | static void 38 | media_configure (GstRTSPMediaFactory * factory, GstRTSPMedia * media) 39 | { 40 | gst_rtsp_media_set_reusable (media, TRUE); 41 | } 42 | 43 | int 44 | main (int argc, char *argv[]) 45 | { 46 | GMainLoop *loop; 47 | GstRTSPServer *server; 48 | GstRTSPMountPoints *mounts; 49 | GstRTSPMediaFactory *factory; 50 | gchar *str; 51 | 52 | gst_init (&argc, &argv); 53 | 54 | if (argc < 2) { 55 | g_message ("usage: %s ", argv[0]); 56 | return -1; 57 | } 58 | 59 | loop = g_main_loop_new (NULL, FALSE); 60 | 61 | /* create a server instance */ 62 | server = gst_rtsp_server_new (); 63 | 64 | /* get the mount points for this server, every server has a default object 65 | * that be used to map uri mount points to media factories */ 66 | mounts = gst_rtsp_server_get_mount_points (server); 67 | 68 | /* make a media factory for a test stream. The default media factory can use 69 | * gst-launch syntax to create pipelines. 70 | * any launch line works as long as it contains elements named pay%d. Each 71 | * element with pay%d names will be a stream */ 72 | factory = gst_rtsp_media_factory_new (); 73 | 74 | str = 75 | g_strdup_printf ("( filesrc location=%s ! sdpdemux name=dynpay0 )", 76 | argv[1]); 77 | gst_rtsp_media_factory_set_launch (factory, str); 78 | gst_rtsp_media_factory_set_shared (factory, TRUE); 79 | g_signal_connect (factory, "media-configure", (GCallback) media_configure, 80 | NULL); 81 | g_free (str); 82 | 83 | /* attach the test factory to the /test url */ 84 | gst_rtsp_mount_points_add_factory (mounts, "/test", factory); 85 | 86 | /* don't need the ref to the mapper anymore */ 87 | g_object_unref (mounts); 88 | 89 | /* attach the server to the default maincontext */ 90 | gst_rtsp_server_attach (server, NULL); 91 | 92 | g_timeout_add_seconds (2, (GSourceFunc) timeout, server); 93 | 94 | /* start serving */ 95 | g_main_loop_run (loop); 96 | 97 | return 0; 98 | } 99 | -------------------------------------------------------------------------------- /hooks/pre-commit.hook: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Check that the code follows a consistent code style 4 | # 5 | 6 | # Check for existence of indent, and error out if not present. 7 | # On some *bsd systems the binary seems to be called gnunindent, 8 | # so check for that first. 9 | 10 | version=`gnuindent --version 2>/dev/null` 11 | if test "x$version" = "x"; then 12 | version=`gindent --version 2>/dev/null` 13 | if test "x$version" = "x"; then 14 | version=`indent --version 2>/dev/null` 15 | if test "x$version" = "x"; then 16 | echo "GStreamer git pre-commit hook:" 17 | echo "Did not find GNU indent, please install it before continuing." 18 | exit 1 19 | else 20 | INDENT=indent 21 | fi 22 | else 23 | INDENT=gindent 24 | fi 25 | else 26 | INDENT=gnuindent 27 | fi 28 | 29 | case `$INDENT --version` in 30 | GNU*) 31 | ;; 32 | default) 33 | echo "GStreamer git pre-commit hook:" 34 | echo "Did not find GNU indent, please install it before continuing." 35 | echo "(Found $INDENT, but it doesn't seem to be GNU indent)" 36 | exit 1 37 | ;; 38 | esac 39 | 40 | INDENT_PARAMETERS="--braces-on-if-line \ 41 | --case-brace-indentation0 \ 42 | --case-indentation2 \ 43 | --braces-after-struct-decl-line \ 44 | --line-length80 \ 45 | --no-tabs \ 46 | --cuddle-else \ 47 | --dont-line-up-parentheses \ 48 | --continuation-indentation4 \ 49 | --honour-newlines \ 50 | --tab-size8 \ 51 | --indent-level2 \ 52 | --leave-preprocessor-space" 53 | 54 | echo "--Checking style--" 55 | for file in `git diff-index --cached --name-only HEAD --diff-filter=ACMR| grep "\.c$"` ; do 56 | # nf is the temporary checkout. This makes sure we check against the 57 | # revision in the index (and not the checked out version). 58 | nf=`git checkout-index --temp ${file} | cut -f 1` 59 | newfile=`mktemp /tmp/${nf}.XXXXXX` || exit 1 60 | $INDENT ${INDENT_PARAMETERS} \ 61 | $nf -o $newfile 2>> /dev/null 62 | # FIXME: Call indent twice as it tends to do line-breaks 63 | # different for every second call. 64 | $INDENT ${INDENT_PARAMETERS} \ 65 | $newfile 2>> /dev/null 66 | diff -u -p "${nf}" "${newfile}" 67 | r=$? 68 | rm "${newfile}" 69 | rm "${nf}" 70 | if [ $r != 0 ] ; then 71 | echo "=================================================================================================" 72 | echo " Code style error in: $file " 73 | echo " " 74 | echo " Please fix before committing. Don't forget to run git add before trying to commit again. " 75 | echo " If the whole file is to be committed, this should work (run from the top-level directory): " 76 | echo " " 77 | echo " gst-indent $file; git add $file; git commit" 78 | echo " " 79 | echo "=================================================================================================" 80 | exit 1 81 | fi 82 | done 83 | echo "--Checking style pass--" 84 | -------------------------------------------------------------------------------- /gst/rtsp-server/meson.build: -------------------------------------------------------------------------------- 1 | rtsp_server_sources = [ 2 | 'rtsp-address-pool.c', 3 | 'rtsp-auth.c', 4 | 'rtsp-client.c', 5 | 'rtsp-context.c', 6 | 'rtsp-latency-bin.c', 7 | 'rtsp-media.c', 8 | 'rtsp-media-factory.c', 9 | 'rtsp-media-factory-uri.c', 10 | 'rtsp-mount-points.c', 11 | 'rtsp-params.c', 12 | 'rtsp-permissions.c', 13 | 'rtsp-sdp.c', 14 | 'rtsp-server.c', 15 | 'rtsp-session.c', 16 | 'rtsp-session-media.c', 17 | 'rtsp-session-pool.c', 18 | 'rtsp-stream.c', 19 | 'rtsp-stream-transport.c', 20 | 'rtsp-thread-pool.c', 21 | 'rtsp-token.c', 22 | 'rtsp-onvif-server.c', 23 | 'rtsp-onvif-client.c', 24 | 'rtsp-onvif-media-factory.c', 25 | 'rtsp-onvif-media.c', 26 | ] 27 | 28 | rtsp_server_headers = [ 29 | 'rtsp-auth.h', 30 | 'rtsp-address-pool.h', 31 | 'rtsp-context.h', 32 | 'rtsp-params.h', 33 | 'rtsp-sdp.h', 34 | 'rtsp-thread-pool.h', 35 | 'rtsp-media.h', 36 | 'rtsp-media-factory.h', 37 | 'rtsp-media-factory-uri.h', 38 | 'rtsp-mount-points.h', 39 | 'rtsp-permissions.h', 40 | 'rtsp-stream.h', 41 | 'rtsp-stream-transport.h', 42 | 'rtsp-session.h', 43 | 'rtsp-session-media.h', 44 | 'rtsp-session-pool.h', 45 | 'rtsp-token.h', 46 | 'rtsp-client.h', 47 | 'rtsp-server.h', 48 | 'rtsp-server-object.h', 49 | 'rtsp-server-prelude.h', 50 | 'rtsp-onvif-server.h', 51 | 'rtsp-onvif-client.h', 52 | 'rtsp-onvif-media-factory.h', 53 | 'rtsp-onvif-media.h', 54 | ] 55 | 56 | install_headers(rtsp_server_headers, subdir : 'gstreamer-1.0/gst/rtsp-server') 57 | 58 | gst_rtsp_server_deps = [gstrtsp_dep, gstrtp_dep, gstsdp_dep, gstnet_dep, gstapp_dep] 59 | gst_rtsp_server = library('gstrtspserver-@0@'.format(api_version), 60 | rtsp_server_sources, 61 | include_directories : rtspserver_incs, 62 | c_args: rtspserver_args + ['-DBUILDING_GST_RTSP_SERVER'], 63 | version : libversion, 64 | soversion : soversion, 65 | darwin_versions : osxversion, 66 | install : true, 67 | dependencies : gst_rtsp_server_deps) 68 | 69 | pkgconfig.generate(gst_rtsp_server, 70 | libraries : [gst_dep], 71 | subdirs : pkgconfig_subdirs, 72 | name : 'gstreamer-rtsp-server-1.0', 73 | description : 'GStreamer based RTSP server', 74 | ) 75 | 76 | rtsp_server_gen_sources = [] 77 | if build_gir 78 | gst_gir_extra_args = gir_init_section + ['--c-include=gst/rtsp-server/rtsp-server.h'] 79 | rtsp_server_gir = gnome.generate_gir(gst_rtsp_server, 80 | sources : rtsp_server_headers + rtsp_server_sources, 81 | namespace : 'GstRtspServer', 82 | nsversion : api_version, 83 | identifier_prefix : 'Gst', 84 | symbol_prefix : 'gst', 85 | export_packages : 'gstreamer-rtsp-server-' + api_version, 86 | install : true, 87 | extra_args : gst_gir_extra_args, 88 | includes : ['Gst-1.0', 'GstRtsp-1.0', 'GstNet-1.0'], 89 | dependencies : gst_rtsp_server_deps, 90 | ) 91 | rtsp_server_gen_sources += [rtsp_server_gir] 92 | endif 93 | 94 | gst_rtsp_server_dep = declare_dependency(link_with : gst_rtsp_server, 95 | include_directories : rtspserver_incs, 96 | sources : rtsp_server_gen_sources, 97 | dependencies : [gstrtsp_dep, gstrtp_dep, gstsdp_dep, gstnet_dep, gstapp_dep]) 98 | 99 | meson.override_dependency('gstreamer-rtsp-server-1.0', gst_rtsp_server_dep) 100 | -------------------------------------------------------------------------------- /gst/rtsp-server/rtsp-context.h: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #ifndef __GST_RTSP_CONTEXT_H__ 24 | #define __GST_RTSP_CONTEXT_H__ 25 | 26 | G_BEGIN_DECLS 27 | 28 | #define GST_TYPE_RTSP_CONTEXT (gst_rtsp_context_get_type ()) 29 | 30 | typedef struct _GstRTSPContext GstRTSPContext; 31 | 32 | #include "rtsp-server-prelude.h" 33 | #include "rtsp-server-object.h" 34 | #include "rtsp-media.h" 35 | #include "rtsp-media-factory.h" 36 | #include "rtsp-session-media.h" 37 | #include "rtsp-auth.h" 38 | #include "rtsp-thread-pool.h" 39 | #include "rtsp-token.h" 40 | 41 | /** 42 | * GstRTSPContext: 43 | * @server: the server 44 | * @conn: the connection 45 | * @client: the client 46 | * @request: the complete request 47 | * @uri: the complete url parsed from @request 48 | * @method: the parsed method of @uri 49 | * @auth: the current auth object or %NULL 50 | * @token: authorisation token 51 | * @session: the session, can be %NULL 52 | * @sessmedia: the session media for the url can be %NULL 53 | * @factory: the media factory for the url, can be %NULL 54 | * @media: the media for the url can be %NULL 55 | * @stream: the stream for the url can be %NULL 56 | * @response: the response 57 | * @trans: the stream transport, can be %NULL 58 | * 59 | * Information passed around containing the context of a request. 60 | */ 61 | struct _GstRTSPContext { 62 | GstRTSPServer *server; 63 | GstRTSPConnection *conn; 64 | GstRTSPClient *client; 65 | GstRTSPMessage *request; 66 | GstRTSPUrl *uri; 67 | GstRTSPMethod method; 68 | GstRTSPAuth *auth; 69 | GstRTSPToken *token; 70 | GstRTSPSession *session; 71 | GstRTSPSessionMedia *sessmedia; 72 | GstRTSPMediaFactory *factory; 73 | GstRTSPMedia *media; 74 | GstRTSPStream *stream; 75 | GstRTSPMessage *response; 76 | GstRTSPStreamTransport *trans; 77 | 78 | /*< private >*/ 79 | gpointer _gst_reserved[GST_PADDING - 1]; 80 | }; 81 | 82 | GST_RTSP_SERVER_API 83 | GType gst_rtsp_context_get_type (void); 84 | 85 | GST_RTSP_SERVER_API 86 | GstRTSPContext * gst_rtsp_context_get_current (void); 87 | 88 | GST_RTSP_SERVER_API 89 | void gst_rtsp_context_push_current (GstRTSPContext * ctx); 90 | 91 | GST_RTSP_SERVER_API 92 | void gst_rtsp_context_pop_current (GstRTSPContext * ctx); 93 | 94 | 95 | G_END_DECLS 96 | 97 | #endif /* __GST_RTSP_CONTEXT_H__ */ 98 | -------------------------------------------------------------------------------- /gst/rtsp-server/rtsp-server-internal.h: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2019 Mathieu Duponchelle 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef __GST_RTSP_SERVER_INTERNAL_H__ 21 | #define __GST_RTSP_SERVER_INTERNAL_H__ 22 | 23 | #include 24 | 25 | G_BEGIN_DECLS 26 | 27 | #include "rtsp-stream-transport.h" 28 | 29 | /* Internal GstRTSPStreamTransport interface */ 30 | 31 | typedef gboolean (*GstRTSPBackPressureFunc) (guint8 channel, gpointer user_data); 32 | 33 | gboolean gst_rtsp_stream_transport_backlog_push (GstRTSPStreamTransport *trans, 34 | GstBuffer *buffer, 35 | GstBufferList *buffer_list, 36 | gboolean is_rtp); 37 | 38 | gboolean gst_rtsp_stream_transport_backlog_pop (GstRTSPStreamTransport *trans, 39 | GstBuffer **buffer, 40 | GstBufferList **buffer_list, 41 | gboolean *is_rtp); 42 | 43 | gboolean gst_rtsp_stream_transport_backlog_is_empty (GstRTSPStreamTransport *trans); 44 | 45 | void gst_rtsp_stream_transport_clear_backlog (GstRTSPStreamTransport * trans); 46 | 47 | void gst_rtsp_stream_transport_lock_backlog (GstRTSPStreamTransport * trans); 48 | 49 | void gst_rtsp_stream_transport_unlock_backlog (GstRTSPStreamTransport * trans); 50 | 51 | void gst_rtsp_stream_transport_set_back_pressure_callback (GstRTSPStreamTransport *trans, 52 | GstRTSPBackPressureFunc back_pressure_func, 53 | gpointer user_data, 54 | GDestroyNotify notify); 55 | 56 | gboolean gst_rtsp_stream_transport_check_back_pressure (GstRTSPStreamTransport *trans, 57 | gboolean is_rtp); 58 | 59 | gboolean gst_rtsp_stream_is_tcp_receiver (GstRTSPStream * stream); 60 | 61 | void gst_rtsp_media_set_enable_rtcp (GstRTSPMedia *media, gboolean enable); 62 | void gst_rtsp_stream_set_enable_rtcp (GstRTSPStream *stream, gboolean enable); 63 | 64 | G_END_DECLS 65 | 66 | #endif /* __GST_RTSP_SERVER_INTERNAL_H__ */ 67 | -------------------------------------------------------------------------------- /examples/test-ogg.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | 24 | #define DEFAULT_RTSP_PORT "8554" 25 | 26 | static char *port = (char *) DEFAULT_RTSP_PORT; 27 | 28 | static GOptionEntry entries[] = { 29 | {"port", 'p', 0, G_OPTION_ARG_STRING, &port, 30 | "Port to listen on (default: " DEFAULT_RTSP_PORT ")", "PORT"}, 31 | {NULL} 32 | }; 33 | 34 | int 35 | main (int argc, char *argv[]) 36 | { 37 | GMainLoop *loop; 38 | GstRTSPServer *server; 39 | GstRTSPMountPoints *mounts; 40 | GstRTSPMediaFactory *factory; 41 | GOptionContext *optctx; 42 | GError *error = NULL; 43 | gchar *str; 44 | 45 | optctx = g_option_context_new (" - Test RTSP Server, OGG"); 46 | g_option_context_add_main_entries (optctx, entries, NULL); 47 | g_option_context_add_group (optctx, gst_init_get_option_group ()); 48 | if (!g_option_context_parse (optctx, &argc, &argv, &error)) { 49 | g_printerr ("Error parsing options: %s\n", error->message); 50 | g_option_context_free (optctx); 51 | g_clear_error (&error); 52 | return -1; 53 | } 54 | g_option_context_free (optctx); 55 | 56 | loop = g_main_loop_new (NULL, FALSE); 57 | 58 | /* create a server instance */ 59 | server = gst_rtsp_server_new (); 60 | g_object_set (server, "service", port, NULL); 61 | 62 | /* get the mount points for this server, every server has a default object 63 | * that be used to map uri mount points to media factories */ 64 | mounts = gst_rtsp_server_get_mount_points (server); 65 | 66 | str = g_strdup_printf ("( " 67 | "filesrc location=%s ! oggdemux name=d " 68 | "d. ! queue ! rtptheorapay name=pay0 pt=96 " 69 | "d. ! queue ! rtpvorbispay name=pay1 pt=97 " ")", argv[1]); 70 | 71 | /* make a media factory for a test stream. The default media factory can use 72 | * gst-launch syntax to create pipelines. 73 | * any launch line works as long as it contains elements named pay%d. Each 74 | * element with pay%d names will be a stream */ 75 | factory = gst_rtsp_media_factory_new (); 76 | gst_rtsp_media_factory_set_launch (factory, str); 77 | g_free (str); 78 | 79 | /* attach the test factory to the /test url */ 80 | gst_rtsp_mount_points_add_factory (mounts, "/test", factory); 81 | 82 | /* don't need the ref to the mapper anymore */ 83 | g_object_unref (mounts); 84 | 85 | /* attach the server to the default maincontext */ 86 | gst_rtsp_server_attach (server, NULL); 87 | 88 | /* start serving */ 89 | g_print ("stream ready at rtsp://127.0.0.1:%s/test\n", port); 90 | g_main_loop_run (loop); 91 | 92 | return 0; 93 | } 94 | -------------------------------------------------------------------------------- /examples/test-launch.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | 24 | #define DEFAULT_RTSP_PORT "8554" 25 | #define DEFAULT_DISABLE_RTCP FALSE 26 | 27 | static char *port = (char *) DEFAULT_RTSP_PORT; 28 | static gboolean disable_rtcp = DEFAULT_DISABLE_RTCP; 29 | 30 | static GOptionEntry entries[] = { 31 | {"port", 'p', 0, G_OPTION_ARG_STRING, &port, 32 | "Port to listen on (default: " DEFAULT_RTSP_PORT ")", "PORT"}, 33 | {"disable-rtcp", '\0', 0, G_OPTION_ARG_NONE, &disable_rtcp, 34 | "Whether RTCP should be disabled (default false)", NULL}, 35 | {NULL} 36 | }; 37 | 38 | int 39 | main (int argc, char *argv[]) 40 | { 41 | GMainLoop *loop; 42 | GstRTSPServer *server; 43 | GstRTSPMountPoints *mounts; 44 | GstRTSPMediaFactory *factory; 45 | GOptionContext *optctx; 46 | GError *error = NULL; 47 | 48 | optctx = g_option_context_new (" - Test RTSP Server, Launch\n\n" 49 | "Example: \"( videotestsrc ! x264enc ! rtph264pay name=pay0 pt=96 )\""); 50 | g_option_context_add_main_entries (optctx, entries, NULL); 51 | g_option_context_add_group (optctx, gst_init_get_option_group ()); 52 | if (!g_option_context_parse (optctx, &argc, &argv, &error)) { 53 | g_printerr ("Error parsing options: %s\n", error->message); 54 | g_option_context_free (optctx); 55 | g_clear_error (&error); 56 | return -1; 57 | } 58 | g_option_context_free (optctx); 59 | 60 | loop = g_main_loop_new (NULL, FALSE); 61 | 62 | /* create a server instance */ 63 | server = gst_rtsp_server_new (); 64 | g_object_set (server, "service", port, NULL); 65 | 66 | /* get the mount points for this server, every server has a default object 67 | * that be used to map uri mount points to media factories */ 68 | mounts = gst_rtsp_server_get_mount_points (server); 69 | 70 | /* make a media factory for a test stream. The default media factory can use 71 | * gst-launch syntax to create pipelines. 72 | * any launch line works as long as it contains elements named pay%d. Each 73 | * element with pay%d names will be a stream */ 74 | factory = gst_rtsp_media_factory_new (); 75 | gst_rtsp_media_factory_set_launch (factory, argv[1]); 76 | gst_rtsp_media_factory_set_shared (factory, TRUE); 77 | gst_rtsp_media_factory_set_enable_rtcp (factory, !disable_rtcp); 78 | 79 | /* attach the test factory to the /test url */ 80 | gst_rtsp_mount_points_add_factory (mounts, "/test", factory); 81 | 82 | /* don't need the ref to the mapper anymore */ 83 | g_object_unref (mounts); 84 | 85 | /* attach the server to the default maincontext */ 86 | gst_rtsp_server_attach (server, NULL); 87 | 88 | /* start serving */ 89 | g_print ("stream ready at rtsp://127.0.0.1:%s/test\n", port); 90 | g_main_loop_run (loop); 91 | 92 | return 0; 93 | } 94 | -------------------------------------------------------------------------------- /examples/test-video-rtx.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | 24 | /* this timeout is periodically run to clean up the expired sessions from the 25 | * pool. This needs to be run explicitly currently but might be done 26 | * automatically as part of the mainloop. */ 27 | static gboolean 28 | timeout (GstRTSPServer * server) 29 | { 30 | GstRTSPSessionPool *pool; 31 | 32 | pool = gst_rtsp_server_get_session_pool (server); 33 | gst_rtsp_session_pool_cleanup (pool); 34 | g_object_unref (pool); 35 | 36 | return TRUE; 37 | } 38 | 39 | int 40 | main (int argc, char *argv[]) 41 | { 42 | GMainLoop *loop; 43 | GstRTSPServer *server; 44 | GstRTSPMountPoints *mounts; 45 | GstRTSPMediaFactory *factory; 46 | 47 | gst_init (&argc, &argv); 48 | 49 | loop = g_main_loop_new (NULL, FALSE); 50 | 51 | /* create a server instance */ 52 | server = gst_rtsp_server_new (); 53 | 54 | /* get the mount points for this server, every server has a default object 55 | * that be used to map uri mount points to media factories */ 56 | mounts = gst_rtsp_server_get_mount_points (server); 57 | 58 | /* make a media factory for a test stream. The default media factory can use 59 | * gst-launch syntax to create pipelines. 60 | * any launch line works as long as it contains elements named pay%d. Each 61 | * element with pay%d names will be a stream */ 62 | factory = gst_rtsp_media_factory_new (); 63 | gst_rtsp_media_factory_set_launch (factory, "( " 64 | "videotestsrc ! video/x-raw,width=352,height=288,framerate=15/1 ! " 65 | "x264enc ! rtph264pay name=pay0 pt=96 " 66 | "audiotestsrc ! audio/x-raw,rate=8000 ! " 67 | "alawenc ! rtppcmapay name=pay1 pt=8 " ")"); 68 | 69 | gst_rtsp_media_factory_set_profiles (factory, GST_RTSP_PROFILE_AVPF); 70 | 71 | /* store up to 0.4 seconds of retransmission data */ 72 | gst_rtsp_media_factory_set_retransmission_time (factory, 400 * GST_MSECOND); 73 | 74 | /* attach the test factory to the /test url */ 75 | gst_rtsp_mount_points_add_factory (mounts, "/test", factory); 76 | 77 | /* don't need the ref to the mapper anymore */ 78 | g_object_unref (mounts); 79 | 80 | /* attach the server to the default maincontext */ 81 | if (gst_rtsp_server_attach (server, NULL) == 0) 82 | goto failed; 83 | 84 | /* add a timeout for the session cleanup */ 85 | g_timeout_add_seconds (2, (GSourceFunc) timeout, server); 86 | 87 | /* start serving, this never stops */ 88 | g_print ("stream ready at rtsp://127.0.0.1:8554/test\n"); 89 | 90 | g_main_loop_run (loop); 91 | 92 | return 0; 93 | 94 | /* ERRORS */ 95 | failed: 96 | { 97 | g_print ("failed to attach the server\n"); 98 | return -1; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /examples/test-multicast.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | 24 | 25 | static gboolean 26 | timeout (GstRTSPServer * server) 27 | { 28 | GstRTSPSessionPool *pool; 29 | 30 | pool = gst_rtsp_server_get_session_pool (server); 31 | gst_rtsp_session_pool_cleanup (pool); 32 | g_object_unref (pool); 33 | 34 | return TRUE; 35 | } 36 | 37 | int 38 | main (int argc, char *argv[]) 39 | { 40 | GMainLoop *loop; 41 | GstRTSPServer *server; 42 | GstRTSPMountPoints *mounts; 43 | GstRTSPMediaFactory *factory; 44 | GstRTSPAddressPool *pool; 45 | 46 | gst_init (&argc, &argv); 47 | 48 | loop = g_main_loop_new (NULL, FALSE); 49 | 50 | /* create a server instance */ 51 | server = gst_rtsp_server_new (); 52 | 53 | /* get the mount points for this server, every server has a default object 54 | * that be used to map uri mount points to media factories */ 55 | mounts = gst_rtsp_server_get_mount_points (server); 56 | 57 | /* make a media factory for a test stream. The default media factory can use 58 | * gst-launch syntax to create pipelines. 59 | * any launch line works as long as it contains elements named pay%d. Each 60 | * element with pay%d names will be a stream */ 61 | factory = gst_rtsp_media_factory_new (); 62 | gst_rtsp_media_factory_set_launch (factory, "( " 63 | "videotestsrc ! video/x-raw,width=352,height=288,framerate=15/1 ! " 64 | "x264enc ! rtph264pay name=pay0 pt=96 " 65 | "audiotestsrc ! audio/x-raw,rate=8000 ! " 66 | "alawenc ! rtppcmapay name=pay1 pt=97 " ")"); 67 | 68 | gst_rtsp_media_factory_set_shared (factory, TRUE); 69 | 70 | /* make a new address pool */ 71 | pool = gst_rtsp_address_pool_new (); 72 | gst_rtsp_address_pool_add_range (pool, 73 | "224.3.0.0", "224.3.0.10", 5000, 5010, 16); 74 | gst_rtsp_media_factory_set_address_pool (factory, pool); 75 | /* only allow multicast */ 76 | gst_rtsp_media_factory_set_protocols (factory, 77 | GST_RTSP_LOWER_TRANS_UDP_MCAST); 78 | g_object_unref (pool); 79 | 80 | /* attach the test factory to the /test url */ 81 | gst_rtsp_mount_points_add_factory (mounts, "/test", factory); 82 | 83 | /* don't need the ref to the mapper anymore */ 84 | g_object_unref (mounts); 85 | 86 | /* attach the server to the default maincontext */ 87 | if (gst_rtsp_server_attach (server, NULL) == 0) 88 | goto failed; 89 | 90 | g_timeout_add_seconds (2, (GSourceFunc) timeout, server); 91 | 92 | /* start serving */ 93 | g_print ("stream ready at rtsp://127.0.0.1:8554/test\n"); 94 | g_main_loop_run (loop); 95 | 96 | return 0; 97 | 98 | /* ERRORS */ 99 | failed: 100 | { 101 | g_print ("failed to attach the server\n"); 102 | return -1; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /gst/rtsp-server/rtsp-media-factory-uri.h: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #include "rtsp-media-factory.h" 23 | 24 | #ifndef __GST_RTSP_MEDIA_FACTORY_URI_H__ 25 | #define __GST_RTSP_MEDIA_FACTORY_URI_H__ 26 | 27 | G_BEGIN_DECLS 28 | 29 | /* types for the media factory */ 30 | #define GST_TYPE_RTSP_MEDIA_FACTORY_URI (gst_rtsp_media_factory_uri_get_type ()) 31 | #define GST_IS_RTSP_MEDIA_FACTORY_URI(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_RTSP_MEDIA_FACTORY_URI)) 32 | #define GST_IS_RTSP_MEDIA_FACTORY_URI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_RTSP_MEDIA_FACTORY_URI)) 33 | #define GST_RTSP_MEDIA_FACTORY_URI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RTSP_MEDIA_FACTORY_URI, GstRTSPMediaFactoryURIClass)) 34 | #define GST_RTSP_MEDIA_FACTORY_URI(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_RTSP_MEDIA_FACTORY_URI, GstRTSPMediaFactoryURI)) 35 | #define GST_RTSP_MEDIA_FACTORY_URI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_RTSP_MEDIA_FACTORY_URI, GstRTSPMediaFactoryURIClass)) 36 | #define GST_RTSP_MEDIA_FACTORY_URI_CAST(obj) ((GstRTSPMediaFactoryURI*)(obj)) 37 | #define GST_RTSP_MEDIA_FACTORY_URI_CLASS_CAST(klass) ((GstRTSPMediaFactoryURIClass*)(klass)) 38 | 39 | typedef struct _GstRTSPMediaFactoryURI GstRTSPMediaFactoryURI; 40 | typedef struct _GstRTSPMediaFactoryURIClass GstRTSPMediaFactoryURIClass; 41 | typedef struct _GstRTSPMediaFactoryURIPrivate GstRTSPMediaFactoryURIPrivate; 42 | 43 | /** 44 | * GstRTSPMediaFactoryURI: 45 | * 46 | * A media factory that creates a pipeline to play any uri. 47 | */ 48 | struct _GstRTSPMediaFactoryURI { 49 | GstRTSPMediaFactory parent; 50 | 51 | /*< private >*/ 52 | GstRTSPMediaFactoryURIPrivate *priv; 53 | gpointer _gst_reserved[GST_PADDING]; 54 | }; 55 | 56 | /** 57 | * GstRTSPMediaFactoryURIClass: 58 | * 59 | * The #GstRTSPMediaFactoryURI class structure. 60 | */ 61 | struct _GstRTSPMediaFactoryURIClass { 62 | GstRTSPMediaFactoryClass parent_class; 63 | 64 | /*< private >*/ 65 | gpointer _gst_reserved[GST_PADDING]; 66 | }; 67 | 68 | GST_RTSP_SERVER_API 69 | GType gst_rtsp_media_factory_uri_get_type (void); 70 | 71 | /* creating the factory */ 72 | 73 | GST_RTSP_SERVER_API 74 | GstRTSPMediaFactoryURI * gst_rtsp_media_factory_uri_new (void); 75 | 76 | /* configuring the factory */ 77 | 78 | GST_RTSP_SERVER_API 79 | void gst_rtsp_media_factory_uri_set_uri (GstRTSPMediaFactoryURI *factory, 80 | const gchar *uri); 81 | 82 | GST_RTSP_SERVER_API 83 | gchar * gst_rtsp_media_factory_uri_get_uri (GstRTSPMediaFactoryURI *factory); 84 | 85 | #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC 86 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstRTSPMediaFactoryURI, gst_object_unref) 87 | #endif 88 | 89 | G_END_DECLS 90 | 91 | #endif /* __GST_RTSP_MEDIA_FACTORY_URI_H__ */ 92 | -------------------------------------------------------------------------------- /gst/rtsp-server/rtsp-onvif-server.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2017 Sebastian Dröge 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | /** 20 | * SECTION:rtsp-onvif-server 21 | * @short_description: The main server object 22 | * @see_also: #GstRTSPOnvifMediaFactory, #GstRTSPClient 23 | * 24 | * The server object is the object listening for connections on a port and 25 | * creating #GstRTSPOnvifClient objects to handle those connections. 26 | * 27 | * The only different to #GstRTSPServer is that #GstRTSPOnvifServer creates 28 | * #GstRTSPOnvifClient that have special handling for ONVIF specific features, 29 | * like a backchannel that allows clients to send back media to the server. 30 | * 31 | * Since: 1.14 32 | */ 33 | 34 | #ifdef HAVE_CONFIG_H 35 | #include "config.h" 36 | #endif 37 | 38 | #include "rtsp-context.h" 39 | #include "rtsp-onvif-server.h" 40 | #include "rtsp-onvif-client.h" 41 | 42 | G_DEFINE_TYPE (GstRTSPOnvifServer, gst_rtsp_onvif_server, GST_TYPE_RTSP_SERVER); 43 | 44 | static GstRTSPClient * 45 | gst_rtsp_onvif_server_create_client (GstRTSPServer * server) 46 | { 47 | GstRTSPClient *client; 48 | GstRTSPSessionPool *session_pool; 49 | GstRTSPMountPoints *mount_points; 50 | GstRTSPAuth *auth; 51 | GstRTSPThreadPool *thread_pool; 52 | 53 | /* a new client connected, create a session to handle the client. */ 54 | client = g_object_new (GST_TYPE_RTSP_ONVIF_CLIENT, NULL); 55 | 56 | /* set the session pool that this client should use */ 57 | session_pool = gst_rtsp_server_get_session_pool (server); 58 | gst_rtsp_client_set_session_pool (client, session_pool); 59 | g_object_unref (session_pool); 60 | /* set the mount points that this client should use */ 61 | mount_points = gst_rtsp_server_get_mount_points (server); 62 | gst_rtsp_client_set_mount_points (client, mount_points); 63 | g_object_unref (mount_points); 64 | /* set authentication manager */ 65 | auth = gst_rtsp_server_get_auth (server); 66 | gst_rtsp_client_set_auth (client, auth); 67 | if (auth) 68 | g_object_unref (auth); 69 | /* set threadpool */ 70 | thread_pool = gst_rtsp_server_get_thread_pool (server); 71 | gst_rtsp_client_set_thread_pool (client, thread_pool); 72 | g_object_unref (thread_pool); 73 | 74 | return client; 75 | } 76 | 77 | /** 78 | * gst_rtsp_onvif_server_new: 79 | * 80 | * Create a new #GstRTSPOnvifServer instance. 81 | * 82 | * Returns: (transfer full): a new #GstRTSPOnvifServer 83 | */ 84 | GstRTSPServer * 85 | gst_rtsp_onvif_server_new (void) 86 | { 87 | return g_object_new (GST_TYPE_RTSP_ONVIF_SERVER, NULL); 88 | } 89 | 90 | static void 91 | gst_rtsp_onvif_server_class_init (GstRTSPOnvifServerClass * klass) 92 | { 93 | GstRTSPServerClass *server_klass = (GstRTSPServerClass *) klass; 94 | 95 | server_klass->create_client = gst_rtsp_onvif_server_create_client; 96 | } 97 | 98 | static void 99 | gst_rtsp_onvif_server_init (GstRTSPOnvifServer * server) 100 | { 101 | } 102 | -------------------------------------------------------------------------------- /docs/meson.build: -------------------------------------------------------------------------------- 1 | build_hotdoc = false 2 | 3 | if meson.is_cross_build() 4 | if get_option('doc').enabled() 5 | error('Documentation enabled but building the doc while cross building is not supported yet.') 6 | endif 7 | 8 | message('Documentation not built as building it while cross building is not supported yet.') 9 | subdir_done() 10 | endif 11 | 12 | required_hotdoc_extensions = ['gi-extension', 'gst-extension'] 13 | if gst_dep.type_name() == 'internal' 14 | gst_proj = subproject('gstreamer') 15 | plugins_cache_generator = gst_proj.get_variable('plugins_cache_generator') 16 | else 17 | required_hotdoc_extensions += ['gst-extension'] 18 | plugins_cache_generator = find_program(join_paths(gst_dep.get_pkgconfig_variable('libexecdir'), 'gstreamer-' + api_version, 'gst-plugins-doc-cache-generator'), 19 | required: false) 20 | endif 21 | 22 | plugins_cache = join_paths(meson.current_source_dir(), 'gst_plugins_cache.json') 23 | if plugins.length() == 0 24 | message('All rtsp-server plugins have been disabled') 25 | elif plugins_cache_generator.found() 26 | plugins_doc_dep = custom_target('rtsp-server-plugins-doc-cache', 27 | command: [plugins_cache_generator, plugins_cache, '@OUTPUT@', '@INPUT@'], 28 | input: plugins, 29 | output: 'gst_plugins_cache.json', 30 | ) 31 | else 32 | warning('GStreamer plugin inspector for documentation not found, can\'t update the cache') 33 | endif 34 | 35 | hotdoc_p = find_program('hotdoc', required: get_option('doc')) 36 | if not hotdoc_p.found() 37 | message('Hotdoc not found, not building the documentation') 38 | subdir_done() 39 | endif 40 | 41 | hotdoc_req = '>= 0.11.0' 42 | hotdoc_version = run_command(hotdoc_p, '--version').stdout() 43 | if not hotdoc_version.version_compare(hotdoc_req) 44 | if get_option('doc').enabled() 45 | error('Hotdoc version @0@ not found, got @1@'.format(hotdoc_req, hotdoc_version)) 46 | else 47 | message('Hotdoc version @0@ not found, got @1@'.format(hotdoc_req, hotdoc_version)) 48 | subdir_done() 49 | endif 50 | endif 51 | 52 | hotdoc = import('hotdoc') 53 | foreach extension: required_hotdoc_extensions 54 | if not hotdoc.has_extensions(extension) 55 | if get_option('doc').enabled() 56 | error('Documentation enabled but @0@ missing'.format(extension)) 57 | endif 58 | 59 | message('@0@ extension not found, not building documentation'.format(extension)) 60 | subdir_done() 61 | endif 62 | endforeach 63 | 64 | if not build_gir 65 | if get_option('doc').enabled() 66 | error('Documentation enabled but introspection not built.') 67 | endif 68 | 69 | message('Introspection not built, can\'t build the documentation') 70 | subdir_done() 71 | endif 72 | 73 | build_hotdoc = true 74 | hotdoc = import('hotdoc') 75 | 76 | libs_doc = [hotdoc.generate_doc('gst-rtsp-server', 77 | project_version: api_version, 78 | gi_c_sources: ['../gst/rtsp-server/*.[hc]'], 79 | gi_sources: rtsp_server_gir[0].full_path(), 80 | sitemap: 'sitemap.txt', 81 | index: 'index.md', 82 | gi_index: 'index.md', 83 | gi_smart_index: true, 84 | gi_order_generated_subpages: true, 85 | )] 86 | 87 | plugins_doc = [hotdoc.generate_doc('rtspclientsink', 88 | project_version: api_version, 89 | sitemap: 'plugin-sitemap.txt', 90 | index: 'plugin-index.md', 91 | gst_index: 'plugin-index.md', 92 | gst_c_sources: ['../gst/rtsp-sink/*.[ch]'], 93 | gst_dl_sources: [rtspsink.full_path()], 94 | gst_smart_index: true, 95 | dependencies: gst_rtsp_server_deps + [rtspsink], 96 | gst_cache_file: plugins_cache, 97 | gst_plugin_name: 'rtspclientsink', 98 | )] 99 | doc = libs_doc[0] 100 | -------------------------------------------------------------------------------- /RELEASE: -------------------------------------------------------------------------------- 1 | This is GStreamer gst-rtsp-server 1.19.2. 2 | 3 | GStreamer 1.19 is the development branch leading up to the next major 4 | stable version which will be 1.20. 5 | 6 | The 1.19 development series adds new features on top of the 1.18 series and is 7 | part of the API and ABI-stable 1.x release series of the GStreamer multimedia 8 | framework. 9 | 10 | Full release notes will one day be found at: 11 | 12 | https://gstreamer.freedesktop.org/releases/1.20/ 13 | 14 | Binaries for Android, iOS, Mac OS X and Windows will usually be provided 15 | shortly after the release. 16 | 17 | This module will not be very useful by itself and should be used in conjunction 18 | with other GStreamer modules for a complete multimedia experience. 19 | 20 | - gstreamer: provides the core GStreamer libraries and some generic plugins 21 | 22 | - gst-plugins-base: a basic set of well-supported plugins and additional 23 | media-specific GStreamer helper libraries for audio, 24 | video, rtsp, rtp, tags, OpenGL, etc. 25 | 26 | - gst-plugins-good: a set of well-supported plugins under our preferred 27 | license 28 | 29 | - gst-plugins-ugly: a set of well-supported plugins which might pose 30 | problems for distributors 31 | 32 | - gst-plugins-bad: a set of plugins of varying quality that have not made 33 | their way into one of core/base/good/ugly yet, for one 34 | reason or another. Many of these are are production quality 35 | elements, but may still be missing documentation or unit 36 | tests; others haven't passed the rigorous quality testing 37 | we expect yet. 38 | 39 | - gst-libav: a set of codecs plugins based on the ffmpeg library. This is 40 | where you can find audio and video decoders and encoders 41 | for a wide variety of formats including H.264, AAC, etc. 42 | 43 | - gstreamer-vaapi: hardware-accelerated video decoding and encoding using 44 | VA-API on Linux. Primarily for Intel graphics hardware. 45 | 46 | - gst-omx: hardware-accelerated video decoding and encoding, primarily for 47 | embedded Linux systems that provide an OpenMax 48 | implementation layer such as the Raspberry Pi. 49 | 50 | - gst-rtsp-server: library to serve files or streaming pipelines via RTSP 51 | 52 | - gst-editing-services: library an plugins for non-linear editing 53 | 54 | ==== Download ==== 55 | 56 | You can find source releases of gstreamer in the download 57 | directory: https://gstreamer.freedesktop.org/src/gstreamer/ 58 | 59 | The git repository and details how to clone it can be found at 60 | https://gitlab.freedesktop.org/gstreamer/ 61 | 62 | ==== Homepage ==== 63 | 64 | The project's website is https://gstreamer.freedesktop.org/ 65 | 66 | ==== Support and Bugs ==== 67 | 68 | We have recently moved from GNOME Bugzilla to GitLab on freedesktop.org 69 | for bug reports and feature requests: 70 | 71 | https://gitlab.freedesktop.org/gstreamer 72 | 73 | Please submit patches via GitLab as well, in form of Merge Requests. See 74 | 75 | https://gstreamer.freedesktop.org/documentation/contribute/ 76 | 77 | for more details. 78 | 79 | For help and support, please subscribe to and send questions to the 80 | gstreamer-devel mailing list (see below for details). 81 | 82 | There is also a #gstreamer IRC channel on the Freenode IRC network. 83 | 84 | ==== Developers ==== 85 | 86 | GStreamer source code repositories can be found on GitLab on freedesktop.org: 87 | 88 | https://gitlab.freedesktop.org/gstreamer 89 | 90 | and can also be cloned from there and this is also where you can submit 91 | Merge Requests or file issues for bugs or feature requests. 92 | 93 | Interested developers of the core library, plugins, and applications should 94 | subscribe to the gstreamer-devel list: 95 | 96 | https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel 97 | -------------------------------------------------------------------------------- /examples/test-record.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * Copyright (C) 2015 Centricular Ltd 4 | * Author: Sebastian Dröge 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 19 | * Boston, MA 02110-1301, USA. 20 | */ 21 | 22 | #include 23 | 24 | #include 25 | 26 | #define DEFAULT_RTSP_PORT "8554" 27 | 28 | static char *port = (char *) DEFAULT_RTSP_PORT; 29 | 30 | static GOptionEntry entries[] = { 31 | {"port", 'p', 0, G_OPTION_ARG_STRING, &port, 32 | "Port to listen on (default: " DEFAULT_RTSP_PORT ")", "PORT"}, 33 | {NULL} 34 | }; 35 | 36 | int 37 | main (int argc, char *argv[]) 38 | { 39 | GMainLoop *loop; 40 | GstRTSPServer *server; 41 | GstRTSPMountPoints *mounts; 42 | GstRTSPMediaFactory *factory; 43 | GOptionContext *optctx; 44 | GError *error = NULL; 45 | 46 | optctx = g_option_context_new (" - Test RTSP Server, Launch\n\n" 47 | "Example: \"( decodebin name=depay0 ! autovideosink )\""); 48 | g_option_context_add_main_entries (optctx, entries, NULL); 49 | g_option_context_add_group (optctx, gst_init_get_option_group ()); 50 | if (!g_option_context_parse (optctx, &argc, &argv, &error)) { 51 | g_printerr ("Error parsing options: %s\n", error->message); 52 | g_option_context_free (optctx); 53 | g_clear_error (&error); 54 | return -1; 55 | } 56 | 57 | if (argc < 2) { 58 | g_print ("%s\n", g_option_context_get_help (optctx, TRUE, NULL)); 59 | return 1; 60 | } 61 | g_option_context_free (optctx); 62 | 63 | loop = g_main_loop_new (NULL, FALSE); 64 | 65 | /* create a server instance */ 66 | server = gst_rtsp_server_new (); 67 | 68 | g_object_set (server, "service", port, NULL); 69 | 70 | /* get the mount points for this server, every server has a default object 71 | * that be used to map uri mount points to media factories */ 72 | mounts = gst_rtsp_server_get_mount_points (server); 73 | 74 | /* make a media factory for a test stream. The default media factory can use 75 | * gst-launch syntax to create pipelines. 76 | * any launch line works as long as it contains elements named depay%d. Each 77 | * element with depay%d names will be a stream */ 78 | factory = gst_rtsp_media_factory_new (); 79 | gst_rtsp_media_factory_set_transport_mode (factory, 80 | GST_RTSP_TRANSPORT_MODE_RECORD); 81 | gst_rtsp_media_factory_set_launch (factory, argv[1]); 82 | gst_rtsp_media_factory_set_latency (factory, 2000); 83 | 84 | /* attach the test factory to the /test url */ 85 | gst_rtsp_mount_points_add_factory (mounts, "/test", factory); 86 | 87 | /* don't need the ref to the mapper anymore */ 88 | g_object_unref (mounts); 89 | 90 | /* attach the server to the default maincontext */ 91 | gst_rtsp_server_attach (server, NULL); 92 | 93 | /* start serving */ 94 | g_print ("stream ready at rtsp://127.0.0.1:%s/test\n", port); 95 | g_print ("On the sender, send a stream with rtspclientsink:\n" 96 | " gst-launch-1.0 videotestsrc ! x264enc ! rtspclientsink location=rtsp://127.0.0.1:%s/test\n", 97 | port); 98 | g_main_loop_run (loop); 99 | 100 | return 0; 101 | } 102 | -------------------------------------------------------------------------------- /examples/test-multicast2.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | 24 | 25 | static gboolean 26 | timeout (GstRTSPServer * server) 27 | { 28 | GstRTSPSessionPool *pool; 29 | 30 | pool = gst_rtsp_server_get_session_pool (server); 31 | gst_rtsp_session_pool_cleanup (pool); 32 | g_object_unref (pool); 33 | 34 | return TRUE; 35 | } 36 | 37 | static void 38 | media_constructed (GstRTSPMediaFactory * factory, GstRTSPMedia * media) 39 | { 40 | guint i, n_streams; 41 | 42 | n_streams = gst_rtsp_media_n_streams (media); 43 | 44 | for (i = 0; i < n_streams; i++) { 45 | GstRTSPAddressPool *pool; 46 | GstRTSPStream *stream; 47 | gchar *min, *max; 48 | 49 | stream = gst_rtsp_media_get_stream (media, i); 50 | 51 | /* make a new address pool */ 52 | pool = gst_rtsp_address_pool_new (); 53 | 54 | min = g_strdup_printf ("224.3.0.%d", (2 * i) + 1); 55 | max = g_strdup_printf ("224.3.0.%d", (2 * i) + 2); 56 | gst_rtsp_address_pool_add_range (pool, min, max, 57 | 5000 + (10 * i), 5010 + (10 * i), 1); 58 | g_free (min); 59 | g_free (max); 60 | 61 | gst_rtsp_stream_set_address_pool (stream, pool); 62 | g_object_unref (pool); 63 | } 64 | } 65 | 66 | int 67 | main (int argc, char *argv[]) 68 | { 69 | GMainLoop *loop; 70 | GstRTSPServer *server; 71 | GstRTSPMountPoints *mounts; 72 | GstRTSPMediaFactory *factory; 73 | 74 | gst_init (&argc, &argv); 75 | 76 | loop = g_main_loop_new (NULL, FALSE); 77 | 78 | /* create a server instance */ 79 | server = gst_rtsp_server_new (); 80 | 81 | /* get the mount points for this server, every server has a default object 82 | * that be used to map uri mount points to media factories */ 83 | mounts = gst_rtsp_server_get_mount_points (server); 84 | 85 | /* make a media factory for a test stream. The default media factory can use 86 | * gst-launch syntax to create pipelines. 87 | * any launch line works as long as it contains elements named pay%d. Each 88 | * element with pay%d names will be a stream */ 89 | factory = gst_rtsp_media_factory_new (); 90 | gst_rtsp_media_factory_set_launch (factory, "( " 91 | "videotestsrc ! video/x-raw,width=352,height=288,framerate=15/1 ! " 92 | "x264enc ! rtph264pay name=pay0 pt=96 " 93 | "audiotestsrc ! audio/x-raw,rate=8000 ! " 94 | "alawenc ! rtppcmapay name=pay1 pt=97 " ")"); 95 | 96 | gst_rtsp_media_factory_set_shared (factory, TRUE); 97 | 98 | g_signal_connect (factory, "media-constructed", (GCallback) 99 | media_constructed, NULL); 100 | 101 | /* attach the test factory to the /test url */ 102 | gst_rtsp_mount_points_add_factory (mounts, "/test", factory); 103 | 104 | /* don't need the ref to the mapper anymore */ 105 | g_object_unref (mounts); 106 | 107 | /* attach the server to the default maincontext */ 108 | if (gst_rtsp_server_attach (server, NULL) == 0) 109 | goto failed; 110 | 111 | g_timeout_add_seconds (2, (GSourceFunc) timeout, server); 112 | 113 | /* start serving */ 114 | g_print ("stream ready at rtsp://127.0.0.1:8554/test\n"); 115 | g_main_loop_run (loop); 116 | 117 | return 0; 118 | 119 | /* ERRORS */ 120 | failed: 121 | { 122 | g_print ("failed to attach the server\n"); 123 | return -1; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /gst/rtsp-server/rtsp-token.h: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2010 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #ifndef __GST_RTSP_TOKEN_H__ 23 | #define __GST_RTSP_TOKEN_H__ 24 | 25 | typedef struct _GstRTSPToken GstRTSPToken; 26 | 27 | #include "rtsp-auth.h" 28 | 29 | G_BEGIN_DECLS 30 | 31 | GST_RTSP_SERVER_API 32 | GType gst_rtsp_token_get_type(void); 33 | 34 | #define GST_TYPE_RTSP_TOKEN (gst_rtsp_token_get_type()) 35 | #define GST_IS_RTSP_TOKEN(obj) (GST_IS_MINI_OBJECT_TYPE (obj, GST_TYPE_RTSP_TOKEN)) 36 | #define GST_RTSP_TOKEN_CAST(obj) ((GstRTSPToken*)(obj)) 37 | #define GST_RTSP_TOKEN(obj) (GST_RTSP_TOKEN_CAST(obj)) 38 | 39 | /** 40 | * GstRTSPToken: 41 | * 42 | * An opaque object used for checking authorisations. 43 | * It is generated after successful authentication. 44 | */ 45 | struct _GstRTSPToken { 46 | GstMiniObject mini_object; 47 | }; 48 | 49 | /* refcounting */ 50 | /** 51 | * gst_rtsp_token_ref: 52 | * @token: The token to refcount 53 | * 54 | * Increase the refcount of this token. 55 | * 56 | * Returns: (transfer full): @token (for convenience when doing assignments) 57 | */ 58 | static inline GstRTSPToken * 59 | gst_rtsp_token_ref (GstRTSPToken * token) 60 | { 61 | return (GstRTSPToken *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (token)); 62 | } 63 | 64 | /** 65 | * gst_rtsp_token_unref: 66 | * @token: (transfer full): the token to refcount 67 | * 68 | * Decrease the refcount of an token, freeing it if the refcount reaches 0. 69 | */ 70 | static inline void 71 | gst_rtsp_token_unref (GstRTSPToken * token) 72 | { 73 | gst_mini_object_unref (GST_MINI_OBJECT_CAST (token)); 74 | } 75 | 76 | 77 | GST_RTSP_SERVER_API 78 | GstRTSPToken * gst_rtsp_token_new_empty (void); 79 | 80 | GST_RTSP_SERVER_API 81 | GstRTSPToken * gst_rtsp_token_new (const gchar * firstfield, ...); 82 | 83 | GST_RTSP_SERVER_API 84 | GstRTSPToken * gst_rtsp_token_new_valist (const gchar * firstfield, va_list var_args); 85 | 86 | GST_RTSP_SERVER_API 87 | const GstStructure * gst_rtsp_token_get_structure (GstRTSPToken *token); 88 | 89 | GST_RTSP_SERVER_API 90 | GstStructure * gst_rtsp_token_writable_structure (GstRTSPToken *token); 91 | 92 | GST_RTSP_SERVER_API 93 | void gst_rtsp_token_set_string (GstRTSPToken * token, 94 | const gchar * field, 95 | const gchar * string_value); 96 | GST_RTSP_SERVER_API 97 | const gchar * gst_rtsp_token_get_string (GstRTSPToken *token, 98 | const gchar *field); 99 | GST_RTSP_SERVER_API 100 | void gst_rtsp_token_set_bool (GstRTSPToken * token, 101 | const gchar * field, 102 | gboolean bool_value); 103 | GST_RTSP_SERVER_API 104 | gboolean gst_rtsp_token_is_allowed (GstRTSPToken *token, 105 | const gchar *field); 106 | 107 | #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC 108 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstRTSPToken, gst_rtsp_token_unref) 109 | #endif 110 | 111 | G_END_DECLS 112 | 113 | #endif /* __GST_RTSP_TOKEN_H__ */ 114 | -------------------------------------------------------------------------------- /gst/rtsp-server/rtsp-onvif-media-factory.h: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2017 Sebastian Dröge 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef __GST_RTSP_ONVIF_MEDIA_FACTORY_H__ 21 | #define __GST_RTSP_ONVIF_MEDIA_FACTORY_H__ 22 | 23 | #include 24 | #include "rtsp-media-factory.h" 25 | 26 | #define GST_TYPE_RTSP_ONVIF_MEDIA_FACTORY (gst_rtsp_onvif_media_factory_get_type ()) 27 | #define GST_IS_RTSP_ONVIF_MEDIA_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_RTSP_ONVIF_MEDIA_FACTORY)) 28 | #define GST_IS_RTSP_ONVIF_MEDIA_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_RTSP_ONVIF_MEDIA_FACTORY)) 29 | #define GST_RTSP_ONVIF_MEDIA_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RTSP_ONVIF_MEDIA_FACTORY, GstRTSPOnvifMediaFactoryClass)) 30 | #define GST_RTSP_ONVIF_MEDIA_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_RTSP_ONVIF_MEDIA_FACTORY, GstRTSPOnvifMediaFactory)) 31 | #define GST_RTSP_ONVIF_MEDIA_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_RTSP_ONVIF_MEDIA_FACTORY, GstRTSPOnvifMediaFactoryClass)) 32 | #define GST_RTSP_ONVIF_MEDIA_FACTORY_CAST(obj) ((GstRTSPOnvifMediaFactory*)(obj)) 33 | #define GST_RTSP_ONVIF_MEDIA_FACTORY_CLASS_CAST(klass) ((GstRTSPOnvifMediaFactoryClass*)(klass)) 34 | 35 | typedef struct GstRTSPOnvifMediaFactoryClass GstRTSPOnvifMediaFactoryClass; 36 | typedef struct GstRTSPOnvifMediaFactory GstRTSPOnvifMediaFactory; 37 | typedef struct GstRTSPOnvifMediaFactoryPrivate GstRTSPOnvifMediaFactoryPrivate; 38 | 39 | /** 40 | * GstRTSPOnvifMediaFactory: 41 | * 42 | * Since: 1.14 43 | */ 44 | struct GstRTSPOnvifMediaFactoryClass 45 | { 46 | GstRTSPMediaFactoryClass parent; 47 | gboolean (*has_backchannel_support) (GstRTSPOnvifMediaFactory * factory); 48 | 49 | /*< private >*/ 50 | gpointer _gst_reserved[GST_PADDING_LARGE]; 51 | }; 52 | 53 | struct GstRTSPOnvifMediaFactory 54 | { 55 | GstRTSPMediaFactory parent; 56 | GstRTSPOnvifMediaFactoryPrivate *priv; 57 | 58 | /*< private >*/ 59 | gpointer _gst_reserved[GST_PADDING]; 60 | }; 61 | 62 | GST_RTSP_SERVER_API 63 | GType gst_rtsp_onvif_media_factory_get_type (void); 64 | 65 | GST_RTSP_SERVER_API 66 | GstRTSPMediaFactory *gst_rtsp_onvif_media_factory_new (void); 67 | 68 | GST_RTSP_SERVER_API 69 | void gst_rtsp_onvif_media_factory_set_backchannel_launch (GstRTSPOnvifMediaFactory * 70 | factory, const gchar * launch); 71 | GST_RTSP_SERVER_API 72 | gchar * gst_rtsp_onvif_media_factory_get_backchannel_launch (GstRTSPOnvifMediaFactory * factory); 73 | 74 | GST_RTSP_SERVER_API 75 | gboolean gst_rtsp_onvif_media_factory_has_backchannel_support (GstRTSPOnvifMediaFactory * factory); 76 | 77 | GST_RTSP_SERVER_API 78 | gboolean gst_rtsp_onvif_media_factory_has_replay_support (GstRTSPOnvifMediaFactory * factory); 79 | 80 | GST_RTSP_SERVER_API 81 | void gst_rtsp_onvif_media_factory_set_replay_support (GstRTSPOnvifMediaFactory * factory, gboolean has_replay_support); 82 | 83 | GST_RTSP_SERVER_API 84 | void gst_rtsp_onvif_media_factory_set_backchannel_bandwidth (GstRTSPOnvifMediaFactory * factory, guint bandwidth); 85 | GST_RTSP_SERVER_API 86 | guint gst_rtsp_onvif_media_factory_get_backchannel_bandwidth (GstRTSPOnvifMediaFactory * factory); 87 | 88 | GST_RTSP_SERVER_API 89 | gboolean gst_rtsp_onvif_media_factory_requires_backchannel (GstRTSPMediaFactory * factory, GstRTSPContext * ctx); 90 | 91 | #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC 92 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstRTSPOnvifMediaFactory, gst_object_unref) 93 | #endif 94 | 95 | #endif /* __GST_RTSP_ONVIF_MEDIA_FACTORY_H__ */ 96 | -------------------------------------------------------------------------------- /examples/test-netclock.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * Copyright (C) 2014 Jan Schmidt 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Library General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Library General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Library General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 18 | * Boston, MA 02110-1301, USA. 19 | */ 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | GstClock *global_clock; 27 | 28 | #define TEST_TYPE_RTSP_MEDIA_FACTORY (test_rtsp_media_factory_get_type ()) 29 | #define TEST_TYPE_RTSP_MEDIA (test_rtsp_media_get_type ()) 30 | 31 | GType test_rtsp_media_get_type (void); 32 | 33 | typedef struct TestRTSPMediaClass TestRTSPMediaClass; 34 | typedef struct TestRTSPMedia TestRTSPMedia; 35 | 36 | struct TestRTSPMediaClass 37 | { 38 | GstRTSPMediaClass parent; 39 | }; 40 | 41 | struct TestRTSPMedia 42 | { 43 | GstRTSPMedia parent; 44 | }; 45 | 46 | static gboolean custom_setup_rtpbin (GstRTSPMedia * media, GstElement * rtpbin); 47 | 48 | G_DEFINE_TYPE (TestRTSPMedia, test_rtsp_media, GST_TYPE_RTSP_MEDIA); 49 | 50 | static void 51 | test_rtsp_media_class_init (TestRTSPMediaClass * test_klass) 52 | { 53 | GstRTSPMediaClass *klass = (GstRTSPMediaClass *) (test_klass); 54 | klass->setup_rtpbin = custom_setup_rtpbin; 55 | } 56 | 57 | static void 58 | test_rtsp_media_init (TestRTSPMedia * media) 59 | { 60 | } 61 | 62 | static gboolean 63 | custom_setup_rtpbin (GstRTSPMedia * media, GstElement * rtpbin) 64 | { 65 | g_object_set (rtpbin, "ntp-time-source", 3, NULL); 66 | return TRUE; 67 | } 68 | 69 | int 70 | main (int argc, char *argv[]) 71 | { 72 | GMainLoop *loop; 73 | GstRTSPServer *server; 74 | GstRTSPMountPoints *mounts; 75 | GstRTSPMediaFactory *factory; 76 | 77 | gst_init (&argc, &argv); 78 | 79 | if (argc < 2) { 80 | g_print ("usage: %s \n" 81 | "example: %s \"( videotestsrc is-live=true ! x264enc ! rtph264pay name=pay0 pt=96 )\"\n" 82 | "Pipeline must be live for synchronisation to work properly with this method!\n", 83 | argv[0], argv[0]); 84 | return -1; 85 | } 86 | 87 | loop = g_main_loop_new (NULL, FALSE); 88 | 89 | global_clock = gst_system_clock_obtain (); 90 | gst_net_time_provider_new (global_clock, "0.0.0.0", 8554); 91 | 92 | /* create a server instance */ 93 | server = gst_rtsp_server_new (); 94 | 95 | /* get the mount points for this server, every server has a default object 96 | * that be used to map uri mount points to media factories */ 97 | mounts = gst_rtsp_server_get_mount_points (server); 98 | 99 | /* make a media factory for a test stream. The default media factory can use 100 | * gst-launch syntax to create pipelines. 101 | * any launch line works as long as it contains elements named pay%d. Each 102 | * element with pay%d names will be a stream */ 103 | factory = gst_rtsp_media_factory_new (); 104 | gst_rtsp_media_factory_set_launch (factory, argv[1]); 105 | gst_rtsp_media_factory_set_shared (factory, TRUE); 106 | gst_rtsp_media_factory_set_media_gtype (factory, TEST_TYPE_RTSP_MEDIA); 107 | gst_rtsp_media_factory_set_clock (factory, global_clock); 108 | 109 | /* attach the test factory to the /test url */ 110 | gst_rtsp_mount_points_add_factory (mounts, "/test", factory); 111 | 112 | /* don't need the ref to the mapper anymore */ 113 | g_object_unref (mounts); 114 | 115 | /* attach the server to the default maincontext */ 116 | gst_rtsp_server_attach (server, NULL); 117 | 118 | /* start serving */ 119 | g_print ("stream ready at rtsp://127.0.0.1:8554/test\n"); 120 | g_main_loop_run (loop); 121 | 122 | return 0; 123 | } 124 | -------------------------------------------------------------------------------- /gst/rtsp-server/rtsp-mount-points.h: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #include "rtsp-media-factory.h" 23 | 24 | #ifndef __GST_RTSP_MOUNT_POINTS_H__ 25 | #define __GST_RTSP_MOUNT_POINTS_H__ 26 | 27 | G_BEGIN_DECLS 28 | 29 | #define GST_TYPE_RTSP_MOUNT_POINTS (gst_rtsp_mount_points_get_type ()) 30 | #define GST_IS_RTSP_MOUNT_POINTS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_RTSP_MOUNT_POINTS)) 31 | #define GST_IS_RTSP_MOUNT_POINTS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_RTSP_MOUNT_POINTS)) 32 | #define GST_RTSP_MOUNT_POINTS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RTSP_MOUNT_POINTS, GstRTSPMountPointsClass)) 33 | #define GST_RTSP_MOUNT_POINTS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_RTSP_MOUNT_POINTS, GstRTSPMountPoints)) 34 | #define GST_RTSP_MOUNT_POINTS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_RTSP_MOUNT_POINTS, GstRTSPMountPointsClass)) 35 | #define GST_RTSP_MOUNT_POINTS_CAST(obj) ((GstRTSPMountPoints*)(obj)) 36 | #define GST_RTSP_MOUNT_POINTS_CLASS_CAST(klass) ((GstRTSPMountPointsClass*)(klass)) 37 | 38 | typedef struct _GstRTSPMountPoints GstRTSPMountPoints; 39 | typedef struct _GstRTSPMountPointsClass GstRTSPMountPointsClass; 40 | typedef struct _GstRTSPMountPointsPrivate GstRTSPMountPointsPrivate; 41 | 42 | /** 43 | * GstRTSPMountPoints: 44 | * 45 | * Creates a #GstRTSPMediaFactory object for a given url. 46 | */ 47 | struct _GstRTSPMountPoints { 48 | GObject parent; 49 | 50 | /*< private >*/ 51 | GstRTSPMountPointsPrivate *priv; 52 | gpointer _gst_reserved[GST_PADDING]; 53 | }; 54 | 55 | /** 56 | * GstRTSPMountPointsClass: 57 | * @make_path: make a path from the given url. 58 | * 59 | * The class for the media mounts object. 60 | */ 61 | struct _GstRTSPMountPointsClass { 62 | GObjectClass parent_class; 63 | 64 | gchar * (*make_path) (GstRTSPMountPoints *mounts, 65 | const GstRTSPUrl *url); 66 | 67 | /*< private >*/ 68 | gpointer _gst_reserved[GST_PADDING]; 69 | }; 70 | 71 | GST_RTSP_SERVER_API 72 | GType gst_rtsp_mount_points_get_type (void); 73 | 74 | /* creating a mount points */ 75 | 76 | GST_RTSP_SERVER_API 77 | GstRTSPMountPoints * gst_rtsp_mount_points_new (void); 78 | 79 | GST_RTSP_SERVER_API 80 | gchar * gst_rtsp_mount_points_make_path (GstRTSPMountPoints *mounts, 81 | const GstRTSPUrl * url); 82 | /* finding a media factory */ 83 | 84 | GST_RTSP_SERVER_API 85 | GstRTSPMediaFactory * gst_rtsp_mount_points_match (GstRTSPMountPoints *mounts, 86 | const gchar *path, 87 | gint * matched); 88 | /* managing media to a mount point */ 89 | 90 | GST_RTSP_SERVER_API 91 | void gst_rtsp_mount_points_add_factory (GstRTSPMountPoints *mounts, 92 | const gchar *path, 93 | GstRTSPMediaFactory *factory); 94 | 95 | GST_RTSP_SERVER_API 96 | void gst_rtsp_mount_points_remove_factory (GstRTSPMountPoints *mounts, 97 | const gchar *path); 98 | 99 | #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC 100 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstRTSPMountPoints, gst_object_unref) 101 | #endif 102 | 103 | G_END_DECLS 104 | 105 | #endif /* __GST_RTSP_MOUNT_POINTS_H__ */ 106 | -------------------------------------------------------------------------------- /examples/test-netclock-client.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * Copyright (C) 2014 Jan Schmidt 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Library General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Library General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Library General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 18 | * Boston, MA 02110-1301, USA. 19 | */ 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | #define PLAYBACK_DELAY_MS 40 27 | 28 | static void 29 | source_created (GstElement * pipe, GstElement * source) 30 | { 31 | g_object_set (source, "latency", PLAYBACK_DELAY_MS, 32 | "ntp-time-source", 3, "buffer-mode", 4, "ntp-sync", TRUE, NULL); 33 | } 34 | 35 | static gboolean 36 | message (GstBus * bus, GstMessage * message, gpointer user_data) 37 | { 38 | GMainLoop *loop = user_data; 39 | 40 | switch (GST_MESSAGE_TYPE (message)) { 41 | case GST_MESSAGE_ERROR:{ 42 | GError *err = NULL; 43 | gchar *name, *debug = NULL; 44 | 45 | name = gst_object_get_path_string (message->src); 46 | gst_message_parse_error (message, &err, &debug); 47 | 48 | g_printerr ("ERROR: from element %s: %s\n", name, err->message); 49 | if (debug != NULL) 50 | g_printerr ("Additional debug info:\n%s\n", debug); 51 | 52 | g_error_free (err); 53 | g_free (debug); 54 | g_free (name); 55 | 56 | g_main_loop_quit (loop); 57 | break; 58 | } 59 | case GST_MESSAGE_WARNING:{ 60 | GError *err = NULL; 61 | gchar *name, *debug = NULL; 62 | 63 | name = gst_object_get_path_string (message->src); 64 | gst_message_parse_warning (message, &err, &debug); 65 | 66 | g_printerr ("ERROR: from element %s: %s\n", name, err->message); 67 | if (debug != NULL) 68 | g_printerr ("Additional debug info:\n%s\n", debug); 69 | 70 | g_error_free (err); 71 | g_free (debug); 72 | g_free (name); 73 | break; 74 | } 75 | case GST_MESSAGE_EOS: 76 | g_print ("Got EOS\n"); 77 | g_main_loop_quit (loop); 78 | break; 79 | default: 80 | break; 81 | } 82 | 83 | return TRUE; 84 | } 85 | 86 | int 87 | main (int argc, char *argv[]) 88 | { 89 | GstClock *net_clock; 90 | gchar *server; 91 | gint clock_port; 92 | GstElement *pipe; 93 | GMainLoop *loop; 94 | 95 | gst_init (&argc, &argv); 96 | 97 | if (argc < 2) { 98 | g_print ("usage: %s rtsp://URI clock-IP clock-PORT\n" 99 | "example: %s rtsp://localhost:8554/test 127.0.0.1 8554\n", 100 | argv[0], argv[0]); 101 | return -1; 102 | } 103 | 104 | server = argv[2]; 105 | clock_port = atoi (argv[3]); 106 | 107 | net_clock = gst_net_client_clock_new ("net_clock", server, clock_port, 0); 108 | if (net_clock == NULL) { 109 | g_print ("Failed to create net clock client for %s:%d\n", 110 | server, clock_port); 111 | return 1; 112 | } 113 | 114 | /* Wait for the clock to stabilise */ 115 | gst_clock_wait_for_sync (net_clock, GST_CLOCK_TIME_NONE); 116 | 117 | loop = g_main_loop_new (NULL, FALSE); 118 | 119 | pipe = gst_element_factory_make ("playbin", NULL); 120 | g_object_set (pipe, "uri", argv[1], NULL); 121 | g_signal_connect (pipe, "source-setup", G_CALLBACK (source_created), NULL); 122 | 123 | gst_pipeline_use_clock (GST_PIPELINE (pipe), net_clock); 124 | 125 | /* Set this high enough so that it's higher than the minimum latency 126 | * on all receivers */ 127 | gst_pipeline_set_latency (GST_PIPELINE (pipe), 500 * GST_MSECOND); 128 | 129 | if (gst_element_set_state (pipe, 130 | GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) { 131 | g_print ("Failed to set state to PLAYING\n"); 132 | goto exit; 133 | }; 134 | 135 | gst_bus_add_signal_watch (GST_ELEMENT_BUS (pipe)); 136 | g_signal_connect (GST_ELEMENT_BUS (pipe), "message", G_CALLBACK (message), 137 | loop); 138 | 139 | g_main_loop_run (loop); 140 | 141 | exit: 142 | gst_element_set_state (pipe, GST_STATE_NULL); 143 | gst_object_unref (pipe); 144 | g_main_loop_unref (loop); 145 | 146 | return 0; 147 | } 148 | -------------------------------------------------------------------------------- /tests/check/gst/token.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2013 Sebastian Rasmussen 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | 24 | GST_START_TEST (test_token) 25 | { 26 | GstRTSPToken *token; 27 | GstRTSPToken *token2; 28 | GstRTSPToken *copy; 29 | GstStructure *str; 30 | 31 | token = gst_rtsp_token_new_empty (); 32 | fail_if (gst_rtsp_token_is_allowed (token, "missing")); 33 | gst_rtsp_token_unref (token); 34 | 35 | token = gst_rtsp_token_new ("role", G_TYPE_STRING, "user", 36 | "permission1", G_TYPE_BOOLEAN, TRUE, 37 | "permission2", G_TYPE_BOOLEAN, FALSE, NULL); 38 | fail_unless_equals_string (gst_rtsp_token_get_string (token, "role"), "user"); 39 | fail_unless (gst_rtsp_token_is_allowed (token, "permission1")); 40 | fail_if (gst_rtsp_token_is_allowed (token, "permission2")); 41 | fail_if (gst_rtsp_token_is_allowed (token, "missing")); 42 | copy = GST_RTSP_TOKEN (gst_mini_object_copy (GST_MINI_OBJECT (token))); 43 | gst_rtsp_token_unref (token); 44 | fail_unless_equals_string (gst_rtsp_token_get_string (copy, "role"), "user"); 45 | fail_unless (gst_rtsp_token_is_allowed (copy, "permission1")); 46 | fail_if (gst_rtsp_token_is_allowed (copy, "permission2")); 47 | fail_if (gst_rtsp_token_is_allowed (copy, "missing")); 48 | gst_rtsp_token_unref (copy); 49 | 50 | token = gst_rtsp_token_new ("role", G_TYPE_STRING, "user", 51 | "permission1", G_TYPE_BOOLEAN, TRUE, 52 | "permission2", G_TYPE_BOOLEAN, FALSE, NULL); 53 | fail_unless_equals_string (gst_rtsp_token_get_string (token, "role"), "user"); 54 | fail_unless (gst_rtsp_token_is_allowed (token, "permission1")); 55 | fail_if (gst_rtsp_token_is_allowed (token, "permission2")); 56 | fail_unless_equals_string (gst_rtsp_token_get_string (token, "role"), "user"); 57 | 58 | fail_unless (gst_mini_object_is_writable (GST_MINI_OBJECT (token))); 59 | fail_unless (gst_rtsp_token_writable_structure (token) != NULL); 60 | fail_unless (gst_rtsp_token_get_structure (token) != NULL); 61 | 62 | token2 = gst_rtsp_token_ref (token); 63 | 64 | fail_if (gst_mini_object_is_writable (GST_MINI_OBJECT (token))); 65 | ASSERT_CRITICAL (fail_unless (gst_rtsp_token_writable_structure (token) == 66 | NULL)); 67 | fail_unless (gst_rtsp_token_get_structure (token) != NULL); 68 | 69 | gst_rtsp_token_unref (token2); 70 | 71 | fail_unless (gst_mini_object_is_writable (GST_MINI_OBJECT (token))); 72 | fail_unless (gst_rtsp_token_writable_structure (token) != NULL); 73 | fail_unless (gst_rtsp_token_get_structure (token) != NULL); 74 | 75 | str = gst_rtsp_token_writable_structure (token); 76 | gst_structure_set (str, "permission2", G_TYPE_BOOLEAN, TRUE, NULL); 77 | fail_unless_equals_string (gst_rtsp_token_get_string (token, "role"), "user"); 78 | fail_unless (gst_rtsp_token_is_allowed (token, "permission1")); 79 | fail_unless (gst_rtsp_token_is_allowed (token, "permission2")); 80 | fail_unless_equals_string (gst_rtsp_token_get_string (token, "role"), "user"); 81 | 82 | gst_rtsp_token_set_bool (token, "permission3", FALSE); 83 | fail_unless (!gst_rtsp_token_is_allowed (token, "permission3")); 84 | gst_rtsp_token_set_bool (token, "permission4", TRUE); 85 | fail_unless (gst_rtsp_token_is_allowed (token, "permission4")); 86 | 87 | fail_unless_equals_string (gst_rtsp_token_get_string (token, "role"), "user"); 88 | gst_rtsp_token_set_string (token, "role", "admin"); 89 | fail_unless_equals_string (gst_rtsp_token_get_string (token, "role"), 90 | "admin"); 91 | 92 | gst_rtsp_token_unref (token); 93 | } 94 | 95 | GST_END_TEST; 96 | 97 | static Suite * 98 | rtsptoken_suite (void) 99 | { 100 | Suite *s = suite_create ("rtsptoken"); 101 | TCase *tc = tcase_create ("general"); 102 | 103 | suite_add_tcase (s, tc); 104 | tcase_set_timeout (tc, 20); 105 | tcase_add_test (tc, test_token); 106 | 107 | return s; 108 | } 109 | 110 | GST_CHECK_MAIN (rtsptoken); 111 | -------------------------------------------------------------------------------- /gst/rtsp-server/rtsp-permissions.h: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2010 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #ifndef __GST_RTSP_PERMISSIONS_H__ 23 | #define __GST_RTSP_PERMISSIONS_H__ 24 | 25 | #include "rtsp-server-prelude.h" 26 | 27 | typedef struct _GstRTSPPermissions GstRTSPPermissions; 28 | 29 | G_BEGIN_DECLS 30 | 31 | GST_RTSP_SERVER_API 32 | GType gst_rtsp_permissions_get_type (void); 33 | 34 | #define GST_TYPE_RTSP_PERMISSIONS (gst_rtsp_permissions_get_type ()) 35 | #define GST_IS_RTSP_PERMISSIONS(obj) (GST_IS_MINI_OBJECT_TYPE (obj, GST_TYPE_RTSP_PERMISSIONS)) 36 | #define GST_RTSP_PERMISSIONS_CAST(obj) ((GstRTSPPermissions*)(obj)) 37 | #define GST_RTSP_PERMISSIONS(obj) (GST_RTSP_PERMISSIONS_CAST(obj)) 38 | 39 | /** 40 | * GstRTSPPermissions: 41 | * 42 | * The opaque permissions structure. It is used to define the permissions 43 | * of objects in different roles. 44 | */ 45 | struct _GstRTSPPermissions { 46 | GstMiniObject mini_object; 47 | }; 48 | 49 | /* refcounting */ 50 | /** 51 | * gst_rtsp_permissions_ref: 52 | * @permissions: The permissions to refcount 53 | * 54 | * Increase the refcount of this permissions. 55 | * 56 | * Returns: (transfer full): @permissions (for convenience when doing assignments) 57 | */ 58 | static inline GstRTSPPermissions * 59 | gst_rtsp_permissions_ref (GstRTSPPermissions * permissions) 60 | { 61 | return (GstRTSPPermissions *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (permissions)); 62 | } 63 | 64 | /** 65 | * gst_rtsp_permissions_unref: 66 | * @permissions: (transfer full): the permissions to refcount 67 | * 68 | * Decrease the refcount of an permissions, freeing it if the refcount reaches 0. 69 | */ 70 | static inline void 71 | gst_rtsp_permissions_unref (GstRTSPPermissions * permissions) 72 | { 73 | gst_mini_object_unref (GST_MINI_OBJECT_CAST (permissions)); 74 | } 75 | 76 | 77 | GST_RTSP_SERVER_API 78 | GstRTSPPermissions * gst_rtsp_permissions_new (void); 79 | 80 | GST_RTSP_SERVER_API 81 | void gst_rtsp_permissions_add_role (GstRTSPPermissions *permissions, 82 | const gchar *role, 83 | const gchar *fieldname, ...); 84 | 85 | GST_RTSP_SERVER_API 86 | void gst_rtsp_permissions_add_role_valist (GstRTSPPermissions *permissions, 87 | const gchar *role, 88 | const gchar *fieldname, 89 | va_list var_args); 90 | 91 | GST_RTSP_SERVER_API 92 | void gst_rtsp_permissions_add_role_empty (GstRTSPPermissions * permissions, 93 | const gchar * role); 94 | 95 | GST_RTSP_SERVER_API 96 | void gst_rtsp_permissions_add_role_from_structure (GstRTSPPermissions * permissions, 97 | GstStructure *structure); 98 | GST_RTSP_SERVER_API 99 | void gst_rtsp_permissions_add_permission_for_role (GstRTSPPermissions * permissions, 100 | const gchar * role, 101 | const gchar * permission, 102 | gboolean allowed); 103 | 104 | GST_RTSP_SERVER_API 105 | void gst_rtsp_permissions_remove_role (GstRTSPPermissions *permissions, 106 | const gchar *role); 107 | 108 | GST_RTSP_SERVER_API 109 | const GstStructure * gst_rtsp_permissions_get_role (GstRTSPPermissions *permissions, 110 | const gchar *role); 111 | 112 | GST_RTSP_SERVER_API 113 | gboolean gst_rtsp_permissions_is_allowed (GstRTSPPermissions *permissions, 114 | const gchar *role, const gchar *permission); 115 | 116 | #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC 117 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstRTSPPermissions, gst_rtsp_permissions_unref) 118 | #endif 119 | 120 | G_END_DECLS 121 | 122 | #endif /* __GST_RTSP_PERMISSIONS_H__ */ 123 | -------------------------------------------------------------------------------- /examples/test-appsrc.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | 24 | typedef struct 25 | { 26 | gboolean white; 27 | GstClockTime timestamp; 28 | } MyContext; 29 | 30 | /* called when we need to give data to appsrc */ 31 | static void 32 | need_data (GstElement * appsrc, guint unused, MyContext * ctx) 33 | { 34 | GstBuffer *buffer; 35 | guint size; 36 | GstFlowReturn ret; 37 | 38 | size = 385 * 288 * 2; 39 | 40 | buffer = gst_buffer_new_allocate (NULL, size, NULL); 41 | 42 | /* this makes the image black/white */ 43 | gst_buffer_memset (buffer, 0, ctx->white ? 0xff : 0x0, size); 44 | 45 | ctx->white = !ctx->white; 46 | 47 | /* increment the timestamp every 1/2 second */ 48 | GST_BUFFER_PTS (buffer) = ctx->timestamp; 49 | GST_BUFFER_DURATION (buffer) = gst_util_uint64_scale_int (1, GST_SECOND, 2); 50 | ctx->timestamp += GST_BUFFER_DURATION (buffer); 51 | 52 | g_signal_emit_by_name (appsrc, "push-buffer", buffer, &ret); 53 | gst_buffer_unref (buffer); 54 | } 55 | 56 | /* called when a new media pipeline is constructed. We can query the 57 | * pipeline and configure our appsrc */ 58 | static void 59 | media_configure (GstRTSPMediaFactory * factory, GstRTSPMedia * media, 60 | gpointer user_data) 61 | { 62 | GstElement *element, *appsrc; 63 | MyContext *ctx; 64 | 65 | /* get the element used for providing the streams of the media */ 66 | element = gst_rtsp_media_get_element (media); 67 | 68 | /* get our appsrc, we named it 'mysrc' with the name property */ 69 | appsrc = gst_bin_get_by_name_recurse_up (GST_BIN (element), "mysrc"); 70 | 71 | /* this instructs appsrc that we will be dealing with timed buffer */ 72 | gst_util_set_object_arg (G_OBJECT (appsrc), "format", "time"); 73 | /* configure the caps of the video */ 74 | g_object_set (G_OBJECT (appsrc), "caps", 75 | gst_caps_new_simple ("video/x-raw", 76 | "format", G_TYPE_STRING, "RGB16", 77 | "width", G_TYPE_INT, 384, 78 | "height", G_TYPE_INT, 288, 79 | "framerate", GST_TYPE_FRACTION, 0, 1, NULL), NULL); 80 | 81 | ctx = g_new0 (MyContext, 1); 82 | ctx->white = FALSE; 83 | ctx->timestamp = 0; 84 | /* make sure ther datais freed when the media is gone */ 85 | g_object_set_data_full (G_OBJECT (media), "my-extra-data", ctx, 86 | (GDestroyNotify) g_free); 87 | 88 | /* install the callback that will be called when a buffer is needed */ 89 | g_signal_connect (appsrc, "need-data", (GCallback) need_data, ctx); 90 | gst_object_unref (appsrc); 91 | gst_object_unref (element); 92 | } 93 | 94 | int 95 | main (int argc, char *argv[]) 96 | { 97 | GMainLoop *loop; 98 | GstRTSPServer *server; 99 | GstRTSPMountPoints *mounts; 100 | GstRTSPMediaFactory *factory; 101 | 102 | gst_init (&argc, &argv); 103 | 104 | loop = g_main_loop_new (NULL, FALSE); 105 | 106 | /* create a server instance */ 107 | server = gst_rtsp_server_new (); 108 | 109 | /* get the mount points for this server, every server has a default object 110 | * that be used to map uri mount points to media factories */ 111 | mounts = gst_rtsp_server_get_mount_points (server); 112 | 113 | /* make a media factory for a test stream. The default media factory can use 114 | * gst-launch syntax to create pipelines. 115 | * any launch line works as long as it contains elements named pay%d. Each 116 | * element with pay%d names will be a stream */ 117 | factory = gst_rtsp_media_factory_new (); 118 | gst_rtsp_media_factory_set_launch (factory, 119 | "( appsrc name=mysrc ! videoconvert ! x264enc ! rtph264pay name=pay0 pt=96 )"); 120 | 121 | /* notify when our media is ready, This is called whenever someone asks for 122 | * the media and a new pipeline with our appsrc is created */ 123 | g_signal_connect (factory, "media-configure", (GCallback) media_configure, 124 | NULL); 125 | 126 | /* attach the test factory to the /test url */ 127 | gst_rtsp_mount_points_add_factory (mounts, "/test", factory); 128 | 129 | /* don't need the ref to the mounts anymore */ 130 | g_object_unref (mounts); 131 | 132 | /* attach the server to the default maincontext */ 133 | gst_rtsp_server_attach (server, NULL); 134 | 135 | /* start serving */ 136 | g_print ("stream ready at rtsp://127.0.0.1:8554/test\n"); 137 | g_main_loop_run (loop); 138 | 139 | return 0; 140 | } 141 | -------------------------------------------------------------------------------- /examples/test-uri.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | #define DEFAULT_RTSP_PORT "8554" 26 | 27 | static char *port = (char *) DEFAULT_RTSP_PORT; 28 | 29 | static GOptionEntry entries[] = { 30 | {"port", 'p', 0, G_OPTION_ARG_STRING, &port, 31 | "Port to listen on (default: " DEFAULT_RTSP_PORT ")", "PORT"}, 32 | {NULL} 33 | }; 34 | 35 | 36 | static gboolean 37 | timeout (GstRTSPServer * server) 38 | { 39 | GstRTSPSessionPool *pool; 40 | 41 | pool = gst_rtsp_server_get_session_pool (server); 42 | gst_rtsp_session_pool_cleanup (pool); 43 | g_object_unref (pool); 44 | 45 | return TRUE; 46 | } 47 | 48 | #if 0 49 | static gboolean 50 | remove_map (GstRTSPServer * server) 51 | { 52 | GstRTSPMountPoints *mounts; 53 | 54 | g_print ("removing /test mount point\n"); 55 | mounts = gst_rtsp_server_get_mount_points (server); 56 | gst_rtsp_mount_points_remove_factory (mounts, "/test"); 57 | g_object_unref (mounts); 58 | 59 | return FALSE; 60 | } 61 | #endif 62 | 63 | int 64 | main (int argc, gchar * argv[]) 65 | { 66 | GMainLoop *loop; 67 | GstRTSPServer *server; 68 | GstRTSPMountPoints *mounts; 69 | GstRTSPMediaFactoryURI *factory; 70 | GOptionContext *optctx; 71 | GError *error = NULL; 72 | gchar *uri; 73 | 74 | optctx = g_option_context_new (" - Test RTSP Server, URI"); 75 | g_option_context_add_main_entries (optctx, entries, NULL); 76 | g_option_context_add_group (optctx, gst_init_get_option_group ()); 77 | if (!g_option_context_parse (optctx, &argc, &argv, &error)) { 78 | g_printerr ("Error parsing options: %s\n", error->message); 79 | g_option_context_free (optctx); 80 | g_clear_error (&error); 81 | return -1; 82 | } 83 | g_option_context_free (optctx); 84 | 85 | if (argc < 2) { 86 | g_printerr ("Please pass an URI or file as argument!\n"); 87 | return -1; 88 | } 89 | 90 | loop = g_main_loop_new (NULL, FALSE); 91 | 92 | /* create a server instance */ 93 | server = gst_rtsp_server_new (); 94 | g_object_set (server, "service", port, NULL); 95 | 96 | /* get the mount points for this server, every server has a default object 97 | * that be used to map uri mount points to media factories */ 98 | mounts = gst_rtsp_server_get_mount_points (server); 99 | 100 | /* make a URI media factory for a test stream. */ 101 | factory = gst_rtsp_media_factory_uri_new (); 102 | 103 | /* when using GStreamer as a client, one can use the gst payloader, which is 104 | * more efficient when there is no payloader for the compressed format */ 105 | /* g_object_set (factory, "use-gstpay", TRUE, NULL); */ 106 | 107 | /* check if URI is valid, otherwise convert filename to URI if it's a file */ 108 | if (gst_uri_is_valid (argv[1])) { 109 | uri = g_strdup (argv[1]); 110 | } else if (g_file_test (argv[1], G_FILE_TEST_EXISTS)) { 111 | uri = gst_filename_to_uri (argv[1], NULL); 112 | } else { 113 | g_printerr ("Unrecognised command line argument '%s'.\n" 114 | "Please pass an URI or file as argument!\n", argv[1]); 115 | return -1; 116 | } 117 | 118 | gst_rtsp_media_factory_uri_set_uri (factory, uri); 119 | g_free (uri); 120 | 121 | /* if you want multiple clients to see the same video, set the shared property 122 | * to TRUE */ 123 | /* gst_rtsp_media_factory_set_shared ( GST_RTSP_MEDIA_FACTORY (factory), TRUE); */ 124 | 125 | /* attach the test factory to the /test url */ 126 | gst_rtsp_mount_points_add_factory (mounts, "/test", 127 | GST_RTSP_MEDIA_FACTORY (factory)); 128 | 129 | /* don't need the ref to the mapper anymore */ 130 | g_object_unref (mounts); 131 | 132 | /* attach the server to the default maincontext */ 133 | if (gst_rtsp_server_attach (server, NULL) == 0) 134 | goto failed; 135 | 136 | /* do session cleanup every 2 seconds */ 137 | g_timeout_add_seconds (2, (GSourceFunc) timeout, server); 138 | 139 | #if 0 140 | /* remove the mount point after 10 seconds, new clients won't be able to use 141 | * the /test url anymore */ 142 | g_timeout_add_seconds (10, (GSourceFunc) remove_map, server); 143 | #endif 144 | 145 | /* start serving */ 146 | g_print ("stream ready at rtsp://127.0.0.1:%s/test\n", port); 147 | g_main_loop_run (loop); 148 | 149 | return 0; 150 | 151 | /* ERRORS */ 152 | failed: 153 | { 154 | g_print ("failed to attach the server\n"); 155 | return -1; 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /gst/rtsp-server/rtsp-session-media.h: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | 24 | #ifndef __GST_RTSP_SESSION_MEDIA_H__ 25 | #define __GST_RTSP_SESSION_MEDIA_H__ 26 | 27 | #include "rtsp-server-prelude.h" 28 | 29 | G_BEGIN_DECLS 30 | 31 | #define GST_TYPE_RTSP_SESSION_MEDIA (gst_rtsp_session_media_get_type ()) 32 | #define GST_IS_RTSP_SESSION_MEDIA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_RTSP_SESSION_MEDIA)) 33 | #define GST_IS_RTSP_SESSION_MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_RTSP_SESSION_MEDIA)) 34 | #define GST_RTSP_SESSION_MEDIA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RTSP_SESSION_MEDIA, GstRTSPSessionMediaClass)) 35 | #define GST_RTSP_SESSION_MEDIA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_RTSP_SESSION_MEDIA, GstRTSPSessionMedia)) 36 | #define GST_RTSP_SESSION_MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_RTSP_SESSION_MEDIA, GstRTSPSessionMediaClass)) 37 | #define GST_RTSP_SESSION_MEDIA_CAST(obj) ((GstRTSPSessionMedia*)(obj)) 38 | #define GST_RTSP_SESSION_MEDIA_CLASS_CAST(klass) ((GstRTSPSessionMediaClass*)(klass)) 39 | 40 | typedef struct _GstRTSPSessionMedia GstRTSPSessionMedia; 41 | typedef struct _GstRTSPSessionMediaClass GstRTSPSessionMediaClass; 42 | typedef struct _GstRTSPSessionMediaPrivate GstRTSPSessionMediaPrivate; 43 | 44 | /** 45 | * GstRTSPSessionMedia: 46 | * 47 | * State of a client session regarding a specific media identified by path. 48 | */ 49 | struct _GstRTSPSessionMedia 50 | { 51 | GObject parent; 52 | 53 | /*< private >*/ 54 | GstRTSPSessionMediaPrivate *priv; 55 | gpointer _gst_reserved[GST_PADDING]; 56 | }; 57 | 58 | struct _GstRTSPSessionMediaClass 59 | { 60 | GObjectClass parent_class; 61 | 62 | /*< private >*/ 63 | gpointer _gst_reserved[GST_PADDING]; 64 | }; 65 | 66 | GST_RTSP_SERVER_API 67 | GType gst_rtsp_session_media_get_type (void); 68 | 69 | GST_RTSP_SERVER_API 70 | GstRTSPSessionMedia * gst_rtsp_session_media_new (const gchar *path, 71 | GstRTSPMedia *media); 72 | 73 | GST_RTSP_SERVER_API 74 | gboolean gst_rtsp_session_media_matches (GstRTSPSessionMedia *media, 75 | const gchar *path, 76 | gint * matched); 77 | 78 | GST_RTSP_SERVER_API 79 | GstRTSPMedia * gst_rtsp_session_media_get_media (GstRTSPSessionMedia *media); 80 | 81 | GST_RTSP_SERVER_API 82 | GstClockTime gst_rtsp_session_media_get_base_time (GstRTSPSessionMedia *media); 83 | /* control media */ 84 | 85 | GST_RTSP_SERVER_API 86 | gboolean gst_rtsp_session_media_set_state (GstRTSPSessionMedia *media, 87 | GstState state); 88 | 89 | GST_RTSP_SERVER_API 90 | void gst_rtsp_session_media_set_rtsp_state (GstRTSPSessionMedia *media, 91 | GstRTSPState state); 92 | 93 | GST_RTSP_SERVER_API 94 | GstRTSPState gst_rtsp_session_media_get_rtsp_state (GstRTSPSessionMedia *media); 95 | 96 | /* get stream transport config */ 97 | 98 | GST_RTSP_SERVER_API 99 | GstRTSPStreamTransport * gst_rtsp_session_media_set_transport (GstRTSPSessionMedia *media, 100 | GstRTSPStream *stream, 101 | GstRTSPTransport *tr); 102 | 103 | GST_RTSP_SERVER_API 104 | GstRTSPStreamTransport * gst_rtsp_session_media_get_transport (GstRTSPSessionMedia *media, 105 | guint idx); 106 | 107 | GST_RTSP_SERVER_API 108 | GPtrArray * gst_rtsp_session_media_get_transports (GstRTSPSessionMedia *media); 109 | 110 | GST_RTSP_SERVER_API 111 | gboolean gst_rtsp_session_media_alloc_channels (GstRTSPSessionMedia *media, 112 | GstRTSPRange *range); 113 | 114 | GST_RTSP_SERVER_API 115 | gchar * gst_rtsp_session_media_get_rtpinfo (GstRTSPSessionMedia * media); 116 | 117 | #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC 118 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstRTSPSessionMedia, gst_object_unref) 119 | #endif 120 | 121 | G_END_DECLS 122 | 123 | #endif /* __GST_RTSP_SESSION_MEDIA_H__ */ 124 | -------------------------------------------------------------------------------- /tests/check/gst/mountpoints.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2012 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | 24 | GST_START_TEST (test_create) 25 | { 26 | GstRTSPMountPoints *mounts; 27 | GstRTSPUrl *url, *url2; 28 | GstRTSPMediaFactory *factory; 29 | 30 | mounts = gst_rtsp_mount_points_new (); 31 | 32 | fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test", 33 | &url) == GST_RTSP_OK); 34 | fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test2", 35 | &url2) == GST_RTSP_OK); 36 | 37 | fail_unless (gst_rtsp_mount_points_match (mounts, url->abspath, 38 | NULL) == NULL); 39 | 40 | factory = gst_rtsp_media_factory_new (); 41 | gst_rtsp_mount_points_add_factory (mounts, "/test", factory); 42 | 43 | fail_unless (gst_rtsp_mount_points_match (mounts, url->abspath, 44 | NULL) == factory); 45 | g_object_unref (factory); 46 | fail_unless (gst_rtsp_mount_points_match (mounts, url2->abspath, 47 | NULL) == NULL); 48 | 49 | gst_rtsp_mount_points_remove_factory (mounts, "/test"); 50 | 51 | fail_unless (gst_rtsp_mount_points_match (mounts, url->abspath, 52 | NULL) == NULL); 53 | fail_unless (gst_rtsp_mount_points_match (mounts, url2->abspath, 54 | NULL) == NULL); 55 | 56 | gst_rtsp_url_free (url); 57 | gst_rtsp_url_free (url2); 58 | 59 | g_object_unref (mounts); 60 | } 61 | 62 | GST_END_TEST; 63 | 64 | static const gchar *paths[] = { 65 | "/test", 66 | "/booz/fooz", 67 | "/booz/foo/zoop", 68 | "/tark/bar", 69 | "/tark/bar/baz", 70 | "/tark/bar/baz/t", 71 | "/boozop", 72 | "/raw", 73 | "/raw/video", 74 | "/raw/snapshot", 75 | }; 76 | 77 | GST_START_TEST (test_match) 78 | { 79 | GstRTSPMountPoints *mounts; 80 | GstRTSPMediaFactory *f[G_N_ELEMENTS (paths)], *tmp; 81 | gint i, matched; 82 | 83 | mounts = gst_rtsp_mount_points_new (); 84 | 85 | for (i = 0; i < G_N_ELEMENTS (paths); i++) { 86 | f[i] = gst_rtsp_media_factory_new (); 87 | gst_rtsp_mount_points_add_factory (mounts, paths[i], f[i]); 88 | } 89 | 90 | tmp = gst_rtsp_mount_points_match (mounts, "/test", &matched); 91 | fail_unless (tmp == f[0]); 92 | fail_unless (matched == 5); 93 | g_object_unref (tmp); 94 | tmp = gst_rtsp_mount_points_match (mounts, "/test/stream=1", &matched); 95 | fail_unless (tmp == f[0]); 96 | fail_unless (matched == 5); 97 | g_object_unref (tmp); 98 | tmp = gst_rtsp_mount_points_match (mounts, "/booz", &matched); 99 | fail_unless (tmp == NULL); 100 | tmp = gst_rtsp_mount_points_match (mounts, "/booz/foo", &matched); 101 | fail_unless (tmp == NULL); 102 | tmp = gst_rtsp_mount_points_match (mounts, "/booz/fooz", &matched); 103 | fail_unless (tmp == f[1]); 104 | fail_unless (matched == 10); 105 | g_object_unref (tmp); 106 | tmp = gst_rtsp_mount_points_match (mounts, "/booz/fooz/zoo", &matched); 107 | fail_unless (tmp == f[1]); 108 | fail_unless (matched == 10); 109 | g_object_unref (tmp); 110 | tmp = gst_rtsp_mount_points_match (mounts, "/booz/foo/zoop", &matched); 111 | fail_unless (tmp == f[2]); 112 | fail_unless (matched == 14); 113 | g_object_unref (tmp); 114 | tmp = gst_rtsp_mount_points_match (mounts, "/tark/bar", &matched); 115 | fail_unless (tmp == f[3]); 116 | fail_unless (matched == 9); 117 | g_object_unref (tmp); 118 | tmp = gst_rtsp_mount_points_match (mounts, "/tark/bar/boo", &matched); 119 | fail_unless (tmp == f[3]); 120 | fail_unless (matched == 9); 121 | g_object_unref (tmp); 122 | tmp = gst_rtsp_mount_points_match (mounts, "/tark/bar/ba", &matched); 123 | fail_unless (tmp == f[3]); 124 | fail_unless (matched == 9); 125 | g_object_unref (tmp); 126 | tmp = gst_rtsp_mount_points_match (mounts, "/tark/bar/baz", &matched); 127 | fail_unless (tmp == f[4]); 128 | fail_unless (matched == 13); 129 | g_object_unref (tmp); 130 | tmp = gst_rtsp_mount_points_match (mounts, "/raw/video", &matched); 131 | fail_unless (tmp == f[8]); 132 | fail_unless (matched == 10); 133 | g_object_unref (tmp); 134 | tmp = gst_rtsp_mount_points_match (mounts, "/raw/snapshot", &matched); 135 | fail_unless (tmp == f[9]); 136 | fail_unless (matched == 13); 137 | g_object_unref (tmp); 138 | 139 | g_object_unref (mounts); 140 | } 141 | 142 | GST_END_TEST; 143 | 144 | static Suite * 145 | rtspmountpoints_suite (void) 146 | { 147 | Suite *s = suite_create ("rtspmountpoints"); 148 | TCase *tc = tcase_create ("general"); 149 | 150 | suite_add_tcase (s, tc); 151 | tcase_set_timeout (tc, 20); 152 | tcase_add_test (tc, test_create); 153 | tcase_add_test (tc, test_match); 154 | 155 | return s; 156 | } 157 | 158 | GST_CHECK_MAIN (rtspmountpoints); 159 | -------------------------------------------------------------------------------- /examples/test-mp4.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | 24 | #define DEFAULT_RTSP_PORT "8554" 25 | 26 | static char *port = (char *) DEFAULT_RTSP_PORT; 27 | 28 | static GOptionEntry entries[] = { 29 | {"port", 'p', 0, G_OPTION_ARG_STRING, &port, 30 | "Port to listen on (default: " DEFAULT_RTSP_PORT ")", "PORT"}, 31 | {NULL} 32 | }; 33 | 34 | /* called when a stream has received an RTCP packet from the client */ 35 | static void 36 | on_ssrc_active (GObject * session, GObject * source, GstRTSPMedia * media) 37 | { 38 | GstStructure *stats; 39 | 40 | GST_INFO ("source %p in session %p is active", source, session); 41 | 42 | g_object_get (source, "stats", &stats, NULL); 43 | if (stats) { 44 | gchar *sstr; 45 | 46 | sstr = gst_structure_to_string (stats); 47 | g_print ("structure: %s\n", sstr); 48 | g_free (sstr); 49 | 50 | gst_structure_free (stats); 51 | } 52 | } 53 | 54 | static void 55 | on_sender_ssrc_active (GObject * session, GObject * source, 56 | GstRTSPMedia * media) 57 | { 58 | GstStructure *stats; 59 | 60 | GST_INFO ("source %p in session %p is active", source, session); 61 | 62 | g_object_get (source, "stats", &stats, NULL); 63 | if (stats) { 64 | gchar *sstr; 65 | 66 | sstr = gst_structure_to_string (stats); 67 | g_print ("Sender stats:\nstructure: %s\n", sstr); 68 | g_free (sstr); 69 | 70 | gst_structure_free (stats); 71 | } 72 | } 73 | 74 | /* signal callback when the media is prepared for streaming. We can get the 75 | * session manager for each of the streams and connect to some signals. */ 76 | static void 77 | media_prepared_cb (GstRTSPMedia * media) 78 | { 79 | guint i, n_streams; 80 | 81 | n_streams = gst_rtsp_media_n_streams (media); 82 | 83 | GST_INFO ("media %p is prepared and has %u streams", media, n_streams); 84 | 85 | for (i = 0; i < n_streams; i++) { 86 | GstRTSPStream *stream; 87 | GObject *session; 88 | 89 | stream = gst_rtsp_media_get_stream (media, i); 90 | if (stream == NULL) 91 | continue; 92 | 93 | session = gst_rtsp_stream_get_rtpsession (stream); 94 | GST_INFO ("watching session %p on stream %u", session, i); 95 | 96 | g_signal_connect (session, "on-ssrc-active", 97 | (GCallback) on_ssrc_active, media); 98 | g_signal_connect (session, "on-sender-ssrc-active", 99 | (GCallback) on_sender_ssrc_active, media); 100 | } 101 | } 102 | 103 | static void 104 | media_configure_cb (GstRTSPMediaFactory * factory, GstRTSPMedia * media) 105 | { 106 | /* connect our prepared signal so that we can see when this media is 107 | * prepared for streaming */ 108 | g_signal_connect (media, "prepared", (GCallback) media_prepared_cb, factory); 109 | } 110 | 111 | int 112 | main (int argc, char *argv[]) 113 | { 114 | GMainLoop *loop; 115 | GstRTSPServer *server; 116 | GstRTSPMountPoints *mounts; 117 | GstRTSPMediaFactory *factory; 118 | GOptionContext *optctx; 119 | GError *error = NULL; 120 | gchar *str; 121 | 122 | optctx = g_option_context_new (" - Test RTSP Server, MP4"); 123 | g_option_context_add_main_entries (optctx, entries, NULL); 124 | g_option_context_add_group (optctx, gst_init_get_option_group ()); 125 | if (!g_option_context_parse (optctx, &argc, &argv, &error)) { 126 | g_printerr ("Error parsing options: %s\n", error->message); 127 | g_option_context_free (optctx); 128 | g_clear_error (&error); 129 | return -1; 130 | } 131 | 132 | if (argc < 2) { 133 | g_print ("%s\n", g_option_context_get_help (optctx, TRUE, NULL)); 134 | return 1; 135 | } 136 | g_option_context_free (optctx); 137 | 138 | loop = g_main_loop_new (NULL, FALSE); 139 | 140 | /* create a server instance */ 141 | server = gst_rtsp_server_new (); 142 | g_object_set (server, "service", port, NULL); 143 | 144 | /* get the mount points for this server, every server has a default object 145 | * that be used to map uri mount points to media factories */ 146 | mounts = gst_rtsp_server_get_mount_points (server); 147 | 148 | str = g_strdup_printf ("( " 149 | "filesrc location=\"%s\" ! qtdemux name=d " 150 | "d. ! queue ! rtph264pay pt=96 name=pay0 " 151 | "d. ! queue ! rtpmp4apay pt=97 name=pay1 " ")", argv[1]); 152 | 153 | /* make a media factory for a test stream. The default media factory can use 154 | * gst-launch syntax to create pipelines. 155 | * any launch line works as long as it contains elements named pay%d. Each 156 | * element with pay%d names will be a stream */ 157 | factory = gst_rtsp_media_factory_new (); 158 | gst_rtsp_media_factory_set_launch (factory, str); 159 | g_signal_connect (factory, "media-configure", (GCallback) media_configure_cb, 160 | factory); 161 | g_free (str); 162 | 163 | /* attach the test factory to the /test url */ 164 | gst_rtsp_mount_points_add_factory (mounts, "/test", factory); 165 | 166 | /* don't need the ref to the mapper anymore */ 167 | g_object_unref (mounts); 168 | 169 | /* attach the server to the default maincontext */ 170 | gst_rtsp_server_attach (server, NULL); 171 | 172 | /* start serving */ 173 | g_print ("stream ready at rtsp://127.0.0.1:%s/test\n", port); 174 | g_main_loop_run (loop); 175 | 176 | return 0; 177 | } 178 | -------------------------------------------------------------------------------- /tests/check/gst/permissions.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2013 Sebastian Rasmussen 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | 24 | GST_START_TEST (test_permissions) 25 | { 26 | GstRTSPPermissions *perms; 27 | GstRTSPPermissions *copy; 28 | GstStructure *role_structure; 29 | 30 | perms = gst_rtsp_permissions_new (); 31 | fail_if (gst_rtsp_permissions_is_allowed (perms, "missing", "permission1")); 32 | gst_rtsp_permissions_unref (perms); 33 | 34 | perms = gst_rtsp_permissions_new (); 35 | gst_rtsp_permissions_add_role (perms, "user", 36 | "permission1", G_TYPE_BOOLEAN, TRUE, 37 | "permission2", G_TYPE_BOOLEAN, FALSE, NULL); 38 | fail_unless (gst_rtsp_permissions_is_allowed (perms, "user", "permission1")); 39 | fail_if (gst_rtsp_permissions_is_allowed (perms, "user", "permission2")); 40 | fail_if (gst_rtsp_permissions_is_allowed (perms, "user", "missing")); 41 | fail_if (gst_rtsp_permissions_is_allowed (perms, "missing", "permission1")); 42 | copy = GST_RTSP_PERMISSIONS (gst_mini_object_copy (GST_MINI_OBJECT (perms))); 43 | gst_rtsp_permissions_unref (perms); 44 | fail_unless (gst_rtsp_permissions_is_allowed (copy, "user", "permission1")); 45 | fail_if (gst_rtsp_permissions_is_allowed (copy, "user", "permission2")); 46 | gst_rtsp_permissions_unref (copy); 47 | 48 | perms = gst_rtsp_permissions_new (); 49 | gst_rtsp_permissions_add_role (perms, "admin", 50 | "permission1", G_TYPE_BOOLEAN, TRUE, 51 | "permission2", G_TYPE_BOOLEAN, TRUE, NULL); 52 | gst_rtsp_permissions_add_role (perms, "user", 53 | "permission1", G_TYPE_BOOLEAN, TRUE, 54 | "permission2", G_TYPE_BOOLEAN, FALSE, NULL); 55 | fail_unless (gst_rtsp_permissions_is_allowed (perms, "admin", "permission1")); 56 | fail_unless (gst_rtsp_permissions_is_allowed (perms, "admin", "permission2")); 57 | fail_unless (gst_rtsp_permissions_is_allowed (perms, "user", "permission1")); 58 | fail_if (gst_rtsp_permissions_is_allowed (perms, "user", "permission2")); 59 | gst_rtsp_permissions_unref (perms); 60 | 61 | perms = gst_rtsp_permissions_new (); 62 | gst_rtsp_permissions_add_role (perms, "user", 63 | "permission1", G_TYPE_BOOLEAN, TRUE, 64 | "permission2", G_TYPE_BOOLEAN, FALSE, NULL); 65 | fail_unless (gst_rtsp_permissions_is_allowed (perms, "user", "permission1")); 66 | fail_if (gst_rtsp_permissions_is_allowed (perms, "user", "permission2")); 67 | gst_rtsp_permissions_add_role (perms, "user", 68 | "permission1", G_TYPE_BOOLEAN, FALSE, 69 | "permission2", G_TYPE_BOOLEAN, TRUE, NULL); 70 | fail_if (gst_rtsp_permissions_is_allowed (perms, "user", "permission1")); 71 | fail_unless (gst_rtsp_permissions_is_allowed (perms, "user", "permission2")); 72 | gst_rtsp_permissions_unref (perms); 73 | 74 | perms = gst_rtsp_permissions_new (); 75 | gst_rtsp_permissions_add_role (perms, "admin", 76 | "permission1", G_TYPE_BOOLEAN, TRUE, 77 | "permission2", G_TYPE_BOOLEAN, TRUE, NULL); 78 | gst_rtsp_permissions_add_role (perms, "user", 79 | "permission1", G_TYPE_BOOLEAN, TRUE, 80 | "permission2", G_TYPE_BOOLEAN, FALSE, NULL); 81 | fail_unless (gst_rtsp_permissions_is_allowed (perms, "admin", "permission1")); 82 | fail_unless (gst_rtsp_permissions_is_allowed (perms, "admin", "permission2")); 83 | fail_unless (gst_rtsp_permissions_is_allowed (perms, "user", "permission1")); 84 | fail_if (gst_rtsp_permissions_is_allowed (perms, "user", "permission2")); 85 | gst_rtsp_permissions_remove_role (perms, "user"); 86 | fail_unless (gst_rtsp_permissions_is_allowed (perms, "admin", "permission1")); 87 | fail_unless (gst_rtsp_permissions_is_allowed (perms, "admin", "permission2")); 88 | fail_if (gst_rtsp_permissions_is_allowed (perms, "user", "permission1")); 89 | fail_if (gst_rtsp_permissions_is_allowed (perms, "user", "permission2")); 90 | 91 | /* _add_permission_for_role() should overwrite existing or create new role */ 92 | fail_unless (gst_rtsp_permissions_is_allowed (perms, "admin", "permission1")); 93 | gst_rtsp_permissions_add_permission_for_role (perms, "admin", "permission1", 94 | FALSE); 95 | fail_if (gst_rtsp_permissions_is_allowed (perms, "admin", "permission1")); 96 | 97 | fail_if (gst_rtsp_permissions_is_allowed (perms, "tester", "permission1")); 98 | gst_rtsp_permissions_add_permission_for_role (perms, "tester", "permission1", 99 | TRUE); 100 | fail_unless (gst_rtsp_permissions_is_allowed (perms, "tester", 101 | "permission1")); 102 | gst_rtsp_permissions_add_permission_for_role (perms, "tester", "permission1", 103 | FALSE); 104 | fail_if (gst_rtsp_permissions_is_allowed (perms, "tester", "permission1")); 105 | gst_rtsp_permissions_add_permission_for_role (perms, "tester", "permission2", 106 | TRUE); 107 | fail_unless (gst_rtsp_permissions_is_allowed (perms, "tester", 108 | "permission2")); 109 | fail_if (gst_rtsp_permissions_is_allowed (perms, "tester", "permission3")); 110 | 111 | gst_rtsp_permissions_add_role_empty (perms, "noone"); 112 | fail_if (gst_rtsp_permissions_is_allowed (perms, "noone", "permission1")); 113 | 114 | role_structure = gst_structure_new ("tester", "permission1", G_TYPE_BOOLEAN, 115 | TRUE, NULL); 116 | gst_rtsp_permissions_add_role_from_structure (perms, role_structure); 117 | gst_structure_free (role_structure); 118 | fail_unless (gst_rtsp_permissions_is_allowed (perms, "tester", 119 | "permission1")); 120 | fail_if (gst_rtsp_permissions_is_allowed (perms, "tester", "permission2")); 121 | 122 | gst_rtsp_permissions_unref (perms); 123 | } 124 | 125 | GST_END_TEST; 126 | 127 | static Suite * 128 | rtsppermissions_suite (void) 129 | { 130 | Suite *s = suite_create ("rtsppermissions"); 131 | TCase *tc = tcase_create ("general"); 132 | 133 | suite_add_tcase (s, tc); 134 | tcase_set_timeout (tc, 20); 135 | tcase_add_test (tc, test_permissions); 136 | 137 | return s; 138 | } 139 | 140 | GST_CHECK_MAIN (rtsppermissions); 141 | -------------------------------------------------------------------------------- /examples/test-video.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | 24 | /* define this if you want the resource to only be available when using 25 | * user/password as the password */ 26 | #undef WITH_AUTH 27 | 28 | /* define this if you want the server to use TLS (it will also need WITH_AUTH 29 | * to be defined) */ 30 | #undef WITH_TLS 31 | 32 | /* this timeout is periodically run to clean up the expired sessions from the 33 | * pool. This needs to be run explicitly currently but might be done 34 | * automatically as part of the mainloop. */ 35 | static gboolean 36 | timeout (GstRTSPServer * server) 37 | { 38 | GstRTSPSessionPool *pool; 39 | 40 | pool = gst_rtsp_server_get_session_pool (server); 41 | gst_rtsp_session_pool_cleanup (pool); 42 | g_object_unref (pool); 43 | 44 | return TRUE; 45 | } 46 | 47 | int 48 | main (int argc, char *argv[]) 49 | { 50 | GMainLoop *loop; 51 | GstRTSPServer *server; 52 | GstRTSPMountPoints *mounts; 53 | GstRTSPMediaFactory *factory; 54 | #ifdef WITH_AUTH 55 | GstRTSPAuth *auth; 56 | GstRTSPToken *token; 57 | gchar *basic; 58 | GstRTSPPermissions *permissions; 59 | #endif 60 | #ifdef WITH_TLS 61 | GTlsCertificate *cert; 62 | GError *error = NULL; 63 | #endif 64 | 65 | gst_init (&argc, &argv); 66 | 67 | loop = g_main_loop_new (NULL, FALSE); 68 | 69 | /* create a server instance */ 70 | server = gst_rtsp_server_new (); 71 | 72 | #ifdef WITH_AUTH 73 | /* make a new authentication manager. it can be added to control access to all 74 | * the factories on the server or on individual factories. */ 75 | auth = gst_rtsp_auth_new (); 76 | #ifdef WITH_TLS 77 | cert = g_tls_certificate_new_from_pem ("-----BEGIN CERTIFICATE-----" 78 | "MIICJjCCAY+gAwIBAgIBBzANBgkqhkiG9w0BAQUFADCBhjETMBEGCgmSJomT8ixk" 79 | "ARkWA0NPTTEXMBUGCgmSJomT8ixkARkWB0VYQU1QTEUxHjAcBgNVBAsTFUNlcnRp" 80 | "ZmljYXRlIEF1dGhvcml0eTEXMBUGA1UEAxMOY2EuZXhhbXBsZS5jb20xHTAbBgkq" 81 | "hkiG9w0BCQEWDmNhQGV4YW1wbGUuY29tMB4XDTExMDExNzE5NDcxN1oXDTIxMDEx" 82 | "NDE5NDcxN1owSzETMBEGCgmSJomT8ixkARkWA0NPTTEXMBUGCgmSJomT8ixkARkW" 83 | "B0VYQU1QTEUxGzAZBgNVBAMTEnNlcnZlci5leGFtcGxlLmNvbTBcMA0GCSqGSIb3" 84 | "DQEBAQUAA0sAMEgCQQDYScTxk55XBmbDM9zzwO+grVySE4rudWuzH2PpObIonqbf" 85 | "hRoAalKVluG9jvbHI81eXxCdSObv1KBP1sbN5RzpAgMBAAGjIjAgMAkGA1UdEwQC" 86 | "MAAwEwYDVR0lBAwwCgYIKwYBBQUHAwEwDQYJKoZIhvcNAQEFBQADgYEAYx6fMqT1" 87 | "Gvo0jq88E8mc+bmp4LfXD4wJ7KxYeadQxt75HFRpj4FhFO3DOpVRFgzHlOEo3Fwk" 88 | "PZOKjvkT0cbcoEq5whLH25dHoQxGoVQgFyAP5s+7Vp5AlHh8Y/vAoXeEVyy/RCIH" 89 | "QkhUlAflfDMcrrYjsmwoOPSjhx6Mm/AopX4=" 90 | "-----END CERTIFICATE-----" 91 | "-----BEGIN PRIVATE KEY-----" 92 | "MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEA2EnE8ZOeVwZmwzPc" 93 | "88DvoK1ckhOK7nVrsx9j6TmyKJ6m34UaAGpSlZbhvY72xyPNXl8QnUjm79SgT9bG" 94 | "zeUc6QIDAQABAkBRFJZ32VbqWMP9OVwDJLiwC01AlYLnka0mIQZbT/2xq9dUc9GW" 95 | "U3kiVw4lL8v/+sPjtTPCYYdzHHOyDen6znVhAiEA9qJT7BtQvRxCvGrAhr9MS022" 96 | "tTdPbW829BoUtIeH64cCIQDggG5i48v7HPacPBIH1RaSVhXl8qHCpQD3qrIw3FMw" 97 | "DwIga8PqH5Sf5sHedy2+CiK0V4MRfoU4c3zQ6kArI+bEgSkCIQCLA1vXBiE31B5s" 98 | "bdHoYa1BXebfZVd+1Hd95IfEM5mbRwIgSkDuQwV55BBlvWph3U8wVIMIb4GStaH8" 99 | "W535W8UBbEg=" "-----END PRIVATE KEY-----", -1, &error); 100 | if (cert == NULL) { 101 | g_printerr ("failed to parse PEM: %s\n", error->message); 102 | return -1; 103 | } 104 | gst_rtsp_auth_set_tls_certificate (auth, cert); 105 | g_object_unref (cert); 106 | #endif 107 | 108 | /* make user token */ 109 | token = 110 | gst_rtsp_token_new (GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING, 111 | "user", NULL); 112 | basic = gst_rtsp_auth_make_basic ("user", "password"); 113 | gst_rtsp_auth_add_basic (auth, basic, token); 114 | g_free (basic); 115 | gst_rtsp_token_unref (token); 116 | 117 | /* configure in the server */ 118 | gst_rtsp_server_set_auth (server, auth); 119 | #endif 120 | 121 | /* get the mount points for this server, every server has a default object 122 | * that be used to map uri mount points to media factories */ 123 | mounts = gst_rtsp_server_get_mount_points (server); 124 | 125 | /* make a media factory for a test stream. The default media factory can use 126 | * gst-launch syntax to create pipelines. 127 | * any launch line works as long as it contains elements named pay%d. Each 128 | * element with pay%d names will be a stream */ 129 | factory = gst_rtsp_media_factory_new (); 130 | gst_rtsp_media_factory_set_launch (factory, "( " 131 | "videotestsrc ! video/x-raw,width=352,height=288,framerate=15/1 ! " 132 | "x264enc ! rtph264pay name=pay0 pt=96 " 133 | "audiotestsrc ! audio/x-raw,rate=8000 ! " 134 | "alawenc ! rtppcmapay name=pay1 pt=97 " ")"); 135 | #ifdef WITH_AUTH 136 | /* add permissions for the user media role */ 137 | permissions = gst_rtsp_permissions_new (); 138 | gst_rtsp_permissions_add_role (permissions, "user", 139 | GST_RTSP_PERM_MEDIA_FACTORY_ACCESS, G_TYPE_BOOLEAN, TRUE, 140 | GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT, G_TYPE_BOOLEAN, TRUE, NULL); 141 | gst_rtsp_media_factory_set_permissions (factory, permissions); 142 | gst_rtsp_permissions_unref (permissions); 143 | #ifdef WITH_TLS 144 | gst_rtsp_media_factory_set_profiles (factory, GST_RTSP_PROFILE_SAVP); 145 | #endif 146 | #endif 147 | 148 | /* attach the test factory to the /test url */ 149 | gst_rtsp_mount_points_add_factory (mounts, "/test", factory); 150 | 151 | /* don't need the ref to the mapper anymore */ 152 | g_object_unref (mounts); 153 | 154 | /* attach the server to the default maincontext */ 155 | if (gst_rtsp_server_attach (server, NULL) == 0) 156 | goto failed; 157 | 158 | /* add a timeout for the session cleanup */ 159 | g_timeout_add_seconds (2, (GSourceFunc) timeout, server); 160 | 161 | /* start serving, this never stops */ 162 | #ifdef WITH_TLS 163 | g_print ("stream ready at rtsps://127.0.0.1:8554/test\n"); 164 | #else 165 | g_print ("stream ready at rtsp://127.0.0.1:8554/test\n"); 166 | #endif 167 | g_main_loop_run (loop); 168 | 169 | return 0; 170 | 171 | /* ERRORS */ 172 | failed: 173 | { 174 | g_print ("failed to attach the server\n"); 175 | return -1; 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /gst/rtsp-server/rtsp-session-pool.h: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #ifndef __GST_RTSP_SESSION_POOL_H__ 23 | #define __GST_RTSP_SESSION_POOL_H__ 24 | 25 | #include "rtsp-server-prelude.h" 26 | 27 | G_BEGIN_DECLS 28 | 29 | typedef struct _GstRTSPSessionPool GstRTSPSessionPool; 30 | typedef struct _GstRTSPSessionPoolClass GstRTSPSessionPoolClass; 31 | typedef struct _GstRTSPSessionPoolPrivate GstRTSPSessionPoolPrivate; 32 | 33 | #include "rtsp-session.h" 34 | 35 | #define GST_TYPE_RTSP_SESSION_POOL (gst_rtsp_session_pool_get_type ()) 36 | #define GST_IS_RTSP_SESSION_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_RTSP_SESSION_POOL)) 37 | #define GST_IS_RTSP_SESSION_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_RTSP_SESSION_POOL)) 38 | #define GST_RTSP_SESSION_POOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RTSP_SESSION_POOL, GstRTSPSessionPoolClass)) 39 | #define GST_RTSP_SESSION_POOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_RTSP_SESSION_POOL, GstRTSPSessionPool)) 40 | #define GST_RTSP_SESSION_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_RTSP_SESSION_POOL, GstRTSPSessionPoolClass)) 41 | #define GST_RTSP_SESSION_POOL_CAST(obj) ((GstRTSPSessionPool*)(obj)) 42 | #define GST_RTSP_SESSION_POOL_CLASS_CAST(klass) ((GstRTSPSessionPoolClass*)(klass)) 43 | 44 | /** 45 | * GstRTSPSessionPool: 46 | * 47 | * An object that keeps track of the active sessions. This object is usually 48 | * attached to a #GstRTSPServer object to manage the sessions in that server. 49 | */ 50 | struct _GstRTSPSessionPool { 51 | GObject parent; 52 | 53 | /*< private >*/ 54 | GstRTSPSessionPoolPrivate *priv; 55 | gpointer _gst_reserved[GST_PADDING]; 56 | }; 57 | 58 | /** 59 | * GstRTSPSessionPoolClass: 60 | * @create_session_id: create a new random session id. Subclasses can create 61 | * custom session ids and should not check if the session exists. 62 | * @create_session: make a new session object. 63 | * @session_removed: a session was removed from the pool 64 | */ 65 | struct _GstRTSPSessionPoolClass { 66 | GObjectClass parent_class; 67 | 68 | gchar * (*create_session_id) (GstRTSPSessionPool *pool); 69 | GstRTSPSession * (*create_session) (GstRTSPSessionPool *pool, const gchar *id); 70 | 71 | /* signals */ 72 | void (*session_removed) (GstRTSPSessionPool *pool, 73 | GstRTSPSession *session); 74 | 75 | /*< private >*/ 76 | gpointer _gst_reserved[GST_PADDING_LARGE - 1]; 77 | }; 78 | 79 | /** 80 | * GstRTSPSessionPoolFunc: 81 | * @pool: a #GstRTSPSessionPool object 82 | * @user_data: user data that has been given when registering the handler 83 | * 84 | * The function that will be called from the GSource watch on the session pool. 85 | * 86 | * The function will be called when the pool must be cleaned up because one or 87 | * more sessions timed out. 88 | * 89 | * Returns: %FALSE if the source should be removed. 90 | */ 91 | typedef gboolean (*GstRTSPSessionPoolFunc) (GstRTSPSessionPool *pool, gpointer user_data); 92 | 93 | /** 94 | * GstRTSPSessionPoolFilterFunc: 95 | * @pool: a #GstRTSPSessionPool object 96 | * @session: a #GstRTSPSession in @pool 97 | * @user_data: user data that has been given to gst_rtsp_session_pool_filter() 98 | * 99 | * This function will be called by the gst_rtsp_session_pool_filter(). An 100 | * implementation should return a value of #GstRTSPFilterResult. 101 | * 102 | * When this function returns #GST_RTSP_FILTER_REMOVE, @session will be removed 103 | * from @pool. 104 | * 105 | * A return value of #GST_RTSP_FILTER_KEEP will leave @session untouched in 106 | * @pool. 107 | * 108 | * A value of GST_RTSP_FILTER_REF will add @session to the result #GList of 109 | * gst_rtsp_session_pool_filter(). 110 | * 111 | * Returns: a #GstRTSPFilterResult. 112 | */ 113 | typedef GstRTSPFilterResult (*GstRTSPSessionPoolFilterFunc) (GstRTSPSessionPool *pool, 114 | GstRTSPSession *session, 115 | gpointer user_data); 116 | 117 | 118 | GST_RTSP_SERVER_API 119 | GType gst_rtsp_session_pool_get_type (void); 120 | 121 | /* creating a session pool */ 122 | 123 | GST_RTSP_SERVER_API 124 | GstRTSPSessionPool * gst_rtsp_session_pool_new (void); 125 | 126 | /* counting sessions */ 127 | 128 | GST_RTSP_SERVER_API 129 | void gst_rtsp_session_pool_set_max_sessions (GstRTSPSessionPool *pool, guint max); 130 | 131 | GST_RTSP_SERVER_API 132 | guint gst_rtsp_session_pool_get_max_sessions (GstRTSPSessionPool *pool); 133 | 134 | GST_RTSP_SERVER_API 135 | guint gst_rtsp_session_pool_get_n_sessions (GstRTSPSessionPool *pool); 136 | 137 | /* managing sessions */ 138 | 139 | GST_RTSP_SERVER_API 140 | GstRTSPSession * gst_rtsp_session_pool_create (GstRTSPSessionPool *pool); 141 | 142 | GST_RTSP_SERVER_API 143 | GstRTSPSession * gst_rtsp_session_pool_find (GstRTSPSessionPool *pool, 144 | const gchar *sessionid); 145 | 146 | GST_RTSP_SERVER_API 147 | gboolean gst_rtsp_session_pool_remove (GstRTSPSessionPool *pool, 148 | GstRTSPSession *sess); 149 | 150 | /* perform session maintenance */ 151 | 152 | GST_RTSP_SERVER_API 153 | GList * gst_rtsp_session_pool_filter (GstRTSPSessionPool *pool, 154 | GstRTSPSessionPoolFilterFunc func, 155 | gpointer user_data); 156 | 157 | GST_RTSP_SERVER_API 158 | guint gst_rtsp_session_pool_cleanup (GstRTSPSessionPool *pool); 159 | 160 | GST_RTSP_SERVER_API 161 | GSource * gst_rtsp_session_pool_create_watch (GstRTSPSessionPool *pool); 162 | 163 | #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC 164 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstRTSPSessionPool, gst_object_unref) 165 | #endif 166 | 167 | G_END_DECLS 168 | 169 | #endif /* __GST_RTSP_SESSION_POOL_H__ */ 170 | -------------------------------------------------------------------------------- /gst/rtsp-server/rtsp-thread-pool.h: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2010 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #ifndef __GST_RTSP_THREAD_POOL_H__ 23 | #define __GST_RTSP_THREAD_POOL_H__ 24 | 25 | typedef struct _GstRTSPThread GstRTSPThread; 26 | typedef struct _GstRTSPThreadPool GstRTSPThreadPool; 27 | typedef struct _GstRTSPThreadPoolClass GstRTSPThreadPoolClass; 28 | typedef struct _GstRTSPThreadPoolPrivate GstRTSPThreadPoolPrivate; 29 | 30 | #include "rtsp-client.h" 31 | 32 | G_BEGIN_DECLS 33 | 34 | #define GST_TYPE_RTSP_THREAD_POOL (gst_rtsp_thread_pool_get_type ()) 35 | #define GST_IS_RTSP_THREAD_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_RTSP_THREAD_POOL)) 36 | #define GST_IS_RTSP_THREAD_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_RTSP_THREAD_POOL)) 37 | #define GST_RTSP_THREAD_POOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RTSP_THREAD_POOL, GstRTSPThreadPoolClass)) 38 | #define GST_RTSP_THREAD_POOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_RTSP_THREAD_POOL, GstRTSPThreadPool)) 39 | #define GST_RTSP_THREAD_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_RTSP_THREAD_POOL, GstRTSPThreadPoolClass)) 40 | #define GST_RTSP_THREAD_POOL_CAST(obj) ((GstRTSPThreadPool*)(obj)) 41 | #define GST_RTSP_THREAD_POOL_CLASS_CAST(klass) ((GstRTSPThreadPoolClass*)(klass)) 42 | 43 | GST_RTSP_SERVER_API 44 | GType gst_rtsp_thread_get_type (void); 45 | 46 | #define GST_TYPE_RTSP_THREAD (gst_rtsp_thread_get_type ()) 47 | #define GST_IS_RTSP_THREAD(obj) (GST_IS_MINI_OBJECT_TYPE (obj, GST_TYPE_RTSP_THREAD)) 48 | #define GST_RTSP_THREAD_CAST(obj) ((GstRTSPThread*)(obj)) 49 | #define GST_RTSP_THREAD(obj) (GST_RTSP_THREAD_CAST(obj)) 50 | 51 | /** 52 | * GstRTSPThreadType: 53 | * @GST_RTSP_THREAD_TYPE_CLIENT: a thread to handle the client communication 54 | * @GST_RTSP_THREAD_TYPE_MEDIA: a thread to handle media 55 | * 56 | * Different thread types 57 | */ 58 | typedef enum 59 | { 60 | GST_RTSP_THREAD_TYPE_CLIENT, 61 | GST_RTSP_THREAD_TYPE_MEDIA 62 | } GstRTSPThreadType; 63 | 64 | /** 65 | * GstRTSPThread: 66 | * @mini_object: parent #GstMiniObject 67 | * @type: the thread type 68 | * @context: a #GMainContext 69 | * @loop: a #GMainLoop 70 | * 71 | * Structure holding info about a mainloop running in a thread 72 | */ 73 | struct _GstRTSPThread { 74 | GstMiniObject mini_object; 75 | 76 | GstRTSPThreadType type; 77 | GMainContext *context; 78 | GMainLoop *loop; 79 | }; 80 | 81 | GST_RTSP_SERVER_API 82 | GstRTSPThread * gst_rtsp_thread_new (GstRTSPThreadType type); 83 | 84 | GST_RTSP_SERVER_API 85 | gboolean gst_rtsp_thread_reuse (GstRTSPThread * thread); 86 | 87 | GST_RTSP_SERVER_API 88 | void gst_rtsp_thread_stop (GstRTSPThread * thread); 89 | 90 | /** 91 | * gst_rtsp_thread_ref: 92 | * @thread: The thread to refcount 93 | * 94 | * Increase the refcount of this thread. 95 | * 96 | * Returns: (transfer full): @thread (for convenience when doing assignments) 97 | */ 98 | static inline GstRTSPThread * 99 | gst_rtsp_thread_ref (GstRTSPThread * thread) 100 | { 101 | return (GstRTSPThread *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (thread)); 102 | } 103 | 104 | /** 105 | * gst_rtsp_thread_unref: 106 | * @thread: (transfer full): the thread to refcount 107 | * 108 | * Decrease the refcount of an thread, freeing it if the refcount reaches 0. 109 | */ 110 | static inline void 111 | gst_rtsp_thread_unref (GstRTSPThread * thread) 112 | { 113 | gst_mini_object_unref (GST_MINI_OBJECT_CAST (thread)); 114 | } 115 | 116 | /** 117 | * GstRTSPThreadPool: 118 | * 119 | * The thread pool structure. 120 | */ 121 | struct _GstRTSPThreadPool { 122 | GObject parent; 123 | 124 | /*< private >*/ 125 | GstRTSPThreadPoolPrivate *priv; 126 | gpointer _gst_reserved[GST_PADDING]; 127 | }; 128 | 129 | /** 130 | * GstRTSPThreadPoolClass: 131 | * @pool: a #GThreadPool used internally 132 | * @get_thread: this function should make or reuse an existing thread that runs 133 | * a mainloop. 134 | * @configure_thread: configure a thread object. this vmethod is called when 135 | * a new thread has been created and should be configured. 136 | * @thread_enter: called from the thread when it is entered 137 | * @thread_leave: called from the thread when it is left 138 | * 139 | * Class for managing threads. 140 | */ 141 | struct _GstRTSPThreadPoolClass { 142 | GObjectClass parent_class; 143 | 144 | GThreadPool *pool; 145 | 146 | GstRTSPThread * (*get_thread) (GstRTSPThreadPool *pool, 147 | GstRTSPThreadType type, 148 | GstRTSPContext *ctx); 149 | void (*configure_thread) (GstRTSPThreadPool *pool, 150 | GstRTSPThread * thread, 151 | GstRTSPContext *ctx); 152 | 153 | void (*thread_enter) (GstRTSPThreadPool *pool, 154 | GstRTSPThread *thread); 155 | void (*thread_leave) (GstRTSPThreadPool *pool, 156 | GstRTSPThread *thread); 157 | 158 | /*< private >*/ 159 | gpointer _gst_reserved[GST_PADDING]; 160 | }; 161 | 162 | GST_RTSP_SERVER_API 163 | GType gst_rtsp_thread_pool_get_type (void); 164 | 165 | GST_RTSP_SERVER_API 166 | GstRTSPThreadPool * gst_rtsp_thread_pool_new (void); 167 | 168 | GST_RTSP_SERVER_API 169 | void gst_rtsp_thread_pool_set_max_threads (GstRTSPThreadPool * pool, gint max_threads); 170 | 171 | GST_RTSP_SERVER_API 172 | gint gst_rtsp_thread_pool_get_max_threads (GstRTSPThreadPool * pool); 173 | 174 | GST_RTSP_SERVER_API 175 | GstRTSPThread * gst_rtsp_thread_pool_get_thread (GstRTSPThreadPool *pool, 176 | GstRTSPThreadType type, 177 | GstRTSPContext *ctx); 178 | 179 | GST_RTSP_SERVER_API 180 | void gst_rtsp_thread_pool_cleanup (void); 181 | #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC 182 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstRTSPThread, gst_rtsp_thread_unref) 183 | #endif 184 | 185 | #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC 186 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstRTSPThreadPool, gst_object_unref) 187 | #endif 188 | 189 | G_END_DECLS 190 | 191 | #endif /* __GST_RTSP_THREAD_POOL_H__ */ 192 | -------------------------------------------------------------------------------- /examples/test-auth.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | 24 | static gboolean 25 | remove_func (GstRTSPSessionPool * pool, GstRTSPSession * session, 26 | GstRTSPServer * server) 27 | { 28 | return GST_RTSP_FILTER_REMOVE; 29 | } 30 | 31 | static gboolean 32 | remove_sessions (GstRTSPServer * server) 33 | { 34 | GstRTSPSessionPool *pool; 35 | 36 | g_print ("removing all sessions\n"); 37 | pool = gst_rtsp_server_get_session_pool (server); 38 | gst_rtsp_session_pool_filter (pool, 39 | (GstRTSPSessionPoolFilterFunc) remove_func, server); 40 | g_object_unref (pool); 41 | 42 | return FALSE; 43 | } 44 | 45 | static gboolean 46 | timeout (GstRTSPServer * server) 47 | { 48 | GstRTSPSessionPool *pool; 49 | 50 | pool = gst_rtsp_server_get_session_pool (server); 51 | gst_rtsp_session_pool_cleanup (pool); 52 | g_object_unref (pool); 53 | 54 | return TRUE; 55 | } 56 | 57 | int 58 | main (int argc, char *argv[]) 59 | { 60 | GMainLoop *loop; 61 | GstRTSPServer *server; 62 | GstRTSPMountPoints *mounts; 63 | GstRTSPMediaFactory *factory; 64 | GstRTSPAuth *auth; 65 | GstRTSPToken *token; 66 | gchar *basic; 67 | 68 | gst_init (&argc, &argv); 69 | 70 | loop = g_main_loop_new (NULL, FALSE); 71 | 72 | /* create a server instance */ 73 | server = gst_rtsp_server_new (); 74 | 75 | /* get the mounts for this server, every server has a default mapper object 76 | * that be used to map uri mount points to media factories */ 77 | mounts = gst_rtsp_server_get_mount_points (server); 78 | 79 | 80 | /* make a media factory for a test stream. The default media factory can use 81 | * gst-launch syntax to create pipelines. 82 | * any launch line works as long as it contains elements named pay%d. Each 83 | * element with pay%d names will be a stream */ 84 | factory = gst_rtsp_media_factory_new (); 85 | gst_rtsp_media_factory_set_launch (factory, "( " 86 | "videotestsrc ! video/x-raw,width=352,height=288,framerate=15/1 ! " 87 | "x264enc ! rtph264pay name=pay0 pt=96 " 88 | "audiotestsrc ! audio/x-raw,rate=8000 ! " 89 | "alawenc ! rtppcmapay name=pay1 pt=97 " ")"); 90 | /* attach the test factory to the /test url */ 91 | gst_rtsp_mount_points_add_factory (mounts, "/test", factory); 92 | 93 | /* allow user and admin to access this resource */ 94 | gst_rtsp_media_factory_add_role (factory, "user", 95 | GST_RTSP_PERM_MEDIA_FACTORY_ACCESS, G_TYPE_BOOLEAN, TRUE, 96 | GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT, G_TYPE_BOOLEAN, TRUE, NULL); 97 | gst_rtsp_media_factory_add_role (factory, "admin", 98 | GST_RTSP_PERM_MEDIA_FACTORY_ACCESS, G_TYPE_BOOLEAN, TRUE, 99 | GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT, G_TYPE_BOOLEAN, TRUE, NULL); 100 | /* admin2 can look at the media but not construct so he gets a 101 | * 401 Unauthorized */ 102 | gst_rtsp_media_factory_add_role (factory, "admin2", 103 | GST_RTSP_PERM_MEDIA_FACTORY_ACCESS, G_TYPE_BOOLEAN, TRUE, 104 | GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT, G_TYPE_BOOLEAN, FALSE, NULL); 105 | /* Anonymous user can do the same things as admin2 on this resource */ 106 | gst_rtsp_media_factory_add_role (factory, "anonymous", 107 | GST_RTSP_PERM_MEDIA_FACTORY_ACCESS, G_TYPE_BOOLEAN, TRUE, 108 | GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT, G_TYPE_BOOLEAN, FALSE, NULL); 109 | 110 | /* make another factory */ 111 | factory = gst_rtsp_media_factory_new (); 112 | gst_rtsp_media_factory_set_launch (factory, "( " 113 | "videotestsrc ! video/x-raw,width=352,height=288,framerate=30/1 ! " 114 | "x264enc ! rtph264pay name=pay0 pt=96 )"); 115 | /* attach the test factory to the /test url */ 116 | gst_rtsp_mount_points_add_factory (mounts, "/test2", factory); 117 | 118 | /* allow admin2 to access this resource */ 119 | /* user and admin have no permissions so they can't even see the 120 | * media and get a 404 Not Found */ 121 | gst_rtsp_media_factory_add_role (factory, "admin2", 122 | GST_RTSP_PERM_MEDIA_FACTORY_ACCESS, G_TYPE_BOOLEAN, TRUE, 123 | GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT, G_TYPE_BOOLEAN, TRUE, NULL); 124 | 125 | /* don't need the ref to the mapper anymore */ 126 | g_object_unref (mounts); 127 | 128 | /* make a new authentication manager */ 129 | auth = gst_rtsp_auth_new (); 130 | 131 | /* make default token, it has no permissions */ 132 | token = 133 | gst_rtsp_token_new (GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING, 134 | "anonymous", NULL); 135 | gst_rtsp_auth_set_default_token (auth, token); 136 | gst_rtsp_token_unref (token); 137 | 138 | /* make user token */ 139 | token = 140 | gst_rtsp_token_new (GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING, 141 | "user", NULL); 142 | basic = gst_rtsp_auth_make_basic ("user", "password"); 143 | gst_rtsp_auth_add_basic (auth, basic, token); 144 | g_free (basic); 145 | gst_rtsp_token_unref (token); 146 | 147 | /* make admin token */ 148 | token = 149 | gst_rtsp_token_new (GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING, 150 | "admin", NULL); 151 | basic = gst_rtsp_auth_make_basic ("admin", "power"); 152 | gst_rtsp_auth_add_basic (auth, basic, token); 153 | g_free (basic); 154 | gst_rtsp_token_unref (token); 155 | 156 | /* make admin2 token */ 157 | token = 158 | gst_rtsp_token_new (GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING, 159 | "admin2", NULL); 160 | basic = gst_rtsp_auth_make_basic ("admin2", "power2"); 161 | gst_rtsp_auth_add_basic (auth, basic, token); 162 | g_free (basic); 163 | gst_rtsp_token_unref (token); 164 | 165 | /* set as the server authentication manager */ 166 | gst_rtsp_server_set_auth (server, auth); 167 | g_object_unref (auth); 168 | 169 | /* attach the server to the default maincontext */ 170 | if (gst_rtsp_server_attach (server, NULL) == 0) 171 | goto failed; 172 | 173 | g_timeout_add_seconds (2, (GSourceFunc) timeout, server); 174 | g_timeout_add_seconds (10, (GSourceFunc) remove_sessions, server); 175 | 176 | /* start serving */ 177 | g_print ("stream with user:password ready at rtsp://127.0.0.1:8554/test\n"); 178 | g_print ("stream with admin:power ready at rtsp://127.0.0.1:8554/test\n"); 179 | g_print ("stream with admin2:power2 ready at rtsp://127.0.0.1:8554/test2\n"); 180 | g_main_loop_run (loop); 181 | 182 | return 0; 183 | 184 | /* ERRORS */ 185 | failed: 186 | { 187 | g_print ("failed to attach the server\n"); 188 | return -1; 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /gst/rtsp-server/rtsp-onvif-client.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2017 Sebastian Dröge 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | #include "config.h" 22 | #endif 23 | 24 | #include 25 | 26 | #include "rtsp-onvif-client.h" 27 | #include "rtsp-onvif-server.h" 28 | #include "rtsp-onvif-media-factory.h" 29 | 30 | G_DEFINE_TYPE (GstRTSPOnvifClient, gst_rtsp_onvif_client, GST_TYPE_RTSP_CLIENT); 31 | 32 | static gchar * 33 | gst_rtsp_onvif_client_check_requirements (GstRTSPClient * client, 34 | GstRTSPContext * ctx, gchar ** requirements) 35 | { 36 | GstRTSPMountPoints *mount_points = NULL; 37 | GstRTSPMediaFactory *factory = NULL; 38 | gchar *path = NULL; 39 | gboolean has_backchannel = FALSE; 40 | gboolean has_replay = FALSE; 41 | GString *unsupported = g_string_new (""); 42 | 43 | while (*requirements) { 44 | if (strcmp (*requirements, GST_RTSP_ONVIF_BACKCHANNEL_REQUIREMENT) == 0) { 45 | has_backchannel = TRUE; 46 | } else if (strcmp (*requirements, GST_RTSP_ONVIF_REPLAY_REQUIREMENT) == 0) { 47 | has_replay = TRUE; 48 | } else { 49 | if (unsupported->len) 50 | g_string_append (unsupported, ", "); 51 | g_string_append (unsupported, *requirements); 52 | } 53 | requirements++; 54 | } 55 | 56 | if (unsupported->len) 57 | goto out; 58 | 59 | mount_points = gst_rtsp_client_get_mount_points (client); 60 | if (!(path = gst_rtsp_mount_points_make_path (mount_points, ctx->uri))) 61 | goto out; 62 | 63 | if (!(factory = gst_rtsp_mount_points_match (mount_points, path, NULL))) 64 | goto out; 65 | 66 | if (has_backchannel && !GST_IS_RTSP_ONVIF_MEDIA_FACTORY (factory)) { 67 | if (unsupported->len) 68 | g_string_append (unsupported, ", "); 69 | g_string_append (unsupported, GST_RTSP_ONVIF_BACKCHANNEL_REQUIREMENT); 70 | } else if (has_backchannel) { 71 | GstRTSPOnvifMediaFactory *onvif_factory = 72 | GST_RTSP_ONVIF_MEDIA_FACTORY (factory); 73 | 74 | if (!gst_rtsp_onvif_media_factory_has_backchannel_support (onvif_factory)) { 75 | if (unsupported->len) 76 | g_string_append (unsupported, ", "); 77 | g_string_append (unsupported, GST_RTSP_ONVIF_BACKCHANNEL_REQUIREMENT); 78 | } 79 | } 80 | 81 | if (has_replay && !GST_IS_RTSP_ONVIF_MEDIA_FACTORY (factory)) { 82 | if (unsupported->len) 83 | g_string_append (unsupported, ", "); 84 | g_string_append (unsupported, GST_RTSP_ONVIF_REPLAY_REQUIREMENT); 85 | } else if (has_replay) { 86 | GstRTSPOnvifMediaFactory *onvif_factory = 87 | GST_RTSP_ONVIF_MEDIA_FACTORY (factory); 88 | 89 | if (!gst_rtsp_onvif_media_factory_has_replay_support (onvif_factory)) { 90 | if (unsupported->len) 91 | g_string_append (unsupported, ", "); 92 | g_string_append (unsupported, GST_RTSP_ONVIF_REPLAY_REQUIREMENT); 93 | } 94 | } 95 | 96 | 97 | out: 98 | if (path) 99 | g_free (path); 100 | if (factory) 101 | g_object_unref (factory); 102 | if (mount_points) 103 | g_object_unref (mount_points); 104 | 105 | return g_string_free (unsupported, FALSE); 106 | } 107 | 108 | static GstRTSPStatusCode 109 | gst_rtsp_onvif_client_adjust_play_mode (GstRTSPClient * client, 110 | GstRTSPContext * ctx, GstRTSPTimeRange ** range, GstSeekFlags * flags, 111 | gdouble * rate, GstClockTime * trickmode_interval, 112 | gboolean * enable_rate_control) 113 | { 114 | GstRTSPStatusCode ret = GST_RTSP_STS_BAD_REQUEST; 115 | gchar **split = NULL; 116 | gchar *str; 117 | 118 | if (gst_rtsp_message_get_header (ctx->request, GST_RTSP_HDR_FRAMES, 119 | &str, 0) == GST_RTSP_OK) { 120 | 121 | split = g_strsplit (str, "/", 2); 122 | 123 | if (!g_strcmp0 (split[0], "intra")) { 124 | if (split[1]) { 125 | guint64 interval; 126 | gchar *end; 127 | 128 | interval = g_ascii_strtoull (split[1], &end, 10); 129 | 130 | if (!end || *end != '\0') { 131 | GST_ERROR ("Unexpected interval value %s", split[1]); 132 | goto done; 133 | } 134 | 135 | *trickmode_interval = interval * GST_MSECOND; 136 | } 137 | *flags |= GST_SEEK_FLAG_TRICKMODE_KEY_UNITS; 138 | } else if (!g_strcmp0 (split[0], "predicted")) { 139 | if (split[1]) { 140 | GST_ERROR ("Predicted frames mode does not allow an interval (%s)", 141 | str); 142 | goto done; 143 | } 144 | *flags |= GST_SEEK_FLAG_TRICKMODE_FORWARD_PREDICTED; 145 | } else { 146 | GST_ERROR ("Invalid frames mode (%s)", str); 147 | goto done; 148 | } 149 | } 150 | 151 | if (gst_rtsp_message_get_header (ctx->request, GST_RTSP_HDR_RATE_CONTROL, 152 | &str, 0) == GST_RTSP_OK) { 153 | if (!g_strcmp0 (str, "no")) { 154 | *enable_rate_control = FALSE; 155 | } else if (!g_strcmp0 (str, "yes")) { 156 | *enable_rate_control = TRUE; 157 | } else { 158 | GST_ERROR ("Invalid rate control header: %s", str); 159 | goto done; 160 | } 161 | } 162 | 163 | ret = GST_RTSP_STS_OK; 164 | 165 | done: 166 | if (split) 167 | g_strfreev (split); 168 | return ret; 169 | } 170 | 171 | static GstRTSPStatusCode 172 | gst_rtsp_onvif_client_adjust_play_response (GstRTSPClient * client, 173 | GstRTSPContext * ctx) 174 | { 175 | GstRTSPStatusCode ret = GST_RTSP_STS_OK; 176 | gchar *str; 177 | 178 | if (gst_rtsp_message_get_header (ctx->request, GST_RTSP_HDR_RATE_CONTROL, 179 | &str, 0) == GST_RTSP_OK) { 180 | gst_rtsp_message_add_header (ctx->response, GST_RTSP_HDR_RATE_CONTROL, 181 | gst_rtsp_media_get_rate_control (ctx->media) ? "yes" : "no"); 182 | } 183 | 184 | return ret; 185 | } 186 | 187 | static void 188 | gst_rtsp_onvif_client_class_init (GstRTSPOnvifClientClass * klass) 189 | { 190 | GstRTSPClientClass *client_klass = (GstRTSPClientClass *) klass; 191 | 192 | client_klass->check_requirements = gst_rtsp_onvif_client_check_requirements; 193 | client_klass->adjust_play_mode = gst_rtsp_onvif_client_adjust_play_mode; 194 | client_klass->adjust_play_response = 195 | gst_rtsp_onvif_client_adjust_play_response; 196 | } 197 | 198 | static void 199 | gst_rtsp_onvif_client_init (GstRTSPOnvifClient * client) 200 | { 201 | } 202 | 203 | /** 204 | * gst_rtsp_onvif_client_new: 205 | * 206 | * Create a new #GstRTSPOnvifClient instance. 207 | * 208 | * Returns: (transfer full): a new #GstRTSPOnvifClient 209 | * Since: 1.18 210 | */ 211 | GstRTSPClient * 212 | gst_rtsp_onvif_client_new (void) 213 | { 214 | GstRTSPClient *result; 215 | 216 | result = g_object_new (GST_TYPE_RTSP_ONVIF_CLIENT, NULL); 217 | 218 | return result; 219 | } 220 | -------------------------------------------------------------------------------- /tests/check/gst/sessionpool.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2014 Sebastian Rasmussen 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | typedef struct 24 | { 25 | GstRTSPSession *sessions[3]; 26 | GstRTSPFilterResult response[3]; 27 | } Responses; 28 | 29 | static GstRTSPFilterResult 30 | filter_func (GstRTSPSessionPool * pool, GstRTSPSession * session, 31 | gpointer user_data) 32 | { 33 | Responses *responses = (Responses *) user_data; 34 | gint i; 35 | 36 | for (i = 0; i < 3; i++) 37 | if (session == responses->sessions[i]) 38 | return responses->response[i]; 39 | 40 | return GST_RTSP_FILTER_KEEP; 41 | } 42 | 43 | GST_START_TEST (test_pool) 44 | { 45 | GstRTSPSessionPool *pool; 46 | GstRTSPSession *session1, *session2, *session3; 47 | GstRTSPSession *compare; 48 | gchar *session1id, *session2id, *session3id; 49 | GList *list; 50 | guint maxsessions; 51 | GSource *source; 52 | guint sourceid; 53 | 54 | pool = gst_rtsp_session_pool_new (); 55 | fail_unless_equals_int (gst_rtsp_session_pool_get_n_sessions (pool), 0); 56 | fail_unless_equals_int (gst_rtsp_session_pool_get_max_sessions (pool), 0); 57 | 58 | gst_rtsp_session_pool_set_max_sessions (pool, 3); 59 | fail_unless_equals_int (gst_rtsp_session_pool_get_max_sessions (pool), 3); 60 | 61 | session1 = gst_rtsp_session_pool_create (pool); 62 | fail_unless (GST_IS_RTSP_SESSION (session1)); 63 | fail_unless_equals_int (gst_rtsp_session_pool_get_n_sessions (pool), 1); 64 | fail_unless_equals_int (gst_rtsp_session_pool_get_max_sessions (pool), 3); 65 | session1id = g_strdup (gst_rtsp_session_get_sessionid (session1)); 66 | 67 | session2 = gst_rtsp_session_pool_create (pool); 68 | fail_unless (GST_IS_RTSP_SESSION (session2)); 69 | fail_unless_equals_int (gst_rtsp_session_pool_get_n_sessions (pool), 2); 70 | fail_unless_equals_int (gst_rtsp_session_pool_get_max_sessions (pool), 3); 71 | session2id = g_strdup (gst_rtsp_session_get_sessionid (session2)); 72 | 73 | session3 = gst_rtsp_session_pool_create (pool); 74 | fail_unless (GST_IS_RTSP_SESSION (session3)); 75 | fail_unless_equals_int (gst_rtsp_session_pool_get_n_sessions (pool), 3); 76 | fail_unless_equals_int (gst_rtsp_session_pool_get_max_sessions (pool), 3); 77 | session3id = g_strdup (gst_rtsp_session_get_sessionid (session3)); 78 | 79 | fail_if (GST_IS_RTSP_SESSION (gst_rtsp_session_pool_create (pool))); 80 | 81 | compare = gst_rtsp_session_pool_find (pool, session1id); 82 | fail_unless (compare == session1); 83 | g_object_unref (compare); 84 | compare = gst_rtsp_session_pool_find (pool, session2id); 85 | fail_unless (compare == session2); 86 | g_object_unref (compare); 87 | compare = gst_rtsp_session_pool_find (pool, session3id); 88 | fail_unless (compare == session3); 89 | g_object_unref (compare); 90 | fail_unless (gst_rtsp_session_pool_find (pool, "") == NULL); 91 | 92 | fail_unless (gst_rtsp_session_pool_remove (pool, session2)); 93 | g_object_unref (session2); 94 | fail_unless_equals_int (gst_rtsp_session_pool_get_n_sessions (pool), 2); 95 | fail_unless_equals_int (gst_rtsp_session_pool_get_max_sessions (pool), 3); 96 | 97 | gst_rtsp_session_pool_set_max_sessions (pool, 2); 98 | fail_unless_equals_int (gst_rtsp_session_pool_get_n_sessions (pool), 2); 99 | fail_unless_equals_int (gst_rtsp_session_pool_get_max_sessions (pool), 2); 100 | 101 | session2 = gst_rtsp_session_pool_create (pool); 102 | fail_if (GST_IS_RTSP_SESSION (session2)); 103 | 104 | { 105 | list = gst_rtsp_session_pool_filter (pool, NULL, NULL); 106 | fail_unless_equals_int (g_list_length (list), 2); 107 | fail_unless (g_list_find (list, session1) != NULL); 108 | fail_unless (g_list_find (list, session3) != NULL); 109 | g_list_free_full (list, (GDestroyNotify) g_object_unref); 110 | } 111 | 112 | { 113 | Responses responses = { 114 | {session1, session2, session3} 115 | , 116 | {GST_RTSP_FILTER_KEEP, GST_RTSP_FILTER_KEEP, GST_RTSP_FILTER_KEEP} 117 | , 118 | }; 119 | 120 | list = gst_rtsp_session_pool_filter (pool, filter_func, &responses); 121 | fail_unless (list == NULL); 122 | } 123 | 124 | { 125 | Responses responses = { 126 | {session1, session2, session3} 127 | , 128 | {GST_RTSP_FILTER_REF, GST_RTSP_FILTER_KEEP, GST_RTSP_FILTER_KEEP} 129 | , 130 | }; 131 | 132 | list = gst_rtsp_session_pool_filter (pool, filter_func, &responses); 133 | fail_unless_equals_int (g_list_length (list), 1); 134 | fail_unless (g_list_nth_data (list, 0) == session1); 135 | g_list_free_full (list, (GDestroyNotify) g_object_unref); 136 | } 137 | 138 | { 139 | Responses responses = { 140 | {session1, session2, session3} 141 | , 142 | {GST_RTSP_FILTER_KEEP, GST_RTSP_FILTER_KEEP, GST_RTSP_FILTER_REMOVE} 143 | , 144 | }; 145 | 146 | list = gst_rtsp_session_pool_filter (pool, filter_func, &responses); 147 | fail_unless_equals_int (g_list_length (list), 0); 148 | g_list_free (list); 149 | } 150 | 151 | compare = gst_rtsp_session_pool_find (pool, session1id); 152 | fail_unless (compare == session1); 153 | g_object_unref (compare); 154 | fail_unless (gst_rtsp_session_pool_find (pool, session2id) == NULL); 155 | fail_unless (gst_rtsp_session_pool_find (pool, session3id) == NULL); 156 | 157 | g_object_get (pool, "max-sessions", &maxsessions, NULL); 158 | fail_unless_equals_int (maxsessions, 2); 159 | 160 | g_object_set (pool, "max-sessions", 3, NULL); 161 | g_object_get (pool, "max-sessions", &maxsessions, NULL); 162 | fail_unless_equals_int (maxsessions, 3); 163 | 164 | fail_unless_equals_int (gst_rtsp_session_pool_cleanup (pool), 0); 165 | 166 | gst_rtsp_session_set_timeout (session1, 1); 167 | 168 | source = gst_rtsp_session_pool_create_watch (pool); 169 | fail_unless (source != NULL); 170 | 171 | sourceid = g_source_attach (source, NULL); 172 | fail_unless (sourceid != 0); 173 | 174 | while (!g_main_context_iteration (NULL, TRUE)); 175 | 176 | g_source_unref (source); 177 | 178 | g_object_unref (session1); 179 | g_object_unref (session3); 180 | 181 | g_free (session1id); 182 | g_free (session2id); 183 | g_free (session3id); 184 | 185 | g_object_unref (pool); 186 | } 187 | 188 | GST_END_TEST; 189 | 190 | static Suite * 191 | rtspsessionpool_suite (void) 192 | { 193 | Suite *s = suite_create ("rtspsessionpool"); 194 | TCase *tc = tcase_create ("general"); 195 | 196 | suite_add_tcase (s, tc); 197 | tcase_set_timeout (tc, 15); 198 | tcase_add_test (tc, test_pool); 199 | 200 | return s; 201 | } 202 | 203 | GST_CHECK_MAIN (rtspsessionpool); 204 | -------------------------------------------------------------------------------- /gst/rtsp-server/rtsp-session.h: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 | * Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | #include "rtsp-server-prelude.h" /* for GST_RTSP_SERVER_DEPRECATED_FOR */ 24 | 25 | #ifndef __GST_RTSP_SESSION_H__ 26 | #define __GST_RTSP_SESSION_H__ 27 | 28 | G_BEGIN_DECLS 29 | 30 | #define GST_TYPE_RTSP_SESSION (gst_rtsp_session_get_type ()) 31 | #define GST_IS_RTSP_SESSION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_RTSP_SESSION)) 32 | #define GST_IS_RTSP_SESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_RTSP_SESSION)) 33 | #define GST_RTSP_SESSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RTSP_SESSION, GstRTSPSessionClass)) 34 | #define GST_RTSP_SESSION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_RTSP_SESSION, GstRTSPSession)) 35 | #define GST_RTSP_SESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_RTSP_SESSION, GstRTSPSessionClass)) 36 | #define GST_RTSP_SESSION_CAST(obj) ((GstRTSPSession*)(obj)) 37 | #define GST_RTSP_SESSION_CLASS_CAST(klass) ((GstRTSPSessionClass*)(klass)) 38 | 39 | typedef struct _GstRTSPSession GstRTSPSession; 40 | typedef struct _GstRTSPSessionClass GstRTSPSessionClass; 41 | typedef struct _GstRTSPSessionPrivate GstRTSPSessionPrivate; 42 | 43 | /** 44 | * GstRTSPFilterResult: 45 | * @GST_RTSP_FILTER_REMOVE: Remove session 46 | * @GST_RTSP_FILTER_KEEP: Keep session in the pool 47 | * @GST_RTSP_FILTER_REF: Ref session in the result list 48 | * 49 | * Possible return values for gst_rtsp_session_pool_filter(). 50 | */ 51 | typedef enum 52 | { 53 | GST_RTSP_FILTER_REMOVE, 54 | GST_RTSP_FILTER_KEEP, 55 | GST_RTSP_FILTER_REF, 56 | } GstRTSPFilterResult; 57 | 58 | #include "rtsp-media.h" 59 | #include "rtsp-session-media.h" 60 | 61 | /** 62 | * GstRTSPSession: 63 | * 64 | * Session information kept by the server for a specific client. 65 | * One client session, identified with a session id, can handle multiple medias 66 | * identified with the url of a media. 67 | */ 68 | struct _GstRTSPSession { 69 | GObject parent; 70 | 71 | /*< private >*/ 72 | GstRTSPSessionPrivate *priv; 73 | gpointer _gst_reserved[GST_PADDING]; 74 | }; 75 | 76 | struct _GstRTSPSessionClass { 77 | GObjectClass parent_class; 78 | 79 | /*< private >*/ 80 | gpointer _gst_reserved[GST_PADDING]; 81 | }; 82 | 83 | GST_RTSP_SERVER_API 84 | GType gst_rtsp_session_get_type (void); 85 | 86 | /* create a new session */ 87 | 88 | GST_RTSP_SERVER_API 89 | GstRTSPSession * gst_rtsp_session_new (const gchar *sessionid); 90 | 91 | GST_RTSP_SERVER_API 92 | const gchar * gst_rtsp_session_get_sessionid (GstRTSPSession *session); 93 | 94 | GST_RTSP_SERVER_API 95 | gchar * gst_rtsp_session_get_header (GstRTSPSession *session); 96 | 97 | GST_RTSP_SERVER_API 98 | void gst_rtsp_session_set_timeout (GstRTSPSession *session, guint timeout); 99 | 100 | GST_RTSP_SERVER_API 101 | guint gst_rtsp_session_get_timeout (GstRTSPSession *session); 102 | 103 | /* session timeout stuff */ 104 | 105 | GST_RTSP_SERVER_API 106 | void gst_rtsp_session_touch (GstRTSPSession *session); 107 | 108 | GST_RTSP_SERVER_API 109 | void gst_rtsp_session_prevent_expire (GstRTSPSession *session); 110 | 111 | GST_RTSP_SERVER_API 112 | void gst_rtsp_session_allow_expire (GstRTSPSession *session); 113 | 114 | GST_RTSP_SERVER_API 115 | gint gst_rtsp_session_next_timeout_usec (GstRTSPSession *session, gint64 now); 116 | 117 | GST_RTSP_SERVER_API 118 | gboolean gst_rtsp_session_is_expired_usec (GstRTSPSession *session, gint64 now); 119 | 120 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS 121 | GST_RTSP_SERVER_DEPRECATED_FOR(gst_rtsp_session_next_timeout_usec) 122 | gint gst_rtsp_session_next_timeout (GstRTSPSession *session, GTimeVal *now); 123 | 124 | GST_RTSP_SERVER_DEPRECATED_FOR(gst_rtsp_session_is_expired_usec) 125 | gboolean gst_rtsp_session_is_expired (GstRTSPSession *session, GTimeVal *now); 126 | G_GNUC_END_IGNORE_DEPRECATIONS 127 | 128 | /* handle media in a session */ 129 | 130 | GST_RTSP_SERVER_API 131 | GstRTSPSessionMedia * gst_rtsp_session_manage_media (GstRTSPSession *sess, 132 | const gchar *path, 133 | GstRTSPMedia *media); 134 | 135 | GST_RTSP_SERVER_API 136 | gboolean gst_rtsp_session_release_media (GstRTSPSession *sess, 137 | GstRTSPSessionMedia *media); 138 | /* get media in a session */ 139 | 140 | GST_RTSP_SERVER_API 141 | GstRTSPSessionMedia * gst_rtsp_session_get_media (GstRTSPSession *sess, 142 | const gchar *path, 143 | gint * matched); 144 | 145 | /** 146 | * GstRTSPSessionFilterFunc: 147 | * @sess: a #GstRTSPSession object 148 | * @media: a #GstRTSPSessionMedia in @sess 149 | * @user_data: user data that has been given to gst_rtsp_session_filter() 150 | * 151 | * This function will be called by the gst_rtsp_session_filter(). An 152 | * implementation should return a value of #GstRTSPFilterResult. 153 | * 154 | * When this function returns #GST_RTSP_FILTER_REMOVE, @media will be removed 155 | * from @sess. 156 | * 157 | * A return value of #GST_RTSP_FILTER_KEEP will leave @media untouched in 158 | * @sess. 159 | * 160 | * A value of GST_RTSP_FILTER_REF will add @media to the result #GList of 161 | * gst_rtsp_session_filter(). 162 | * 163 | * Returns: a #GstRTSPFilterResult. 164 | */ 165 | typedef GstRTSPFilterResult (*GstRTSPSessionFilterFunc) (GstRTSPSession *sess, 166 | GstRTSPSessionMedia *media, 167 | gpointer user_data); 168 | 169 | GST_RTSP_SERVER_API 170 | GList * gst_rtsp_session_filter (GstRTSPSession *sess, 171 | GstRTSPSessionFilterFunc func, 172 | gpointer user_data); 173 | 174 | 175 | #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC 176 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstRTSPSession, gst_object_unref) 177 | #endif 178 | 179 | G_END_DECLS 180 | 181 | #endif /* __GST_RTSP_SESSION_H__ */ 182 | -------------------------------------------------------------------------------- /examples/test-record-auth.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * Copyright (C) 2008 Wim Taymans 3 | * Copyright (C) 2015 Centricular Ltd 4 | * Author: Sebastian Dröge 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 19 | * Boston, MA 02110-1301, USA. 20 | */ 21 | 22 | #include 23 | 24 | #include 25 | 26 | /* define this if you want the server to use TLS */ 27 | //#define WITH_TLS 28 | 29 | #define DEFAULT_RTSP_PORT "8554" 30 | 31 | static char *port = (char *) DEFAULT_RTSP_PORT; 32 | 33 | static GOptionEntry entries[] = { 34 | {"port", 'p', 0, G_OPTION_ARG_STRING, &port, 35 | "Port to listen on (default: " DEFAULT_RTSP_PORT ")", "PORT"}, 36 | {NULL} 37 | }; 38 | 39 | int 40 | main (int argc, char *argv[]) 41 | { 42 | GMainLoop *loop; 43 | GstRTSPServer *server; 44 | GstRTSPMountPoints *mounts; 45 | GstRTSPMediaFactory *factory; 46 | GOptionContext *optctx; 47 | GError *error = NULL; 48 | GstRTSPAuth *auth; 49 | GstRTSPToken *token; 50 | gchar *basic; 51 | #ifdef WITH_TLS 52 | GTlsCertificate *cert; 53 | #endif 54 | 55 | optctx = g_option_context_new (" - Test RTSP Server, Launch\n\n" 56 | "Example: \"( decodebin name=depay0 ! autovideosink )\""); 57 | g_option_context_add_main_entries (optctx, entries, NULL); 58 | g_option_context_add_group (optctx, gst_init_get_option_group ()); 59 | if (!g_option_context_parse (optctx, &argc, &argv, &error)) { 60 | g_printerr ("Error parsing options: %s\n", error->message); 61 | return -1; 62 | } 63 | 64 | if (argc < 2) { 65 | g_print ("%s\n", g_option_context_get_help (optctx, TRUE, NULL)); 66 | return 1; 67 | } 68 | g_option_context_free (optctx); 69 | 70 | loop = g_main_loop_new (NULL, FALSE); 71 | 72 | /* create a server instance */ 73 | server = gst_rtsp_server_new (); 74 | g_object_set (server, "service", port, NULL); 75 | 76 | /* get the mount points for this server, every server has a default object 77 | * that be used to map uri mount points to media factories */ 78 | mounts = gst_rtsp_server_get_mount_points (server); 79 | 80 | /* make a media factory for a test stream. The default media factory can use 81 | * gst-launch syntax to create pipelines. 82 | * any launch line works as long as it contains elements named depay%d. Each 83 | * element with depay%d names will be a stream */ 84 | factory = gst_rtsp_media_factory_new (); 85 | gst_rtsp_media_factory_set_transport_mode (factory, 86 | GST_RTSP_TRANSPORT_MODE_RECORD); 87 | gst_rtsp_media_factory_set_launch (factory, argv[1]); 88 | gst_rtsp_media_factory_set_latency (factory, 2000); 89 | #ifdef WITH_TLS 90 | gst_rtsp_media_factory_set_profiles (factory, 91 | GST_RTSP_PROFILE_SAVP | GST_RTSP_PROFILE_SAVPF); 92 | #else 93 | gst_rtsp_media_factory_set_profiles (factory, 94 | GST_RTSP_PROFILE_AVP | GST_RTSP_PROFILE_AVPF); 95 | #endif 96 | 97 | /* allow user to access this resource */ 98 | gst_rtsp_media_factory_add_role (factory, "user", 99 | GST_RTSP_PERM_MEDIA_FACTORY_ACCESS, G_TYPE_BOOLEAN, TRUE, 100 | GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT, G_TYPE_BOOLEAN, TRUE, NULL); 101 | /* Anonymous users can see but not construct, so get UNAUTHORIZED */ 102 | gst_rtsp_media_factory_add_role (factory, "anonymous", 103 | GST_RTSP_PERM_MEDIA_FACTORY_ACCESS, G_TYPE_BOOLEAN, TRUE, 104 | GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT, G_TYPE_BOOLEAN, FALSE, NULL); 105 | 106 | /* attach the test factory to the /test url */ 107 | gst_rtsp_mount_points_add_factory (mounts, "/test", factory); 108 | 109 | /* don't need the ref to the mapper anymore */ 110 | g_object_unref (mounts); 111 | 112 | /* Set up the auth for user account */ 113 | /* make a new authentication manager */ 114 | auth = gst_rtsp_auth_new (); 115 | #ifdef WITH_TLS 116 | cert = g_tls_certificate_new_from_pem ("-----BEGIN CERTIFICATE-----" 117 | "MIICJjCCAY+gAwIBAgIBBzANBgkqhkiG9w0BAQUFADCBhjETMBEGCgmSJomT8ixk" 118 | "ARkWA0NPTTEXMBUGCgmSJomT8ixkARkWB0VYQU1QTEUxHjAcBgNVBAsTFUNlcnRp" 119 | "ZmljYXRlIEF1dGhvcml0eTEXMBUGA1UEAxMOY2EuZXhhbXBsZS5jb20xHTAbBgkq" 120 | "hkiG9w0BCQEWDmNhQGV4YW1wbGUuY29tMB4XDTExMDExNzE5NDcxN1oXDTIxMDEx" 121 | "NDE5NDcxN1owSzETMBEGCgmSJomT8ixkARkWA0NPTTEXMBUGCgmSJomT8ixkARkW" 122 | "B0VYQU1QTEUxGzAZBgNVBAMTEnNlcnZlci5leGFtcGxlLmNvbTBcMA0GCSqGSIb3" 123 | "DQEBAQUAA0sAMEgCQQDYScTxk55XBmbDM9zzwO+grVySE4rudWuzH2PpObIonqbf" 124 | "hRoAalKVluG9jvbHI81eXxCdSObv1KBP1sbN5RzpAgMBAAGjIjAgMAkGA1UdEwQC" 125 | "MAAwEwYDVR0lBAwwCgYIKwYBBQUHAwEwDQYJKoZIhvcNAQEFBQADgYEAYx6fMqT1" 126 | "Gvo0jq88E8mc+bmp4LfXD4wJ7KxYeadQxt75HFRpj4FhFO3DOpVRFgzHlOEo3Fwk" 127 | "PZOKjvkT0cbcoEq5whLH25dHoQxGoVQgFyAP5s+7Vp5AlHh8Y/vAoXeEVyy/RCIH" 128 | "QkhUlAflfDMcrrYjsmwoOPSjhx6Mm/AopX4=" 129 | "-----END CERTIFICATE-----" 130 | "-----BEGIN PRIVATE KEY-----" 131 | "MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEA2EnE8ZOeVwZmwzPc" 132 | "88DvoK1ckhOK7nVrsx9j6TmyKJ6m34UaAGpSlZbhvY72xyPNXl8QnUjm79SgT9bG" 133 | "zeUc6QIDAQABAkBRFJZ32VbqWMP9OVwDJLiwC01AlYLnka0mIQZbT/2xq9dUc9GW" 134 | "U3kiVw4lL8v/+sPjtTPCYYdzHHOyDen6znVhAiEA9qJT7BtQvRxCvGrAhr9MS022" 135 | "tTdPbW829BoUtIeH64cCIQDggG5i48v7HPacPBIH1RaSVhXl8qHCpQD3qrIw3FMw" 136 | "DwIga8PqH5Sf5sHedy2+CiK0V4MRfoU4c3zQ6kArI+bEgSkCIQCLA1vXBiE31B5s" 137 | "bdHoYa1BXebfZVd+1Hd95IfEM5mbRwIgSkDuQwV55BBlvWph3U8wVIMIb4GStaH8" 138 | "W535W8UBbEg=" "-----END PRIVATE KEY-----", -1, &error); 139 | if (cert == NULL) { 140 | g_printerr ("failed to parse PEM: %s\n", error->message); 141 | return -1; 142 | } 143 | gst_rtsp_auth_set_tls_certificate (auth, cert); 144 | g_object_unref (cert); 145 | #endif 146 | 147 | /* make default token - anonymous unauthenticated access */ 148 | token = 149 | gst_rtsp_token_new (GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING, 150 | "anonymous", NULL); 151 | gst_rtsp_auth_set_default_token (auth, token); 152 | gst_rtsp_token_unref (token); 153 | 154 | /* make user token */ 155 | token = 156 | gst_rtsp_token_new (GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING, 157 | "user", NULL); 158 | basic = gst_rtsp_auth_make_basic ("user", "password"); 159 | gst_rtsp_auth_add_basic (auth, basic, token); 160 | g_free (basic); 161 | gst_rtsp_token_unref (token); 162 | 163 | /* set as the server authentication manager */ 164 | gst_rtsp_server_set_auth (server, auth); 165 | g_object_unref (auth); 166 | 167 | /* attach the server to the default maincontext */ 168 | gst_rtsp_server_attach (server, NULL); 169 | 170 | /* start serving */ 171 | #ifdef WITH_TLS 172 | g_print ("stream ready at rtsps://127.0.0.1:%s/test\n", port); 173 | #else 174 | g_print ("stream ready at rtsp://127.0.0.1:%s/test\n", port); 175 | #endif 176 | g_main_loop_run (loop); 177 | 178 | return 0; 179 | } 180 | --------------------------------------------------------------------------------