Ejemplo n.º 1
0
            public AudioSinkBin(string elementName) : base(elementName)
            {
                hw_audio_sink = SelectAudioSink();
                Add(hw_audio_sink);
                first = hw_audio_sink;

                // Our audio sink is a tee, so plugins can attach their own pipelines
                audiotee = ElementFactory.Make("tee", "audiotee");
                if (audiotee == null)
                {
                    Log.Error("Can not create audio tee!");
                }
                else
                {
                    Add(audiotee);
                }

                volume = FindVolumeProvider(hw_audio_sink);
                if (volume != null)
                {
                    // If the sink provides its own volume property we assume that it will
                    // also save that value across program runs.  Pulsesink has this behaviour.
                    VolumeNeedsSaving = false;
                }
                else
                {
                    volume            = ElementFactory.Make("volume", "volume");
                    VolumeNeedsSaving = true;
                    Add(volume);
                    volume.Link(hw_audio_sink);
                    first = volume;
                }

                equalizer = ElementFactory.Make("equalizer-10bands", "equalizer-10bands");

                if (equalizer != null)
                {
                    Element eq_audioconvert  = ElementFactory.Make("audioconvert", "audioconvert");
                    Element eq_audioconvert2 = ElementFactory.Make("audioconvert", "audioconvert2");
                    preamp = ElementFactory.Make("volume", "preamp");

                    this.Add(eq_audioconvert, preamp, equalizer, eq_audioconvert2);

                    Element.Link(eq_audioconvert, preamp, equalizer, eq_audioconvert2, first);

                    first = eq_audioconvert;
                    Log.Debug("Built and linked Equalizer");
                }

                // Link the first tee pad to the primary audio sink queue
                Pad sinkpad = first.GetStaticPad("sink");
                Pad pad     = RequestTeePad();

                audiotee["alloc-pad"] = pad;
                pad.Link(sinkpad);
                first = audiotee;

                visible_sink = new GhostPad("sink", first.GetStaticPad("sink"));
                AddPad(visible_sink);
            }
Ejemplo n.º 2
0
        public static void Run(string[] args)
        {
            // Initialize GStreamer
            Application.Init(ref args);
            GtkSharp.GstreamerSharp.ObjectManager.Initialize();

            /* Build the pipeline */
            var pipeline = Parse.Launch("playbin3 uri=https://www.freedesktop.org/software/gstreamer-sdk/data/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)
            {
                "Not all elements could be created".PrintErr();
                return;
            }

            /* Create the sink bin, add the elements and link them */
            var bin = new Bin("audio_sink_bin");

            bin.Add(equalizer, convert, sink);
            if (!Element.Link(equalizer, convert, sink))
            {
                "Elements could not be linked".PrintErr();
                return;
            }
            var pad      = equalizer.GetStaticPad("sink");
            var ghostPad = new GhostPad("sink", pad);

            ghostPad.SetActive(true);
            bin.AddPad(ghostPad);

            /* Configure the equalizer */
            equalizer["band1"] = -24.0;
            equalizer["band2"] = -24.0;

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

            /* Start playing */
            pipeline.SetState(State.Playing);

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

            if (msg != null)
            {
                System.Console.WriteLine(msg.Type);
                msg.Dispose();
            }
            bus.Dispose();

            pipeline.SetState(State.Null);
            pipeline.Dispose();
            pipeline = null;
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            // Initialize GStreamer
            Application.Init(ref args);

            // Build the pipeline
            var pipeline = Parse.Launch("playbin uri=http://freedesktop.org/software/gstreamer-sdk/data/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 playbin'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);
        }
        /// <summary>
        /// Creates a new recoding pipeline with the best (by user preference) available encoder and attaches it
        /// to the audiotee
        /// </summary>
        /// <returns>
        /// A <see cref="System.Boolean"/>, true if the pipeline was successfully created, false otherwise.
        /// </returns>
        public bool Create()
        {
            string bin_description = BuildPipeline();

            try {
                audiotee = new PlayerAudioTee(ServiceManager.PlayerEngine.ActiveEngine.GetBaseElements()[2]);

                if (bin_description.Equals(""))
                {
                    return(false);
                }

                encoder_bin = Parse.BinFromDescription(bin_description, true);
//                Hyena.Log.Debug ("DEBUG bin to string: " + encoder_bin.ToString());

                tagger    = new TagSetter(encoder_bin.GetByInterface(TagSetter.GetType()));
                file_sink = encoder_bin.GetByName("file_sink").ToFileSink();

                file_sink.Location = empty_file;
                file_sink.SetBooleanProperty("sync", true);
                file_sink.SetBooleanProperty("async", false);

                OldGLib.Object.GetObject(file_sink.ToIntPtr()).AddNotification("allow-overwrite", OnAllowOverwrite);

                ghost_pad = encoder_bin.GetStaticPad("sink").ToGhostPad();

                outputselector = encoder_bin.GetByName("sel");

                Pad filesinkpad = file_sink.GetStaticPad("sink");
                selector_filepad = filesinkpad.GetPeer();

                Element fake_sink   = encoder_bin.GetByName("fake_sink");
                Pad     fakesinkpad = fake_sink.GetStaticPad("sink");
                selector_fakepad = fakesinkpad.GetPeer();

                audiotee.AddBin(encoder_bin, ServiceManager.PlayerEngine.CurrentState == PlayerState.Playing);
                Hyena.Log.Debug("[Recorder] Recorder attached");
            } catch (Exception e) {
                Hyena.Log.InformationFormat("[Streamrecorder] An exception occurred during pipeline construction: {0}", bin_description);
                Hyena.Log.Debug(e.Message);
                Hyena.Log.Debug(e.StackTrace);
                return(false);
            }

            return(true);
        }
        void IDelayedInitializeService.DelayedInitialize()
        {
            if (!has_karaoke)
            {
                return;
            }

            playbin  = new Bin(ServiceManager.PlayerEngine.ActiveEngine.GetBaseElements()[0]);
            audiobin = new Bin(ServiceManager.PlayerEngine.ActiveEngine.GetBaseElements()[1]);
            audiotee = new Bin(ServiceManager.PlayerEngine.ActiveEngine.GetBaseElements()[2]);

            if (playbin.IsNull())
            {
                Hyena.Log.Debug("[Karaoke] Playbin is not yet initialized, cannot start Karaoke Mode");
            }

            audiokaraoke = audiobin.GetByName("karaoke");

            if (audiokaraoke.IsNull())
            {
                audiokaraoke = ElementFactory.Make("audiokaraoke", "karaoke");

                //add audiokaraoke to audiobin
                audiobin.Add(audiokaraoke);

                //setting new audiobin sink to audiokaraoke sink
                GhostPad teepad          = new GhostPad(audiobin.GetStaticPad("sink").ToIntPtr());
                Pad      audiokaraokepad = audiokaraoke.GetStaticPad("sink");
                teepad.SetTarget(audiokaraokepad);

                //link audiokaraoke sink and audiotee sink
                audiokaraoke.Link(audiotee);
            }

            if (!karaoke_enabled)
            {
                audiokaraoke.SetFloatProperty("level", 0);
                audiokaraoke.SetFloatProperty("mono-level", 0);
            }
            else
            {
                audiokaraoke.SetFloatProperty("level", effect_level);
                audiokaraoke.SetFloatProperty("mono-level", effect_level);
            }
        }
Ejemplo n.º 6
0
        public MyBin() : base()
        {
            Element filesrc = ElementFactory.Make("filesrc");

            Add(filesrc);
            CollectionAssert.IsEmpty(Pads);

            GhostPad pad1 = new GhostPad("ghost-sink", PadDirection.Sink);
            GhostPad pad2 = new GhostPad("ghost-src", new PadTemplate("src-template", PadDirection.Src, PadPresence.Request, Caps.NewAny()));

            Assert.IsFalse(pad1.SetTarget(filesrc.GetStaticPad("src")));
            Assert.IsTrue(pad2.SetTarget(filesrc.GetStaticPad("src")));

            AddPad(pad1);
            AddPad(pad2);

            CollectionAssert.Contains(Pads, pad1);
            CollectionAssert.Contains(Pads, pad2);
            CollectionAssert.Contains(SinkPads, pad1);
            CollectionAssert.Contains(SrcPads, pad2);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Helper function to really attach a bin to the audio player tee
        /// </summary>
        /// <param name="pad">
        /// A <see cref="IntPtr"/> referencing the pad that may need to be unblocked
        /// </param>
        /// <param name="blocked">
        /// A <see cref="System.Boolean"/> indicating if the pad is blocked
        /// </param>
        /// <param name="user_data">
        /// A <see cref="IntPtr"/> containing references to the bin and the audio tee
        /// </param>
        private PadProbeReturn ReallyAddBin(IntPtr pad, IntPtr probe_info, IntPtr user_data, bool blocked)
        {
            GCHandle gch = GCHandle.FromIntPtr(user_data);

            Bin[] user_bins = (Gst.Bin[])gch.Target;
            Bin   fixture   = user_bins[0];
            Bin   element   = user_bins[1];

            Element   queue;
            Element   audioconvert;
            Bin       bin;
            Bin       parent_bin;
            Pad       sink_pad;
            Pad       ghost_pad;
            GstObject element_parent;

            element_parent = element.GetParent();
            if (element_parent != null && !element_parent.IsNull())
            {
                Hyena.Log.Debug("[Streamrecorder.PlayerAudioTee]<ReallyAddBin>element already linked, exiting. assume double function call");
                element_parent.UnRef();
                return(PadProbeReturn.GST_PAD_PROBE_OK);
            }

            /* set up containing bin */
            bin          = new Bin();
            queue        = ElementFactory.Make("queue");
            audioconvert = ElementFactory.Make("audioconvert");

            bin.SetBooleanProperty("async-handling", true);
            queue.SetIntegerProperty("max-size-buffers", 10);

            bin.AddMany(new Element[3] {
                queue, audioconvert, element
            });
            queue.LinkMany(new Element[2] {
                audioconvert, element
            });

            sink_pad  = queue.GetStaticPad("sink");
            ghost_pad = new GhostPad("sink", sink_pad);
            bin.AddPad(ghost_pad);

            parent_bin = new Bin(fixture.GetParent().ToIntPtr());
            parent_bin.Add(bin);
            fixture.Link(bin);

            attached = true;

            if (blocked)
            {
                Hyena.Log.Debug("[Streamrecorder.PlayerAudioTee]<ReallyAddBin> unblocking pad after adding tee");

                parent_bin.SetState(State.Playing);
                ghost_pad.Ref();
                parent_bin.UnRef();
//                new Pad (pad).AddProbe (PadProbeType.GST_PAD_PROBE_TYPE_BLOCK, AddRemoveBinDone, ghost_pad.ToIntPtr (), null);
                PadProbeInfo info = (PadProbeInfo)Marshal.PtrToStructure(probe_info, typeof(PadProbeInfo));
                new Pad(pad).RemoveProbe(info.id);
                AddRemoveBinDone(IntPtr.Zero, IntPtr.Zero, ghost_pad.ToIntPtr());
            }
            else
            {
                parent_bin.SetState(State.Paused);
                ghost_pad.Ref();
                parent_bin.UnRef();
                AddRemoveBinDone(IntPtr.Zero, IntPtr.Zero, ghost_pad.ToIntPtr());
            }
            return(PadProbeReturn.GST_PAD_PROBE_OK);
        }
Ejemplo n.º 8
0
        public override bool Open(bool prescan)
        {
            System.Diagnostics.Debug.Assert(!_FileOpened);
            if (_FileOpened)
            {
                return(false);
            }
            Length = -1;
            Element convert   = ElementFactory.Make("audioconvert", "convert");
            Element audiosink = ElementFactory.Make("autoaudiosink", "audiosink");

            if (convert == null || audiosink == null)
            {
                CLog.LogError("Could not create pipeline");
                if (convert != null)
                {
                    convert.Dispose();
                }
                if (audiosink != null)
                {
                    audiosink.Dispose();
                }
                return(false);
            }

            var     audioSinkBin = new Bin("Audiosink");
            Element audiokaraoke = null;

            if (_Effect.HasFlag(EAudioEffect.Karaoke))
            {
                audiokaraoke = ElementFactory.Make("audiokaraoke", "karaoke");
                audioSinkBin.Add(audiokaraoke);
                audioSinkBin.Add(convert);
                audioSinkBin.Add(audiosink);

                audiokaraoke.Link(audiosink);
                audiokaraoke["level"]      = CConfig.Config.Sound.KaraokeEffectLevel;
                audiokaraoke["mono-level"] = CConfig.Config.Sound.KaraokeEffectLevel;

                convert.Link(audiokaraoke);
            }
            else
            {
                audioSinkBin.Add(convert);
                audioSinkBin.Add(audiosink);
                convert.Link(audiosink);
            }



            Pad      pad      = convert.GetStaticPad("sink");
            GhostPad ghostpad = new GhostPad("sink", pad);

            if (pad == null)
            {
                CLog.LogError("Could not create pads");
                convert.Dispose();
                audiosink.Dispose();
                audioSinkBin.Dispose();
                if (audiokaraoke != null)
                {
                    audiokaraoke.Dispose();
                }
                return(false);
            }

            if (!ghostpad.SetActive(true))
            {
                CLog.LogError("Could not link pads");
                convert.Dispose();
                audiosink.Dispose();
                audioSinkBin.Dispose();
                ghostpad.Dispose();
                if (audiokaraoke != null)
                {
                    audiokaraoke.Dispose();
                }
                return(false);
            }
            if (!audioSinkBin.AddPad(ghostpad))
            {
                CLog.LogError("Could not add pad");
                convert.Dispose();
                audiosink.Dispose();
                audioSinkBin.Dispose();
                ghostpad.Dispose();
                if (audiokaraoke != null)
                {
                    audiokaraoke.Dispose();
                }
                return(false);
            }

            _Element = ElementFactory.Make("playbin", "playbin");
            if (_Element == null)
            {
                CLog.LogError("Could not create playbin");
                convert.Dispose();
                audiosink.Dispose();
                audioSinkBin.Dispose();
                ghostpad.Dispose();
                if (audiokaraoke != null)
                {
                    audiokaraoke.Dispose();
                }
                return(false);
            }
            _Element["audio-sink"] = audioSinkBin;
            _Element["flags"]      = 1 << 1;
            _Element["uri"]        = new Uri(_Medium).AbsoluteUri;
            _Element.SetState(State.Paused);

            // Passing CLOCK_TIME_NONE here causes the pipeline to block for a long time so with
            // prescan enabled the pipeline will wait 500ms for stream to initialize and then continue
            // if it takes more than 500ms, duration queries will be performed asynchronously
            Message msg = _Element.Bus.TimedPopFiltered(prescan ? ulong.MaxValue : 0L, MessageType.AsyncDone | MessageType.Error);

            if (!_OnMessage(msg))
            {
                _Dispose(true);
                return(false);
            }
            _FileOpened = true;
            return(true);
        }