bool InspectorPageAgent::dataContent(const char* data, unsigned size, const String& textEncodingName, bool withBase64Encode, String* result) { if (withBase64Encode) { *result = base64Encode(data, size); return true; } return decodeBuffer(data, size, textEncodingName, result); }
static std::string decodeReverseBuffer(buffer_type const & reve) { std::string rstring = decodeBuffer(reve); std::reverse(rstring.begin(),rstring.end()); for ( unsigned int i = 0; i < rstring.size(); ++i ) rstring[i] = ::libmaus::fastx::remapChar( ::libmaus::fastx::invertN(::libmaus::fastx::mapChar(rstring[i])) ); return rstring; }
bool InspectorPageAgent::cachedResourceContent(Resource* cachedResource, String* result, bool* base64Encoded) { bool hasZeroSize; bool prepared = prepareResourceBuffer(cachedResource, &hasZeroSize); if (!prepared) return false; *base64Encoded = !hasTextContent(cachedResource); if (*base64Encoded) { RefPtr<SharedBuffer> buffer = hasZeroSize ? SharedBuffer::create() : cachedResource->resourceBuffer(); if (!buffer) return false; *result = base64Encode(buffer->data(), buffer->size()); return true; } if (hasZeroSize) { *result = ""; return true; } if (cachedResource) { switch (cachedResource->type()) { case Resource::CSSStyleSheet: *result = toCSSStyleSheetResource(cachedResource)->sheetText(false); return true; case Resource::Script: *result = toScriptResource(cachedResource)->script(); return true; case Resource::MainResource: return false; case Resource::Raw: { SharedBuffer* buffer = cachedResource->resourceBuffer(); if (!buffer) return false; OwnPtr<TextResourceDecoder> decoder = createXHRTextDecoder(cachedResource->response().mimeType(), cachedResource->response().textEncodingName()); String content = decoder->decode(buffer->data(), buffer->size()); *result = content + decoder->flush(); return true; } default: SharedBuffer* buffer = cachedResource->resourceBuffer(); return decodeBuffer(buffer ? buffer->data() : 0, buffer ? buffer->size() : 0, cachedResource->response().textEncodingName(), result); } } return false; }
char* CStdCrypt::decodeString(const BYTE *pBuf, size_t bufLen, size_t *cbResultLen) { size_t resLen; char *result = (char*)decodeBuffer(pBuf, bufLen, &resLen); if (result) { if (result[resLen-1] != 0) { // smth went wrong mir_free(result); return NULL; } } if (cbResultLen) *cbResultLen = resLen; return result; }
void AnatomyOMXComponent::onQueueFilled(OMX_U32 portIndex) { List<BufferInfo *> &inQueue = getPortQueue(kInputPortIndex); List<BufferInfo *> &outQueue = getPortQueue(kOutputPortIndex); LOGD("onQueueFilled called"); while (!inQueue.empty() && !outQueue.empty()) { BufferInfo *inInfo = *inQueue.begin(); OMX_BUFFERHEADERTYPE *inHeader = inInfo->mHeader; BufferInfo *outInfo = *outQueue.begin(); OMX_BUFFERHEADERTYPE *outHeader = outInfo->mHeader; if (inHeader->nFlags & OMX_BUFFERFLAG_EOS) { inQueue.erase(inQueue.begin()); inInfo->mOwnedByUs = false; notifyEmptyBufferDone(inHeader); outHeader->nFilledLen = 0; outHeader->nFlags = OMX_BUFFERFLAG_EOS; outQueue.erase(outQueue.begin()); outInfo->mOwnedByUs = false; notifyFillBufferDone(outHeader); return; } OMX_U32 decoded_size; decodeBuffer(outHeader->pBuffer, inHeader->pBuffer, inHeader->nSize, &decoded_size); usleep(10000); outHeader->nSize = decoded_size; inQueue.erase(inQueue.begin()); inInfo->mOwnedByUs = false; inInfo = NULL; notifyEmptyBufferDone(inHeader); inHeader = NULL; outQueue.erase(outQueue.begin()); outInfo->mOwnedByUs = false; outInfo = NULL; notifyFillBufferDone(outHeader); outHeader = NULL; } }
/* ------------------------------------------------------------------------- */ int main(void) { unsigned int i; uchar calibrationValue; calibrationValue = eeprom_read_byte(0); /* calibration value from last time */ if(calibrationValue != 0xff) { OSCCAL = calibrationValue; } //odDebugInit(); //Production Test Routine - Turn on white LED. DDRB |= _BV(PB1); /* output for LED */ sbi(PORTB, PB1); for(i=0;i<20;i++) { /* 300 ms disconnect */ _delay_ms(15); } cbi(PORTB, PB1); //Initialize the USB Connection with the host computer. usbDeviceDisconnect(); for(i=0;i<20;i++){ /* 300 ms disconnect */ _delay_ms(15); } usbDeviceConnect(); wdt_enable(WDTO_1S); pinsInit(); interruptsInit(); timerInit(); usbInit(); //Initialize USB comm. sei(); for(;;) { /* main event loop */ wdt_reset(); usbPoll(); //Check to see if it's time to send a USB packet if (isRecBufBusy && nextDigit==NULL) { #ifndef DECODE if (rbcur>rbidx) isRecBufBusy = 0; else reportChar(rbuff[rbcur++], 1); #else uchar command; command = decodeBuffer(); if (0!=command) { if (command!=cmdPrev) { reportChar(pgm_read_byte(&lookupTable[command & 0b00111111]), 0); // 64 values maximum cmdPrev = command; cmdCounter = 1; } else if (++cmdCounter==3) { cmdCounter = 0; cmdPrev = 0; } } isRecBufBusy = 0; #endif } if(usbInterruptIsReady() && nextDigit!=NULL) { /* we can send another key */ buildReport(); //Get the next 'key press' to send to the host. usbSetInterrupt(reportBuffer, sizeof(reportBuffer)); if(*++nextDigit == 0xff) /* this was terminator character */ nextDigit = NULL; } } return 0; }
bool SoundBuffer::LoadVorbis(const std::string& file, std::vector<boost::uint8_t> buffer, bool strict) { VorbisInputBuffer buf; buf.data = &buffer[0]; buf.pos = 0; buf.size = buffer.size(); ov_callbacks vorbisCallbacks; vorbisCallbacks.read_func = VorbisRead; vorbisCallbacks.close_func = VorbisClose; vorbisCallbacks.seek_func = NULL; vorbisCallbacks.tell_func = NULL; OggVorbis_File oggStream; int result = 0; if ((result = ov_open_callbacks(&buf, &oggStream, NULL, 0, vorbisCallbacks)) < 0) { logOutput.Print("Could not open Ogg stream (reason: %s).", ErrorString(result).c_str()); return false; } vorbis_info* vorbisInfo = ov_info(&oggStream, -1); // vorbis_comment* vorbisComment = ov_comment(&oggStream, -1); ALenum format; if (vorbisInfo->channels == 1) { format = AL_FORMAT_MONO16; } else if (vorbisInfo->channels == 2) { format = AL_FORMAT_STEREO16; } else { if (strict) ErrorMessageBox("SoundBuffer::LoadVorbis (%s): invalid number of channels.", file, 0); else LogObject(LOG_SOUND) << "File " << file << ": invalid number of channels: " << vorbisInfo->channels; return false; } size_t pos = 0; std::vector<boost::uint8_t> decodeBuffer(512*1024); // 512kb read buffer int section = 0; long read = 0; do { if (4*pos > 3*decodeBuffer.size()) // enlarge buffer so ov_read has enough space decodeBuffer.resize(decodeBuffer.size()*2); read = ov_read(&oggStream, (char*)&decodeBuffer[pos], decodeBuffer.size() - pos, 0, 2, 1, §ion); switch(read) { case OV_HOLE: LogObject(LOG_SOUND) << file << ": garbage or corrupt page in stream (non-fatal)"; continue; // read next case OV_EBADLINK: LogObject(LOG_SOUND) << file << ": corrupted stream"; return false; // abort case OV_EINVAL: LogObject(LOG_SOUND) << file << ": corrupted headers"; return false; // abort default: break; // all good }; pos += read; } while (read > 0); // read == 0 indicated EOF, read < 0 is error AlGenBuffer(file, format, &decodeBuffer[0], pos, vorbisInfo->rate); return true; }
int GenericChannel::handleWrite(const unsigned char *message, unsigned int length) { #ifdef TEST *logofs << "handleWrite: Called for FD#" << fd_ << ".\n" << logofs_flush; #endif // // Create the buffer from which to // decode messages. // DecodeBuffer decodeBuffer(message, length); #if defined(TEST) || defined(INFO) || defined(FLUSH) *logofs << "handleWrite: Decoding messages for FD#" << fd_ << " with " << length << " bytes in the buffer.\n" << logofs_flush; #endif unsigned char *outputMessage; unsigned int outputLength; // // Tag message as generic data // in decompression. // unsigned char outputOpcode = X_NXInternalGenericData; for (;;) { decodeBuffer.decodeValue(outputLength, 32, 14); if (outputLength == 0) { break; } if (isCompressed() == 1) { if (writeBuffer_.getAvailable() < outputLength || (int) outputLength >= control -> TransportFlushBufferSize) { #ifdef DEBUG *logofs << "handleWrite: Using scratch buffer for " << "generic data with size " << outputLength << " and " << writeBuffer_.getLength() << " bytes in buffer.\n" << logofs_flush; #endif outputMessage = writeBuffer_.addScratchMessage(outputLength); } else { outputMessage = writeBuffer_.addMessage(outputLength); } const unsigned char *compressedData = NULL; unsigned int compressedDataSize = 0; int decompressed = handleDecompress(decodeBuffer, outputOpcode, 0, outputMessage, outputLength, compressedData, compressedDataSize); if (decompressed < 0) { return -1; } } else { #ifdef DEBUG *logofs << "handleWrite: Using scratch buffer for " << "generic data with size " << outputLength << " and " << writeBuffer_.getLength() << " bytes in buffer.\n" << logofs_flush; #endif writeBuffer_.addScratchMessage((unsigned char *) decodeBuffer.decodeMemory(outputLength), outputLength); } #if defined(TEST) || defined(OPCODES) *logofs << "handleWrite: Handled generic data for FD#" << fd_ << ". " << outputLength << " bytes out.\n" << logofs_flush; #endif handleFlush(flush_if_needed); } // // Write any remaining data to socket. // if (handleFlush(flush_if_any) < 0) { return -1; } return 1; }
/** * Decode the image from the memory buffer * \param buffer: memory buffer * \param size: size of buffer * \return true if is ok */ bool bufferImage::decodeBuffer(unsigned char * buffer, unsigned long size) { MemoryObj file(buffer,size); return decodeBuffer(&file); }