how to use application/x-rtp binding with gstreamer-sharp?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

how to use application/x-rtp binding with gstreamer-sharp?

Hi, I am wondering how/if it's possible to use the following gstreamer bindings using gstreamer-sharp/C# for Windows?

udpsrc port=1234 ! application/x-rtp, payload=127 ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink

I am not sure how to do the "application/x-rtp, payload=127" part and I think that's all I am missing, but I am not 100% sure about this.  The videosink I am trying to use is dshowvideosink.

Here's the relevant parts of my code (note: the variable videoDisplay is just a WinForms Panel control on my form)

internal enum videosinktype { glimagesink, d3dvideosink, dshowvideosink, directdrawsink}

static Element mVideoConv, mUdpcSrc, mDemux, mAvDecH264, mAVSink;
static Gst.App.AppSink mAppSink;
static System.Threading.Thread mMainGlibThread;
static GLib.MainLoop mMainLoop;  // GLib's Main Loop

private const videosinktype mCfgVideosinkType = videosinktype.dshowvideosink;
private ulong mHandle;
private Gst.Video.VideoSink mGlImageSink;
private Gst.Pipeline mCurrentPipeline = null;

private void InitGStreamerPipeline()
        //Assign Handle to prevent Cross-Threading Access
    mHandle = (ulong)videoDisplay.Handle;
        //Init Gstreamer
        mMainLoop = new GLib.MainLoop();
        mMainGlibThread = new System.Threading.Thread(mMainLoop.Run);
    #region BuildPipeline
        switch (mCfgVideosinkType)
                case videosinktype.glimagesink:
                        mGlImageSink = (Gst.Video.VideoSink)Gst.ElementFactory.Make("glimagesink", "glimagesink");
                case videosinktype.d3dvideosink:
                        mGlImageSink = (Gst.Video.VideoSink)Gst.ElementFactory.Make("d3dvideosink", "d3dvideosink");
                        //mGlImageSink = (Gst.Video.VideoSink)Gst.ElementFactory.Make("dshowvideosink", "dshowvideosink");
                case videosinktype.dshowvideosink:
                        mGlImageSink = (Gst.Video.VideoSink)Gst.ElementFactory.Make("dshowvideosink", "dshowvideosink");
                case videosinktype.directdrawsink:
                        mGlImageSink = (Gst.Video.VideoSink)Gst.ElementFactory.Make("directdrawsink", "directdrawsink");
        //what's the gstreamer-sharp equivalent of:
        //application/x-rtp, payload=127
        mUdpcSrc = ElementFactory.Make("udpsrc", "sink0");
    mUdpcSrc["port"] = 1234;
        mDemux = ElementFactory.Make("rtph264depay", "depay0");
        mAvDecH264 = ElementFactory.Make("avdec_h264", "avdech2640");
        mVideoConv = ElementFactory.Make("videoconvert", "vidconvert0");
        mAVSink = ElementFactory.Make("autovideosink", "video_sink");
        mCurrentPipeline = new Gst.Pipeline("pipeline");
        mCurrentPipeline.Add(mUdpcSrc, mDemux, mAvDecH264, mVideoConv, mAVSink);
        if (!mVideoTestSource.Link(mVideoSink))
    if (mUdpcSrc.Link(mVideoSink))            
                System.Diagnostics.Debug.WriteLine("Elements could not be linked");
        //subscribe to bus & bussync msgs
        Bus bus = mCurrentPipeline.Bus;
    bus.Message += HandleMessage;
        Bus bus = mCurrentPipeline.Bus;
    bus.SyncMessage += new SyncMessageHandler(bus_SyncMessage);
        //play the stream
        var setStateRet = mCurrentPipeline.SetState(State.Null);
    System.Diagnostics.Debug.WriteLine("SetStateNULL returned: " + setStateRet.ToString());
    setStateRet = mCurrentPipeline.SetState(State.Ready);
    System.Diagnostics.Debug.WriteLine("SetStateReady returned: " + setStateRet.ToString());
    setStateRet = mCurrentPipeline.SetState(Gst.State.Playing);

 /// <summary>
/// </summary>
/// <remarks>
/// Indeed the application needs to set its Window identifier at the right time to avoid internal Window creation
/// from the video sink element. To solve this issue a GstMessage is posted on the bus to inform the application
/// that it should set the Window identifier immediately.
/// API:
/// </remarks>
private void bus_SyncMessage(object o, SyncMessageArgs args)
        //Convenience function to check if the given message is a "prepare-window-handle" message from a GstVideoOverlay.

        System.Diagnostics.Debug.WriteLine("bus_SyncMessage: " + args.Message.Type.ToString());
        if (Gst.Video.Global.IsVideoOverlayPrepareWindowHandleMessage(args.Message))
                Element src = (Gst.Element)args.Message.Src;

                System.Diagnostics.Debug.WriteLine("Message'prepare-window-handle' received by: " + src.Name + " " + src.ToString());

                if (src != null && (src is Gst.Video.VideoSink | src is Gst.Bin))
                        //    Try to set Aspect Ratio
                                src["force-aspect-ratio"] = true;
                        catch (PropertyNotFoundException) { }

                        //    Try to set Overlay
                                Gst.Video.VideoOverlayAdapter overlay_ = new Gst.Video.VideoOverlayAdapter(src.Handle);
                                overlay_.WindowHandle = mHandle;                        
                        catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception thrown: " + ex.Message); }

private void HandleMessage (object o, MessageArgs args)
        var msg = args.Message;
        //System.Diagnostics.Debug.WriteLine("HandleMessage received msg of type: {0}", msg.Type);
        switch (msg.Type)
                case MessageType.Error:
                        GLib.GException err;
                        string debug;
                        System.Diagnostics.Debug.WriteLine("Error received: " + msg.ToString());
                        //msg.ParseError (out err, out debug);
                        //if(debug == null) { debug = "none"; }
                        //System.Diagnostics.Debug.WriteLine ("Error received from element {0}: {1}", msg.Src, err.Message);
                        //System.Diagnostics.Debug.WriteLine ("Debugging information: "+ debug);
                case MessageType.StreamStatus:
                        Gst.StreamStatusType status;
                        Element theOwner;
                        msg.ParseStreamStatus(out status, out theOwner);
                        System.Diagnostics.Debug.WriteLine("Case SteamingStatus: status is: " + status + " ; Ownder is: " + theOwner.Name);
                case MessageType.StateChanged:
                        //System.Diagnostics.Debug.WriteLine("Case StateChanged: " + args.Message.ToString());
                        State oldState, newState, pendingState;
                        msg.ParseStateChanged(out oldState, out newState, out pendingState);
                        if (newState == State.Paused)
                                args.RetVal = false;
                        System.Diagnostics.Debug.WriteLine("Pipeline state changed from {0} to {1}: ; Pending: {2}", Element.StateGetName(oldState), Element.StateGetName(newState), Element.StateGetName(pendingState));
                case MessageType.Element:
                        System.Diagnostics.Debug.WriteLine("Element message: {0}", args.Message.ToString());
                        System.Diagnostics.Debug.WriteLine("HandleMessage received msg of type: {0}", msg.Type);
        args.RetVal = true;