mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-07 16:08:51 +00:00
+ some whitespace changes + adding dummy definitions to prepare for float caps
Original commit message from CVS: + some whitespace changes + adding dummy definitions to prepare for float caps
This commit is contained in:
parent
f761e28ff2
commit
2ad6bd23cf
1 changed files with 292 additions and 329 deletions
|
@ -19,15 +19,14 @@
|
||||||
* Boston, MA 02111-1307, USA.
|
* Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
#include "config.h"
|
|
||||||
#endif
|
|
||||||
#include <gst/gst.h>
|
|
||||||
#include <string.h>
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <gst/gst.h>
|
||||||
|
#include <gst/audio/audio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
static void
|
static void
|
||||||
print_caps (GstCaps *caps)
|
print_caps (GstCaps *caps)
|
||||||
|
@ -53,17 +52,42 @@ print_caps (GstCaps *caps)
|
||||||
#define GST_IS_AUDIO_CONVERT_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AUDIO_CONVERT))
|
#define GST_IS_AUDIO_CONVERT_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AUDIO_CONVERT))
|
||||||
|
|
||||||
typedef struct _GstAudioConvert GstAudioConvert;
|
typedef struct _GstAudioConvert GstAudioConvert;
|
||||||
|
typedef struct _GstAudioConvertCaps GstAudioConvertCaps;
|
||||||
typedef struct _GstAudioConvertClass GstAudioConvertClass;
|
typedef struct _GstAudioConvertClass GstAudioConvertClass;
|
||||||
|
|
||||||
|
/* this struct is a handy way of passing around all the caps info ... */
|
||||||
|
struct _GstAudioConvertCaps {
|
||||||
|
/* general caps */
|
||||||
|
gint endianness;
|
||||||
|
gint width;
|
||||||
|
gint rate;
|
||||||
|
gint channels;
|
||||||
|
|
||||||
|
gboolean is_float; /* true iff a pad is carrying float data */
|
||||||
|
|
||||||
|
/* int audio caps */
|
||||||
|
gint depth;
|
||||||
|
gboolean is_signed;
|
||||||
|
|
||||||
|
/* float audio caps */
|
||||||
|
guint buffer_frames;
|
||||||
|
};
|
||||||
|
|
||||||
struct _GstAudioConvert {
|
struct _GstAudioConvert {
|
||||||
GstElement element;
|
GstElement element;
|
||||||
|
|
||||||
/* pads */
|
/* pads */
|
||||||
GstPad * sink;
|
GstPad * sink;
|
||||||
GstPad * src;
|
GstPad * src;
|
||||||
|
|
||||||
/* properties */
|
/* properties */
|
||||||
gboolean aggressive;
|
gboolean aggressive;
|
||||||
|
guint min_rate, max_rate, rate_steps;
|
||||||
|
|
||||||
/* caps: 0 = sink, 1 = src, so always convert from 0 to 1 */
|
/* caps: 0 = sink, 1 = src, so always convert from 0 to 1 */
|
||||||
gboolean caps_set[2];
|
gboolean caps_set[2];
|
||||||
|
GstAudioConvertCaps caps[2];
|
||||||
|
|
||||||
gint law[2];
|
gint law[2];
|
||||||
gint endian[2];
|
gint endian[2];
|
||||||
gint sign[2];
|
gint sign[2];
|
||||||
|
@ -71,6 +95,9 @@ struct _GstAudioConvert {
|
||||||
gint width[2]; /* in BYTES */
|
gint width[2]; /* in BYTES */
|
||||||
gint rate[2];
|
gint rate[2];
|
||||||
gint channels[2];
|
gint channels[2];
|
||||||
|
|
||||||
|
/* conversion functions */
|
||||||
|
GstBuffer * (* convert_internal) (GstAudioConvert *this, GstBuffer *buf);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstAudioConvertClass {
|
struct _GstAudioConvertClass {
|
||||||
|
@ -81,100 +108,73 @@ struct _GstAudioConvertClass {
|
||||||
static GType gst_audio_convert_get_type (void);
|
static GType gst_audio_convert_get_type (void);
|
||||||
static void gst_audio_convert_class_init (GstAudioConvertClass *klass);
|
static void gst_audio_convert_class_init (GstAudioConvertClass *klass);
|
||||||
static void gst_audio_convert_init (GstAudioConvert *audio_convert);
|
static void gst_audio_convert_init (GstAudioConvert *audio_convert);
|
||||||
static void gst_audio_convert_set_property (GObject *object,
|
static void gst_audio_convert_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
|
||||||
guint prop_id,
|
static void gst_audio_convert_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
|
||||||
const GValue *value,
|
|
||||||
GParamSpec *pspec);
|
|
||||||
static void gst_audio_convert_get_property (GObject *object,
|
|
||||||
guint prop_id,
|
|
||||||
GValue *value,
|
|
||||||
GParamSpec *pspec);
|
|
||||||
/* gstreamer functions */
|
/* gstreamer functions */
|
||||||
static void gst_audio_convert_chain (GstPad *pad,
|
static void gst_audio_convert_chain (GstPad *pad, GstBuffer *buf);
|
||||||
GstBuffer *buf);
|
static GstPadLinkReturn gst_audio_convert_link (GstPad *pad, GstCaps *caps);
|
||||||
static GstPadLinkReturn gst_audio_convert_link (GstPad *pad,
|
|
||||||
GstCaps *caps);
|
|
||||||
static GstElementStateReturn gst_audio_convert_change_state (GstElement *element);
|
static GstElementStateReturn gst_audio_convert_change_state (GstElement *element);
|
||||||
|
|
||||||
/* actual work */
|
/* actual work */
|
||||||
static gboolean gst_audio_convert_set_caps (GstPad *pad);
|
static gboolean gst_audio_convert_set_caps (GstPad *pad);
|
||||||
static GstBuffer * gst_audio_convert_buffer_to_default_format (GstAudioConvert *this,
|
|
||||||
GstBuffer *buf);
|
|
||||||
static GstBuffer * gst_audio_convert_buffer_from_default_format (GstAudioConvert *this,
|
|
||||||
GstBuffer *buf);
|
|
||||||
static GstBuffer * gst_audio_convert_channels (GstAudioConvert *this,
|
|
||||||
GstBuffer *buf);
|
|
||||||
|
|
||||||
|
static GstBuffer * gst_audio_convert_buffer_to_default_format (GstAudioConvert *this, GstBuffer *buf);
|
||||||
|
static GstBuffer * gst_audio_convert_buffer_from_default_format (GstAudioConvert *this, GstBuffer *buf);
|
||||||
|
|
||||||
|
static GstBuffer * gst_audio_convert_channels (GstAudioConvert *this, GstBuffer *buf);
|
||||||
static GstElementClass *parent_class = NULL;
|
|
||||||
/*static guint gst_audio_convert_signals[LAST_SIGNAL] = { 0 }; */
|
|
||||||
|
|
||||||
/* AudioConvert signals and args */
|
/* AudioConvert signals and args */
|
||||||
enum {
|
enum {
|
||||||
/* FILL ME */
|
/* FILL ME */
|
||||||
LAST_SIGNAL
|
LAST_SIGNAL
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
ARG_0,
|
ARG_0,
|
||||||
ARG_AGGRESSIVE,
|
ARG_AGGRESSIVE,
|
||||||
|
ARG_MIN_RATE,
|
||||||
|
ARG_MAX_RATE,
|
||||||
|
ARG_RATE_STEPS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static GstElementClass *parent_class = NULL;
|
||||||
|
/*static guint gst_audio_convert_signals[LAST_SIGNAL] = { 0 }; */
|
||||||
|
|
||||||
/*** GSTREAMER PROTOTYPES *****************************************************/
|
/*** GSTREAMER PROTOTYPES *****************************************************/
|
||||||
|
|
||||||
GST_PAD_TEMPLATE_FACTORY (audio_convert_src_template_factory,
|
GST_PAD_TEMPLATE_FACTORY (audio_convert_src_template_factory,
|
||||||
"src",
|
"src",
|
||||||
GST_PAD_SRC,
|
GST_PAD_SRC,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
GST_CAPS_NEW (
|
gst_caps_append (
|
||||||
"audio_convert_src",
|
gst_caps_new (
|
||||||
|
"audio_convert_src_int",
|
||||||
"audio/x-raw-int",
|
"audio/x-raw-int",
|
||||||
"endianness", GST_PROPS_LIST (
|
GST_AUDIO_INT_PAD_TEMPLATE_PROPS),
|
||||||
GST_PROPS_INT (G_LITTLE_ENDIAN),
|
gst_caps_new (
|
||||||
GST_PROPS_INT (G_BIG_ENDIAN)
|
"audio_convert_src_float",
|
||||||
),
|
"audio/x-raw-float",
|
||||||
"signed", GST_PROPS_LIST (
|
GST_AUDIO_FLOAT_PAD_TEMPLATE_PROPS)
|
||||||
GST_PROPS_BOOLEAN (FALSE),
|
|
||||||
GST_PROPS_BOOLEAN (TRUE)
|
|
||||||
),
|
|
||||||
"depth", GST_PROPS_INT_RANGE (1, 32),
|
|
||||||
"width", GST_PROPS_LIST (
|
|
||||||
GST_PROPS_INT (8),
|
|
||||||
GST_PROPS_INT (16),
|
|
||||||
GST_PROPS_INT (24),
|
|
||||||
GST_PROPS_INT (32)
|
|
||||||
),
|
|
||||||
"rate", GST_PROPS_INT_RANGE (8000, 192000),
|
|
||||||
"channels", GST_PROPS_INT_RANGE (1, 2)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
GST_PAD_TEMPLATE_FACTORY (audio_convert_sink_template_factory,
|
GST_PAD_TEMPLATE_FACTORY (audio_convert_sink_template_factory,
|
||||||
"sink",
|
"sink",
|
||||||
GST_PAD_SINK,
|
GST_PAD_SINK,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
GST_CAPS_NEW (
|
gst_caps_append (
|
||||||
"audio_convert_sink",
|
gst_caps_new (
|
||||||
|
"audio_convert_sink_int",
|
||||||
"audio/x-raw-int",
|
"audio/x-raw-int",
|
||||||
"endianness", GST_PROPS_LIST (
|
GST_AUDIO_INT_PAD_TEMPLATE_PROPS),
|
||||||
GST_PROPS_INT (G_LITTLE_ENDIAN),
|
gst_caps_new (
|
||||||
GST_PROPS_INT (G_BIG_ENDIAN)
|
"audio_convert_sink_float",
|
||||||
),
|
"audio/x-raw-float",
|
||||||
"signed", GST_PROPS_LIST (
|
GST_AUDIO_FLOAT_PAD_TEMPLATE_PROPS)
|
||||||
GST_PROPS_BOOLEAN (FALSE),
|
|
||||||
GST_PROPS_BOOLEAN (TRUE)
|
|
||||||
),
|
|
||||||
"depth", GST_PROPS_INT_RANGE (1, 32),
|
|
||||||
"width", GST_PROPS_LIST (
|
|
||||||
GST_PROPS_INT (8),
|
|
||||||
GST_PROPS_INT (16),
|
|
||||||
GST_PROPS_INT (24),
|
|
||||||
GST_PROPS_INT (32)
|
|
||||||
),
|
|
||||||
"rate", GST_PROPS_INT_RANGE (8000, 192000),
|
|
||||||
"channels", GST_PROPS_INT_RANGE (1, 2)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
/*** TYPE FUNCTIONS ***********************************************************/
|
/*** TYPE FUNCTIONS ***********************************************************/
|
||||||
|
|
||||||
GType
|
GType
|
||||||
|
@ -192,7 +192,9 @@ gst_audio_convert_get_type(void) {
|
||||||
0,
|
0,
|
||||||
(GInstanceInitFunc)gst_audio_convert_init,
|
(GInstanceInitFunc)gst_audio_convert_init,
|
||||||
};
|
};
|
||||||
audio_convert_type = g_type_register_static(GST_TYPE_ELEMENT, "GstAudioConvert", &audio_convert_info, 0);
|
audio_convert_type = g_type_register_static(GST_TYPE_ELEMENT,
|
||||||
|
"GstAudioConvert",
|
||||||
|
&audio_convert_info, 0);
|
||||||
}
|
}
|
||||||
return audio_convert_type;
|
return audio_convert_type;
|
||||||
}
|
}
|
||||||
|
@ -208,15 +210,32 @@ gst_audio_convert_class_init (GstAudioConvertClass *klass)
|
||||||
|
|
||||||
parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
|
parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
|
||||||
|
|
||||||
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_AGGRESSIVE,
|
|
||||||
g_param_spec_boolean("aggressive","aggressive mode","if true, tries any possible format before giving up",
|
|
||||||
FALSE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
|
||||||
|
|
||||||
gobject_class->set_property = gst_audio_convert_set_property;
|
gobject_class->set_property = gst_audio_convert_set_property;
|
||||||
gobject_class->get_property = gst_audio_convert_get_property;
|
gobject_class->get_property = gst_audio_convert_get_property;
|
||||||
|
|
||||||
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_AGGRESSIVE,
|
||||||
|
g_param_spec_boolean("aggressive", "aggressive mode",
|
||||||
|
"if true, tries any possible format before giving up",
|
||||||
|
FALSE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
||||||
|
|
||||||
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_MIN_RATE,
|
||||||
|
g_param_spec_uint("min-rate", "minimum rate allowed",
|
||||||
|
"defines the lower bound for the audio rate",
|
||||||
|
0, G_MAXUINT, 8000, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
||||||
|
|
||||||
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_MAX_RATE,
|
||||||
|
g_param_spec_uint("max-rate", "maximum rate allowed",
|
||||||
|
"defines the upper bound for the audio rate",
|
||||||
|
0, G_MAXUINT, 192000, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
||||||
|
|
||||||
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_RATE_STEPS,
|
||||||
|
g_param_spec_uint("rate-steps", "rate search steps",
|
||||||
|
"the number of steps used for searching between min and max rates",
|
||||||
|
0, G_MAXUINT, 32, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
||||||
|
|
||||||
gstelement_class->change_state = gst_audio_convert_change_state;
|
gstelement_class->change_state = gst_audio_convert_change_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_audio_convert_init (GstAudioConvert *this)
|
gst_audio_convert_init (GstAudioConvert *this)
|
||||||
{
|
{
|
||||||
|
@ -225,6 +244,7 @@ gst_audio_convert_init (GstAudioConvert *this)
|
||||||
audio_convert_sink_template_factory), "sink");
|
audio_convert_sink_template_factory), "sink");
|
||||||
gst_pad_set_link_function (this->sink, gst_audio_convert_link);
|
gst_pad_set_link_function (this->sink, gst_audio_convert_link);
|
||||||
gst_element_add_pad (GST_ELEMENT(this), this->sink);
|
gst_element_add_pad (GST_ELEMENT(this), this->sink);
|
||||||
|
|
||||||
/* srcpad */
|
/* srcpad */
|
||||||
this->src = gst_pad_new_from_template (GST_PAD_TEMPLATE_GET (
|
this->src = gst_pad_new_from_template (GST_PAD_TEMPLATE_GET (
|
||||||
audio_convert_src_template_factory), "src");
|
audio_convert_src_template_factory), "src");
|
||||||
|
@ -232,9 +252,10 @@ gst_audio_convert_init (GstAudioConvert *this)
|
||||||
gst_element_add_pad (GST_ELEMENT(this), this->src);
|
gst_element_add_pad (GST_ELEMENT(this), this->src);
|
||||||
|
|
||||||
gst_pad_set_chain_function(this->sink, gst_audio_convert_chain);
|
gst_pad_set_chain_function(this->sink, gst_audio_convert_chain);
|
||||||
gst_pad_set_chain_function(this->sink, gst_audio_convert_chain);
|
|
||||||
/* clear important variables */
|
/* clear important variables */
|
||||||
this->caps_set[0] = this->caps_set[1] = FALSE;
|
this->caps_set[0] = this->caps_set[1] = FALSE;
|
||||||
|
this->convert_internal = NULL;
|
||||||
}
|
}
|
||||||
static void
|
static void
|
||||||
gst_audio_convert_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
gst_audio_convert_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
||||||
|
@ -249,6 +270,15 @@ gst_audio_convert_set_property (GObject *object, guint prop_id, const GValue *va
|
||||||
case ARG_AGGRESSIVE:
|
case ARG_AGGRESSIVE:
|
||||||
audio_convert->aggressive = g_value_get_boolean (value);
|
audio_convert->aggressive = g_value_get_boolean (value);
|
||||||
break;
|
break;
|
||||||
|
case ARG_MIN_RATE:
|
||||||
|
audio_convert->min_rate = g_value_get_uint (value);
|
||||||
|
break;
|
||||||
|
case ARG_MAX_RATE:
|
||||||
|
audio_convert->max_rate = g_value_get_uint (value);
|
||||||
|
break;
|
||||||
|
case ARG_RATE_STEPS:
|
||||||
|
audio_convert->rate_steps = g_value_get_uint (value);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
|
@ -268,6 +298,15 @@ gst_audio_convert_get_property (GObject *object, guint prop_id, GValue *value, G
|
||||||
case ARG_AGGRESSIVE:
|
case ARG_AGGRESSIVE:
|
||||||
g_value_set_boolean (value, audio_convert->aggressive);
|
g_value_set_boolean (value, audio_convert->aggressive);
|
||||||
break;
|
break;
|
||||||
|
case ARG_MIN_RATE:
|
||||||
|
g_value_set_uint (value, audio_convert->min_rate);
|
||||||
|
break;
|
||||||
|
case ARG_MAX_RATE:
|
||||||
|
g_value_set_uint (value, audio_convert->max_rate);
|
||||||
|
break;
|
||||||
|
case ARG_RATE_STEPS:
|
||||||
|
g_value_set_uint (value, audio_convert->rate_steps);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
|
@ -295,12 +334,15 @@ gst_audio_convert_chain (GstPad *pad, GstBuffer *buf)
|
||||||
|
|
||||||
if (!this->caps_set[1]) {
|
if (!this->caps_set[1]) {
|
||||||
if (!gst_audio_convert_set_caps (this->src)) {
|
if (!gst_audio_convert_set_caps (this->src)) {
|
||||||
gst_element_error (GST_ELEMENT (this), "AudioConvert: could not set caps on pad %s",
|
gst_element_error (GST_ELEMENT (this),
|
||||||
|
"AudioConvert: could not set caps on pad %s",
|
||||||
GST_PAD_NAME(this->src));
|
GST_PAD_NAME(this->src));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_assert(this->caps_set[0] && this->caps_set[1]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Theory of operation:
|
* Theory of operation:
|
||||||
* - convert the format (endianness, signedness, width, depth) to
|
* - convert the format (endianness, signedness, width, depth) to
|
||||||
|
@ -317,6 +359,7 @@ gst_audio_convert_chain (GstPad *pad, GstBuffer *buf)
|
||||||
|
|
||||||
gst_pad_push (this->src, buf);
|
gst_pad_push (this->src, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstPadLinkReturn
|
static GstPadLinkReturn
|
||||||
gst_audio_convert_link (GstPad *pad, GstCaps *caps)
|
gst_audio_convert_link (GstPad *pad, GstCaps *caps)
|
||||||
{
|
{
|
||||||
|
@ -330,25 +373,19 @@ gst_audio_convert_link (GstPad *pad, GstCaps *caps)
|
||||||
this = GST_AUDIO_CONVERT(GST_OBJECT_PARENT (pad));
|
this = GST_AUDIO_CONVERT(GST_OBJECT_PARENT (pad));
|
||||||
|
|
||||||
/* could we do better? */
|
/* could we do better? */
|
||||||
if (!GST_CAPS_IS_FIXED (caps))
|
if (!GST_CAPS_IS_FIXED (caps)) return GST_PAD_LINK_DELAYED;
|
||||||
return GST_PAD_LINK_DELAYED;
|
|
||||||
|
|
||||||
if (pad == this->sink) {
|
nr = (pad == this->sink) ? 0 : (pad == this->src) ? 1 : -1;
|
||||||
nr = 0;
|
g_assert (nr > -1);
|
||||||
} else if (pad == this->src) {
|
|
||||||
nr = 1;
|
|
||||||
} else {
|
|
||||||
g_assert_not_reached ();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!gst_caps_get (caps, "rate", &rate,
|
if (! gst_caps_get (caps,
|
||||||
"channels", &channels,
|
"channels", &channels,
|
||||||
"signed", &sign,
|
"signed", &sign,
|
||||||
"depth", &depth,
|
"depth", &depth,
|
||||||
"width", &width,
|
"width", &width,
|
||||||
NULL
|
"rate", &rate, NULL))
|
||||||
))
|
|
||||||
return GST_PAD_LINK_DELAYED;
|
return GST_PAD_LINK_DELAYED;
|
||||||
|
|
||||||
if (!gst_caps_get_int (caps, "endianness", &endianness)) {
|
if (!gst_caps_get_int (caps, "endianness", &endianness)) {
|
||||||
if (width == 1) {
|
if (width == 1) {
|
||||||
endianness = G_BYTE_ORDER;
|
endianness = G_BYTE_ORDER;
|
||||||
|
@ -356,11 +393,11 @@ gst_audio_convert_link (GstPad *pad, GstCaps *caps)
|
||||||
return GST_PAD_LINK_DELAYED;
|
return GST_PAD_LINK_DELAYED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* we cannot yet convert this, so check */
|
/* we can't convert rate changes yet */
|
||||||
if (this->caps_set[1 - nr]) {
|
if ((this->caps_set[1 - nr]) &&
|
||||||
if (rate != this->rate[1 - nr])
|
(rate != this->rate[1 - nr]))
|
||||||
return GST_PAD_LINK_REFUSED;
|
return GST_PAD_LINK_REFUSED;
|
||||||
}
|
|
||||||
this->caps_set[nr] = TRUE;
|
this->caps_set[nr] = TRUE;
|
||||||
this->rate[nr] = rate;
|
this->rate[nr] = rate;
|
||||||
this->channels[nr] = channels;
|
this->channels[nr] = channels;
|
||||||
|
@ -371,6 +408,7 @@ gst_audio_convert_link (GstPad *pad, GstCaps *caps)
|
||||||
|
|
||||||
return GST_PAD_LINK_OK;
|
return GST_PAD_LINK_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstElementStateReturn
|
static GstElementStateReturn
|
||||||
gst_audio_convert_change_state (GstElement *element)
|
gst_audio_convert_change_state (GstElement *element)
|
||||||
{
|
{
|
||||||
|
@ -379,6 +417,7 @@ gst_audio_convert_change_state (GstElement *element)
|
||||||
switch (GST_STATE_TRANSITION (element)) {
|
switch (GST_STATE_TRANSITION (element)) {
|
||||||
case GST_STATE_PAUSED_TO_READY:
|
case GST_STATE_PAUSED_TO_READY:
|
||||||
this->caps_set[0] = this->caps_set[1] = FALSE;
|
this->caps_set[0] = this->caps_set[1] = FALSE;
|
||||||
|
this->convert_internal = NULL;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -430,15 +469,14 @@ gst_audio_convert_set_caps (GstPad *pad)
|
||||||
gboolean sign;
|
gboolean sign;
|
||||||
|
|
||||||
this = GST_AUDIO_CONVERT (GST_PAD_PARENT (pad));
|
this = GST_AUDIO_CONVERT (GST_PAD_PARENT (pad));
|
||||||
nr = this->src == pad ? 1 : this->sink == pad ? 0 : -1;
|
nr = (this->src == pad) ? 1 : (this->sink == pad) ? 0 : -1;
|
||||||
g_assert (nr > -1);
|
g_assert (nr > -1);
|
||||||
|
|
||||||
/* try 1:1 first */
|
/* try 1:1 first */
|
||||||
caps = make_caps (this->endian[1 - nr], this->sign[1 - nr], this->depth[1 - nr],
|
caps = make_caps (this->endian[1 - nr], this->sign[1 - nr], this->depth[1 - nr],
|
||||||
this->width[1 - nr], this->rate[1 - nr], this->channels[1 - nr]);
|
this->width[1 - nr], this->rate[1 - nr], this->channels[1 - nr]);
|
||||||
ret = gst_pad_try_set_caps (pad, caps);
|
ret = gst_pad_try_set_caps (pad, caps);
|
||||||
if (ret == GST_PAD_LINK_DONE || ret == GST_PAD_LINK_OK)
|
if (ret == GST_PAD_LINK_DONE || ret == GST_PAD_LINK_OK) goto success;
|
||||||
goto success;
|
|
||||||
|
|
||||||
/* now do some iterating, this is gonna be fun */
|
/* now do some iterating, this is gonna be fun */
|
||||||
/* stereo is most important */
|
/* stereo is most important */
|
||||||
|
@ -448,8 +486,7 @@ gst_audio_convert_set_caps (GstPad *pad)
|
||||||
/* endianness comes second */
|
/* endianness comes second */
|
||||||
endianness = 0;
|
endianness = 0;
|
||||||
do {
|
do {
|
||||||
if (endianness == G_BIG_ENDIAN)
|
if (endianness == G_BIG_ENDIAN) break;
|
||||||
break;
|
|
||||||
endianness = endianness == 0 ? G_LITTLE_ENDIAN : G_BIG_ENDIAN;
|
endianness = endianness == 0 ? G_LITTLE_ENDIAN : G_BIG_ENDIAN;
|
||||||
|
|
||||||
/* signedness */
|
/* signedness */
|
||||||
|
@ -457,41 +494,32 @@ gst_audio_convert_set_caps (GstPad *pad)
|
||||||
do {
|
do {
|
||||||
sign = !sign;
|
sign = !sign;
|
||||||
|
|
||||||
/* depth */
|
/* width */
|
||||||
for (width = 4; width >= 1; width--) {
|
for (width = 4; width >= 1; width--) {
|
||||||
|
|
||||||
/* width */
|
/* depth */
|
||||||
for (depth = width * 8; depth >= 1; depth -= this->aggressive ? 1 : 8) {
|
for (depth = width * 8; depth >= 1; depth -= this->aggressive ? 1 : 8) {
|
||||||
|
|
||||||
/* rate - not supported yet*/
|
/* rate - not supported yet*/
|
||||||
|
|
||||||
caps = make_caps (endianness, sign, depth,
|
caps = make_caps (endianness, sign, depth, width, this->rate[1 - nr], channels);
|
||||||
width, this->rate[1 - nr], channels);
|
|
||||||
ret = gst_pad_try_set_caps (pad, caps);
|
ret = gst_pad_try_set_caps (pad, caps);
|
||||||
if (ret == GST_PAD_LINK_DONE || ret == GST_PAD_LINK_OK) {
|
if (ret == GST_PAD_LINK_DONE || ret == GST_PAD_LINK_OK)
|
||||||
goto success;
|
goto success;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} while (sign != TRUE);
|
} while (sign != TRUE);
|
||||||
|
|
||||||
} while TRUE;
|
} while TRUE;
|
||||||
|
|
||||||
channels--;
|
channels--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
goto fail;
|
|
||||||
fail:
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
success:
|
success:
|
||||||
g_assert (gst_audio_convert_link (pad, caps) == GST_PAD_LINK_OK);
|
g_assert (gst_audio_convert_link (pad, caps) == GST_PAD_LINK_OK);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return a writable buffer of size which ideally is the same as before
|
/* return a writable buffer of size which ideally is the same as before
|
||||||
- You must unref the new buffer
|
- You must unref the new buffer
|
||||||
- The size of the old buffer is undefined after this operation */
|
- The size of the old buffer is undefined after this operation */
|
||||||
|
@ -513,8 +541,10 @@ gst_audio_convert_get_buffer (GstBuffer *buf, guint size)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline guint8 GUINT8_IDENTITY (guint8 x) { return x; }
|
static inline guint8 GUINT8_IDENTITY (guint8 x) { return x; }
|
||||||
static inline guint8 GINT8_IDENTITY (gint8 x) { return x; }
|
static inline guint8 GINT8_IDENTITY (gint8 x) { return x; }
|
||||||
|
|
||||||
#define CONVERT_TO(to, from, type, sign, endianness, LE_FUNC, BE_FUNC) G_STMT_START{\
|
#define CONVERT_TO(to, from, type, sign, endianness, LE_FUNC, BE_FUNC) G_STMT_START{\
|
||||||
type value; \
|
type value; \
|
||||||
memcpy (&value, from, sizeof (type)); \
|
memcpy (&value, from, sizeof (type)); \
|
||||||
|
@ -526,6 +556,7 @@ static inline guint8 GINT8_IDENTITY (gint8 x) { return x; }
|
||||||
to = (gint64) value - (1 << (sizeof (type) * 8 - 1)); \
|
to = (gint64) value - (1 << (sizeof (type) * 8 - 1)); \
|
||||||
} \
|
} \
|
||||||
}G_STMT_END;
|
}G_STMT_END;
|
||||||
|
|
||||||
static GstBuffer*
|
static GstBuffer*
|
||||||
gst_audio_convert_buffer_to_default_format (GstAudioConvert *this, GstBuffer *buf)
|
gst_audio_convert_buffer_to_default_format (GstAudioConvert *this, GstBuffer *buf)
|
||||||
{
|
{
|
||||||
|
@ -561,38 +592,6 @@ gst_audio_convert_buffer_to_default_format (GstAudioConvert *this, GstBuffer *bu
|
||||||
CONVERT_TO (cur, src, guint16, this->sign[0], this->endian[0], GUINT16_FROM_LE, GUINT16_FROM_BE);
|
CONVERT_TO (cur, src, guint16, this->sign[0], this->endian[0], GUINT16_FROM_LE, GUINT16_FROM_BE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 3:
|
|
||||||
if (this->sign[0]) {
|
|
||||||
gint32 value;
|
|
||||||
if (this->endian[0] == G_BIG_ENDIAN) {
|
|
||||||
gpointer p = &value;
|
|
||||||
p++;
|
|
||||||
memcpy (p, src, 3);
|
|
||||||
value = GINT32_FROM_BE (value);
|
|
||||||
} else if (this->endian[0] == G_LITTLE_ENDIAN) {
|
|
||||||
memcpy (&value, src, 3);
|
|
||||||
value = GINT32_FROM_LE (value);
|
|
||||||
} else {
|
|
||||||
g_assert_not_reached();
|
|
||||||
}
|
|
||||||
cur = value;
|
|
||||||
} else {
|
|
||||||
guint32 value;
|
|
||||||
if (this->endian[0] == G_BIG_ENDIAN) {
|
|
||||||
gpointer p = &value;
|
|
||||||
p++;
|
|
||||||
memcpy (p, src, 3);
|
|
||||||
value = GUINT32_FROM_BE (value);
|
|
||||||
} else if (this->endian[0] == G_LITTLE_ENDIAN) {
|
|
||||||
memcpy (&value, src, 3);
|
|
||||||
value = GUINT32_FROM_LE (value);
|
|
||||||
} else {
|
|
||||||
g_assert_not_reached();
|
|
||||||
}
|
|
||||||
cur = (gint64) value - (1 << 23);
|
|
||||||
}
|
|
||||||
src -= 3;
|
|
||||||
break;
|
|
||||||
case 4:
|
case 4:
|
||||||
if (this->sign[0]) {
|
if (this->sign[0]) {
|
||||||
CONVERT_TO (cur, src, gint32, this->sign[0], this->endian[0], GINT32_FROM_LE, GINT32_FROM_BE);
|
CONVERT_TO (cur, src, gint32, this->sign[0], this->endian[0], GINT32_FROM_LE, GINT32_FROM_BE);
|
||||||
|
@ -612,6 +611,7 @@ gst_audio_convert_buffer_to_default_format (GstAudioConvert *this, GstBuffer *bu
|
||||||
gst_buffer_unref (buf);
|
gst_buffer_unref (buf);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define POPULATE(format, be_func, le_func) G_STMT_START{ \
|
#define POPULATE(format, be_func, le_func) G_STMT_START{ \
|
||||||
format val; \
|
format val; \
|
||||||
format* p = (format *) dest; \
|
format* p = (format *) dest; \
|
||||||
|
@ -631,6 +631,7 @@ gst_audio_convert_buffer_to_default_format (GstAudioConvert *this, GstBuffer *bu
|
||||||
p ++; \
|
p ++; \
|
||||||
dest = (guint8 *) p; \
|
dest = (guint8 *) p; \
|
||||||
}G_STMT_END
|
}G_STMT_END
|
||||||
|
|
||||||
static GstBuffer *
|
static GstBuffer *
|
||||||
gst_audio_convert_buffer_from_default_format (GstAudioConvert *this, GstBuffer *buf)
|
gst_audio_convert_buffer_from_default_format (GstAudioConvert *this, GstBuffer *buf)
|
||||||
{
|
{
|
||||||
|
@ -668,45 +669,6 @@ gst_audio_convert_buffer_from_default_format (GstAudioConvert *this, GstBuffer *
|
||||||
POPULATE (guint16, GUINT16_TO_BE, GUINT16_TO_LE);
|
POPULATE (guint16, GUINT16_TO_BE, GUINT16_TO_LE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 3:
|
|
||||||
if (this->sign[1]) {
|
|
||||||
gpointer p;
|
|
||||||
gint32 val = (gint32) int_value;
|
|
||||||
switch (this->endian[1]) {
|
|
||||||
case G_LITTLE_ENDIAN:
|
|
||||||
val = GINT32_TO_LE (val);
|
|
||||||
break;
|
|
||||||
case G_BIG_ENDIAN:
|
|
||||||
val = GINT32_TO_BE (val);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
g_assert_not_reached ();
|
|
||||||
};
|
|
||||||
p = &val;
|
|
||||||
if (this->endian[1] == G_BIG_ENDIAN)
|
|
||||||
p++;
|
|
||||||
memcpy (dest, p, 3);
|
|
||||||
dest += 3;
|
|
||||||
} else {
|
|
||||||
gpointer p;
|
|
||||||
guint32 val = (guint32) int_value;
|
|
||||||
switch (this->endian[1]) {
|
|
||||||
case G_LITTLE_ENDIAN:
|
|
||||||
val = GUINT32_TO_LE (val);
|
|
||||||
break;
|
|
||||||
case G_BIG_ENDIAN:
|
|
||||||
val = GUINT32_TO_BE (val);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
g_assert_not_reached ();
|
|
||||||
};
|
|
||||||
p = &val;
|
|
||||||
if (this->endian[1] == G_BIG_ENDIAN)
|
|
||||||
p++;
|
|
||||||
memcpy (dest, p, 3);
|
|
||||||
dest += 3;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 4:
|
case 4:
|
||||||
if (this->sign[1]) {
|
if (this->sign[1]) {
|
||||||
POPULATE (gint32, GINT32_TO_BE, GINT32_TO_LE);
|
POPULATE (gint32, GINT32_TO_BE, GINT32_TO_LE);
|
||||||
|
@ -722,6 +684,7 @@ gst_audio_convert_buffer_from_default_format (GstAudioConvert *this, GstBuffer *
|
||||||
gst_buffer_unref(buf);
|
gst_buffer_unref(buf);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstBuffer *
|
static GstBuffer *
|
||||||
gst_audio_convert_channels (GstAudioConvert *this, GstBuffer *buf)
|
gst_audio_convert_channels (GstAudioConvert *this, GstBuffer *buf)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue