コード例 #1
0
bool PulseHandler::Suspend(enum PulseAction action)
{
    // global lock around all access to our global singleton
    static QMutex global_lock;
    QMutexLocker locker(&global_lock);

    // cleanup the PulseAudio server connection if requested
    if (kPulseCleanup == action)
    {
        if (g_pulseHandler)
        {
            LOG(VB_GENERAL, LOG_INFO, LOC + "Cleaning up PulseHandler");
            delete g_pulseHandler;
            g_pulseHandler = NULL;
        }
        return true;
    }

    // do nothing if PulseAudio is not currently running
    if (!IsPulseAudioRunning())
    {
        LOG(VB_AUDIO, LOG_INFO, LOC + "PulseAudio not running");
        return false;
    }

    // make sure any pre-existing handler is still valid
    if (g_pulseHandler && !g_pulseHandler->Valid())
    {
        LOG(VB_AUDIO, LOG_INFO, LOC + "PulseHandler invalidated. Deleting.");
        delete g_pulseHandler;
        g_pulseHandler = NULL;
    }

    // create our handler
    if (!g_pulseHandler)
    {
        PulseHandler* handler = new PulseHandler();
        if (handler)
        {
            LOG(VB_AUDIO, LOG_INFO, LOC + "Created PulseHandler object");
            g_pulseHandler = handler;
        }
        else
        {
            LOG(VB_GENERAL, LOG_ERR, LOC + 
                "Failed to create PulseHandler object");
            return false;
        }
    }

    bool result;
    // enable processing of incoming callbacks
    g_pulseHandlerActive = true;
    result = g_pulseHandler->SuspendInternal(kPulseSuspend == action);
    // disable processing of incoming callbacks in case we delete/recreate our
    // instance due to a termination or other failure
    g_pulseHandlerActive = false;
    return result;
}
コード例 #2
0
bool PulseHandler::Suspend(enum PulseAction action)
{
    // global lock around all access to our global singleton
    static QMutex global_lock;
    QMutexLocker locker(&global_lock);

    // cleanup the PulseAudio server connection if requested
    if (kPulseCleanup == action)
    {
        if (g_pulseHandler)
        {
            LOG(VB_GENERAL, LOG_INFO, LOC + "Cleaning up PulseHandler");
            delete g_pulseHandler;
            g_pulseHandler = NULL;
        }
        return true;
    }

    if (getenv("DEBUG_PULSE_AUDIO_ALSA_EMULATION"))
    {
        LOG(VB_AUDIO, LOG_WARNING, "WARNING: ");
        LOG(VB_AUDIO, LOG_WARNING, "WARNING: ***Pulse Audio is running!!!!***");
        LOG(VB_AUDIO, LOG_WARNING, "WARNING: ");
        LOG(VB_AUDIO, LOG_WARNING, "WARNING: You have told MythTV to ignore it.");
        LOG(VB_AUDIO, LOG_WARNING, "WARNING: ");
        return false;
    }

    static int s_iPulseRunning = -1;
    static QTime s_time;
    static enum PulseAction s_ePulseAction = PulseAction(-1);

    // Use the last result of IsPulseAudioRunning if within time
    if (!s_time.isNull() && s_time.elapsed() < 30000)
    {
        if (!s_iPulseRunning)
            return false;

        // If the last action is repeated then do nothing
        if (action == s_ePulseAction)
            return true;
    }
    // NB IsPulseAudioRunning calls myth_system and can take up to 100mS
    else if (IsPulseAudioRunning())
    {
        s_iPulseRunning = 1;
        s_time.start();
    }
    else
    {
        // do nothing if PulseAudio is not currently running
        LOG(VB_AUDIO, LOG_INFO, LOC + "PulseAudio not running");
        s_iPulseRunning = 0;
        s_time.start();
        return false;
    }

    // make sure any pre-existing handler is still valid
    if (g_pulseHandler && !g_pulseHandler->Valid())
    {
        LOG(VB_AUDIO, LOG_INFO, LOC + "PulseHandler invalidated. Deleting.");
        delete g_pulseHandler;
        g_pulseHandler = NULL;
    }

    // create our handler
    if (!g_pulseHandler)
    {
        PulseHandler* handler = new PulseHandler();
        if (handler)
        {
            LOG(VB_AUDIO, LOG_INFO, LOC + "Created PulseHandler object");
            g_pulseHandler = handler;
        }
        else
        {
            LOG(VB_GENERAL, LOG_ERR, LOC +
                "Failed to create PulseHandler object");
            return false;
        }
    }

    bool result;
    // enable processing of incoming callbacks
    g_pulseHandlerActive = true;
    result = g_pulseHandler->SuspendInternal(kPulseSuspend == action);
    // disable processing of incoming callbacks in case we delete/recreate our
    // instance due to a termination or other failure
    g_pulseHandlerActive = false;
    s_ePulseAction = action;
    return result;
}