Inheritance: Gst.Bin
        private void StartPipeline()
        {
            pipeline = new Pipeline ();

            Element src = ElementFactory.Make ("filesrc", "source"),
            decoder = ElementFactory.Make ("decodebin", "decoder"),
            chroma_print = ElementFactory.Make ("chromaprint", "processor"),
            sink = ElementFactory.Make ("fakesink", "sink");

            pipeline.Bus.AddSignalWatch();
            pipeline.Bus.Message += MsgHandler;

            if (src == null || decoder == null || chroma_print == null || sink == null) {
                Console.WriteLine ("cannot find necessary gstreamer element (filesrc, decodebin, chromaprint or fakesink)!");
                pipeline = null;
                return;
            }

            sink ["sync"] = 0;
            src ["location"] = filename;

            pipeline.Add (src);
            pipeline.Add (decoder);
            pipeline.Add (chroma_print);
            pipeline.Add (sink);

            src.Link (decoder);
            chroma_print.Link (sink);

            decoder.PadAdded += (o, args) => {
                args.NewPad.Link (chroma_print.GetStaticPad ("sink"));
            };

            pipeline.SetState (State.Playing);
        }
Exemplo n.º 2
0
        bool ConstructPipeline()
        {
            Element queue;

            pipeline = new Gst.Pipeline("pipeline");
            if (pipeline == null)
            {
                RaiseError(current_track, Catalog.GetString("Could not create pipeline"));
                return(false);
            }

            cddasrc = ElementFactory.MakeFromUri(URIType.Src, "cdda://1", "cddasrc");
            if (cddasrc == null)
            {
                RaiseError(current_track, Catalog.GetString("Could not initialize element from cdda URI"));
                return(false);
            }

            cddasrc ["device"] = device;

            if (cddasrc.HasProperty("paranoia-mode"))
            {
                cddasrc ["paranoia-mode"] = paranoia_mode;
            }

            try {
                encoder = (Bin)Parse.BinFromDescription(encoder_pipeline, true);
            } catch (Exception e) {
                string err = Catalog.GetString("Could not create encoder pipeline : {0}");
                RaiseError(current_track, String.Format(err, e.Message));
                return(false);
            }

            queue = ElementFactory.Make("queue", "queue");
            if (queue == null)
            {
                RaiseError(current_track, Catalog.GetString("Could not create queue plugin"));
                return(false);
            }

            queue ["max-size-time"] = 120 * Gst.Clock.Second;

            filesink = ElementFactory.Make("filesink", "filesink");
            if (filesink == null)
            {
                RaiseError(current_track, Catalog.GetString("Could not create filesink plugin"));
                return(false);
            }

            pipeline.Add(cddasrc, queue, encoder, filesink);

            if (!Element.Link(cddasrc, queue, encoder, filesink))
            {
                RaiseError(current_track, Catalog.GetString("Could not link pipeline elements"));
            }

            pipeline.Bus.AddWatch(OnBusMessage);

            return(true);
        }
Exemplo n.º 3
0
        private bool OnBusMessage(Bus bus, Message msg)
        {
            switch (msg.Type)
            {
            case MessageType.Eos:
                pipeline.SetState(State.Null);
                pipeline       = null;
                is_transcoding = false;
                timer.Stop();
                RaiseTrackFinished(current_track, output_uri);
                break;

            case MessageType.Error:
                Enum   error_type;
                string err_msg, debug;
                is_transcoding = false;
                timer.Stop();
                msg.ParseError(out error_type, out err_msg, out debug);
                RaiseError(current_track, String.Format("{0} : {1}", err_msg, debug));
                timer.Stop();
                break;

            default:
                break;
            }

            return(true);
        }
Exemplo n.º 4
0
        public void TestPipelineDispose()
        {
            Gst.Pipeline pipeline = new Gst.Pipeline();
            var          src      = Gst.ElementFactory.Make("videotestsrc");

            src["num-buffers"] = 10;

            var vsink = ElementFactory.Make("fakesink");

            pipeline.Add(src, vsink);
            src.Link(vsink);

            var srcWeakRef      = new WeakReference(src);
            var vsinkWeakRef    = new WeakReference(vsink);
            var pipelineWeakRef = new WeakReference(pipeline);
            var busWeakRef      = new WeakReference(pipeline.Bus);

            pipeline.SetState(State.Playing);
            bool terminated = false;

            do
            {
                using (Message msg = pipeline.Bus.PopFiltered(MessageType.StateChanged))
                {
                    if (msg == null || msg.Src != pipeline)
                    {
                        continue;
                    }

                    msg.ParseStateChanged(out State oldstate, out State newstate, out State pendingstate);

                    if (newstate == State.Playing)
                    {
                        terminated = true;
                    }
                }
            } while (!terminated);

            pipeline.SetState(State.Null);

            pipeline.Dispose();
            pipeline = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            Assert.IsFalse(srcWeakRef.IsAlive);
            Assert.IsFalse(vsinkWeakRef.IsAlive);
            Assert.IsFalse(busWeakRef.IsAlive);
            Assert.IsFalse(pipelineWeakRef.IsAlive);
        }
Exemplo n.º 5
0
        public void Cancel()
        {
            timer.Stop();
            is_transcoding = false;

            if (pipeline != null)
            {
                pipeline.SetState(State.Null);
                pipeline = null;
            }

            output_uri = null;
        }
Exemplo n.º 6
0
        private void InitGStreamerPipeline()
        {
            //#region BuildPipeline
            switch (mCfgVideosinkType)
            {
            case videosinktype.glimagesink:
                mGlImageSink = (Gst.Video.VideoSink)Gst.ElementFactory.Make("glimagesink", "glimagesink");
                break;

            case videosinktype.d3dvideosink:
                mGlImageSink = (Gst.Video.VideoSink)Gst.ElementFactory.Make("d3dvideosink", "d3dvideosink");
                //mGlImageSink = (Gst.Video.VideoSink)Gst.ElementFactory.Make("dshowvideosink", "dshowvideosink");
                break;

            case videosinktype.dshowvideosink:
                mGlImageSink = (Gst.Video.VideoSink)Gst.ElementFactory.Make("dshowvideosink", "dshowvideosink");
                break;

            case videosinktype.directdrawsink:
                mGlImageSink = (Gst.Video.VideoSink)Gst.ElementFactory.Make("directdrawsink", "directdrawsink");
                break;

            default:
                break;
            }

            Gst.Element pipeline;
            //string command = "videotestsrc pattern=ball ! queue ! x264enc ! rtph264pay ! queue ! decodebin ! autovideosink";
            //string command = "rtspsrc location = rtsp://140.130.20.168:8554/RTSP0001 latency=0 ! application/x-rtp,encoding-name=H264,payload=96 ! rtph264depay ! decodebin ! autovideosink";
            string command = "rtspsrc location = rtsp://140.130.20.168:8554/RTSP0001 latency=0 ! application/x-rtp,encoding-name=H264,payload=96 ! rtph264depay ! decodebin ! autovideosink";

            pipeline = Gst.Parse.Launch(command);

            mCurrentPipeline = new Gst.Pipeline("pipeline");
            mCurrentPipeline.Add(pipeline);


            //subscribe to bus & bussync msgs

            SubscribeBusMessage();
            SubscribeBusSyncMessage();

            //play the stream
            var setStateRet = mCurrentPipeline.SetState(State.Null);

            System.Diagnostics.Debug.WriteLine("SetStateNULL returned: " + setStateRet.ToString());
            setStateRet = mCurrentPipeline.SetState(State.Ready);
            System.Diagnostics.Debug.WriteLine("SetStateReady returned: " + setStateRet.ToString());
            setStateRet = mCurrentPipeline.SetState(Gst.State.Playing);
        }
Exemplo n.º 7
0
 public GStreamerPlayer()
 {
     Application.Init();
     loop = new MainLoop();
     pipeline = new Pipeline("audio-player");
     try {
         bin = (Bin)Parse.Launch("filesrc name=my_filesrc ! progressreport update-freq=1 ! flump3dec ! alsasink");
     } catch {
         bin = (Bin)Parse.Launch("filesrc name=my_filesrc ! progressreport update-freq=1 ! mad ! autoaudiosink");
     }
     if (bin == null)
         throw new Exception("Parse error.");
     filesrc = bin.GetByName("my_filesrc") as FileSrc;
     bin.Bus.AddWatch(new BusFunc(BusCb));
 }
Exemplo n.º 8
0
        public void Finish()
        {
            timer.Stop();

            if (pipeline != null)
            {
                pipeline.SetState(State.Null);
                pipeline = null;
            }

            if (output_uri != null)
            {
                output_uri = null;
            }
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
	public static void StopRecording()
	{
		if (gstRecording != null)
		{
			gstRecording.SetState(Gst.State.Null);

			Gst.State s;
			gstRecording.GetState(out s, timeout);

			gstRecording.Dispose();
			gstRecording = null;
		}


		isRecording = false;

	}
Exemplo n.º 11
0
        public PlayerEngine ()
        {
            Console.WriteLine ("Gst# PlayerEngine ctor - completely experimental, still a WIP");
            Gst.Application.Init ();
            pipeline = new Pipeline ();
            playbin = new PlayBin2 ();
            pipeline.Add (playbin);

            pipeline.Bus.AddWatch (OnBusMessage);

            Banshee.ServiceStack.Application.RunTimeout (200, delegate {
                OnEventChanged (PlayerEvent.Iterate);
                return true;
            });

            OnStateChanged (PlayerState.Ready);
        }
Exemplo n.º 12
0
        public BpmDetector()
        {
            try {
                pipeline = new Pipeline ("the pipeline");
                filesrc          = ElementFactory.Make ("filesrc", "the filesrc");
                var decodebin    = ElementFactory.Make ("decodebin", "the decodebin");
                var audioconvert = Make ("audioconvert");
                var bpmdetect    = Make ("bpmdetect");
                fakesink         = ElementFactory.Make ("fakesink", "the 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.PadAdded += (o,args) => {
                    var audiopad = audioconvert.GetStaticPad ("sink");
                    if (audiopad.IsLinked) {
                        return;
                    }

                    var caps = args.NewPad.QueryCaps ();
                    if (caps == null)
                        return;

                    var str = caps[0];
                    if (!str.Name.Contains ("audio"))
                        return;

                    args.NewPad.Link (audiopad);
                };

                if (!Element.Link (audioconvert, bpmdetect, fakesink)) {
                    Log.Error ("Could not link pipeline elements");
                    throw new Exception ();
                }
                pipeline.Bus.AddWatch (OnBusMessage);
            } catch (Exception e) {
                Log.Exception (e);
                throw new ApplicationException (Catalog.GetString ("Could not create BPM detection driver."), e);
            }
        }
Exemplo n.º 13
0
        private bool ConstructPipeline(string encoder_pipeline)
        {
            Element source_elem;
            Element decoder_elem;

            pipeline = new Gst.Pipeline("pipeline");

            source_elem = ElementFactory.MakeFromUri(URIType.Src, current_track.Uri.AbsoluteUri, "source");
            if (source_elem == null)
            {
                RaiseError(current_track, Catalog.GetString("Could not create source element"));
                return(false);
            }

            decoder_elem = ElementFactory.Make("decodebin2", "decodebin2");
            if (decoder_elem == null)
            {
                RaiseError(current_track, Catalog.GetString("Could not create decodebin2 plugin"));
                return(false);
            }

            try {
                sink_bin = new AudioSinkBin("sinkbin", encoder_pipeline, output_uri.AbsoluteUri);
            } catch (Exception e) {
                RaiseError(current_track, e.Message);
            }

            if (sink_bin == null)
            {
                RaiseError(current_track, Catalog.GetString("Could not create sinkbin plugin"));
                return(false);
            }

            pipeline.Add(source_elem, decoder_elem, sink_bin);

            source_elem.Link(decoder_elem);

            decoder_elem.PadAdded += OnPadAdded;

            pipeline.Bus.AddWatch(OnBusMessage);

            return(true);
        }
Exemplo n.º 14
0
        public void Finish()
        {
            if (output_path != null)
            {
                Banshee.IO.File.Delete(new SafeUri(output_path));
            }

            TrackReset();

            encoder_pipeline = null;
            output_extension = null;

            if (timer != null)
            {
                timer.Stop();
            }

            if (pipeline != null && pipeline is Element)
            {
                pipeline.SetState(State.Null);
                pipeline = null;
            }
        }
 public PlayerEngine ()
 {
     Console.WriteLine ("Gst# PlayerEngine ctor - completely experimental, still a WIP");
     Gst.Application.Init ();
     
     //Making early-bound elements
     pipeline = new Pipeline ();
     playbin = new PlayBin2 ();
     audiobin = new MyBinType ("audiobin");
     filterbin = new BinList<Element> ("filterbin");
     
     //Making late-bound elements (not currently bound by gst-sharp)
     audiosink = ElementFactory.Make ("gconfaudiosink", "thesink");
     if (audiosink == null)
         audiosink = ElementFactory.Make ("autoaudiosink", "thesink");
     queue = ElementFactory.Make ("queue", "audioqueue");
     
     //Adding, linking, and padding
     filterbin.Add (queue);
     audiobin.Add (filterbin.GetBin (), audiosink);
     filterbin.GetSourceGhostPad ().Link (audiosink.GetStaticPad ("sink"));
     audiobinsink.SetTarget (filterbin.GetSinkGhostPad ());
     audiobin.AddPadHack (audiobinsink);
     
     playbin.AudioSink = audiobin;
     pipeline.Add (playbin);
     
     pipeline.Bus.AddWatch (OnBusMessage);
     
     Banshee.ServiceStack.Application.RunTimeout (200, delegate {
         OnEventChanged (PlayerEvent.Iterate);
         return true;
     });
     
     OnStateChanged (PlayerState.Ready);
 }
Exemplo n.º 16
0
        public PlayerEngine ()
        {
            Log.InformationFormat ("GStreamer# {0} Initializing; {1}.{2}",
                typeof (Gst.Version).Assembly.GetName ().Version, Gst.Version.Description, Gst.Version.Nano);

            // Setup the gst plugins/registry paths if running Windows
            if (PlatformDetection.IsWindows) {
                var gst_paths = new string [] { Hyena.Paths.Combine (Hyena.Paths.InstalledApplicationPrefix, "gst-plugins") };
                Environment.SetEnvironmentVariable ("GST_PLUGIN_PATH", String.Join (";", gst_paths));
                Environment.SetEnvironmentVariable ("GST_PLUGIN_SYSTEM_PATH", "");
                Environment.SetEnvironmentVariable ("GST_DEBUG", "1");

                string registry = Hyena.Paths.Combine (Hyena.Paths.ApplicationData, "registry.bin");
                if (!System.IO.File.Exists (registry)) {
                    System.IO.File.Create (registry).Close ();
                }

                Environment.SetEnvironmentVariable ("GST_REGISTRY", registry);

                //System.Environment.SetEnvironmentVariable ("GST_REGISTRY_FORK", "no");
                Log.DebugFormat ("GST_PLUGIN_PATH = {0}", Environment.GetEnvironmentVariable ("GST_PLUGIN_PATH"));
            }

            Gst.Application.Init ();
            pipeline = new Pipeline ();
            playbin = new PlayBin2 ();
            pipeline.Add (playbin);

            // Remember the volume from last time
            Volume = (ushort)PlayerEngineService.VolumeSchema.Get ();

            playbin.AddNotification ("volume", OnVolumeChanged);
            pipeline.Bus.AddWatch (OnBusMessage);

            OnStateChanged (PlayerState.Ready);
        }
Exemplo n.º 17
0
        public void Cancel ()
        {
            timer.Stop ();
            is_transcoding = false;
    
            if(pipeline != null) {
                pipeline.SetState (State.Null);
                pipeline = null;
            }

            output_uri = null;
        }
Exemplo n.º 18
0
        public void Finish ()
        {
            timer.Stop ();

            if(pipeline != null) {
                pipeline.SetState (State.Null);
                pipeline = null;
            }

            if(output_uri != null) {
                output_uri = null;
            }
        }
Exemplo n.º 19
0
        static void Main(string[] args)
        {
            Application.Init(ref args);

            Element src = ElementFactory.Make("audiotestsrc");
            Element convert = ElementFactory.Make("audioconvert");
            Element volume = new ExampleVolume();
            Element sink = ElementFactory.Make("autoaudiosink");

            Pipeline pipeline = new Pipeline();
            pipeline.Add(src, convert, volume, sink);
            Element.Link(src, convert, volume, sink);

            pipeline.SetState(State.Playing);

            MainLoop loop = new MainLoop();
            loop.Run();

            pipeline.SetState(State.Null);

            Console.ReadLine();
        }
Exemplo n.º 20
0
        //udpsrc port=9000  buffer-size=60000 ! application/x-rtp,encoding-name=H264,payload=96 ! rtph264depay ! h264parse ! queue ! avdec_h264

        public MainForm()
        {
            // These environment variables are necessary to locate GStreamer libraries, and to stop it from loading

            // wrong libraries installed elsewhere on the system.

            string apppath = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);

            System.Environment.SetEnvironmentVariable("GST_PLUGIN_PATH", "");

            System.Environment.SetEnvironmentVariable("GST_PLUGIN_SYSTEM_PATH", apppath + @"\gstreamer\bin\plugins");

            System.Environment.SetEnvironmentVariable("PATH", @"C:\Windows;"

                                                        + apppath + @"\gstreamer\lib;"

                                                        + apppath + @"\gstreamer\bin");

            System.Environment.SetEnvironmentVariable("GST_REGISTRY", apppath + @"\gstreamer\bin\registry.bin");



            // These are for saving debug information.

            System.Environment.SetEnvironmentVariable("GST_DEBUG", "*:3");

            System.Environment.SetEnvironmentVariable("GST_DEBUG_FILE", "GstreamerLog.txt");

            System.Environment.SetEnvironmentVariable("GST_DEBUG_DUMP_DOT_DIR", apppath);











            // Initialize Gstreamer
            Gst.Application.Init();

            // Build the pipeline
            var source = ElementFactory.Make("videotestsrc", "source");
            var sink = ElementFactory.Make("autovideosink", "sink");

            // Create the empty pipeline
            var pipeline = new Pipeline("test-pipeline");

            if (pipeline == null || source == null || sink == null)
            {
                Console.WriteLine("Not all elements could be created");
                return;
            }

            // Build the pipeline
            pipeline.Add(source, sink);
            if (!source.Link(sink))
            {
                Console.WriteLine("Elements could not be linked");
                return;
            }

            // Modify the source's properties
            source["pattern"] = 0;

            // Start playing
            var ret = pipeline.SetState(State.Playing);
            if (ret == StateChangeReturn.Failure)
            {
                Console.WriteLine("Unable to set the pipeline to the playing state");
                return;
            }

            // Wait until error or EOS
            var bus = pipeline.Bus;
            //var msg = bus.TimedPopFiltered(Constants.CLOCK_TIME_NONE, MessageType.Eos | MessageType.Error);

            // Free resources
          /*  if (msg != null)
            {
                switch (msg.Type)
                {
                    case MessageType.Error:
                        GLib.GException exc;
                        string debug;
                        msg.ParseError(out exc, out debug);
                        Console.WriteLine(String.Format("Error received from element {0}: {1}", msg.Src.Name, exc.Message));
                        Console.WriteLine(String.Format("Debugging information {0}", debug));
                        break;
                    case MessageType.Eos:
                        Console.WriteLine("End-Of-Stream reached");
                        break;
                    default:
                        // We should not reach here because we only asked for ERRORs and EOS
                        Console.WriteLine("Unexpected messag received");
                        break;
                }
            }*/

            pipeline.SetState(State.Null);

          //  return;


          

            Gst.Application.Init(); 



            InitializeComponent();



            // Create a main loop for GLib, run it in a separate thread

            m_GLibMainLoop = new Gst.GLib.MainLoop();

            m_GLibThread = new System.Threading.Thread(m_GLibMainLoop.Run);

            m_GLibThread.IsBackground = true;

            m_GLibThread.Name = "GLibMainLoop";

            m_GLibThread.Start();



           // System.Threading.Thread.CurrentThread.Name = "WinForms";



            CreatePipeline();

        }
Exemplo n.º 21
0
	public void StartRecordingUnix()
	{
		if (txtFolderOut.Text != String.Empty && Directory.Exists(txtFolderOut.Text.Trim()))
		{
			GstCapture.cameraDevice cDev = cameras[cbxCamera.ActiveText];
			//String sDev = "yes";
			String aDev = cbxMic.ActiveText;
			String _path = txtFolderOut.Text.Trim();

			DateTime dt = DateTime.Now;

			//Encoding w = Encoding.GetEncoding("windows-1251"); // HACK

			String aargs = null,
			cargs = null,
			sargs = null;


			if ((aDev != null) && ckbxMic.Active)
			{


				//aargs = String.Format(" dshowaudiosrc device-name=\"{0}\"", w.GetString(Encoding.UTF8.GetBytes(aDev)));
				aargs = String.Format(" pulsesrc");
				//aargs += " ! audio/x-raw-int, rate = 44100, channels = 1, depth = 16 ! queue ! faac ! tee name = audio";
				aargs += " ! audio/x-raw-int, rate = 44100, channels = 1, depth = 16 ! queue ! ffenc_adpcm_swf ! tee name = audio";

			}

			dir = String.Format("{0:yyyy-MM-dd_HH-mm-ss}", dt);
			path = Directory.CreateDirectory(
				System.IO.Path.Combine(_path, dir)
				).FullName;

			Directory.SetCurrentDirectory(path);
			Environment.SetEnvironmentVariable("GST_DEBUG", "3");

			if (cDev != null && ckbxCamera.Active)
			{
				int gop = 450;

				cargs = " flvmux name=camera ! filesink location=\"camera.flv\"";

				cargs += String.Format(" v4l2src device =\"{0}\"", cDev.device.ToString());
				cargs += String.Format(" ! video/x-raw-yuv, framerate = {0}/{1}, width={2}, height={3}" +
				                       " ! videorate ! video/x-raw-yuv, framerate = {4}/1" +
				                       " ! queue ! ffenc_flv name = cv gop-size = {5} ! camera.",
				                       cDev.framerate.Numerator, cDev.framerate.Denominator, cDev.width, cDev.height,
				                       30, gop);
				if (aargs != null)
				{
					//cargs += " audio. ! queue ! audio/mpeg ! camera.";
					cargs += " audio. ! queue ! audio/x-adpcm ! camera.";
				}

			}

			if (ckbxDisplay.Active)//sDev != null)
			{
				int gop = 150;
				sargs = " flvmux name=\"screen\" ! filesink location=\"screen.flv\"";

				sargs += " ximagesrc use-damage=false";
				sargs += String.Format(" ! video/x-raw-rgb, framerate = {0}/1" +
				                       " ! ffmpegcolorspace ! queue " +
				                       " ! ffenc_flashsv name=sv gop-size = {1} ! screen.",
				                       5, gop);


				if (aargs != null)
				{
					// sargs += " audio. ! queue ! audio/mpeg ! screen.";
					sargs += " audio. ! queue ! audio/x-adpcm ! screen.";
				}

			}

			try
			{
				String final =  cargs + sargs + aargs;
				gstRecording = (Gst.Pipeline)Gst.Parse.Launch(final);

				lblStatus.Text = "Recording";

			}
			catch (Exception error)
			{
				GstCapture.MessageBox.Show(String.Format("{0}: {1}", error.Message, cargs + sargs + aargs));
			}

			if (gstRecording != null)
			{
				gstRecording.SetState(Gst.State.Playing);

				Gst.State s;
				gstRecording.GetState(out s, timeout);

				isRecording = true;

			}

			Directory.SetCurrentDirectory(_path);
		}
	}
Exemplo n.º 22
0
		private void SetupRecordingPipeline ()
		{
			// set up pipeline and elements
			// gst-launch-0.10 autoaudiosrc ! audioconvert ! vorbisenc ! oggmux ! filesink location=dump.ogg
			// Create new pipeline.

			_pipeline = new Gst.Pipeline ();

			//Pipeline pipeline = new Pipeline("pipeline");

			// Construct pipeline filesrc -> avidemux -> mpeg4 -> directdrawsink

			//_eleAudioSource = ElementFactory.Make("autoaudiosrc", "autoaudiosrc");
			_eleAudioSource = ElementFactory.Make ("pulsesrc");
			_eleAudioConvert = ElementFactory.Make ("audioconvert");
			if (_recordOgg) {
				_eleVorbisEnc = ElementFactory.Make ("vorbisenc");
				_eleOggMux = ElementFactory.Make ("oggmux");
			} else {
				_eleWavPack = ElementFactory.Make ("wavpackenc");
			}
			_eleFileSink = new Gst.CorePlugins.FileSink ();
			//_eleFileSink = ElementFactory.Make("filesink", "filesink");
			_eleFileSink ["location"] = _path;

			// Add and link pipeline.
			if (_recordOgg) {
				_pipeline.Add (_eleAudioSource, _eleAudioConvert, _eleVorbisEnc, _eleOggMux, _eleFileSink);
			} else {
				_pipeline.Add (_eleAudioSource, _eleAudioConvert, _eleWavPack, _eleFileSink);
			}

			// Play video.
			_pipeline.SetState (Gst.State.Ready);
			_pipeline.SetState (Gst.State.Paused);

			if (!_eleAudioSource.Link (_eleAudioConvert)) {
				Console.WriteLine ("link failed between source and converter");
			}
			if (_recordOgg) {
				if (!_eleAudioConvert.Link (_eleVorbisEnc)) {
					Console.WriteLine ("link failed between converter and encoder");
				}

				if (!_eleVorbisEnc.Link (_eleOggMux)) {
					Console.WriteLine ("link failed between e and parser");
				}

				if (!_eleOggMux.Link (_eleFileSink)) {
					Console.Error.WriteLine ("link failed between parser and sink");
				}
			} else {

				if (!_eleAudioConvert.Link (_eleWavPack)) {
					Console.WriteLine ("link failed between converter and encoder");
				}

				if (!_eleWavPack.Link (_eleFileSink)) {
					Console.Error.WriteLine ("link failed between encoder and sink");
				}
			}

			_recordInit = true;
		}
Exemplo n.º 23
0
        bool ConstructPipeline()
        {
            Element queue;

            pipeline = new Gst.Pipeline ("pipeline");
            if (pipeline == null) {
                RaiseError (current_track, Catalog.GetString ("Could not create pipeline"));
                return false;
            }

            cddasrc = Element.MakeFromUri (URIType.Src, "cdda://1", "cddasrc");
            if (cddasrc == null) {
                RaiseError (current_track, Catalog.GetString ("Could not initialize element from cdda URI"));
                return false;
            }

            cddasrc ["device"] = device;

            try {
                cddasrc ["paranoia-mode"] = paranoia_mode;
            } catch (Gst.PropertyNotFoundException) { }

            try {
                encoder = Parse.BinFromDescription (encoder_pipeline, true);
            } catch (Exception e) {
                string err = Catalog.GetString ("Could not create encoder pipeline : {0}");
                RaiseError (current_track, String.Format (err, e.Message));
                return false;
            }

            queue = ElementFactory.Make ("queue", "queue");
            if (queue == null) {
                RaiseError (current_track, Catalog.GetString ("Could not create queue plugin"));
                return false;
            }

            queue ["max-size-time"] = 120L * Gst.Constants.SECOND;

            filesink = ElementFactory.Make ("filesink", "filesink");
            if (filesink == null) {
                RaiseError (current_track, Catalog.GetString ("Could not create filesink plugin"));
                return false;
            }

            pipeline.Add (cddasrc, queue, encoder, filesink);

            if (!Element.Link (cddasrc, queue, encoder, filesink)) {
                RaiseError (current_track, Catalog.GetString ("Could not link pipeline elements"));
            }

            pipeline.Bus.AddWatch (OnBusMessage);

            return true;
        }
