locked
How to write custom media sink for StartRecordToCustomSinkAsync function?

    Question

  • Hello..

    I am trying to capture video frames from webcam using below API.

    public:
    IAsyncAction^ StartRecordToCustomSinkAsync(
      MediaEncodingProfile^ encodingProfile,
      IMediaExtension^ customMediaSink
    )

    To make customMediaSink, writting IDL ( as given in example in below link)  is mandatory?

    http://code.msdn.microsoft.com/windowsapps/Simple-Communication-Sample-eac73290

    If I dont want write IDL, Is it possible to make custom media sink for StartRecordToCustomSinkAsync as just simple ref class which is derived from IMediaExtension and IMFMediaSink?

    Please let me know ...

    Thanks in advance for any help..


    a

    Monday, December 10, 2012 2:45 PM

Answers

  • This can actually be done. The IMediaExtension instance must implement the IMFMediaSink interface. Here is how to declare such a class:

    class CGetSamples WrlSealed
    	: public RuntimeClass<
    	RuntimeClassFlags< Microsoft::WRL::RuntimeClassType::WinRtClassicComMix >,
    	ABI::Windows::Media::IMediaExtension,
    	IMFMediaSink,
    	IMFClockStateSink>
    {
    ...
    };

    Then the problem just comes down to creating an instance of this custom sink to pass to the StartRecordToCustomSinkAsync function.  That doesn't have to be in a .dll and doesn't have to be created by name.  It can be part of your app code.

    
    
    IInspectable* pInstpectable = nullptr;
    HRESULT hr = MakeAndInitialize<CGetSamples>(&pInstpectable);
    CHECK(hr);
    IMediaExtension^ me = reinterpret_cast<IMediaExtension^>(pInstpectable);
    
    
    // m_MC is an instance of MediaCapture
    MediaEncodingProfile^ mep = MediaEncodingProfile::CreateMp4(VideoEncodingQuality::Vga);
    m_MC->StartRecordToCustomSinkAsync(mep, me);


    Tuesday, April 15, 2014 3:31 AM

All replies

  • Hello,

     

    I will involve more experts to investigate it.

     

    Best regards,

    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, December 14, 2012 9:21 AM
  • Hi - I'm researching this and will update you next week.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, December 14, 2012 7:51 PM
    Moderator
  • Thanks a lot for the reply.. I will be waiting for the update...

    Please give me a sample code if you are able to make without IDL, It would save lot of my time.

    If making IDL is the only way..then Could you please let me know answer for the post : http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/335b4201-22b9-4e5a-b467-c7af1521fbc0

    Thanks in advance.


    a

    Monday, December 17, 2012 4:07 AM
  • Hi Abwin - I spoke to our media specialist.  He said that you do have to use IDL as shown in the sample.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, December 19, 2012 6:18 PM
    Moderator
  • Hi......

    Thanks for all your efforts in getting me answer. Thanks a lot.

    For simple usecase like recording frames using IDL is big headache!! I am really really interested to know the reason behind the design.

    Also, Could you please answer my question in the below link

      http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/335b4201-22b9-4e5a-b467-c7af1521fbc0

    Thanks


    a

    Thursday, December 20, 2012 3:00 AM
  • Did the last post in the other thread help?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, December 20, 2012 3:02 PM
    Moderator
  • Hi Matt Small,

    I wanted to capture video frames without IDL. Now the IDL is mandatory. So I am getting data in ProcessSample of custom sink.

    How should I get data back to the module one which has called StartRecordToCustomSinkAsync ?

    My project structure is something like this :  

    Windows store app -> Platform Lib -> Interface (custom Media Sink)

    Platform lib is calling StartRecordToCustomSinkAsync function and I am getting recorded data in custom Media Sink.

    I need captured data back in my platform lib for further processing.

    Memory should be allocated by which module if u consider my projects?

    And how the pointers should be passed ?


    a

    Friday, December 21, 2012 4:02 AM
  • This can actually be done. The IMediaExtension instance must implement the IMFMediaSink interface. Here is how to declare such a class:

    class CGetSamples WrlSealed
    	: public RuntimeClass<
    	RuntimeClassFlags< Microsoft::WRL::RuntimeClassType::WinRtClassicComMix >,
    	ABI::Windows::Media::IMediaExtension,
    	IMFMediaSink,
    	IMFClockStateSink>
    {
    ...
    };

    Then the problem just comes down to creating an instance of this custom sink to pass to the StartRecordToCustomSinkAsync function.  That doesn't have to be in a .dll and doesn't have to be created by name.  It can be part of your app code.

    
    
    IInspectable* pInstpectable = nullptr;
    HRESULT hr = MakeAndInitialize<CGetSamples>(&pInstpectable);
    CHECK(hr);
    IMediaExtension^ me = reinterpret_cast<IMediaExtension^>(pInstpectable);
    
    
    // m_MC is an instance of MediaCapture
    MediaEncodingProfile^ mep = MediaEncodingProfile::CreateMp4(VideoEncodingQuality::Vga);
    m_MC->StartRecordToCustomSinkAsync(mep, me);


    Tuesday, April 15, 2014 3:31 AM