SOLVED: UdpSrc?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

SOLVED: UdpSrc?

killerrats
Administrator
This post was updated on .
Ethernet 1
Ethernet 2

I have a multi interfaces on my windows machine. I was wanting to get the
Udpsrc to use a specific ethernet but doesn't seem to work. I can join the
multicast network but the only way to do it, would be to disable the card
that doesn't go to that network. Then enable it after i join. So if Ethernet
2 is the one to join and work and the Ethernet 1 is the one that is for
internet. If I have Ethernet 2 disabled and then windows will try to join
the network on Ethernet 1. But if i re-enable the Ethernet 2 it will still
try Ethernet 1 until I disable Ethernet 1 again. Any ideas?

[Video iP] = 232.232.232.0
[Ethernet] = 10.0.0.1

gst-launch-1.0 --gst-debug="*udpsrc,6" udpsrc multicast-iface="Ethernet 2"
address=[Video iP] port=61454
caps=application/x-rtp,media=video,payload=90000 ! rtpmp4vdepay !
mpeg4videoparse ! avdec_mpeg4 ! d3dvideosink sync=false



-----
------------------------------
Gstreamer 1.14.3
------------------------------
Windows
--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
gstreamer-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
------------------------------
Gstreamer 1.16.2
------------------------------
Windows
Reply | Threaded
Open this post in threaded view
|

Re: UdpSrc?

Nicolas Dufresne-5
Le mercredi 09 octobre 2019 à 16:52 -0500, killerrats a écrit :

> Ethernet 1
> Ethernet 2
>
> I have a multi interfaces on my windows machine. I was wanting to get the
> Udpsrc to use a specific ethernet but doesn't seem to work. I can join the
> multicast network but the only way to do it, would be to disable the card
> that doesn't go to that network. Then enable it after i join. So if Ethernet
> 2 is the one to join and work and the Ethernet 1 is the one that is for
> internet. If I have Ethernet 2 disabled and then windows will try to join
> the network on Ethernet 1. But if i re-enable the Ethernet 2 it will still
> try Ethernet 1 until I disable Ethernet 1 again. Any ideas?
>
> [Video iP] = 232.232.232.0
> [Ethernet] = 10.0.0.1
>
> gst-launch-1.0 --gst-debug="*udpsrc,6" udpsrc multicast-iface="Ethernet 2"
> address=[Video iP] port=61454
> caps=application/x-rtp,media=video,payload=90000 ! rtpmp4vdepay !
> mpeg4videoparse ! avdec_mpeg4 ! d3dvideosink sync=false

On Windows, interface are identified with it's IP address. So
multicast-iface on windows is expecting an IP.

Nicolas

>
>
>
> -----
> ------------------------------
> Gstreamer 1.14.3
> ------------------------------
> Windows
> --
> Sent from: http://gstreamer-devel.966125.n4.nabble.com/
> _______________________________________________
> gstreamer-devel mailing list
> [hidden email]
> https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: UdpSrc?

killerrats
Administrator
I tried putting in my ip for the interface but didn't seem to work.



-----
------------------------------
Gstreamer 1.14.3
------------------------------
Windows
--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
------------------------------
Gstreamer 1.16.2
------------------------------
Windows
Reply | Threaded
Open this post in threaded view
|

Re: UdpSrc?

killerrats
Administrator
In reply to this post by Nicolas Dufresne-5

following method I got to work to set in the udpsrc to connect to a multicast address. the only thing is that the line that says:

g_socket_bind(socketUDP, g_inet_socket_address_new(g_inet_address_new_from_string(interfaceIp), port), TRUE, &err);

doesn't bind to the interface. if i changed to:

g_socket_bind(socketUDP, g_inet_socket_address_new(g_inet_address_new_any(G_SOCKET_FAMILY_IPV4), port), TRUE, &err)

seems to bind the first available interface which is not the one i want. any suggestions?

GSocket* GetTheSocketReady(const char* ipaddress, const int portNumber, const char* interfaceIp)
{
	GSocketAddress *bind_addr;
	GInetAddress *bind_iaddr;
	GSocketFamily family;
	guint16 port = portNumber;
	GError *err = NULL;
	gint val = 0;
	const guint8 *native_addr;
	struct ip_mreq mc_req;

	GInetSocketAddress *bAddr;
	guint16 bPort;

	bind_iaddr = g_inet_address_new_from_string(ipaddress);
	bind_addr = g_inet_socket_address_new(bind_iaddr, port);

	family = g_socket_address_get_family(G_SOCKET_ADDRESS(bind_addr));

	GSocket * socketUDP = g_socket_new(family, G_SOCKET_TYPE_DATAGRAM, G_SOCKET_PROTOCOL_UDP, &err);
	if (socketUDP == NULL)
	{
		printf("Could not create socket: %s", err->message);
		g_object_unref(bind_addr);

		goto Error;
	}

		if (!g_socket_bind(socketUDP, g_inet_socket_address_new(g_inet_address_new_from_string(interfaceIp), port), TRUE, &err))
		{
			printf("Failed to bind socket: %s", err->message);
			goto Error;
		}
		g_socket_set_multicast_loopback(socketUDP, TRUE);

		if (g_socket_get_option(socketUDP, SOL_SOCKET, SO_RCVBUF, &val,
			NULL)) {
			std::cout << "\r\nReceived\r\n";
		}
		else {
			goto Error;
		}

		g_socket_set_broadcast(socketUDP, TRUE);

		native_addr = g_inet_address_to_bytes(bind_iaddr);

		memset(&mc_req, 0, sizeof(mc_req));
		memcpy(&mc_req.imr_multiaddr, native_addr, sizeof(struct in_addr));

		mc_req.imr_interface.s_addr = inet_addr(interfaceIp);

		if (setsockopt(g_socket_get_fd(socketUDP), IPPROTO_IP, IP_ADD_MEMBERSHIP,
			(char*)&mc_req, sizeof(mc_req)))
		{
			printf("\r\nYeah\r\n");
		}
	

End:
	{
		g_object_unref(bind_iaddr);

		return socketUDP;
	}
	Error:
	{
		g_object_unref(bind_iaddr);

		return NULL;
	}
}
------------------------------
Gstreamer 1.14.3
------------------------------
Windows


