Commit e7b003b2 authored by hark's avatar hark
Browse files

working snowmixaudiosink

parent 80dac0f1
......@@ -10,6 +10,10 @@ CFLAGS= -O0 -march=native -Wall -Wextra -Wno-unused-parameter -Wno-unused-variab
all : c-player c-player-0.10 c-player-debug vartest snowControl s2s s2s-cli bigscreen
rot13: rot13.c
gcc -DTESTING -DGTK -g rot13.c -o rot13 `pkg-config --cflags --libs libevent gstreamer-interfaces-0.10 gstreamer-pbutils-0.10 gtk+-2.0 gstreamer-0.10` $(CFLAGS)
tcpclient: tcpclient.c
gcc -DTESTING -DGTK -g tcpclient.c -o tcpclient `pkg-config --cflags --libs gstreamer-interfaces-0.10 gstreamer-pbutils-0.10 gtk+-2.0 gstreamer-0.10` $(CFLAGS)
......@@ -30,7 +34,7 @@ c-player-debug : c-player.c
gcc -D TT -DTESTING -DGTK -DGST1 -g c-player.c wraps.c playlist.c snowbin.c teebin.c -o c-player-debug `pkg-config --cflags --libs gtk+-2.0 gstreamer-1.0 gstreamer-pbutils-1.0 gstreamer-video-1.0` $(CFLAGS)
c-player : c-player.c snowbin.c playlist.c teebin.c wraps.c
gcc -DGTK -DGST1 -g c-player.c wraps.c playlist.c snowbin.c teebin.c -o c-player `pkg-config --cflags --libs gtk+-2.0 gstreamer-1.0 gstreamer-pbutils-1.0 gstreamer-video-1.0` $(CFLAGS)
gcc -DFP -DGTK -DGST1 -g c-player.c wraps.c playlist.c snowbin.c teebin.c -o c-player `pkg-config --cflags --libs gtk+-2.0 gstreamer-1.0 gstreamer-pbutils-1.0 gstreamer-video-1.0` $(CFLAGS)
c-player-cli : c-player.c
gcc -DGST1 -g c-player.c wraps.c playlist.c snowbin.c teebin.c -o c-player-cli `pkg-config --cflags --libs gtk+-2.0 gstreamer-1.0 gstreamer-pbutils-1.0 gstreamer-video-1.0` $(CFLAGS)
......
......@@ -32,7 +32,21 @@
#include <unistd.h>
#include <time.h>
#include <regex.h>
// switch for strings
#include "switchs.h"
// sockets
#include <netinet/in.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
//glib stuff
//#include <glib.h>
//#include <glib-2.0/glib/gprintf.h>
......
......@@ -1013,18 +1013,18 @@ playlist_init_gtk ()
G_CALLBACK (playlist_selection_changed_cb), NULL);
/*discoverer */
discoverer_init ();
#ifdef TESTING
#ifdef FP
/* put some stuff in playlist */
playlist_add_item("file:///crypthome/hark/media/pinknoise/vloek/video/De Vloek Defends Autonomous Zone From Eviction (Interview)-SD.mp4");
playlist_add_item("file:///crypthome/hark/media/pinknoise/vloek/Mini Documentaire over de ontruiming van de Vloek op Scheveningen.");
playlist_add_item("file:///crypthome/hark/media/pinknoise/vloek/input/input/mob5-1441765927-09-Sep-15-04:32:07.flv");
playlist_add_item ("http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_stereo.ogg");
playlist_add_item ("https://archive.org/download/ElephantsDream_628/ElephantsDream_720p_DivXPlus_512kb.mp4");
playlist_add_item ("https://archive.org/download/marcelo_bronxnet_SegB_201509/segB.m4v");
playlist_add_item
("file:///home/yids/src/cpu/snowmix/test/LES_TDS_launch.mp4");
playlist_add_item("file:///home/yids/Videos/Sintel.2010.720p.mkv");
playlist_add_item("file:///crypthome/hark/media/pinknoise/vloek/video/De Vloek Defends Autonomous Zone From Eviction (Interview)-SD.mp4");
playlist_add_item("file:///crypthome/hark/media/pinknoise/vloek/Mini Documentaire over de ontruiming van de Vloek op Scheveningen.");
playlist_add_item("file:///crypthome/hark/media/pinknoise/vloek/input/input/mob5-1441765927-09-Sep-15-04:32:07.flv");
/*
......
/* For sockaddr_in */
#include <netinet/in.h>
/* For socket functions */
#include <sys/socket.h>
/* For fcntl */
#include <fcntl.h>
#include <event2/event.h>
#include <event2/buffer.h>
#include <event2/bufferevent.h>
#include <assert.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#define MAX_LINE 16384
void do_read(evutil_socket_t fd, short events, void *arg);
void do_write(evutil_socket_t fd, short events, void *arg);
char
rot13_char(char c)
{
/* We don't want to use isalpha here; setting the locale would change
* which characters are considered alphabetical. */
if ((c >= 'a' && c <= 'm') || (c >= 'A' && c <= 'M'))
return c + 13;
else if ((c >= 'n' && c <= 'z') || (c >= 'N' && c <= 'Z'))
return c - 13;
else
return c;
}
void
readcb(struct bufferevent *bev, void *ctx)
{
struct evbuffer *input, *output;
char *line;
size_t n;
int i;
input = bufferevent_get_input(bev);
output = bufferevent_get_output(bev);
while ((line = evbuffer_readln(input, &n, EVBUFFER_EOL_LF))) {
for (i = 0; i < n; ++i)
line[i] = rot13_char(line[i]);
evbuffer_add(output, line, n);
evbuffer_add(output, "\n", 1);
free(line);
}
if (evbuffer_get_length(input) >= MAX_LINE) {
/* Too long; just process what there is and go on so that the buffer
* doesn't grow infinitely long. */
char buf[1024];
while (evbuffer_get_length(input)) {
int n = evbuffer_remove(input, buf, sizeof(buf));
for (i = 0; i < n; ++i)
buf[i] = rot13_char(buf[i]);
evbuffer_add(output, buf, n);
}
evbuffer_add(output, "\n", 1);
}
}
void
errorcb(struct bufferevent *bev, short error, void *ctx)
{
if (error & BEV_EVENT_EOF) {
/* connection has been closed, do any clean up here */
/* ... */
} else if (error & BEV_EVENT_ERROR) {
/* check errno to see what error occurred */
/* ... */
} else if (error & BEV_EVENT_TIMEOUT) {
/* must be a timeout event handle, handle it */
/* ... */
}
bufferevent_free(bev);
}
void
do_accept(evutil_socket_t listener, short event, void *arg)
{
struct event_base *base = arg;
struct sockaddr_storage ss;
socklen_t slen = sizeof(ss);
int fd = accept(listener, (struct sockaddr*)&ss, &slen);
if (fd < 0) {
perror("accept");
} else if (fd > FD_SETSIZE) {
close(fd);
} else {
struct bufferevent *bev;
evutil_make_socket_nonblocking(fd);
bev = bufferevent_socket_new(base, fd, BEV_OPT_CLOSE_ON_FREE);
bufferevent_setcb(bev, readcb, NULL, errorcb, NULL);
bufferevent_setwatermark(bev, EV_READ, 0, MAX_LINE);
bufferevent_enable(bev, EV_READ|EV_WRITE);
}
}
void
run(void)
{
evutil_socket_t listener;
struct sockaddr_in sin;
struct event_base *base;
struct event *listener_event;
base = event_base_new();
if (!base)
return; /*XXXerr*/
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = 0;
sin.sin_port = htons(40713);
listener = socket(AF_INET, SOCK_STREAM, 0);
evutil_make_socket_nonblocking(listener);
#ifndef WIN32
{
int one = 1;
setsockopt(listener, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
}
#endif
if (bind(listener, (struct sockaddr*)&sin, sizeof(sin)) < 0) {
perror("bind");
return;
}
if (listen(listener, 16)<0) {
perror("listen");
return;
}
listener_event = event_new(base, listener, EV_READ|EV_PERSIST, do_accept, (void*)base);
/*XXX check it */
event_add(listener_event, NULL);
event_base_dispatch(base);
}
int
main(int c, char **v)
{
setvbuf(stdout, NULL, _IONBF, 0);
run();
return 0;
}
......@@ -21,10 +21,76 @@
#ifdef CLI
#include "s2s-cli.h"
#else
#include "common.h"
#endif
#include "common.h"
// for snowaudiosink
#define MAXDATASIZE 1000 // max number of bytes we can get at once
// get sockaddr, IPv4 or IPv6:
void *get_in_addr(struct sockaddr *sa)
{
if (sa->sa_family == AF_INET) {
return &(((struct sockaddr_in*)sa)->sin_addr);
}
return &(((struct sockaddr_in6*)sa)->sin6_addr);
}
static int
open_client_socket(char *host, char *port)
{
int sockfd;
char buf[MAXDATASIZE];
struct addrinfo hints, *servinfo, *p;
int rv;
char s[INET6_ADDRSTRLEN];
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
if ((rv = getaddrinfo(host, port, &hints, &servinfo)) != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
return 1;
}
// loop through all the results and connect to the first we can
for(p = servinfo; p != NULL; p = p->ai_next) {
if ((sockfd = socket(p->ai_family, p->ai_socktype,
p->ai_protocol)) == -1) {
perror("client: socket");
continue;
}
if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
close(sockfd);
perror("client: connect");
continue;
}
break;
}
if (p == NULL) {
fprintf(stderr, "client: failed to connect\n");
return 2;
}
//set nonblocking
// fcntl(sockfd, F_SETFL, O_NONBLOCK);
inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr),
s, sizeof s);
printf("client: connecting to %s\n", s);
freeaddrinfo(servinfo); // all done with this structure
return sockfd;
}
int
get_vars (snowMixer *mixer, snowFeed *feed)
......@@ -322,49 +388,38 @@ get_jacksink (int feedid)
}
extern GstElement *
get_snowsink (int feedid)
get_snowaudiosink (int feedid)
{
GstElement *fdsink, *abin;
int socket;
GstElement *fdsink, *abin, *capsfilter, *audioconvert;
char *feedname = "feedfuck";
char *startaudio = "audio feed ctr isaudio 1 \n asdfasdfasdfsadfsadfasdfsadf";
asprintf (&feedname, "feed%u", feedid);
asprintf (&startaudio, "audio feed ctr isaudio %u \n", feedid);
abin = gst_bin_new("snowmix socket");
printf("createing snowaudiosinke \n \n \n ");
// file descriptor sink
socket = open_client_socket("localhost", "9999" );
write(socket, startaudio, strlen(startaudio));
// set filedescriptor
fdsink = gst_element_factory_make("fdsink","fdsink");
// start nc
int filedes[2];
if (pipe(filedes) == -1)
{
perror("pipe");
exit(1);
}
g_object_set( G_OBJECT (fdsink), "fd", socket, NULL);
// fdsink = gst_element_factory_make("fakesink","fakesink123");
audioconvert = gst_element_factory_make ("audioconvert", "audioconvert123");
// gst_bin_add_many (GST_BIN (abin), audioconvert, fdsink,NULL);
// gst_element_link_many (audioconvert, fdsink, NULL);
pid_t pid = fork();
if (pid == -1)
{
perror("fork");
//exit(1);
}
else if (pid == 0)
{
while ((dup2(filedes[1], STDOUT_FILENO) == -1) && (errno == EINTR)) {}
close(filedes[1]);
close(filedes[0]);
printf("executing nc\n");
execl("/bin/nc", "nc", "--stdout", "127.0.0.1", "9999");
perror("execl");
//_exit(1);
}
close(filedes[1]);
printf("fd: %i\n", filedes[0]);
// set filedescriptor
g_object_set( G_OBJECT (fdsink), "fd", filedes[0], NULL);
printf("END: createing snowaudiosinke \n \n \n ");
return abin;
return fdsink;
}
......@@ -400,7 +455,7 @@ snowbin_init_snowData (PlayerData *s)
extern GstElement *
get_snowaudiobin (snowData *sd)
{
GstElement *jackaudiosink, *audioconvert;
GstElement *audiosink, *audioconvert, *capsfilter;
GstPad *apad, *aghostpad;
GstElement *snowaudiobin;
char *feedname = "feedfuck";
......@@ -408,13 +463,29 @@ get_snowaudiobin (snowData *sd)
snowaudiobin = gst_bin_new ("snowaudiobin");
jackaudiosink = get_jacksink(sd->currentFeed->id);
// audiosink = get_jacksink(sd->currentFeed->id);
audiosink = get_snowaudiosink(sd->currentFeed->id);
//AUDIOFORMAT='audio/x-raw,format=S16LE,rate='$feed_rate',channels='$feed_channels
GstCaps *caps = gst_caps_new_simple ("audio/x-raw",
"rate", G_TYPE_INT, 4800,
"channels", G_TYPE_INT, 2,
"format", G_TYPE_STRING, "S16LE",
NULL);
capsfilter = gst_element_factory_make ("capsfilter", "capsfilter123");
g_object_set (G_OBJECT (capsfilter), "caps", caps, NULL);
audioconvert = gst_element_factory_make ("audioconvert", "audioconvert");
gst_bin_add_many (GST_BIN (snowaudiobin), audioconvert, jackaudiosink,
gst_bin_add_many (GST_BIN (snowaudiobin), audioconvert, capsfilter, audiosink,
NULL);
gst_element_link_many (audioconvert, jackaudiosink, NULL);
gst_element_link_many (audioconvert, capsfilter, audiosink, NULL);
apad = gst_element_get_static_pad (audioconvert, "sink");
aghostpad = gst_ghost_pad_new ("sink", apad);
......
......@@ -22,6 +22,6 @@
extern GstBin *get_snowvideobin (snowData *);
extern GstBin *get_snowaudiobin (snowData *);
extern snowData *snowbin_init_snowData (snowData *);
extern snowData *snowbin_init_snowData (PlayerData *);
extern void print_snowFeed(snowFeed *);
extern void print_snowMixer(snowMixer *);
......@@ -9,6 +9,7 @@
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <fcntl.h>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment