static void NewVideoSample(object sender, NewSampleArgs args) { var sink = (Gst.App.AppSink)sender; // Retrieve the buffer var sample = sink.PullSample(); if (sample != null) { Caps caps = sample.Caps; var cap = caps[0]; string format; int width = 0; int height = 0; int fpsNumerator = 0; int fpsDenominator = 1; format = cap.GetString("format"); cap.GetInt("width", out width); cap.GetInt("height", out height); cap.GetFraction("framerate", out fpsNumerator, out fpsDenominator); MapInfo map; if (sample.Buffer.Map(out map, MapFlags.Read)) { // TODO: work with your RGBA frame in map.Data or map DataPtr or use map.CopyTo(IntPtr, long) to copy raw memory sample.Buffer.Unmap(map); } sample.Dispose(); } }
static void NewAudioSample(object sender, NewSampleArgs args) { var sink = (Gst.App.AppSink)sender; // Retrieve the buffer var sample = sink.PullSample(); if (sample != null) { var caps = sample.Caps; var cap = caps[0]; int rate = 0; // audio rate int channels = 0; // number of audio channels cap.GetInt("rate", out rate); cap.GetInt("channels", out channels); MapInfo map; if (sample.Buffer.Map(out map, MapFlags.Read)) { float[] f32leSamples = new float[map.Size / sizeof(float)]; // convert sample's byte array to floats System.Buffer.BlockCopy(map.Data, 0, f32leSamples, 0, f32leSamples.Length * sizeof(float)); sample.Buffer.Unmap(map); // TODO: work with your F32LE sample in f32leSamples } sample.Dispose(); } }
/// <summary> /// The appsink has received a buffer /// </summary> static void NewSample(object o, NewSampleArgs args) { AppSink sink = o as AppSink; // Retrieve the buffer using (var sample = sink.PullSample()) { if (sample == null) { return; } // The only thing we do in this example is print a * to indicate a received buffer Console.Write("* "); sample.Dispose(); } }
private void Videosink_NewSample(object o, NewSampleArgs args) { using (var sample = videosink.PullSample()) PushImage(sample); }