The role of MediaSession (and what to do without it) or how to use a custom presentation time source RRS feed

  • Question

  • Hi,

    I was wondering if someone can tell me what the specific functionality of the MediaSession is? I want to play videos based on a custom presentation time source which as far as I understand it forces me to NOT use a MediaSession. Unfortunately there neither seems to be any sample that addresses this use case nor does the documentation specifically say what the MediaSession does under the hood. My assumption is that I might be able to create the same partial topology as in the case of using a MediaSession, use the topology loader to complete it, create the presentation clock myself and just have to notify the sources about start/pause/stop ... but it would be great if someone could confirm that before I head into the wrong direction...



    Monday, November 1, 2010 10:01 AM

All replies

  • The media session manages the state of the presentation clock, source, and sink state, and manages sample flow from topology node to topology node throughout the pipeline.

    The time source for a presentation clock is typically provided from one of the sinks.  The audio renderer usually defines the time source for the presentation clock, because otherwise video can get desynchronized with the audio.  If you insert your own sink into the topology that implements the IMFPresentationTimeSource interface, that time source will specify the clock time for the session.  This requires that your custom sink be the first inserted into the topology and sets the MEDIASINK_CANNOT_MATCH_CLOCK characteristic if there are other sinks in the topology (such as the standard audio renderer) that might be time sources.

    Before going the route of a custom time source, you should make sure you cannot implement your solution by managing the media session's state -- using the media session and it's rate control service, you can start, stop, pause, seek, and set forward and backwards rates at will.

    Thursday, November 11, 2010 1:18 AM
  • Hi Matt,

    thanks, that sounds like it could work for what I try to do. About the second part, actually I'm not sure yet. There are a number of reasons why we can't use the audio clock directly and using our internal application clock to implement a presentation time source seems to be the cleanest solution. But I'll have another look at using the MediaSession for that as you suggested once I've managed to solve all the other, currently more pressing problems in the implementation...


    Monday, November 22, 2010 2:51 PM
  • Hi Matt,

    I finally got to the point where I can start implementing the clock stuff. I have a custom EVR presenter but no custom media sink. So do I have to implement a "fake media sink" just to get my own IMFPresentationTimeSource into the topology? If so, which of the methods do I really have to implement and which could stay not implemented (as in just return E_NOTIMPL)? And what type (i.e. MF_TOPOLOGY_OUTPUT_NODE, ...) of topology node do I have to create to attach the fake media sink to when inserting it into the topology?



    P.S.: I checked, just using the time management of the session as suggested is not enough, I really have to be able to control the time source.



    I created a class that implements IClusterTimeMediaSink, IMFMediaSink, IMFStreamSink, IMFPresentationTimeSource, IMFClockStateSink, IMFGetService created an output topology node, added it to the topology (first thing right after MFCreateTopology) and put breakpoints into all methods of the class. It gets queried for IMFPersist (and a couple of derived interfaces) and IMFActive which it does not implement.

    The thing is that GetCharacteristics gets called (returns MEDIASINK_FIXED_STREAMS | MEDIASINK_CANNOT_MATCH_CLOCK) but nothing else... so it doesn't seem to work to have it act as a time source... any ideas? I had a look at the wav sink sample but couldn't find any obvious that was missing. Can the problem be related to me creating the video renderer manually and connecting it to the source node via ConnectOutput ? Do I have to ConnectOutput the source to my fake media stream as well?

    Monday, March 7, 2011 3:35 PM
  • News flash... I'm now using MFCreatePresentationClock and SetTimeSource (with the fake timesource described above) and then explicitly call SetPresentationClock on the Video Renderer. I've triple checked that my fake time source is the first media sink to be added to the topology (I even moved that code right after the create topology call) and setting the presentation clock returns S_OK. Still my timesource's methods don't get called when the video plays. I've used a video without audio, so no audio renderer is created.

    Does the media sink just have to exist in the topology or does it have to be connected to the source node? Also, is your proposed method if "clock injection via media sink" able to work when the actual audio/video output should be done with the standard audio/video renderer objects?

    Monday, March 14, 2011 2:31 PM
  • The media sink should be connected in the topology, and discard any data it receives (you can use a tee node to forward data from another stream to the dummy sink).  The topology loader will trim unconnected sinks, and and unconnected sink will not receive some of the events it needs to properly work in the pipeline.

    If the time source sink sets the MEDIASINK_CANNOT_MATCH_CLOCK, it will override the standard audio renderer for being the time source.  The video renderer is never a time source.

    Wednesday, March 30, 2011 7:59 PM
  • Thanks for the reply. I did several attempts today but have achieved nothing... best thing I got was the video to not play at all (i.e. the async start request did not complete). Is there any way to get source code support (i.e. a sample implementation or someone that uses our program to analyze what MF is expecting from it that it does not get) against a fee or something? Maybe I'm missing something very basic, but this feels like I'm getting nowhere for weeks...
    Monday, April 4, 2011 2:40 PM