uses
DirectShow9;
var
GraphB: IGraphBuilder =
nil;
FTVTuner : IAMTVTuner =
nil;
CaptureGraph: ICaptureGraphBuilder2 =
nil;
SourceFilter: IBaseFilter =
nil;
procedure AddFilter(
CLSID: TGUID; FriendlyName:
string;
out pFilter: IBaseFilter);
begin
if Succeeded(CoCreateInstance(
CLSID,
nil, CLSCTX_SERVER, IID_IBaseFilter, pFilter))
then
if Failed(GraphB.AddFilter(pFilter, StringToOLEStr(FriendlyName)))
then
Showmessage('
Error while adding "' + FriendlyName + '
" Filter');
end;
function InitTuner: Boolean;
var
pEnum: IEnumMoniker;
pmoniker: IMoniker;
pDevEnum: ICreateDevEnum;
pmt: PAMMediaType;
pFilter, pFilter2: IBaseFilter;
ipin, opin: DirectShow9.IPin;
pEnumPins: IEnumPins;
begin
Result:= true;
// Create the Filter Graph Manager.
if Succeeded(CoCreateInstance(CLSID_FilterGraph,
nil, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, GraphB))
then
// Create the Capture Graph Builder.
if Succeeded(CoCreateInstance(CLSID_CaptureGraphBuilder2,
nil,
CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, CaptureGraph))
then
begin
CaptureGraph.SetFiltergraph(GraphB);
end else Result:= false;
// get the SourceFilter
if Succeeded(CoCreateInstance(CLSID_SystemDeviceEnum,
nil, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, pDevEnum))
then
if Succeeded(pDevEnum.CreateClassEnumerator(CLSID_VideoInputDeviceCategory, pEnum, 0))
then
if Succeeded(pEnum.Next(1, pmoniker,
nil))
then
if Succeeded(pmoniker.BindToObject(
nil,
nil, IID_IBaseFilter, sourceFilter))
then
if Succeeded(Graphb.AddFilter(SourceFilter, StringToOleStr('
Capture Filter')))
then
// Get Tuner Interface
if Failed(CaptureGraph.FindInterface(@LOOK_UPSTREAM_ONLY,
nil, SourceFilter, IID_IAMTVTuner, FTVTuner))
then
begin
Showmessage('
No TV card in system!');
Result:= false;
end else
if Succeeded(FTVTuner.put_InputType(0, TunerInputCable))
then
if Succeeded(FTVTuner.put_Mode(AMTUNER_MODE_TV))
then
begin
AddFilter(CLSID_OverlayMixer, '
Overlay Mixer', pFilter);
AddFilter(CLSID_VideoRenderer, '
Video Renderer', pFilter2);
// Overlay Mixer -> Video Renderer
if Succeeded(pFilter.FindPin(StringToOlestr('
Output'), oPin))
then
if Succeeded(GraphB.FindFilterByName(StringToOlestr('
Video Renderer'), pFilter2))
then
if Succeeded(pFilter2.EnumPins(pEnumPins))
then
if Succeeded(pEnumPins.Next(1, iPin,
nil))
then
if Succeeded(GraphB.Connect(oPin, ipin))
then
// Capture Filter -> Overlay Mixer
if Succeeded(CaptureGraph.FindPin(SourceFilter, PINDIR_OUTPUT, @PIN_CATEGORY_PREVIEW,
nil, TRUE, 0, oPin))
then
if Succeeded(pFilter.FindPin(stringtoolestr('
Input0'),ipin))
then
GraphB.Connect(ipin, opin)
else Result:= false;
end else Result:= false;
// Show Graph
ShowGraph(Result);
// eigene Procedur die hier etwas den Rahmen sprengen würde.
// Release Interfaces
pMoniker:=
nil;
pDevEnum:=
nil;
pEnum:=
nil;
pEnumPins:=
nil;
iPin:=
nil;
oPin:=
nil;
pFilter:=
nil;
pFilter2:=
nil;
if not Result
then
begin
FTVTuner:=
nil;
CaptureGraph:=
nil;
GraphB:=
nil;
end;
end;