NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public Developers v
« Previous 1 … 8 9 10 11 12 … 93 Next »
Using Graphs in C#

 
  • 0 Vote(s) - 0 Average
Using Graphs in C#
bgowland
Offline

Posting Freak

West Yorkshire, UK
Posts: 4,583
Threads: 384
Joined: Dec 2004
#11
2013-01-15, 11:56 PM (This post was last modified: 2013-01-16, 05:45 AM by bgowland.)
Martin - you're right, it does look harder than it is. There's a steep (but short) learning curve but once you have the basics down, it will make sense.

Some snippets of code using DirectShow.NET...

A basic graph builder class including code to clean up. I've included two filters to use in the next snippets.

Code:
public class DvbRadioGraphBuilder : IDisposable
{
    DsROTEntry rot = null;
    IFilterGraph2 graph = null;
    IBaseFilter lameEncoder = null;
    IBaseFilter fileWriter = null;
    ...

    public DvbRadioGraphBuilder(object ParentLog, bool AddToROT)
    {
        graph = (IFilterGraph2) new FilterGraph();
        rot = new DsROTEntry(graph);
    }

    ...

    protected void Decompose()
    {
        int hr = 0;
        try
        {
            // Decompose the graph
            FilterState pfs;
            if (graph != null)
            {
                hr = (graph as DirectShowLib.IMediaControl).GetState(500, out pfs);
                if (pfs != FilterState.Stopped)
                {
                    //
                    // Not sure why I call both StopWhenReady() and Stop()...there must have been a reason
                    //
                    hr = (graph as DirectShowLib.IMediaControl).StopWhenReady();
                    hr = (graph as DirectShowLib.IMediaControl).Stop();
                }
            }

            FilterGraphTools.RemoveAllFilters(graph);

            //
            // Release or dispose of all of the DShow components here
            //

            ...

            if (lameEncoder != null)
            {
                Marshal.ReleaseComObject(lameEncoder);
                lameEncoder = null;
            }
            if (fileWriter != null)
            {
                Marshal.ReleaseComObject(fileWriter);
                fileWriter = null;
            }
            if (rot != null)
            {
                rot.Dispose();
                rot = null;
            }
            if (graph != null)
            {
                Marshal.ReleaseComObject(graph);
                graph = null;
            }
        }
        catch (Exception e)
        {
            // Handle exception
        }
    }

    #region IDisposable Members
    public void Dispose()
    {
        Decompose();
    }
    #endregion
}
Adding filters to a graph.

Code:
private bool AddLAMEEncoderFilter()
    {
        int hr = 0;
        DsDevice[] devices;
        bool FoundLAMEEncoder = false;

        try
        {
            //
            // Get all of the filters normally listed in the "DirectShow Filters" category of GraphEdit
            //
            devices = DsDevice.GetDevicesOfCat(FilterCategory.LegacyAmFilterCategory);

            if (devices.Length == 0)
                Log.WriteLine("No LegacyAmFilterCategory filters found!!!!");
            else
            {
                for (int i = 0; i < devices.Length; i++)
                {
                    try
                    {
                        if (devices[i].Name.Equals("LAME Audio Encoder"))
                        {
                            FoundLAMEEncoder = true;
                            hr = graph.AddSourceFilterForMoniker(devices[i].Mon, null, devices[i].Name, out lameEncoder);
                            DsError.ThrowExceptionForHR(hr);
                            break;
                        }
                    }
                    catch (NullReferenceException e)
                    {
                        // Handle exception
                    }
                }
            }
        }
        catch (Exception e)
        {
            // Handle exception
        }
        return FoundLAMEEncoder;
    }

Connecting filters.

Code:
private bool ConnectFiltersForRadio(string RecordingName)
    {
        int hr = 0;
        ...
        IPin pinLameEncOut = null;
        IPin pinFileWriterIn = null;
        bool Success = false;

        try
        {
            IFileSinkFilter2 fs = (IFileSinkFilter2) fileWriter;
            hr = fs.SetMode(AMFileSinkFlags.None);
            DsError.ThrowExceptionForHR(hr);
            hr = fs.SetFileName(RecordingName, null);
            DsError.ThrowExceptionForHR(hr);

            ...

            //
            // The first parameter of FindPin(...) is the actual pin name as shown in GraphEdit
            //
            hr = lameEncoder.FindPin("Out", out pinLameEncOut);
            DsError.ThrowExceptionForHR(hr);

            hr = fileWriter.FindPin("Input", out pinFileWriterIn);
            DsError.ThrowExceptionForHR(hr);

            hr = graph.Connect(pinLameEncOut, pinFileWriterIn);
            DsError.ThrowExceptionForHR(hr);

            Success = true;
        }
        catch (Exception e)
        {
            // Handle exception
        }
        finally
        {
            ...
            if (pinLameEncOut != null)
                Marshal.ReleaseComObject(pinLameEncOut);
            if (pinFileWriterIn != null)
                Marshal.ReleaseComObject(pinFileWriterIn);
        }
        return Success;
    }
mvallevand
Online

Posting Freak

Ontario Canada
Posts: 52,770
Threads: 954
Joined: May 2006
#12
2013-01-16, 12:19 AM
Thanks Brian that is a good start so I don't need a web page. Now I need to be able to create a graph that doesn't crash, I see what sub sees.

Martin
bgowland
Offline

Posting Freak

West Yorkshire, UK
Posts: 4,583
Threads: 384
Joined: Dec 2004
#13
2013-01-16, 12:32 AM
If you can create a graph that works in GraphEdit then it should be fairly straight-forward in code using the methods I posted. The process is basically Create Graph -> Add Filters -> Find Pins -> Connect Pins -> Run.

On that final note, I realise I'd forgotten the "run" code but that's basically just
Code:
hr = (graph as IMediaControl).Run();
whurlston
Offline

Posting Freak

Posts: 7,885
Threads: 102
Joined: Nov 2006
#14
2013-01-16, 03:58 AM
Have you tried just using a basic File Dump filter? Of course that won't write the metadata and timing info data streams if that's handled by sub's TS writer though.
mvallevand
Online

Posting Freak

Ontario Canada
Posts: 52,770
Threads: 954
Joined: May 2006
#15
2013-01-16, 04:43 AM
SageDCT is already writing the file nicely. The problem is NextPVR (and XBMC) balk at the DVR style files it makes from Ceton (and HDHR Prime) with multiple PMT/PID's with only one being valid. Sub is suggesting that his writer might be able to demux this correctly on-the-fly.

Martin
whurlston
Offline

Posting Freak

Posts: 7,885
Threads: 102
Joined: Nov 2006
#16
2013-01-16, 04:49 AM
Ah, gotcha.
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,626
Threads: 767
Joined: Nov 2003
#17
2013-01-16, 06:25 AM
mvallevand Wrote:SageDCT is already writing the file nicely. The problem is NextPVR (and XBMC) balk at the DVR style files it makes from Ceton (and HDHR Prime) with multiple PMT/PID's with only one being valid. Sub is suggesting that his writer might be able to demux this correctly on-the-fly.
Actually no, it wouldn't fix that. It would fix other stuff though: getting the proper lively segment tv rolling buffer file, timing.info, and correct duration reporting problems.
mvallevand
Online

Posting Freak

Ontario Canada
Posts: 52,770
Threads: 954
Joined: May 2006
#18
2013-01-16, 05:43 PM
If the XBMC users have to run yet another program to post-process the file then this like isn't worth the effort. The rolling file has no major savings since the large master file from SageDCT still will be there as overhead, and NextPVR IMO live tv is more reliable with a big file. Also Timing.Info isn't used for LiveTV but if it is needed on the post-processed file, I have a utility for that too.

Martin
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,626
Threads: 767
Joined: Nov 2003
#19
2013-01-16, 06:27 PM
You'd have to come up with a more sophisticated graph if you wanted to correct the PMT. It's probably involve a tsreader filter -> demux -> mux -> 'NPVR Writer'.
mvallevand
Online

Posting Freak

Ontario Canada
Posts: 52,770
Threads: 954
Joined: May 2006
#20
2013-01-16, 11:34 PM (This post was last modified: 2013-01-16, 11:48 PM by mvallevand.)
What I was hoping to figure out was a way to use DVB Portal's HDTV Pump as the source, tell it to output PID's using something that I figure is similar to your lot of data algorithm directly to a file writer.

Martin
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)

Pages (2): « Previous 1 2


  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode