Beispiel #1
0
void ConnectSocketChannel::OnWrite()
{

	if (mState == ConnectionState::Connecting)
	{
		int err = mSocket.GetError();
		if (err != 0)
		{
			Log::FormatError("Connect error:{}", err);
			Retry();
		}
		else if (mSocket.IsSelfConnected())
		{
			Log::FormatError("Self connect.");
			Retry();
		}
		else
		{
			mState = ConnectionState::Connected;
			OnConnectionEstablished(mSocket);
		}
	}
	else
	{
		//error
	}
}
Beispiel #2
0
void ConnectSocketChannel::Connect()
{
	RETURN_IF_EQUAL(mState, ConnectionState::Connected);
	mState = ConnectionState::Connecting;
	mLoop->AssertInLoopThread();
	mSocket.CreateSocket();
	mSocket.EnableAsync(true);
	mSocket.EnableTcpNoDelay(true);

	ChannelEventResult connectResult = mSocket.Connect();	//connect timeout
	switch (connectResult)
	{
	case ChannelEventResult::Success:
		mState = ConnectionState::Connected;
		return;
	case ChannelEventResult::InProgress:
		mState = ConnectionState::Connecting;
		BeginWrite();
		SubmitToLoop();
		break;
	case ChannelEventResult::Retry:
		Retry();
		break;
	case ChannelEventResult::Fault:
	default:
		OnError();
		break;
	}

}
	FramePtr decodeUntilVideoFrame(){
		StreamFrameMap streamFrames;
		streamFrames[videoStream] = Frame::CreateEmpty();

		for(int i = 0; i < 100; i++){
			try {
				bool ret = decodeFrame(streamFrames);

				if(!ret){
					FlogW("failed to decode frame");
					return false;
				}

				// throw away any resulting frames
				if(streamFrames[videoStream]->finished != 0)
					return streamFrames[videoStream];
			}

			catch(VideoException e)
			{
				FlogW("While decoding video frame");
				FlogW(e.what());
			}

			Retry("not a video frame in decodeUntilVideoFrame()");
		}

		FlogD("couldn't find a video frame in 100 steps");
		return 0;
	}
	void tick(bool includeOldAudio = false){
		bool success = false;

		StreamFrameMap streamFrames;

		streamFrames[videoStream] = Frame::CreateEmpty();
		streamFrames[audioStream] = Frame::CreateEmpty();

		while(!IsEof() && !success)
		{
			try
			{
				int audioQueueTargetSize = audioDevice->GetBlockSize() * 4;

				while(
					frameQueue.size() < (unsigned int)targetFrameQueueSize || 
					(hasAudioStream() && audioHandler->getAudioQueueSize() < audioQueueTargetSize))
				{
					if(frameQueue.size() >= (unsigned int)maxFrameQueueSize)
						break;
					
					bool frameDecoded = decodeFrame(streamFrames);

					if(!frameDecoded)
						throw VideoException(VideoException::EDecodingVideo);

					if(streamFrames[videoStream]->finished != 0){
						frameQueue.push(streamFrames[videoStream]->Clone());
						streamFrames[videoStream] = Frame::CreateEmpty();
					}
					
					if(streamFrames[audioStream]->finished != 0){
						// only enqueue audio that's newer than the current video time, 
						// eg. on seeking we might encounter audio that's older than the frames in the frame queue.
						if(streamFrames[audioStream]->GetSamples().size() > 0 && 
							(includeOldAudio || streamFrames[audioStream]->GetSamples()[0].ts >= timeHandler->GetTime()))
						{
							audioHandler->EnqueueAudio(streamFrames[audioStream]->GetSamples());
						}else{
							FlogD("skipping old audio samples: " << streamFrames[audioStream]->GetSamples().size());
						}
						streamFrames[audioStream] = Frame::CreateEmpty();
					}
				}

				// sync framequeue target size with number of frames needed for audio queue 
				if(targetFrameQueueSize < (int)frameQueue.size()){
					targetFrameQueueSize = std::max((int)frameQueue.size(), minFrameQueueSize);
				}
					
				success = true;
			}

			catch(VideoException e)
			{
				Retry(Str("Exception in tick: " << e.what()));
			}
		}
	}
Beispiel #5
0
void ConnectSocketChannel::OnError()
{
	SocketChannel::OnError();
	if (mState == ConnectionState::Connecting)
	{
		Retry();
	}
}
	void decodePacket(PacketPtr packet, StreamFrameMap& streamFrames)
	{
		int bytesRemaining = packet->avPacket.size;

		// Decode until all bytes in the read frame is decoded
		while(bytesRemaining > 0)
		{
			int bytesDecoded = 0;
			int idx = packet->avPacket.stream_index;
			auto it = streamFrames.find(idx);

			if(it != streamFrames.end()){
				FramePtr frame = it->second;

				switch(pFormatCtx->streams[idx]->codec->codec_type){
					case AVMEDIA_TYPE_VIDEO:
						if( (bytesDecoded = avcodec_decode_video2(pCodecCtx, frame->GetAvFrame(), &frame->finished, &packet->avPacket)) <= 0 ){
							Retry(Str("avcodec_decode_video2() failed in decodePacket, returned: " << bytesDecoded));
						}
						frame->hasVideo = true;
						break;

					case AVMEDIA_TYPE_AUDIO:
						if((bytesDecoded = audioHandler->decode(packet->avPacket, pFormatCtx->streams[audioStream], frame, frame->finished)) <= 0){
							Retry(Str("audio decoder failed in decodePacket, returned: " << bytesDecoded));
						}
						frame->hasAudio = true;
						break;

					default:
						break;
				}
			}else{
				// stream not handled
				return;
			}

			bytesRemaining -= bytesDecoded;

			if(bytesRemaining > 0)
				Retry(Str("decodePacket not finished, bytesRemaining: " << bytesRemaining << ", bytesDecoded: " << bytesDecoded));
		}
	}
