From bb5b0f2d127b14f8d80c6df041ea37e6fd1f0475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 23 Mar 2015 11:57:09 +0100 Subject: [PATCH] opusdec: Take output sample rate from the stream headers too This way we let opusdec do the resampling if needed and don't carry around buffers with a too high sample rate if not required. While Opus always uses 48kHz internally, this information from the header specifies which frequencies are safe to drop. --- ext/opus/gstopusdec.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/opus/gstopusdec.c b/ext/opus/gstopusdec.c index cfa711a18c..2b7bcb2834 100644 --- a/ext/opus/gstopusdec.c +++ b/ext/opus/gstopusdec.c @@ -224,13 +224,11 @@ gst_opus_dec_negotiate (GstOpusDec * dec, const GstAudioChannelPosition * pos) caps = gst_caps_truncate (caps); caps = gst_caps_make_writable (caps); s = gst_caps_get_structure (caps, 0); - gst_structure_fixate_field_nearest_int (s, "rate", 48000); + gst_structure_fixate_field_nearest_int (s, "rate", dec->sample_rate); gst_structure_get_int (s, "rate", &dec->sample_rate); gst_structure_fixate_field_nearest_int (s, "channels", dec->n_channels); gst_structure_get_int (s, "channels", &dec->n_channels); gst_caps_unref (caps); - } else { - dec->sample_rate = 48000; } GST_INFO_OBJECT (dec, "Negotiated %d channels, %d Hz", dec->n_channels, @@ -282,6 +280,7 @@ gst_opus_dec_parse_header (GstOpusDec * dec, GstBuffer * buf) } dec->n_channels = data[9]; + dec->sample_rate = GST_READ_UINT32_LE (data + 12); dec->pre_skip = GST_READ_UINT16_LE (data + 10); dec->r128_gain = GST_READ_UINT16_LE (data + 16); dec->r128_gain_volume = gst_opus_dec_get_r128_volume (dec->r128_gain);