mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 16:50:47 +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 \
|
||||
decklink fbdev linsys shm vcd \
|
||||
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 \
|
||||
wildmidi xvid apple_media lv2 teletextdec opus dvb"
|
||||
AC_SUBST(GST_PLUGINS_NONPORTED)
|
||||
|
|
|
@ -67,20 +67,22 @@ static GstStaticPadTemplate gsmdec_src_template =
|
|||
GST_STATIC_PAD_TEMPLATE ("src",
|
||||
GST_PAD_SRC,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS ("audio/x-raw-int, "
|
||||
"endianness = (int) BYTE_ORDER, "
|
||||
"signed = (boolean) true, "
|
||||
"width = (int) 16, "
|
||||
"depth = (int) 16, " "rate = (int) [1, MAX], " "channels = (int) 1")
|
||||
GST_STATIC_CAPS ("audio/x-raw, "
|
||||
"format = (string) " GST_AUDIO_NE (S16) ", "
|
||||
"layout = (string) interleaved, "
|
||||
"rate = (int) [1, MAX], channels = (int) 1")
|
||||
);
|
||||
|
||||
GST_BOILERPLATE (GstGSMDec, gst_gsmdec, GstAudioDecoder,
|
||||
GST_TYPE_AUDIO_DECODER);
|
||||
G_DEFINE_TYPE (GstGSMDec, gst_gsmdec, GST_TYPE_AUDIO_DECODER);
|
||||
|
||||
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_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",
|
||||
"Codec/Decoder/Audio",
|
||||
"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->stop = GST_DEBUG_FUNCPTR (gst_gsmdec_stop);
|
||||
|
@ -108,7 +102,7 @@ gst_gsmdec_class_init (GstGSMDecClass * klass)
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
/* Setting up src caps based on the input sample rate. */
|
||||
srccaps = gst_caps_new_simple ("audio/x-raw-int",
|
||||
"endianness", G_TYPE_INT, G_BYTE_ORDER,
|
||||
"signed", G_TYPE_BOOLEAN, TRUE,
|
||||
"width", G_TYPE_INT, 16,
|
||||
"depth", G_TYPE_INT, 16,
|
||||
srccaps = gst_caps_new_simple ("audio/x-raw",
|
||||
"format", G_TYPE_STRING, GST_AUDIO_NE (S16),
|
||||
"layout", G_TYPE_STRING, "interleaved",
|
||||
"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);
|
||||
|
||||
return ret;
|
||||
|
@ -208,7 +200,7 @@ gst_gsmdec_parse (GstAudioDecoder * dec, GstAdapter * adapter,
|
|||
}
|
||||
|
||||
if (size < gsmdec->needed)
|
||||
return GST_FLOW_UNEXPECTED;
|
||||
return GST_FLOW_EOS;
|
||||
|
||||
*offset = 0;
|
||||
*length = gsmdec->needed;
|
||||
|
@ -223,6 +215,7 @@ gst_gsmdec_handle_frame (GstAudioDecoder * dec, GstBuffer * buffer)
|
|||
gsm_byte *data;
|
||||
GstFlowReturn ret = GST_FLOW_OK;
|
||||
GstBuffer *outbuf;
|
||||
GstMapInfo map, omap;
|
||||
|
||||
/* no fancy draining */
|
||||
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));
|
||||
|
||||
/* now encode frame into the output buffer */
|
||||
data = (gsm_byte *) GST_BUFFER_DATA (buffer);
|
||||
if (gsm_decode (gsmdec->state, data,
|
||||
(gsm_signal *) GST_BUFFER_DATA (outbuf)) < 0) {
|
||||
gst_buffer_map (buffer, &map, GST_MAP_READ);
|
||||
gst_buffer_map (outbuf, &omap, GST_MAP_WRITE);
|
||||
data = (gsm_byte *) map.data;
|
||||
if (gsm_decode (gsmdec->state, data, (gsm_signal *) omap.data) < 0) {
|
||||
/* invalid frame */
|
||||
GST_AUDIO_DECODER_ERROR (gsmdec, 1, STREAM, DECODE, (NULL),
|
||||
("tried to decode an invalid frame"), ret);
|
||||
if (ret != GST_FLOW_OK)
|
||||
goto exit;
|
||||
gst_buffer_unmap (outbuf, &omap);
|
||||
gst_buffer_unref (outbuf);
|
||||
outbuf = NULL;
|
||||
} else {
|
||||
gst_buffer_unmap (outbuf, &omap);
|
||||
}
|
||||
|
||||
gst_buffer_unmap (buffer, &map);
|
||||
|
||||
gst_audio_decoder_finish_frame (dec, outbuf, 1);
|
||||
|
||||
exit:
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -61,20 +61,22 @@ static GstStaticPadTemplate gsmenc_sink_template =
|
|||
GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
GST_PAD_SINK,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS ("audio/x-raw-int, "
|
||||
"endianness = (int) BYTE_ORDER, "
|
||||
"signed = (boolean) true, "
|
||||
"width = (int) 16, "
|
||||
"depth = (int) 16, " "rate = (int) 8000, " "channels = (int) 1")
|
||||
GST_STATIC_CAPS ("audio/x-raw, "
|
||||
"format = (string) " GST_AUDIO_NE (S16) ", "
|
||||
"layout = (string) interleaved, "
|
||||
"rate = (int) 8000, channels = (int) 1")
|
||||
);
|
||||
|
||||
GST_BOILERPLATE (GstGSMEnc, gst_gsmenc, GstAudioEncoder,
|
||||
GST_TYPE_AUDIO_ENCODER);
|
||||
G_DEFINE_TYPE (GstGSMEnc, gst_gsmenc, GST_TYPE_AUDIO_ENCODER);
|
||||
|
||||
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_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",
|
||||
"Codec/Encoder/Audio",
|
||||
"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->stop = GST_DEBUG_FUNCPTR (gst_gsmenc_stop);
|
||||
|
@ -101,7 +95,7 @@ gst_gsmenc_class_init (GstGSMEncClass * klass)
|
|||
}
|
||||
|
||||
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;
|
||||
GstFlowReturn ret = GST_FLOW_OK;
|
||||
GstBuffer *outbuf;
|
||||
GstMapInfo map, omap;
|
||||
|
||||
gsmenc = GST_GSMENC (benc);
|
||||
|
||||
|
@ -165,20 +160,24 @@ gst_gsmenc_handle_frame (GstAudioEncoder * benc, GstBuffer * buffer)
|
|||
goto done;
|
||||
}
|
||||
|
||||
if (G_UNLIKELY (GST_BUFFER_SIZE (buffer) < 320)) {
|
||||
GST_DEBUG_OBJECT (gsmenc, "discarding trailing data %d",
|
||||
GST_BUFFER_SIZE (buffer));
|
||||
gst_buffer_map (buffer, &map, GST_MAP_READ);
|
||||
if (G_UNLIKELY (map.size < 320)) {
|
||||
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);
|
||||
goto done;
|
||||
}
|
||||
|
||||
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 */
|
||||
data = (gsm_signal *) GST_BUFFER_DATA (buffer);
|
||||
gsm_encode (gsmenc->state, data, (gsm_byte *) GST_BUFFER_DATA (outbuf));
|
||||
data = (gsm_signal *) map.data;
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue