mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-07 06:52:41 +00:00
Add unit test for basic Gst.Element subclasses
This implements a simple source and sink and sends 10 buffers from one to another.
This commit is contained in:
parent
5414963019
commit
55c47c29ec
1 changed files with 144 additions and 0 deletions
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using GLib;
|
||||||
using Gst;
|
using Gst;
|
||||||
|
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
|
@ -74,4 +75,147 @@ public class ElementTest
|
||||||
source.Unlink(sink);
|
source.Unlink(sink);
|
||||||
Assert.IsFalse(source.GetStaticPad("src").IsLinked);
|
Assert.IsFalse(source.GetStaticPad("src").IsLinked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class TestSubclassesApp {
|
||||||
|
static MainLoop loop;
|
||||||
|
|
||||||
|
public class MySrc : Gst.Element {
|
||||||
|
public MySrc () : base () {
|
||||||
|
Init ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MySrc (IntPtr raw) : base (raw) {
|
||||||
|
Init ();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Pad src;
|
||||||
|
private uint nbuffers = 0;
|
||||||
|
|
||||||
|
private void Init () {
|
||||||
|
src = new Pad (templ, "src");
|
||||||
|
AddPad (src);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Caps caps = Caps.FromString ("my/dummy-data");
|
||||||
|
|
||||||
|
private void loop () {
|
||||||
|
Gst.Buffer buf = new Gst.Buffer ();
|
||||||
|
buf.Caps = caps;
|
||||||
|
Gst.FlowReturn ret = src.Push (buf);
|
||||||
|
nbuffers++;
|
||||||
|
|
||||||
|
Assert.AreEqual (ret, Gst.FlowReturn.Ok);
|
||||||
|
if (ret != Gst.FlowReturn.Ok) {
|
||||||
|
src.StopTask ();
|
||||||
|
this.PostMessage (Message.NewError (this, CoreError.Failed, "Oh no"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nbuffers == 10) {
|
||||||
|
Assert.IsTrue (src.PushEvent (Gst.Event.NewEos ()));
|
||||||
|
src.PauseTask ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override StateChangeReturn OnChangeState (StateChange transition) {
|
||||||
|
if (transition == StateChange.ReadyToPaused)
|
||||||
|
src.StartTask (loop);
|
||||||
|
else if (transition == StateChange.PausedToReady)
|
||||||
|
src.StopTask ();
|
||||||
|
|
||||||
|
return StateChangeReturn.Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PadTemplate templ = new PadTemplate ("src", Gst.PadDirection.Src, Gst.PadPresence.Always, Caps.FromString ("my/dummy-data"));
|
||||||
|
|
||||||
|
public static bool Register () {
|
||||||
|
SetDetails ( (GType) typeof (MySrc), "long", "klass", "desc", "author");
|
||||||
|
AddPadTemplate ( (GType) typeof (MySrc), templ);
|
||||||
|
return ElementFactory.Register (null, "mysrc", (uint) Gst.Rank.None, (GType) typeof (MySrc));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MySink : Gst.Element {
|
||||||
|
public MySink () : base () {
|
||||||
|
Init ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MySink (IntPtr raw) : base (raw) {
|
||||||
|
Init ();
|
||||||
|
}
|
||||||
|
|
||||||
|
Gst.FlowReturn on_chain (Gst.Pad pad, Gst.Buffer buffer) {
|
||||||
|
Assert.IsNotNull (buffer);
|
||||||
|
return Gst.FlowReturn.Ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool on_event (Gst.Pad pad, Gst.Event evnt) {
|
||||||
|
if (evnt.Type == Gst.EventType.Eos) {
|
||||||
|
this.PostMessage (Message.NewEos (this));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Init () {
|
||||||
|
Pad pad = new Pad (templ, "sink");
|
||||||
|
pad.ChainFunction = on_chain;
|
||||||
|
pad.EventFunction = on_event;
|
||||||
|
AddPad (pad);
|
||||||
|
}
|
||||||
|
|
||||||
|
static PadTemplate templ = new PadTemplate ("sink", Gst.PadDirection.Sink, Gst.PadPresence.Always, Caps.FromString ("my/dummy-data"));
|
||||||
|
|
||||||
|
public static bool Register () {
|
||||||
|
SetDetails ( (GType) typeof (MySink), "long", "klass", "desc", "author");
|
||||||
|
AddPadTemplate ( (GType) typeof (MySink), templ);
|
||||||
|
|
||||||
|
return ElementFactory.Register (null, "mysink", (uint) Gst.Rank.None, (GType) typeof (MySink));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool BusCb (Bus bus, Message message) {
|
||||||
|
switch (message.Type) {
|
||||||
|
case MessageType.Error:
|
||||||
|
Enum err;
|
||||||
|
string msg;
|
||||||
|
|
||||||
|
message.ParseError (out err, out msg);
|
||||||
|
Assert.Fail (String.Format ("Error message: {0}", msg));
|
||||||
|
loop.Quit ();
|
||||||
|
break;
|
||||||
|
case MessageType.Eos:
|
||||||
|
loop.Quit ();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Run () {
|
||||||
|
|
||||||
|
MySrc.Register ();
|
||||||
|
MySink.Register ();
|
||||||
|
|
||||||
|
MySrc mysrc = Gst.ElementFactory.Make ("mysrc") as MySrc;
|
||||||
|
MySink mysink = Gst.ElementFactory.Make ("mysink") as MySink;
|
||||||
|
|
||||||
|
Gst.Pipeline pipeline = new Pipeline ("pipeline");
|
||||||
|
pipeline.Add (mysrc, mysink);
|
||||||
|
Assert.IsTrue (mysrc.Link (mysink));
|
||||||
|
|
||||||
|
loop = new MainLoop ();
|
||||||
|
|
||||||
|
pipeline.Bus.AddWatch (new BusFunc (BusCb));
|
||||||
|
pipeline.SetState (Gst.State.Playing);
|
||||||
|
|
||||||
|
loop.Run ();
|
||||||
|
|
||||||
|
pipeline.SetState (Gst.State.Null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestSubclasses ()
|
||||||
|
{
|
||||||
|
TestSubclassesApp.Run ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue