summaryrefslogtreecommitdiff
path: root/gst/rawparse/gstrawbaseparse.h
blob: 4af4408c2378e9283c8d1a8aeecf110c24034bb1 (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* GStreamer
 * Copyright (C) <2016> Carlos Rafael Giani <dv at pseudoterminal dot org>
 *
 * 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_RAW_BASE_PARSE_H__
#define __GST_RAW_BASE_PARSE_H__

#include <gst/gst.h>
#include <gst/base/base.h>

G_BEGIN_DECLS

#define GST_TYPE_RAW_BASE_PARSE \
  (gst_raw_base_parse_get_type())
#define GST_RAW_BASE_PARSE(obj) \
  (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_RAW_BASE_PARSE, GstRawBaseParse))
#define GST_RAW_BASE_PARSE_CAST(obj) \
  ((GstRawBaseParse *)(obj))
#define GST_RAW_BASE_PARSE_CLASS(klass) \
  (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_RAW_BASE_PARSE, GstRawBaseParseClass))
#define GST_RAW_BASE_PARSE_GET_CLASS(obj) \
  (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_RAW_BASE_PARSE, GstRawBaseParseClass))
#define GST_IS_RAW_BASE_PARSE(obj) \
  (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_RAW_BASE_PARSE))
#define GST_IS_RAW_BASE_PARSE_CLASS(klass) \
  (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_RAW_BASE_PARSE))

#define GST_RAW_BASE_PARSE_CONFIG_MUTEX_LOCK(obj)   g_mutex_lock(&(((GstRawBaseParse *)(obj))->config_mutex))
#define GST_RAW_BASE_PARSE_CONFIG_MUTEX_UNLOCK(obj) g_mutex_unlock(&(((GstRawBaseParse *)(obj))->config_mutex))


typedef enum _GstRawBaseParseConfig GstRawBaseParseConfig;
typedef struct _GstRawBaseParse GstRawBaseParse;
typedef struct _GstRawBaseParseClass GstRawBaseParseClass;


/**
 * GstRawBaseParseConfig:
 * @GST_RAW_BASE_PARSE_CONFIG_CURRENT: configuration that is currently active
 * @GST_RAW_BASE_PARSE_CONFIG_SINKCAPS: configuration that is defined by the input sink caps
 * @GST_RAW_BASE_PARSE_CONFIG_PROPERTIES: configuration that is defined by class properties
 *
 * Identifier for the type of parser configuration.
 */
enum _GstRawBaseParseConfig
{
  GST_RAW_BASE_PARSE_CONFIG_CURRENT = 1,
  GST_RAW_BASE_PARSE_CONFIG_SINKCAPS,
  GST_RAW_BASE_PARSE_CONFIG_PROPERTIES
};


/**
 * GstRawBaseParse:
 *
 * The opaque #GstRawBaseParse data structure.
 */
struct _GstRawBaseParse
{
  GstBaseParse parent;

  /*< private > */

  /* TRUE if the source pad caps have been set already. This is used
   * for checking if the source pad caps have to be set. */
  gboolean src_caps_set;

  /* Mutex which protects access to and modifications on the configs. */
  GMutex config_mutex;
};


