Skip to content

Commit

Permalink
Merge branch 'Bug_fixes'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/sip/siptransactions.cpp
  • Loading branch information
jrsnen committed May 13, 2019
2 parents 2f0041a + 5376181 commit 74ce69c
Show file tree
Hide file tree
Showing 48 changed files with 892 additions and 612 deletions.
21 changes: 9 additions & 12 deletions src/audio/audiocapturefilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "audiocapturedevice.h"
#include "statisticsinterface.h"

#include "common.h"

#include <QAudioInput>
#include <QDebug>
#include <QTime>
Expand All @@ -23,21 +25,17 @@ AudioCaptureFilter::~AudioCaptureFilter(){}

bool AudioCaptureFilter::init()
{
qDebug() << "Initiating," << metaObject()->className() << ": Initializing audio capture filter";

printDebug(DEBUG_NORMAL, this, "Iniating", "Initializing audio capture filter.");
QAudioDeviceInfo info(deviceInfo_);

for(auto device : QAudioDeviceInfo::availableDevices(QAudio::AudioInput))
{
qDebug() << "Iniating," << metaObject()->className()
<< ": Audio Recording device:" << device.deviceName();
printDebug(DEBUG_NORMAL, this, "Iniating", "", {"Available audio recording devices"}, {device.deviceName()});
}

qDebug() << "Iniating," << metaObject()->className()
<< ": Device:" << info.deviceName();
printDebug(DEBUG_NORMAL, this, "Iniating", "", {"Chosen Device"}, {info.deviceName()});

if (!info.isFormatSupported(format_)) {
qWarning() << "WARNING: Default audio format not supported - trying to use nearest";
printDebug(DEBUG_WARNING, this, "Iniating", "Default audio format not supported - trying to use nearest");
format_ = info.nearestFormat(format_);
}

Expand All @@ -51,8 +49,7 @@ bool AudioCaptureFilter::init()
device_ = new AudioCaptureDevice(format_, this);

createAudioInput();
qDebug() << "Iniating," << metaObject()->className() << ": Audio initializing completed";

printDebug(DEBUG_NORMAL, this, "Iniating", "Audio initializing completed.");
return true;
}

Expand All @@ -71,7 +68,7 @@ void AudioCaptureFilter::readMore()
{
if (!audioInput_)
{
qWarning() << "WARNING," << metaObject()->className() << ": No audio input in readMore";
printDebug(DEBUG_WARNING, this, "Audio input", "No audio input in readMore");
return;
}
qint64 len = audioInput_->bytesReady();
Expand Down Expand Up @@ -139,7 +136,7 @@ void AudioCaptureFilter::stop()
// changing of audio device mid stream.
void AudioCaptureFilter::deviceChanged(int index)
{
qWarning() << "WARNING: audiocapturefilter device change not implemented fully:" << index;
printDebug(DEBUG_WARNING, this, "Settings", "audiocapturefilter device change not implemented fully.");

device_->stop();
audioInput_->stop();
Expand Down
7 changes: 4 additions & 3 deletions src/audio/audiooutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "audiooutputdevice.h"

#include <QDebug>
#include "common.h"

const int BufferSize = 32768;

Expand All @@ -25,7 +25,7 @@ void AudioOutput::initializeAudio(QAudioFormat format)
{
QAudioDeviceInfo info(device_);
if (!info.isFormatSupported(format)) {
qWarning() << "Default format not supported - trying to use nearest";
printDebug(DEBUG_WARNING, this, "Iniating", "Default format not supported - trying to use nearest.");
format_ = info.nearestFormat(format);
}
else
Expand Down Expand Up @@ -57,7 +57,8 @@ void AudioOutput::createAudioOutput()

void AudioOutput::deviceChanged(int index)
{
qWarning() << "WARNING: audio output device change not implemented fully:" << index;
printDebug(DEBUG_WARNING, this, "Audio", "Audio output device change not implemented fully.",
{"Index"}, {QString::number(index)});

//m_pushTimer->stop();
source_->stop();
Expand Down
7 changes: 4 additions & 3 deletions src/audio/opusdecoderfilter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "opusdecoderfilter.h"

#include <QDebug>
#include "common.h"

OpusDecoderFilter::OpusDecoderFilter(QString id, QAudioFormat format, StatisticsInterface *stats):
Filter(id, "Opus_Decoder", stats, OPUSAUDIO, RAWAUDIO),
Expand Down Expand Up @@ -28,7 +28,8 @@ bool OpusDecoderFilter::init()

if(error)
{
qWarning() << "WARNING:" << metaObject()->className() << ": Failed to initialize opus decoder with errorcode:" << error;
printDebug(DEBUG_WARNING, this, "Iniating", "Failed to initialize opus decoder.",
{"Errorcode"}, {QString::number(error)});
return false;
}
return true;
Expand Down Expand Up @@ -61,7 +62,7 @@ void OpusDecoderFilter::process()
}
else
{
qWarning() << "WARNING," << metaObject()->className() << ":Failed to encode audio frame. Error:" << len;
printDebug(DEBUG_WARNING, this, "Process", "Failed to encode audio frame.", {"Error"}, {QString::number(len)});
}
input = getInput();
}
Expand Down
12 changes: 8 additions & 4 deletions src/audio/opusencoderfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

#include "statisticsinterface.h"

#include <QDebug>
#include "common.h"

#include <QDateTime>

// this is how many frames the audio capture seems to send
Expand Down Expand Up @@ -34,7 +35,8 @@ bool OpusEncoderFilter::init()

if(error)
{
qWarning() << "Failed to initialize opus encoder with errorcode:" << error;
printDebug(DEBUG_WARNING, this, "Iniating", "Failed to initialize opus encoder.",
{"Errorcode"}, {QString::number(error)});
return false;
}

Expand All @@ -58,7 +60,8 @@ void OpusEncoderFilter::process()
len = opus_encode(enc_, (opus_int16*)input->data.get()+i/2, numberOfSamples_, opusOutput_ + pos, max_data_bytes_ - pos);
if(len <= 0)
{
qWarning() << "Warning: Failed to encode audio. Error:" << len;
printDebug(DEBUG_WARNING, this, "Process", "Failed to encode audio",
{"Errorcode:"}, {QString::number(len)});
break;
}

Expand Down Expand Up @@ -86,7 +89,8 @@ void OpusEncoderFilter::process()
}
else
{
qWarning() << "Warning: Failed to encode audio frame. Length:" << input->data_size;
printDebug(DEBUG_WARNING, this, "Process", "Failed to encode audio frame.",
{"Frame length"}, {QString::number(input->data_size)});
}
input = getInput();
}
Expand Down
5 changes: 3 additions & 2 deletions src/audio/speexaecfilter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "speexaecfilter.h"

#include <QDebug>
#include "common.h"

// this is how many frames the audio capture seems to send
const uint16_t FRAMESPERSECOND = 25;
Expand Down Expand Up @@ -74,7 +74,8 @@ void SpeexAECFilter::process()
}
else
{
qWarning() << "Warning: AEC received too much output before input";
printDebug(DEBUG_WARNING, this, "Process", "AEC received too much output before input.",
{"input", "output"}, {QString::number(in_), QString::number(out_)});
break;
}
}
Expand Down
67 changes: 67 additions & 0 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <windows.h> // for Sleep
#endif

#include <QDebug>

// TODO move this to a different file from common.h
void qSleep(int ms)
{
Expand Down Expand Up @@ -36,3 +38,68 @@ QString generateRandomString(uint32_t length)
}
return string;
}


void printDebug(DebugType type, QObject* object,
QString context, QString description,
QStringList valueNames, QStringList values)
{
printDebug(type, object->metaObject()->className(), context, description, valueNames, values);
}

void printDebug(DebugType type, QString className, QString context, QString description, QStringList valueNames, QStringList values)
{
QString valueString = "";
if (valueNames.size() == values.size())
{
for (int i = 0; i < valueNames.size(); ++i)
{
valueString.append(valueNames.at(i));
valueString.append(": ");
valueString.append(values.at(i));
if (i != valueNames.size() - 1)
{
valueString.append("\r\n");
}
}
}
else {
qDebug() << "Value printing failed";
}

// This could be reduced, but it might change so not worth probably at the moment.
// Choose which text to print based on type.
switch (type) {
case DEBUG_NORMAL:
{
qDebug().nospace().noquote() << context << ", " << className << ": "
<< description << " " << valueString;
break;
}
case DEBUG_ERROR:
{
qCritical().nospace().noquote() << "ERROR: --------------------------------------------";
qCritical().nospace().noquote() << context << ", " << className << ": "
<< description << " " << valueString;
qCritical().nospace().noquote() << "-------------------------------------------- ERROR";
break;
}
case DEBUG_WARNING:
{
qWarning().nospace().noquote() << "WARNING: --------------------------------------------";
qWarning().nospace().noquote() << context << ", " << className << ": "
<< description << " " << valueString;
qWarning().nospace() << "\r\n" << "-------------------------------------------- WARNING";
break;
}
case DEBUG_PEER_ERROR:
{
qWarning().nospace().noquote() << "PEER ERROR: --------------------------------------------";
qWarning().nospace().noquote() << context << ", " << className << ": "
<< description << " " << valueString;
qWarning().nospace().noquote() << "-------------------------------------------- PEER ERROR";
break;
}

}
}
19 changes: 19 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <QList>
#include <QString>
#include <QObject>
#include <stdint.h>

