Esempio n. 1
0
        protected void ConfigTV()
        {
            int    hr;
            object o;

            hr = _captureGraphBuilder.FindInterface(null, null, _captureFilter, typeof(IAMTVTuner).GUID, out o);
            if (hr >= 0)
            {
                _amTvTuner = (IAMTVTuner)o;
                hr         = _amTvTuner.put_InputType(0, AppUser.Current.TunerInputType);
                DsError.ThrowExceptionForHR(hr);
                o  = null;
                hr = _captureGraphBuilder.FindInterface(null, null, _captureFilter, typeof(IAMCrossbar).GUID, out o);
                if (hr >= 0)
                {
                    _amCrossbar = (IAMCrossbar)o;
                    o           = null;
                }
                else
                {
                    throw new Exception("IAMCrossbar interface not found");
                }
            }
            else
            {
                throw new Exception("IAMTVTuner interface not found");
            }

            hr = _amTvTuner.put_InputType(0, AppUser.Current.TunerInputType);
            DsError.ThrowExceptionForHR(hr);
        }
Esempio n. 2
0
        private void BuildGraph()
        {
            int hr = 0;

            DsDevice [] devs;

            graphBuilder = (IFilterGraph2) new FilterGraph();
            rot          = new DsROTEntry(graphBuilder);

            vmr9 = (IBaseFilter) new VideoMixingRenderer9();
            hr   = graphBuilder.AddFilter(vmr9, "VMR9");

            devs = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
            DsDevice dev = devs[0];

            hr = graphBuilder.AddSourceFilterForMoniker(dev.Mon, null, dev.Name, out filter);
            DsError.ThrowExceptionForHR(hr);

            captureGraph = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();
            hr           = captureGraph.SetFiltergraph(graphBuilder);
            DsError.ThrowExceptionForHR(hr);

            hr = captureGraph.RenderStream(PinCategory.Capture, MediaType.Video, filter, null, vmr9);
            DsError.ThrowExceptionForHR(hr);

            object tmp;

            hr = captureGraph.FindInterface(null, null, filter, typeof(IAMTVTuner).GUID, out tmp);
            DsError.ThrowExceptionForHR(hr);
            tuner = (IAMTVTuner)tmp;

            mediaControl = (IMediaControl)graphBuilder;
            mediaControl.Run();
        }
Esempio n. 3
0
        private void ConfigTV()
        {
            int    hr;
            object o;

            hr = _captureGraphBuilder.FindInterface(null, null, _captureFilter, typeof(IAMTVTuner).GUID, out o);
            if (hr >= 0)
            {
                _amTvTuner = (IAMTVTuner)o;
                o          = null;
                hr         = _captureGraphBuilder.FindInterface(null, null, _captureFilter, typeof(IAMCrossbar).GUID, out o);
                if (hr >= 0)
                {
                    _amCrossbar = (IAMCrossbar)o;
                    o           = null;
                }
                else
                {
                    throw new Exception("IAMCrossbar interface not found");
                }
            }
            else
            {
                throw new Exception("IAMTVTuner interface not found");
            }
            hr = _amTvTuner.put_InputType(0, (DirectShowLib.TunerInputType)_tvConfig.AnalogTunerInputType);
            DsError.ThrowExceptionForHR(hr);
        }
Esempio n. 4
0
        /// <summary>
        /// Stop recording and release the graph
        /// </summary>
        public void StopRecord()
        {
            //Stop the Graph
            mediaControl.Stop();

#if DEBUG
            if (m_rot != null)
            {
                m_rot.Dispose();
                m_rot = null;
            }
#endif

            //Release COM objects
            Marshal.ReleaseComObject(graphBuilder);
            graphBuilder = null;

            if (tuner != null)
            {
                Marshal.ReleaseComObject(tuner);
                tuner = null;
            }

            if (crossbar != null)
            {
                Marshal.ReleaseComObject(crossbar);
                crossbar = null;
            }
        }
Esempio n. 5
0
        // Dispose(bool disposing) executes in two distinct scenarios.
        // If disposing equals true, the method has been called directly
        // or indirectly by a user's code. Managed and unmanaged resources
        // can be disposed.
        // If disposing equals false, the method has been called by the
        // runtime from inside the finalizer and you should not reference
        // other objects. Only unmanaged resources can be disposed.
        private void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!this._disposed)
            {
                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                    // Dispose managed resources.
                }

                // Call the appropriate methods to clean up
                // unmanaged resources here.
                if (_tvTuner != null)
                {
                    Marshal.ReleaseComObject(_tvTuner);
                }

                _tvTuner = null;

                // Note disposing has been done.
                _disposed = true;
            }
        }
Esempio n. 6
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                ForceReleaseComObject(_tuner);
                _tuner = null;
                ForceReleaseComObject(_tvaudio);
                _tvaudio = null;
                ForceReleaseComObject(_crossbar2);
                _crossbar2 = null;
                ForceReleaseComObject(_videoEncoder);
                _videoEncoder = null;
                ForceReleaseComObject(_audioEncoder);
                _audioEncoder = null;
                ForceReleaseComObject(_mpeg2Demux);
                _mpeg2Demux = null;
                ForceReleaseComObject(_leadYUVColorConverter);
                _leadYUVColorConverter = null;
                ForceReleaseComObject(_frameRateController);
                _frameRateController = null;
                ForceReleaseComObject(_audioVolumeFilter);
                _audioVolumeFilter = null;

                ForceReleaseComObject(_amTvTuner);
                _amTvTuner = null;
                ForceReleaseComObject(_amCrossbar);
                _amCrossbar = null;
            }

            base.Dispose(disposing);
        }
Esempio n. 7
0
        // ---------------- Public Methods ---------------

        /// <summary>
        /// Dispose components
        /// </summary>
        public void Dispose()
        {
            if (tvTuner != null)
            {
                Marshal.ReleaseComObject(tvTuner);
            }
            tvTuner = null;
        }
Esempio n. 8
0
 protected virtual void Dispose(bool disposing)
 {
     if (tvTuner != null)
     {
         Marshal.ReleaseComObject(tvTuner);
     }
     tvTuner = null;
 }
Esempio n. 9
0
 public override void Dispose(bool disposing)
 {
     AppLogger.Message("WinTV.Dispose");
     if (disposing)
     {
         if (_tuner != null)
         {
             Marshal.ReleaseComObject(_tuner);
             _tuner = null;
         }
         if (_tvaudio != null)
         {
             Marshal.ReleaseComObject(_tvaudio);
             _tvaudio = null;
         }
         if (_crossbar2 != null)
         {
             Marshal.ReleaseComObject(_crossbar2);
             _crossbar2 = null;
         }
         if (_videoEncoder != null)
         {
             Marshal.ReleaseComObject(_videoEncoder);
             _videoEncoder = null;
         }
         if (_audioEncoder != null)
         {
             Marshal.ReleaseComObject(_audioEncoder);
             _audioEncoder = null;
         }
         if (_mpeg2Demux != null)
         {
             Marshal.ReleaseComObject(_mpeg2Demux);
             _mpeg2Demux = null;
         }
         if (_captureFilter != null)
         {
             Marshal.ReleaseComObject(_captureFilter);
             _captureFilter = null;
         }
         if (_hcwColorConverter != null)
         {
             Marshal.ReleaseComObject(_hcwColorConverter);
             _hcwColorConverter = null;
         }
         if (_amTvTuner != null)
         {
             Marshal.ReleaseComObject(_amTvTuner);
             _amTvTuner = null;
         }
         if (_amCrossbar != null)
         {
             Marshal.ReleaseComObject(_amCrossbar);
             _amCrossbar = null;
         }
     }
     base.Dispose(disposing);
 }
Esempio n. 10
0
 /// <summary>
 /// Diposes the tuner component
 /// </summary>
 public void Dispose()
 {
     _tuner = null;
     if (_audioPin != null)
     {
         Release.ComObject("_audioPin", _audioPin);
     }
     if (_filterTvTuner != null)
     {
         while (Release.ComObject(_filterTvTuner) > 0)
         {
         }
         _filterTvTuner = null;
     }
     DevicesInUse.Instance.Remove(_tunerDevice);
 }
Esempio n. 11
0
        public void CloseInterfaces()
        {
            // Stop previewing data
            if (this.mediaControl != null)
            {
                this.mediaControl.StopWhenReady();
            }

            this.currentState = PlayState.Stopped;

            // Stop receiving events
            if (this.mediaEventEx != null)
            {
                this.mediaEventEx.SetNotifyWindow(IntPtr.Zero, WM_GRAPHNOTIFY, IntPtr.Zero);
            }

            // Relinquish ownership (IMPORTANT!) of the video window.
            // Failing to call put_Owner can lead to assert failures within
            // the video renderer, as it still assumes that it has a valid
            // parent window.
            if (this.videoWindow != null)
            {
                this.videoWindow.put_Visible(OABool.False);
                this.videoWindow.put_Owner(IntPtr.Zero);
            }


            // Remove filter graph from the running object table
            if (rot != null)
            {
                rot.Dispose();
                rot = null;
            }

            if (tuner != null)
            {
                Marshal.ReleaseComObject(tuner);
                tuner = null;
            }
            // Release DirectShow interfaces
            Marshal.ReleaseComObject(this.mediaControl); this.mediaControl = null;
            Marshal.ReleaseComObject(this.mediaEventEx); this.mediaEventEx = null;
            Marshal.ReleaseComObject(this.videoWindow); this.videoWindow   = null;
            Marshal.ReleaseComObject(this.graphBuilder); this.graphBuilder = null;
            Marshal.ReleaseComObject(this.captureGraphBuilder); this.captureGraphBuilder = null;
        }
Esempio n. 12
0
        internal TVFineTune(IAMTVTuner tuner, int countryCode, int tuningSpace)
        {
            _tvTuner = tuner;

            // Initialize the TV tuner
            this.InputType   = TunerInputType.Cable;
            this.CountryCode = countryCode;
            this.TuningSpace = tuningSpace;
            this.AudioMode   = AMTunerModeType.TV;

            // Minimum and maximum frequencies of TV tuner. These values are country
            // and TV tuner dependent! Real frequencies can be found via checking the
            // frequencies corresponding with the minimum and maximum channel numbers.
            // But becareful, some TV tuners return incorrect values.
            // For US the maximum frequency is usually 801MHz, for European countries
            // the maximum frequency is usually 863MHz

            // Try to find the maximum and the minimum TV tuning frequency
            int lastChan = this.Channel;
            int max      = this.ChannelMinMax[1];

            if (lastChan < max)
            {
                int chan = max;
                for (int i = 0; (i < 30) && (max != this.Channel); i++)
                {
                    max          = chan;
                    this.Channel = chan;
                    chan--;
                    this.maxFrequency = this.GetVideoFrequency;
                }
            }
            this.Channel      = max;
            this.maxFrequency = this.GetVideoFrequency;

            int min = this.ChannelMinMax[0];

            this.Channel      = min;
            this.minFrequency = this.GetVideoFrequency;

            // Default choice used for selecting my favorit channel (at 567MHz,
            // this frequency maps to Windows channel number 212. The Windows
            // default choice is usually channel 4 (48Mhz)
            this.Channel = lastChan;
            //this.Channel = 212;
        }
Esempio n. 13
0
        /// <summary>
        /// Creates the tuner filter instance
        /// </summary>
        /// <param name="graph">The stored graph</param>
        /// <param name="graphBuilder">The graphbuilder</param>
        /// <returns>true, if the graph building was successful</returns>
        public bool CreateFilterInstance(Graph graph, IFilterGraph2 graphBuilder)
        {
            Log.Log.WriteFile("analog: AddTvTunerFilter {0}", _tunerDevice.Name);
            if (DevicesInUse.Instance.IsUsed(_tunerDevice))
            {
                return(false);
            }
            IBaseFilter tmp;
            int         hr;

            try
            {
                hr = graphBuilder.AddSourceFilterForMoniker(_tunerDevice.Mon, null, _tunerDevice.Name, out tmp);
            }
            catch (Exception)
            {
                Log.Log.WriteFile("analog: cannot add filter to graph");
                return(false);
            }
            if (hr != 0)
            {
                Log.Log.Error("analog: AddTvTunerFilter failed:0x{0:X}", hr);
                throw new TvException("Unable to add tvtuner to graph");
            }
            _filterTvTuner = tmp;
            DevicesInUse.Instance.Add(_tunerDevice);
            _tuner = _filterTvTuner as IAMTVTuner;
            if (string.IsNullOrEmpty(graph.Tuner.Name) || !_tunerDevice.Name.Equals(
                    graph.Tuner.Name))
            {
                Log.Log.WriteFile("analog: Detecting capabilities of the tuner");
                graph.Tuner.Name = _tunerDevice.Name;
                int index;
                _audioPin = FilterGraphTools.FindMediaPin(_filterTvTuner, MediaType.AnalogAudio, MediaSubType.Null,
                                                          PinDirection.Output, out index);
                graph.Tuner.AudioPin = index;
                return(CheckCapabilities(graph));
            }
            Log.Log.WriteFile("analog: Using stored capabilities of the tuner");
            _audioPin        = DsFindPin.ByDirection(_filterTvTuner, PinDirection.Output, graph.Tuner.AudioPin);
            _supportsFMRadio = (graph.Tuner.RadioMode & RadioMode.FM) != 0;
            _supportsAMRadio = (graph.Tuner.RadioMode & RadioMode.AM) != 0;
            return(true);
        }
Esempio n. 14
0
        private void GetControlInterface()
        {
            this.tuner    = null;
            this.crossbar = null;

            object o;

            int hr = this.captureGraphBuilder.FindInterface(null, null, this.videoCaptureFilter, typeof(IAMTVTuner).GUID, out o);

            if (hr >= 0)
            {
                this.tuner = o as IAMTVTuner;
                o          = null;

                hr = this.captureGraphBuilder.FindInterface(null, null, this.videoCaptureFilter, typeof(IAMCrossbar).GUID, out o);
                if (hr >= 0)
                {
                    this.crossbar = o as IBaseFilter;
                    o             = null;
                }

                // Use the crossbar class to help us sort out all the possible video inputs
                // The class needs to be given the capture filters ANALOGVIDEO input pin
                IPin pinVideo = DsFindPin.ByCategory(this.videoCaptureFilter, PinCategory.AnalogVideoIn, 0);
                if (pinVideo != null)
                {
                    try
                    {
                        this.crossbarHelper = new CrossbarHelper(pinVideo);
                    }
                    catch {}
                    Marshal.ReleaseComObject(pinVideo);
                }

                hr = this.captureGraphBuilder.FindInterface(null, null, this.videoCaptureFilter, typeof(IAMTVAudio).GUID, out o);
                if (hr >= 0)
                {
                    this.amTVAudio = o as IAMTVAudio;
                    o = null;
                }
            }
        }
Esempio n. 15
0
 // ------------------- Constructors ------------------
 /// <summary> Initialize this object with a DirectShow tuner </summary>
 public Tuner(IAMTVTuner tuner)
 {
     tvTuner = tuner;
 }
Esempio n. 16
0
 // ---------------- Public Methods ---------------
 public void Dispose()
 {
     if ( tvTuner != null )
         Marshal.ReleaseComObject( tvTuner ); tvTuner = null;
 }
