Skip to content

Commit

Permalink
Switched audiooutput suspend resume to start and stop functions to ma…
Browse files Browse the repository at this point in the history
…ke it consistent with audiocapturefilter. Large cleanup commit.
  • Loading branch information
jrsnen committed Nov 14, 2016
1 parent 22ea36f commit f4b79f7
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/audiocapturedevice.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

// This class has been modified from QT audio input example

// This class has been modified from QT audio input example

#include <QAudioInput>

Expand Down
33 changes: 5 additions & 28 deletions src/audiocapturefilter.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "audiocapturefilter.h"

#include <QDebug>

#include <QTime>


Expand All @@ -12,9 +11,9 @@ const int AUDIO_BUFFER_SIZE = 65536;
AudioCaptureFilter::AudioCaptureFilter(StatisticsInterface *stats) :
Filter("Audio capture", stats, false, true),
deviceInfo_(QAudioDeviceInfo::defaultInputDevice()),
device_(0),
audioInput_(0),
input_(0),
device_(NULL),
audioInput_(NULL),
input_(NULL),
buffer_(AUDIO_BUFFER_SIZE, 0)
{}

Expand All @@ -39,7 +38,6 @@ void AudioCaptureFilter::initializeAudio(QAudioFormat format)
if (device_)
delete device_;
device_ = new AudioCaptureDevice(format_, this);
// connect(device_, SIGNAL(update()), SLOT(refreshDisplay()));

createAudioInput();
qDebug() << "Audio initializing completed";
Expand All @@ -49,7 +47,6 @@ void AudioCaptureFilter::createAudioInput()
{
qDebug() << "Creating audio input";
audioInput_ = new QAudioInput(deviceInfo_, format_, this);
//volumeSlider->setValue(audioInput->volume() * 100);

device_->start();

Expand Down Expand Up @@ -78,7 +75,7 @@ void AudioCaptureFilter::readMore()

Data* newSample = new Data;

// set time
// create audio data packet to be sent to filter graph
timeval present_time;
present_time.tv_sec = QDateTime::currentMSecsSinceEpoch()/1000;
present_time.tv_usec = (QDateTime::currentMSecsSinceEpoch()%1000) * 1000;
Expand Down Expand Up @@ -127,23 +124,6 @@ void AudioCaptureFilter::stop()
qDebug() << "Audio input suspended.";
}

void AudioCaptureFilter::toggleSuspend()
{
// toggle suspend/resume
if (audioInput_->state() == QAudio::SuspendedState) {
audioInput_->resume();
//suspendResumeButton_->setText(tr(SUSPEND_LABEL));
} else if (audioInput_->state() == QAudio::ActiveState) {
audioInput_->suspend();
//m_suspendResumeButton->setText(tr(RESUME_LABEL));
} else if (audioInput_->state() == QAudio::StoppedState) {
audioInput_->resume();
//m_suspendResumeButton->setText(tr(SUSPEND_LABEL));
} else if (audioInput_->state() == QAudio::IdleState) {
// no-op
}
}

// changing of audio device mid stream.
void AudioCaptureFilter::deviceChanged(int index)
{
Expand All @@ -152,7 +132,6 @@ void AudioCaptureFilter::deviceChanged(int index)
audioInput_->disconnect(this);
delete audioInput_;

//deviceInfo_ = m_deviceBox->itemData(index).value<QAudioDeviceInfo>();
initializeAudio(format_);
}

Expand All @@ -165,6 +144,4 @@ void AudioCaptureFilter::volumeChanged(int value)
}

void AudioCaptureFilter::process()
{

}
{}
4 changes: 1 addition & 3 deletions src/audiocapturefilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <QByteArray>

//TODO: this class would not have to be a filter, just needs to send data to one

class AudioCaptureFilter : public Filter
{
Expand All @@ -30,10 +31,7 @@ private slots:

private:

void toggleMode();
void toggleSuspend();
void deviceChanged(int index);

void createAudioInput();

QAudioDeviceInfo deviceInfo_;
Expand Down
31 changes: 11 additions & 20 deletions src/audiooutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ AudioOutput::~AudioOutput()

void AudioOutput::initializeAudio(QAudioFormat format)
{
// connect(m_pushTimer, SIGNAL(timeout()), SLOT(pushTimerExpired()));


QAudioDeviceInfo info(device_);
if (!info.isFormatSupported(format)) {
qWarning() << "Default format not supported - trying to use nearest";
Expand Down Expand Up @@ -57,13 +54,6 @@ void AudioOutput::createAudioOutput()
source_->start();
// pull mode
output_ = audioOutput_->start();


// push mode
// audioOutput_->start(source_);


// m_volumeSlider->setValue(int(m_audioOutput->volume()*100.0f));
}

void AudioOutput::deviceChanged(int index)
Expand Down Expand Up @@ -98,18 +88,19 @@ void AudioOutput::receiveInput()
}
}

void AudioOutput::toggleSuspendResume()
void AudioOutput::start()
{
if (audioOutput_->state() == QAudio::SuspendedState) {
if(audioOutput_->state() == QAudio::SuspendedState
|| audioOutput_->state() == QAudio::StoppedState)
{
audioOutput_->resume();
// m_suspendResumeButton->setText(tr(SUSPEND_LABEL));
} else if (audioOutput_->state() == QAudio::ActiveState) {
}
}

void AudioOutput::stop()
{
if(audioOutput_->state() == QAudio::ActiveState)
{
audioOutput_->suspend();
// m_suspendResumeButton->setText(tr(RESUME_LABEL));
} else if (audioOutput_->state() == QAudio::StoppedState) {
audioOutput_->resume();
// m_suspendResumeButton->setText(tr(SUSPEND_LABEL));
} else if (audioOutput_->state() == QAudio::IdleState) {
// no-op
}
}
4 changes: 3 additions & 1 deletion src/audiooutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class AudioOutput : public QObject
return source_;
}

void start();
void stop();

private:

void createAudioOutput();
Expand All @@ -38,7 +41,6 @@ class AudioOutput : public QObject

private slots:
void receiveInput();
void toggleSuspendResume();
void deviceChanged(int index);
void volumeChanged(int);
};
4 changes: 3 additions & 1 deletion src/audiooutputdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ class AudioOutputDevice : public QIODevice
void start();
void stop();

// read data from buffer
qint64 readData(char *data, qint64 maxlen);
qint64 writeData(const char *data, qint64 len);
qint64 writeData(const char *data, qint64 len); // unused
qint64 bytesAvailable() const;

// Receives input from filter graph and tells output that there is input available
void takeInput(std::unique_ptr<Data> input);

signals:
Expand Down
4 changes: 1 addition & 3 deletions src/cameraframegrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

CameraFrameGrabber::CameraFrameGrabber(QObject *parent) :
QAbstractVideoSurface(parent)
{

}
{}

bool CameraFrameGrabber::present(const QVideoFrame &frame)
{
Expand Down

0 comments on commit f4b79f7

Please sign in to comment.