Solved

DirectShow Editing Services - problem with MS example

Posted on 2003-12-12
5
1,302 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
ID: 9928192
do NOT use _Release !!! instead set the interfaces to nil !
0
 
LVL 8

Accepted Solution

by:
gmayo earned 150 total points
ID: 9928408
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
ID: 9932720
Thanks! I assume C++ works differently then. Or are MS giving out flunky examples?
0
 
LVL 8

Expert Comment

by:gmayo
ID: 9933782
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
ID: 9933922
and I like it this way better :)
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

828 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