11
novembre
2012
Gstreamer-sharp : utilisation de l’élément CameraBin
novembre
2012
Un article de Rachel
Pas de commentaires
voici l’implémentation de l’élément camerabin en c#. Il est utile si on ne veut pas configurer soit même la caméra dans son application.
using Gst.GLib;
using Gst.Interfaces;
using Gst;
using System;
using System.Runtime.InteropServices;
namespace Gst.BadPlugins
{
internal class CameraBinFlagsGType
{
//
// Static Properties
//
public static GType GType
{
get
{
return new GType (CameraBinFlagsGType.gst_camerabin_flags_get_type ());
}
}
//
// Static Methods
//
[DllImport ("gstreamer-0.10", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr gst_camerabin_flags_get_type ();
}
[GType(typeof(CameraBinFlagsGType)),Flags]
public enum CameraBinFlags
{
SourceResize = (1 << 0),
SourceColorConversion = (1 << 1),
ViewfinderColorConversion = (1 << 2),
ViewfinderScale = (1 << 3),
AudioConversion = (1 << 4),
DisableAudio = (1 << 5),
ImageColorConversion = (1 << 6),
VideoColorConversion = (1 << 7)
}
public enum CameraBinMode
{
Image=0,
Video
}
public class CameraBin : Gst.Pipeline
{
[DllImport ("gstreamer-0.10")]
private static extern IntPtr gst_camerabin_get_type();
[DllImport ("gstreamer-0.10")]
private static extern IntPtr gst_element_factory_make (IntPtr element, IntPtr name);
public CameraBin (string name)
{
IntPtr intPtr = Marshaller.StringToPtrGStrdup (name);
IntPtr intPtr2 = Marshaller.StringToPtrGStrdup ("camerabin");
this.Raw = CameraBin.gst_element_factory_make (intPtr2, intPtr);
Marshaller.Free (intPtr);
Marshaller.Free (intPtr2);
}
public CameraBin () : this(null)
{
}
public CameraBin (IntPtr raw) : base(raw)
{
}
public CameraBinMode Mode {
get{return (CameraBinMode)base.GetProperty ("mode").Val;}
set{base.SetProperty ("mode",new Gst.GLib.Value(value));}
}
public string Filename {
get{return (string)base.GetProperty ("filename").Val;}
set{base.SetProperty ("filename",new Gst.GLib.Value(value));}
}
public Caps VideoSourceCaps {
get{return (Caps)base.GetProperty ("video-source-caps").Val;}
set{base.SetProperty ("video-source-caps",new Value(value));}
}
public Caps FilterCaps {
get{return (Caps)base.GetProperty ("filter-caps").Val;}
set{base.SetProperty ("filter-caps",new Value(value));}
}
public Caps PreviewCaps {
get{return (Caps)base.GetProperty ("preview-caps").Val;}
set{base.SetProperty ("preview-caps",new Value(value));}
}
public Element VideoSource {
get{return (Element)base.GetProperty ("video-source").Val;}
set{base.SetProperty ("video-source",new Value(value));}
}
public Element AudioSource {
get{return (Element)base.GetProperty ("audio-source").Val;}
set{base.SetProperty ("audio-source",new Value(value));}
}
public Element ViewfinderSink {
get{return (Element)base.GetProperty ("viewfinder-sink").Val;}
set{base.SetProperty ("viewfinder-sink",new Value(value));}
}
public Element ViewfinderFilter {
get{return (Element)base.GetProperty ("viewfinder-filter").Val;}
set{base.SetProperty ("viewfinder-filter",new Value(value));}
}
public Element VideoSourceFilter {
get{return (Element)base.GetProperty ("video-source-filter").Val;}
set{base.SetProperty ("video-source-filter",new Value(value));}
}
public Element PreviewSourceFilter {
get{return (Element)base.GetProperty ("preview-source-filter").Val;}
set{base.SetProperty ("preview-source-filter",new Value(value));}
}
public Element ImageEncoder {
get{return (Element)base.GetProperty ("image-encoder").Val;}
set{base.SetProperty ("image-encoder",new Value(value));}
}
public Element VideoEncoder {
get{return (Element)base.GetProperty ("video-encoder").Val;}
set{base.SetProperty ("video-encoder",new Value(value));}
}
public Element AudioEncoder {
get{return (Element)base.GetProperty ("audio-encoder").Val;}
set{base.SetProperty ("audio-encoder",new Value(value));}
}
public bool BlockAfterCapture {
get{return (bool)base.GetProperty ("block-after-capture").Val;}
set{base.SetProperty ("block-after-capture",new Value(value));}
}
public bool MessageForward {
get{return (bool)base.GetProperty ("message-forward").Val;}
set{base.SetProperty ("message-forward",new Value(value));}
}
public bool Mute {
get{return (bool)base.GetProperty ("mute").Val;}
set{base.SetProperty ("mute",new Value(value));}
}
public float Zoom {
get{return (float)base.GetProperty ("zoom").Val;}
set{base.SetProperty ("zoom",new Value(value));}
}
public Element VideoMuxer {
get{return (Element)base.GetProperty ("video-muxer").Val;}
set{base.SetProperty ("video-muxer",new Value(value));}
}
public Element ImageFormatter {
get{return (Element)base.GetProperty ("image-formatter").Val;}
set{base.SetProperty ("image-formatter",new Value(value));}
}
public Element ImagePostProcessing {
get{return (Element)base.GetProperty ("image-post-processing").Val;}
set{base.SetProperty ("image-post-processing",new Value(value));}
}
public Element VideoPostProcessing {
get{return (Element)base.GetProperty ("video-post-processing").Val;}
set{base.SetProperty ("video-post-processing",new Value(value));}
}
public int ImageCaptureHeight {
get{return (int)base.GetProperty ("image-capture-height").Val;}
set{base.SetProperty ("image-capture-height",new Value(value));}
}
public int ImageCaptureWidth {
get{return (int)base.GetProperty ("image-capture-width").Val;}
set{base.SetProperty ("image-capture-width",new Value(value));}
}
public int VideoCaptureHeight {
get{return (int)base.GetProperty ("video-capture-height").Val;}
set{base.SetProperty ("video-capture-height",new Value(value));}
}
public int VideoCaptureWidth {
get{return (int)base.GetProperty ("video-capture-width").Val;}
set{base.SetProperty ("video-capture-width",new Value(value));}
}
public Fraction VideoCaptureFramerate {
get{return (Fraction)base.GetProperty ("video-capture-framerate").Val;}
set{base.SetProperty ("video-capture-height",new Value(value));}
}
public bool Idle {
get{return (bool)base.GetProperty ("idle").Val;}
set{base.SetProperty ("idle",new Value(value));}
}
public bool ReadyForCapture {
get{return (bool)base.GetProperty ("ready-for-capture").Val;}
set{base.SetProperty ("ready-for-capture",new Value(value));}
}
public void StartCapture(){this.Emit ("capture-start");}
public void StopCapture(){this.Emit ("capture-stop");}
public void PauseCapture(){this.Emit ("capture-pause");}
public void SetVideoResolution(int width, int height,int fps_n, int fps_d){
this.Emit ("set-image-resolution",width,height,fps_n,fps_d);
}
public bool Done(string filename){
return (bool)this.Emit ("img-done",filename);
}
}
}
using Gst.Interfaces;
using Gst;
using System;
using System.Runtime.InteropServices;
namespace Gst.BadPlugins
{
internal class CameraBinFlagsGType
{
//
// Static Properties
//
public static GType GType
{
get
{
return new GType (CameraBinFlagsGType.gst_camerabin_flags_get_type ());
}
}
//
// Static Methods
//
[DllImport ("gstreamer-0.10", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr gst_camerabin_flags_get_type ();
}
[GType(typeof(CameraBinFlagsGType)),Flags]
public enum CameraBinFlags
{
SourceResize = (1 << 0),
SourceColorConversion = (1 << 1),
ViewfinderColorConversion = (1 << 2),
ViewfinderScale = (1 << 3),
AudioConversion = (1 << 4),
DisableAudio = (1 << 5),
ImageColorConversion = (1 << 6),
VideoColorConversion = (1 << 7)
}
public enum CameraBinMode
{
Image=0,
Video
}
public class CameraBin : Gst.Pipeline
{
[DllImport ("gstreamer-0.10")]
private static extern IntPtr gst_camerabin_get_type();
[DllImport ("gstreamer-0.10")]
private static extern IntPtr gst_element_factory_make (IntPtr element, IntPtr name);
public CameraBin (string name)
{
IntPtr intPtr = Marshaller.StringToPtrGStrdup (name);
IntPtr intPtr2 = Marshaller.StringToPtrGStrdup ("camerabin");
this.Raw = CameraBin.gst_element_factory_make (intPtr2, intPtr);
Marshaller.Free (intPtr);
Marshaller.Free (intPtr2);
}
public CameraBin () : this(null)
{
}
public CameraBin (IntPtr raw) : base(raw)
{
}
public CameraBinMode Mode {
get{return (CameraBinMode)base.GetProperty ("mode").Val;}
set{base.SetProperty ("mode",new Gst.GLib.Value(value));}
}
public string Filename {
get{return (string)base.GetProperty ("filename").Val;}
set{base.SetProperty ("filename",new Gst.GLib.Value(value));}
}
public Caps VideoSourceCaps {
get{return (Caps)base.GetProperty ("video-source-caps").Val;}
set{base.SetProperty ("video-source-caps",new Value(value));}
}
public Caps FilterCaps {
get{return (Caps)base.GetProperty ("filter-caps").Val;}
set{base.SetProperty ("filter-caps",new Value(value));}
}
public Caps PreviewCaps {
get{return (Caps)base.GetProperty ("preview-caps").Val;}
set{base.SetProperty ("preview-caps",new Value(value));}
}
public Element VideoSource {
get{return (Element)base.GetProperty ("video-source").Val;}
set{base.SetProperty ("video-source",new Value(value));}
}
public Element AudioSource {
get{return (Element)base.GetProperty ("audio-source").Val;}
set{base.SetProperty ("audio-source",new Value(value));}
}
public Element ViewfinderSink {
get{return (Element)base.GetProperty ("viewfinder-sink").Val;}
set{base.SetProperty ("viewfinder-sink",new Value(value));}
}
public Element ViewfinderFilter {
get{return (Element)base.GetProperty ("viewfinder-filter").Val;}
set{base.SetProperty ("viewfinder-filter",new Value(value));}
}
public Element VideoSourceFilter {
get{return (Element)base.GetProperty ("video-source-filter").Val;}
set{base.SetProperty ("video-source-filter",new Value(value));}
}
public Element PreviewSourceFilter {
get{return (Element)base.GetProperty ("preview-source-filter").Val;}
set{base.SetProperty ("preview-source-filter",new Value(value));}
}
public Element ImageEncoder {
get{return (Element)base.GetProperty ("image-encoder").Val;}
set{base.SetProperty ("image-encoder",new Value(value));}
}
public Element VideoEncoder {
get{return (Element)base.GetProperty ("video-encoder").Val;}
set{base.SetProperty ("video-encoder",new Value(value));}
}
public Element AudioEncoder {
get{return (Element)base.GetProperty ("audio-encoder").Val;}
set{base.SetProperty ("audio-encoder",new Value(value));}
}
public bool BlockAfterCapture {
get{return (bool)base.GetProperty ("block-after-capture").Val;}
set{base.SetProperty ("block-after-capture",new Value(value));}
}
public bool MessageForward {
get{return (bool)base.GetProperty ("message-forward").Val;}
set{base.SetProperty ("message-forward",new Value(value));}
}
public bool Mute {
get{return (bool)base.GetProperty ("mute").Val;}
set{base.SetProperty ("mute",new Value(value));}
}
public float Zoom {
get{return (float)base.GetProperty ("zoom").Val;}
set{base.SetProperty ("zoom",new Value(value));}
}
public Element VideoMuxer {
get{return (Element)base.GetProperty ("video-muxer").Val;}
set{base.SetProperty ("video-muxer",new Value(value));}
}
public Element ImageFormatter {
get{return (Element)base.GetProperty ("image-formatter").Val;}
set{base.SetProperty ("image-formatter",new Value(value));}
}
public Element ImagePostProcessing {
get{return (Element)base.GetProperty ("image-post-processing").Val;}
set{base.SetProperty ("image-post-processing",new Value(value));}
}
public Element VideoPostProcessing {
get{return (Element)base.GetProperty ("video-post-processing").Val;}
set{base.SetProperty ("video-post-processing",new Value(value));}
}
public int ImageCaptureHeight {
get{return (int)base.GetProperty ("image-capture-height").Val;}
set{base.SetProperty ("image-capture-height",new Value(value));}
}
public int ImageCaptureWidth {
get{return (int)base.GetProperty ("image-capture-width").Val;}
set{base.SetProperty ("image-capture-width",new Value(value));}
}
public int VideoCaptureHeight {
get{return (int)base.GetProperty ("video-capture-height").Val;}
set{base.SetProperty ("video-capture-height",new Value(value));}
}
public int VideoCaptureWidth {
get{return (int)base.GetProperty ("video-capture-width").Val;}
set{base.SetProperty ("video-capture-width",new Value(value));}
}
public Fraction VideoCaptureFramerate {
get{return (Fraction)base.GetProperty ("video-capture-framerate").Val;}
set{base.SetProperty ("video-capture-height",new Value(value));}
}
public bool Idle {
get{return (bool)base.GetProperty ("idle").Val;}
set{base.SetProperty ("idle",new Value(value));}
}
public bool ReadyForCapture {
get{return (bool)base.GetProperty ("ready-for-capture").Val;}
set{base.SetProperty ("ready-for-capture",new Value(value));}
}
public void StartCapture(){this.Emit ("capture-start");}
public void StopCapture(){this.Emit ("capture-stop");}
public void PauseCapture(){this.Emit ("capture-pause");}
public void SetVideoResolution(int width, int height,int fps_n, int fps_d){
this.Emit ("set-image-resolution",width,height,fps_n,fps_d);
}
public bool Done(string filename){
return (bool)this.Emit ("img-done",filename);
}
}
}
Il sélectionnera l'entrée vidéo par défaut (généralement /dev/video0). L'attribut filename est le nom qui désigne un fichier de sortie éventuel, si vous voulez capturer la vidéo ou une image.