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);
}
Esempio n. 2
0
void QGstreamerPlayerControl::fifoReadyWrite(int socket)
{
    if (socket == m_fifoFd[1]) {
        m_fifoCanWrite = true;

        writeFifo();
    }
}
Esempio n. 3
0
int msgDispatch(void)
//This function runs in an application-independant task, and is woken up periodically
//by the isr, it's role is to process msgs sent by the isr and to put them into the 
//right devices fifos
{
	myDev * i;  
	fifo * j;
	//This previous two variables are used to search through all devices.
	char value[] = {0,0,0,0}; 			//Local storage for isr message
	short int sensorNb = 0;
	struct timespec timev;	//Used to store timestamp
	msg message;	
	for (;;)
	{
		if(msgQReceive(isrmq,value,4,WAIT_FOREVER)==ERROR)//get isr message
		{
			sleep(1);
			continue;
		}
		printf("message received!\n");
		memcpy(&sensorNb,value,2); 			//get sensor number
		memcpy(&(message.mdata),value+2,2);	//get sensor value and store it in message
		printf("sensor : %d, value : %d\n",sensorNb,message.mdata);
		semTake(semMAdmin,WAIT_FOREVER);
		printf("looking for devices...\n");
		//We can't afford to have an acces to the device linked list while we
		//are looking trough it
		
		/*N.B. : if msgQReceive or semTake goes wrong it means there is a serious
		 * issue. Either the obj has been deleted (i can't see why it would be), or
		 * somme other inprobable event has happened. We definitly can not ignore it
		 * as it would mean possible concurential acces to the device linked list
		 * if semTake fails, and, far worse, a infinite loop with nothing to stop the
		 * task if msgQReceive stops blocking. 
		 * That would basically mean a deadlock system since this task's priority is 1.
		 * However if we just killed the task we could as well uninstall the whole driver
		 * as it would become pretty useless, so we just make it sleep and hope it will
		 * work better next time... 
		 */
		for (i=first;i!=NULL;i=i->next)
		{//go through all installed devices
			if (i->devNumber == sensorNb)
			{//this is the logical device corresponding to the sender's id :
				semGive(semMAdmin);//From this point on, we'll only acces the data. 
				printf("found device : %s\n",i->devHdr.name);
				//dispatch message to all apps listening to this device :
				semTake(i->semMData,WAIT_FOREVER);
				for(j=i->firstFifo; j!=NULL; j=j->nextFifo)
				{
					semGive(i->semMData);
					message.mnb=j->count;
					j->count++;
					clock_gettime(CLOCK_REALTIME, &timev);
					message.mtimestamp=timev.tv_sec*(long)1000+timev.tv_nsec/(long)1000000;
					writeFifo(j,message);
					//We do not care whether the fifo is full or not,
					//as we can't really do anything from here if it is. 
					//Therefore there is no return code test.
					semTake(i->semMData,WAIT_FOREVER);
					printf("message written in fifo \n");
				}
				semGive(i->semMData);
				//There is only one logical device per sensor and we have found it,
				//it is then useless to keep on looping onto devices, let's exit isr.
				break;
			}
		}
		semGive(semMAdmin);
	}
	return 0; //just to avoid compiler warnings
}