Beispiel #7
0
void MainWindow::showEvent(QShowEvent *)
{
    // Setting the QGraphicsScene


    //scene = new QGraphicsScene(0,0,width(),ui->graphicsView->height());
    scene = new QGraphicsScene(0,0,1920,1080);
    ui->graphicsView->setScene(scene);

    // Create world
    world = new b2World(b2Vec2(0.0f, -9.8f));

    // Setting Size
    GameItem::setGlobalSize(QSizeF(32,18),size());

    // Create ground (You can edit here)
    itemList.push_back(new Land(16,1.5,32,3,QPixmap(":/ground.png").scaled(width(),height()/6.0),world,scene));
        shoot.setPixmap(QPixmap(":/shot.png"));
    scene->addItem(&shoot);



    shoot.setPos(QPointF(500,500));
    // Create bird (You can edit here)
    birdie[0] = new Bird(1,4,0.27f,&timer,QPixmap(":/red.png").scaled(height()/9.0,height()/9.0)   ,world,scene,red);
    birdie[1] = new Bird(2,4,0.27f,&timer,QPixmap(":/blue.png").scaled(height()/9.0,height()/9.0)  ,world,scene,blue);
    birdie[2] = new Bird(3,4,0.27f,&timer,QPixmap(":/yellow.png").scaled(height()/9.0,height()/9.0),world,scene,yellow);
    birdie[3] = new Bird(4,4,0.27f,&timer,QPixmap(":/black.png").scaled(height()/9.0,height()/9.0) ,world,scene,black);
    birdie[7] = new Bird(25,4,0.27f,&timer,QPixmap(":/pig.png").scaled(height()/9.0,height()/9.0) ,world,scene,pig);
    avaliable[7]=true;
    shootpos->setX(150);
    shootpos->setY(200);

    birdie[0]->SetPosion(shootpos);
    birdie[0]->g_body->SetAwake(false);

    // Setting the Velocity
    for (int i=0;i<4;i++){
        avaliable[i]=true;
        shooted  [i]=false;
        birdie[i]->setLinearVelocity(b2Vec2(0,0));
        itemList.push_back(birdie[i]);
    }
    for(int i=4;i<7;i++)avaliable[i]=false;


    // Timer
    connect(&timer,SIGNAL(timeout()),this,SLOT(tick()));
    connect(&sleep,SIGNAL(timeout()),this,SLOT(Ready()));
    connect(this,SIGNAL(quitGame()),this,SLOT(QUITSLOT()));
    connect(ui->QuiButton,SIGNAL(released()),this,SLOT(QUITSLOT()));
    connect(ui->RetryButton,SIGNAL(released()),this,SLOT(Retry()));
    timer.start(100/6);

}
	PacketPtr demuxPacket()
	{
		PacketPtr packet = Packet::Create();

		do{
			// Read frames until we get a frame from the video or audio stream
			int ret = 0;
			if((ret = av_read_frame(pFormatCtx, &packet->avPacket)) < 0){
				Retry("av_read_frame failed in demuxPacket");
			}
		} while(packet->avPacket.stream_index != videoStream && packet->avPacket.stream_index != audioStream);

		return packet;
	}
