Solved

DirectShow Editing Services - problem with MS example

Posted on 2003-12-12
5
1,286 Views
Last Modified: 2008-02-07
I've tried converting the MS Directshow Editing services demo (on the MS developers web site) to Delphi, using the Directshow9.pas header provided by JEDI at www.prodigy.com. Everything works fine except I get an exception whenever I use a _release statement. My code is as follows:

procedure TForm1.PreviewTL(pTL : IAMTimeline; pRender : IRenderEngine);
var
    pGraph : IGraphBuilder;
    pControl : IMediaControl;
    pEvent : IMediaEvent;
    evCode : integer;
begin
     // Preview a timeline.
     // Build the graph.

     pRender.SetTimelineObject(pTL);
     pRender.ConnectFrontEnd();
     pRender.RenderOutputPins();

     // Run the graph.
     pRender.GetFilterGraph(pGraph);
     pGraph.QueryInterface(IID_IMediaControl,pControl);
     pGraph.QueryInterface(IID_IMediaEvent,pEvent);
     pControl.Run();

     pEvent.WaitForCompletion(INFINITE, evCode);
     pControl.Stop();

     // Clean up.
     //pEvent._Release();
     //pControl._Release();
     //pGraph._Release();
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  pTL : IAMTimeline;  //The main timeline
  pGroup: IAMTimelineGroup;
  pGroupObj: IAMTimelineObj;
  mtGroup: AM_MEDIA_TYPE;
  pTrackObj: IAMTimelineObj;
  pTrack: IAMTimelineTrack;
  pComp: IAMTimelineComp;
  pSource: IAMTimelineSrc;
  pSourceObj: IAMTimelineObj;
  bstrFile: String;
  pRenderEngine: IRenderEngine;
  hr : integer;

begin
     bstrFile := 'C:\cvr\goodtime.avi';
     QzInitialize(nil);
     QzCreateFilterObject(CLSID_AMTimeline, NIL, CLSCTX_INPROC_SERVER,
         IID_IAMTimeline, pTL);

     //Add a video group to the timeline.

     hr := pTL.CreateEmptyNode(pGroupObj,TIMELINE_MAJOR_TYPE_GROUP);
     Showmessage(inttostr(hr));
     pGroupObj.QueryInterface(IID_IAMTimelineGroup,pGroup);

     (* Set the group media type. This example sets the type to "video" and*)
     (* lets DES pick the default settings. For a more detailed example,*)
     (* see "Setting the Group Media Type."*)

     ZeroMemory(@mtGroup,sizeof(AM_MEDIA_TYPE));
     mtGroup.majortype:= MEDIATYPE_Video;
     pGroup.SetMediaType(@mtGroup);
     pTL.AddGroup(pGroupObj);
     //pGroupObj._Release();

     (* TRACK: Add a track to the group.*)
     pTL.CreateEmptyNode(pTrackObj,TIMELINE_MAJOR_TYPE_TRACK);
     pGroup.QueryInterface(IID_IAMTimelineComp,pComp);
     pComp.VTrackInsBefore(pTrackObj,0);
     pTrackObj.QueryInterface(IID_IAMTimelineTrack,pTrack);

     //pTrackObj._Release();
     //pComp._Release();
     //pGroup._Release();

     (* SOURCE: Add a source to the track.*)
     pTL.CreateEmptyNode(pSourceObj,TIMELINE_MAJOR_TYPE_SOURCE);
     pSourceObj.QueryInterface(IID_IAMTimelineSrc,pSource);
     pSourceObj.SetStartStop(0,60000000);

     (* Set the times and the file name.*)
     pSource.SetMediaName(bstrFile);
     pSource.SetMediaTimes(10000000,70000000);
     pTrack.SrcAdd(pSourceObj);
//     SysFreeString(bstrFile);
     //pSourceObj._Release();
     //pSource._Release();
     //pTrack._Release();

     (* Preview the timeline.*)
     CoCreateInstance(CLSID_RenderEngine,nil,CLSCTX_INPROC_SERVER,IID_IRenderEngine,pRenderEngine);
          PreviewTL(pTL,pRenderEngine);
     pRenderEngine.ScrapIt();
     (* Clean up.*)
     //pRenderEngine._Release();
     //pTL._Release();
     CoUninitialize();

end;


As you see I've removed all the _Release statement, and things work fine (except that's not a good idea...). Any ideas as to what might be wrong? Anyone else working with Editing Services I can talk this through with?

Cheers!

Martin Coster

0
Comment
Question by:passpics
  • 2
  • 2
5 Comments
 
LVL 12

Assisted Solution

by:Lee_Nover
Lee_Nover earned 100 total points
Comment Utility
do NOT use _Release !!! instead set the interfaces to nil !
0
 
LVL 8

Accepted Solution

by:
gmayo earned 150 total points
Comment Utility
All you need do is:
pRenderEngine := nil;

Strange as it may sound, that's all you need do. Any variable you assign to an interface will increment its reference count. Any setting of a variable that is an interface will effectively call _Release, hence the need to not do it.

Geoff M.
0
 

Author Comment

by:passpics
Comment Utility
Thanks! I assume C++ works differently then. Or are MS giving out flunky examples?
0
 
LVL 8

Expert Comment

by:gmayo
Comment Utility
It's the way Borland chose to handle interfaces. Whether that is right or wrong is open to some debate!

Cheers

Geoff M.
0
 
LVL 12

Expert Comment

by:Lee_Nover
Comment Utility
and I like it this way better :)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now