locked
DatagramSocket's MessageReceived event with MF MediaSource strategies?

    Question

  • I'm trying to integrate sending and receiving data over UDP sockets using Media Foundation.  I've already got my MF MediaSink setup to send data out over a UDP socket.  However, I can't figure out how to get an MF MediaSource to receive data.  I'm using a Multicast setup and want to just listen at a single port.  I know how to bind to a service (and I know about the overload for store apps to handle the error with some NICs).  What I don't know how to do is handle the MessageReceived event of DatagramSocket via the MF MediaSource.

    From what I can tell, I can't handle it from the MF MediaSource because the MediaSource is a COM class, not a WinRT class... correct?

    So what strategy should I be using?

    1.  I've very briefly tried using a task_completion_event that gets triggered when the message is received.  The MFMediaSource waits for an async method on the UDPClient class I've created to continue after receiving this task_completion_event.  I was trying to do something very similar to how the "Simple Communication" sample works for initialiating a connection using a StreamSocket.  However, that was done once and I need my event to loop.  I couldn't get it to work without throwing an exception (with not much information).  I'm not sure if it's a deadend.

    2.  Should I create a MemoryStream (whatever the C++ equivalent is) within my UDPClient class, then copy data received over UDP from the IInputStream to my new stream?  I guess I'd have to emply some kind of lock and then poll the new stream in a loop from the MF MediaSource. 

    I'm still very much a novice at C++ (trying to learn by example), but I would very much appreciate some help on how to proceed.  Thanks!


    Lee McPherson




    • Changed type Lee McPherson Monday, February 9, 2015 12:34 PM actually is a question
    • Edited by Lee McPherson Tuesday, February 10, 2015 6:32 PM
    Monday, February 9, 2015 12:32 PM

Answers

  • Hello Lee,

    All Windows Runtime components are based on what we call Modern COM (MoCOM). There are two ways to consume MoCOM object in C++. The first is to use the C++ Cx environment. Unfortunately due to compatibility requirement with desktop apps, MFTs cannot easily use C++ Cx (although it is possible). To enable Runtime functionality in an MFT you can use the Windows Runtime Template Library (WRL). You can instantiate and use any Runtime component or object from a MoCOM object such as an MFT using the WRL. Check out the following link for more information on consuming Runtime components via the WRL.

    Activate and Use a Windows Runtime Component Using WRL 

    I hope this helps,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Tuesday, February 10, 2015 7:08 PM
    Moderator

All replies

  • I'll ask our Media guru to check this question out.

    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.

    Tuesday, February 10, 2015 1:21 PM
    Moderator
  • Hello Lee,

    All Windows Runtime components are based on what we call Modern COM (MoCOM). There are two ways to consume MoCOM object in C++. The first is to use the C++ Cx environment. Unfortunately due to compatibility requirement with desktop apps, MFTs cannot easily use C++ Cx (although it is possible). To enable Runtime functionality in an MFT you can use the Windows Runtime Template Library (WRL). You can instantiate and use any Runtime component or object from a MoCOM object such as an MFT using the WRL. Check out the following link for more information on consuming Runtime components via the WRL.

    Activate and Use a Windows Runtime Component Using WRL 

    I hope this helps,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Tuesday, February 10, 2015 7:08 PM
    Moderator
  • This has helped quite a bit. Thanks for pointing me in the right direction!

    FYI, it would help to create a primer on the history of C++ as it pertains to Microsoft technologies.  I think a lot of people who learn to program now don't necessarily have a formal background in computer programming (mine is in chemistry).  I learn from examples and there are plenty of great C++ samples for Windows Store apps, but they are all pretty high level.  I didn't really know until now that they use C++/Cx. I've seen the term before but couldn't make the connection as to what it was out of the C++ I was being shown.  I didn't know what WRL was or MFC or any of the other names applied to a flavor of C++.

    The hardest thing about learning over the internet is that you'll get examples written using any number of these... whatever they are called.  Books tend to focus on console apps if they explain COM or WRL.  The ones that use store apps tend to focus on C++/Cx and WinRT only.

    All I'm saying is that someone should write a book that explains the non-C++/Cx (and relevant) portions of C++ for Win8.1/WP8.1 to a C# or JavaScript Windows Store app writer . 


    Lee McPherson

    Wednesday, February 11, 2015 9:05 PM