Пример #1
0
bool SocketSender::flush(Exception& ex,Socket& socket) {
	if (available()) {

		UInt32 size;
		const UInt8* data;
		if (_ppBuffer) {
			size = (*_ppBuffer)->size();
			data = (*_ppBuffer)->data();
		} else {
			size = this->size();
			data = this->data();
		}

		_position += send(ex,socket,data + _position, size - _position);

		if (ex) // terminate the sender if error
			_position = size;
		// everything has been sent
		if (_position >= size) {
			if (_ppBuffer)
				_ppBuffer->release();
		} else if (buffering(socket.manager().poolBuffers))
			return false;
	}
	onSent(socket);
	return true;
}
        bool operator()(Component const& component)
        {
            typedef
                typename traits::attribute_of<Component, Context>::type
            expected_type;
            typedef
                alternative_generate<Component, Attribute, expected_type>
            generate;

            if (failed)
                return false;     // give up when already failed

            // wrap the given output iterator avoid output as long as one
            // component fails
            detail::enable_buffering<OutputIterator> buffering(sink);
            bool r = false;
            {
                detail::disable_counting<OutputIterator> nocounting(sink);
                r = generate::call(component, sink, ctx, delim, attr, failed);
            }
            if (r && !failed) 
            {
                buffering.buffer_copy();
                return true;
            }
            return false;
        }
