static gboolean gst_proxy_pad_do_acceptcaps (GstPad * pad, GstCaps * caps) { GstPad *target = gst_proxy_pad_get_target (pad); gboolean res; if (target) { res = gst_pad_accept_caps (target, caps); gst_object_unref (target); } else { /* We don't have a target, we return TRUE and we assume that any future * target will be able to deal with any configured caps. */ res = TRUE; } return res; }
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; } }