You can make UDP streaming in your application with an MFWriter or MWriter object. Like in other captioning cases you need to complete these steps:
- Configure your source object,
- Configure your MFWriter (MWriter) object,
- Start capturing.
UDP streaming has MPEG Transport stream format (mpegts). You should set it in your configuration string. Then you should select video and audio codecs and their attributes.
As result your configuration string looks like:
format='mpegts' protocol='udp://' video::codec='mpeg2video' video::b='5M' audio::codec='libmp3lame'
Set this line and your target URL the encoding object and start encoding:
MPlatform SDK
string myDestination = @"udp://192.168.0.177:5000"; string myConfiguration = "format='mpegts' protocol='udp://' video::codec='mpeg2video' video::b='5M' audio::codec='libmp3lame'"; myWriter.WriterNameSet(myDestination, myConfiguration); myWriter.ObjectStart(mySource);
MFormats SDK
string myDestination = @"udp://192.168.0.177:5000"; string myConfiguration = "format='mpegts' protocol='udp://' video::codec='mpeg2video' video::b='5M' audio::codec='libmp3lame'"; int resetPreviousConfiguration = 1; myWriter.WriterSet(myDestination, resetPreviousConfiguration, myConfiguration);
And then use myWriter in core method to make UDP streaming:
// a frame object MFFrame myFrame; // grab a frame ((IMFSource)myLiveSource).SourceFrameGet(-1, out myFrame, ""); // send to receiver ((IMFReceiver)myWriter).ReceiverFramePut(myFrame, -1, "");
The required syntax for a UDP destination URL is:
udp://hostname:port[?options]
options contain a list of options separated by '&' symbol in 'key=value' structure.
Parameters for UDP streaming
Parameter | Description |
---|---|
buffer_size=size | Set the UDP maximum socket buffer size in bytes. This is used to set either the receive or send buffer size, depending on what the socket is used for. The default is 64KB. See also fifo_size. |
localport=port | Override the local UDP port to bind with. |
localaddr=addr | Choose the local IP address. This is useful e.g. if sending multicast and the host has multiple interfaces, where the user can choose which interface to send on by specifying the IP address of that interface. |
pkt_size=size | Set the size in bytes of UDP packets. |
reuse=1|0 | Explicitly allow or disallow reusing UDP sockets. |
ttl=ttl | Set the time to live value (for multicast only). |
connect=1|0 | Initialize the UDP socket with connect(). This allows finding out the source address for the packets with stock names and makes writers return with an error if "destination unreachable" is received. For receiving, this gives the benefit of only receiving packets from the specified peer address/port. |
sources=address[,address] | Only receive packets sent to the multicast group from one of the specified sender IP addresses. |
block=address[,address] | Ignore packets sent to the multicast group from the specified sender IP addresses. |
fifo_size=units | Set the UDP receiving circular buffer size, expressed as a number of packets with a size of 188 bytes. If not specified defaults to 7*4096. |
overrun_nonfatal=1|0 | Survive in case of UDP receiving circular buffer overrun. The default value is 0. |
timeout=microseconds | Set raise error timeout, expressed in microseconds. This option is only relevant in reading mode: if no data arrived in more than this time interval, raise an error. |
broadcast=1|0 |
Explicitly allow or disallow UDP broadcasting. |
How to change audio/ video PID for UDP stream?
Just add the following configuration properties to your MWriter/MFWriter config string
video::streamid= video_pid
audio::streamid= audio_pid