void BaseVideoPlayer::flush()
{


	doFlush_requested = true;
	lock();
	lockDecoder();
	doFlush_requested = false;
	doFlush = true;
	while (!packets.empty())
	{
		OMXPacket *pkt = packets.front();
		packets.pop_front();
		OMXReader::freePacket(pkt);

	}

	currentPTS = DVD_NOPTS_VALUE;
	cachedSize = 0;

	if(decoder)
	{
		decoder->Reset();
	}

	unlockDecoder();
	unlock();
}
void OMXAudioPlayer::process()
{
    OMXPacket* omxPacket = NULL;

    while(!doStop && !doAbort)
    {
        lock();
        if(packets.empty())
        {
            pthread_cond_wait(&m_packet_cond, &m_lock);
        }
        unlock();

        if(doAbort)
        {
            break;
        }

        lock();
        if(doFlush && omxPacket)
        {
            OMXReader::freePacket(omxPacket);
            omxPacket = NULL;
            doFlush = false;
        }
        else if(!omxPacket && !packets.empty())
        {
            omxPacket = packets.front();
            cachedSize -= omxPacket->size;
            packets.pop_front();
        }
        unlock();

        lockDecoder();
        if(doFlush && omxPacket)
        {
            OMXReader::freePacket(omxPacket);
            omxPacket = NULL;
            doFlush = false;
        }
        else if(omxPacket && decode(omxPacket))
        {
            OMXReader::freePacket(omxPacket);
            omxPacket = NULL;
        }
        unlockDecoder();
    }

    if(omxPacket)
    {
        OMXReader::freePacket(omxPacket);
    }
}
void OMXAudioPlayer::flush()
{
    //ofLogVerbose(__func__) << "OMXAudioPlayer::Flush start";
    lock();
    lockDecoder();
    doFlush = true;
    while (!packets.empty())
    {
        OMXPacket *pkt = packets.front();
        packets.pop_front();
        OMXReader::freePacket(pkt);
    }
    currentPTS = DVD_NOPTS_VALUE;
    cachedSize = 0;
    if(decoder)
    {
        decoder->flush();
    }
    unlockDecoder();
    unlock();
    //ofLogVerbose(__func__) << "OMXAudioPlayer::Flush end";
}
void BaseVideoPlayer::process()
{
	OMXPacket *omxPacket = NULL;

	//m_pts was previously set to 0 - might need later...
	//currentPTS = 0;
	
	while(!doStop && !doAbort)
	{
		lock();
		if(packets.empty())
		{
			pthread_cond_wait(&m_packet_cond, &m_lock);
		}
		unlock();

		if(doAbort)
		{
			break;
		}

		lock();
		if(doFlush && omxPacket)
		{
			OMXReader::freePacket(omxPacket);
			omxPacket = NULL;
			doFlush = false;
		}
		else
		{
			if(!omxPacket && !packets.empty())
			{
				omxPacket = packets.front();
				cachedSize -= omxPacket->size;
                //ofLogNotice() << "omxPacket->pts: " << omxPacket->pts;
				packets.pop_front();
			}
		}
		unlock();

		lockDecoder();
		if(doFlush && omxPacket)
		{
			OMXReader::freePacket(omxPacket);
			omxPacket = NULL;
			doFlush = false;
		}
		else
		{
			if(omxPacket && decode(omxPacket))
			{
				
				OMXReader::freePacket(omxPacket);
				omxPacket = NULL;
			}
		}
		
		unlockDecoder();


	}
	
	if(omxPacket)
	{
		OMXReader::freePacket(omxPacket);
	}
}