// A module for functions used multiple times across the whole program
Expand All @@ -9,3 +10,21 @@
void qSleep(int ms);

QString generateRandomString(uint32_t length);

enum DebugType{DEBUG_NORMAL, DEBUG_ERROR, DEBUG_WARNING, DEBUG_PEER_ERROR};


// use this if printing happens inside class derived from QObject which is most Qt-classes
void printDebug(DebugType type, QObject* object,
QString context = "", QString description = "",
QStringList valueNames = {}, QStringList values = {});

// print debug information
// DEBUG_NORMAL is for one time informational debug printing.
// DEBUG_WARNING is for events that should not be able to happen in Kvazzup which do not cause problems.
// DEBUG_ERROR is for events that should not be able to happen in Kvazzup and results in problems.
// DEBUG_PEER_ERROR is for events that are errors in behavior of entities that are not us.
void printDebug(DebugType type, QString className,
QString context = "", QString description = "",
QStringList valueNames = {}, QStringList values = {});

17 changes: 9 additions & 8 deletions src/filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "statisticsinterface.h"

#include "common.h"

#include <QDebug>

Filter::Filter(QString id, QString name, StatisticsInterface *stats,
Expand Down Expand Up @@ -59,7 +61,7 @@ void Filter::removeOutConnection(std::shared_ptr<Filter> out)

if(!removed)
{
qWarning() << "WARNING: Did not succeed at removing outconnection.";
printDebug(DEBUG_WARNING, this, "Uninit", "Did not succeed at removing outconnection.");
}
}

Expand All @@ -80,7 +82,7 @@ void Filter::putInput(std::unique_ptr<Data> data)
|| data->type == NONE
|| data->data_size == 0)
{
qWarning() << "Warning: Discarding bad data";
printDebug(DEBUG_WARNING, this, "Processing", "Discarding bad data.");
return;
}

Expand Down Expand Up @@ -123,7 +125,7 @@ void Filter::putInput(std::unique_ptr<Data> data)
{
if(inBuffer_[0]->type == OPUSAUDIO)
{
qWarning() << "WARNING: Unimplented: Should input Null pointer to decoder";
printDebug(DEBUG_WARNING, this, "Processing", "Should input Null pointer to decoder.");
}
inBuffer_.pop_front(); // discard the oldest
}
Expand Down Expand Up @@ -160,7 +162,7 @@ void Filter::sendOutput(std::unique_ptr<Data> output)

if(outDataCallbacks_.size() == 0 && outConnections_.size() == 0)
{
qWarning() << name_ << "trying to send output data without outconnections";
printDebug(DEBUG_WARNING, this, "Processing", "Trying to send output data without outconnections.");
return;
}

Expand Down Expand Up @@ -217,10 +219,9 @@ void Filter::run()
stats_->addFilter(name_, (uint64_t)currentThreadId());
//qDebug() << "Iniating," << metaObject()->className()
//<< Running filter" << name_ << "with max buffer:" << maxBufferSize_;
running_ = true;
while(running_)
{
sleep();
waitForInput();
if(!running_) break;

process();
Expand All @@ -244,7 +245,7 @@ Data* Filter::shallowDataCopy(Data* original)

return copy;
}
qWarning() << "Warning: Trying to copy nullptr Data pointer";
printDebug(DEBUG_WARNING, this, "Processing", "Trying to copy nullptr Data pointer.");
return nullptr;
}

Expand All @@ -259,7 +260,7 @@ Data* Filter::deepDataCopy(Data* original)

return copy;
}
qWarning() << "Warning: Trying to copy nullptr Data pointer";
printDebug(DEBUG_WARNING, this, "Processing", "Trying to copy nullptr Data pointer.");
return nullptr;
}

Expand Down
5 changes: 3 additions & 2 deletions src/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// called filter graph. A class inherited from filter can do any sort of processing to the data it
// receives. The filter sleeps when it does not have any input to process.

enum DataType {NONE = 0, RGB32VIDEO, YUVVIDEO, RAWAUDIO, HEVCVIDEO, OPUSAUDIO};
enum DataType {NONE = 0, RGB32VIDEO, YUV420VIDEO, RAWAUDIO, HEVCVIDEO, OPUSAUDIO};
enum DataSource {UNKNOWN, LOCAL, REMOTE};

// NOTE: remember to make changes to deepcopy, camera, audiocapture and RTPSinkFilter
Expand Down Expand Up @@ -86,6 +86,7 @@ class Filter : public QThread

virtual void start()
{
running_ = true;
QThread::start();
}

Expand Down Expand Up @@ -122,7 +123,7 @@ class Filter : public QThread
waitMutex_->unlock();
}

void sleep()
void waitForInput()
{
waitMutex_->lock();
hasInput_.wait(waitMutex_);
Expand Down
Loading

0 comments on commit 74ce69c

Please sign in to comment.