mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
gst/audioresample/gstaudioresample.c: Add support for other formats audioresample can handle such as 32 bits in and f...
Original commit message from CVS: * gst/audioresample/gstaudioresample.c: (gst_audioresample_init), (resample_set_state_from_caps): Add support for other formats audioresample can handle such as 32 bits in and float and 64 bits float. Fixes #301759
This commit is contained in:
parent
2d4c661169
commit
c19601eab9
1 changed files with 77 additions and 19 deletions
|
@ -83,16 +83,26 @@ GST_STATIC_CAPS ( \
|
||||||
"endianness = (int) BYTE_ORDER, " \
|
"endianness = (int) BYTE_ORDER, " \
|
||||||
"width = (int) 16, " \
|
"width = (int) 16, " \
|
||||||
"depth = (int) 16, " \
|
"depth = (int) 16, " \
|
||||||
"signed = (boolean) true " \
|
"signed = (boolean) true;" \
|
||||||
|
"audio/x-raw-int, " \
|
||||||
|
"rate = (int) [ 1, MAX ], " \
|
||||||
|
"channels = (int) [ 1, MAX ], " \
|
||||||
|
"endianness = (int) BYTE_ORDER, " \
|
||||||
|
"width = (int) 32, " \
|
||||||
|
"depth = (int) 32, " \
|
||||||
|
"signed = (boolean) true;" \
|
||||||
|
"audio/x-raw-float, " \
|
||||||
|
"rate = (int) [ 1, MAX ], " \
|
||||||
|
"channels = (int) [ 1, MAX ], " \
|
||||||
|
"endianness = (int) BYTE_ORDER, " \
|
||||||
|
"width = (int) 32; " \
|
||||||
|
"audio/x-raw-float, " \
|
||||||
|
"rate = (int) [ 1, MAX ], " \
|
||||||
|
"channels = (int) [ 1, MAX ], " \
|
||||||
|
"endianness = (int) BYTE_ORDER, " \
|
||||||
|
"width = (int) 64" \
|
||||||
)
|
)
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* disabled because it segfaults */
|
|
||||||
"audio/x-raw-float, "
|
|
||||||
"rate = (int) [ 1, MAX ], "
|
|
||||||
"channels = (int) [ 1, MAX ], "
|
|
||||||
"endianness = (int) BYTE_ORDER, " "width = (int) 32"
|
|
||||||
#endif
|
|
||||||
static GstStaticPadTemplate gst_audioresample_sink_template =
|
static GstStaticPadTemplate gst_audioresample_sink_template =
|
||||||
GST_STATIC_PAD_TEMPLATE ("sink",
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
||||||
GST_PAD_SINK, GST_PAD_ALWAYS, SUPPORTED_CAPS);
|
GST_PAD_SINK, GST_PAD_ALWAYS, SUPPORTED_CAPS);
|
||||||
|
@ -197,7 +207,6 @@ gst_audioresample_init (GstAudioresample * audioresample,
|
||||||
audioresample->next_ts = -1;
|
audioresample->next_ts = -1;
|
||||||
|
|
||||||
resample_set_filter_length (r, DEFAULT_FILTERLEN);
|
resample_set_filter_length (r, DEFAULT_FILTERLEN);
|
||||||
resample_set_format (r, RESAMPLE_FORMAT_S16);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -259,28 +268,49 @@ resample_set_state_from_caps (ResampleState * state, GstCaps * incaps,
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
gint myinrate, myoutrate;
|
gint myinrate, myoutrate;
|
||||||
int mychannels;
|
int mychannels;
|
||||||
|
gint width, depth;
|
||||||
|
ResampleFormat format;
|
||||||
|
|
||||||
GST_DEBUG ("incaps %" GST_PTR_FORMAT ", outcaps %"
|
GST_DEBUG ("incaps %" GST_PTR_FORMAT ", outcaps %"
|
||||||
GST_PTR_FORMAT, incaps, outcaps);
|
GST_PTR_FORMAT, incaps, outcaps);
|
||||||
|
|
||||||
structure = gst_caps_get_structure (incaps, 0);
|
structure = gst_caps_get_structure (incaps, 0);
|
||||||
|
|
||||||
/* FIXME: once it does float, set the correct format */
|
/* get width */
|
||||||
#if 0
|
ret = gst_structure_get_int (structure, "width", &width);
|
||||||
if (g_str_equal (gst_structure_get_name (structure), "audio/x-raw-float")) {
|
if (!ret)
|
||||||
r->format = GST_RESAMPLE_FLOAT;
|
goto no_width;
|
||||||
} else {
|
|
||||||
r->format = GST_RESAMPLE_S16;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
/* figure out the format */
|
||||||
|
if (g_str_equal (gst_structure_get_name (structure), "audio/x-raw-float")) {
|
||||||
|
if (width == 32)
|
||||||
|
format = RESAMPLE_FORMAT_F32;
|
||||||
|
else if (width == 64)
|
||||||
|
format = RESAMPLE_FORMAT_F64;
|
||||||
|
else
|
||||||
|
goto wrong_depth;
|
||||||
|
} else {
|
||||||
|
/* for int, depth and width must be the same */
|
||||||
|
ret = gst_structure_get_int (structure, "depth", &depth);
|
||||||
|
if (!ret || width != depth)
|
||||||
|
goto not_equal;
|
||||||
|
|
||||||
|
if (width == 16)
|
||||||
|
format = RESAMPLE_FORMAT_S16;
|
||||||
|
else if (width == 32)
|
||||||
|
format = RESAMPLE_FORMAT_S32;
|
||||||
|
else
|
||||||
|
goto wrong_depth;
|
||||||
|
}
|
||||||
ret = gst_structure_get_int (structure, "rate", &myinrate);
|
ret = gst_structure_get_int (structure, "rate", &myinrate);
|
||||||
ret &= gst_structure_get_int (structure, "channels", &mychannels);
|
ret &= gst_structure_get_int (structure, "channels", &mychannels);
|
||||||
g_return_val_if_fail (ret, FALSE);
|
if (!ret)
|
||||||
|
goto no_in_rate_channels;
|
||||||
|
|
||||||
structure = gst_caps_get_structure (outcaps, 0);
|
structure = gst_caps_get_structure (outcaps, 0);
|
||||||
ret = gst_structure_get_int (structure, "rate", &myoutrate);
|
ret = gst_structure_get_int (structure, "rate", &myoutrate);
|
||||||
g_return_val_if_fail (ret, FALSE);
|
if (!ret)
|
||||||
|
goto no_out_rate;
|
||||||
|
|
||||||
if (channels)
|
if (channels)
|
||||||
*channels = mychannels;
|
*channels = mychannels;
|
||||||
|
@ -289,11 +319,39 @@ resample_set_state_from_caps (ResampleState * state, GstCaps * incaps,
|
||||||
if (outrate)
|
if (outrate)
|
||||||
*outrate = myoutrate;
|
*outrate = myoutrate;
|
||||||
|
|
||||||
|
resample_set_format (state, format);
|
||||||
resample_set_n_channels (state, mychannels);
|
resample_set_n_channels (state, mychannels);
|
||||||
resample_set_input_rate (state, myinrate);
|
resample_set_input_rate (state, myinrate);
|
||||||
resample_set_output_rate (state, myoutrate);
|
resample_set_output_rate (state, myoutrate);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
/* ERRORS */
|
||||||
|
no_width:
|
||||||
|
{
|
||||||
|
GST_DEBUG ("failed to get width from caps");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
not_equal:
|
||||||
|
{
|
||||||
|
GST_DEBUG ("width %d and depth %d must be the same", width, depth);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
wrong_depth:
|
||||||
|
{
|
||||||
|
GST_DEBUG ("unknown depth %d found", depth);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
no_in_rate_channels:
|
||||||
|
{
|
||||||
|
GST_DEBUG ("could not get input rate and channels");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
no_out_rate:
|
||||||
|
{
|
||||||
|
GST_DEBUG ("could not get output rate");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
|
Loading…
Reference in a new issue