Esempio n. 17
0
        /// <summary>
        /// Stop recording and release the graph
        /// </summary>
        public void StopRecord()
        {
            //Stop the Graph
            mediaControl.Stop();

            #if DEBUG
            if (m_rot != null)
            {
                m_rot.Dispose();
                m_rot = null;
            }
            #endif

            //Release COM objects
            Marshal.ReleaseComObject(graphBuilder);
            graphBuilder = null;

            if (tuner != null)
            {
                Marshal.ReleaseComObject(tuner);
                tuner = null;
            }

            if (crossbar != null)
            {
                Marshal.ReleaseComObject(crossbar);
                crossbar = null;
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Initialize the graph
        /// </summary>
        public void InitGraph()
        {
            if (theDevice == null)
                return;

            object o;

            //Create the Graph
            graphBuilder = (IGraphBuilder) new FilterGraph();

            #if DEBUG
            m_rot = new DsROTEntry(graphBuilder);
            #endif

            //Create the Capture Graph Builder
            ICaptureGraphBuilder2 captureGraphBuilder = null;
            captureGraphBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            //Create the media control for controlling the graph
            mediaControl = (IMediaControl) this.graphBuilder;

            // Attach the filter graph to the capture graph
            int hr = captureGraphBuilder.SetFiltergraph(this.graphBuilder);
            DsError.ThrowExceptionForHR(hr);

            //Add the Video input device to the graph
            hr = graphBuilder.AddFilter(theDevice, "source filter");
            DsError.ThrowExceptionForHR(hr);

            //Add the Video compressor filter to the graph
            if (theCompressor != null)
            {
                hr = graphBuilder.AddFilter(theCompressor, "compressor filter");
                DsError.ThrowExceptionForHR(hr);
            }

            //Create the file writer part of the graph. SetOutputFileName does this for us, and returns the mux and sink
            IBaseFilter mux;
            IFileSinkFilter sink;
            hr = captureGraphBuilder.SetOutputFileName(MediaSubType.Avi, textBox1.Text, out mux, out sink);
            DsError.ThrowExceptionForHR(hr);

            //Connect the device and compressor to the mux to render the capture part of the graph
            hr = captureGraphBuilder.RenderStream(PinCategory.Capture, MediaType.Video, theDevice, theCompressor, mux);
            DsError.ThrowExceptionForHR(hr);

            //Render any preview pin of the device
            hr = captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, theDevice, null, null);
            DsError.ThrowExceptionForHR(hr);

            tuner = null;
            crossbar = null;

            hr = captureGraphBuilder.FindInterface(null, null, theDevice, typeof(IAMTVTuner).GUID, out o);
            if (hr >= 0)
            {
                tuner = (IAMTVTuner)o;
                o = null;

                hr = captureGraphBuilder.FindInterface(null, null, theDevice, typeof(IAMCrossbar).GUID, out o);
                if (hr >= 0)
                {
                    crossbar = (IBaseFilter)o;
                    o = null;
                }
            }

            //get the video window from the graph
            IVideoWindow videoWindow = null;
            videoWindow = (IVideoWindow) graphBuilder;

            //Set the owener of the videoWindow to an IntPtr of some sort (the Handle of any control - could be a form / button etc.)
            hr = videoWindow.put_Owner(panel1.Handle);
            DsError.ThrowExceptionForHR(hr);

            //Set the style of the video window
            hr = videoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren);
            DsError.ThrowExceptionForHR(hr);

            // Position video window in client rect of main application window
            hr = videoWindow.SetWindowPosition(0, 0, panel1.Width, panel1.Height);
            DsError.ThrowExceptionForHR(hr);

            // Make the video window visible
            hr = videoWindow.put_Visible(OABool.True);
            DsError.ThrowExceptionForHR(hr);

            Marshal.ReleaseComObject(mux);
            Marshal.ReleaseComObject(sink);
            Marshal.ReleaseComObject(captureGraphBuilder);
        }
