Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DirectShow Editing Services - problem with MS example

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

Accepted Solution

by:
gmayo earned 450 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

824 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