Skip to content

Commit

Permalink
Add -H option for rsdplay.
Browse files Browse the repository at this point in the history
  • Loading branch information
Themaister committed Apr 16, 2011
1 parent f32e571 commit 6bb36fc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions doc/rsdplay.1
Expand Up @@ -52,6 +52,10 @@ Uses FILE as input source, rather than \fBstdin\fR.
\fB--identity TAG, -i TAG\fR
Defines TAG as identity string for rsdplay. Defaults to "rsdplay".

.TP
\fB--high, -H\fR
Enables high-latency connection with big buffers. Most likely needed if you need to stream audio over the internet.

.SH "ENVIRONMENTAL VARIABLES"

.TP
Expand Down
31 changes: 30 additions & 1 deletion src/client.c
Expand Up @@ -25,6 +25,7 @@
#include <rsound.h>
#define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#include <ws2tcpip.h>
#else
#include "librsound/rsound.h"
#include <signal.h>
Expand All @@ -36,16 +37,29 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include "config.h"
#endif

#undef CONST_CAST
#ifdef _WIN32
#undef close
#define close(x) closesocket(x)
#define CONST_CAST (const char*)
#else
#define CONST_CAST
#endif

#define READ_SIZE 1024
#define HEADER_SIZE 44

static int raw_mode = 0;
static uint32_t raw_rate = 44100;
static uint16_t channel = 2;
static int format = 0;
static int high_latency = 0;

static char port[128] = "";
static char host[1024] = "";
Expand Down Expand Up @@ -100,6 +114,14 @@ int main(int argc, char **argv)
return 1;
}

if ( high_latency )
{
int bufsiz = 1 << 20;
setsockopt(rsd_fd, SOL_SOCKET, SO_SNDBUF, CONST_CAST &bufsiz, sizeof(int));
int flag = 0;
setsockopt(rsd_fd, IPPROTO_TCP, TCP_NODELAY, CONST_CAST &flag, sizeof(int));
}

buffer = malloc ( READ_SIZE );
if ( buffer == NULL )
{
Expand All @@ -122,6 +144,8 @@ int main(int argc, char **argv)
if ( infile )
fclose(infile);

close(rsd_fd);

return 0;
}

Expand Down Expand Up @@ -249,6 +273,7 @@ static void print_help()
printf("-f/--file: Uses file rather than stdin\n");
printf("-s/--server: More explicit way of assigning hostname\n");
printf("-i/--identity: Defines the identity associated with this client. Defaults to \"rsdplay\"\n");
printf("-H/--high: Uses a high-latency connection with big buffers. Ideal for transmission over internet.\n");
}

static void parse_input(int argc, char **argv)
Expand All @@ -264,10 +289,11 @@ static void parse_input(int argc, char **argv)
{ "file", 1, NULL, 'f'},
{ "server", 1, NULL, 's'},
{ "identity", 1, NULL, 'i'},
{ "high", 0, NULL, 'H' },
{ NULL, 0, NULL, 0 }
};

char optstring[] = "r:p:hc:f:B:s:i:";
char optstring[] = "r:p:hc:f:B:s:i:H";
while ( 1 )
{
c = getopt_long ( argc, argv, optstring, opts, &option_index );
Expand Down Expand Up @@ -354,6 +380,9 @@ static void parse_input(int argc, char **argv)
}
break;

case 'H':
high_latency = 1;
break;

default:
fprintf(stderr, "Error in parsing arguments.\n");
Expand Down

0 comments on commit 6bb36fc

Please sign in to comment.