Esempio n. 19
0
        public void StartDisplay(Panel panel, IntPtr notifyWindow, DisplaySource dispSource, string filename)
        {
            int hr = 0;

            displaySource = dispSource;

            if (dispSource == DisplaySource.Clip)
            {
                if (filename == String.Empty)
                {
                    return;
                }
            }

            try
            {
                graphBuilder = (IGraphBuilder) new FilterGraph();
                // QueryInterface for DirectShow interfaces
                mediaControl  = (IMediaControl)graphBuilder;
                mediaEventEx  = (IMediaEventEx)graphBuilder;
                mediaSeeking  = (IMediaSeeking)graphBuilder;
                mediaPosition = (IMediaPosition)graphBuilder;
                // Query for video interfaces, which may not be relevant for audio files
                videoWindow = graphBuilder as IVideoWindow;
                basicVideo  = graphBuilder as IBasicVideo;
                // Query for audio interfaces, which may not be relevant for video-only files
                basicAudio = graphBuilder as IBasicAudio;

                if (displaySource == DisplaySource.Stream)
                {
                    /// Find source filter ///

                    string     possibleTvTunerName = "Video Capture";
                    DsDevice[] vidInputDevices     = GetVideoInputDevices();

                    for (int i = 0; i < vidInputDevices.Length; i++)
                    {
                        DsDevice possibleTvTuner = vidInputDevices[i];

                        // use first device if none defined
                        if (videoInputDevicePath == "")
                        {
                            videoInputDevicePath = possibleTvTuner.DevicePath;
                        }

                        if (possibleTvTuner.DevicePath != videoInputDevicePath)
                        {
                            continue;
                        }
                        try
                        {
                            if (sourceFilter != null)
                            {
                                Marshal.ReleaseComObject(sourceFilter);
                                sourceFilter = null;
                            }
                            //Create the filter for the selected video input device
                            sourceFilter         = CreateFilterFromPath(FilterCategory.VideoInputDevice, possibleTvTuner.DevicePath);
                            possibleTvTunerName  = possibleTvTuner.Name;
                            videoInputDeviceName = possibleTvTuner.Name;

                            if (sourceFilter == null)
                            {
                                return;
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                            //System.Diagnostics.Debug.WriteLine(ex.ToString());
                        }
                    }
                    ///////////////////////////////////////////////////////////////////////////////////////////
                    captureGraphBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

                    // Attach the filter graph to the capture graph
                    hr = captureGraphBuilder.SetFiltergraph(graphBuilder);
                    DsError.ThrowExceptionForHR(hr);

                    // Add Capture filter to our graph.
                    hr = graphBuilder.AddFilter(sourceFilter, possibleTvTunerName /*"Video Capture"*/);
                    DsError.ThrowExceptionForHR(hr);

                    //// Init tuner/crossbar //////////////////////////////////////////////////////////////////
                    object o;
                    tuner    = null;
                    crossbar = null;

                    hr = captureGraphBuilder.FindInterface(FindDirection.UpstreamOnly, null, sourceFilter, typeof(IAMTVTuner).GUID, out o);
                    //DsError.ThrowExceptionForHR(hr);
                    if (hr >= 0)
                    {
                        tuner = (IAMTVTuner)o;
                        o     = null;

                        hr = captureGraphBuilder.FindInterface(null, null, sourceFilter, typeof(IAMCrossbar).GUID, out o);
                        DsError.ThrowExceptionForHR(hr);
                        if (hr >= 0)
                        {
                            crossbar = (IAMCrossbar)o;
                            //crossbar = (IBaseFilter)o;
                            o = null;
                        }
                        usingCrossBar = true;
                    }
                    else
                    {
                        usingCrossBar = false;
                    }
                    ///////////////////////////////////////////////////////////////////////////////////////////

                    // Render the preview pin on the video capture filter
                    // Use this instead of this.graphBuilder.RenderFile
                    hr = captureGraphBuilder.RenderStream(PinCategory.Preview, DirectShowLib.MediaType.Video, sourceFilter, null, null);
                    DsError.ThrowExceptionForHR(hr);

                    // If we are using tv tuner, force audio on..and set device input from tuner
                    if (tuner != null)
                    {
                        if (videoInputDeviceSource == PhysicalConnectorType.Video_Tuner)
                        {
                            ChangeVideoInputSource(PhysicalConnectorType.Video_Tuner);
                            ChangeAudioInputSource(PhysicalConnectorType.Audio_Tuner);
                        }
                    }

                    // Now that the filter has been added to the graph and we have
                    // rendered its stream, we can release this reference to the filter.
                    // temp
                    //Marshal.ReleaseComObject(sourceFilter);

                    isAudioOnly = false;
                }
                else
                {
                    // Have the graph builder construct its the appropriate graph automatically
                    hr = graphBuilder.RenderFile(filename, null);
                    DsError.ThrowExceptionForHR(hr);

                    // Is this an audio-only file (no video component)?
                    CheckVisibility();
                }

                if (!isAudioOnly)
                {
                    RenderToPanel(panel, notifyWindow);
                    GetFrameStepInterface();
                }
                else
                {
                    /// Initialize the default player size and enable playback menu items
                    /// <jefri> hr = InitPlayerWindow();
                    /// <jefri> DsError.ThrowExceptionForHR(hr);
                    /// <jefri> EnablePlaybackMenu(true, MediaType.Audio);
                }

                currentPlaybackRate = 1.0;

                #if DEBUG
                rot = new DsROTEntry(this.graphBuilder);
                #endif

                // Run the graph to play the media
                hr = mediaControl.Run();
                DsError.ThrowExceptionForHR(hr);

                currentState = PlayState.Running;

                // Every call to this method,volume level will be 0,
                // so inform client to adjust volume level
                // Raise event, so our client can take action for it
                if (PlayerStarted != null)
                {
                    PlayerStarted(new EventArgs());
                }
            }
            catch (COMException ce)
            {
                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "DirectShow Exception";
                args.Source    = ce.Source;
                args.Message   = ce.Message;
                args.Exception = ce;

                OnNotifyError(args);
            }
            catch
            {
                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "DirectShow Exception";
                args.Source    = "";
                args.Message   = "An unrecoverable error has occurred.";
                args.Exception = null;

                OnNotifyError(args);
            }
        }
Esempio n. 20
0
 // Token: 0x0600018F RID: 399 RVA: 0x00011350 File Offset: 0x0000F550
 protected void createGraph()
 {
     if (this.zgraphState < Capture.GraphState.Created)
     {
         GC.Collect();
         this.graphBuilder = (IGraphBuilder)Activator.CreateInstance(Type.GetTypeFromCLSID(Clsid.FilterGraph, true));
         Guid captureGraphBuilder = Clsid.CaptureGraphBuilder2;
         Guid guid = typeof(ICaptureGraphBuilder2).GUID;
         this.captureGraphBuilder = (ICaptureGraphBuilder2)DsBugWO.CreateDsInstance(ref captureGraphBuilder, ref guid);
         int    num           = this.captureGraphBuilder.SetFiltergraph(this.graphBuilder);
         Type   typeFromCLSID = Type.GetTypeFromCLSID(Clsid.SampleGrabber);
         object objectValue   = RuntimeHelpers.GetObjectValue(Activator.CreateInstance(typeFromCLSID));
         this.sampGrabber = (ISampleGrabber)objectValue;
         this.baseGrabFlt = (IBaseFilter)this.sampGrabber;
         AMMediaType ammediaType = new AMMediaType();
         if (this.VideoDevice != null)
         {
             this.videoDeviceFilter = (IBaseFilter)Marshal.BindToMoniker(this.VideoDevice.MonikerString);
             num = this.graphBuilder.AddFilter(this.videoDeviceFilter, "Video Capture Device");
             ammediaType.majorType  = MediaType.Video;
             ammediaType.subType    = MediaSubType.RGB24;
             ammediaType.formatType = FormatType.VideoInfo;
             num = this.sampGrabber.SetMediaType(ammediaType);
             num = this.graphBuilder.AddFilter(this.baseGrabFlt, "Ds.NET Grabber");
         }
         if (this.AudioDevice != null)
         {
             this.audioDeviceFilter = (IBaseFilter)Marshal.BindToMoniker(this.AudioDevice.MonikerString);
             num = this.graphBuilder.AddFilter(this.audioDeviceFilter, "Audio Capture Device");
         }
         if (this.VideoCompressor != null)
         {
             this.videoCompressorFilter = (IBaseFilter)Marshal.BindToMoniker(this.VideoCompressor.MonikerString);
             num = this.graphBuilder.AddFilter(this.videoCompressorFilter, "Video Compressor");
         }
         if (this.AudioCompressor != null)
         {
             this.audioCompressorFilter = (IBaseFilter)Marshal.BindToMoniker(this.AudioCompressor.MonikerString);
             num = this.graphBuilder.AddFilter(this.audioCompressorFilter, "Audio Compressor");
         }
         Guid   capture = PinCategory.Capture;
         Guid   guid2   = MediaType.Interleaved;
         Guid   guid3   = typeof(IAMStreamConfig).GUID;
         object obj;
         num = this.captureGraphBuilder.FindInterface(ref capture, ref guid2, this.videoDeviceFilter, ref guid3, out obj);
         if (num != 0)
         {
             guid2 = MediaType.Video;
             num   = this.captureGraphBuilder.FindInterface(ref capture, ref guid2, this.videoDeviceFilter, ref guid3, out obj);
             if (num != 0)
             {
                 obj = null;
             }
         }
         this.videoStreamConfig = (obj as IAMStreamConfig);
         obj     = null;
         capture = PinCategory.Capture;
         guid2   = MediaType.Audio;
         guid3   = typeof(IAMStreamConfig).GUID;
         num     = this.captureGraphBuilder.FindInterface(ref capture, ref guid2, this.audioDeviceFilter, ref guid3, out obj);
         if (num != 0)
         {
             obj = null;
         }
         this.audioStreamConfig = (obj as IAMStreamConfig);
         this.mediaControl      = (IMediaControl)this.graphBuilder;
         if (this.m_videoSources != null)
         {
             this.m_videoSources.Dispose();
         }
         this.m_videoSources = null;
         if (this.m_audioSources != null)
         {
             this.m_audioSources.Dispose();
         }
         this.m_audioSources = null;
         if (this.m_propertyPages != null)
         {
             this.m_propertyPages.Dispose();
         }
         this.m_propertyPages = null;
         this.m_videoCaps     = null;
         obj     = null;
         capture = PinCategory.Capture;
         guid2   = MediaType.Interleaved;
         guid3   = typeof(IAMTVTuner).GUID;
         num     = this.captureGraphBuilder.FindInterface(ref capture, ref guid2, this.videoDeviceFilter, ref guid3, out obj);
         if (num != 0)
         {
             guid2 = MediaType.Video;
             num   = this.captureGraphBuilder.FindInterface(ref capture, ref guid2, this.videoDeviceFilter, ref guid3, out obj);
             if (num != 0)
             {
                 obj = null;
             }
         }
         IAMTVTuner iamtvtuner = obj as IAMTVTuner;
         if (iamtvtuner != null)
         {
             this.m_tuner = new Tuner(iamtvtuner);
         }
         this.videoInfoHeader = (VideoInfoHeader)Marshal.PtrToStructure(ammediaType.formatPtr, typeof(VideoInfoHeader));
         Marshal.FreeCoTaskMem(ammediaType.formatPtr);
         ammediaType.formatPtr = IntPtr.Zero;
         num = this.sampGrabber.SetBufferSamples(false);
         if (num == 0)
         {
             num = this.sampGrabber.SetOneShot(false);
         }
         if (num == 0)
         {
             num = this.sampGrabber.SetCallback(null, 0);
         }
         this.zgraphState = Capture.GraphState.Created;
     }
 }
Esempio n. 21
0
        private void GetControlInterface()
        {
            this.tuner = null;
            this.crossbar = null;

            object o;

            int hr = this.captureGraphBuilder.FindInterface(null, null, this.videoCaptureFilter, typeof(IAMTVTuner).GUID, out o);
            if (hr >= 0)
            {
                this.tuner = o as IAMTVTuner;
                o = null;

                hr = this.captureGraphBuilder.FindInterface(null, null, this.videoCaptureFilter, typeof(IAMCrossbar).GUID, out o);
                if (hr >= 0)
                {
                    this.crossbar = o as IBaseFilter;
                    o = null;
                }

                // Use the crossbar class to help us sort out all the possible video inputs
                // The class needs to be given the capture filters ANALOGVIDEO input pin
                IPin pinVideo = DsFindPin.ByCategory(this.videoCaptureFilter, PinCategory.AnalogVideoIn, 0);
                if (pinVideo != null)
                {
                    try
                    {
                        this.crossbarHelper = new CrossbarHelper(pinVideo);
                    }
                    catch{}
                    Marshal.ReleaseComObject(pinVideo);
                }

                hr = this.captureGraphBuilder.FindInterface(null, null, this.videoCaptureFilter, typeof(IAMTVAudio).GUID, out o);
                if (hr >= 0)
                {
                    this.amTVAudio = o as IAMTVAudio;
                    o = null;
                }
            }
        }
Esempio n. 22
0
 /// <summary>
 /// Diposes the tuner component
 /// </summary>
 public void Dispose()
 {
   _tuner = null;
   if (_audioPin != null)
   {
     Release.ComObject("_audioPin", _audioPin);
   }
   if (_filterTvTuner != null)
   {
     while (Release.ComObject(_filterTvTuner) > 0) {}
     _filterTvTuner = null;
   }
   DevicesInUse.Instance.Remove(_tunerDevice);
 }
Esempio n. 23
0
        protected void createGraph()
        {
            Guid cat;
            Guid med;
            int  hr;

            // Ensure required properties are set
            if (videoDevice == null && audioDevice == null)
            {
                throw new ArgumentException("The video and/or audio device have not been set. Please set one or both to valid capture devices.\n");
            }

            // Skip if we are already created
            if ((int)graphState < (int)GraphState.Created)
            {
                // Garbage collect, ensure that previous filters are released
                GC.Collect();

                // Make a new filter graph
                graphBuilder = (IGraphBuilder)Activator.CreateInstance(Type.GetTypeFromCLSID(Clsid.FilterGraph, true));

                // Get the Capture Graph Builder
                Guid clsid = Clsid.CaptureGraphBuilder2;
                Guid riid  = typeof(ICaptureGraphBuilder2).GUID;
                captureGraphBuilder = (ICaptureGraphBuilder2)BugFixes.InstantiateDirectShow(ref clsid, ref riid);

                // Link the CaptureGraphBuilder to the filter graph
                hr = captureGraphBuilder.SetFiltergraph(graphBuilder);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                // Add the graph to the Running Object Table so it can be
                // viewed with GraphEdit
#if DEBUG
                rotCookie = DsROT.AddGraphToRot(graphBuilder);
#endif

                // Get the video device and add it to the filter graph
                if (VideoDevice != null)
                {
                    videoDeviceFilter = (IBaseFilter)Marshal.BindToMoniker(VideoDevice.MonikerString);
                    hr = graphBuilder.AddFilter(videoDeviceFilter, "Video Capture Device");
                    if (hr < 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }
                }

                // Get the audio device and add it to the filter graph
                if (AudioDevice != null)
                {
                    audioDeviceFilter = (IBaseFilter)Marshal.BindToMoniker(AudioDevice.MonikerString);
                    hr = graphBuilder.AddFilter(audioDeviceFilter, "Audio Capture Device");
                    if (hr < 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }
                }

                // Get the video compressor and add it to the filter graph
                if (VideoCompressor != null)
                {
                    videoCompressorFilter = (IBaseFilter)Marshal.BindToMoniker(VideoCompressor.MonikerString);
                    hr = graphBuilder.AddFilter(videoCompressorFilter, "Video Compressor");
                    if (hr < 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }
                }

                // Get the audio compressor and add it to the filter graph
                if (AudioCompressor != null)
                {
                    audioCompressorFilter = (IBaseFilter)Marshal.BindToMoniker(AudioCompressor.MonikerString);
                    hr = graphBuilder.AddFilter(audioCompressorFilter, "Audio Compressor");
                    if (hr < 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }
                }

                // Retrieve the stream control interface for the video device
                // FindInterface will also add any required filters
                // (WDM devices in particular may need additional
                // upstream filters to function).

                // Try looking for an interleaved media type
                object o;
                cat = PinCategory.Capture;
                med = MediaType.Interleaved;
                Guid iid = typeof(IAMStreamConfig).GUID;
                hr = captureGraphBuilder.FindInterface(
                    ref cat, ref med, videoDeviceFilter, ref iid, out o);

                if (hr != 0)
                {
                    // If not found, try looking for a video media type
                    med = MediaType.Video;
                    hr  = captureGraphBuilder.FindInterface(
                        ref cat, ref med, videoDeviceFilter, ref iid, out o);

                    if (hr != 0)
                    {
                        o = null;
                    }
                }
                videoStreamConfig = o as IAMStreamConfig;

                // Retrieve the stream control interface for the audio device
                o   = null;
                cat = PinCategory.Capture;
                med = MediaType.Audio;
                iid = typeof(IAMStreamConfig).GUID;
                hr  = captureGraphBuilder.FindInterface(
                    ref cat, ref med, audioDeviceFilter, ref iid, out o);
                if (hr != 0)
                {
                    o = null;
                }
                audioStreamConfig = o as IAMStreamConfig;

                // Retreive the media control interface (for starting/stopping graph)
                mediaControl = (IMediaControl)graphBuilder;

                // Reload any video crossbars
                if (videoSources != null)
                {
                    videoSources.Dispose();
                }
                videoSources = null;

                // Reload any audio crossbars
                if (audioSources != null)
                {
                    audioSources.Dispose();
                }
                audioSources = null;

                // Reload any property pages exposed by filters
                if (propertyPages != null)
                {
                    propertyPages.Dispose();
                }
                propertyPages = null;

                // Reload capabilities of video device
                videoCaps = null;

                // Reload capabilities of video device
                audioCaps = null;

                // Retrieve TV Tuner if available
                o   = null;
                cat = PinCategory.Capture;
                med = MediaType.Interleaved;
                iid = typeof(IAMTVTuner).GUID;
                hr  = captureGraphBuilder.FindInterface(
                    ref cat, ref med, videoDeviceFilter, ref iid, out o);
                if (hr != 0)
                {
                    med = MediaType.Video;
                    hr  = captureGraphBuilder.FindInterface(
                        ref cat, ref med, videoDeviceFilter, ref iid, out o);
                    if (hr != 0)
                    {
                        o = null;
                    }
                }
                IAMTVTuner t = o as IAMTVTuner;
                if (t != null)
                {
                    tuner = new Tuner(t);
                }



                // Update the state now that we are done
                graphState = GraphState.Created;
            }
        }
Esempio n. 24
0
 /// <summary>
 /// Creates the tuner filter instance
 /// </summary>
 /// <param name="graph">The stored graph</param>
 /// <param name="graphBuilder">The graphbuilder</param>
 /// <returns>true, if the graph building was successful</returns>
 public bool CreateFilterInstance(Graph graph, IFilterGraph2 graphBuilder)
 {
   Log.Log.WriteFile("analog: AddTvTunerFilter {0}", _tunerDevice.Name);
   if (DevicesInUse.Instance.IsUsed(_tunerDevice))
     return false;
   IBaseFilter tmp;
   int hr;
   try
   {
     hr = graphBuilder.AddSourceFilterForMoniker(_tunerDevice.Mon, null, _tunerDevice.Name, out tmp);
   }
   catch (Exception)
   {
     Log.Log.WriteFile("analog: cannot add filter to graph");
     return false;
   }
   if (hr != 0)
   {
     Log.Log.Error("analog: AddTvTunerFilter failed:0x{0:X}", hr);
     throw new TvException("Unable to add tvtuner to graph");
   }
   _filterTvTuner = tmp;
   DevicesInUse.Instance.Add(_tunerDevice);
   _tuner = _filterTvTuner as IAMTVTuner;
   if (string.IsNullOrEmpty(graph.Tuner.Name) || !_tunerDevice.Name.Equals(
     graph.Tuner.Name))
   {
     Log.Log.WriteFile("analog: Detecting capabilities of the tuner");
     graph.Tuner.Name = _tunerDevice.Name;
     int index;
     _audioPin = FilterGraphTools.FindMediaPin(_filterTvTuner, MediaType.AnalogAudio, MediaSubType.Null,
                                               PinDirection.Output, out index);
     graph.Tuner.AudioPin = index;
     return CheckCapabilities(graph);
   }
   Log.Log.WriteFile("analog: Using stored capabilities of the tuner");
   _audioPin = DsFindPin.ByDirection(_filterTvTuner, PinDirection.Output, graph.Tuner.AudioPin);
   _supportsFMRadio = (graph.Tuner.RadioMode & RadioMode.FM) != 0;
   _supportsAMRadio = (graph.Tuner.RadioMode & RadioMode.AM) != 0;
   return true;
 }
Esempio n. 25
0
        public void CloseInterfaces()
        {
            int hr = 0;

            try
            {
                lock (this)
                {
                    // Relinquish ownership (IMPORTANT!) after hiding video window
                    if (!isAudioOnly)
                    {
                        hr = videoWindow.put_Visible(OABool.False);
                        DsError.ThrowExceptionForHR(hr);
                        hr = videoWindow.put_Owner(IntPtr.Zero);
                        DsError.ThrowExceptionForHR(hr);
                    }

                    if (mediaEventEx != null)
                    {
                        hr = mediaEventEx.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);
                        DsError.ThrowExceptionForHR(hr);
                    }

                    #if DEBUG
                    if (rot != null)
                    {
                        rot.Dispose();
                        rot = null;
                    }
                    #endif

                    // Release and zero DirectShow interfaces
                    if (mediaEventEx != null)
                    {
                        mediaEventEx = null;
                    }
                    if (mediaSeeking != null)
                    {
                        mediaSeeking = null;
                    }
                    if (mediaPosition != null)
                    {
                        mediaPosition = null;
                    }
                    if (mediaControl != null)
                    {
                        mediaControl = null;
                    }
                    if (basicAudio != null)
                    {
                        basicAudio = null;
                    }
                    if (basicVideo != null)
                    {
                        basicVideo = null;
                    }
                    if (videoWindow != null)
                    {
                        videoWindow = null;
                    }
                    if (frameStep != null)
                    {
                        frameStep = null;
                    }
                    if (graphBuilder != null)
                    {
                        Marshal.ReleaseComObject(graphBuilder);
                    }
                    graphBuilder = null;

                    // Tuner stuff
                    if (captureGraphBuilder != null)
                    {
                        Marshal.ReleaseComObject(captureGraphBuilder);
                    }
                    captureGraphBuilder = null;

                    if (tuner != null)
                    {
                        Marshal.ReleaseComObject(tuner);
                        tuner = null;
                    }

                    if (crossbar != null)
                    {
                        Marshal.ReleaseComObject(crossbar);
                        crossbar = null;
                    }

                    //temp
                    if (sourceFilter != null)
                    {
                        Marshal.ReleaseComObject(sourceFilter);
                        sourceFilter = null;
                    }
                    GC.Collect();
                }
            }
            catch
            {
            }
        }
Esempio n. 26
0
        public void CaptureVideo()
        {
            int hr = 0;

            try
            {
                int  width            = INI.Default["DirectShow Player"]["Video Player/Device Source Width", "352"].Integer;
                int  Height           = INI.Default["DirectShow Player"]["Video Player/Device Source Height", "240"].Integer;
                int  fps              = INI.Default["DirectShow Player"]["Video Player/Frames Per Second (0 unlimited)", "30"].Integer;
                bool antenna_input    = INI.Default[Options.ProgramName]["Video Player/Capture Tuner from antenna", "true"].Bool;
                bool capture_TV       = INI.Default[Options.ProgramName]["Video Player/Capture Tuner", "true"].Bool;
                bool capture_is_audio = INI.Default[Options.ProgramName]["Video Player/Capture Video is Audio also", "true"].Bool;
                IPin cap_pin          = null;
                IPin cap_audio_pin;

                crossbar_to_tuner = capture_TV;
                // Get DirectShow interfaces
                GetInterfaces();

                // Attach the filter graph to the capture graph
                hr = this.captureGraphBuilder.SetFiltergraph(this.graphBuilder);
                DsError.ThrowExceptionForHR(hr);

                // Use the system device enumerator and class enumerator to find
                // a video capture/preview device, such as a desktop USB video camera.
                sourceFilter = this.DeviceFinder.FindVideoCaptureDevice(false);
                if (sourceFilter == null)
                {
                    Network.SendStatus(channel, volume, false);
                    return;
                }

#if use_bda
                bda_filter = FindVideoCaptureDevice(true);
#endif

                if (!capture_is_audio)
                {
                    sourceAudioFilter = this.DeviceFinder.FindAudioCaptureDevice();
                }
                else
                {
                    sourceAudioFilter = sourceFilter;
                }
                //reclock_video_filter = FindVideoRenderDevice();

                //scale_filter = FindVideoScaleDevice();
                reclock_filter = this.DeviceFinder.FindAudioRenderDevice();

                IAMAnalogVideoDecoder decoder = sourceFilter as IAMAnalogVideoDecoder;
                if (decoder != null)
                {
                    AnalogVideoStandard oldStandard;
                    decoder.get_TVFormat(out oldStandard);
                    if (oldStandard != AnalogVideoStandard.NTSC_M)
                    {
                        decoder.put_TVFormat(AnalogVideoStandard.NTSC_M);
                    }
                    decoder = null;
                }

                // this is really for which input - the tuner we shouldn't adjust
                //if( !capture_TV )

                // Add Capture filter to our graph.
                hr = this.graphBuilder.AddFilter(sourceFilter, "Video Capture");
                DsError.ThrowExceptionForHR(hr);

                if (scale_filter != null)
                {
                    hr = this.graphBuilder.AddFilter(scale_filter, "Video Scaler");
                    DsError.ThrowExceptionForHR(hr);
                }
                this.graphBuilder.Connect(null, null);
#if use_bda
                if (bda_filter != null)
                {
                    hr = this.graphBuilder.AddFilter(bda_filter, "Video Tuner");
                    DsError.ThrowExceptionForHR(hr);
                }
#endif

                if (capture_TV && !capture_is_audio)
                {
                    if (sourceAudioFilter != null)
                    {
                        hr = this.graphBuilder.AddFilter(sourceAudioFilter, "Audio Capture");
                        DsError.ThrowExceptionForHR(hr);
                    }
                }

                if (reclock_filter != null)
                {
                    Log.log("Adding 'reclock' which is the audio output device?");
                    hr = this.graphBuilder.AddFilter(reclock_filter, "Audio Renderer");
                    DsError.ThrowExceptionForHR(hr);
                }

                //this.graphBuilder.AddFilter(
                AdjustCrossbarPin();

                bool cap_is_preview;
                {
                    // set the video input size on the preview pin.
                    cap_audio_pin = DsFindPin.ByCategory((IBaseFilter)sourceAudioFilter, PinCategory.Preview, 0);
                    cap_pin       = DsFindPin.ByCategory((IBaseFilter)sourceFilter, PinCategory.Preview, 0);
                    if (cap_pin == null)
                    {
                        cap_is_preview = false;
                        cap_audio_pin  = DsFindPin.ByCategory((IBaseFilter)sourceAudioFilter, PinCategory.Capture, 0);
                        cap_pin        = DsFindPin.ByCategory((IBaseFilter)sourceFilter, PinCategory.Capture, 0);
                    }
                    else
                    {
                        cap_is_preview = true;
                    }
                    //Log.log( "Cap pin + " + cap_pin );
                }

                // Render the preview pin on the video capture filter
                // Use this instead of this.graphBuilder.RenderFile
                if (cap_is_preview)
                {
                    //hr = this.captureGraphBuilder.RenderStream( PinCategory.Preview, MediaType.Video, scale_filter, null, null );
                    //DsError.ThrowExceptionForHR( hr );
                    hr = this.captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, sourceFilter, null, null);
                    DsError.ThrowExceptionForHR(hr);
                    if (sourceAudioFilter != null)
                    {
                        hr = this.captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Audio, sourceAudioFilter, null, reclock_filter);
                        DsError.ThrowExceptionForHR(hr);
                    }
                }
                else
                {
                    //hr = this.captureGraphBuilder.RenderStream( PinCategory.Capture, MediaType.Video, scale_filter, null, null );
                    //DsError.ThrowExceptionForHR( hr );
                    hr = this.captureGraphBuilder.RenderStream(PinCategory.Capture, MediaType.Video, sourceFilter, null, null);
                    DsError.ThrowExceptionForHR(hr);
                    if (sourceAudioFilter != null)
                    {
                        //IBaseFilter renderer = null;
                        //Log.log( "reclock is " + reclock_filter );
                        hr = this.captureGraphBuilder.RenderStream(PinCategory.Capture, MediaType.Audio, sourceAudioFilter, null, reclock_filter);
                        if (hr != 0)
                        {
                            Log.log("Bad audio stream");
                        }
                        //DsError.ThrowExceptionForHR( hr );
                    }
                }

                IAMStreamConfig stream = cap_pin as IAMStreamConfig;
                if (stream != null)
                {
                    // 352x240
                    AMMediaType     media;
                    VideoInfoHeader vih = new VideoInfoHeader();
                    stream.GetFormat(out media);

                    Marshal.PtrToStructure(media.formatPtr, vih);

                    //vih.BmiHeader.Width = width;
                    //vih.BmiHeader.Height = Height;
                    if (fps > 0)
                    {
                        vih.AvgTimePerFrame = (10000000L / fps);
                    }

                    //Log.log( "set the bitmap override..." );
                    Marshal.StructureToPtr(vih, media.formatPtr, false);

                    hr = stream.SetFormat(media);
                    if (hr != 0)
                    {
                        Log.log("Failed to set format (preview)." + hr);
                    }
                }
                else
                {
                    Log.log("Failed to get stream config from source filter");
                }
                //graph_filter.SetSyncSource( ref_clock );
                object o;
                hr = captureGraphBuilder.FindInterface(null, null, sourceFilter, typeof(IReferenceClock).GUID, out o);
                if (hr == 0)
                {
                    ref_clock = (IReferenceClock)o;
                }
                if (ref_clock == null)
                {
                    hr        = captureGraphBuilder.FindInterface(null, null, sourceAudioFilter, typeof(IReferenceClock).GUID, out o);
                    ref_clock = (IReferenceClock)o;
                }

                hr = captureGraphBuilder.FindInterface(null, null, sourceFilter, typeof(IAMTVTuner).GUID, out o);

                //graphBuilder.sa.

                if (hr >= 0)
                {
                    tuner = (IAMTVTuner)o;
                    o     = null;
                }
                if (tuner != null)
                {
                    if (antenna_input)
                    {
                        TunerInputType type;
                        hr = tuner.get_InputType(0, out type);
                        if (type != TunerInputType.Antenna)
                        {
                            tuner.put_InputType(0, TunerInputType.Antenna);
                            hr = tuner.get_InputType(0, out type);
                        }
                    }
                    else
                    {
                        if (tuner != null)
                        {
                            TunerInputType type;
                            hr = tuner.get_InputType(0, out type);
                            if (type != TunerInputType.Cable)
                            {
                                tuner.put_InputType(0, TunerInputType.Cable);
                                hr = tuner.get_InputType(0, out type);
                            }
                        }
                    }
                    tuner.ChannelMinMax(out min_channel, out max_channel);
                    min_channel = INI.Default["DirectShow Player"]["Video Player/Minimum Channel", min_channel.ToString()].Integer;
                    max_channel = INI.Default["DirectShow Player"]["Video Player/Maximum Channel", max_channel.ToString()].Integer;
                }
                // Now that the filter has been added to the graph and we have
                // rendered its stream, we can release this reference to the filter.

                if (sourceAudioFilter != null)
                {
                    //hr = captureGraphBuilder.FindInterface( null, null, sourceFilter, typeof( IAMTVAudio ).GUID, out o );
                    hr = captureGraphBuilder.FindInterface(null, null, sourceAudioFilter, typeof(IBasicAudio).GUID, out o);
                    if (hr >= 0)
                    {
                        audio_mixer = (IBasicAudio)o;
                        o           = null;
                    }
                }

                Marshal.ReleaseComObject(sourceFilter);

                if (audio_mixer != null)
                {
                    audio_mixer.get_Volume(out volume);
                }
                if (tuner != null)
                {
                    tuner.get_Channel(out channel, out sub_channel, out sub_channel2);
                }


                //this.graphBuilder.SetDefaultSyncSource();
                if (ref_clock != null)
                {
                    this.graph_filter.SetSyncSource(ref_clock);
                }
                graph_streams.SyncUsingStreamOffset(true);

                // Set video window style and position
                SetupVideoWindow();

                // Add our graph to the running object table, which will allow
                // the GraphEdit application to "spy" on our graph
                rot = new DsROTEntry(this.graphBuilder);

                //this.mediaControl.set
                // Start previewing video data
                hr = this.mediaControl.Run();
                DsError.ThrowExceptionForHR(hr);

                // Remember current state
                this.currentState = PlayState.Running;

                Network.SendStatus(channel, volume, (this.currentState == PlayState.Running));
            }
            catch (Exception e)
            {
                MessageBox.Show("An unrecoverable error has occurred : " + e.Message);
                this.DialogResult = DialogResult.Abort;
                this.Close();
                Application.Exit();
            }
        }
Esempio n. 27
0
        protected void createGraph()
        {
            System.Type typeFromCLSID = null;
            object      obj2          = null;

            if ((this.videoDevice == null) && (this.audioDevice == null))
            {
                throw new ArgumentException("The video and/or audio device have not been set. Please set one or both to valid capture devices.\n");
            }
            if (this.graphState < GraphState.Created)
            {
                object obj3;
                GC.Collect();
                this.graphBuilder = (IGraphBuilder)Activator.CreateInstance(System.Type.GetTypeFromCLSID(Clsid.FilterGraph, true));
                Guid clsid = Clsid.CaptureGraphBuilder2;
                Guid gUID  = typeof(ICaptureGraphBuilder2).GUID;
                this.captureGraphBuilder = (ICaptureGraphBuilder2)DsBugWO.CreateDsInstance(ref clsid, ref gUID);
                typeFromCLSID            = System.Type.GetTypeFromCLSID(Clsid.SampleGrabber, true);
                if (typeFromCLSID == null)
                {
                    throw new NotImplementedException("DirectShow SampleGrabber not installed/registered");
                }
                obj2             = Activator.CreateInstance(typeFromCLSID);
                this.sampGrabber = (ISampleGrabber)obj2;
                obj2             = null;
                int errorCode = this.captureGraphBuilder.SetFiltergraph(this.graphBuilder);
                if (errorCode < 0)
                {
                    Marshal.ThrowExceptionForHR(errorCode);
                }
                AMMediaType pmt = new AMMediaType();
                pmt.majorType  = MediaType.Video;
                pmt.subType    = MediaSubType.RGB24;
                pmt.formatType = FormatType.VideoInfo;
                errorCode      = this.sampGrabber.SetMediaType(pmt);
                if (errorCode < 0)
                {
                    Marshal.ThrowExceptionForHR(errorCode);
                }
                if (this.VideoDevice != null)
                {
                    this.videoDeviceFilter = (IBaseFilter)Marshal.BindToMoniker(this.VideoDevice.MonikerString);
                    errorCode = this.graphBuilder.AddFilter(this.videoDeviceFilter, "Video Capture Device");
                    if (errorCode < 0)
                    {
                        Marshal.ThrowExceptionForHR(errorCode);
                    }
                    this.mediaEvt    = (IMediaEventEx)this.graphBuilder;
                    this.baseGrabFlt = (IBaseFilter)this.sampGrabber;
                    errorCode        = this.graphBuilder.AddFilter(this.baseGrabFlt, "DS.NET Grabber");
                    if (errorCode < 0)
                    {
                        Marshal.ThrowExceptionForHR(errorCode);
                    }
                }
                if (this.AudioDevice != null)
                {
                    this.audioDeviceFilter = (IBaseFilter)Marshal.BindToMoniker(this.AudioDevice.MonikerString);
                    errorCode = this.graphBuilder.AddFilter(this.audioDeviceFilter, "Audio Capture Device");
                    if (errorCode < 0)
                    {
                        Marshal.ThrowExceptionForHR(errorCode);
                    }
                }
                if (this.VideoCompressor != null)
                {
                    this.videoCompressorFilter = (IBaseFilter)Marshal.BindToMoniker(this.VideoCompressor.MonikerString);
                    errorCode = this.graphBuilder.AddFilter(this.videoCompressorFilter, "Video Compressor");
                    if (errorCode < 0)
                    {
                        Marshal.ThrowExceptionForHR(errorCode);
                    }
                }
                if (this.AudioCompressor != null)
                {
                    this.audioCompressorFilter = (IBaseFilter)Marshal.BindToMoniker(this.AudioCompressor.MonikerString);
                    errorCode = this.graphBuilder.AddFilter(this.audioCompressorFilter, "Audio Compressor");
                    if (errorCode < 0)
                    {
                        Marshal.ThrowExceptionForHR(errorCode);
                    }
                }
                Guid capture     = PinCategory.Capture;
                Guid interleaved = MediaType.Interleaved;
                Guid riid        = typeof(IAMStreamConfig).GUID;
                if (this.captureGraphBuilder.FindInterface(ref capture, ref interleaved, this.videoDeviceFilter, ref riid, out obj3) != 0)
                {
                    interleaved = MediaType.Video;
                    if (this.captureGraphBuilder.FindInterface(ref capture, ref interleaved, this.videoDeviceFilter, ref riid, out obj3) != 0)
                    {
                        obj3 = null;
                    }
                }
                this.videoStreamConfig = obj3 as IAMStreamConfig;
                obj3        = null;
                capture     = PinCategory.Capture;
                interleaved = MediaType.Audio;
                riid        = typeof(IAMStreamConfig).GUID;
                if (this.captureGraphBuilder.FindInterface(ref capture, ref interleaved, this.audioDeviceFilter, ref riid, out obj3) != 0)
                {
                    obj3 = null;
                }
                this.audioStreamConfig = obj3 as IAMStreamConfig;
                this.mediaControl      = (IMediaControl)this.graphBuilder;
                if (this.videoSources != null)
                {
                    this.videoSources.Dispose();
                }
                this.videoSources = null;
                if (this.audioSources != null)
                {
                    this.audioSources.Dispose();
                }
                this.audioSources = null;
                if (this.propertyPages != null)
                {
                    this.propertyPages.Dispose();
                }
                this.propertyPages = null;
                this.videoCaps     = null;
                this.audioCaps     = null;
                obj3        = null;
                capture     = PinCategory.Capture;
                interleaved = MediaType.Interleaved;
                riid        = typeof(IAMTVTuner).GUID;
                if (this.captureGraphBuilder.FindInterface(ref capture, ref interleaved, this.videoDeviceFilter, ref riid, out obj3) != 0)
                {
                    interleaved = MediaType.Video;
                    if (this.captureGraphBuilder.FindInterface(ref capture, ref interleaved, this.videoDeviceFilter, ref riid, out obj3) != 0)
                    {
                        obj3 = null;
                    }
                }
                IAMTVTuner tuner = obj3 as IAMTVTuner;
                if (tuner != null)
                {
                    this.tuner = new Tuner(tuner);
                }
                this.graphState = GraphState.Created;
            }
        }
Esempio n. 28
0
        protected override void Decompose()
        {
            if (this.graphBuilder != null)
            {
                int hr = 0;

                OnGraphEnded();

                // Decompose the graph
                try { hr = (this.graphBuilder as IMediaControl).StopWhenReady(); }
                catch { }
                try { hr = (this.graphBuilder as IMediaControl).Stop(); }
                catch { }
                RemoveHandlers();


                FilterGraphTools.RemoveAllFilters(this.graphBuilder);

                if (this.crossbarHelper != null)
                {
                    this.crossbarHelper.Dispose();
                }
                this.crossbarHelper = null;
                if (this.tuner != null)
                {
                    Marshal.ReleaseComObject(this.tuner);
                }
                this.tuner = null;
                if (this.amTVAudio != null)
                {
                    Marshal.ReleaseComObject(this.amTVAudio);
                }
                this.amTVAudio = null;
                if (this.crossbar != null)
                {
                    Marshal.ReleaseComObject(this.crossbar);
                }
                this.crossbar = null;
                if (this.videoCaptureFilter != null)
                {
                    Marshal.ReleaseComObject(this.videoCaptureFilter);
                }
                this.videoCaptureFilter = null;
                if (this.audioCaptureFilter != null)
                {
                    Marshal.ReleaseComObject(this.audioCaptureFilter);
                }
                this.audioCaptureFilter = null;
                if (this.audioRenderer != null)
                {
                    Marshal.ReleaseComObject(this.audioRenderer);
                }
                this.audioRenderer = null;
                if (this.videoRenderer != null)
                {
                    Marshal.ReleaseComObject(this.videoRenderer);
                }
                this.videoRenderer = null;
                if (this.captureGraphBuilder != null)
                {
                    Marshal.ReleaseComObject(this.captureGraphBuilder);
                }
                this.captureGraphBuilder = null;

                if (useWPF)
                {
                    WPFStop();
                }

                try { rot.Dispose(); }
                catch { }
                try { Marshal.ReleaseComObject(this.graphBuilder); this.graphBuilder = null; }
                catch { }
            }
        }
