From dc0e0e379ba1a9474f5e760c26c076fd1f13ac57 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 21 Sep 2014 10:57:35 +0200 Subject: Add peer name to video widget. --- src/Makefile.am | 12 +++++----- src/mainwindow.cc | 38 ++++++------------------------- src/mainwindow.h | 4 ++-- src/videowidget.cc | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/videowidget.h | 48 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 129 insertions(+), 38 deletions(-) create mode 100644 src/videowidget.cc create mode 100644 src/videowidget.h diff --git a/src/Makefile.am b/src/Makefile.am index 224dab9..5dcf5cf 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -26,11 +26,12 @@ simplertp_SOURCES = \ audiooutputhandler.cc \ soundplayer.cc \ outputstreamer.cc \ - inputstreamer.cc + inputstreamer.cc \ + videowidget.cc -simplertp-genkey_LDADD = -simplertp-genkey_CXXFLAGS = -simplertp-genkey_SOURCES = \ +simplertp_genkey_LDADD = +simplertp_genkey_CXXFLAGS = +simplertp_genkey_SOURCES = \ simplertp-genkey.cc EXTRA_DIST = \ @@ -46,7 +47,8 @@ EXTRA_DIST = \ audiooutputhandler.h \ soundplayer.h \ outputstreamer.h \ - inputstreamer.h + inputstreamer.h \ + videowidget.h simplertp_MOC = $(shell ../tools/MocList cc ) diff --git a/src/mainwindow.cc b/src/mainwindow.cc index d7faf2d..81ea65c 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -41,18 +41,18 @@ MainWindow::MainWindow(QString v4ldev, QString adev, */ setCentralWidget(new QLabel); - memset(video, 0 ,sizeof(video)); - int idx = 0; QList::iterator i = islist.begin(); while(i != islist.end()) { - connect(*i, SIGNAL(newImage(int,Frame)), - this, SLOT(newImage(int,Frame))); + VideoWidget *vw = new VideoWidget(idx, *i); + videowidgets.push_back(vw); + connect(*i, SIGNAL(newAudio(int,Frame)), &aoh, SLOT(newAudio(int,Frame))); - video[idx] = new QLabel(NULL); - video[idx]->resize(640,480); - video[idx]->show(); + + connect(*i, SIGNAL(newImage(int,Frame)), + vw, SLOT(newImage(int,Frame))); + i++; idx++; } @@ -103,27 +103,3 @@ void MainWindow::updateStatus() ; statusBar()->showMessage(status); } - -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"); - if(img.isNull()) { - printf("Invalid image\n"); - return; - } - - // printf("img->w: %d\n", img.width()); - // printf("img->h: %d\n", img.height()) - - QLabel *l = video[peer]; - QPixmap p; - p.convertFromImage(img); - l->setPixmap(p); - - free(frame.data); - - // printf("v"); fflush(stdout); -} diff --git a/src/mainwindow.h b/src/mainwindow.h index 72ba092..d8329bb 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -38,6 +38,7 @@ #include "audiooutputhandler.h" #include "outputstreamer.h" #include "inputstreamer.h" +#include "videowidget.h" class MainWindow : public QMainWindow { Q_OBJECT @@ -47,7 +48,6 @@ public: QList &islist); public slots: - void newImage(int peer, Frame frame); void updateStatus(); private: @@ -59,7 +59,7 @@ private: QTimer status_timer; - QLabel* video[10]; + QVector videowidgets; }; #endif/*__SIMPLERTP_MAINWINDOW_H__*/ diff --git a/src/videowidget.cc b/src/videowidget.cc new file mode 100644 index 0000000..a556e56 --- /dev/null +++ b/src/videowidget.cc @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * videowidget.cc + * + * Sun Sep 21 10:42:42 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 "videowidget.h" + +#include + +VideoWidget::VideoWidget(int peer, InputStreamer *is) +{ + this->is = is; + this->peer = peer; + resize(640, 480); + show(); +} + +void VideoWidget::newImage(int peer, Frame frame) +{ + if(peer != this->peer) return; + + QImage img; + bool res = img.loadFromData((const uchar*)frame.data, frame.size, "JPG"); + // printf("processImage() => %s\n", res?"true":"false"); + if(img.isNull()) { + printf("Invalid image\n"); + return; + } + + { + size_t font_size = 14; + size_t border = 4; + QPainter p(&img); + p.setPen(Qt::white); + p.setFont(QFont("Arial Bold", font_size)); + p.drawText(border, font_size + border, is->getName()); + } + + QPixmap p; + p.convertFromImage(img); + setPixmap(p); + + free(frame.data); +} diff --git a/src/videowidget.h b/src/videowidget.h new file mode 100644 index 0000000..ebcaeff --- /dev/null +++ b/src/videowidget.h @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * videowidget.h + * + * Sun Sep 21 10:42:41 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. + */ +#ifndef __SIMPLERTP_VIDEOWIDGET_H__ +#define __SIMPLERTP_VIDEOWIDGET_H__ + +#include + +#include "inputstreamer.h" +#include "frame.h" + +class VideoWidget : public QLabel { +Q_OBJECT +public: + VideoWidget(int peer, InputStreamer *is); + +public slots: + void newImage(int peer, Frame frame); + +private: + int peer; + InputStreamer *is; +}; + +#endif/*__SIMPLERTP_VIDEOWIDGET_H__*/ -- cgit v1.2.3