static GstCaps * gst_video_test_src_src_fixate (GstBaseSrc * bsrc, GstCaps * caps) { GstStructure *structure; caps = gst_caps_make_writable (caps); structure = gst_caps_get_structure (caps, 0); gst_structure_fixate_field_nearest_int (structure, "width", 320); gst_structure_fixate_field_nearest_int (structure, "height", 240); gst_structure_fixate_field_nearest_fraction (structure, "framerate", 30, 1); if (gst_structure_has_field (structure, "pixel-aspect-ratio")) gst_structure_fixate_field_nearest_fraction (structure, "pixel-aspect-ratio", 1, 1); if (gst_structure_has_field (structure, "colorimetry")) gst_structure_fixate_field_string (structure, "colorimetry", "bt601"); if (gst_structure_has_field (structure, "chroma-site")) gst_structure_fixate_field_string (structure, "chroma-site", "mpeg2"); if (gst_structure_has_field (structure, "interlace-mode")) gst_structure_fixate_field_string (structure, "interlace-mode", "progressive"); caps = GST_BASE_SRC_CLASS (parent_class)->fixate (bsrc, caps); return caps; }
static GstCaps * gst_inter_video_src_fixate (GstBaseSrc * src, GstCaps * caps) { GstInterVideoSrc *intervideosrc = GST_INTER_VIDEO_SRC (src); GstStructure *structure; GST_DEBUG_OBJECT (intervideosrc, "fixate"); caps = gst_caps_make_writable (caps); structure = gst_caps_get_structure (caps, 0); gst_structure_fixate_field_nearest_int (structure, "width", 320); gst_structure_fixate_field_nearest_int (structure, "height", 240); gst_structure_fixate_field_nearest_fraction (structure, "framerate", 30, 1); if (gst_structure_has_field (structure, "pixel-aspect-ratio")) gst_structure_fixate_field_nearest_fraction (structure, "pixel-aspect-ratio", 1, 1); if (gst_structure_has_field (structure, "color-matrix")) gst_structure_fixate_field_string (structure, "color-matrix", "sdtv"); if (gst_structure_has_field (structure, "chroma-site")) gst_structure_fixate_field_string (structure, "chroma-site", "mpeg2"); if (gst_structure_has_field (structure, "interlaced")) gst_structure_fixate_field_boolean (structure, "interlaced", FALSE); return caps; }
static GstCaps * gst_ladspa_source_type_fixate (GstBaseSrc * base, GstCaps * caps) { GstLADSPASource *ladspa = GST_LADSPA_SOURCE (base); GstStructure *structure; caps = gst_caps_make_writable (caps); structure = gst_caps_get_structure (caps, 0); GST_DEBUG_OBJECT (ladspa, "fixating samplerate to %d", GST_AUDIO_DEF_RATE); gst_structure_fixate_field_nearest_int (structure, "rate", GST_AUDIO_DEF_RATE); gst_structure_fixate_field_string (structure, "format", GST_AUDIO_NE (F32)); gst_structure_fixate_field_nearest_int (structure, "channels", ladspa->ladspa.klass->count.audio.out); caps = GST_BASE_SRC_CLASS (gst_ladspa_source_type_parent_class)->fixate (base, caps); return caps; }
static GstCaps * gst_inter_audio_src_fixate (GstBaseSrc * src, GstCaps * caps) { GstStructure *structure; GST_DEBUG_OBJECT (src, "fixate"); caps = gst_caps_make_writable (caps); caps = gst_caps_truncate (caps); structure = gst_caps_get_structure (caps, 0); gst_structure_fixate_field_string (structure, "format", GST_AUDIO_NE (S16)); gst_structure_fixate_field_nearest_int (structure, "channels", 2); gst_structure_fixate_field_nearest_int (structure, "rate", 48000); gst_structure_fixate_field_string (structure, "layout", "interleaved"); return caps; }
static GstCaps * gst_lv2_source_fixate (GstBaseSrc * base, GstCaps * caps) { GstLV2Source *lv2 = (GstLV2Source *) base; GstStructure *structure; caps = gst_caps_make_writable (caps); structure = gst_caps_get_structure (caps, 0); GST_DEBUG_OBJECT (lv2, "fixating samplerate to %d", GST_AUDIO_DEF_RATE); gst_structure_fixate_field_nearest_int (structure, "rate", GST_AUDIO_DEF_RATE); gst_structure_fixate_field_string (structure, "format", GST_AUDIO_NE (F32)); gst_structure_fixate_field_nearest_int (structure, "channels", lv2->lv2.klass->out_group.ports->len); caps = GST_BASE_SRC_CLASS (parent_class)->fixate (base, caps); return caps; }
static GstCaps * gst_audio_test_src_fixate (GstBaseSrc * bsrc, GstCaps * caps) { GstAudioTestSrc *src = GST_AUDIO_TEST_SRC (bsrc); GstStructure *structure; caps = gst_caps_make_writable (caps); structure = gst_caps_get_structure (caps, 0); GST_DEBUG_OBJECT (src, "fixating samplerate to %d", GST_AUDIO_DEF_RATE); gst_structure_fixate_field_nearest_int (structure, "rate", GST_AUDIO_DEF_RATE); gst_structure_fixate_field_string (structure, "format", DEFAULT_FORMAT_STR); /* fixate to mono unless downstream requires stereo, for backwards compat */ gst_structure_fixate_field_nearest_int (structure, "channels", 1); caps = GST_BASE_SRC_CLASS (parent_class)->fixate (bsrc, caps); return caps; }
static gboolean gst_rtp_opus_pay_setcaps (GstRTPBasePayload * payload, GstCaps * caps) { gboolean res; GstCaps *src_caps; GstStructure *s; char *encoding_name; gint channels, rate; const char *sprop_stereo = NULL; char *sprop_maxcapturerate = NULL; src_caps = gst_pad_get_allowed_caps (GST_RTP_BASE_PAYLOAD_SRCPAD (payload)); if (src_caps) { src_caps = gst_caps_make_writable (src_caps); src_caps = gst_caps_truncate (src_caps); s = gst_caps_get_structure (src_caps, 0); gst_structure_fixate_field_string (s, "encoding-name", "OPUS"); encoding_name = g_strdup (gst_structure_get_string (s, "encoding-name")); gst_caps_unref (src_caps); } else { encoding_name = g_strdup ("X-GST-OPUS-DRAFT-SPITTKA-00"); } s = gst_caps_get_structure (caps, 0); if (gst_structure_get_int (s, "channels", &channels)) { if (channels > 2) { GST_ERROR_OBJECT (payload, "More than 2 channels with channel-mapping-family=0 is invalid"); return FALSE; } else if (channels == 2) { sprop_stereo = "1"; } else { sprop_stereo = "0"; } } if (gst_structure_get_int (s, "rate", &rate)) { sprop_maxcapturerate = g_strdup_printf ("%d", rate); } gst_rtp_base_payload_set_options (payload, "audio", FALSE, encoding_name, 48000); g_free (encoding_name); if (sprop_maxcapturerate && sprop_stereo) { res = gst_rtp_base_payload_set_outcaps (payload, "sprop-maxcapturerate", G_TYPE_STRING, sprop_maxcapturerate, "sprop-stereo", G_TYPE_STRING, sprop_stereo, NULL); } else if (sprop_maxcapturerate) { res = gst_rtp_base_payload_set_outcaps (payload, "sprop-maxcapturerate", G_TYPE_STRING, sprop_maxcapturerate, NULL); } else if (sprop_stereo) { res = gst_rtp_base_payload_set_outcaps (payload, "sprop-stereo", G_TYPE_STRING, sprop_stereo, NULL); } else { res = gst_rtp_base_payload_set_outcaps (payload, NULL); } g_free (sprop_maxcapturerate); return res; }
static gboolean gst_sbc_enc_set_format (GstAudioEncoder * audio_enc, GstAudioInfo * info) { const gchar *allocation_method, *channel_mode; GstSbcEnc *enc = GST_SBC_ENC (audio_enc); GstStructure *s; GstCaps *caps, *filter_caps; GstCaps *output_caps = NULL; guint sampleframes_per_frame; enc->rate = GST_AUDIO_INFO_RATE (info); enc->channels = GST_AUDIO_INFO_CHANNELS (info); /* negotiate output format based on downstream caps restrictions */ caps = gst_pad_get_allowed_caps (GST_AUDIO_ENCODER_SRC_PAD (enc)); if (caps == GST_CAPS_NONE || gst_caps_is_empty (caps)) goto failure; if (caps == NULL) caps = gst_static_pad_template_get_caps (&sbc_enc_src_factory); /* fixate output caps */ filter_caps = gst_caps_new_simple ("audio/x-sbc", "rate", G_TYPE_INT, enc->rate, "channels", G_TYPE_INT, enc->channels, NULL); output_caps = gst_caps_intersect (caps, filter_caps); gst_caps_unref (filter_caps); if (output_caps == NULL || gst_caps_is_empty (output_caps)) { GST_WARNING_OBJECT (enc, "Couldn't negotiate output caps with input rate " "%d and input channels %d and allowed output caps %" GST_PTR_FORMAT, enc->rate, enc->channels, caps); goto failure; } gst_caps_unref (caps); caps = NULL; GST_DEBUG_OBJECT (enc, "fixating caps %" GST_PTR_FORMAT, output_caps); output_caps = gst_caps_truncate (output_caps); s = gst_caps_get_structure (output_caps, 0); if (enc->channels == 1) gst_structure_fixate_field_string (s, "channel-mode", "mono"); else gst_structure_fixate_field_string (s, "channel-mode", "joint"); gst_structure_fixate_field_nearest_int (s, "bitpool", 64); gst_structure_fixate_field_nearest_int (s, "blocks", 16); gst_structure_fixate_field_nearest_int (s, "subbands", 8); gst_structure_fixate_field_string (s, "allocation-method", "loudness"); s = NULL; /* in case there's anything else left to fixate */ output_caps = gst_caps_fixate (output_caps); gst_caps_set_simple (output_caps, "parsed", G_TYPE_BOOLEAN, TRUE, NULL); GST_INFO_OBJECT (enc, "output caps %" GST_PTR_FORMAT, output_caps); /* let's see what we fixated to */ s = gst_caps_get_structure (output_caps, 0); gst_structure_get_int (s, "blocks", &enc->blocks); gst_structure_get_int (s, "subbands", &enc->subbands); gst_structure_get_int (s, "bitpool", &enc->bitpool); allocation_method = gst_structure_get_string (s, "allocation-method"); channel_mode = gst_structure_get_string (s, "channel-mode"); /* We want channel-mode and channels coherent */ if (enc->channels == 1) { if (g_strcmp0 (channel_mode, "mono") != 0) { GST_ERROR_OBJECT (enc, "Can't have channel-mode '%s' for 1 channel", channel_mode); goto failure; } } else { if (g_strcmp0 (channel_mode, "joint") != 0 && g_strcmp0 (channel_mode, "stereo") != 0 && g_strcmp0 (channel_mode, "dual") != 0) { GST_ERROR_OBJECT (enc, "Can't have channel-mode '%s' for 2 channels", channel_mode); goto failure; } } /* we want to be handed all available samples in handle_frame, but always * enough to encode a frame */ sampleframes_per_frame = enc->blocks * enc->subbands; gst_audio_encoder_set_frame_samples_min (audio_enc, sampleframes_per_frame); gst_audio_encoder_set_frame_samples_max (audio_enc, sampleframes_per_frame); gst_audio_encoder_set_frame_max (audio_enc, 0); /* FIXME: what to do with left-over samples at the end? can we encode them? */ gst_audio_encoder_set_hard_min (audio_enc, TRUE); /* and configure encoder based on the output caps we negotiated */ if (enc->rate == 16000) enc->sbc.frequency = SBC_FREQ_16000; else if (enc->rate == 32000) enc->sbc.frequency = SBC_FREQ_32000; else if (enc->rate == 44100) enc->sbc.frequency = SBC_FREQ_44100; else if (enc->rate == 48000) enc->sbc.frequency = SBC_FREQ_48000; else goto failure; if (enc->blocks == 4) enc->sbc.blocks = SBC_BLK_4; else if (enc->blocks == 8) enc->sbc.blocks = SBC_BLK_8; else if (enc->blocks == 12) enc->sbc.blocks = SBC_BLK_12; else if (enc->blocks == 16) enc->sbc.blocks = SBC_BLK_16; else goto failure; enc->sbc.subbands = (enc->subbands == 4) ? SBC_SB_4 : SBC_SB_8; enc->sbc.bitpool = enc->bitpool; if (channel_mode == NULL || allocation_method == NULL) goto failure; if (strcmp (channel_mode, "joint") == 0) enc->sbc.mode = SBC_MODE_JOINT_STEREO; else if (strcmp (channel_mode, "stereo") == 0) enc->sbc.mode = SBC_MODE_STEREO; else if (strcmp (channel_mode, "dual") == 0) enc->sbc.mode = SBC_MODE_DUAL_CHANNEL; else if (strcmp (channel_mode, "mono") == 0) enc->sbc.mode = SBC_MODE_MONO; else if (strcmp (channel_mode, "auto") == 0) enc->sbc.mode = SBC_MODE_JOINT_STEREO; else goto failure; if (strcmp (allocation_method, "loudness") == 0) enc->sbc.allocation = SBC_AM_LOUDNESS; else if (strcmp (allocation_method, "snr") == 0) enc->sbc.allocation = SBC_AM_SNR; else goto failure; if (!gst_audio_encoder_set_output_format (audio_enc, output_caps)) goto failure; return gst_audio_encoder_negotiate (audio_enc); failure: if (output_caps) gst_caps_unref (output_caps); if (caps) gst_caps_unref (caps); return FALSE; }
static gboolean gst_video_rate_setcaps (GstPad * pad, GstCaps * caps) { GstVideoRate *videorate; GstStructure *structure; gboolean ret = TRUE; GstPad *otherpad, *opeer; gint rate_numerator, rate_denominator; videorate = GST_VIDEO_RATE (gst_pad_get_parent (pad)); GST_DEBUG_OBJECT (pad, "setcaps called %" GST_PTR_FORMAT, caps); structure = gst_caps_get_structure (caps, 0); if (!gst_structure_get_fraction (structure, "framerate", &rate_numerator, &rate_denominator)) goto no_framerate; if (pad == videorate->srcpad) { /* out_frame_count is scaled by the frame rate caps when calculating next_ts. * when the frame rate caps change, we must update base_ts and reset * out_frame_count */ if (videorate->to_rate_numerator) { videorate->base_ts += gst_util_uint64_scale (videorate->out_frame_count, videorate->to_rate_denominator * GST_SECOND, videorate->to_rate_numerator); } videorate->out_frame_count = 0; videorate->to_rate_numerator = rate_numerator; videorate->to_rate_denominator = rate_denominator; otherpad = videorate->sinkpad; } else { videorate->from_rate_numerator = rate_numerator; videorate->from_rate_denominator = rate_denominator; otherpad = videorate->srcpad; } /* now try to find something for the peer */ opeer = gst_pad_get_peer (otherpad); if (opeer) { if (gst_pad_accept_caps (opeer, caps)) { /* the peer accepts the caps as they are */ gst_pad_set_caps (otherpad, caps); ret = TRUE; } else { GstCaps *peercaps; GstCaps *transform = NULL; ret = FALSE; /* see how we can transform the input caps */ if (!gst_video_rate_transformcaps (pad, caps, otherpad, &transform)) goto no_transform; /* see what the peer can do */ peercaps = gst_pad_get_caps (opeer); GST_DEBUG_OBJECT (opeer, "icaps %" GST_PTR_FORMAT, peercaps); GST_DEBUG_OBJECT (videorate, "transform %" GST_PTR_FORMAT, transform); /* filter against our possibilities */ caps = gst_caps_intersect (peercaps, transform); gst_caps_unref (peercaps); gst_caps_unref (transform); GST_DEBUG_OBJECT (videorate, "intersect %" GST_PTR_FORMAT, caps); /* could turn up empty, due to e.g. colorspace etc */ if (gst_caps_get_size (caps) == 0) { gst_caps_unref (caps); goto no_transform; } /* take first possibility */ gst_caps_truncate (caps); structure = gst_caps_get_structure (caps, 0); /* and fixate */ gst_structure_fixate_field_nearest_fraction (structure, "framerate", rate_numerator, rate_denominator); gst_structure_get_fraction (structure, "framerate", &rate_numerator, &rate_denominator); if (otherpad == videorate->srcpad) { videorate->to_rate_numerator = rate_numerator; videorate->to_rate_denominator = rate_denominator; } else { videorate->from_rate_numerator = rate_numerator; videorate->from_rate_denominator = rate_denominator; } if (gst_structure_has_field (structure, "interlaced")) gst_structure_fixate_field_boolean (structure, "interlaced", FALSE); if (gst_structure_has_field (structure, "color-matrix")) gst_structure_fixate_field_string (structure, "color-matrix", "sdtv"); if (gst_structure_has_field (structure, "chroma-site")) gst_structure_fixate_field_string (structure, "chroma-site", "mpeg2"); if (gst_structure_has_field (structure, "pixel-aspect-ratio")) gst_structure_fixate_field_nearest_fraction (structure, "pixel-aspect-ratio", 1, 1); gst_pad_set_caps (otherpad, caps); gst_caps_unref (caps); ret = TRUE; } gst_object_unref (opeer); } done: /* After a setcaps, our caps may have changed. In that case, we can't use * the old buffer, if there was one (it might have different dimensions) */ GST_DEBUG_OBJECT (videorate, "swapping old buffers"); gst_video_rate_swap_prev (videorate, NULL, GST_CLOCK_TIME_NONE); gst_object_unref (videorate); return ret; no_framerate: { GST_DEBUG_OBJECT (videorate, "no framerate specified"); goto done; } no_transform: { GST_DEBUG_OBJECT (videorate, "no framerate transform possible"); ret = FALSE; goto done; } }