summaryrefslogtreecommitdiff
path: root/ext/srt/gstsrtobject.h
blob: 8dad9753641497145e6825122b78dd09c8996377 (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
/* GStreamer
 * Copyright (C) 2018, Collabora Ltd.
 * Copyright (C) 2018, SK Telecom, Co., Ltd.
 *   Author: Jeongseok Kim <jeongseok.kim@sk.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., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifndef __GST_SRT_OBJECT_H__
#define __GST_SRT_OBJECT_H__

#include "gstsrt-enums.h"
#include "gstsrt-enumtypes.h"

#include <gio/gio.h>
#include <srt/srt.h>

G_BEGIN_DECLS

#define GST_SRT_DEFAULT_URI_SCHEME "srt"
#define GST_SRT_DEFAULT_PORT 7001
#define GST_SRT_DEFAULT_HOST "127.0.0.1"
#define GST_SRT_DEFAULT_LOCALADDRESS "0.0.0.0"
#define GST_SRT_DEFAULT_URI GST_SRT_DEFAULT_URI_SCHEME"://"GST_SRT_DEFAULT_HOST":"G_STRINGIFY(GST_SRT_DEFAULT_PORT)

#define GST_SRT_DEFAULT_MODE GST_SRT_CONNECTION_MODE_CALLER
#define GST_SRT_DEFAULT_PBKEYLEN GST_SRT_KEY_LENGTH_BITS_128
#define GST_SRT_DEFAULT_POLL_TIMEOUT -1
#define GST_SRT_DEFAULT_LATENCY 125
#define GST_SRT_DEFAULT_MSG_SIZE 1316
#define GST_SRT_DEFAULT_KEY_LENGTH 16

typedef struct _GstSRTObject GstSRTObject;

struct _GstSRTObject
{
  GstElement                   *element;
  GstUri                       *uri;

  GstStructure                 *parameters;
  gboolean                      opened;
  SRTSOCKET                     sock;
  gint                          poll_id;
  gboolean                      sent_headers;

  GMutex                        sock_lock;
  GCond                         sock_cond;

  GTask                        *listener_task;
  SRTSOCKET                     listener_sock;
  gint                          listener_poll_id;

  GMainLoop                    *loop;
  GMainContext                 *context;
  GSource                      *listener_source;
  GThread                      *thread;

  GList                        *callers;

  GClosure                     *caller_added_closure;
  GClosure                     *caller_removed_closure;
};


typedef void (*GstSRTObjectCallerAdded)         (int sock, GSocketAddress *addr, GstSRTObject * srtobject);

typedef void (*GstSRTObjectCallerRemoved)       (int sock, GSocketAddress *addr, GstSRTObject * srtobject);

GstSRTObject   *gst_srt_object_new              (GstElement *element);

void            gst_srt_object_destroy          (GstSRTObject *srtobject);

gboolean        gst_srt_object_open             (GstSRTObject *srtobject,
                                                 GCancellable *cancellable,
                                                 GError **error);

gboolean        gst_srt_object_open_full        (GstSRTObject *srtobject,
                                                 GstSRTObjectCallerAdded caller_added_func,
                                                 GstSRTObjectCallerRemoved caller_removed_func,
                                                 GCancellable *cancellable,
                                                 GError **error);

void            gst_srt_object_close            (GstSRTObject *srtobject);

gboolean        gst_srt_object_set_property_helper (GstSRTObject *srtobject, 
                                                    guint prop_id, const GValue * value,
                                                    GParamSpec * pspec);

gboolean        gst_srt_object_get_property_helper (GstSRTObject *srtobject, 
                                                    guint prop_id, GValue * value,
                                                    GParamSpec * pspec);

void            gst_srt_object_install_properties_helper (GObjectClass *gobject_class);

gboolean        gst_srt_object_set_uri (GstSRTObject * srtobject, const gchar *uri, GError ** err);

gssize          gst_srt_object_read     (GstSRTObject * srtobject, 
                                         guint8 *data, gsize size,
                                         GCancellable *cancellable,
                                         GError **err);

gssize          gst_srt_object_write    (GstSRTObject * srtobject, 
                                         GstBufferList * headers,
                                         const GstMapInfo * mapinfo,
                                         GCancellable *cancellable,
                                         GError **err);

void            gst_srt_object_wakeup   (GstSRTObject * srtobject);

GstStructure   *gst_srt_object_get_stats        (GstSRTObject * srtobject);

G_END_DECLS

#endif // __GST_SRT_OBJECT_H__