Blame gst/rawparse/gstrawbaseparse.h

Packit 971217
/* GStreamer
Packit 971217
 * Copyright (C) <2016> Carlos Rafael Giani <dv at pseudoterminal dot org>
Packit 971217
 *
Packit 971217
 * This library is free software; you can redistribute it and/or
Packit 971217
 * modify it under the terms of the GNU Library General Public
Packit 971217
 * License as published by the Free Software Foundation; either
Packit 971217
 * version 2 of the License, or (at your option) any later version.
Packit 971217
 *
Packit 971217
 * This library is distributed in the hope that it will be useful,
Packit 971217
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 971217
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 971217
 * Library General Public License for more details.
Packit 971217
 *
Packit 971217
 * You should have received a copy of the GNU Library General Public
Packit 971217
 * License along with this library; if not, write to the
Packit 971217
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit 971217
 * Boston, MA 02110-1301, USA.
Packit 971217
 */
Packit 971217
Packit 971217
#ifndef __GST_RAW_BASE_PARSE_H__
Packit 971217
#define __GST_RAW_BASE_PARSE_H__
Packit 971217
Packit 971217
#include <gst/gst.h>
Packit 971217
#include <gst/base/base.h>
Packit 971217
Packit 971217
G_BEGIN_DECLS
Packit 971217
Packit 971217
#define GST_TYPE_RAW_BASE_PARSE \
Packit 971217
  (gst_raw_base_parse_get_type())
Packit 971217
#define GST_RAW_BASE_PARSE(obj) \
Packit 971217
  (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_RAW_BASE_PARSE, GstRawBaseParse))
Packit 971217
#define GST_RAW_BASE_PARSE_CAST(obj) \
Packit 971217
  ((GstRawBaseParse *)(obj))
Packit 971217
#define GST_RAW_BASE_PARSE_CLASS(klass) \
Packit 971217
  (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_RAW_BASE_PARSE, GstRawBaseParseClass))
Packit 971217
#define GST_RAW_BASE_PARSE_GET_CLASS(obj) \
Packit 971217
  (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_RAW_BASE_PARSE, GstRawBaseParseClass))
Packit 971217
#define GST_IS_RAW_BASE_PARSE(obj) \
Packit 971217
  (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_RAW_BASE_PARSE))
Packit 971217
#define GST_IS_RAW_BASE_PARSE_CLASS(klass) \
Packit 971217
  (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_RAW_BASE_PARSE))
Packit 971217
Packit 971217
#define GST_RAW_BASE_PARSE_CONFIG_MUTEX_LOCK(obj)   g_mutex_lock(&(((GstRawBaseParse *)(obj))->config_mutex))
Packit 971217
#define GST_RAW_BASE_PARSE_CONFIG_MUTEX_UNLOCK(obj) g_mutex_unlock(&(((GstRawBaseParse *)(obj))->config_mutex))
Packit 971217
Packit 971217
typedef enum _GstRawBaseParseConfig GstRawBaseParseConfig;
Packit 971217
typedef struct _GstRawBaseParse GstRawBaseParse;
Packit 971217
typedef struct _GstRawBaseParseClass GstRawBaseParseClass;
Packit 971217
Packit 971217
/**
Packit 971217
 * GstRawBaseParseConfig:
Packit 971217
 * @GST_RAW_BASE_PARSE_CONFIG_CURRENT: configuration that is currently active
Packit 971217
 * @GST_RAW_BASE_PARSE_CONFIG_SINKCAPS: configuration that is defined by the input sink caps
Packit 971217
 * @GST_RAW_BASE_PARSE_CONFIG_PROPERTIES: configuration that is defined by class properties
Packit 971217
 *
Packit 971217
 * Identifier for the type of parser configuration.
Packit 971217
 */
Packit 971217
enum _GstRawBaseParseConfig
Packit 971217
{
Packit 971217
  GST_RAW_BASE_PARSE_CONFIG_CURRENT = 1,
Packit 971217
  GST_RAW_BASE_PARSE_CONFIG_SINKCAPS,
Packit 971217
  GST_RAW_BASE_PARSE_CONFIG_PROPERTIES
Packit 971217
};
Packit 971217
Packit 971217
/**
Packit 971217
 * GstRawBaseParse:
Packit 971217
 *
Packit 971217
 * The opaque #GstRawBaseParse data structure.
Packit 971217
 */