Esempio n. 29
0
        // ------------------- Constructors ------------------

        /// <summary> Initialize this object with a DirectShow tuner </summary>
        public Tuner(IAMTVTuner tuner)
        {
            tvTuner = tuner;
        }
Esempio n. 30
0
 // Token: 0x0600036F RID: 879 RVA: 0x00014598 File Offset: 0x00012798
 public Tuner(IAMTVTuner tuner__1)
 {
     this.tvTuner = null;
     this.tvTuner = tuner__1;
 }
Esempio n. 31
0
        private void InitTuner(ICaptureGraphBuilder2 captureGraphBuilder)
        {
            Object o;
            var hr = captureGraphBuilder.FindInterface(null, null, videoDevice, typeof(IAMTVTuner).GUID, out o);
            if (hr >= 0)
            {

                tuner = (IAMTVTuner)o;
                //tuner.put_Mode(AMTunerModeType.TV);
                o = null;
                //find crossbar
                var list = findCrossbars(captureGraphBuilder, (IBaseFilter)tuner);
                /*hr = captureGraphBuilder.FindInterface(null, null, (IBaseFilter)Tuner, typeof(IAMCrossbar).GUID, out o);
                if (hr >= 0)
                {
                    crossbar = (IAMCrossbar)o;
                    InitCrossbar();
                }
                else
                    crossbar = null;
                */
                if (list.Count > 0)
                {
                    crossbar = (IAMCrossbar)list[0];
                    InitCrossbar();

                }
                o = null;
                // find amtvaudio
                hr = captureGraphBuilder.FindInterface(null, null, videoDevice, typeof(IAMTVAudio).GUID, out o);
                if (hr >= 0)
                {
                    TVAudio = (IAMTVAudio)o;

                }
                o = null;
                // find IAMAnalogVideoDecoder
                hr = captureGraphBuilder.FindInterface(null, null, videoDevice, typeof(IAMAnalogVideoDecoder).GUID, out o);

                if (hr >= 0)
                {
                    analogVideoDecoder = (o as IAMAnalogVideoDecoder);
                    AnalogVideoStandard avs;
                    analogVideoDecoder.get_TVFormat(out avs);

                }

                o = null;
            }
            else
                tuner = null;
        }
Esempio n. 32
0
		protected virtual void Dispose(bool disposing)
		{
			if (tvTuner != null)
				Marshal.ReleaseComObject(tvTuner); tvTuner = null;
		}
Esempio n. 33
0
        /// <summary>
        /// Initialize the graph
        /// </summary>
        public void InitGraph()
        {
            if (theDevice == null)
            {
                return;
            }

            object o;

            //Create the Graph
            graphBuilder = (IGraphBuilder) new FilterGraph();

#if DEBUG
            m_rot = new DsROTEntry(graphBuilder);
#endif

            //Create the Capture Graph Builder
            ICaptureGraphBuilder2 captureGraphBuilder = null;
            captureGraphBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            //Create the media control for controlling the graph
            mediaControl = (IMediaControl)this.graphBuilder;

            // Attach the filter graph to the capture graph
            int hr = captureGraphBuilder.SetFiltergraph(this.graphBuilder);
            DsError.ThrowExceptionForHR(hr);

            //Add the Video input device to the graph
            hr = graphBuilder.AddFilter(theDevice, "source filter");
            DsError.ThrowExceptionForHR(hr);

            //Add the Video compressor filter to the graph
            if (theCompressor != null)
            {
                hr = graphBuilder.AddFilter(theCompressor, "compressor filter");
                DsError.ThrowExceptionForHR(hr);
            }

            //Create the file writer part of the graph. SetOutputFileName does this for us, and returns the mux and sink
            IBaseFilter     mux;
            IFileSinkFilter sink;
            hr = captureGraphBuilder.SetOutputFileName(MediaSubType.Avi, textBox1.Text, out mux, out sink);
            DsError.ThrowExceptionForHR(hr);

            //Connect the device and compressor to the mux to render the capture part of the graph
            hr = captureGraphBuilder.RenderStream(PinCategory.Capture, MediaType.Video, theDevice, theCompressor, mux);
            DsError.ThrowExceptionForHR(hr);

            //Render any preview pin of the device
            hr = captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, theDevice, null, null);
            DsError.ThrowExceptionForHR(hr);

            tuner    = null;
            crossbar = null;

            hr = captureGraphBuilder.FindInterface(null, null, theDevice, typeof(IAMTVTuner).GUID, out o);
            if (hr >= 0)
            {
                tuner = (IAMTVTuner)o;
                o     = null;

                hr = captureGraphBuilder.FindInterface(null, null, theDevice, typeof(IAMCrossbar).GUID, out o);
                if (hr >= 0)
                {
                    crossbar = (IBaseFilter)o;
                    o        = null;
                }
            }

            //get the video window from the graph
            IVideoWindow videoWindow = null;
            videoWindow = (IVideoWindow)graphBuilder;

            //Set the owener of the videoWindow to an IntPtr of some sort (the Handle of any control - could be a form / button etc.)
            hr = videoWindow.put_Owner(panel1.Handle);
            DsError.ThrowExceptionForHR(hr);

            //Set the style of the video window
            hr = videoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren);
            DsError.ThrowExceptionForHR(hr);

            // Position video window in client rect of main application window
            hr = videoWindow.SetWindowPosition(0, 0, panel1.Width, panel1.Height);
            DsError.ThrowExceptionForHR(hr);

            // Make the video window visible
            hr = videoWindow.put_Visible(OABool.True);
            DsError.ThrowExceptionForHR(hr);

            Marshal.ReleaseComObject(mux);
            Marshal.ReleaseComObject(sink);
            Marshal.ReleaseComObject(captureGraphBuilder);
        }
Esempio n. 34
0
        protected override void Decompose()
        {
            if (this.graphBuilder != null)
            {
                int hr = 0;

                OnGraphEnded();

                // Decompose the graph
                try { hr = (this.graphBuilder as IMediaControl).StopWhenReady(); }
                catch { }
                try { hr = (this.graphBuilder as IMediaControl).Stop(); }
                catch { }
                RemoveHandlers();

                FilterGraphTools.RemoveAllFilters(this.graphBuilder);

                if (this.crossbarHelper != null) this.crossbarHelper.Dispose(); this.crossbarHelper = null;
                if (this.tuner != null) Marshal.ReleaseComObject(this.tuner); this.tuner = null;
                if (this.amTVAudio != null) Marshal.ReleaseComObject(this.amTVAudio); this.amTVAudio = null;
                if (this.crossbar != null) Marshal.ReleaseComObject(this.crossbar); this.crossbar = null;
                if (this.videoCaptureFilter != null) Marshal.ReleaseComObject(this.videoCaptureFilter); this.videoCaptureFilter = null;
                if (this.audioCaptureFilter != null) Marshal.ReleaseComObject(this.audioCaptureFilter); this.audioCaptureFilter = null;
                if (this.audioRenderer != null) Marshal.ReleaseComObject(this.audioRenderer); this.audioRenderer = null;
                if (this.videoRenderer != null) Marshal.ReleaseComObject(this.videoRenderer); this.videoRenderer = null;
                if (this.captureGraphBuilder != null) Marshal.ReleaseComObject(this.captureGraphBuilder); this.captureGraphBuilder = null;

                if (useWPF)
                    WPFStop();

                try { rot.Dispose(); }
                catch { }
                try { Marshal.ReleaseComObject(this.graphBuilder); this.graphBuilder = null; }
                catch { }
            }
        }