Ejemplo n.º 1
0
static unsigned increaseBufferTo(UsageEnvironment& env, int bufOptName,
				 int socket, unsigned requestedSize) {
  // First, get the current buffer size.  If it's already at least
  // as big as what we're requesting, do nothing.
  unsigned curSize = getBufferSize(env, bufOptName, socket);

  // Next, try to increase the buffer to the requested size,
  // or to some smaller size, if that's not possible:
  while (requestedSize > curSize) {
    SOCKLEN_T sizeSize = sizeof requestedSize;
    if (setsockopt(socket, SOL_SOCKET, bufOptName,
		   (char*)&requestedSize, sizeSize) >= 0) {
      // success
      return requestedSize;
    }
    requestedSize = (requestedSize+curSize)/2;
  }

  return getBufferSize(env, bufOptName, socket);
}
Ejemplo n.º 2
0
/** \brief Initializes the stream buffer.
 *
 * This function resets the zlib stream and purges input and output buffers.
 * It also repositions the input streambuf at stream_position.
 *
 * \warning
 * This method is called in the constructor, so it must not read anything
 * from the input streambuf m_inbuf (see notice in constructor.)
 *
 * \param[in] stream_position  A position to reset the inbuf to before
 *                             reading. Specify -1 to read from the
 *                             current position.
 *
 * \sa InflateInputStreambuf()
 */
bool InflateInputStreambuf::reset(offset_t stream_position)
{
    if(stream_position >= 0)
    {
        // reposition m_inbuf
        m_inbuf->pubseekpos(stream_position);
    }

    // m_zs.next_in and avail_in must be set according to
    // zlib.h (inline doc).
    m_zs.next_in = reinterpret_cast<Bytef *>(&m_invec[0]);
    m_zs.avail_in = 0;

    int err(Z_OK);
    if(m_zs_initialized)
    {
        // just reset it
        err = inflateReset(&m_zs);
    }
    else
    {
        // initialize it
        err = inflateInit2(&m_zs, -MAX_WBITS);
        /* windowBits is passed < 0 to tell that there is no zlib header.
           Note that in this case inflate *requires* an extra "dummy" byte
           after the compressed stream in order to complete decompression
           and return Z_STREAM_END.  We always have an extra "dummy" byte,
           because there is always some trailing data after the compressed
           data (either the next entry or the central directory.  */
        m_zs_initialized = true;
    }

    // streambuf init:
    // The important thing here, is that
    // - the pointers are not NULL (which would mean unbuffered)
    // - and that gptr() is not less than egptr() (so we trigger underflow
    //   the first time data is read).
    setg(&m_outvec[0], &m_outvec[0] + getBufferSize(), &m_outvec[0] + getBufferSize());

    return err == Z_OK;
}
Ejemplo n.º 3
0
angle::Result StaticIndexBufferInterface::reserveBufferSpace(const gl::Context *context,
                                                             unsigned int size,
                                                             gl::DrawElementsType indexType)
{
    unsigned int curSize = getBufferSize();
    if (curSize == 0)
    {
        return setBufferSize(context, size, indexType);
    }

    ASSERT(curSize >= size && indexType == getIndexType());
    return angle::Result::Continue;
}
Ejemplo n.º 4
0
QSize ARender::getPreferSize()
{
	Q_D(ARender);
	if (d->music){
		return QSize();
	}
	if (d->pref.isValid()){
		return d->pref;
	}
	QSize s = getBufferSize();
	d->pixelAspectRatio > 1 ? (s.rwidth() *= d->pixelAspectRatio) : (s.rheight() /= d->pixelAspectRatio);
	return s;
}
Ejemplo n.º 5
0
  void ProcessorRouter::addProcessor(Processor* processor) {
    TWYTCH_MOPO_ASSERT(processor->router() == 0 || processor->router() == this);
    (*global_changes_)++;
    local_changes_++;

    processor->router(this);
    processor->setBufferSize(getBufferSize());
    global_order_->push_back(processor);
    processors_[processor] = processor;
    local_order_.push_back(processor);

    for (int i = 0; i < processor->numInputs(); ++i)
      connect(processor, processor->input(i)->source, i);
  }
Ejemplo n.º 6
0
/** \brief Initialize a InflateInputStreambuf.
 *
 * The constructor initializes the various stream buffers and
 * setup the stream start position using the \p start_pos
 * parameter.
 *
 * Data will be inflated (decompressed using zlib) before being
 * returned.
 *
 * \param[in,out] inbuf  The streambuf to use for input.
 * \param[in] start_pos  A position to reset the inbuf to before reading. Specify
 *                       -1 to not change the position.
 */
InflateInputStreambuf::InflateInputStreambuf(std::streambuf *inbuf, offset_t start_pos)
    : FilterInputStreambuf(inbuf)
    , m_outvec(getBufferSize())
    , m_invec(getBufferSize())
    //, m_zs() -- auto-init
    //, m_zs_initialized(false) -- auto-init
{
    // NOTICE: It is important that this constructor and the methods it
    // calls doesn't do anything with the input streambuf inbuf, other
    // than repositioning it to the specified position. The reason is
    // that this class can be subclassed, and the subclass should get a
    // chance to read from the buffer first)

    // zlib init:
    m_zs.zalloc = Z_NULL;
    m_zs.zfree  = Z_NULL;
    m_zs.opaque = Z_NULL;

    reset(start_pos);
    // We are not checking the return value of reset() and throwing
    // an exception in case of an error, because we cannot catch the exception
    // in the constructors of subclasses with all compilers.
}
Ejemplo n.º 7
0
    /**
     * Удаляет все найденые ключи, тоесть ищет их командой keys и удаляет каждый найденый ключь.
     * @param key
     * @return Вернёт -1 или количество удалёных ключей
     * @todo Реализовать более быстрый способ работы
     */
    int SimpleRedisClient::delete_keys( const char *key)
    {
        if(keys(key))
        {
            if(getDataSize() < 1 || getBufferSize() < 1)
            {
                return 0;
            }

            char **ptr_data = new char*[getDataSize()];

            // Выделяем память для buf_data
            char *buf_data = new char[ getBufferSize() ];
            memcpy(buf_data, getData(), getBufferSize());

            long int offset = buf_data - getData(); // Опасное дело!
            int num_keys = getDataSize();
            for(int i =0; i< num_keys; i++)
            {
                ptr_data[i] = getData(i) + offset;
            }

            for(int i =0; i< num_keys; i++)
            {
                printf("del[%d]:'%s'\n", i, ptr_data[i]);
                del(ptr_data[i]);
            }

            // [SimpleRedisClient.cpp:1171]: (error) Mismatching allocation and deallocation: buf_data
            // Очищаем buf_data
            delete[] buf_data;
            delete[] ptr_data;
            return num_keys;
        }

        return -1;
    }
ProtocolParser::ProtocolParserStatus PushProtocolParser::parse(int &bytesParsed) {
	
	bytesParsed = getBufferSize();
	const std::vector<uint8> *buffer = getBuffer();

	Frame *frame = new Frame();
	frame->append(buffer, bytesParsed);

	setNewFrame(frame);

	return FRAME_FINISHED;


	//return NEED_MORE;
}
// Set the default value of the port. This function is used by the construct() function of the proxy
// when creating a new instance of the proxy
void MPEG2Dec_Port::setDefault()
{
    OstTraceInt0(TRACE_FLOW,"Enter MPEG2Dec_Port::setDefault");
    DBC_ASSERT(mParamPortDefinition.eDomain==OMX_PortDomainVideo);
    //MPEG2Dec_Proxy *comp = getProxy();

    mParamPortDefinition.format.video.cMIMEType = (char *)"video/MPEG2";
    mParamPortDefinition.format.video.pNativeRender = 0;
    mParamPortDefinition.format.video.nFrameHeight = 16;      // from OMX spec 1.1.1
    mParamPortDefinition.format.video.nFrameWidth = 16;       // from OMX spec 1.1.1
    mParamPortDefinition.format.video.bFlagErrorConcealment = OMX_FALSE;
    mParamPortDefinition.format.video.pNativeWindow = 0;

    switch (mParamPortDefinition.nPortIndex)
        {
        case 0:
            DBC_ASSERT(mParamPortDefinition.eDir==OMX_DirInput);
            mParamPortDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG2;
            mParamPortDefinition.format.video.eColorFormat = OMX_COLOR_FormatUnused;
            mParamPortDefinition.format.video.nBitrate = 64000;        // from OMX spec 1.1.1
            mParamPortDefinition.format.video.xFramerate = 15;         // from OMX spec 1.1.1
            mParamPortDefinition.format.video.nStride = 0;             // unused for compressed data
            mParamPortDefinition.format.video.nSliceHeight = 1;        // unused for compressed data
            //comp->mParam.setProfileLevel(OMX_VIDEO_MPEG2ProfileSimple, OMX_VIDEO_MPEG2LevelLL);  // from OMX spec 1.1.1
            break;
        case 1:
            DBC_ASSERT(mParamPortDefinition.eDir==OMX_DirOutput);
            mParamPortDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused;
            mParamPortDefinition.format.video.eColorFormat = OMX_COLOR_FormatYUV420Planar;
            mParamPortDefinition.format.video.nBitrate = 0;
            mParamPortDefinition.format.video.xFramerate = 0;
            mParamPortDefinition.format.video.nStride = (mParamPortDefinition.format.video.nFrameWidth * 3) / 2;        // corresponds to a raw in OMX_COLOR_FormatYUV420Planar
            mParamPortDefinition.format.video.nSliceHeight = 1;        // a single raw in the buffer is required. FIXME
            break;
        default:
            DBC_ASSERT(0==1);
        }

    // mParamPortDefinition.nBufferCountActual updated by the component when buffers are allocated
    // mParamPortDefinition.nBufferCountMin set at the creation of the port (check constructor of the proxy)
    // mParamPortDefinition.bEnabled set by the component
    // mParamPortDefinition.bPopulated set by the component
    mParamPortDefinition.bBuffersContiguous = OMX_TRUE;
    mParamPortDefinition.nBufferAlignment = 0x100;
    mParamPortDefinition.nBufferSize = getBufferSize();
    mParamPortDefinition.nBufferCountMin = getBufferCountMin();
    OstTraceInt0(TRACE_FLOW,"Exit MPEG2Dec_Port::setDefault");
}
Ejemplo n.º 10
0
BOOL LLDataPackerAsciiBuffer::packBinaryDataFixed(const U8 *value, S32 size, const char *name)
{
	BOOL success = TRUE;
	writeIndentedName(name);
	
	if (mWriteEnabled)
	{
		S32 i;
		int numCopied = 0;
		BOOL bBufferFull = FALSE;
		for (i = 0; i < size && !bBufferFull; i++)
		{
			numCopied = snprintf(mCurBufferp, getBufferSize()-getCurrentSize(), "%02x ", value[i]);	/* Flawfinder: ignore */
			if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize())
			{
			    numCopied = getBufferSize()-getCurrentSize();
				llwarns << "LLDataPackerAsciiBuffer::packBinaryDataFixed: data truncated: " << llendl;
			    bBufferFull = TRUE;
			}
			mCurBufferp += numCopied;

		}
		if (!bBufferFull)
		{
			numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(), "\n");	/* Flawfinder: ignore */
			if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize())
			{
				numCopied = getBufferSize()-getCurrentSize();
				llwarns << "LLDataPackerAsciiBuffer::packBinaryDataFixed: newline truncated: " << llendl;
			}
			
			mCurBufferp += numCopied;
		}
	}
	else
	{
		int numCopied = 2 * size + 1; //hex bytes plus newline 
		if (numCopied > getBufferSize()-getCurrentSize())
		{
			numCopied = getBufferSize()-getCurrentSize();
		}   
		mCurBufferp += numCopied;
	}
	return success;
}
Ejemplo n.º 11
0
void VideoReader::run()
{
    while (!m_stop)
    {
        while (getBufferSize() < 200 && m_bufferEndPos <= m_numOfFrames)
        {
            bool capSuccess = m_capture->read(m_frame);
            if (!capSuccess)
                qDebug() << "NULL";
            cv::cvtColor(m_frame, m_RGBframe, CV_BGR2RGB);
            m_FrameBuffer->enqueue(m_RGBframe.clone());
            ++m_bufferEndPos;
            msleep(0);
        }
    }
}
Ejemplo n.º 12
0
gl::Error StaticVertexBufferInterface::reserveSpace(unsigned int size)
{
    unsigned int curSize = getBufferSize();
    if (curSize == 0)
    {
        return setBufferSize(size);
    }
    else if (curSize >= size)
    {
        return gl::Error(GL_NO_ERROR);
    }
    else
    {
        UNREACHABLE();
        return gl::Error(GL_INVALID_OPERATION, "Internal error, Static vertex buffers can't be resized.");
    }
}
Ejemplo n.º 13
0
    AbstractPluginFX(const uint32_t params, const uint32_t programs)
        : Plugin(params-2, programs, 0),
          paramCount(params-2), // volume and pan handled by host
          programCount(programs),
          bufferSize(getBufferSize()),
          sampleRate(getSampleRate()),
          effect(nullptr),
          efxoutl(nullptr),
          efxoutr(nullptr)
    {
        efxoutl = new float[bufferSize];
        efxoutr = new float[bufferSize];
        std::memset(efxoutl, 0, sizeof(float)*bufferSize);
        std::memset(efxoutr, 0, sizeof(float)*bufferSize);

        doReinit(true);
    }
Ejemplo n.º 14
0
gl::Error StaticIndexBufferInterface::reserveBufferSpace(unsigned int size, GLenum indexType)
{
    unsigned int curSize = getBufferSize();
    if (curSize == 0)
    {
        return setBufferSize(size, indexType);
    }
    else if (curSize >= size && indexType == getIndexType())
    {
        return gl::Error(GL_NO_ERROR);
    }
    else
    {
        UNREACHABLE();
        return gl::Error(GL_INVALID_OPERATION, "Internal static index buffers can't be resized");
    }
}
    /// Resource init and destroy template member function specializations
    CUCCA_RESOURCE_INIT(HeightMap, HeightMapInitInfo_Default) {
        if (initResources.size() < 1)
            return; // TODO_EXCEPTION: maybe throw a proper exception instead?

        numXSegments_ = initInfo.numXSegments;
        numYSegments_ = initInfo.numYSegments;
        segmentXResolution_ = initInfo.segmentXResolution;
        segmentYResolution_ = initInfo.segmentYResolution;
        segmentXSize_ = initInfo.segmentXSize;
        segmentYSize_ = initInfo.segmentYSize;
        offsetX_ = initInfo.offsetX;
        offsetY_ = initInfo.offsetY;

        auto majorBinary = resourceManager->getResource<Binary>(initResources[0]);

        major_.loadFromMemory(majorBinary->getBufferPtr(), majorBinary->getBufferSize());
    }
