Esempio n. 1
0
void DriverAlsa::Pimpl::Write(const Brx& aData)
{
    int err;

    err = snd_pcm_writei(iHandle, aData.Ptr(), aData.Bytes() / iSampleBytes);

    // Handle underrun errors.
    if(err == -EPIPE) {
        err = snd_pcm_prepare(iHandle);

        if (err < 0)
        {
            Log::Print("DriverAlsa: failed to snd_pcm_recover with %s\n",
                       snd_strerror(err));
            ASSERTS();
        }

        err = snd_pcm_writei(iHandle,
                             aData.Ptr(),
                             aData.Bytes() / iSampleBytes);
    }


    if (err < 0)
    {
        Log::Print("DriverAlsa: snd_pcm_writei() got error %s\n",
                   snd_strerror(err));
    }
    else
    {
        iBytesSent += aData.Bytes();
    }
}
Esempio n. 2
0
TInt Log::PrintHex(FunctorMsg& aOutput, const Brx& aBrx)
{
    Bws<kMaxPrintBytes+1> buf(kMaxPrintBytes+1);
    TUint split = aBrx.Bytes()/128;
    for(TUint k=0; k<split; k++) {
        TUint i=0;
        TUint j=0;
        for(i=0; i<128; i++) {
            buf[j++] = hexChar( (aBrx[i+(k*128)]&0xF0)>>4 );
            buf[j++] = hexChar( (aBrx[i+(k*128)]&0x0F) );
        }
        buf.SetBytes(j);
        buf.PtrZ();
        DoPrint(aOutput, buf.Ptr());
    }
    TUint rem = aBrx.Bytes()%128;
    buf.SetBytes(rem*2);
    TUint i=0;
    TUint j=0;
    for(i=0; i<(rem); i++) {
        buf[j++] = hexChar( (aBrx[i+(split*128)]&0xF0)>>4 );
        buf[j++] = hexChar( (aBrx[i+(split*128)]&0x0F) );
    }
    buf.PtrZ();
    return DoPrint(aOutput, buf.Ptr());
}
Esempio n. 3
0
TUint HeaderAcceptLanguage::ParseQualityValue(const Brx& aBuf)
{
    if (aBuf.Bytes() == 0) {
        return kMaxQuality;
    }
    if (aBuf[0] == '1') {
        return kMaxQuality;
    }
    else if (aBuf[0] != '0') {
        // invalid value, ignore it
        return kMinQuality;
    }
    if (aBuf.Bytes() < 3 || aBuf[1] != '.' || aBuf.Bytes() > kMaxQualityChars) {
        // invalid value, ignore it
        return kMinQuality;
    }

    TUint quality = kMinQuality;
    TUint i;
    for (i=2; i<aBuf.Bytes(); i++) {
        if (!Ascii::IsDigit(aBuf[i])) {
            return 0;
        }
        quality = (quality * 10) + aBuf[i] - '0';
    }
    for (; i<kMaxQualityChars; i++) {
        quality *= 10;
    }
    return quality;
}
Esempio n. 4
0
void OutputProcessorDv::ProcessBinary(const Brx& aBuffer, Brh& aVal)
{
    Bwh tmp(aBuffer.Bytes());
    if (aBuffer.Bytes() > 0) {
        tmp.Append(aBuffer);
    }
    tmp.TransferTo(aVal);
}
Esempio n. 5
0
Brn WriterRingBuffer::Tail(const Brx& aBuffer, TUint aMaxBytes)
{
    const TUint bytes = aBuffer.Bytes();

    if (bytes <= aMaxBytes)
        return Brn(aBuffer);
    else
        return aBuffer.Split(bytes - aMaxBytes, aMaxBytes);
}
Esempio n. 6
0
void DviProtocolUpnpServiceXmlWriter::GetRelatedVariableName(Bwh& aName, const Brx& aActionName, const Brx& aParameterName)
{
    static const Brn prefix("A_ARG_TYPE_");
    const TUint len = prefix.Bytes() + aActionName.Bytes() + 1 + aParameterName.Bytes();
    aName.Grow(len);
    aName.Append(prefix);
    aName.Append(aActionName);
    aName.Append('_');
    aName.Append(aParameterName);
}
Esempio n. 7
0
void CpTopology2Group::UpdateName(const Brx& aValue)
{
    if (aValue.Bytes() > iName.MaxBytes())
    {
        iName.Replace(aValue.Ptr(), iName.MaxBytes());
    }
    else
    {
        iName.Replace(aValue);
    }
}
Esempio n. 8
0
void CpTopology2Group::UpdateRoom(const Brx& aValue)
{
    if (aValue.Bytes() > iRoom.MaxBytes())
    {
        iRoom.Replace(aValue.Ptr(), iRoom.MaxBytes());
    }
    else
    {
        iRoom.Replace(aValue);
    }
}
Esempio n. 9
0
TBool Brx::BeginsWith(const Brx& aBrx) const
{
    if(Bytes() >= aBrx.Bytes()) {
        const TByte* ptr1 = Ptr();
        ASSERT(ptr1 != NULL);
        const TByte* ptr2 = aBrx.Ptr();
        ASSERT(ptr2 != NULL);
        return(memcmp(ptr1, ptr2, aBrx.Bytes()) == 0);
    }
    return false;
}
Esempio n. 10
0
TBool Brx::Equals(const Brx& aBrx) const
{
    if(Bytes() == aBrx.Bytes()) {
        const TByte* dest = Ptr();
        ASSERT(dest != NULL);
        const TByte* src = aBrx.Ptr();
        ASSERT(src != NULL);
        return(memcmp(dest, src, Bytes()) == 0);
    }
    return false;
}
Esempio n. 11
0
void FileAnsii::Write(const Brx& aBuffer, TUint32 aBytes)
{
    // IFile implementations must check write length
    ASSERT(aBytes);
    // Check we have enough bytes
    ASSERT(aBuffer.Bytes() >= aBytes);
    // Do the write
    TUint bytesWritten = (TUint)fwrite(aBuffer.Ptr(), 1, aBytes, iFilePtr);
    // throw if entire write was not performed
    if ( bytesWritten != aBytes )
        THROW(FileWriteError);
}
Esempio n. 12
0
TBool Ascii::CaseInsensitiveEquals(const Brx& aBuffer1, const Brx& aBuffer2)
{
    TUint bytes = aBuffer1.Bytes();
    if(aBuffer2.Bytes() != bytes) {
        return (false);
    }
    for (TUint i = 0; i < bytes; i++) {
        if (!CaseInsensitiveEquals(aBuffer1[i], aBuffer2[i])) {
            return (false);
        }
    }
    return (true);
}
Esempio n. 13
0
TUint32 OpenHome::Os::NetworkGetHostByName(const Brx& aAddress)
{
    TUint32 addr;
    const TInt len = aAddress.Bytes();
    char* name = new char[len+1];
    (void)memcpy(name, aAddress.Ptr(), len);
    name[len] = '\0';
    int32_t ret = OsNetworkGetHostByName(name, &addr);
    delete[] name;
    if (ret == -1) {
        THROW(NetworkError);
    }
    return addr;
}
Esempio n. 14
0
void CpTopology2Source::Update(const Brx& aName, const Brx& aType, TBool aVisible)
{
    if (aName.Bytes() > iName.MaxBytes())
    {
        iName.Replace(aName.Ptr(), iName.MaxBytes());
    }
    else
    {
        iName.Replace(aName);
    }

    iType.Replace(aType);
    iVisible = aVisible;
}
Esempio n. 15
0
void PcmProcessorLe32::ProcessFragment24(const Brx& aData, TUint aNumChannels)
{
    TByte *nData;
    TUint  bytes;

    // 24 bit audio is not supported on the platform so it is converted
    // to signed 32 bit audio for playback.
    //
    // Accordingly we allocate room for 4 byte samples.
    bytes = (aData.Bytes() * 4) / 3;

    // If we are manually converting mono to stereo the data will double.
    if (iDuplicateChannel)
    {
        bytes *= 2;
    }

    nData = new TByte[bytes];
    ASSERT(nData != NULL);

    TByte *ptr  = (TByte *)(aData.Ptr() + 0);
    TByte *ptr1 = (TByte *)nData;
    TByte *endp = ptr1 + bytes;

    ASSERT(bytes % 2 == 0);

    while (ptr1 < endp)
    {
        // Store the data in little endian format.
        *ptr1++ = 0;
        *ptr1++ = *(ptr+2);
        *ptr1++ = *(ptr+1);
        *ptr1++ = *(ptr+0);

        if (iDuplicateChannel)
        {
            *ptr1++ = 0;
            *ptr1++ = *(ptr+2);
            *ptr1++ = *(ptr+1);
            *ptr1++ = *(ptr+0);
        }

        ptr += 3;
    }

    Brn fragment(nData, bytes);
    Flush();
    iSink.Write(fragment);
    delete[] nData;
}
Esempio n. 16
0
void ProviderTestBasic::WriteFile(IDvInvocation& aInvocation, const Brx& aData, const Brx& aFileFullName)
{
    TUint len = aFileFullName.Bytes();
    char* name = (char*)malloc(len+1);
    (void)memcpy(name, aFileFullName.Ptr(), aFileFullName.Bytes());
    name[len] = 0;
    FILE* fp = fopen(name, "wb");
    free(name);
    (void)fwrite(aData.Ptr(), aData.Bytes(), 1, fp);
    (void)fflush(fp);
    (void)fclose(fp);
    aInvocation.StartResponse();
    aInvocation.EndResponse();
}
Esempio n. 17
0
void Bwx::ReplaceThrow(const Brx& aBuf)
{
    if (aBuf.Bytes() > MaxBytes()) {
        THROW(BufferOverflow);
    }
    else
    {
        const TByte* dest = Ptr();
        ASSERT(dest != NULL);
        const TByte* src = aBuf.Ptr();
        ASSERT(src != NULL);
        (void)memmove(const_cast<TByte*>(dest), src, aBuf.Bytes());
        iBytes = aBuf.Bytes();
    }
}
Esempio n. 18
0
void OhmSenderDriverWindows::Resend(const Brx& aFrames)
{
    KSPROPERTY prop;
				
	prop.Set = OHSOUNDCARD_GUID;
    prop.Id = KSPROPERTY_OHSOUNDCARD_RESEND;
    prop.Flags = KSPROPERTY_TYPE_SET;

    DWORD returned;

	LPVOID ptr = (LPVOID) aFrames.Ptr();
	DWORD bytes = aFrames.Bytes();

    DeviceIoControl(iHandle, IOCTL_KS_PROPERTY, &prop, sizeof(KSPROPERTY), ptr, bytes, &returned, 0);
}
Esempio n. 19
0
TBool BufferCmp::operator()(const Brx& aStr1, const Brx& aStr2) const
{
    const TInt bytes1 = aStr1.Bytes();
    const TInt bytes2 = aStr2.Bytes();
    const TInt bytes = (bytes1<bytes2? bytes1 : bytes2);
    const TByte* ptr1 = aStr1.Ptr();
    const TByte* ptr2 = aStr2.Ptr();
    for (TInt i=0; i<bytes; i++) {
        if (*ptr1 != *ptr2) {
            return (*ptr1 < *ptr2);
        }
        ptr1++;
        ptr2++;
    }
    return (bytes1 < bytes2);
}
Esempio n. 20
0
void WriterShellResponse::Write(const Brx& aBuffer)
{
    const TUint bytes = aBuffer.Bytes();
    for (TUint i=0; i<bytes; i++) {
        Write(aBuffer[i]);
    }
    WriteFlush();
}
Esempio n. 21
0
TInt Log::Print(FunctorMsg& aOutput, const Brx& aMessage)
{
    TUint remaining = aMessage.Bytes();
    TInt ret = 0;
    const TByte* ptr = aMessage.Ptr();
    while (remaining > 0) {
        TInt len = (remaining<kMaxPrintBytes? remaining : kMaxPrintBytes);
        remaining -= len;
        TChar temp[kMaxPrintBytes+1];
        Bwn msg(temp, len, kMaxPrintBytes+1);
        msg.Replace(ptr, len);
        msg.PtrZ();
        ret += DoPrint(aOutput, msg.Ptr());
        ptr += len;
    }
    return ret;
}
Esempio n. 22
0
const Brn CommandTokens::GetNextToken(const Brx& aValue, TUint& aIndex)
{
   const TByte* start = aValue.Ptr() + aIndex;
   TUint bytes = aValue.Bytes();
   ASSERT(aIndex <= bytes)

   for (;;)
   {
      if (aIndex == bytes)
      {
         return (Brn(start, 0));
      }

      if (*start != ' ')
      {
         break;
      }

      aIndex++;
      start++;
   }

   const TByte* ptr = start;
   aIndex++;
   ptr++;
   TUint count = 1;

   for (;;)
   {
      if (aIndex == bytes)
      {
         break;
      }

      if (*ptr == ' ')
      {
         break;
      }

      aIndex++;
      ptr++;
      count++;
   }

   return (Brn(start, count));
}
Esempio n. 23
0
void PcmProcessorLe::ProcessFragment8(const Brx& aData, TUint aNumChannels)
{
    TByte *nData;
    TUint  bytes;

    // The input data is converted from unsigned 8 bit to signed 16 bit.
    // to removes poor audio quality and glitches when part of a playlist
    // with tracks of a different bit depth.
    //
    // Accordingly the amount of data is doubled.
    bytes = aData.Bytes() * 2;

    // If we are manually converting mono to stereo the data will double.
    if (iDuplicateChannel)
    {
        bytes *= 2;
    }

    nData = new TByte[bytes];
    ASSERT(nData != NULL);

    TByte *ptr  = (TByte *)(aData.Ptr() + 0);
    TByte *ptr1 = (TByte *)nData;
    TByte *endp = ptr1 + bytes;

    while (ptr1 < endp)
    {
        // Convert U8 to S16 data in little endian format.
        *ptr1++ = 0x00;
        *ptr1++ = *ptr - 0x80;

        if (iDuplicateChannel)
        {
            *ptr1++ = 0x00;
            *ptr1++ = *ptr - 0x80;
        }

        ptr++;
    }

    Brn fragment(nData, bytes);
    Flush();
    iSink.Write(fragment);
    delete[] nData;
}
Esempio n. 24
0
void OutputProcessorDv::ProcessString(const Brx& aBuffer, Brhz& aVal)
{
    TUint bytes = aBuffer.Bytes();
    Bwh tmp(bytes + 1);
    tmp.Append(aBuffer);
    tmp.Append((TByte)0);
    tmp.SetBytes(bytes);
    tmp.TransferTo(aVal);
}
Esempio n. 25
0
void DeviceBasic::WriteResource(const Brx& aUriTail, TIpAddress /*aInterface*/, std::vector<char*>& /*aLanguageList*/, IResourceWriter& aResourceWriter)
{
    const Brn kIndexFile("index.html");
    Bwh filePath(iConfigDir);
    Brn file;
    if (aUriTail.Bytes() == 0) {
        file.Set(kIndexFile);
    }
    else {
        file.Set(aUriTail);
    }
    const TByte sep =
#ifdef _WIN32
                      '\\';
#else
                      '/';
#endif
    filePath.Grow(filePath.Bytes() + 1 + file.Bytes()+1);
    filePath.Append(sep);
    filePath.Append(file);
    filePath.PtrZ();

    const char* path = (const char*)filePath.Ptr();
    FILE* fd = fopen(path, "rb");
    if (fd == NULL) {
        return;
    }
    static const TUint kMaxReadSize = 4096;
    struct stat fileStats;
    (void)stat(path, &fileStats);
    TUint bytes = (TUint)fileStats.st_size;
    const char* mime = NULL;
    for (TUint i=filePath.Bytes()-1; i>0; i--) {
        if (filePath[i] == '/' || filePath[i] == '\\') {
            break;
        }    
        if (filePath[i] == '.') {
            const char* ext = (const char*)filePath.Split(i+1, filePath.Bytes()-i-1).Ptr();
            if (strcmp(ext, "html") == 0 || strcmp(ext, "htm") == 0) {
                mime = kOhNetMimeTypeHtml;
            }
            break;
        }
    }
    aResourceWriter.WriteResourceBegin(bytes, mime);
    do {
        TByte buf[kMaxReadSize];
        TUint size = (bytes<kMaxReadSize? bytes : kMaxReadSize);
        size_t records_read = fread(buf, size, 1, fd);
        ASSERT(records_read == 1);
        aResourceWriter.WriteResource(buf, size);
        bytes -= size;
    } while (bytes > 0);
    aResourceWriter.WriteResourceEnd();
    (void)fclose(fd);
}
Esempio n. 26
0
void Swx::Write(const Brx& aBuffer)
{
    TByte* ptr = Ptr();
    TUint bytes = aBuffer.Bytes();
    if (iBytes + bytes > iMaxBytes) { // would overflow, drain the buffer
        WriteDrain();
        if (bytes > iMaxBytes) { // would still overflow
            try {
                iWriter.Write(aBuffer); // pass it on
                return;
            }
            catch (WriterError&) {
                Error();
            }
        }
    }
    memcpy(ptr + iBytes, aBuffer.Ptr(), bytes);
    iBytes += bytes;
}
Esempio n. 27
0
void PcmProcessorLe::ProcessFragment16(const Brx& aData, TUint aNumChannels)
{
    TByte *nData;
    TUint  bytes;

    bytes = aData.Bytes();

    // If we are manually converting mono to stereo the data will double.
    if (iDuplicateChannel)
    {
        bytes *= 2;
    }

    nData = new TByte[bytes];
    ASSERT(nData != NULL);

    TByte *ptr  = (TByte *)(aData.Ptr() + 0);
    TByte *ptr1 = (TByte *)nData;
    TByte *endp = ptr1 + bytes;

    ASSERT(bytes % 2 == 0);

    while (ptr1 < endp)
    {
        // Store the S16 data in little endian format.
        *ptr1++ = *(ptr+1);
        *ptr1++ = *(ptr);

        if (iDuplicateChannel)
        {
            *ptr1++ = *(ptr+1);
            *ptr1++ = *(ptr);
        }

        ptr +=2;
    }

    Brn fragment(nData, bytes);
    Flush();
    iSink.Write(fragment);
    delete[] nData;
}
Esempio n. 28
0
void WriterBwh::Write(const Brx& aBuffer)
{
    TInt maxBytes = iBuf.MaxBytes();
    TInt reqMaxBytes = iBuf.Bytes() + aBuffer.Bytes();
    if (reqMaxBytes > maxBytes) {
        do {
            maxBytes += iGranularity;
        } while (reqMaxBytes > maxBytes);
        iBuf.Grow(maxBytes);
    }
    iBuf.Append(aBuffer);
}
Esempio n. 29
0
ArgumentBinary::ArgumentBinary(const OpenHome::Net::Parameter& aParameter, const Brx& aValue)
    : Argument(aParameter)
{
    try {
        aParameter.ValidateBinary(aValue);
        if (aValue.Bytes() > 0) {
            iValue.Set(aValue);
        }
    }
    catch (ParameterValidationError&) {
        ValidationFailed(aParameter);
    }
}
Esempio n. 30
0
void WriterHttpChunked::Write(const Brx& aBuffer)
{
    if (iChunked) {
        Bws<16> count;
        Ascii::AppendHex(count, aBuffer.Bytes());
        iBuffer.Write(count);
        iBuffer.Write(Http::kHeaderTerminator);
        iBuffer.Write(aBuffer);
        iBuffer.Write(Http::kHeaderTerminator);
    }
    else {
        iBuffer.Write(aBuffer);
    }
}