summaryrefslogtreecommitdiff
path: root/gst/rtsp-server/rtsp-media-factory.h
blob: 1c7bab944465daa251880355bee01452540e844d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* GStreamer
 * Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <gst/gst.h>
#include <gst/rtsp/gstrtspurl.h>

#include "rtsp-media.h"
#include "rtsp-auth.h"

#ifndef __GST_RTSP_MEDIA_FACTORY_H__
#define __GST_RTSP_MEDIA_FACTORY_H__

G_BEGIN_DECLS

/* types for the media factory */
#define GST_TYPE_RTSP_MEDIA_FACTORY              (gst_rtsp_media_factory_get_type ())
#define GST_IS_RTSP_MEDIA_FACTORY(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_RTSP_MEDIA_FACTORY))
#define GST_IS_RTSP_MEDIA_FACTORY_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_RTSP_MEDIA_FACTORY))
#define GST_RTSP_MEDIA_FACTORY_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RTSP_MEDIA_FACTORY, GstRTSPMediaFactoryClass))
#define GST_RTSP_MEDIA_FACTORY(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_RTSP_MEDIA_FACTORY, GstRTSPMediaFactory))
#define GST_RTSP_MEDIA_FACTORY_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_RTSP_MEDIA_FACTORY, GstRTSPMediaFactoryClass))
#define GST_RTSP_MEDIA_FACTORY_CAST(obj)         ((GstRTSPMediaFactory*)(obj))
#define GST_RTSP_MEDIA_FACTORY_CLASS_CAST(klass) ((GstRTSPMediaFactoryClass*)(klass))

typedef struct _GstRTSPMediaFactory GstRTSPMediaFactory;
typedef struct _GstRTSPMediaFactoryClass GstRTSPMediaFactoryClass;

#define GST_RTSP_MEDIA_FACTORY_GET_LOCK(f)       (GST_RTSP_MEDIA_FACTORY_CAST(f)->lock)
#define GST_RTSP_MEDIA_FACTORY_LOCK(f)           (g_mutex_lock(GST_RTSP_MEDIA_FACTORY_GET_LOCK(f)))
#define GST_RTSP_MEDIA_FACTORY_UNLOCK(f)         (g_mutex_unlock(GST_RTSP_MEDIA_FACTORY_GET_LOCK(f)))

/**
 * GstRTSPMediaFactory:
 * @lock: mutex protecting the datastructure.
 * @launch: the launch description
 * @shared: if media from this factory can be shared between clients
 * @media_lock: mutex protecting the medias.
 * @media: hashtable of shared media
 *
 * The definition and logic for constructing the pipeline for a media. The media
 * can contain multiple streams like audio and video.
 */
struct _GstRTSPMediaFactory {
  GObject       parent;

  GMutex       *lock;
  gchar        *launch;
  gboolean      shared;
  gboolean      eos_shutdown;
  GstRTSPAuth  *auth;
  guint         buffer_size;

  GMutex       *medias_lock;
  GHashTable   *medias;
};

/**
 * GstRTSPMediaFactoryClass:
 * @gen_key: convert @url to a key for caching shared #GstRTSPMedia objects.
 *       The default implementation of this function will use the complete URL
 *       including the query parameters to return a key.
 * @get_element: Construct and return a #GstElement that is a #GstBin containing
 *       the elements to use for streaming the media. The bin should contain
 *       payloaders pay%d for each stream. The default implementation of this
 *       function returns the bin created from the launch parameter.
 * @construct: the vmethod that will be called when the factory has to create the
 *       #GstRTSPMedia for @url. The default implementation of this
 *       function calls get_element to retrieve an element and then looks for
 *       pay%d to create the streams.
 * @configure: configure the media created with @construct. The default
 *       implementation will configure the 'shared' property of the media.
 * @create_pipeline: create a new pipeline or re-use an existing one and
 *       add the #GstRTSPMedia's element created by @construct to the pipeline.
 *
 * The #GstRTSPMediaFactory class structure.
 */
struct _GstRTSPMediaFactoryClass {
  GObjectClass  parent_class;

  gchar *           (*gen_key)		(GstRTSPMediaFactory *factory, const GstRTSPUrl *url);

  GstElement *      (*get_element)	(GstRTSPMediaFactory *factory, const GstRTSPUrl *url);
  GstRTSPMedia *    (*construct)	(GstRTSPMediaFactory *factory, const GstRTSPUrl *url);
  void              (*configure)	(GstRTSPMediaFactory *factory, GstRTSPMedia *media);
  GstElement *      (*create_pipeline)	(GstRTSPMediaFactory *factory, GstRTSPMedia *media);

  /* signals */
  void		    (*media_constructed)(GstRTSPMediaFactory *factory, GstRTSPMedia *media);
};

GType                 gst_rtsp_media_factory_get_type     (void);

/* creating the factory */
GstRTSPMediaFactory * gst_rtsp_media_factory_new          (void);

/* configuring the factory */
void                  gst_rtsp_media_factory_set_launch   (GstRTSPMediaFactory *factory,
                                                           const gchar *launch);
gchar *               gst_rtsp_media_factory_get_launch   (GstRTSPMediaFactory *factory);

void                  gst_rtsp_media_factory_set_shared   (GstRTSPMediaFactory *factory,
                                                           gboolean shared);
gboolean              gst_rtsp_media_factory_is_shared    (GstRTSPMediaFactory *factory);

void                  gst_rtsp_media_factory_set_eos_shutdown   (GstRTSPMediaFactory *factory,
                                                                 gboolean eos_shutdown);
gboolean              gst_rtsp_media_factory_is_eos_shutdown    (GstRTSPMediaFactory *factory);

void                  gst_rtsp_media_factory_set_auth     (GstRTSPMediaFactory *factory, GstRTSPAuth *auth);
GstRTSPAuth *         gst_rtsp_media_factory_get_auth     (GstRTSPMediaFactory *factory);

void                  gst_rtsp_media_factory_set_buffer_size    (GstRTSPMediaFactory * factory, guint size);
guint                 gst_rtsp_media_factory_get_buffer_size    (GstRTSPMediaFactory * factory);


/* creating the media from the factory and a url */
GstRTSPMedia *        gst_rtsp_media_factory_construct    (GstRTSPMediaFactory *factory,
                                                           const GstRTSPUrl *url);

void                  gst_rtsp_media_factory_collect_streams (GstRTSPMediaFactory *factory,
                                                              const GstRTSPUrl *url,
                                                              GstRTSPMedia *media);

G_END_DECLS

#endif /* __GST_RTSP_MEDIA_FACTORY_H__ */