Solved

DirectShow Editing Services - problem with MS example

Posted on 2003-12-12
5
1,317 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

Technology Partners: 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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month3 days, 11 hours left to enroll

630 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