void TorcPlayer::DestroyNextDecoder(void) { LOG(VB_GENERAL, LOG_ERR, "Failed to create new decoder"); if (m_switching) SendUserMessage(tr("Failed to open media decoder")); m_nextUri = QString(); delete m_nextDecoder; m_nextDecoder = NULL; m_switching = false; KillTimer(m_nextDecoderStartTimer); if (!m_decoder) SetState(Errored); }
bool TorcPlayer::PlayMedia(const QString &URI, bool StartPaused) { if (thread() != QThread::currentThread()) { // turn this into an asynchronous call QVariantMap data; data.insert("uri", URI); data.insert("paused", StartPaused); TorcEvent *event = new TorcEvent(Torc::PlayMedia, data); QCoreApplication::postEvent(m_parent, event); return true; } if (URI == m_uri && !(m_state == Stopped || m_state == Errored)) return false; if (URI.isEmpty()) { LOG(VB_GENERAL, LOG_ERR, "Invalid uri"); SendUserMessage(tr("Failed to open '%1' (invalid filename)").arg(URI)); return false; } if (m_switching) { LOG(VB_GENERAL, LOG_ERR, "Player busy"); SendUserMessage(tr("Player busy")); return false; } if (!m_decoder) SetState(Opening); // create the new decoder m_nextDecoderPlay = !StartPaused; m_nextUri = URI; m_nextDecoder = TorcDecoder::Create(m_decoderFlags, URI, this); if (!m_nextDecoder) { LOG(VB_GENERAL, LOG_ERR, "Failed to open decoder"); SendUserMessage(tr("Failed to open media decoder")); m_nextUri = QString(); return false; } if (!m_nextDecoder->Open()) { LOG(VB_GENERAL, LOG_ERR, "Failed to open decoder"); SendUserMessage(tr("Failed to open media decoder")); m_nextUri = QString(); delete m_nextDecoder; m_nextDecoder = NULL; return false; } StartTimer(m_nextDecoderStartTimer, DECODER_START_TIMEOUT); m_switching = true; return true; }
bool TorcPlayer::Refresh(quint64 TimeNow, const QSizeF &Size, bool Visible) { (void)TimeNow; (void)Size; (void)Visible; // destroy last decoder once it has stopped if (m_oldDecoder && m_oldDecoder->GetState() == TorcDecoder::Stopped) DestroyOldDecoder(); // check next decoder status if (m_nextDecoder) { int state = m_nextDecoder->GetState(); if (state == TorcDecoder::Errored || state == TorcDecoder::Stopped) { DestroyNextDecoder(); } else if (state > TorcDecoder::Opening && !m_oldDecoder) { m_oldDecoder = m_decoder; if (m_oldDecoder) { StartTimer(m_oldDecoderStopTimer, DECODER_STOP_TIMEOUT); m_oldDecoder->Stop(); } m_decoder = m_nextDecoder; m_uri = m_nextUri; m_nextUri = QString(); m_nextDecoder = NULL; m_switching = false; KillTimer(m_nextDecoderStartTimer); SetState(Paused); if (m_nextDecoderPlay && !m_oldDecoder) Play(); } } // I need fixing if ((m_state == Stopped || m_state == Errored) && m_nextState == None) return false; // check for fatal errors if (m_decoder) { if (m_decoder->GetState() == TorcDecoder::Errored) { SendUserMessage(tr("Fatal error decoding media")); LOG(VB_GENERAL, LOG_ERR, "Fatal decoder error detected. Stopping playback"); SetState(Errored); return false; } } else // no decoder { if (m_state == None || m_state == Opening) return false; SetState(Errored); return false; } // check for playback completion if (m_decoder->GetState() == TorcDecoder::Stopped) { SetState(Stopped); delete m_decoder; m_decoder = NULL; } // update state if (m_nextState != None) { if (m_nextState != m_state) { if (m_nextState == Paused) { SetState(Pausing); StartTimer(m_pauseTimer, DECODER_PAUSE_TIMEOUT); } else if (m_nextState == Playing) { if (m_oldDecoder) { LOG(VB_GENERAL, LOG_WARNING, "Trying to start decoder before old decoder stopped"); return false; } SetState(Starting); StartTimer(m_playTimer, DECODER_PAUSE_TIMEOUT); } else if (m_nextState == Stopped) { SetState(Stopping); StartTimer(m_stopTimer, DECODER_STOP_TIMEOUT); } } m_nextState = None; } if (m_state == Pausing) { if (m_decoder->GetState() == TorcDecoder::Paused) SetState(Paused); else if (m_decoder->GetState() != TorcDecoder::Pausing) m_decoder->Pause(); } if (m_state == Starting) { if (m_decoder->GetState() == TorcDecoder::Running) SetState(Playing); else if (m_decoder->GetState() != TorcDecoder::Starting) m_decoder->Start(); } if (m_state == Stopping) { if (m_decoder->GetState() == TorcDecoder::Stopped) SetState(Stopped); else if (m_decoder->GetState() != TorcDecoder::Stopping) m_decoder->Stop(); } return true; }
bool VideoUIPlayer::HandleAction(int Action) { if (m_render) { if (Action == Torc::DisplayDeviceReset) { return m_render->DisplayReset(); } else if (Action == Torc::EnableHighQualityScaling || Action == Torc::DisableHighQualityScaling || Action == Torc::ToggleHighQualityScaling) { if (IsPropertyAvailable(HQScaling)) { if (Action == Torc::EnableHighQualityScaling) { SendUserMessage(QObject::tr("Requested high quality scaling")); return m_render->SetProperty(TorcPlayer::HQScaling, QVariant(true)); } else if (Action == Torc::DisableHighQualityScaling) { SendUserMessage(QObject::tr("Disabled high quality scaling")); return m_render->SetProperty(TorcPlayer::HQScaling, QVariant(false)); } else if (Action == Torc::ToggleHighQualityScaling) { bool enabled = !(m_render->GetProperty(TorcPlayer::HQScaling).toBool()); SendUserMessage(enabled ? QObject::tr("Requested high quality scaling") : QObject::tr("Disabled high quality scaling")); return m_render->SetProperty(TorcPlayer::HQScaling, QVariant(enabled)); } } else { SendUserMessage(QObject::tr("Not available")); } } else if (Action == Torc::DecreaseBrightness) { return m_colourSpace->ChangeProperty(Brightness, false); } else if (Action == Torc::IncreaseBrightness) { return m_colourSpace->ChangeProperty(Brightness, true); } else if (Action == Torc::DecreaseContrast) { return m_colourSpace->ChangeProperty(Contrast, false); } else if (Action == Torc::IncreaseContrast) { return m_colourSpace->ChangeProperty(Contrast, true); } else if (Action == Torc::DecreaseSaturation) { return m_colourSpace->ChangeProperty(Saturation, false); } else if (Action == Torc::IncreaseSaturation) { return m_colourSpace->ChangeProperty(Saturation, true); } else if (Action == Torc::DecreaseHue) { return m_colourSpace->ChangeProperty(Hue, false); } else if (Action == Torc::IncreaseHue) { return m_colourSpace->ChangeProperty(Hue, true); } } return VideoPlayer::HandleAction(Action); }