mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-11 18:05:37 +00:00
gsm: port to 0.11
This commit is contained in:
parent
2b5c6d67ee
commit
de606f64eb
3 changed files with 51 additions and 56 deletions
|
@ -325,7 +325,7 @@ GST_PLUGINS_NONPORTED=" adpcmdec adpcmenc aiff asfmux \
|
||||||
videomeasure videosignal vmnc \
|
videomeasure videosignal vmnc \
|
||||||
decklink fbdev linsys shm vcd \
|
decklink fbdev linsys shm vcd \
|
||||||
apexsink bz2 cdaudio celt cog curl dc1394 dirac directfb resindvd \
|
apexsink bz2 cdaudio celt cog curl dc1394 dirac directfb resindvd \
|
||||||
gsettings gsm jp2k ladspa modplug mimic \
|
gsettings jp2k ladspa modplug mimic \
|
||||||
musepack musicbrainz nas neon ofa openal opencv rsvg schro sdl smooth sndfile soundtouch spandsp timidity \
|
musepack musicbrainz nas neon ofa openal opencv rsvg schro sdl smooth sndfile soundtouch spandsp timidity \
|
||||||
wildmidi xvid apple_media lv2 teletextdec opus dvb"
|
wildmidi xvid apple_media lv2 teletextdec opus dvb"
|
||||||
AC_SUBST(GST_PLUGINS_NONPORTED)
|
AC_SUBST(GST_PLUGINS_NONPORTED)
|
||||||
|
|
|
@ -67,20 +67,22 @@ static GstStaticPadTemplate gsmdec_src_template =
|
||||||
GST_STATIC_PAD_TEMPLATE ("src",
|
GST_STATIC_PAD_TEMPLATE ("src",
|
||||||
GST_PAD_SRC,
|
GST_PAD_SRC,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
GST_STATIC_CAPS ("audio/x-raw-int, "
|
GST_STATIC_CAPS ("audio/x-raw, "
|
||||||
"endianness = (int) BYTE_ORDER, "
|
"format = (string) " GST_AUDIO_NE (S16) ", "
|
||||||
"signed = (boolean) true, "
|
"layout = (string) interleaved, "
|
||||||
"width = (int) 16, "
|
"rate = (int) [1, MAX], channels = (int) 1")
|
||||||
"depth = (int) 16, " "rate = (int) [1, MAX], " "channels = (int) 1")
|
|
||||||
);
|
);
|
||||||
|
|
||||||
GST_BOILERPLATE (GstGSMDec, gst_gsmdec, GstAudioDecoder,
|
G_DEFINE_TYPE (GstGSMDec, gst_gsmdec, GST_TYPE_AUDIO_DECODER);
|
||||||
GST_TYPE_AUDIO_DECODER);
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_gsmdec_base_init (gpointer g_class)
|
gst_gsmdec_class_init (GstGSMDecClass * klass)
|
||||||
{
|
{
|
||||||
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
GstElementClass *element_class;
|
||||||
|
GstAudioDecoderClass *base_class;
|
||||||
|
|
||||||
|
element_class = (GstElementClass *) klass;
|
||||||
|
base_class = (GstAudioDecoderClass *) klass;
|
||||||
|
|
||||||
gst_element_class_add_pad_template (element_class,
|
gst_element_class_add_pad_template (element_class,
|
||||||
gst_static_pad_template_get (&gsmdec_sink_template));
|
gst_static_pad_template_get (&gsmdec_sink_template));
|
||||||
|
@ -89,14 +91,6 @@ gst_gsmdec_base_init (gpointer g_class)
|
||||||
gst_element_class_set_details_simple (element_class, "GSM audio decoder",
|
gst_element_class_set_details_simple (element_class, "GSM audio decoder",
|
||||||
"Codec/Decoder/Audio",
|
"Codec/Decoder/Audio",
|
||||||
"Decodes GSM encoded audio", "Philippe Khalaf <burger@speedy.org>");
|
"Decodes GSM encoded audio", "Philippe Khalaf <burger@speedy.org>");
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_gsmdec_class_init (GstGSMDecClass * klass)
|
|
||||||
{
|
|
||||||
GstAudioDecoderClass *base_class;
|
|
||||||
|
|
||||||
base_class = (GstAudioDecoderClass *) klass;
|
|
||||||
|
|
||||||
base_class->start = GST_DEBUG_FUNCPTR (gst_gsmdec_start);
|
base_class->start = GST_DEBUG_FUNCPTR (gst_gsmdec_start);
|
||||||
base_class->stop = GST_DEBUG_FUNCPTR (gst_gsmdec_stop);
|
base_class->stop = GST_DEBUG_FUNCPTR (gst_gsmdec_stop);
|
||||||
|
@ -108,7 +102,7 @@ gst_gsmdec_class_init (GstGSMDecClass * klass)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_gsmdec_init (GstGSMDec * gsmdec, GstGSMDecClass * klass)
|
gst_gsmdec_init (GstGSMDec * gsmdec)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,14 +164,12 @@ gst_gsmdec_set_format (GstAudioDecoder * dec, GstCaps * caps)
|
||||||
gsm_option (gsmdec->state, GSM_OPT_WAV49, &gsmdec->use_wav49);
|
gsm_option (gsmdec->state, GSM_OPT_WAV49, &gsmdec->use_wav49);
|
||||||
|
|
||||||
/* Setting up src caps based on the input sample rate. */
|
/* Setting up src caps based on the input sample rate. */
|
||||||
srccaps = gst_caps_new_simple ("audio/x-raw-int",
|
srccaps = gst_caps_new_simple ("audio/x-raw",
|
||||||
"endianness", G_TYPE_INT, G_BYTE_ORDER,
|
"format", G_TYPE_STRING, GST_AUDIO_NE (S16),
|
||||||
"signed", G_TYPE_BOOLEAN, TRUE,
|
"layout", G_TYPE_STRING, "interleaved",
|
||||||
"width", G_TYPE_INT, 16,
|
|
||||||
"depth", G_TYPE_INT, 16,
|
|
||||||
"rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, 1, NULL);
|
"rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, 1, NULL);
|
||||||
|
|
||||||
ret = gst_pad_set_caps (GST_AUDIO_DECODER_SRC_PAD (dec), srccaps);
|
ret = gst_audio_decoder_set_outcaps (dec, srccaps);
|
||||||
gst_caps_unref (srccaps);
|
gst_caps_unref (srccaps);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -208,7 +200,7 @@ gst_gsmdec_parse (GstAudioDecoder * dec, GstAdapter * adapter,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size < gsmdec->needed)
|
if (size < gsmdec->needed)
|
||||||
return GST_FLOW_UNEXPECTED;
|
return GST_FLOW_EOS;
|
||||||
|
|
||||||
*offset = 0;
|
*offset = 0;
|
||||||
*length = gsmdec->needed;
|
*length = gsmdec->needed;
|
||||||
|
@ -223,6 +215,7 @@ gst_gsmdec_handle_frame (GstAudioDecoder * dec, GstBuffer * buffer)
|
||||||
gsm_byte *data;
|
gsm_byte *data;
|
||||||
GstFlowReturn ret = GST_FLOW_OK;
|
GstFlowReturn ret = GST_FLOW_OK;
|
||||||
GstBuffer *outbuf;
|
GstBuffer *outbuf;
|
||||||
|
GstMapInfo map, omap;
|
||||||
|
|
||||||
/* no fancy draining */
|
/* no fancy draining */
|
||||||
if (G_UNLIKELY (!buffer))
|
if (G_UNLIKELY (!buffer))
|
||||||
|
@ -234,20 +227,23 @@ gst_gsmdec_handle_frame (GstAudioDecoder * dec, GstBuffer * buffer)
|
||||||
outbuf = gst_buffer_new_and_alloc (ENCODED_SAMPLES * sizeof (gsm_signal));
|
outbuf = gst_buffer_new_and_alloc (ENCODED_SAMPLES * sizeof (gsm_signal));
|
||||||
|
|
||||||
/* now encode frame into the output buffer */
|
/* now encode frame into the output buffer */
|
||||||
data = (gsm_byte *) GST_BUFFER_DATA (buffer);
|
gst_buffer_map (buffer, &map, GST_MAP_READ);
|
||||||
if (gsm_decode (gsmdec->state, data,
|
gst_buffer_map (outbuf, &omap, GST_MAP_WRITE);
|
||||||
(gsm_signal *) GST_BUFFER_DATA (outbuf)) < 0) {
|
data = (gsm_byte *) map.data;
|
||||||
|
if (gsm_decode (gsmdec->state, data, (gsm_signal *) omap.data) < 0) {
|
||||||
/* invalid frame */
|
/* invalid frame */
|
||||||
GST_AUDIO_DECODER_ERROR (gsmdec, 1, STREAM, DECODE, (NULL),
|
GST_AUDIO_DECODER_ERROR (gsmdec, 1, STREAM, DECODE, (NULL),
|
||||||
("tried to decode an invalid frame"), ret);
|
("tried to decode an invalid frame"), ret);
|
||||||
if (ret != GST_FLOW_OK)
|
gst_buffer_unmap (outbuf, &omap);
|
||||||
goto exit;
|
|
||||||
gst_buffer_unref (outbuf);
|
gst_buffer_unref (outbuf);
|
||||||
outbuf = NULL;
|
outbuf = NULL;
|
||||||
|
} else {
|
||||||
|
gst_buffer_unmap (outbuf, &omap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gst_buffer_unmap (buffer, &map);
|
||||||
|
|
||||||
gst_audio_decoder_finish_frame (dec, outbuf, 1);
|
gst_audio_decoder_finish_frame (dec, outbuf, 1);
|
||||||
|
|
||||||
exit:
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,20 +61,22 @@ static GstStaticPadTemplate gsmenc_sink_template =
|
||||||
GST_STATIC_PAD_TEMPLATE ("sink",
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
||||||
GST_PAD_SINK,
|
GST_PAD_SINK,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
GST_STATIC_CAPS ("audio/x-raw-int, "
|
GST_STATIC_CAPS ("audio/x-raw, "
|
||||||
"endianness = (int) BYTE_ORDER, "
|
"format = (string) " GST_AUDIO_NE (S16) ", "
|
||||||
"signed = (boolean) true, "
|
"layout = (string) interleaved, "
|
||||||
"width = (int) 16, "
|
"rate = (int) 8000, channels = (int) 1")
|
||||||
"depth = (int) 16, " "rate = (int) 8000, " "channels = (int) 1")
|
|
||||||
);
|
);
|
||||||
|
|
||||||
GST_BOILERPLATE (GstGSMEnc, gst_gsmenc, GstAudioEncoder,
|
G_DEFINE_TYPE (GstGSMEnc, gst_gsmenc, GST_TYPE_AUDIO_ENCODER);
|
||||||
GST_TYPE_AUDIO_ENCODER);
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_gsmenc_base_init (gpointer g_class)
|
gst_gsmenc_class_init (GstGSMEncClass * klass)
|
||||||
{
|
{
|
||||||
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
GstElementClass *element_class;
|
||||||
|
GstAudioEncoderClass *base_class;
|
||||||
|
|
||||||
|
element_class = (GstElementClass *) klass;
|
||||||
|
base_class = (GstAudioEncoderClass *) klass;
|
||||||
|
|
||||||
gst_element_class_add_pad_template (element_class,
|
gst_element_class_add_pad_template (element_class,
|
||||||
gst_static_pad_template_get (&gsmenc_sink_template));
|
gst_static_pad_template_get (&gsmenc_sink_template));
|
||||||
|
@ -83,14 +85,6 @@ gst_gsmenc_base_init (gpointer g_class)
|
||||||
gst_element_class_set_details_simple (element_class, "GSM audio encoder",
|
gst_element_class_set_details_simple (element_class, "GSM audio encoder",
|
||||||
"Codec/Encoder/Audio",
|
"Codec/Encoder/Audio",
|
||||||
"Encodes GSM audio", "Philippe Khalaf <burger@speedy.org>");
|
"Encodes GSM audio", "Philippe Khalaf <burger@speedy.org>");
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_gsmenc_class_init (GstGSMEncClass * klass)
|
|
||||||
{
|
|
||||||
GstAudioEncoderClass *base_class;
|
|
||||||
|
|
||||||
base_class = (GstAudioEncoderClass *) klass;
|
|
||||||
|
|
||||||
base_class->start = GST_DEBUG_FUNCPTR (gst_gsmenc_start);
|
base_class->start = GST_DEBUG_FUNCPTR (gst_gsmenc_start);
|
||||||
base_class->stop = GST_DEBUG_FUNCPTR (gst_gsmenc_stop);
|
base_class->stop = GST_DEBUG_FUNCPTR (gst_gsmenc_stop);
|
||||||
|
@ -101,7 +95,7 @@ gst_gsmenc_class_init (GstGSMEncClass * klass)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_gsmenc_init (GstGSMEnc * gsmenc, GstGSMEncClass * klass)
|
gst_gsmenc_init (GstGSMEnc * gsmenc)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,6 +150,7 @@ gst_gsmenc_handle_frame (GstAudioEncoder * benc, GstBuffer * buffer)
|
||||||
gsm_signal *data;
|
gsm_signal *data;
|
||||||
GstFlowReturn ret = GST_FLOW_OK;
|
GstFlowReturn ret = GST_FLOW_OK;
|
||||||
GstBuffer *outbuf;
|
GstBuffer *outbuf;
|
||||||
|
GstMapInfo map, omap;
|
||||||
|
|
||||||
gsmenc = GST_GSMENC (benc);
|
gsmenc = GST_GSMENC (benc);
|
||||||
|
|
||||||
|
@ -165,20 +160,24 @@ gst_gsmenc_handle_frame (GstAudioEncoder * benc, GstBuffer * buffer)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (G_UNLIKELY (GST_BUFFER_SIZE (buffer) < 320)) {
|
gst_buffer_map (buffer, &map, GST_MAP_READ);
|
||||||
GST_DEBUG_OBJECT (gsmenc, "discarding trailing data %d",
|
if (G_UNLIKELY (map.size < 320)) {
|
||||||
GST_BUFFER_SIZE (buffer));
|
GST_DEBUG_OBJECT (gsmenc, "discarding trailing data %d", (gint) map.size);
|
||||||
|
gst_buffer_unmap (buffer, &map);
|
||||||
ret = gst_audio_encoder_finish_frame (benc, NULL, -1);
|
ret = gst_audio_encoder_finish_frame (benc, NULL, -1);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
outbuf = gst_buffer_new_and_alloc (33 * sizeof (gsm_byte));
|
outbuf = gst_buffer_new_and_alloc (33 * sizeof (gsm_byte));
|
||||||
|
gst_buffer_map (outbuf, &omap, GST_MAP_WRITE);
|
||||||
|
|
||||||
/* encode 160 16-bit samples into 33 bytes */
|
/* encode 160 16-bit samples into 33 bytes */
|
||||||
data = (gsm_signal *) GST_BUFFER_DATA (buffer);
|
data = (gsm_signal *) map.data;
|
||||||
gsm_encode (gsmenc->state, data, (gsm_byte *) GST_BUFFER_DATA (outbuf));
|
gsm_encode (gsmenc->state, data, (gsm_byte *) omap.data);
|
||||||
|
|
||||||
GST_LOG_OBJECT (gsmenc, "encoded to %d bytes", GST_BUFFER_SIZE (outbuf));
|
GST_LOG_OBJECT (gsmenc, "encoded to %d bytes", (gint) omap.size);
|
||||||
|
gst_buffer_unmap (buffer, &map);
|
||||||
|
gst_buffer_unmap (buffer, &omap);
|
||||||
|
|
||||||
ret = gst_audio_encoder_finish_frame (benc, outbuf, 160);
|
ret = gst_audio_encoder_finish_frame (benc, outbuf, 160);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue