MCPcopy Create free account
hub / github.com/Haivision/srt / UdpSource

Method UdpSource

testing/testmedia.cpp:2892–2931  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2890}
2891
2892UdpSource::UdpSource(string host, int port, const map<string,string>& attr)
2893{
2894 Setup(host, port, attr);
2895
2896 // On Windows it somehow doesn't work when bind()
2897 // is called with multicast address. Write the address
2898 // that designates the network device here, always.
2899
2900 // Hance we have two fields holding the address:
2901 // * target_addr: address from which reading will be done
2902 // * unicast: local address of the interface
2903 // * multicast: the IGMP address
2904 // * interface_addr: address of the local interface
2905 // (same as target_addr for unicast)
2906
2907 // In case of multicast, binding should be done:
2908 // On most POSIX systems, to the multicast address (target_addr in this case)
2909 // On Windows, to a local address (hence use interface_addr, as in this
2910 // case it differs to target_addr).
2911
2912#if defined(_WIN32) || defined(__CYGWIN__)
2913 sockaddr_any baddr = is_multicast ? interface_addr : target_addr;
2914 static const char* const sysname = "Windows";
2915#else
2916 static const char* const sysname = "POSIX";
2917 sockaddr_any baddr = target_addr;
2918#endif
2919 Verb("UDP:", is_multicast ? "Multicast" : "Unicast", "(", sysname,
2920 "): will bind to: ", baddr.str());
2921 int stat = ::bind(m_sock, baddr.get(), baddr.size());
2922
2923 if (stat == -1)
2924 Error(SysError(), "Binding address for UDP");
2925 eof = false;
2926 struct timeval tv;
2927 tv.tv_sec = 1;
2928 tv.tv_usec = 0;
2929 if (::setsockopt(m_sock, SOL_SOCKET, SO_RCVTIMEO, (const char*) &tv, sizeof(tv)) < 0)
2930 Error(SysError(), "Setting timeout for UDP");
2931}
2932
2933MediaPacket UdpSource::Read(size_t chunk)
2934{

Callers

nothing calls this directly

Calls 7

VerbFunction · 0.85
bindFunction · 0.85
SysErrorFunction · 0.85
setsockoptFunction · 0.85
strMethod · 0.45
getMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected