Example #1
0
            /// <summary>
            /// Create a pipeline use gstreamer
            /// </summary>
            /// <returns>
            /// A <see cref="System.Boolean"/>
            /// </returns>
            private bool Make_Pipeline()
            {
                try{
                    pipeline = new Pipeline("pipeline");

                    // crear un elemento filesrc para leer el Archivo MP3
                    filesrc = ElementFactory.Make("filesrc", "filesrc");

                    // Crear un Mad Decodificador
                    mad = ElementFactory.Make("mad", "mad");

                    // Crear el Audio Sink
                    osssink = ElementFactory.Make("alsasink", "alsasink");

                    // Agregar los elementos al pipeline principal
                    pipeline.Add(filesrc);
                    pipeline.Add(mad);
                    pipeline.Add(osssink);

                    // Conectar los elementos
                    filesrc.Link(mad);
                    mad.Link(osssink);
                }catch (Exception e) { Console.WriteLine(e); }

                return(true);
            }
Example #2
0
 /// <summary>
 /// This function reads the file to play
 /// </summary>
 public bool LoadFile(string file)
 {
     // The file to play exists
     if (System.IO.File.Exists(file))
     {
         if (loop.IsRunning)
         {
             loop.Quit();
         }
         if (pipeline != null)
         {
             pipeline.SetState(State.Null);
             pipeline = null;
         }
         Make_Pipeline();
         controller.ResetTimer();
         pipeline.Bus.AddWatch(new BusFunc(BusCb));
         filesrc.SetProperty("location", file);
         this.file = file;
         state     = State.Ready;
         pipeline.SetState(state);
         controller.MediaPlayer_GetTags();
         controller.buttons_SetMediaInfo();
         return(true);
     }
     else                     // The file dont exists
     {
         filesrc.SetProperty("location", null);
         state = State.Ready;
         pipeline.SetState(state);
         return(false);
     }
 }
 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));
 }
        public static void Main(string[] args)
        {
            // Initialize GStreamer
            Application.Init (ref args);

            // Build the pipeline
            var pipeline = Parse.Launch ("playbin uri=http://docs.gstreamer.com/media/sintel_trailer-480p.webm");

            // Create the elements inside the sink bin
            var equalizer = ElementFactory.Make ("equalizer-3bands", "equalizer");
            var convert = ElementFactory.Make ("audioconvert", "convert");
            var sink = ElementFactory.Make ("autoaudiosink", "audio_sink");
            if (equalizer == null || convert == null || sink == null) {
                Console.WriteLine ("Not all elements could be created.");
                return;
            }

            // Create the sink bin, add the elements and link them
            var bin = new Bin ("audio_sink_bin");
            bin.Add (equalizer, convert, sink);
            Element.Link (equalizer, convert, sink);
            var pad = equalizer.GetStaticPad ("sink");
            var ghostPad = new GhostPad ("sink", pad);
            ghostPad.SetActive (true);
            bin.AddPad (ghostPad);

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

            // Configure the equalizer
            equalizer ["band1"] = (double)-24.0;
            equalizer ["band2"] = (double)-24.0;

            // Set playbin2's audio sink to be our sink bin
            pipeline ["audio-sink"] = bin;

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

            // Free resources
            pipeline.SetState (State.Null);
        }
Example #5
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;
        }
Example #6
0
        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;
        }