Commit d5085251 authored by Carlos Rafael Giani's avatar Carlos Rafael Giani Committed by Sebastian Dröge
Browse files

rawparse: Add new raw audio and video parser elements

The new rawaudioparse and rawvideoparse elements are based on GstBaseParse
and completely replace audioparse and videoparse

https://bugzilla.gnome.org/show_bug.cgi?id=767011
parent f6e62647
......@@ -4,8 +4,12 @@ plugin_LTLIBRARIES = libgstrawparse.la
libgstrawparse_la_SOURCES = \
gstrawparse.c \
gstunalignedaudioparse.c \
gstunalignedvideoparse.c \
gstaudioparse.c \
gstvideoparse.c \
gstrawbaseparse.c \
gstrawaudioparse.c \
gstrawvideoparse.c \
plugin.c
libgstrawparse_la_CFLAGS = \
$(GST_PLUGINS_BASE_CFLAGS) \
......@@ -21,7 +25,12 @@ libgstrawparse_la_LIBTOOLFLAGS = $(GST_PLUGIN_LIBTOOLFLAGS)
noinst_HEADERS = \
unalignedaudio.h \
unalignedvideo.h \
gstunalignedaudioparse.h \
gstunalignedvideoparse.h \
gstaudioparse.h \
gstrawparse.h \
gstvideoparse.h
gstvideoparse.h \
gstrawbaseparse.h \
gstrawaudioparse.h \
gstrawvideoparse.h
This diff is collapsed.
/* 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_AUDIO_PARSE_H__
#define __GST_RAW_AUDIO_PARSE_H__
#include <gst/gst.h>
#include <gst/audio/audio.h>
#include "gstrawbaseparse.h"
G_BEGIN_DECLS
#define GST_TYPE_RAW_AUDIO_PARSE \
(gst_raw_audio_parse_get_type())
#define GST_RAW_AUDIO_PARSE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_RAW_AUDIO_PARSE, GstRawAudioParse))
#define GST_RAW_AUDIO_PARSE_CAST(obj) \
((GstRawAudioParse *)(obj))
#define GST_RAW_AUDIO_PARSE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_RAW_AUDIO_PARSE, GstRawAudioParseClass))
#define GST_IS_RAW_AUDIO_PARSE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_RAW_AUDIO_PARSE))
#define GST_IS_RAW_AUDIO_PARSE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_RAW_AUDIO_PARSE))
typedef enum _GstRawAudioParseFormat GstRawAudioParseFormat;
typedef struct _GstRawAudioParseConfig GstRawAudioParseConfig;
typedef struct _GstRawAudioParse GstRawAudioParse;
typedef struct _GstRawAudioParseClass GstRawAudioParseClass;
enum _GstRawAudioParseFormat
{
GST_RAW_AUDIO_PARSE_FORMAT_PCM,
GST_RAW_AUDIO_PARSE_FORMAT_MULAW,
GST_RAW_AUDIO_PARSE_FORMAT_ALAW
};
/* Contains information about the sample rate, format, and channel count to use. */
struct _GstRawAudioParseConfig
{
/* If TRUE, then this configuration is ready to use */
gboolean ready;
/* Format of the configuration. Can be PCM, a-law, mu-law. */
GstRawAudioParseFormat format;
/* If format is set to PCM, this specifies the exact PCM format in use.
* Meaningless if format is set to anything other than PCM. */
GstAudioFormat pcm_format;
/* Bytes per frame. Calculated as: bpf = bytes_per_sample * num_channels
* Must be nonzero. This is the size of one frame, the value returned
* by the GstRawBaseParseClass get_config_frame_size() vfunc. */
guint bpf;
/* Sample rate in Hz - must be nonzero */
guint sample_rate;
/* Number of channels - must be nonzero */
guint num_channels;
/* TRUE if the data is interleaved, FALSE otherwise */
gboolean interleaved;
/* Array of channel positions, one position per channel; its first
* num_channels values are valid. They are computed out of the number
* of channels if no positions are explicitely given. */
GstAudioChannelPosition channel_positions[64];
/* If the channel_positions are in a valid GStreamer channel order, then
* this is not used, and needs_channel_reordering is FALSE. Otherwise,
* this contains the same positions as in channel_positions, but in the
* order GStreamer expects. needs_channel_reordering will be TRUE in that
* case. This is used for reordering samples in outgoing buffers if
* necessary. */
GstAudioChannelPosition reordered_channel_positions[64];
/* TRUE if channel reordering is necessary, FALSE otherwise. See above
* for details. */
gboolean needs_channel_reordering;
};
struct _GstRawAudioParse
{
GstRawBaseParse parent;
/*< private > */
/* Configuration controlled by the object properties. Its ready value
* is set to TRUE from the start, so it can be used right away.
*/
GstRawAudioParseConfig properties_config;
/* Configuration controlled by the sink caps. Its ready value is
* initially set to FALSE until valid sink caps come in. It is set to
* FALSE again when the stream-start event is observed.
*/
GstRawAudioParseConfig sink_caps_config;
/* Currently active configuration. Points either to properties_config
* or to sink_caps_config. This is never NULL. */
GstRawAudioParseConfig *current_config;
};
struct _GstRawAudioParseClass
{
GstRawBaseParseClass parent_class;
};
GType gst_raw_audio_parse_get_type (void);
GType gst_raw_audio_parse_format_get_type (void);
G_END_DECLS
#endif
This diff is collapsed.
/* 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);
};
void gst_raw_base_parse_invalidate_src_caps (GstRawBaseParse * raw_base_parse);
GType gst_raw_base_parse_get_type (void);
G_END_DECLS
#endif
This diff is collapsed.
/* 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_VIDEO_PARSE_H__
#define __GST_RAW_VIDEO_PARSE_H__
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstrawbaseparse.h"
G_BEGIN_DECLS
#define GST_TYPE_RAW_VIDEO_PARSE \
(gst_raw_video_parse_get_type())
#define GST_RAW_VIDEO_PARSE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_RAW_VIDEO_PARSE, GstRawVideoParse))
#define GST_RAW_VIDEO_PARSE_CAST(obj) \
((GstRawVideoParse *)(obj))
#define GST_RAW_VIDEO_PARSE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_RAW_VIDEO_PARSE, GstRawVideoParseClass))
#define GST_IS_RAW_VIDEO_PARSE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_RAW_VIDEO_PARSE))
#define GST_IS_RAW_VIDEO_PARSE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_RAW_VIDEO_PARSE))
typedef struct _GstRawVideoParseConfig GstRawVideoParseConfig;
typedef struct _GstRawVideoParse GstRawVideoParse;
typedef struct _GstRawVideoParseClass GstRawVideoParseClass;
/* Contains information about the video frame format. */
struct _GstRawVideoParseConfig
{
/* If TRUE, then this configuration is ready to use */
gboolean ready;
/* FIXME: These values should not be necessary, since there's
* GstVideoInfo. However, setting these values in the video
* info independently is currently difficult. For example,
* setting the video format requires the gst_video_info_set_format()
* function, but this function also overwrites plane strides
* and offsets. */
gint width, height;
GstVideoFormat format;
gint pixel_aspect_ratio_n, pixel_aspect_ratio_d;
gint framerate_n, framerate_d;
gboolean interlaced;
gsize plane_offsets[GST_VIDEO_MAX_PLANES];
gint plane_strides[GST_VIDEO_MAX_PLANES];
/* If TRUE, then TFF flags are added to outgoing buffers and
* their video metadata */
gboolean top_field_first;
/* Distance between the start of each frame, in bytes. If this value
* is larger than the actual size of a frame, then the extra bytes
* are skipped. For example, with frames that have 115200 bytes, a
* frame_stride value of 120000 means that 4800 trailing bytes are
* skipped after the 115200 frame bytes. This is useful to skip
* metadata in between frames. */
guint frame_stride;
GstVideoInfo info;
};
struct _GstRawVideoParse
{
GstRawBaseParse parent;
/*< private > */
/* Configuration controlled by the object properties. Its ready value
* is set to TRUE from the start, so it can be used right away.
*/
GstRawVideoParseConfig properties_config;
/* Configuration controlled by the sink caps. Its ready value is
* initially set to FALSE until valid sink caps come in. It is set to
* FALSE again when the stream-start event is observed.
*/
GstRawVideoParseConfig sink_caps_config;
/* Currently active configuration. Points either to properties_config
* or to sink_caps_config. This is never NULL. */
GstRawVideoParseConfig *current_config;
};
struct _GstRawVideoParseClass
{
GstRawBaseParseClass parent_class;
};
GType gst_raw_video_parse_get_type (void);
G_END_DECLS
#endif
......@@ -96,7 +96,7 @@ gst_unaligned_audio_parse_init (GstUnalignedAudioParse * unaligned_audio_parse)
GstPad *ghostpad;
unaligned_audio_parse->inner_parser =
gst_element_factory_make ("audioparse", "inner_parser");
gst_element_factory_make ("rawaudioaudioparse", "inner_parser");
g_assert (unaligned_audio_parse->inner_parser != NULL);
g_object_set (G_OBJECT (unaligned_audio_parse->inner_parser),
......
/* GStreamer
* Copyright (C) 2016 Carlos Rafael Giani <dv@pseudoterminal.org>
*
* gstunalignedvideoparse.c:
*
* 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.
*/
#include <string.h>
#include <stdio.h>
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstunalignedvideoparse.h"
#include "unalignedvideo.h"
GST_DEBUG_CATEGORY (unaligned_video_parse_debug);
#define GST_CAT_DEFAULT unaligned_video_parse_debug
struct _GstUnalignedVideoParse
{
GstBin parent;
GstElement *inner_parser;
};
struct _GstUnalignedVideoParseClass
{
GstBinClass parent_class;
};
static GstStaticPadTemplate static_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_UNALIGNED_RAW_VIDEO_CAPS)
);
static GstStaticPadTemplate static_src_template =
GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL))
);
G_DEFINE_TYPE (GstUnalignedVideoParse, gst_unaligned_video_parse, GST_TYPE_BIN);
static void
gst_unaligned_video_parse_class_init (GstUnalignedVideoParseClass * klass)
{
GstElementClass *element_class;
GST_DEBUG_CATEGORY_INIT (unaligned_video_parse_debug, "unalignedvideoparse",
0, "Unaligned raw video parser");
element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&static_sink_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&static_src_template));
gst_element_class_set_static_metadata (element_class,
"unalignedvideoparse",
"Codec/Parser/Bin/Video",
"Parse unaligned raw video data",
"Carlos Rafael Giani <dv@pseudoterminal.org>");
}
static void
gst_unaligned_video_parse_init (GstUnalignedVideoParse * unaligned_video_parse)
{
GstPad *inner_pad;
GstPad *ghostpad;
unaligned_video_parse->inner_parser =
gst_element_factory_make ("rawvideoparse", "inner_parser");
g_assert (unaligned_video_parse->inner_parser != NULL);
g_object_set (G_OBJECT (unaligned_video_parse->inner_parser),
"use-sink-caps", TRUE, NULL);
gst_bin_add (GST_BIN (unaligned_video_parse),
unaligned_video_parse->inner_parser);
inner_pad =
gst_element_get_static_pad (unaligned_video_parse->inner_parser, "sink");
ghostpad =
gst_ghost_pad_new_from_template ("sink", inner_pad,
gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS
(unaligned_video_parse), "sink"));
gst_element_add_pad (GST_ELEMENT (unaligned_video_parse), ghostpad);
gst_object_unref (GST_OBJECT (inner_pad));
inner_pad = gst_element_get_static_pad (unaligned_video_parse->inner_parser,
"src");
ghostpad =
gst_ghost_pad_new_from_template ("src", inner_pad,
gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS
(unaligned_video_parse), "src"));
gst_element_add_pad (GST_ELEMENT (unaligned_video_parse), ghostpad);
gst_object_unref (GST_OBJECT (inner_pad));
}
/* GStreamer
* Copyright (C) 2016 Carlos Rafael Giani <dv@pseudoterminal.org>
*
* gstunalignedvideoparse.h:
*
* This library is free software; you can redistribute it and/or