Packit 971217
struct _GstRawBaseParse
Packit 971217
{
Packit 971217
  GstBaseParse parent;
Packit 971217
Packit 971217
  /*< private > */
Packit 971217
Packit 971217
  /* TRUE if the source pad caps have been set already. This is used
Packit 971217
   * for checking if the source pad caps have to be set. */
Packit 971217
  gboolean src_caps_set;
Packit 971217
Packit 971217
  /* Mutex which protects access to and modifications on the configs. */
Packit 971217
  GMutex config_mutex;
Packit 971217
};
Packit 971217
Packit 971217
/**
Packit 971217
 * GstRawBaseParseClass:
Packit 971217
 * @parent_class:              The parent class structure
Packit 971217
 * @set_current_config:        Sets the new current configuration. Subclasses must internally
Packit 971217
 *                             switch to this new configuration. Return FALSE if this failed,
Packit 971217
 *                             TRUE otherwise.
Packit 971217
 * @get_current_config:        Gets the current configuration. All return values except
Packit 971217
 *                             except GST_RAW_BASE_PARSE_CONFIG_CURRENT are valid.
Packit 971217
 * @set_config_from_caps:      Parses the caps and copies its information to the configuration.
Packit 971217
 *                             Returns FALSE if this failed, TRUE otheriwse. Specified caps
Packit 971217
 *                             are not unref'd.
Packit 971217
 * @get_caps_from_config:      Creates a new caps structure out of the information from the
Packit 971217
 *                             specified configuration. Ownership over the returned caps are
Packit 971217
 *                             transferred to the caller. If something fails during the caps
Packit 971217
 *                             creation, the vfunc must make sure to destroy any partially
Packit 971217
 *                             created caps; the *caps value is always set to NULL in case of
Packit 971217
 *                             failure. Returns FALSE in case of failure,
Packit 971217
 *                             TRUE in case of success.
Packit 971217
 * @get_config_frame_size:     Gets the size of one frame, in bytes, from the specified
Packit 971217
 *                             configuration. This must be the size of the complete frame,
Packit 971217
 *                             including any overhead (metadata, headers, padding bytes etc.).
Packit 971217
 * @get_max_frames_per_buffer: Optional.
Packit 971217
 *                             Returns up to how many complete frames one output buffer may
Packit 971217
 *                             contain. The value must be nonzero. This is useful for example
Packit 971217
 *                             with video parsers which need to ensure that one output buffer
Packit 971217
 *                             contains only one video frame, even if the input buffer contains
Packit 971217
 *                             several complete frames. If this vfunc is not set, then there
Packit 971217
 *                             is no maximum number of frames per buffer - the parser reads
Packit 971217
 *                             as many complete frames as possible from the input buffer.
Packit 971217
 * @is_config_ready:           Returns TRUE if the specified configuration is ready, FALSE
Packit 971217
 *                             otherwise.
Packit 971217
 * @process:                   Optional.
Packit 971217
 *                             This is useful to do any last minute processing before the
Packit 971217
 *                             data is pushed downstream. One example is channel reordering
Packit 971217
 *                             in audio parsers.
Packit 971217
 *                             in_data is the complete input buffer, total_num_in_bytes is
Packit 971217
 *                             the total amount of bytes this input buffer contains (including
Packit 971217
 *                             excess bytes that form an incomplete rame). num_valid_in_bytes
Packit 971217
 *                             is the subset of these bytes that are to be pushed downstream.
Packit 971217
 *                             If for example the frame size is 4, and total_num_in_bytes is
Packit 971217
 *                             411, then num_valid_in_bytes will be 408, since the last 3
Packit 971217
 *                             bytes form an incomplete frame.
Packit 971217
 *                             The value of num_valid_in_bytes excludes the overhead bytes
Packit 971217
 *                             indicated by @get_overhead_size.
Packit 971217
 *                             If the subclass creates a new buffer here, *processed_data
Packit 971217
 *                             must be set to the new buffer's pointer. If the subclass does
Packit 971217
 *                             not create any new buffer, and just expects the first
Packit 971217
 *                             num_valid_in_bytes of the input buffer to be pushed downstream,
Packit 971217
 *                             then *processed_data must be set to NULL.
Packit 971217
 *                             If this vfunc is not set, then the parser behaves as if this
Packit 971217
 *                             vfunc set *processed_data data to NULL.
Packit 971217
 * @is_unit_format_supported:  Returns TRUE if the given format is supported by the
Packit 971217
 *                             @get_units_per_second function, FALSE otherwise.
Packit 971217
 * @get_units_per_second:      Returns how many units per second exist for a given format.
Packit 971217
 *                             For example, with an audio parser and format DEFAULT, the units
Packit 971217
 *                             per second are typically the number of samples per second
Packit 971217
 *                             (= the sample rate). For video parsers, this would be the frame
Packit 971217
 *                             rate. If BYTES or TIME are used as format, then the result must
Packit 971217
 *                             not include any extra overhead (metadata, headers, padding etc.)
Packit 971217
 * @get_overhead_size:         Optional.
Packit 971217
 *                             Returns the number of bytes that make up the portion of a frame
Packit 971217
 *                             that isn't payload. Examples are padding bytes, headers, and
Packit 971217
 *                             other kinds of metadata. If this vfunc isn't defined, then an
Packit 971217
 *                             overhead size of 0 bytes is assumed.
Packit 971217
 *
Packit 971217
 * Subclasses are required to override all vfuncs except for @process, which is optional.
Packit 971217
 * The raw base parser lock is held during all vfunc calls.
Packit 971217
 */
Packit 971217
struct _GstRawBaseParseClass
Packit 971217
{
Packit 971217
  GstBaseParseClass parent_class;
Packit 971217
Packit 971217
  gboolean              (*set_current_config)        (GstRawBaseParse *raw_base_parse,
Packit 971217
                                                      GstRawBaseParseConfig config);
Packit 971217
  GstRawBaseParseConfig (*get_current_config)        (GstRawBaseParse *raw_base_parse);
Packit 971217
Packit 971217
  gboolean              (*set_config_from_caps)      (GstRawBaseParse * raw_base_parse,
Packit 971217
                                                      GstRawBaseParseConfig config,
Packit 971217
                                                      GstCaps * caps);
Packit 971217
  gboolean              (*get_caps_from_config)      (GstRawBaseParse * raw_base_parse,
Packit 971217
                                                      GstRawBaseParseConfig config,
Packit 971217
                                                      GstCaps ** caps);
Packit 971217
Packit 971217
  gsize                 (*get_config_frame_size)     (GstRawBaseParse * raw_base_parse,
Packit 971217
                                                      GstRawBaseParseConfig config);
Packit 971217
  guint                 (*get_max_frames_per_buffer) (GstRawBaseParse * raw_base_parse,
Packit 971217
                                                      GstRawBaseParseConfig config);
Packit 971217
Packit 971217
  gboolean              (*is_config_ready)           (GstRawBaseParse * raw_base_parse,
Packit 971217
                                                      GstRawBaseParseConfig config);
Packit 971217
Packit 971217
  gboolean              (*process)                   (GstRawBaseParse * raw_base_parse,
Packit 971217
                                                      GstRawBaseParseConfig config,
Packit 971217
                                                      GstBuffer * in_data,
Packit 971217
                                                      gsize total_num_in_bytes,
Packit 971217
                                                      gsize num_valid_in_bytes,
Packit 971217
                                                      GstBuffer ** processed_data);
Packit 971217
Packit 971217
  gboolean              (*is_unit_format_supported)  (GstRawBaseParse * raw_base_parse,
Packit 971217
                                                      GstFormat format);
Packit 971217
  void                  (*get_units_per_second)      (GstRawBaseParse * raw_base_parse,
Packit 971217
                                                      GstFormat format,
Packit 971217
                                                      GstRawBaseParseConfig config,
Packit 971217
                                                      gsize * units_per_sec_n,
Packit 971217
                                                      gsize * units_per_sec_d);
Packit 971217
Packit 971217
  gint                  (*get_overhead_size)         (GstRawBaseParse * raw_base_parse,
Packit 971217
                                                      GstRawBaseParseConfig config);
Packit 971217
Packit 971217
  gint                  (*get_alignment)             (GstRawBaseParse * raw_base_parse,
Packit 971217
                                                      GstRawBaseParseConfig config);
Packit 971217
};
Packit 971217
Packit 971217
void gst_raw_base_parse_invalidate_src_caps (GstRawBaseParse * raw_base_parse);
Packit 971217
Packit 971217
GType gst_raw_base_parse_get_type (void);
Packit 971217
Packit 971217
G_END_DECLS
Packit 971217
Packit 971217
#endif