/* Based on gstbasetextoverlay.c */ static GstCaps * gst_overlay_composition_src_query_caps (GstOverlayComposition * self, GstCaps * filter) { GstCaps *peer_caps = NULL, *caps = NULL, *overlay_filter = NULL; if (filter) { /* duplicate filter caps which contains the composition into one version * with the meta and one without. Filter the other caps by the software * caps */ GstCaps *sw_caps = gst_static_caps_get (&overlay_composition_caps); overlay_filter = intersect_by_feature (filter, GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION, sw_caps); gst_caps_unref (sw_caps); } peer_caps = gst_pad_peer_query_caps (self->sinkpad, overlay_filter); if (overlay_filter) gst_caps_unref (overlay_filter); if (peer_caps) { GST_DEBUG_OBJECT (self->srcpad, "peer caps %" GST_PTR_FORMAT, peer_caps); if (gst_caps_is_any (peer_caps)) { /* if peer returns ANY caps, return filtered sink pad template caps */ caps = gst_caps_copy (gst_pad_get_pad_template_caps (self->sinkpad)); } else { /* return upstream caps + composition feature + upstream caps * filtered by the software caps. */ GstCaps *sw_caps = gst_static_caps_get (&overlay_composition_caps); caps = add_feature_and_intersect (peer_caps, GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION, sw_caps); gst_caps_unref (sw_caps); } gst_caps_unref (peer_caps); } else { /* no peer, our padtemplate is enough then */ caps = gst_pad_get_pad_template_caps (self->srcpad); } if (filter) { GstCaps *intersection; intersection = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST); gst_caps_unref (caps); caps = intersection; } GST_DEBUG_OBJECT (self->srcpad, "returning %" GST_PTR_FORMAT, caps); return caps; }
static GstCaps * smart_encoder_sink_getcaps (GstPad * pad, GstCaps * filter) { GstCaps *peer, *tmpl, *res; GstSmartEncoder *smart_encoder = GST_SMART_ENCODER (gst_pad_get_parent (pad)); /* Use computed caps */ if (smart_encoder->available_caps) tmpl = gst_caps_ref (smart_encoder->available_caps); else tmpl = gst_static_pad_template_get_caps (&src_template); /* Try getting it from downstream */ peer = gst_pad_peer_query_caps (smart_encoder->srcpad, tmpl); if (peer == NULL) { res = tmpl; } else { res = peer; gst_caps_unref (tmpl); } gst_object_unref (smart_encoder); return res; }
static gboolean gst_rtp_h263p_pay_setcaps (GstRTPBasePayload * payload, GstCaps * caps) { gboolean res; GstCaps *peercaps; gchar *encoding_name = NULL; g_return_val_if_fail (gst_caps_is_fixed (caps), FALSE); peercaps = gst_pad_peer_query_caps (GST_RTP_BASE_PAYLOAD_SRCPAD (payload), NULL); if (peercaps) { GstCaps *tcaps = gst_pad_get_pad_template_caps (GST_RTP_BASE_PAYLOAD_SRCPAD (payload)); GstCaps *intersect = gst_caps_intersect (peercaps, tcaps); gst_caps_unref (tcaps); gst_caps_unref (peercaps); if (!gst_caps_is_empty (intersect)) { GstStructure *s = gst_caps_get_structure (intersect, 0); encoding_name = g_strdup (gst_structure_get_string (s, "encoding-name")); } gst_caps_unref (intersect); } if (!encoding_name) encoding_name = g_strdup ("H263-1998"); gst_rtp_base_payload_set_options (payload, "video", TRUE, (gchar *) encoding_name, 90000); res = gst_rtp_base_payload_set_outcaps (payload, NULL); g_free (encoding_name); return res; }
static gboolean srcpad_can_dmabuf (GstMsdkDec * thiz) { gboolean ret = FALSE; GstCaps *caps, *out_caps; GstPad *srcpad; srcpad = GST_VIDEO_DECODER_SRC_PAD (thiz); caps = gst_pad_get_pad_template_caps (srcpad); out_caps = gst_pad_peer_query_caps (srcpad, caps); if (!out_caps) goto done; if (gst_caps_is_any (out_caps) || gst_caps_is_empty (out_caps) || out_caps == caps) goto done; if (_gst_caps_has_feature (out_caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) ret = TRUE; done: if (caps) gst_caps_unref (caps); if (out_caps) gst_caps_unref (out_caps); return ret; }
gboolean gst_rtp_dtmf_depay_setcaps (GstRTPBaseDepayload * filter, GstCaps * caps) { GstCaps *filtercaps, *srccaps; GstStructure *structure = gst_caps_get_structure (caps, 0); gint clock_rate = 8000; /* default */ gst_structure_get_int (structure, "clock-rate", &clock_rate); filter->clock_rate = clock_rate; filtercaps = gst_pad_get_pad_template_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (filter)); filtercaps = gst_caps_make_writable (filtercaps); gst_caps_set_simple (filtercaps, "rate", G_TYPE_INT, clock_rate, NULL); srccaps = gst_pad_peer_query_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (filter), filtercaps); gst_caps_unref (filtercaps); gst_pad_set_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (filter), srccaps); gst_caps_unref (srccaps); return TRUE; }
static GstCaps * gst_dvd_spu_video_proxy_getcaps (GstPad * pad, GstCaps * filter) { GstDVDSpu *dvdspu = GST_DVD_SPU (gst_pad_get_parent (pad)); GstCaps *caps; GstPad *otherpad; /* Proxy the getcaps between videosink and the srcpad, ignoring the * subpicture sink pad */ otherpad = (pad == dvdspu->srcpad) ? dvdspu->videosinkpad : dvdspu->srcpad; caps = gst_pad_peer_query_caps (otherpad, filter); if (caps) { GstCaps *temp, *templ; templ = gst_pad_get_pad_template_caps (otherpad); temp = gst_caps_intersect (caps, templ); gst_caps_unref (templ); gst_caps_unref (caps); caps = temp; } else { caps = gst_pad_get_pad_template_caps (pad); } gst_object_unref (dvdspu); return caps; }
static gboolean same_clock_rate_fold (const GValue * item, GValue * ret, gpointer user_data) { GstPad *mypad = user_data; GstPad *pad = g_value_get_object (item); GstCaps *peercaps; GstCaps *accumcaps; GstCaps *intersect; if (pad == mypad) return TRUE; accumcaps = g_value_get_boxed (ret); peercaps = gst_pad_peer_query_caps (pad, accumcaps); if (!peercaps) { g_warning ("no peercaps"); return TRUE; } peercaps = gst_caps_make_writable (peercaps); clear_caps (peercaps, TRUE); intersect = gst_caps_intersect (accumcaps, peercaps); g_value_take_boxed (ret, intersect); gst_caps_unref (peercaps); return !gst_caps_is_empty (intersect); }
static GstCaps * gst_rtp_opus_pay_getcaps (GstRTPBasePayload * payload, GstPad * pad, GstCaps * filter) { GstCaps *caps, *peercaps, *tcaps; GstStructure *s; const gchar *stereo; if (pad == GST_RTP_BASE_PAYLOAD_SRCPAD (payload)) return GST_RTP_BASE_PAYLOAD_CLASS (gst_rtp_opus_pay_parent_class)->get_caps (payload, pad, filter); tcaps = gst_pad_get_pad_template_caps (GST_RTP_BASE_PAYLOAD_SRCPAD (payload)); peercaps = gst_pad_peer_query_caps (GST_RTP_BASE_PAYLOAD_SRCPAD (payload), tcaps); gst_caps_unref (tcaps); if (!peercaps) return GST_RTP_BASE_PAYLOAD_CLASS (gst_rtp_opus_pay_parent_class)->get_caps (payload, pad, filter); if (gst_caps_is_empty (peercaps)) return peercaps; caps = gst_pad_get_pad_template_caps (GST_RTP_BASE_PAYLOAD_SINKPAD (payload)); s = gst_caps_get_structure (peercaps, 0); stereo = gst_structure_get_string (s, "stereo"); if (stereo != NULL) { caps = gst_caps_make_writable (caps); if (!strcmp (stereo, "1")) { GstCaps *caps2 = gst_caps_copy (caps); gst_caps_set_simple (caps, "channels", G_TYPE_INT, 2, NULL); gst_caps_set_simple (caps2, "channels", G_TYPE_INT, 1, NULL); caps = gst_caps_merge (caps, caps2); } else if (!strcmp (stereo, "0")) { GstCaps *caps2 = gst_caps_copy (caps); gst_caps_set_simple (caps, "channels", G_TYPE_INT, 1, NULL); gst_caps_set_simple (caps2, "channels", G_TYPE_INT, 2, NULL); caps = gst_caps_merge (caps, caps2); } } gst_caps_unref (peercaps); if (filter) { GstCaps *tmp = gst_caps_intersect_full (caps, filter, GST_CAPS_INTERSECT_FIRST); gst_caps_unref (caps); caps = tmp; } GST_DEBUG_OBJECT (payload, "Returning caps: %" GST_PTR_FORMAT, caps); return caps; }
static GstCaps * gst_rtp_mux_getcaps (GstPad * pad, GstRTPMux * mux, GstCaps * filter) { GstCaps *caps = NULL; GstIterator *iter = NULL; GValue v = { 0 }; GstIteratorResult res; GstCaps *peercaps; GstCaps *othercaps; GstCaps *tcaps; GstCaps *other_filtered; peercaps = gst_pad_peer_query_caps (mux->srcpad, filter); if (peercaps) { tcaps = gst_pad_get_pad_template_caps (pad); othercaps = gst_caps_intersect_full (peercaps, tcaps, GST_CAPS_INTERSECT_FIRST); gst_caps_unref (peercaps); } else { tcaps = gst_pad_get_pad_template_caps (mux->srcpad); if (filter) othercaps = gst_caps_intersect_full (filter, tcaps, GST_CAPS_INTERSECT_FIRST); else othercaps = gst_caps_copy (tcaps); } gst_caps_unref (tcaps); clear_caps (othercaps, FALSE); other_filtered = gst_caps_copy (othercaps); clear_caps (other_filtered, TRUE); g_value_init (&v, GST_TYPE_CAPS); iter = gst_element_iterate_sink_pads (GST_ELEMENT (mux)); do { gst_value_set_caps (&v, other_filtered); res = gst_iterator_fold (iter, same_clock_rate_fold, &v, pad); gst_iterator_resync (iter); } while (res == GST_ITERATOR_RESYNC); gst_iterator_free (iter); gst_caps_unref (other_filtered); caps = gst_caps_intersect ((GstCaps *) gst_value_get_caps (&v), othercaps); g_value_unset (&v); gst_caps_unref (othercaps); if (res == GST_ITERATOR_ERROR) { gst_caps_unref (caps); caps = gst_caps_new_empty (); } return caps; }
static GstCaps * gst_ac3_parse_get_sink_caps (GstBaseParse * parse, GstCaps * filter) { GstCaps *peercaps, *templ; GstCaps *res; templ = gst_pad_get_pad_template_caps (GST_BASE_PARSE_SINK_PAD (parse)); if (filter) { GstCaps *fcopy = gst_caps_copy (filter); /* Remove the fields we convert */ remove_fields (fcopy); /* we do not ask downstream to handle x-private1-ac3 */ fcopy = extend_caps (fcopy, FALSE); peercaps = gst_pad_peer_query_caps (GST_BASE_PARSE_SRC_PAD (parse), fcopy); gst_caps_unref (fcopy); } else peercaps = gst_pad_peer_query_caps (GST_BASE_PARSE_SRC_PAD (parse), NULL); if (peercaps) { /* Remove the framed and alignment field. We can convert * between different alignments. */ peercaps = gst_caps_make_writable (peercaps); remove_fields (peercaps); /* also allow for x-private1-ac3 input */ peercaps = extend_caps (peercaps, TRUE); res = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST); gst_caps_unref (peercaps); gst_caps_unref (templ); } else { res = templ; } if (filter) { GstCaps *intersection; intersection = gst_caps_intersect_full (filter, res, GST_CAPS_INTERSECT_FIRST); gst_caps_unref (res); res = intersection; } return res; }
static gboolean gst_v4l2_transform_query (GstBaseTransform * trans, GstPadDirection direction, GstQuery * query) { GstV4l2Transform *self = GST_V4L2_TRANSFORM (trans); gboolean ret = TRUE; switch (GST_QUERY_TYPE (query)) { case GST_QUERY_CAPS:{ GstCaps *filter, *caps = NULL, *result = NULL; GstPad *pad, *otherpad; gst_query_parse_caps (query, &filter); if (direction == GST_PAD_SRC) { pad = GST_BASE_TRANSFORM_SRC_PAD (trans); otherpad = GST_BASE_TRANSFORM_SINK_PAD (trans); if (self->probed_srccaps) caps = gst_caps_ref (self->probed_srccaps); } else { pad = GST_BASE_TRANSFORM_SINK_PAD (trans); otherpad = GST_BASE_TRANSFORM_SRC_PAD (trans); if (self->probed_sinkcaps) caps = gst_caps_ref (self->probed_sinkcaps); } if (!caps) caps = gst_pad_get_pad_template_caps (pad); if (filter) { GstCaps *tmp = caps; caps = gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST); gst_caps_unref (tmp); } result = gst_pad_peer_query_caps (otherpad, caps); result = gst_caps_make_writable (result); gst_caps_append (result, caps); GST_DEBUG_OBJECT (self, "Returning %s caps %" GST_PTR_FORMAT, GST_PAD_NAME (pad), result); gst_query_set_caps_result (query, result); gst_caps_unref (result); break; } default: ret = GST_BASE_TRANSFORM_CLASS (parent_class)->query (trans, direction, query); break; } return ret; }
static gboolean gst_stream_splitter_sink_setcaps (GstPad * pad, GstCaps * caps) { GstStreamSplitter *stream_splitter = (GstStreamSplitter *) GST_PAD_PARENT (pad); guint32 cookie; GList *tmp; gboolean res; GST_DEBUG_OBJECT (stream_splitter, "caps %" GST_PTR_FORMAT, caps); /* Try on all pads, choose the one that succeeds as the current stream */ STREAMS_LOCK (stream_splitter); resync: if (G_UNLIKELY (stream_splitter->srcpads == NULL)) { res = FALSE; goto beach; } res = FALSE; tmp = stream_splitter->srcpads; cookie = stream_splitter->cookie; while (tmp) { GstPad *srcpad = (GstPad *) tmp->data; GstCaps *peercaps; STREAMS_UNLOCK (stream_splitter); peercaps = gst_pad_peer_query_caps (srcpad, NULL); if (peercaps) { res = gst_caps_can_intersect (caps, peercaps); gst_caps_unref (peercaps); } STREAMS_LOCK (stream_splitter); if (G_UNLIKELY (cookie != stream_splitter->cookie)) goto resync; if (res) { /* FIXME : we need to switch properly */ GST_DEBUG_OBJECT (srcpad, "Setting caps on this pad was successful"); stream_splitter->current = srcpad; goto beach; } tmp = tmp->next; } beach: STREAMS_UNLOCK (stream_splitter); return res; }
static GstCaps * gst_dirac_parse_get_sink_caps (GstBaseParse * parse, GstCaps * filter) { GstCaps *peercaps, *templ; GstCaps *res; templ = gst_pad_get_pad_template_caps (GST_BASE_PARSE_SINK_PAD (parse)); if (filter) { GstCaps *fcopy = gst_caps_copy (filter); /* Remove the fields we convert */ remove_fields (fcopy); peercaps = gst_pad_peer_query_caps (GST_BASE_PARSE_SRC_PAD (parse), fcopy); gst_caps_unref (fcopy); } else peercaps = gst_pad_peer_query_caps (GST_BASE_PARSE_SRC_PAD (parse), NULL); if (peercaps) { /* Remove the parsed field */ peercaps = gst_caps_make_writable (peercaps); remove_fields (peercaps); res = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST); gst_caps_unref (peercaps); gst_caps_unref (templ); } else { res = templ; } if (filter) { GstCaps *intersection; intersection = gst_caps_intersect_full (filter, res, GST_CAPS_INTERSECT_FIRST); gst_caps_unref (res); res = intersection; } return res; }
/* we can only accept caps that we and downstream can handle. */ static GstCaps * gst_interleave_sink_getcaps (GstPad * pad, GstInterleave * self, GstCaps * filter) { GstCaps *result, *peercaps, *sinkcaps; GST_OBJECT_LOCK (self); /* If we already have caps on one of the sink pads return them */ if (self->sinkcaps) { result = gst_caps_copy (self->sinkcaps); } else { /* get the downstream possible caps */ peercaps = gst_pad_peer_query_caps (self->src, NULL); /* get the allowed caps on this sinkpad */ sinkcaps = gst_caps_copy (gst_pad_get_pad_template_caps (pad)); __remove_channels (sinkcaps); if (peercaps) { peercaps = gst_caps_make_writable (peercaps); __remove_channels (peercaps); /* if the peer has caps, intersect */ GST_DEBUG_OBJECT (pad, "intersecting peer and template caps"); result = gst_caps_intersect (peercaps, sinkcaps); gst_caps_unref (peercaps); gst_caps_unref (sinkcaps); } else { /* the peer has no caps (or there is no peer), just use the allowed caps * of this sinkpad. */ GST_DEBUG_OBJECT (pad, "no peer caps, using sinkcaps"); result = sinkcaps; } __set_channels (result, 1); } GST_OBJECT_UNLOCK (self); if (filter != NULL) { GstCaps *caps = result; GST_LOG_OBJECT (pad, "intersecting filter caps %" GST_PTR_FORMAT " with " "preliminary result %" GST_PTR_FORMAT, filter, caps); result = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST); gst_caps_unref (caps); } GST_DEBUG_OBJECT (pad, "Returning caps %" GST_PTR_FORMAT, result); return result; }
static GstCaps * gst_amr_parse_sink_getcaps (GstBaseParse * parse, GstCaps * filter) { GstCaps *peercaps, *templ; GstCaps *res; templ = gst_pad_get_pad_template_caps (GST_BASE_PARSE_SINK_PAD (parse)); peercaps = gst_pad_peer_query_caps (GST_BASE_PARSE_SRC_PAD (parse), filter); if (peercaps) { guint i, n; /* Rename structure names */ peercaps = gst_caps_make_writable (peercaps); n = gst_caps_get_size (peercaps); for (i = 0; i < n; i++) { GstStructure *s = gst_caps_get_structure (peercaps, i); if (gst_structure_has_name (s, "audio/AMR")) gst_structure_set_name (s, "audio/x-amr-nb-sh"); else gst_structure_set_name (s, "audio/x-amr-wb-sh"); } res = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST); gst_caps_unref (peercaps); res = gst_caps_make_writable (res); /* Append the template caps because we still want to accept * caps without any fields in the case upstream does not * know anything. */ gst_caps_append (res, templ); } else { res = templ; } if (filter) { GstCaps *intersection; intersection = gst_caps_intersect_full (filter, res, GST_CAPS_INTERSECT_FIRST); gst_caps_unref (res); res = intersection; } return res; }
static GstCaps * gst_ac3_parse_get_sink_caps (GstBaseParse * parse, GstCaps * filter) { GstCaps *peercaps, *templ; GstCaps *res; templ = gst_pad_get_pad_template_caps (GST_BASE_PARSE_SINK_PAD (parse)); peercaps = gst_pad_peer_query_caps (GST_BASE_PARSE_SRC_PAD (parse), filter); if (peercaps) { guint i, n; /* Remove the framed and alignment field. We can convert * between different alignments. */ peercaps = gst_caps_make_writable (peercaps); n = gst_caps_get_size (peercaps); for (i = 0; i < n; i++) { GstStructure *s = gst_caps_get_structure (peercaps, i); gst_structure_remove_field (s, "framed"); gst_structure_remove_field (s, "alignment"); } res = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST); gst_caps_unref (peercaps); res = gst_caps_make_writable (res); /* Append the template caps because we still want to accept * caps without any fields in the case upstream does not * know anything. */ gst_caps_append (res, templ); } else { res = templ; } if (filter) { GstCaps *intersection; intersection = gst_caps_intersect_full (filter, res, GST_CAPS_INTERSECT_FIRST); gst_caps_unref (res); res = intersection; } return res; }
static GstCaps * gst_frei0r_mixer_query_pad_caps (GstPad * pad, GstPad * skip, GstCaps * filter) { GstCaps *caps; if (pad == skip) return filter; caps = gst_pad_peer_query_caps (pad, filter); if (caps) gst_caps_unref (filter); else caps = filter; return caps; }
static void check_peer_caps (GstPad * pad, const char *expected, const char *name) { GstCaps *caps; GstCaps *expected_caps; caps = gst_pad_peer_query_caps (pad, NULL); fail_unless (caps != NULL); expected_caps = gst_caps_from_string (expected); fail_unless (expected_caps != NULL); check_caps_identical (caps, expected_caps, name); gst_caps_unref (caps); gst_caps_unref (expected_caps); }
static gboolean gst_vtdec_negotiate_output_format (GstVtdec * vtdec, GstVideoCodecState * input_state) { GstCaps *caps = NULL, *peercaps = NULL, *templcaps; GstVideoFormat output_format; GstVideoCodecState *output_state = NULL; GstCapsFeatures *features; GstStructure *structure; const gchar *s; peercaps = gst_pad_peer_query_caps (GST_VIDEO_DECODER_SRC_PAD (vtdec), NULL); /* Check if output supports GL caps by preference */ templcaps = gst_pad_get_pad_template_caps (GST_VIDEO_DECODER_SRC_PAD (vtdec)); caps = gst_caps_intersect_full (templcaps, peercaps, GST_CAPS_INTERSECT_FIRST); gst_caps_unref (peercaps); gst_caps_unref (templcaps); caps = gst_caps_truncate (caps); structure = gst_caps_get_structure (caps, 0); s = gst_structure_get_string (structure, "format"); output_format = gst_video_format_from_string (s); features = gst_caps_features_copy (gst_caps_get_features (caps, 0)); gst_caps_unref (caps); if (!gst_vtdec_create_session (vtdec, output_format)) { gst_caps_features_free (features); return FALSE; } output_state = gst_video_decoder_set_output_state (GST_VIDEO_DECODER (vtdec), output_format, vtdec->video_info.width, vtdec->video_info.height, input_state); output_state->caps = gst_video_info_to_caps (&output_state->info); gst_caps_set_features (output_state->caps, 0, features); return TRUE; }
static GstCaps * gst_segment_clip_getcaps (GstSegmentClip * self, GstPad * pad, GstCaps * filter) { GstPad *otherpad; GstCaps *tmp, *ret; otherpad = (pad == self->srcpad) ? self->sinkpad : self->srcpad; tmp = gst_pad_peer_query_caps (otherpad, filter); if (tmp) { ret = gst_caps_intersect (tmp, gst_pad_get_pad_template_caps (pad)); gst_caps_unref (tmp); } else { ret = gst_caps_copy (gst_pad_get_pad_template_caps (pad)); } GST_LOG_OBJECT (pad, "Returning caps: %" GST_PTR_FORMAT, ret); return ret; }
static GstCaps * stereosplit_get_src_caps (GstGLStereoSplit * split, GstPad * pad, GstVideoMultiviewMode preferred_mode) { GstCaps *outcaps, *tmp, *templ_caps; GValue item = G_VALUE_INIT, list = G_VALUE_INIT; /* Get the template format */ templ_caps = gst_pad_get_pad_template_caps (pad); /* And limit down to the preferred mode or mono */ templ_caps = gst_caps_make_writable (templ_caps); g_value_init (&item, G_TYPE_STRING); g_value_init (&list, GST_TYPE_LIST); g_value_set_static_string (&item, gst_video_multiview_mode_to_caps_string (preferred_mode)); gst_value_list_append_value (&list, &item); g_value_set_static_string (&item, gst_video_multiview_mode_to_caps_string (GST_VIDEO_MULTIVIEW_MODE_MONO)); gst_value_list_append_value (&list, &item); gst_caps_set_value (templ_caps, "multiview-mode", &list); g_value_unset (&list); g_value_unset (&item); /* And intersect with the peer */ if ((tmp = gst_pad_peer_query_caps (pad, NULL)) == NULL) { gst_caps_unref (templ_caps); return NULL; } outcaps = gst_caps_intersect_full (tmp, templ_caps, GST_CAPS_INTERSECT_FIRST); gst_caps_unref (tmp); gst_caps_unref (templ_caps); GST_DEBUG_OBJECT (split, "Src pad %" GST_PTR_FORMAT " caps %" GST_PTR_FORMAT, pad, outcaps); return outcaps; }
/* we can only accept caps that we and downstream can handle. */ static GstCaps * gst_interleave_sink_getcaps (GstPad * pad, GstObject * parent, GstCaps * filter) { GstInterleave *self = GST_INTERLEAVE (parent); GstCaps *result, *peercaps, *sinkcaps; GST_OBJECT_LOCK (self); /* If we already have caps on one of the sink pads return them */ if (self->sinkcaps) { result = gst_caps_copy (self->sinkcaps); } else { /* get the downstream possible caps */ peercaps = gst_pad_peer_query_caps (self->src, NULL); /* get the allowed caps on this sinkpad */ sinkcaps = gst_caps_copy (gst_pad_get_pad_template_caps (pad)); __remove_channels (sinkcaps); if (peercaps) { __remove_channels (peercaps); /* if the peer has caps, intersect */ GST_DEBUG_OBJECT (pad, "intersecting peer and template caps"); result = gst_caps_intersect (peercaps, sinkcaps); gst_caps_unref (peercaps); gst_caps_unref (sinkcaps); } else { /* the peer has no caps (or there is no peer), just use the allowed caps * of this sinkpad. */ GST_DEBUG_OBJECT (pad, "no peer caps, using sinkcaps"); result = sinkcaps; } __set_channels (result, 1); } GST_OBJECT_UNLOCK (self); GST_DEBUG_OBJECT (pad, "Returning caps %" GST_PTR_FORMAT, result); return result; }
static GstCaps * gst_interlace_getcaps (GstPad * pad, GstInterlace * interlace, GstCaps * filter) { GstPad *otherpad; GstCaps *othercaps, *tcaps; GstCaps *icaps; const char *mode; otherpad = (pad == interlace->srcpad) ? interlace->sinkpad : interlace->srcpad; tcaps = gst_pad_get_pad_template_caps (otherpad); othercaps = gst_pad_peer_query_caps (otherpad, filter); if (othercaps) { icaps = gst_caps_intersect (othercaps, tcaps); gst_caps_unref (othercaps); } else { icaps = tcaps; } if (filter) { othercaps = gst_caps_intersect (icaps, filter); gst_caps_unref (icaps); icaps = othercaps; } icaps = gst_caps_make_writable (icaps); if (interlace->pattern > GST_INTERLACE_PATTERN_2_2) { mode = "mixed"; } else { mode = "interleaved"; } gst_caps_set_simple (icaps, "interlace-mode", G_TYPE_STRING, pad == interlace->srcpad ? mode : "progressive", NULL); gst_caps_unref (tcaps); return icaps; }
static GstCaps * gst_image_freeze_sink_getcaps (GstImageFreeze * self, GstCaps * filter) { GstCaps *ret, *tmp, *templ; GstPad *pad; pad = self->sinkpad; if (gst_pad_has_current_caps (pad)) { ret = gst_pad_get_current_caps (pad); goto done; } if (filter) { filter = gst_caps_copy (filter); gst_image_freeze_remove_fps (self, filter); } templ = gst_pad_get_pad_template_caps (pad); tmp = gst_pad_peer_query_caps (self->srcpad, filter); if (tmp) { GST_LOG_OBJECT (self, "peer caps %" GST_PTR_FORMAT, tmp); ret = gst_caps_intersect (tmp, templ); gst_caps_unref (tmp); } else { GST_LOG_OBJECT (self, "going to copy"); ret = gst_caps_copy (templ); } gst_caps_unref (templ); if (filter) gst_caps_unref (filter); ret = gst_caps_make_writable (ret); gst_image_freeze_remove_fps (self, ret); done: GST_LOG_OBJECT (pad, "Returning caps: %" GST_PTR_FORMAT, ret); return ret; }
static gboolean pad_can_dmabuf (GstMsdkVPP * thiz, GstPadDirection direction, GstCaps * filter) { gboolean ret = FALSE; GstCaps *caps, *out_caps; GstPad *pad; GstBaseTransform *trans = GST_BASE_TRANSFORM (thiz); if (direction == GST_PAD_SRC) pad = GST_BASE_TRANSFORM_SRC_PAD (trans); else pad = GST_BASE_TRANSFORM_SINK_PAD (trans); /* make a copy of filter caps since we need to alter the structure * by adding dmabuf-capsfeatures */ caps = gst_caps_copy (filter); gst_caps_set_features (caps, 0, gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_DMABUF)); out_caps = gst_pad_peer_query_caps (pad, caps); if (!out_caps) goto done; if (gst_caps_is_any (out_caps) || gst_caps_is_empty (out_caps) || out_caps == caps) goto done; if (_gst_caps_has_feature (out_caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) ret = TRUE; done: if (caps) gst_caps_unref (caps); if (out_caps) gst_caps_unref (out_caps); return ret; }
/* the first caps we receive on any of the sinkpads will define the caps for all * the other sinkpads because we can only mix streams with the same caps. */ static gboolean gst_audiomixer_setcaps (GstAudioMixer * audiomixer, GstPad * pad, GstCaps * orig_caps) { GstAggregator *agg = GST_AGGREGATOR (audiomixer); GstAudioAggregator *aagg = GST_AUDIO_AGGREGATOR (audiomixer); GstCaps *caps; GstAudioInfo info; GstStructure *s; gint channels = 0; caps = gst_caps_copy (orig_caps); s = gst_caps_get_structure (caps, 0); if (gst_structure_get_int (s, "channels", &channels)) if (channels <= 2) gst_structure_remove_field (s, "channel-mask"); if (!gst_audio_info_from_caps (&info, caps)) goto invalid_format; if (channels == 1) { GstCaps *filter; GstCaps *downstream_caps; if (audiomixer->filter_caps) filter = gst_caps_intersect_full (caps, audiomixer->filter_caps, GST_CAPS_INTERSECT_FIRST); else filter = gst_caps_ref (caps); downstream_caps = gst_pad_peer_query_caps (agg->srcpad, filter); gst_caps_unref (filter); if (downstream_caps) { gst_caps_unref (caps); caps = downstream_caps; if (gst_caps_is_empty (caps)) { gst_caps_unref (caps); return FALSE; } caps = gst_caps_fixate (caps); } } GST_OBJECT_LOCK (audiomixer); /* don't allow reconfiguration for now; there's still a race between the * different upstream threads doing query_caps + accept_caps + sending * (possibly different) CAPS events, but there's not much we can do about * that, upstream needs to deal with it. */ if (aagg->current_caps != NULL) { if (gst_audio_info_is_equal (&info, &aagg->info)) { GST_OBJECT_UNLOCK (audiomixer); gst_caps_unref (caps); gst_audio_aggregator_set_sink_caps (aagg, GST_AUDIO_AGGREGATOR_PAD (pad), orig_caps); return TRUE; } else { GST_DEBUG_OBJECT (pad, "got input caps %" GST_PTR_FORMAT ", but " "current caps are %" GST_PTR_FORMAT, caps, aagg->current_caps); GST_OBJECT_UNLOCK (audiomixer); gst_pad_push_event (pad, gst_event_new_reconfigure ()); gst_caps_unref (caps); return FALSE; } } else { gst_caps_replace (&aagg->current_caps, caps); aagg->info = info; gst_pad_mark_reconfigure (GST_AGGREGATOR_SRC_PAD (agg)); } GST_OBJECT_UNLOCK (audiomixer); gst_audio_aggregator_set_sink_caps (aagg, GST_AUDIO_AGGREGATOR_PAD (pad), orig_caps); GST_INFO_OBJECT (pad, "handle caps change to %" GST_PTR_FORMAT, caps); gst_caps_unref (caps); return TRUE; /* ERRORS */ invalid_format: { gst_caps_unref (caps); GST_WARNING_OBJECT (audiomixer, "invalid format set as caps"); return FALSE; } }
/* we can only accept caps that we and downstream can handle. * if we have filtercaps set, use those to constrain the target caps. */ static GstCaps * gst_audiomixer_sink_getcaps (GstAggregator * agg, GstPad * pad, GstCaps * filter) { GstAudioAggregator *aagg; GstAudioMixer *audiomixer; GstCaps *result, *peercaps, *current_caps, *filter_caps; GstStructure *s; gint i, n; audiomixer = GST_AUDIO_MIXER (agg); aagg = GST_AUDIO_AGGREGATOR (agg); GST_OBJECT_LOCK (audiomixer); /* take filter */ if ((filter_caps = audiomixer->filter_caps)) { if (filter) filter_caps = gst_caps_intersect_full (filter, filter_caps, GST_CAPS_INTERSECT_FIRST); else gst_caps_ref (filter_caps); } else { filter_caps = filter ? gst_caps_ref (filter) : NULL; } GST_OBJECT_UNLOCK (audiomixer); if (filter_caps && gst_caps_is_empty (filter_caps)) { GST_WARNING_OBJECT (pad, "Empty filter caps"); return filter_caps; } /* get the downstream possible caps */ peercaps = gst_pad_peer_query_caps (agg->srcpad, filter_caps); /* get the allowed caps on this sinkpad */ GST_OBJECT_LOCK (audiomixer); current_caps = aagg->current_caps ? gst_caps_ref (aagg->current_caps) : NULL; if (current_caps == NULL) { current_caps = gst_pad_get_pad_template_caps (pad); if (!current_caps) current_caps = gst_caps_new_any (); } GST_OBJECT_UNLOCK (audiomixer); if (peercaps) { /* if the peer has caps, intersect */ GST_DEBUG_OBJECT (audiomixer, "intersecting peer and our caps"); result = gst_caps_intersect_full (peercaps, current_caps, GST_CAPS_INTERSECT_FIRST); gst_caps_unref (peercaps); gst_caps_unref (current_caps); } else { /* the peer has no caps (or there is no peer), just use the allowed caps * of this sinkpad. */ /* restrict with filter-caps if any */ if (filter_caps) { GST_DEBUG_OBJECT (audiomixer, "no peer caps, using filtered caps"); result = gst_caps_intersect_full (filter_caps, current_caps, GST_CAPS_INTERSECT_FIRST); gst_caps_unref (current_caps); } else { GST_DEBUG_OBJECT (audiomixer, "no peer caps, using our caps"); result = current_caps; } } result = gst_caps_make_writable (result); n = gst_caps_get_size (result); for (i = 0; i < n; i++) { GstStructure *sref; s = gst_caps_get_structure (result, i); sref = gst_structure_copy (s); gst_structure_set (sref, "channels", GST_TYPE_INT_RANGE, 0, 2, NULL); if (gst_structure_is_subset (s, sref)) { /* This field is irrelevant when in mono or stereo */ gst_structure_remove_field (s, "channel-mask"); } gst_structure_free (sref); } if (filter_caps) gst_caps_unref (filter_caps); GST_LOG_OBJECT (audiomixer, "getting caps on pad %p,%s to %" GST_PTR_FORMAT, pad, GST_PAD_NAME (pad), result); return result; }
static gboolean gst_omx_h264_enc_set_format (GstOMXVideoEnc * enc, GstOMXPort * port, GstVideoCodecState * state) { GstOMXH264Enc *self = GST_OMX_H264_ENC (enc); GstCaps *peercaps; OMX_PARAM_PORTDEFINITIONTYPE port_def; OMX_VIDEO_PARAM_PROFILELEVELTYPE param; OMX_ERRORTYPE err; const gchar *profile_string, *level_string; gst_omx_port_get_port_definition (GST_OMX_VIDEO_ENC (self)->enc_out_port, &port_def); port_def.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC; err = gst_omx_port_update_port_definition (GST_OMX_VIDEO_ENC (self)->enc_out_port, &port_def); if (err != OMX_ErrorNone) return FALSE; GST_OMX_INIT_STRUCT (¶m); param.nPortIndex = GST_OMX_VIDEO_ENC (self)->enc_out_port->index; err = gst_omx_component_get_parameter (GST_OMX_VIDEO_ENC (self)->enc, OMX_IndexParamVideoProfileLevelCurrent, ¶m); if (err != OMX_ErrorNone) { GST_WARNING_OBJECT (self, "Setting profile/level not supported by component"); return TRUE; } peercaps = gst_pad_peer_query_caps (GST_VIDEO_ENCODER_SRC_PAD (enc), gst_pad_get_pad_template_caps (GST_VIDEO_ENCODER_SRC_PAD (enc))); if (peercaps) { GstStructure *s; if (gst_caps_is_empty (peercaps)) { gst_caps_unref (peercaps); GST_ERROR_OBJECT (self, "Empty caps"); return FALSE; } s = gst_caps_get_structure (peercaps, 0); profile_string = gst_structure_get_string (s, "profile"); if (profile_string) { if (g_str_equal (profile_string, "baseline")) { param.eProfile = OMX_VIDEO_AVCProfileBaseline; } else if (g_str_equal (profile_string, "main")) { param.eProfile = OMX_VIDEO_AVCProfileMain; } else if (g_str_equal (profile_string, "extended")) { param.eProfile = OMX_VIDEO_AVCProfileExtended; } else if (g_str_equal (profile_string, "high")) { param.eProfile = OMX_VIDEO_AVCProfileHigh; } else if (g_str_equal (profile_string, "high-10")) { param.eProfile = OMX_VIDEO_AVCProfileHigh10; } else if (g_str_equal (profile_string, "high-4:2:2")) { param.eProfile = OMX_VIDEO_AVCProfileHigh422; } else if (g_str_equal (profile_string, "high-4:4:4")) { param.eProfile = OMX_VIDEO_AVCProfileHigh444; } else { goto unsupported_profile; } } level_string = gst_structure_get_string (s, "level"); if (level_string) { if (g_str_equal (level_string, "1")) { param.eLevel = OMX_VIDEO_AVCLevel1; } else if (g_str_equal (level_string, "1b")) { param.eLevel = OMX_VIDEO_AVCLevel1b; } else if (g_str_equal (level_string, "1.1")) { param.eLevel = OMX_VIDEO_AVCLevel11; } else if (g_str_equal (level_string, "1.2")) { param.eLevel = OMX_VIDEO_AVCLevel12; } else if (g_str_equal (level_string, "1.3")) { param.eLevel = OMX_VIDEO_AVCLevel13; } else if (g_str_equal (level_string, "2")) { param.eLevel = OMX_VIDEO_AVCLevel2; } else if (g_str_equal (level_string, "2.1")) { param.eLevel = OMX_VIDEO_AVCLevel21; } else if (g_str_equal (level_string, "2.2")) { param.eLevel = OMX_VIDEO_AVCLevel22; } else if (g_str_equal (level_string, "3")) { param.eLevel = OMX_VIDEO_AVCLevel3; } else if (g_str_equal (level_string, "3.1")) { param.eLevel = OMX_VIDEO_AVCLevel31; } else if (g_str_equal (level_string, "3.2")) { param.eLevel = OMX_VIDEO_AVCLevel32; } else if (g_str_equal (level_string, "4")) { param.eLevel = OMX_VIDEO_AVCLevel4; } else if (g_str_equal (level_string, "4.1")) { param.eLevel = OMX_VIDEO_AVCLevel41; } else if (g_str_equal (level_string, "4.2")) { param.eLevel = OMX_VIDEO_AVCLevel42; } else if (g_str_equal (level_string, "5")) { param.eLevel = OMX_VIDEO_AVCLevel5; } else if (g_str_equal (level_string, "5.1")) { param.eLevel = OMX_VIDEO_AVCLevel51; } else { goto unsupported_level; } } gst_caps_unref (peercaps); } err = gst_omx_component_set_parameter (GST_OMX_VIDEO_ENC (self)->enc, OMX_IndexParamVideoProfileLevelCurrent, ¶m); if (err == OMX_ErrorUnsupportedIndex) { GST_WARNING_OBJECT (self, "Setting profile/level not supported by component"); } else if (err != OMX_ErrorNone) { GST_ERROR_OBJECT (self, "Error setting profile %u and level %u: %s (0x%08x)", (guint) param.eProfile, (guint) param.eLevel, gst_omx_error_to_string (err), err); return FALSE; } return TRUE; unsupported_profile: GST_ERROR_OBJECT (self, "Unsupported profile %s", profile_string); gst_caps_unref (peercaps); return FALSE; unsupported_level: GST_ERROR_OBJECT (self, "Unsupported level %s", level_string); gst_caps_unref (peercaps); return FALSE; }
static GstCaps * gst_shape_wipe_src_getcaps (GstPad * pad, GstCaps * filter) { GstShapeWipe *self = GST_SHAPE_WIPE (gst_pad_get_parent (pad)); GstCaps *templ, *ret, *tmp; if (gst_pad_has_current_caps (pad)) return gst_pad_get_current_caps (pad); else if (gst_pad_has_current_caps (self->video_sinkpad)) return gst_pad_get_current_caps (self->video_sinkpad); templ = gst_pad_get_pad_template_caps (self->video_sinkpad); tmp = gst_pad_peer_query_caps (self->video_sinkpad, NULL); if (tmp) { ret = gst_caps_intersect (tmp, templ); gst_caps_unref (templ); gst_caps_unref (tmp); } else { ret = templ; } GST_LOG_OBJECT (pad, "video sink accepted caps: %" GST_PTR_FORMAT, ret); if (gst_caps_is_empty (ret)) goto done; tmp = gst_pad_peer_query_caps (pad, NULL); GST_LOG_OBJECT (pad, "peer accepted caps: %" GST_PTR_FORMAT, ret); if (tmp) { GstCaps *intersection; intersection = gst_caps_intersect (tmp, ret); gst_caps_unref (tmp); gst_caps_unref (ret); ret = intersection; } GST_LOG_OBJECT (pad, "intersection: %" GST_PTR_FORMAT, ret); if (gst_caps_is_empty (ret)) goto done; if (self->vinfo.height && self->vinfo.width) { guint i, n; ret = gst_caps_make_writable (ret); n = gst_caps_get_size (ret); for (i = 0; i < n; i++) { GstStructure *s = gst_caps_get_structure (ret, i); gst_structure_set (s, "width", G_TYPE_INT, self->vinfo.width, "height", G_TYPE_INT, self->vinfo.height, NULL); } } tmp = gst_pad_peer_query_caps (self->mask_sinkpad, NULL); GST_LOG_OBJECT (pad, "mask sink accepted caps: %" GST_PTR_FORMAT, ret); if (tmp) { GstCaps *intersection, *tmp2; guint i, n; tmp2 = gst_pad_get_pad_template_caps (self->mask_sinkpad); intersection = gst_caps_intersect (tmp, tmp2); gst_caps_unref (tmp); gst_caps_unref (tmp2); tmp = gst_caps_make_writable (intersection); n = gst_caps_get_size (tmp); for (i = 0; i < n; i++) { GstStructure *s = gst_caps_get_structure (tmp, i); gst_structure_remove_fields (s, "format", "framerate", NULL); gst_structure_set_name (s, "video/x-raw"); } intersection = gst_caps_intersect (tmp, ret); gst_caps_unref (tmp); gst_caps_unref (ret); ret = intersection; } done: gst_object_unref (self); GST_LOG_OBJECT (pad, "Returning caps: %" GST_PTR_FORMAT, ret); return ret; }
static GstCaps * gst_shape_wipe_mask_sink_getcaps (GstPad * pad, GstCaps * filter) { GstShapeWipe *self = GST_SHAPE_WIPE (gst_pad_get_parent (pad)); GstCaps *ret, *tmp; guint i, n; if (gst_pad_has_current_caps (pad)) return gst_pad_get_current_caps (pad); tmp = gst_pad_peer_query_caps (self->video_sinkpad, NULL); if (tmp) { ret = gst_caps_intersect (tmp, gst_pad_get_pad_template_caps (self->video_sinkpad)); gst_caps_unref (tmp); } else { ret = gst_pad_get_pad_template_caps (self->video_sinkpad); } GST_LOG_OBJECT (pad, "video sink accepted caps: %" GST_PTR_FORMAT, ret); if (gst_caps_is_empty (ret)) goto done; tmp = gst_pad_peer_query_caps (self->srcpad, NULL); GST_LOG_OBJECT (pad, "srcpad accepted caps: %" GST_PTR_FORMAT, ret); if (tmp) { GstCaps *intersection; intersection = gst_caps_intersect (ret, tmp); gst_caps_unref (ret); gst_caps_unref (tmp); ret = intersection; } GST_LOG_OBJECT (pad, "intersection: %" GST_PTR_FORMAT, ret); if (gst_caps_is_empty (ret)) goto done; n = gst_caps_get_size (ret); tmp = gst_caps_new_empty (); for (i = 0; i < n; i++) { GstStructure *s = gst_caps_get_structure (ret, i); GstStructure *t; gst_structure_set_name (s, "video/x-raw"); gst_structure_remove_fields (s, "format", "framerate", NULL); if (self->vinfo.width && self->vinfo.height) gst_structure_set (s, "width", G_TYPE_INT, self->vinfo.width, "height", G_TYPE_INT, self->vinfo.height, NULL); gst_structure_set (s, "framerate", GST_TYPE_FRACTION, 0, 1, NULL); t = gst_structure_copy (s); gst_structure_set (s, "format", G_TYPE_STRING, GST_VIDEO_NE (GRAY16), NULL); gst_structure_set (t, "format", G_TYPE_STRING, "GRAY8", NULL); gst_caps_append_structure (tmp, t); } gst_caps_append (ret, tmp); tmp = gst_pad_peer_query_caps (pad, NULL); GST_LOG_OBJECT (pad, "peer accepted caps: %" GST_PTR_FORMAT, tmp); if (tmp) { GstCaps *intersection; intersection = gst_caps_intersect (tmp, ret); gst_caps_unref (tmp); gst_caps_unref (ret); ret = intersection; } done: gst_object_unref (self); GST_LOG_OBJECT (pad, "Returning caps: %" GST_PTR_FORMAT, ret); return ret; }