Exemplo n.º 1
0
void
MediaSourceReader::MaybeNotifyHaveData()
{
  ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
  bool haveAudio = false, haveVideo = false;
  bool ended = IsEnded();
  // If we are in ended mode, we will resolve any pending wait promises.
  // The next Request*Data will handle END_OF_STREAM or going back into waiting
  // mode.
  if (!IsSeeking() && mAudioTrack) {
    if (!mLastAudioTime) {
      nsRefPtr<SourceBufferDecoder> d = FirstDecoder(MediaData::AUDIO_DATA);
      haveAudio = !!d;
    } else {
      haveAudio = HaveData(mLastAudioTime, MediaData::AUDIO_DATA);
    }
    if (ended || haveAudio) {
      WaitPromise(MediaData::AUDIO_DATA).ResolveIfExists(MediaData::AUDIO_DATA, __func__);
    }
  }
  if (!IsSeeking() && mVideoTrack) {
    if (!mLastVideoTime) {
      nsRefPtr<SourceBufferDecoder> d = FirstDecoder(MediaData::VIDEO_DATA);
      haveVideo = !!d;
    } else {
      haveVideo = HaveData(mLastVideoTime, MediaData::VIDEO_DATA);
    }
    if (ended || haveVideo) {
      WaitPromise(MediaData::VIDEO_DATA).ResolveIfExists(MediaData::VIDEO_DATA, __func__);
    }
  }
  MSE_DEBUG("isSeeking=%d haveAudio=%d, haveVideo=%d ended=%d",
            IsSeeking(), haveAudio, haveVideo, ended);
}
void
MediaSourceReader::MaybeNotifyHaveData()
{
  ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
  bool haveAudio = false, haveVideo = false;
  if (!mAudioIsSeeking && mAudioTrack && HaveData(mLastAudioTime, MediaData::AUDIO_DATA)) {
    haveAudio = true;
    WaitPromise(MediaData::AUDIO_DATA).ResolveIfExists(MediaData::AUDIO_DATA, __func__);
  }
  if (!mVideoIsSeeking && mVideoTrack && HaveData(mLastVideoTime, MediaData::VIDEO_DATA)) {
    haveVideo = true;
    WaitPromise(MediaData::VIDEO_DATA).ResolveIfExists(MediaData::VIDEO_DATA, __func__);
  }
  MSE_DEBUG("MediaSourceReader(%p)::MaybeNotifyHaveData haveAudio=%d, haveVideo=%d", this,
            haveAudio, haveVideo);
}
Exemplo n.º 3
0
///////////////////////////////////////////////////////////////////////////////
///@author      Ghervase Gabriel
///@brief       Tells the length of the full message that can be read
///@param       [in]p_nMiliSec - How much to wait for data before abandoning the operation
///@retval      0  if no data or error
///@retval      >0 len of data that can be read
///////////////////////////////////////////////////////////////////////////////
int CFragmentedUSBLink::GetMsgLen(unsigned int p_nMiliSec/* = 10*/)
{
	if (HaveData(p_nMiliSec))
	{	return m_nBytesReceivedSoFar;
	}

	return 0;
}
Exemplo n.º 4
0
///////////////////////////////////////////////////////////////////////////////
///@author      Ghervase Gabriel
///@brief       Reads fragments from the USB device and reconstructs the final message from the fragments
///@param       [out]p_pData - Buffer to store output data
///@param       [in]p_nLegth - Size of the output buffer
///@param       [in]p_nMiliSec - How much to wait for data before abandoning the read operation
///@retval      size of the data written in the output buffer or < 0 for error
///////////////////////////////////////////////////////////////////////////////
int CFragmentedUSBLink::ReadBulk(unsigned char* p_pData, uint32_t p_nLegth, unsigned int p_nMiliSec/* = 10*/)
{
	int retval = 0;

	if ( HaveData(p_nMiliSec) )
	{
		retval = m_nBytesReceivedSoFar;
		if (p_nLegth < m_nBytesReceivedSoFar)
		{
			NLOG_ERR("[CFragmentedUSBLink][ReadBulk] Output Buffer too small; is %d and we need %d - Discard existing fragments",
				(int)p_nLegth, (int)(m_nBytesReceivedSoFar));
			retval = -1;
		}
		else
		{	memcpy(p_pData, m_pu8ReadBuf, m_nBytesReceivedSoFar);
		}

		dropExistingReadData();
	}

	return retval;
}
Exemplo n.º 5
0
        OdbcExpected<bool> SqlLexer::Shift()
        {
            if (IsEod())
            {
                SetEod();

                return false;
            }

            TokenType::Type tokenType = TokenType::EOD;

            while (!IsEod())
            {
                int32_t tokenBegin = pos;

                switch (sql[pos])
                {
                    case '-':
                    {
                        // Full-line comment.
                        if (HaveData(1) && sql[pos + 1] == '-')
                        {
                            pos += 2;

                            while (!IsEod() && sql[pos] != '\n' && sql[pos] != '\r')
                                ++pos;

                            continue;
                        }

                        // Minus.
                        tokenType = TokenType::MINUS;

                        break;
                    }

                    case '"':
                    {
                        // Quoted string.
                        while (true)
                        {
                            ++pos;

                            if (IsEod())
                                return OdbcError(SqlState::SHY000_GENERAL_ERROR, "Unclosed quoted identifier.");

                            if (sql[pos] == '"')
                            {
                                if (!HaveData(2) || sql[pos + 1] != '"')
                                    break;

                                ++pos;
                            }
                        }

                        tokenType = TokenType::QUOTED;

                        break;
                    }

                    case '\'':
                    {
                        // String literal.
                        while (true)
                        {
                            ++pos;

                            if (IsEod())
                                return OdbcError(SqlState::SHY000_GENERAL_ERROR, "Unclosed string literal.");

                            if (sql[pos] == '\'')
                            {
                                if (!HaveData(2) || sql[pos + 1] != '\'')
                                    break;

                                ++pos;
                            }
                        }

                        tokenType = TokenType::STRING;

                        break;
                    }

                    case '.':
                    {
                        tokenType = TokenType::DOT;

                        break;
                    }

                    case ',':
                    {
                        tokenType = TokenType::COMMA;

                        break;
                    }

                    case ';':
                    {
                        tokenType = TokenType::SEMICOLON;

                        break;
                    }

                    case '(':
                    {
                        tokenType = TokenType::PARENTHESIS_LEFT;

                        break;
                    }

                    case ')':
                    {
                        tokenType = TokenType::PARENTHESIS_RIGHT;

                        break;
                    }

                    default:
                    {
                        // Skipping spaces.
                        if (iscntrl(sql[pos]) || isspace(sql[pos]))
                        {
                            do
                            {
                                ++pos;
                            }
                            while (!IsEod() && (iscntrl(sql[pos]) || isspace(sql[pos])));

                            continue;
                        }

                        // Word.
                        while (!IsEod() && !IsDelimiter(sql[pos]))
                            ++pos;

                        --pos;

                        tokenType = TokenType::WORD;

                        break;
                    }
                }

                ++pos;

                if (tokenType != TokenType::EOD)
                {
                    currentToken = SqlToken(&sql[tokenBegin], pos - tokenBegin, tokenType);

                    return true;
                }
            }

            SetEod();

            return false;
        }