void QGstreamerPlayerControl::setMedia(const QMediaContent &content, QIODevice *stream) { QMediaPlayer::State oldState = m_state; m_state = QMediaPlayer::StoppedState; m_session->stop(); if (m_bufferProgress != -1) { m_bufferProgress = -1; emit bufferStatusChanged(0); } if (m_stream) { closeFifo(); disconnect(m_stream, SIGNAL(readyRead()), this, SLOT(writeFifo())); m_stream = 0; } m_currentResource = content; m_stream = stream; m_seekToStartPending = false; QNetworkRequest request; if (m_stream) { if (m_stream->isReadable() && openFifo()) { request = QNetworkRequest(QUrl(QString(QLatin1String("fd://%1")).arg(m_fifoFd[0]))); } } else if (!content.isNull()) { request = content.canonicalRequest(); } m_session->load(request); if (m_fifoFd[1] >= 0) { m_fifoCanWrite = true; writeFifo(); } if (!request.url().isEmpty()) { if (m_mediaStatus != QMediaPlayer::LoadingMedia) emit mediaStatusChanged(m_mediaStatus = QMediaPlayer::LoadingMedia); m_session->pause(); } else { if (m_mediaStatus != QMediaPlayer::NoMedia) emit mediaStatusChanged(m_mediaStatus = QMediaPlayer::NoMedia); setBufferProgress(0); } emit mediaChanged(m_currentResource); if (m_state != oldState) emit stateChanged(m_state); }
void QGstreamerPlayerControl::setMedia(const QMediaContent &content, QIODevice *stream) { #ifdef DEBUG_PLAYBIN qDebug() << Q_FUNC_INFO; #endif pushState(); m_currentState = QMediaPlayer::StoppedState; QMediaContent oldMedia = m_currentResource; m_pendingSeekPosition = 0; m_session->showPrerollFrames(false); // do not show prerolled frames until pause() or play() explicitly called m_setMediaPending = false; if (!content.isNull() || stream) { if (!m_resources->isGranted()) m_resources->acquire(); } else { m_resources->release(); } m_session->stop(); bool userStreamValid = false; if (m_bufferProgress != -1) { m_bufferProgress = -1; emit bufferStatusChanged(0); } if (m_stream && m_stream != stream) { if (m_ownStream) delete m_stream; m_stream = 0; m_ownStream = false; } // If the canonical URL refers to a Qt resource, open with QFile and use // the stream playback capability to play. if (stream == 0 && content.canonicalUrl().scheme() == QLatin1String("qrc")) { stream = new QFile(QLatin1Char(':') + content.canonicalUrl().path(), this); if (!stream->open(QIODevice::ReadOnly)) { delete stream; m_mediaStatus = QMediaPlayer::InvalidMedia; m_currentResource = content; emit mediaChanged(m_currentResource); emit error(QMediaPlayer::FormatError, tr("Attempting to play invalid Qt resource")); if (m_currentState != QMediaPlayer::PlayingState) m_resources->release(); popAndNotifyState(); return; } m_ownStream = true; } m_currentResource = content; m_stream = stream; QNetworkRequest request; if (m_stream) { userStreamValid = stream->isOpen() && m_stream->isReadable(); request = content.canonicalRequest(); } else if (!content.isNull()) { request = content.canonicalRequest(); } #if !defined(HAVE_GST_APPSRC) m_session->loadFromUri(request); #else if (m_stream) { if (userStreamValid){ m_session->loadFromStream(request, m_stream); } else { m_mediaStatus = QMediaPlayer::InvalidMedia; emit error(QMediaPlayer::FormatError, tr("Attempting to play invalid user stream")); if (m_currentState != QMediaPlayer::PlayingState) m_resources->release(); popAndNotifyState(); return; } } else m_session->loadFromUri(request); #endif #if defined(HAVE_GST_APPSRC) if (!request.url().isEmpty() || userStreamValid) { #else if (!request.url().isEmpty()) { #endif m_mediaStatus = QMediaPlayer::LoadingMedia; m_session->pause(); } else { m_mediaStatus = QMediaPlayer::NoMedia; setBufferProgress(0); } if (m_currentResource != oldMedia) emit mediaChanged(m_currentResource); emit positionChanged(position()); if (content.isNull() && !stream) m_resources->release(); popAndNotifyState(); } void QGstreamerPlayerControl::setVideoOutput(QObject *output) { m_session->setVideoRenderer(output); }