Beispiel #1
0
FXbool AacDecoder::flush() {
  if (out) {
    buffer.clear();
    out->clear();
    }
  return true;
  }
Beispiel #2
0
 byte getWUSresult(MemoryBuffer &mb)
 {
     byte ret = 0;
     wusbuf.swapWith(mb);    
     if (mb.length()==1) {
         mb.read(ret);
         mb.clear();
     }
     return ret;
 }
void TransferServer::sendProgress(OutputProgress & curProgress)
{
    MemoryBuffer msg;
    msg.setEndian(__BIG_ENDIAN);
    curProgress.serialize(msg.clear().append(false));
    if (!catchWriteBuffer(masterSocket, msg))
        throwError(RFSERR_TimeoutWaitMaster);

    checkForRemoteAbort(masterSocket);
}
Beispiel #4
0
AudioBuffer* PatchProcessor::createMemoryBuffer(int channels, int size){
  // assert_param(bufferCount < MAX_BUFFERS_PER_PATCH];
  float* buffer = extbuffer+extpos;
  size = min(size, BUFFER_LENGTH-extpos);
  extpos += size;
  size /= channels;
  MemoryBuffer* buf = new MemoryBuffer(buffer, channels, size);
  buffers[bufferCount++] = buf;
  buf->clear();
  return buf;
}
Beispiel #5
0
    //IIncludeHandler
    bool getInclude(const char* includename, MemoryBuffer& includebuf, bool& pathOnly)
    {
        if(!includename)
            return false;

        pathOnly = true;
        includebuf.clear();
        const char *finger=pastLast(includename, "esp/xslt/");
        if (finger)
        {
            StringBuffer filepath;
            if (fileExists(filepath.append(getCFD()).append("smc_xslt/").append(finger)) || fileExists(filepath.clear().append(getCFD()).append("xslt/").append(finger)))
            {
                includebuf.append(filepath.length(), filepath.str());
                return true;
            }
        }
        else
        {
            // First of all, it's better to use absolute path to specify the include, like /esp/xslt/ui_overrides.xslt.
            // When you specify the include as relative path, for example ./ui_overrides.xslt
            // the path will be expanded (by xmllib's source resolver) to its full path, beginning with file://
            // on windows it looks like: file:///C:/playground/esp_lsb2/xslt/ui_overrides.xslt
            // on linux: file:///home/yma/playground/esp_lsb2/xslt/ui_overrides.xslt
            // If current path not found, use root
            char dir[_MAX_PATH];
            if (!GetCurrentDirectory(sizeof(dir), dir)) {
                ERRLOG("ESPxsltIncludeHandler::getInclude: Current directory path too big, setting local path to null");
                dir[0] = 0;
            }
#ifdef _WIN32
            for(int i = 0; i < _MAX_PATH; i++)
            {
                if(dir[i] == '\0')
                    break;
                else if(dir[i] == PATHSEPCHAR)
                    dir[i] = '/';
            }
#endif
            finger = strstr(includename, dir);
            if(finger)
            {
                finger += strlen(dir) + 1;
                StringBuffer filepath(finger);
                if (fileExists(filepath))
                {
                    includebuf.append(filepath.length(), filepath.str());
                    return true;
                }
            }
        }
        return false;
    }
 void addResult(rowcount_t resultCount, MemoryBuffer &resultData, bool complete)
 {
     Owned<IWorkUnit> wu = &container.queryJob().queryWorkUnit().lock();
     Owned<IWUResult> result = updateWorkUnitResult(wu, resultName, resultSeq);
     if (appendOutput)
         result->addResultRaw(resultData.length(), resultData.toByteArray(), ResultFormatRaw);
     else
         result->setResultRaw(resultData.length(), resultData.toByteArray(), ResultFormatRaw);
     result->setResultRowCount(resultCount);
     result->setResultTotalRowCount(resultCount);
     resultData.clear();
     if (complete)
         result->setResultStatus(ResultStatusCalculated);
     appendOutput = true;
 }
Beispiel #7
0
 inline bool fileRead(const char *filename, MemoryBuffer &buff)
 {
     Owned<IFile> fi=createIFile(filename);
     if (fi)
     {
         Owned<IFileIO> fio=fi->open(IFOread);
         if (fio)
         {
             offset_t len=fio->size();
             if (fio->read(0, len, buff.reserveTruncate(len))==len)
                 return true;
         }
     }
     buff.clear();
     return false;
 }