Beispiel #9
0
void MediumModeWindow::correct()
{
    _chronometre->stop();
    delete _chronometre;
    _chronometre = NULL;

    unsigned short int rep[10];
    for(int i = 0; i < 10; ++i)
        rep[i] = _reponses[i]->text().toInt();

    Correction test(_mode, _multiple, _array, rep, _secondes);

    bool isGood[10];
    QString texte[10];

    _note = test.getCorrection(texte, isGood);

    CustomMessageBox results(_secondes, _note, this);

    _secondes = 0;

    _corriger->setText(tr("Retenter"));
    disconnect(_corriger, SIGNAL(clicked()), this, SLOT(correct()));
    connect(_corriger, SIGNAL(clicked()), this, SLOT(Retry()));

    for(int i = 0; i < 10; ++i)
    {
        _reponses[i]->setVisible(false);

        _labelCorrection[i]->setText(texte[i]);
        _labelCorrection[i]->move(200, (80 + (i * 40)));
        _labelCorrection[i]->setVisible(true);

        if(isGood[i])
        {
            _trueFalseLabel[0][i]->setPixmap(QPixmap(":/image/Right.png"));
            _trueFalseLabel[1][i]->setPixmap(QPixmap(":/image/OpacWrong.png"));
        }
        else
        {
            _trueFalseLabel[0][i]->setPixmap(QPixmap(":/image/OpacRight.png"));
            _trueFalseLabel[1][i]->setPixmap(QPixmap(":/image/Wrong.png"));
        }
        this->repaint();
    }

    results.exec();
}
Beispiel #10
0
HTTPRequest::HTTPRequest(
	HTTPConnection *	inConnection,
	const char *		inURL,
	bool				inIsPost,
	const FieldMap&		inExtraFields,
	const char *		inContentBuffer,
	int					inContentBufferLength,
	const char *		inDestFile)
{
	mConnection = NULL;
	mGotWholeHeader = false;
	mResponseNum = status_Pending;
	mDestFile = NULL;
	mDestFileName = inDestFile ? inDestFile : "";
	mIncomingLength = -1;
	mReceivedPayload = 0;

	string	request;

	if (inIsPost)
		request = "POST ";
	else
		request = "GET ";
	request += inURL;
	request += " HTTP/1.1\r\n";
	for (FieldMap::const_iterator iter = inExtraFields.begin();
		iter != inExtraFields.end(); ++iter)
	{
		request += iter->first;
		request += ": ";
		request += iter->second;
		request += "\r\n";
	}
	if (inContentBuffer)
	{
		char	buf[256];
		sprintf(buf, "Content-Length: %d\r\n", inContentBufferLength);
		request += buf;
	}
	request += "\r\n";

	mRequest.insert(mRequest.end(),request.begin(),request.end());
	if (inContentBuffer) mRequest.insert(mRequest.end(),inContentBuffer,inContentBuffer+inContentBufferLength);

	if (inConnection)
		Retry(inConnection);
}
Beispiel #11
0
void MediumModeWindow::Retry()
{
    _corriger->setText(tr("Corriger"));
    disconnect(_corriger, SIGNAL(clicked()), this, SLOT(Retry()));
    connect(_corriger, SIGNAL(clicked()), this, SLOT(correct()));

    for(int i = 0; i < 10; ++i)
    {
        _labelCorrection[i]->setVisible(false);
        _reponses[i]->clear();
        _reponses[i]->setVisible(true);

        _trueFalseLabel[0][i]->setPixmap(QPixmap(":/image/OpacRight.png"));
        _trueFalseLabel[1][i]->setPixmap(QPixmap(":/image/OpacWrong.png"));
    }

    _reponses[0]->setFocus();

    _minute->setText("00");
    _seconde->setText("00");
    startTime();
}
void CLogIteratorBase::Advance (revision_t last)
{
    // maybe, there was some cache update

    HandleCacheUpdates();

    // end of history?

    if (revision >= last)
    {
        // the current revision may be a copy / rename
        // -> update our path before we proceed, if necessary

        if (HandleCopyAndDelete())
        {
            // revision may have been set to NO_REVISION,
            // e.g. if a deletion has been found

            if (revision != NO_REVISION)
            {
                // switched to a new path
                // -> retry access on that new path
                // (especially, we must try (copy-from-) revision)

                Retry();
            }
        }
        else
        {
            // find next entry that mentions the path
            // stop @ revision 0 or missing log data

            InternalAdvance (last);
        }
    }
}
Beispiel #13
0
void GameInfoViewer::RetryButtonClicked()
{
    emit Retry();
}
int main(){
	int i;
	int play;
	int anser[4];
	char input[6];
	int hit = 0, blow = 0;

	do{
		srand ((unsigned) time (NULL));

		printf("\n------------- Hit and Blow -------------\n\n");

		make4number(&anser[0]);

		for(play = 0 ; play < 10 ; ++play){
			int Flag = 0;

			printf("%d", play + 1);
			switch(play){
				case 0:
					printf("st "); break;
				case 1:
				case 2:
					printf("nd "); break;
				default:
					printf("th ");
			}
			printf("try.\n");

			do{
				printf("Number:");
				input_str(&input[0], sizeof(input));
				if(0 == checknumber(input)){
					Flag = 1;
				}else if (1 == checknumber(input)){
					printf("Error : number of digits is not correct.\n");
				}else if(2 == checknumber(input)){
					printf("Error: contains non-numeric.\n");
				}else if (3 == checknumber(input)){
					printf("Error: contains the same number.\n");
				}
			}while (Flag == 0);
			judgeHB(anser, input, &hit, &blow);
			if(4 == hit){
				printf("congratulations!\nIt is a success in the %d", play);
				switch(play){
					case 1:
						printf("st."); break;
					case 2:
					case 3:
						printf("nd."); break;
					default:
						printf("th.");
				}
				break;
			}else{
				printHB(hit, blow);
			}
			hit = 0;
			blow = 0;
		}
		if (play == 10){
			printf("That's too bad.\n");
		for(i = 0 ; i < 4 ; ++i){
			printf("%d", anser[i]);
		}
		}
		puts ("");
	}while(0 ==Retry());
	return 0;
}