本文整理汇总了C#中IGraphBuilder.RemoveFilter方法的典型用法代码示例。如果您正苦于以下问题:C# IGraphBuilder.RemoveFilter方法的具体用法?C# IGraphBuilder.RemoveFilter怎么用?C# IGraphBuilder.RemoveFilter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGraphBuilder
的用法示例。
在下文中一共展示了IGraphBuilder.RemoveFilter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddFilterById
public static IBaseFilter AddFilterById(IGraphBuilder graph, Guid guid, string name)
{
Ensure.IsNotNull(Log, graph, "graph is null");
IBaseFilter filter = null;
try
{
var type = Type.GetTypeFromCLSID(guid);
filter = (IBaseFilter)Activator.CreateInstance(type);
var hr = graph.AddFilter(filter, name);
DsError.ThrowExceptionForHR(hr);
}
catch (Exception ex)
{
if (filter != null)
{
graph.RemoveFilter(filter);
Marshal.ReleaseComObject(filter);
filter = null;
}
Log.Fatal(string.Format("Filter {0} is not added to the graph", name) + ex);
}
return filter;
}
示例2: LoadSubtitles
public bool LoadSubtitles(IGraphBuilder graphBuilder, string filename)
{
LoadSettings();
MpcSubtitles.SetDefaultStyle(ref this.defStyle, this.overrideASSStyle);
if (selectionOff)
{
MpcSubtitles.SetShowForcedOnly(false);
}
else
{
MpcSubtitles.SetShowForcedOnly(!this.autoShow);
}
//remove DirectVobSub
DirectVobSubUtil.RemoveFromGraph(graphBuilder);
{
//remove InternalScriptRenderer as it takes subtitle pin
IBaseFilter isr = null;
DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.InternalScriptRenderer, out isr);
if (isr != null)
{
graphBuilder.RemoveFilter(isr);
DirectShowUtil.ReleaseComObject(isr);
}
}
FFDShowEngine.DisableFFDShowSubtitles(graphBuilder);
Size size = new Size(GUIGraphicsContext.Width, GUIGraphicsContext.Height);
// Get Default Language from MP Setting and parse it to MPC-HC Engine (needed for forced track)
string defaultLanguageCulture = "EN";
string localizedCINameSub = "EN";
int lcidCI = 0;
using (Settings xmlreader = new MPSettings())
{
try
{
if (g_Player.IsVideo && (g_Player.CurrentFile.ToUpperInvariant().Contains(@"\BDMV\INDEX.BDMV")))
{
localizedCINameSub = (xmlreader.GetValueAsString("bdplayer", "subtitlelanguage", "English"));
foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.NeutralCultures))
{
if (ci.EnglishName == localizedCINameSub)
{
lcidCI = ci.TextInfo.LCID;;
}
}
Log.Info("MpcEngine: Subtitle Blu-ray Player CultureInfo {0}", localizedCINameSub);
}
else
{
CultureInfo ci = new CultureInfo(xmlreader.GetValueAsString("subtitles", "language", defaultLanguageCulture));
lcidCI = ci.TextInfo.LCID;
Log.Info("MpcEngine: Subtitle VideoPlayer CultureInfo {0}", ci);
}
}
catch (Exception ex)
{
CultureInfo ci = new CultureInfo(defaultLanguageCulture);
lcidCI = ci.TextInfo.LCID;
Log.Error(
"MpcEngine: SelectSubtitleLanguage - unable to build CultureInfo, make sure MediaPortal.xml is not corrupted! - {0}",
ex);
}
}
return MpcSubtitles.LoadSubtitles(
DirectShowUtil.GetUnmanagedDevice(GUIGraphicsContext.DX9Device),
size, filename, graphBuilder, subPaths, lcidCI);
}
示例3: Transcode
//.........这里部分代码省略.........
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;
}
示例4: AddAudioRendererToGraph
//.........这里部分代码省略.........
}
catch (Exception e)
{
Log.Info("Exception in BindToMoniker({0}): {1}", filter.MonikerString, e.Message);
continue;
}
NewFilter.GetClassID(out classId2);
ReleaseComObject(NewFilter);
NewFilter = null;
if (classId1.Equals(classId2))
{
if (filter.Name == strFilterName)
{
Log.Info("filter already in graph");
if (setAsReferenceClock)
{
hr.Set((graphBuilder as IMediaFilter).SetSyncSource(pBasefilter[0] as IReferenceClock));
if (hr != 0)
{
Log.Warn("setAsReferenceClock sync source " + hr.ToDXString());
}
}
ReleaseComObject(pBasefilter[0]);
pBasefilter[0] = null;
bNeedAdd = false;
break;
}
else
{
Log.Info("remove " + filter.Name + " from graph");
pinOut = FindSourcePinOf(pBasefilter[0]);
graphBuilder.RemoveFilter(pBasefilter[0]);
bAllRemoved = true;
break;
}
} //if (classId1.Equals(classId2))
} //foreach (Filter filter in filters.AudioRenderers)
if (pBasefilter[0] != null)
{
ReleaseComObject(pBasefilter[0]);
}
} //while(!bAllRemoved)
ReleaseComObject(enumFilters);
} //if (hr>=0 && enumFilters!=null)
Log.Info("DirectShowUtils: Passed removing audio renderer");
if (!bNeedAdd)
{
return null;
}
// next add the new one...
foreach (Filter filter in Filters.AudioRenderers)
{
if (String.Compare(filter.Name, strFilterName, true) == 0)
{
Log.Info("DirectShowUtils: Passed finding Audio Renderer");
NewFilter = (IBaseFilter)Marshal.BindToMoniker(filter.MonikerString);
hr.Set(graphBuilder.AddFilter(NewFilter, strFilterName));
if (hr < 0)
{
Log.Error("failed:unable to add filter:{0} to graph", strFilterName);
NewFilter = null;
}
else
{
示例5: LoadSubtitles
public bool LoadSubtitles(IGraphBuilder graphBuilder, string filename)
{
LoadSettings();
MpcSubtitles.SetDefaultStyle(ref this.defStyle, this.overrideASSStyle);
if (selectionOff)
{
MpcSubtitles.SetShowForcedOnly(false);
}
else
{
MpcSubtitles.SetShowForcedOnly(!this.autoShow);
}
//remove DirectVobSub
DirectVobSubUtil.RemoveFromGraph(graphBuilder);
{
//remove InternalScriptRenderer as it takes subtitle pin
IBaseFilter isr = null;
DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.InternalScriptRenderer, out isr);
if (isr != null)
{
graphBuilder.RemoveFilter(isr);
DirectShowUtil.ReleaseComObject(isr);
}
}
FFDShowEngine.DisableFFDShowSubtitles(graphBuilder);
Size size = new Size(GUIGraphicsContext.Width, GUIGraphicsContext.Height);
return MpcSubtitles.LoadSubtitles(
DirectShowUtil.GetUnmanagedDevice(GUIGraphicsContext.DX9Device),
size, filename, graphBuilder, subPaths);
}
示例6: RemoveAllFilters
/// <summary>
/// Removes all filters from a DirectShow graph
/// </summary>
/// <param name="graphBuilder">The DirectShow graph to remove all the filters from</param>
protected static void RemoveAllFilters(IGraphBuilder graphBuilder)
{
if (graphBuilder == null)
return;
IEnumFilters enumFilters;
/* The list of filters from the DirectShow graph */
var filtersArray = new List<IBaseFilter>();
if (graphBuilder == null)
throw new ArgumentNullException("graphBuilder");
/* Gets the filter enumerator from the graph */
int hr = graphBuilder.EnumFilters(out enumFilters);
DsError.ThrowExceptionForHR(hr);
try
{
/* This array is filled with reference to a filter */
var filters = new IBaseFilter[1];
IntPtr fetched = IntPtr.Zero;
/* Get reference to all the filters */
while (enumFilters.Next(filters.Length, filters, fetched) == 0)
{
/* Add the filter to our array */
filtersArray.Add(filters[0]);
}
}
finally
{
/* Enum filters is a COM, so release that */
Marshal.ReleaseComObject(enumFilters);
}
/* Loop over and release each COM */
for (int i = 0; i < filtersArray.Count; i++)
{
graphBuilder.RemoveFilter(filtersArray[i]);
while (Marshal.ReleaseComObject(filtersArray[i]) > 0)
{}
}
}
示例7: SetupGraph
/// <summary> build the capture graph for grabber. </summary>
private void SetupGraph(string FileName)
{
int hr;
// Get the graphbuilder object
this.graphBuilder = new FilterGraph() as IGraphBuilder;
this.mediaControl = this.graphBuilder as IMediaControl;
this.mediaSeeking = this.graphBuilder as IMediaSeeking;
this.mediaEvent = this.graphBuilder as IMediaEvent;
try
{
// Get the SampleGrabber interface
this.sampleGrabber = new SampleGrabber() as ISampleGrabber;
this.sampleGrabberFilter = sampleGrabber as IBaseFilter;
ConfigureSampleGrabber(sampleGrabber);
// Add the frame grabber to the graph
hr = graphBuilder.AddFilter(sampleGrabberFilter, "Ds.NET Sample Grabber");
DsError.ThrowExceptionForHR(hr);
IBaseFilter aviSplitter = new AviSplitter() as IBaseFilter;
// Add the aviSplitter to the graph
hr = graphBuilder.AddFilter(aviSplitter, "Splitter");
DsError.ThrowExceptionForHR(hr);
// Have the graph builder construct its appropriate graph automatically
hr = this.graphBuilder.RenderFile(FileName, null);
DsError.ThrowExceptionForHR(hr);
#if DEBUG
m_rot = new DsROTEntry(graphBuilder);
#endif
// Remove the video renderer filter
IBaseFilter defaultVideoRenderer = null;
graphBuilder.FindFilterByName("Video Renderer", out defaultVideoRenderer);
graphBuilder.RemoveFilter(defaultVideoRenderer);
// Disconnect anything that is connected
// to the output of the sample grabber
IPin iPinSampleGrabberOut = DsFindPin.ByDirection(sampleGrabberFilter, PinDirection.Output, 0);
IPin iPinVideoIn;
hr = iPinSampleGrabberOut.ConnectedTo(out iPinVideoIn);
if (hr == 0)
{
// Disconnect the sample grabber output from the attached filters
hr = iPinVideoIn.Disconnect();
DsError.ThrowExceptionForHR(hr);
hr = iPinSampleGrabberOut.Disconnect();
DsError.ThrowExceptionForHR(hr);
}
else
{
// Try other way round because automatic renderer could not build
// graph including the sample grabber
IPin iPinAVISplitterOut = DsFindPin.ByDirection(aviSplitter, PinDirection.Output, 0);
IPin iPinAVISplitterIn;
hr = iPinAVISplitterOut.ConnectedTo(out iPinAVISplitterIn);
DsError.ThrowExceptionForHR(hr);
hr = iPinAVISplitterOut.Disconnect();
DsError.ThrowExceptionForHR(hr);
hr = iPinAVISplitterIn.Disconnect();
DsError.ThrowExceptionForHR(hr);
// Connect the avi splitter output to sample grabber
IPin iPinSampleGrabberIn = DsFindPin.ByDirection(sampleGrabberFilter, PinDirection.Input, 0);
hr = graphBuilder.Connect(iPinAVISplitterOut, iPinSampleGrabberIn);
DsError.ThrowExceptionForHR(hr);
}
// Add the null renderer to the graph
nullrenderer = new NullRenderer() as IBaseFilter;
hr = graphBuilder.AddFilter(nullrenderer, "Null renderer");
DsError.ThrowExceptionForHR(hr);
// Get the input pin of the null renderer
IPin iPinNullRendererIn = DsFindPin.ByDirection(nullrenderer, PinDirection.Input, 0);
// Connect the sample grabber to the null renderer
hr = graphBuilder.Connect(iPinSampleGrabberOut, iPinNullRendererIn);
DsError.ThrowExceptionForHR(hr);
// Read and cache the image sizes
SaveSizeInfo(sampleGrabber);
this.GetFrameStepInterface();
}
finally
{
}
}
示例8: OpenSource
/// <summary>
/// Opens the media by initializing the DirectShow graph
/// </summary>
protected virtual void OpenSource()
{
/* Make sure we clean up any remaining mess */
FreeResources();
if (m_sourceUri == null)
return;
string fileSource = m_sourceUri.OriginalString;
if (string.IsNullOrEmpty(fileSource))
return;
try
{
/* Creates the GraphBuilder COM object */
m_graph = new FilterGraphNoThread() as IGraphBuilder;
if (m_graph == null)
throw new Exception("Could not create a graph");
var filterGraph = m_graph as IFilterGraph2;
if (filterGraph == null)
throw new Exception("Could not QueryInterface for the IFilterGraph2");
IBaseFilter sourceFilter;
int hr;
// Set LAV Splitter
/* LAVSplitterSource reader = new LAVSplitterSource();
sourceFilter = reader as IBaseFilter;
var objectWithSite = reader as IObjectWithSite;
if (objectWithSite != null)
{
objectWithSite.SetSite(this);
}
hr = m_graph.AddFilter(sourceFilter, SplitterSource);
DsError.ThrowExceptionForHR(hr);*/
sourceFilter = DirectShowUtil.AddFilterToGraph(m_graph, SplitterSource, Guid.Empty);
IFileSourceFilter interfaceFile = (IFileSourceFilter)sourceFilter;
hr = interfaceFile.Load(fileSource, null);
DsError.ThrowExceptionForHR(hr);
// Set Video Codec
// Remove Pin
var videoPinFrom = DirectShowLib.DsFindPin.ByName(sourceFilter, "Video");
IPin videoPinTo;
if (videoPinFrom != null)
{
hr = videoPinFrom.ConnectedTo(out videoPinTo);
if (hr >= 0 && videoPinTo != null)
{
PinInfo pInfo;
videoPinTo.QueryPinInfo(out pInfo);
FilterInfo fInfo;
pInfo.filter.QueryFilterInfo(out fInfo);
DirectShowUtil.DisconnectAllPins(m_graph, pInfo.filter);
m_graph.RemoveFilter(pInfo.filter);
DsUtils.FreePinInfo(pInfo);
Marshal.ReleaseComObject(fInfo.pGraph);
Marshal.ReleaseComObject(videoPinTo);
videoPinTo = null;
}
Marshal.ReleaseComObject(videoPinFrom);
videoPinFrom = null;
}
DirectShowUtil.AddFilterToGraph(m_graph, VideoDecoder, Guid.Empty);
try
{
// Set Audio Codec
// Remove Pin
var audioPinFrom = DirectShowLib.DsFindPin.ByName(sourceFilter, "Audio");
IPin audioPinTo;
if (audioPinFrom != null)
{
hr = audioPinFrom.ConnectedTo(out audioPinTo);
if (hr >= 0 && audioPinTo != null)
{
PinInfo pInfo;
audioPinTo.QueryPinInfo(out pInfo);
FilterInfo fInfo;
pInfo.filter.QueryFilterInfo(out fInfo);
DirectShowUtil.DisconnectAllPins(m_graph, pInfo.filter);
m_graph.RemoveFilter(pInfo.filter);
DsUtils.FreePinInfo(pInfo);
Marshal.ReleaseComObject(fInfo.pGraph);
Marshal.ReleaseComObject(audioPinTo);
//.........这里部分代码省略.........
示例9: RemoveFromGraph
public static void RemoveFromGraph(IGraphBuilder graphBuilder)
{
IBaseFilter vob = null;
DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.DirectVobSubAutoload, out vob);
if (vob == null)
{
//Try the "normal" filter then.
DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.DirectVobSubNormal, out vob);
if (vob == null)
return;
}
Log.Info("VideoPlayerVMR9: DirectVobSub in graph, removing...");
// Check where video inputs are connected
IPin pinVideoIn = DsFindPin.ByDirection(vob, PinDirection.Input, 0);
IPin pinVideoOut = DsFindPin.ByDirection(vob, PinDirection.Output, 0);
//find directvobsub's video output pin source input pin
IPin pinVideoTo = null;
pinVideoOut.ConnectedTo(out pinVideoTo);
//find directvobsub's video input pin source output pin
IPin pinVideoFrom = null;
pinVideoIn.ConnectedTo(out pinVideoFrom);
int hr;
if (pinVideoFrom != null)
{
hr = pinVideoFrom.Disconnect();
if (hr != 0)
{
Log.Error("VideoPlayerVMR9: DirectVobSub failed disconnecting source pin");
}
}
if (pinVideoTo != null)
{
hr = pinVideoTo.Disconnect();
if (hr != 0)
{
Log.Error("VideoPlayerVMR9: DirectVobSub failed disconnecting destination pin");
}
}
//remove the DirectVobSub filter from the graph
graphBuilder.RemoveFilter(vob);
DirectShowUtil.ReleaseComObject(vob);
vob = null;
//reconnect the source output pin to the vmr9/evr filter
hr = graphBuilder.Connect(pinVideoFrom, pinVideoTo);
//hr = graphBuilder.Render(pinVideoFrom);
DirectShowUtil.ReleaseComObject(pinVideoFrom);
pinVideoFrom = null;
DirectShowUtil.ReleaseComObject(pinVideoTo);
pinVideoTo = null;
DirectShowUtil.ReleaseComObject(pinVideoOut);
pinVideoOut = null;
DirectShowUtil.ReleaseComObject(pinVideoIn);
pinVideoIn = null;
if (hr != 0)
Log.Error("VideoPlayerVMR9: Could not connect video out to video renderer: {0}", hr);
else
Log.Debug("VideoPlayerVMR9: DirectVobSub graph rebuild finished");
}
示例10: LoadSubtitles
public bool LoadSubtitles(IGraphBuilder graphBuilder, string filename)
{
FreeSubtitles();
LoadSettings();
{
//remove InternalScriptRenderer as it takes subtitle pin
IBaseFilter isr = null;
DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.InternalScriptRenderer, out isr);
if (isr != null)
{
graphBuilder.RemoveFilter(isr);
DirectShowUtil.ReleaseComObject(isr);
}
}
vobSub = (IDirectVobSub)DirectVobSubUtil.AddToGraph(graphBuilder);
if (vobSub == null)
return false;
{
//set style
Log.Debug("VideoPlayerVMR9: Setting DirectVobsub parameters");
LOGFONT logFont = new LOGFONT();
int txtcolor;
bool fShadow, fOutLine, fAdvancedRenderer = false;
int size = Marshal.SizeOf(typeof(LOGFONT));
vobSub.get_TextSettings(logFont, size, out txtcolor, out fShadow, out fOutLine, out fAdvancedRenderer);
FontStyle fontStyle = defStyle.fontIsBold ? FontStyle.Regular : FontStyle.Bold;
Font Subfont = new Font(defStyle.fontName, defStyle.fontSize, fontStyle, GraphicsUnit.Point,
(byte)defStyle.fontCharset);
Subfont.ToLogFont(logFont);
fShadow = defStyle.shadow > 0;
fOutLine = defStyle.isBorderOutline;
vobSub.put_TextSettings(logFont, size, defStyle.fontColor, fShadow, fOutLine, fAdvancedRenderer);
vobSub.put_FileName(filename);
bool fBuffer, fOnlyForced, fPolygonize;
vobSub.get_VobSubSettings(out fBuffer, out fOnlyForced, out fPolygonize);
vobSub.put_VobSubSettings(fBuffer, !this.autoShow, fPolygonize);
}
{
//load sub streams
IBaseFilter hms = null;
DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.HaaliGuid, out hms);
if (hms == null)
DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.LAVFilterSource, out hms);
if (hms == null)
DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.LAVFilter, out hms);
embeddedSelector = hms as IAMStreamSelect;
if (embeddedSelector != null)
{
AddStreams(embeddedSelector);
}
vobSub.get_LanguageCount(out extCount);
if (intSubs.Count > 0)
{
//if there are embedded subtitles,
//last stream of directvobsub is currently selected embedded subtitle
extCount--;
}
}
FFDShowEngine.DisableFFDShowSubtitles(graphBuilder);
Current = 0;
if (selectionOff)
{
Enable = false;
}
else
{
Enable = autoShow;
}
return true;
}
示例11: Transcode
//.........这里部分代码省略.........
{
Log.Error("DVRMS2DIVX:FAILED:unable to connect audio pins :0x{0:X}", hr);
Cleanup();
return false;
}
hr = graphBuilder.Connect(pinOut1, pinIn0);
if (hr != 0)
{
Log.Error("DVRMS2DIVX:FAILED:unable to connect video pins :0x{0:X}", hr);
Cleanup();
return false;
}
if (!AddCodecs(graphBuilder, info)) return false;
// hr=(graphBuilder as IMediaFilter).SetSyncSource(null);
// if (hr!=0)
// Log.Error("DVRMS2DIVX:FAILED:to SetSyncSource :0x{0:X}",hr);
mediaControl = graphBuilder as IMediaControl;
mediaSeeking = bufferSource as IStreamBufferMediaSeeking;
mediaEvt = graphBuilder as IMediaEventEx;
mediaPos = graphBuilder as IMediaPosition;
//get file duration
Log.Info("DVRMS2DIVX: Get duration of movie");
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("DVRMS2DIVX: movie duration:{0}", MediaPortal.Util.Utils.SecondsToHMSString((int)duration));
// hr=(graphBuilder as IMediaFilter).SetSyncSource(null);
// if (hr!=0)
// Log.Error("DVRMS2DIVX:FAILED:to SetSyncSource :0x{0:X}",hr);
hr = mediaControl.Run();
if (hr != 0)
{
Log.Error("DVRMS2DIVX: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;
}
mediaControl.Stop();
FilterState state;
mediaControl.GetState(500, out state);
GC.Collect();
GC.Collect();
GC.Collect();
GC.WaitForPendingFinalizers();
graphBuilder.RemoveFilter(aviMuxer);
graphBuilder.RemoveFilter(divxCodec);
graphBuilder.RemoveFilter(mp3Codec);
graphBuilder.RemoveFilter((IBaseFilter)fileWriterFilter);
if (!AddCodecs(graphBuilder, info)) return false;
// hr=(graphBuilder as IMediaFilter).SetSyncSource(null);
// if (hr!=0)
// Log.Error("DVRMS2DIVX:FAILED:to SetSyncSource :0x{0:X}",hr);
Log.Info("DVRMS2DIVX: start transcoding");
hr = mediaControl.Run();
if (hr != 0)
{
Log.Error("DVRMS2DIVX:FAILED:unable to start graph :0x{0:X}", hr);
Cleanup();
return false;
}
}
catch (Exception ex)
{
Log.Error("DVRMS2DIVX:Unable create graph: {0}", ex.Message);
Cleanup();
return false;
}
return true;
}
示例12: OpenSource
/// <summary>
/// Opens the media by initializing the DirectShow graph
/// </summary>
protected virtual void OpenSource()
{
string fileSource = m_sourceUri.OriginalString;
/* Make sure we clean up any remaining mess */
FreeResources();
try
{
/* Creates the GraphBuilder COM object */
m_graph = new FilterGraph() as IGraphBuilder;
if (m_graph == null)
throw new Exception("Could not create a graph");
m_renderer = CreateVideoRenderer(VideoRenderer, m_graph);
/* Add our prefered audio renderer */
InsertAudioRenderer(AudioRenderer);
var filterGraph = m_graph as IFilterGraph2; // Switched this down from IFilterGraph3
if (filterGraph == null)
throw new Exception("Could not QueryInterface for the IFilterGraph3");
IBaseFilter sourceFilter;
/* Have DirectShow find the correct source filter for the Uri */
int hr = filterGraph.AddSourceFilter(fileSource, fileSource, out sourceFilter);
DsError.ThrowExceptionForHR(hr);
// Check for subtitles.
IPin ip;
sourceFilter.FindPin("Subtitle", out ip);
if (ip != null)
{
/* Add DirectVobSub to the graph before rendering pins, so it's connected */
IBaseFilter dvs;
dvs = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(new DsGuid("{93A22E7A-5091-45EF-BA61-6DA26156A5D0}")));
m_graph.AddFilter(dvs, "DirectVobSub");
}
/* We will want to enum all the pins on the source filter */
IEnumPins pinEnum;
hr = sourceFilter.EnumPins(out pinEnum);
DsError.ThrowExceptionForHR(hr);
IntPtr fetched = IntPtr.Zero;
IPin[] pins = { null };
/* Counter for how many pins successfully rendered */
int pinsRendered = 0;
/* Loop over each pin of the source filter */
while (pinEnum.Next(pins.Length, pins, fetched) == 0)
{
if (filterGraph.RenderEx(pins[0],
AMRenderExFlags.RenderToExistingRenderers,
IntPtr.Zero) == 0)
pinsRendered++;
}
NewAllocatorFrame += new Action(MediaUriPlayer_NewAllocatorFrame);
Marshal.ReleaseComObject(pinEnum);
Marshal.ReleaseComObject(sourceFilter);
if (pinsRendered == 0)
throw new Exception("Could not render any streams from the source Uri");
Thread.CurrentThread.Priority = ThreadPriority.Normal;
#if DEBUG
/* Adds the GB to the ROT so we can view
* it in graphedit */
m_dsRotEntry = new DsROTEntry(m_graph);
#endif
/* Configure the graph in the base class */
SetupFilterGraph(m_graph);
/* Sets the NaturalVideoWidth/Height */
SetNativePixelSizes(m_renderer);
// Populate the filters
Filters = new FilterControl(m_graph);
/* Remove and dispose of renderer if we do not
* have a video stream */
if (!HasVideo)
{
m_graph.RemoveFilter(m_renderer);
/* Tells the base class to unregister and
* free the custom allocator */
FreeCustomAllocator();
Marshal.FinalReleaseComObject(m_renderer);
//.........这里部分代码省略.........
示例13: RemoveFromGraph
public static void RemoveFromGraph(IGraphBuilder graphBuilder)
{
IBaseFilter vob = null;
using (Settings xmlreader = new MPSettings())
{
string engineType = xmlreader.GetValueAsString("subtitles", "engine", "DirectVobSub");
XySubFilter = engineType.Equals("XySubFilter");
}
if (!XySubFilter)
{
DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.DirectVobSubAutoload, out vob);
if (vob == null)
{
//Try the "normal" filter then.
DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.DirectVobSubNormal, out vob);
}
}
if (vob == null)
{
DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.XySubFilterAutoload, out vob);
if (vob != null)
{
//remove the XySubFilter filter from the graph
graphBuilder.RemoveFilter(vob);
DirectShowUtil.ReleaseComObject(vob);
vob = null;
return;
}
//Try the XySubFilter "normal" filter then.
DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.XySubFilterNormal, out vob);
if (vob != null)
{
//remove the XySubFilter filter from the graph
graphBuilder.RemoveFilter(vob);
DirectShowUtil.ReleaseComObject(vob);
vob = null;
}
return;
}
Log.Info("VideoPlayerVMR9: DirectVobSub in graph, removing...");
// Check where video inputs are connected
IPin pinVideoIn = DsFindPin.ByDirection(vob, PinDirection.Input, 0);
IPin pinVideoOut = DsFindPin.ByDirection(vob, PinDirection.Output, 0);
//find directvobsub's video output pin source input pin
IPin pinVideoTo = null;
if (pinVideoOut != null)
{
pinVideoOut.ConnectedTo(out pinVideoTo);
}
//find directvobsub's video input pin source output pin
IPin pinVideoFrom = null;
if (pinVideoIn != null)
{
pinVideoIn.ConnectedTo(out pinVideoFrom);
}
int hr = 0;
if (pinVideoFrom != null)
{
hr = pinVideoFrom.Disconnect();
if (hr != 0)
{
Log.Error("VideoPlayerVMR9: DirectVobSub failed disconnecting source pin");
}
}
if (pinVideoTo != null)
{
hr = pinVideoTo.Disconnect();
if (hr != 0)
{
Log.Error("VideoPlayerVMR9: DirectVobSub failed disconnecting destination pin");
}
}
//remove the DirectVobSub filter from the graph
graphBuilder.RemoveFilter(vob);
DirectShowUtil.ReleaseComObject(vob);
vob = null;
//reconnect the source output pin to the vmr9/evr filter
if (pinVideoFrom != null)
{
if (pinVideoTo != null)
{
hr = graphBuilder.Connect(pinVideoFrom, pinVideoTo);
}
//hr = graphBuilder.Render(pinVideoFrom);
DirectShowUtil.ReleaseComObject(pinVideoFrom);
pinVideoFrom = null;
}
if (pinVideoTo != null)
//.........这里部分代码省略.........
示例14: RemoveAllFilters
public static void RemoveAllFilters(IGraphBuilder graphBuilder)
{
if (graphBuilder == null)
throw new ArgumentNullException("graphBuilder");
IEnumFilters enumFilters = null;
System.Collections.ArrayList filtersArray = new System.Collections.ArrayList();
try
{
int hr = graphBuilder.EnumFilters(out enumFilters);
DsError.ThrowExceptionForHR(hr);
IBaseFilter[] filters = new IBaseFilter[1];
int fetched;
while (enumFilters.Next(filters.Length, filters, out fetched) == 0)
{
filtersArray.Add(filters[0]);
}
foreach (IBaseFilter filter in filtersArray)
{
FilterInfo info;
filter.QueryFilterInfo(out info);
Log.Log.Write("Remove filter from graph: {0}", info.achName);
graphBuilder.RemoveFilter(filter);
while (Release.ComObject(filter) > 0) ;
}
}
catch (Exception)
{
Log.Log.Write("Remove filter error!");
return;
}
finally
{
if (enumFilters != null)
{
Release.ComObject(enumFilters);
}
}
}
示例15: Transcode
//.........这里部分代码省略.........
return false;
}
}
Log.Info("TSReader2WMV: connect tsreader->audio/video decoders");
//connect output #0 (audio) of tsreader->audio decoder input pin 0
//connect output #1 (video) of tsreader->video decoder input pin 0
pinIn0 = DsFindPin.ByDirection(AudioCodec, PinDirection.Input, 0); //audio
pinIn1 = DsFindPin.ByDirection(VideoCodec, PinDirection.Input, 0); //video
if (pinIn0 == null || pinIn1 == null)
{
Log.Error("TSReader2WMV: FAILED: unable to get pins of video/audio codecs");
Cleanup();
return false;
}
hr = graphBuilder.Connect(pinOut0, pinIn0);
if (hr != 0)
{
Log.Error("TSReader2WMV: FAILED: unable to connect audio pins :0x{0:X}", hr);
Cleanup();
return false;
}
hr = graphBuilder.Connect(pinOut1, pinIn1);
if (hr != 0)
{
Log.Error("TSReader2WMV: 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("TSReader2WMV: start pre-run");
mediaControl = graphBuilder as IMediaControl;
mediaSeeking = tsreaderSource as IMediaSeeking;
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("TSReader2WMV: movie duration:{0}", Util.Utils.SecondsToHMSString((int)duration));
hr = mediaControl.Run();
if (hr != 0)
{
Log.Error("TSReader2WMV: 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("TSReader2WMV: pre-run done");
Log.Info("TSReader2WMV: Get duration of movie");
mediaControl.Stop();
FilterState state;
mediaControl.GetState(500, out state);
GC.Collect();
GC.Collect();
GC.Collect();
GC.WaitForPendingFinalizers();
Log.Info("TSReader2WMV: reconnect mpeg2 video codec->ASF WM Writer");
graphBuilder.RemoveFilter(fileWriterbase);
if (!AddWmAsfWriter(outputFilename, quality, standard)) return false;
Log.Info("TSReader2WMV: Start transcoding");
hr = mediaControl.Run();
if (hr != 0)
{
Log.Error("TSReader2WMV: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;
}