Ejemplo n.º 1
0
void MFPlayerControl::play()
{
    if (m_state == QMediaPlayer::PlayingState)
        return;
    if (QMediaPlayer::InvalidMedia == m_session->status())
        m_session->load(m_media, m_stream);

    switch (m_session->status()) {
    case QMediaPlayer::UnknownMediaStatus:
    case QMediaPlayer::NoMedia:
    case QMediaPlayer::InvalidMedia:
        return;
    case QMediaPlayer::LoadedMedia:
    case QMediaPlayer::BufferingMedia:
    case QMediaPlayer::BufferedMedia:
    case QMediaPlayer::EndOfMedia:
        changeState(QMediaPlayer::PlayingState);
        m_session->start();
        break;
    default: //Loading/Stalled
        changeState(QMediaPlayer::PlayingState);
        break;
    }
    refreshState();
}
Ejemplo n.º 2
0
TErrors SalsaStream::setSampleRate(TSampleRate sample_rate) {
	if(pcm_state_ != CLOSED) refreshState();
	if(pcm_state_ == OPENED || pcm_state_ == SETUP) {

		snd_pcm_hw_params_alloca(&hw_config_);
		snd_pcm_hw_params_current(pcm_, hw_config_);

		unsigned int rate = sample_rate;
		int err=snd_pcm_hw_params_set_rate_near(pcm_, hw_config_, &rate, NULL);
		CHECK_SNDERROR(err, E_STREAM_CONFIG);

		rate_ = rate;

		if(sample_rate != rate) {
			stringstream s;
			const char* dir = (direction_==INPUT_STREAM)?"Input":"Output";
			s << dir << " stream: "<< name_ << "Sample rate: given = " << sample_rate << "applied = " << rate;
			LOGGER().warning(E_STREAM_PARAM_DIFFERENCE, s.str().c_str());
			return E_STREAM_PARAM_DIFFERENCE;
		}

		snd_pcm_hw_params(pcm_, hw_config_);
	}
	else rate_ = sample_rate;


	return E_OK;
}
Ejemplo n.º 3
0
TErrors SalsaStream::setChannelCount(TChannels channels) {
	if(pcm_state_ != CLOSED) refreshState();
	if(pcm_state_ == OPENED || pcm_state_ == SETUP) {

		snd_pcm_hw_params_alloca(&hw_config_);
		snd_pcm_hw_params_current(pcm_, hw_config_);

		unsigned int ch = channels;
		int err = snd_pcm_hw_params_set_channels_near(pcm_, hw_config_, &ch);
		CHECK_SNDERROR(err, E_STREAM_CONFIG);

		channels_ = (TChannels) ch;
		if(channels != ch){
			stringstream s;
			const char* dir = (direction_==INPUT_STREAM)?"Input":"Output";
			s << dir<< " stream: "<<
					name_ << "channel number: given = " << channels <<
					"applied = " << ch;
			LOGGER().warning(E_STREAM_PARAM_DIFFERENCE, s.str().c_str());
			return E_STREAM_PARAM_DIFFERENCE;
		}


		snd_pcm_hw_params(pcm_, hw_config_);
	}
	else channels_ = channels;

	return E_OK;
}
Ejemplo n.º 4
0
void CsmaAloha::stateRxPacketNotForMe(Packet* p) {
    if (debug_) cout << NOW << "  CsmaAloha("<< addr << ")::stateRxPacketNotForMe() pkt for another address. Dropping pkt" << endl;
    if ( p != NULL ) Packet::free(p);

    refreshState( CSMA_STATE_WRONG_PKT_RX );

    switch( prev_state ) {

    case CSMA_STATE_RX_IDLE:
        stateIdle();
        break;

    case CSMA_STATE_RX_LISTEN:
        stateCheckListenExpired();
        break;

    case CSMA_STATE_RX_BACKOFF:
        stateCheckBackoffExpired();
        break;

    case CSMA_STATE_RX_WAIT_ACK:
        stateCheckAckExpired();
        break;

    default:
        cerr << NOW << "  CsmaAloha("<< addr << ")::stateRxPacketNotForMe() logical error, current state = "
             << status_info[curr_state] << endl;
        stateIdle();

    }
}
Ejemplo n.º 5
0
void CsmaAloha::stateTxAck( int dest_addr ) {
    refreshState(CSMA_STATE_TX_ACK);

    if (debug_) cout << NOW << "  CsmaAloha("<< addr << ")::stateTxAck() dest addr " << dest_addr << endl;
    if (print_transitions) printStateInfo();

    txAck( dest_addr );
}
Ejemplo n.º 6
0
void MFPlayerControl::pause()
{
    if (m_state != QMediaPlayer::PlayingState)
        return;
    changeState(QMediaPlayer::PausedState);
    m_session->pause();
    refreshState();
}
Ejemplo n.º 7
0
void MFPlayerControl::stop()
{
    if (m_state == QMediaPlayer::StoppedState)
        return;
    changeState(QMediaPlayer::StoppedState);
    m_session->stop();
    refreshState();
}
Ejemplo n.º 8
0
void CsmaAloha::stateBackoff() {
    refreshState(CSMA_STATE_BACKOFF);

    if ( backoff_timer.isFrozen() ) backoff_timer.unFreeze();
    else backoff_timer.schedule( getBackoffTime() );

    if (debug_) cout << NOW << "  CsmaAloha("<< addr << ")::stateBackoff() " << endl;
    if (print_transitions) printStateInfo(backoff_timer.getDuration());
}
void
UwCsmaAloha_Trigger_SINK::stateDisableRx()
{
	refreshState(UW_CS_ALOHA_TRIG_SINK_STATE_DISABLE_RX);
	if (debug_)
		cout << NOW << "UwCsmaAloha_Trigger_SINK(" << addr
			 << ")----> Timer fired ----> Disabling Receving Data" << endl;
	receiving_state_active = false;
	stateIdle();
}
Ejemplo n.º 10
0
void CsmaAloha::stateCheckAckExpired() {
    refreshState(CSMA_STATE_CHK_ACK_TIMEOUT);

    if (debug_) cout << NOW << "  CsmaAloha("<< addr << ")::stateCheckAckExpired()" << endl;
    if (print_transitions) printStateInfo();
    if ( ack_timer.isActive() ) {
        refreshReason( CSMA_REASON_WAIT_ACK_PENDING );
        refreshState( CSMA_STATE_WAIT_ACK );
    }
    else if ( ack_timer.isExpired() ) {
        refreshReason( CSMA_REASON_ACK_TIMEOUT );
        stateBackoff();
    }
    else {
        cerr << NOW << "  CsmaAloha("<< addr << ")::stateCheckAckExpired() ack_timer logical error, current timer state = "
             << status_info[curr_state] << endl;
        stateIdle();
    }
}
Ejemplo n.º 11
0
void CsmaAloha::stateWaitAck() {
    ack_timer.stop();
    refreshState(CSMA_STATE_WAIT_ACK);

    if (debug_) cout << NOW << "  CsmaAloha("<< addr << ")::stateWaitAck() " << endl;
    if (print_transitions) printStateInfo();

    ack_timer.incrCounter();
    ack_timer.schedule(ACK_timeout + 2*wait_costant);
}
void
UwCsmaAloha_Trigger_SINK::stateIdle()
{
	receive_timer.force_cancel();
	refreshState(UW_CS_ALOHA_TRIG_SINK_STATE_IDLE);
	if (debug_)
		std::cout << NOW << "  UwCsmaAloha_Trigger_SINK(" << addr
				  << ")::stateIdle() --> TRANSMITTING TRIGGER" << endl;
	stateTxTRIGGER();
}
void
UwCsmaAloha_Trigger_SINK::stateRxData(Packet *data_pkt)
{
	refreshState(UW_CS_ALOHA_TRIG_SINK_STATE_DATA_RX);
	if (debug_)
		cout << NOW << "  UwCsmaAloha_Trigger_SINK(" << addr
			 << ")::stateRxData() " << endl;
	incrDataPktsRx();
	sendUp(data_pkt);
}
void
UwCsmaAloha_Trigger_SINK::stateTxTRIGGER()
{
	if (debug_)
		cout << NOW << "UwCsmaAloha_Trigger_SINK(" << addr
			 << ")--->stateTxTRIGGER()" << endl;
	refreshState(UW_CS_ALOHA_TRIG_SINK_STATE_TX_TRIGGER);
	Packet *p = Packet::alloc();
	initPkt(p, MAC_BROADCAST);
	txTRIGGER(p);
}
void
UwCsmaAloha_Trigger_SINK::stateEnableRx()
{
	refreshState(UW_CS_ALOHA_TRIG_SINK_STATE_ENABLE_RX);
	if (debug_)
		cout << NOW << "UwCsmaAloha_Trigger_SINK(" << addr
			 << ") ----> Enabling Receive() timer_duration = "
			 << tx_timer_duration << endl;
	receive_timer.resched(tx_timer_duration);
	receiving_state_active = true;
}
Ejemplo n.º 16
0
void CsmaAloha::stateCheckListenExpired() {
    refreshState(CSMA_STATE_CHK_LISTEN_TIMEOUT);

    if (debug_) cout << NOW << "  CsmaAloha("<< addr << ")::stateCheckListenExpired()" << endl;
    if (print_transitions) printStateInfo();
    if ( listen_timer.isActive() ) {
        refreshReason( CSMA_REASON_LISTEN_PENDING );
        refreshState( CSMA_STATE_LISTEN );
    }
    else if ( listen_timer.isExpired() ) {
        refreshReason( CSMA_REASON_LISTEN_TIMEOUT );
        if ( !( prev_state == CSMA_STATE_TX_ACK || prev_state == CSMA_STATE_WRONG_PKT_RX
                || prev_state == CSMA_STATE_ACK_RX || prev_state == CSMA_STATE_DATA_RX ) ) stateTxData();
        else stateListen();
    }
    else {
        cerr << NOW << "  CsmaAloha("<< addr << ")::stateCheckListenExpired() listen_timer logical error, current timer state = "
             << status_info[curr_state] << endl;
        stateIdle();
    }
}
Ejemplo n.º 17
0
void CsmaAloha::stateRxData(Packet* data_pkt) {
    refreshState( CSMA_STATE_DATA_RX );

    if (debug_) cout << NOW << "  CsmaAloha("<< addr << ")::stateRxData() in state " << status_info[curr_state] << endl;
    refreshReason( CSMA_REASON_DATA_RX );

    hdr_mac* mach = HDR_MAC(data_pkt);
    int dst_addr = mach->macSA();

    switch( prev_state ) {

    case CSMA_STATE_RX_IDLE: {
        hdr_cmn* ch = hdr_cmn::access(data_pkt);
        ch->size() = ch->size() - HDR_size;
        incrDataPktsRx();
        sendUp(data_pkt);

        if (ack_mode == CSMA_ACK_MODE) stateTxAck(dst_addr);
        else stateIdle();
    }
    break;

    case CSMA_STATE_RX_LISTEN: {
        hdr_cmn* ch = hdr_cmn::access(data_pkt);
        ch->size() = ch->size() - HDR_size;
        incrDataPktsRx();
        sendUp(data_pkt);

        if (ack_mode == CSMA_ACK_MODE) stateTxAck(dst_addr);
        else stateCheckListenExpired();
    }
    break;

    case CSMA_STATE_RX_BACKOFF: {
        hdr_cmn* ch = hdr_cmn::access(data_pkt);
        ch->size() = ch->size() - HDR_size;
        incrDataPktsRx();
        sendUp(data_pkt);
        if (ack_mode == CSMA_ACK_MODE) stateTxAck(dst_addr);
        else stateCheckBackoffExpired();
    }
    break;


    default:

        cerr << NOW << " CsmaAloha("<< addr << ")::stateRxData() logical error, prev state = " << status_info[prev_state]
             << endl;

    }
}
Ejemplo n.º 18
0
void CsmaAloha::stateListen() {
    listen_timer.stop();
    refreshState(CSMA_STATE_LISTEN);

    listen_timer.incrCounter();

    double time = listen_time * RNG::defaultrng()->uniform_double() + wait_costant;

    if (debug_) cout << NOW << "  CsmaAloha("<< addr << ")::stateListen() listen time = " << time << endl;

    if (print_transitions) printStateInfo();

    listen_timer.schedule( time );
}
Ejemplo n.º 19
0
void MFPlayerControl::setMedia(const QMediaContent &media, QIODevice *stream)
{
    if (m_state != QMediaPlayer::StoppedState) {
        changeState(QMediaPlayer::StoppedState);
        m_session->stop(true);
        refreshState();
    }

    m_media = media;
    m_stream = stream;
    resetAudioVideoAvailable();
    handleDurationUpdate(-1);
    handleSeekableUpdate(false);
    m_session->load(media, stream);
    emit mediaChanged(m_media);
}
void
UwCsmaAloha_Trigger_SINK::txTRIGGER(Packet *p)
{
	if (!receiving_state_active) {
		refreshState(UW_CS_ALOHA_TRIG_SINK_STATE_TX_TRIGGER);
		if (debug_)
			cout << NOW << "UwCsmaAloha_Trigger_SINK(" << addr
				 << ")---> Transmitting TRIGGER" << endl;
		incrTRIGGERPacketTx();
		Mac2PhyStartTx(p);
	} else {
		if (debug_)
			cout << NOW << "UwCsmaAloha_Trigger_SINK(" << addr
				 << ")----> Not transmitting TRIGGER, receiving active" << endl;
		Packet::free(p);
	}
}
Ejemplo n.º 21
0
void CsmaAloha::stateIdle() {
    ack_timer.stop();
    backoff_timer.stop();
    listen_timer.stop();
    resetSession();

    refreshState(CSMA_STATE_IDLE);

    if (print_transitions) printStateInfo();

    if (debug_) cout << NOW << "  CsmaAloha("<< addr << ")::stateIdle() queue size = " << Q.size() << endl;

    if ( !Q.empty() ) {
        refreshReason(CSMA_REASON_LISTEN);
        stateListen();
    }
}
Ejemplo n.º 22
0
void MFPlayerControl::handleStatusChanged()
{
    QMediaPlayer::MediaStatus status = m_session->status();
    switch (status) {
    case QMediaPlayer::EndOfMedia:
        changeState(QMediaPlayer::StoppedState);
        break;
    case QMediaPlayer::InvalidMedia:
        break;
    case QMediaPlayer::LoadedMedia:
    case QMediaPlayer::BufferingMedia:
    case QMediaPlayer::BufferedMedia:
        if (m_state == QMediaPlayer::PlayingState)
            m_session->start();
        break;
    }
    emit mediaStatusChanged(m_session->status());
    refreshState();
}
Ejemplo n.º 23
0
StatusBar::StatusBar(StateManager* sm)
{
	xPos = 0;
	yPos = 0;
	width = 0;
	height = 0;
	
	state = sm;

	curr = state->getCurrent();
	
	directory = new DrawText("a");
	num_files = new DrawText("b");
	
	directory->setFontSize(12);
	directory->setAlignment(LEFT);
	num_files->setFontSize(12);
	num_files->setAlignment(RIGHT);
	refreshState();
}
Ejemplo n.º 24
0
Killswitch::Killswitch(UrfEnumType type)
{
    QDBusConnection conn = QDBusConnection::systemBus();
    if (!QDBusConnection::systemBus().isConnected()) {
        qDebug() << "Cannot connect to the D-Bus system bus.";

        return;
    }

    QString objPath = getObjectPath(type);
    killswitchIface = new QDBusInterface(URFKILL_SERVICE, objPath, URFKILL_KILLSWITCH_INTERFACE, conn, this);
    if (!killswitchIface->isValid()) {
        qDebug() << "Can not create DBus interface!";
        qDebug() << QDBusConnection::systemBus().lastError().message();

        return;
    }

    refreshState();

    connect(killswitchIface, SIGNAL(StateChanged(int)), this, SLOT(stateChanged(int)));
}
Ejemplo n.º 25
0
void StatusBar::draw()
{
	if (curr != state->getCurrent())
		refreshState();
	
	// Set the position of the labels, based on the viewport.
	int p[4];
	glGetIntegerv(GL_VIEWPORT,p);
	
	// Turn on blending.
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
	directory->setPosition(2,directory->getHeight()-(float)p[3]);
	num_files->setPosition((float)p[2]-2,num_files->getHeight()-(float)p[3]);
	
	directory->draw();
	num_files->draw();
	
	// Turn off blending.
	glDisable(GL_BLEND);
}
Ejemplo n.º 26
0
void CsmaAloha::stateRxAck(Packet* p) {
    ack_timer.stop();
    refreshState(CSMA_STATE_ACK_RX);
    if (debug_) cout << NOW << "  CsmaAloha("<< addr << ")::stateRxAck() " << endl;

    Packet::free(p);

    refreshReason(CSMA_REASON_ACK_RX);

    switch( prev_state ) {

    case CSMA_STATE_RX_IDLE:
        stateIdle();
        break;

    case CSMA_STATE_RX_LISTEN:
        stateCheckListenExpired();
        break;

    case CSMA_STATE_RX_BACKOFF:
        stateCheckBackoffExpired();
        break;

    case CSMA_STATE_RX_WAIT_ACK:
        queuePop();
        updateAckTimeout(NOW - start_tx_time);
        incrAckPktsRx();
        stateIdle();
        break;

    default:

        cerr << NOW << " CsmaAloha("<< addr << ")::stateRxAck() logical error, prev state = " << status_info[prev_state]
             << endl;

    }
}
Ejemplo n.º 27
0
void CsmaAloha::stateTxData()
{
    refreshState(CSMA_STATE_TX_DATA);


    if (debug_) cout << NOW << "  CsmaAloha("<< addr << ")::stateTxData() " << endl;
    if (print_transitions) printStateInfo();

    curr_data_pkt = Q.front();


    if ( data_sn_queue.front() != last_sent_data_id) {
        resetCurrTxRounds();
        ack_timer.resetCounter();
        listen_timer.resetCounter();
        backoff_timer.resetCounter();
    }
    if ( curr_tx_rounds < max_tx_tries ) {
        hdr_mac* mach = HDR_MAC(curr_data_pkt);

        mach->macSA() = addr;
        start_tx_time = NOW;
        last_sent_data_id = data_sn_queue.front();
        txData();
    }
    else {
        queuePop(false);
        incrDroppedPktsTx();

        refreshReason(CSMA_REASON_MAX_TX_TRIES);

        if (debug_) cout << NOW << "  CsmaAloha("<< addr << ")::stateTxData() curr_tx_rounds " << curr_tx_rounds
                             << " > max_tx_tries = " << max_tx_tries << endl;

        stateIdle();
    }
}
Ejemplo n.º 28
0
void CsmaAloha::stateRxBackoff() {
    backoff_timer.freeze();
    refreshState(CSMA_STATE_RX_BACKOFF);

    if (print_transitions) printStateInfo();
}
Ejemplo n.º 29
0
void Killswitch::stateChanged(int state)
{
    //qDebug() << "state changed!";
    refreshState();
    emit triggerStateChanged();
}
Ejemplo n.º 30
0
void CsmaAloha::stateRxWaitAck() {
    refreshState(CSMA_STATE_RX_WAIT_ACK);

    if (print_transitions) printStateInfo();
}