Exemple #1
0
void SoundSourceProxy::initSoundSource() {
    DEBUG_ASSERT(!m_pSoundSource);
    DEBUG_ASSERT(!m_pAudioSource);
    while (!m_pSoundSource) {
        mixxx::SoundSourceProviderPointer pProvider(getSoundSourceProvider());
        if (!pProvider) {
            if (!getUrl().isEmpty()) {
                kLogger.warning() << "No SoundSourceProvider for file"
                           << getUrl().toString();
            }
            // Failure
            return;
        }
        m_pSoundSource = pProvider->newSoundSource(m_url);
        if (!m_pSoundSource) {
            kLogger.warning() << "SoundSourceProvider"
                       << pProvider->getName()
                       << "failed to create a SoundSource for file"
                       << getUrl().toString();
            // Switch to next provider...
            nextSoundSourceProvider();
            // ...and continue loop
            DEBUG_ASSERT(!m_pSoundSource);
        } else {
            if (kLogger.debugEnabled()) {
                kLogger.debug() << "SoundSourceProvider"
                         << pProvider->getName()
                         << "created a SoundSource for file"
                         << getUrl().toString()
                         << "of type"
                         << m_pSoundSource->getType();
            }
        }
    }
}
void SoundSourceProxy::initSoundSource() {
    DEBUG_ASSERT(m_pSoundSource.isNull());
    DEBUG_ASSERT(m_pAudioSource.isNull());
    while (m_pSoundSource.isNull()) {
        Mixxx::SoundSourceProviderPointer pProvider(getSoundSourceProvider());
        if (pProvider.isNull()) {
            qWarning() << "No SoundSourceProvider for file"
                    << getUrl();
            // Failure
            return;
        }
        m_pSoundSource = pProvider->newSoundSource(m_url);
        if (m_pSoundSource.isNull()) {
            qWarning() << "SoundSourceProvider"
                    << pProvider->getName()
                    << "failed to create a SoundSource for file"
                    << getUrl();
            // Switch to next provider...
            nextSoundSourceProvider();
            // ...and continue loop
            DEBUG_ASSERT(m_pSoundSource.isNull());
        } else {
            QString trackType(m_pSoundSource->getType());
            qDebug() << "SoundSourceProvider"
                    << pProvider->getName()
                    << "created a SoundSource for file"
                    << getUrl()
                    << "of type"
                    << trackType;
            if (!m_pTrack.isNull()) {
                m_pTrack->setType(trackType);
            }
        }
    }
}
mixxx::AudioSourcePointer SoundSourceProxy::openAudioSource(const mixxx::AudioSourceConfig& audioSrcCfg) {
    DEBUG_ASSERT(m_pTrack);
    while (!m_pAudioSource) {
        if (!m_pSoundSource) {
            qWarning() << "Failed to open AudioSource for file"
                       << getUrl().toString();
            return m_pAudioSource; // failure -> exit loop
        }
        const mixxx::SoundSource::OpenResult openResult = m_pSoundSource->open(audioSrcCfg);
        if (mixxx::SoundSource::OpenResult::UNSUPPORTED_FORMAT != openResult) {
            qDebug() << "Opened AudioSource for file"
                     << getUrl().toString()
                     << "with provider"
                     << getSoundSourceProvider()->getName();
            if ((mixxx::SoundSource::OpenResult::SUCCEEDED == openResult) && m_pSoundSource->verifyReadable()) {
                m_pAudioSource =
                        AudioSourceProxy::create(m_pTrack, m_pSoundSource);
                if (m_pAudioSource->isEmpty()) {
                    qWarning() << "Empty audio data in file"
                               << getUrl().toString();
                }
                // Overwrite metadata with actual audio properties
                if (m_pTrack) {
                    m_pTrack->setChannels(m_pAudioSource->getChannelCount());
                    m_pTrack->setSampleRate(m_pAudioSource->getSamplingRate());
                    if (m_pAudioSource->hasDuration()) {
                        m_pTrack->setDuration(m_pAudioSource->getDuration());
                    }
                    if (m_pAudioSource->hasBitrate()) {
                        m_pTrack->setBitrate(m_pAudioSource->getBitrate());
                    }
                }
                return m_pAudioSource; // success -> exit loop
            } else {
                qWarning() << "Invalid audio data in file"
                           << getUrl().toString();
                // Do NOT retry with the next SoundSource provider if
                // the file itself is malformed!
                m_pSoundSource->close();
                break; // exit loop
            }
        }
        qWarning() << "Failed to open AudioSource for file"
                   << getUrl().toString()
                   << "with provider"
                   << getSoundSourceProvider()->getName();
        // Continue with the next SoundSource provider
        nextSoundSourceProvider();
        initSoundSource();
    }
    // m_pSoundSource might be invalid when reaching this point
    qWarning() << "Failed to open AudioSource for file"
               << getUrl().toString();
    return m_pAudioSource;
}
Mixxx::AudioSourcePointer SoundSourceProxy::openAudioSource(const Mixxx::AudioSourceConfig& audioSrcCfg) {
    DEBUG_ASSERT(!m_pTrack.isNull());
    while (m_pAudioSource.isNull()) {
        if (m_pSoundSource.isNull()) {
            qWarning() << "Failed to open AudioSource for file"
                    << getUrl();
            return m_pAudioSource; // failure -> exit loop
        }
        if (OK == m_pSoundSource->open(audioSrcCfg)) {
            qDebug() << "Opened AudioSource for file"
                    << getUrl()
                    << "with provider"
                    << getSoundSourceProvider()->getName();
            if (m_pSoundSource->isValid()) {
                m_pAudioSource =
                        AudioSourceProxy::create(m_pTrack, m_pSoundSource);
                if (m_pAudioSource->isEmpty()) {
                    qWarning() << "Empty audio data in file"
                            << getUrl();
                }
                // Overwrite metadata with actual audio properties
                if (!m_pTrack.isNull()) {
                    m_pTrack->setChannels(m_pAudioSource->getChannelCount());
                    m_pTrack->setSampleRate(m_pAudioSource->getSamplingRate());
                    if (m_pAudioSource->hasDuration()) {
                        m_pTrack->setDuration(m_pAudioSource->getDuration());
                    }
                    if (m_pAudioSource->hasBitrate()) {
                        m_pTrack->setBitrate(m_pAudioSource->getBitrate());
                    }
                }
                return m_pAudioSource; // success -> exit loop
            } else {
                qWarning() << "Invalid audio data in file"
                        << getUrl();
                // Do NOT retry with the next SoundSource provider if
                // only the file itself is malformed!
                m_pSoundSource->close();
                break; // exit loop
            }
        }
        qWarning() << "Failed to open AudioSource for file"
                << getUrl()
                << "with provider"
                << getSoundSourceProvider()->getName();
        // Continue with the next SoundSource provider
        nextSoundSourceProvider();
        initSoundSource();
    }
    // m_pSoundSource might be invalid when reaching this point
    qWarning() << "Failed to open AudioSource for file"
            << getUrl();
    return m_pAudioSource;
}
Exemple #5
0
mixxx::AudioSourcePointer SoundSourceProxy::openAudioSource(const mixxx::AudioSource::OpenParams& params) {
    DEBUG_ASSERT(m_pTrack);
    auto openMode = mixxx::SoundSource::OpenMode::Strict;
    while (m_pSoundSource && !m_pAudioSource) {
        // NOTE(uklotzde): Log unconditionally (with debug level) to
        // identify files in the log file that might have caused a
        // crash while importing metadata or decoding audio subsequently.
        kLogger.debug() << "Opening file"
                << getUrl().toString()
                << "with provider"
                << getSoundSourceProvider()->getName()
                << "using mode"
                << openMode;
        const mixxx::SoundSource::OpenResult openResult =
                m_pSoundSource->open(openMode, params);
        if ((openResult == mixxx::SoundSource::OpenResult::Aborted) ||
                ((openMode == mixxx::SoundSource::OpenMode::Strict) && (openResult == mixxx::SoundSource::OpenResult::Failed))) {
            kLogger.warning() << "Unable to open file"
                    << getUrl().toString()
                    << "with provider"
                    << getSoundSourceProvider()->getName()
                    << "using mode"
                    << openMode;
            // Continue with the next SoundSource provider
            nextSoundSourceProvider();
            if (!getSoundSourceProvider() && (openMode == mixxx::SoundSource::OpenMode::Strict)) {
                // No provider was able to open the source in Strict mode.
                // Retry to open the file in Permissive mode starting with
                // the first provider...
                m_soundSourceProviderRegistrationIndex = 0;
                openMode = mixxx::SoundSource::OpenMode::Permissive;
            }
            initSoundSource();
            continue; // try again
        }
        if ((openResult == mixxx::SoundSource::OpenResult::Succeeded) && m_pSoundSource->verifyReadable()) {
            m_pAudioSource = mixxx::AudioSourceTrackProxy::create(m_pTrack, m_pSoundSource);
            DEBUG_ASSERT(m_pAudioSource);
            if (m_pAudioSource->frameIndexRange().empty()) {
                kLogger.warning() << "File is empty"
                           << getUrl().toString();
            }
            // Overwrite metadata with actual audio properties
            if (m_pTrack) {
                DEBUG_ASSERT(m_pAudioSource->channelCount().valid());
                m_pTrack->setChannels(m_pAudioSource->channelCount());
                DEBUG_ASSERT(m_pAudioSource->sampleRate().valid());
                m_pTrack->setSampleRate(m_pAudioSource->sampleRate());
                if (m_pAudioSource->hasDuration()) {
                    // optional property
                    m_pTrack->setDuration(m_pAudioSource->getDuration());
                }
                if (m_pAudioSource->bitrate() != mixxx::AudioSource::Bitrate()) {
                    // optional property
                    m_pTrack->setBitrate(m_pAudioSource->bitrate());
                }
            }
        } else {
            kLogger.warning() << "Failed to open file"
                       << getUrl().toString()
                       << "with provider"
                       << getSoundSourceProvider()->getName();
            if (openResult == mixxx::SoundSource::OpenResult::Succeeded) {
                m_pSoundSource->close(); // cleanup
            }
            // Do NOT retry with the next SoundSource provider if the file
            // itself is the cause!
            DEBUG_ASSERT(!m_pAudioSource);
        }
        return m_pAudioSource; // either success or failure
    }
    // All available providers have returned OpenResult::Aborted when
    // getting here. m_pSoundSource might already be invalid/null!
    kLogger.warning() << "Unable to decode file"
            << getUrl().toString();
    DEBUG_ASSERT(!m_pAudioSource);
    return m_pAudioSource;
}