Solved

DirectShow Editing Services - problem with MS example

Posted on 2003-12-12
5
1,311 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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