Exemplo n.º 24
0
        private bool ConstructPipeline (string encoder_pipeline)
        {
            Element source_elem;
            Element decoder_elem;

            pipeline = new Gst.Pipeline ("pipeline");

            source_elem = ElementFactory.MakeFromUri (URIType.Src, current_track.Uri.AbsoluteUri, "source");
            if (source_elem == null) {
                RaiseError (current_track, Catalog.GetString ("Could not create source element"));
                return false;
            }

            decoder_elem = ElementFactory.Make ("decodebin2", "decodebin2");
            if (decoder_elem == null) {
                RaiseError (current_track, Catalog.GetString ("Could not create decodebin2 plugin"));
                return false;
            }

            try {
                sink_bin = new AudioSinkBin ("sinkbin", encoder_pipeline, output_uri.AbsoluteUri);
            } catch (Exception e) {
                RaiseError (current_track, e.Message);
            }

            if (sink_bin == null) {
                RaiseError (current_track, Catalog.GetString ("Could not create sinkbin plugin"));
                return false;
            }

            pipeline.Add (source_elem, decoder_elem, sink_bin);

            source_elem.Link (decoder_elem);

            decoder_elem.PadAdded += OnPadAdded;

            pipeline.Bus.AddWatch (OnBusMessage);

            return true;
        }
Exemplo n.º 25
0
        private void CreatePipeline()
        {

            m_Pipeline = new Pipeline("test-pipeline");

            //m_Source = Gst.Parse.Launch("playbin uri=http://ftp.nluug.nl/ftp/graphics/blender/apricot/trailer/Sintel_Trailer1.1080p.DivX_Plus_HD.mkv"); 



            m_Source = Gst.ElementFactory.Make("videotestsrc","source");

            m_Source["pattern"] = 18; // Example of setting element properties



            m_Sink = Gst.ElementFactory.Make("autovideosink", "sink");



            m_Pipeline.Add(m_Source, m_Sink);

            m_Source.Link(m_Sink);

        }
Exemplo n.º 26
0
        private bool OnBusMessage (Bus bus, Message msg)
        {
            switch (msg.Type) {
                case MessageType.Eos:
                    pipeline.SetState (State.Null);
                    pipeline = null;
                    is_transcoding = false;
                    timer.Stop ();
                    RaiseTrackFinished (current_track, output_uri);
                    break;

                case MessageType.Error:
                    Enum error_type;
                    string err_msg, debug;
                    is_transcoding = false;
                    timer.Stop ();
                    msg.ParseError (out error_type, out err_msg, out debug);
                    RaiseError (current_track, String.Format ("{0} : {1}", err_msg, debug));
                    timer.Stop ();
                    break;

                default:
                    break;
            }

            return true;
        }
Exemplo n.º 27
0
        public static void Main(string[] args)
        {
            // Initialize Gstreamer
            Gst.Application.Init(ref args);

            // Create the elements
            var audioSource = ElementFactory.Make ("audiotestsrc", "audio_source");
            var tee = ElementFactory.Make ("tee", "tee");
            var audioQueue = ElementFactory.Make ("queue", "audio_queue");
            var audioConvert = ElementFactory.Make ("audioconvert", "audio_convert");
            var audioResample = ElementFactory.Make ("audioresample", "audio_resample");
            var audioSink = ElementFactory.Make ("autoaudiosink", "audio_sink");
            var videoQueue = ElementFactory.Make ("queue", "video_queue");
            var visual = ElementFactory.Make ("wavescope", "visual");
            var videoConvert = ElementFactory.Make ("videoconvert", "csp");
            var videoSink = ElementFactory.Make ("autovideosink", "video_sink");

            // Create the empty pipeline
            var pipeline = new Pipeline ("test-pipeline");

            if (audioSource == null || tee == null || audioQueue == null || audioConvert == null || audioResample == null ||
                audioSink == null || videoQueue == null || visual == null || videoConvert == null || videoSink == null || pipeline == null) {
                Console.WriteLine ("Not all elements could be created.");
                return;
            }

            // Link all elements that can be automatically linked because they have "Always" pads
            pipeline.Add (audioSource, tee, audioQueue, audioConvert, audioResample, audioSink,
                videoQueue, visual, videoConvert, videoSink);
            if (!audioSource.Link (tee) ||
                !Element.Link (audioQueue, audioConvert, audioResample, audioSink) ||
                !Element.Link (videoQueue, visual, videoConvert, videoSink)) {
                Console.WriteLine ("Elements could not be linked.");
                return;
            }

            // Manually link the Tee, which has "Request" pads
            var teeSrcPadTemplate = tee.GetPadTemplate ("src_%u");
            var teeAudioPad = tee.RequestPad (teeSrcPadTemplate, null, null);
            Console.WriteLine ("Obtained request pad {0} for audio branch.", teeAudioPad.Name);
            var queueAudioPad = audioQueue.GetStaticPad ("sink");
            var teeVideoPad = tee.RequestPad (teeSrcPadTemplate, null, null);
            Console.WriteLine ("Obtained request pad {0} for video branch.", teeVideoPad.Name);
            var queueVideoPad = videoQueue.GetStaticPad ("sink");
            if (teeAudioPad.Link (queueAudioPad) != PadLinkReturn.Ok ||
                teeVideoPad.Link(queueVideoPad) != PadLinkReturn.Ok) {
                Console.WriteLine ("Tee could not be linked.");
                return;
            }

            // Start playing
            var ret = pipeline.SetState (State.Playing);
            if (ret == StateChangeReturn.Failure) {
                Console.WriteLine ("Unable to set the pipeline to the playing state (check the bus for error messages).");
            }

            // Wait until error or EOS
            pipeline.Bus.TimedPopFiltered (Constants.CLOCK_TIME_NONE, MessageType.Error | MessageType.Eos);

            // Release the request pads from the Tee, and unref them
            tee.ReleaseRequestPad (teeAudioPad);
            tee.ReleaseRequestPad (teeVideoPad);

            // Free resources
            pipeline.SetState (State.Null);
        }
Exemplo n.º 28
0
        public void Finish()
        {
            if (output_path != null) {
                Banshee.IO.File.Delete (new SafeUri (output_path));
            }

            TrackReset ();

            encoder_pipeline = null;
            output_extension = null;

            if (timer != null) {
                timer.Stop ();
            }

            if (pipeline != null && pipeline is Element) {
                pipeline.SetState (State.Null);
                pipeline = null;
            }
        }
Exemplo n.º 29
0
        public static void Main(string[] args)
        {
            // Initialize Gstreamer
            Gst.Application.Init(ref args);

            // Create the element factories
            var sourceFactory = ElementFactory.Find ("audiotestsrc");
            var sinkFactory = ElementFactory.Find ("autoaudiosink");

            if (sourceFactory == null || sinkFactory == null) {
                Console.WriteLine ("Not all element factories could be created.");
                return;
            }

            // Print information about the pad templates of these factories
            PrintPadTemplateInformation (sourceFactory);
            PrintPadTemplateInformation (sinkFactory);

            // Ask the factories to instantiate actual elements
            var source = sourceFactory.Create ("source");
            var sink = sinkFactory.Create ("sink");

            // Create the empty pipeline
            var pipeline = new Pipeline ("test-pipeline");

            if (pipeline == null || source == null || sink == null) {
                Console.WriteLine ("Not all elements could be created.");
                return;
            }

            // Build the pipeline
            pipeline.Add (source, sink);
            if (!source.Link (sink)) {
                Console.WriteLine ("Elements could not be linked.");
                return;
            }

            // Print initial negotiated caps (in NULL state)
            Console.WriteLine ("In NULL state:");
            PrintPadCapabilities (sink, "sink");

            // Start playing
            var ret = pipeline.SetState (State.Playing);
            if (ret == StateChangeReturn.Failure) {
                Console.WriteLine ("Unable to set the pipeline to the playing state (check the bus for error messages).");
            }

            // Wait until error, EOS or State Change
            var bus = pipeline.Bus;
            var terminate = false;

            do {
                var msg = bus.TimedPopFiltered (Constants.CLOCK_TIME_NONE, MessageType.Error | MessageType.Eos | MessageType.StateChanged);

                // Parse message
                if (msg != null) {
                    switch (msg.Type) {
                    case MessageType.Error:
                        string debug;
                        GLib.GException exc;
                        msg.ParseError (out exc, out debug);
                        Console.WriteLine ("Error received from element {0}: {1}", msg.Src.Name, exc.Message);
                        Console.WriteLine ("Debugging information: {0}", debug != null ? debug : "none");
                        terminate = true;
                        break;
                    case MessageType.Eos:
                        Console.WriteLine ("End-Of-Stream reached.\n");
                        terminate = true;
                        break;
                    case MessageType.StateChanged:
                        // We are only interested in state-changed messages from the pipeline
                        if (msg.Src == pipeline) {
                            State oldState, newState, pendingState;
                            msg.ParseStateChanged (out oldState, out newState, out pendingState);
                            Console.WriteLine ("Pipeline state changed from {0} to {1}:",
                                Element.StateGetName (oldState), Element.StateGetName (newState));
                            // Print the current capabilities of the sink element
                            PrintPadCapabilities (sink, "sink");
                        }
                        break;
                    default:
                        // We should not reach here because we only asked for ERRORs, EOS and STATE_CHANGED
                        Console.WriteLine ("Unexpected message received.");
                        break;
                    }
                }
            } while (!terminate);

            // Free resources
            pipeline.SetState (State.Null);
        }
Exemplo n.º 30
0
        public void Dispose ()
        {
            Reset ();

            if (pipeline != null) {
                pipeline.SetState (State.Null);
                pipeline.Dispose ();
                pipeline = null;
            }
        }
Exemplo n.º 31
0
        private void ReInitPipeline()
        {
            if (pipeline != null) {
                pipeline.SetState (Gst.State.Null);
                pipeline = null;
            }

            pipeline = new Gst.Pipeline ();
            drawSink = Gst.ElementFactory.Make ("xvimagesink");
            camerabin = Gst.ElementFactory.Make ("camerabin");
            camerabin.Connect ("image-done", new Gst.SignalHandler (OnImageDone));
            pipeline.SetState (Gst.State.Null);

            overlayAdapter = new Gst.Interfaces.XOverlayAdapter (drawSink.Handle);
            overlayAdapter.XwindowId = gdk_x11_drawable_get_xid (drawingArea.GdkWindow.Handle);
            pipeline.Add (camerabin);

            if (camerabin.HasProperty ("viewfinder-sink")) {
                camerabin ["viewfinder-sink"] = drawSink;
            }

            if (camerabin.HasProperty ("filename")) {
                camerabin ["filename"] = "snapshot.png";
            }

            pipeline.SetState (Gst.State.Playing);
            needReInit = false;
        }
Exemplo n.º 32
0
        private void SetupRecordingPipeline()
        {
            // set up pipeline and elements
            // gst-launch-0.10 autoaudiosrc ! audioconvert ! vorbisenc ! oggmux ! filesink location=dump.ogg
            // Create new pipeline.

            _pipeline = new Gst.Pipeline();

            //Pipeline pipeline = new Pipeline("pipeline");

            // Construct pipeline filesrc -> avidemux -> mpeg4 -> directdrawsink

            //_eleAudioSource = ElementFactory.Make("autoaudiosrc", "autoaudiosrc");
            _eleAudioSource  = ElementFactory.Make("pulsesrc");
            _eleAudioConvert = ElementFactory.Make("audioconvert");
            if (_recordOgg)
            {
                _eleVorbisEnc = ElementFactory.Make("vorbisenc");
                _eleOggMux    = ElementFactory.Make("oggmux");
            }
            else
            {
                _eleWavPack = ElementFactory.Make("wavpackenc");
            }
            _eleFileSink = new Gst.CorePlugins.FileSink();
            //_eleFileSink = ElementFactory.Make("filesink", "filesink");
            _eleFileSink ["location"] = _path;

            // Add and link pipeline.
            if (_recordOgg)
            {
                _pipeline.Add(_eleAudioSource, _eleAudioConvert, _eleVorbisEnc, _eleOggMux, _eleFileSink);
            }
            else
            {
                _pipeline.Add(_eleAudioSource, _eleAudioConvert, _eleWavPack, _eleFileSink);
            }

            // Play video.
            _pipeline.SetState(Gst.State.Ready);
            _pipeline.SetState(Gst.State.Paused);

            if (!_eleAudioSource.Link(_eleAudioConvert))
            {
                Console.WriteLine("link failed between source and converter");
            }
            if (_recordOgg)
            {
                if (!_eleAudioConvert.Link(_eleVorbisEnc))
                {
                    Console.WriteLine("link failed between converter and encoder");
                }

                if (!_eleVorbisEnc.Link(_eleOggMux))
                {
                    Console.WriteLine("link failed between e and parser");
                }

                if (!_eleOggMux.Link(_eleFileSink))
                {
                    Console.Error.WriteLine("link failed between parser and sink");
                }
            }
            else
            {
                if (!_eleAudioConvert.Link(_eleWavPack))
                {
                    Console.WriteLine("link failed between converter and encoder");
                }

                if (!_eleWavPack.Link(_eleFileSink))
                {
                    Console.Error.WriteLine("link failed between encoder and sink");
                }
            }

            _recordInit = true;
        }
Exemplo n.º 33
0
        public static void Main(string[] args)
        {
            // Initialize Gstreamer
            Application.Init(ref args);

            // Create the elements
            source = ElementFactory.Make ("uridecodebin", "source");
            convert = ElementFactory.Make ("audioconvert", "convert");
            sink = ElementFactory.Make ("autoaudiosink", "sink");

            // Create the empty pipeline
            pipeline = new Pipeline ("test-pipeline");

            if (source == null || convert == null || sink == null || pipeline == null) {
                Console.WriteLine ("Not all elements could be created");
                return;
            }

            // Build the pipeline. Note that we are NOT linking the source at this point.
            // We will do it later.
            pipeline.Add (source, convert, sink);
            if (!convert.Link (sink)) {
                Console.WriteLine ("Elements could not be linked");
                return;
            }

            // Set the URI to play
            source ["uri"] = "http://download.blender.org/durian/trailer/sintel_trailer-1080p.mp4";

            // Connect to the pad-added signal
            source.PadAdded += HandlePadAdded;

            // Start playing
            var ret = pipeline.SetState (State.Playing);
            if (ret == StateChangeReturn.Failure) {
                Console.WriteLine ("Unable to set the pipeline to the playing state.");
                return;
            }

            // Listen to the bus
            var bus = pipeline.Bus;
            bool terminated = false;
            do {
                var msg = bus.TimedPopFiltered (Constants.CLOCK_TIME_NONE, MessageType.StateChanged | MessageType.Error | MessageType.Eos);

                if (msg != null) {
                    switch (msg.Type) {
                    case MessageType.Error:
                        string debug;
                        GLib.GException exc;
                        msg.ParseError (out exc, out debug);
                        Console.WriteLine (string.Format ("Error received from element {0}: {1}", msg.Src.Name, exc.Message));
                        Console.WriteLine ("Debugging information: {0}", debug);
                        terminated = true;
                        break;
                    case MessageType.Eos:
                        Console.WriteLine("End-Of-Stream reached.");
                        terminated = true;
                        break;
                    case MessageType.StateChanged:
                        // We are only interested in state-changed messages from the pipeline
                        if (msg.Src == pipeline) {
                            State oldState, newState, pendingState;
                            msg.ParseStateChanged(out oldState, out newState, out pendingState);
                            Console.WriteLine ("Pipeline state changed from {0} to {1}:", Element.StateGetName(oldState), Element.StateGetName(newState));
                        }
                        break;
                    default:
                        // We should not reach here
                        Console.WriteLine ("Unexpected message received.");
                        break;
                    }
                }
            } while (!terminated);

            pipeline.SetState (State.Null);
        }