Skip to content

Commit

Permalink
Provide hints for opening audio sources via AudioSourceConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
uklotzde committed Apr 22, 2015
1 parent def4a50 commit df73263
Show file tree
Hide file tree
Showing 30 changed files with 64 additions and 46 deletions.
9 changes: 5 additions & 4 deletions plugins/soundsourcem4a/soundsourcem4a.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ SoundSourceM4A::~SoundSourceM4A() {
close();
}

Result SoundSourceM4A::tryOpen(SINT channelCountHint) {
Result SoundSourceM4A::tryOpen(const AudioSourceConfig& audioSrcCfg) {
DEBUG_ASSERT(MP4_INVALID_FILE_HANDLE == m_hFile);
/* open MP4 file, check for >= ver 1.9.1 */
#if MP4V2_PROJECT_version_hex <= 0x00010901
Expand Down Expand Up @@ -155,9 +155,10 @@ Result SoundSourceM4A::tryOpen(SINT channelCountHint) {
}
NeAACDecConfigurationPtr pDecoderConfig = NeAACDecGetCurrentConfiguration(
m_hDecoder);
pDecoderConfig->outputFormat = FAAD_FMT_FLOAT; /* 32-bit float */
if ((kChannelCountZero < channelCountHint) && (2 >= channelCountHint)) {
pDecoderConfig->downMatrix = 1; /* multi -> stereo */
pDecoderConfig->outputFormat = FAAD_FMT_FLOAT;
if ((1 == audioSrcCfg.channelCountHint) || (2 == audioSrcCfg.channelCountHint)) {
// mono or stereo requested
pDecoderConfig->downMatrix = 1;
} else {
pDecoderConfig->downMatrix = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/soundsourcem4a/soundsourcem4a.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SoundSourceM4A: public SoundSourcePlugin {
CSAMPLE* sampleBuffer) /*override*/;

private:
Result tryOpen(SINT channelCountHint) /*override*/;
Result tryOpen(const AudioSourceConfig& audioSrcCfg) /*override*/;

bool isValidSampleBlockId(MP4SampleId sampleBlockId) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ SoundSourceMediaFoundation::~SoundSourceMediaFoundation() {
close();
}

Result SoundSourceMediaFoundation::tryOpen(SINT channelCountHint) {
Result SoundSourceMediaFoundation::tryOpen(const Mixxx::AudioSourceConfig& audioSrcCfg) {
if (SUCCEEDED(m_hrCoInitialize)) {
qWarning() << "Cannot reopen MediaFoundation file" << getUrlString();
return ERR;
Expand Down Expand Up @@ -156,7 +156,7 @@ Result SoundSourceMediaFoundation::tryOpen(SINT channelCountHint) {
return ERR;
}

if (!configureAudioStream(channelCountHint)) {
if (!configureAudioStream(audioSrcCfg)) {
qWarning() << "SSMF: Error configuring audio stream.";
return ERR;
}
Expand Down Expand Up @@ -434,7 +434,7 @@ SINT SoundSourceMediaFoundation::readSampleFrames(
If anything in here fails, just bail. I'm not going to decode HRESULTS.
-- Bill
*/
bool SoundSourceMediaFoundation::configureAudioStream(SINT channelCountHint) {
bool SoundSourceMediaFoundation::configureAudioStream(const Mixxx::AudioSourceConfig& audioSrcCfg) {
HRESULT hr(S_OK);

// deselect all streams, we only want the first
Expand Down Expand Up @@ -500,8 +500,8 @@ bool SoundSourceMediaFoundation::configureAudioStream(SINT channelCountHint) {
return false;
}

if (kChannelCountZero < channelCountHint) {
hr = m_pAudioType->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, channelCountHint);
if (kChannelCountZero < audioSrcCfg.channelCountHint) {
hr = m_pAudioType->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, audioSrcCfg.channelCountHint);
if (FAILED(hr)) {
qWarning() << "SSMF: failed to set number of channels";
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class SoundSourceMediaFoundation : public Mixxx::SoundSourcePlugin {
SINT readSampleFrames(SINT numberOfFrames, CSAMPLE* sampleBuffer) /*override*/;

private:
Result tryOpen(SINT channelCountHint) /*override*/;
Result tryOpen(const Mixxx::AudioSourceConfig& audioSrcCfg) /*override*/;

bool configureAudioStream(SINT channelCountHint);
bool configureAudioStream(const Mixxx::AudioSourceConfig& audioSrcCfg);

void copyFrames(CSAMPLE *dest, SINT *destFrames, const CSAMPLE *src,
SINT srcFrames);
Expand Down
6 changes: 3 additions & 3 deletions plugins/soundsourcewv/soundsourcewv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ SoundSourceWV::~SoundSourceWV() {
close();
}

Result SoundSourceWV::tryOpen(SINT channelCountHint) {
Result SoundSourceWV::tryOpen(const AudioSourceConfig& audioSrcCfg) {
DEBUG_ASSERT(!m_wpc);
char msg[80]; // hold possible error message
int openFlags = OPEN_WVC | OPEN_NORMALIZE;
if ((kChannelCountZero < channelCountHint) && (2 >= channelCountHint)) {
// mono or stereo
if ((1 == audioSrcCfg.channelCountHint) || (2 == audioSrcCfg.channelCountHint)) {
// mono or stereo requested
openFlags |= OPEN_2CH_MAX;
}
m_wpc = WavpackOpenFileInput(
Expand Down
2 changes: 1 addition & 1 deletion plugins/soundsourcewv/soundsourcewv.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SoundSourceWV: public SoundSourcePlugin {
CSAMPLE* sampleBuffer) /*override*/;

private:
Result tryOpen(SINT channelCountHint) /*override*/;
Result tryOpen(const AudioSourceConfig& audioSrcCfg) /*override*/;

WavpackContext* m_wpc;

Expand Down
4 changes: 3 additions & 1 deletion src/analyserqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ void AnalyserQueue::run() {

// Get the audio
SoundSourceProxy soundSourceProxy(nextTrack);
Mixxx::AudioSourcePointer pAudioSource(soundSourceProxy.openAudioSource(kAnalysisChannels));
Mixxx::AudioSourceConfig audioSrcCfg;
audioSrcCfg.channelCountHint = kAnalysisChannels;
Mixxx::AudioSourcePointer pAudioSource(soundSourceProxy.openAudioSource(audioSrcCfg));
if (!pAudioSource) {
qWarning() << "Failed to open file for analyzing:" << nextTrack->getLocation();
continue;
Expand Down
8 changes: 5 additions & 3 deletions src/cachingreaderworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ void CachingReaderWorker::run() {

namespace
{
Mixxx::AudioSourcePointer openAudioSourceForReading(const TrackPointer& pTrack, SINT channelCountHint) {
Mixxx::AudioSourcePointer openAudioSourceForReading(const TrackPointer& pTrack, const Mixxx::AudioSourceConfig& audioSrcCfg) {
SoundSourceProxy soundSourceProxy(pTrack);
Mixxx::AudioSourcePointer pAudioSource(soundSourceProxy.openAudioSource(channelCountHint));
Mixxx::AudioSourcePointer pAudioSource(soundSourceProxy.openAudioSource(audioSrcCfg));
if (pAudioSource.isNull()) {
qWarning() << "Failed to open file:" << pTrack->getLocation();
return Mixxx::AudioSourcePointer();
Expand Down Expand Up @@ -169,7 +169,9 @@ void CachingReaderWorker::loadTrack(const TrackPointer& pTrack) {
return;
}

m_pAudioSource = openAudioSourceForReading(pTrack, kChunkChannels);
Mixxx::AudioSourceConfig audioSrcCfg;
audioSrcCfg.channelCountHint = kChunkChannels;
m_pAudioSource = openAudioSourceForReading(pTrack, audioSrcCfg);
if (m_pAudioSource.isNull()) {
// Must unlock before emitting to avoid deadlock
qDebug() << m_group << "CachingReaderWorker::loadTrack() load failed for\""
Expand Down
4 changes: 3 additions & 1 deletion src/musicbrainz/chromaprinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ ChromaPrinter::ChromaPrinter(QObject* parent)

QString ChromaPrinter::getFingerprint(TrackPointer pTrack) {
SoundSourceProxy soundSourceProxy(pTrack);
Mixxx::AudioSourcePointer pAudioSource(soundSourceProxy.openAudioSource(kFingerprintChannels));
Mixxx::AudioSourceConfig audioSrcCfg;
audioSrcCfg.channelCountHint = kFingerprintChannels;
Mixxx::AudioSourcePointer pAudioSource(soundSourceProxy.openAudioSource(audioSrcCfg));
if (pAudioSource.isNull()) {
qDebug() << "Skipping invalid file:" << pTrack->getLocation();
return QString();
Expand Down
4 changes: 2 additions & 2 deletions src/soundsourceproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ QLibrary* SoundSourceProxy::getPlugin(QString lib_filename)
return pPlugin;
}

Mixxx::AudioSourcePointer SoundSourceProxy::openAudioSource(SINT channelCountHint) {
Mixxx::AudioSourcePointer SoundSourceProxy::openAudioSource(const Mixxx::AudioSourceConfig& audioSrcCfg) {
if (m_pAudioSource) {
qDebug() << "AudioSource is already open";
return m_pAudioSource;
Expand All @@ -323,7 +323,7 @@ Mixxx::AudioSourcePointer SoundSourceProxy::openAudioSource(SINT channelCountHin
return m_pAudioSource;
}

if (OK != m_pSoundSource->open(channelCountHint)) {
if (OK != m_pSoundSource->open(audioSrcCfg)) {
qWarning() << "Failed to open SoundSource";
return m_pAudioSource;
}
Expand Down
2 changes: 1 addition & 1 deletion src/soundsourceproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class SoundSourceProxy: public Mixxx::MetadataSource {
// Opening the audio data through the proxy will
// update the some metadata of the track object.
// Returns a null pointer on failure.
Mixxx::AudioSourcePointer openAudioSource(SINT channelCountHint = Mixxx::AudioSource::kChannelCountDefault);
Mixxx::AudioSourcePointer openAudioSource(const Mixxx::AudioSourceConfig& audioSrcCfg = Mixxx::AudioSourceConfig());

void closeAudioSource();

Expand Down
11 changes: 11 additions & 0 deletions src/sources/audiosource.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,17 @@ class AudioSource: public UrlResource {
SINT m_bitrate;
};

// Parameters for configuring audio sources
struct AudioSourceConfig {
AudioSourceConfig()
: channelCountHint(AudioSource::kChannelCountDefault),
frameRateHint(AudioSource::kFrameRateDefault){
}

SINT channelCountHint;
SINT frameRateHint;
};

typedef QSharedPointer<AudioSource> AudioSourcePointer;

} // namespace Mixxx
Expand Down
4 changes: 2 additions & 2 deletions src/sources/soundsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ SoundSource::SoundSource(QUrl url, QString type)
DEBUG_ASSERT(getUrl().isValid());
}

Result SoundSource::open(SINT channelCountHint) {
Result SoundSource::open(const AudioSourceConfig& audioSrcCfg) {
close(); // reopening is not supported
Result result;
try {
result = tryOpen(channelCountHint);
result = tryOpen(audioSrcCfg);
} catch (...) {
close();
throw;
Expand Down
4 changes: 2 additions & 2 deletions src/sources/soundsource.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SoundSource: public MetadataSource, public AudioSource {
//
// Since reopening is not supported close() will be called
// implicitly before the AudioSource is actually opened.
Result open(SINT channelCountHint = kChannelCountDefault);
Result open(const AudioSourceConfig& audioSrcCfg = AudioSourceConfig());

// Closes the AudioSource and frees all resources.
//
Expand All @@ -54,7 +54,7 @@ class SoundSource: public MetadataSource, public AudioSource {
// need to free resources in tryOpen() themselves, but
// should instead be prepared for the following invocation
// of close().
virtual Result tryOpen(SINT channelCountHint) = 0;
virtual Result tryOpen(const AudioSourceConfig& audioSrcCfg) = 0;

const QString m_type;
};
Expand Down
4 changes: 2 additions & 2 deletions src/sources/soundsourcecoreaudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ SoundSourceCoreAudio::~SoundSourceCoreAudio() {
}

// soundsource overrides
Result AudioSourceCoreAudio::tryOpen(SINT channelCountHint) {
Result AudioSourceCoreAudio::tryOpen(const AudioSourceConfig& audioSrcCfg) {
const QString fileName(getLocalFileName());

//Open the audio file.
Expand Down Expand Up @@ -66,7 +66,7 @@ Result AudioSourceCoreAudio::tryOpen(SINT channelCountHint) {

// create the output format
const UInt32 numChannels =
(channelCountZero < channelCountHint) ? channelCountHint : 2;
(channelCountZero < audioSrcCfg.channelCountHint) ? audioSrcCfg.channelCountHint : 2;
m_outputFormat = CAStreamBasicDescription(m_inputFormat.mSampleRate,
numChannels, CAStreamBasicDescription::kPCMFormatFloat32, true);

Expand Down
2 changes: 1 addition & 1 deletion src/sources/soundsourcecoreaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SoundSourceCoreAudio : public Mixxx::SoundSource {
CSAMPLE* sampleBuffer) /*override*/;

private:
Result tryOpen(SINT channelCountHint) /*override*/;
Result tryOpen(const AudioSourceConfig& audioSrcCfg) /*override*/;

ExtAudioFileRef m_audioFile;
CAStreamBasicDescription m_inputFormat;
Expand Down
4 changes: 2 additions & 2 deletions src/sources/soundsourceffmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ SoundSourceFFmpeg::~SoundSourceFFmpeg() {
close();
}

Result SoundSourceFFmpeg::tryOpen(SINT channelCountHint) {
Result SoundSourceFFmpeg::tryOpen(const AudioSourceConfig& /*audioSrcCfg*/) {
unsigned int i;
AVDictionary *l_iFormatOpts = NULL;

const QByteArray qBAFilename(getLocalFileNameBytes());
qDebug() << "New SoundSourceFFmpeg :" << qBAFilename << "(channelCountHint:" << channelCountHint << ")";
qDebug() << "New SoundSourceFFmpeg :" << qBAFilename;

DEBUG_ASSERT(!m_pFormatCtx);
m_pFormatCtx = avformat_alloc_context();
Expand Down
2 changes: 1 addition & 1 deletion src/sources/soundsourceffmpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SoundSourceFFmpeg : public SoundSource {
SINT readSampleFrames(SINT numberOfFrames, CSAMPLE* sampleBuffer) /*override*/;

private:
Result tryOpen(SINT channelCountHint) /*override*/;
Result tryOpen(const AudioSourceConfig& audioSrcCfg) /*override*/;

bool readFramesToCache(unsigned int count, SINT offset);
bool getBytesFromCache(char *buffer, SINT offset, SINT size);
Expand Down
2 changes: 1 addition & 1 deletion src/sources/soundsourceflac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ SoundSourceFLAC::~SoundSourceFLAC() {
close();
}

Result SoundSourceFLAC::tryOpen(SINT /*channelCountHint*/) {
Result SoundSourceFLAC::tryOpen(const AudioSourceConfig& /*audioSrcCfg*/) {
DEBUG_ASSERT(!m_file.isOpen());
if (!m_file.open(QIODevice::ReadOnly)) {
qWarning() << "Failed to open FLAC file:" << m_file.fileName();
Expand Down
2 changes: 1 addition & 1 deletion src/sources/soundsourceflac.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SoundSourceFLAC: public SoundSource {
void flacError(FLAC__StreamDecoderErrorStatus status);

private:
Result tryOpen(SINT channelCountHint) /*override*/;
Result tryOpen(const AudioSourceConfig& audioSrcCfg) /*override*/;

SINT readSampleFrames(SINT numberOfFrames,
CSAMPLE* sampleBuffer, SINT sampleBufferSize,
Expand Down
2 changes: 1 addition & 1 deletion src/sources/soundsourcemodplug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ QImage SoundSourceModPlug::parseCoverArt() const {
return QImage();
}

Result SoundSourceModPlug::tryOpen(SINT /*channelCountHint*/) {
Result SoundSourceModPlug::tryOpen(const AudioSourceConfig& /*audioSrcCfg*/) {
ScopedTimer t("SoundSourceModPlug::open()");

// read module file to byte array
Expand Down
2 changes: 1 addition & 1 deletion src/sources/soundsourcemodplug.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SoundSourceModPlug: public Mixxx::SoundSource {
CSAMPLE* sampleBuffer) /*override*/;

private:
Result tryOpen(SINT channelCountHint) /*override*/;
Result tryOpen(const AudioSourceConfig& audioSrcCfg) /*override*/;

static unsigned int s_bufferSizeLimit; // max track buffer length (bytes)

Expand Down
2 changes: 1 addition & 1 deletion src/sources/soundsourcemp3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ SoundSourceMp3::~SoundSourceMp3() {
close();
}

Result SoundSourceMp3::tryOpen(SINT /*channelCountHint*/) {
Result SoundSourceMp3::tryOpen(const AudioSourceConfig& /*audioSrcCfg*/) {
DEBUG_ASSERT(!isChannelCountValid());
DEBUG_ASSERT(!isFrameRateValid());

Expand Down
2 changes: 1 addition & 1 deletion src/sources/soundsourcemp3.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SoundSourceMp3: public SoundSource {
bool readStereoSamples);

private:
Result tryOpen(SINT channelCountHint) /*override*/;
Result tryOpen(const AudioSourceConfig& audioSrcCfg) /*override*/;

QFile m_file;
quint64 m_fileSize;
Expand Down
2 changes: 1 addition & 1 deletion src/sources/soundsourceoggvorbis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ SoundSourceOggVorbis::~SoundSourceOggVorbis() {
close();
}

Result SoundSourceOggVorbis::tryOpen(SINT /*channelCountHint*/) {
Result SoundSourceOggVorbis::tryOpen(const AudioSourceConfig& /*audioSrcCfg*/) {
const QByteArray qbaFilename(getLocalFileNameBytes());
if (0 != ov_fopen(qbaFilename.constData(), &m_vf)) {
qWarning() << "Failed to open OggVorbis file:" << getUrlString();
Expand Down
2 changes: 1 addition & 1 deletion src/sources/soundsourceoggvorbis.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SoundSourceOggVorbis: public SoundSource {
CSAMPLE* sampleBuffer, SINT sampleBufferSize) /*override*/;

private:
Result tryOpen(SINT channelCountHint) /*override*/;
Result tryOpen(const AudioSourceConfig& audioSrcCfg) /*override*/;

SINT readSampleFrames(SINT numberOfFrames,
CSAMPLE* sampleBuffer, SINT sampleBufferSize,
Expand Down
2 changes: 1 addition & 1 deletion src/sources/soundsourceopus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Result SoundSourceOpus::parseTrackMetadata(Mixxx::TrackMetadata* pMetadata) cons
return OK;
}

Result SoundSourceOpus::tryOpen(SINT /*channelCountHint*/) {
Result SoundSourceOpus::tryOpen(const AudioSourceConfig& /*audioSrcCfg*/) {
const QByteArray qbaFilename(getLocalFileNameBytes());
int errorCode = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/sources/soundsourceopus.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SoundSourceOpus: public Mixxx::SoundSource {
CSAMPLE* sampleBuffer, SINT sampleBufferSize) /*override*/;

private:
Result tryOpen(SINT channelCountHint) /*override*/;
Result tryOpen(const AudioSourceConfig& audioSrcCfg) /*override*/;

OggOpusFile *m_pOggOpusFile;

Expand Down
2 changes: 1 addition & 1 deletion src/sources/soundsourcesndfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ SoundSourceSndFile::~SoundSourceSndFile() {
close();
}

Result SoundSourceSndFile::tryOpen(SINT /*channelCountHint*/) {
Result SoundSourceSndFile::tryOpen(const AudioSourceConfig& /*audioSrcCfg*/) {
DEBUG_ASSERT(!m_pSndFile);
memset(&m_sfInfo, 0, sizeof(m_sfInfo));
#ifdef __WINDOWS__
Expand Down
2 changes: 1 addition & 1 deletion src/sources/soundsourcesndfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SoundSourceSndFile: public Mixxx::SoundSource {
CSAMPLE* sampleBuffer) /*override*/;

private:
Result tryOpen(SINT channelCountHint) /*override*/;
Result tryOpen(const AudioSourceConfig& audioSrcCfg) /*override*/;

SNDFILE* m_pSndFile;
SF_INFO m_sfInfo;
Expand Down

0 comments on commit df73263

Please sign in to comment.