mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-09-08 21:28:45 +00:00
ext/speex/gstspeexdec.c: Some small cleanups, use _scale.
Original commit message from CVS: * ext/speex/gstspeexdec.c: (speex_dec_convert), (speex_dec_sink_event), (speex_dec_chain_parse_header): Some small cleanups, use _scale.
This commit is contained in:
parent
92172d85bb
commit
1e68f40b74
2 changed files with 56 additions and 30 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2006-10-31 Wim Taymans <wim@fluendo.com>
|
||||||
|
|
||||||
|
* ext/speex/gstspeexdec.c: (speex_dec_convert),
|
||||||
|
(speex_dec_sink_event), (speex_dec_chain_parse_header):
|
||||||
|
Some small cleanups, use _scale.
|
||||||
|
|
||||||
2006-10-31 Wim Taymans <wim@fluendo.com>
|
2006-10-31 Wim Taymans <wim@fluendo.com>
|
||||||
|
|
||||||
* gst/avi/gstavidemux.c: (gst_avi_demux_handle_src_query):
|
* gst/avi/gstavidemux.c: (gst_avi_demux_handle_src_query):
|
||||||
|
|
|
@ -221,7 +221,9 @@ speex_dec_convert (GstPad * pad,
|
||||||
case GST_FORMAT_BYTES:
|
case GST_FORMAT_BYTES:
|
||||||
scale = sizeof (float) * dec->header->nb_channels;
|
scale = sizeof (float) * dec->header->nb_channels;
|
||||||
case GST_FORMAT_DEFAULT:
|
case GST_FORMAT_DEFAULT:
|
||||||
*dest_value = scale * (src_value * dec->header->rate / GST_SECOND);
|
*dest_value =
|
||||||
|
gst_util_uint64_scale_int (scale * src_value, dec->header->rate,
|
||||||
|
GST_SECOND);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
res = FALSE;
|
res = FALSE;
|
||||||
|
@ -234,7 +236,9 @@ speex_dec_convert (GstPad * pad,
|
||||||
*dest_value = src_value * sizeof (float) * dec->header->nb_channels;
|
*dest_value = src_value * sizeof (float) * dec->header->nb_channels;
|
||||||
break;
|
break;
|
||||||
case GST_FORMAT_TIME:
|
case GST_FORMAT_TIME:
|
||||||
*dest_value = src_value * GST_SECOND / dec->header->rate;
|
*dest_value =
|
||||||
|
gst_util_uint64_scale_int (src_value, GST_SECOND,
|
||||||
|
dec->header->rate);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
res = FALSE;
|
res = FALSE;
|
||||||
|
@ -247,8 +251,8 @@ speex_dec_convert (GstPad * pad,
|
||||||
*dest_value = src_value / (sizeof (float) * dec->header->nb_channels);
|
*dest_value = src_value / (sizeof (float) * dec->header->nb_channels);
|
||||||
break;
|
break;
|
||||||
case GST_FORMAT_TIME:
|
case GST_FORMAT_TIME:
|
||||||
*dest_value = src_value * GST_SECOND /
|
*dest_value = gst_util_uint64_scale_int (src_value, GST_SECOND,
|
||||||
(dec->header->rate * sizeof (float) * dec->header->nb_channels);
|
dec->header->rate * sizeof (float) * dec->header->nb_channels);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
res = FALSE;
|
res = FALSE;
|
||||||
|
@ -440,12 +444,12 @@ speex_dec_sink_event (GstPad * pad, GstEvent * event)
|
||||||
switch (GST_EVENT_TYPE (event)) {
|
switch (GST_EVENT_TYPE (event)) {
|
||||||
case GST_EVENT_NEWSEGMENT:{
|
case GST_EVENT_NEWSEGMENT:{
|
||||||
GstFormat format;
|
GstFormat format;
|
||||||
gdouble rate;
|
gdouble rate, arate;
|
||||||
gint64 start, stop, time;
|
gint64 start, stop, time;
|
||||||
gboolean update;
|
gboolean update;
|
||||||
|
|
||||||
gst_event_parse_new_segment (event, &update, &rate, &format, &start,
|
gst_event_parse_new_segment_full (event, &update, &rate, &arate, &format,
|
||||||
&stop, &time);
|
&start, &stop, &time);
|
||||||
|
|
||||||
if (format != GST_FORMAT_TIME)
|
if (format != GST_FORMAT_TIME)
|
||||||
goto newseg_wrong_format;
|
goto newseg_wrong_format;
|
||||||
|
@ -454,8 +458,8 @@ speex_dec_sink_event (GstPad * pad, GstEvent * event)
|
||||||
goto newseg_wrong_rate;
|
goto newseg_wrong_rate;
|
||||||
|
|
||||||
/* now configure the values */
|
/* now configure the values */
|
||||||
gst_segment_set_newsegment (&dec->segment, update,
|
gst_segment_set_newsegment_full (&dec->segment, update,
|
||||||
rate, GST_FORMAT_TIME, start, stop, time);
|
rate, arate, GST_FORMAT_TIME, start, stop, time);
|
||||||
|
|
||||||
dec->granulepos = -1;
|
dec->granulepos = -1;
|
||||||
|
|
||||||
|
@ -500,29 +504,18 @@ speex_dec_chain_parse_header (GstSpeexDec * dec, GstBuffer * buf)
|
||||||
dec->header = speex_packet_to_header ((char *) GST_BUFFER_DATA (buf),
|
dec->header = speex_packet_to_header ((char *) GST_BUFFER_DATA (buf),
|
||||||
GST_BUFFER_SIZE (buf));
|
GST_BUFFER_SIZE (buf));
|
||||||
|
|
||||||
if (!dec->header) {
|
if (!dec->header)
|
||||||
GST_ELEMENT_ERROR (GST_ELEMENT (dec), STREAM, DECODE,
|
goto no_header;
|
||||||
(NULL), ("couldn't read header"));
|
|
||||||
return GST_FLOW_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dec->header->mode >= SPEEX_NB_MODES) {
|
if (dec->header->mode >= SPEEX_NB_MODES)
|
||||||
GST_ELEMENT_ERROR (GST_ELEMENT (dec), STREAM, DECODE,
|
goto mode_too_old;
|
||||||
(NULL),
|
|
||||||
("Mode number %d does not (yet/any longer) exist in this version",
|
|
||||||
dec->header->mode));
|
|
||||||
return GST_FLOW_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
dec->mode = (SpeexMode *) speex_mode_list[dec->header->mode];
|
dec->mode = (SpeexMode *) speex_mode_list[dec->header->mode];
|
||||||
|
|
||||||
/* initialize the decoder */
|
/* initialize the decoder */
|
||||||
dec->state = speex_decoder_init (dec->mode);
|
dec->state = speex_decoder_init (dec->mode);
|
||||||
if (!dec->state) {
|
if (!dec->state)
|
||||||
GST_ELEMENT_ERROR (GST_ELEMENT (dec), STREAM, DECODE,
|
goto init_failed;
|
||||||
(NULL), ("couldn't initialize decoder"));
|
|
||||||
return GST_FLOW_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
speex_decoder_ctl (dec->state, SPEEX_SET_ENH, &dec->enh);
|
speex_decoder_ctl (dec->state, SPEEX_SET_ENH, &dec->enh);
|
||||||
speex_decoder_ctl (dec->state, SPEEX_GET_FRAME_SIZE, &dec->frame_size);
|
speex_decoder_ctl (dec->state, SPEEX_GET_FRAME_SIZE, &dec->frame_size);
|
||||||
|
@ -549,13 +542,40 @@ speex_dec_chain_parse_header (GstSpeexDec * dec, GstBuffer * buf)
|
||||||
"endianness", G_TYPE_INT, G_BYTE_ORDER,
|
"endianness", G_TYPE_INT, G_BYTE_ORDER,
|
||||||
"width", G_TYPE_INT, 16, "depth", G_TYPE_INT, 16, NULL);
|
"width", G_TYPE_INT, 16, "depth", G_TYPE_INT, 16, NULL);
|
||||||
|
|
||||||
if (!gst_pad_set_caps (dec->srcpad, caps)) {
|
if (!gst_pad_set_caps (dec->srcpad, caps))
|
||||||
gst_caps_unref (caps);
|
goto nego_failed;
|
||||||
return GST_FLOW_NOT_NEGOTIATED;
|
|
||||||
}
|
|
||||||
|
|
||||||
gst_caps_unref (caps);
|
gst_caps_unref (caps);
|
||||||
return GST_FLOW_OK;
|
return GST_FLOW_OK;
|
||||||
|
|
||||||
|
/* ERRORS */
|
||||||
|
no_header:
|
||||||
|
{
|
||||||
|
GST_ELEMENT_ERROR (GST_ELEMENT (dec), STREAM, DECODE,
|
||||||
|
(NULL), ("couldn't read header"));
|
||||||
|
return GST_FLOW_ERROR;
|
||||||
|
}
|
||||||
|
mode_too_old:
|
||||||
|
{
|
||||||
|
GST_ELEMENT_ERROR (GST_ELEMENT (dec), STREAM, DECODE,
|
||||||
|
(NULL),
|
||||||
|
("Mode number %d does not (yet/any longer) exist in this version",
|
||||||
|
dec->header->mode));
|
||||||
|
return GST_FLOW_ERROR;
|
||||||
|
}
|
||||||
|
init_failed:
|
||||||
|
{
|
||||||
|
GST_ELEMENT_ERROR (GST_ELEMENT (dec), STREAM, DECODE,
|
||||||
|
(NULL), ("couldn't initialize decoder"));
|
||||||
|
return GST_FLOW_ERROR;
|
||||||
|
}
|
||||||
|
nego_failed:
|
||||||
|
{
|
||||||
|
GST_ELEMENT_ERROR (GST_ELEMENT (dec), STREAM, DECODE,
|
||||||
|
(NULL), ("couldn't negotiate format"));
|
||||||
|
gst_caps_unref (caps);
|
||||||
|
return GST_FLOW_NOT_NEGOTIATED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
|
|
Loading…
Reference in a new issue