How to use GStreamers switchbin element?

I have two working pipelines - one for MJPEG streams and one for H.264.

udpsrc port=5021 caps="application/x-rtp,encoding-name=JPEG,payload=26" ! \
    rtpjitterbuffer ! rtpjpegdepay ! jpegparse ! jpegdec ! autovideosink

udpsrc port=5021 caps="application/x-rtp,encoding-name=H264,payload=96" ! \
    rtpjitterbuffer ! rtph264depay ! h264parse ! openh264dec ! autovideosink

Now I don’t want to switch between those manually depending on which encoding is currenty used, so I tried to use switchbin, which just doesn’t seem to work for me…

What I’ve tried:

udpsrc port=5021 ! rtpjitterbuffer ! \
    switchbin num-paths=2 \
    path0::element="rtpjpegdepay ! jpegparse ! jpegdec" \
    path0::caps="application/x-rtp,encoding-name=JPEG,payload=26" \
    path1::element="rtph264depay ! h264parse ! openh264dec" \
    path1::caps="application/x-rtp,encoding-name=H264,payload=96" ! autovideosink

This is just not showing anything after Setting pipeline to PLAYING ....

udpsrc port=5021 ! \
    switchbin num-paths=2 \
    path0::element="rtpjitterbuffer ! rtpjpegdepay ! jpegparse ! jpegdec" \
    path0::caps="application/x-rtp,encoding-name=JPEG,payload=26" \
    path1::element="rtpjitterbuffer ! rtph264depay ! h264parse ! openh264dec" \
    path1::caps="application/x-rtp,encoding-name=H264,payload=96" ! autovideosink

This is throwing following error:

ERROR: from element /GstPipeline:pipeline0/GstUDPSrc:udpsrc0: Internal data stream error.

What am I doing wrong here?

Fyi: I am using Windows 11 23H2 with GStreamer 1.22.7 (MSVC 64-bit).

I realise this doesn’t answer your question, but have you considered or tried doing something like this instead?

udpsrc caps=... ! rtpjitterbuffer ! decodebin3 ! videoconvert ! videoscale ! autovideosink

I have tried that too.

Missing element: application/x-rtp decoder
ERROR: from element /GstPipeline:pipeline0/GstDecodeBin:decodebin0: Your GStreamer installation is missing a plug-in.
Additional debug info:
../gst/playback/gstdecodebin2.c(4705): gst_decode_bin_expose (): /GstPipeline:pipeline0/GstDecodeBin:decodebin0:
no suitable plugins found:
Missing decoder: application/x-rtp (application/x-rtp, encoding-name=(string)H264, payload=(int)96)

That sounds like you’re missing the rtph264depay element which comes with gstreamer1.0-plugins-good on debian/ubuntu, and should be included in any Windows build and our Windows binary packages, so I’m surprised you don’t have it. Does gst-inspect-1.0.exe rtph264depay work?

Actually, perhaps it’s just because you’re missing the fields media=video,clock-rate=90000 in your RTP caps?

It’s there and I can use it (see pipeline in first post).
It’s just that decodebin doesn’t do depay and parse - just decode?

decodebin and decodebin3 should handle RTP caps just fine (unless mandatory fields are missing), e.g. this works just fine for me: gst-launch-1.0 rtspsrc location=rtsp://127.0.0.1:8554/test ! application/x-rtp,media=video ! decodebin3 ! videoconvert ! ximagesink (and it has to, otherwise playbin/playbin3 wouldn’t be able to play RTSP streams).

So not sure what the problem is in your case with decodebin. A GST_DEBUG=*decode*:6 debug log might shed some light.