Skip to content

Commit

Permalink
renamed outputstreamhandler
Browse files Browse the repository at this point in the history
  • Loading branch information
taraldv committed Aug 1, 2020
1 parent ece0fa4 commit a5ffd65
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 41 deletions.
1 change: 1 addition & 0 deletions components/TaskBar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ Rectangle {
property var toggled: true
onClicked: {
//streamHandler.stopRecording();
//TODO handle return value?
sessionHandler.leaveSession();
changePage("home");
}
Expand Down
2 changes: 1 addition & 1 deletion handlers/inputstreamhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void InputStreamHandler::addStreamToVector(int index, QString streamId, QString
mAudioPlaybackStartedVector.push_back(false);
mVideoPlaybackStartedVector.push_back(false);

//Your own image is at 0, so we add 1 here and in videoPlayback constructor
//Your own image is at 0, but index 0 in the vectors is NOT you.
mImageHandler->addPeer((index + 1), displayName);
}

Expand Down
28 changes: 14 additions & 14 deletions handlers/streamhandler.cpp → handlers/outputstreamhandler.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "streamhandler.h"
#include "outputstreamhandler.h"


StreamHandler::StreamHandler(ImageHandler* _imageHandler, UdpSocketHandler* _socketHandler, int bufferSize, Settings* settings, TcpSocketHandler* tcpSocketHandler, QObject *parent) : QObject(parent)
OutputStreamHandler::OutputStreamHandler(ImageHandler* _imageHandler, UdpSocketHandler* _socketHandler, int bufferSize, Settings* settings, TcpSocketHandler* tcpSocketHandler, QObject *parent) : QObject(parent)
{
mSettings = settings;
mBufferSize = bufferSize;
Expand All @@ -18,7 +18,7 @@ StreamHandler::StreamHandler(ImageHandler* _imageHandler, UdpSocketHandler* _soc
}
}

void StreamHandler::init()
void OutputStreamHandler::init()
{
mVideoEnabled = mSettings->getVideoOn();
mAudioEnabled = mSettings->getAudioOn();
Expand Down Expand Up @@ -51,7 +51,7 @@ void StreamHandler::init()
}
}

void StreamHandler::close()
void OutputStreamHandler::close()
{
qDebug() << "Closing streamHandler";

Expand Down Expand Up @@ -85,7 +85,7 @@ void StreamHandler::close()



void StreamHandler::grabVideoHeader()
void OutputStreamHandler::grabVideoHeader()
{
if(mVideoHandler == nullptr)
{
Expand All @@ -103,7 +103,7 @@ void StreamHandler::grabVideoHeader()
mVideoHandler = nullptr;
}

int StreamHandler::enableAudio()
int OutputStreamHandler::enableAudio()
{
mAudioEnabled = true;
qDebug() << "enabling audio";
Expand All @@ -130,7 +130,7 @@ int StreamHandler::enableAudio()
return 0;
}

void StreamHandler::disableAudio()
void OutputStreamHandler::disableAudio()
{
if(mAudioHandler != nullptr)
{
Expand All @@ -141,7 +141,7 @@ void StreamHandler::disableAudio()
}
}

int StreamHandler::enableVideo()
int OutputStreamHandler::enableVideo()
{
mVideoEnabled = true;
qDebug() << "enabling video";
Expand Down Expand Up @@ -170,7 +170,7 @@ int StreamHandler::enableVideo()
return 0;
}

void StreamHandler::disableVideo()
void OutputStreamHandler::disableVideo()
{
if(mVideoHandler != nullptr)
{
Expand All @@ -181,12 +181,12 @@ void StreamHandler::disableVideo()
}
}

QVariantList StreamHandler::getAudioInputDevices()
QVariantList OutputStreamHandler::getAudioInputDevices()
{
return mAudioHandler->getAudioInputDevices();
}

void StreamHandler::changeAudioInputDevice(QString deviceName)
void OutputStreamHandler::changeAudioInputDevice(QString deviceName)
{
qDebug() << "Changing Audio to: " << deviceName;
mAudioDevice = deviceName;
Expand All @@ -195,17 +195,17 @@ void StreamHandler::changeAudioInputDevice(QString deviceName)
enableAudio();
}

QString StreamHandler::getDefaultAudioInputDevice()
QString OutputStreamHandler::getDefaultAudioInputDevice()
{
return "default";
}

bool StreamHandler::checkVideoEnabled()
bool OutputStreamHandler::checkVideoEnabled()
{
return mVideoEnabled;
}

bool StreamHandler::checkAudioEnabled()
bool OutputStreamHandler::checkAudioEnabled()
{
return mAudioEnabled;
}
4 changes: 2 additions & 2 deletions handlers/streamhandler.h → handlers/outputstreamhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
#include "settings.h"
#include "handlers/errorhandler.h"

class StreamHandler : public QObject
class OutputStreamHandler : public QObject
{
Q_OBJECT
public:
StreamHandler(ImageHandler* _imageHandler, UdpSocketHandler* _socketHandler, int buffer_size, Settings* settings, TcpSocketHandler* tcpSocketHandler, QObject *parent = nullptr);
OutputStreamHandler(ImageHandler* _imageHandler, UdpSocketHandler* _socketHandler, int buffer_size, Settings* settings, TcpSocketHandler* tcpSocketHandler, QObject *parent = nullptr);
VideoHandler* mVideoHandler = nullptr;
AudioHandler* mAudioHandler = nullptr;
Q_INVOKABLE void disableAudio();
Expand Down
47 changes: 29 additions & 18 deletions handlers/sessionhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ UserHandler* SessionHandler::getUser()

bool SessionHandler::enableVideo()
{
return mStreamHandler->enableVideo() >= 0;
return mOutputStreamHandler->enableVideo() >= 0;

}

void SessionHandler::disableVideo()
{
mStreamHandler->disableVideo();
mOutputStreamHandler->disableVideo();
}

bool SessionHandler::enableAudio()
{
return mStreamHandler->enableAudio() >= 0;
return mOutputStreamHandler->enableAudio() >= 0;
}

void SessionHandler::disableAudio()
{
mStreamHandler->disableAudio();
mOutputStreamHandler->disableAudio();
}

void SessionHandler::initOtherStuff()
Expand All @@ -53,37 +53,43 @@ void SessionHandler::initOtherStuff()
QString displayName = mSettings->getDisplayName();
mSessionIsActive = true;
mInputStreamHandler = new InputStreamHandler(mImageHandler, mBufferSize, mAddress);
mSocketHandler = new UdpSocketHandler(mBufferSize, mPortNumberUDP, mInputStreamHandler, streamId, roomId, mAddress);
mUdpSocketHandler = new UdpSocketHandler(mBufferSize, mPortNumberUDP, mInputStreamHandler, streamId, roomId, mAddress);
//mTcpServerHandler = new TcpServerHandler(mInputStreamHandler, mPort);
mTcpSocketHandler = new TcpSocketHandler(mInputStreamHandler, streamId, roomId, displayName, mAddress, mPortNumberTCP);
mStreamHandler = new StreamHandler(mImageHandler, mSocketHandler, mBufferSize, mSettings, mTcpSocketHandler);
mOutputStreamHandler = new OutputStreamHandler(mImageHandler, mUdpSocketHandler, mBufferSize, mSettings, mTcpSocketHandler);
//Init tcpServerHandler
//mTcpServerHandler->init();
//Init sending of our header, empty or not
mTcpSocketHandler->init();
mStreamHandler->init();
mOutputStreamHandler->init();
}

void SessionHandler::closeOtherStuff()
{
mSessionIsActive = false;
qDebug() << "Before close";
mInputStreamHandler->close();
mSocketHandler->closeSocket();
//Sockets should close first, they use buffers and locks inside inputStreamHandler
mUdpSocketHandler->closeSocket();
mTcpSocketHandler->close();
mStreamHandler->close();

//This will clear all the vectors containing objects connected to each person in the room
mInputStreamHandler->close();

//This will close the output streams
mOutputStreamHandler->close();

qDebug() << "After close, about to delete";
delete mInputStreamHandler;
delete mSocketHandler;
delete mUdpSocketHandler;
delete mTcpSocketHandler;
delete mStreamHandler;
delete mOutputStreamHandler;
qDebug() << "Deleted everything";
mImageHandler->removeAllPeers();
}

QVariantList SessionHandler::getAudioInputDevices()
{
return mStreamHandler->getAudioInputDevices();
return mOutputStreamHandler->getAudioInputDevices();
}

bool SessionHandler::joinSession(QString _roomId, QString _roomPassword)
Expand All @@ -110,7 +116,11 @@ bool SessionHandler::joinSession(QString _roomId, QString _roomPassword)
mSettings->setLastRoomPassword(mRoomPassword);
mSettings->saveSettings();
qDebug() << "Adding peer with display name" << mSettings->getDisplayName();
mImageHandler->addPeer(0, mSettings->getDisplayName());

//TODO maybe more intensive to find numeric_limit in map compared to 0?
uint_8 userIndex = std::numeric_limits<uint_8>::max();

mImageHandler->addPeer(userIndex, mSettings->getDisplayName());


//Init everything that needs init
Expand Down Expand Up @@ -187,8 +197,9 @@ bool SessionHandler::leaveSession()
//CLose all that is opened;
closeOtherStuff();

//Serveren gjør jo dette når TCP blir disconnected? Er dette bare gammel kode?

if (mUser->isGuest())
/*if (mUser->isGuest())
{
QSqlQuery q(mDb->mDb);
q.prepare("DELETE FROM roomSession WHERE roomId = :roomId AND userId = :userId");
Expand Down Expand Up @@ -222,7 +233,7 @@ bool SessionHandler::leaveSession()
qDebug() << "Failed Query" << Q_FUNC_INFO;
}
}
return false;
return false;*/
}

bool SessionHandler::createSession(QString roomId, QString roomPassword)
Expand Down Expand Up @@ -301,10 +312,10 @@ void SessionHandler::updateDisplayName()

bool SessionHandler::checkVideoEnabled()
{
return mStreamHandler->checkVideoEnabled();
return mOutputStreamHandler->checkVideoEnabled();
}

bool SessionHandler::checkAudioEnabled()
{
return mStreamHandler->checkAudioEnabled();
return mOutputStreamHandler->checkAudioEnabled();
}
6 changes: 3 additions & 3 deletions handlers/sessionhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "handlers/udpsockethandler.h"
#include "handlers/tcpserverhandler.h"
#include "handlers/tcpsockethandler.h"
#include "handlers/streamhandler.h"
#include "handlers/outputstreamhandler.h"

class SessionHandler : public QObject
{
Expand Down Expand Up @@ -61,10 +61,10 @@ class SessionHandler : public QObject
Database* mDb;
UserHandler* mUser;
Settings* mSettings;
StreamHandler* mStreamHandler;
OutputStreamHandler* mOutputStreamHandler;
ImageHandler* mImageHandler;
InputStreamHandler* mInputStreamHandler;
UdpSocketHandler* mSocketHandler;
UdpSocketHandler* mUdpSocketHandler;
TcpServerHandler* mTcpServerHandler;
TcpSocketHandler* mTcpSocketHandler;

Expand Down
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <libavformat/avformat.h>
#include <QAudioInput>
#include <QTimer>
#include "handlers/streamhandler.h"
#include "handlers/outputstreamhandler.h"
#include "handlers/videoplaybackhandler.h"
#include "settings.h"
#include "handlers/imagehandler.h"
Expand Down
4 changes: 2 additions & 2 deletions qZoom-Client.pro
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ SOURCES += \
config.cpp \
core/database.cpp \
handlers/errorhandler.cpp \
handlers/outputstreamhandler.cpp \
handlers/sessionhandler.cpp \
handlers/userhandler.cpp \
handlers/imagehandler.cpp \
handlers/inputstreamhandler.cpp \
main.cpp \
settings.cpp \
handlers/udpsockethandler.cpp \
handlers/streamhandler.cpp \
handlers/tcpserverhandler.cpp \
handlers/tcpsockethandler.cpp \
handlers/videohandler.cpp \
Expand Down Expand Up @@ -58,13 +58,13 @@ HEADERS += \
handlers/audioplaybackhandler.h \
core/database.h \
handlers/errorhandler.h \
handlers/outputstreamhandler.h \
handlers/sessionhandler.h \
handlers/userhandler.h \
handlers/imagehandler.h \
handlers/inputstreamhandler.h \
settings.h \
handlers/udpsockethandler.h \
handlers/streamhandler.h \
handlers/tcpserverhandler.h \
handlers/tcpsockethandler.h \
handlers/videohandler.h \
Expand Down

0 comments on commit a5ffd65

Please sign in to comment.