Beispiel #8
0
    virtual int run()
    {
        unsigned start=0;
        try {
            MemoryBuffer mb;
            bool first = true;
            loop
            {
                size32_t sz = sock->receive_block_size();
                if (sz==0)
                    break;
                {
                    //CriticalBlock block(recvsect);        // TEST
                    unsigned start=msTick();
                    if (!sock->receive_block(mb.clear().reserve(sz),sz)) {
                        StringBuffer err("Timeout receiving from ");
                        err.append(src);
                        ninfo->sendError(err.str());
                        break;
                    }
                }
#ifdef TRACE
                DBGLOG("received %d from %d",sz,src+1);
#endif
                unsigned seq;
                mb.read(seq);
                if (seq!=ninfo->recvseq[src]++) {
                    StringBuffer msg;
                    msg.append("Block out of sequence from ").append(src+1).append(", got ").append(seq).append(" expected ").append(ninfo->recvseq[src]-1);
                    ninfo->sendError(msg.str());
                    break; // errors fatal otherwise overload q
                }
                ninfo->recvtime[src] += (msTick()-start);
                ninfo->recvbytes[src] += sz;
            }
        }
        catch (IException *e) {
            StringBuffer err;
            e->errorMessage(err);
            ninfo->sendError("Receive exception",err.str());
        }
#ifdef TRACE
        DBGLOG("receive exit from %d",src+1);
#endif
        return 1;
    };
