Relaying a stream to a VLC client

About encoding, codec settings, muxers and filter usage
paulkatuliiba
New Cone
New Cone
Posts: 1
Joined: 05 Oct 2009 19:20

Relaying a stream to a VLC client

Postby paulkatuliiba » 05 Oct 2009 19:34

Hi this is my first time posting to a technical forum. I’ve written a simple C program that uses sockets.
I stream to it using VLC and it receives each RTP packet and sends it to a VLC client (on the same computer). But the client wont play the relayed stream. I go through the steps Open network stream-> Protocol: RTP, Address: xxx:xxx:xxx:xxx, Port 1234. -> Play but the VLC client does not display the video. I’ve even tried getting the VLC client to open up an sdp file that directs it to play whats on port 1234 but still it wont play.
Below is the simple C program if you need to look at it:

//----------------------------------------------------------------------
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>
#include <iostream.h>
#include <winerror.h>
#define RECEIVEPORT "1240"

#define SENDPORT "1234"


#define BACKLOG 10
#define MAXBUFLEN 100000
int main()
{
//-------------------------------------------------------------------------
WSADATA wsaData;
WORD version;
int error;

version = MAKEWORD( 2, 0 );

error = WSAStartup( version, &wsaData );

/* check for error */
if ( error != 0 )
{
/* error occured */
return FALSE;
}

/* check for correct version */
if ( LOBYTE( wsaData.wVersion ) != 2 ||
HIBYTE( wsaData.wVersion ) != 0 )
{
/* incorrect WinSock version */
WSACleanup();
return FALSE;
}

/* WinSock has been initialized */
//---------------------------------------------------------------------------

struct in_addr addr;

int sockfd, sockfd2;
struct addrinfo hints, *servinfo, hints2, *servinfo2;

int numbytes;
struct sockaddr_storage their_addr;
char buf[MAXBUFLEN];
int addr_len;
char s[INET6_ADDRSTRLEN];

char yes='1';

memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC; // set to AF_INET to force IPv4
hints.ai_socktype = SOCK_DGRAM;
hints.ai_flags = AI_PASSIVE; // use my IP

getaddrinfo(NULL, RECEIVEPORT, &hints, &servinfo) ;

sockfd = socket(servinfo->ai_family, servinfo->ai_socktype,servinfo->ai_protocol);
setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int));
bind(sockfd, servinfo->ai_addr, servinfo->ai_addrlen);

memset(&hints2, 0, sizeof hints2);
hints2.ai_family = AF_UNSPEC; // set to AF_INET to force IPv4
hints2.ai_socktype = SOCK_DGRAM;

getaddrinfo(NULL, SENDPORT, &hints2, &servinfo2) ;
sockfd2 = socket(servinfo2->ai_family, servinfo2->ai_socktype,servinfo2->ai_protocol);
setsockopt(sockfd2,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int));
addr_len = sizeof their_addr;

while(1)
{
numbytes =recvfrom(sockfd, buf, MAXBUFLEN-1 , 0,(struct sockaddr *)&their_addr, &addr_len);
cout<<"received "<<strlen(buf)<<endl;
numbytes = sendto(sockfd2, buf,strlen(buf), 0, servinfo2->ai_addr, servinfo2->ai_addrlen);
cout<<"sent "<<strlen(buf)<<endl;
}

WSACleanup();
return 0;
}
//------------------------------------------------------------------------------------------

I want to eventually extend this program to switch between lower or higher bitrate streams from different VLC streamers and relay the packets on to the single VLC client in the same way.(it’s for my thesis)
Any help is greatly appreciated! :)


What saves a man is to take a step. Then another step. It is always the same step, but you have to take it
- Antoine de Saint-Exupery

isync
Blank Cone
Blank Cone
Posts: 23
Joined: 18 Oct 2009 14:22

Re: Relaying a stream to a VLC client

Postby isync » 18 Oct 2009 15:13

Any progress on this thread? Please share.

vlc_rlk
Blank Cone
Blank Cone
Posts: 11
Joined: 21 Sep 2009 05:43

Re: Relaying a stream to a VLC client

Postby vlc_rlk » 23 Oct 2009 00:32

Hi paulkatuliiba,

How do you implement the C code that you have above? And also, how would you would you switch between lower or higher bitrate streams?

Thanks.


Return to “VLC stream-output (sout)”

Who is online

Users browsing this forum: No registered users and 11 guests