Last active
March 7, 2018 09:32
-
-
Save justinjoy/36575945f6aa65b31e088beb4aadfc29 to your computer and use it in GitHub Desktop.
Simple Pipeline for leak detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Gst; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace PipelineTest | |
{ | |
class Playback | |
{ | |
static GLib.MainLoop mainLoop; | |
static void SourceSetup (object o, GLib.SignalArgs args) | |
{ | |
Console.WriteLine("source-setup ----"); | |
} | |
static void Run(object o) | |
{ | |
int i = 500; | |
while (i-- > 0) | |
{ | |
Pipeline pipeline = (Pipeline)Parse.Launch("uridecodebin name=uridecodebin ! videoconvert ! textoverlay name=textoverlay ! fakesink name=vsink"); | |
//Pipeline pipeline = (Pipeline)Parse.Launch("videotestsrc ! fakesink"); | |
var uridecodebin = pipeline.GetByName("uridecodebin"); | |
uridecodebin["uri"] = "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov"; | |
//uridecodebin.Connect("source-setup", SourceSetup); | |
pipeline.SetState(State.Playing); | |
bool terminated = false; | |
do | |
{ | |
using (Message msg = pipeline.Bus.PopFiltered(MessageType.StateChanged)) | |
{ | |
if (msg == null || msg.Src != pipeline) | |
continue; | |
msg.ParseStateChanged(out State oldstate, out State newstate, out State pendingstate); | |
if (newstate == State.Playing) terminated = true; | |
Console.WriteLine("State {0} to {1} - pending {2}", | |
Element.StateGetName(oldstate), | |
Element.StateGetName(newstate), | |
Element.StateGetName(pendingstate)); | |
} | |
} while (!terminated); | |
Thread.Sleep(1000); | |
pipeline.SetState(State.Null); | |
// Once a signal is registered, it seems to need to call 'Disconnect' | |
// Otherwise, gstreamer-sharp holds Gst.Element in DynamicSignals. | |
//uridecodebin.Disconnect("source-setup", null); | |
uridecodebin.Dispose(); | |
pipeline.Dispose(); | |
} | |
mainLoop.Quit(); | |
} | |
public static void Main(string[] args) | |
{ | |
Environment.SetEnvironmentVariable("GST_DEBUG", "GST_TRACER:7"); | |
Environment.SetEnvironmentVariable("GST_TRACERS", "leaks"); | |
Application.Init(ref args); | |
GLib.Object.WarnOnFinalize = true; | |
GLib.MainContext context = new GLib.MainContext(); | |
mainLoop = new GLib.MainLoop(context); | |
Thread thread = new Thread(Run); | |
thread.Start(); | |
mainLoop.Run(); | |
thread.Join(); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It holds Gst.Bin, Gst.Element, Gst.Bus so memory usage gradually increases.
Screenshot: https://imgur.com/a/ma7LY