/// <summary> /// Adds a source filter to the graph and sets the input. /// </summary> protected override void AddSourceFilter() { if (!_useTsReader) { base.AddSourceFilter(); return; } // Render the file _sourceFilter = FilterLoader.LoadFilterFromDll("TsReader.ax", typeof(TsReader).GUID, true); IFileSourceFilter fileSourceFilter = (IFileSourceFilter)_sourceFilter; ITsReader tsReader = (ITsReader)_sourceFilter; tsReader.SetRelaxedMode(1); tsReader.SetTsReaderCallback(this); tsReader.SetRequestAudioChangeCallback(this); _graphBuilder.AddFilter(_sourceFilter, TSREADER_FILTER_NAME); if (_resourceLocator.NativeResourcePath.IsNetworkResource) { // _resourceAccessor points to an rtsp:// stream or network file var sourcePathOrUrl = SourcePathOrUrl; if (sourcePathOrUrl == null) { throw new IllegalCallException("The LiveRadioPlayer can only play network resources of type INetworkResourceAccessor"); } ServiceRegistration.Get <ILogger>().Debug("{0}: Initializing for stream '{1}'", PlayerTitle, sourcePathOrUrl); IDisposable accessEnsurer = null; if (IsLocalFilesystemResource) { accessEnsurer = ((ILocalFsResourceAccessor)_resourceAccessor).EnsureLocalFileSystemAccess(); } using (accessEnsurer) { int hr = fileSourceFilter.Load(SourcePathOrUrl, null); new HRESULT(hr).Throw(); } } else { //_resourceAccessor points to a local .ts file var localFileSystemResourceAccessor = _resourceAccessor as ILocalFsResourceAccessor; if (localFileSystemResourceAccessor == null) { throw new IllegalCallException("The LiveRadioPlayer can only play file resources of type ILocalFsResourceAccessor"); } using (localFileSystemResourceAccessor.EnsureLocalFileSystemAccess()) { ServiceRegistration.Get <ILogger>().Debug("{0}: Initializing for stream '{1}'", PlayerTitle, localFileSystemResourceAccessor.LocalFileSystemPath); fileSourceFilter.Load(localFileSystemResourceAccessor.LocalFileSystemPath, null); } } }
/// <summary> /// Adds the TsReader filter to the graph. /// </summary> protected override void AddSourceFilter() { // Render the file _sourceFilter = FilterLoader.LoadFilterFromDll("TsReader.ax", typeof(TsReader).GUID, true); IFileSourceFilter fileSourceFilter = (IFileSourceFilter)_sourceFilter; ITsReader tsReader = (ITsReader)_sourceFilter; tsReader.SetRelaxedMode(1); tsReader.SetTsReaderCallback(this); tsReader.SetRequestAudioChangeCallback(this); _graphBuilder.AddFilter(_sourceFilter, TSREADER_FILTER_NAME); _subtitleRenderer = new SubtitleRenderer(OnTextureInvalidated); _subtitleFilter = _subtitleRenderer.AddSubtitleFilter(_graphBuilder); if (_subtitleFilter != null) { _subtitleRenderer.RenderSubtitles = true; _subtitleRenderer.SetPlayer(this); } if (_resourceLocator.NativeResourcePath.IsNetworkResource) { // _resourceAccessor points to an rtsp:// stream or network file var sourcePathOrUrl = SourcePathOrUrl; if (sourcePathOrUrl == null) { throw new IllegalCallException("The TsVideoPlayer can only play network resources of type INetworkResourceAccessor"); } ServiceRegistration.Get <ILogger>().Debug("{0}: Initializing for stream '{1}'", PlayerTitle, sourcePathOrUrl); int hr = fileSourceFilter.Load(SourcePathOrUrl, null); new HRESULT(hr).Throw(); } else { // _resourceAccessor points to a local or remote mapped .ts file _localFsRaHelper = new LocalFsResourceAccessorHelper(_resourceAccessor); var localFileSystemResourceAccessor = _localFsRaHelper.LocalFsResourceAccessor; if (localFileSystemResourceAccessor == null) { throw new IllegalCallException("The TsVideoPlayer can only play file resources of type ILocalFsResourceAccessor"); } ServiceRegistration.Get <ILogger>().Debug("{0}: Initializing for stream '{1}'", PlayerTitle, localFileSystemResourceAccessor.LocalFileSystemPath); int hr = fileSourceFilter.Load(localFileSystemResourceAccessor.LocalFileSystemPath, null); new HRESULT(hr).Throw(); } // Init GraphRebuilder _graphRebuilder = new GraphRebuilder(_graphBuilder, _sourceFilter, OnAfterGraphRebuild) { PlayerName = PlayerTitle }; }
public string ChooseSrcFileName() { string ret = null; IFileSourceFilter fsrc = basefilter as IFileSourceFilter; if (fsrc != null) { using (var fd = new OpenFileDialog()) { fd.DefaultExt = "*.*"; if (fd.ShowDialog() == DialogResult.OK) { try { int hr = fsrc.Load(fd.FileName, null); DsError.ThrowExceptionForHR(hr); ret = fd.FileName; } catch (COMException e) { Graph.ShowCOMException(e, "Can't load file " + fd.FileName); } catch (Exception e) { MessageBox.Show(e.Message, "Exception caught while loading file " + fd.FileName); } } else if (Program.mainform.suggestURLs) { using (var rf = new RenderURLForm("Open URL")) { rf.ShowDialog(); if (rf.selectedURL != null) { try { int hr = fsrc.Load(rf.selectedURL, null); DsError.ThrowExceptionForHR(hr); ret = rf.selectedURL; } catch (COMException e) { Graph.ShowCOMException(e, "Can't open " + rf.selectedURL); } catch (Exception e) { MessageBox.Show(e.Message, "Exception caught while loading URL " + rf.selectedURL); } } } //using } }//using } return(ret); }
/// <summary> /// Adds the file source filter to the graph. /// </summary> protected override void AddFileSource() { // Render the file _fileSource = (IBaseFilter) new TsReader(); ITsReader tsReader = (ITsReader)_fileSource; tsReader.SetRelaxedMode(1); tsReader.SetTsReaderCallback(this); tsReader.SetRequestAudioChangeCallback(this); _graphBuilder.AddFilter(_fileSource, TSREADER_FILTER_NAME); _subtitleRenderer = new SubtitleRenderer(OnTextureInvalidated); _subtitleFilter = _subtitleRenderer.AddSubtitleFilter(_graphBuilder); if (_subtitleFilter != null) { _subtitleRenderer.RenderSubtitles = true; _subtitleRenderer.SetPlayer(this); } IFileSourceFilter f = (IFileSourceFilter)_fileSource; f.Load(_resourceAccessor.LocalFileSystemPath, null); // Init GraphRebuilder _graphRebuilder = new GraphRebuilder(_graphBuilder, _fileSource, OnAfterGraphRebuild) { PlayerName = PlayerTitle }; }
protected void LoadNetSrcURL() { int hr; hr = _fileSource.Load(Url, _netSrcMediaType); DsError.ThrowExceptionForHR(hr); }
private void Configure() { int hr; IFilterGraph2 filterGraph = (IFilterGraph2) new FilterGraph(); URLReader u = new URLReader(); m_iop = (IAMOpenProgress)u; IFileSourceFilter fsf = (IFileSourceFilter)u; IFileSourceFilter fsf2 = (IFileSourceFilter)u; hr = filterGraph.AddFilter((IBaseFilter)m_iop, "url"); DsError.ThrowExceptionForHR(hr); ThreadStart o2 = new ThreadStart(this.ThreadProc); Thread thread; thread = new Thread(o2); thread.Name = "cancellor"; thread.Start(); hr = fsf.Load(@"http://192.168.1.77/DShow/foo.avi", null); m_bAbort = (hr == -2147467260); // Aborted Marshal.ReleaseComObject(u); Marshal.ReleaseComObject(filterGraph); }
/// <summary>Initializes the editor.</summary> /// <param name="filepath">The path to the file.</param> public DvrmsMetadataEditor(string filepath) : base() { IFileSourceFilter sourceFilter = (IFileSourceFilter)ClassId.CoCreateInstance(ClassId.RecordingAttributes); sourceFilter.Load(filepath, null); _editor = (IStreamBufferRecordingAttribute)sourceFilter; }
private void AddLeadNetSrc() { int hr; string sinkUrl = _sessionInfo.SinkURL; // _eventThread = new Thread(new ThreadStart(EventListener)); // _eventThread.Start(); _netSrc = AddFilterByDevicePath(@"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\{E2B7DE03-38C5-11D5-91F6-00104BDB8FF9}", "LEAD Network Source (2.0"); LMNetSrc lmNetSrc = (LMNetSrc)_netSrc; Message = "Buffering stream " + sinkUrl + "..."; //lmNetSrc.CheckConnection(sinkUrl, 0, 5000); IFileSourceFilter fileSource = (IFileSourceFilter)_netSrc; if (fileSource == null) { throw new Exception("IFileSourceFilter not found on lmNetSrc"); } AMMediaType mediaType = new AMMediaType(); mediaType.majorType = MediaType.Stream; mediaType.subType = MediaSubType.LeadToolsStreamFormat; hr = fileSource.Load(sinkUrl, mediaType); DsError.ThrowExceptionForHR(hr); }
private IFilterGraph2 BuildGraph(string sFileName) { int hr; IFilterGraph2 graphBuilder = new FilterGraph() as IFilterGraph2; m_dsrot = new DsROTEntry(graphBuilder); try { // Get the file source filter m_Source = new AsyncReader() as IBaseFilter; // Add it to the graph hr = graphBuilder.AddFilter(m_Source, "Ds.NET AsyncReader"); Marshal.ThrowExceptionForHR(hr); // Set the file name IFileSourceFilter fsf = m_Source as IFileSourceFilter; hr = fsf.Load(sFileName, null); Marshal.ThrowExceptionForHR(hr); // Get the interface we are testing m_icgb2 = new CaptureGraphBuilder2() as ICaptureGraphBuilder2; } catch { Marshal.ReleaseComObject(graphBuilder); throw; } return(graphBuilder); }
private void Config2() { int hr; IFilterGraph2 fg; ISBE2Crossbar iSBE2Crossbar; fg = new FilterGraph() as IFilterGraph2; DsROTEntry rot = new DsROTEntry(fg); IBaseFilter streamBuffer = (IBaseFilter) new StreamBufferSource(); m_se = streamBuffer as ISBE2SpanningEvent; m_mc = fg as IMediaControl; hr = fg.AddFilter(streamBuffer, "SBS"); DsError.ThrowExceptionForHR(hr); IFileSourceFilter fs = streamBuffer as IFileSourceFilter; hr = fs.Load(@"C:\Users\Public\Recorded TV\Sample Media\win7_scenic-demoshort_raw.wtv", null); DsError.ThrowExceptionForHR(hr); iSBE2Crossbar = streamBuffer as ISBE2Crossbar; hr = iSBE2Crossbar.EnableDefaultMode(CrossbarDefaultFlags.None); DsError.ThrowExceptionForHR(hr); HookupGraphEventService(fg); RegisterForSBEGlobalEvents(); }
/// <summary> /// Adds the file source filter to the graph. /// </summary> protected override void AddFileSource() { // Render the file _fileSource = FilterLoader.LoadFilterFromDll("TsReader.ax", typeof(TsReader).GUID, true); ITsReader tsReader = (ITsReader)_fileSource; tsReader.SetRelaxedMode(1); tsReader.SetTsReaderCallback(this); tsReader.SetRequestAudioChangeCallback(this); _graphBuilder.AddFilter(_fileSource, TSREADER_FILTER_NAME); _subtitleRenderer = new SubtitleRenderer(OnTextureInvalidated); _subtitleFilter = _subtitleRenderer.AddSubtitleFilter(_graphBuilder); if (_subtitleFilter != null) { _subtitleRenderer.RenderSubtitles = true; _subtitleRenderer.SetPlayer(this); } IFileSourceFilter f = (IFileSourceFilter)_fileSource; f.Load(SourcePathOrUrl, null); // Init GraphRebuilder _graphRebuilder = new GraphRebuilder(_graphBuilder, _fileSource, OnAfterGraphRebuild) { PlayerName = PlayerTitle }; }
private void Config() { IFilterGraph2 fg; ISBE2Crossbar iSBE2Crossbar; fg = new FilterGraph() as IFilterGraph2; IBaseFilter streamBuffer = (IBaseFilter) new StreamBufferSource(); int hr; hr = fg.AddFilter(streamBuffer, "SBS"); DsError.ThrowExceptionForHR(hr); IFileSourceFilter fs = streamBuffer as IFileSourceFilter; hr = fs.Load(@"C:\Users\Public\Recorded TV\Sample Media\win7_scenic-demoshort_raw.wtv", null); DsError.ThrowExceptionForHR(hr); iSBE2Crossbar = streamBuffer as ISBE2Crossbar; hr = iSBE2Crossbar.EnableDefaultMode(CrossbarDefaultFlags.None); DsError.ThrowExceptionForHR(hr); IMediaControl mc = fg as IMediaControl; hr = mc.Run(); DsError.ThrowExceptionForHR(hr); System.Threading.Thread.Sleep(10); hr = iSBE2Crossbar.EnumStreams(out m_es); DsError.ThrowExceptionForHR(hr); Debug.Assert(m_es != null); }
/// <summary> /// Adds the file source filter to the graph. /// </summary> protected override void AddFileSource() { string strFile = _resourceAccessor.LocalFileSystemPath; // Render the file strFile = Path.Combine(strFile.ToLower(), @"BDMV\index.bdmv"); // only continue with playback if a feature was selected or the extension was m2ts. if (DoFeatureSelection(ref strFile)) { // find the SourceFilter CodecInfo sourceFilter = ServiceRegistration.Get <ISettingsManager>().Load <BDPlayerSettings>().BDSourceFilter; // load the SourceFilter if (TryAdd(sourceFilter)) { IFileSourceFilter fileSourceFilter = FilterGraphTools.FindFilterByInterface <IFileSourceFilter>(_graphBuilder); // load the file int hr = fileSourceFilter.Load(strFile, null); Marshal.ReleaseComObject(fileSourceFilter); DsError.ThrowExceptionForHR(hr); } else { BDPlayerBuilder.LogError("Unable to load DirectShowFilter: {0}", sourceFilter.Name); throw new Exception("Unable to load DirectShowFilter"); } } }
private void ConfigSourceFilter(IFileSourceFilter filter) { int hr = 0; // Requiered to connect with the avi splitter hr = filter.Load("foo.avi", null); Marshal.ThrowExceptionForHR(hr); }
/// <summary>Initializes the editor.</summary> /// <param name="filepath">The path to the file.</param> public MCRecMetadataEditor(string filepath) : base(filepath) { _editor = (IStreamBufferRecordingAttribute) new StreamBufferRecordingAttributes();//ClassId.CoCreateInstance(ClassId.RecordingAttributes); IFileSourceFilter sourceFilter = (IFileSourceFilter)_editor; sourceFilter.Load(filepath, null); }
/// <summary>Get all of the attributes on a file.</summary> /// <returns>A collection of the attributes from the file.</returns> public static IDictionary <string, object> GetAttributes(string path) { IFileSourceFilter sourceFilter = (IFileSourceFilter)Activator.CreateInstance <StreamBufferRecordingAttributes>(); sourceFilter.Load(path, null); IStreamBufferRecordingAttribute editor = (IStreamBufferRecordingAttribute)sourceFilter; return(GetAttributes(editor)); }
private IFilterGraph2 BuildGraph(string sFileName) { int hr; IBaseFilter ibfRenderer = null; IBaseFilter ibfAVISource = null; IPin IPinIn = null; IPin IPinOut = null; IFilterGraph2 graphBuilder = new FilterGraph() as IFilterGraph2; m_dsrot = new DsROTEntry(graphBuilder); try { // Get the file source filter ibfAVISource = new AsyncReader() as IBaseFilter; // Add it to the graph hr = graphBuilder.AddFilter(ibfAVISource, "Ds.NET AsyncReader"); Marshal.ThrowExceptionForHR(hr); // Set the file name IFileSourceFilter fsf = ibfAVISource as IFileSourceFilter; hr = fsf.Load(sFileName, null); Marshal.ThrowExceptionForHR(hr); IPinOut = DsFindPin.ByDirection(ibfAVISource, PinDirection.Output, 0); // Get the default video renderer ibfRenderer = (IBaseFilter) new VideoRendererDefault(); // Add it to the graph hr = graphBuilder.AddFilter(ibfRenderer, "Ds.NET VideoRendererDefault"); Marshal.ThrowExceptionForHR(hr); IPinIn = DsFindPin.ByDirection(ibfRenderer, PinDirection.Input, 0); hr = graphBuilder.Connect(IPinOut, IPinIn); Marshal.ThrowExceptionForHR(hr); } catch { Marshal.ReleaseComObject(graphBuilder); throw; } finally { Marshal.ReleaseComObject(ibfAVISource); Marshal.ReleaseComObject(ibfRenderer); Marshal.ReleaseComObject(IPinIn); Marshal.ReleaseComObject(IPinOut); } return(graphBuilder); }
private void BuildGraph(string sFileName, bool bLeft) { int hr; IBaseFilter ibfFile = null; IBaseFilter ibfFilter = null; IBaseFilter ibfRender = null; IDMOWrapperFilter dmoWrapperFilter = null; ICaptureGraphBuilder2 icgb = (ICaptureGraphBuilder2) new CaptureGraphBuilder2(); graphBuilder = (IFilterGraph2) new FilterGraph(); #if DEBUG m_rot = new DsROTEntry(graphBuilder); #endif hr = icgb.SetFiltergraph(graphBuilder); DsError.ThrowExceptionForHR(hr); // Add a DMO Wrapper Filter ibfFilter = (IBaseFilter) new DMOWrapperFilter(); dmoWrapperFilter = (IDMOWrapperFilter)ibfFilter; // Since I know the guid of the DMO I am looking for, I can do this. hr = dmoWrapperFilter.Init(new Guid("{EAB6CBA9-78DD-4ae4-9A69-1CE1C55369F6}"), DMOCategory.AudioEffect); DMOError.ThrowExceptionForHR(hr); // Add it to the Graph hr = graphBuilder.AddFilter(ibfFilter, "DMO Filter"); DsError.ThrowExceptionForHR(hr); ibfRender = (IBaseFilter) new AudioRender(); hr = graphBuilder.AddFilter(ibfRender, "Renderer"); DsError.ThrowExceptionForHR(hr); ibfFile = (IBaseFilter) new AsyncReader(); hr = graphBuilder.AddFilter(ibfFile, "Reader"); DsError.ThrowExceptionForHR(hr); IFileSourceFilter ifileSink = (IFileSourceFilter)ibfFile; hr = ifileSink.Load(sFileName, null); DsError.ThrowExceptionForHR(hr); hr = icgb.RenderStream(null, null, ibfFile, null, ibfFilter); DsError.ThrowExceptionForHR(hr); IPin iPin = DsFindPin.ByDirection(ibfFilter, PinDirection.Output, bLeft ? 0 : 1); hr = icgb.RenderStream(null, null, iPin, null, ibfRender); DsError.ThrowExceptionForHR(hr); Marshal.ReleaseComObject(ibfRender); Marshal.ReleaseComObject(dmoWrapperFilter); Marshal.ReleaseComObject(iPin); }
private void LoadNetSrcURL() { int hr; AMMediaType mediaType = new AMMediaType(); mediaType.majorType = MediaType.Stream; mediaType.subType = MediaSubType.LeadToolsStreamFormat; hr = _fileSource.Load(Url, mediaType); DsError.ThrowExceptionForHR(hr); DsUtils.FreeAMMediaType(mediaType); }
private void Config() { m_fg = new FilterGraph() as IFilterGraph2; IBaseFilter streamBuffer = (IBaseFilter) new StreamBufferSource(); int hr; hr = m_fg.AddFilter(streamBuffer, "SBS"); IFileSourceFilter fs = streamBuffer as IFileSourceFilter; hr = fs.Load(@"C:\Users\Public\Recorded TV\Sample Media\win7_scenic-demoshort_raw.wtv", null); m_ISBE2Crossbar = streamBuffer as ISBE2Crossbar; }
public DVRtoMPEG2TS(StreamSourceInfo sourceConfig, OpenGraphRequest openGraphRequest) : base(sourceConfig, openGraphRequest) { AppLogger.Message("In DVRtoMPEG2TS - CurrentProfile is " + CurrentProfile.Name); InitializeSink(); _captureFilter = AddFilterByName(FilterCategory.LegacyAmFilterCategory, "LEAD DVR Source"); IFileSourceFilter fileSource = (IFileSourceFilter)_captureFilter; String[] sourceNameParts = sourceConfig.SourceName.Split('-'); DVRSettings dvrSettings = DVRSettings.LoadFromFile(); int hr = fileSource.Load(dvrSettings.RootFolder + sourceNameParts[0] + @"/Stream.LBL", null); DsError.ThrowExceptionForHR(hr); ILMDVRSource sourceControl = (ILMDVRSource)_captureFilter; sourceControl.ResetToDefaultsEx(LMDVRSource_APILEVEL.LMDVRSource_APILEVEL_1); _demux = AddFilterByName(FilterCategory.LegacyAmFilterCategory, "LEAD MPEG2 Transport Demultiplexer"); _demuxControl = (ILMMpgDmx)_demux; _demuxControl.AutoLive = true; _demuxControl.AutoLiveTolerance = .5; // _currentVideoSettings = new VideoSettings(); // _currentVideoSettings.CodecType = CurrentProfile.Video.CodecType; ConnectFilters(_captureFilter, "Output", _demux, "Input 01"); if (CurrentProfile.Video != null) { VideoSettings settings = CurrentProfile.Video; _videoDecoder = AddFilterByName(FilterCategory.LegacyAmFilterCategory, "LEAD H264 Decoder (3.0)"); _videoEncoder = AddFilterByName(FilterCategory.LegacyAmFilterCategory, "LEAD H264 Encoder (4.0)"); ConnectFilters(_demux, "H.264 Video", _videoDecoder, "XForm In"); ConnectFilters(_videoDecoder, "XForm Out", _videoEncoder, "XForm In"); LMH264EncoderLib.ILMH264Encoder encoderConfig = (LMH264EncoderLib.ILMH264Encoder)_videoEncoder; encoderConfig.EnableRateControl = true; encoderConfig.BitRate = settings.ConstantBitRate * 1024; ConnectFilterToMux(_videoEncoder, "XForm Out", "Input 01"); } else { ConnectFilterToMux(_demux, "H.264 Video", "Input 01"); } ConnectMuxToSink(); }
private void AddLeadNetSrc(string url) { int hr; _netSrc = AddFilterByDevicePath(@"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\{E2B7DE03-38C5-11D5-91F6-00104BDB8FF9}", "LEAD Network Source (2.0"); LMNetSrc lmNetSrc = (LMNetSrc)_netSrc; IFileSourceFilter fileSource = (IFileSourceFilter)_netSrc; if (fileSource == null) { throw new Exception("IFileSourceFilter not found on lmNetSrc"); } AMMediaType mediaType = new AMMediaType(); mediaType.majorType = MediaType.Stream; mediaType.subType = new Guid("8256426B-28BF-4EBD-8EF4-306913875F34"); hr = fileSource.Load(url, mediaType); DsError.ThrowExceptionForHR(hr); }
/// <summary> /// Performs the actual connection to the sink, then connects the LTNetSource to the LTNetDmx /// </summary> /// <param name="ltsfUrl">fully qualified url in ltsf:// format</param> private void DoConnect(string ltsfUrl) { //do network connection at DirectShow level int hr; netFileSource = (IFileSourceFilter)netSource; if (netFileSource == null) { throw new Exception("IFileSourceFilter not found on netSource"); } AMMediaType mediaType = new AMMediaType(); mediaType.majorType = MediaType.Stream; mediaType.subType = MediaSubType.LeadToolsStreamFormat; hr = netFileSource.Load(ltsfUrl, mediaType); DsError.ThrowExceptionForHR(hr); DsUtils.FreeAMMediaType(mediaType); }
/// <summary> /// Add the LEAD DVR Source filter to a graph (builder) and /// load the fileSource using the associated input graph's /// source name (from sourceConfig). For example, if the output /// graph source name was "Vid1-RTSP" then the input graph /// source name will have a name of "Vid1". /// <DVRSourceName> --> <LeftOfSinkSourceName> /// Vid1-RTSP (the output graph source name) --> Vid1 (the input graph source name) /// </summary> public static IBaseFilter GetAndConfigureDVRSourceForSink(IGraphBuilder builder, StreamSourceInfo sourceConfig) { IBaseFilter result = FilterGraphTools.AddFilterByName(builder, FilterCategory.LegacyAmFilterCategory, "LEAD DVR Source"); if (result == null) { throw new Exception("The LEADTOOLS DVR Source filter is not registered"); } IFileSourceFilter fileSource = (IFileSourceFilter)result; String[] sourceNameParts = sourceConfig.SourceName.Split('-'); DVRSettings dvrSettings = DVRSettings.LoadFromFile(); int hr = fileSource.Load(dvrSettings.RootFolder + sourceNameParts[0] + @"/Stream.LBL", null); DsError.ThrowExceptionForHR(hr); ILMDVRSource sourceControl = (ILMDVRSource)result; sourceControl.ResetToDefaultsEx(LMDVRSource_APILEVEL.LMDVRSource_APILEVEL_1); return(result); }
private void Configure2() { int hr; IFilterGraph2 filterGraph = (IFilterGraph2) new FilterGraph(); URLReader u = new URLReader(); m_iop = (IAMOpenProgress)u; IFileSourceFilter fsf = (IFileSourceFilter)u; hr = filterGraph.AddFilter((IBaseFilter)m_iop, "url"); DsError.ThrowExceptionForHR(hr); ThreadStart o2 = new ThreadStart(this.ThreadProc2); Thread thread; thread = new Thread(o2); thread.Name = "cancellor2"; thread.Start(); hr = fsf.Load(@"http://www.LimeGreenSocks.com/test.avi", null); DsError.ThrowExceptionForHR(hr); // -2147467260 m_bLoaded = true; ICaptureGraphBuilder2 icgb = (ICaptureGraphBuilder2) new CaptureGraphBuilder2(); hr = icgb.SetFiltergraph(filterGraph); DsError.ThrowExceptionForHR(hr); hr = icgb.RenderStream(null, null, u, null, null); ((IMediaControl)filterGraph).Run(); while (!m_bQuery) { System.Windows.Forms.Application.DoEvents(); } }
private void SetupGraph2() { int hr; // Get a ICaptureGraphBuilder2 to help build the graph ICaptureGraphBuilder2 icgb2 = (ICaptureGraphBuilder2)new CaptureGraphBuilder2(); try { // Get the graphbuilder object IFilterGraph2 graphBuilder2 = (IFilterGraph2)new FilterGraph(); m_imc2 = graphBuilder2 as IMediaControl; // Link the ICaptureGraphBuilder2 to the IFilterGraph2 hr = icgb2.SetFiltergraph(graphBuilder2); DsError.ThrowExceptionForHR(hr); IBaseFilter streamBuffer = (IBaseFilter)new StreamBufferSource(); hr = graphBuilder2.AddFilter(streamBuffer, "Stream buffer sink"); DsError.ThrowExceptionForHR(hr); IFileSourceFilter sbfsf = (IFileSourceFilter)streamBuffer; hr = sbfsf.Load(Environment.ExpandEnvironmentVariables(FILENAME), null); DsError.ThrowExceptionForHR(hr); RenderPins(streamBuffer, icgb2); m_cb = streamBuffer as ISBE2Crossbar; ISBE2GlobalEvent2 ge2 = streamBuffer as ISBE2GlobalEvent2; } finally { if (icgb2 != null) { Marshal.ReleaseComObject(icgb2); } } }
/// <summary> /// Adds the file source filter to the graph. /// </summary> protected override void AddFileSource() { if (!_useTsReader) { base.AddFileSource(); return; } // Render the file _fileSource = (IBaseFilter) new TsReader(); ITsReader tsReader = (ITsReader)_fileSource; tsReader.SetRelaxedMode(1); tsReader.SetTsReaderCallback(this); tsReader.SetRequestAudioChangeCallback(this); _graphBuilder.AddFilter(_fileSource, TSREADER_FILTER_NAME); IFileSourceFilter f = (IFileSourceFilter)_fileSource; f.Load(SourcePathOrUrl, null); }
private void Config() { int hr; ISBE2Crossbar ISBE2Crossbar; IFilterGraph2 fg; fg = new FilterGraph() as IFilterGraph2; IBaseFilter streamBuffer = (IBaseFilter) new StreamBufferSource(); hr = fg.AddFilter(streamBuffer, "SBS"); IFileSourceFilter fs = streamBuffer as IFileSourceFilter; hr = fs.Load(@"C:\Users\Public\Recorded TV\Sample Media\win7_scenic-demoshort_raw.wtv", null); ISBE2Crossbar = streamBuffer as ISBE2Crossbar; hr = ISBE2Crossbar.EnableDefaultMode(CrossbarDefaultFlags.None); DsError.ThrowExceptionForHR(hr); hr = ISBE2Crossbar.GetInitialProfile(out m_pProfile); DsError.ThrowExceptionForHR(hr); }
/// <summary> /// Adds a source filter to the graph and sets the input. /// </summary> protected override void AddSourceFilter() { // get a local file system path - will mount via DOKAN when resource is not on the local system ILocalFsResourceAccessor lfsr; if (!_resourceLocator.TryCreateLocalFsAccessor(out lfsr)) { throw new IllegalCallException("The BDPlayer can only play file system resources"); } string strFile = lfsr.LocalFileSystemPath; // Render the file strFile = Path.Combine(strFile.ToLower(), @"BDMV\index.bdmv"); // only continue with playback if a feature was selected or the extension was m2ts. if (DoFeatureSelection(ref strFile)) { // find the SourceFilter CodecInfo sourceFilter = ServiceRegistration.Get <ISettingsManager>().Load <BDPlayerSettings>().BDSourceFilter; // load the SourceFilter if (TryAdd(sourceFilter)) { IFileSourceFilter fileSourceFilter = FilterGraphTools.FindFilterByInterface <IFileSourceFilter>(_graphBuilder); // load the file int hr = fileSourceFilter.Load(strFile, null); Marshal.ReleaseComObject(fileSourceFilter); new HRESULT(hr).Throw(); } else { BDPlayerBuilder.LogError("Unable to load DirectShowFilter: {0}", sourceFilter.Name); throw new Exception("Unable to load DirectShowFilter"); } } }
public bool Transcode(TranscodeInfo info, VideoFormat format, Quality quality, Standard standard) { try { if (!Supports(format)) { return(false); } string ext = System.IO.Path.GetExtension(info.file); if (ext.ToLower() != ".dvr-ms" && ext.ToLower() != ".sbe") { Log.Info("DVRMS2WMV: wrong file format"); return(false); } Log.Info("DVRMS2WMV: create graph"); graphBuilder = (IGraphBuilder) new FilterGraph(); _rotEntry = new DsROTEntry((IFilterGraph)graphBuilder); Log.Info("DVRMS2WMV: add streambuffersource"); bufferSource = (IStreamBufferSource) new StreamBufferSource(); IBaseFilter filter = (IBaseFilter)bufferSource; graphBuilder.AddFilter(filter, "SBE SOURCE"); Log.Info("DVRMS2WMV: load file:{0}", info.file); IFileSourceFilter fileSource = (IFileSourceFilter)bufferSource; int hr = fileSource.Load(info.file, null); //add mpeg2 audio/video codecs string strVideoCodec = ""; string strAudioCodec = ""; using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.MPSettings()) { strVideoCodec = xmlreader.GetValueAsString("mytv", "videocodec", "MPC - MPEG-2 Video Decoder (Gabest)"); strAudioCodec = xmlreader.GetValueAsString("mytv", "audiocodec", "MPC - MPA Decoder Filter"); } Log.Info("DVRMS2WMV: add mpeg2 video codec:{0}", strVideoCodec); Mpeg2VideoCodec = DirectShowUtil.AddFilterToGraph(graphBuilder, strVideoCodec); if (hr != 0) { Log.Error("DVRMS2WMV:FAILED:Add mpeg2 video to filtergraph :0x{0:X}", hr); Cleanup(); return(false); } Log.Info("DVRMS2WMV: add mpeg2 audio codec:{0}", strAudioCodec); Mpeg2AudioCodec = DirectShowUtil.AddFilterToGraph(graphBuilder, strAudioCodec); if (Mpeg2AudioCodec == null) { Log.Error("DVRMS2WMV:FAILED:unable to add mpeg2 audio codec"); Cleanup(); return(false); } Log.Info("DVRMS2WMV: connect streambufer source->mpeg audio/video decoders"); //connect output #0 of streambuffer source->mpeg2 audio codec pin 1 //connect output #1 of streambuffer source->mpeg2 video codec pin 1 IPin pinOut0, pinOut1; IPin pinIn0, pinIn1; pinOut0 = DsFindPin.ByDirection((IBaseFilter)bufferSource, PinDirection.Output, 0); //audio pinOut1 = DsFindPin.ByDirection((IBaseFilter)bufferSource, PinDirection.Output, 1); //video if (pinOut0 == null || pinOut1 == null) { Log.Error("DVRMS2WMV:FAILED:unable to get pins of source"); Cleanup(); return(false); } pinIn0 = DsFindPin.ByDirection(Mpeg2VideoCodec, PinDirection.Input, 0); //video pinIn1 = DsFindPin.ByDirection(Mpeg2AudioCodec, PinDirection.Input, 0); //audio if (pinIn0 == null || pinIn1 == null) { Log.Error("DVRMS2WMV:FAILED:unable to get pins of mpeg2 video/audio codec"); Cleanup(); return(false); } hr = graphBuilder.Connect(pinOut0, pinIn1); if (hr != 0) { Log.Error("DVRMS2WMV:FAILED:unable to connect audio pins :0x{0:X}", hr); Cleanup(); return(false); } hr = graphBuilder.Connect(pinOut1, pinIn0); if (hr != 0) { Log.Error("DVRMS2WMV:FAILED:unable to connect video pins :0x{0:X}", hr); Cleanup(); return(false); } string outputFilename = System.IO.Path.ChangeExtension(info.file, ".wmv"); if (!AddWmAsfWriter(outputFilename, quality, standard)) { return(false); } Log.Info("DVRMS2WMV: start pre-run"); mediaControl = graphBuilder as IMediaControl; mediaSeeking = bufferSource as IStreamBufferMediaSeeking; mediaEvt = graphBuilder as IMediaEventEx; mediaPos = graphBuilder as IMediaPosition; //get file duration long lTime = 5 * 60 * 60; lTime *= 10000000; long pStop = 0; hr = mediaSeeking.SetPositions(new DsLong(lTime), AMSeekingSeekingFlags.AbsolutePositioning, new DsLong(pStop), AMSeekingSeekingFlags.NoPositioning); if (hr == 0) { long lStreamPos; mediaSeeking.GetCurrentPosition(out lStreamPos); // stream position m_dDuration = lStreamPos; lTime = 0; mediaSeeking.SetPositions(new DsLong(lTime), AMSeekingSeekingFlags.AbsolutePositioning, new DsLong(pStop), AMSeekingSeekingFlags.NoPositioning); } double duration = m_dDuration / 10000000d; Log.Info("DVRMS2WMV: movie duration:{0}", Util.Utils.SecondsToHMSString((int)duration)); hr = mediaControl.Run(); if (hr != 0) { Log.Error("DVRMS2WMV:FAILED:unable to start graph :0x{0:X}", hr); Cleanup(); return(false); } int maxCount = 20; while (true) { long lCurrent; mediaSeeking.GetCurrentPosition(out lCurrent); double dpos = (double)lCurrent; dpos /= 10000000d; System.Threading.Thread.Sleep(100); if (dpos >= 2.0d) { break; } maxCount--; if (maxCount <= 0) { break; } } Log.Info("DVRMS2WMV: pre-run done"); Log.Info("DVRMS2WMV: Get duration of movie"); mediaControl.Stop(); FilterState state; mediaControl.GetState(500, out state); GC.Collect(); GC.Collect(); GC.Collect(); GC.WaitForPendingFinalizers(); Log.Info("DVRMS2WMV: reconnect mpeg2 video codec->ASF WM Writer"); graphBuilder.RemoveFilter(fileWriterbase); if (!AddWmAsfWriter(outputFilename, quality, standard)) { return(false); } Log.Info("DVRMS2WMV: Start transcoding"); hr = mediaControl.Run(); if (hr != 0) { Log.Error("DVRMS2WMV:FAILED:unable to start graph :0x{0:X}", hr); Cleanup(); return(false); } } catch (Exception e) { // TODO: Handle exceptions. Log.Error("unable to transcode file:{0} message:{1}", info.file, e.Message); return(false); } return(true); }