public void TestAddRemove() { Bin bin = ElementFactory.Make("bin") as Bin; Assert.IsNotNull(bin, "Could not create bin"); Element e1 = new FakeSrc("fakesrc"); Element e2 = new Identity("identity"); Element e3 = new FakeSink("fakesink"); Assert.IsNotNull(e1, "Could not create fakesrc"); Assert.IsNotNull(e2, "Could not create identity"); Assert.IsNotNull(e3, "Could not create fakesink"); bin.Add(e1, e2, e3); Element.Link(e1, e2, e3); Assert.AreEqual(bin.ChildrenCount, 3); bin.Remove(e2, e3); Assert.AreEqual(bin.ChildrenCount, 1); bin.Add(e2); Assert.AreEqual(bin.ChildrenCount, 2); bin.Remove(e1, e2); Assert.AreEqual(bin.ChildrenCount, 0); }
public BpmDetector() { try { pipeline = new Pipeline(); filesrc = new FileSrc(); var decodebin = new DecodeBin2(); var audioconvert = Make("audioconvert"); var bpmdetect = Make("bpmdetect"); fakesink = new FakeSink(); pipeline.Add(filesrc, decodebin, audioconvert, bpmdetect, fakesink); if (!filesrc.Link(decodebin)) { Log.Error("Could not link pipeline elements"); throw new Exception(); } // decodebin and audioconvert are linked dynamically when the decodebin creates a new pad decodebin.NewDecodedPad += delegate(object o, DecodeBin2.NewDecodedPadArgs args) { var audiopad = audioconvert.GetStaticPad("sink"); if (audiopad.IsLinked) { return; } using (var caps = args.Pad.Caps) { using (var str = caps[0]) { if (!str.Name.Contains("audio")) { return; } } } args.Pad.Link(audiopad); }; if (!Element.Link(audioconvert, bpmdetect, fakesink)) { Log.Error("Could not link pipeline elements"); throw new Exception(); } pipeline.Bus.AddWatch(OnBusMessage); //gst_bus_add_watch (gst_pipeline_get_bus (GST_PIPELINE (detector->pipeline)), bbd_pipeline_bus_callback, detector); } catch (Exception e) { Log.Exception(e); throw new ApplicationException(Catalog.GetString("Could not create BPM detection driver."), e); } }
public void TestAdd() { Bin bin = new Bin("test-bin"); Element e1 = new FakeSrc("fakesrc"); Element e2 = new FakeSink("fakesink"); Assert.IsNotNull(bin, "Could not create bin"); Assert.IsNotNull(e1, "Could not create fakesrc"); Assert.IsNotNull(e2, "Could not create fakesink"); bin.Add(e1, e2); Assert.AreEqual(bin.ChildrenCount, 2); }
public void TestBaseTime() { Element pipeline = ElementFactory.Make("pipeline", "pipeline"); FakeSrc fakesrc = FakeSrc.Make("fakesrc"); FakeSink fakesink = FakeSink.Make("fakesink"); Assert.IsNotNull(pipeline, "Could not create pipeline"); Assert.IsNotNull(fakesrc, "Could not create fakesrc"); Assert.IsNotNull(fakesink, "Could not create fakesink"); fakesrc.IsLive = true; Bin bin = (Bin)pipeline; bin.Add(fakesrc, fakesink); Assert.IsTrue(fakesrc.Link(fakesink)); Pad sink = fakesink.GetStaticPad("sink"); }
public static void Main(string [] args) { Application.Init(); Pipeline pipeline = new Pipeline("pipeline"); FileSrc source = FileSrc.Make("source"); typefind = TypeFindElement.Make("typefind"); FakeSink sink = FakeSink.Make("sink"); source.Location = args[0]; typefind.HaveType += OnHaveType; pipeline.Add(source, typefind, sink); source.Link(typefind); typefind.Link(sink); pipeline.SetState(State.Paused); pipeline.SetState(State.Null); pipeline.Dispose(); }
public void SimpleAutoSyncTrackingCancelledCycle() { // arrange identifiers var scopeId = Guid.NewGuid(); var scopeName = Guid.NewGuid().ToString(); var trackingId = Guid.NewGuid(); // arrange a stopwatch that tracks a known interval var elapsed = TimeSpan.FromSeconds(123); var watch = new FakeTrackerStopwatch { TargetElapsed = elapsed }; var factory = Mock.Of <ITrackerStopwatchFactory>(x => x.Create() == watch); // arrange a test sink var sink = new FakeSink(); // arrange a system clock var now = DateTimeOffset.Now; var clock = new FakeSystemClock { Now = now }; // act - build host using (var host = Host .CreateDefaultBuilder() .UseChronoscope(chrono => { chrono.ConfigureServices(services => { services.AddSingleton(factory); services.AddSingleton <ITrackingSink>(sink); services.AddSingleton <ISystemClock>(clock); }); }) .Build()) { // act - request services var chrono = host.Services.GetRequiredService <IChronoscope>(); var scope = chrono.CreateScope(scopeId, scopeName); var tracker = scope.CreateAutoTracker(trackingId); // assert - elapsed is zero Assert.Equal(TimeSpan.Zero, tracker.Elapsed); // act - do tracking int result = -1; try { var token = new CancellationToken(true); result = tracker.Track((scope, token) => { token.ThrowIfCancellationRequested(); return(1); }, token); } catch (OperationCanceledException) { /* noop */ } // assert - the result is correct Assert.Equal(-1, result); // assert - elapsed time is correct Assert.Equal(elapsed, tracker.Elapsed); // assert - events were generated Assert.Collection(sink.Events, e => { var x = Assert.IsAssignableFrom <IScopeCreatedEvent>(e); Assert.Equal(scopeId, x.ScopeId); Assert.Equal(scopeName, x.Name); Assert.Null(x.ParentScopeId); Assert.Equal(now, x.Timestamp); }, e => { var x = Assert.IsAssignableFrom <ITrackerCreatedEvent>(e); Assert.Equal(scopeId, x.ScopeId); Assert.Equal(trackingId, x.TrackerId); Assert.Equal(now, x.Timestamp); Assert.Equal(TimeSpan.Zero, x.Elapsed); }, e => { var x = Assert.IsAssignableFrom <ITrackerStartedEvent>(e); Assert.Equal(scopeId, x.ScopeId); Assert.Equal(trackingId, x.TrackerId); Assert.Equal(now, x.Timestamp); Assert.Equal(TimeSpan.Zero, x.Elapsed); }, e => { var x = Assert.IsAssignableFrom <ITrackerStoppedEvent>(e); Assert.Equal(scopeId, x.ScopeId); Assert.Equal(trackingId, x.TrackerId); Assert.Equal(now, x.Timestamp); Assert.Equal(elapsed, x.Elapsed); }, e => { var x = Assert.IsAssignableFrom <ITrackerCancelledEvent>(e); Assert.Equal(scopeId, x.ScopeId); Assert.Equal(trackingId, x.TrackerId); Assert.Equal(now, x.Timestamp); Assert.Equal(elapsed, x.Elapsed); Assert.IsAssignableFrom <OperationCanceledException>(x.Exception); }); } }
public void SimpleManualTrackingCancelledCycle() { // arrange identifiers var scopeId = Guid.NewGuid(); var scopeName = Guid.NewGuid().ToString(); var trackingId = Guid.NewGuid(); // arrange a stopwatch that tracks a known interval var elapsed = TimeSpan.FromSeconds(123); var watch = Mock.Of <ITrackerStopwatch>(); Mock.Get(watch).Setup(x => x.Stop()).Callback(() => Mock.Get(watch).Setup(x => x.Elapsed).Returns(elapsed)); var factory = Mock.Of <ITrackerStopwatchFactory>(x => x.Create() == watch); // arrange a test sink var sink = new FakeSink(); // arrange a system clock var now = DateTimeOffset.Now; var clock = Mock.Of <ISystemClock>(x => x.Now == now); // act - build host using (var host = Host .CreateDefaultBuilder() .UseChronoscope(chrono => { chrono.ConfigureServices(services => { services.AddSingleton(factory); services.AddSingleton <ITrackingSink>(sink); services.AddSingleton(clock); }); }) .Build()) { // act - request services var chrono = host.Services.GetRequiredService <IChronoscope>(); var scope = chrono.CreateScope(scopeId, scopeName); var tracker = scope.CreateManualTracker(trackingId); // assert - elapsed is zero Assert.Equal(TimeSpan.Zero, tracker.Elapsed); // act - start manual tracking tracker.Start(); // assert - stopwatch was started Mock.Get(watch).Verify(x => x.Start()); Assert.Equal(TimeSpan.Zero, tracker.Elapsed); // act - stop manual tracking tracker.Stop(); // assert - elapsed time is correct Mock.Get(watch).Verify(x => x.Stop()); Assert.Equal(elapsed, tracker.Elapsed); // act - fault tracking var exception = new InvalidCastException(); tracker.Cancel(exception); // assert - elapsed time is correct Assert.Equal(elapsed, tracker.Elapsed); // assert - events were generated Assert.Collection(sink.Events, e => { var x = Assert.IsAssignableFrom <IScopeCreatedEvent>(e); Assert.Equal(scopeId, x.ScopeId); Assert.Equal(scopeName, x.Name); Assert.Null(x.ParentScopeId); Assert.Equal(now, x.Timestamp); }, e => { var x = Assert.IsAssignableFrom <ITrackerCreatedEvent>(e); Assert.Equal(scopeId, x.ScopeId); Assert.Equal(trackingId, x.TrackerId); Assert.Equal(now, x.Timestamp); Assert.Equal(TimeSpan.Zero, x.Elapsed); }, e => { var x = Assert.IsAssignableFrom <ITrackerStartedEvent>(e); Assert.Equal(scopeId, x.ScopeId); Assert.Equal(trackingId, x.TrackerId); Assert.Equal(now, x.Timestamp); Assert.Equal(TimeSpan.Zero, x.Elapsed); }, e => { var x = Assert.IsAssignableFrom <ITrackerStoppedEvent>(e); Assert.Equal(scopeId, x.ScopeId); Assert.Equal(trackingId, x.TrackerId); Assert.Equal(now, x.Timestamp); Assert.Equal(elapsed, x.Elapsed); }, e => { var x = Assert.IsAssignableFrom <ITrackerCancelledEvent>(e); Assert.Equal(scopeId, x.ScopeId); Assert.Equal(trackingId, x.TrackerId); Assert.Equal(now, x.Timestamp); Assert.Equal(elapsed, x.Elapsed); Assert.Same(exception, x.Exception); }); } }
public Visualization(Bin audiobin, Pad teepad) { // The basic pipeline we're constructing is: // .audiotee ! queue ! audioresample ! audioconvert ! fakesink Element converter, resampler; Queue audiosinkqueue; Pad pad; vis_buffer = null; vis_fft = gst_fft_f32_new(SLICE_SIZE * 2, false); vis_fft_buffer = new GstFFTF32Complex [SLICE_SIZE + 1]; vis_fft_sample_buffer = new float [SLICE_SIZE]; // Core elements, if something fails here, it's the end of the world audiosinkqueue = (Queue)ElementFactory.Make("queue", "vis-queue"); pad = audiosinkqueue.GetStaticPad("sink"); pad.AddEventProbe(new PadEventProbeCallback(EventProbe)); resampler = ElementFactory.Make("audioresample", "vis-resample"); converter = ElementFactory.Make("audioconvert", "vis-convert"); FakeSink fakesink = ElementFactory.Make("fakesink", "vis-sink") as FakeSink; // channels * slice size * float size = size of chunks we want wanted_size = (uint)(2 * SLICE_SIZE * sizeof(float)); if (audiosinkqueue == null || resampler == null || converter == null || fakesink == null) { Log.Debug("Could not construct visualization pipeline, a fundamental element could not be created"); return; } // Keep around the 5 most recent seconds of audio so that when resuming // visualization we have something to show right away. audiosinkqueue.Leaky = Queue.LeakyType.Downstream; audiosinkqueue.MaxSizeBuffers = 0; audiosinkqueue.MaxSizeBytes = 0; audiosinkqueue.MaxSizeTime = Clock.Second * 5; fakesink.Handoff += PCMHandoff; // This enables the handoff signal. fakesink.SignalHandoffs = true; // Synchronize so we see vis at the same time as we hear it. fakesink.Sync = true; // Drop buffers if they come in too late. This is mainly used when // thawing the vis pipeline. fakesink.MaxLateness = (long)(Clock.Second / 120); // Deliver buffers one frame early. This allows for rendering // time. (TODO: It would be great to calculate this on-the-fly so // we match the rendering time. fakesink.TsOffset = -(long)(Clock.Second / 60); // Don't go to PAUSED when we freeze the pipeline. fakesink.Async = false; audiobin.Add(audiosinkqueue, resampler, converter, fakesink); pad = audiosinkqueue.GetStaticPad("sink"); teepad.Link(pad); Element.Link(audiosinkqueue, resampler, converter); converter.LinkFiltered(fakesink, caps); vis_buffer = new Adapter(); vis_resampler = resampler; vis_thawing = false; active = false; // Disable the pipeline till we hear otherwise from managed land. Blocked = true; }