Sent from the GStreamer-devel mailing list archive at Nabble.com.

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
------------------------------
Gstreamer 1.16.2
------------------------------
Windows
Reply | Threaded
Open this post in threaded view
|

Re: UdpSrc?

killerrats
Administrator
This post was updated on .
In reply to this post by Nicolas Dufresne-5

I tried this but didn't seemed to work at all either. seemed to say unknown family

SOCKET fd = getSocket(ipaddress, interfaceIp, portNumber);
	socketUDP = g_socket_new_from_fd(fd, &err);

SOCKET getSocket(const char* ipaddress,const char* interfaceIp,const int portNumber)
	{
		struct sockaddr_in addr;
		struct sockaddr_in* pAddr;
		struct sockaddr_in* a;
		struct sockaddr_in aa;
		struct group_req mreq;
		a = &aa;
		pAddr = &addr;
		int fd = socket(AF_INET, SOCK_DGRAM, 0);

		memset(&addr, 0, sizeof(addr));
		memset(&aa, 0, sizeof(aa));

		addr.sin_family = AF_INET;
		addr.sin_addr.s_addr = InetPtonW(AF_INET, L"232.232.232.0", &pAddr->sin_addr);
		addr.sin_port = ntohs(portNumber);

		bind(fd, (const struct sockaddr *) &addr, sizeof(addr)) == 0;

		mreq.gr_interface = InetPtonW(AF_INET, L"10.16.14.210", &a->sin_addr);
		memset(&mreq.gr_group, 0, sizeof(mreq.gr_group));
		a = (struct sockaddr_in *) &mreq.gr_group;
		a->sin_family = AF_INET;
		a->sin_port = portNumber;

		setsockopt(fd, IPPROTO_IP, MCAST_JOIN_GROUP, (const char*)&mreq, sizeof(mreq)) == 0;

		return fd;

	}
------------------------------
Gstreamer 1.16.2
------------------------------
Windows
Reply | Threaded
Open this post in threaded view
|

Re: UdpSrc?

killerrats
Administrator
In reply to this post by Nicolas Dufresne-5

Got it to work. the ones in bold and big are the ones I edited in the code.

GSocket* GetTheSocketReady(const char* ipaddress, const int portNumber, const char* interfaceIp)
{
	GSocketAddress *bind_addr;
	GInetAddress *bind_iaddr;
	GSocketFamily family;
	guint16 port = portNumber;
	GError *err = NULL;
	gint val = 0;
	const guint8 *native_addr;
	struct ip_mreq mc_req;

	GInetSocketAddress *bAddr;
	guint16 bPort;

	bind_iaddr = g_inet_address_new_from_string(ipaddress);
	bind_addr = g_inet_socket_address_new(bind_iaddr, port);

	family = g_socket_address_get_family(G_SOCKET_ADDRESS(bind_addr));

	GSocket * socketUDP = g_socket_new(family, G_SOCKET_TYPE_DATAGRAM, G_SOCKET_PROTOCOL_UDP, &err);
	if (socketUDP == NULL)
	{
		printf("Could not create socket: %s", err->message);
		g_object_unref(bind_addr);

		goto Error;
	}

	if (!g_socket_bind(socketUDP, g_inet_socket_address_new(g_inet_address_new_from_string(interfaceIp), port), TRUE, &err))
	{
		printf("Failed to bind socket: %s", err->message);
		goto Error;
	}
	g_socket_set_multicast_loopback(socketUDP, TRUE);

	if (g_socket_get_option(socketUDP, SOL_SOCKET, SO_RCVBUF, &val,
		NULL)) {
		std::cout << "\r\nReceived\r\n";
	}
	else {
		goto Error;
	}

	g_socket_set_broadcast(socketUDP, TRUE);

	native_addr = g_inet_address_to_bytes(bind_iaddr);

	memset(&mc_req, 0, sizeof(mc_req));
	memcpy(&mc_req.imr_multiaddr, native_addr, sizeof(struct in_addr));

	inet_pton(AF_INET, interfaceIp, &mc_req.imr_interface);
        inet_pton(AF_INET, ipaddress, &mc_req.imr_multiaddr);

	if (setsockopt(g_socket_get_fd(socketUDP), IPPROTO_IP, IP_ADD_MEMBERSHIP,
		(char*)&mc_req, sizeof(mc_req)))
	{
		printf("\r\nYeah\r\n");
	}


End:
	{
		g_object_unref(bind_iaddr);

		return socketUDP;
	}
Error:
	{
		g_object_unref(bind_iaddr);

		return NULL;
	}
}
------------------------------
Gstreamer 1.14.3
------------------------------
Windows


Sent from the GStreamer-devel mailing list archive at Nabble.com.

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
------------------------------
Gstreamer 1.16.2
------------------------------
Windows