summaryrefslogtreecommitdiff
path: root/src/inputstreamer.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2014-09-20 11:53:40 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2014-09-20 11:53:40 +0200
commit808225629721c2f7d5c751edc60e5c6744be7886 (patch)
tree3d97fc3b7319b5f94e688a454de51b32321ebfd7 /src/inputstreamer.cc
parent46d4e577bceb12c9463fdf4ef1d9a9a348f13543 (diff)
First (crashing) prototype.
Diffstat (limited to 'src/inputstreamer.cc')
-rw-r--r--src/inputstreamer.cc122
1 files changed, 122 insertions, 0 deletions
diff --git a/src/inputstreamer.cc b/src/inputstreamer.cc
new file mode 100644
index 0000000..a1d7aa9
--- /dev/null
+++ b/src/inputstreamer.cc
@@ -0,0 +1,122 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * inputstreamer.cc
+ *
+ * Sat Sep 20 10:15:51 CEST 2014
+ * Copyright 2014 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of SimpleRTP.
+ *
+ * SimpleRTP is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * SimpleRTP is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with SimpleRTP; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "inputstreamer.h"
+
+#define KEY "123456789012345678901234567890123456789012345678901234567890"
+#define SSRC 1234567890
+#define CSRC_V 42
+#define CSRC_A 43
+
+InputStreamer::InputStreamer(QHostAddress addr, quint16 port)
+ : socket(this)
+{
+ total = 0;
+
+ socket.bind(port);
+ this->addr = addr;
+ this->port = port;
+
+ running = true;
+ start();
+}
+
+InputStreamer::~InputStreamer()
+{
+ running = false;
+ wait();
+}
+
+#include <unistd.h>
+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);
+
+ 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);
+
+ res = lrtp_create_profile(lrtp, PROFILE_OPUS, CSRC_A, OPTION_END);
+ if(res != 0) printf("O:lrtp_create_profile (a) err: %d\n", res);
+
+ char packet[16*1024];
+ while(running) {
+ qint64 packetsize =
+ socket.readDatagram(packet, (quint64)sizeof(packet), 0,0);
+ if(packetsize < 1) {
+ usleep(1000);
+ continue;
+ }
+ total += packetsize;
+
+ // Now decode the sucker....
+ lrtp_unpack(lrtp, packet, packetsize);
+ int n = 0;
+ int ret;
+ char frame[512 * 1024]; // 512kbyte should be enough for even the larges
+ // JPEG frames...
+ unsigned int csrc;
+ 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(csrc == CSRC_V) {
+ // Video frame
+ Frame f(frame, ret);
+ f.ts = ts;
+ emit newImage(f);
+ printf("v"); fflush(stdout);
+ } else if(csrc == CSRC_A) {
+ // Audio frame
+ Frame f(frame, ret);
+ f.ts = ts;
+ emit newAudio(f);
+ printf("a"); fflush(stdout);
+ } else {
+ printf("Unknown stream: CSRC: %d\n", csrc);
+ }
+ }
+ }
+
+ status = lrtp_destroy_profile(lrtp, CSRC_V);
+ if(status != LRTP_OK) printf("O: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);
+
+ status = lrtp_close(lrtp);
+ if(status != LRTP_OK) printf("O:lrtp_close err: %d\n", status);
+}
+
+size_t InputStreamer::getTotal()
+{
+ size_t t = total;
+ total = 0;
+ return t;
+}