static gboolean gst_wavpack_enc_sink_set_caps (GstPad * pad, GstCaps * caps) { GstWavpackEnc *enc = GST_WAVPACK_ENC (gst_pad_get_parent (pad)); GstStructure *structure = gst_caps_get_structure (caps, 0); GstAudioChannelPosition *pos; if (!gst_structure_get_int (structure, "channels", &enc->channels) || !gst_structure_get_int (structure, "rate", &enc->samplerate) || !gst_structure_get_int (structure, "depth", &enc->depth)) { GST_ELEMENT_ERROR (enc, LIBRARY, INIT, (NULL), ("got invalid caps: %" GST_PTR_FORMAT, caps)); gst_object_unref (enc); return FALSE; } pos = gst_audio_get_channel_positions (structure); /* If one channel is NONE they'll be all undefined */ if (pos != NULL && pos[0] == GST_AUDIO_CHANNEL_POSITION_NONE) { g_free (pos); pos = NULL; } if (pos == NULL) { GST_ELEMENT_ERROR (enc, STREAM, FORMAT, (NULL), ("input has no valid channel layout")); gst_object_unref (enc); return FALSE; } enc->channel_mask = gst_wavpack_get_channel_mask_from_positions (pos, enc->channels); enc->need_channel_remap = gst_wavpack_set_channel_mapping (pos, enc->channels, enc->channel_mapping); g_free (pos); /* set fixed src pad caps now that we know what we will get */ caps = gst_caps_new_simple ("audio/x-wavpack", "channels", G_TYPE_INT, enc->channels, "rate", G_TYPE_INT, enc->samplerate, "width", G_TYPE_INT, enc->depth, "framed", G_TYPE_BOOLEAN, TRUE, NULL); if (!gst_wavpack_set_channel_layout (caps, enc->channel_mask)) GST_WARNING_OBJECT (enc, "setting channel layout failed"); if (!gst_pad_set_caps (enc->srcpad, caps)) { GST_ELEMENT_ERROR (enc, LIBRARY, INIT, (NULL), ("setting caps failed: %" GST_PTR_FORMAT, caps)); gst_caps_unref (caps); gst_object_unref (enc); return FALSE; } gst_pad_use_fixed_caps (enc->srcpad); gst_caps_unref (caps); gst_object_unref (enc); return TRUE; }
static gboolean gst_wavpack_dec_sink_set_caps (GstPad * pad, GstCaps * caps) { GstWavpackDec *dec = GST_WAVPACK_DEC (gst_pad_get_parent (pad)); GstStructure *structure = gst_caps_get_structure (caps, 0); /* Check if we can set the caps here already */ if (gst_structure_get_int (structure, "channels", &dec->channels) && gst_structure_get_int (structure, "rate", &dec->sample_rate) && gst_structure_get_int (structure, "width", &dec->depth)) { GstCaps *caps; GstAudioChannelPosition *pos; caps = gst_caps_new_simple ("audio/x-raw-int", "rate", G_TYPE_INT, dec->sample_rate, "channels", G_TYPE_INT, dec->channels, "depth", G_TYPE_INT, dec->depth, "width", G_TYPE_INT, 32, "endianness", G_TYPE_INT, G_BYTE_ORDER, "signed", G_TYPE_BOOLEAN, TRUE, NULL); /* If we already have the channel layout set from upstream * take this */ if (gst_structure_has_field (structure, "channel-positions")) { pos = gst_audio_get_channel_positions (structure); if (pos != NULL && dec->channels > 2) { GstStructure *new_str = gst_caps_get_structure (caps, 0); gst_audio_set_channel_positions (new_str, pos); dec->channel_mask = gst_wavpack_get_channel_mask_from_positions (pos, dec->channels); } if (pos != NULL) g_free (pos); } GST_DEBUG_OBJECT (dec, "setting caps %" GST_PTR_FORMAT, caps); /* should always succeed */ gst_pad_set_caps (dec->srcpad, caps); gst_caps_unref (caps); /* send GST_TAG_AUDIO_CODEC and GST_TAG_BITRATE tags before something * is decoded or after the format has changed */ gst_wavpack_dec_post_tags (dec); } gst_object_unref (dec); return TRUE; }