• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * Copyright (C) <2016> Carlos Rafael Giani <dv at pseudoterminal dot org>
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_RAW_BASE_PARSE_H__
21 #define __GST_RAW_BASE_PARSE_H__
22 
23 #include <gst/gst.h>
24 #include <gst/base/base.h>
25 
26 G_BEGIN_DECLS
27 
28 #define GST_TYPE_RAW_BASE_PARSE \
29   (gst_raw_base_parse_get_type())
30 #define GST_RAW_BASE_PARSE(obj) \
31   (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_RAW_BASE_PARSE, GstRawBaseParse))
32 #define GST_RAW_BASE_PARSE_CAST(obj) \
33   ((GstRawBaseParse *)(obj))
34 #define GST_RAW_BASE_PARSE_CLASS(klass) \
35   (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_RAW_BASE_PARSE, GstRawBaseParseClass))
36 #define GST_RAW_BASE_PARSE_GET_CLASS(obj) \
37   (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_RAW_BASE_PARSE, GstRawBaseParseClass))
38 #define GST_IS_RAW_BASE_PARSE(obj) \
39   (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_RAW_BASE_PARSE))
40 #define GST_IS_RAW_BASE_PARSE_CLASS(klass) \
41   (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_RAW_BASE_PARSE))
42 
43 #define GST_RAW_BASE_PARSE_CONFIG_MUTEX_LOCK(obj)   g_mutex_lock(&(((GstRawBaseParse *)(obj))->config_mutex))
44 #define GST_RAW_BASE_PARSE_CONFIG_MUTEX_UNLOCK(obj) g_mutex_unlock(&(((GstRawBaseParse *)(obj))->config_mutex))
45 
46 typedef enum _GstRawBaseParseConfig GstRawBaseParseConfig;
47 typedef struct _GstRawBaseParse GstRawBaseParse;
48 typedef struct _GstRawBaseParseClass GstRawBaseParseClass;
49 
50 /**
51  * GstRawBaseParseConfig:
52  * @GST_RAW_BASE_PARSE_CONFIG_CURRENT: configuration that is currently active
53  * @GST_RAW_BASE_PARSE_CONFIG_SINKCAPS: configuration that is defined by the input sink caps
54  * @GST_RAW_BASE_PARSE_CONFIG_PROPERTIES: configuration that is defined by class properties
55  *
56  * Identifier for the type of parser configuration.
57  */
58 enum _GstRawBaseParseConfig
59 {
60   GST_RAW_BASE_PARSE_CONFIG_CURRENT = 1,
61   GST_RAW_BASE_PARSE_CONFIG_SINKCAPS,
62   GST_RAW_BASE_PARSE_CONFIG_PROPERTIES
63 };
64 
65 /**
66  * GstRawBaseParse:
67  *
68  * The opaque #GstRawBaseParse data structure.
69  */
70 struct _GstRawBaseParse
71 {
72   GstBaseParse parent;
73 
74   /*< private > */
75 
76   /* TRUE if the source pad caps have been set already. This is used
77    * for checking if the source pad caps have to be set. */
78   gboolean src_caps_set;
79 
80   /* Mutex which protects access to and modifications on the configs. */
81   GMutex config_mutex;
82 };
83 
84 /**
85  * GstRawBaseParseClass:
86  * @parent_class:              The parent class structure
87  * @set_current_config:        Sets the new current configuration. Subclasses must internally
88  *                             switch to this new configuration. Return FALSE if this failed,
89  *                             TRUE otherwise.
90  * @get_current_config:        Gets the current configuration. All return values except
91  *                             except GST_RAW_BASE_PARSE_CONFIG_CURRENT are valid.
92  * @set_config_from_caps:      Parses the caps and copies its information to the configuration.
93  *                             Returns FALSE if this failed, TRUE otherwise. Specified caps
94  *                             are not unref'd.
95  * @get_caps_from_config:      Creates a new caps structure out of the information from the
96  *                             specified configuration. Ownership over the returned caps are
97  *                             transferred to the caller. If something fails during the caps
98  *                             creation, the vfunc must make sure to destroy any partially
99  *                             created caps; the *caps value is always set to NULL in case of
100  *                             failure. Returns FALSE in case of failure,
101  *                             TRUE in case of success.
102  * @get_config_frame_size:     Gets the size of one frame, in bytes, from the specified
103  *                             configuration. This must be the size of the complete frame,
104  *                             including any overhead (metadata, headers, padding bytes etc.).
105  * @get_max_frames_per_buffer: Optional.
106  *                             Returns up to how many complete frames one output buffer may
107  *                             contain. The value must be nonzero. This is useful for example
108  *                             with video parsers which need to ensure that one output buffer
109  *                             contains only one video frame, even if the input buffer contains
110  *                             several complete frames. If this vfunc is not set, then there
111  *                             is no maximum number of frames per buffer - the parser reads
112  *                             as many complete frames as possible from the input buffer.
113  * @is_config_ready:           Returns TRUE if the specified configuration is ready, FALSE
114  *                             otherwise.
115  * @process:                   Optional.
116  *                             This is useful to do any last minute processing before the
117  *                             data is pushed downstream. One example is channel reordering
118  *                             in audio parsers.
119  *                             in_data is the complete input buffer, total_num_in_bytes is
120  *                             the total amount of bytes this input buffer contains (including
121  *                             excess bytes that form an incomplete rame). num_valid_in_bytes
122  *                             is the subset of these bytes that are to be pushed downstream.
123  *                             If for example the frame size is 4, and total_num_in_bytes is
124  *                             411, then num_valid_in_bytes will be 408, since the last 3
125  *                             bytes form an incomplete frame.
126  *                             The value of num_valid_in_bytes excludes the overhead bytes
127  *                             indicated by @get_overhead_size.
128  *                             If the subclass creates a new buffer here, *processed_data
129  *                             must be set to the new buffer's pointer. If the subclass does
130  *                             not create any new buffer, and just expects the first
131  *                             num_valid_in_bytes of the input buffer to be pushed downstream,
132  *                             then *processed_data must be set to NULL.
133  *                             If this vfunc is not set, then the parser behaves as if this
134  *                             vfunc set *processed_data data to NULL.
135  * @is_unit_format_supported:  Returns TRUE if the given format is supported by the
136  *                             @get_units_per_second function, FALSE otherwise.
137  * @get_units_per_second:      Returns how many units per second exist for a given format.
138  *                             For example, with an audio parser and format DEFAULT, the units
139  *                             per second are typically the number of samples per second
140  *                             (= the sample rate). For video parsers, this would be the frame
141  *                             rate. If BYTES or TIME are used as format, then the result must
142  *                             not include any extra overhead (metadata, headers, padding etc.)
143  * @get_overhead_size:         Optional.
144  *                             Returns the number of bytes that make up the portion of a frame
145  *                             that isn't payload. Examples are padding bytes, headers, and
146  *                             other kinds of metadata. If this vfunc isn't defined, then an
147  *                             overhead size of 0 bytes is assumed.
148  *
149  * Subclasses are required to override all vfuncs except for @process, which is optional.
150  * The raw base parser lock is held during all vfunc calls.
151  */
152 struct _GstRawBaseParseClass
153 {
154   GstBaseParseClass parent_class;
155 
156   gboolean              (*set_current_config)        (GstRawBaseParse *raw_base_parse,
157                                                       GstRawBaseParseConfig config);
158   GstRawBaseParseConfig (*get_current_config)        (GstRawBaseParse *raw_base_parse);
159 
160   gboolean              (*set_config_from_caps)      (GstRawBaseParse * raw_base_parse,
161                                                       GstRawBaseParseConfig config,
162                                                       GstCaps * caps);
163   gboolean              (*get_caps_from_config)      (GstRawBaseParse * raw_base_parse,
164                                                       GstRawBaseParseConfig config,
165                                                       GstCaps ** caps);
166 
167   gsize                 (*get_config_frame_size)     (GstRawBaseParse * raw_base_parse,
168                                                       GstRawBaseParseConfig config);
169   guint                 (*get_max_frames_per_buffer) (GstRawBaseParse * raw_base_parse,
170                                                       GstRawBaseParseConfig config);
171 
172   gboolean              (*is_config_ready)           (GstRawBaseParse * raw_base_parse,
173                                                       GstRawBaseParseConfig config);
174 
175   gboolean              (*process)                   (GstRawBaseParse * raw_base_parse,
176                                                       GstRawBaseParseConfig config,
177                                                       GstBuffer * in_data,
178                                                       gsize total_num_in_bytes,
179                                                       gsize num_valid_in_bytes,
180                                                       GstBuffer ** processed_data);
181 
182   gboolean              (*is_unit_format_supported)  (GstRawBaseParse * raw_base_parse,
183                                                       GstFormat format);
184   void                  (*get_units_per_second)      (GstRawBaseParse * raw_base_parse,
185                                                       GstFormat format,
186                                                       GstRawBaseParseConfig config,
187                                                       gsize * units_per_sec_n,
188                                                       gsize * units_per_sec_d);
189 
190   gint                  (*get_overhead_size)         (GstRawBaseParse * raw_base_parse,
191                                                       GstRawBaseParseConfig config);
192 
193   gint                  (*get_alignment)             (GstRawBaseParse * raw_base_parse,
194                                                       GstRawBaseParseConfig config);
195 };
196 
197 void gst_raw_base_parse_invalidate_src_caps (GstRawBaseParse * raw_base_parse);
198 
199 GType gst_raw_base_parse_get_type (void);
200 
201 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstRawBaseParse, gst_object_unref)
202 
203 G_END_DECLS
204 
205 #endif
206