summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2014-09-21 09:36:45 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2014-09-21 09:36:45 +0200
commitd40a2d23e2bde81d2ab2ef316b4b3c30450041eb (patch)
tree75f997d877ff8dac7b2fc8a8afec38f792392cf5
parentd6c86e2037dae147bb0292b9da109614872a99d7 (diff)
Read key and ssrc form config file.
-rw-r--r--src/audiooutputhandler.cc4
-rw-r--r--src/audiooutputhandler.h2
-rw-r--r--src/config.ini5
-rw-r--r--src/inputstreamer.cc43
-rw-r--r--src/inputstreamer.h14
-rw-r--r--src/mainwindow.cc40
-rw-r--r--src/mainwindow.h6
-rw-r--r--src/outputstreamer.cc9
-rw-r--r--src/outputstreamer.h5
-rw-r--r--src/simplertp.cc21
-rw-r--r--src/soundplayer.cc8
-rw-r--r--src/soundplayer.h4
12 files changed, 96 insertions, 65 deletions
diff --git a/src/audiooutputhandler.cc b/src/audiooutputhandler.cc
index bccbc50..1c58d7e 100644
--- a/src/audiooutputhandler.cc
+++ b/src/audiooutputhandler.cc
@@ -30,10 +30,10 @@ AudioOutputHandler::AudioOutputHandler()
{
}
-void AudioOutputHandler::newAudio(Frame frame)
+void AudioOutputHandler::newAudio(int peer, Frame frame)
{
char pcm[10000];
int ret = decoder.decode(frame, pcm, sizeof(pcm));
- if(ret > 0) player.playSamples(pcm, ret);
+ if(ret > 0) player.playSamples(peer, pcm, ret);
free(frame.data);
}
diff --git a/src/audiooutputhandler.h b/src/audiooutputhandler.h
index ff2054e..03777d6 100644
--- a/src/audiooutputhandler.h
+++ b/src/audiooutputhandler.h
@@ -38,7 +38,7 @@ public:
AudioOutputHandler();
public slots:
- void newAudio(Frame frame);
+ void newAudio(int peer, Frame frame);
private:
SoundPlayer player;
diff --git a/src/config.ini b/src/config.ini
index 9846903..67893e6 100644
--- a/src/config.ini
+++ b/src/config.ini
@@ -7,15 +7,14 @@ v4ldev="/dev/video0"
adev="hw:1,0"
[crypto]
-key=""
+key="123456789012345678901234567890123456789012345678901234567890"
+ssrc=1234567890
[peers]
num_peers=2
addr1="127.0.0.1"
port1=10000
-ssrc1=42
addr2="127.0.0.1"
port2=10001
-ssrc2=43 \ No newline at end of file
diff --git a/src/inputstreamer.cc b/src/inputstreamer.cc
index 3ddf36e..fdc5d2a 100644
--- a/src/inputstreamer.cc
+++ b/src/inputstreamer.cc
@@ -29,20 +29,23 @@
#include <QApplication>
#include <unistd.h>
-#define KEY "123456789012345678901234567890123456789012345678901234567890"
-#define SSRC 1234567890
#define CSRC_V 42
#define CSRC_A 43
-InputStreamer::InputStreamer(QHostAddress addr, quint16 port)
+InputStreamer::InputStreamer(int peer, QString peer_name,
+ QHostAddress addr, quint16 port,
+ QString key, unsigned int ssrc)
// : socket(this)
{
- total = 0;
-
-
+ this->peer = peer;
+ this->peer_name = peer_name;
+ this->key = key;
+ this->ssrc = ssrc;
this->addr = addr;
this->port = port;
+ total = 0;
+
name.sin_family = AF_INET;
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(sock < 0) {
@@ -87,15 +90,18 @@ void InputStreamer::run()
{
lrtp_status_t status;
- lrtp = lrtp_init(&status, KEY, SSRC);
- if(status != LRTP_OK) printf("O:lrtp_init err: %d\n", status);
+ char ckey[61];
+ strcpy(ckey, key.toStdString().c_str());
+
+ lrtp = lrtp_init(&status, ckey, ssrc);
+ if(status != LRTP_OK) printf("I:lrtp_init err: %d\n", status);
int res;
res = lrtp_create_profile(lrtp, PROFILE_JPEG, CSRC_V, OPTION_END);
- if(res != 0) printf("O:lrtp_create_profile (v) err: %d\n", res);
+ if(res != 0) printf("I:lrtp_create_profile (v) err: %d\n", res);
res = lrtp_create_profile(lrtp, PROFILE_OPUS, CSRC_A, OPTION_END);
- if(res != 0) printf("O:lrtp_create_profile (a) err: %d\n", res);
+ if(res != 0) printf("I:lrtp_create_profile (a) err: %d\n", res);
char packet[64*1024];
while(running) {
@@ -141,18 +147,18 @@ void InputStreamer::run()
unsigned int ts;
while((ret = lrtp_dequeue_frame(lrtp, frame, sizeof(frame), &csrc, &ts))
!= 0) {
- if(ret < 0) printf("\nlrtp_dequeue_frame: %d\n", ret);
+ if(ret < 0) printf("I:lrtp_dequeue_frame: %d\n", ret);
if(csrc == CSRC_V) {
// Video frame
Frame f(frame, ret);
f.ts = ts;
- emit newImage(f);
+ emit newImage(peer, f);
//printf("v"); fflush(stdout);
} else if(csrc == CSRC_A) {
// Audio frame
Frame f(frame, ret);
f.ts = ts;
- emit newAudio(f);
+ emit newAudio(peer, f);
//printf("a"); fflush(stdout);
} else {
printf("Unknown stream: CSRC: %d\n", csrc);
@@ -163,13 +169,13 @@ void InputStreamer::run()
printf("done\n");
status = lrtp_destroy_profile(lrtp, CSRC_V);
- if(status != LRTP_OK) printf("O:lrtp_destroy_profile (v) err: %d\n", status);
+ if(status != LRTP_OK) printf("I:lrtp_destroy_profile (v) err: %d\n", status);
status = lrtp_destroy_profile(lrtp, CSRC_A);
- if(status != LRTP_OK) printf("O:lrtp_destroy_profile (a) err: %d\n", status);
+ if(status != LRTP_OK) printf("I:lrtp_destroy_profile (a) err: %d\n", status);
status = lrtp_close(lrtp);
- if(status != LRTP_OK) printf("O:lrtp_close err: %d\n", status);
+ if(status != LRTP_OK) printf("I:lrtp_close err: %d\n", status);
}
size_t InputStreamer::getTotal()
@@ -178,3 +184,8 @@ size_t InputStreamer::getTotal()
total = 0;
return t;
}
+
+QString InputStreamer::getName()
+{
+ return peer_name;
+}
diff --git a/src/inputstreamer.h b/src/inputstreamer.h
index 842e0d2..d2053ab 100644
--- a/src/inputstreamer.h
+++ b/src/inputstreamer.h
@@ -42,16 +42,19 @@
class InputStreamer : public QThread {
Q_OBJECT
public:
- InputStreamer(QHostAddress addr, quint16 port);
+ InputStreamer(int peer, QString peer_name,
+ QHostAddress addr, quint16 port,
+ QString key, unsigned int ssrc);
~InputStreamer();
void run();
size_t getTotal();
+ QString getName();
signals:
- void newImage(Frame frame);
- void newAudio(Frame frame);
+ void newImage(int peer, Frame frame);
+ void newAudio(int peer, Frame frame);
private:
struct lrtp_t *lrtp;
@@ -67,6 +70,11 @@ private:
size_t total;
volatile bool running;
+
+ int peer;
+ QString peer_name;
+ QString key;
+ unsigned int ssrc;
};
#endif/*__SIMPLERTP_INPUTSTREAMER_H__*/
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index 8a7c44a..d7faf2d 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -26,7 +26,6 @@
*/
#include "mainwindow.h"
-#include <QLabel>
#include <QStatusBar>
#include <stdio.h>
@@ -40,13 +39,21 @@ MainWindow::MainWindow(QString v4ldev, QString adev,
connect(&v4l, SIGNAL(newImage(Frame)),
this, SLOT(newImage(Frame)));
*/
+ setCentralWidget(new QLabel);
+
+ memset(video, 0 ,sizeof(video));
+
+ int idx = 0;
QList<InputStreamer*>::iterator i = islist.begin();
while(i != islist.end()) {
- connect(*i, SIGNAL(newImage(Frame)),
- this, SLOT(newImage(Frame)));
- connect(*i, SIGNAL(newAudio(Frame)),
- &aoh, SLOT(newAudio(Frame)));
- i++;
+ connect(*i, SIGNAL(newImage(int,Frame)),
+ this, SLOT(newImage(int,Frame)));
+ connect(*i, SIGNAL(newAudio(int,Frame)),
+ &aoh, SLOT(newAudio(int,Frame)));
+ video[idx] = new QLabel(NULL);
+ video[idx]->resize(640,480);
+ video[idx]->show();
+ i++; idx++;
}
/*
@@ -64,14 +71,12 @@ MainWindow::MainWindow(QString v4ldev, QString adev,
status_timer.start(1000);
- setCentralWidget(new QLabel());
-
statusBar()->showMessage("Starting...");
}
void MainWindow::updateStatus()
{
- size_t ob = ostreamer.getTotal() / 60;
+ size_t ob = ostreamer.getTotal() / 60;
size_t ib = 0;
QList<InputStreamer*>::iterator i = islist.begin();
while(i != islist.end()) {
@@ -99,8 +104,9 @@ void MainWindow::updateStatus()
statusBar()->showMessage(status);
}
-void MainWindow::newImage(Frame frame)
+void MainWindow::newImage(int peer, Frame frame)
{
+ if(peer >= 10 || video[peer] == NULL) return;
QImage img;
bool res = img.loadFromData((const uchar*)frame.data, frame.size, "JPG");
// printf("processImage() => %s\n", res?"true":"false");
@@ -112,7 +118,7 @@ void MainWindow::newImage(Frame frame)
// printf("img->w: %d\n", img.width());
// printf("img->h: %d\n", img.height())
- QLabel *l = (QLabel*)centralWidget();
+ QLabel *l = video[peer];
QPixmap p;
p.convertFromImage(img);
l->setPixmap(p);
@@ -121,15 +127,3 @@ void MainWindow::newImage(Frame frame)
// printf("v"); fflush(stdout);
}
-
-void MainWindow::newAudio(framelist_t list)
-{
- /*
- framelist_t::iterator i = list.begin();
- while(i != list.end()) {
- sp.playSamples(*i);
- }
- // printf("audio: %d frames\n", list.size());
- */
- // printf("a"); fflush(stdout);
-}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index c3c6115..72ba092 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -31,6 +31,7 @@
#include <QString>
#include <QTimer>
#include <QList>
+#include <QLabel>
#include "v4l.h"
#include "audioinputhandler.h"
@@ -46,8 +47,7 @@ public:
QList<InputStreamer*> &islist);
public slots:
- void newImage(Frame frame);
- void newAudio(framelist_t list);
+ void newImage(int peer, Frame frame);
void updateStatus();
private:
@@ -58,6 +58,8 @@ private:
QList<InputStreamer*> &islist;
QTimer status_timer;
+
+ QLabel* video[10];
};
#endif/*__SIMPLERTP_MAINWINDOW_H__*/
diff --git a/src/outputstreamer.cc b/src/outputstreamer.cc
index e5b7436..0d7b557 100644
--- a/src/outputstreamer.cc
+++ b/src/outputstreamer.cc
@@ -26,19 +26,20 @@
*/
#include "outputstreamer.h"
-#define KEY "123456789012345678901234567890123456789012345678901234567890"
-#define SSRC 1234567890
#define CSRC_V 42
#define CSRC_A 43
-OutputStreamer::OutputStreamer()
+OutputStreamer::OutputStreamer(QString key, unsigned int ssrc)
: socket(this)
{
total = 0;
lrtp_status_t status;
- lrtp = lrtp_init(&status, KEY, SSRC);
+ char ckey[61];
+ strcpy(ckey, key.toStdString().c_str());
+
+ lrtp = lrtp_init(&status, ckey, ssrc);
if(status != LRTP_OK) printf("O:lrtp_init err: %d\n", status);
int res;
diff --git a/src/outputstreamer.h b/src/outputstreamer.h
index de5d010..cfc3ad6 100644
--- a/src/outputstreamer.h
+++ b/src/outputstreamer.h
@@ -38,7 +38,7 @@
class OutputStreamer : public QObject {
Q_OBJECT
public:
- OutputStreamer();
+ OutputStreamer(QString key, unsigned int ssrc);
~OutputStreamer();
void addPeer(QHostAddress addr, quint16 port);
@@ -65,6 +65,9 @@ private:
QUdpSocket socket;
size_t total;
+
+ QString key;
+ unsigned int ssrc;
};
#endif/*__SIMPLERTP_STREAMER_H__*/
diff --git a/src/simplertp.cc b/src/simplertp.cc
index ef71192..9a0a938 100644
--- a/src/simplertp.cc
+++ b/src/simplertp.cc
@@ -55,22 +55,35 @@ int main(int argc, char *argv[])
settings.beginGroup("crypto");
QString key = settings.value("key").toString();
+ unsigned int ssrc = settings.value("ssrc").toUInt();
settings.endGroup();
- OutputStreamer os;
+ // printf("Key: %s\n", key.toStdString().c_str());
+ // printf("SSrc: %u\n", ssrc);
+
+ if(key == "" || ssrc == 0) {
+ printf("Missing key/ssrc in config.\n");
+ return 1;
+ }
+
+ if(key.size() != 60) {
+ printf("Key length shoule be 60 it is %d\n", key.size());
+ return 1;
+ }
+
+ OutputStreamer os(key, ssrc);
QList<InputStreamer*> islist;
settings.beginGroup("peers");
int num_peers = settings.value("num_peers", "0").toInt();
for(int peer = 1; peer < num_peers + 1; peer++) {
QString saddr = settings.value("addr" + QString::number(peer)).toString();
+ QString name = settings.value("name" + QString::number(peer)).toString();
quint16 port = settings.value("port" + QString::number(peer)).toInt();
- unsigned int ssrc = settings.value("ssrc" + QString::number(peer)).toInt();
QHostAddress addr(saddr);
os.addPeer(addr, port);
- InputStreamer *is = new InputStreamer(addr, port);
+ InputStreamer *is = new InputStreamer(peer-1, name, addr, port, key, ssrc);
islist.push_back(is);
- // Create
}
settings.endGroup();
diff --git a/src/soundplayer.cc b/src/soundplayer.cc
index bc031d0..0f4fec2 100644
--- a/src/soundplayer.cc
+++ b/src/soundplayer.cc
@@ -36,7 +36,7 @@ SoundPlayer::SoundPlayer()
{
start();
pread = 0;
- pwrite = BUFSZ * 4;
+ for(int i = 0; i < 10; i++) pwrite[i] = BUFSZ * 4;
memset(ringbuffer, 0, sizeof(ringbuffer));
}
@@ -77,11 +77,11 @@ void SoundPlayer::run()
ao_shutdown();
}
-void SoundPlayer::playSamples(const char *pcm, size_t size)
+void SoundPlayer::playSamples(int peer, const char *pcm, size_t size)
{
short *p = (short*)pcm;
for(int i = 0; i < size / sizeof(short); i++) {
- ringbuffer[pwrite % RINGBUFFER] += p[i];
- pwrite++;
+ ringbuffer[pwrite[peer] % RINGBUFFER] += p[i];
+ pwrite[peer]++;
}
}
diff --git a/src/soundplayer.h b/src/soundplayer.h
index 33ba248..35138bd 100644
--- a/src/soundplayer.h
+++ b/src/soundplayer.h
@@ -50,14 +50,14 @@ public:
SoundPlayer();
~SoundPlayer();
- void playSamples(const char *pcm, size_t size);
+ void playSamples(int peer, const char *pcm, size_t size);
void run();
private:
volatile bool running;
short ringbuffer[RINGBUFFER];
- int pwrite;
+ int pwrite[16];
int pread;
};