void TextTrackLoader::processNewCueData(CachedResource* resource) { ASSERT(m_cachedCueData == resource); if (m_state == Failed || !resource->data()) return; SharedBuffer* buffer = resource->data(); if (m_parseOffset == buffer->size()) return; const char* data; unsigned length; if (!m_cueParser) { if (resource->response().mimeType() == "text/vtt") m_cueParser = WebVTTParser::create(this, m_scriptExecutionContext); else { // Don't proceed until we have enough data to check for the WebVTT magic identifier. unsigned identifierLength = WebVTTParser::fileIdentifierMaximumLength(); if (buffer->size() < identifierLength) return; Vector<char> identifier; unsigned offset = 0; while (offset < identifierLength && (length = buffer->getSomeData(data, offset))) { if (length > identifierLength) length = identifierLength; identifier.append(data, length); offset += length; } if (!WebVTTParser::hasRequiredFileIdentifier(identifier.data(), identifier.size())) { LOG(Media, "TextTrackLoader::didReceiveData - file \"%s\" does not have WebVTT magic header", resource->response().url().string().utf8().data()); m_state = Failed; m_cueLoadTimer.startOneShot(0); return; } m_cueParser = WebVTTParser::create(this, m_scriptExecutionContext); } } ASSERT(m_cueParser); while ((length = buffer->getSomeData(data, m_parseOffset))) { m_cueParser->parseBytes(data, length); m_parseOffset += length; } }
static unsigned copyFromSharedBuffer(char* buffer, unsigned bufferLength, const SharedBuffer& sharedBuffer, unsigned offset) { unsigned bytesExtracted = 0; const char* moreData; while (unsigned moreDataLength = sharedBuffer.getSomeData(moreData, offset)) { unsigned bytesToCopy = std::min(bufferLength - bytesExtracted, moreDataLength); memcpy(buffer + bytesExtracted, moreData, bytesToCopy); bytesExtracted += bytesToCopy; if (bytesExtracted == bufferLength) break; offset += bytesToCopy; } return bytesExtracted; }
bool decode(const SharedBuffer& data, bool sizeOnly) { m_decodingSizeOnly = sizeOnly; // We need to do the setjmp here. Otherwise bad things will happen. if (setjmp(JMPBUF(m_png))) return m_decoder->setFailed(); const char* segment; while (unsigned segmentLength = data.getSomeData(segment, m_readOffset)) { m_readOffset += segmentLength; m_currentBufferSize = m_readOffset; png_process_data(m_png, m_info, reinterpret_cast<png_bytep>(const_cast<char*>(segment)), segmentLength); if (sizeOnly ? m_decoder->isDecodedSizeAvailable() : m_decoder->frameIsCompleteAtIndex(0)) return true; } return false; }
bool decode(const SharedBuffer& data, bool sizeOnly) { m_decodingSizeOnly = sizeOnly; PNGImageDecoder* decoder = static_cast<PNGImageDecoder*>(png_get_progressive_ptr(m_png)); // We need to do the setjmp here. Otherwise bad things will happen. if (setjmp(JMPBUF(m_png))) return decoder->setFailed(); const char* segment; while (unsigned segmentLength = data.getSomeData(segment, m_readOffset)) { m_readOffset += segmentLength; m_currentBufferSize = m_readOffset; png_process_data(m_png, m_info, reinterpret_cast<png_bytep>(const_cast<char*>(segment)), segmentLength); // We explicitly specify the superclass isSizeAvailable() because we // merely want to check if we've managed to set the size, not // (recursively) trigger additional decoding if we haven't. if (sizeOnly ? decoder->ImageDecoder::isSizeAvailable() : decoder->isComplete()) return true; } return false; }
void TextTrackLoader::processNewCueData(CachedResource* resource) { ASSERT(m_cachedCueData == resource); if (m_state == Failed || !resource->data()) return; SharedBuffer* buffer = resource->data(); if (m_parseOffset == buffer->size()) return; if (!m_cueParser) m_cueParser = WebVTTParser::create(this, m_scriptExecutionContext); const char* data; unsigned length; while ((length = buffer->getSomeData(data, m_parseOffset))) { m_cueParser->parseBytes(data, length); m_parseOffset += length; } }