Ejemplo n.º 16
0
bool StaticIndexBufferInterface::reserveBufferSpace(unsigned int size, GLenum indexType)
{
    unsigned int curSize = getBufferSize();
    if (curSize == 0)
    {
        return setBufferSize(size, indexType);
    }
    else if (curSize >= size && indexType == getIndexType())
    {
        return true;
    }
    else
    {
        ERR("Static index buffers can't be resized");
        UNREACHABLE();
        return false;
    }
}
Ejemplo n.º 17
0
bool StaticVertexBufferInterface::reserveSpace(unsigned int size)
{
    unsigned int curSize = getBufferSize();
    if (curSize == 0)
    {
        setBufferSize(size);
        return true;
    }
    else if (curSize >= size)
    {
        return true;
    }
    else
    {
        UNREACHABLE();   // Static vertex buffers can't be resized
        return false;
    }
}
Ejemplo n.º 18
0
angle::Result StreamingIndexBufferInterface::reserveBufferSpace(const gl::Context *context,
                                                                unsigned int size,
                                                                gl::DrawElementsType indexType)
{
    unsigned int curBufferSize = getBufferSize();
    unsigned int writePos      = getWritePosition();
    if (size > curBufferSize)
    {
        ANGLE_TRY(setBufferSize(context, std::max(size, 2 * curBufferSize), indexType));
        setWritePosition(0);
    }
    else if (writePos + size > curBufferSize || writePos + size < writePos)
    {
        ANGLE_TRY(discard(context));
        setWritePosition(0);
    }

    return angle::Result::Continue;
}
Ejemplo n.º 19
0
void*
kma_malloc(kma_size_t size)
{
	if (debug) printf("\nREQUEST %i\n", size);
	if (entryPoint == 0) {
		entryPoint = getEntryPoint();
	}
	
	int adjustedSize = size + sizeof(buffer);
	int bufferSize = getBufferSize(adjustedSize);
	freeListInfo* freeList = getFreeList(bufferSize);
	
	if (freeList == NULL) {
		return NULL;
	}
	
	getSpaceIfNeeded(freeList, bufferSize);
	return getNextBuffer(freeList);
}
Ejemplo n.º 20
0
int MBASE::configure()
{
	int status = 0;
	
	in = new float [RTBUFSAMPS * inputChannels()];
    status = alloc_delays();			/* allocates memory for delays */
	
	for (int i = 0; i < 2; i++)
		for (int j = 0; j < 13; j++)
			m_vectors[i][j].Sig = new double[getBufferSize()];

	rvb_reset(m_tapDelay);   			// resets tap delay

	if (status == 0 && m_binaural) {
		rtcmix_advise(name(), "Running in binaural mode.");
		status = alloc_firfilters();	// allocates memory for FIRs
	}
	return status;
}
Ejemplo n.º 21
0
bool StreamingVertexBufferInterface::reserveSpace(unsigned int size)
{
    bool result = true;
    unsigned int curBufferSize = getBufferSize();
    if (size > curBufferSize)
    {
        result = setBufferSize(std::max(size, 3 * curBufferSize / 2));
        setWritePosition(0);
    }
    else if (getWritePosition() + size > curBufferSize)
    {
        if (!discard())
        {
            return false;
        }
        setWritePosition(0);
    }

    return result;
}
Ejemplo n.º 22
0
bool StreamingIndexBufferInterface::reserveBufferSpace(unsigned int size, GLenum indexType)
{
    bool result = true;
    unsigned int curBufferSize = getBufferSize();
    unsigned int writePos = getWritePosition();
    if (size > curBufferSize)
    {
        result = setBufferSize(std::max(size, 2 * curBufferSize), indexType);
        setWritePosition(0);
    }
    else if (writePos + size > curBufferSize || writePos + size < writePos)
    {
        if (!discard())
        {
            return false;
        }
        setWritePosition(0);
    }

    return result;
}
Ejemplo n.º 23
0
int main(int argc, char * const * argv)
{
	int size = getBufferSize(argc, argv);
	short c = 0;

	meminit(size);
	memattach();

	do {
		errno = 0;
		if ((c = fgetc(stdin)) == (short) EOF && ferror(stdin) != 0)
		{
			fprintf(stderr, "%s: %s\n", appname, strerror(errno));
			memdetach();
			memrmv();
			return EXIT_FAILURE;
		}
		memwrite(c);
	} while (c != EOF);

	memdetach();

	return EXIT_SUCCESS;
}
Ejemplo n.º 24
0
gl::Error StreamingVertexBufferInterface::reserveSpace(unsigned int size)
{
    unsigned int curBufferSize = getBufferSize();
    if (size > curBufferSize)
    {
        gl::Error error = setBufferSize(std::max(size, 3 * curBufferSize / 2));
        if (error.isError())
        {
            return error;
        }
        setWritePosition(0);
    }
    else if (getWritePosition() + size > curBufferSize)
    {
        gl::Error error = discard();
        if (error.isError())
        {
            return error;
        }
        setWritePosition(0);
    }

    return gl::Error(GL_NO_ERROR);
}
Ejemplo n.º 25
0
unsigned getReceiveBufferSize(UsageEnvironment& env, int socket) {
  return getBufferSize(env, SO_RCVBUF, socket);
}
Ejemplo n.º 26
0
KpInt32_t getSysBufferSize (KpHandle_t h)
{
	return (getBufferSize(h));
}
Ejemplo n.º 27
0
bool ImageAlphaLut::saveToFile(const std::string path) const
{

    FileUtils::getInstance()->createDirectory(path);

    // 分配文件头 BUFF
    unsigned char * buff = (unsigned char *)malloc(FILEHEADINFO);

    CCASSERT(buff, "No more mem");

    // 基本信息保存到 BUFF
    int * p = (int *)buff;
    *p = 0x89;
    *(++p) = _width;
    *(++p) = _height;
    *(++p) = _offsetX;
    *(++p) = _offsetY;
    *(++p) = _offsetWidth;
    *(++p) = _offsetHeight;

    bool * bp = (bool*)(++p);
    *bp = _isOptimize;

    char * cp = (char*)(++bp);
    strcpy(cp, _name);

    // 设置文件保存位置
    std::string spath;
    if (FileUtils::getInstance()->isDirectoryExist(path))
    {
        if (path.find_last_of('/') == path.length() - 1) {
            spath = path + _name;
        }
        else
        {
            spath = path + '/' + _name;
        }
    }
    else
    {
        spath += FILESAVEDIR;
        spath += _name;
    }
    spath.replace(spath.find_last_of(".") + 1, spath.length(), FILEEXTENSION);

    // 打开文件
    auto fp = fopen(spath.c_str(), "wb");

    CCASSERT(fp, "Open file error");

    // 写入文件
    size_t ws = fwrite(buff, sizeof(unsigned char), FILEHEADINFO, fp);

    CCASSERT(ws == FILEHEADINFO, "Write file info error");

    ws = fwrite(_alphaLut, sizeof(unsigned char), getBufferSize(), fp);

    CCASSERT(ws == getBufferSize(), "Write file data error");
    // 关闭文/Users/wjdev02件
    fclose(fp);
    // 释放 BUFF
    CC_SAFE_FREE(buff);

    return true;
}
Ejemplo n.º 28
0
unsigned getSendBufferSize(UsageEnvironment& env, int socket) {
  return getBufferSize(env, SO_SNDBUF, socket);
}
Ejemplo n.º 29
0
 size_t getBufferSize()
 {
     auto out = static_cast<ModuleOutput*>(outputs->front());
     return out->getBufferSize();
 }
Ejemplo n.º 30
0
      if(nib1 > 9)
         *outBuffer++ = 'a' + nib1 - 10;
      else
         *outBuffer++ = '0' + nib1;
      if(nib2 > 9)
         *outBuffer++ = 'a' + nib2 - 10;
      else
         *outBuffer++ = '0' + nib2;
   }
   *outBuffer = 0;
   return ret;
}

RefPtr<ByteBuffer> ByteBuffer::decodeBase16() const
{
   size_t outLen = getBufferSize() >> 1;
   ByteBuffer *ret = new ByteBuffer(outLen);
   const U8 *src = getBuffer();
   U8 *dst = ret->getBuffer();
   for(U32 i = 0; i < outLen; i++)
   {
      U8 out = 0;
      U8 nib1 = *src++;
      U8 nib2 = *src++;
      if(nib1 >= '0' && nib1 <= '9')
         out = (nib1 - '0') << 4;
      else if(nib1 >= 'a' && nib1 <= 'f')
         out = (nib1 - 'a' + 10) << 4;
      else if(nib1 >= 'A' && nib1 <= 'A')
         out = (nib1 - 'A' + 10) << 4;
      if(nib2 >= '0' && nib2 <= '9')