static bool serializeWUInfo(IConstWorkUnitInfo &info,MemoryBuffer &mb)
{
    fixedAppend(mb,24,info.queryWuid());
    varAppendMax(mb,64,info.queryUser());
    varAppendMax(mb,64,info.queryClusterName());
    varAppendMax(mb,64,""); // roxiecluster is obsolete
    varAppendMax(mb,256,info.queryJobName());
    fixedAppend(mb,10,info.queryStateDesc());
    fixedAppend(mb,7,info.queryPriorityDesc());
    short int prioritylevel = info.getPriorityLevel();
    mb.append(prioritylevel);
    fixedAppend(mb,20,"");  // Created timestamp
    fixedAppend(mb,20,"");  // Modified timestamp
    mb.append(true);
    mb.append(info.isProtected());
    if (mb.length()>WORKUNIT_SERVICES_BUFFER_MAX) {
        mb.clear().append(WUS_STATUS_OVERFLOWED);
        return false;
    }
    return true;
}
Beispiel #10
0
int readResults(ISocket * socket, bool readBlocked, bool useHTTP, StringBuffer &result, const char *query, size32_t queryLen)
{
    if (readBlocked)
        socket->set_block_mode(BF_SYNC_TRANSFER_PULL,0,60*1000);

    MemoryBuffer remoteReadCursorMb;
    unsigned len;
    bool is_status;
    bool isBlockedResult;
    for (;;)
    {
        if (delay)
            MilliSleep(delay);
        is_status = false;
        isBlockedResult = false;
        try
        {
            if (useHTTP)
                len = 0x10000;
            else if (readBlocked)
                len = socket->receive_block_size();
            else
            {
                socket->read(&len, sizeof(len));
                _WINREV(len);                    
            }
        }
        catch(IException * e)
        {
            if (manyResults)
                showMessage("End of result multiple set\n");
            else
                pexception("failed to read len data", e);
            e->Release();
            return 1;
        }

        if (len == 0)
        {
            if (manyResults)
            {
                showMessage("----End of result set----\n");
                continue;
            }
            break;
        }

        bool isSpecial = false;
        bool pluginRequest = false;
        bool dataBlockRequest = false;
        bool remoteReadRequest = false;
        if (len & 0x80000000)
        {
            unsigned char flag;
            isSpecial = true;
            socket->read(&flag, sizeof(flag));
            switch (flag)
            {
            case '-':
                if (echoResults)
                    fputs("Error:", stdout);
                if (saveResults && trace != NULL)
                    fputs("Error:", trace);
                break;
            case 'D':
                showMessage("request for datablock\n");
                dataBlockRequest = true;
                break;
            case 'P':
                showMessage("request for plugin\n");
                pluginRequest = true;
                break;
            case 'S':
                 if (showStatus)
                 showMessage("Status:");
                 is_status=true;
                 break;
            case 'T':
                 showMessage("Timing:\n");
                 break;
            case 'X':
                showMessage("---Compound query finished---\n");
                return 1;
            case 'R':
                isBlockedResult = true;
                break;
            case 'J':
                remoteReadRequest = true;
                break;
            }
            len &= 0x7FFFFFFF;
            len--;      // flag already read
        }

        MemoryBuffer mb;
        mb.setEndian(__BIG_ENDIAN);
        char *mem = (char *)mb.reserveTruncate(len+1);
        char * t = mem;
        size32_t sendlen = len;
        t[len]=0;
        try
        {
            if (useHTTP)
            {
                try
                {
                    socket->read(t, 0, len, sendlen);
                }
                catch (IException *E)
                {
                    if (E->errorCode()!= JSOCKERR_graceful_close)
                        throw;
                    E->Release();
                    break;
                }
                if (!sendlen)
                    break;
            }
            else if (readBlocked)
                socket->receive_block(t, len); 
            else
                socket->read(t, len);
        }
        catch(IException * e)
        {
            pexception("failed to read data", e);
            e->Release();
            return 1;
        }
        if (pluginRequest)
        {
            //Not very robust!  A poor man's implementation for testing...
            StringBuffer dllname, libname;
            const char * dot = strchr(t, '.');
            dllname.append("\\edata\\bin\\debug\\").append(t);
            libname.append("\\edata\\bin\\debug\\").append(dot-t,t).append(".lib");

            sendFile(dllname.str(), socket);
            sendFile(libname.str(), socket);
        }
        else if (dataBlockRequest)
        {
            //Not very robust!  A poor man's implementation for testing...
            offset_t offset;
            mb.read(offset);
            sendFileChunk((const char *)mb.readDirect(offset), offset, socket);
        }
        else if (remoteReadRequest)
        {
            Owned<IPropertyTree> requestTree = createPTreeFromJSONString(queryLen, query);
            Owned<IPropertyTree> responseTree; // used if response is xml or json
            const char *outputFmtStr = requestTree->queryProp("format");
            const char *response = nullptr;
            if (!outputFmtStr || strieq("xml", outputFmtStr))
            {
                response = (const char *)mb.readDirect(len);
                responseTree.setown(createPTreeFromXMLString(len, response));
            }
            else if (strieq("json", outputFmtStr))
            {
                response = (const char *)mb.readDirect(len);
                responseTree.setown(createPTreeFromJSONString(len, response));
            }
            unsigned cursorHandle;
            if (responseTree)
                cursorHandle = responseTree->getPropInt("cursor");
            else
                mb.read(cursorHandle);
            bool retrySend = false;
            if (cursorHandle)
            {
                PROGLOG("Got handle back: %u; len=%u", cursorHandle, len);
                StringBuffer xml;
                if (responseTree)
                {
                    if (echoResults && response)
                    {
                        fputs(response, stdout);
                        fflush(stdout);
                    }
                    if (!responseTree->getPropBin("cursorBin", remoteReadCursorMb.clear()))
                        break;
                }
                else
                {
                    size32_t dataLen;
                    mb.read(dataLen);
                    if (!dataLen)
                        break;
                    const void *rowData = mb.readDirect(dataLen);
                    // JCSMORE - output binary row data?

                    // cursor
                    size32_t cursorLen;
                    mb.read(cursorLen);
                    if (!cursorLen)
                        break;
                    const void *cursor = mb.readDirect(cursorLen);
                    memcpy(remoteReadCursorMb.clear().reserveTruncate(cursorLen), cursor, cursorLen);
                }

                if (remoteStreamForceResend)
                    cursorHandle = NotFound; // fake that it's a handle dafilesrv doesn't know about

                Owned<IPropertyTree> requestTree = createPTree();
                requestTree->setPropInt("cursor", cursorHandle);

                // Only the handle is needed for continuation, but this tests the behaviour of some clients which may send cursor per request (e.g. to refresh)
                if (remoteStreamSendCursor)
                    requestTree->setPropBin("cursorBin", remoteReadCursorMb.length(), remoteReadCursorMb.toByteArray());

                requestTree->setProp("format", outputFmtStr);
                StringBuffer requestStr;
                toJSON(requestTree, requestStr);
#ifdef _DEBUG
                fputs(requestStr, stdout);
#endif

                sendlen = requestStr.length();
                _WINREV(sendlen);

                try
                {
                    if (!rawSend && !useHTTP)
                        socket->write(&sendlen, sizeof(sendlen));
                    socket->write(requestStr.str(), requestStr.length());
                }
                catch (IJSOCK_Exception *e)
                {
                    retrySend = true;
                    EXCLOG(e, nullptr);
                    e->Release();
                }
            }
            else // dafilesrv didn't know who I was, resent query + serialized cursor
                retrySend = true;
            if (retrySend)
            {
                PROGLOG("Retry send for handle: %u", cursorHandle);
                requestTree->setPropBin("cursorBin", remoteReadCursorMb.length(), remoteReadCursorMb.toByteArray());
                StringBuffer requestStr;
                toJSON(requestTree, requestStr);

                PROGLOG("requestStr = %s", requestStr.str());
                sendlen = requestStr.length();
                _WINREV(sendlen);
                if (!rawSend && !useHTTP)
                    socket->write(&sendlen, sizeof(sendlen));
                socket->write(requestStr.str(), requestStr.length());
            }
        }
        else
        {
            if (isBlockedResult)
            {
                t += 8;
                t += strlen(t)+1;
                sendlen -= (t - mem);
            }
            if (echoResults && (!is_status || showStatus))
            {
                fwrite(t, sendlen, 1, stdout);
                fflush(stdout);
            }
            if (!is_status)
                result.append(sendlen, t);
        }

        if (abortAfterFirst)
            return 0;
    }
    return 0;
}
void GlareStreaksOperation::generateGlare(float *data, MemoryBuffer *inputTile, NodeGlare *settings)
{
	int x, y, n;
	unsigned int nump = 0;
	float c1[4], c2[4], c3[4], c4[4];
	float a, ang = DEG2RADF(360.0f) / (float)settings->streaks;

	int size = inputTile->getWidth() * inputTile->getHeight();
	int size4 = size * 4;

	bool breaked = false;

	MemoryBuffer *tsrc = inputTile->duplicate();
	MemoryBuffer *tdst = new MemoryBuffer(COM_DT_COLOR, inputTile->getRect());
	tdst->clear();
	memset(data, 0, size4 * sizeof(float));

	for (a = 0.0f; a < DEG2RADF(360.0f) && (!breaked); a += ang) {
		const float an = a + settings->angle_ofs;
		const float vx = cos((double)an), vy = sin((double)an);
		for (n = 0; n < settings->iter && (!breaked); ++n) {
			const float p4 = pow(4.0, (double)n);
			const float vxp = vx * p4, vyp = vy * p4;
			const float wt = pow((double)settings->fade, (double)p4);
			const float cmo = 1.0f - (float)pow((double)settings->colmod, (double)n + 1);  // colormodulation amount relative to current pass
			float *tdstcol = tdst->getBuffer();
			for (y = 0; y < tsrc->getHeight() && (!breaked); ++y) {
				for (x = 0; x < tsrc->getWidth(); ++x, tdstcol += 4) {
					// first pass no offset, always same for every pass, exact copy,
					// otherwise results in uneven brightness, only need once
					if (n == 0) tsrc->read(c1, x, y); else c1[0] = c1[1] = c1[2] = 0;
					tsrc->readBilinear(c2, x + vxp, y + vyp);
					tsrc->readBilinear(c3, x + vxp * 2.0f, y + vyp * 2.0f);
					tsrc->readBilinear(c4, x + vxp * 3.0f, y + vyp * 3.0f);
					// modulate color to look vaguely similar to a color spectrum
					c2[1] *= cmo;
					c2[2] *= cmo;

					c3[0] *= cmo;
					c3[1] *= cmo;

					c4[0] *= cmo;
					c4[2] *= cmo;

					tdstcol[0] = 0.5f * (tdstcol[0] + c1[0] + wt * (c2[0] + wt * (c3[0] + wt * c4[0])));
					tdstcol[1] = 0.5f * (tdstcol[1] + c1[1] + wt * (c2[1] + wt * (c3[1] + wt * c4[1])));
					tdstcol[2] = 0.5f * (tdstcol[2] + c1[2] + wt * (c2[2] + wt * (c3[2] + wt * c4[2])));
					tdstcol[3] = 1.0f;
				}
				if (isBreaked()) {
					breaked = true;
				}
			}
			memcpy(tsrc->getBuffer(), tdst->getBuffer(), sizeof(float) * size4);
		}

		float *sourcebuffer = tsrc->getBuffer();
		float factor = 1.0f / (float)(6 - settings->iter);
		for (int i = 0; i < size4; i += 4) {
			madd_v3_v3fl(&data[i], &sourcebuffer[i], factor);
			data[i + 3] =  1.0f;
		}

		tdst->clear();
		memcpy(tsrc->getBuffer(), inputTile->getBuffer(), sizeof(float) * size4);
		nump++;
	}

	delete tsrc;
	delete tdst;
}