return DB_TO_LINEAR (gst_opus_dec_get_r128_gain (r128_gain));
}
+static GstCaps *
+gst_opus_dec_negotiate (GstOpusDec * dec)
+{
+ GstCaps *caps = gst_pad_get_allowed_caps (GST_AUDIO_DECODER_SRC_PAD (dec));
+ GstStructure *s = gst_caps_get_structure (caps, 0);
+ gst_structure_fixate_field_nearest_int (s, "rate", 48000);
+ 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_INFO_OBJECT (dec, "Negotiated %d channels, %d Hz", dec->n_channels,
+ dec->sample_rate);
+
+ return caps;
+}
+
static GstFlowReturn
gst_opus_dec_parse_header (GstOpusDec * dec, GstBuffer * buf)
{
const guint8 *data = GST_BUFFER_DATA (buf);
GstCaps *caps;
- GstStructure *s;
const GstAudioChannelPosition *pos = NULL;
g_return_val_if_fail (gst_opus_header_is_id_header (buf), GST_FLOW_ERROR);
}
}
- /* negotiate width with downstream */
- caps = gst_pad_get_allowed_caps (GST_AUDIO_DECODER_SRC_PAD (dec));
- s = gst_caps_get_structure (caps, 0);
- gst_structure_fixate_field_nearest_int (s, "rate", 48000);
- 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_INFO_OBJECT (dec, "Negotiated %d channels, %d Hz", dec->n_channels,
- dec->sample_rate);
+ caps = gst_opus_dec_negotiate (dec);
if (pos) {
GST_DEBUG_OBJECT (dec, "Setting channel positions on caps");
return GST_FLOW_OK;
}
-
static GstFlowReturn
gst_opus_dec_parse_comments (GstOpusDec * dec, GstBuffer * buf)
{
GstBuffer *buf;
if (dec->state == NULL) {
+ /* If we did not get any headers, default to 2 channels */
+ if (dec->n_channels == 0) {
+ GstCaps *caps;
+ GST_INFO_OBJECT (dec, "No header, assuming single stream");
+ dec->n_channels = 2;
+ dec->sample_rate = 48000;
+ caps = gst_opus_dec_negotiate (dec);
+ GST_INFO_OBJECT (dec, "Setting src caps to %" GST_PTR_FORMAT, caps);
+ gst_pad_set_caps (GST_AUDIO_DECODER_SRC_PAD (dec), caps);
+ gst_caps_unref (caps);
+ /* default stereo mapping */
+ dec->channel_mapping_family = 0;
+ dec->channel_mapping[0] = 0;
+ dec->channel_mapping[1] = 1;
+ dec->n_streams = 1;
+ dec->n_stereo_streams = 1;
+ }
+
GST_DEBUG_OBJECT (dec, "Creating decoder with %d channels, %d Hz",
dec->n_channels, dec->sample_rate);
dec->state = opus_multistream_decoder_create (dec->sample_rate,