Пример #3
0
int Playengine::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: volume((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 1: statusChanged((*reinterpret_cast< Playengine::STATUS(*)>(_a[1]))); break;
        case 2: buffering((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 3: tick((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
        case 4: togglePause(); break;
        case 5: play((*reinterpret_cast< const QUrl(*)>(_a[1]))); break;
        case 6: stop(); break;
        case 7: setVolume((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 8: stateChanged((*reinterpret_cast< Phonon::State(*)>(_a[1])),(*reinterpret_cast< Phonon::State(*)>(_a[2]))); break;
        case 9: tickslot((*reinterpret_cast< qint64(*)>(_a[1]))); break;
        case 10: sourceChanged((*reinterpret_cast< const Phonon::MediaSource(*)>(_a[1]))); break;
        case 11: metaStateChanged((*reinterpret_cast< Phonon::State(*)>(_a[1])),(*reinterpret_cast< Phonon::State(*)>(_a[2]))); break;
        case 12: aboutToFinish(); break;
        case 13: bufferPercent((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 14: volumeChanged((*reinterpret_cast< qreal(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 15;
    }
    return _id;
}
void S60VideoPlayerSession::MvloLoadingStarted()
{
    DP0("S60VideoPlayerSession::MvloLoadingStarted +++");

    buffering();

    DP0("S60VideoPlayerSession::MvloLoadingStarted ---");
}
void S60AudioPlayerSession::doPlay()
{
// For some reason loading progress callbalck are not called on emulator
#ifdef __WINSCW__
    buffering();
#endif
    m_player->Play();
#ifdef __WINSCW__
    buffered();
#endif

}
    inline static bool 
    center_generate(OutputIterator& sink, Context& ctx, 
        Delimiter const& d, Parameter const& param, Embedded const& e, 
        unsigned int const width, Padding const& p) 
    {
        // make sure all generator parameters are valid
        BOOST_MPL_ASSERT_MSG(
            (spirit::traits::is_component<karma::domain, Embedded>::value), 
            embedded_is_not_convertible_to_a_generator, (Context, Embedded));

        BOOST_MPL_ASSERT_MSG(
            (spirit::traits::is_component<karma::domain, Padding>::value), 
            padding_is_not_convertible_to_a_generator, (Context, Padding));

        typedef 
            typename result_of::as_component<karma::domain, Embedded>::type 
        embedded;
        typedef 
            typename result_of::as_component<karma::domain, Padding>::type 
        padding;

        // wrap the given output iterator to allow left padding
        detail::enable_buffering<OutputIterator> buffering(sink, width);

        // first generate the embedded output 
        embedded ec = spirit::as_component(karma::domain(), e);
        typedef typename embedded::director director;
        bool r = director::generate(ec, sink, ctx, d, param);

        buffering.disable();    // do not perform buffering any more
        
        // generate the left padding
        detail::enable_counting<OutputIterator> 
            counting(sink, (sink.buffer_size() + width) / 2);

        padding pc = spirit::as_component(karma::domain(), p);
        typedef typename padding::director padding_director;
        while (r && sink.count() < width) 
            r = padding_director::generate(pc, sink, ctx, unused, unused);

        if (r) {
            // copy the embedded output to the target output iterator
            sink.buffer_copy();
        
            // generate the right padding
            std::size_t const max_count = width + (width - sink.buffer_size()) / 2;
            while (r && sink.count() < max_count) 
                r = padding_director::generate(pc, sink, ctx, unused, unused);
        }
        return r;
    }
Пример #7
0
void ZAudioAdaptor::init(){
    if(instance()){
        connect(instance(), SIGNAL(bookmarkAdded(qint64)),
                this,       SIGNAL(bookmarkAdded(qint64)));
        connect(instance(), SIGNAL(bufferChanged(int)),
                this,       SIGNAL(bufferChanged(int)));
        connect(instance(), SIGNAL(buffering()),
                this,       SIGNAL(buffering()));
        connect(instance(), SIGNAL(durationChanged(qint64)),
                this,       SIGNAL(durationChanged(qint64)));
        connect(instance(), SIGNAL(loading()),
                this,       SIGNAL(loading()));
        connect(instance(), SIGNAL(paused()),
                this,       SIGNAL(paused()));
        connect(instance(), SIGNAL(playing()),
                this,       SIGNAL(playing()));
        connect(instance(), SIGNAL(positionChanged(double)),
                this,       SIGNAL(positionChanged(double)));
        connect(instance(), SIGNAL(queueChanged()),
                this,       SIGNAL(queueChanged()));
        connect(instance(), SIGNAL(queueCleared()),
                this,       SIGNAL(queueCleared()));
        connect(instance(), SIGNAL(queuedSongChanged(int)),
                this,       SIGNAL(queuedSongChanged(int)));
	connect(instance(), SIGNAL(reachedBookmark(qint64)),
                this,       SIGNAL(reachedBookmark(qint64)));
        connect(instance(), SIGNAL(sourceChanged(QString)),
                this,       SIGNAL(sourceChanged(QString)));
        connect(instance(), SIGNAL(stopped()),
                this,       SIGNAL(stopped()));
        connect(instance(), SIGNAL(timeChanged(qint64)),
                this,       SIGNAL(timeChanged(qint64)));
    }

    registerService();
}
Пример #8
0
void
HttpInput::data( QByteArray& fillMe, int numBytes )
{
    switch ( m_state )
    {
        case State_FetchingStream:
        case State_Buffering:
        {
            // Do nothing, the caller will have to wait until we're streaming again.
            Q_ASSERT( !"Caller shouldn't call us when we're not streaming." );
        }
        break;

        case State_Streaming:
        case State_Stopped:
        {
            // Even though we've stopped there might still be data left in the buffer
            fillMe = m_buffer.left( numBytes );
            m_buffer.remove( 0, numBytes );

            // Once the Http connection's closed, we've gone to Stopped
            if ( m_state != State_Stopped )
            {
                if ( m_buffer.size() == 0 )
                {
                    LOGL( 3, "Buffer empty, buffering..." );

                    m_timeoutTimer.start();

                    setState( State_Buffering );
                    emit buffering( 0, m_bufferCapacity );
                }
            }
        }
        break;

        default:
        {
            Q_ASSERT( !"Unhandled state" );
        }
        break;
    }

}
Пример #9
0
void
HttpInput::onHttpDataAvailable( const QHttpResponseHeader &resp )
{
    Q_UNUSED( resp );

    m_timeoutTimer.stop();

    m_buffer.append( m_http.readAll() );

    switch ( m_state )
    {
        case State_FetchingStream:
        {
            setState( State_StreamFetched );
            setState( State_Buffering );
        }
        // fall-through

        case State_Buffering:
        {
            if ( m_buffer.size() >= m_bufferCapacity )
            {
                setState( State_Streaming );
            }

            // We want both numbers to be the same when the buffering is finished,
            // client code might rely on it.
            emit buffering( qMin( m_buffer.size(), m_bufferCapacity ), m_bufferCapacity );
        }
        break;

        case State_Streaming:
        {
            // Do nothing
        }
        break;

        case State_Stopped:
        default:
            Q_ASSERT( !"Invalid state" );
    }
}
Пример #10
0
void GStreamerPipeline::onBuffering( const QGst::BufferingMessagePtr &msg )
{
    int percent = msg->percent();
    QGst::ObjectPtr source = msg->source();

    int minPercent = 100;

    bool isFromRightSource = false;
    for( StreamInfo &info : mStreams ) {
        if( info.queue == source ) {
            isFromRightSource = true;
            if( percent <= 5 ) {
                info.isBuffering = true;
                switchToState( PS_Buffering );
            }
            if( percent == 100 ) {
                info.isBuffering = false;
            }
            info.percent = percent;
        }
        if( info.isBuffering ) {
            minPercent = std::min( minPercent, info.percent );
        }
    }
    if( !isFromRightSource ) return;


    qDebug() << "Buffering... " << minPercent << "Source: " << source->name();

    buffering( minPercent );
    if( minPercent == 100 ) {
        finnishedBuffering();
        if( mPlayAfterBuffering ) {
            switchToState( PS_Playing );
        }
        else {
            switchToState( PS_Paused );
        }
    }
}
Пример #11
0
void ZAudioAdaptor::_stateHandler(ZAudioManager::ZAudioState state){
    switch(state){
    case ZAudioManager::Playing:
	emit playing();
	break;
    case ZAudioManager::Paused:
	emit paused();
	break;
    case ZAudioManager::Stopped:
	emit stopped();
	break;
    case ZAudioManager::Buffering:
	emit buffering();
	break;
    case ZAudioManager::Loading:
	emit loading();
	break;
    case ZAudioManager::Error:
	emit error();
	break;
    default:
	return;
    }
}
void PlayerComponent::handleMpvEvent(mpv_event *event)
{
  switch (event->event_id)
  {
    case MPV_EVENT_START_FILE:
    {
      m_CurrentUrl = mpv::qt::get_property_variant(m_mpv, "path").toString();
      m_playbackStartSent = false;
      break;
    }
    case MPV_EVENT_FILE_LOADED:
    {
      emit playing(m_CurrentUrl);
      break;
    }
    case MPV_EVENT_END_FILE:
    {
      mpv_event_end_file *end_file = (mpv_event_end_file *)event->data;
      switch (end_file->reason)
      {
        case MPV_END_FILE_REASON_EOF:
          emit finished(m_CurrentUrl);
          break;
        case MPV_END_FILE_REASON_ERROR:
          emit error(end_file->error, mpv_error_string(end_file->error));
          break;
        default:
          emit stopped(m_CurrentUrl);
          break;
      }

      emit playbackEnded(m_CurrentUrl);
      m_CurrentUrl = "";

      m_restoreDisplayTimer.start(0);
      break;
    }
    case MPV_EVENT_IDLE:
    {
      emit playbackAllDone();
      break;
    }
    case MPV_EVENT_PLAYBACK_RESTART:
    {
      // it's also sent after seeks are completed
      if (!m_playbackStartSent)
        emit playbackStarting();
      m_playbackStartSent = true;
      break;
    }
    case MPV_EVENT_PROPERTY_CHANGE:
    {
      mpv_event_property *prop = (mpv_event_property *)event->data;
      if (strcmp(prop->name, "pause") == 0 && prop->format == MPV_FORMAT_FLAG)
      {
        int state = *(int *)prop->data;
        emit paused(state);
      }
      else if (strcmp(prop->name, "cache-buffering-state") == 0 && prop->format == MPV_FORMAT_INT64)
      {
        int64_t percentage = *(int64_t *)prop->data;
        emit buffering(percentage);
      }
      else if (strcmp(prop->name, "playback-time") == 0 && prop->format == MPV_FORMAT_DOUBLE)
      {
        double pos = *(double*)prop->data;
        if (fabs(pos - m_lastPositionUpdate) > 0.25)
        {
          quint64 ms = (quint64)(qMax(pos * 1000.0, 0.0));
          emit positionUpdate(ms);
          m_lastPositionUpdate = pos;
        }
      }
      else if (strcmp(prop->name, "vo-configured") == 0)
      {
        int state = prop->format == MPV_FORMAT_FLAG ? *(int *)prop->data : 0;
        emit windowVisible(state);
      }
      else if (strcmp(prop->name, "duration") == 0)
      {
        if (prop->format == MPV_FORMAT_DOUBLE)
          emit updateDuration(*(double *)prop->data * 1000.0);
      }
      else if (strcmp(prop->name, "audio-device-list") == 0)
      {
        updateAudioDeviceList();
      }
      break;
    }
    case MPV_EVENT_LOG_MESSAGE:
    {
      mpv_event_log_message *msg = (mpv_event_log_message *)event->data;
      // Strip the trailing '\n'
      size_t len = strlen(msg->text);
      if (len > 0 && msg->text[len - 1] == '\n')
        len -= 1;
      QString logline = QString::fromUtf8(msg->prefix) + ": " + QString::fromUtf8(msg->text, len);
      if (msg->log_level >= MPV_LOG_LEVEL_V)
        QLOG_DEBUG() << qPrintable(logline);
      else if (msg->log_level >= MPV_LOG_LEVEL_INFO)
        QLOG_INFO() << qPrintable(logline);
      else if (msg->log_level >= MPV_LOG_LEVEL_WARN)
        QLOG_WARN() << qPrintable(logline);
      else
        QLOG_ERROR() << qPrintable(logline);
      break;
    }
    case MPV_EVENT_CLIENT_MESSAGE:
    {
      mpv_event_client_message *msg = (mpv_event_client_message *)event->data;
      // This happens when the player is about to load the file, but no actual loading has taken part yet.
      // We use this to block loading until we explicitly tell it to continue.
      if (msg->num_args >= 3 && !strcmp(msg->args[0], "hook_run") && !strcmp(msg->args[1], "1"))
      {
        QString resume_id = QString::fromUtf8(msg->args[2]);
        // Calling this lambda will instruct mpv to continue loading the file.
        auto resume = [=] {
          QLOG_INFO() << "resuming loading";
          mpv::qt::command_variant(m_mpv, QStringList() << "hook-ack" << resume_id);
        };
        if (switchDisplayFrameRate())
        {
          // Now wait for some time for mode change - this is needed because mode changing can take some
          // time, during which the screen is black, and initializing hardware decoding could fail due
          // to various strange OS-related reasons.
          // (Better hope the user doesn't try to exit Konvergo during mode change.)
          int pause = SettingsComponent::Get().value(SETTINGS_SECTION_VIDEO, "refreshrate.delay").toInt() * 1000;
          QLOG_INFO() << "waiting" << pause << "msec after rate switch before loading";
          QTimer::singleShot(pause, resume);
        }
        else
        {
          resume();
        }
        break;
      }
    }
    default:; /* ignore */
  }
}
void S60AudioPlayerSession::MaloLoadingStarted()
{
    buffering();
}
Пример #14
0
void S60AudioPlayerSession::doPlay()
{
    buffering();
    m_player->Play();
    buffered();
}
Пример #15
0
void S60AudioPlayerSession::MaloLoadingStarted()
{
    TRACE("S60AudioPlayerSession::MaloLoadingStarted" << qtThisPtr());
    buffering();
}