Example #1
0
  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);
  }
Example #2
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);
            }
        }
Example #3
0
  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);
  }
Example #4
0
        private void PCMHandoff (object o, FakeSink.HandoffArgs args)
        {
            Gst.Buffer data;
        
            if (OnDataAvailable == null) {
                return;
            }
        
            if (vis_thawing) {
                // Flush our buffers out.
                vis_buffer.Clear ();
                System.Array.Clear (vis_fft_sample_buffer, 0, vis_fft_sample_buffer.Length);
        
                vis_thawing = false;
            }
        
            Structure structure = args.Buffer.Caps [0];
            int channels = (int)structure.GetValue ("channels");
        
            wanted_size = (uint)(channels * SLICE_SIZE * sizeof (float));

            //TODO see if buffer need a copy or not
            //but copy is no available in gst# ;(
            vis_buffer.Push (args.Buffer);
            int i, j;
            while ((data = vis_buffer.Peek (wanted_size)) != null) {
                float[] buff = new float[data.Size];
                Marshal.Copy (data.Data, buff, 0, (int) data.Size);
                float[] deinterlaced = new float [channels * SLICE_SIZE];
                float[] specbuf = new float [SLICE_SIZE * 2];

                System.Array.Copy (specbuf, vis_fft_sample_buffer, SLICE_SIZE);
                
                for (i = 0; i < SLICE_SIZE; i++) {
                    float avg = 0.0f;
        
                    for (j = 0; j < channels; j++) {
                        float sample = buff[i * channels + j];
        
                        deinterlaced[j * SLICE_SIZE + i] = sample;
                        avg += sample;
                    }
        
                    avg /= channels;
                    specbuf[i + SLICE_SIZE] = avg;
                }
        
                System.Array.Copy (vis_fft_sample_buffer, 0, specbuf, SLICE_SIZE, SLICE_SIZE);
        
                gst_fft_f32_window (vis_fft, specbuf, FFTWindow.Hamming);
                gst_fft_f32_fft (vis_fft, specbuf, vis_fft_buffer);
        
                for (i = 0; i < SLICE_SIZE; i++) {
                    float val;
        
                    GstFFTF32Complex cplx = vis_fft_buffer[i];
        
                    val = cplx.r * cplx.r + cplx.i * cplx.i;
                    val /= SLICE_SIZE * SLICE_SIZE;
                    val = (float)(10.0f * System.Math.Log10 ((double)val));
        
                    val = (val + 60.0f) / 60.0f;
                    if (val < 0.0f)
                        val = 0.0f;
        
                    specbuf[i] = val;
                }
        
                float [] flat = new float[channels * SLICE_SIZE];
                System.Array.Copy (deinterlaced, flat, flat.Length);
        
                float [][] cbd = new float[channels][];
                for (int k = 0; k < channels; k++) {
                    float [] channel = new float[SLICE_SIZE];
                    System.Array.Copy (flat, k * SLICE_SIZE, channel, 0, SLICE_SIZE);
                    cbd [k] = channel;
                }
        
                float [] spec = new float [SLICE_SIZE];
                System.Array.Copy (specbuf, spec, SLICE_SIZE);
        
                try {
                    OnDataAvailable (cbd, new float[][] { spec });
                } catch (System.Exception e) {
                    Log.Exception ("Uncaught exception during visualization data post.", e);
                }
        
                vis_buffer.Flush ((uint)wanted_size);
            }
        }