/**
 * GstRawBaseParseClass:
 * @parent_class:              The parent class structure
 * @set_current_config:        Sets the new current configuration. Subclasses must internally
 *                             switch to this new configuration. Return FALSE if this failed,
 *                             TRUE otherwise.
 * @get_current_config:        Gets the current configuration. All return values except
 *                             except GST_RAW_BASE_PARSE_CONFIG_CURRENT are valid.
 * @set_config_from_caps:      Parses the caps and copies its information to the configuration.
 *                             Returns FALSE if this failed, TRUE otheriwse. Specified caps
 *                             are not unref'd.
 * @get_caps_from_config:      Creates a new caps structure out of the information from the
 *                             specified configuration. Ownership over the returned caps are
 *                             transferred to the caller. If something fails during the caps
 *                             creation, the vfunc must make sure to destroy any partially
 *                             created caps; the *caps value is always set to NULL in case of
 *                             failure. Returns FALSE in case of failure,
 *                             TRUE in case of success.
 * @get_config_frame_size:     Gets the size of one frame, in bytes, from the specified
 *                             configuration. This must be the size of the complete frame,
 *                             including any overhead (metadata, headers, padding bytes etc.).
 * @get_max_frames_per_buffer: Optional.
 *                             Returns up to how many complete frames one output buffer may
 *                             contain. The value must be nonzero. This is useful for example
 *                             with video parsers which need to ensure that one output buffer
 *                             contains only one video frame, even if the input buffer contains
 *                             several complete frames. If this vfunc is not set, then there
 *                             is no maximum number of frames per buffer - the parser reads
 *                             as many complete frames as possible from the input buffer.
 * @is_config_ready:           Returns TRUE if the specified configuration is ready, FALSE
 *                             otherwise.
 * @process:                   Optional.
 *                             This is useful to do any last minute processing before the
 *                             data is pushed downstream. One example is channel reordering
 *                             in audio parsers.
 *                             in_data is the complete input buffer, total_num_in_bytes is
 *                             the total amount of bytes this input buffer contains (including
 *                             excess bytes that form an incomplete rame). num_valid_in_bytes
 *                             is the subset of these bytes that are to be pushed downstream.
 *                             If for example the frame size is 4, and total_num_in_bytes is
 *                             411, then num_valid_in_bytes will be 408, since the last 3
 *                             bytes form an incomplete frame.
 *                             The value of num_valid_in_bytes excludes the overhead bytes
 *                             indicated by @get_overhead_size.
 *                             If the subclass creates a new buffer here, *processed_data
 *                             must be set to the new buffer's pointer. If the subclass does
 *                             not create any new buffer, and just expects the first
 *                             num_valid_in_bytes of the input buffer to be pushed downstream,
 *                             then *processed_data must be set to NULL.
 *                             If this vfunc is not set, then the parser behaves as if this
 *                             vfunc set *processed_data data to NULL.
 * @is_unit_format_supported:  Returns TRUE if the given format is supported by the
 *                             @get_units_per_second function, FALSE otherwise.
 * @get_units_per_second:      Returns how many units per second exist for a given format.
 *                             For example, with an audio parser and format DEFAULT, the units
 *                             per second are typically the number of samples per second
 *                             (= the sample rate). For video parsers, this would be the frame
 *                             rate. If BYTES or TIME are used as format, then the result must
 *                             not include any extra overhead (metadata, headers, padding etc.)
 * @get_overhead_size:         Optional.
 *                             Returns the number of bytes that make up the portion of a frame
 *                             that isn't payload. Examples are padding bytes, headers, and
 *                             other kinds of metadata. If this vfunc isn't defined, then an
 *                             overhead size of 0 bytes is assumed.
 *
 * Subclasses are required to override all vfuncs except for @process, which is optional.
 * The raw base parser lock is held during all vfunc calls.
 */
struct _GstRawBaseParseClass
{
  GstBaseParseClass parent_class;

  gboolean              (*set_current_config)        (GstRawBaseParse *raw_base_parse,
                                                      GstRawBaseParseConfig config);
  GstRawBaseParseConfig (*get_current_config)        (GstRawBaseParse *raw_base_parse);

  gboolean              (*set_config_from_caps)      (GstRawBaseParse * raw_base_parse,
                                                      GstRawBaseParseConfig config,
                                                      GstCaps * caps);
  gboolean              (*get_caps_from_config)      (GstRawBaseParse * raw_base_parse,
                                                      GstRawBaseParseConfig config,
                                                      GstCaps ** caps);

  gsize                 (*get_config_frame_size)     (GstRawBaseParse * raw_base_parse,
                                                      GstRawBaseParseConfig config);
  guint                 (*get_max_frames_per_buffer) (GstRawBaseParse * raw_base_parse,
                                                      GstRawBaseParseConfig config);

  gboolean              (*is_config_ready)           (GstRawBaseParse * raw_base_parse,
                                                      GstRawBaseParseConfig config);

  gboolean              (*process)                   (GstRawBaseParse * raw_base_parse,
                                                      GstRawBaseParseConfig config,
                                                      GstBuffer * in_data,
                                                      gsize total_num_in_bytes,
                                                      gsize num_valid_in_bytes,
                                                      GstBuffer ** processed_data);

  gboolean              (*is_unit_format_supported)  (GstRawBaseParse * raw_base_parse,
                                                      GstFormat format);
  void                  (*get_units_per_second)      (GstRawBaseParse * raw_base_parse,
                                                      GstFormat format,
                                                      GstRawBaseParseConfig config,
                                                      gsize * units_per_sec_n,
                                                      gsize * units_per_sec_d);

  gint                  (*get_overhead_size)         (GstRawBaseParse * raw_base_parse,
                                                      GstRawBaseParseConfig config);

  gint                  (*get_alignment)             (GstRawBaseParse * raw_base_parse,
                                                      GstRawBaseParseConfig config);
};


void gst_raw_base_parse_invalidate_src_caps (GstRawBaseParse * raw_base_parse);


GType gst_raw_base_parse_get_type (void);


G_END_DECLS

#endif