//インスタンス変数
private IFilterGraph2 _filterGraph;
private IMediaControl _mediaControl;
private IPin _outputPin;
private IPin _inputPin;
///グラフ作成
private void SetupGraph( Control control)
{
//デバイス取得
var capDevices = DsDevice.GetDevicesOfCat ( FilterCategory.VideoInputDevice ) ;
filterGraph = new FilterGraph( ) as IFilterGraph2;
IBaseFilter capFilter;
var hr = filterGraph.AddSourceFilterForMoniker ( capDevices[ 0 ] .Mon , null , capDevices[ 0 ] .Name , out capFilter) ;
DsError.ThrowExceptionForHR ( hr) ;
outputPin = DsFindPin.ByCategory ( capFilter, PinCategory.Capture , 0 ) ;
var pRender = new VideoRendererDefault( ) as IBaseFilter;
hr = filterGraph.AddFilter ( pRender, "Renderer" ) ;
DsError.ThrowExceptionForHR ( hr) ;
_inputPin = DsFindPin.ByDirection ( pRender, PinDirection.Input , 0 ) ;
hr = filterGraph.Connect ( _outputPin, _inputPin) ;
DsError.ThrowExceptionForHR ( hr) ;
//このメソッドでコントロールに描画する設定を行います。
ConfigVideoWindow( control) ;
_mediaControl = _filterGraph as IMediaControl;
_mediaControl.Run ( ) ;
}
//切断
public void Disconnect( )
{
_mediaControl.Stop ( ) ;
var hr= filterGraph.Disconnect ( _outputPin) ;
DsError.ThrowExceptionForHR ( hr) ;
_mediaControl.Run ( ) ;
}
///再接続
public void Reconnect( )
{
_mediaControl.Stop ( ) ;
var hr= filterGraph.Connect ( _outputPin, inputPin) ;
DsError.ThrowExceptionForHR ( hr) ;
_mediaControl.Run ( ) ;
}
Ly/jgqTjg7Pjgrnjgr/jg7PjgrnlpInmlbAKcHJpdmF0ZSBJRmlsdGVyR3JhcGgyIF9maWx0ZXJHcmFwaDsKcHJpdmF0ZSBJTWVkaWFDb250cm9sIF9tZWRpYUNvbnRyb2w7CnByaXZhdGUgSVBpbiBfb3V0cHV0UGluOwpwcml2YXRlIElQaW4gX2lucHV0UGluOwoKLy8v44Kw44Op44OV5L2c5oiQCnByaXZhdGUgdm9pZCBTZXR1cEdyYXBoKENvbnRy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VkaWFDb250cm9sID0gX2ZpbHRlckdyYXBoIGFzIElNZWRpYUNvbnRyb2w7CglfbWVkaWFDb250cm9sLlJ1bigpOwp9CgovL+WIh+aWrQpwdWJsaWMgdm9pZCBEaXNjb25uZWN0KCkKewoJX21lZGlhQ29udHJvbC5TdG9wKCk7Cgl2YXIgaHI9ICBmaWx0ZXJHcmFwaC5EaXNjb25uZWN0KF9vdXRwdXRQaW4pOwoJRHNFcnJvci5UaHJvd0V4Y2VwdGlvbkZvckhSKGhyKTsKCV9tZWRpYUNvbnRyb2wuUnVuKCk7Cn0KCi8vL+WGjeaOpee2mgpwdWJsaWMgdm9pZCBSZWNvbm5lY3QoKQp7CglfbWVkaWFDb250cm9sLlN0b3AoKTsKCXZhciBocj0gZmlsdGVyR3JhcGguQ29ubmVjdChfb3V0cHV0UGluLCBpbnB1dFBpbik7CglEc0Vycm9yLlRocm93RXhjZXB0aW9uRm9ySFIoaHIpOwoJX21lZGlhQ29udHJvbC5SdW4oKTsJCn0=
compilation info
prog.cs(2,23): error CS0116: A namespace can only contain types and namespace declarations
prog.cs(3,23): error CS0116: A namespace can only contain types and namespace declarations
prog.cs(4,14): error CS0116: A namespace can only contain types and namespace declarations
prog.cs(5,14): error CS0116: A namespace can only contain types and namespace declarations
prog.cs(8,14): error CS0116: A namespace can only contain types and namespace declarations
prog.cs(31,13): error CS0116: A namespace can only contain types and namespace declarations
prog.cs(40,13): error CS0116: A namespace can only contain types and namespace declarations
Compilation failed: 7 error(s), 0 warnings
stdout